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];
108 for (
unsigned int i = 0; i < max_xy; i++) {
109 float val = 255.f * (src.
bitmap[i] - min) / (max - min);
115 dest.
bitmap[i] = (int)val;
148 for (
unsigned int i = 0; i < max_xy; i++) {
149 double val = 255. * (src.
bitmap[i] - min) / (max - min);
155 dest.
bitmap[i] = (int)val;
173 #ifdef VISP_HAVE_OPENCV
217 int nChannel = src->nChannels;
218 int depth = src->depth;
219 int height = src->height;
220 int width = src->width;
221 int widthStep = src->widthStep;
222 int lineStep = (flip) ? 1 : 0;
224 if(nChannel == 3 && depth == 8){
225 dest.
resize((
unsigned int)height, (
unsigned int)width);
228 unsigned char* input = (
unsigned char*)src->imageData;
230 unsigned char* beginOutput = (
unsigned char*)dest.
bitmap;
231 unsigned char* output = NULL;
233 for(
int i=0 ; i < height ; i++)
236 output = beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) + (1-lineStep) * 4 * width * i;
237 for(
int j=0 ; j < width ; j++)
239 *(output++) = *(line+2);
240 *(output++) = *(line+1);
241 *(output++) = *(line);
250 else if(nChannel == 1 && depth == 8 ){
251 dest.
resize((
unsigned int)height, (
unsigned int)width);
253 unsigned char * input = (
unsigned char*)src->imageData;
254 unsigned char * line;
255 unsigned char* beginOutput = (
unsigned char*)dest.
bitmap;
256 unsigned char* output = NULL;
258 for(
int i=0 ; i < height ; i++)
261 output = beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) + (1-lineStep) * 4 * width * i;
262 for(
int j=0 ; j < width ; j++)
267 *output++ = *(line);;
321 int nChannel = src->nChannels;
322 int depth = src->depth;
323 int height = src->height;
324 int width = src->width;
325 int widthStep = src->widthStep;
326 int lineStep = (flip) ? 1 : 0;
330 if(widthStep == width){
331 if(nChannel == 1 && depth == 8){
332 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
333 memcpy(dest.
bitmap, src->imageData,
334 (
size_t)(height*width));
336 if(nChannel == 3 && depth == 8){
337 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
338 BGRToGrey((
unsigned char*)src->imageData,dest.
bitmap, (
unsigned int)width, (
unsigned int)height,
false);
342 if(nChannel == 1 && depth == 8){
343 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
344 for (
int i =0 ; i < height ; i++){
345 memcpy(dest.
bitmap+i*width, src->imageData + i*widthStep,
349 if(nChannel == 3 && depth == 8){
350 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
351 for (
int i = 0 ; i < height ; i++){
352 BGRToGrey((
unsigned char*)src->imageData + i*widthStep,
353 dest.
bitmap + i*width, (
unsigned int)width, 1,
false);
360 if(nChannel == 1 && depth == 8){
361 unsigned char* beginOutput = (
unsigned char*)dest.
bitmap;
362 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
363 for (
int i =0 ; i < height ; i++){
364 memcpy(beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) , src->imageData + i*widthStep,
368 if(nChannel == 3 && depth == 8){
369 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
371 BGRToGrey((
unsigned char*)src->imageData ,
372 dest.
bitmap , (
unsigned int)width, (
unsigned int)height,
true);
424 CvSize size = cvSize(width, height);
428 if(dest->nChannels != channels || dest->depth != depth
429 || dest->height != height || dest->width != width){
430 if(dest->nChannels != 0) cvReleaseImage(&dest);
431 dest = cvCreateImage( size, depth, channels );
434 else dest = cvCreateImage( size, depth, channels );
438 unsigned char * input = (
unsigned char*)src.
bitmap;
439 unsigned char * line;
440 unsigned char * output = (
unsigned char*)dest->imageData;
444 int widthStep = dest->widthStep;
446 for(i=0 ; i < height ; i++)
448 output = (
unsigned char*)dest->imageData + i*widthStep;
450 for( j=0 ; j < width ; j++)
452 *output++ = *(line+2);
453 *output++ = *(line+1);
509 unsigned int width = src.
getWidth();
510 CvSize size = cvSize((
int)width, (
int)height);
514 if(dest->nChannels != channels || dest->depth != depth
515 || dest->height != (
int) height || dest->width != (
int) width){
516 if(dest->nChannels != 0) cvReleaseImage(&dest);
517 dest = cvCreateImage( size, depth, channels );
520 else dest = cvCreateImage( size, depth, channels );
522 unsigned int widthStep = (
unsigned int)dest->widthStep;
524 if ( width == widthStep){
525 memcpy(dest->imageData,src.
bitmap, width*height);
529 for (
unsigned int i =0 ; i < height ; i++){
530 memcpy(dest->imageData + i*widthStep, src.
bitmap + i*width,
536 #if VISP_HAVE_OPENCV_VERSION >= 0x020100
583 if(src.type() == CV_8UC4){
584 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
586 for(
unsigned int i=0; i<dest.
getRows(); ++i)
587 for(
unsigned int j=0; j<dest.
getCols(); ++j){
588 cv::Vec4b tmp = src.at<cv::Vec4b>((int)i, (
int)j);
594 dest[dest.
getRows()-i-1][j] = rgbaVal;
596 dest[i][j] = rgbaVal;
598 }
else if(src.type() == CV_8UC3){
599 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
602 for(
unsigned int i=0; i<dest.
getRows(); ++i){
603 for(
unsigned int j=0; j<dest.
getCols(); ++j){
604 cv::Vec3b tmp = src.at<cv::Vec3b>((int)i, (
int)j);
609 dest[dest.
getRows()-i-1][j] = rgbaVal;
611 dest[i][j] = rgbaVal;
615 }
else if(src.type() == CV_8UC1){
616 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
618 for(
unsigned int i=0; i<dest.
getRows(); ++i){
619 for(
unsigned int j=0; j<dest.
getCols(); ++j){
620 rgbaVal = src.at<
unsigned char>((int)i, (
int)j);
622 dest[dest.
getRows()-i-1][j] = rgbaVal;
624 dest[i][j] = rgbaVal;
677 if(src.type() == CV_8UC1){
678 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
679 if(src.isContinuous() && !flip){
680 memcpy(dest.
bitmap, src.data, (
size_t)(src.rows*src.cols));
684 for(
unsigned int i=0; i<dest.
getRows(); ++i){
685 memcpy(dest.
bitmap+i*dest.
getCols(), src.data+(dest.
getRows()-i-1)*src.step1(), (size_t)src.step);
688 for(
unsigned int i=0; i<dest.
getRows(); ++i){
689 memcpy(dest.
bitmap+i*dest.
getCols(), src.data+i*src.step1(), (size_t)src.step);
693 }
else if(src.type() == CV_8UC3){
694 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
695 if(src.isContinuous() && !flip){
696 BGRToGrey((
unsigned char*)src.data, (
unsigned char*)dest.
bitmap, (
unsigned int)src.cols, (
unsigned int)src.rows, flip);
700 for(
unsigned int i=0; i<dest.
getRows(); ++i){
701 BGRToGrey((
unsigned char*)src.data+i*src.step1(),
703 (
unsigned int)dest.
getCols(), 1,
false);
706 for(
unsigned int i=0; i<dest.
getRows(); ++i){
707 BGRToGrey((
unsigned char*)src.data+i*src.step1(),
709 (
unsigned int)dest.
getCols(), 1,
false);
765 cv::Mat out[] = {dest, alpha};
766 int from_to[] = { 0,2, 1,1, 2,0, 3,3 };
767 cv::mixChannels(&vpToMat, 1, out, 2, from_to, 4);
813 cv::Mat& dest,
const bool copyData)
817 dest = tmpMap.clone();
826 #ifdef VISP_HAVE_YARP
860 yarp::sig::ImageOf< yarp::sig::PixelMono > *dest,
const bool copyData)
910 dest.
resize(src->height(),src->width());
912 memcpy(dest.
bitmap, src->getRawImage(), src->height()*src->width()*
sizeof(yarp::sig::PixelMono));
914 dest.
bitmap = src->getRawImage();
951 yarp::sig::ImageOf< yarp::sig::PixelRgba > *dest,
const bool copyData)
1001 dest.
resize(src->height(),src->width());
1003 memcpy(dest.
bitmap, src->getRawImage(),src->height()*src->width()*
sizeof(yarp::sig::PixelRgba));
1041 yarp::sig::ImageOf< yarp::sig::PixelRgb > *dest)
1044 for(
unsigned int i = 0 ; i < src.
getRows() ; i++){
1045 for(
unsigned int j = 0 ; j < src.
getWidth() ; j++){
1046 dest->pixel(j,i).r = src[i][j].R;
1047 dest->pixel(j,i).g = src[i][j].G;
1048 dest->pixel(j,i).b = src[i][j].B;
1092 dest.
resize(src->height(),src->width());
1093 for(
int i = 0 ; i < src->height() ; i++){
1094 for(
int j = 0 ; j < src->width() ; j++){
1095 dest[i][j].R = src->pixel(j,i).r;
1096 dest[i][j].G = src->pixel(j,i).g;
1097 dest[i][j].B = src->pixel(j,i).b;
1105 #if defined(VISP_HAVE_LIBJPEG)
1106 #if JPEG_LIB_VERSION > 70
1116 unsigned char **dest,
long unsigned int &destSize,
int quality)
1118 struct jpeg_compress_struct cinfo;
1119 struct jpeg_error_mgr jerr;
1121 cinfo.err = jpeg_std_error(&jerr);
1122 jpeg_create_compress(&cinfo);
1127 jpeg_mem_dest(&cinfo, dest, &destSize);
1129 unsigned int width = src.
getWidth();
1132 cinfo.image_width = width;
1133 cinfo.image_height = height;
1134 cinfo.input_components = 1;
1135 cinfo.in_color_space = JCS_GRAYSCALE;
1136 jpeg_set_defaults(&cinfo);
1137 jpeg_set_quality(&cinfo, quality, TRUE);
1139 jpeg_start_compress(&cinfo,TRUE);
1141 unsigned char *line;
1142 line =
new unsigned char[width];
1143 unsigned char* input = (
unsigned char*)src.
bitmap;
1144 while (cinfo.next_scanline < cinfo.image_height)
1146 for (
unsigned int i = 0; i < width; i++)
1151 jpeg_write_scanlines(&cinfo, &line, 1);
1154 jpeg_finish_compress(&cinfo);
1155 jpeg_destroy_compress(&cinfo);
1166 void vpImageConvert::convertToJPEGBuffer(
unsigned char *src,
long unsigned int srcSize,
1169 struct jpeg_decompress_struct cinfo;
1170 struct jpeg_error_mgr jerr;
1172 cinfo.err = jpeg_std_error(&jerr);
1173 jpeg_create_decompress(&cinfo);
1175 jpeg_mem_src(&cinfo, src, srcSize);
1176 jpeg_read_header(&cinfo, TRUE);
1178 unsigned int width = cinfo.image_width;
1179 unsigned int height = cinfo.image_height;
1182 dest.
resize(height,width);
1184 jpeg_start_decompress(&cinfo);
1186 unsigned int rowbytes = cinfo.output_width * (
unsigned int)(cinfo.output_components);
1187 JSAMPARRAY buf = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, rowbytes, 1);
1189 if (cinfo.out_color_space == JCS_GRAYSCALE)
1192 while (cinfo.output_scanline<cinfo.output_height)
1194 row = cinfo.output_scanline;
1195 jpeg_read_scanlines(&cinfo,buf,1);
1196 memcpy(dest[row], buf[0], rowbytes);
1200 jpeg_finish_decompress(&cinfo);
1201 jpeg_destroy_decompress(&cinfo);
1204 #endif // defined(VISP_HAVE_LIBJPEG)
1208 if (c & (~255)) { if (c < 0) c = 0; else c = 255; }
1216 unsigned int width,
unsigned int height)
1221 int r, g, b, cr, cg, cb, y1, y2;
1231 cb = ((*s - 128) * 454) >> 8;
1232 cg = (*s++ - 128) * 88;
1234 cr = ((*s - 128) * 359) >> 8;
1235 cg = (cg + (*s++ - 128) * 183) >> 8;
1244 *d++ =
static_cast<unsigned char>(r);
1245 *d++ =
static_cast<unsigned char>(g);
1246 *d++ =
static_cast<unsigned char>(b);
1256 *d++ =
static_cast<unsigned char>(r);
1257 *d++ =
static_cast<unsigned char>(g);
1258 *d++ =
static_cast<unsigned char>(b);
1272 unsigned int width,
unsigned int height)
1277 int r, g, b, cr, cg, cb, y1, y2;
1287 cb = ((*s - 128) * 454) >> 8;
1288 cg = (*s++ - 128) * 88;
1290 cr = ((*s - 128) * 359) >> 8;
1291 cg = (cg + (*s++ - 128) * 183) >> 8;
1300 *d++ =
static_cast<unsigned char>(r);
1301 *d++ =
static_cast<unsigned char>(g);
1302 *d++ =
static_cast<unsigned char>(b);
1311 *d++ =
static_cast<unsigned char>(r);
1312 *d++ =
static_cast<unsigned char>(g);
1313 *d++ =
static_cast<unsigned char>(b);
1327 unsigned int i=0,j=0;
1331 grey[i++] = yuyv[j];
1332 grey[i++] = yuyv[j+2];
1345 unsigned char* rgba,
1350 register int U, V, R, G, B, V2, U5, UV;
1351 register int Y0, Y1, Y2, Y3;
1352 for(
unsigned int i = size / 4; i; i--) {
1353 U = (int)((*yuv++ - 128) * 0.354);
1357 V = (int)((*yuv++ - 128) * 0.707);
1368 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1371 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1374 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1376 *rgba++ = (
unsigned char)R;
1377 *rgba++ = (
unsigned char)G;
1378 *rgba++ = (
unsigned char)B;
1383 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1386 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1389 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1391 *rgba++ = (
unsigned char)R;
1392 *rgba++ = (
unsigned char)G;
1393 *rgba++ = (
unsigned char)B;
1398 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1401 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1404 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1406 *rgba++ = (
unsigned char)R;
1407 *rgba++ = (
unsigned char)G;
1408 *rgba++ = (
unsigned char)B;
1413 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1416 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1419 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1421 *rgba++ = (
unsigned char)R;
1422 *rgba++ = (
unsigned char)G;
1423 *rgba++ = (
unsigned char)B;
1428 unsigned int i=0,j=0;
1429 unsigned char r, g, b;
1430 while( j < numpixels*3/2)
1433 YUVToRGB (yuv[j+1], yuv[j], yuv[j+3], r, g, b);
1440 YUVToRGB (yuv[j+2], yuv[j], yuv[j+3], r, g, b);
1447 YUVToRGB (yuv[j+4], yuv[j], yuv[j+3], r, g, b);
1454 YUVToRGB (yuv[j+5], yuv[j], yuv[j+3], r, g, b);
1474 unsigned char* rgba,
1480 register int U, V, R, G, B, V2, U5, UV;
1481 register int Y0, Y1;
1482 for(
unsigned int i = size / 2; i; i-- ) {
1483 U = (int)((*yuv++ - 128) * 0.354);
1486 V = (int)((*yuv++ - 128) * 0.707);
1493 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1496 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1499 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1501 *rgba++ = (
unsigned char)R;
1502 *rgba++ = (
unsigned char)G;
1503 *rgba++ = (
unsigned char)B;
1508 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1511 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1514 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1516 *rgba++ = (
unsigned char)R;
1517 *rgba++ = (
unsigned char)G;
1518 *rgba++ = (
unsigned char)B;
1524 unsigned int i=0,j=0;
1525 unsigned char r, g, b;
1530 YUVToRGB (yuv[j+1], yuv[j], yuv[j+2], r, g, b);
1537 YUVToRGB (yuv[j+3], yuv[j], yuv[j+2], r, g, b);
1556 unsigned char* grey,
1561 unsigned int i=0,j=0;
1562 while( j < size*3/2)
1565 grey[i ] = yuv[j+1];
1566 grey[i+1] = yuv[j+2];
1567 grey[i+2] = yuv[j+4];
1568 grey[i+3] = yuv[j+5];
1590 register int U, V, R, G, B, V2, U5, UV;
1591 register int Y0, Y1;
1592 for(
unsigned int i = size / 2; i; i-- ) {
1593 U = (int)((*yuv++ - 128) * 0.354);
1596 V = (int)((*yuv++ - 128) * 0.707);
1603 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1606 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1609 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1611 *rgb++ = (
unsigned char)R;
1612 *rgb++ = (
unsigned char)G;
1613 *rgb++ = (
unsigned char)B;
1617 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1620 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1623 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1625 *rgb++ = (
unsigned char)R;
1626 *rgb++ = (
unsigned char)G;
1627 *rgb++ = (
unsigned char)B;
1633 unsigned int i=0,j=0;
1634 unsigned char r, g, b;
1639 YUVToRGB (yuv[j+1], yuv[j], yuv[j+2], r, g, b);
1645 YUVToRGB (yuv[j+3], yuv[j], yuv[j+2], r, g, b);
1665 unsigned char* grey,
1668 unsigned int i=0,j=0;
1672 grey[i++] = yuv[j+1];
1673 grey[i++] = yuv[j+3];
1690 register int U, V, R, G, B, V2, U5, UV;
1691 register int Y0, Y1, Y2, Y3;
1692 for(
unsigned int i = size / 4; i; i--) {
1693 U = (int)((*yuv++ - 128) * 0.354);
1697 V = (int)((*yuv++ - 128) * 0.707);
1708 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1711 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1714 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1716 *rgb++ = (
unsigned char)R;
1717 *rgb++ = (
unsigned char)G;
1718 *rgb++ = (
unsigned char)B;
1722 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1725 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1728 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1730 *rgb++ = (
unsigned char)R;
1731 *rgb++ = (
unsigned char)G;
1732 *rgb++ = (
unsigned char)B;
1736 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1739 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1742 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1744 *rgb++ = (
unsigned char)R;
1745 *rgb++ = (
unsigned char)G;
1746 *rgb++ = (
unsigned char)B;
1750 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1753 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1756 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1758 *rgb++ = (
unsigned char)R;
1759 *rgb++ = (
unsigned char)G;
1760 *rgb++ = (
unsigned char)B;
1765 unsigned int i=0,j=0;
1766 unsigned char r, g, b;
1768 while( j < size*3/2)
1770 YUVToRGB (yuv[j+1], yuv[j], yuv[j+3], r, g, b);
1776 YUVToRGB (yuv[j+2], yuv[j], yuv[j+3], r, g, b);
1782 YUVToRGB (yuv[j+4], yuv[j], yuv[j+3], r, g, b);
1788 YUVToRGB (yuv[j+5], yuv[j], yuv[j+3], r, g, b);
1810 unsigned char* rgba,
1811 unsigned int width,
unsigned int height)
1814 register int U, V, R, G, B, V2, U5, UV;
1815 register int Y0, Y1, Y2, Y3;
1816 unsigned int size = width*height;
1817 unsigned char* iU = yuv + size;
1818 unsigned char* iV = yuv + 5*size/4;
1819 for(
unsigned int i = 0; i<height/2; i++)
1821 for(
unsigned int j = 0; j < width/2 ; j++)
1823 U = (int)((*iU++ - 128) * 0.354);
1825 V = (int)((*iV++ - 128) * 0.707);
1840 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1843 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1846 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1848 *rgba++ = (
unsigned char)R;
1849 *rgba++ = (
unsigned char)G;
1850 *rgba++ = (
unsigned char)B;
1855 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1858 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1861 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1863 *rgba++ = (
unsigned char)R;
1864 *rgba++ = (
unsigned char)G;
1865 *rgba++ = (
unsigned char)B;
1867 rgba = rgba + 4*width-7;
1871 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1874 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1877 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1879 *rgba++ = (
unsigned char)R;
1880 *rgba++ = (
unsigned char)G;
1881 *rgba++ = (
unsigned char)B;
1886 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1889 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1892 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1894 *rgba++ = (
unsigned char)R;
1895 *rgba++ = (
unsigned char)G;
1896 *rgba++ = (
unsigned char)B;
1898 rgba = rgba -4*width+1;
1912 unsigned int width,
unsigned int height)
1915 register int U, V, R, G, B, V2, U5, UV;
1916 register int Y0, Y1, Y2, Y3;
1917 unsigned int size = width*height;
1918 unsigned char* iU = yuv + size;
1919 unsigned char* iV = yuv + 5*size/4;
1920 for(
unsigned int i = 0; i<height/2; i++)
1922 for(
unsigned int j = 0; j < width/2 ; j++)
1924 U = (int)((*iU++ - 128) * 0.354);
1926 V = (int)((*iV++ - 128) * 0.707);
1941 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1944 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1947 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1949 *rgb++ = (
unsigned char)R;
1950 *rgb++ = (
unsigned char)G;
1951 *rgb++ = (
unsigned char)B;
1955 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1958 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1961 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1963 *rgb++ = (
unsigned char)R;
1964 *rgb++ = (
unsigned char)G;
1965 *rgb = (
unsigned char)B;
1966 rgb = rgb + 3*width-5;
1970 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1973 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1976 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1978 *rgb++ = (
unsigned char)R;
1979 *rgb++ = (
unsigned char)G;
1980 *rgb++ = (
unsigned char)B;
1984 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1987 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1990 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1992 *rgb++ = (
unsigned char)R;
1993 *rgb++ = (
unsigned char)G;
1994 *rgb = (
unsigned char)B;
1995 rgb = rgb -3*width+1;
2009 unsigned char* grey,
2012 for(
unsigned int i=0 ; i < size ; i++)
2025 unsigned char* rgba,
2028 register int U, V, R, G, B, V2, U5, UV;
2030 for(
unsigned int i = 0; i<size; i++)
2032 U = (int)((*yuv++ - 128) * 0.354);
2035 V = (int)((*yuv++ - 128) * 0.707);
2045 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2048 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2051 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2053 *rgba++ = (
unsigned char)R;
2054 *rgba++ = (
unsigned char)G;
2055 *rgba++ = (
unsigned char)B;
2069 register int U, V, R, G, B, V2, U5, UV;
2071 for(
unsigned int i = 0; i<size; i++)
2074 U = (int)((*yuv++ - 128) * 0.354);
2077 V = (int)((*yuv++ - 128) * 0.707);
2086 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2089 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2092 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2094 *rgb++ = (
unsigned char)R;
2095 *rgb++ = (
unsigned char)G;
2096 *rgb++ = (
unsigned char)B;
2107 unsigned char* grey,
2111 for(
unsigned int i=0 ; i < size ; i++)
2125 unsigned char* rgba,
2126 unsigned int width,
unsigned int height)
2129 register int U, V, R, G, B, V2, U5, UV;
2130 register int Y0, Y1, Y2, Y3;
2131 unsigned int size = width*height;
2132 unsigned char* iV = yuv + size;
2133 unsigned char* iU = yuv + 5*size/4;
2134 for(
unsigned int i = 0; i<height/2; i++)
2136 for(
unsigned int j = 0; j < width/2 ; j++)
2138 U = (int)((*iU++ - 128) * 0.354);
2140 V = (int)((*iV++ - 128) * 0.707);
2155 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2158 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2161 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2163 *rgba++ = (
unsigned char)R;
2164 *rgba++ = (
unsigned char)G;
2165 *rgba++ = (
unsigned char)B;
2170 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2173 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2176 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2178 *rgba++ = (
unsigned char)R;
2179 *rgba++ = (
unsigned char)G;
2180 *rgba++ = (
unsigned char)B;
2182 rgba = rgba + 4*width-7;
2186 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2189 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2192 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2194 *rgba++ = (
unsigned char)R;
2195 *rgba++ = (
unsigned char)G;
2196 *rgba++ = (
unsigned char)B;
2201 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2204 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2207 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2209 *rgba++ = (
unsigned char)R;
2210 *rgba++ = (
unsigned char)G;
2211 *rgba++ = (
unsigned char)B;
2213 rgba = rgba -4*width+1;
2227 unsigned int height,
unsigned int width)
2230 register int U, V, R, G, B, V2, U5, UV;
2231 register int Y0, Y1, Y2, Y3;
2232 unsigned int size = width*height;
2233 unsigned char* iV = yuv + size;
2234 unsigned char* iU = yuv + 5*size/4;
2235 for(
unsigned int i = 0; i<height/2; i++)
2237 for(
unsigned int j = 0; j < width/2 ; j++)
2239 U = (int)((*iU++ - 128) * 0.354);
2241 V = (int)((*iV++ - 128) * 0.707);
2256 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2259 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2262 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2264 *rgb++ = (
unsigned char)R;
2265 *rgb++ = (
unsigned char)G;
2266 *rgb++ = (
unsigned char)B;
2270 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2273 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2276 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2278 *rgb++ = (
unsigned char)R;
2279 *rgb++ = (
unsigned char)G;
2280 *rgb = (
unsigned char)B;
2281 rgb = rgb + 3*width-5;
2285 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2288 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2291 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2293 *rgb++ = (
unsigned char)R;
2294 *rgb++ = (
unsigned char)G;
2295 *rgb++ = (
unsigned char)B;
2299 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2302 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2305 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2307 *rgb++ = (
unsigned char)R;
2308 *rgb++ = (
unsigned char)G;
2309 *rgb = (
unsigned char)B;
2310 rgb = rgb -3*width+1;
2324 unsigned char* rgba,
2325 unsigned int width,
unsigned int height)
2328 register int U, V, R, G, B, V2, U5, UV;
2329 register int Y0, Y1, Y2, Y3,Y4, Y5, Y6, Y7,Y8, Y9, Y10, Y11,Y12, Y13, Y14, Y15;
2330 unsigned int size = width*height;
2331 unsigned char* iV = yuv + size;
2332 unsigned char* iU = yuv + 17*size/16;
2333 for(
unsigned int i = 0; i<height/4; i++)
2335 for(
unsigned int j = 0; j < width/4 ; j++)
2337 U = (int)((*iU++ - 128) * 0.354);
2339 V = (int)((*iV++ - 128) * 0.707);
2361 yuv = yuv-3*width+1;
2368 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2371 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2374 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2376 *rgba++ = (
unsigned char)R;
2377 *rgba++ = (
unsigned char)G;
2378 *rgba++ = (
unsigned char)B;
2383 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2386 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2389 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2391 *rgba++ = (
unsigned char)R;
2392 *rgba++ = (
unsigned char)G;
2393 *rgba++ = (
unsigned char)B;
2398 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2401 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2404 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2406 *rgba++ = (
unsigned char)R;
2407 *rgba++ = (
unsigned char)G;
2408 *rgba++ = (
unsigned char)B;
2413 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2416 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2419 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2421 *rgba++ = (
unsigned char)R;
2422 *rgba++ = (
unsigned char)G;
2423 *rgba++ = (
unsigned char)B;
2425 rgba = rgba + 4*width-15;
2428 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2431 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2434 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2436 *rgba++ = (
unsigned char)R;
2437 *rgba++ = (
unsigned char)G;
2438 *rgba++ = (
unsigned char)B;
2443 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2446 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2449 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2451 *rgba++ = (
unsigned char)R;
2452 *rgba++ = (
unsigned char)G;
2453 *rgba++ = (
unsigned char)B;
2458 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2461 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2464 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2466 *rgba++ = (
unsigned char)R;
2467 *rgba++ = (
unsigned char)G;
2468 *rgba++ = (
unsigned char)B;
2473 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2476 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2479 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2481 *rgba++ = (
unsigned char)R;
2482 *rgba++ = (
unsigned char)G;
2483 *rgba++ = (
unsigned char)B;
2485 rgba = rgba + 4*width-15;
2488 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2491 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2494 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2496 *rgba++ = (
unsigned char)R;
2497 *rgba++ = (
unsigned char)G;
2498 *rgba++ = (
unsigned char)B;
2503 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2506 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2509 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2511 *rgba++ = (
unsigned char)R;
2512 *rgba++ = (
unsigned char)G;
2513 *rgba++ = (
unsigned char)B;
2518 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2521 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2524 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2526 *rgba++ = (
unsigned char)R;
2527 *rgba++ = (
unsigned char)G;
2528 *rgba++ = (
unsigned char)B;
2533 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2536 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2539 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2541 *rgba++ = (
unsigned char)R;
2542 *rgba++ = (
unsigned char)G;
2543 *rgba++ = (
unsigned char)B;
2545 rgba = rgba + 4*width-15;
2548 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2551 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2554 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2556 *rgba++ = (
unsigned char)R;
2557 *rgba++ = (
unsigned char)G;
2558 *rgba++ = (
unsigned char)B;
2563 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2566 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2569 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2571 *rgba++ = (
unsigned char)R;
2572 *rgba++ = (
unsigned char)G;
2573 *rgba++ = (
unsigned char)B;
2578 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2581 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2584 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2586 *rgba++ = (
unsigned char)R;
2587 *rgba++ = (
unsigned char)G;
2588 *rgba++ = (
unsigned char)B;
2593 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2596 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2599 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2601 *rgba++ = (
unsigned char)R;
2602 *rgba++ = (
unsigned char)G;
2603 *rgba++ = (
unsigned char)B;
2605 rgba = rgba -12*width+1;
2619 unsigned int height,
unsigned int width)
2622 register int U, V, R, G, B, V2, U5, UV;
2623 register int Y0, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10, Y11, Y12, Y13, Y14, Y15;
2624 unsigned int size = width*height;
2625 unsigned char* iV = yuv + size;
2626 unsigned char* iU = yuv + 17*size/16;
2627 for(
unsigned int i = 0; i<height/4; i++)
2629 for(
unsigned int j = 0; j < width/4 ; j++)
2631 U = (int)((*iU++ - 128) * 0.354);
2633 V = (int)((*iV++ - 128) * 0.707);
2655 yuv = yuv-3*width+1;
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;
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;
2715 rgb = rgb + 3*width-11;
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;
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;
2771 rgb = rgb + 3*width-11;
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;
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;
2827 rgb = rgb + 3*width-11;
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;
2844 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2847 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2850 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2852 *rgb++ = (
unsigned char)R;
2853 *rgb++ = (
unsigned char)G;
2854 *rgb++ = (
unsigned char)B;
2858 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2861 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2864 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2866 *rgb++ = (
unsigned char)R;
2867 *rgb++ = (
unsigned char)G;
2868 *rgb++ = (
unsigned char)B;
2872 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2875 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2878 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2880 *rgb++ = (
unsigned char)R;
2881 *rgb++ = (
unsigned char)G;
2882 *rgb++ = (
unsigned char)B;
2883 rgb = rgb -9*width+1;
2898 unsigned char *pt_input = rgb;
2899 unsigned char *pt_end = rgb + 3*size;
2900 unsigned char *pt_output = rgba;
2902 while(pt_input != pt_end) {
2903 *(pt_output++) = *(pt_input++) ;
2904 *(pt_output++) = *(pt_input++) ;
2905 *(pt_output++) = *(pt_input++) ;
2906 *(pt_output++) = 0 ;
2918 unsigned char *pt_input = rgba;
2919 unsigned char *pt_end = rgba + 4*size;
2920 unsigned char *pt_output = rgb;
2922 while(pt_input != pt_end) {
2923 *(pt_output++) = *(pt_input++) ;
2924 *(pt_output++) = *(pt_input++) ;
2925 *(pt_output++) = *(pt_input++) ;
2938 unsigned char *pt_input = rgb;
2939 unsigned char* pt_end = rgb + size*3;
2940 unsigned char *pt_output = grey;
2941 while(pt_input != pt_end) {
2942 *pt_output = (
unsigned char) (0.2126 * (*pt_input)
2943 + 0.7152 * (*(pt_input + 1))
2944 + 0.0722 * (*(pt_input + 2)) );
2959 unsigned char *pt_input = rgba;
2960 unsigned char* pt_end = rgba + size*4;
2961 unsigned char *pt_output = grey;
2963 while(pt_input != pt_end) {
2964 *pt_output = (
unsigned char) (0.2126 * (*pt_input)
2965 + 0.7152 * (*(pt_input + 1))
2966 + 0.0722 * (*(pt_input + 2)) );
2978 unsigned char* rgba,
unsigned int size)
2980 unsigned char *pt_input = grey;
2981 unsigned char *pt_end = grey + size;
2982 unsigned char *pt_output = rgba;
2984 while(pt_input != pt_end) {
2985 unsigned char p = *pt_input ;
2987 *(pt_output + 1) = p ;
2988 *(pt_output + 2) = p ;
2989 *(pt_output + 3) = p ;
3002 unsigned char* rgb,
unsigned int size)
3004 unsigned char *pt_input = grey;
3005 unsigned char* pt_end = grey + size;
3006 unsigned char *pt_output = rgb;
3008 while(pt_input != pt_end) {
3009 unsigned char p = *pt_input ;
3011 *(pt_output + 1) = p ;
3012 *(pt_output + 2) = p ;
3027 unsigned int width,
unsigned int height,
bool flip)
3031 int lineStep = (flip) ? -(
int)(width*3) : (
int)(width*3);
3034 unsigned char * src = (flip) ? (bgr+(width*height*3)+lineStep) : bgr;
3035 unsigned char * line;
3040 for(i=0 ; i < height ; i++)
3043 for( j=0 ; j < width ; j++)
3045 *rgba++ = *(line+2);
3046 *rgba++ = *(line+1);
3047 *rgba++ = *(line+0);
3065 unsigned int width,
unsigned int height,
bool flip)
3069 int lineStep = (flip) ? -(
int)(width*3) : (
int)(width*3);
3072 unsigned char * src = (flip) ? bgr+(width*height*3)+lineStep : bgr;
3073 unsigned char * line;
3078 for(i=0 ; i < height ; i++)
3081 for( j=0 ; j < width ; j++)
3083 *grey++ = (
unsigned char)( 0.2126 * *(line+2)
3084 + 0.7152 * *(line+1)
3085 + 0.0722 * *(line+0)) ;
3100 unsigned int width,
unsigned int height,
bool flip)
3104 int lineStep = (flip) ? -(
int)(width*3) : (
int)(width*3);
3107 unsigned char * src = (flip) ? (rgb+(width*height*3)+lineStep) : rgb;
3108 unsigned char * line;
3113 for(i=0 ; i < height ; i++)
3116 for( j=0 ; j < width ; j++)
3118 *rgba++ = *(line++);
3119 *rgba++ = *(line++);
3120 *rgba++ = *(line++);
3135 unsigned int width,
unsigned int height,
bool flip)
3139 int lineStep = (flip) ? -(
int)(width*3) : (
int)(width*3);
3142 unsigned char * src = (flip) ? rgb+(width*height*3)+lineStep : rgb;
3143 unsigned char * line;
3150 for(i=0 ; i < height ; i++)
3153 for( j=0 ; j < width ; j++)
3158 *grey++ = (
unsigned char)( 0.2126 * r + 0.7152 * g + 0.0722 * b) ;
3171 void vpImageConvert::computeYCbCrLUT()
3173 if (YCbCrLUTcomputed ==
false) {
3174 int index = 256, aux;
3179 vpImageConvert::vpCrr[index] = (int)( 364.6610 * aux) >> 8;
3180 vpImageConvert::vpCgb[index] = (int)( -89.8779 * aux) >> 8;
3181 vpImageConvert::vpCgr[index] = (int)(-185.8154 * aux) >> 8;
3182 vpImageConvert::vpCbb[index] = (int)( 460.5724 * aux) >> 8;
3185 YCbCrLUTcomputed =
true;
3214 unsigned char *pt_ycbcr = ycbcr;
3215 unsigned char *pt_rgb = rgb;
3219 vpImageConvert::computeYCbCrLUT();
3224 register int val_r, val_g, val_b;
3230 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3231 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3232 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3234 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3236 *pt_rgb++ = (val_r < 0) ? 0u :
3237 ((val_r > 255) ? 255u : (
unsigned char)val_r);
3238 *pt_rgb++ = (val_g < 0) ? 0u :
3239 ((val_g > 255) ? 255u : (
unsigned char)val_g);
3240 *pt_rgb++ = (val_b < 0) ? 0u :
3241 ((val_b > 255) ? 255u : (
unsigned char)val_b);
3273 unsigned char *pt_ycbcr = ycbcr;
3274 unsigned char *pt_rgba = rgba;
3278 vpImageConvert::computeYCbCrLUT();
3283 register int val_r, val_g, val_b;
3289 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3290 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3291 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3293 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3295 *pt_rgba++ = (val_r < 0) ? 0u :
3296 ((val_r > 255) ? 255u : (
unsigned char)val_r);
3297 *pt_rgba++ = (val_g < 0) ? 0u :
3298 ((val_g > 255) ? 255u : (
unsigned char)val_g);
3299 *pt_rgba++ = (val_b < 0) ? 0u :
3300 ((val_b > 255) ? 255u : (
unsigned char)val_b);
3325 unsigned char* grey,
3328 unsigned int i=0,j=0;
3333 grey[i++] = yuv[j+2];
3361 unsigned char *pt_ycbcr = ycrcb;
3362 unsigned char *pt_rgb = rgb;
3366 vpImageConvert::computeYCbCrLUT();
3371 register int val_r, val_g, val_b;
3377 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3378 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3379 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3381 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3383 *pt_rgb++ = (val_r < 0) ? 0u :
3384 ((val_r > 255) ? 255u : (
unsigned char)val_r);
3385 *pt_rgb++ = (val_g < 0) ? 0u :
3386 ((val_g > 255) ? 255u : (
unsigned char)val_g);
3387 *pt_rgb++ = (val_b < 0) ? 0u :
3388 ((val_b > 255) ? 255u : (
unsigned char)val_b);
3418 unsigned char *pt_ycbcr = ycrcb;
3419 unsigned char *pt_rgba = rgba;
3423 vpImageConvert::computeYCbCrLUT();
3428 register int val_r, val_g, val_b;
3434 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3435 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3436 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3438 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3440 *pt_rgba++ = (val_r < 0) ? 0u :
3441 ((val_r > 255) ? 255u : (
unsigned char)val_r);
3442 *pt_rgba++ = (val_g < 0) ? 0u :
3443 ((val_g > 255) ? 255u : (
unsigned char)val_g);
3444 *pt_rgba++ = (val_b < 0) ? 0u :
3445 ((val_b > 255) ? 255u : (
unsigned char)val_b);
3495 unsigned int width = src.
getWidth();
3496 unsigned char* input;
3497 unsigned char* dst ;
3513 for(
unsigned int j = 0;j < 4;j++){
3514 if(tabChannel[j]!=NULL){
3515 if(tabChannel[j]->getHeight() != height ||
3516 tabChannel[j]->getWidth() != width){
3517 tabChannel[j]->
resize(height,width);
3519 dst = (
unsigned char*)tabChannel[j]->bitmap;
3521 input = (
unsigned char*)src.
bitmap+j;
3526 for (; i < n; i += 4) {
3527 *dst = *input; input += 4; dst++;
3528 *dst = *input; input += 4; dst++;
3529 *dst = *input; input += 4; dst++;
3530 *dst = *input; input += 4; dst++;
3535 for (; i < n; i++) {
3536 *dst = *input; input += 4; dst ++;
3555 register int i = (((int)size)<<1)-1;
3556 register int j = (int)size-1;
3561 grey[j--] =
static_cast<unsigned char>( (y+(grey16[i--]<<8))>>8 );
3578 register int i = (((int)size)<<1)-1;
3579 register int j = (int)(size*4-1);
3581 register unsigned char v;
3585 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)
void resize(const unsigned int height, const unsigned int width)
set the size of the image
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
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)