原理为:将原始图像的每个像素通过一个比例关系式映射到相应的位置。
1 /* 2 lrgb: input 24bits rgb buffer 3 srgb: output 24bits rgb buffer 4 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 }