53 #include <visp/vpImageConvert.h>
55 bool vpImageConvert::YCbCrLUTcomputed =
false;
56 int vpImageConvert::vpCrr[256];
57 int vpImageConvert::vpCgb[256];
58 int vpImageConvert::vpCgr[256];
59 int vpImageConvert::vpCbb[256];
105 for (
unsigned int i = 0; i < max_xy; i++) {
106 float val = 255.f * (src.
bitmap[i] - min) / (max - min);
112 dest.
bitmap[i] = (
unsigned char)val;
143 for (
unsigned int i = 0; i < max_xy; i++) {
144 double val = 255. * (src.
bitmap[i] - min) / (max - min);
150 dest.
bitmap[i] = (
unsigned char)val;
167 #ifdef VISP_HAVE_OPENCV
211 int nChannel = src->nChannels;
212 int depth = src->depth;
213 int height = src->height;
214 int width = src->width;
215 int widthStep = src->widthStep;
216 int lineStep = (flip) ? 1 : 0;
218 if(nChannel == 3 && depth == 8){
219 dest.
resize((
unsigned int)height, (
unsigned int)width);
222 unsigned char* input = (
unsigned char*)src->imageData;
224 unsigned char* beginOutput = (
unsigned char*)dest.
bitmap;
225 unsigned char* output = NULL;
227 for(
int i=0 ; i < height ; i++)
230 output = beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) + (1-lineStep) * 4 * width * i;
231 for(
int j=0 ; j < width ; j++)
233 *(output++) = *(line+2);
234 *(output++) = *(line+1);
235 *(output++) = *(line);
244 else if(nChannel == 1 && depth == 8 ){
245 dest.
resize((
unsigned int)height, (
unsigned int)width);
247 unsigned char * input = (
unsigned char*)src->imageData;
248 unsigned char * line;
249 unsigned char* beginOutput = (
unsigned char*)dest.
bitmap;
250 unsigned char* output = NULL;
252 for(
int i=0 ; i < height ; i++)
255 output = beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) + (1-lineStep) * 4 * width * i;
256 for(
int j=0 ; j < width ; j++)
261 *output++ = *(line);;
314 int nChannel = src->nChannels;
315 int depth = src->depth;
316 int height = src->height;
317 int width = src->width;
318 int widthStep = src->widthStep;
319 int lineStep = (flip) ? 1 : 0;
323 if(widthStep == width){
324 if(nChannel == 1 && depth == 8){
325 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
326 memcpy(dest.
bitmap, src->imageData,
327 (
size_t)(height*width));
329 if(nChannel == 3 && depth == 8){
330 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
331 BGRToGrey((
unsigned char*)src->imageData,dest.
bitmap, (
unsigned int)width, (
unsigned int)height,
false);
335 if(nChannel == 1 && depth == 8){
336 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
337 for (
int i =0 ; i < height ; i++){
338 memcpy(dest.
bitmap+i*width, src->imageData + i*widthStep,
342 if(nChannel == 3 && depth == 8){
343 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
344 for (
int i = 0 ; i < height ; i++){
345 BGRToGrey((
unsigned char*)src->imageData + i*widthStep,
346 dest.
bitmap + i*width, (
unsigned int)width, 1,
false);
353 if(nChannel == 1 && depth == 8){
354 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
355 unsigned char* beginOutput = (
unsigned char*)dest.
bitmap;
356 for (
int i =0 ; i < height ; i++){
357 memcpy(beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) , src->imageData + i*widthStep,
361 if(nChannel == 3 && depth == 8){
362 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
364 BGRToGrey((
unsigned char*)src->imageData ,
365 dest.
bitmap , (
unsigned int)width, (
unsigned int)height,
true);
417 CvSize size = cvSize(width, height);
421 if(dest->nChannels != channels || dest->depth != depth
422 || dest->height != height || dest->width != width){
423 if(dest->nChannels != 0) cvReleaseImage(&dest);
424 dest = cvCreateImage( size, depth, channels );
427 else dest = cvCreateImage( size, depth, channels );
431 unsigned char * input = (
unsigned char*)src.
bitmap;
432 unsigned char * line;
433 unsigned char * output = (
unsigned char*)dest->imageData;
437 int widthStep = dest->widthStep;
439 for(i=0 ; i < height ; i++)
441 output = (
unsigned char*)dest->imageData + i*widthStep;
443 for( j=0 ; j < width ; j++)
445 *output++ = *(line+2);
446 *output++ = *(line+1);
501 unsigned int width = src.
getWidth();
502 CvSize size = cvSize((
int)width, (
int)height);
506 if(dest->nChannels != channels || dest->depth != depth
507 || dest->height != (
int) height || dest->width != (
int) width){
508 if(dest->nChannels != 0) cvReleaseImage(&dest);
509 dest = cvCreateImage( size, depth, channels );
512 else dest = cvCreateImage( size, depth, channels );
514 unsigned int widthStep = (
unsigned int)dest->widthStep;
516 if ( width == widthStep){
517 memcpy(dest->imageData,src.
bitmap, width*height);
521 for (
unsigned int i =0 ; i < height ; i++){
522 memcpy(dest->imageData + i*widthStep, src.
bitmap + i*width,
528 #if VISP_HAVE_OPENCV_VERSION >= 0x020100
574 if(src.type() == CV_8UC4){
575 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
577 for(
unsigned int i=0; i<dest.
getRows(); ++i)
578 for(
unsigned int j=0; j<dest.
getCols(); ++j){
579 cv::Vec4b tmp = src.at<cv::Vec4b>((int)i, (
int)j);
585 dest[dest.
getRows()-i-1][j] = rgbaVal;
587 dest[i][j] = rgbaVal;
589 }
else if(src.type() == CV_8UC3){
590 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
593 for(
unsigned int i=0; i<dest.
getRows(); ++i){
594 for(
unsigned int j=0; j<dest.
getCols(); ++j){
595 cv::Vec3b tmp = src.at<cv::Vec3b>((int)i, (
int)j);
600 dest[dest.
getRows()-i-1][j] = rgbaVal;
602 dest[i][j] = rgbaVal;
606 }
else if(src.type() == CV_8UC1){
607 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
609 for(
unsigned int i=0; i<dest.
getRows(); ++i){
610 for(
unsigned int j=0; j<dest.
getCols(); ++j){
611 rgbaVal = src.at<
unsigned char>((int)i, (
int)j);
613 dest[dest.
getRows()-i-1][j] = rgbaVal;
615 dest[i][j] = rgbaVal;
667 if(src.type() == CV_8UC1){
668 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
669 if(src.isContinuous() && !flip){
670 memcpy(dest.
bitmap, src.data, (
size_t)(src.rows*src.cols));
674 for(
unsigned int i=0; i<dest.
getRows(); ++i){
675 memcpy(dest.
bitmap+i*dest.
getCols(), src.data+(dest.
getRows()-i-1)*src.step1(), (size_t)src.step);
678 for(
unsigned int i=0; i<dest.
getRows(); ++i){
679 memcpy(dest.
bitmap+i*dest.
getCols(), src.data+i*src.step1(), (size_t)src.step);
683 }
else if(src.type() == CV_8UC3){
684 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
685 if(src.isContinuous() && !flip){
686 BGRToGrey((
unsigned char*)src.data, (
unsigned char*)dest.
bitmap, (
unsigned int)src.cols, (
unsigned int)src.rows, flip);
690 for(
unsigned int i=0; i<dest.
getRows(); ++i){
691 BGRToGrey((
unsigned char*)src.data+i*src.step1(),
693 (
unsigned int)dest.
getCols(), 1,
false);
696 for(
unsigned int i=0; i<dest.
getRows(); ++i){
697 BGRToGrey((
unsigned char*)src.data+i*src.step1(),
699 (
unsigned int)dest.
getCols(), 1,
false);
754 cv::Mat out[] = {dest, alpha};
755 int from_to[] = { 0,2, 1,1, 2,0, 3,3 };
756 cv::mixChannels(&vpToMat, 1, out, 2, from_to, 4);
805 dest = tmpMap.clone();
814 #ifdef VISP_HAVE_YARP
848 yarp::sig::ImageOf< yarp::sig::PixelMono > *dest,
const bool copyData)
898 dest.
resize(src->height(),src->width());
900 memcpy(dest.
bitmap, src->getRawImage(), src->height()*src->width()*
sizeof(yarp::sig::PixelMono));
902 dest.
bitmap = src->getRawImage();
939 yarp::sig::ImageOf< yarp::sig::PixelRgba > *dest,
const bool copyData)
989 dest.
resize(src->height(),src->width());
991 memcpy(dest.
bitmap, src->getRawImage(),src->height()*src->width()*
sizeof(yarp::sig::PixelRgba));
1031 for(
unsigned int i = 0 ; i < src.
getRows() ; i++){
1032 for(
unsigned int j = 0 ; j < src.
getWidth() ; j++){
1033 dest->pixel(j,i).r = src[i][j].R;
1034 dest->pixel(j,i).g = src[i][j].G;
1035 dest->pixel(j,i).b = src[i][j].B;
1078 dest.
resize(src->height(),src->width());
1079 for(
int i = 0 ; i < src->height() ; i++){
1080 for(
int j = 0 ; j < src->width() ; j++){
1081 dest[i][j].R = src->pixel(j,i).r;
1082 dest[i][j].G = src->pixel(j,i).g;
1083 dest[i][j].B = src->pixel(j,i).b;
1091 #if defined(VISP_HAVE_LIBJPEG)
1092 #if JPEG_LIB_VERSION > 70
1102 unsigned char **dest,
long unsigned int &destSize,
int quality)
1104 struct jpeg_compress_struct cinfo;
1105 struct jpeg_error_mgr jerr;
1107 cinfo.err = jpeg_std_error(&jerr);
1108 jpeg_create_compress(&cinfo);
1113 jpeg_mem_dest(&cinfo, dest, &destSize);
1115 unsigned int width = src.
getWidth();
1118 cinfo.image_width = width;
1119 cinfo.image_height = height;
1120 cinfo.input_components = 1;
1121 cinfo.in_color_space = JCS_GRAYSCALE;
1122 jpeg_set_defaults(&cinfo);
1123 jpeg_set_quality(&cinfo, quality, TRUE);
1125 jpeg_start_compress(&cinfo,TRUE);
1127 unsigned char *line;
1128 line =
new unsigned char[width];
1129 unsigned char* input = (
unsigned char*)src.
bitmap;
1130 while (cinfo.next_scanline < cinfo.image_height)
1132 for (
unsigned int i = 0; i < width; i++)
1137 jpeg_write_scanlines(&cinfo, &line, 1);
1140 jpeg_finish_compress(&cinfo);
1141 jpeg_destroy_compress(&cinfo);
1152 void vpImageConvert::convertToJPEGBuffer(
unsigned char *src,
long unsigned int srcSize,
1155 struct jpeg_decompress_struct cinfo;
1156 struct jpeg_error_mgr jerr;
1158 cinfo.err = jpeg_std_error(&jerr);
1159 jpeg_create_decompress(&cinfo);
1161 jpeg_mem_src(&cinfo, src, srcSize);
1162 jpeg_read_header(&cinfo, TRUE);
1164 unsigned int width = cinfo.image_width;
1165 unsigned int height = cinfo.image_height;
1168 dest.
resize(height,width);
1170 jpeg_start_decompress(&cinfo);
1172 unsigned int rowbytes = cinfo.output_width * (
unsigned int)(cinfo.output_components);
1173 JSAMPARRAY buf = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, rowbytes, 1);
1175 if (cinfo.out_color_space == JCS_GRAYSCALE)
1178 while (cinfo.output_scanline<cinfo.output_height)
1180 row = cinfo.output_scanline;
1181 jpeg_read_scanlines(&cinfo,buf,1);
1182 memcpy(dest[row], buf[0], rowbytes);
1186 jpeg_finish_decompress(&cinfo);
1187 jpeg_destroy_decompress(&cinfo);
1190 #endif // defined(VISP_HAVE_LIBJPEG)
1194 if (c & (~255)) { if (c < 0) c = 0; else c = 255; }
1202 unsigned int width,
unsigned int height)
1207 int r, g, b, cr, cg, cb, y1, y2;
1217 cb = ((*s - 128) * 454) >> 8;
1218 cg = (*s++ - 128) * 88;
1220 cr = ((*s - 128) * 359) >> 8;
1221 cg = (cg + (*s++ - 128) * 183) >> 8;
1230 *d++ =
static_cast<unsigned char>(r);
1231 *d++ =
static_cast<unsigned char>(g);
1232 *d++ =
static_cast<unsigned char>(b);
1242 *d++ =
static_cast<unsigned char>(r);
1243 *d++ =
static_cast<unsigned char>(g);
1244 *d++ =
static_cast<unsigned char>(b);
1258 unsigned int width,
unsigned int height)
1263 int r, g, b, cr, cg, cb, y1, y2;
1273 cb = ((*s - 128) * 454) >> 8;
1274 cg = (*s++ - 128) * 88;
1276 cr = ((*s - 128) * 359) >> 8;
1277 cg = (cg + (*s++ - 128) * 183) >> 8;
1286 *d++ =
static_cast<unsigned char>(r);
1287 *d++ =
static_cast<unsigned char>(g);
1288 *d++ =
static_cast<unsigned char>(b);
1297 *d++ =
static_cast<unsigned char>(r);
1298 *d++ =
static_cast<unsigned char>(g);
1299 *d++ =
static_cast<unsigned char>(b);
1312 unsigned int i=0,j=0;
1316 grey[i++] = yuyv[j];
1317 grey[i++] = yuyv[j+2];
1333 register int U, V, R, G, B, V2, U5, UV;
1334 register int Y0, Y1, Y2, Y3;
1335 for(
unsigned int i = size / 4; i; i--) {
1336 U = (int)((*yuv++ - 128) * 0.354);
1340 V = (int)((*yuv++ - 128) * 0.707);
1351 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1354 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1357 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1359 *rgba++ = (
unsigned char)R;
1360 *rgba++ = (
unsigned char)G;
1361 *rgba++ = (
unsigned char)B;
1366 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1369 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1372 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1374 *rgba++ = (
unsigned char)R;
1375 *rgba++ = (
unsigned char)G;
1376 *rgba++ = (
unsigned char)B;
1381 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1384 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1387 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1389 *rgba++ = (
unsigned char)R;
1390 *rgba++ = (
unsigned char)G;
1391 *rgba++ = (
unsigned char)B;
1396 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1399 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1402 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1404 *rgba++ = (
unsigned char)R;
1405 *rgba++ = (
unsigned char)G;
1406 *rgba++ = (
unsigned char)B;
1411 unsigned int i=0,j=0;
1412 unsigned char r, g, b;
1413 while( j < numpixels*3/2)
1416 YUVToRGB (yuv[j+1], yuv[j], yuv[j+3], r, g, b);
1423 YUVToRGB (yuv[j+2], yuv[j], yuv[j+3], r, g, b);
1430 YUVToRGB (yuv[j+4], yuv[j], yuv[j+3], r, g, b);
1437 YUVToRGB (yuv[j+5], yuv[j], yuv[j+3], r, g, b);
1461 register int U, V, R, G, B, V2, U5, UV;
1462 register int Y0, Y1;
1463 for(
unsigned int i = size / 2; i; i-- ) {
1464 U = (int)((*yuv++ - 128) * 0.354);
1467 V = (int)((*yuv++ - 128) * 0.707);
1474 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1477 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1480 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1482 *rgba++ = (
unsigned char)R;
1483 *rgba++ = (
unsigned char)G;
1484 *rgba++ = (
unsigned char)B;
1489 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1492 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1495 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1497 *rgba++ = (
unsigned char)R;
1498 *rgba++ = (
unsigned char)G;
1499 *rgba++ = (
unsigned char)B;
1505 unsigned int i=0,j=0;
1506 unsigned char r, g, b;
1511 YUVToRGB (yuv[j+1], yuv[j], yuv[j+2], r, g, b);
1518 YUVToRGB (yuv[j+3], yuv[j], yuv[j+2], r, g, b);
1538 unsigned int i=0,j=0;
1539 while( j < size*3/2)
1542 grey[i ] = yuv[j+1];
1543 grey[i+1] = yuv[j+2];
1544 grey[i+2] = yuv[j+4];
1545 grey[i+3] = yuv[j+5];
1565 register int U, V, R, G, B, V2, U5, UV;
1566 register int Y0, Y1;
1567 for(
unsigned int i = size / 2; i; i-- ) {
1568 U = (int)((*yuv++ - 128) * 0.354);
1571 V = (int)((*yuv++ - 128) * 0.707);
1578 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1581 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1584 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1586 *rgb++ = (
unsigned char)R;
1587 *rgb++ = (
unsigned char)G;
1588 *rgb++ = (
unsigned char)B;
1592 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1595 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1598 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1600 *rgb++ = (
unsigned char)R;
1601 *rgb++ = (
unsigned char)G;
1602 *rgb++ = (
unsigned char)B;
1608 unsigned int i=0,j=0;
1609 unsigned char r, g, b;
1614 YUVToRGB (yuv[j+1], yuv[j], yuv[j+2], r, g, b);
1620 YUVToRGB (yuv[j+3], yuv[j], yuv[j+2], r, g, b);
1641 unsigned int i=0,j=0;
1645 grey[i++] = yuv[j+1];
1646 grey[i++] = yuv[j+3];
1661 register int U, V, R, G, B, V2, U5, UV;
1662 register int Y0, Y1, Y2, Y3;
1663 for(
unsigned int i = size / 4; i; i--) {
1664 U = (int)((*yuv++ - 128) * 0.354);
1668 V = (int)((*yuv++ - 128) * 0.707);
1679 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1682 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1685 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1687 *rgb++ = (
unsigned char)R;
1688 *rgb++ = (
unsigned char)G;
1689 *rgb++ = (
unsigned char)B;
1693 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1696 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1699 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1701 *rgb++ = (
unsigned char)R;
1702 *rgb++ = (
unsigned char)G;
1703 *rgb++ = (
unsigned char)B;
1707 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1710 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1713 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1715 *rgb++ = (
unsigned char)R;
1716 *rgb++ = (
unsigned char)G;
1717 *rgb++ = (
unsigned char)B;
1721 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1724 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1727 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1729 *rgb++ = (
unsigned char)R;
1730 *rgb++ = (
unsigned char)G;
1731 *rgb++ = (
unsigned char)B;
1736 unsigned int i=0,j=0;
1737 unsigned char r, g, b;
1739 while( j < size*3/2)
1741 YUVToRGB (yuv[j+1], yuv[j], yuv[j+3], r, g, b);
1747 YUVToRGB (yuv[j+2], yuv[j], yuv[j+3], r, g, b);
1753 YUVToRGB (yuv[j+4], yuv[j], yuv[j+3], r, g, b);
1759 YUVToRGB (yuv[j+5], yuv[j], yuv[j+3], r, g, b);
1781 unsigned int width,
unsigned int height)
1784 register int U, V, R, G, B, V2, U5, UV;
1785 register int Y0, Y1, Y2, Y3;
1786 unsigned int size = width*height;
1787 unsigned char* iU = yuv + size;
1788 unsigned char* iV = yuv + 5*size/4;
1789 for(
unsigned int i = 0; i<height/2; i++)
1791 for(
unsigned int j = 0; j < width/2 ; j++)
1793 U = (int)((*iU++ - 128) * 0.354);
1795 V = (int)((*iV++ - 128) * 0.707);
1810 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1813 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1816 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1818 *rgba++ = (
unsigned char)R;
1819 *rgba++ = (
unsigned char)G;
1820 *rgba++ = (
unsigned char)B;
1825 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1828 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1831 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1833 *rgba++ = (
unsigned char)R;
1834 *rgba++ = (
unsigned char)G;
1835 *rgba++ = (
unsigned char)B;
1837 rgba = rgba + 4*width-7;
1841 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1844 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1847 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1849 *rgba++ = (
unsigned char)R;
1850 *rgba++ = (
unsigned char)G;
1851 *rgba++ = (
unsigned char)B;
1856 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1859 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1862 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1864 *rgba++ = (
unsigned char)R;
1865 *rgba++ = (
unsigned char)G;
1866 *rgba++ = (
unsigned char)B;
1868 rgba = rgba -4*width+1;
1882 unsigned int width,
unsigned int height)
1885 register int U, V, R, G, B, V2, U5, UV;
1886 register int Y0, Y1, Y2, Y3;
1887 unsigned int size = width*height;
1888 unsigned char* iU = yuv + size;
1889 unsigned char* iV = yuv + 5*size/4;
1890 for(
unsigned int i = 0; i<height/2; i++)
1892 for(
unsigned int j = 0; j < width/2 ; j++)
1894 U = (int)((*iU++ - 128) * 0.354);
1896 V = (int)((*iV++ - 128) * 0.707);
1911 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1914 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1917 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1919 *rgb++ = (
unsigned char)R;
1920 *rgb++ = (
unsigned char)G;
1921 *rgb++ = (
unsigned char)B;
1925 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1928 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1931 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1933 *rgb++ = (
unsigned char)R;
1934 *rgb++ = (
unsigned char)G;
1935 *rgb = (
unsigned char)B;
1936 rgb = rgb + 3*width-5;
1940 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1943 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1946 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1948 *rgb++ = (
unsigned char)R;
1949 *rgb++ = (
unsigned char)G;
1950 *rgb++ = (
unsigned char)B;
1954 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1957 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1960 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1962 *rgb++ = (
unsigned char)R;
1963 *rgb++ = (
unsigned char)G;
1964 *rgb = (
unsigned char)B;
1965 rgb = rgb -3*width+1;
1980 for(
unsigned int i=0 ; i < size ; i++)
1994 register int U, V, R, G, B, V2, U5, UV;
1996 for(
unsigned int i = 0; i<size; i++)
1998 U = (int)((*yuv++ - 128) * 0.354);
2001 V = (int)((*yuv++ - 128) * 0.707);
2011 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2014 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2017 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2019 *rgba++ = (
unsigned char)R;
2020 *rgba++ = (
unsigned char)G;
2021 *rgba++ = (
unsigned char)B;
2033 register int U, V, R, G, B, V2, U5, UV;
2035 for(
unsigned int i = 0; i<size; i++)
2038 U = (int)((*yuv++ - 128) * 0.354);
2041 V = (int)((*yuv++ - 128) * 0.707);
2050 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2053 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2056 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2058 *rgb++ = (
unsigned char)R;
2059 *rgb++ = (
unsigned char)G;
2060 *rgb++ = (
unsigned char)B;
2073 for(
unsigned int i=0 ; i < size ; i++)
2087 unsigned int width,
unsigned int height)
2090 register int U, V, R, G, B, V2, U5, UV;
2091 register int Y0, Y1, Y2, Y3;
2092 unsigned int size = width*height;
2093 unsigned char* iV = yuv + size;
2094 unsigned char* iU = yuv + 5*size/4;
2095 for(
unsigned int i = 0; i<height/2; i++)
2097 for(
unsigned int j = 0; j < width/2 ; j++)
2099 U = (int)((*iU++ - 128) * 0.354);
2101 V = (int)((*iV++ - 128) * 0.707);
2116 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2119 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2122 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2124 *rgba++ = (
unsigned char)R;
2125 *rgba++ = (
unsigned char)G;
2126 *rgba++ = (
unsigned char)B;
2131 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2134 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2137 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2139 *rgba++ = (
unsigned char)R;
2140 *rgba++ = (
unsigned char)G;
2141 *rgba++ = (
unsigned char)B;
2143 rgba = rgba + 4*width-7;
2147 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2150 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2153 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2155 *rgba++ = (
unsigned char)R;
2156 *rgba++ = (
unsigned char)G;
2157 *rgba++ = (
unsigned char)B;
2162 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2165 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2168 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2170 *rgba++ = (
unsigned char)R;
2171 *rgba++ = (
unsigned char)G;
2172 *rgba++ = (
unsigned char)B;
2174 rgba = rgba -4*width+1;
2187 unsigned int height,
unsigned int width)
2190 register int U, V, R, G, B, V2, U5, UV;
2191 register int Y0, Y1, Y2, Y3;
2192 unsigned int size = width*height;
2193 unsigned char* iV = yuv + size;
2194 unsigned char* iU = yuv + 5*size/4;
2195 for(
unsigned int i = 0; i<height/2; i++)
2197 for(
unsigned int j = 0; j < width/2 ; j++)
2199 U = (int)((*iU++ - 128) * 0.354);
2201 V = (int)((*iV++ - 128) * 0.707);
2216 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2219 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2222 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2224 *rgb++ = (
unsigned char)R;
2225 *rgb++ = (
unsigned char)G;
2226 *rgb++ = (
unsigned char)B;
2230 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2233 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2236 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2238 *rgb++ = (
unsigned char)R;
2239 *rgb++ = (
unsigned char)G;
2240 *rgb = (
unsigned char)B;
2241 rgb = rgb + 3*width-5;
2245 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2248 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2251 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2253 *rgb++ = (
unsigned char)R;
2254 *rgb++ = (
unsigned char)G;
2255 *rgb++ = (
unsigned char)B;
2259 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2262 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2265 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2267 *rgb++ = (
unsigned char)R;
2268 *rgb++ = (
unsigned char)G;
2269 *rgb = (
unsigned char)B;
2270 rgb = rgb -3*width+1;
2284 unsigned int width,
unsigned int height)
2287 register int U, V, R, G, B, V2, U5, UV;
2288 register int Y0, Y1, Y2, Y3,Y4, Y5, Y6, Y7,Y8, Y9, Y10, Y11,Y12, Y13, Y14, Y15;
2289 unsigned int size = width*height;
2290 unsigned char* iV = yuv + size;
2291 unsigned char* iU = yuv + 17*size/16;
2292 for(
unsigned int i = 0; i<height/4; i++)
2294 for(
unsigned int j = 0; j < width/4 ; j++)
2296 U = (int)((*iU++ - 128) * 0.354);
2298 V = (int)((*iV++ - 128) * 0.707);
2320 yuv = yuv-3*width+1;
2327 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2330 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2333 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2335 *rgba++ = (
unsigned char)R;
2336 *rgba++ = (
unsigned char)G;
2337 *rgba++ = (
unsigned char)B;
2342 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2345 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2348 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2350 *rgba++ = (
unsigned char)R;
2351 *rgba++ = (
unsigned char)G;
2352 *rgba++ = (
unsigned char)B;
2357 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2360 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2363 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2365 *rgba++ = (
unsigned char)R;
2366 *rgba++ = (
unsigned char)G;
2367 *rgba++ = (
unsigned char)B;
2372 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2375 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2378 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2380 *rgba++ = (
unsigned char)R;
2381 *rgba++ = (
unsigned char)G;
2382 *rgba++ = (
unsigned char)B;
2384 rgba = rgba + 4*width-15;
2387 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2390 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2393 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2395 *rgba++ = (
unsigned char)R;
2396 *rgba++ = (
unsigned char)G;
2397 *rgba++ = (
unsigned char)B;
2402 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2405 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2408 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2410 *rgba++ = (
unsigned char)R;
2411 *rgba++ = (
unsigned char)G;
2412 *rgba++ = (
unsigned char)B;
2417 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2420 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2423 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2425 *rgba++ = (
unsigned char)R;
2426 *rgba++ = (
unsigned char)G;
2427 *rgba++ = (
unsigned char)B;
2432 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2435 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2438 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2440 *rgba++ = (
unsigned char)R;
2441 *rgba++ = (
unsigned char)G;
2442 *rgba++ = (
unsigned char)B;
2444 rgba = rgba + 4*width-15;
2447 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2450 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2453 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2455 *rgba++ = (
unsigned char)R;
2456 *rgba++ = (
unsigned char)G;
2457 *rgba++ = (
unsigned char)B;
2462 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2465 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2468 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2470 *rgba++ = (
unsigned char)R;
2471 *rgba++ = (
unsigned char)G;
2472 *rgba++ = (
unsigned char)B;
2477 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2480 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2483 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2485 *rgba++ = (
unsigned char)R;
2486 *rgba++ = (
unsigned char)G;
2487 *rgba++ = (
unsigned char)B;
2492 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2495 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2498 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2500 *rgba++ = (
unsigned char)R;
2501 *rgba++ = (
unsigned char)G;
2502 *rgba++ = (
unsigned char)B;
2504 rgba = rgba + 4*width-15;
2507 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2510 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2513 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2515 *rgba++ = (
unsigned char)R;
2516 *rgba++ = (
unsigned char)G;
2517 *rgba++ = (
unsigned char)B;
2522 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2525 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2528 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2530 *rgba++ = (
unsigned char)R;
2531 *rgba++ = (
unsigned char)G;
2532 *rgba++ = (
unsigned char)B;
2537 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2540 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2543 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2545 *rgba++ = (
unsigned char)R;
2546 *rgba++ = (
unsigned char)G;
2547 *rgba++ = (
unsigned char)B;
2552 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2555 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2558 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2560 *rgba++ = (
unsigned char)R;
2561 *rgba++ = (
unsigned char)G;
2562 *rgba++ = (
unsigned char)B;
2564 rgba = rgba -12*width+1;
2577 unsigned int height,
unsigned int width)
2580 register int U, V, R, G, B, V2, U5, UV;
2581 register int Y0, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10, Y11, Y12, Y13, Y14, Y15;
2582 unsigned int size = width*height;
2583 unsigned char* iV = yuv + size;
2584 unsigned char* iU = yuv + 17*size/16;
2585 for(
unsigned int i = 0; i<height/4; i++)
2587 for(
unsigned int j = 0; j < width/4 ; j++)
2589 U = (int)((*iU++ - 128) * 0.354);
2591 V = (int)((*iV++ - 128) * 0.707);
2613 yuv = yuv-3*width+1;
2620 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2623 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2626 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2628 *rgb++ = (
unsigned char)R;
2629 *rgb++ = (
unsigned char)G;
2630 *rgb++ = (
unsigned char)B;
2634 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2637 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2640 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2642 *rgb++ = (
unsigned char)R;
2643 *rgb++ = (
unsigned char)G;
2644 *rgb++ = (
unsigned char)B;
2648 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2651 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2654 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2656 *rgb++ = (
unsigned char)R;
2657 *rgb++ = (
unsigned char)G;
2658 *rgb++ = (
unsigned char)B;
2662 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2665 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2668 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2670 *rgb++ = (
unsigned char)R;
2671 *rgb++ = (
unsigned char)G;
2672 *rgb = (
unsigned char)B;
2673 rgb = rgb + 3*width-11;
2676 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2679 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2682 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2684 *rgb++ = (
unsigned char)R;
2685 *rgb++ = (
unsigned char)G;
2686 *rgb++ = (
unsigned char)B;
2690 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2693 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2696 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2698 *rgb++ = (
unsigned char)R;
2699 *rgb++ = (
unsigned char)G;
2700 *rgb++ = (
unsigned char)B;
2704 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2707 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2710 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2712 *rgb++ = (
unsigned char)R;
2713 *rgb++ = (
unsigned char)G;
2714 *rgb++ = (
unsigned char)B;
2718 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2721 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2724 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2726 *rgb++ = (
unsigned char)R;
2727 *rgb++ = (
unsigned char)G;
2728 *rgb = (
unsigned char)B;
2729 rgb = rgb + 3*width-11;
2732 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2735 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2738 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2740 *rgb++ = (
unsigned char)R;
2741 *rgb++ = (
unsigned char)G;
2742 *rgb++ = (
unsigned char)B;
2746 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2749 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2752 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2754 *rgb++ = (
unsigned char)R;
2755 *rgb++ = (
unsigned char)G;
2756 *rgb++ = (
unsigned char)B;
2760 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2763 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2766 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2768 *rgb++ = (
unsigned char)R;
2769 *rgb++ = (
unsigned char)G;
2770 *rgb++ = (
unsigned char)B;
2774 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2777 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2780 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2782 *rgb++ = (
unsigned char)R;
2783 *rgb++ = (
unsigned char)G;
2784 *rgb = (
unsigned char)B;
2785 rgb = rgb + 3*width-11;
2788 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2791 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2794 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2796 *rgb++ = (
unsigned char)R;
2797 *rgb++ = (
unsigned char)G;
2798 *rgb++ = (
unsigned char)B;
2802 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2805 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2808 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2810 *rgb++ = (
unsigned char)R;
2811 *rgb++ = (
unsigned char)G;
2812 *rgb++ = (
unsigned char)B;
2816 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2819 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2822 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2824 *rgb++ = (
unsigned char)R;
2825 *rgb++ = (
unsigned char)G;
2826 *rgb++ = (
unsigned char)B;
2830 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2833 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2836 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2838 *rgb++ = (
unsigned char)R;
2839 *rgb++ = (
unsigned char)G;
2840 *rgb++ = (
unsigned char)B;
2841 rgb = rgb -9*width+1;
2855 unsigned char *pt_input = rgb;
2856 unsigned char *pt_end = rgb + 3*size;
2857 unsigned char *pt_output = rgba;
2859 while(pt_input != pt_end) {
2860 *(pt_output++) = *(pt_input++) ;
2861 *(pt_output++) = *(pt_input++) ;
2862 *(pt_output++) = *(pt_input++) ;
2863 *(pt_output++) = 0 ;
2874 unsigned char *pt_input = rgba;
2875 unsigned char *pt_end = rgba + 4*size;
2876 unsigned char *pt_output = rgb;
2878 while(pt_input != pt_end) {
2879 *(pt_output++) = *(pt_input++) ;
2880 *(pt_output++) = *(pt_input++) ;
2881 *(pt_output++) = *(pt_input++) ;
2893 unsigned char *pt_input = rgb;
2894 unsigned char* pt_end = rgb + size*3;
2895 unsigned char *pt_output = grey;
2896 while(pt_input != pt_end) {
2897 *pt_output = (
unsigned char) (0.2126 * (*pt_input)
2898 + 0.7152 * (*(pt_input + 1))
2899 + 0.0722 * (*(pt_input + 2)) );
2913 unsigned char *pt_input = rgba;
2914 unsigned char* pt_end = rgba + size*4;
2915 unsigned char *pt_output = grey;
2917 while(pt_input != pt_end) {
2918 *pt_output = (
unsigned char) (0.2126 * (*pt_input)
2919 + 0.7152 * (*(pt_input + 1))
2920 + 0.0722 * (*(pt_input + 2)) );
2933 unsigned char *pt_input = grey;
2934 unsigned char *pt_end = grey + size;
2935 unsigned char *pt_output = rgba;
2937 while(pt_input != pt_end) {
2938 unsigned char p = *pt_input ;
2940 *(pt_output + 1) = p ;
2941 *(pt_output + 2) = p ;
2942 *(pt_output + 3) = p ;
2956 unsigned char *pt_input = grey;
2957 unsigned char* pt_end = grey + size;
2958 unsigned char *pt_output = rgb;
2960 while(pt_input != pt_end) {
2961 unsigned char p = *pt_input ;
2963 *(pt_output + 1) = p ;
2964 *(pt_output + 2) = p ;
2979 unsigned int width,
unsigned int height,
bool flip)
2983 int lineStep = (flip) ? -(
int)(width*3) : (
int)(width*3);
2986 unsigned char * src = (flip) ? (bgr+(width*height*3)+lineStep) : bgr;
2987 unsigned char * line;
2992 for(i=0 ; i < height ; i++)
2995 for( j=0 ; j < width ; j++)
2997 *rgba++ = *(line+2);
2998 *rgba++ = *(line+1);
2999 *rgba++ = *(line+0);
3017 unsigned int width,
unsigned int height,
bool flip)
3021 int lineStep = (flip) ? -(
int)(width*3) : (
int)(width*3);
3024 unsigned char * src = (flip) ? bgr+(width*height*3)+lineStep : bgr;
3025 unsigned char * line;
3030 for(i=0 ; i < height ; i++)
3033 for( j=0 ; j < width ; j++)
3035 *grey++ = (
unsigned char)( 0.2126 * *(line+2)
3036 + 0.7152 * *(line+1)
3037 + 0.0722 * *(line+0)) ;
3052 unsigned int width,
unsigned int height,
bool flip)
3056 int lineStep = (flip) ? -(
int)(width*3) : (
int)(width*3);
3059 unsigned char * src = (flip) ? (rgb+(width*height*3)+lineStep) : rgb;
3060 unsigned char * line;
3065 for(i=0 ; i < height ; i++)
3068 for( j=0 ; j < width ; j++)
3070 *rgba++ = *(line++);
3071 *rgba++ = *(line++);
3072 *rgba++ = *(line++);
3087 unsigned int width,
unsigned int height,
bool flip)
3091 int lineStep = (flip) ? -(
int)(width*3) : (
int)(width*3);
3094 unsigned char * src = (flip) ? rgb+(width*height*3)+lineStep : rgb;
3095 unsigned char * line;
3102 for(i=0 ; i < height ; i++)
3105 for( j=0 ; j < width ; j++)
3110 *grey++ = (
unsigned char)( 0.2126 * r + 0.7152 * g + 0.0722 * b) ;
3123 void vpImageConvert::computeYCbCrLUT()
3125 if (YCbCrLUTcomputed ==
false) {
3126 int index = 256, aux;
3131 vpImageConvert::vpCrr[index] = (int)( 364.6610 * aux) >> 8;
3132 vpImageConvert::vpCgb[index] = (int)( -89.8779 * aux) >> 8;
3133 vpImageConvert::vpCgr[index] = (int)(-185.8154 * aux) >> 8;
3134 vpImageConvert::vpCbb[index] = (int)( 460.5724 * aux) >> 8;
3137 YCbCrLUTcomputed =
true;
3165 unsigned char *pt_ycbcr = ycbcr;
3166 unsigned char *pt_rgb = rgb;
3170 vpImageConvert::computeYCbCrLUT();
3175 register int val_r, val_g, val_b;
3181 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3182 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3183 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3185 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3187 *pt_rgb++ = (val_r < 0) ? 0u :
3188 ((val_r > 255) ? 255u : (
unsigned char)val_r);
3189 *pt_rgb++ = (val_g < 0) ? 0u :
3190 ((val_g > 255) ? 255u : (
unsigned char)val_g);
3191 *pt_rgb++ = (val_b < 0) ? 0u :
3192 ((val_b > 255) ? 255u : (
unsigned char)val_b);
3223 unsigned char *pt_ycbcr = ycbcr;
3224 unsigned char *pt_rgba = rgba;
3228 vpImageConvert::computeYCbCrLUT();
3233 register int val_r, val_g, val_b;
3239 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3240 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3241 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3243 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3245 *pt_rgba++ = (val_r < 0) ? 0u :
3246 ((val_r > 255) ? 255u : (
unsigned char)val_r);
3247 *pt_rgba++ = (val_g < 0) ? 0u :
3248 ((val_g > 255) ? 255u : (
unsigned char)val_g);
3249 *pt_rgba++ = (val_b < 0) ? 0u :
3250 ((val_b > 255) ? 255u : (
unsigned char)val_b);
3276 unsigned int i=0,j=0;
3281 grey[i++] = yuv[j+2];
3308 unsigned char *pt_ycbcr = ycrcb;
3309 unsigned char *pt_rgb = rgb;
3313 vpImageConvert::computeYCbCrLUT();
3318 register int val_r, val_g, val_b;
3324 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3325 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3326 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3328 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3330 *pt_rgb++ = (val_r < 0) ? 0u :
3331 ((val_r > 255) ? 255u : (
unsigned char)val_r);
3332 *pt_rgb++ = (val_g < 0) ? 0u :
3333 ((val_g > 255) ? 255u : (
unsigned char)val_g);
3334 *pt_rgb++ = (val_b < 0) ? 0u :
3335 ((val_b > 255) ? 255u : (
unsigned char)val_b);
3364 unsigned char *pt_ycbcr = ycrcb;
3365 unsigned char *pt_rgba = rgba;
3369 vpImageConvert::computeYCbCrLUT();
3374 register int val_r, val_g, val_b;
3380 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3381 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3382 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3384 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3386 *pt_rgba++ = (val_r < 0) ? 0u :
3387 ((val_r > 255) ? 255u : (
unsigned char)val_r);
3388 *pt_rgba++ = (val_g < 0) ? 0u :
3389 ((val_g > 255) ? 255u : (
unsigned char)val_g);
3390 *pt_rgba++ = (val_b < 0) ? 0u :
3391 ((val_b > 255) ? 255u : (
unsigned char)val_b);
3441 unsigned int width = src.
getWidth();
3442 unsigned char* input;
3443 unsigned char* dst ;
3459 for(
unsigned int j = 0;j < 4;j++){
3460 if(tabChannel[j]!=NULL){
3461 if(tabChannel[j]->getHeight() != height ||
3462 tabChannel[j]->getWidth() != width){
3463 tabChannel[j]->
resize(height,width);
3465 dst = (
unsigned char*)tabChannel[j]->bitmap;
3467 input = (
unsigned char*)src.
bitmap+j;
3472 for (; i < n; i += 4) {
3473 *dst = *input; input += 4; dst++;
3474 *dst = *input; input += 4; dst++;
3475 *dst = *input; input += 4; dst++;
3476 *dst = *input; input += 4; dst++;
3481 for (; i < n; i++) {
3482 *dst = *input; input += 4; dst ++;
3500 register int i = (((int)size)<<1)-1;
3501 register int j = (int)size-1;
3506 grey[j--] =
static_cast<unsigned char>( (y+(grey16[i--]<<8))>>8 );
3522 register int i = (((int)size)<<1)-1;
3523 register int j = (int)(size*4-1);
3525 register unsigned char v;
3529 v =
static_cast<unsigned char>( (y+(grey16[i--]<<8))>>8 );
unsigned int getCols() const
static void YUYVToRGBa(unsigned char *yuyv, unsigned char *rgba, unsigned int width, unsigned int height)
static void RGBToGrey(unsigned char *rgb, unsigned char *grey, unsigned int size)
unsigned int getWidth() const
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
void getMinMaxValue(Type &min, Type &max) const
Look for the minimum and the maximum value within the bitmap.
unsigned char B
Blue component.
static void RGBToRGBa(unsigned char *rgb, unsigned char *rgba, unsigned int size)
Type * bitmap
points toward the bitmap
static void MONO16ToGrey(unsigned char *grey16, unsigned char *grey, unsigned int size)
static void YUV422ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int size)
static void YUV420ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
static void GreyToRGBa(unsigned char *grey, unsigned char *rgba, unsigned int size)
static void YUV422ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int size)
static void YCbCrToRGB(unsigned char *ycbcr, unsigned char *rgb, unsigned int size)
static void YUV411ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int size)
static void split(const vpImage< vpRGBa > &src, vpImage< unsigned char > *pR, vpImage< unsigned char > *pG, vpImage< unsigned char > *pB, vpImage< unsigned char > *pa=NULL)
static void YUVToRGB(unsigned char y, unsigned char u, unsigned char v, unsigned char &r, unsigned char &g, unsigned char &b)
unsigned char G
Green component.
static void GreyToRGB(unsigned char *grey, unsigned char *rgb, unsigned int size)
Class that defines a RGB 32 bits structure.
static void YUV444ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int size)
static void YUV420ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int width, unsigned int height)
static void YVU9ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int width, unsigned int height)
static void YUV422ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
unsigned int getRows() const
static void YVU9ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int width, unsigned int height)
static void YV12ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int width, unsigned int height)
static void YCbCrToGrey(unsigned char *ycbcr, unsigned char *grey, unsigned int size)
unsigned char A
Additionnal component.
static void YUYVToGrey(unsigned char *yuyv, unsigned char *grey, unsigned int size)
static void MONO16ToRGBa(unsigned char *grey16, unsigned char *rgba, unsigned int size)
unsigned int getNumberOfPixel() const
void resize(const unsigned int h, const unsigned int w)
set the size of the image
static void YUYVToRGB(unsigned char *yuyv, unsigned char *rgb, unsigned int width, unsigned int height)
static void YUV444ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int size)
static void YUV444ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
static void YUV411ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int size)
unsigned char R
Red component.
static void BGRToGrey(unsigned char *bgr, unsigned char *grey, unsigned int width, unsigned int height, bool flip)
unsigned int getHeight() const
static void YCbCrToRGBa(unsigned char *ycbcr, unsigned char *rgb, unsigned int size)
static void YUV411ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
static void RGBaToRGB(unsigned char *rgba, unsigned char *rgb, unsigned int size)
static void YCrCbToRGB(unsigned char *ycbcr, unsigned char *rgb, unsigned int size)
static void YCrCbToRGBa(unsigned char *ycbcr, unsigned char *rgb, unsigned int size)
static void RGBaToGrey(unsigned char *rgba, unsigned char *grey, unsigned int size)
static void BGRToRGBa(unsigned char *bgr, unsigned char *rgba, unsigned int width, unsigned int height, bool flip)
static void YV12ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int width, unsigned int height)
static void YUV420ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int width, unsigned int height)