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;
1079 #if defined(VISP_HAVE_SIMDLIB)
1087 int lineStep = flip ? -
static_cast<int>(width * 3) :
static_cast<int>(width * 3);
1090 unsigned char *src = flip ? (rgb + (width * height * 3) + lineStep) : rgb;
1095 for (i = 0; i < height; ++i) {
1096 unsigned char *line = src;
1097 for (j = 0; j < width; ++j) {
1098 *rgba++ = *(++line);
1099 *rgba++ = *(++line);
1100 *rgba++ = *(++line);
1106 #if defined(VISP_HAVE_SIMDLIB)
1125 #if defined(VISP_HAVE_SIMDLIB)
1126 SimdBgraToBgr(rgba, size, 1, size * 4, rgb, size * 3);
1128 unsigned char *pt_input = rgba;
1129 unsigned char *pt_end = rgba + (4 * size);
1130 unsigned char *pt_output = rgb;
1132 while (pt_input != pt_end) {
1133 *(++pt_output) = *(++pt_input);
1134 *(++pt_output) = *(++pt_input);
1135 *(++pt_output) = *(++pt_input);
1174 #if defined(VISP_HAVE_SIMDLIB)
1176 SimdRgbToGray(rgb, width, height, width * 3, grey, width);
1182 int lineStep = flip ? -
static_cast<int>(width * 3) :
static_cast<int>(width * 3);
1185 unsigned char *src = flip ? (rgb + (width * height * 3) + lineStep) : rgb;
1192 for (i = 0; i < height; ++i) {
1193 unsigned char *line = src;
1194 for (j = 0; j < width; ++j) {
1198 *grey++ =
static_cast<unsigned char>((0.2126 * r) + (0.7152 * g) + (0.0722 * b));
1204 #if defined(VISP_HAVE_SIMDLIB)
1226 #
if defined(_OPENMP)
1231 #if defined(VISP_HAVE_SIMDLIB)
1232 const int heightAsInt =
static_cast<int>(height);
1233 #if defined(_OPENMP)
1235 omp_set_num_threads(
static_cast<int>(nThreads));
1237 #pragma omp parallel for
1239 for (
int i = 0; i < heightAsInt; ++i) {
1240 SimdRgbaToGray(rgba + (i * width * 4), width, 1, width * 4, grey + (i * width), width);
1243 #if defined(_OPENMP)
1266 #if defined(VISP_HAVE_SIMDLIB)
1267 SimdRgbaToGray(rgba, size, 1, size * 4, grey, size);
1269 unsigned char *pt_input = rgba;
1270 unsigned char *pt_end = rgba + (size * 4);
1271 unsigned char *pt_output = grey;
1273 while (pt_input != pt_end) {
1274 *pt_output =
static_cast<unsigned char>((0.2126 * (*pt_input)) + (0.7152 * (*(pt_input + 1))) + (0.0722 * (*(pt_input + 2))));
1294 #if defined(VISP_HAVE_SIMDLIB)
1315 #if defined(VISP_HAVE_SIMDLIB)
1318 unsigned char *pt_input = grey;
1319 unsigned char *pt_end = grey + size;
1320 unsigned char *pt_output = rgba;
1322 while (pt_input != pt_end) {
1323 unsigned char p = *pt_input;
1325 *(pt_output + 1) = p;
1326 *(pt_output + 2) = p;
1347 #if defined(VISP_HAVE_SIMDLIB)
1348 SimdGrayToBgr(grey, size, 1, size, rgb, size * 3);
1350 unsigned char *pt_input = grey;
1351 unsigned char *pt_end = grey + size;
1352 unsigned char *pt_output = rgb;
1354 while (pt_input != pt_end) {
1355 unsigned char p = *pt_input;
1357 *(pt_output + 1) = p;
1358 *(pt_output + 2) = p;
1384 #if defined(VISP_HAVE_SIMDLIB)
1392 int lineStep = flip ? -
static_cast<int>(width * 3) :
static_cast<int>(width * 3);
1395 unsigned char *src = flip ? (bgr + (width * height * 3) + lineStep) : bgr;
1397 for (
unsigned int i = 0; i < height; ++i) {
1398 unsigned char *line = src;
1399 for (
unsigned int j = 0; j < width; ++j) {
1400 *rgba++ = *(line + 2);
1401 *rgba++ = *(line + 1);
1402 *rgba++ = *(line + 0);
1410 #if defined(VISP_HAVE_SIMDLIB)
1432 #if defined(VISP_HAVE_SIMDLIB)
1434 SimdBgraToRgba(bgra, width, height, width * 4, rgba, width * 4);
1440 int lineStep = flip ? -
static_cast<int>(width * 4) :
static_cast<int>(width * 4);
1443 unsigned char *src = flip ? (bgra + (width * height * 4) + lineStep) : bgra;
1445 for (
unsigned int i = 0; i < height; ++i) {
1446 unsigned char *line = src;
1447 for (
unsigned int j = 0; j < width; ++j) {
1448 *rgba++ = *(line + 2);
1449 *rgba++ = *(line + 1);
1450 *rgba++ = *(line + 0);
1451 *rgba++ = *(line + 3);
1458 #if defined(VISP_HAVE_SIMDLIB)
1480 #
if defined(_OPENMP)
1485 #if defined(VISP_HAVE_SIMDLIB)
1486 const int heightAsInt =
static_cast<int>(height);
1488 #if defined(_OPENMP)
1490 omp_set_num_threads(
static_cast<int>(nThreads));
1492 #pragma omp parallel for
1494 for (
int i = 0; i < heightAsInt; ++i) {
1495 SimdBgrToGray(bgr + (i * width * 3), width, 1, width * 3, grey + (i * width), width);
1502 int lineStep = flip ? -
static_cast<int>(width * 3) :
static_cast<int>(width * 3);
1505 unsigned char *src = flip ? (bgr + (width * height * 3) + lineStep) : bgr;
1507 for (
unsigned int i = 0; i < height; ++i) {
1508 unsigned char *line = src;
1509 for (
unsigned int j = 0; j < width; ++j) {
1510 *grey++ =
static_cast<unsigned int>((0.2126 * *(line + 2)) + (0.7152 * *(line + 1)) + (0.0722 * *(line + 0)));
1517 #if defined(VISP_HAVE_SIMDLIB)
1520 #if !defined(VISP_HAVE_SIMDLIB) && defined(_OPENMP)
1542 #
if defined(_OPENMP)
1547 #if defined(VISP_HAVE_SIMDLIB)
1549 const int heightAsInt =
static_cast<int>(height);
1550 #if defined(_OPENMP)
1552 omp_set_num_threads(
static_cast<int>(nThreads));
1554 #pragma omp parallel for
1556 for (
int i = 0; i < heightAsInt; ++i) {
1557 SimdBgraToGray(bgra + (i * width * 4), width, 1, width * 4, grey + (i * width), width);
1564 int lineStep = flip ? -
static_cast<int>(width * 4) :
static_cast<int>(width * 4);
1567 unsigned char *src = flip ? (bgra + (width * height * 4) + lineStep) : bgra;
1569 for (
unsigned int i = 0; i < height; ++i) {
1570 unsigned char *line = src;
1571 for (
unsigned int j = 0; j < width; ++j) {
1572 *grey++ =
static_cast<unsigned char>((0.2126 * *(line + 2)) + (0.7152 * *(line + 1)) + (0.0722 * *(line + 0)));
1579 #if defined(VISP_HAVE_SIMDLIB)
1582 #if !defined(VISP_HAVE_SIMDLIB) && defined(_OPENMP)
1590 void vpImageConvert::computeYCbCrLUT()
1592 if (YCbCrLUTcomputed ==
false) {
1597 int aux = index - 128;
1598 vpImageConvert::vpCrr[index] =
static_cast<int>((364.6610 * aux) / 256);
1599 vpImageConvert::vpCgb[index] =
static_cast<int>((-89.8779 * aux) / 256);
1600 vpImageConvert::vpCgr[index] =
static_cast<int>((-185.8154 * aux) / 256);
1601 vpImageConvert::vpCbb[index] =
static_cast<int>((460.5724 * aux) / 256);
1604 YCbCrLUTcomputed =
true;
1633 unsigned char *pt_ycbcr = ycbcr;
1634 unsigned char *pt_rgb = rgb;
1638 vpImageConvert::computeYCbCrLUT();
1643 int val_r, val_g, val_b;
1649 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
1650 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
1651 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
1653 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
1655 *pt_rgb++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u :
static_cast<unsigned char>(val_r));
1656 *pt_rgb++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u :
static_cast<unsigned char>(val_g));
1657 *pt_rgb++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u :
static_cast<unsigned char>(val_b));
1693 unsigned char *pt_ycbcr = ycbcr;
1694 unsigned char *pt_rgba = rgba;
1698 vpImageConvert::computeYCbCrLUT();
1703 int val_r, val_g, val_b;
1709 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
1710 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
1711 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
1713 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
1715 *pt_rgba++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u :
static_cast<unsigned char>(val_r));
1716 *pt_rgba++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u :
static_cast<unsigned char>(val_g));
1717 *pt_rgba++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u :
static_cast<unsigned char>(val_b));
1746 unsigned int i = 0, j = 0;
1747 const unsigned int doubleSize = size * 2;
1748 while (j < doubleSize) {
1749 grey[i++] = ycbcr[j];
1750 grey[i++] = ycbcr[j + 2];
1780 unsigned char *pt_ycbcr = ycrcb;
1781 unsigned char *pt_rgb = rgb;
1785 vpImageConvert::computeYCbCrLUT();
1790 int val_r, val_g, val_b;
1796 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
1797 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
1798 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
1800 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
1802 *pt_rgb++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u :
static_cast<unsigned char>(val_r));
1803 *pt_rgb++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u :
static_cast<unsigned char>(val_g));
1804 *pt_rgb++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u :
static_cast<unsigned char>(val_b));
1839 unsigned char *pt_ycbcr = ycrcb;
1840 unsigned char *pt_rgba = rgba;
1844 vpImageConvert::computeYCbCrLUT();
1849 int val_r, val_g, val_b;
1855 val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
1856 val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
1857 val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
1859 vpDEBUG_TRACE(5,
"[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
1861 *pt_rgba++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u :
static_cast<unsigned char>(val_r));
1862 *pt_rgba++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u :
static_cast<unsigned char>(val_g));
1863 *pt_rgba++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u :
static_cast<unsigned char>(val_b));
1912 #if defined(VISP_HAVE_SIMDLIB)
1927 unsigned char *ptrR = pR ? pR->
bitmap :
new unsigned char[src.
getSize()];
1928 unsigned char *ptrG = pG ? pG->
bitmap :
new unsigned char[src.
getSize()];
1929 unsigned char *ptrB = pB ? pB->
bitmap :
new unsigned char[src.
getSize()];
1930 unsigned char *ptrA = pa ? pa->
bitmap :
new unsigned char[src.
getSize()];
1952 unsigned int width = src.
getWidth();
1953 unsigned char *input;
1970 for (
unsigned int j = 0; j < 4; ++j) {
1971 if (tabChannel[j] !=
nullptr) {
1972 if ((tabChannel[j]->getHeight() != height) || (tabChannel[j]->getWidth() != width)) {
1973 tabChannel[j]->
resize(height, width);
1975 dst = (
unsigned char *)tabChannel[j]->bitmap;
1977 input = (
unsigned char *)src.
bitmap + j;
1982 for (; i < n; i += 4) {
1999 for (; i < n; ++i) {
2023 std::map<unsigned int, unsigned int> mapOfWidths, mapOfHeights;
2044 if ((mapOfWidths.size() == 1) && (mapOfHeights.size() == 1)) {
2045 unsigned int width = mapOfWidths.begin()->first;
2046 unsigned int height = mapOfHeights.begin()->first;
2048 RGBa.
resize(height, width);
2051 #if defined(VISP_HAVE_SIMDLIB)
2052 if ((R !=
nullptr) && (G !=
nullptr) && (B !=
nullptr) && (a !=
nullptr)) {
2053 SimdInterleaveBgra(R->
bitmap, width, G->
bitmap, width, B->
bitmap, width, a->
bitmap, width, width, height,
2054 reinterpret_cast<uint8_t *
>(RGBa.
bitmap), width *
sizeof(
vpRGBa));
2058 unsigned int size = width * height;
2059 for (
unsigned int i = 0; i < size; ++i) {
2076 #if defined(VISP_HAVE_SIMDLIB)
2097 int i = (
static_cast<int>(size) * 2) - 1;
2098 int j =
static_cast<int>(size) - 1;
2101 int y = grey16[i--];
2102 grey[j--] =
static_cast<unsigned char>((y + (grey16[i] * 256)) / 256);
2120 int i = (
static_cast<int>(size) * 2) - 1;
2121 int j = (
static_cast<int>(size) * 4) - 1;
2124 int y = grey16[i--];
2125 unsigned char v =
static_cast<unsigned char>((y + (grey16[i] * 256)) / 256);
2149 unsigned int height,
unsigned int nThreads)
2151 demosaicBGGRToRGBaBilinearTpl(bggr, rgba, width, height, nThreads);
2167 unsigned int height,
unsigned int nThreads)
2169 demosaicBGGRToRGBaBilinearTpl(bggr, rgba, width, height, nThreads);
2185 unsigned int height,
unsigned int nThreads)
2187 demosaicGBRGToRGBaBilinearTpl(gbrg, rgba, width, height, nThreads);
2203 unsigned int height,
unsigned int nThreads)
2205 demosaicGBRGToRGBaBilinearTpl(gbrg, rgba, width, height, nThreads);
2221 unsigned int height,
unsigned int nThreads)
2223 demosaicGRBGToRGBaBilinearTpl(grbg, rgba, width, height, nThreads);
2239 unsigned int height,
unsigned int nThreads)
2241 demosaicGRBGToRGBaBilinearTpl(grbg, rgba, width, height, nThreads);
2257 unsigned int height,
unsigned int nThreads)
2259 demosaicRGGBToRGBaBilinearTpl(rggb, rgba, width, height, nThreads);
2275 unsigned int height,
unsigned int nThreads)
2277 demosaicRGGBToRGBaBilinearTpl(rggb, rgba, width, height, nThreads);
2295 unsigned int height,
unsigned int nThreads)
2297 demosaicBGGRToRGBaMalvarTpl(bggr, rgba, width, height, nThreads);
2313 unsigned int height,
unsigned int nThreads)
2315 demosaicBGGRToRGBaMalvarTpl(bggr, rgba, width, height, nThreads);
2331 unsigned int height,
unsigned int nThreads)
2333 demosaicGBRGToRGBaMalvarTpl(gbrg, rgba, width, height, nThreads);
2349 unsigned int height,
unsigned int nThreads)
2351 demosaicGBRGToRGBaMalvarTpl(gbrg, rgba, width, height, nThreads);
2367 unsigned int height,
unsigned int nThreads)
2369 demosaicGRBGToRGBaMalvarTpl(grbg, rgba, width, height, nThreads);
2385 unsigned int height,
unsigned int nThreads)
2387 demosaicGRBGToRGBaMalvarTpl(grbg, rgba, width, height, nThreads);
2403 unsigned int height,
unsigned int nThreads)
2405 demosaicRGGBToRGBaMalvarTpl(rggb, rgba, width, height, nThreads);
2421 unsigned int height,
unsigned int nThreads)
2423 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 MONO16ToGrey(unsigned char *grey16, unsigned char *grey, unsigned int size)
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 demosaicGRBGToRGBaMalvar(const uint8_t *grbg, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void demosaicGBRGToRGBaMalvar(const uint8_t *gbrg, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
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 demosaicBGGRToRGBaMalvar(const uint8_t *bggr, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
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 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 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 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 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)
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.
unsigned char B
Blue component.
unsigned char R
Red component.
unsigned char G
Green component.
unsigned char A
Additionnal component.