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_720x576: 00202 case STK11XX_800x600: 00203 factor = 2; 00204 break; 00205 00206 case STK11XX_1024x768: 00207 factor = 2; 00208 break; 00209 00210 case STK11XX_1280x1024: 00211 factor = 1; 00212 break; 00213 00214 default: 00215 return -EFAULT; 00216 } 00217 00218 00219 switch (dev->vsettings.palette) { 00220 case STK11XX_PALETTE_RGB24: 00221 stk11xx_b2rgb24(data, image, &dev->image, &dev->view, 00222 dev->vsettings.hflip, dev->vsettings.vflip, factor); 00223 break; 00224 00225 case STK11XX_PALETTE_RGB32: 00226 stk11xx_b2rgb32(data, image, &dev->image, &dev->view, 00227 dev->vsettings.hflip, dev->vsettings.vflip, factor); 00228 break; 00229 00230 case STK11XX_PALETTE_BGR24: 00231 stk11xx_b2bgr24(data, image, &dev->image, &dev->view, 00232 dev->vsettings.hflip, dev->vsettings.vflip, factor); 00233 break; 00234 00235 case STK11XX_PALETTE_BGR32: 00236 stk11xx_b2bgr32(data, image, &dev->image, &dev->view, 00237 dev->vsettings.hflip, dev->vsettings.vflip, factor); 00238 break; 00239 00240 case STK11XX_PALETTE_UYVY: 00241 stk11xx_b2uyvy(data, image, &dev->image, &dev->view, 00242 dev->vsettings.hflip, dev->vsettings.vflip, factor); 00243 break; 00244 00245 case STK11XX_PALETTE_YUYV: 00246 stk11xx_b2yuyv(data, image, &dev->image, &dev->view, 00247 dev->vsettings.hflip, dev->vsettings.vflip, factor); 00248 break; 00249 } 00250 00251 stk11xx_correct_brightness(image, dev->view.x, dev->view.y, 00252 dev->vsettings.brightness, dev->vsettings.palette, dev->vsettings.depth); 00253 00254 return 0; 00255 } 00256 00257 00271 void stk11xx_correct_brightness(uint8_t *img, const int width, const int height, 00272 const int brightness, int palette, int depth) 00273 { 00274 int i; 00275 int x; 00276 00277 00278 switch (palette) { 00279 case STK11XX_PALETTE_RGB24: 00280 case STK11XX_PALETTE_BGR24: 00281 case STK11XX_PALETTE_RGB32: 00282 case STK11XX_PALETTE_BGR32: 00283 depth = (depth == 24) ? 3 : 4; 00284 00285 if (brightness >= 32767) { 00286 x = (brightness - 32767) / 256; 00287 00288 for (i = 0; i < (width * height * depth); i++) { 00289 if ((*(img + i) + (unsigned char) x) > 255) 00290 *(img + i) = 255; 00291 else 00292 *(img + i) += (unsigned char) x; 00293 } 00294 } 00295 else { 00296 x = (32767 - brightness) / 256; 00297 00298 for (i = 0; i < (width * height * depth); i++) { 00299 if ((unsigned char) x > *(img + i)) 00300 *(img + i) = 0; 00301 else 00302 *(img + i) -= (unsigned char) x; 00303 } 00304 } 00305 00306 break; 00307 00308 case STK11XX_PALETTE_UYVY: 00309 depth = 2; 00310 00311 if (brightness >= 32767) { 00312 x = (brightness - 32767) / 256; 00313 00314 for (i = 1; i < (width * height * depth); i=i+depth) { 00315 if ((*(img + i) + (unsigned char) x) > 255) 00316 *(img + i) = 255; 00317 else 00318 *(img + i) += (unsigned char) x; 00319 } 00320 } 00321 else { 00322 x = (32767 - brightness) / 256; 00323 00324 for (i = 1; i < (width * height * depth); i=i+depth) { 00325 if ((unsigned char) x > *(img + i)) 00326 *(img + i) = 0; 00327 else 00328 *(img + i) -= (unsigned char) x; 00329 } 00330 } 00331 00332 break; 00333 00334 case STK11XX_PALETTE_YUYV: 00335 depth = 2; 00336 00337 if (brightness >= 32767) { 00338 x = (brightness - 32767) / 256; 00339 00340 for (i = 0; i < (width * height * depth); i=i+depth) { 00341 if ((*(img + i) + (unsigned char) x) > 255) 00342 *(img + i) = 255; 00343 else 00344 *(img + i) += (unsigned char) x; 00345 } 00346 } 00347 else { 00348 x = (32767 - brightness) / 256; 00349 00350 for (i = 0; i < (width * height * depth); i=i+depth) { 00351 if ((unsigned char) x > *(img + i)) 00352 *(img + i) = 0; 00353 else 00354 *(img + i) -= (unsigned char) x; 00355 } 00356 } 00357 00358 break; 00359 } 00360 } 00361 00362 00375 void stk11xx_b2rgb24(uint8_t *bayer, uint8_t *rgb, 00376 struct stk11xx_coord *image, 00377 struct stk11xx_coord *view, 00378 const int hflip, const int vflip, 00379 const int factor) { 00380 uint8_t *b; 00381 00382 int x, y; // Position in bayer image 00383 int i, j; // Position in rgb image 00384 00385 int width = image->x; 00386 int height = image->y; 00387 00388 int nwidth = width / factor; 00389 int nheight = height / factor; 00390 00391 int offset; 00392 int startx, stepx; 00393 int starty, stepy; 00394 00395 00396 // Calculate the initial position (on Y axis) 00397 if (vflip) { 00398 starty = height - 2; 00399 stepy = -factor; 00400 } 00401 else { 00402 starty = 0; 00403 stepy = factor; 00404 } 00405 00406 // Calculate the initial position (on X axis) 00407 if (hflip) { 00408 startx = width - 1; 00409 stepx = -factor; 00410 offset = width - 2; 00411 } 00412 else { 00413 startx = 0; 00414 stepx = factor; 00415 offset = 1; 00416 } 00417 00418 00419 // Skip the first line 00420 bayer += width; 00421 00422 // To center vertically the image in the view 00423 rgb += ((view->y - nheight) / 2) * view->x * 3; 00424 00425 // To center horizontally the image in the view 00426 rgb += ((view->x - nwidth) / 2) * 3; 00427 00428 // Clean the first line 00429 memset(rgb, 0, nwidth * 3); 00430 rgb += nwidth * 3; 00431 00432 00433 // For each rgb line without the borders (first and last line) 00434 for (j=0, y=starty; j<nheight-2; j++, y=y+stepy) { 00435 // Go to the start of line 00436 b = bayer + y * width + offset; 00437 00438 // Offset to center horizontally the image in the view 00439 rgb += (view->x - nwidth) * 3; 00440 00441 if (y & 0x1) { 00442 // Skip the first pixel 00443 *rgb++ = 0; 00444 *rgb++ = 0; 00445 *rgb++ = 0; 00446 00447 // GBGBGB : Line process... 00448 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 00449 if (x & 0x1) { 00450 *rgb++ = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 00451 *rgb++ = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 00452 *rgb++ = *b; 00453 } 00454 else { 00455 *rgb++ = (*(b-width) + *(b+width)) >> 1; 00456 *rgb++ = *b; 00457 *rgb++ = (*(b-1) + *(b+1)) >> 1; 00458 } 00459 00460 b += stepx; 00461 } 00462 00463 // Skip the last pixel 00464 *rgb++ = 0; 00465 *rgb++ = 0; 00466 *rgb++ = 0; 00467 } 00468 else { 00469 // Skip the first pixel 00470 *rgb++ = 0; 00471 *rgb++ = 0; 00472 *rgb++ = 0; 00473 00474 // RGRGRG : Line process... 00475 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 00476 if (x & 0x1) { 00477 *rgb++ = (*(b-1) + *(b+1)) >> 1; 00478 *rgb++ = *b; 00479 *rgb++ = (*(b-width) + *(b+width)) >> 1; 00480 } 00481 else { 00482 *rgb++ = *b; 00483 *rgb++ = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 00484 *rgb++ = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 00485 } 00486 00487 b += stepx; 00488 } 00489 00490 // Skip the last pixel 00491 *rgb++ = 0; 00492 *rgb++ = 0; 00493 *rgb++ = 0; 00494 } 00495 } 00496 00497 // Clean the last line 00498 memset(rgb, 0, nwidth * 3); 00499 } 00500 00501 00514 void stk11xx_b2rgb32(uint8_t *bayer, uint8_t *rgb, 00515 struct stk11xx_coord *image, 00516 struct stk11xx_coord *view, 00517 const int hflip, const int vflip, 00518 const int factor) { 00519 uint8_t *b; 00520 00521 int x, y; // Position in bayer image 00522 int i, j; // Position in rgb image 00523 00524 int width = image->x; 00525 int height = image->y; 00526 00527 int nwidth = width / factor; 00528 int nheight = height / factor; 00529 00530 int offset; 00531 int startx, stepx; 00532 int starty, stepy; 00533 00534 00535 // Calculate the initial position (on Y axis) 00536 if (vflip) { 00537 starty = height - 2; 00538 stepy = -factor; 00539 } 00540 else { 00541 starty = 0; 00542 stepy = factor; 00543 } 00544 00545 // Calculate the initial position (on X axis) 00546 if (hflip) { 00547 startx = width - 1; 00548 stepx = -factor; 00549 offset = width - 2; 00550 } 00551 else { 00552 startx = 0; 00553 stepx = factor; 00554 offset = 1; 00555 } 00556 00557 00558 // Skip the first line 00559 bayer += width; 00560 00561 // To center vertically the image in the view 00562 rgb += ((view->y - nheight) / 2) * view->x * 4; 00563 00564 // To center horizontally the image in the view 00565 rgb += ((view->x - nwidth) / 2) * 4; 00566 00567 // Clean the first line 00568 memset(rgb, 0, nwidth * 4); 00569 rgb += nwidth * 4; 00570 00571 00572 // For each rgb line without the borders (first and last line) 00573 for (j=0, y=starty; j<nheight-2; j++, y=y+stepy) { 00574 // Go to the start of line 00575 b = bayer + y * width + offset; 00576 00577 // Offset to center horizontally the image in the view 00578 rgb += (view->x - nwidth) * 4; 00579 00580 if (y & 0x1) { 00581 // Skip the first pixel 00582 *rgb++ = 0; 00583 *rgb++ = 0; 00584 *rgb++ = 0; 00585 *rgb++ = 0; 00586 00587 // GBGBGB : Line process... 00588 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 00589 if (x & 0x1) { 00590 *rgb++ = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 00591 *rgb++ = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 00592 *rgb++ = *b; 00593 *rgb++ = 0; 00594 } 00595 else { 00596 *rgb++ = (*(b-width) + *(b+width)) >> 1; 00597 *rgb++ = *b; 00598 *rgb++ = (*(b-1) + *(b+1)) >> 1; 00599 *rgb++ = 0; 00600 } 00601 00602 b += stepx; 00603 } 00604 00605 // Skip the last pixel 00606 *rgb++ = 0; 00607 *rgb++ = 0; 00608 *rgb++ = 0; 00609 *rgb++ = 0; 00610 } 00611 else { 00612 // Skip the first pixel 00613 *rgb++ = 0; 00614 *rgb++ = 0; 00615 *rgb++ = 0; 00616 *rgb++ = 0; 00617 00618 // RGRGRG : Line process... 00619 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 00620 if (x & 0x1) { 00621 *rgb++ = (*(b-1) + *(b+1)) >> 1; 00622 *rgb++ = *b; 00623 *rgb++ = (*(b-width) + *(b+width)) >> 1; 00624 *rgb++ = 0; 00625 } 00626 else { 00627 *rgb++ = *b; 00628 *rgb++ = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 00629 *rgb++ = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 00630 *rgb++ = 0; 00631 } 00632 00633 b += stepx; 00634 } 00635 00636 // Skip the last pixel 00637 *rgb++ = 0; 00638 *rgb++ = 0; 00639 *rgb++ = 0; 00640 *rgb++ = 0; 00641 } 00642 } 00643 00644 // Clean the last line 00645 memset(rgb, 0, nwidth * 4); 00646 } 00647 00648 00661 void stk11xx_b2bgr24(uint8_t *bayer, uint8_t *bgr, 00662 struct stk11xx_coord *image, 00663 struct stk11xx_coord *view, 00664 const int hflip, const int vflip, 00665 const int factor) { 00666 uint8_t *b; 00667 00668 int x, y; // Position in bayer image 00669 int i, j; // Position in bgr image 00670 00671 int width = image->x; 00672 int height = image->y; 00673 00674 int nwidth = width / factor; 00675 int nheight = height / factor; 00676 00677 int offset; 00678 int startx, stepx; 00679 int starty, stepy; 00680 00681 00682 // Calculate the initial position (on Y axis) 00683 if (vflip) { 00684 starty = height - 2; 00685 stepy = -factor; 00686 } 00687 else { 00688 starty = 0; 00689 stepy = factor; 00690 } 00691 00692 // Calculate the initial position (on X axis) 00693 if (hflip) { 00694 startx = width - 1; 00695 stepx = -factor; 00696 offset = width - 2; 00697 } 00698 else { 00699 startx = 0; 00700 stepx = factor; 00701 offset = 1; 00702 } 00703 00704 00705 // Skip the first line 00706 bayer += width; 00707 00708 // To center vertically the image in the view 00709 bgr += ((view->y - nheight) / 2) * view->x * 3; 00710 00711 // To center horizontally the image in the view 00712 bgr += ((view->x - nwidth) / 2) * 3; 00713 00714 // Clean the first line 00715 memset(bgr, 0, nwidth * 3); 00716 bgr += nwidth * 3; 00717 00718 00719 // For each bgr line without the borders (first and last line) 00720 for (j=0, y=starty; j<nheight-2; j++, y=y+stepy) { 00721 // Go to the start of line 00722 b = bayer + y * width + offset; 00723 00724 // Offset to center horizontally the image in the view 00725 bgr += (view->x - nwidth) * 3; 00726 00727 if (y & 0x1) { 00728 // Skip the first pixel 00729 *bgr++ = 0; 00730 *bgr++ = 0; 00731 *bgr++ = 0; 00732 00733 // GBGBGB : Line process... 00734 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 00735 if (x & 0x1) { 00736 *bgr++ = *b; 00737 *bgr++ = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 00738 *bgr++ = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 00739 } 00740 else { 00741 *bgr++ = (*(b-1) + *(b+1)) >> 1; 00742 *bgr++ = *b; 00743 *bgr++ = (*(b-width) + *(b+width)) >> 1; 00744 } 00745 00746 b += stepx; 00747 } 00748 00749 // Skip the last pixel 00750 *bgr++ = 0; 00751 *bgr++ = 0; 00752 *bgr++ = 0; 00753 } 00754 else { 00755 // Skip the first pixel 00756 *bgr++ = 0; 00757 *bgr++ = 0; 00758 *bgr++ = 0; 00759 00760 // RGRGRG : Line process... 00761 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 00762 if (x & 0x1) { 00763 *bgr++ = (*(b-width) + *(b+width)) >> 1; 00764 *bgr++ = *b; 00765 *bgr++ = (*(b-1) + *(b+1)) >> 1; 00766 } 00767 else { 00768 *bgr++ = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 00769 *bgr++ = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 00770 *bgr++ = *b; 00771 } 00772 00773 b += stepx; 00774 } 00775 00776 // Skip the last pixel 00777 *bgr++ = 0; 00778 *bgr++ = 0; 00779 *bgr++ = 0; 00780 } 00781 } 00782 00783 // Clean the last line 00784 memset(bgr, 0, nwidth * 3); 00785 } 00786 00787 00800 void stk11xx_b2bgr32(uint8_t *bayer, uint8_t *bgr, 00801 struct stk11xx_coord *image, 00802 struct stk11xx_coord *view, 00803 const int hflip, const int vflip, 00804 const int factor) { 00805 uint8_t *b; 00806 00807 int x, y; // Position in bayer image 00808 int i, j; // Position in bgr image 00809 00810 int width = image->x; 00811 int height = image->y; 00812 00813 int nwidth = width / factor; 00814 int nheight = height / factor; 00815 00816 int offset; 00817 int startx, stepx; 00818 int starty, stepy; 00819 00820 00821 // Calculate the initial position (on Y axis) 00822 if (vflip) { 00823 starty = height - 2; 00824 stepy = -factor; 00825 } 00826 else { 00827 starty = 0; 00828 stepy = factor; 00829 } 00830 00831 // Calculate the initial position (on X axis) 00832 if (hflip) { 00833 startx = width - 1; 00834 stepx = -factor; 00835 offset = width - 2; 00836 } 00837 else { 00838 startx = 0; 00839 stepx = factor; 00840 offset = 1; 00841 } 00842 00843 00844 // Skip the first line 00845 bayer += width; 00846 00847 // To center vertically the image in the view 00848 bgr += ((view->y - nheight) / 2) * view->x * 4; 00849 00850 // To center horizontally the image in the view 00851 bgr += ((view->x - nwidth) / 2) * 4; 00852 00853 // Clean the first line 00854 memset(bgr, 0, nwidth * 4); 00855 bgr += nwidth * 4; 00856 00857 00858 // For each bgr line without the borders (first and last line) 00859 for (j=0, y=starty; j<nheight-2; j++, y=y+stepy) { 00860 // Go to the start of line 00861 b = bayer + y * width + offset; 00862 00863 // Offset to center horizontally the image in the view 00864 bgr += (view->x - nwidth) * 4; 00865 00866 if (y & 0x1) { 00867 // Skip the first pixel 00868 *bgr++ = 0; 00869 *bgr++ = 0; 00870 *bgr++ = 0; 00871 *bgr++ = 0; 00872 00873 // GBGBGB : Line process... 00874 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 00875 if (x & 0x1) { 00876 *bgr++ = *b; 00877 *bgr++ = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 00878 *bgr++ = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 00879 *bgr++ = 0; 00880 } 00881 else { 00882 *bgr++ = (*(b-1) + *(b+1)) >> 1; 00883 *bgr++ = *b; 00884 *bgr++ = (*(b-width) + *(b+width)) >> 1; 00885 *bgr++ = 0; 00886 } 00887 00888 b += stepx; 00889 } 00890 00891 // Skip the last pixel 00892 *bgr++ = 0; 00893 *bgr++ = 0; 00894 *bgr++ = 0; 00895 *bgr++ = 0; 00896 } 00897 else { 00898 // Skip the first pixel 00899 *bgr++ = 0; 00900 *bgr++ = 0; 00901 *bgr++ = 0; 00902 *bgr++ = 0; 00903 00904 // RGRGRG : Line process... 00905 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 00906 if (x & 0x1) { 00907 *bgr++ = (*(b-width) + *(b+width)) >> 1; 00908 *bgr++ = *b; 00909 *bgr++ = (*(b-1) + *(b+1)) >> 1; 00910 *bgr++ = 0; 00911 } 00912 else { 00913 *bgr++ = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 00914 *bgr++ = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 00915 *bgr++ = *b; 00916 *bgr++ = 0; 00917 } 00918 00919 b += stepx; 00920 } 00921 00922 // Skip the last pixel 00923 *bgr++ = 0; 00924 *bgr++ = 0; 00925 *bgr++ = 0; 00926 *bgr++ = 0; 00927 } 00928 } 00929 00930 // Clean the last line 00931 memset(bgr, 0, nwidth * 4); 00932 } 00933 00934 00947 void stk11xx_b2uyvy(uint8_t *bayer, uint8_t *yuv, 00948 struct stk11xx_coord *image, 00949 struct stk11xx_coord *view, 00950 const int hflip, const int vflip, 00951 const int factor) { 00952 uint8_t *b; 00953 00954 int x, y; // Position in bayer image 00955 int i, j; // Position in yuv image 00956 00957 int pR, pG, pB; 00958 int pY, pU, pV; 00959 00960 int width = image->x; 00961 int height = image->y; 00962 00963 int nwidth = width / factor; 00964 int nheight = height / factor; 00965 00966 int offset; 00967 int startx, stepx; 00968 int starty, stepy; 00969 00970 00971 // Calculate the initial position (on Y axis) 00972 if (vflip) { 00973 starty = height - 2; 00974 stepy = -factor; 00975 } 00976 else { 00977 starty = 0; 00978 stepy = factor; 00979 } 00980 00981 // Calculate the initial position (on X axis) 00982 if (hflip) { 00983 startx = width - 1; 00984 stepx = -factor; 00985 offset = width - 2; 00986 } 00987 else { 00988 startx = 0; 00989 stepx = factor; 00990 offset = 1; 00991 } 00992 00993 // Background color... 00994 memset(yuv, 16, width * 2); 00995 for (i=0; i<width*2; i=i+2, *(yuv+i)=128); 00996 for (i=1; i<height; i++) 00997 memcpy(yuv+i*width*2, yuv, width*2); 00998 00999 // Skip the first line 01000 bayer += width; 01001 01002 // To center vertically the image in the view 01003 yuv += ((view->y - nheight) / 2) * view->x * 2; 01004 01005 // To center horizontally the image in the view 01006 yuv += ((view->x - nwidth) / 2) * 2; 01007 01008 // Clean the first line 01009 memset(yuv, 16, nwidth * 2); 01010 for (i=0; i<nwidth*2; i=i+2, *(yuv+i)=128); 01011 yuv += nwidth * 2; 01012 01013 01014 // For each yuv line without the borders (first and last line) 01015 for (j=0, y=starty; j<nheight-2; j++, y=y+stepy) { 01016 // Go to the start of line 01017 b = bayer + y * width + offset; 01018 01019 // Offset to center horizontally the image in the view 01020 yuv += (view->x - nwidth) * 2; 01021 01022 if (y & 0x1) { 01023 // Skip the first pixel 01024 *yuv++ = 128; 01025 *yuv++ = 16; 01026 01027 // GBGBGB : Line process... 01028 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 01029 if (x & 0x1) { 01030 pR = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 01031 pG = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 01032 pB = *b; 01033 } 01034 else { 01035 pR = (*(b-width) + *(b+width)) >> 1; 01036 pG = *b; 01037 pB = (*(b-1) + *(b+1)) >> 1; 01038 } 01039 01040 pY = stk11xx_yuv_interp[pR][0] + stk11xx_yuv_interp[pG][1] + stk11xx_yuv_interp[pB][2]; 01041 pU = stk11xx_yuv_interp[pR][3] + stk11xx_yuv_interp[pG][4] + stk11xx_yuv_interp[pB][5]; 01042 pV = stk11xx_yuv_interp[pR][5] + stk11xx_yuv_interp[pG][6] + stk11xx_yuv_interp[pB][7]; 01043 01044 pY = CLIP(pY, 0,255); 01045 pU = CLIP(pU, -127,127); 01046 pV = CLIP(pV, -127,127); 01047 01048 if (i % 2){ 01049 *yuv++ = (112 * pU)/127 + 128; // U 01050 *yuv++ = (219 * pY)/255 + 16; // Y 01051 } 01052 else { 01053 *yuv++ = (112 * pV)/127 + 128; // V 01054 *yuv++ = (219 * pY)/255 + 16; // Y 01055 } 01056 01057 b += stepx; 01058 } 01059 01060 // Skip the last pixel 01061 *yuv++ = 128; 01062 *yuv++ = 16; 01063 } 01064 else { 01065 // Skip the first pixel 01066 *yuv++ = 128; 01067 *yuv++ = 16; 01068 01069 // RGRGRG : Line process... 01070 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 01071 if (x & 0x1) { 01072 pR = (*(b-1) + *(b+1)) >> 1; 01073 pG = *b; 01074 pB = (*(b-width) + *(b+width)) >> 1; 01075 } 01076 else { 01077 pR = *b; 01078 pG = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 01079 pB = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 01080 } 01081 01082 pY = stk11xx_yuv_interp[pR][0] + stk11xx_yuv_interp[pG][1] + stk11xx_yuv_interp[pB][2]; 01083 pU = stk11xx_yuv_interp[pR][3] + stk11xx_yuv_interp[pG][4] + stk11xx_yuv_interp[pB][5]; 01084 pV = stk11xx_yuv_interp[pR][5] + stk11xx_yuv_interp[pG][6] + stk11xx_yuv_interp[pB][7]; 01085 01086 pY = CLIP(pY, 0,255); 01087 pU = CLIP(pU, -127,127); 01088 pV = CLIP(pV, -127,127); 01089 01090 if (i % 2){ 01091 *yuv++ = (112 * pU)/127 + 128; // U 01092 *yuv++ = (219 * pY)/255 + 16; // Y 01093 } 01094 else { 01095 *yuv++ = (112 * pV)/127 + 128; // V 01096 *yuv++ = (219 * pY)/255 + 16; // Y 01097 } 01098 01099 b += stepx; 01100 } 01101 01102 // Skip the last pixel 01103 *yuv++ = 128; 01104 *yuv++ = 16; 01105 } 01106 } 01107 01108 // Clean the last line 01109 memset(yuv, 16, nwidth * 2); 01110 for (i=0; i<nwidth*2; i=i+2, *(yuv+i)=128); 01111 } 01112 01113 01126 void stk11xx_b2yuyv(uint8_t *bayer, uint8_t *yuv, 01127 struct stk11xx_coord *image, 01128 struct stk11xx_coord *view, 01129 const int hflip, const int vflip, 01130 const int factor) { 01131 uint8_t *b; 01132 01133 int x, y; // Position in bayer image 01134 int i, j; // Position in yuv image 01135 01136 int pR, pG, pB; 01137 int pY, pU, pV; 01138 01139 int width = image->x; 01140 int height = image->y; 01141 01142 int nwidth = width / factor; 01143 int nheight = height / factor; 01144 01145 int offset; 01146 int startx, stepx; 01147 int starty, stepy; 01148 01149 01150 // Calculate the initial position (on Y axis) 01151 if (vflip) { 01152 starty = height - 2; 01153 stepy = -factor; 01154 } 01155 else { 01156 starty = 0; 01157 stepy = factor; 01158 } 01159 01160 // Calculate the initial position (on X axis) 01161 if (hflip) { 01162 startx = width - 1; 01163 stepx = -factor; 01164 offset = width - 2; 01165 } 01166 else { 01167 startx = 0; 01168 stepx = factor; 01169 offset = 1; 01170 } 01171 01172 // Background color... 01173 memset(yuv, 128, width * 2); 01174 for (i=0; i<width*2; i=i+2, *(yuv+i)=16); 01175 for (i=1; i<height; i++) 01176 memcpy(yuv+i*width*2, yuv, width*2); 01177 01178 // Skip the first line 01179 bayer += width; 01180 01181 // To center vertically the image in the view 01182 yuv += ((view->y - nheight) / 2) * view->x * 2; 01183 01184 // To center horizontally the image in the view 01185 yuv += ((view->x - nwidth) / 2) * 2; 01186 01187 // Clean the first line 01188 memset(yuv, 128, nwidth * 2); 01189 for (i=0; i<nwidth*2; i=i+2, *(yuv+i)=16); 01190 yuv += nwidth * 2; 01191 01192 01193 // For each yuv line without the borders (first and last line) 01194 for (j=0, y=starty; j<nheight-2; j++, y=y+stepy) { 01195 // Go to the start of line 01196 b = bayer + y * width + offset; 01197 01198 // Offset to center horizontally the image in the view 01199 yuv += (view->x - nwidth) * 2; 01200 01201 if (y & 0x1) { 01202 // Skip the first pixel 01203 *yuv++ = 16; 01204 *yuv++ = 128; 01205 01206 // GBGBGB : Line process... 01207 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 01208 if (x & 0x1) { 01209 pR = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 01210 pG = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 01211 pB = *b; 01212 } 01213 else { 01214 pR = (*(b-width) + *(b+width)) >> 1; 01215 pG = *b; 01216 pB = (*(b-1) + *(b+1)) >> 1; 01217 } 01218 01219 pY = stk11xx_yuv_interp[pR][0] + stk11xx_yuv_interp[pG][1] + stk11xx_yuv_interp[pB][2]; 01220 pU = stk11xx_yuv_interp[pR][3] + stk11xx_yuv_interp[pG][4] + stk11xx_yuv_interp[pB][5]; 01221 pV = stk11xx_yuv_interp[pR][5] + stk11xx_yuv_interp[pG][6] + stk11xx_yuv_interp[pB][7]; 01222 01223 pY = CLIP(pY, 0,255); 01224 pU = CLIP(pU, -127,127); 01225 pV = CLIP(pV, -127,127); 01226 01227 if (i % 2){ 01228 *yuv++ = (219 * pY)/255 + 16; // Y 01229 *yuv++ = (112 * pU)/127 + 128; // U 01230 } 01231 else { 01232 *yuv++ = (219 * pY)/255 + 16; // Y 01233 *yuv++ = (112 * pV)/127 + 128; // V 01234 } 01235 01236 b += stepx; 01237 } 01238 01239 // Skip the last pixel 01240 *yuv++ = 16; 01241 *yuv++ = 128; 01242 } 01243 else { 01244 // Skip the first pixel 01245 *yuv++ = 16; 01246 *yuv++ = 128; 01247 01248 // RGRGRG : Line process... 01249 for (i=0, x=startx; i<nwidth-2; i++, x=x+stepx) { 01250 if (x & 0x1) { 01251 pR = (*(b-1) + *(b+1)) >> 1; 01252 pG = *b; 01253 pB = (*(b-width) + *(b+width)) >> 1; 01254 } 01255 else { 01256 pR = *b; 01257 pG = (*(b-width) + *(b-1) + *(b+1) + *(b+width)) >> 2; 01258 pB = (*(b-width-1) + *(b-width+1) + *(b+width-1) + *(b+width+1)) >> 2; 01259 } 01260 01261 pY = stk11xx_yuv_interp[pR][0] + stk11xx_yuv_interp[pG][1] + stk11xx_yuv_interp[pB][2]; 01262 pU = stk11xx_yuv_interp[pR][3] + stk11xx_yuv_interp[pG][4] + stk11xx_yuv_interp[pB][5]; 01263 pV = stk11xx_yuv_interp[pR][5] + stk11xx_yuv_interp[pG][6] + stk11xx_yuv_interp[pB][7]; 01264 01265 pY = CLIP(pY, 0,255); 01266 pU = CLIP(pU, -127,127); 01267 pV = CLIP(pV, -127,127); 01268 01269 if (i % 2){ 01270 *yuv++ = (219 * pY)/255 + 16; // Y 01271 *yuv++ = (112 * pU)/127 + 128; // U 01272 } 01273 else { 01274 *yuv++ = (219 * pY)/255 + 16; // Y 01275 *yuv++ = (112 * pV)/127 + 128; // V 01276 } 01277 01278 b += stepx; 01279 } 01280 01281 // Skip the last pixel 01282 *yuv++ = 16; 01283 *yuv++ = 128; 01284 } 01285 } 01286 01287 // Clean the last line 01288 memset(yuv, 128, nwidth * 2); 01289 for (i=0; i<nwidth*2; i=i+2, *(yuv+i)=16); 01290 } 01291 01292