50 #include <visp3/core/vpImageConvert.h>
52 bool vpImageConvert::YCbCrLUTcomputed =
false;
53 int vpImageConvert::vpCrr[256];
54 int vpImageConvert::vpCgb[256];
55 int vpImageConvert::vpCgr[256];
56 int vpImageConvert::vpCbb[256];
102 for (
unsigned int i = 0; i < max_xy; i++) {
103 float val = 255.f * (src.
bitmap[i] - min) / (max - min);
109 dest.
bitmap[i] = (
unsigned char)val;
140 for (
unsigned int i = 0; i < max_xy; i++) {
141 double val = 255. * (src.
bitmap[i] - min) / (max - min);
147 dest.
bitmap[i] = (
unsigned char)val;
164 #ifdef VISP_HAVE_OPENCV
212 int nChannel = src->nChannels;
213 int depth = src->depth;
214 int height = src->height;
215 int width = src->width;
216 int widthStep = src->widthStep;
217 int lineStep = (flip) ? 1 : 0;
219 if(nChannel == 3 && depth == 8){
220 dest.
resize((
unsigned int)height, (
unsigned int)width);
223 unsigned char* input = (
unsigned char*)src->imageData;
225 unsigned char* beginOutput = (
unsigned char*)dest.
bitmap;
226 unsigned char* output = NULL;
228 for(
int i=0 ; i < height ; i++)
231 output = beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) + (1-lineStep) * 4 * width * i;
232 for(
int j=0 ; j < width ; j++)
234 *(output++) = *(line+2);
235 *(output++) = *(line+1);
236 *(output++) = *(line);
245 else if(nChannel == 1 && depth == 8 ){
246 dest.
resize((
unsigned int)height, (
unsigned int)width);
248 unsigned char * input = (
unsigned char*)src->imageData;
249 unsigned char * line;
250 unsigned char* beginOutput = (
unsigned char*)dest.
bitmap;
251 unsigned char* output = NULL;
253 for(
int i=0 ; i < height ; i++)
256 output = beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) + (1-lineStep) * 4 * width * i;
257 for(
int j=0 ; j < width ; j++)
262 *output++ = *(line);;
318 int nChannel = src->nChannels;
319 int depth = src->depth;
320 int height = src->height;
321 int width = src->width;
322 int widthStep = src->widthStep;
323 int lineStep = (flip) ? 1 : 0;
327 if(widthStep == width){
328 if(nChannel == 1 && depth == 8){
329 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
330 memcpy(dest.
bitmap, src->imageData,
331 (
size_t)(height*width));
333 if(nChannel == 3 && depth == 8){
334 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
335 BGRToGrey((
unsigned char*)src->imageData,dest.
bitmap, (
unsigned int)width, (
unsigned int)height,
false);
339 if(nChannel == 1 && depth == 8){
340 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
341 for (
int i =0 ; i < height ; i++){
342 memcpy(dest.
bitmap+i*width, src->imageData + i*widthStep,
346 if(nChannel == 3 && depth == 8){
347 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
348 for (
int i = 0 ; i < height ; i++){
349 BGRToGrey((
unsigned char*)src->imageData + i*widthStep,
350 dest.
bitmap + i*width, (
unsigned int)width, 1,
false);
357 if(nChannel == 1 && depth == 8){
358 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
359 unsigned char* beginOutput = (
unsigned char*)dest.
bitmap;
360 for (
int i =0 ; i < height ; i++){
361 memcpy(beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) , src->imageData + i*widthStep,
365 if(nChannel == 3 && depth == 8){
366 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
368 BGRToGrey((
unsigned char*)src->imageData ,
369 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);
511 unsigned int width = src.
getWidth();
512 CvSize size = cvSize((
int)width, (
int)height);
516 if(dest->nChannels != channels || dest->depth != depth
517 || dest->height != (
int) height || dest->width != (
int) width){
518 if(dest->nChannels != 0) cvReleaseImage(&dest);
519 dest = cvCreateImage( size, depth, channels );
522 else dest = cvCreateImage( size, depth, channels );
524 unsigned int widthStep = (
unsigned int)dest->widthStep;
526 if ( width == widthStep){
527 memcpy(dest->imageData,src.
bitmap, width*height);
531 for (
unsigned int i =0 ; i < height ; i++){
532 memcpy(dest->imageData + i*widthStep, src.
bitmap + i*width,
538 #if VISP_HAVE_OPENCV_VERSION >= 0x020100
584 if(src.type() == CV_8UC4){
585 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
587 for(
unsigned int i=0; i<dest.
getRows(); ++i)
588 for(
unsigned int j=0; j<dest.
getCols(); ++j){
589 cv::Vec4b tmp = src.at<cv::Vec4b>((int)i, (
int)j);
595 dest[dest.
getRows()-i-1][j] = rgbaVal;
597 dest[i][j] = rgbaVal;
599 }
else if(src.type() == CV_8UC3){
600 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
603 for(
unsigned int i=0; i<dest.
getRows(); ++i){
604 for(
unsigned int j=0; j<dest.
getCols(); ++j){
605 cv::Vec3b tmp = src.at<cv::Vec3b>((int)i, (
int)j);
610 dest[dest.
getRows()-i-1][j] = rgbaVal;
612 dest[i][j] = rgbaVal;
616 }
else if(src.type() == CV_8UC1){
617 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
619 for(
unsigned int i=0; i<dest.
getRows(); ++i){
620 for(
unsigned int j=0; j<dest.
getCols(); ++j){
621 rgbaVal = src.at<
unsigned char>((int)i, (
int)j);
623 dest[dest.
getRows()-i-1][j] = rgbaVal;
625 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);
764 cv::Mat out[] = {dest, alpha};
765 int from_to[] = { 0,2, 1,1, 2,0, 3,3 };
766 cv::mixChannels(&vpToMat, 1, out, 2, from_to, 4);
815 dest = tmpMap.clone();
824 #ifdef VISP_HAVE_YARP
858 yarp::sig::ImageOf< yarp::sig::PixelMono > *dest,
const bool copyData)
908 dest.
resize(src->height(),src->width());
910 memcpy(dest.
bitmap, src->getRawImage(), src->height()*src->width()*
sizeof(yarp::sig::PixelMono));
912 dest.
bitmap = src->getRawImage();
949 yarp::sig::ImageOf< yarp::sig::PixelRgba > *dest,
const bool copyData)
999 dest.
resize(src->height(),src->width());
1001 memcpy(dest.
bitmap, src->getRawImage(),src->height()*src->width()*
sizeof(yarp::sig::PixelRgba));
1041 for(
unsigned int i = 0 ; i < src.
getRows() ; i++){
1042 for(
unsigned int j = 0 ; j < src.
getWidth() ; j++){
1043 dest->pixel(j,i).r = src[i][j].R;
1044 dest->pixel(j,i).g = src[i][j].G;
1045 dest->pixel(j,i).b = src[i][j].B;
1088 dest.
resize(src->height(),src->width());
1089 for(
int i = 0 ; i < src->height() ; i++){
1090 for(
int j = 0 ; j < src->width() ; j++){
1091 dest[i][j].R = src->pixel(j,i).r;
1092 dest[i][j].G = src->pixel(j,i).g;
1093 dest[i][j].B = src->pixel(j,i).b;
1102 if (c & (~255)) { if (c < 0) c = 0; else c = 255; }
1110 unsigned int width,
unsigned int height)
1115 int r, g, b, cr, cg, cb, y1, y2;
1125 cb = ((*s - 128) * 454) >> 8;
1126 cg = (*s++ - 128) * 88;
1128 cr = ((*s - 128) * 359) >> 8;
1129 cg = (cg + (*s++ - 128) * 183) >> 8;
1138 *d++ =
static_cast<unsigned char>(r);
1139 *d++ =
static_cast<unsigned char>(g);
1140 *d++ =
static_cast<unsigned char>(b);
1150 *d++ =
static_cast<unsigned char>(r);
1151 *d++ =
static_cast<unsigned char>(g);
1152 *d++ =
static_cast<unsigned char>(b);
1166 unsigned int width,
unsigned int height)
1171 int r, g, b, cr, cg, cb, y1, y2;
1181 cb = ((*s - 128) * 454) >> 8;
1182 cg = (*s++ - 128) * 88;
1184 cr = ((*s - 128) * 359) >> 8;
1185 cg = (cg + (*s++ - 128) * 183) >> 8;
1194 *d++ =
static_cast<unsigned char>(r);
1195 *d++ =
static_cast<unsigned char>(g);
1196 *d++ =
static_cast<unsigned char>(b);
1205 *d++ =
static_cast<unsigned char>(r);
1206 *d++ =
static_cast<unsigned char>(g);
1207 *d++ =
static_cast<unsigned char>(b);
1220 unsigned int i=0,j=0;
1224 grey[i++] = yuyv[j];
1225 grey[i++] = yuyv[j+2];
1241 register int U, V, R, G, B, V2, U5, UV;
1242 register int Y0, Y1, Y2, Y3;
1243 for(
unsigned int i = size / 4; i; i--) {
1244 U = (int)((*yuv++ - 128) * 0.354);
1248 V = (int)((*yuv++ - 128) * 0.707);
1259 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1262 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1265 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1267 *rgba++ = (
unsigned char)R;
1268 *rgba++ = (
unsigned char)G;
1269 *rgba++ = (
unsigned char)B;
1274 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1277 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1280 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1282 *rgba++ = (
unsigned char)R;
1283 *rgba++ = (
unsigned char)G;
1284 *rgba++ = (
unsigned char)B;
1289 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1292 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1295 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1297 *rgba++ = (
unsigned char)R;
1298 *rgba++ = (
unsigned char)G;
1299 *rgba++ = (
unsigned char)B;
1304 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1307 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1310 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1312 *rgba++ = (
unsigned char)R;
1313 *rgba++ = (
unsigned char)G;
1314 *rgba++ = (
unsigned char)B;
1319 unsigned int i=0,j=0;
1320 unsigned char r, g, b;
1321 while( j < numpixels*3/2)
1324 YUVToRGB (yuv[j+1], yuv[j], yuv[j+3], r, g, b);
1331 YUVToRGB (yuv[j+2], yuv[j], yuv[j+3], r, g, b);
1338 YUVToRGB (yuv[j+4], yuv[j], yuv[j+3], r, g, b);
1345 YUVToRGB (yuv[j+5], yuv[j], yuv[j+3], r, g, b);
1369 register int U, V, R, G, B, V2, U5, UV;
1370 register int Y0, Y1;
1371 for(
unsigned int i = size / 2; i; i-- ) {
1372 U = (int)((*yuv++ - 128) * 0.354);
1375 V = (int)((*yuv++ - 128) * 0.707);
1382 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1385 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1388 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1390 *rgba++ = (
unsigned char)R;
1391 *rgba++ = (
unsigned char)G;
1392 *rgba++ = (
unsigned char)B;
1397 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1400 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1403 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1405 *rgba++ = (
unsigned char)R;
1406 *rgba++ = (
unsigned char)G;
1407 *rgba++ = (
unsigned char)B;
1413 unsigned int i=0,j=0;
1414 unsigned char r, g, b;
1419 YUVToRGB (yuv[j+1], yuv[j], yuv[j+2], r, g, b);
1426 YUVToRGB (yuv[j+3], yuv[j], yuv[j+2], r, g, b);
1446 unsigned int i=0,j=0;
1447 while( j < size*3/2)
1450 grey[i ] = yuv[j+1];
1451 grey[i+1] = yuv[j+2];
1452 grey[i+2] = yuv[j+4];
1453 grey[i+3] = yuv[j+5];
1473 register int U, V, R, G, B, V2, U5, UV;
1474 register int Y0, Y1;
1475 for(
unsigned int i = size / 2; i; i-- ) {
1476 U = (int)((*yuv++ - 128) * 0.354);
1479 V = (int)((*yuv++ - 128) * 0.707);
1486 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1489 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1492 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1494 *rgb++ = (
unsigned char)R;
1495 *rgb++ = (
unsigned char)G;
1496 *rgb++ = (
unsigned char)B;
1500 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1503 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1506 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1508 *rgb++ = (
unsigned char)R;
1509 *rgb++ = (
unsigned char)G;
1510 *rgb++ = (
unsigned char)B;
1516 unsigned int i=0,j=0;
1517 unsigned char r, g, b;
1522 YUVToRGB (yuv[j+1], yuv[j], yuv[j+2], r, g, b);
1528 YUVToRGB (yuv[j+3], yuv[j], yuv[j+2], r, g, b);
1549 unsigned int i=0,j=0;
1553 grey[i++] = yuv[j+1];
1554 grey[i++] = yuv[j+3];
1569 register int U, V, R, G, B, V2, U5, UV;
1570 register int Y0, Y1, Y2, Y3;
1571 for(
unsigned int i = size / 4; i; i--) {
1572 U = (int)((*yuv++ - 128) * 0.354);
1576 V = (int)((*yuv++ - 128) * 0.707);
1587 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1590 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1593 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1595 *rgb++ = (
unsigned char)R;
1596 *rgb++ = (
unsigned char)G;
1597 *rgb++ = (
unsigned char)B;
1601 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1604 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1607 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1609 *rgb++ = (
unsigned char)R;
1610 *rgb++ = (
unsigned char)G;
1611 *rgb++ = (
unsigned char)B;
1615 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1618 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1621 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1623 *rgb++ = (
unsigned char)R;
1624 *rgb++ = (
unsigned char)G;
1625 *rgb++ = (
unsigned char)B;
1629 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1632 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1635 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1637 *rgb++ = (
unsigned char)R;
1638 *rgb++ = (
unsigned char)G;
1639 *rgb++ = (
unsigned char)B;
1644 unsigned int i=0,j=0;
1645 unsigned char r, g, b;
1647 while( j < size*3/2)
1649 YUVToRGB (yuv[j+1], yuv[j], yuv[j+3], r, g, b);
1655 YUVToRGB (yuv[j+2], yuv[j], yuv[j+3], r, g, b);
1661 YUVToRGB (yuv[j+4], yuv[j], yuv[j+3], r, g, b);
1667 YUVToRGB (yuv[j+5], yuv[j], yuv[j+3], r, g, b);
1689 unsigned int width,
unsigned int height)
1692 register int U, V, R, G, B, V2, U5, UV;
1693 register int Y0, Y1, Y2, Y3;
1694 unsigned int size = width*height;
1695 unsigned char* iU = yuv + size;
1696 unsigned char* iV = yuv + 5*size/4;
1697 for(
unsigned int i = 0; i<height/2; i++)
1699 for(
unsigned int j = 0; j < width/2 ; j++)
1701 U = (int)((*iU++ - 128) * 0.354);
1703 V = (int)((*iV++ - 128) * 0.707);
1718 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1721 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1724 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1726 *rgba++ = (
unsigned char)R;
1727 *rgba++ = (
unsigned char)G;
1728 *rgba++ = (
unsigned char)B;
1733 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1736 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1739 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1741 *rgba++ = (
unsigned char)R;
1742 *rgba++ = (
unsigned char)G;
1743 *rgba++ = (
unsigned char)B;
1745 rgba = rgba + 4*width-7;
1749 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1752 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1755 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1757 *rgba++ = (
unsigned char)R;
1758 *rgba++ = (
unsigned char)G;
1759 *rgba++ = (
unsigned char)B;
1764 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1767 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1770 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1772 *rgba++ = (
unsigned char)R;
1773 *rgba++ = (
unsigned char)G;
1774 *rgba++ = (
unsigned char)B;
1776 rgba = rgba -4*width+1;
1790 unsigned int width,
unsigned int height)
1793 register int U, V, R, G, B, V2, U5, UV;
1794 register int Y0, Y1, Y2, Y3;
1795 unsigned int size = width*height;
1796 unsigned char* iU = yuv + size;
1797 unsigned char* iV = yuv + 5*size/4;
1798 for(
unsigned int i = 0; i<height/2; i++)
1800 for(
unsigned int j = 0; j < width/2 ; j++)
1802 U = (int)((*iU++ - 128) * 0.354);
1804 V = (int)((*iV++ - 128) * 0.707);
1819 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1822 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1825 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1827 *rgb++ = (
unsigned char)R;
1828 *rgb++ = (
unsigned char)G;
1829 *rgb++ = (
unsigned char)B;
1833 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1836 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1839 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1841 *rgb++ = (
unsigned char)R;
1842 *rgb++ = (
unsigned char)G;
1843 *rgb = (
unsigned char)B;
1844 rgb = rgb + 3*width-5;
1848 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1851 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1854 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1856 *rgb++ = (
unsigned char)R;
1857 *rgb++ = (
unsigned char)G;
1858 *rgb++ = (
unsigned char)B;
1862 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1865 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1868 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1870 *rgb++ = (
unsigned char)R;
1871 *rgb++ = (
unsigned char)G;
1872 *rgb = (
unsigned char)B;
1873 rgb = rgb -3*width+1;
1888 for(
unsigned int i=0 ; i < size ; i++)
1902 register int U, V, R, G, B, V2, U5, UV;
1904 for(
unsigned int i = 0; i<size; i++)
1906 U = (int)((*yuv++ - 128) * 0.354);
1909 V = (int)((*yuv++ - 128) * 0.707);
1919 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1922 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1925 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1927 *rgba++ = (
unsigned char)R;
1928 *rgba++ = (
unsigned char)G;
1929 *rgba++ = (
unsigned char)B;
1941 register int U, V, R, G, B, V2, U5, UV;
1943 for(
unsigned int i = 0; i<size; i++)
1946 U = (int)((*yuv++ - 128) * 0.354);
1949 V = (int)((*yuv++ - 128) * 0.707);
1958 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1961 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1964 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1966 *rgb++ = (
unsigned char)R;
1967 *rgb++ = (
unsigned char)G;
1968 *rgb++ = (
unsigned char)B;
1981 for(
unsigned int i=0 ; i < size ; i++)
1995 unsigned int width,
unsigned int height)
1998 register int U, V, R, G, B, V2, U5, UV;
1999 register int Y0, Y1, Y2, Y3;
2000 unsigned int size = width*height;
2001 unsigned char* iV = yuv + size;
2002 unsigned char* iU = yuv + 5*size/4;
2003 for(
unsigned int i = 0; i<height/2; i++)
2005 for(
unsigned int j = 0; j < width/2 ; j++)
2007 U = (int)((*iU++ - 128) * 0.354);
2009 V = (int)((*iV++ - 128) * 0.707);
2024 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2027 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2030 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2032 *rgba++ = (
unsigned char)R;
2033 *rgba++ = (
unsigned char)G;
2034 *rgba++ = (
unsigned char)B;
2039 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2042 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2045 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2047 *rgba++ = (
unsigned char)R;
2048 *rgba++ = (
unsigned char)G;
2049 *rgba++ = (
unsigned char)B;
2051 rgba = rgba + 4*width-7;
2055 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2058 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2061 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2063 *rgba++ = (
unsigned char)R;
2064 *rgba++ = (
unsigned char)G;
2065 *rgba++ = (
unsigned char)B;
2070 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2073 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2076 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2078 *rgba++ = (
unsigned char)R;
2079 *rgba++ = (
unsigned char)G;
2080 *rgba++ = (
unsigned char)B;
2082 rgba = rgba -4*width+1;
2095 unsigned int height,
unsigned int width)
2098 register int U, V, R, G, B, V2, U5, UV;
2099 register int Y0, Y1, Y2, Y3;
2100 unsigned int size = width*height;
2101 unsigned char* iV = yuv + size;
2102 unsigned char* iU = yuv + 5*size/4;
2103 for(
unsigned int i = 0; i<height/2; i++)
2105 for(
unsigned int j = 0; j < width/2 ; j++)
2107 U = (int)((*iU++ - 128) * 0.354);
2109 V = (int)((*iV++ - 128) * 0.707);
2124 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2127 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2130 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2132 *rgb++ = (
unsigned char)R;
2133 *rgb++ = (
unsigned char)G;
2134 *rgb++ = (
unsigned char)B;
2138 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2141 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2144 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2146 *rgb++ = (
unsigned char)R;
2147 *rgb++ = (
unsigned char)G;
2148 *rgb = (
unsigned char)B;
2149 rgb = rgb + 3*width-5;
2153 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2156 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2159 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2161 *rgb++ = (
unsigned char)R;
2162 *rgb++ = (
unsigned char)G;
2163 *rgb++ = (
unsigned char)B;
2167 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2170 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2173 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2175 *rgb++ = (
unsigned char)R;
2176 *rgb++ = (
unsigned char)G;
2177 *rgb = (
unsigned char)B;
2178 rgb = rgb -3*width+1;
2192 unsigned int width,
unsigned int height)
2195 register int U, V, R, G, B, V2, U5, UV;
2196 register int Y0, Y1, Y2, Y3,Y4, Y5, Y6, Y7,Y8, Y9, Y10, Y11,Y12, Y13, Y14, Y15;
2197 unsigned int size = width*height;
2198 unsigned char* iV = yuv + size;
2199 unsigned char* iU = yuv + 17*size/16;
2200 for(
unsigned int i = 0; i<height/4; i++)
2202 for(
unsigned int j = 0; j < width/4 ; j++)
2204 U = (int)((*iU++ - 128) * 0.354);
2206 V = (int)((*iV++ - 128) * 0.707);
2228 yuv = yuv-3*width+1;
2235 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2238 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2241 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2243 *rgba++ = (
unsigned char)R;
2244 *rgba++ = (
unsigned char)G;
2245 *rgba++ = (
unsigned char)B;
2250 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2253 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2256 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2258 *rgba++ = (
unsigned char)R;
2259 *rgba++ = (
unsigned char)G;
2260 *rgba++ = (
unsigned char)B;
2265 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2268 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2271 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2273 *rgba++ = (
unsigned char)R;
2274 *rgba++ = (
unsigned char)G;
2275 *rgba++ = (
unsigned char)B;
2280 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2283 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2286 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2288 *rgba++ = (
unsigned char)R;
2289 *rgba++ = (
unsigned char)G;
2290 *rgba++ = (
unsigned char)B;
2292 rgba = rgba + 4*width-15;
2295 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2298 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2301 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2303 *rgba++ = (
unsigned char)R;
2304 *rgba++ = (
unsigned char)G;
2305 *rgba++ = (
unsigned char)B;
2310 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2313 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2316 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2318 *rgba++ = (
unsigned char)R;
2319 *rgba++ = (
unsigned char)G;
2320 *rgba++ = (
unsigned char)B;
2325 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2328 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2331 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2333 *rgba++ = (
unsigned char)R;
2334 *rgba++ = (
unsigned char)G;
2335 *rgba++ = (
unsigned char)B;
2340 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2343 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2346 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2348 *rgba++ = (
unsigned char)R;
2349 *rgba++ = (
unsigned char)G;
2350 *rgba++ = (
unsigned char)B;
2352 rgba = rgba + 4*width-15;
2355 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2358 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2361 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2363 *rgba++ = (
unsigned char)R;
2364 *rgba++ = (
unsigned char)G;
2365 *rgba++ = (
unsigned char)B;
2370 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2373 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2376 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2378 *rgba++ = (
unsigned char)R;
2379 *rgba++ = (
unsigned char)G;
2380 *rgba++ = (
unsigned char)B;
2385 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2388 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2391 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2393 *rgba++ = (
unsigned char)R;
2394 *rgba++ = (
unsigned char)G;
2395 *rgba++ = (
unsigned char)B;
2400 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2403 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2406 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2408 *rgba++ = (
unsigned char)R;
2409 *rgba++ = (
unsigned char)G;
2410 *rgba++ = (
unsigned char)B;
2412 rgba = rgba + 4*width-15;
2415 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2418 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2421 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2423 *rgba++ = (
unsigned char)R;
2424 *rgba++ = (
unsigned char)G;
2425 *rgba++ = (
unsigned char)B;
2430 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2433 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2436 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2438 *rgba++ = (
unsigned char)R;
2439 *rgba++ = (
unsigned char)G;
2440 *rgba++ = (
unsigned char)B;
2445 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2448 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2451 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2453 *rgba++ = (
unsigned char)R;
2454 *rgba++ = (
unsigned char)G;
2455 *rgba++ = (
unsigned char)B;
2460 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2463 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2466 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2468 *rgba++ = (
unsigned char)R;
2469 *rgba++ = (
unsigned char)G;
2470 *rgba++ = (
unsigned char)B;
2472 rgba = rgba -12*width+1;
2485 unsigned int height,
unsigned int width)
2488 register int U, V, R, G, B, V2, U5, UV;
2489 register int Y0, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10, Y11, Y12, Y13, Y14, Y15;
2490 unsigned int size = width*height;
2491 unsigned char* iV = yuv + size;
2492 unsigned char* iU = yuv + 17*size/16;
2493 for(
unsigned int i = 0; i<height/4; i++)
2495 for(
unsigned int j = 0; j < width/4 ; j++)
2497 U = (int)((*iU++ - 128) * 0.354);
2499 V = (int)((*iV++ - 128) * 0.707);
2521 yuv = yuv-3*width+1;
2528 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2531 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2534 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2536 *rgb++ = (
unsigned char)R;
2537 *rgb++ = (
unsigned char)G;
2538 *rgb++ = (
unsigned char)B;
2542 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2545 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2548 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2550 *rgb++ = (
unsigned char)R;
2551 *rgb++ = (
unsigned char)G;
2552 *rgb++ = (
unsigned char)B;
2556 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2559 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2562 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2564 *rgb++ = (
unsigned char)R;
2565 *rgb++ = (
unsigned char)G;
2566 *rgb++ = (
unsigned char)B;
2570 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2573 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2576 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2578 *rgb++ = (
unsigned char)R;
2579 *rgb++ = (
unsigned char)G;
2580 *rgb = (
unsigned char)B;
2581 rgb = rgb + 3*width-11;
2584 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2587 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2590 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2592 *rgb++ = (
unsigned char)R;
2593 *rgb++ = (
unsigned char)G;
2594 *rgb++ = (
unsigned char)B;
2598 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2601 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2604 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2606 *rgb++ = (
unsigned char)R;
2607 *rgb++ = (
unsigned char)G;
2608 *rgb++ = (
unsigned char)B;
2612 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2615 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2618 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2620 *rgb++ = (
unsigned char)R;
2621 *rgb++ = (
unsigned char)G;
2622 *rgb++ = (
unsigned char)B;
2626 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2629 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2632 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2634 *rgb++ = (
unsigned char)R;
2635 *rgb++ = (
unsigned char)G;
2636 *rgb = (
unsigned char)B;
2637 rgb = rgb + 3*width-11;
2640 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2643 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2646 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2648 *rgb++ = (
unsigned char)R;
2649 *rgb++ = (
unsigned char)G;
2650 *rgb++ = (
unsigned char)B;
2654 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2657 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2660 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2662 *rgb++ = (
unsigned char)R;
2663 *rgb++ = (
unsigned char)G;
2664 *rgb++ = (
unsigned char)B;
2668 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2671 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2674 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2676 *rgb++ = (
unsigned char)R;
2677 *rgb++ = (
unsigned char)G;
2678 *rgb++ = (
unsigned char)B;
2682 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2685 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2688 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2690 *rgb++ = (
unsigned char)R;
2691 *rgb++ = (
unsigned char)G;
2692 *rgb = (
unsigned char)B;
2693 rgb = rgb + 3*width-11;
2696 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2699 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2702 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2704 *rgb++ = (
unsigned char)R;
2705 *rgb++ = (
unsigned char)G;
2706 *rgb++ = (
unsigned char)B;
2710 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2713 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2716 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2718 *rgb++ = (
unsigned char)R;
2719 *rgb++ = (
unsigned char)G;
2720 *rgb++ = (
unsigned char)B;
2724 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2727 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2730 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2732 *rgb++ = (
unsigned char)R;
2733 *rgb++ = (
unsigned char)G;
2734 *rgb++ = (
unsigned char)B;
2738 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2741 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2744 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2746 *rgb++ = (
unsigned char)R;
2747 *rgb++ = (
unsigned char)G;
2748 *rgb++ = (
unsigned char)B;
2749 rgb = rgb -9*width+1;
2763 unsigned char *pt_input = rgb;
2764 unsigned char *pt_end = rgb + 3*size;
2765 unsigned char *pt_output = rgba;
2767 while(pt_input != pt_end) {
2768 *(pt_output++) = *(pt_input++) ;
2769 *(pt_output++) = *(pt_input++) ;
2770 *(pt_output++) = *(pt_input++) ;
2771 *(pt_output++) = 0 ;
2782 unsigned char *pt_input = rgba;
2783 unsigned char *pt_end = rgba + 4*size;
2784 unsigned char *pt_output = rgb;
2786 while(pt_input != pt_end) {
2787 *(pt_output++) = *(pt_input++) ;
2788 *(pt_output++) = *(pt_input++) ;
2789 *(pt_output++) = *(pt_input++) ;
2801 unsigned char *pt_input = rgb;
2802 unsigned char* pt_end = rgb + size*3;
2803 unsigned char *pt_output = grey;
2804 while(pt_input != pt_end) {
2805 *pt_output = (
unsigned char) (0.2126 * (*pt_input)
2806 + 0.7152 * (*(pt_input + 1))
2807 + 0.0722 * (*(pt_input + 2)) );
2821 unsigned char *pt_input = rgba;
2822 unsigned char* pt_end = rgba + size*4;
2823 unsigned char *pt_output = grey;
2825 while(pt_input != pt_end) {
2826 *pt_output = (
unsigned char) (0.2126 * (*pt_input)
2827 + 0.7152 * (*(pt_input + 1))
2828 + 0.0722 * (*(pt_input + 2)) );
2841 unsigned char *pt_input = grey;
2842 unsigned char *pt_end = grey + size;
2843 unsigned char *pt_output = rgba;
2845 while(pt_input != pt_end) {
2846 unsigned char p = *pt_input ;
2848 *(pt_output + 1) = p ;
2849 *(pt_output + 2) = p ;
2850 *(pt_output + 3) = p ;
2864 unsigned char *pt_input = grey;
2865 unsigned char* pt_end = grey + size;
2866 unsigned char *pt_output = rgb;
2868 while(pt_input != pt_end) {
2869 unsigned char p = *pt_input ;
2871 *(pt_output + 1) = p ;
2872 *(pt_output + 2) = p ;
2887 unsigned int width,
unsigned int height,
bool flip)
2891 int lineStep = (flip) ? -(
int)(width*3) : (
int)(width*3);
2894 unsigned char * src = (flip) ? (bgr+(width*height*3)+lineStep) : bgr;
2895 unsigned char * line;
2900 for(i=0 ; i < height ; i++)
2903 for( j=0 ; j < width ; j++)
2905 *rgba++ = *(line+2);
2906 *rgba++ = *(line+1);
2907 *rgba++ = *(line+0);
2925 unsigned int width,
unsigned int height,
bool flip)
2929 int lineStep = (flip) ? -(
int)(width*3) : (
int)(width*3);
2932 unsigned char * src = (flip) ? bgr+(width*height*3)+lineStep : bgr;
2933 unsigned char * line;
2938 for(i=0 ; i < height ; i++)
2941 for( j=0 ; j < width ; j++)
2943 *grey++ = (
unsigned char)( 0.2126 * *(line+2)
2944 + 0.7152 * *(line+1)
2945 + 0.0722 * *(line+0)) ;
2960 unsigned int width,
unsigned int height,
bool flip)
2964 int lineStep = (flip) ? -(
int)(width*3) : (
int)(width*3);
2967 unsigned char * src = (flip) ? (rgb+(width*height*3)+lineStep) : rgb;
2968 unsigned char * line;
2973 for(i=0 ; i < height ; i++)
2976 for( j=0 ; j < width ; j++)
2978 *rgba++ = *(line++);
2979 *rgba++ = *(line++);
2980 *rgba++ = *(line++);
2995 unsigned int width,
unsigned int height,
bool flip)
2999 int lineStep = (flip) ? -(
int)(width*3) : (
int)(width*3);
3002 unsigned char * src = (flip) ? rgb+(width*height*3)+lineStep : rgb;
3003 unsigned char * line;
3010 for(i=0 ; i < height ; i++)
3013 for( j=0 ; j < width ; j++)
3018 *grey++ = (
unsigned char)( 0.2126 * r + 0.7152 * g + 0.0722 * b) ;
3031 void vpImageConvert::computeYCbCrLUT()
3033 if (YCbCrLUTcomputed ==
false) {
3034 int index = 256, aux;
3039 vpImageConvert::vpCrr[index] = (int)( 364.6610 * aux) >> 8;
3040 vpImageConvert::vpCgb[index] = (int)( -89.8779 * aux) >> 8;
3041 vpImageConvert::vpCgr[index] = (int)(-185.8154 * aux) >> 8;
3042 vpImageConvert::vpCbb[index] = (int)( 460.5724 * aux) >> 8;
3045 YCbCrLUTcomputed =
true;
3073 unsigned char *pt_ycbcr = ycbcr;
3074 unsigned char *pt_rgb = rgb;
3078 vpImageConvert::computeYCbCrLUT();
3083 register int val_r, val_g, val_b;
3089 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3090 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3091 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3093 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3095 *pt_rgb++ = (val_r < 0) ? 0u :
3096 ((val_r > 255) ? 255u : (
unsigned char)val_r);
3097 *pt_rgb++ = (val_g < 0) ? 0u :
3098 ((val_g > 255) ? 255u : (
unsigned char)val_g);
3099 *pt_rgb++ = (val_b < 0) ? 0u :
3100 ((val_b > 255) ? 255u : (
unsigned char)val_b);
3131 unsigned char *pt_ycbcr = ycbcr;
3132 unsigned char *pt_rgba = rgba;
3136 vpImageConvert::computeYCbCrLUT();
3141 register int val_r, val_g, val_b;
3147 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3148 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3149 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3151 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3153 *pt_rgba++ = (val_r < 0) ? 0u :
3154 ((val_r > 255) ? 255u : (
unsigned char)val_r);
3155 *pt_rgba++ = (val_g < 0) ? 0u :
3156 ((val_g > 255) ? 255u : (
unsigned char)val_g);
3157 *pt_rgba++ = (val_b < 0) ? 0u :
3158 ((val_b > 255) ? 255u : (
unsigned char)val_b);
3184 unsigned int i=0,j=0;
3189 grey[i++] = yuv[j+2];
3216 unsigned char *pt_ycbcr = ycrcb;
3217 unsigned char *pt_rgb = rgb;
3221 vpImageConvert::computeYCbCrLUT();
3226 register int val_r, val_g, val_b;
3232 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3233 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3234 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3236 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3238 *pt_rgb++ = (val_r < 0) ? 0u :
3239 ((val_r > 255) ? 255u : (
unsigned char)val_r);
3240 *pt_rgb++ = (val_g < 0) ? 0u :
3241 ((val_g > 255) ? 255u : (
unsigned char)val_g);
3242 *pt_rgb++ = (val_b < 0) ? 0u :
3243 ((val_b > 255) ? 255u : (
unsigned char)val_b);
3272 unsigned char *pt_ycbcr = ycrcb;
3273 unsigned char *pt_rgba = rgba;
3277 vpImageConvert::computeYCbCrLUT();
3282 register int val_r, val_g, val_b;
3288 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3289 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3290 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3292 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3294 *pt_rgba++ = (val_r < 0) ? 0u :
3295 ((val_r > 255) ? 255u : (
unsigned char)val_r);
3296 *pt_rgba++ = (val_g < 0) ? 0u :
3297 ((val_g > 255) ? 255u : (
unsigned char)val_g);
3298 *pt_rgba++ = (val_b < 0) ? 0u :
3299 ((val_b > 255) ? 255u : (
unsigned char)val_b);
3349 unsigned int width = src.
getWidth();
3350 unsigned char* input;
3351 unsigned char* dst ;
3367 for(
unsigned int j = 0;j < 4;j++){
3368 if(tabChannel[j]!=NULL){
3369 if(tabChannel[j]->getHeight() != height ||
3370 tabChannel[j]->getWidth() != width){
3371 tabChannel[j]->
resize(height,width);
3373 dst = (
unsigned char*)tabChannel[j]->bitmap;
3375 input = (
unsigned char*)src.
bitmap+j;
3380 for (; i < n; i += 4) {
3381 *dst = *input; input += 4; dst++;
3382 *dst = *input; input += 4; dst++;
3383 *dst = *input; input += 4; dst++;
3384 *dst = *input; input += 4; dst++;
3389 for (; i < n; i++) {
3390 *dst = *input; input += 4; dst ++;
3410 std::map<unsigned int, unsigned int> mapOfWidths, mapOfHeights;
3431 if(mapOfWidths.size() == 1 && mapOfHeights.size() == 1) {
3432 unsigned int width = mapOfWidths.begin()->first;
3433 unsigned int height = mapOfHeights.begin()->first;
3435 RGBa.
resize(height, width);
3437 unsigned int size = width*height;
3438 for(
unsigned int i = 0; i < size; i++) {
3472 register int i = (((int)size)<<1)-1;
3473 register int j = (int)size-1;
3478 grey[j--] =
static_cast<unsigned char>( (y+(grey16[i--]<<8))>>8 );
3494 register int i = (((int)size)<<1)-1;
3495 register int j = (int)(size*4-1);
3497 register unsigned char v;
3501 v =
static_cast<unsigned char>( (y+(grey16[i--]<<8))>>8 );
3509 void vpImageConvert::HSV2RGB(
const double *hue_,
const double *saturation_,
const double *value_,
unsigned char *rgb,
3510 const unsigned int size,
const unsigned int step) {
3511 for(
unsigned int i = 0; i < size; i++) {
3514 double hue = hue_[i], saturation = saturation_[i], value = value_[i];
3516 if (
vpMath::equal(saturation, 0.0, std::numeric_limits<double>::epsilon())) {
3524 if (
vpMath::equal(h, 6.0, std::numeric_limits<double>::epsilon())) {
3530 q = v * (1.0 - s * f);
3531 t = v * (1.0 - s * (1.0 - f));
3573 rgb[i*step + 1] = (
unsigned char)
vpMath::round(saturation * 255.0);
3574 rgb[i*step + 2] = (
unsigned char)
vpMath::round(value * 255.0);
3578 void vpImageConvert::RGB2HSV(
const unsigned char *rgb,
double *hue,
double *saturation,
double *value,
3579 const unsigned int size,
const unsigned int step) {
3580 for(
unsigned int i = 0; i < size; i++) {
3581 double red, green, blue;
3586 red = rgb[i*step] / 255.0;
3587 green = rgb[i*step + 1] / 255.0;
3588 blue = rgb[i*step + 2] / 255.0;
3591 max = (std::max)(red, blue);
3592 min = (std::min)(green, blue);
3594 max = (std::max)(green, blue);
3595 min = (std::min)(red, blue);
3600 if (!
vpMath::equal(max, 0.0, std::numeric_limits<double>::epsilon())) {
3601 s = (max - min) / max;
3606 if (
vpMath::equal(s, 0.0, std::numeric_limits<double>::epsilon())) {
3610 if (
vpMath::equal(delta, 0.0, std::numeric_limits<double>::epsilon())) {
3614 if (
vpMath::equal(red, max, std::numeric_limits<double>::epsilon())) {
3615 h = (green - blue) / delta;
3616 }
else if (
vpMath::equal(green, max, std::numeric_limits<double>::epsilon())) {
3617 h = 2 + (blue - red) / delta;
3619 h = 4 + (red - green) / delta;
3625 }
else if (h > 1.0) {
3646 const unsigned int size) {
3647 vpImageConvert::HSV2RGB(hue, saturation, value, rgba, size, 4);
3660 unsigned char *rgba,
const unsigned int size) {
3661 for(
unsigned int i = 0; i < size; i++) {
3662 double h = hue[i] / 255.0, s = saturation[i] / 255.0, v = value[i] / 255.0;
3679 const unsigned int size) {
3680 vpImageConvert::RGB2HSV(rgba, hue, saturation, value, size, 4);
3694 unsigned char *value,
const unsigned int size) {
3695 for(
unsigned int i = 0; i < size; i++) {
3699 hue[i] = (
unsigned char) (255.0 * h);
3700 saturation[i] = (
unsigned char) (255.0 * s);
3701 value[i] = (
unsigned char) (255.0 * v);
3715 const unsigned int size) {
3716 vpImageConvert::HSV2RGB(hue, saturation, value, rgb, size, 3);
3729 unsigned char *rgb,
const unsigned int size) {
3730 for(
unsigned int i = 0; i < size; i++) {
3731 double h = hue[i] / 255.0, s = saturation[i] / 255.0, v = value[i] / 255.0;
3747 const unsigned int size) {
3748 vpImageConvert::RGB2HSV(rgb, hue, saturation, value, size, 3);
3761 const unsigned int size) {
3762 for(
unsigned int i = 0; i < size; i++) {
3767 hue[i] = (
unsigned char) (255.0 * h);
3768 saturation[i] = (
unsigned char) (255.0 * s);
3769 value[i] = (
unsigned char) (255.0 * v);
unsigned int getCols() const
static void BGRToRGBa(unsigned char *bgr, unsigned char *rgba, unsigned int width, unsigned int height, bool flip=false)
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.
static void RGBToHSV(const unsigned char *rgb, double *hue, double *saturation, double *value, const unsigned int size)
unsigned char B
Blue component.
static void RGBToRGBa(unsigned char *rgb, unsigned char *rgba, unsigned int size)
static void BGRToGrey(unsigned char *bgr, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false)
Type * bitmap
points toward the bitmap
static void MONO16ToGrey(unsigned char *grey16, unsigned char *grey, unsigned int size)
static bool equal(double x, double y, double s=0.001)
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)
error that can be emited by ViSP classes.
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)
static int round(const double x)
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 without initializing it.
static void merge(const vpImage< unsigned char > *R, const vpImage< unsigned char > *G, const vpImage< unsigned char > *B, const vpImage< unsigned char > *a, vpImage< vpRGBa > &RGBa)
static void RGBaToHSV(const unsigned char *rgba, double *hue, double *saturation, double *value, const unsigned int size)
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 HSVToRGBa(const double *hue, const double *saturation, const double *value, unsigned char *rgba, const unsigned int size)
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 HSVToRGB(const double *hue, const double *saturation, const double *value, unsigned char *rgb, const 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 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)