50 #include <visp3/core/vpImageConvert.h>
52 #if defined __SSE2__ || defined _M_X64 || (defined _M_IX86_FP && _M_IX86_FP >= 2)
53 # include <emmintrin.h>
54 # define VISP_HAVE_SSE2 1
56 # if defined __SSE3__ || (defined _MSC_VER && _MSC_VER >= 1500)
57 # include <pmmintrin.h>
58 # define VISP_HAVE_SSE3 1
60 # if defined __SSSE3__ || (defined _MSC_VER && _MSC_VER >= 1500)
61 # include <tmmintrin.h>
62 # define VISP_HAVE_SSSE3 1
67 bool vpImageConvert::YCbCrLUTcomputed =
false;
68 int vpImageConvert::vpCrr[256];
69 int vpImageConvert::vpCgb[256];
70 int vpImageConvert::vpCgr[256];
71 int vpImageConvert::vpCbb[256];
116 for (
unsigned int i = 0; i < max_xy; i++) {
117 float val = 255.f * (src.
bitmap[i] - min) / (max - min);
123 dest.
bitmap[i] = (
unsigned char)val;
154 for (
unsigned int i = 0; i < max_xy; i++) {
155 double val = 255. * (src.
bitmap[i] - min) / (max - min);
161 dest.
bitmap[i] = (
unsigned char)val;
175 for (
unsigned int i=0; i< src.
getSize(); i++)
189 for (
unsigned int i=0; i< src.
getSize(); i++)
216 static uint32_t histogram[0x10000];
217 memset(histogram, 0,
sizeof(histogram));
218 for(
unsigned int i = 0; i < src_depth.
getSize(); ++i) ++histogram[src_depth.
bitmap[i]];
219 for(
int i = 2; i < 0x10000; ++i) histogram[i] += histogram[i-1];
221 for(
unsigned int i = 0; i < src_depth.
getSize(); ++i)
223 uint16_t d = src_depth.
bitmap[i];
226 int f = (int)(histogram[d] * 255 / histogram[0xFFFF]);
227 dest_rgba.
bitmap[i].
R = 255 - f;
242 #ifdef VISP_HAVE_OPENCV
292 int nChannel = src->nChannels;
293 int depth = src->depth;
294 int height = src->height;
295 int width = src->width;
296 int widthStep = src->widthStep;
297 int lineStep = (flip) ? 1 : 0;
299 if(nChannel == 3 && depth == 8){
300 dest.
resize((
unsigned int)height, (
unsigned int)width);
303 unsigned char* input = (
unsigned char*)src->imageData;
304 unsigned char* beginOutput = (
unsigned char*)dest.
bitmap;
306 for(
int i=0 ; i < height ; i++)
308 unsigned char *line = input;
309 unsigned char *output = beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) + (1-lineStep) * 4 * width * i;
310 for(
int j=0 ; j < width ; j++)
312 *(output++) = *(line+2);
313 *(output++) = *(line+1);
314 *(output++) = *(line);
323 else if(nChannel == 1 && depth == 8 ){
324 dest.
resize((
unsigned int)height, (
unsigned int)width);
326 unsigned char *input = (
unsigned char*)src->imageData;
327 unsigned char *beginOutput = (
unsigned char*)dest.
bitmap;
329 for(
int i=0 ; i < height ; i++)
331 unsigned char *line = input;
332 unsigned char *output = beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) + (1-lineStep) * 4 * width * i;
333 for(
int j=0 ; j < width ; j++)
394 int nChannel = src->nChannels;
395 int depth = src->depth;
396 int height = src->height;
397 int width = src->width;
398 int widthStep = src->widthStep;
399 int lineStep = (flip) ? 1 : 0;
403 if(widthStep == width){
404 if(nChannel == 1 && depth == 8){
405 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
406 memcpy(dest.
bitmap, src->imageData,
407 (
size_t)(height*width));
409 if(nChannel == 3 && depth == 8){
410 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
411 BGRToGrey((
unsigned char*)src->imageData,dest.
bitmap, (
unsigned int)width, (
unsigned int)height,
false);
415 if(nChannel == 1 && depth == 8){
416 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
417 for (
int i =0 ; i < height ; i++){
418 memcpy(dest.
bitmap+i*width, src->imageData + i*widthStep,
422 if(nChannel == 3 && depth == 8){
423 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
424 for (
int i = 0 ; i < height ; i++){
425 BGRToGrey((
unsigned char*)src->imageData + i*widthStep,
426 dest.
bitmap + i*width, (
unsigned int)width, 1,
false);
433 if(nChannel == 1 && depth == 8){
434 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
435 unsigned char* beginOutput = (
unsigned char*)dest.
bitmap;
436 for (
int i =0 ; i < height ; i++){
437 memcpy(beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) , src->imageData + i*widthStep,
441 if(nChannel == 3 && depth == 8){
442 dest.
resize((
unsigned int)height, (
unsigned int)width) ;
444 BGRToGrey((
unsigned char*)src->imageData ,
445 dest.
bitmap , (
unsigned int)width, (
unsigned int)height,
true);
500 CvSize size = cvSize(width, height);
504 if(dest->nChannels != channels || dest->depth != depth
505 || dest->height != height || dest->width != width){
506 if(dest->nChannels != 0) cvReleaseImage(&dest);
507 dest = cvCreateImage( size, depth, channels );
510 else dest = cvCreateImage( size, depth, channels );
514 unsigned char * input = (
unsigned char*)src.
bitmap;
515 unsigned char * output = (
unsigned char*)dest->imageData;
519 int widthStep = dest->widthStep;
521 for(i=0 ; i < height ; i++)
523 output = (
unsigned char*)dest->imageData + i*widthStep;
524 unsigned char *line = input;
525 for( j=0 ; j < width ; j++)
527 *output++ = *(line+2);
528 *output++ = *(line+1);
586 unsigned int width = src.
getWidth();
587 CvSize size = cvSize((
int)width, (
int)height);
591 if(dest->nChannels != channels || dest->depth != depth
592 || dest->height != (
int) height || dest->width != (
int) width){
593 if(dest->nChannels != 0) cvReleaseImage(&dest);
594 dest = cvCreateImage( size, depth, channels );
597 else dest = cvCreateImage( size, depth, channels );
599 unsigned int widthStep = (
unsigned int)dest->widthStep;
601 if ( width == widthStep){
602 memcpy(dest->imageData,src.
bitmap, width*height);
606 for (
unsigned int i =0 ; i < height ; i++){
607 memcpy(dest->imageData + i*widthStep, src.
bitmap + i*width,
613 #if VISP_HAVE_OPENCV_VERSION >= 0x020100
661 if(src.type() == CV_8UC4){
662 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
664 for(
unsigned int i=0; i<dest.
getRows(); ++i)
665 for(
unsigned int j=0; j<dest.
getCols(); ++j){
666 cv::Vec4b tmp = src.at<cv::Vec4b>((int)i, (
int)j);
672 dest[dest.
getRows()-i-1][j] = rgbaVal;
674 dest[i][j] = rgbaVal;
676 }
else if(src.type() == CV_8UC3){
677 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
680 for(
unsigned int i=0; i<dest.
getRows(); ++i){
681 for(
unsigned int j=0; j<dest.
getCols(); ++j){
682 cv::Vec3b tmp = src.at<cv::Vec3b>((int)i, (
int)j);
687 dest[dest.
getRows()-i-1][j] = rgbaVal;
689 dest[i][j] = rgbaVal;
693 }
else if(src.type() == CV_8UC1){
694 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
696 for(
unsigned int i=0; i<dest.
getRows(); ++i){
697 for(
unsigned int j=0; j<dest.
getCols(); ++j){
698 rgbaVal = src.at<
unsigned char>((int)i, (
int)j);
700 dest[dest.
getRows()-i-1][j] = rgbaVal;
702 dest[i][j] = rgbaVal;
754 if(src.type() == CV_8UC1){
755 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
756 if(src.isContinuous() && !flip){
757 memcpy(dest.
bitmap, src.data, (
size_t)(src.rows*src.cols));
761 for(
unsigned int i=0; i<dest.
getRows(); ++i){
762 memcpy(dest.
bitmap+i*dest.
getCols(), src.data+(dest.
getRows()-i-1)*src.step1(), (size_t)src.step);
765 for(
unsigned int i=0; i<dest.
getRows(); ++i){
766 memcpy(dest.
bitmap+i*dest.
getCols(), src.data+i*src.step1(), (size_t)src.step);
770 }
else if(src.type() == CV_8UC3){
771 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
772 if(src.isContinuous() ){
773 BGRToGrey((
unsigned char*)src.data, (
unsigned char*)dest.
bitmap, (
unsigned int)src.cols, (
unsigned int)src.rows, flip);
777 for(
unsigned int i=0; i<dest.
getRows(); ++i){
778 BGRToGrey((
unsigned char*)src.data+i*src.step1(),
780 (
unsigned int)dest.
getCols(), 1,
false);
783 for(
unsigned int i=0; i<dest.
getRows(); ++i){
784 BGRToGrey((
unsigned char*)src.data+i*src.step1(),
786 (
unsigned int)dest.
getCols(), 1,
false);
841 cv::Mat out[] = {dest, alpha};
842 int from_to[] = { 0,2, 1,1, 2,0, 3,3 };
843 cv::mixChannels(&vpToMat, 1, out, 2, from_to, 4);
892 dest = tmpMap.clone();
901 #ifdef VISP_HAVE_YARP
935 yarp::sig::ImageOf< yarp::sig::PixelMono > *dest,
const bool copyData)
985 dest.
resize(src->height(),src->width());
987 memcpy(dest.
bitmap, src->getRawImage(), src->height()*src->width()*
sizeof(yarp::sig::PixelMono));
989 dest.
bitmap = src->getRawImage();
1026 yarp::sig::ImageOf< yarp::sig::PixelRgba > *dest,
const bool copyData)
1076 dest.
resize(src->height(),src->width());
1078 memcpy(dest.
bitmap, src->getRawImage(),src->height()*src->width()*
sizeof(yarp::sig::PixelRgba));
1118 for(
unsigned int i = 0 ; i < src.
getRows() ; i++){
1119 for(
unsigned int j = 0 ; j < src.
getWidth() ; j++){
1120 dest->pixel(j,i).r = src[i][j].R;
1121 dest->pixel(j,i).g = src[i][j].G;
1122 dest->pixel(j,i).b = src[i][j].B;
1167 dest.
resize(src->height(),src->width());
1168 for(
int i = 0 ; i < src->height() ; i++){
1169 for(
int j = 0 ; j < src->width() ; j++){
1170 dest[i][j].R = src->pixel(j,i).r;
1171 dest[i][j].G = src->pixel(j,i).g;
1172 dest[i][j].B = src->pixel(j,i).b;
1181 if (c & (~255)) { if (c < 0) c = 0; else c = 255; }
1191 unsigned int width,
unsigned int height)
1196 int r, g, b, cr, cg, cb, y1, y2;
1206 cb = ((*s - 128) * 454) >> 8;
1207 cg = (*s++ - 128) * 88;
1209 cr = ((*s - 128) * 359) >> 8;
1210 cg = (cg + (*s++ - 128) * 183) >> 8;
1219 *d++ =
static_cast<unsigned char>(r);
1220 *d++ =
static_cast<unsigned char>(g);
1221 *d++ =
static_cast<unsigned char>(b);
1231 *d++ =
static_cast<unsigned char>(r);
1232 *d++ =
static_cast<unsigned char>(g);
1233 *d++ =
static_cast<unsigned char>(b);
1247 unsigned int width,
unsigned int height)
1252 int r, g, b, cr, cg, cb, y1, y2;
1262 cb = ((*s - 128) * 454) >> 8;
1263 cg = (*s++ - 128) * 88;
1265 cr = ((*s - 128) * 359) >> 8;
1266 cg = (cg + (*s++ - 128) * 183) >> 8;
1275 *d++ =
static_cast<unsigned char>(r);
1276 *d++ =
static_cast<unsigned char>(g);
1277 *d++ =
static_cast<unsigned char>(b);
1286 *d++ =
static_cast<unsigned char>(r);
1287 *d++ =
static_cast<unsigned char>(g);
1288 *d++ =
static_cast<unsigned char>(b);
1301 unsigned int i=0,j=0;
1305 grey[i++] = yuyv[j];
1306 grey[i++] = yuyv[j+2];
1322 for(
unsigned int i = size / 4; i; i--) {
1323 int U = (int)((*yuv++ - 128) * 0.354);
1327 int V = (int)((*yuv++ - 128) * 0.707);
1338 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1341 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1344 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1346 *rgba++ = (
unsigned char)R;
1347 *rgba++ = (
unsigned char)G;
1348 *rgba++ = (
unsigned char)B;
1353 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1356 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1359 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1361 *rgba++ = (
unsigned char)R;
1362 *rgba++ = (
unsigned char)G;
1363 *rgba++ = (
unsigned char)B;
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 unsigned int i=0,j=0;
1399 unsigned char r, g, b;
1400 while( j < numpixels*3/2)
1403 YUVToRGB (yuv[j+1], yuv[j], yuv[j+3], r, g, b);
1410 YUVToRGB (yuv[j+2], yuv[j], yuv[j+3], r, g, b);
1417 YUVToRGB (yuv[j+4], yuv[j], yuv[j+3], r, g, b);
1424 YUVToRGB (yuv[j+5], yuv[j], yuv[j+3], r, g, b);
1450 for(
unsigned int i = size / 2; i; i-- ) {
1451 int U = (int)((*yuv++ - 128) * 0.354);
1454 int V = (int)((*yuv++ - 128) * 0.707);
1461 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1464 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1467 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1469 *rgba++ = (
unsigned char)R;
1470 *rgba++ = (
unsigned char)G;
1471 *rgba++ = (
unsigned char)B;
1476 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1479 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1482 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1484 *rgba++ = (
unsigned char)R;
1485 *rgba++ = (
unsigned char)G;
1486 *rgba++ = (
unsigned char)B;
1492 unsigned int i=0,j=0;
1493 unsigned char r, g, b;
1498 YUVToRGB (yuv[j+1], yuv[j], yuv[j+2], r, g, b);
1505 YUVToRGB (yuv[j+3], yuv[j], yuv[j+2], r, g, b);
1525 unsigned int i=0,j=0;
1526 while( j < size*3/2)
1528 grey[i ] = yuv[j+1];
1529 grey[i+1] = yuv[j+2];
1530 grey[i+2] = yuv[j+4];
1531 grey[i+3] = yuv[j+5];
1551 for(
unsigned int i = size / 2; i; i-- ) {
1552 int U = (int)((*yuv++ - 128) * 0.354);
1555 int V = (int)((*yuv++ - 128) * 0.707);
1562 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1565 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1568 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1570 *rgb++ = (
unsigned char)R;
1571 *rgb++ = (
unsigned char)G;
1572 *rgb++ = (
unsigned char)B;
1576 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1579 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1582 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1584 *rgb++ = (
unsigned char)R;
1585 *rgb++ = (
unsigned char)G;
1586 *rgb++ = (
unsigned char)B;
1592 unsigned int i=0,j=0;
1593 unsigned char r, g, b;
1598 YUVToRGB (yuv[j+1], yuv[j], yuv[j+2], r, g, b);
1604 YUVToRGB (yuv[j+3], yuv[j], yuv[j+2], r, g, b);
1625 unsigned int i=0,j=0;
1629 grey[i++] = yuv[j+1];
1630 grey[i++] = yuv[j+3];
1645 for(
unsigned int i = size / 4; i; i--) {
1646 int U = (int)((*yuv++ - 128) * 0.354);
1650 int V = (int)((*yuv++ - 128) * 0.707);
1661 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1664 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1667 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1669 *rgb++ = (
unsigned char)R;
1670 *rgb++ = (
unsigned char)G;
1671 *rgb++ = (
unsigned char)B;
1675 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1678 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1681 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1683 *rgb++ = (
unsigned char)R;
1684 *rgb++ = (
unsigned char)G;
1685 *rgb++ = (
unsigned char)B;
1689 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1692 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1695 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1697 *rgb++ = (
unsigned char)R;
1698 *rgb++ = (
unsigned char)G;
1699 *rgb++ = (
unsigned char)B;
1703 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1706 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1709 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1711 *rgb++ = (
unsigned char)R;
1712 *rgb++ = (
unsigned char)G;
1713 *rgb++ = (
unsigned char)B;
1718 unsigned int i=0,j=0;
1719 unsigned char r, g, b;
1721 while( j < size*3/2)
1723 YUVToRGB (yuv[j+1], yuv[j], yuv[j+3], r, g, b);
1729 YUVToRGB (yuv[j+2], yuv[j], yuv[j+3], r, g, b);
1735 YUVToRGB (yuv[j+4], yuv[j], yuv[j+3], r, g, b);
1741 YUVToRGB (yuv[j+5], yuv[j], yuv[j+3], r, g, b);
1764 unsigned int width,
unsigned int height)
1767 int U, V, R, G, B, V2, U5, UV;
1769 unsigned int size = width*height;
1770 unsigned char* iU = yuv + size;
1771 unsigned char* iV = yuv + 5*size/4;
1772 for(
unsigned int i = 0; i<height/2; i++)
1774 for(
unsigned int j = 0; j < width/2 ; j++)
1776 U = (int)((*iU++ - 128) * 0.354);
1778 V = (int)((*iV++ - 128) * 0.707);
1793 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1796 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1799 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1801 *rgba++ = (
unsigned char)R;
1802 *rgba++ = (
unsigned char)G;
1803 *rgba++ = (
unsigned char)B;
1808 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1811 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1814 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1816 *rgba++ = (
unsigned char)R;
1817 *rgba++ = (
unsigned char)G;
1818 *rgba++ = (
unsigned char)B;
1820 rgba = rgba + 4*width-7;
1824 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1827 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1830 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1832 *rgba++ = (
unsigned char)R;
1833 *rgba++ = (
unsigned char)G;
1834 *rgba++ = (
unsigned char)B;
1839 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1842 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1845 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1847 *rgba++ = (
unsigned char)R;
1848 *rgba++ = (
unsigned char)G;
1849 *rgba++ = (
unsigned char)B;
1851 rgba = rgba -4*width+1;
1864 unsigned int width,
unsigned int height)
1867 int U, V, R, G, B, V2, U5, UV;
1869 unsigned int size = width*height;
1870 unsigned char* iU = yuv + size;
1871 unsigned char* iV = yuv + 5*size/4;
1872 for(
unsigned int i = 0; i<height/2; i++)
1874 for(
unsigned int j = 0; j < width/2 ; j++)
1876 U = (int)((*iU++ - 128) * 0.354);
1878 V = (int)((*iV++ - 128) * 0.707);
1893 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1896 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1899 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1901 *rgb++ = (
unsigned char)R;
1902 *rgb++ = (
unsigned char)G;
1903 *rgb++ = (
unsigned char)B;
1907 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1910 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1913 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1915 *rgb++ = (
unsigned char)R;
1916 *rgb++ = (
unsigned char)G;
1917 *rgb = (
unsigned char)B;
1918 rgb = rgb + 3*width-5;
1922 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1925 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1928 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1930 *rgb++ = (
unsigned char)R;
1931 *rgb++ = (
unsigned char)G;
1932 *rgb++ = (
unsigned char)B;
1936 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1939 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1942 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1944 *rgb++ = (
unsigned char)R;
1945 *rgb++ = (
unsigned char)G;
1946 *rgb = (
unsigned char)B;
1947 rgb = rgb -3*width+1;
1961 for(
unsigned int i=0 ; i < size ; i++)
1975 for(
unsigned int i = 0; i<size; i++)
1977 int U = (int)((*yuv++ - 128) * 0.354);
1980 int V = (int)((*yuv++ - 128) * 0.707);
1989 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
1992 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
1995 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
1997 *rgba++ = (
unsigned char)R;
1998 *rgba++ = (
unsigned char)G;
1999 *rgba++ = (
unsigned char)B;
2010 for(
unsigned int i = 0; i<size; i++)
2012 int U = (int)((*yuv++ - 128) * 0.354);
2015 int V = (int)((*yuv++ - 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 *rgb++ = (
unsigned char)R;
2033 *rgb++ = (
unsigned char)G;
2034 *rgb++ = (
unsigned char)B;
2046 for(
unsigned int i=0 ; i < size ; i++)
2061 unsigned int width,
unsigned int height)
2064 int U, V, R, G, B, V2, U5, UV;
2066 unsigned int size = width*height;
2067 unsigned char* iV = yuv + size;
2068 unsigned char* iU = yuv + 5*size/4;
2069 for(
unsigned int i = 0; i<height/2; i++)
2071 for(
unsigned int j = 0; j < width/2 ; j++)
2073 U = (int)((*iU++ - 128) * 0.354);
2075 V = (int)((*iV++ - 128) * 0.707);
2090 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2093 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2096 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2098 *rgba++ = (
unsigned char)R;
2099 *rgba++ = (
unsigned char)G;
2100 *rgba++ = (
unsigned char)B;
2105 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2108 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2111 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2113 *rgba++ = (
unsigned char)R;
2114 *rgba++ = (
unsigned char)G;
2115 *rgba++ = (
unsigned char)B;
2117 rgba = rgba + 4*width-7;
2121 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2124 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2127 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2129 *rgba++ = (
unsigned char)R;
2130 *rgba++ = (
unsigned char)G;
2131 *rgba++ = (
unsigned char)B;
2136 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2139 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2142 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2144 *rgba++ = (
unsigned char)R;
2145 *rgba++ = (
unsigned char)G;
2146 *rgba++ = (
unsigned char)B;
2148 rgba = rgba -4*width+1;
2160 unsigned int height,
unsigned int width)
2163 int U, V, R, G, B, V2, U5, UV;
2165 unsigned int size = width*height;
2166 unsigned char* iV = yuv + size;
2167 unsigned char* iU = yuv + 5*size/4;
2168 for(
unsigned int i = 0; i<height/2; i++)
2170 for(
unsigned int j = 0; j < width/2 ; j++)
2172 U = (int)((*iU++ - 128) * 0.354);
2174 V = (int)((*iV++ - 128) * 0.707);
2189 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2192 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2195 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2197 *rgb++ = (
unsigned char)R;
2198 *rgb++ = (
unsigned char)G;
2199 *rgb++ = (
unsigned char)B;
2203 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2206 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2209 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2211 *rgb++ = (
unsigned char)R;
2212 *rgb++ = (
unsigned char)G;
2213 *rgb = (
unsigned char)B;
2214 rgb = rgb + 3*width-5;
2218 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2221 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2224 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2226 *rgb++ = (
unsigned char)R;
2227 *rgb++ = (
unsigned char)G;
2228 *rgb++ = (
unsigned char)B;
2232 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2235 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2238 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2240 *rgb++ = (
unsigned char)R;
2241 *rgb++ = (
unsigned char)G;
2242 *rgb = (
unsigned char)B;
2243 rgb = rgb -3*width+1;
2258 unsigned int width,
unsigned int height)
2261 int U, V, R, G, B, V2, U5, UV;
2262 int Y0, Y1, Y2, Y3,Y4, Y5, Y6, Y7,Y8, Y9, Y10, Y11,Y12, Y13, Y14, Y15;
2263 unsigned int size = width*height;
2264 unsigned char* iV = yuv + size;
2265 unsigned char* iU = yuv + 17*size/16;
2266 for(
unsigned int i = 0; i<height/4; i++)
2268 for(
unsigned int j = 0; j < width/4 ; j++)
2270 U = (int)((*iU++ - 128) * 0.354);
2272 V = (int)((*iV++ - 128) * 0.707);
2294 yuv = yuv-3*width+1;
2301 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2304 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2307 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2309 *rgba++ = (
unsigned char)R;
2310 *rgba++ = (
unsigned char)G;
2311 *rgba++ = (
unsigned char)B;
2316 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2319 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2322 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2324 *rgba++ = (
unsigned char)R;
2325 *rgba++ = (
unsigned char)G;
2326 *rgba++ = (
unsigned char)B;
2331 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2334 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2337 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2339 *rgba++ = (
unsigned char)R;
2340 *rgba++ = (
unsigned char)G;
2341 *rgba++ = (
unsigned char)B;
2346 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2349 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2352 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2354 *rgba++ = (
unsigned char)R;
2355 *rgba++ = (
unsigned char)G;
2356 *rgba++ = (
unsigned char)B;
2358 rgba = rgba + 4*width-15;
2361 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2364 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2367 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2369 *rgba++ = (
unsigned char)R;
2370 *rgba++ = (
unsigned char)G;
2371 *rgba++ = (
unsigned char)B;
2376 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2379 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2382 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2384 *rgba++ = (
unsigned char)R;
2385 *rgba++ = (
unsigned char)G;
2386 *rgba++ = (
unsigned char)B;
2391 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2394 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2397 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2399 *rgba++ = (
unsigned char)R;
2400 *rgba++ = (
unsigned char)G;
2401 *rgba++ = (
unsigned char)B;
2406 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2409 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2412 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2414 *rgba++ = (
unsigned char)R;
2415 *rgba++ = (
unsigned char)G;
2416 *rgba++ = (
unsigned char)B;
2418 rgba = rgba + 4*width-15;
2421 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2424 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2427 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2429 *rgba++ = (
unsigned char)R;
2430 *rgba++ = (
unsigned char)G;
2431 *rgba++ = (
unsigned char)B;
2436 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2439 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2442 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2444 *rgba++ = (
unsigned char)R;
2445 *rgba++ = (
unsigned char)G;
2446 *rgba++ = (
unsigned char)B;
2451 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2454 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2457 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2459 *rgba++ = (
unsigned char)R;
2460 *rgba++ = (
unsigned char)G;
2461 *rgba++ = (
unsigned char)B;
2466 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2469 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2472 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2474 *rgba++ = (
unsigned char)R;
2475 *rgba++ = (
unsigned char)G;
2476 *rgba++ = (
unsigned char)B;
2478 rgba = rgba + 4*width-15;
2481 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2484 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2487 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2489 *rgba++ = (
unsigned char)R;
2490 *rgba++ = (
unsigned char)G;
2491 *rgba++ = (
unsigned char)B;
2496 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2499 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2502 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2504 *rgba++ = (
unsigned char)R;
2505 *rgba++ = (
unsigned char)G;
2506 *rgba++ = (
unsigned char)B;
2511 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2514 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2517 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2519 *rgba++ = (
unsigned char)R;
2520 *rgba++ = (
unsigned char)G;
2521 *rgba++ = (
unsigned char)B;
2526 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2529 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2532 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2534 *rgba++ = (
unsigned char)R;
2535 *rgba++ = (
unsigned char)G;
2536 *rgba++ = (
unsigned char)B;
2538 rgba = rgba -12*width+1;
2550 unsigned int height,
unsigned int width)
2553 int U, V, R, G, B, V2, U5, UV;
2554 int Y0, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10, Y11, Y12, Y13, Y14, Y15;
2555 unsigned int size = width*height;
2556 unsigned char* iV = yuv + size;
2557 unsigned char* iU = yuv + 17*size/16;
2558 for(
unsigned int i = 0; i<height/4; i++)
2560 for(
unsigned int j = 0; j < width/4 ; j++)
2562 U = (int)((*iU++ - 128) * 0.354);
2564 V = (int)((*iV++ - 128) * 0.707);
2586 yuv = yuv-3*width+1;
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 *rgb++ = (
unsigned char)R;
2602 *rgb++ = (
unsigned char)G;
2603 *rgb++ = (
unsigned char)B;
2607 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2610 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2613 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2615 *rgb++ = (
unsigned char)R;
2616 *rgb++ = (
unsigned char)G;
2617 *rgb++ = (
unsigned char)B;
2621 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2624 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2627 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2629 *rgb++ = (
unsigned char)R;
2630 *rgb++ = (
unsigned char)G;
2631 *rgb++ = (
unsigned char)B;
2635 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2638 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2641 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2643 *rgb++ = (
unsigned char)R;
2644 *rgb++ = (
unsigned char)G;
2645 *rgb = (
unsigned char)B;
2646 rgb = rgb + 3*width-11;
2649 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2652 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2655 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2657 *rgb++ = (
unsigned char)R;
2658 *rgb++ = (
unsigned char)G;
2659 *rgb++ = (
unsigned char)B;
2663 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2666 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2669 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2671 *rgb++ = (
unsigned char)R;
2672 *rgb++ = (
unsigned char)G;
2673 *rgb++ = (
unsigned char)B;
2677 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2680 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2683 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2685 *rgb++ = (
unsigned char)R;
2686 *rgb++ = (
unsigned char)G;
2687 *rgb++ = (
unsigned char)B;
2691 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2694 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2697 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2699 *rgb++ = (
unsigned char)R;
2700 *rgb++ = (
unsigned char)G;
2701 *rgb = (
unsigned char)B;
2702 rgb = rgb + 3*width-11;
2705 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2708 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2711 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2713 *rgb++ = (
unsigned char)R;
2714 *rgb++ = (
unsigned char)G;
2715 *rgb++ = (
unsigned char)B;
2719 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2722 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2725 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2727 *rgb++ = (
unsigned char)R;
2728 *rgb++ = (
unsigned char)G;
2729 *rgb++ = (
unsigned char)B;
2733 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2736 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2739 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2741 *rgb++ = (
unsigned char)R;
2742 *rgb++ = (
unsigned char)G;
2743 *rgb++ = (
unsigned char)B;
2747 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2750 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2753 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2755 *rgb++ = (
unsigned char)R;
2756 *rgb++ = (
unsigned char)G;
2757 *rgb = (
unsigned char)B;
2758 rgb = rgb + 3*width-11;
2761 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2764 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2767 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2769 *rgb++ = (
unsigned char)R;
2770 *rgb++ = (
unsigned char)G;
2771 *rgb++ = (
unsigned char)B;
2775 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2778 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2781 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2783 *rgb++ = (
unsigned char)R;
2784 *rgb++ = (
unsigned char)G;
2785 *rgb++ = (
unsigned char)B;
2789 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2792 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2795 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2797 *rgb++ = (
unsigned char)R;
2798 *rgb++ = (
unsigned char)G;
2799 *rgb++ = (
unsigned char)B;
2803 if ((R >> 8) > 0) R = 255;
else if (R < 0) R = 0;
2806 if ((G >> 8) > 0) G = 255;
else if (G < 0) G = 0;
2809 if ((B >> 8) > 0) B = 255;
else if (B < 0) B = 0;
2811 *rgb++ = (
unsigned char)R;
2812 *rgb++ = (
unsigned char)G;
2813 *rgb++ = (
unsigned char)B;
2814 rgb = rgb -9*width+1;
2830 unsigned char *pt_input = rgb;
2831 unsigned char *pt_end = rgb + 3*size;
2832 unsigned char *pt_output = rgba;
2834 while(pt_input != pt_end) {
2835 *(pt_output++) = *(pt_input++) ;
2836 *(pt_output++) = *(pt_input++) ;
2837 *(pt_output++) = *(pt_input++) ;
2851 unsigned char *pt_input = rgba;
2852 unsigned char *pt_end = rgba + 4*size;
2853 unsigned char *pt_output = rgb;
2855 while(pt_input != pt_end) {
2856 *(pt_output++) = *(pt_input++) ;
2857 *(pt_output++) = *(pt_input++) ;
2858 *(pt_output++) = *(pt_input++) ;
2875 const __m128i mask_R1 = _mm_set_epi8(
2876 -1, -1, -1, -1, 15, -1, 12, -1, 9, -1, 6, -1, 3, -1, 0, -1
2878 const __m128i mask_R2 = _mm_set_epi8(
2879 5, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
2881 const __m128i mask_R3 = _mm_set_epi8(
2882 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 14, -1, 11, -1, 8, -1
2884 const __m128i mask_R4 = _mm_set_epi8(
2885 13, -1, 10, -1, 7, -1, 4, -1, 1, -1, -1, -1, -1, -1, -1, -1
2889 const __m128i mask_G1 = _mm_set_epi8(
2890 -1, -1, -1, -1, -1, -1, 13, -1, 10, -1, 7, -1, 4, -1, 1, -1
2892 const __m128i mask_G2 = _mm_set_epi8(
2893 6, -1, 3, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
2895 const __m128i mask_G3 = _mm_set_epi8(
2896 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, 12, -1, 9, -1
2898 const __m128i mask_G4 = _mm_set_epi8(
2899 14, -1, 11, -1, 8, -1, 5, -1, 2, -1, -1, -1, -1, -1, -1, -1
2903 const __m128i mask_B1 = _mm_set_epi8(
2904 -1, -1, -1, -1, -1, -1, 14, -1, 11, -1, 8, -1, 5, -1, 2, -1
2906 const __m128i mask_B2 = _mm_set_epi8(
2907 7, -1, 4, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
2909 const __m128i mask_B3 = _mm_set_epi8(
2910 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 13, -1, 10, -1
2912 const __m128i mask_B4 = _mm_set_epi8(
2913 15, -1, 12, -1, 9, -1, 6, -1, 3, -1, 0, -1, -1, -1, -1, -1
2917 const __m128i mask_low1 = _mm_set_epi8(
2918 -1, -1, -1, -1, -1, -1, -1, -1, 15, 13, 11, 9, 7, 5, 3, 1
2920 const __m128i mask_low2 = _mm_set_epi8(
2921 15, 13, 11, 9, 7, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1, -1
2925 const __m128i coeff_R = _mm_set_epi16(
2926 13933, 13933, 13933, 13933, 13933, 13933, 13933, 13933
2928 const __m128i coeff_G = _mm_set_epi16(
2929 (
short int) 46871, (
short int) 46871, (
short int) 46871, (
short int) 46871,
2930 (
short int) 46871, (
short int) 46871, (
short int) 46871, (
short int) 46871
2932 const __m128i coeff_B = _mm_set_epi16(
2933 4732, 4732, 4732, 4732, 4732, 4732, 4732, 4732
2936 for(; i <= size - 16; i+=16) {
2938 const __m128i data1 = _mm_loadu_si128((
const __m128i*) rgb);
2939 const __m128i data2 = _mm_loadu_si128((
const __m128i*) (rgb + 16));
2940 const __m128i data3 = _mm_loadu_si128((
const __m128i*) (rgb + 32));
2942 const __m128i red_0_7 = _mm_or_si128( _mm_shuffle_epi8(data1, mask_R1), _mm_shuffle_epi8(data2, mask_R2) );
2943 const __m128i green_0_7 = _mm_or_si128( _mm_shuffle_epi8(data1, mask_G1), _mm_shuffle_epi8(data2, mask_G2) );
2944 const __m128i blue_0_7 = _mm_or_si128( _mm_shuffle_epi8(data1, mask_B1), _mm_shuffle_epi8(data2, mask_B2) );
2946 const __m128i grays_0_7 =
2948 _mm_mulhi_epu16(red_0_7, coeff_R),
2950 _mm_mulhi_epu16(green_0_7, coeff_G),
2951 _mm_mulhi_epu16(blue_0_7, coeff_B)
2954 const __m128i red_8_15 = _mm_or_si128( _mm_shuffle_epi8(data2, mask_R3), _mm_shuffle_epi8(data3, mask_R4) );
2955 const __m128i green_8_15 = _mm_or_si128( _mm_shuffle_epi8(data2, mask_G3), _mm_shuffle_epi8(data3, mask_G4) );
2956 const __m128i blue_8_15 = _mm_or_si128( _mm_shuffle_epi8(data2, mask_B3), _mm_shuffle_epi8(data3, mask_B4) );
2958 const __m128i grays_8_15 =
2960 _mm_mulhi_epu16(red_8_15, coeff_R),
2962 _mm_mulhi_epu16(green_8_15, coeff_G),
2963 _mm_mulhi_epu16(blue_8_15, coeff_B)
2966 _mm_storeu_si128( (__m128i*) grey, _mm_or_si128(_mm_shuffle_epi8(grays_0_7, mask_low1), _mm_shuffle_epi8(grays_8_15, mask_low2)) );
2973 for(; i < size; i++) {
2974 *grey = (
unsigned char) (0.2126 * (*rgb)
2975 + 0.7152 * (*(rgb + 1))
2976 + 0.0722 * (*(rgb + 2)) );
2982 unsigned char *pt_input = rgb;
2983 unsigned char* pt_end = rgb + size*3;
2984 unsigned char *pt_output = grey;
2986 while(pt_input != pt_end) {
2987 *pt_output = (
unsigned char) (0.2126 * (*pt_input)
2988 + 0.7152 * (*(pt_input + 1))
2989 + 0.0722 * (*(pt_input + 2)) );
3009 const __m128i mask_R1 = _mm_set_epi8(
3010 -1, -1, -1, -1, -1, -1, -1, -1, 12, -1, 8, -1, 4, -1, 0, -1
3012 const __m128i mask_R2 = _mm_set_epi8(
3013 12, -1, 8, -1, 4, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1
3017 const __m128i mask_G1 = _mm_set_epi8(
3018 -1, -1, -1, -1, -1, -1, -1, -1, 13, -1, 9, -1, 5, -1, 1, -1
3020 const __m128i mask_G2 = _mm_set_epi8(
3021 13, -1, 9, -1, 5, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1
3025 const __m128i mask_B1 = _mm_set_epi8(
3026 -1, -1, -1, -1, -1, -1, -1, -1, 14, -1, 10, -1, 6, -1, 2, -1
3028 const __m128i mask_B2 = _mm_set_epi8(
3029 14, -1, 10, -1, 6, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1
3033 const __m128i mask_low1 = _mm_set_epi8(
3034 -1, -1, -1, -1, -1, -1, -1, -1, 15, 13, 11, 9, 7, 5, 3, 1
3036 const __m128i mask_low2 = _mm_set_epi8(
3037 15, 13, 11, 9, 7, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1, -1
3041 const __m128i coeff_R = _mm_set_epi16(
3042 13933, 13933, 13933, 13933, 13933, 13933, 13933, 13933
3044 const __m128i coeff_G = _mm_set_epi16(
3045 (
short int) 46871, (
short int) 46871, (
short int) 46871, (
short int) 46871,
3046 (
short int) 46871, (
short int) 46871, (
short int) 46871, (
short int) 46871
3048 const __m128i coeff_B = _mm_set_epi16(
3049 4732, 4732, 4732, 4732, 4732, 4732, 4732, 4732
3052 for(; i <= size - 16; i+=16) {
3054 const __m128i data1 = _mm_loadu_si128((
const __m128i*) rgba);
3055 const __m128i data2 = _mm_loadu_si128((
const __m128i*) (rgba + 16));
3057 const __m128i red_0_7 = _mm_or_si128( _mm_shuffle_epi8(data1, mask_R1), _mm_shuffle_epi8(data2, mask_R2) );
3058 const __m128i green_0_7 = _mm_or_si128( _mm_shuffle_epi8(data1, mask_G1), _mm_shuffle_epi8(data2, mask_G2) );
3059 const __m128i blue_0_7 = _mm_or_si128( _mm_shuffle_epi8(data1, mask_B1), _mm_shuffle_epi8(data2, mask_B2) );
3061 const __m128i grays_0_7 =
3063 _mm_mulhi_epu16(red_0_7, coeff_R),
3065 _mm_mulhi_epu16(green_0_7, coeff_G),
3066 _mm_mulhi_epu16(blue_0_7, coeff_B)
3070 const __m128i data3 = _mm_loadu_si128((
const __m128i*) (rgba + 32));
3071 const __m128i data4 = _mm_loadu_si128((
const __m128i*) (rgba + 48));
3073 const __m128i red_8_15 = _mm_or_si128( _mm_shuffle_epi8(data3, mask_R1), _mm_shuffle_epi8(data4, mask_R2) );
3074 const __m128i green_8_15 = _mm_or_si128( _mm_shuffle_epi8(data3, mask_G1), _mm_shuffle_epi8(data4, mask_G2) );
3075 const __m128i blue_8_15 = _mm_or_si128( _mm_shuffle_epi8(data3, mask_B1), _mm_shuffle_epi8(data4, mask_B2) );
3077 const __m128i grays_8_15 =
3079 _mm_mulhi_epu16(red_8_15, coeff_R),
3081 _mm_mulhi_epu16(green_8_15, coeff_G),
3082 _mm_mulhi_epu16(blue_8_15, coeff_B)
3085 _mm_storeu_si128( (__m128i*) grey, _mm_or_si128(_mm_shuffle_epi8(grays_0_7, mask_low1), _mm_shuffle_epi8(grays_8_15, mask_low2)) );
3092 for(; i < size; i++) {
3093 *grey = (
unsigned char) (0.2126 * (*rgba)
3094 + 0.7152 * (*(rgba + 1))
3095 + 0.0722 * (*(rgba + 2)) );
3101 unsigned char *pt_input = rgba;
3102 unsigned char* pt_end = rgba + size*4;
3103 unsigned char *pt_output = grey;
3105 while(pt_input != pt_end) {
3106 *pt_output = (
unsigned char) (0.2126 * (*pt_input)
3107 + 0.7152 * (*(pt_input + 1))
3108 + 0.0722 * (*(pt_input + 2)) );
3123 unsigned char *pt_input = grey;
3124 unsigned char *pt_end = grey + size;
3125 unsigned char *pt_output = rgba;
3127 while(pt_input != pt_end) {
3128 unsigned char p = *pt_input ;
3130 *(pt_output + 1) = p ;
3131 *(pt_output + 2) = p ;
3146 unsigned char *pt_input = grey;
3147 unsigned char* pt_end = grey + size;
3148 unsigned char *pt_output = rgb;
3150 while(pt_input != pt_end) {
3151 unsigned char p = *pt_input ;
3153 *(pt_output + 1) = p ;
3154 *(pt_output + 2) = p ;
3170 unsigned int width,
unsigned int height,
bool flip)
3174 int lineStep = (flip) ? -(
int)(width*3) : (
int)(width*3);
3177 unsigned char * src = (flip) ? (bgr+(width*height*3)+lineStep) : bgr;
3179 for(
unsigned int i=0 ; i < height ; i++)
3181 unsigned char *line = src;
3182 for(
unsigned int j=0 ; j < width ; j++)
3184 *rgba++ = *(line+2);
3185 *rgba++ = *(line+1);
3186 *rgba++ = *(line+0);
3203 unsigned int width,
unsigned int height,
bool flip)
3207 const __m128i mask_B1 = _mm_set_epi8(
3208 -1, -1, -1, -1, 15, -1, 12, -1, 9, -1, 6, -1, 3, -1, 0, -1
3210 const __m128i mask_B2 = _mm_set_epi8(
3211 5, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
3213 const __m128i mask_B3 = _mm_set_epi8(
3214 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 14, -1, 11, -1, 8, -1
3216 const __m128i mask_B4 = _mm_set_epi8(
3217 13, -1, 10, -1, 7, -1, 4, -1, 1, -1, -1, -1, -1, -1, -1, -1
3221 const __m128i mask_G1 = _mm_set_epi8(
3222 -1, -1, -1, -1, -1, -1, 13, -1, 10, -1, 7, -1, 4, -1, 1, -1
3224 const __m128i mask_G2 = _mm_set_epi8(
3225 6, -1, 3, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
3227 const __m128i mask_G3 = _mm_set_epi8(
3228 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, 12, -1, 9, -1
3230 const __m128i mask_G4 = _mm_set_epi8(
3231 14, -1, 11, -1, 8, -1, 5, -1, 2, -1, -1, -1, -1, -1, -1, -1
3235 const __m128i mask_R1 = _mm_set_epi8(
3236 -1, -1, -1, -1, -1, -1, 14, -1, 11, -1, 8, -1, 5, -1, 2, -1
3238 const __m128i mask_R2 = _mm_set_epi8(
3239 7, -1, 4, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
3241 const __m128i mask_R3 = _mm_set_epi8(
3242 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 13, -1, 10, -1
3244 const __m128i mask_R4 = _mm_set_epi8(
3245 15, -1, 12, -1, 9, -1, 6, -1, 3, -1, 0, -1, -1, -1, -1, -1
3249 const __m128i mask_low1 = _mm_set_epi8(
3250 -1, -1, -1, -1, -1, -1, -1, -1, 15, 13, 11, 9, 7, 5, 3, 1
3252 const __m128i mask_low2 = _mm_set_epi8(
3253 15, 13, 11, 9, 7, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1, -1
3275 const __m128i coeff_R = _mm_set_epi16(
3276 13933, 13933, 13933, 13933, 13933, 13933, 13933, 13933
3278 const __m128i coeff_G = _mm_set_epi16(
3279 (
short int) 46871, (
short int) 46871, (
short int) 46871, (
short int) 46871,
3280 (
short int) 46871, (
short int) 46871, (
short int) 46871, (
short int) 46871
3282 const __m128i coeff_B = _mm_set_epi16(
3283 4732, 4732, 4732, 4732, 4732, 4732, 4732, 4732
3287 int i = ((int) height) - 1;
3288 int lineStep = -(int) (width*3);
3289 bgr = bgr + (width * (height-1) * 3);
3291 unsigned char *linePtr = bgr;
3292 unsigned char r,g,b;
3295 for(; i >= 0; i--) {
3298 for(; j <= width - 16; j+=16) {
3300 const __m128i data1 = _mm_loadu_si128((
const __m128i*) bgr);
3301 const __m128i data2 = _mm_loadu_si128((
const __m128i*) (bgr + 16));
3302 const __m128i data3 = _mm_loadu_si128((
const __m128i*) (bgr + 32));
3304 const __m128i red_0_7 = _mm_or_si128( _mm_shuffle_epi8(data1, mask_R1), _mm_shuffle_epi8(data2, mask_R2) );
3305 const __m128i green_0_7 = _mm_or_si128( _mm_shuffle_epi8(data1, mask_G1), _mm_shuffle_epi8(data2, mask_G2) );
3306 const __m128i blue_0_7 = _mm_or_si128( _mm_shuffle_epi8(data1, mask_B1), _mm_shuffle_epi8(data2, mask_B2) );
3308 const __m128i grays_0_7 =
3310 _mm_mulhi_epu16(red_0_7, coeff_R),
3312 _mm_mulhi_epu16(green_0_7, coeff_G),
3313 _mm_mulhi_epu16(blue_0_7, coeff_B)
3316 const __m128i red_8_15 = _mm_or_si128( _mm_shuffle_epi8(data2, mask_R3), _mm_shuffle_epi8(data3, mask_R4) );
3317 const __m128i green_8_15 = _mm_or_si128( _mm_shuffle_epi8(data2, mask_G3), _mm_shuffle_epi8(data3, mask_G4) );
3318 const __m128i blue_8_15 = _mm_or_si128( _mm_shuffle_epi8(data2, mask_B3), _mm_shuffle_epi8(data3, mask_B4) );
3320 const __m128i grays_8_15 =
3322 _mm_mulhi_epu16(red_8_15, coeff_R),
3324 _mm_mulhi_epu16(green_8_15, coeff_G),
3325 _mm_mulhi_epu16(blue_8_15, coeff_B)
3328 _mm_storeu_si128( (__m128i*) grey, _mm_or_si128(_mm_shuffle_epi8(grays_0_7, mask_low1), _mm_shuffle_epi8(grays_8_15, mask_low2)) );
3334 for(; j < width; j++) {
3338 *grey++ = (
unsigned char) ( 0.2126 * r + 0.7152 * g + 0.0722 * b);
3341 linePtr += lineStep;
3346 for(; i >= 0; i--) {
3347 for(
unsigned int j = 0; j < width; j++) {
3351 *grey++ = (
unsigned char) ( 0.2126 * r + 0.7152 * g + 0.0722 * b);
3354 linePtr += lineStep;
3359 unsigned int size = width * height;
3362 for(; i <= size - 16; i+=16) {
3364 const __m128i data1 = _mm_loadu_si128((
const __m128i*) bgr);
3365 const __m128i data2 = _mm_loadu_si128((
const __m128i*) (bgr + 16));
3366 const __m128i data3 = _mm_loadu_si128((
const __m128i*) (bgr + 32));
3368 const __m128i red_0_7 = _mm_or_si128( _mm_shuffle_epi8(data1, mask_R1), _mm_shuffle_epi8(data2, mask_R2) );
3369 const __m128i green_0_7 = _mm_or_si128( _mm_shuffle_epi8(data1, mask_G1), _mm_shuffle_epi8(data2, mask_G2) );
3370 const __m128i blue_0_7 = _mm_or_si128( _mm_shuffle_epi8(data1, mask_B1), _mm_shuffle_epi8(data2, mask_B2) );
3372 const __m128i grays_0_7 =
3374 _mm_mulhi_epu16(red_0_7, coeff_R),
3376 _mm_mulhi_epu16(green_0_7, coeff_G),
3377 _mm_mulhi_epu16(blue_0_7, coeff_B)
3380 const __m128i red_8_15 = _mm_or_si128( _mm_shuffle_epi8(data2, mask_R3), _mm_shuffle_epi8(data3, mask_R4) );
3381 const __m128i green_8_15 = _mm_or_si128( _mm_shuffle_epi8(data2, mask_G3), _mm_shuffle_epi8(data3, mask_G4) );
3382 const __m128i blue_8_15 = _mm_or_si128( _mm_shuffle_epi8(data2, mask_B3), _mm_shuffle_epi8(data3, mask_B4) );
3384 const __m128i grays_8_15 =
3386 _mm_mulhi_epu16(red_8_15, coeff_R),
3388 _mm_mulhi_epu16(green_8_15, coeff_G),
3389 _mm_mulhi_epu16(blue_8_15, coeff_B)
3392 _mm_storeu_si128( (__m128i*) grey, _mm_or_si128(_mm_shuffle_epi8(grays_0_7, mask_low1), _mm_shuffle_epi8(grays_8_15, mask_low2)) );
3399 for(; i < size; i++) {
3400 *grey = (
unsigned char) (0.2126 * (*(bgr + 2))
3401 + 0.7152 * (*(bgr + 1))
3402 + 0.0722 * (*bgr) );
3411 int lineStep = (flip) ? -(
int)(width*3) : (
int)(width*3);
3414 unsigned char * src = (flip) ? bgr+(width*height*3)+lineStep : bgr;
3416 for(
unsigned int i=0 ; i < height ; i++)
3418 unsigned char *line = src;
3419 for(
unsigned int j=0 ; j < width ; j++)
3421 *grey++ = (
unsigned char)( 0.2126 * *(line+2)
3422 + 0.7152 * *(line+1)
3423 + 0.0722 * *(line+0)) ;
3441 unsigned int width,
unsigned int height,
bool flip)
3445 int lineStep = (flip) ? -(
int)(width*3) : (
int)(width*3);
3448 unsigned char * src = (flip) ? (rgb+(width*height*3)+lineStep) : rgb;
3453 for(i=0 ; i < height ; i++)
3455 unsigned char * line = src;
3456 for( j=0 ; j < width ; j++)
3458 *rgba++ = *(line++);
3459 *rgba++ = *(line++);
3460 *rgba++ = *(line++);
3475 unsigned int width,
unsigned int height,
bool flip)
3479 int i = ((int) height) - 1;
3480 int lineStep = -(int) (width*3);
3481 rgb = rgb + (width * (height-1) * 3);
3483 unsigned char *linePtr = rgb;
3484 unsigned char r,g,b;
3488 const __m128i mask_R1 = _mm_set_epi8(
3489 -1, -1, -1, -1, 15, -1, 12, -1, 9, -1, 6, -1, 3, -1, 0, -1
3491 const __m128i mask_R2 = _mm_set_epi8(
3492 5, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
3494 const __m128i mask_R3 = _mm_set_epi8(
3495 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 14, -1, 11, -1, 8, -1
3497 const __m128i mask_R4 = _mm_set_epi8(
3498 13, -1, 10, -1, 7, -1, 4, -1, 1, -1, -1, -1, -1, -1, -1, -1
3502 const __m128i mask_G1 = _mm_set_epi8(
3503 -1, -1, -1, -1, -1, -1, 13, -1, 10, -1, 7, -1, 4, -1, 1, -1
3505 const __m128i mask_G2 = _mm_set_epi8(
3506 6, -1, 3, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
3508 const __m128i mask_G3 = _mm_set_epi8(
3509 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, 12, -1, 9, -1
3511 const __m128i mask_G4 = _mm_set_epi8(
3512 14, -1, 11, -1, 8, -1, 5, -1, 2, -1, -1, -1, -1, -1, -1, -1
3516 const __m128i mask_B1 = _mm_set_epi8(
3517 -1, -1, -1, -1, -1, -1, 14, -1, 11, -1, 8, -1, 5, -1, 2, -1
3519 const __m128i mask_B2 = _mm_set_epi8(
3520 7, -1, 4, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
3522 const __m128i mask_B3 = _mm_set_epi8(
3523 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 13, -1, 10, -1
3525 const __m128i mask_B4 = _mm_set_epi8(
3526 15, -1, 12, -1, 9, -1, 6, -1, 3, -1, 0, -1, -1, -1, -1, -1
3530 const __m128i mask_low1 = _mm_set_epi8(
3531 -1, -1, -1, -1, -1, -1, -1, -1, 15, 13, 11, 9, 7, 5, 3, 1
3533 const __m128i mask_low2 = _mm_set_epi8(
3534 15, 13, 11, 9, 7, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1, -1
3538 const __m128i coeff_R = _mm_set_epi16(
3539 13933, 13933, 13933, 13933, 13933, 13933, 13933, 13933
3541 const __m128i coeff_G = _mm_set_epi16(
3542 (
short int) 46871, (
short int) 46871, (
short int) 46871, (
short int) 46871,
3543 (
short int) 46871, (
short int) 46871, (
short int) 46871, (
short int) 46871
3545 const __m128i coeff_B = _mm_set_epi16(
3546 4732, 4732, 4732, 4732, 4732, 4732, 4732, 4732
3549 for(; i >= 0; i--) {
3552 for(; j <= width - 16; j+=16) {
3554 const __m128i data1 = _mm_loadu_si128((
const __m128i*) rgb);
3555 const __m128i data2 = _mm_loadu_si128((
const __m128i*) (rgb + 16));
3556 const __m128i data3 = _mm_loadu_si128((
const __m128i*) (rgb + 32));
3558 const __m128i red_0_7 = _mm_or_si128( _mm_shuffle_epi8(data1, mask_R1), _mm_shuffle_epi8(data2, mask_R2) );
3559 const __m128i green_0_7 = _mm_or_si128( _mm_shuffle_epi8(data1, mask_G1), _mm_shuffle_epi8(data2, mask_G2) );
3560 const __m128i blue_0_7 = _mm_or_si128( _mm_shuffle_epi8(data1, mask_B1), _mm_shuffle_epi8(data2, mask_B2) );
3562 const __m128i grays_0_7 =
3564 _mm_mulhi_epu16(red_0_7, coeff_R),
3566 _mm_mulhi_epu16(green_0_7, coeff_G),
3567 _mm_mulhi_epu16(blue_0_7, coeff_B)
3570 const __m128i red_8_15 = _mm_or_si128( _mm_shuffle_epi8(data2, mask_R3), _mm_shuffle_epi8(data3, mask_R4) );
3571 const __m128i green_8_15 = _mm_or_si128( _mm_shuffle_epi8(data2, mask_G3), _mm_shuffle_epi8(data3, mask_G4) );
3572 const __m128i blue_8_15 = _mm_or_si128( _mm_shuffle_epi8(data2, mask_B3), _mm_shuffle_epi8(data3, mask_B4) );
3574 const __m128i grays_8_15 =
3576 _mm_mulhi_epu16(red_8_15, coeff_R),
3578 _mm_mulhi_epu16(green_8_15, coeff_G),
3579 _mm_mulhi_epu16(blue_8_15, coeff_B)
3582 _mm_storeu_si128( (__m128i*) grey, _mm_or_si128(_mm_shuffle_epi8(grays_0_7, mask_low1), _mm_shuffle_epi8(grays_8_15, mask_low2)) );
3588 for(; j < width; j++) {
3592 *grey++ = (
unsigned char) ( 0.2126 * r + 0.7152 * g + 0.0722 * b);
3595 linePtr += lineStep;
3600 for(; i >= 0; i--) {
3601 for(
unsigned int j = 0; j < width; j++) {
3605 *grey++ = (
unsigned char) ( 0.2126 * r + 0.7152 * g + 0.0722 * b);
3608 linePtr += lineStep;
3614 int lineStep = (flip) ? -(
int)(width*3) : (
int)(width*3);
3617 unsigned char * src = (flip) ? rgb+(width*height*3)+lineStep : rgb;
3624 for(i=0 ; i < height ; i++)
3626 unsigned char * line = src;
3627 for( j=0 ; j < width ; j++)
3632 *grey++ = (
unsigned char)( 0.2126 * r + 0.7152 * g + 0.0722 * b) ;
3649 void vpImageConvert::computeYCbCrLUT()
3651 if (YCbCrLUTcomputed ==
false) {
3656 int aux = index - 128;
3657 vpImageConvert::vpCrr[index] = (int)( 364.6610 * aux) >> 8;
3658 vpImageConvert::vpCgb[index] = (int)( -89.8779 * aux) >> 8;
3659 vpImageConvert::vpCgr[index] = (int)(-185.8154 * aux) >> 8;
3660 vpImageConvert::vpCbb[index] = (int)( 460.5724 * aux) >> 8;
3663 YCbCrLUTcomputed =
true;
3691 unsigned char *pt_ycbcr = ycbcr;
3692 unsigned char *pt_rgb = rgb;
3696 vpImageConvert::computeYCbCrLUT();
3701 int val_r, val_g, val_b;
3707 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3708 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3709 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3711 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3713 *pt_rgb++ = (val_r < 0) ? 0u :
3714 ((val_r > 255) ? 255u : (
unsigned char)val_r);
3715 *pt_rgb++ = (val_g < 0) ? 0u :
3716 ((val_g > 255) ? 255u : (
unsigned char)val_g);
3717 *pt_rgb++ = (val_b < 0) ? 0u :
3718 ((val_b > 255) ? 255u : (
unsigned char)val_b);
3751 unsigned char *pt_ycbcr = ycbcr;
3752 unsigned char *pt_rgba = rgba;
3756 vpImageConvert::computeYCbCrLUT();
3761 int val_r, val_g, val_b;
3767 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3768 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3769 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3771 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3773 *pt_rgba++ = (val_r < 0) ? 0u :
3774 ((val_r > 255) ? 255u : (
unsigned char)val_r);
3775 *pt_rgba++ = (val_g < 0) ? 0u :
3776 ((val_g > 255) ? 255u : (
unsigned char)val_g);
3777 *pt_rgba++ = (val_b < 0) ? 0u :
3778 ((val_b > 255) ? 255u : (
unsigned char)val_b);
3804 unsigned int i=0,j=0;
3809 grey[i++] = yuv[j+2];
3836 unsigned char *pt_ycbcr = ycrcb;
3837 unsigned char *pt_rgb = rgb;
3841 vpImageConvert::computeYCbCrLUT();
3846 int val_r, val_g, val_b;
3852 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3853 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3854 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3856 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3858 *pt_rgb++ = (val_r < 0) ? 0u :
3859 ((val_r > 255) ? 255u : (
unsigned char)val_r);
3860 *pt_rgb++ = (val_g < 0) ? 0u :
3861 ((val_g > 255) ? 255u : (
unsigned char)val_g);
3862 *pt_rgb++ = (val_b < 0) ? 0u :
3863 ((val_b > 255) ? 255u : (
unsigned char)val_b);
3894 unsigned char *pt_ycbcr = ycrcb;
3895 unsigned char *pt_rgba = rgba;
3899 vpImageConvert::computeYCbCrLUT();
3904 int val_r, val_g, val_b;
3910 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3911 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3912 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3914 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3916 *pt_rgba++ = (val_r < 0) ? 0u :
3917 ((val_r > 255) ? 255u : (
unsigned char)val_r);
3918 *pt_rgba++ = (val_g < 0) ? 0u :
3919 ((val_g > 255) ? 255u : (
unsigned char)val_g);
3920 *pt_rgba++ = (val_b < 0) ? 0u :
3921 ((val_b > 255) ? 255u : (
unsigned char)val_b);
3971 unsigned int width = src.
getWidth();
3972 unsigned char* input;
3973 unsigned char* dst ;
3989 for(
unsigned int j = 0;j < 4;j++){
3990 if(tabChannel[j]!=NULL){
3991 if(tabChannel[j]->getHeight() != height ||
3992 tabChannel[j]->getWidth() != width){
3993 tabChannel[j]->
resize(height,width);
3995 dst = (
unsigned char*)tabChannel[j]->bitmap;
3997 input = (
unsigned char*)src.
bitmap+j;
4002 for (; i < n; i += 4) {
4003 *dst = *input; input += 4; dst++;
4004 *dst = *input; input += 4; dst++;
4005 *dst = *input; input += 4; dst++;
4006 *dst = *input; input += 4; dst++;
4011 for (; i < n; i++) {
4012 *dst = *input; input += 4; dst ++;
4032 std::map<unsigned int, unsigned int> mapOfWidths, mapOfHeights;
4053 if(mapOfWidths.size() == 1 && mapOfHeights.size() == 1) {
4054 unsigned int width = mapOfWidths.begin()->first;
4055 unsigned int height = mapOfHeights.begin()->first;
4057 RGBa.
resize(height, width);
4059 unsigned int size = width*height;
4060 for(
unsigned int i = 0; i < size; i++) {
4094 int i = (((int)size)<<1)-1;
4095 int j = (int)size-1;
4098 int y = grey16[i--];
4099 grey[j--] =
static_cast<unsigned char>( (y+(grey16[i--]<<8))>>8 );
4117 int i = (((int)size)<<1)-1;
4118 int j = (int)(size*4-1);
4121 int y = grey16[i--];
4122 unsigned char v =
static_cast<unsigned char>( (y+(grey16[i--]<<8))>>8 );
4130 void vpImageConvert::HSV2RGB(
const double *hue_,
const double *saturation_,
const double *value_,
unsigned char *rgb,
4131 const unsigned int size,
const unsigned int step) {
4132 for(
unsigned int i = 0; i < size; i++) {
4133 double hue = hue_[i], saturation = saturation_[i], value = value_[i];
4135 if (
vpMath::equal(saturation, 0.0, std::numeric_limits<double>::epsilon())) {
4139 double h = hue * 6.0;
4140 double s = saturation;
4143 if (
vpMath::equal(h, 6.0, std::numeric_limits<double>::epsilon())) {
4147 double f = h - (int) h;
4148 double p = v * (1.0 - s);
4149 double q = v * (1.0 - s * f);
4150 double t = v * (1.0 - s * (1.0 - f));
4192 rgb[i*step + 1] = (
unsigned char)
vpMath::round(saturation * 255.0);
4193 rgb[i*step + 2] = (
unsigned char)
vpMath::round(value * 255.0);
4199 void vpImageConvert::RGB2HSV(
const unsigned char *rgb,
double *hue,
double *saturation,
double *value,
4200 const unsigned int size,
const unsigned int step) {
4201 for(
unsigned int i = 0; i < size; i++) {
4202 double red, green, blue;
4206 red = rgb[i*step] / 255.0;
4207 green = rgb[i*step + 1] / 255.0;
4208 blue = rgb[i*step + 2] / 255.0;
4211 max = (std::max)(red, blue);
4212 min = (std::min)(green, blue);
4214 max = (std::max)(green, blue);
4215 min = (std::min)(red, blue);
4220 if (!
vpMath::equal(max, 0.0, std::numeric_limits<double>::epsilon())) {
4221 s = (max - min) / max;
4226 if (
vpMath::equal(s, 0.0, std::numeric_limits<double>::epsilon())) {
4229 double delta = max - min;
4230 if (
vpMath::equal(delta, 0.0, std::numeric_limits<double>::epsilon())) {
4234 if (
vpMath::equal(red, max, std::numeric_limits<double>::epsilon())) {
4235 h = (green - blue) / delta;
4236 }
else if (
vpMath::equal(green, max, std::numeric_limits<double>::epsilon())) {
4237 h = 2 + (blue - red) / delta;
4239 h = 4 + (red - green) / delta;
4245 }
else if (h > 1.0) {
4268 const unsigned int size) {
4269 vpImageConvert::HSV2RGB(hue, saturation, value, rgba, size, 4);
4284 unsigned char *rgba,
const unsigned int size) {
4285 for(
unsigned int i = 0; i < size; i++) {
4286 double h = hue[i] / 255.0, s = saturation[i] / 255.0, v = value[i] / 255.0;
4303 const unsigned int size) {
4304 vpImageConvert::RGB2HSV(rgba, hue, saturation, value, size, 4);
4318 unsigned char *value,
const unsigned int size) {
4319 for(
unsigned int i = 0; i < size; i++) {
4323 hue[i] = (
unsigned char) (255.0 * h);
4324 saturation[i] = (
unsigned char) (255.0 * s);
4325 value[i] = (
unsigned char) (255.0 * v);
4339 const unsigned int size) {
4340 vpImageConvert::HSV2RGB(hue, saturation, value, rgb, size, 3);
4353 unsigned char *rgb,
const unsigned int size) {
4354 for(
unsigned int i = 0; i < size; i++) {
4355 double h = hue[i] / 255.0, s = saturation[i] / 255.0, v = value[i] / 255.0;
4371 const unsigned int size) {
4372 vpImageConvert::RGB2HSV(rgb, hue, saturation, value, size, 3);
4385 const unsigned int size) {
4386 for(
unsigned int i = 0; i < size; i++) {
4391 hue[i] = (
unsigned char) (255.0 * h);
4392 saturation[i] = (
unsigned char) (255.0 * s);
4393 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)
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)
unsigned int getSize() const
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)
resize the image : Image initialization
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 createDepthHistogram(const vpImage< uint16_t > &src_depth, vpImage< vpRGBa > &dest_rgba)
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)