50 #include <visp3/core/vpCPUFeatures.h> 51 #include <visp3/core/vpImageConvert.h> 53 #if defined __SSE2__ || defined _M_X64 || (defined _M_IX86_FP && _M_IX86_FP >= 2) 54 #include <emmintrin.h> 55 #define VISP_HAVE_SSE2 1 57 #if defined __SSE3__ || (defined _MSC_VER && _MSC_VER >= 1500) 58 #include <pmmintrin.h> 59 #define VISP_HAVE_SSE3 1 61 #if defined __SSSE3__ || (defined _MSC_VER && _MSC_VER >= 1500) 62 #include <tmmintrin.h> 63 #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];
110 for (
unsigned int i = 0; i < max_xy; i++) {
111 float val = 255.f * (src.
bitmap[i] - min) / (max - min);
117 dest.
bitmap[i] = (
unsigned char)val;
145 for (
unsigned int i = 0; i < max_xy; i++) {
146 double val = 255. * (src.
bitmap[i] - min) / (max - min);
152 dest.
bitmap[i] = (
unsigned char)val;
165 for (
unsigned int i = 0; i < src.
getSize(); i++)
178 for (
unsigned int i = 0; i < src.
getSize(); i++)
204 static uint32_t histogram[0x10000];
205 memset(histogram, 0,
sizeof(histogram));
207 for (
unsigned int i = 0; i < src_depth.
getSize(); ++i)
208 ++histogram[src_depth.
bitmap[i]];
209 for (
int i = 2; i < 0x10000; ++i)
210 histogram[i] += histogram[i - 1];
213 for (
unsigned int i = 0; i < src_depth.
getSize(); ++i) {
214 uint16_t d = src_depth.
bitmap[i];
216 int f = (int)(histogram[d] * 255 / histogram[0xFFFF]);
217 dest_rgba.
bitmap[i].
R = 255 - f;
239 static uint32_t histogram2[0x10000];
240 memset(histogram2, 0,
sizeof(histogram2));
242 for (
unsigned int i = 0; i < src_depth.
getSize(); ++i)
243 ++histogram2[src_depth.
bitmap[i]];
244 for (
int i = 2; i < 0x10000; ++i)
245 histogram2[i] += histogram2[i - 1];
248 for (
unsigned int i = 0; i < src_depth.
getSize(); ++i) {
249 uint16_t d = src_depth.
bitmap[i];
251 int f = (int)(histogram2[d] * 255 / histogram2[0xFFFF]);
259 #ifdef VISP_HAVE_OPENCV 309 int nChannel = src->nChannels;
310 int depth = src->depth;
311 int height = src->height;
312 int width = src->width;
313 int widthStep = src->widthStep;
314 int lineStep = (flip) ? 1 : 0;
316 if (nChannel == 3 && depth == 8) {
317 dest.
resize((
unsigned int)height, (
unsigned int)width);
320 unsigned char *input = (
unsigned char *)src->imageData;
321 unsigned char *beginOutput = (
unsigned char *)dest.
bitmap;
323 for (
int i = 0; i < height; i++) {
324 unsigned char *line = input;
325 unsigned char *output = beginOutput + lineStep * (4 * width * (height - 1 - i)) + (1 - lineStep) * 4 * width * i;
326 for (
int j = 0; j < width; j++) {
327 *(output++) = *(line + 2);
328 *(output++) = *(line + 1);
329 *(output++) = *(line);
337 }
else if (nChannel == 1 && depth == 8) {
338 dest.
resize((
unsigned int)height, (
unsigned int)width);
340 unsigned char *input = (
unsigned char *)src->imageData;
341 unsigned char *beginOutput = (
unsigned char *)dest.
bitmap;
343 for (
int i = 0; i < height; i++) {
344 unsigned char *line = input;
345 unsigned char *output = beginOutput + lineStep * (4 * width * (height - 1 - i)) + (1 - lineStep) * 4 * width * i;
346 for (
int j = 0; j < width; j++) {
405 int nChannel = src->nChannels;
406 int depth = src->depth;
407 int height = src->height;
408 int width = src->width;
409 int widthStep = src->widthStep;
410 int lineStep = (flip) ? 1 : 0;
413 if (widthStep == width) {
414 if (nChannel == 1 && depth == 8) {
415 dest.
resize((
unsigned int)height, (
unsigned int)width);
416 memcpy(dest.
bitmap, src->imageData, (
size_t)(height * width));
418 if (nChannel == 3 && depth == 8) {
419 dest.
resize((
unsigned int)height, (
unsigned int)width);
420 BGRToGrey((
unsigned char *)src->imageData, dest.
bitmap, (
unsigned int)width, (
unsigned int)height,
false);
423 if (nChannel == 1 && depth == 8) {
424 dest.
resize((
unsigned int)height, (
unsigned int)width);
425 for (
int i = 0; i < height; i++) {
426 memcpy(dest.
bitmap + i * width, src->imageData + i * widthStep, (
size_t)width);
429 if (nChannel == 3 && depth == 8) {
430 dest.
resize((
unsigned int)height, (
unsigned int)width);
431 for (
int i = 0; i < height; i++) {
432 BGRToGrey((
unsigned char *)src->imageData + i * widthStep, dest.
bitmap + i * width, (
unsigned int)width, 1,
438 if (nChannel == 1 && depth == 8) {
439 dest.
resize((
unsigned int)height, (
unsigned int)width);
440 unsigned char *beginOutput = (
unsigned char *)dest.
bitmap;
441 for (
int i = 0; i < height; i++) {
442 memcpy(beginOutput + lineStep * (4 * width * (height - 1 - i)), src->imageData + i * widthStep, (
size_t)width);
445 if (nChannel == 3 && depth == 8) {
446 dest.
resize((
unsigned int)height, (
unsigned int)width);
448 BGRToGrey((
unsigned char *)src->imageData , dest.
bitmap , (
unsigned int)width,
449 (
unsigned int)height ,
true);
503 CvSize size = cvSize(width, height);
507 if (dest->nChannels != channels || dest->depth != depth || dest->height != height || dest->width != width) {
508 if (dest->nChannels != 0)
509 cvReleaseImage(&dest);
510 dest = cvCreateImage(size, depth, channels);
513 dest = cvCreateImage(size, depth, channels);
516 unsigned char *input = (
unsigned char *)src.
bitmap;
517 unsigned char *output = (
unsigned char *)dest->imageData;
521 int widthStep = dest->widthStep;
523 for (i = 0; i < height; i++) {
524 output = (
unsigned char *)dest->imageData + i * widthStep;
525 unsigned char *line = input;
526 for (j = 0; j < width; j++) {
527 *output++ = *(line + 2);
528 *output++ = *(line + 1);
585 unsigned int width = src.
getWidth();
586 CvSize size = cvSize((
int)width, (
int)height);
590 if (dest->nChannels != channels || dest->depth != depth || dest->height != (
int)height ||
591 dest->width != (
int)width) {
592 if (dest->nChannels != 0)
593 cvReleaseImage(&dest);
594 dest = cvCreateImage(size, depth, channels);
597 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);
605 for (
unsigned int i = 0; i < height; i++) {
606 memcpy(dest->imageData + i * widthStep, src.
bitmap + i * width, width);
611 #if VISP_HAVE_OPENCV_VERSION >= 0x020100 659 if (src.type() == CV_8UC4) {
660 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
662 for (
unsigned int i = 0; i < dest.
getRows(); ++i)
663 for (
unsigned int j = 0; j < dest.
getCols(); ++j) {
664 cv::Vec4b tmp = src.at<cv::Vec4b>((int)i, (
int)j);
670 dest[dest.
getRows() - i - 1][j] = rgbaVal;
672 dest[i][j] = rgbaVal;
674 }
else if (src.type() == CV_8UC3) {
675 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
678 for (
unsigned int i = 0; i < dest.
getRows(); ++i) {
679 for (
unsigned int j = 0; j < dest.
getCols(); ++j) {
680 cv::Vec3b tmp = src.at<cv::Vec3b>((int)i, (
int)j);
685 dest[dest.
getRows() - i - 1][j] = rgbaVal;
687 dest[i][j] = rgbaVal;
691 }
else if (src.type() == CV_8UC1) {
692 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
694 for (
unsigned int i = 0; i < dest.
getRows(); ++i) {
695 for (
unsigned int j = 0; j < dest.
getCols(); ++j) {
696 rgbaVal = src.at<
unsigned char>((int)i, (
int)j);
698 dest[dest.
getRows() - i - 1][j] = rgbaVal;
700 dest[i][j] = rgbaVal;
751 if (src.type() == CV_8UC1) {
752 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
753 if (src.isContinuous() && !flip) {
754 memcpy(dest.
bitmap, src.data, (
size_t)(src.rows * src.cols));
757 for (
unsigned int i = 0; i < dest.
getRows(); ++i) {
758 memcpy(dest.
bitmap + i * dest.
getCols(), src.data + (dest.
getRows() - i - 1) * src.step1(), (size_t)src.step);
761 for (
unsigned int i = 0; i < dest.
getRows(); ++i) {
762 memcpy(dest.
bitmap + i * dest.
getCols(), src.data + i * src.step1(), (size_t)src.step);
766 }
else if (src.type() == CV_8UC3) {
767 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
768 if (src.isContinuous() ) {
769 BGRToGrey((
unsigned char *)src.data, (
unsigned char *)dest.
bitmap, (
unsigned int)src.cols, (
unsigned int)src.rows,
773 for (
unsigned int i = 0; i < dest.
getRows(); ++i) {
774 BGRToGrey((
unsigned char *)src.data + i * src.step1(),
776 (
unsigned int)dest.
getCols(), 1,
false);
779 for (
unsigned int i = 0; i < dest.
getRows(); ++i) {
781 (
unsigned int)dest.
getCols(), 1,
false);
834 cv::Mat out[] = {dest, alpha};
835 int from_to[] = {0, 2, 1, 1, 2, 0, 3, 3};
836 cv::mixChannels(&vpToMat, 1, out, 2, from_to, 4);
884 dest = tmpMap.clone();
893 #ifdef VISP_HAVE_YARP 981 dest.
resize(src->height(), src->width());
983 memcpy(dest.
bitmap, src->getRawImage(), src->height() * src->width() *
sizeof(yarp::sig::PixelMono));
985 dest.
bitmap = src->getRawImage();
1024 const bool copyData)
1073 const bool copyData)
1075 dest.
resize(src->height(), src->width());
1077 memcpy(dest.
bitmap, src->getRawImage(), src->height() * src->width() *
sizeof(yarp::sig::PixelRgba));
1079 dest.
bitmap =
static_cast<vpRGBa *
>(src->getRawImage());
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;
1168 dest.
resize(src->height(), src->width());
1169 for (
int i = 0; i < src->height(); i++) {
1170 for (
int j = 0; j < src->width(); j++) {
1171 dest[i][j].R = src->pixel(j, i).r;
1172 dest[i][j].G = src->pixel(j, i).g;
1173 dest[i][j].B = src->pixel(j, i).b;
1201 int r, g, b, cr, cg, cb, y1, y2;
1211 cb = ((*s - 128) * 454) >> 8;
1212 cg = (*s++ - 128) * 88;
1214 cr = ((*s - 128) * 359) >> 8;
1215 cg = (cg + (*s++ - 128) * 183) >> 8;
1224 *d++ =
static_cast<unsigned char>(r);
1225 *d++ =
static_cast<unsigned char>(g);
1226 *d++ =
static_cast<unsigned char>(b);
1236 *d++ =
static_cast<unsigned char>(r);
1237 *d++ =
static_cast<unsigned char>(g);
1238 *d++ =
static_cast<unsigned char>(b);
1256 int r, g, b, cr, cg, cb, y1, y2;
1266 cb = ((*s - 128) * 454) >> 8;
1267 cg = (*s++ - 128) * 88;
1269 cr = ((*s - 128) * 359) >> 8;
1270 cg = (cg + (*s++ - 128) * 183) >> 8;
1279 *d++ =
static_cast<unsigned char>(r);
1280 *d++ =
static_cast<unsigned char>(g);
1281 *d++ =
static_cast<unsigned char>(b);
1290 *d++ =
static_cast<unsigned char>(r);
1291 *d++ =
static_cast<unsigned char>(g);
1292 *d++ =
static_cast<unsigned char>(b);
1305 unsigned int i = 0, j = 0;
1307 while (j < size * 2) {
1308 grey[i++] = yuyv[j];
1309 grey[i++] = yuyv[j + 2];
1324 for (
unsigned int i = size / 4; i; i--) {
1325 int U = (int)((*yuv++ - 128) * 0.354);
1329 int V = (int)((*yuv++ - 128) * 0.707);
1357 *rgba++ = (
unsigned char)R;
1358 *rgba++ = (
unsigned char)G;
1359 *rgba++ = (
unsigned char)B;
1381 *rgba++ = (
unsigned char)R;
1382 *rgba++ = (
unsigned char)G;
1383 *rgba++ = (
unsigned char)B;
1405 *rgba++ = (
unsigned char)R;
1406 *rgba++ = (
unsigned char)G;
1407 *rgba++ = (
unsigned char)B;
1429 *rgba++ = (
unsigned char)R;
1430 *rgba++ = (
unsigned char)G;
1431 *rgba++ = (
unsigned char)B;
1436 unsigned int i = 0, j = 0;
1437 unsigned char r, g, b;
1438 while (j < numpixels * 3 / 2) {
1440 YUVToRGB(yuv[j + 1], yuv[j], yuv[j + 3], r, g, b);
1447 YUVToRGB(yuv[j + 2], yuv[j], yuv[j + 3], r, g, b);
1454 YUVToRGB(yuv[j + 4], yuv[j], yuv[j + 3], r, g, b);
1461 YUVToRGB(yuv[j + 5], yuv[j], yuv[j + 3], r, g, b);
1486 for (
unsigned int i = size / 2; i; i--) {
1487 int U = (int)((*yuv++ - 128) * 0.354);
1490 int V = (int)((*yuv++ - 128) * 0.707);
1514 *rgba++ = (
unsigned char)R;
1515 *rgba++ = (
unsigned char)G;
1516 *rgba++ = (
unsigned char)B;
1538 *rgba++ = (
unsigned char)R;
1539 *rgba++ = (
unsigned char)G;
1540 *rgba++ = (
unsigned char)B;
1546 unsigned int i = 0, j = 0;
1547 unsigned char r, g, b;
1549 while (j < size * 2) {
1551 YUVToRGB(yuv[j + 1], yuv[j], yuv[j + 2], r, g, b);
1558 YUVToRGB(yuv[j + 3], yuv[j], yuv[j + 2], r, g, b);
1577 unsigned int i = 0, j = 0;
1578 while (j < size * 3 / 2) {
1579 grey[i] = yuv[j + 1];
1580 grey[i + 1] = yuv[j + 2];
1581 grey[i + 2] = yuv[j + 4];
1582 grey[i + 3] = yuv[j + 5];
1602 for (
unsigned int i = size / 2; i; i--) {
1603 int U = (int)((*yuv++ - 128) * 0.354);
1606 int V = (int)((*yuv++ - 128) * 0.707);
1630 *rgb++ = (
unsigned char)R;
1631 *rgb++ = (
unsigned char)G;
1632 *rgb++ = (
unsigned char)B;
1653 *rgb++ = (
unsigned char)R;
1654 *rgb++ = (
unsigned char)G;
1655 *rgb++ = (
unsigned char)B;
1660 unsigned int i = 0, j = 0;
1661 unsigned char r, g, b;
1663 while (j < size * 2) {
1665 YUVToRGB(yuv[j + 1], yuv[j], yuv[j + 2], r, g, b);
1671 YUVToRGB(yuv[j + 3], yuv[j], yuv[j + 2], r, g, b);
1691 unsigned int i = 0, j = 0;
1693 while (j < size * 2) {
1694 grey[i++] = yuv[j + 1];
1695 grey[i++] = yuv[j + 3];
1710 for (
unsigned int i = size / 4; i; i--) {
1711 int U = (int)((*yuv++ - 128) * 0.354);
1715 int V = (int)((*yuv++ - 128) * 0.707);
1743 *rgb++ = (
unsigned char)R;
1744 *rgb++ = (
unsigned char)G;
1745 *rgb++ = (
unsigned char)B;
1766 *rgb++ = (
unsigned char)R;
1767 *rgb++ = (
unsigned char)G;
1768 *rgb++ = (
unsigned char)B;
1789 *rgb++ = (
unsigned char)R;
1790 *rgb++ = (
unsigned char)G;
1791 *rgb++ = (
unsigned char)B;
1812 *rgb++ = (
unsigned char)R;
1813 *rgb++ = (
unsigned char)G;
1814 *rgb++ = (
unsigned char)B;
1819 unsigned int i = 0, j = 0;
1820 unsigned char r, g, b;
1822 while (j < size * 3 / 2) {
1823 YUVToRGB(yuv[j + 1], yuv[j], yuv[j + 3], r, g, b);
1829 YUVToRGB(yuv[j + 2], yuv[j], yuv[j + 3], r, g, b);
1835 YUVToRGB(yuv[j + 4], yuv[j], yuv[j + 3], r, g, b);
1841 YUVToRGB(yuv[j + 5], yuv[j], yuv[j + 3], r, g, b);
1863 int U, V, R, G, B, V2, U5, UV;
1865 unsigned int size = width * height;
1866 unsigned char *iU = yuv + size;
1867 unsigned char *iV = yuv + 5 * size / 4;
1868 for (
unsigned int i = 0; i < height / 2; i++) {
1869 for (
unsigned int j = 0; j < width / 2; j++) {
1870 U = (int)((*iU++ - 128) * 0.354);
1872 V = (int)((*iV++ - 128) * 0.707);
1877 yuv = yuv + width - 1;
1880 yuv = yuv - width + 1;
1904 *rgba++ = (
unsigned char)R;
1905 *rgba++ = (
unsigned char)G;
1906 *rgba++ = (
unsigned char)B;
1928 *rgba++ = (
unsigned char)R;
1929 *rgba++ = (
unsigned char)G;
1930 *rgba++ = (
unsigned char)B;
1932 rgba = rgba + 4 * width - 7;
1953 *rgba++ = (
unsigned char)R;
1954 *rgba++ = (
unsigned char)G;
1955 *rgba++ = (
unsigned char)B;
1977 *rgba++ = (
unsigned char)R;
1978 *rgba++ = (
unsigned char)G;
1979 *rgba++ = (
unsigned char)B;
1981 rgba = rgba - 4 * width + 1;
1995 int U, V, R, G, B, V2, U5, UV;
1997 unsigned int size = width * height;
1998 unsigned char *iU = yuv + size;
1999 unsigned char *iV = yuv + 5 * size / 4;
2000 for (
unsigned int i = 0; i < height / 2; i++) {
2001 for (
unsigned int j = 0; j < width / 2; j++) {
2002 U = (int)((*iU++ - 128) * 0.354);
2004 V = (int)((*iV++ - 128) * 0.707);
2009 yuv = yuv + width - 1;
2012 yuv = yuv - width + 1;
2036 *rgb++ = (
unsigned char)R;
2037 *rgb++ = (
unsigned char)G;
2038 *rgb++ = (
unsigned char)B;
2059 *rgb++ = (
unsigned char)R;
2060 *rgb++ = (
unsigned char)G;
2061 *rgb = (
unsigned char)B;
2062 rgb = rgb + 3 * width - 5;
2083 *rgb++ = (
unsigned char)R;
2084 *rgb++ = (
unsigned char)G;
2085 *rgb++ = (
unsigned char)B;
2106 *rgb++ = (
unsigned char)R;
2107 *rgb++ = (
unsigned char)G;
2108 *rgb = (
unsigned char)B;
2109 rgb = rgb - 3 * width + 1;
2123 for (
unsigned int i = 0; i < size; i++) {
2136 for (
unsigned int i = 0; i < size; i++) {
2137 int U = (int)((*yuv++ - 128) * 0.354);
2140 int V = (int)((*yuv++ - 128) * 0.707);
2166 *rgba++ = (
unsigned char)R;
2167 *rgba++ = (
unsigned char)G;
2168 *rgba++ = (
unsigned char)B;
2179 for (
unsigned int i = 0; i < size; i++) {
2180 int U = (int)((*yuv++ - 128) * 0.354);
2183 int V = (int)((*yuv++ - 128) * 0.707);
2209 *rgb++ = (
unsigned char)R;
2210 *rgb++ = (
unsigned char)G;
2211 *rgb++ = (
unsigned char)B;
2223 for (
unsigned int i = 0; i < size; i++) {
2239 int U, V, R, G, B, V2, U5, UV;
2241 unsigned int size = width * height;
2242 unsigned char *iV = yuv + size;
2243 unsigned char *iU = yuv + 5 * size / 4;
2244 for (
unsigned int i = 0; i < height / 2; i++) {
2245 for (
unsigned int j = 0; j < width / 2; j++) {
2246 U = (int)((*iU++ - 128) * 0.354);
2248 V = (int)((*iV++ - 128) * 0.707);
2253 yuv = yuv + width - 1;
2256 yuv = yuv - width + 1;
2280 *rgba++ = (
unsigned char)R;
2281 *rgba++ = (
unsigned char)G;
2282 *rgba++ = (
unsigned char)B;
2304 *rgba++ = (
unsigned char)R;
2305 *rgba++ = (
unsigned char)G;
2306 *rgba++ = (
unsigned char)B;
2308 rgba = rgba + 4 * width - 7;
2329 *rgba++ = (
unsigned char)R;
2330 *rgba++ = (
unsigned char)G;
2331 *rgba++ = (
unsigned char)B;
2353 *rgba++ = (
unsigned char)R;
2354 *rgba++ = (
unsigned char)G;
2355 *rgba++ = (
unsigned char)B;
2357 rgba = rgba - 4 * width + 1;
2371 int U, V, R, G, B, V2, U5, UV;
2373 unsigned int size = width * height;
2374 unsigned char *iV = yuv + size;
2375 unsigned char *iU = yuv + 5 * size / 4;
2376 for (
unsigned int i = 0; i < height / 2; i++) {
2377 for (
unsigned int j = 0; j < width / 2; j++) {
2378 U = (int)((*iU++ - 128) * 0.354);
2380 V = (int)((*iV++ - 128) * 0.707);
2385 yuv = yuv + width - 1;
2388 yuv = yuv - width + 1;
2412 *rgb++ = (
unsigned char)R;
2413 *rgb++ = (
unsigned char)G;
2414 *rgb++ = (
unsigned char)B;
2435 *rgb++ = (
unsigned char)R;
2436 *rgb++ = (
unsigned char)G;
2437 *rgb = (
unsigned char)B;
2438 rgb = rgb + 3 * width - 5;
2459 *rgb++ = (
unsigned char)R;
2460 *rgb++ = (
unsigned char)G;
2461 *rgb++ = (
unsigned char)B;
2482 *rgb++ = (
unsigned char)R;
2483 *rgb++ = (
unsigned char)G;
2484 *rgb = (
unsigned char)B;
2485 rgb = rgb - 3 * width + 1;
2502 int U, V, R, G, B, V2, U5, UV;
2503 int Y0, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10, Y11, Y12, Y13, Y14, Y15;
2504 unsigned int size = width * height;
2505 unsigned char *iV = yuv + size;
2506 unsigned char *iU = yuv + 17 * size / 16;
2507 for (
unsigned int i = 0; i < height / 4; i++) {
2508 for (
unsigned int j = 0; j < width / 4; j++) {
2509 U = (int)((*iU++ - 128) * 0.354);
2511 V = (int)((*iV++ - 128) * 0.707);
2518 yuv = yuv + width - 3;
2523 yuv = yuv + width - 3;
2528 yuv = yuv + width - 3;
2533 yuv = yuv - 3 * width + 1;
2557 *rgba++ = (
unsigned char)R;
2558 *rgba++ = (
unsigned char)G;
2559 *rgba++ = (
unsigned char)B;
2581 *rgba++ = (
unsigned char)R;
2582 *rgba++ = (
unsigned char)G;
2583 *rgba++ = (
unsigned char)B;
2605 *rgba++ = (
unsigned char)R;
2606 *rgba++ = (
unsigned char)G;
2607 *rgba++ = (
unsigned char)B;
2629 *rgba++ = (
unsigned char)R;
2630 *rgba++ = (
unsigned char)G;
2631 *rgba++ = (
unsigned char)B;
2633 rgba = rgba + 4 * width - 15;
2653 *rgba++ = (
unsigned char)R;
2654 *rgba++ = (
unsigned char)G;
2655 *rgba++ = (
unsigned char)B;
2677 *rgba++ = (
unsigned char)R;
2678 *rgba++ = (
unsigned char)G;
2679 *rgba++ = (
unsigned char)B;
2701 *rgba++ = (
unsigned char)R;
2702 *rgba++ = (
unsigned char)G;
2703 *rgba++ = (
unsigned char)B;
2725 *rgba++ = (
unsigned char)R;
2726 *rgba++ = (
unsigned char)G;
2727 *rgba++ = (
unsigned char)B;
2729 rgba = rgba + 4 * width - 15;
2749 *rgba++ = (
unsigned char)R;
2750 *rgba++ = (
unsigned char)G;
2751 *rgba++ = (
unsigned char)B;
2773 *rgba++ = (
unsigned char)R;
2774 *rgba++ = (
unsigned char)G;
2775 *rgba++ = (
unsigned char)B;
2797 *rgba++ = (
unsigned char)R;
2798 *rgba++ = (
unsigned char)G;
2799 *rgba++ = (
unsigned char)B;
2821 *rgba++ = (
unsigned char)R;
2822 *rgba++ = (
unsigned char)G;
2823 *rgba++ = (
unsigned char)B;
2825 rgba = rgba + 4 * width - 15;
2845 *rgba++ = (
unsigned char)R;
2846 *rgba++ = (
unsigned char)G;
2847 *rgba++ = (
unsigned char)B;
2869 *rgba++ = (
unsigned char)R;
2870 *rgba++ = (
unsigned char)G;
2871 *rgba++ = (
unsigned char)B;
2893 *rgba++ = (
unsigned char)R;
2894 *rgba++ = (
unsigned char)G;
2895 *rgba++ = (
unsigned char)B;
2917 *rgba++ = (
unsigned char)R;
2918 *rgba++ = (
unsigned char)G;
2919 *rgba++ = (
unsigned char)B;
2921 rgba = rgba - 12 * width + 1;
2935 int U, V, R, G, B, V2, U5, UV;
2936 int Y0, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10, Y11, Y12, Y13, Y14, Y15;
2937 unsigned int size = width * height;
2938 unsigned char *iV = yuv + size;
2939 unsigned char *iU = yuv + 17 * size / 16;
2940 for (
unsigned int i = 0; i < height / 4; i++) {
2941 for (
unsigned int j = 0; j < width / 4; j++) {
2942 U = (int)((*iU++ - 128) * 0.354);
2944 V = (int)((*iV++ - 128) * 0.707);
2951 yuv = yuv + width - 3;
2956 yuv = yuv + width - 3;
2961 yuv = yuv + width - 3;
2966 yuv = yuv - 3 * width + 1;
2990 *rgb++ = (
unsigned char)R;
2991 *rgb++ = (
unsigned char)G;
2992 *rgb++ = (
unsigned char)B;
3013 *rgb++ = (
unsigned char)R;
3014 *rgb++ = (
unsigned char)G;
3015 *rgb++ = (
unsigned char)B;
3036 *rgb++ = (
unsigned char)R;
3037 *rgb++ = (
unsigned char)G;
3038 *rgb++ = (
unsigned char)B;
3059 *rgb++ = (
unsigned char)R;
3060 *rgb++ = (
unsigned char)G;
3061 *rgb = (
unsigned char)B;
3062 rgb = rgb + 3 * width - 11;
3082 *rgb++ = (
unsigned char)R;
3083 *rgb++ = (
unsigned char)G;
3084 *rgb++ = (
unsigned char)B;
3105 *rgb++ = (
unsigned char)R;
3106 *rgb++ = (
unsigned char)G;
3107 *rgb++ = (
unsigned char)B;
3128 *rgb++ = (
unsigned char)R;
3129 *rgb++ = (
unsigned char)G;
3130 *rgb++ = (
unsigned char)B;
3151 *rgb++ = (
unsigned char)R;
3152 *rgb++ = (
unsigned char)G;
3153 *rgb = (
unsigned char)B;
3154 rgb = rgb + 3 * width - 11;
3174 *rgb++ = (
unsigned char)R;
3175 *rgb++ = (
unsigned char)G;
3176 *rgb++ = (
unsigned char)B;
3197 *rgb++ = (
unsigned char)R;
3198 *rgb++ = (
unsigned char)G;
3199 *rgb++ = (
unsigned char)B;
3220 *rgb++ = (
unsigned char)R;
3221 *rgb++ = (
unsigned char)G;
3222 *rgb++ = (
unsigned char)B;
3243 *rgb++ = (
unsigned char)R;
3244 *rgb++ = (
unsigned char)G;
3245 *rgb = (
unsigned char)B;
3246 rgb = rgb + 3 * width - 11;
3266 *rgb++ = (
unsigned char)R;
3267 *rgb++ = (
unsigned char)G;
3268 *rgb++ = (
unsigned char)B;
3289 *rgb++ = (
unsigned char)R;
3290 *rgb++ = (
unsigned char)G;
3291 *rgb++ = (
unsigned char)B;
3312 *rgb++ = (
unsigned char)R;
3313 *rgb++ = (
unsigned char)G;
3314 *rgb++ = (
unsigned char)B;
3335 *rgb++ = (
unsigned char)R;
3336 *rgb++ = (
unsigned char)G;
3337 *rgb++ = (
unsigned char)B;
3338 rgb = rgb - 9 * width + 1;
3354 unsigned char *pt_input = rgb;
3355 unsigned char *pt_end = rgb + 3 * size;
3356 unsigned char *pt_output = rgba;
3358 while (pt_input != pt_end) {
3359 *(pt_output++) = *(pt_input++);
3360 *(pt_output++) = *(pt_input++);
3361 *(pt_output++) = *(pt_input++);
3375 unsigned char *pt_input = rgba;
3376 unsigned char *pt_end = rgba + 4 * size;
3377 unsigned char *pt_output = rgb;
3379 while (pt_input != pt_end) {
3380 *(pt_output++) = *(pt_input++);
3381 *(pt_output++) = *(pt_input++);
3382 *(pt_output++) = *(pt_input++);
3395 #if !VISP_HAVE_SSSE3 3405 const __m128i mask_R1 = _mm_set_epi8(-1, -1, -1, -1, 15, -1, 12, -1, 9, -1, 6, -1, 3, -1, 0, -1);
3406 const __m128i mask_R2 = _mm_set_epi8(5, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
3407 const __m128i mask_R3 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 14, -1, 11, -1, 8, -1);
3408 const __m128i mask_R4 = _mm_set_epi8(13, -1, 10, -1, 7, -1, 4, -1, 1, -1, -1, -1, -1, -1, -1, -1);
3411 const __m128i mask_G1 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, 13, -1, 10, -1, 7, -1, 4, -1, 1, -1);
3412 const __m128i mask_G2 = _mm_set_epi8(6, -1, 3, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
3413 const __m128i mask_G3 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, 12, -1, 9, -1);
3414 const __m128i mask_G4 = _mm_set_epi8(14, -1, 11, -1, 8, -1, 5, -1, 2, -1, -1, -1, -1, -1, -1, -1);
3417 const __m128i mask_B1 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, 14, -1, 11, -1, 8, -1, 5, -1, 2, -1);
3418 const __m128i mask_B2 = _mm_set_epi8(7, -1, 4, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
3419 const __m128i mask_B3 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 13, -1, 10, -1);
3420 const __m128i mask_B4 = _mm_set_epi8(15, -1, 12, -1, 9, -1, 6, -1, 3, -1, 0, -1, -1, -1, -1, -1);
3423 const __m128i mask_low1 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, 15, 13, 11, 9, 7, 5, 3, 1);
3424 const __m128i mask_low2 = _mm_set_epi8(15, 13, 11, 9, 7, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1, -1);
3427 const __m128i coeff_R = _mm_set_epi16(13933, 13933, 13933, 13933, 13933, 13933, 13933, 13933);
3428 const __m128i coeff_G = _mm_set_epi16((
short int)46871, (
short int)46871, (
short int)46871, (
short int)46871,
3429 (
short int)46871, (
short int)46871, (
short int)46871, (
short int)46871);
3430 const __m128i coeff_B = _mm_set_epi16(4732, 4732, 4732, 4732, 4732, 4732, 4732, 4732);
3432 for (; i <= size - 16; i += 16) {
3434 const __m128i data1 = _mm_loadu_si128((
const __m128i *)rgb);
3435 const __m128i data2 = _mm_loadu_si128((
const __m128i *)(rgb + 16));
3436 const __m128i data3 = _mm_loadu_si128((
const __m128i *)(rgb + 32));
3438 const __m128i red_0_7 = _mm_or_si128(_mm_shuffle_epi8(data1, mask_R1), _mm_shuffle_epi8(data2, mask_R2));
3439 const __m128i green_0_7 = _mm_or_si128(_mm_shuffle_epi8(data1, mask_G1), _mm_shuffle_epi8(data2, mask_G2));
3440 const __m128i blue_0_7 = _mm_or_si128(_mm_shuffle_epi8(data1, mask_B1), _mm_shuffle_epi8(data2, mask_B2));
3442 const __m128i grays_0_7 =
3443 _mm_adds_epu16(_mm_mulhi_epu16(red_0_7, coeff_R),
3444 _mm_adds_epu16(_mm_mulhi_epu16(green_0_7, coeff_G), _mm_mulhi_epu16(blue_0_7, coeff_B)));
3446 const __m128i red_8_15 = _mm_or_si128(_mm_shuffle_epi8(data2, mask_R3), _mm_shuffle_epi8(data3, mask_R4));
3447 const __m128i green_8_15 = _mm_or_si128(_mm_shuffle_epi8(data2, mask_G3), _mm_shuffle_epi8(data3, mask_G4));
3448 const __m128i blue_8_15 = _mm_or_si128(_mm_shuffle_epi8(data2, mask_B3), _mm_shuffle_epi8(data3, mask_B4));
3450 const __m128i grays_8_15 =
3451 _mm_adds_epu16(_mm_mulhi_epu16(red_8_15, coeff_R),
3452 _mm_adds_epu16(_mm_mulhi_epu16(green_8_15, coeff_G), _mm_mulhi_epu16(blue_8_15, coeff_B)));
3454 _mm_storeu_si128((__m128i *)grey,
3455 _mm_or_si128(_mm_shuffle_epi8(grays_0_7, mask_low1), _mm_shuffle_epi8(grays_8_15, mask_low2)));
3462 for (; i < size; i++) {
3463 *grey = (
unsigned char)(0.2126 * (*rgb) + 0.7152 * (*(rgb + 1)) + 0.0722 * (*(rgb + 2)));
3470 unsigned char *pt_input = rgb;
3471 unsigned char *pt_end = rgb + size * 3;
3472 unsigned char *pt_output = grey;
3474 while (pt_input != pt_end) {
3475 *pt_output = (
unsigned char)(0.2126 * (*pt_input) + 0.7152 * (*(pt_input + 1)) + 0.0722 * (*(pt_input + 2)));
3491 #if !VISP_HAVE_SSSE3 3501 const __m128i mask_R1 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, 12, -1, 8, -1, 4, -1, 0, -1);
3502 const __m128i mask_R2 = _mm_set_epi8(12, -1, 8, -1, 4, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1);
3505 const __m128i mask_G1 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, 13, -1, 9, -1, 5, -1, 1, -1);
3506 const __m128i mask_G2 = _mm_set_epi8(13, -1, 9, -1, 5, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
3509 const __m128i mask_B1 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, 14, -1, 10, -1, 6, -1, 2, -1);
3510 const __m128i mask_B2 = _mm_set_epi8(14, -1, 10, -1, 6, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1);
3513 const __m128i mask_low1 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, 15, 13, 11, 9, 7, 5, 3, 1);
3514 const __m128i mask_low2 = _mm_set_epi8(15, 13, 11, 9, 7, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1, -1);
3517 const __m128i coeff_R = _mm_set_epi16(13933, 13933, 13933, 13933, 13933, 13933, 13933, 13933);
3518 const __m128i coeff_G = _mm_set_epi16((
short int)46871, (
short int)46871, (
short int)46871, (
short int)46871,
3519 (
short int)46871, (
short int)46871, (
short int)46871, (
short int)46871);
3520 const __m128i coeff_B = _mm_set_epi16(4732, 4732, 4732, 4732, 4732, 4732, 4732, 4732);
3522 for (; i <= size - 16; i += 16) {
3524 const __m128i data1 = _mm_loadu_si128((
const __m128i *)rgba);
3525 const __m128i data2 = _mm_loadu_si128((
const __m128i *)(rgba + 16));
3527 const __m128i red_0_7 = _mm_or_si128(_mm_shuffle_epi8(data1, mask_R1), _mm_shuffle_epi8(data2, mask_R2));
3528 const __m128i green_0_7 = _mm_or_si128(_mm_shuffle_epi8(data1, mask_G1), _mm_shuffle_epi8(data2, mask_G2));
3529 const __m128i blue_0_7 = _mm_or_si128(_mm_shuffle_epi8(data1, mask_B1), _mm_shuffle_epi8(data2, mask_B2));
3531 const __m128i grays_0_7 =
3532 _mm_adds_epu16(_mm_mulhi_epu16(red_0_7, coeff_R),
3533 _mm_adds_epu16(_mm_mulhi_epu16(green_0_7, coeff_G), _mm_mulhi_epu16(blue_0_7, coeff_B)));
3536 const __m128i data3 = _mm_loadu_si128((
const __m128i *)(rgba + 32));
3537 const __m128i data4 = _mm_loadu_si128((
const __m128i *)(rgba + 48));
3539 const __m128i red_8_15 = _mm_or_si128(_mm_shuffle_epi8(data3, mask_R1), _mm_shuffle_epi8(data4, mask_R2));
3540 const __m128i green_8_15 = _mm_or_si128(_mm_shuffle_epi8(data3, mask_G1), _mm_shuffle_epi8(data4, mask_G2));
3541 const __m128i blue_8_15 = _mm_or_si128(_mm_shuffle_epi8(data3, mask_B1), _mm_shuffle_epi8(data4, mask_B2));
3543 const __m128i grays_8_15 =
3544 _mm_adds_epu16(_mm_mulhi_epu16(red_8_15, coeff_R),
3545 _mm_adds_epu16(_mm_mulhi_epu16(green_8_15, coeff_G), _mm_mulhi_epu16(blue_8_15, coeff_B)));
3547 _mm_storeu_si128((__m128i *)grey,
3548 _mm_or_si128(_mm_shuffle_epi8(grays_0_7, mask_low1), _mm_shuffle_epi8(grays_8_15, mask_low2)));
3555 for (; i < size; i++) {
3556 *grey = (
unsigned char)(0.2126 * (*rgba) + 0.7152 * (*(rgba + 1)) + 0.0722 * (*(rgba + 2)));
3563 unsigned char *pt_input = rgba;
3564 unsigned char *pt_end = rgba + size * 4;
3565 unsigned char *pt_output = grey;
3567 while (pt_input != pt_end) {
3568 *pt_output = (
unsigned char)(0.2126 * (*pt_input) + 0.7152 * (*(pt_input + 1)) + 0.0722 * (*(pt_input + 2)));
3582 unsigned char *pt_input = grey;
3583 unsigned char *pt_end = grey + size;
3584 unsigned char *pt_output = rgba;
3586 while (pt_input != pt_end) {
3587 unsigned char p = *pt_input;
3589 *(pt_output + 1) = p;
3590 *(pt_output + 2) = p;
3604 unsigned char *pt_input = grey;
3605 unsigned char *pt_end = grey + size;
3606 unsigned char *pt_output = rgb;
3608 while (pt_input != pt_end) {
3609 unsigned char p = *pt_input;
3611 *(pt_output + 1) = p;
3612 *(pt_output + 2) = p;
3631 int lineStep = (flip) ? -(
int)(width * 3) : (
int)(width * 3);
3634 unsigned char *src = (flip) ? (bgr + (width * height * 3) + lineStep) : bgr;
3636 for (
unsigned int i = 0; i < height; i++) {
3637 unsigned char *line = src;
3638 for (
unsigned int j = 0; j < width; j++) {
3639 *rgba++ = *(line + 2);
3640 *rgba++ = *(line + 1);
3641 *rgba++ = *(line + 0);
3660 #if !VISP_HAVE_SSSE3 3667 const __m128i mask_B1 = _mm_set_epi8(-1, -1, -1, -1, 15, -1, 12, -1, 9, -1, 6, -1, 3, -1, 0, -1);
3668 const __m128i mask_B2 = _mm_set_epi8(5, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
3669 const __m128i mask_B3 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 14, -1, 11, -1, 8, -1);
3670 const __m128i mask_B4 = _mm_set_epi8(13, -1, 10, -1, 7, -1, 4, -1, 1, -1, -1, -1, -1, -1, -1, -1);
3673 const __m128i mask_G1 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, 13, -1, 10, -1, 7, -1, 4, -1, 1, -1);
3674 const __m128i mask_G2 = _mm_set_epi8(6, -1, 3, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
3675 const __m128i mask_G3 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, 12, -1, 9, -1);
3676 const __m128i mask_G4 = _mm_set_epi8(14, -1, 11, -1, 8, -1, 5, -1, 2, -1, -1, -1, -1, -1, -1, -1);
3679 const __m128i mask_R1 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, 14, -1, 11, -1, 8, -1, 5, -1, 2, -1);
3680 const __m128i mask_R2 = _mm_set_epi8(7, -1, 4, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
3681 const __m128i mask_R3 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 13, -1, 10, -1);
3682 const __m128i mask_R4 = _mm_set_epi8(15, -1, 12, -1, 9, -1, 6, -1, 3, -1, 0, -1, -1, -1, -1, -1);
3685 const __m128i mask_low1 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, 15, 13, 11, 9, 7, 5, 3, 1);
3686 const __m128i mask_low2 = _mm_set_epi8(15, 13, 11, 9, 7, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1, -1);
3709 const __m128i coeff_R = _mm_set_epi16(13933, 13933, 13933, 13933, 13933, 13933, 13933, 13933);
3710 const __m128i coeff_G = _mm_set_epi16((
short int)46871, (
short int)46871, (
short int)46871, (
short int)46871,
3711 (
short int)46871, (
short int)46871, (
short int)46871, (
short int)46871);
3712 const __m128i coeff_B = _mm_set_epi16(4732, 4732, 4732, 4732, 4732, 4732, 4732, 4732);
3715 int i = ((int)height) - 1;
3716 int lineStep = -(int)(width * 3);
3717 bgr = bgr + (width * (height - 1) * 3);
3719 unsigned char *linePtr = bgr;
3720 unsigned char r, g, b;
3723 for (; i >= 0; i--) {
3726 for (; j <= width - 16; j += 16) {
3728 const __m128i data1 = _mm_loadu_si128((
const __m128i *)bgr);
3729 const __m128i data2 = _mm_loadu_si128((
const __m128i *)(bgr + 16));
3730 const __m128i data3 = _mm_loadu_si128((
const __m128i *)(bgr + 32));
3732 const __m128i red_0_7 = _mm_or_si128(_mm_shuffle_epi8(data1, mask_R1), _mm_shuffle_epi8(data2, mask_R2));
3733 const __m128i green_0_7 = _mm_or_si128(_mm_shuffle_epi8(data1, mask_G1), _mm_shuffle_epi8(data2, mask_G2));
3734 const __m128i blue_0_7 = _mm_or_si128(_mm_shuffle_epi8(data1, mask_B1), _mm_shuffle_epi8(data2, mask_B2));
3736 const __m128i grays_0_7 =
3737 _mm_adds_epu16(_mm_mulhi_epu16(red_0_7, coeff_R),
3738 _mm_adds_epu16(_mm_mulhi_epu16(green_0_7, coeff_G), _mm_mulhi_epu16(blue_0_7, coeff_B)));
3740 const __m128i red_8_15 = _mm_or_si128(_mm_shuffle_epi8(data2, mask_R3), _mm_shuffle_epi8(data3, mask_R4));
3741 const __m128i green_8_15 = _mm_or_si128(_mm_shuffle_epi8(data2, mask_G3), _mm_shuffle_epi8(data3, mask_G4));
3742 const __m128i blue_8_15 = _mm_or_si128(_mm_shuffle_epi8(data2, mask_B3), _mm_shuffle_epi8(data3, mask_B4));
3744 const __m128i grays_8_15 =
3745 _mm_adds_epu16(_mm_mulhi_epu16(red_8_15, coeff_R), _mm_adds_epu16(_mm_mulhi_epu16(green_8_15, coeff_G),
3746 _mm_mulhi_epu16(blue_8_15, coeff_B)));
3748 _mm_storeu_si128((__m128i *)grey, _mm_or_si128(_mm_shuffle_epi8(grays_0_7, mask_low1),
3749 _mm_shuffle_epi8(grays_8_15, mask_low2)));
3755 for (; j < width; j++) {
3759 *grey++ = (
unsigned char)(0.2126 * r + 0.7152 * g + 0.0722 * b);
3762 linePtr += lineStep;
3767 for (; i >= 0; i--) {
3768 for (
unsigned int j = 0; j < width; j++) {
3772 *grey++ = (
unsigned char)(0.2126 * r + 0.7152 * g + 0.0722 * b);
3775 linePtr += lineStep;
3780 unsigned int size = width * height;
3783 for (; i <= size - 16; i += 16) {
3785 const __m128i data1 = _mm_loadu_si128((
const __m128i *)bgr);
3786 const __m128i data2 = _mm_loadu_si128((
const __m128i *)(bgr + 16));
3787 const __m128i data3 = _mm_loadu_si128((
const __m128i *)(bgr + 32));
3789 const __m128i red_0_7 = _mm_or_si128(_mm_shuffle_epi8(data1, mask_R1), _mm_shuffle_epi8(data2, mask_R2));
3790 const __m128i green_0_7 = _mm_or_si128(_mm_shuffle_epi8(data1, mask_G1), _mm_shuffle_epi8(data2, mask_G2));
3791 const __m128i blue_0_7 = _mm_or_si128(_mm_shuffle_epi8(data1, mask_B1), _mm_shuffle_epi8(data2, mask_B2));
3793 const __m128i grays_0_7 =
3794 _mm_adds_epu16(_mm_mulhi_epu16(red_0_7, coeff_R),
3795 _mm_adds_epu16(_mm_mulhi_epu16(green_0_7, coeff_G), _mm_mulhi_epu16(blue_0_7, coeff_B)));
3797 const __m128i red_8_15 = _mm_or_si128(_mm_shuffle_epi8(data2, mask_R3), _mm_shuffle_epi8(data3, mask_R4));
3798 const __m128i green_8_15 = _mm_or_si128(_mm_shuffle_epi8(data2, mask_G3), _mm_shuffle_epi8(data3, mask_G4));
3799 const __m128i blue_8_15 = _mm_or_si128(_mm_shuffle_epi8(data2, mask_B3), _mm_shuffle_epi8(data3, mask_B4));
3801 const __m128i grays_8_15 =
3802 _mm_adds_epu16(_mm_mulhi_epu16(red_8_15, coeff_R),
3803 _mm_adds_epu16(_mm_mulhi_epu16(green_8_15, coeff_G), _mm_mulhi_epu16(blue_8_15, coeff_B)));
3805 _mm_storeu_si128((__m128i *)grey, _mm_or_si128(_mm_shuffle_epi8(grays_0_7, mask_low1),
3806 _mm_shuffle_epi8(grays_8_15, mask_low2)));
3813 for (; i < size; i++) {
3814 *grey = (
unsigned char)(0.2126 * (*(bgr + 2)) + 0.7152 * (*(bgr + 1)) + 0.0722 * (*bgr));
3824 int lineStep = (flip) ? -(
int)(width * 3) : (
int)(width * 3);
3827 unsigned char *src = (flip) ? bgr + (width * height * 3) + lineStep : bgr;
3829 for (
unsigned int i = 0; i < height; i++) {
3830 unsigned char *line = src;
3831 for (
unsigned int j = 0; j < width; j++) {
3832 *grey++ = (
unsigned char)(0.2126 * *(line + 2) + 0.7152 * *(line + 1) + 0.0722 * *(line + 0));
3854 int lineStep = (flip) ? -(
int)(width * 3) : (
int)(width * 3);
3857 unsigned char *src = (flip) ? (rgb + (width * height * 3) + lineStep) : rgb;
3862 for (i = 0; i < height; i++) {
3863 unsigned char *line = src;
3864 for (j = 0; j < width; j++) {
3865 *rgba++ = *(line++);
3866 *rgba++ = *(line++);
3867 *rgba++ = *(line++);
3885 #if !VISP_HAVE_SSSE3 3891 int i = ((int)height) - 1;
3892 int lineStep = -(int)(width * 3);
3893 rgb = rgb + (width * (height - 1) * 3);
3895 unsigned char *linePtr = rgb;
3896 unsigned char r, g, b;
3900 const __m128i mask_R1 = _mm_set_epi8(-1, -1, -1, -1, 15, -1, 12, -1, 9, -1, 6, -1, 3, -1, 0, -1);
3901 const __m128i mask_R2 = _mm_set_epi8(5, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
3902 const __m128i mask_R3 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 14, -1, 11, -1, 8, -1);
3903 const __m128i mask_R4 = _mm_set_epi8(13, -1, 10, -1, 7, -1, 4, -1, 1, -1, -1, -1, -1, -1, -1, -1);
3906 const __m128i mask_G1 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, 13, -1, 10, -1, 7, -1, 4, -1, 1, -1);
3907 const __m128i mask_G2 = _mm_set_epi8(6, -1, 3, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
3908 const __m128i mask_G3 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, 12, -1, 9, -1);
3909 const __m128i mask_G4 = _mm_set_epi8(14, -1, 11, -1, 8, -1, 5, -1, 2, -1, -1, -1, -1, -1, -1, -1);
3912 const __m128i mask_B1 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, 14, -1, 11, -1, 8, -1, 5, -1, 2, -1);
3913 const __m128i mask_B2 = _mm_set_epi8(7, -1, 4, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
3914 const __m128i mask_B3 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 13, -1, 10, -1);
3915 const __m128i mask_B4 = _mm_set_epi8(15, -1, 12, -1, 9, -1, 6, -1, 3, -1, 0, -1, -1, -1, -1, -1);
3918 const __m128i mask_low1 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, 15, 13, 11, 9, 7, 5, 3, 1);
3919 const __m128i mask_low2 = _mm_set_epi8(15, 13, 11, 9, 7, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1, -1);
3922 const __m128i coeff_R = _mm_set_epi16(13933, 13933, 13933, 13933, 13933, 13933, 13933, 13933);
3923 const __m128i coeff_G = _mm_set_epi16((
short int)46871, (
short int)46871, (
short int)46871, (
short int)46871,
3924 (
short int)46871, (
short int)46871, (
short int)46871, (
short int)46871);
3925 const __m128i coeff_B = _mm_set_epi16(4732, 4732, 4732, 4732, 4732, 4732, 4732, 4732);
3927 for (; i >= 0; i--) {
3930 for (; j <= width - 16; j += 16) {
3932 const __m128i data1 = _mm_loadu_si128((
const __m128i *)rgb);
3933 const __m128i data2 = _mm_loadu_si128((
const __m128i *)(rgb + 16));
3934 const __m128i data3 = _mm_loadu_si128((
const __m128i *)(rgb + 32));
3936 const __m128i red_0_7 = _mm_or_si128(_mm_shuffle_epi8(data1, mask_R1), _mm_shuffle_epi8(data2, mask_R2));
3937 const __m128i green_0_7 = _mm_or_si128(_mm_shuffle_epi8(data1, mask_G1), _mm_shuffle_epi8(data2, mask_G2));
3938 const __m128i blue_0_7 = _mm_or_si128(_mm_shuffle_epi8(data1, mask_B1), _mm_shuffle_epi8(data2, mask_B2));
3940 const __m128i grays_0_7 =
3941 _mm_adds_epu16(_mm_mulhi_epu16(red_0_7, coeff_R),
3942 _mm_adds_epu16(_mm_mulhi_epu16(green_0_7, coeff_G), _mm_mulhi_epu16(blue_0_7, coeff_B)));
3944 const __m128i red_8_15 = _mm_or_si128(_mm_shuffle_epi8(data2, mask_R3), _mm_shuffle_epi8(data3, mask_R4));
3945 const __m128i green_8_15 = _mm_or_si128(_mm_shuffle_epi8(data2, mask_G3), _mm_shuffle_epi8(data3, mask_G4));
3946 const __m128i blue_8_15 = _mm_or_si128(_mm_shuffle_epi8(data2, mask_B3), _mm_shuffle_epi8(data3, mask_B4));
3948 const __m128i grays_8_15 =
3949 _mm_adds_epu16(_mm_mulhi_epu16(red_8_15, coeff_R), _mm_adds_epu16(_mm_mulhi_epu16(green_8_15, coeff_G),
3950 _mm_mulhi_epu16(blue_8_15, coeff_B)));
3952 _mm_storeu_si128((__m128i *)grey, _mm_or_si128(_mm_shuffle_epi8(grays_0_7, mask_low1),
3953 _mm_shuffle_epi8(grays_8_15, mask_low2)));
3959 for (; j < width; j++) {
3963 *grey++ = (
unsigned char)(0.2126 * r + 0.7152 * g + 0.0722 * b);
3966 linePtr += lineStep;
3971 for (; i >= 0; i--) {
3972 for (
unsigned int j = 0; j < width; j++) {
3976 *grey++ = (
unsigned char)(0.2126 * r + 0.7152 * g + 0.0722 * b);
3979 linePtr += lineStep;
3986 int lineStep = (flip) ? -(
int)(width * 3) : (
int)(width * 3);
3989 unsigned char *src = (flip) ? rgb + (width * height * 3) + lineStep : rgb;
3996 for (i = 0; i < height; i++) {
3997 unsigned char *line = src;
3998 for (j = 0; j < width; j++) {
4002 *grey++ = (
unsigned char)(0.2126 * r + 0.7152 * g + 0.0722 * b);
4017 void vpImageConvert::computeYCbCrLUT()
4019 if (YCbCrLUTcomputed ==
false) {
4024 int aux = index - 128;
4025 vpImageConvert::vpCrr[index] = (int)(364.6610 * aux) >> 8;
4026 vpImageConvert::vpCgb[index] = (int)(-89.8779 * aux) >> 8;
4027 vpImageConvert::vpCgr[index] = (int)(-185.8154 * aux) >> 8;
4028 vpImageConvert::vpCbb[index] = (int)(460.5724 * aux) >> 8;
4031 YCbCrLUTcomputed =
true;
4058 unsigned char *pt_ycbcr = ycbcr;
4059 unsigned char *pt_rgb = rgb;
4063 vpImageConvert::computeYCbCrLUT();
4068 int val_r, val_g, val_b;
4074 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
4075 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
4076 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
4078 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
4080 *pt_rgb++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u : (
unsigned char)val_r);
4081 *pt_rgb++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u : (
unsigned char)val_g);
4082 *pt_rgb++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u : (
unsigned char)val_b);
4115 unsigned char *pt_ycbcr = ycbcr;
4116 unsigned char *pt_rgba = rgba;
4120 vpImageConvert::computeYCbCrLUT();
4125 int val_r, val_g, val_b;
4131 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
4132 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
4133 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
4135 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
4137 *pt_rgba++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u : (
unsigned char)val_r);
4138 *pt_rgba++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u : (
unsigned char)val_g);
4139 *pt_rgba++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u : (
unsigned char)val_b);
4164 unsigned int i = 0, j = 0;
4166 while (j < size * 2) {
4168 grey[i++] = yuv[j + 2];
4195 unsigned char *pt_ycbcr = ycrcb;
4196 unsigned char *pt_rgb = rgb;
4200 vpImageConvert::computeYCbCrLUT();
4205 int val_r, val_g, val_b;
4211 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
4212 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
4213 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
4215 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
4217 *pt_rgb++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u : (
unsigned char)val_r);
4218 *pt_rgb++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u : (
unsigned char)val_g);
4219 *pt_rgb++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u : (
unsigned char)val_b);
4250 unsigned char *pt_ycbcr = ycrcb;
4251 unsigned char *pt_rgba = rgba;
4255 vpImageConvert::computeYCbCrLUT();
4260 int val_r, val_g, val_b;
4266 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
4267 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
4268 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
4270 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
4272 *pt_rgba++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u : (
unsigned char)val_r);
4273 *pt_rgba++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u : (
unsigned char)val_g);
4274 *pt_rgba++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u : (
unsigned char)val_b);
4321 unsigned int width = src.
getWidth();
4322 unsigned char *input;
4339 for (
unsigned int j = 0; j < 4; j++) {
4340 if (tabChannel[j] != NULL) {
4341 if (tabChannel[j]->getHeight() != height || tabChannel[j]->getWidth() != width) {
4342 tabChannel[j]->
resize(height, width);
4344 dst = (
unsigned char *)tabChannel[j]->bitmap;
4346 input = (
unsigned char *)src.
bitmap + j;
4351 for (; i < n; i += 4) {
4368 for (; i < n; i++) {
4389 std::map<unsigned int, unsigned int> mapOfWidths, mapOfHeights;
4410 if (mapOfWidths.size() == 1 && mapOfHeights.size() == 1) {
4411 unsigned int width = mapOfWidths.begin()->first;
4412 unsigned int height = mapOfHeights.begin()->first;
4414 RGBa.
resize(height, width);
4416 unsigned int size = width * height;
4417 for (
unsigned int i = 0; i < size; i++) {
4451 int i = (((int)size) << 1) - 1;
4452 int j = (int)size - 1;
4455 int y = grey16[i--];
4456 grey[j--] =
static_cast<unsigned char>((y + (grey16[i--] << 8)) >> 8);
4474 int i = (((int)size) << 1) - 1;
4475 int j = (int)(size * 4 - 1);
4478 int y = grey16[i--];
4479 unsigned char v =
static_cast<unsigned char>((y + (grey16[i--] << 8)) >> 8);
4487 void vpImageConvert::HSV2RGB(
const double *hue_,
const double *saturation_,
const double *value_,
unsigned char *rgb,
4488 const unsigned int size,
const unsigned int step)
4490 for (
unsigned int i = 0; i < size; i++) {
4491 double hue = hue_[i], saturation = saturation_[i], value = value_[i];
4493 if (
vpMath::equal(saturation, 0.0, std::numeric_limits<double>::epsilon())) {
4497 double h = hue * 6.0;
4498 double s = saturation;
4501 if (
vpMath::equal(h, 6.0, std::numeric_limits<double>::epsilon())) {
4505 double f = h - (int)h;
4506 double p = v * (1.0 - s);
4507 double q = v * (1.0 - s * f);
4508 double t = v * (1.0 - s * (1.0 - f));
4550 rgb[i * step + 1] = (
unsigned char)
vpMath::round(saturation * 255.0);
4551 rgb[i * step + 2] = (
unsigned char)
vpMath::round(value * 255.0);
4557 void vpImageConvert::RGB2HSV(
const unsigned char *rgb,
double *hue,
double *saturation,
double *value,
4558 const unsigned int size,
const unsigned int step)
4560 for (
unsigned int i = 0; i < size; i++) {
4561 double red, green, blue;
4565 red = rgb[i * step] / 255.0;
4566 green = rgb[i * step + 1] / 255.0;
4567 blue = rgb[i * step + 2] / 255.0;
4570 max = ((std::max))(red, blue);
4571 min = ((std::min))(green, blue);
4573 max = ((std::max))(green, blue);
4574 min = ((std::min))(red, blue);
4579 if (!
vpMath::equal(max, 0.0, std::numeric_limits<double>::epsilon())) {
4580 s = (max - min) / max;
4585 if (
vpMath::equal(s, 0.0, std::numeric_limits<double>::epsilon())) {
4588 double delta = max - min;
4589 if (
vpMath::equal(delta, 0.0, std::numeric_limits<double>::epsilon())) {
4593 if (
vpMath::equal(red, max, std::numeric_limits<double>::epsilon())) {
4594 h = (green - blue) / delta;
4595 }
else if (
vpMath::equal(green, max, std::numeric_limits<double>::epsilon())) {
4596 h = 2 + (blue - red) / delta;
4598 h = 4 + (red - green) / delta;
4604 }
else if (h > 1.0) {
4628 const unsigned int size)
4630 vpImageConvert::HSV2RGB(hue, saturation, value, rgba, size, 4);
4646 unsigned char *rgba,
const unsigned int size)
4648 for (
unsigned int i = 0; i < size; i++) {
4649 double h = hue[i] / 255.0, s = saturation[i] / 255.0, v = value[i] / 255.0;
4667 const unsigned int size)
4669 vpImageConvert::RGB2HSV(rgba, hue, saturation, value, size, 4);
4684 unsigned char *value,
const unsigned int size)
4686 for (
unsigned int i = 0; i < size; i++) {
4690 hue[i] = (
unsigned char)(255.0 * h);
4691 saturation[i] = (
unsigned char)(255.0 * s);
4692 value[i] = (
unsigned char)(255.0 * v);
4706 const unsigned int size)
4708 vpImageConvert::HSV2RGB(hue, saturation, value, rgb, size, 3);
4721 unsigned char *rgb,
const unsigned int size)
4723 for (
unsigned int i = 0; i < size; i++) {
4724 double h = hue[i] / 255.0, s = saturation[i] / 255.0, v = value[i] / 255.0;
4741 const unsigned int size)
4743 vpImageConvert::RGB2HSV(rgb, hue, saturation, value, size, 3);
4757 unsigned char *value,
const unsigned int size)
4759 for (
unsigned int i = 0; i < size; i++) {
4764 hue[i] = (
unsigned char)(255.0 * h);
4765 saturation[i] = (
unsigned char)(255.0 * s);
4766 value[i] = (
unsigned char)(255.0 * v);
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)
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
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)
unsigned int getRows() const
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)
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 int getCols() const
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)
void resize(const unsigned int h, const unsigned int w)
resize the image : Image initialization
VISP_EXPORT bool checkSSSE3()
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)
unsigned int getNumberOfPixel() const
static void YUYVToRGB(unsigned char *yuyv, unsigned char *rgb, unsigned int width, unsigned int height)
static void YUV444ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int size)
static void YUV444ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
unsigned int getHeight() const
static void YUV411ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int size)
unsigned int getSize() const
unsigned char R
Red component.
static void HSVToRGBa(const double *hue, const double *saturation, const double *value, unsigned char *rgba, const unsigned int size)
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)
unsigned int getWidth() const
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)
void getMinMaxValue(Type &min, Type &max) const
Look for the minimum and the maximum value within the bitmap.
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)