49 #include <visp3/core/vpConfig.h>
51 #include "private/vpBayerConversion.h"
52 #include "private/vpImageConvert_impl.h"
53 #if defined(VISP_HAVE_SIMDLIB)
54 #include <Simd/SimdLib.h>
56 #include <visp3/core/vpImageConvert.h>
58 bool vpImageConvert::YCbCrLUTcomputed =
false;
59 int vpImageConvert::vpCrr[256];
60 int vpImageConvert::vpCgb[256];
61 int vpImageConvert::vpCgr[256];
62 int vpImageConvert::vpCbb[256];
109 for (
unsigned int i = 0; i < max_xy; ++i) {
110 float val = 255.f * ((src.
bitmap[i] - min) / (max - min));
114 else if (val > 255) {
118 dest.
bitmap[i] =
static_cast<unsigned char>(val);
136 for (
unsigned int i = 0; i < srcHeight; ++i) {
137 for (
unsigned int j = 0; j < srcWidth; ++j) {
138 for (
unsigned int c = 0; c < 3; ++c) {
139 float val = 255.f * ((
reinterpret_cast<const float *
>(&(src[i][j]))[c] -
reinterpret_cast<float *
>(&min)[c]) /
140 (
reinterpret_cast<float *
>(&max)[c] -
reinterpret_cast<float *
>(&min)[c]));
142 reinterpret_cast<unsigned char *
>(&(dest[i][j]))[c] = 0;
144 else if (val > 255) {
145 reinterpret_cast<unsigned char *
>(&(dest[i][j]))[c] = 255;
148 reinterpret_cast<unsigned char *
>(&(dest[i][j]))[c] =
static_cast<unsigned char>(val);
163 const unsigned int srcSize = srcHeight * srcWidth;
164 dest.
resize(srcHeight, srcWidth);
165 for (
unsigned int i = 0; i < srcSize; ++i) {
184 for (
unsigned int i = 0; i < max_xy; ++i) {
185 double val = 255. * ((src.
bitmap[i] - min) / (max - min));
189 else if (val > 255) {
193 dest.
bitmap[i] =
static_cast<unsigned char>(val);
206 const unsigned int srcSize = src.
getSize();
209 for (
unsigned int i = 0; i < srcSize; ++i) {
210 dest.
bitmap[i] =
static_cast<unsigned char>(src.
bitmap[i] >> bitshift);
222 const unsigned int srcSize = src.
getSize();
225 for (
unsigned int i = 0; i < srcSize; ++i) {
226 dest.
bitmap[i] =
static_cast<unsigned char>(src.
bitmap[i] << bitshift);
238 const unsigned int srcSize = srcHeight * srcWidth;
239 dest.
resize(srcHeight, srcWidth);
240 for (
unsigned int i = 0; i < srcSize; ++i) {
254 vp_createDepthHistogram(src_depth, dest_rgba);
265 vp_createDepthHistogram(src_depth, dest_depth);
277 vp_createDepthHistogram(src_depth, dest_rgba);
288 vp_createDepthHistogram(src_depth, dest_depth);
291 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC)
335 dest.
resize(
static_cast<unsigned int>(src.rows),
static_cast<unsigned int>(src.cols));
336 unsigned int destRows = dest.
getRows();
337 unsigned int destCols = dest.
getCols();
338 if (src.type() == CV_8UC4) {
340 for (
unsigned int i = 0; i < destRows; ++i)
341 for (
unsigned int j = 0; j < destCols; ++j) {
342 cv::Vec4b tmp = src.at<cv::Vec4b>(
static_cast<int>(i),
static_cast<int>(j));
348 dest[destRows - i - 1][j] = rgbaVal;
351 dest[i][j] = rgbaVal;
355 else if (src.type() == CV_8UC3) {
356 #if defined(VISP_HAVE_SIMDLIB)
357 if (src.isContinuous() && (!flip)) {
358 SimdRgbToBgra(src.data, src.cols, src.rows, src.step[0],
reinterpret_cast<uint8_t *
>(dest.
bitmap),
365 for (
unsigned int i = 0; i < destRows; ++i) {
366 for (
unsigned int j = 0; j < destCols; ++j) {
367 cv::Vec3b tmp = src.at<cv::Vec3b>(
static_cast<int>(i),
static_cast<int>(j));
372 dest[destRows - i - 1][j] = rgbaVal;
375 dest[i][j] = rgbaVal;
379 #if defined(VISP_HAVE_SIMDLIB)
383 else if (src.type() == CV_8UC1) {
384 #if defined(VISP_HAVE_SIMDLIB)
385 if (src.isContinuous() && (!flip)) {
386 SimdGrayToBgra(src.data, src.cols, src.rows, src.step[0],
reinterpret_cast<uint8_t *
>(dest.
bitmap),
392 for (
unsigned int i = 0; i < destRows; ++i) {
393 for (
unsigned int j = 0; j < destCols; ++j) {
394 rgbaVal = src.at<
unsigned char>(
static_cast<int>(i),
static_cast<int>(j));
397 dest[destRows - i - 1][j] = rgbaVal;
400 dest[i][j] = rgbaVal;
404 #if defined(VISP_HAVE_SIMDLIB)
447 if (src.type() == CV_8UC1) {
448 dest.
resize(
static_cast<unsigned int>(src.rows),
static_cast<unsigned int>(src.cols));
449 unsigned int destRows = dest.
getRows();
450 unsigned int destCols = dest.
getCols();
451 if (src.isContinuous() && (!flip)) {
452 memcpy(dest.
bitmap, src.data,
static_cast<size_t>(src.rows * src.cols));
456 for (
unsigned int i = 0; i < destRows; ++i) {
457 memcpy(dest.
bitmap + (i * destCols), src.data + ((destRows - i - 1) * src.step1()),
static_cast<size_t>(src.step));
461 for (
unsigned int i = 0; i < destRows; ++i) {
462 memcpy(dest.
bitmap + (i * destCols), src.data + (i * src.step1()),
static_cast<size_t>(src.step));
467 else if (src.type() == CV_8UC3) {
468 dest.
resize(
static_cast<unsigned int>(src.rows),
static_cast<unsigned int>(src.cols));
469 unsigned int destRows = dest.
getRows();
470 unsigned int destCols = dest.
getCols();
471 if (src.isContinuous()) {
472 BGRToGrey((
unsigned char *)src.data, (
unsigned char *)dest.
bitmap,
static_cast<unsigned int>(src.cols),
static_cast<unsigned int>(src.rows),
477 for (
unsigned int i = 0; i < destRows; ++i) {
478 BGRToGrey((
unsigned char *)src.data + (i * src.step1()),
479 (
unsigned char *)dest.
bitmap + ((destRows - i - 1) * destCols),
480 static_cast<unsigned int>(destCols), 1,
false);
484 for (
unsigned int i = 0; i < destRows; ++i) {
485 BGRToGrey((
unsigned char *)src.data + (i * src.step1()), (
unsigned char *)dest.
bitmap + (i * destCols),
486 static_cast<unsigned int>(destCols), 1,
false);
491 else if (src.type() == CV_8UC4) {
492 dest.
resize(
static_cast<unsigned int>(src.rows),
static_cast<unsigned int>(src.cols));
493 unsigned int destRows = dest.
getRows();
494 unsigned int destCols = dest.
getCols();
495 if (src.isContinuous()) {
496 BGRaToGrey((
unsigned char *)src.data, (
unsigned char *)dest.
bitmap,
static_cast<unsigned int>(src.cols),
497 static_cast<unsigned int>(src.rows), flip, nThreads);
501 for (
unsigned int i = 0; i < destRows; ++i) {
502 BGRaToGrey((
unsigned char *)src.data + (i * src.step1()),
503 (
unsigned char *)dest.
bitmap + ((destRows - i - 1) * destCols),
504 static_cast<unsigned int>(destCols), 1,
false);
508 for (
unsigned int i = 0; i < destRows; ++i) {
509 BGRaToGrey((
unsigned char *)src.data + (i * src.step1()), (
unsigned char *)dest.
bitmap + (i * destCols),
510 static_cast<unsigned int>(destCols), 1,
false);
526 dest.
resize(
static_cast<unsigned int>(src.rows),
static_cast<unsigned int>(src.cols));
527 unsigned int destRows = dest.
getRows();
528 unsigned int destCols = dest.
getCols();
530 if (src.type() == CV_32FC1) {
531 for (
unsigned int i = 0; i < destRows; ++i)
532 for (
unsigned int j = 0; j < destCols; ++j) {
534 dest[dest.
getRows() - i - 1][j] = src.at<
float>(
static_cast<int>(i),
static_cast<int>(j));
537 dest[i][j] = src.at<
float>(
static_cast<int>(i),
static_cast<int>(j));
557 unsigned int nbRows =
static_cast<unsigned int>(src.rows);
558 unsigned int nbCols =
static_cast<unsigned int>(src.cols);
559 dest.
resize(nbRows, nbCols);
560 for (
unsigned int i = 0; i < nbRows; ++i) {
561 for (
unsigned int j = 0; j < nbCols; ++j) {
562 dest[i][j] = I_float[i][j];
576 dest.
resize(
static_cast<unsigned int>(src.rows),
static_cast<unsigned int>(src.cols));
577 unsigned int destRows = dest.
getRows();
578 unsigned int destCols = dest.
getCols();
580 if (src.type() == CV_16UC1) {
581 if (src.isContinuous()) {
582 memcpy(dest.
bitmap, src.data,
static_cast<size_t>(src.rows * src.cols) *
sizeof(uint16_t));
586 for (
unsigned int i = 0; i < destRows; ++i) {
587 memcpy(dest.
bitmap + (i * destCols), src.data + ((destRows - i - 1) * src.step1() *
sizeof(uint16_t)),
static_cast<size_t>(src.step));
591 for (
unsigned int i = 0; i < destRows; ++i) {
592 memcpy(dest.
bitmap + (i * destCols), src.data + (i * src.step1() *
sizeof(uint16_t)),
static_cast<size_t>(src.step));
611 dest.
resize(
static_cast<unsigned int>(src.rows),
static_cast<unsigned int>(src.cols));
612 unsigned int destRows = dest.
getRows();
613 unsigned int destCols = dest.
getCols();
615 if (src.type() == CV_32FC3) {
617 for (
unsigned int i = 0; i < destRows; ++i)
618 for (
unsigned int j = 0; j < destCols; ++j) {
619 cv::Vec3f tmp = src.at<cv::Vec3f>(
static_cast<int>(i),
static_cast<int>(j));
624 dest[destRows - i - 1][j] = rgbVal;
674 cv::Mat vpToMat(
static_cast<int>(src.
getRows()),
static_cast<int>(src.
getCols()), CV_8UC4, (
void *)src.
bitmap);
675 cv::cvtColor(vpToMat, dest, cv::COLOR_RGBA2BGR);
719 cv::Mat tmpMap(
static_cast<int>(src.
getRows()),
static_cast<int>(src.
getCols()), CV_8UC1, (
void *)src.
bitmap);
720 dest = tmpMap.clone();
723 dest = cv::Mat(
static_cast<int>(src.
getRows()),
static_cast<int>(src.
getCols()), CV_8UC1, (
void *)src.
bitmap);
730 cv::Mat tmpMap(
static_cast<int>(src.
getRows()),
static_cast<int>(src.
getCols()), CV_32FC1, (
void *)src.
bitmap);
731 dest = tmpMap.clone();
734 dest = cv::Mat(
static_cast<int>(src.
getRows()),
static_cast<int>(src.
getCols()), CV_32FC1, (
void *)src.
bitmap);
740 unsigned int nbRows = src.
getRows();
741 unsigned int nbCols = src.
getCols();
743 for (
unsigned int i = 0; i < nbRows; ++i) {
744 for (
unsigned int j = 0; j < nbCols; ++j) {
745 I_float[i][j] =
static_cast<float>(src[i][j]);
748 convert(I_float, dest, copyData);
753 cv::Mat vpToMat(
static_cast<int>(src.
getRows()),
static_cast<int>(src.
getCols()), CV_32FC3, (
void *)src.
bitmap);
754 cv::cvtColor(vpToMat, dest, cv::COLOR_RGB2BGR);
759 #ifdef VISP_HAVE_YARP
801 dest->setExternal(src.
bitmap,
static_cast<int>(src.
getCols()),
static_cast<int>(src.
getRows()));
846 dest.
resize(src->height(), src->width());
848 memcpy(dest.
bitmap, src->getRawImage(), src->height() * src->width() *
sizeof(yarp::sig::PixelMono));
851 dest.
bitmap = src->getRawImage();
896 dest->setExternal(src.
bitmap,
static_cast<int>(src.
getCols()),
static_cast<int>(src.
getRows()));
940 dest.
resize(src->height(), src->width());
942 memcpy(dest.
bitmap, src->getRawImage(), src->height() * src->width() *
sizeof(yarp::sig::PixelRgba));
944 dest.
bitmap =
static_cast<vpRGBa *
>(src->getRawImage());
984 for (
unsigned int i = 0; i < srcRows; ++i) {
985 for (
unsigned int j = 0; j < srcWidth; ++j) {
986 dest->pixel(j, i).r = src[i][j].R;
987 dest->pixel(j, i).g = src[i][j].G;
988 dest->pixel(j, i).b = src[i][j].B;
1033 const int srcHeight = src->height(), srcWidth = src->width();
1034 dest.
resize(srcHeight, srcWidth);
1035 for (
int i = 0; i < srcHeight; ++i) {
1036 for (
int j = 0; j < srcWidth; ++j) {
1037 dest[i][j].R = src->pixel(j, i).r;
1038 dest[i][j].G = src->pixel(j, i).g;
1039 dest[i][j].B = src->pixel(j, i).b;
1071 int r, g, b, cr, cg, cb, y1, y2;
1073 h =
static_cast<int>(height);
1074 w =
static_cast<int>(width);
1081 cb = ((*s - 128) * 454) >> 8;
1082 cg = (*s++ - 128) * 88;
1084 cr = ((*s - 128) * 359) >> 8;
1085 cg = (cg + ((*s++ - 128) * 183)) >> 8;
1090 vpSAT(r) vpSAT(g) vpSAT(b)
1092 *d++ =
static_cast<unsigned char>(r);
1093 *d++ =
static_cast<unsigned char>(g);
1094 *d++ =
static_cast<unsigned char>(b);
1100 vpSAT(r) vpSAT(g) vpSAT(b)
1102 *d++ =
static_cast<unsigned char>(r);
1103 *d++ =
static_cast<unsigned char>(g);
1104 *d++ =
static_cast<unsigned char>(b);
1125 int r, g, b, cr, cg, cb, y1, y2;
1127 h =
static_cast<int>(height);
1128 w =
static_cast<int>(width);
1135 cb = ((*s - 128) * 454) >> 8;
1136 cg = (*s++ - 128) * 88;
1138 cr = ((*s - 128) * 359) >> 8;
1139 cg = (cg + ((*s++ - 128) * 183)) >> 8;
1144 vpSAT(r) vpSAT(g) vpSAT(b)
1146 *d++ =
static_cast<unsigned char>(r);
1147 *d++ =
static_cast<unsigned char>(g);
1148 *d++ =
static_cast<unsigned char>(b);
1153 vpSAT(r) vpSAT(g) vpSAT(b)
1155 *d++ =
static_cast<unsigned char>(r);
1156 *d++ =
static_cast<unsigned char>(g);
1157 *d++ =
static_cast<unsigned char>(b);
1174 unsigned int i = 0, j = 0;
1175 const unsigned int doubleSize = size * 2;
1176 while (j < doubleSize) {
1177 grey[i++] = yuyv[j];
1178 grey[i++] = yuyv[j + 2];
1196 for (
unsigned int i = size / 4; i; --i) {
1197 int U =
static_cast<int>((*yuv++ - 128) * 0.354);
1201 int V =
static_cast<int>((*yuv++ - 128) * 0.707);
1235 *rgba++ =
static_cast<unsigned char>(R);
1236 *rgba++ =
static_cast<unsigned char>(G);
1237 *rgba++ =
static_cast<unsigned char>(B);
1265 *rgba++ =
static_cast<unsigned char>(R);
1266 *rgba++ =
static_cast<unsigned char>(G);
1267 *rgba++ =
static_cast<unsigned char>(B);
1295 *rgba++ =
static_cast<unsigned char>(R);
1296 *rgba++ =
static_cast<unsigned char>(G);
1297 *rgba++ =
static_cast<unsigned char>(B);
1325 *rgba++ =
static_cast<unsigned char>(R);
1326 *rgba++ =
static_cast<unsigned char>(G);
1327 *rgba++ =
static_cast<unsigned char>(B);
1332 unsigned int i = 0, j = 0;
1333 unsigned char r, g, b;
1334 const unsigned int iterLimit = (numpixels * 3) / 2;
1335 while (j < iterLimit) {
1337 YUVToRGB(yuv[j + 1], yuv[j], yuv[j + 3], r, g, b);
1344 YUVToRGB(yuv[j + 2], yuv[j], yuv[j + 3], r, g, b);
1351 YUVToRGB(yuv[j + 4], yuv[j], yuv[j + 3], r, g, b);
1358 YUVToRGB(yuv[j + 5], yuv[j], yuv[j + 3], r, g, b);
1387 for (
unsigned int i = size / 2; i; --i) {
1388 int U =
static_cast<int>((*yuv++ - 128) * 0.354);
1391 int V =
static_cast<int>((*yuv++ - 128) * 0.707);
1421 *rgba++ =
static_cast<unsigned char>(R);
1422 *rgba++ =
static_cast<unsigned char>(G);
1423 *rgba++ =
static_cast<unsigned char>(B);
1451 *rgba++ =
static_cast<unsigned char>(R);
1452 *rgba++ =
static_cast<unsigned char>(G);
1453 *rgba++ =
static_cast<unsigned char>(B);
1459 unsigned int i = 0, j = 0;
1460 unsigned char r, g, b;
1461 const unsigned int doubleSize = size * 2;
1462 while (j < doubleSize) {
1464 YUVToRGB(yuv[j + 1], yuv[j], yuv[j + 2], r, g, b);
1471 YUVToRGB(yuv[j + 3], yuv[j], yuv[j + 2], r, g, b);
1492 unsigned int i = 0, j = 0;
1493 const unsigned int iterLimit = (size * 3) / 2;
1494 while (j < iterLimit) {
1495 grey[i] = yuv[j + 1];
1496 grey[i + 1] = yuv[j + 2];
1497 grey[i + 2] = yuv[j + 4];
1498 grey[i + 3] = yuv[j + 5];
1520 for (
unsigned int i = size / 2; i; --i) {
1521 int U =
static_cast<int>((*yuv++ - 128) * 0.354);
1524 int V =
static_cast<int>((*yuv++ - 128) * 0.707);
1554 *rgb++ =
static_cast<unsigned char>(R);
1555 *rgb++ =
static_cast<unsigned char>(G);
1556 *rgb++ =
static_cast<unsigned char>(B);
1583 *rgb++ =
static_cast<unsigned char>(R);
1584 *rgb++ =
static_cast<unsigned char>(G);
1585 *rgb++ =
static_cast<unsigned char>(B);
1590 unsigned int i = 0, j = 0;
1591 unsigned char r, g, b;
1592 const unsigned int doubleSize = size * 2;
1593 while (j < doubleSize) {
1595 YUVToRGB(yuv[j + 1], yuv[j], yuv[j + 2], r, g, b);
1601 YUVToRGB(yuv[j + 3], yuv[j], yuv[j + 2], r, g, b);
1623 unsigned int i = 0, j = 0;
1624 const unsigned int doubleSize = size * 2;
1626 while (j < doubleSize) {
1627 grey[i++] = yuv[j + 1];
1628 grey[i++] = yuv[j + 3];
1645 for (
unsigned int i = size / 4; i; --i) {
1646 int U =
static_cast<int>((*yuv++ - 128) * 0.354);
1650 int V =
static_cast<int>((*yuv++ - 128) * 0.707);
1684 *rgb++ =
static_cast<unsigned char>(R);
1685 *rgb++ =
static_cast<unsigned char>(G);
1686 *rgb++ =
static_cast<unsigned char>(B);
1713 *rgb++ =
static_cast<unsigned char>(R);
1714 *rgb++ =
static_cast<unsigned char>(G);
1715 *rgb++ =
static_cast<unsigned char>(B);
1742 *rgb++ =
static_cast<unsigned char>(R);
1743 *rgb++ =
static_cast<unsigned char>(G);
1744 *rgb++ =
static_cast<unsigned char>(B);
1771 *rgb++ =
static_cast<unsigned char>(R);
1772 *rgb++ =
static_cast<unsigned char>(G);
1773 *rgb++ =
static_cast<unsigned char>(B);
1778 unsigned int i = 0, j = 0;
1779 unsigned char r, g, b;
1781 const unsigned int iterLimit = (size * 3) / 2;
1782 while (j < iterLimit) {
1783 YUVToRGB(yuv[j + 1], yuv[j], yuv[j + 3], r, g, b);
1789 YUVToRGB(yuv[j + 2], yuv[j], yuv[j + 3], r, g, b);
1795 YUVToRGB(yuv[j + 4], yuv[j], yuv[j + 3], r, g, b);
1801 YUVToRGB(yuv[j + 5], yuv[j], yuv[j + 3], r, g, b);
1826 int U, V, R, G, B, V2, U5, UV;
1828 unsigned int size = width * height;
1829 unsigned char *iU = yuv + size;
1830 unsigned char *iV = yuv + ((5 * size) / 4);
1831 const unsigned int halfHeight = height / 2, halfWidth = width / 2;
1832 for (
unsigned int i = 0; i < halfHeight; ++i) {
1833 for (
unsigned int j = 0; j < halfWidth; ++j) {
1834 U =
static_cast<int>((*iU++ - 128) * 0.354);
1836 V =
static_cast<int>((*iV++ - 128) * 0.707);
1841 yuv = yuv + (width - 1);
1844 yuv = (yuv - width) + 1;
1874 *rgba++ =
static_cast<unsigned char>(R);
1875 *rgba++ =
static_cast<unsigned char>(G);
1876 *rgba++ =
static_cast<unsigned char>(B);
1904 *rgba++ =
static_cast<unsigned char>(R);
1905 *rgba++ =
static_cast<unsigned char>(G);
1906 *rgba++ =
static_cast<unsigned char>(B);
1908 rgba = rgba + 4 * width - 7;
1935 *rgba++ =
static_cast<unsigned char>(R);
1936 *rgba++ =
static_cast<unsigned char>(G);
1937 *rgba++ =
static_cast<unsigned char>(B);
1965 *rgba++ =
static_cast<unsigned char>(R);
1966 *rgba++ =
static_cast<unsigned char>(G);
1967 *rgba++ =
static_cast<unsigned char>(B);
1969 rgba = (rgba - (4 * width)) + 1;
1987 int U, V, R, G, B, V2, U5, UV;
1989 unsigned int size = width * height;
1990 unsigned char *iU = yuv + size;
1991 unsigned char *iV = yuv + ((5 * size) / 4);
1992 const unsigned int halfHeight = height / 2, halfWidth = width / 2;
1993 for (
unsigned int i = 0; i < halfHeight; ++i) {
1994 for (
unsigned int j = 0; j < halfWidth; ++j) {
1995 U =
static_cast<int>((*iU++ - 128) * 0.354);
1997 V =
static_cast<int>((*iV++ - 128) * 0.707);
2002 yuv = yuv + (width - 1);
2005 yuv = (yuv - width) + 1;
2035 *rgb++ =
static_cast<unsigned char>(R);
2036 *rgb++ =
static_cast<unsigned char>(G);
2037 *rgb++ =
static_cast<unsigned char>(B);
2064 *rgb++ =
static_cast<unsigned char>(R);
2065 *rgb++ =
static_cast<unsigned char>(G);
2066 *rgb =
static_cast<unsigned char>(B);
2067 rgb = rgb + ((3 * width) - 5);
2094 *rgb++ =
static_cast<unsigned char>(R);
2095 *rgb++ =
static_cast<unsigned char>(G);
2096 *rgb++ =
static_cast<unsigned char>(B);
2123 *rgb++ =
static_cast<unsigned char>(R);
2124 *rgb++ =
static_cast<unsigned char>(G);
2125 *rgb =
static_cast<unsigned char>(B);
2126 rgb = (rgb - (3 * width)) + 1;
2142 for (
unsigned int i = 0; i < size; ++i) {
2158 for (
unsigned int i = 0; i < size; ++i) {
2159 int U =
static_cast<int>((*yuv++ - 128) * 0.354);
2162 int V =
static_cast<int>((*yuv++ - 128) * 0.707);
2194 *rgba++ =
static_cast<unsigned char>(R);
2195 *rgba++ =
static_cast<unsigned char>(G);
2196 *rgba++ =
static_cast<unsigned char>(B);
2210 for (
unsigned int i = 0; i < size; ++i) {
2211 int U =
static_cast<int>((*yuv++ - 128) * 0.354);
2214 int V =
static_cast<int>((*yuv++ - 128) * 0.707);
2246 *rgb++ =
static_cast<unsigned char>(R);
2247 *rgb++ =
static_cast<unsigned char>(G);
2248 *rgb++ =
static_cast<unsigned char>(B);
2262 for (
unsigned int i = 0; i < size; ++i) {
2281 int U, V, R, G, B, V2, U5, UV;
2283 unsigned int size = width * height;
2284 unsigned char *iV = yuv + size;
2285 unsigned char *iU = yuv + ((5 * size) / 4);
2286 const unsigned int halfHeight = height / 2, halfWidth = width / 2;
2287 for (
unsigned int i = 0; i < halfHeight; ++i) {
2288 for (
unsigned int j = 0; j < halfWidth; ++j) {
2289 U =
static_cast<int>((*iU++ - 128) * 0.354);
2291 V =
static_cast<int>((*iV++ - 128) * 0.707);
2296 yuv = yuv + (width - 1);
2299 yuv = (yuv - width) + 1;
2329 *rgba++ =
static_cast<unsigned char>(R);
2330 *rgba++ =
static_cast<unsigned char>(G);
2331 *rgba++ =
static_cast<unsigned char>(B);
2359 *rgba++ =
static_cast<unsigned char>(R);
2360 *rgba++ =
static_cast<unsigned char>(G);
2361 *rgba++ =
static_cast<unsigned char>(B);
2363 rgba = rgba + ((4 * width) - 7);
2390 *rgba++ =
static_cast<unsigned char>(R);
2391 *rgba++ =
static_cast<unsigned char>(G);
2392 *rgba++ =
static_cast<unsigned char>(B);
2420 *rgba++ =
static_cast<unsigned char>(R);
2421 *rgba++ =
static_cast<unsigned char>(G);
2422 *rgba++ =
static_cast<unsigned char>(B);
2424 rgba = (rgba - (4 * width)) + 1;
2442 int U, V, R, G, B, V2, U5, UV;
2444 unsigned int size = width * height;
2445 unsigned char *iV = yuv + size;
2446 unsigned char *iU = yuv + ((5 * size) / 4);
2447 const unsigned int halfHeight = height / 2, halfWidth = width / 2;
2448 for (
unsigned int i = 0; i < halfHeight; ++i) {
2449 for (
unsigned int j = 0; j < halfWidth; ++j) {
2450 U =
static_cast<int>((*iU++ - 128) * 0.354);
2452 V =
static_cast<int>((*iV++ - 128) * 0.707);
2457 yuv = yuv + (width - 1);
2460 yuv = (yuv - width) + 1;
2490 *rgb++ =
static_cast<unsigned char>(R);
2491 *rgb++ =
static_cast<unsigned char>(G);
2492 *rgb++ =
static_cast<unsigned char>(B);
2519 *rgb++ =
static_cast<unsigned char>(R);
2520 *rgb++ =
static_cast<unsigned char>(G);
2521 *rgb =
static_cast<unsigned char>(B);
2522 rgb = rgb + ((3 * width) - 5);
2549 *rgb++ =
static_cast<unsigned char>(R);
2550 *rgb++ =
static_cast<unsigned char>(G);
2551 *rgb++ =
static_cast<unsigned char>(B);
2578 *rgb++ =
static_cast<unsigned char>(R);
2579 *rgb++ =
static_cast<unsigned char>(G);
2580 *rgb =
static_cast<unsigned char>(B);
2581 rgb = (rgb - (3 * width)) + 1;
2601 int U, V, R, G, B, V2, U5, UV;
2602 int Y0, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10, Y11, Y12, Y13, Y14, Y15;
2603 unsigned int size = width * height;
2604 unsigned char *iV = yuv + size;
2605 unsigned char *iU = yuv + ((17 * size) / 16);
2606 const unsigned int quarterHeight = height / 4, quarterWidth = width / 4;
2607 for (
unsigned int i = 0; i < quarterHeight; ++i) {
2608 for (
unsigned int j = 0; j < quarterWidth; ++j) {
2609 U =
static_cast<int>((*iU++ - 128) * 0.354);
2611 V =
static_cast<int>((*iV++ - 128) * 0.707);
2618 yuv = yuv + (width - 3);
2623 yuv = yuv + (width - 3);
2628 yuv = yuv + (width - 3);
2633 yuv = (yuv - (3 * width)) + 1;
2663 *rgba++ =
static_cast<unsigned char>(R);
2664 *rgba++ =
static_cast<unsigned char>(G);
2665 *rgba++ =
static_cast<unsigned char>(B);
2693 *rgba++ =
static_cast<unsigned char>(R);
2694 *rgba++ =
static_cast<unsigned char>(G);
2695 *rgba++ =
static_cast<unsigned char>(B);
2723 *rgba++ =
static_cast<unsigned char>(R);
2724 *rgba++ =
static_cast<unsigned char>(G);
2725 *rgba++ =
static_cast<unsigned char>(B);
2753 *rgba++ =
static_cast<unsigned char>(R);
2754 *rgba++ =
static_cast<unsigned char>(G);
2755 *rgba++ =
static_cast<unsigned char>(B);
2757 rgba = rgba + ((4 * width) - 15);
2783 *rgba++ =
static_cast<unsigned char>(R);
2784 *rgba++ =
static_cast<unsigned char>(G);
2785 *rgba++ =
static_cast<unsigned char>(B);
2813 *rgba++ =
static_cast<unsigned char>(R);
2814 *rgba++ =
static_cast<unsigned char>(G);
2815 *rgba++ =
static_cast<unsigned char>(B);
2843 *rgba++ =
static_cast<unsigned char>(R);
2844 *rgba++ =
static_cast<unsigned char>(G);
2845 *rgba++ =
static_cast<unsigned char>(B);
2873 *rgba++ =
static_cast<unsigned char>(R);
2874 *rgba++ =
static_cast<unsigned char>(G);
2875 *rgba++ =
static_cast<unsigned char>(B);
2877 rgba = rgba + ((4 * width) - 15);
2903 *rgba++ =
static_cast<unsigned char>(R);
2904 *rgba++ =
static_cast<unsigned char>(G);
2905 *rgba++ =
static_cast<unsigned char>(B);
2933 *rgba++ =
static_cast<unsigned char>(R);
2934 *rgba++ =
static_cast<unsigned char>(G);
2935 *rgba++ =
static_cast<unsigned char>(B);
2963 *rgba++ =
static_cast<unsigned char>(R);
2964 *rgba++ =
static_cast<unsigned char>(G);
2965 *rgba++ =
static_cast<unsigned char>(B);
2993 *rgba++ =
static_cast<unsigned char>(R);
2994 *rgba++ =
static_cast<unsigned char>(G);
2995 *rgba++ =
static_cast<unsigned char>(B);
2997 rgba = rgba + ((4 * width) - 15);
3023 *rgba++ =
static_cast<unsigned char>(R);
3024 *rgba++ =
static_cast<unsigned char>(G);
3025 *rgba++ =
static_cast<unsigned char>(B);
3053 *rgba++ =
static_cast<unsigned char>(R);
3054 *rgba++ =
static_cast<unsigned char>(G);
3055 *rgba++ =
static_cast<unsigned char>(B);
3083 *rgba++ =
static_cast<unsigned char>(R);
3084 *rgba++ =
static_cast<unsigned char>(G);
3085 *rgba++ =
static_cast<unsigned char>(B);
3113 *rgba++ =
static_cast<unsigned char>(R);
3114 *rgba++ =
static_cast<unsigned char>(G);
3115 *rgba++ =
static_cast<unsigned char>(B);
3117 rgba = (rgba - (12 * width)) + 1;
3134 int U, V, R, G, B, V2, U5, UV;
3135 int Y0, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10, Y11, Y12, Y13, Y14, Y15;
3136 unsigned int size = width * height;
3137 unsigned char *iV = yuv + size;
3138 unsigned char *iU = yuv + ((17 * size) / 16);
3139 const unsigned int quarterHeight = height / 4, quarterWidth = width / 4;
3140 for (
unsigned int i = 0; i < quarterHeight; ++i) {
3141 for (
unsigned int j = 0; j < quarterWidth; ++j) {
3142 U =
static_cast<int>((*iU++ - 128) * 0.354);
3144 V =
static_cast<int>((*iV++ - 128) * 0.707);
3151 yuv = yuv + (width - 3);
3156 yuv = yuv + (width - 3);
3161 yuv = yuv + (width - 3);
3166 yuv = (yuv - (3 * width)) + 1;
3196 *rgb++ =
static_cast<unsigned char>(R);
3197 *rgb++ =
static_cast<unsigned char>(G);
3198 *rgb++ =
static_cast<unsigned char>(B);
3225 *rgb++ =
static_cast<unsigned char>(R);
3226 *rgb++ =
static_cast<unsigned char>(G);
3227 *rgb++ =
static_cast<unsigned char>(B);
3254 *rgb++ =
static_cast<unsigned char>(R);
3255 *rgb++ =
static_cast<unsigned char>(G);
3256 *rgb++ =
static_cast<unsigned char>(B);
3283 *rgb++ =
static_cast<unsigned char>(R);
3284 *rgb++ =
static_cast<unsigned char>(G);
3285 *rgb =
static_cast<unsigned char>(B);
3286 rgb = rgb + ((3 * width) - 11);
3312 *rgb++ =
static_cast<unsigned char>(R);
3313 *rgb++ =
static_cast<unsigned char>(G);
3314 *rgb++ =
static_cast<unsigned char>(B);
3341 *rgb++ =
static_cast<unsigned char>(R);
3342 *rgb++ =
static_cast<unsigned char>(G);
3343 *rgb++ =
static_cast<unsigned char>(B);
3370 *rgb++ =
static_cast<unsigned char>(R);
3371 *rgb++ =
static_cast<unsigned char>(G);
3372 *rgb++ =
static_cast<unsigned char>(B);
3399 *rgb++ =
static_cast<unsigned char>(R);
3400 *rgb++ =
static_cast<unsigned char>(G);
3401 *rgb =
static_cast<unsigned char>(B);
3402 rgb = rgb + ((3 * width) - 11);
3428 *rgb++ =
static_cast<unsigned char>(R);
3429 *rgb++ =
static_cast<unsigned char>(G);
3430 *rgb++ =
static_cast<unsigned char>(B);
3457 *rgb++ =
static_cast<unsigned char>(R);
3458 *rgb++ =
static_cast<unsigned char>(G);
3459 *rgb++ =
static_cast<unsigned char>(B);
3486 *rgb++ =
static_cast<unsigned char>(R);
3487 *rgb++ =
static_cast<unsigned char>(G);
3488 *rgb++ =
static_cast<unsigned char>(B);
3515 *rgb++ =
static_cast<unsigned char>(R);
3516 *rgb++ =
static_cast<unsigned char>(G);
3517 *rgb =
static_cast<unsigned char>(B);
3518 rgb = rgb + 3 * width - 11;
3544 *rgb++ =
static_cast<unsigned char>(R);
3545 *rgb++ =
static_cast<unsigned char>(G);
3546 *rgb++ =
static_cast<unsigned char>(B);
3573 *rgb++ =
static_cast<unsigned char>(R);
3574 *rgb++ =
static_cast<unsigned char>(G);
3575 *rgb++ =
static_cast<unsigned char>(B);
3602 *rgb++ =
static_cast<unsigned char>(R);
3603 *rgb++ =
static_cast<unsigned char>(G);
3604 *rgb++ =
static_cast<unsigned char>(B);
3631 *rgb++ =
static_cast<unsigned char>(R);
3632 *rgb++ =
static_cast<unsigned char>(G);
3633 *rgb++ =
static_cast<unsigned char>(B);
3634 rgb = (rgb - (9 * width)) + 1;
3673 #if defined(VISP_HAVE_SIMDLIB)
3681 int lineStep = flip ? -
static_cast<int>(width * 3) :
static_cast<int>(width * 3);
3684 unsigned char *src = flip ? (rgb + (width * height * 3) + lineStep) : rgb;
3689 for (i = 0; i < height; ++i) {
3690 unsigned char *line = src;
3691 for (j = 0; j < width; ++j) {
3692 *rgba++ = *(line++);
3693 *rgba++ = *(line++);
3694 *rgba++ = *(line++);
3700 #if defined(VISP_HAVE_SIMDLIB)
3719 #if defined(VISP_HAVE_SIMDLIB)
3720 SimdBgraToBgr(rgba, size, 1, size * 4, rgb, size * 3);
3722 unsigned char *pt_input = rgba;
3723 unsigned char *pt_end = rgba + (4 * size);
3724 unsigned char *pt_output = rgb;
3726 while (pt_input != pt_end) {
3727 *(pt_output++) = *(pt_input++);
3728 *(pt_output++) = *(pt_input++);
3729 *(pt_output++) = *(pt_input++);
3768 #if defined(VISP_HAVE_SIMDLIB)
3770 SimdRgbToGray(rgb, width, height, width * 3, grey, width);
3776 int lineStep = flip ? -
static_cast<int>(width * 3) :
static_cast<int>(width * 3);
3779 unsigned char *src = flip ? (rgb + (width * height * 3) + lineStep) : rgb;
3786 for (i = 0; i < height; ++i) {
3787 unsigned char *line = src;
3788 for (j = 0; j < width; ++j) {
3792 *grey++ =
static_cast<unsigned char>((0.2126 * r) + (0.7152 * g) + (0.0722 * b));
3798 #if defined(VISP_HAVE_SIMDLIB)
3820 #
if defined(_OPENMP)
3825 #if defined(VISP_HAVE_SIMDLIB)
3826 const int heightAsInt =
static_cast<int>(height);
3827 #if defined(_OPENMP)
3829 omp_set_num_threads(
static_cast<int>(nThreads));
3831 #pragma omp parallel for
3833 for (
int i = 0; i < heightAsInt; ++i) {
3834 SimdRgbaToGray(rgba + (i * width * 4), width, 1, width * 4, grey + (i * width), width);
3837 #if defined(_OPENMP)
3860 #if defined(VISP_HAVE_SIMDLIB)
3861 SimdRgbaToGray(rgba, size, 1, size * 4, grey, size);
3863 unsigned char *pt_input = rgba;
3864 unsigned char *pt_end = rgba + (size * 4);
3865 unsigned char *pt_output = grey;
3867 while (pt_input != pt_end) {
3868 *pt_output =
static_cast<unsigned char>((0.2126 * (*pt_input)) + (0.7152 * (*(pt_input + 1))) + (0.0722 * (*(pt_input + 2))));
3888 #if defined(VISP_HAVE_SIMDLIB)
3909 #if defined(VISP_HAVE_SIMDLIB)
3912 unsigned char *pt_input = grey;
3913 unsigned char *pt_end = grey + size;
3914 unsigned char *pt_output = rgba;
3916 while (pt_input != pt_end) {
3917 unsigned char p = *pt_input;
3919 *(pt_output + 1) = p;
3920 *(pt_output + 2) = p;
3941 #if defined(VISP_HAVE_SIMDLIB)
3942 SimdGrayToBgr(grey, size, 1, size, rgb, size * 3);
3944 unsigned char *pt_input = grey;
3945 unsigned char *pt_end = grey + size;
3946 unsigned char *pt_output = rgb;
3948 while (pt_input != pt_end) {
3949 unsigned char p = *pt_input;
3951 *(pt_output + 1) = p;
3952 *(pt_output + 2) = p;
3978 #if defined(VISP_HAVE_SIMDLIB)
3986 int lineStep = flip ? -
static_cast<int>(width * 3) :
static_cast<int>(width * 3);
3989 unsigned char *src = flip ? (bgr + (width * height * 3) + lineStep) : bgr;
3991 for (
unsigned int i = 0; i < height; ++i) {
3992 unsigned char *line = src;
3993 for (
unsigned int j = 0; j < width; ++j) {
3994 *rgba++ = *(line + 2);
3995 *rgba++ = *(line + 1);
3996 *rgba++ = *(line + 0);
4004 #if defined(VISP_HAVE_SIMDLIB)
4026 #if defined(VISP_HAVE_SIMDLIB)
4028 SimdBgraToRgba(bgra, width, height, width * 4, rgba, width * 4);
4034 int lineStep = flip ? -
static_cast<int>(width * 4) :
static_cast<int>(width * 4);
4037 unsigned char *src = flip ? (bgra + (width * height * 4) + lineStep) : bgra;
4039 for (
unsigned int i = 0; i < height; ++i) {
4040 unsigned char *line = src;
4041 for (
unsigned int j = 0; j < width; ++j) {
4042 *rgba++ = *(line + 2);
4043 *rgba++ = *(line + 1);
4044 *rgba++ = *(line + 0);
4045 *rgba++ = *(line + 3);
4052 #if defined(VISP_HAVE_SIMDLIB)
4074 #
if defined(_OPENMP)
4079 #if defined(VISP_HAVE_SIMDLIB)
4080 const int heightAsInt =
static_cast<int>(height);
4082 #if defined(_OPENMP)
4084 omp_set_num_threads(
static_cast<int>(nThreads));
4086 #pragma omp parallel for
4088 for (
int i = 0; i < heightAsInt; ++i) {
4089 SimdBgrToGray(bgr + (i * width * 3), width, 1, width * 3, grey + (i * width), width);
4096 int lineStep = flip ? -
static_cast<int>(width * 3) :
static_cast<int>(width * 3);
4099 unsigned char *src = flip ? (bgr + (width * height * 3) + lineStep) : bgr;
4101 for (
unsigned int i = 0; i < height; ++i) {
4102 unsigned char *line = src;
4103 for (
unsigned int j = 0; j < width; ++j) {
4104 *grey++ =
static_cast<unsigned int>((0.2126 * *(line + 2)) + (0.7152 * *(line + 1)) + (0.0722 * *(line + 0)));
4111 #if defined(VISP_HAVE_SIMDLIB)
4114 #if !defined(VISP_HAVE_SIMDLIB) && defined(_OPENMP)
4136 #
if defined(_OPENMP)
4141 #if defined(VISP_HAVE_SIMDLIB)
4143 const int heightAsInt =
static_cast<int>(height);
4144 #if defined(_OPENMP)
4146 omp_set_num_threads(
static_cast<int>(nThreads));
4148 #pragma omp parallel for
4150 for (
int i = 0; i < heightAsInt; ++i) {
4151 SimdBgraToGray(bgra + (i * width * 4), width, 1, width * 4, grey + (i * width), width);
4158 int lineStep = flip ? -
static_cast<int>(width * 4) :
static_cast<int>(width * 4);
4161 unsigned char *src = flip ? (bgra + (width * height * 4) + lineStep) : bgra;
4163 for (
unsigned int i = 0; i < height; ++i) {
4164 unsigned char *line = src;
4165 for (
unsigned int j = 0; j < width; ++j) {
4166 *grey++ =
static_cast<unsigned char>((0.2126 * *(line + 2)) + (0.7152 * *(line + 1)) + (0.0722 * *(line + 0)));
4173 #if defined(VISP_HAVE_SIMDLIB)
4176 #if !defined(VISP_HAVE_SIMDLIB) && defined(_OPENMP)
4184 void vpImageConvert::computeYCbCrLUT()
4186 if (YCbCrLUTcomputed ==
false) {
4191 int aux = index - 128;
4192 vpImageConvert::vpCrr[index] =
static_cast<int>(364.6610 * aux) >> 8;
4193 vpImageConvert::vpCgb[index] =
static_cast<int>(-89.8779 * aux) >> 8;
4194 vpImageConvert::vpCgr[index] =
static_cast<int>(-185.8154 * aux) >> 8;
4195 vpImageConvert::vpCbb[index] =
static_cast<int>(460.5724 * aux) >> 8;
4198 YCbCrLUTcomputed =
true;
4227 unsigned char *pt_ycbcr = ycbcr;
4228 unsigned char *pt_rgb = rgb;
4232 vpImageConvert::computeYCbCrLUT();
4237 int val_r, val_g, val_b;
4243 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
4244 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
4245 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
4247 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
4249 *pt_rgb++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u : (
unsigned char)val_r);
4250 *pt_rgb++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u : (
unsigned char)val_g);
4251 *pt_rgb++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u : (
unsigned char)val_b);
4286 unsigned char *pt_ycbcr = ycbcr;
4287 unsigned char *pt_rgba = rgba;
4291 vpImageConvert::computeYCbCrLUT();
4296 int val_r, val_g, val_b;
4302 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
4303 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
4304 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
4306 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
4308 *pt_rgba++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u : (
unsigned char)val_r);
4309 *pt_rgba++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u : (
unsigned char)val_g);
4310 *pt_rgba++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u : (
unsigned char)val_b);
4338 unsigned int i = 0, j = 0;
4339 const unsigned int doubleSize = size * 2;
4340 while (j < doubleSize) {
4341 grey[i++] = ycbcr[j];
4342 grey[i++] = ycbcr[j + 2];
4372 unsigned char *pt_ycbcr = ycrcb;
4373 unsigned char *pt_rgb = rgb;
4377 vpImageConvert::computeYCbCrLUT();
4382 int val_r, val_g, val_b;
4388 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
4389 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
4390 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
4392 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
4394 *pt_rgb++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u : (
unsigned char)val_r);
4395 *pt_rgb++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u : (
unsigned char)val_g);
4396 *pt_rgb++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u : (
unsigned char)val_b);
4430 unsigned char *pt_ycbcr = ycrcb;
4431 unsigned char *pt_rgba = rgba;
4435 vpImageConvert::computeYCbCrLUT();
4440 int val_r, val_g, val_b;
4446 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
4447 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
4448 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
4450 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
4452 *pt_rgba++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u : (
unsigned char)val_r);
4453 *pt_rgba++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u : (
unsigned char)val_g);
4454 *pt_rgba++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u : (
unsigned char)val_b);
4502 #if defined(VISP_HAVE_SIMDLIB)
4517 unsigned char *ptrR = pR ? pR->
bitmap :
new unsigned char[src.
getSize()];
4518 unsigned char *ptrG = pG ? pG->
bitmap :
new unsigned char[src.
getSize()];
4519 unsigned char *ptrB = pB ? pB->
bitmap :
new unsigned char[src.
getSize()];
4520 unsigned char *ptrA = pa ? pa->
bitmap :
new unsigned char[src.
getSize()];
4542 unsigned int width = src.
getWidth();
4543 unsigned char *input;
4560 for (
unsigned int j = 0; j < 4; ++j) {
4561 if (tabChannel[j] !=
nullptr) {
4562 if ((tabChannel[j]->getHeight() != height) || (tabChannel[j]->getWidth() != width)) {
4563 tabChannel[j]->
resize(height, width);
4565 dst = (
unsigned char *)tabChannel[j]->bitmap;
4567 input = (
unsigned char *)src.
bitmap + j;
4572 for (; i < n; i += 4) {
4589 for (; i < n; ++i) {
4613 std::map<unsigned int, unsigned int> mapOfWidths, mapOfHeights;
4634 if ((mapOfWidths.size() == 1) && (mapOfHeights.size() == 1)) {
4635 unsigned int width = mapOfWidths.begin()->first;
4636 unsigned int height = mapOfHeights.begin()->first;
4638 RGBa.
resize(height, width);
4641 #if defined(VISP_HAVE_SIMDLIB)
4642 if ((R !=
nullptr) && (G !=
nullptr) && (B !=
nullptr) && (a !=
nullptr)) {
4643 SimdInterleaveBgra(R->
bitmap, width, G->
bitmap, width, B->
bitmap, width, a->
bitmap, width, width, height,
4644 reinterpret_cast<uint8_t *
>(RGBa.
bitmap), width *
sizeof(
vpRGBa));
4648 unsigned int size = width * height;
4649 for (
unsigned int i = 0; i < size; ++i) {
4666 #if defined(VISP_HAVE_SIMDLIB)
4687 int i = (((int)size) << 1) - 1;
4688 int j = (int)size - 1;
4691 int y = grey16[i--];
4692 grey[j--] =
static_cast<unsigned char>((y + (grey16[i--] << 8)) >> 8);
4709 int i = (((int)size) << 1) - 1;
4710 int j =
static_cast<int>(size * 4 - 1);
4713 int y = grey16[i--];
4714 unsigned char v =
static_cast<unsigned char>((y + (grey16[i--] << 8)) >> 8);
4732 void vpImageConvert::HSV2RGB(
const double *hue_,
const double *saturation_,
const double *value_,
unsigned char *rgb,
4733 unsigned int size,
unsigned int step)
4735 for (
unsigned int i = 0; i < size; ++i) {
4736 double hue = hue_[i], saturation = saturation_[i], value = value_[i];
4738 if (
vpMath::equal(saturation, 0.0, std::numeric_limits<double>::epsilon())) {
4743 double h = hue * 6.0;
4744 double s = saturation;
4747 if (
vpMath::equal(h, 6.0, std::numeric_limits<double>::epsilon())) {
4751 double f = h -
static_cast<int>(h);
4752 double p = v * (1.0 - s);
4753 double q = v * (1.0 - (s * f));
4754 double t = v * (1.0 - (s * (1.0 - f)));
4756 switch (
static_cast<int>(h)) {
4795 rgb[i * step] =
static_cast<unsigned char>(
vpMath::round(hue * 255.0));
4796 rgb[i * step + 1] =
static_cast<unsigned char>(
vpMath::round(saturation * 255.0));
4797 rgb[i * step + 2] =
static_cast<unsigned char>(
vpMath::round(value * 255.0));
4814 void vpImageConvert::RGB2HSV(
const unsigned char *rgb,
double *hue,
double *saturation,
double *value,
4815 unsigned int size,
unsigned int step)
4817 for (
unsigned int i = 0; i < size; ++i) {
4818 double red, green, blue;
4822 red = rgb[i * step] / 255.0;
4823 green = rgb[i * step + 1] / 255.0;
4824 blue = rgb[i * step + 2] / 255.0;
4827 max = ((std::max))(red, blue);
4828 min = ((std::min))(green, blue);
4831 max = ((std::max))(green, blue);
4832 min = ((std::min))(red, blue);
4837 if (!
vpMath::equal(max, 0.0, std::numeric_limits<double>::epsilon())) {
4838 s = (max - min) / max;
4844 if (
vpMath::equal(s, 0.0, std::numeric_limits<double>::epsilon())) {
4848 double delta = max - min;
4849 if (
vpMath::equal(delta, 0.0, std::numeric_limits<double>::epsilon())) {
4853 if (
vpMath::equal(red, max, std::numeric_limits<double>::epsilon())) {
4854 h = (green - blue) / delta;
4856 else if (
vpMath::equal(green, max, std::numeric_limits<double>::epsilon())) {
4857 h = 2 + (blue - red) / delta;
4860 h = 4 + (red - green) / delta;
4893 vpImageConvert::HSV2RGB(hue, saturation, value, rgba, size, 4);
4909 unsigned char *rgba,
unsigned int size)
4911 for (
unsigned int i = 0; i < size; ++i) {
4912 double h = hue[i] / 255.0, s = saturation[i] / 255.0, v = value[i] / 255.0;
4933 vpImageConvert::RGB2HSV(rgba, hue, saturation, value, size, 4);
4948 unsigned char *value,
unsigned int size)
4950 for (
unsigned int i = 0; i < size; ++i) {
4954 hue[i] =
static_cast<unsigned char>(255.0 * h);
4955 saturation[i] =
static_cast<unsigned char>(255.0 * s);
4956 value[i] =
static_cast<unsigned char>(255.0 * v);
4973 vpImageConvert::HSV2RGB(hue, saturation, value, rgb, size, 3);
4986 unsigned char *rgb,
unsigned int size)
4988 for (
unsigned int i = 0; i < size; ++i) {
4989 double h = hue[i] / 255.0, s = saturation[i] / 255.0, v = value[i] / 255.0;
5007 vpImageConvert::RGB2HSV(rgb, hue, saturation, value, size, 3);
5020 unsigned char *value,
unsigned int size)
5022 for (
unsigned int i = 0; i < size; ++i) {
5027 hue[i] =
static_cast<unsigned char>(255.0 * h);
5028 saturation[i] =
static_cast<unsigned char>(255.0 * s);
5029 value[i] =
static_cast<unsigned char>(255.0 * v);
5048 unsigned int height,
unsigned int nThreads)
5050 demosaicBGGRToRGBaBilinearTpl(bggr, rgba, width, height, nThreads);
5066 unsigned int height,
unsigned int nThreads)
5068 demosaicBGGRToRGBaBilinearTpl(bggr, rgba, width, height, nThreads);
5084 unsigned int height,
unsigned int nThreads)
5086 demosaicGBRGToRGBaBilinearTpl(gbrg, rgba, width, height, nThreads);
5102 unsigned int height,
unsigned int nThreads)
5104 demosaicGBRGToRGBaBilinearTpl(gbrg, rgba, width, height, nThreads);
5120 unsigned int height,
unsigned int nThreads)
5122 demosaicGRBGToRGBaBilinearTpl(grbg, rgba, width, height, nThreads);
5138 unsigned int height,
unsigned int nThreads)
5140 demosaicGRBGToRGBaBilinearTpl(grbg, rgba, width, height, nThreads);
5156 unsigned int height,
unsigned int nThreads)
5158 demosaicRGGBToRGBaBilinearTpl(rggb, rgba, width, height, nThreads);
5174 unsigned int height,
unsigned int nThreads)
5176 demosaicRGGBToRGBaBilinearTpl(rggb, rgba, width, height, nThreads);
5194 unsigned int height,
unsigned int nThreads)
5196 demosaicBGGRToRGBaMalvarTpl(bggr, rgba, width, height, nThreads);
5212 unsigned int height,
unsigned int nThreads)
5214 demosaicBGGRToRGBaMalvarTpl(bggr, rgba, width, height, nThreads);
5230 unsigned int height,
unsigned int nThreads)
5232 demosaicGBRGToRGBaMalvarTpl(gbrg, rgba, width, height, nThreads);
5248 unsigned int height,
unsigned int nThreads)
5250 demosaicGBRGToRGBaMalvarTpl(gbrg, rgba, width, height, nThreads);
5266 unsigned int height,
unsigned int nThreads)
5268 demosaicGRBGToRGBaMalvarTpl(grbg, rgba, width, height, nThreads);
5284 unsigned int height,
unsigned int nThreads)
5286 demosaicGRBGToRGBaMalvarTpl(grbg, rgba, width, height, nThreads);
5302 unsigned int height,
unsigned int nThreads)
5304 demosaicRGGBToRGBaMalvarTpl(rggb, rgba, width, height, nThreads);
5320 unsigned int height,
unsigned int nThreads)
5322 demosaicRGGBToRGBaMalvarTpl(rggb, rgba, width, height, nThreads);
error that can be emitted by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.
@ dimensionError
Bad dimension.
static void YUV411ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
static void YVU9ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int width, unsigned int height)
static void MONO16ToGrey(unsigned char *grey16, unsigned char *grey, unsigned int size)
static void HSVToRGBa(const double *hue, const double *saturation, const double *value, unsigned char *rgba, unsigned int size)
static void YUYVToRGBa(unsigned char *yuyv, unsigned char *rgba, unsigned int width, unsigned int height)
static void demosaicBGGRToRGBaBilinear(const uint8_t *bggr, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void demosaicGRBGToRGBaBilinear(const uint8_t *grbg, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void RGBToHSV(const unsigned char *rgb, double *hue, double *saturation, double *value, unsigned int size)
static void demosaicGRBGToRGBaMalvar(const uint8_t *grbg, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void YUV422ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
static void YUV420ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int width, unsigned int height)
static void YUYVToGrey(unsigned char *yuyv, unsigned char *grey, unsigned int size)
static void YUV411ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int size)
static void YUV420ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
static void demosaicGBRGToRGBaMalvar(const uint8_t *gbrg, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void YVU9ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int width, unsigned int height)
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 YV12ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int width, unsigned int height)
static void YUV444ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int size)
static void demosaicBGGRToRGBaMalvar(const uint8_t *bggr, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void YUV411ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int size)
static void YUVToRGB(unsigned char y, unsigned char u, unsigned char v, unsigned char &r, unsigned char &g, unsigned char &b)
static void demosaicGBRGToRGBaBilinear(const uint8_t *gbrg, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void YCbCrToGrey(unsigned char *ycbcr, unsigned char *grey, 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=nullptr)
static void YUV422ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int size)
static void YCrCbToRGB(unsigned char *ycrcb, unsigned char *rgb, unsigned int size)
static void YCbCrToRGBa(unsigned char *ycbcr, unsigned char *rgb, unsigned int size)
static void createDepthHistogram(const vpImage< uint16_t > &src_depth, vpImage< vpRGBa > &dest_rgba)
static void RGBaToHSV(const unsigned char *rgba, double *hue, double *saturation, double *value, unsigned int size)
static void demosaicRGGBToRGBaMalvar(const uint8_t *rggb, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void GreyToRGBa(unsigned char *grey, unsigned char *rgba, unsigned int width, unsigned int height)
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void MONO16ToRGBa(unsigned char *grey16, unsigned char *rgba, unsigned int size)
static void RGBToGrey(unsigned char *rgb, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false)
static void RGBaToGrey(unsigned char *rgba, unsigned char *grey, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void GreyToRGB(unsigned char *grey, unsigned char *rgb, unsigned int size)
static void YCrCbToRGBa(unsigned char *ycrcb, unsigned char *rgb, unsigned int size)
static void RGBToRGBa(unsigned char *rgb, unsigned char *rgba, unsigned int size)
static void YCbCrToRGB(unsigned char *ycbcr, unsigned char *rgb, unsigned int size)
static void BGRaToGrey(unsigned char *bgra, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false, unsigned int nThreads=0)
static void YUV422ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int size)
static void YV12ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int width, unsigned int height)
static void BGRToGrey(unsigned char *bgr, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false, unsigned int nThreads=0)
static void BGRToRGBa(unsigned char *bgr, unsigned char *rgba, unsigned int width, unsigned int height, bool flip=false)
static void demosaicRGGBToRGBaBilinear(const uint8_t *rggb, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void YUV444ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int size)
static void BGRaToRGBa(unsigned char *bgra, unsigned char *rgba, unsigned int width, unsigned int height, bool flip=false)
static void RGBaToRGB(unsigned char *rgba, unsigned char *rgb, unsigned int size)
static void YUV444ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
static void YUV420ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int width, unsigned int height)
static void HSVToRGB(const double *hue, const double *saturation, const double *value, unsigned char *rgb, unsigned int size)
static void YUYVToRGB(unsigned char *yuyv, unsigned char *rgb, unsigned int width, unsigned int height)
unsigned int getWidth() const
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
unsigned int getNumberOfPixel() const
unsigned int getSize() const
unsigned int getCols() const
Type * bitmap
points toward the bitmap
unsigned int getHeight() const
unsigned int getRows() const
void getMinMaxValue(Type &min, Type &max, bool onlyFiniteVal=true) const
Look for the minimum and the maximum value within the bitmap.
static bool equal(double x, double y, double threshold=0.001)
static int round(double x)
unsigned char B
Blue component.
unsigned char R
Red component.
unsigned char G
Green component.
unsigned char A
Additionnal component.