40 #include <visp3/core/vpConfig.h>
41 #include <visp3/core/vpImageConvert.h>
47 const int val_255 = 255;
51 else if (c > val_255) {
76 int r, g, b, cr, cg, cb, y1, y2;
78 const int val_88 = 88;
79 const int val_128 = 128;
80 const int val_183 = 183;
81 const int val_256 = 256;
82 const int val_359 = 359;
83 const int val_454 = 454;
85 h =
static_cast<int>(height);
86 w =
static_cast<int>(width);
94 cb = ((*s - val_128) * val_454) / val_256;
95 cg = (*s - val_128) * val_88;
99 cr = ((*s - val_128) * val_359) / val_256;
100 cg = (cg + ((*s - val_128) * val_183)) / val_256;
110 *d++ =
static_cast<unsigned char>(r);
111 *d++ =
static_cast<unsigned char>(g);
112 *d++ =
static_cast<unsigned char>(b);
122 *d++ =
static_cast<unsigned char>(r);
123 *d++ =
static_cast<unsigned char>(g);
124 *d++ =
static_cast<unsigned char>(b);
145 int r, g, b, cr, cg, cb, y1, y2;
147 const int val_88 = 88;
148 const int val_128 = 128;
149 const int val_183 = 183;
150 const int val_256 = 256;
151 const int val_359 = 359;
152 const int val_454 = 454;
154 h =
static_cast<int>(height);
155 w =
static_cast<int>(width);
163 cb = ((*s - val_128) * val_454) / val_256;
164 cg = (*s - val_128) * val_88;
168 cr = ((*s - val_128) * val_359) / val_256;
169 cg = (cg + ((*s - val_128) * val_183)) / val_256;
179 *d++ =
static_cast<unsigned char>(r);
180 *d++ =
static_cast<unsigned char>(g);
181 *d++ =
static_cast<unsigned char>(b);
190 *d++ =
static_cast<unsigned char>(r);
191 *d++ =
static_cast<unsigned char>(g);
192 *d++ =
static_cast<unsigned char>(b);
209 const unsigned int val_2 = 2;
210 const unsigned int val_4 = 4;
211 unsigned int i = 0, j = 0;
212 const unsigned int doubleSize = size * 2;
213 while (j < doubleSize) {
215 grey[i++] = yuyv[j + val_2];
231 const unsigned int val_128 = 128;
232 for (
unsigned int i = size / 4; i; --i) {
233 int U =
static_cast<int>((*yuv - val_128) * 0.354);
240 int V =
static_cast<int>((*yuv - val_128) * 0.707);
262 *rgba++ =
static_cast<unsigned char>(R);
263 *rgba++ =
static_cast<unsigned char>(G);
264 *rgba++ =
static_cast<unsigned char>(B);
277 *rgba++ =
static_cast<unsigned char>(R);
278 *rgba++ =
static_cast<unsigned char>(G);
279 *rgba++ =
static_cast<unsigned char>(B);
292 *rgba++ =
static_cast<unsigned char>(R);
293 *rgba++ =
static_cast<unsigned char>(G);
294 *rgba++ =
static_cast<unsigned char>(B);
307 *rgba++ =
static_cast<unsigned char>(R);
308 *rgba++ =
static_cast<unsigned char>(G);
309 *rgba++ =
static_cast<unsigned char>(B);
328 const unsigned int val_2 = 2;
329 const unsigned int val_128 = 128;
330 for (
unsigned int i = size / val_2; i; --i) {
331 int U =
static_cast<int>((*yuv - val_128) * 0.354);
336 int V =
static_cast<int>((*yuv - val_128) * 0.707);
353 *rgba++ =
static_cast<unsigned char>(R);
354 *rgba++ =
static_cast<unsigned char>(G);
355 *rgba++ =
static_cast<unsigned char>(B);
368 *rgba++ =
static_cast<unsigned char>(R);
369 *rgba++ =
static_cast<unsigned char>(G);
370 *rgba++ =
static_cast<unsigned char>(B);
385 unsigned int i = 0, j = 0;
386 const unsigned int val_2 = 2;
387 const unsigned int val_3 = 3;
388 const unsigned int val_4 = 4;
389 const unsigned int val_5 = 5;
390 const unsigned int val_6 = 6;
391 const unsigned int iterLimit = (size * val_3) / val_2;
392 while (j < iterLimit) {
393 grey[i] = yuv[j + 1];
394 grey[i + 1] = yuv[j + val_2];
395 grey[i + val_2] = yuv[j + val_4];
396 grey[i + val_3] = yuv[j + val_5];
416 const unsigned int val_2 = 2;
417 const unsigned int val_128 = 128;
418 for (
unsigned int i = size / val_2; i; --i) {
419 int U =
static_cast<int>((*yuv - val_128) * 0.354);
424 int V =
static_cast<int>((*yuv - val_128) * 0.707);
441 *rgb++ =
static_cast<unsigned char>(R);
442 *rgb++ =
static_cast<unsigned char>(G);
443 *rgb++ =
static_cast<unsigned char>(B);
455 *rgb++ =
static_cast<unsigned char>(R);
456 *rgb++ =
static_cast<unsigned char>(G);
457 *rgb++ =
static_cast<unsigned char>(B);
473 const unsigned int val_3 = 3;
474 const unsigned int val_4 = 4;
475 unsigned int i = 0, j = 0;
476 const unsigned int doubleSize = size * 2;
478 while (j < doubleSize) {
479 grey[i++] = yuv[j + 1];
480 grey[i++] = yuv[j + val_3];
495 const unsigned int val_128 = 128;
496 for (
unsigned int i = size / 4; i; --i) {
497 int U =
static_cast<int>((*yuv - val_128) * 0.354);
504 int V =
static_cast<int>((*yuv - val_128) * 0.707);
526 *rgb++ =
static_cast<unsigned char>(R);
527 *rgb++ =
static_cast<unsigned char>(G);
528 *rgb++ =
static_cast<unsigned char>(B);
540 *rgb++ =
static_cast<unsigned char>(R);
541 *rgb++ =
static_cast<unsigned char>(G);
542 *rgb++ =
static_cast<unsigned char>(B);
554 *rgb++ =
static_cast<unsigned char>(R);
555 *rgb++ =
static_cast<unsigned char>(G);
556 *rgb++ =
static_cast<unsigned char>(B);
568 *rgb++ =
static_cast<unsigned char>(R);
569 *rgb++ =
static_cast<unsigned char>(G);
570 *rgb++ =
static_cast<unsigned char>(B);
586 int U, V, R, G, B, V2, U5, UV;
588 const unsigned int val_2 = 2;
589 const unsigned int val_4 = 4;
590 const unsigned int val_5 = 5;
591 const unsigned int val_7 = 7;
592 unsigned int size = width * height;
593 unsigned char *iU = yuv + size;
594 unsigned char *iV = yuv + ((val_5 * size) / val_4);
595 const unsigned int halfHeight = height / val_2, halfWidth = width / val_2;
596 const unsigned int val_128 = 128;
597 for (
unsigned int i = 0; i < halfHeight; ++i) {
598 for (
unsigned int j = 0; j < halfWidth; ++j) {
599 U =
static_cast<int>(((*iU) - val_128) * 0.354);
602 V =
static_cast<int>(((*iV) - val_128) * 0.707);
609 yuv = yuv + (width - 1);
613 yuv = (yuv - width) + 1;
628 *rgba++ =
static_cast<unsigned char>(R);
629 *rgba++ =
static_cast<unsigned char>(G);
630 *rgba++ =
static_cast<unsigned char>(B);
643 *rgba++ =
static_cast<unsigned char>(R);
644 *rgba++ =
static_cast<unsigned char>(G);
645 *rgba++ =
static_cast<unsigned char>(B);
647 rgba = (rgba + (val_4 * width)) - val_7;
659 *rgba++ =
static_cast<unsigned char>(R);
660 *rgba++ =
static_cast<unsigned char>(G);
661 *rgba++ =
static_cast<unsigned char>(B);
674 *rgba++ =
static_cast<unsigned char>(R);
675 *rgba++ =
static_cast<unsigned char>(G);
676 *rgba++ =
static_cast<unsigned char>(B);
678 rgba = (rgba - (val_4 * width)) + 1;
681 rgba += val_4 * width;
695 int U, V, R, G, B, V2, U5, UV;
697 const unsigned int val_2 = 2;
698 const unsigned int val_3 = 3;
699 const unsigned int val_4 = 4;
700 const unsigned int val_5 = 5;
701 unsigned int size = width * height;
702 unsigned char *iU = yuv + size;
703 unsigned char *iV = yuv + ((val_5 * size) / val_4);
704 const unsigned int halfHeight = height / val_2, halfWidth = width / val_2;
705 const unsigned int val_128 = 128;
706 for (
unsigned int i = 0; i < halfHeight; ++i) {
707 for (
unsigned int j = 0; j < halfWidth; ++j) {
708 U =
static_cast<int>(((*iU) - val_128) * 0.354);
711 V =
static_cast<int>(((*iV) - val_128) * 0.707);
718 yuv = yuv + (width - 1);
722 yuv = (yuv - width) + 1;
737 *rgb++ =
static_cast<unsigned char>(R);
738 *rgb++ =
static_cast<unsigned char>(G);
739 *rgb++ =
static_cast<unsigned char>(B);
751 *rgb++ =
static_cast<unsigned char>(R);
752 *rgb++ =
static_cast<unsigned char>(G);
753 *rgb =
static_cast<unsigned char>(B);
754 rgb = rgb + ((val_3 * width) - val_5);
766 *rgb++ =
static_cast<unsigned char>(R);
767 *rgb++ =
static_cast<unsigned char>(G);
768 *rgb++ =
static_cast<unsigned char>(B);
780 *rgb++ =
static_cast<unsigned char>(R);
781 *rgb++ =
static_cast<unsigned char>(G);
782 *rgb =
static_cast<unsigned char>(B);
783 rgb = (rgb - (val_3 * width)) + 1;
786 rgb += val_3 * width;
799 for (
unsigned int i = 0; i < size; ++i) {
816 const unsigned int val_128 = 128;
817 for (
unsigned int i = 0; i < size; ++i) {
818 int U =
static_cast<int>((*yuv - val_128) * 0.354);
823 int V =
static_cast<int>((*yuv - val_128) * 0.707);
841 *rgba++ =
static_cast<unsigned char>(R);
842 *rgba++ =
static_cast<unsigned char>(G);
843 *rgba++ =
static_cast<unsigned char>(B);
857 const unsigned int val_128 = 128;
858 for (
unsigned int i = 0; i < size; ++i) {
859 int U =
static_cast<int>((*yuv - val_128) * 0.354);
864 int V =
static_cast<int>((*yuv - val_128) * 0.707);
882 *rgb++ =
static_cast<unsigned char>(R);
883 *rgb++ =
static_cast<unsigned char>(G);
884 *rgb++ =
static_cast<unsigned char>(B);
897 const unsigned int val_3 = 3;
899 for (
unsigned int i = 0; i < size; ++i) {
917 int U, V, R, G, B, V2, U5, UV;
919 const unsigned int val_2 = 2;
920 const unsigned int val_4 = 4;
921 const unsigned int val_5 = 5;
922 const unsigned int val_7 = 7;
923 unsigned int size = width * height;
924 unsigned char *iV = yuv + size;
925 unsigned char *iU = yuv + ((val_5 * size) / val_4);
926 const unsigned int halfHeight = height / val_2, halfWidth = width / val_2;
927 const unsigned int val_128 = 128;
928 for (
unsigned int i = 0; i < halfHeight; ++i) {
929 for (
unsigned int j = 0; j < halfWidth; ++j) {
930 U =
static_cast<int>(((*iU) - val_128) * 0.354);
933 V =
static_cast<int>(((*iV) - val_128) * 0.707);
940 yuv = yuv + (width - 1);
944 yuv = (yuv - width) + 1;
959 *rgba++ =
static_cast<unsigned char>(R);
960 *rgba++ =
static_cast<unsigned char>(G);
961 *rgba++ =
static_cast<unsigned char>(B);
974 *rgba++ =
static_cast<unsigned char>(R);
975 *rgba++ =
static_cast<unsigned char>(G);
976 *rgba++ =
static_cast<unsigned char>(B);
978 rgba = rgba + ((val_4 * width) - val_7);
990 *rgba++ =
static_cast<unsigned char>(R);
991 *rgba++ =
static_cast<unsigned char>(G);
992 *rgba++ =
static_cast<unsigned char>(B);
1005 *rgba++ =
static_cast<unsigned char>(R);
1006 *rgba++ =
static_cast<unsigned char>(G);
1007 *rgba++ =
static_cast<unsigned char>(B);
1009 rgba = (rgba - (val_4 * width)) + 1;
1012 rgba += val_4 * width;
1026 int U, V, R, G, B, V2, U5, UV;
1028 const unsigned int val_2 = 2;
1029 const unsigned int val_3 = 3;
1030 const unsigned int val_4 = 4;
1031 const unsigned int val_5 = 5;
1032 unsigned int size = width * height;
1033 unsigned char *iV = yuv + size;
1034 unsigned char *iU = yuv + ((val_5 * size) / val_4);
1035 const unsigned int halfHeight = height / val_2, halfWidth = width / val_2;
1036 const unsigned int val_128 = 128;
1037 for (
unsigned int i = 0; i < halfHeight; ++i) {
1038 for (
unsigned int j = 0; j < halfWidth; ++j) {
1039 U =
static_cast<int>(((*iU) - val_128) * 0.354);
1042 V =
static_cast<int>(((*iV) - val_128) * 0.707);
1049 yuv = yuv + (width - 1);
1053 yuv = (yuv - width) + 1;
1068 *rgb++ =
static_cast<unsigned char>(R);
1069 *rgb++ =
static_cast<unsigned char>(G);
1070 *rgb++ =
static_cast<unsigned char>(B);
1082 *rgb++ =
static_cast<unsigned char>(R);
1083 *rgb++ =
static_cast<unsigned char>(G);
1084 *rgb =
static_cast<unsigned char>(B);
1085 rgb = rgb + ((val_3 * width) - val_5);
1097 *rgb++ =
static_cast<unsigned char>(R);
1098 *rgb++ =
static_cast<unsigned char>(G);
1099 *rgb++ =
static_cast<unsigned char>(B);
1111 *rgb++ =
static_cast<unsigned char>(R);
1112 *rgb++ =
static_cast<unsigned char>(G);
1113 *rgb =
static_cast<unsigned char>(B);
1114 rgb = (rgb - (val_3 * width)) + 1;
1117 rgb += val_3 * width;
1133 void YVU9ToRGBasubroutine(
unsigned char *rgba,
int R,
int G,
int B,
int a)
1138 *rgba++ =
static_cast<unsigned char>(R);
1139 *rgba++ =
static_cast<unsigned char>(G);
1140 *rgba++ =
static_cast<unsigned char>(B);
1156 int U, V, R, G, B, V2, U5, UV;
1157 int Y0, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10, Y11, Y12, Y13, Y14, Y15;
1158 const unsigned int val_2 = 2;
1159 const unsigned int val_3 = 3;
1160 const unsigned int val_4 = 4;
1161 const unsigned int val_5 = 5;
1162 const unsigned int val_12 = 12;
1163 const unsigned int val_15 = 15;
1164 const unsigned int val_16 = 16;
1165 const unsigned int val_17 = 17;
1166 unsigned int size = width * height;
1167 unsigned char *iV = yuv + size;
1168 unsigned char *iU = yuv + ((val_17 * size) / val_16);
1169 const unsigned int quarterHeight = height / val_4, quarterWidth = width / val_4;
1170 const unsigned int val_128 = 128;
1171 for (
unsigned int i = 0; i < quarterHeight; ++i) {
1172 for (
unsigned int j = 0; j < quarterWidth; ++j) {
1173 U =
static_cast<int>(((*iU) - val_128) * 0.354);
1176 V =
static_cast<int>(((*iV) - val_128) * 0.707);
1187 yuv = yuv + (width - val_3);
1195 yuv = yuv + (width - val_3);
1203 yuv = yuv + (width - val_3);
1211 yuv = (yuv - (val_3 * width)) + 1;
1239 rgba = rgba + ((val_4 * width) - val_15);
1263 rgba = rgba + ((val_4 * width) - val_15);
1287 rgba = rgba + ((val_4 * width) - val_15);
1311 rgba = (rgba - (val_12 * width)) + 1;
1313 yuv += val_3 * width;
1314 rgba += val_12 * width;
1329 void YVU9ToRGBsubroutine(
unsigned char *rgb,
int R,
int G,
int B)
1334 *rgb++ =
static_cast<unsigned char>(R);
1335 *rgb++ =
static_cast<unsigned char>(G);
1336 *rgb++ =
static_cast<unsigned char>(B);
1349 int U, V, R, G, B, V2, U5, UV;
1350 int Y0, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10, Y11, Y12, Y13, Y14, Y15;
1351 const unsigned int val_2 = 2;
1352 const unsigned int val_3 = 3;
1353 const unsigned int val_4 = 4;
1354 const unsigned int val_5 = 5;
1355 const unsigned int val_9 = 9;
1356 const unsigned int val_11 = 11;
1357 const unsigned int val_16 = 16;
1358 const unsigned int val_17 = 17;
1359 unsigned int size = width * height;
1360 unsigned char *iV = yuv + size;
1361 unsigned char *iU = yuv + ((val_17 * size) / val_16);
1362 const unsigned int quarterHeight = height / val_4, quarterWidth = width / val_4;
1363 const unsigned int val_128 = 128;
1364 for (
unsigned int i = 0; i < quarterHeight; ++i) {
1365 for (
unsigned int j = 0; j < quarterWidth; ++j) {
1366 U =
static_cast<int>((*iU - val_128) * 0.354);
1369 V =
static_cast<int>((*iV - val_128) * 0.707);
1380 yuv = yuv + (width - val_3);
1388 yuv = yuv + (width - val_3);
1396 yuv = yuv + (width - val_3);
1404 yuv = (yuv - (val_3 * width)) + 1;
1413 YVU9ToRGBsubroutine(rgb, R, G, B);
1419 YVU9ToRGBsubroutine(rgb, R, G, B);
1425 YVU9ToRGBsubroutine(rgb, R, G, B);
1431 YVU9ToRGBsubroutine(rgb, R, G, B);
1432 rgb = rgb + ((val_3 * width) - val_11);
1437 YVU9ToRGBsubroutine(rgb, R, G, B);
1443 YVU9ToRGBsubroutine(rgb, R, G, B);
1449 YVU9ToRGBsubroutine(rgb, R, G, B);
1455 YVU9ToRGBsubroutine(rgb, R, G, B);
1456 rgb = rgb + ((val_3 * width) - val_11);
1461 YVU9ToRGBsubroutine(rgb, R, G, B);
1467 YVU9ToRGBsubroutine(rgb, R, G, B);
1473 YVU9ToRGBsubroutine(rgb, R, G, B);
1479 YVU9ToRGBsubroutine(rgb, R, G, B);
1480 rgb = (rgb + (val_3 * width)) - val_11;
1485 YVU9ToRGBsubroutine(rgb, R, G, B);
1491 YVU9ToRGBsubroutine(rgb, R, G, B);
1497 YVU9ToRGBsubroutine(rgb, R, G, B);
1503 YVU9ToRGBsubroutine(rgb, R, G, B);
1504 rgb = (rgb - (val_9 * width)) + 1;
1506 yuv += val_3 * width;
1507 rgb += val_9 * width;
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 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 YUYVToRGBa(unsigned char *yuyv, unsigned char *rgba, unsigned int width, unsigned int height)
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 YUV444ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int size)
static void YUV411ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int size)
static void YUV422ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int size)
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 YUV444ToRGBa(unsigned char *yuv, unsigned char *rgba, 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 YUYVToRGB(unsigned char *yuyv, unsigned char *rgb, unsigned int width, unsigned int height)