SyntekUSBVideoCamera
|
00001 00034 #include <linux/module.h> 00035 #include <linux/init.h> 00036 #include <linux/kernel.h> 00037 #include <linux/version.h> 00038 #include <linux/errno.h> 00039 #include <linux/slab.h> 00040 #include <linux/kref.h> 00041 00042 #include <linux/usb.h> 00043 #include <media/v4l2-common.h> 00044 00045 #include "stk11xx.h" 00046 00047 00048 #define MAX(a,b) ((a)>(b)?(a):(b)) 00049 #define MIN(a,b) ((a)<(b)?(a):(b)) 00050 #define CLIP(a,low,high) MAX((low),MIN((high),(a))) 00051 00052 00053 void stk11xx_b2rgb24(uint8_t *, uint8_t *, 00054 struct stk11xx_coord *, struct stk11xx_coord *, 00055 const int, const int, const int); 00056 void stk11xx_b2rgb32(uint8_t *, uint8_t *, 00057 struct stk11xx_coord *, struct stk11xx_coord *, 00058 const int, const int, const int); 00059 void stk11xx_b2bgr24(uint8_t *, uint8_t *, 00060 struct stk11xx_coord *, struct stk11xx_coord *, 00061 const int, const int, const int); 00062 void stk11xx_b2bgr32(uint8_t *, uint8_t *, 00063 struct stk11xx_coord *, struct stk11xx_coord *, 00064 const int, const int, const int); 00065 00066 void stk11xx_b2uyvy(uint8_t *, uint8_t *, 00067 struct stk11xx_coord *, struct stk11xx_coord *, 00068 const int, const int, const int); 00069 void stk11xx_b2yuyv(uint8_t *, uint8_t *, 00070 struct stk11xx_coord *, struct stk11xx_coord *, 00071 const int, const int, const int); 00072 00073 00074 void stk11xx_correct_brightness(uint8_t *, const int, const int, 00075 const int, int, int); 00076 00077 00078 static signed short stk11xx_yuv_interp[256][8] = { 00079 {0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,1,0,0,0,1,0,0},{0,1,0,0,0,1,-1,0}, 00080 {1,2,0,0,-1,2,-1,0},{1,2,0,0,-1,2,-2,0},{1,3,0,-1,-1,3,-2,0},{2,3,0,-1,-2,3,-2,0}, 00081 {2,4,0,-1,-2,4,-3,0},{2,5,1,-1,-2,4,-3,0},{2,5,1,-1,-3,5,-4,0},{3,6,1,-1,-3,5,-4,0}, 00082 {3,6,1,-2,-3,6,-5,0},{3,7,1,-2,-4,6,-5,-1},{4,7,1,-2,-4,7,-5,-1},{4,8,1,-2,-4,7,-6,-1}, 00083 {4,9,1,-2,-5,8,-6,-1},{5,9,1,-2,-5,8,-7,-1},{5,10,2,-3,-5,9,-7,-1},{5,10,2,-3,-6,9,-7,-1}, 00084 {5,11,2,-3,-6,10,-8,-1},{6,11,2,-3,-6,10,-8,-1},{6,12,2,-3,-7,11,-9,-1},{6,13,2,-3,-7,11,-9,-1}, 00085 {7,13,2,-4,-7,12,-10,-1},{7,14,2,-4,-8,12,-10,-2},{7,14,2,-4,-8,13,-10,-2},{8,15,3,-4,-8,13,-11,-2}, 00086 {8,15,3,-4,-9,14,-11,-2},{8,16,3,-4,-9,14,-12,-2},{8,17,3,-5,-9,15,-12,-2},{9,17,3,-5,-10,15,-12,-2}, 00087 {9,18,3,-5,-10,16,-13,-2},{9,18,3,-5,-10,16,-13,-2},{10,19,3,-5,-11,17,-14,-2},{10,19,3,-5,-11,17,-14,-2}, 00088 {10,20,4,-6,-11,18,-15,-2},{11,20,4,-6,-12,18,-15,-3},{11,21,4,-6,-12,19,-15,-3},{11,22,4,-6,-12,19,-16,-3}, 00089 {11,22,4,-6,-13,20,-16,-3},{12,23,4,-6,-13,20,-17,-3},{12,23,4,-7,-13,21,-17,-3},{12,24,4,-7,-14,21,-18,-3}, 00090 {13,24,5,-7,-14,22,-18,-3},{13,25,5,-7,-14,22,-18,-3},{13,26,5,-7,-15,23,-19,-3},{14,26,5,-7,-15,23,-19,-3}, 00091 {14,27,5,-8,-15,24,-20,-3},{14,27,5,-8,-16,24,-20,-3},{14,28,5,-8,-16,25,-20,-4},{15,28,5,-8,-16,25,-21,-4}, 00092 {15,29,5,-8,-17,26,-21,-4},{15,30,6,-8,-17,26,-22,-4},{16,30,6,-9,-17,27,-22,-4},{16,31,6,-9,-18,27,-23,-4}, 00093 {16,31,6,-9,-18,28,-23,-4},{17,32,6,-9,-18,28,-23,-4},{17,32,6,-9,-19,29,-24,-4},{17,33,6,-9,-19,29,-24,-4}, 00094 {17,34,6,-10,-19,30,-25,-4},{18,34,6,-10,-20,30,-25,-4},{18,35,7,-10,-20,31,-25,-5},{18,35,7,-10,-20,31,-26,-5}, 00095 {19,36,7,-10,-21,32,-26,-5},{19,36,7,-10,-21,32,-27,-5},{19,37,7,-11,-21,33,-27,-5},{20,37,7,-11,-22,33,-28,-5}, 00096 {20,38,7,-11,-22,34,-28,-5},{20,39,7,-11,-22,34,-28,-5},{20,39,7,-11,-23,35,-29,-5},{21,40,8,-11,-23,35,-29,-5}, 00097 {21,40,8,-12,-23,36,-30,-5},{21,41,8,-12,-24,36,-30,-5},{22,41,8,-12,-24,37,-30,-6},{22,42,8,-12,-24,37,-31,-6}, 00098 {22,43,8,-12,-25,38,-31,-6},{23,43,8,-12,-25,38,-32,-6},{23,44,8,-13,-25,39,-32,-6},{23,44,9,-13,-26,39,-33,-6}, 00099 {23,45,9,-13,-26,40,-33,-6},{24,45,9,-13,-26,40,-33,-6},{24,46,9,-13,-27,41,-34,-6},{24,47,9,-14,-27,41,-34,-6}, 00100 {25,47,9,-14,-27,42,-35,-6},{25,48,9,-14,-28,42,-35,-6},{25,48,9,-14,-28,43,-36,-6},{26,49,9,-14,-28,43,-36,-7}, 00101 {26,49,10,-14,-29,44,-36,-7},{26,50,10,-15,-29,44,-37,-7},{26,51,10,-15,-29,45,-37,-7},{27,51,10,-15,-30,45,-38,-7}, 00102 {27,52,10,-15,-30,46,-38,-7},{27,52,10,-15,-30,46,-38,-7},{28,53,10,-15,-31,47,-39,-7},{28,53,10,-16,-31,47,-39,-7}, 00103 {28,54,10,-16,-31,48,-40,-7},{29,54,11,-16,-32,48,-40,-7},{29,55,11,-16,-32,49,-41,-7},{29,56,11,-16,-32,49,-41,-8}, 00104 {29,56,11,-16,-33,50,-41,-8},{30,57,11,-17,-33,50,-42,-8},{30,57,11,-17,-33,51,-42,-8},{30,58,11,-17,-34,51,-43,-8}, 00105 {31,58,11,-17,-34,52,-43,-8},{31,59,11,-17,-34,52,-43,-8},{31,60,12,-17,-35,53,-44,-8},{31,60,12,-18,-35,53,-44,-8}, 00106 {32,61,12,-18,-35,54,-45,-8},{32,61,12,-18,-36,54,-45,-8},{32,62,12,-18,-36,55,-46,-8},{33,62,12,-18,-36,55,-46,-9}, 00107 {33,63,12,-18,-37,56,-46,-9},{33,64,12,-19,-37,56,-47,-9},{34,64,12,-19,-37,57,-47,-9},{34,65,13,-19,-38,57,-48,-9}, 00108 {34,65,13,-19,-38,58,-48,-9},{34,66,13,-19,-38,58,-48,-9},{35,66,13,-19,-39,59,-49,-9},{35,67,13,-20,-39,59,-49,-9}, 00109 {35,68,13,-20,-39,60,-50,-9},{36,68,13,-20,-40,60,-50,-9},{36,69,13,-20,-40,61,-51,-9},{36,69,14,-20,-40,61,-51,-9}, 00110 {37,70,14,-20,-41,62,-51,-10},{37,70,14,-21,-41,62,-52,-10},{37,71,14,-21,-41,63,-52,-10},{37,72,14,-21,-42,63,-53,-10}, 00111 {38,72,14,-21,-42,64,-53,-10},{38,73,14,-21,-42,64,-54,-10},{38,73,14,-21,-43,65,-54,-10},{39,74,14,-22,-43,65,-54,-10}, 00112 {39,74,15,-22,-43,66,-55,-10},{39,75,15,-22,-44,66,-55,-10},{40,75,15,-22,-44,67,-56,-10},{40,76,15,-22,-44,67,-56,-10}, 00113 {40,77,15,-22,-45,68,-56,-11},{40,77,15,-23,-45,68,-57,-11},{41,78,15,-23,-45,69,-57,-11},{41,78,15,-23,-46,69,-58,-11}, 00114 {41,79,15,-23,-46,70,-58,-11},{42,79,16,-23,-46,70,-59,-11},{42,80,16,-23,-47,71,-59,-11},{42,81,16,-24,-47,71,-59,-11}, 00115 {43,81,16,-24,-47,72,-60,-11},{43,82,16,-24,-48,72,-60,-11},{43,82,16,-24,-48,73,-61,-11},{43,83,16,-24,-48,73,-61,-11}, 00116 {44,83,16,-24,-49,74,-61,-12},{44,84,16,-25,-49,74,-62,-12},{44,85,17,-25,-49,75,-62,-12},{45,85,17,-25,-50,75,-63,-12}, 00117 {45,86,17,-25,-50,76,-63,-12},{45,86,17,-25,-50,76,-64,-12},{46,87,17,-25,-51,77,-64,-12},{46,87,17,-26,-51,77,-64,-12}, 00118 {46,88,17,-26,-51,78,-65,-12},{46,89,17,-26,-52,78,-65,-12},{47,89,18,-26,-52,79,-66,-12},{47,90,18,-26,-52,79,-66,-12}, 00119 {47,90,18,-26,-53,80,-66,-13},{48,91,18,-27,-53,80,-67,-13},{48,91,18,-27,-53,81,-67,-13},{48,92,18,-27,-54,81,-68,-13}, 00120 {49,92,18,-27,-54,82,-68,-13},{49,93,18,-27,-54,82,-69,-13},{49,94,18,-28,-54,83,-69,-13},{49,94,19,-28,-55,83,-69,-13}, 00121 {50,95,19,-28,-55,84,-70,-13},{50,95,19,-28,-55,84,-70,-13},{50,96,19,-28,-56,85,-71,-13},{51,96,19,-28,-56,85,-71,-13}, 00122 {51,97,19,-29,-56,86,-72,-13},{51,98,19,-29,-57,86,-72,-14},{52,98,19,-29,-57,87,-72,-14},{52,99,19,-29,-57,87,-73,-14}, 00123 {52,99,20,-29,-58,88,-73,-14},{52,100,20,-29,-58,88,-74,-14},{53,100,20,-30,-58,89,-74,-14},{53,101,20,-30,-59,89,-74,-14}, 00124 {53,102,20,-30,-59,90,-75,-14},{54,102,20,-30,-59,90,-75,-14},{54,103,20,-30,-60,91,-76,-14},{54,103,20,-30,-60,91,-76,-14}, 00125 {55,104,20,-31,-60,92,-77,-14},{55,104,21,-31,-61,92,-77,-15},{55,105,21,-31,-61,93,-77,-15},{55,106,21,-31,-61,93,-78,-15}, 00126 {56,106,21,-31,-62,94,-78,-15},{56,107,21,-31,-62,94,-79,-15},{56,107,21,-32,-62,95,-79,-15},{57,108,21,-32,-63,95,-79,-15}, 00127 {57,108,21,-32,-63,96,-80,-15},{57,109,22,-32,-63,96,-80,-15},{58,109,22,-32,-64,97,-81,-15},{58,110,22,-32,-64,97,-81,-15}, 00128 {58,111,22,-33,-64,98,-82,-15},{58,111,22,-33,-65,98,-82,-16},{59,112,22,-33,-65,99,-82,-16},{59,112,22,-33,-65,99,-83,-16}, 00129 {59,113,22,-33,-66,100,-83,-16},{60,113,22,-33,-66,100,-84,-16},{60,114,23,-34,-66,101,-84,-16},{60,115,23,-34,-67,101,-84,-16}, 00130 {60,115,23,-34,-67,102,-85,-16},{61,116,23,-34,-67,102,-85,-16},{61,116,23,-34,-68,103,-86,-16},{61,117,23,-34,-68,103,-86,-16}, 00131 {62,117,23,-35,-68,104,-87,-16},{62,118,23,-35,-69,104,-87,-16},{62,119,23,-35,-69,105,-87,-17},{63,119,24,-35,-69,105,-88,-17}, 00132 {63,120,24,-35,-70,106,-88,-17},{63,120,24,-35,-70,106,-89,-17},{63,121,24,-36,-70,107,-89,-17},{64,121,24,-36,-71,107,-90,-17}, 00133 {64,122,24,-36,-71,108,-90,-17},{64,123,24,-36,-71,108,-90,-17},{65,123,24,-36,-72,109,-91,-17},{65,124,24,-36,-72,109,-91,-17}, 00134 {65,124,25,-37,-72,110,-92,-17},{66,125,25,-37,-73,110,-92,-17},{66,125,25,-37,-73,111,-92,-18},{66,126,25,-37,-73,111,-93,-18}, 00135 {66,127,25,-37,-74,112,-93,-18},{67,127,25,-37,-74,112,-94,-18},{67,128,25,-38,-74,113,-94,-18},{67,128,25,-38,-75,113,-95,-18}, 00136 {68,129,25,-38,-75,114,-95,-18},{68,129,26,-38,-75,114,-95,-18},{68,130,26,-38,-76,115,-96,-18},{69,130,26,-38,-76,115,-96,-18}, 00137 {69,131,26,-39,-76,116,-97,-18},{69,132,26,-39,-77,116,-97,-18},{69,132,26,-39,-77,117,-97,-19},{70,133,26,-39,-77,117,-98,-19}, 00138 {70,133,26,-39,-78,118,-98,-19},{70,134,27,-39,-78,118,-99,-19},{71,134,27,-40,-78,119,-99,-19},{71,135,27,-40,-79,119,-100,-19}, 00139 {71,136,27,-40,-79,120,-100,-19},{72,136,27,-40,-79,120,-100,-19},{72,137,27,-40,-80,121,-101,-19},{72,137,27,-40,-80,121,-101,-19}, 00140 {72,138,27,-41,-80,122,-102,-19},{73,138,27,-41,-81,122,-102,-19},{73,139,28,-41,-81,123,-103,-19},{73,140,28,-41,-81,123,-103,-20}, 00141 {74,140,28,-41,-82,124,-103,-20},{74,141,28,-42,-82,124,-104,-20},{74,141,28,-42,-82,125,-104,-20},{75,142,28,-42,-83,125,-105,-20}, 00142 {75,142,28,-42,-83,126,-105,-20},{75,143,28,-42,-83,126,-105,-20},{75,144,28,-42,-84,127,-106,-20},{76,144,29,-43,-84,127,-106,-20} 00143 }; 00144 00145 00155 int stk11xx_decompress(struct usb_stk11xx *dev) 00156 { 00157 int factor; 00158 00159 void *data; 00160 void *image; 00161 struct stk11xx_frame_buf *framebuf; 00162 00163 if (dev == NULL) 00164 return -EFAULT; 00165 00166 framebuf = dev->read_frame; 00167 00168 if (framebuf == NULL) 00169 return -EFAULT; 00170 00171 image = dev->image_data; 00172 image += dev->images[dev->fill_image].offset; 00173 00174 data = framebuf->data; 00175 00176 switch (dev->resolution) { 00177 case STK11XX_80x60: 00178 factor = 8; 00179 break; 00180 00181 case STK11XX_128x96: 00182 factor = 5; 00183 break; 00184 00185 case STK11XX_160x120: 00186 factor = 4; 00187 break; 00188 00189 case STK11XX_213x160: 00190 factor = 3; 00191 break; 00192 00193 case STK11XX_320x240: 00194 factor = 2; 00195 break; 00196 00197 case STK11XX_640x480: 00198 factor = 1; 00199 break; 00200 00201 case STK11XX_800x600: 00202 factor = 1; 00203 break; 00204 00205 case STK11XX_1024x768: 00206 factor = 1; 00207 break; 00208 00209 case STK11XX_1280x1024: 00210 factor = 1; 00211 break; 00212 00213 default: 00214 return -EFAULT; 00215 } 00216 00217 00218 switch (dev->vsettings.palette) { 00219 case STK11XX_PALETTE_RGB24: 00220 stk11xx_b2rgb24(data, image, &dev->image, &dev->view, 00221 dev->vsettings.hflip, dev->vsettings.vflip, factor); 00222 break; 00223 00224 case STK11XX_PALETTE_RGB32: 00225 stk11xx_b2rgb32(data, image, &dev->image, &dev->view, 00226 dev->vsettings.hflip, dev->vsettings.vflip, factor); 00227 break; 00228 00229 case STK11XX_PALETTE_BGR24: 00230 stk11xx_b2bgr24(data, image, &dev->image, &dev->view, 00231 dev->vsettings.hflip, dev->vsettings.vflip, factor); 00232 break; 00233 00234 case STK11XX_PALETTE_BGR32: 00235 stk11xx_b2bgr32(data, image, &dev->image, &dev->view, 00236 dev->vsettings.hflip, dev->vsettings.vflip, factor); 00237 break; 00238 00239 case STK11XX_PALETTE_UYVY: 00240 stk11xx_b2uyvy(data, image, &dev->image, &dev->view, 00241 dev->vsettings.hflip, dev->vsettings.vflip, factor); 00242 break; 00243 00244 case STK11XX_PALETTE_YUYV: 00245 stk11xx_b2yuyv(data, image, &dev->image, &dev->view, 00246 dev->vsettings.hflip, dev->vsettings.vflip, factor); 00247 break; 00248 } 00249 00250 stk11xx_correct_brightness(image, dev->view.x, dev->view.y, 00251 dev->vsettings.brightness, dev->vsettings.palette, dev->vsettings.depth); 00252 00253 return 0; 00254 } 00255 00256 00270 void stk11xx_correct_brightness(uint8_t *img, const int width, const int height, 00271 const int brightness, int palette, int depth) 00272 { 00273 int i; 00274 int x; 00275 00276 00277 switch (palette) { 00278 case STK11XX_PALETTE_RGB24: 00279 case STK11XX_PALETTE_BGR24: 00280 case STK11XX_PALETTE_RGB32: 00281 case STK11XX_PALETTE_BGR32: 00282 depth = (depth == 24) ? 3 : 4; 00283 00284 if (brightness >= 32767) { 00285 x = (brightness - 32767) / 256; 00286 00287 for (i = 0; i < (width * height * depth); i++) { 00288 if ((*(img + i) + (unsigned char) x) > 255) 00289 *(img + i) = 255; 00290 else 00291 *(img + i) += (unsigned char) x; 00292 } 00293 } 00294 else { 00295 x = (32767 - brightness) / 256; 00296 00297 for (i = 0; i < (width * height * depth); i++) { 00298 if ((unsigned char) x > *(img + i)) 00299 *(img + i) = 0; 00300 else 00301 *(img + i) -= (unsigned char) x; 00302 } 00303 } 00304 00305 break; 00306 00307 case STK11XX_PALETTE_UYVY: 00308 depth = 2; 00309 00310 if (brightness >= 32767) { 00311 x = (brightness - 32767) / 256; 00312 00313 for (i = 1; i < (width * height * depth); i=i+depth) { 00314 if ((*(img + i) + (unsigned char) x) > 255) 00315 *(img + i) = 255; 00316 else 00317 *(img + i) += (unsigned char) x; 00318 } 00319 } 00320 else { 00321 x = (32767 - brightness) / 256; 00322 00323 for (i = 1; i < (width * height * depth); i=i+depth) { 00324 if ((unsigned char) x > *(img + i)) 00325 *(img + i) = 0; 00326 else 00327 *(img + i) -= (unsigned char) x; 00328 } 00329 } 00330 00331 break; 00332 00333 case STK11XX_PALETTE_YUYV: 00334 depth = 2; 00335 00336 if (brightness >= 32767) { 00337 x = (brightness - 32767) / 256; 00338 00339 for (i = 0; i < (width * height * depth); i=i+depth) { 00340 if ((*(img + i) + (unsigned char) x) > 255) 00341 *(img + i) = 255; 00342 else 00343 *(img + i) += (unsigned char) x; 00344 } 00345 } 00346 else { 00347 x = (32767 - brightness) / 256; 00348 00349 for (i = 0; i < (width * height * depth); i=i+depth) { 00350 if ((unsigned char) x > *(img + i)) 00351 *(img + i) = 0; 00352 else 00353 *(img + i) -= (unsigned char) x; 00354 } 00355 } 00356 00357 break; 00358 } 00359 } 00360 00361 00374 void stk11xx_b2rgb24(uint8_t *bayer, uint8_t *rgb, 00375 struct stk11xx_coord *image, 00376 struct stk11xx_coord *view, 00377 const int hflip, const int vflip, 00378 const int factor) { 00379 uint8_t *b; 00380 00381 int x, y; // Position in bayer image 00382 int i, j; // Position in rgb image 00383 00384 int width = image->x; 00385 int height = image->y; 00386 00387 int nwidth = width / factor; 00388 int nheight = height / factor; 00389 00390 int offset; 00391 int startx, stepx; 00392 int starty, stepy; 00393 00394 00395 // Calculate the initial position (on Y axis) 00396 if (vflip) { 00397 starty = height - 2; 00398 stepy = -factor; 00399 } 00400 else { 00401 starty = 0; 00402 stepy = factor; 00403 } 00404 00405 // Calculate the initial position (on X axis) 00406 if (hflip) { 00407 startx = width - 1; 00408 stepx = -factor; 00409 offset = width - 2; 00410 } 00411 else { 00412 startx = 0; 00413 stepx = factor; 00414 offset = 1; 00415 } 00416 00417 00418 // Skip the first line 00419 bayer += width; 00420 00421 // To center vertically the image in the view 00422 rgb += ((view->y - nheight) / 2) * view->x * 3; 00423 00424 // To center horizontally the image in the view 00425 rgb += ((view->x - nwidth) / 2) * 3; 00426 00427 // Clean the first line 00428 memset(rgb, 0, nwidth * 3); 00429 rgb += nwidth * 3; 00430 00431 00432 // For each rgb line without the borders (first and last line) 00433 for (j=0, y=starty; j<nheight-2; j++, y=y+stepy) { 00434 // Go to the start of line 00435 b = bayer + y * width + offset; 00436 00437 // Offset to center horizontally the image in the view 00438 rgb += (view->x - nwidth) * 3; 00439 00440 if (y & 0x1) { 00441 // Skip the first pixel 00442 *rgb++ = 0; 00443 *rgb++ = 0; 00444 *rgb++ = 0; 00445 00446 // GBGBGB : Line process... 00447 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 00448 if (x & 0x1) { 00449 *rgb++ = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 00450 *rgb++ = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 00451 *rgb++ = *b; 00452 } 00453 else { 00454 *rgb++ = (*(b-width) + *(b+width)) >> 1; 00455 *rgb++ = *b; 00456 *rgb++ = (*(b-1) + *(b+1)) >> 1; 00457 } 00458 00459 b += stepx; 00460 } 00461 00462 // Skip the last pixel 00463 *rgb++ = 0; 00464 *rgb++ = 0; 00465 *rgb++ = 0; 00466 } 00467 else { 00468 // Skip the first pixel 00469 *rgb++ = 0; 00470 *rgb++ = 0; 00471 *rgb++ = 0; 00472 00473 // RGRGRG : Line process... 00474 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 00475 if (x & 0x1) { 00476 *rgb++ = (*(b-1) + *(b+1)) >> 1; 00477 *rgb++ = *b; 00478 *rgb++ = (*(b-width) + *(b+width)) >> 1; 00479 } 00480 else { 00481 *rgb++ = *b; 00482 *rgb++ = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 00483 *rgb++ = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 00484 } 00485 00486 b += stepx; 00487 } 00488 00489 // Skip the last pixel 00490 *rgb++ = 0; 00491 *rgb++ = 0; 00492 *rgb++ = 0; 00493 } 00494 } 00495 00496 // Clean the last line 00497 memset(rgb, 0, nwidth * 3); 00498 } 00499 00500 00513 void stk11xx_b2rgb32(uint8_t *bayer, uint8_t *rgb, 00514 struct stk11xx_coord *image, 00515 struct stk11xx_coord *view, 00516 const int hflip, const int vflip, 00517 const int factor) { 00518 uint8_t *b; 00519 00520 int x, y; // Position in bayer image 00521 int i, j; // Position in rgb image 00522 00523 int width = image->x; 00524 int height = image->y; 00525 00526 int nwidth = width / factor; 00527 int nheight = height / factor; 00528 00529 int offset; 00530 int startx, stepx; 00531 int starty, stepy; 00532 00533 00534 // Calculate the initial position (on Y axis) 00535 if (vflip) { 00536 starty = height - 2; 00537 stepy = -factor; 00538 } 00539 else { 00540 starty = 0; 00541 stepy = factor; 00542 } 00543 00544 // Calculate the initial position (on X axis) 00545 if (hflip) { 00546 startx = width - 1; 00547 stepx = -factor; 00548 offset = width - 2; 00549 } 00550 else { 00551 startx = 0; 00552 stepx = factor; 00553 offset = 1; 00554 } 00555 00556 00557 // Skip the first line 00558 bayer += width; 00559 00560 // To center vertically the image in the view 00561 rgb += ((view->y - nheight) / 2) * view->x * 4; 00562 00563 // To center horizontally the image in the view 00564 rgb += ((view->x - nwidth) / 2) * 4; 00565 00566 // Clean the first line 00567 memset(rgb, 0, nwidth * 4); 00568 rgb += nwidth * 4; 00569 00570 00571 // For each rgb line without the borders (first and last line) 00572 for (j=0, y=starty; j<nheight-2; j++, y=y+stepy) { 00573 // Go to the start of line 00574 b = bayer + y * width + offset; 00575 00576 // Offset to center horizontally the image in the view 00577 rgb += (view->x - nwidth) * 4; 00578 00579 if (y & 0x1) { 00580 // Skip the first pixel 00581 *rgb++ = 0; 00582 *rgb++ = 0; 00583 *rgb++ = 0; 00584 *rgb++ = 0; 00585 00586 // GBGBGB : Line process... 00587 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 00588 if (x & 0x1) { 00589 *rgb++ = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 00590 *rgb++ = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 00591 *rgb++ = *b; 00592 *rgb++ = 0; 00593 } 00594 else { 00595 *rgb++ = (*(b-width) + *(b+width)) >> 1; 00596 *rgb++ = *b; 00597 *rgb++ = (*(b-1) + *(b+1)) >> 1; 00598 *rgb++ = 0; 00599 } 00600 00601 b += stepx; 00602 } 00603 00604 // Skip the last pixel 00605 *rgb++ = 0; 00606 *rgb++ = 0; 00607 *rgb++ = 0; 00608 *rgb++ = 0; 00609 } 00610 else { 00611 // Skip the first pixel 00612 *rgb++ = 0; 00613 *rgb++ = 0; 00614 *rgb++ = 0; 00615 *rgb++ = 0; 00616 00617 // RGRGRG : Line process... 00618 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 00619 if (x & 0x1) { 00620 *rgb++ = (*(b-1) + *(b+1)) >> 1; 00621 *rgb++ = *b; 00622 *rgb++ = (*(b-width) + *(b+width)) >> 1; 00623 *rgb++ = 0; 00624 } 00625 else { 00626 *rgb++ = *b; 00627 *rgb++ = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 00628 *rgb++ = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 00629 *rgb++ = 0; 00630 } 00631 00632 b += stepx; 00633 } 00634 00635 // Skip the last pixel 00636 *rgb++ = 0; 00637 *rgb++ = 0; 00638 *rgb++ = 0; 00639 *rgb++ = 0; 00640 } 00641 } 00642 00643 // Clean the last line 00644 memset(rgb, 0, nwidth * 4); 00645 } 00646 00647 00660 void stk11xx_b2bgr24(uint8_t *bayer, uint8_t *bgr, 00661 struct stk11xx_coord *image, 00662 struct stk11xx_coord *view, 00663 const int hflip, const int vflip, 00664 const int factor) { 00665 uint8_t *b; 00666 00667 int x, y; // Position in bayer image 00668 int i, j; // Position in bgr image 00669 00670 int width = image->x; 00671 int height = image->y; 00672 00673 int nwidth = width / factor; 00674 int nheight = height / factor; 00675 00676 int offset; 00677 int startx, stepx; 00678 int starty, stepy; 00679 00680 00681 // Calculate the initial position (on Y axis) 00682 if (vflip) { 00683 starty = height - 2; 00684 stepy = -factor; 00685 } 00686 else { 00687 starty = 0; 00688 stepy = factor; 00689 } 00690 00691 // Calculate the initial position (on X axis) 00692 if (hflip) { 00693 startx = width - 1; 00694 stepx = -factor; 00695 offset = width - 2; 00696 } 00697 else { 00698 startx = 0; 00699 stepx = factor; 00700 offset = 1; 00701 } 00702 00703 00704 // Skip the first line 00705 bayer += width; 00706 00707 // To center vertically the image in the view 00708 bgr += ((view->y - nheight) / 2) * view->x * 3; 00709 00710 // To center horizontally the image in the view 00711 bgr += ((view->x - nwidth) / 2) * 3; 00712 00713 // Clean the first line 00714 memset(bgr, 0, nwidth * 3); 00715 bgr += nwidth * 3; 00716 00717 00718 // For each bgr line without the borders (first and last line) 00719 for (j=0, y=starty; j<nheight-2; j++, y=y+stepy) { 00720 // Go to the start of line 00721 b = bayer + y * width + offset; 00722 00723 // Offset to center horizontally the image in the view 00724 bgr += (view->x - nwidth) * 3; 00725 00726 if (y & 0x1) { 00727 // Skip the first pixel 00728 *bgr++ = 0; 00729 *bgr++ = 0; 00730 *bgr++ = 0; 00731 00732 // GBGBGB : Line process... 00733 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 00734 if (x & 0x1) { 00735 *bgr++ = *b; 00736 *bgr++ = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 00737 *bgr++ = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 00738 } 00739 else { 00740 *bgr++ = (*(b-1) + *(b+1)) >> 1; 00741 *bgr++ = *b; 00742 *bgr++ = (*(b-width) + *(b+width)) >> 1; 00743 } 00744 00745 b += stepx; 00746 } 00747 00748 // Skip the last pixel 00749 *bgr++ = 0; 00750 *bgr++ = 0; 00751 *bgr++ = 0; 00752 } 00753 else { 00754 // Skip the first pixel 00755 *bgr++ = 0; 00756 *bgr++ = 0; 00757 *bgr++ = 0; 00758 00759 // RGRGRG : Line process... 00760 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 00761 if (x & 0x1) { 00762 *bgr++ = (*(b-width) + *(b+width)) >> 1; 00763 *bgr++ = *b; 00764 *bgr++ = (*(b-1) + *(b+1)) >> 1; 00765 } 00766 else { 00767 *bgr++ = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 00768 *bgr++ = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 00769 *bgr++ = *b; 00770 } 00771 00772 b += stepx; 00773 } 00774 00775 // Skip the last pixel 00776 *bgr++ = 0; 00777 *bgr++ = 0; 00778 *bgr++ = 0; 00779 } 00780 } 00781 00782 // Clean the last line 00783 memset(bgr, 0, nwidth * 3); 00784 } 00785 00786 00799 void stk11xx_b2bgr32(uint8_t *bayer, uint8_t *bgr, 00800 struct stk11xx_coord *image, 00801 struct stk11xx_coord *view, 00802 const int hflip, const int vflip, 00803 const int factor) { 00804 uint8_t *b; 00805 00806 int x, y; // Position in bayer image 00807 int i, j; // Position in bgr image 00808 00809 int width = image->x; 00810 int height = image->y; 00811 00812 int nwidth = width / factor; 00813 int nheight = height / factor; 00814 00815 int offset; 00816 int startx, stepx; 00817 int starty, stepy; 00818 00819 00820 // Calculate the initial position (on Y axis) 00821 if (vflip) { 00822 starty = height - 2; 00823 stepy = -factor; 00824 } 00825 else { 00826 starty = 0; 00827 stepy = factor; 00828 } 00829 00830 // Calculate the initial position (on X axis) 00831 if (hflip) { 00832 startx = width - 1; 00833 stepx = -factor; 00834 offset = width - 2; 00835 } 00836 else { 00837 startx = 0; 00838 stepx = factor; 00839 offset = 1; 00840 } 00841 00842 00843 // Skip the first line 00844 bayer += width; 00845 00846 // To center vertically the image in the view 00847 bgr += ((view->y - nheight) / 2) * view->x * 4; 00848 00849 // To center horizontally the image in the view 00850 bgr += ((view->x - nwidth) / 2) * 4; 00851 00852 // Clean the first line 00853 memset(bgr, 0, nwidth * 4); 00854 bgr += nwidth * 4; 00855 00856 00857 // For each bgr line without the borders (first and last line) 00858 for (j=0, y=starty; j<nheight-2; j++, y=y+stepy) { 00859 // Go to the start of line 00860 b = bayer + y * width + offset; 00861 00862 // Offset to center horizontally the image in the view 00863 bgr += (view->x - nwidth) * 4; 00864 00865 if (y & 0x1) { 00866 // Skip the first pixel 00867 *bgr++ = 0; 00868 *bgr++ = 0; 00869 *bgr++ = 0; 00870 *bgr++ = 0; 00871 00872 // GBGBGB : Line process... 00873 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 00874 if (x & 0x1) { 00875 *bgr++ = *b; 00876 *bgr++ = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 00877 *bgr++ = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 00878 *bgr++ = 0; 00879 } 00880 else { 00881 *bgr++ = (*(b-1) + *(b+1)) >> 1; 00882 *bgr++ = *b; 00883 *bgr++ = (*(b-width) + *(b+width)) >> 1; 00884 *bgr++ = 0; 00885 } 00886 00887 b += stepx; 00888 } 00889 00890 // Skip the last pixel 00891 *bgr++ = 0; 00892 *bgr++ = 0; 00893 *bgr++ = 0; 00894 *bgr++ = 0; 00895 } 00896 else { 00897 // Skip the first pixel 00898 *bgr++ = 0; 00899 *bgr++ = 0; 00900 *bgr++ = 0; 00901 *bgr++ = 0; 00902 00903 // RGRGRG : Line process... 00904 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 00905 if (x & 0x1) { 00906 *bgr++ = (*(b-width) + *(b+width)) >> 1; 00907 *bgr++ = *b; 00908 *bgr++ = (*(b-1) + *(b+1)) >> 1; 00909 *bgr++ = 0; 00910 } 00911 else { 00912 *bgr++ = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 00913 *bgr++ = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 00914 *bgr++ = *b; 00915 *bgr++ = 0; 00916 } 00917 00918 b += stepx; 00919 } 00920 00921 // Skip the last pixel 00922 *bgr++ = 0; 00923 *bgr++ = 0; 00924 *bgr++ = 0; 00925 *bgr++ = 0; 00926 } 00927 } 00928 00929 // Clean the last line 00930 memset(bgr, 0, nwidth * 4); 00931 } 00932 00933 00946 void stk11xx_b2uyvy(uint8_t *bayer, uint8_t *yuv, 00947 struct stk11xx_coord *image, 00948 struct stk11xx_coord *view, 00949 const int hflip, const int vflip, 00950 const int factor) { 00951 uint8_t *b; 00952 00953 int x, y; // Position in bayer image 00954 int i, j; // Position in yuv image 00955 00956 int pR, pG, pB; 00957 int pY, pU, pV; 00958 00959 int width = image->x; 00960 int height = image->y; 00961 00962 int nwidth = width / factor; 00963 int nheight = height / factor; 00964 00965 int offset; 00966 int startx, stepx; 00967 int starty, stepy; 00968 00969 00970 // Calculate the initial position (on Y axis) 00971 if (vflip) { 00972 starty = height - 2; 00973 stepy = -factor; 00974 } 00975 else { 00976 starty = 0; 00977 stepy = factor; 00978 } 00979 00980 // Calculate the initial position (on X axis) 00981 if (hflip) { 00982 startx = width - 1; 00983 stepx = -factor; 00984 offset = width - 2; 00985 } 00986 else { 00987 startx = 0; 00988 stepx = factor; 00989 offset = 1; 00990 } 00991 00992 // Background color... 00993 memset(yuv, 16, width * 2); 00994 for (i=0; i<width*2; i=i+2, *(yuv+i)=128); 00995 for (i=1; i<height; i++) 00996 memcpy(yuv+i*width*2, yuv, width*2); 00997 00998 // Skip the first line 00999 bayer += width; 01000 01001 // To center vertically the image in the view 01002 yuv += ((view->y - nheight) / 2) * view->x * 2; 01003 01004 // To center horizontally the image in the view 01005 yuv += ((view->x - nwidth) / 2) * 2; 01006 01007 // Clean the first line 01008 memset(yuv, 16, nwidth * 2); 01009 for (i=0; i<nwidth*2; i=i+2, *(yuv+i)=128); 01010 yuv += nwidth * 2; 01011 01012 01013 // For each yuv line without the borders (first and last line) 01014 for (j=0, y=starty; j<nheight-2; j++, y=y+stepy) { 01015 // Go to the start of line 01016 b = bayer + y * width + offset; 01017 01018 // Offset to center horizontally the image in the view 01019 yuv += (view->x - nwidth) * 2; 01020 01021 if (y & 0x1) { 01022 // Skip the first pixel 01023 *yuv++ = 128; 01024 *yuv++ = 16; 01025 01026 // GBGBGB : Line process... 01027 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 01028 if (x & 0x1) { 01029 pR = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 01030 pG = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 01031 pB = *b; 01032 } 01033 else { 01034 pR = (*(b-width) + *(b+width)) >> 1; 01035 pG = *b; 01036 pB = (*(b-1) + *(b+1)) >> 1; 01037 } 01038 01039 pY = stk11xx_yuv_interp[pR][0] + stk11xx_yuv_interp[pG][1] + stk11xx_yuv_interp[pB][2]; 01040 pU = stk11xx_yuv_interp[pR][3] + stk11xx_yuv_interp[pG][4] + stk11xx_yuv_interp[pB][5]; 01041 pV = stk11xx_yuv_interp[pR][5] + stk11xx_yuv_interp[pG][6] + stk11xx_yuv_interp[pB][7]; 01042 01043 pY = CLIP(pY, 0,255); 01044 pU = CLIP(pU, -127,127); 01045 pV = CLIP(pV, -127,127); 01046 01047 if (i % 2){ 01048 *yuv++ = (112 * pU)/127 + 128; // U 01049 *yuv++ = (219 * pY)/255 + 16; // Y 01050 } 01051 else { 01052 *yuv++ = (112 * pV)/127 + 128; // V 01053 *yuv++ = (219 * pY)/255 + 16; // Y 01054 } 01055 01056 b += stepx; 01057 } 01058 01059 // Skip the last pixel 01060 *yuv++ = 128; 01061 *yuv++ = 16; 01062 } 01063 else { 01064 // Skip the first pixel 01065 *yuv++ = 128; 01066 *yuv++ = 16; 01067 01068 // RGRGRG : Line process... 01069 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 01070 if (x & 0x1) { 01071 pR = (*(b-1) + *(b+1)) >> 1; 01072 pG = *b; 01073 pB = (*(b-width) + *(b+width)) >> 1; 01074 } 01075 else { 01076 pR = *b; 01077 pG = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 01078 pB = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 01079 } 01080 01081 pY = stk11xx_yuv_interp[pR][0] + stk11xx_yuv_interp[pG][1] + stk11xx_yuv_interp[pB][2]; 01082 pU = stk11xx_yuv_interp[pR][3] + stk11xx_yuv_interp[pG][4] + stk11xx_yuv_interp[pB][5]; 01083 pV = stk11xx_yuv_interp[pR][5] + stk11xx_yuv_interp[pG][6] + stk11xx_yuv_interp[pB][7]; 01084 01085 pY = CLIP(pY, 0,255); 01086 pU = CLIP(pU, -127,127); 01087 pV = CLIP(pV, -127,127); 01088 01089 if (i % 2){ 01090 *yuv++ = (112 * pU)/127 + 128; // U 01091 *yuv++ = (219 * pY)/255 + 16; // Y 01092 } 01093 else { 01094 *yuv++ = (112 * pV)/127 + 128; // V 01095 *yuv++ = (219 * pY)/255 + 16; // Y 01096 } 01097 01098 b += stepx; 01099 } 01100 01101 // Skip the last pixel 01102 *yuv++ = 128; 01103 *yuv++ = 16; 01104 } 01105 } 01106 01107 // Clean the last line 01108 memset(yuv, 16, nwidth * 2); 01109 for (i=0; i<nwidth*2; i=i+2, *(yuv+i)=128); 01110 } 01111 01112 01125 void stk11xx_b2yuyv(uint8_t *bayer, uint8_t *yuv, 01126 struct stk11xx_coord *image, 01127 struct stk11xx_coord *view, 01128 const int hflip, const int vflip, 01129 const int factor) { 01130 uint8_t *b; 01131 01132 int x, y; // Position in bayer image 01133 int i, j; // Position in yuv image 01134 01135 int pR, pG, pB; 01136 int pY, pU, pV; 01137 01138 int width = image->x; 01139 int height = image->y; 01140 01141 int nwidth = width / factor; 01142 int nheight = height / factor; 01143 01144 int offset; 01145 int startx, stepx; 01146 int starty, stepy; 01147 01148 01149 // Calculate the initial position (on Y axis) 01150 if (vflip) { 01151 starty = height - 2; 01152 stepy = -factor; 01153 } 01154 else { 01155 starty = 0; 01156 stepy = factor; 01157 } 01158 01159 // Calculate the initial position (on X axis) 01160 if (hflip) { 01161 startx = width - 1; 01162 stepx = -factor; 01163 offset = width - 2; 01164 } 01165 else { 01166 startx = 0; 01167 stepx = factor; 01168 offset = 1; 01169 } 01170 01171 // Background color... 01172 memset(yuv, 128, width * 2); 01173 for (i=0; i<width*2; i=i+2, *(yuv+i)=16); 01174 for (i=1; i<height; i++) 01175 memcpy(yuv+i*width*2, yuv, width*2); 01176 01177 // Skip the first line 01178 bayer += width; 01179 01180 // To center vertically the image in the view 01181 yuv += ((view->y - nheight) / 2) * view->x * 2; 01182 01183 // To center horizontally the image in the view 01184 yuv += ((view->x - nwidth) / 2) * 2; 01185 01186 // Clean the first line 01187 memset(yuv, 128, nwidth * 2); 01188 for (i=0; i<nwidth*2; i=i+2, *(yuv+i)=16); 01189 yuv += nwidth * 2; 01190 01191 01192 // For each yuv line without the borders (first and last line) 01193 for (j=0, y=starty; j<nheight-2; j++, y=y+stepy) { 01194 // Go to the start of line 01195 b = bayer + y * width + offset; 01196 01197 // Offset to center horizontally the image in the view 01198 yuv += (view->x - nwidth) * 2; 01199 01200 if (y & 0x1) { 01201 // Skip the first pixel 01202 *yuv++ = 16; 01203 *yuv++ = 128; 01204 01205 // GBGBGB : Line process... 01206 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 01207 if (x & 0x1) { 01208 pR = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 01209 pG = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 01210 pB = *b; 01211 } 01212 else { 01213 pR = (*(b-width) + *(b+width)) >> 1; 01214 pG = *b; 01215 pB = (*(b-1) + *(b+1)) >> 1; 01216 } 01217 01218 pY = stk11xx_yuv_interp[pR][0] + stk11xx_yuv_interp[pG][1] + stk11xx_yuv_interp[pB][2]; 01219 pU = stk11xx_yuv_interp[pR][3] + stk11xx_yuv_interp[pG][4] + stk11xx_yuv_interp[pB][5]; 01220 pV = stk11xx_yuv_interp[pR][5] + stk11xx_yuv_interp[pG][6] + stk11xx_yuv_interp[pB][7]; 01221 01222 pY = CLIP(pY, 0,255); 01223 pU = CLIP(pU, -127,127); 01224 pV = CLIP(pV, -127,127); 01225 01226 if (i % 2){ 01227 *yuv++ = (219 * pY)/255 + 16; // Y 01228 *yuv++ = (112 * pU)/127 + 128; // U 01229 } 01230 else { 01231 *yuv++ = (219 * pY)/255 + 16; // Y 01232 *yuv++ = (112 * pV)/127 + 128; // V 01233 } 01234 01235 b += stepx; 01236 } 01237 01238 // Skip the last pixel 01239 *yuv++ = 16; 01240 *yuv++ = 128; 01241 } 01242 else { 01243 // Skip the first pixel 01244 *yuv++ = 16; 01245 *yuv++ = 128; 01246 01247 // RGRGRG : Line process... 01248 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 01249 if (x & 0x1) { 01250 pR = (*(b-1) + *(b+1)) >> 1; 01251 pG = *b; 01252 pB = (*(b-width) + *(b+width)) >> 1; 01253 } 01254 else { 01255 pR = *b; 01256 pG = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 01257 pB = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 01258 } 01259 01260 pY = stk11xx_yuv_interp[pR][0] + stk11xx_yuv_interp[pG][1] + stk11xx_yuv_interp[pB][2]; 01261 pU = stk11xx_yuv_interp[pR][3] + stk11xx_yuv_interp[pG][4] + stk11xx_yuv_interp[pB][5]; 01262 pV = stk11xx_yuv_interp[pR][5] + stk11xx_yuv_interp[pG][6] + stk11xx_yuv_interp[pB][7]; 01263 01264 pY = CLIP(pY, 0,255); 01265 pU = CLIP(pU, -127,127); 01266 pV = CLIP(pV, -127,127); 01267 01268 if (i % 2){ 01269 *yuv++ = (219 * pY)/255 + 16; // Y 01270 *yuv++ = (112 * pU)/127 + 128; // U 01271 } 01272 else { 01273 *yuv++ = (219 * pY)/255 + 16; // Y 01274 *yuv++ = (112 * pV)/127 + 128; // V 01275 } 01276 01277 b += stepx; 01278 } 01279 01280 // Skip the last pixel 01281 *yuv++ = 16; 01282 *yuv++ = 128; 01283 } 01284 } 01285 01286 // Clean the last line 01287 memset(yuv, 128, nwidth * 2); 01288 for (i=0; i<nwidth*2; i=i+2, *(yuv+i)=16); 01289 } 01290 01291