RGB格式等比例缩放

原理为:将原始图像的每个像素通过一个比例关系式映射到相应的位置。

 1 /*
 2  lrgb:   input 24bits rgb buffer
 3  srgb:   output 24bits rgb buffer
 4  width:  input width
 5  height: input height
 6  xscale: changed vector
 7  yscale: changed vector
 8  */
 9 int lrgbtosrgb(unsigned char *lrgb, unsigned char *srgb, int width, int height, float xscale, float yscale)
10 {
11     int in = 0, out = 0;
12     int ox, oy;     //the pixel site is after changed
13     int rx, ry;     //the pixel site is before changed
14     int temp = 0;   //turn site(x,y) to memory storage
15     int outwidth = width * xscale;      //after changed width
16     int outheight = height * yscale;    //after changed height
17 
18     //rx = ox/xscale + 0.5;// out--to--input
19     //ry = oy/yscale + 0.5;// out--to--input
20 
21     for (oy = 0; oy < outheight; oy++)
22     {
23         ry = (int)(oy/0.5 + 0.5);
24         if(ry >= height)
25         ry--;
26         temp = ry * width *3;//origion pixel site of which width
27 
28         for (ox = 0; ox < outwidth; ox++)
29         {
30             rx = (int)(ox/0.5 + 0.5);
31             if (rx >= width)
32                 rx--;
33             in = temp + rx * 3;//change site(x,y) to storage
34 
35             srgb[out+0] = lrgb[in+0];
36             srgb[out+1] = lrgb[in+1];
37             srgb[out+2] = lrgb[in+2];
38 
39             out += 3;
40         }
41     }
42     return 0;
43 }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值