码迷,mamicode.com
首页 > 其他好文 > 详细

RGB格式等比例缩放

时间:2017-04-04 11:51:38      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:oat   height   before   put   缩放   bit   格式   span   mem   

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

 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 }

 

RGB格式等比例缩放

标签:oat   height   before   put   缩放   bit   格式   span   mem   

原文地址:http://www.cnblogs.com/eustoma/p/6664446.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!