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 unsigned int i = 0, j = 0;
210 const unsigned int doubleSize = size * 2;
211 while (j < doubleSize) {
213 grey[i++] = yuyv[j + 2];
229 const unsigned int val_128 = 128;
230 for (
unsigned int i = size / 4; i; --i) {
231 int U =
static_cast<int>((*yuv - val_128) * 0.354);
238 int V =
static_cast<int>((*yuv - val_128) * 0.707);
260 *rgba++ =
static_cast<unsigned char>(R);
261 *rgba++ =
static_cast<unsigned char>(G);
262 *rgba++ =
static_cast<unsigned char>(B);
275 *rgba++ =
static_cast<unsigned char>(R);
276 *rgba++ =
static_cast<unsigned char>(G);
277 *rgba++ =
static_cast<unsigned char>(B);
290 *rgba++ =
static_cast<unsigned char>(R);
291 *rgba++ =
static_cast<unsigned char>(G);
292 *rgba++ =
static_cast<unsigned char>(B);
305 *rgba++ =
static_cast<unsigned char>(R);
306 *rgba++ =
static_cast<unsigned char>(G);
307 *rgba++ =
static_cast<unsigned char>(B);
326 const unsigned int val_2 = 2;
327 const unsigned int val_128 = 128;
328 for (
unsigned int i = size / val_2; i; --i) {
329 int U =
static_cast<int>((*yuv - val_128) * 0.354);
334 int V =
static_cast<int>((*yuv - val_128) * 0.707);
351 *rgba++ =
static_cast<unsigned char>(R);
352 *rgba++ =
static_cast<unsigned char>(G);
353 *rgba++ =
static_cast<unsigned char>(B);
366 *rgba++ =
static_cast<unsigned char>(R);
367 *rgba++ =
static_cast<unsigned char>(G);
368 *rgba++ =
static_cast<unsigned char>(B);
383 unsigned int i = 0, j = 0;
384 const unsigned int val_2 = 2;
385 const unsigned int iterLimit = (size * 3) / val_2;
386 while (j < iterLimit) {
387 grey[i] = yuv[j + 1];
388 grey[i + 1] = yuv[j + 2];
389 grey[i + 2] = yuv[j + 4];
390 grey[i + 3] = yuv[j + 5];
410 const unsigned int val_2 = 2;
411 const unsigned int val_128 = 128;
412 for (
unsigned int i = size / val_2; i; --i) {
413 int U =
static_cast<int>((*yuv - val_128) * 0.354);
418 int V =
static_cast<int>((*yuv - val_128) * 0.707);
435 *rgb++ =
static_cast<unsigned char>(R);
436 *rgb++ =
static_cast<unsigned char>(G);
437 *rgb++ =
static_cast<unsigned char>(B);
449 *rgb++ =
static_cast<unsigned char>(R);
450 *rgb++ =
static_cast<unsigned char>(G);
451 *rgb++ =
static_cast<unsigned char>(B);
467 unsigned int i = 0, j = 0;
468 const unsigned int doubleSize = size * 2;
470 while (j < doubleSize) {
471 grey[i++] = yuv[j + 1];
472 grey[i++] = yuv[j + 3];
487 const unsigned int val_128 = 128;
488 for (
unsigned int i = size / 4; i; --i) {
489 int U =
static_cast<int>((*yuv - val_128) * 0.354);
496 int V =
static_cast<int>((*yuv - val_128) * 0.707);
518 *rgb++ =
static_cast<unsigned char>(R);
519 *rgb++ =
static_cast<unsigned char>(G);
520 *rgb++ =
static_cast<unsigned char>(B);
532 *rgb++ =
static_cast<unsigned char>(R);
533 *rgb++ =
static_cast<unsigned char>(G);
534 *rgb++ =
static_cast<unsigned char>(B);
546 *rgb++ =
static_cast<unsigned char>(R);
547 *rgb++ =
static_cast<unsigned char>(G);
548 *rgb++ =
static_cast<unsigned char>(B);
560 *rgb++ =
static_cast<unsigned char>(R);
561 *rgb++ =
static_cast<unsigned char>(G);
562 *rgb++ =
static_cast<unsigned char>(B);
578 int U, V, R, G, B, V2, U5, UV;
580 const unsigned int val_2 = 2;
581 const unsigned int val_4 = 4;
582 const unsigned int val_5 = 5;
583 const unsigned int val_7 = 7;
584 unsigned int size = width * height;
585 unsigned char *iU = yuv + size;
586 unsigned char *iV = yuv + ((val_5 * size) / val_4);
587 const unsigned int halfHeight = height / val_2, halfWidth = width / val_2;
588 const unsigned int val_128 = 128;
589 for (
unsigned int i = 0; i < halfHeight; ++i) {
590 for (
unsigned int j = 0; j < halfWidth; ++j) {
591 U =
static_cast<int>(((*iU) - val_128) * 0.354);
594 V =
static_cast<int>(((*iV) - val_128) * 0.707);
601 yuv = yuv + (width - 1);
605 yuv = (yuv - width) + 1;
620 *rgba++ =
static_cast<unsigned char>(R);
621 *rgba++ =
static_cast<unsigned char>(G);
622 *rgba++ =
static_cast<unsigned char>(B);
635 *rgba++ =
static_cast<unsigned char>(R);
636 *rgba++ =
static_cast<unsigned char>(G);
637 *rgba++ =
static_cast<unsigned char>(B);
639 rgba = (rgba + (val_4 * width)) - val_7;
651 *rgba++ =
static_cast<unsigned char>(R);
652 *rgba++ =
static_cast<unsigned char>(G);
653 *rgba++ =
static_cast<unsigned char>(B);
666 *rgba++ =
static_cast<unsigned char>(R);
667 *rgba++ =
static_cast<unsigned char>(G);
668 *rgba++ =
static_cast<unsigned char>(B);
670 rgba = (rgba - (val_4 * width)) + 1;
673 rgba += val_4 * width;
687 int U, V, R, G, B, V2, U5, UV;
689 const unsigned int val_2 = 2;
690 const unsigned int val_3 = 3;
691 const unsigned int val_4 = 4;
692 const unsigned int val_5 = 5;
693 unsigned int size = width * height;
694 unsigned char *iU = yuv + size;
695 unsigned char *iV = yuv + ((val_5 * size) / val_4);
696 const unsigned int halfHeight = height / val_2, halfWidth = width / val_2;
697 const unsigned int val_128 = 128;
698 for (
unsigned int i = 0; i < halfHeight; ++i) {
699 for (
unsigned int j = 0; j < halfWidth; ++j) {
700 U =
static_cast<int>(((*iU) - val_128) * 0.354);
703 V =
static_cast<int>(((*iV) - val_128) * 0.707);
710 yuv = yuv + (width - 1);
714 yuv = (yuv - width) + 1;
729 *rgb++ =
static_cast<unsigned char>(R);
730 *rgb++ =
static_cast<unsigned char>(G);
731 *rgb++ =
static_cast<unsigned char>(B);
743 *rgb++ =
static_cast<unsigned char>(R);
744 *rgb++ =
static_cast<unsigned char>(G);
745 *rgb =
static_cast<unsigned char>(B);
746 rgb = rgb + ((val_3 * width) - val_5);
758 *rgb++ =
static_cast<unsigned char>(R);
759 *rgb++ =
static_cast<unsigned char>(G);
760 *rgb++ =
static_cast<unsigned char>(B);
772 *rgb++ =
static_cast<unsigned char>(R);
773 *rgb++ =
static_cast<unsigned char>(G);
774 *rgb =
static_cast<unsigned char>(B);
775 rgb = (rgb - (val_3 * width)) + 1;
791 for (
unsigned int i = 0; i < size; ++i) {
808 const unsigned int val_128 = 128;
809 for (
unsigned int i = 0; i < size; ++i) {
810 int U =
static_cast<int>((*yuv - val_128) * 0.354);
815 int V =
static_cast<int>((*yuv - val_128) * 0.707);
833 *rgba++ =
static_cast<unsigned char>(R);
834 *rgba++ =
static_cast<unsigned char>(G);
835 *rgba++ =
static_cast<unsigned char>(B);
849 const unsigned int val_128 = 128;
850 for (
unsigned int i = 0; i < size; ++i) {
851 int U =
static_cast<int>((*yuv - val_128) * 0.354);
856 int V =
static_cast<int>((*yuv - val_128) * 0.707);
874 *rgb++ =
static_cast<unsigned char>(R);
875 *rgb++ =
static_cast<unsigned char>(G);
876 *rgb++ =
static_cast<unsigned char>(B);
890 for (
unsigned int i = 0; i < size; ++i) {
908 int U, V, R, G, B, V2, U5, UV;
910 const unsigned int val_2 = 2;
911 const unsigned int val_4 = 4;
912 const unsigned int val_5 = 5;
913 const unsigned int val_7 = 7;
914 unsigned int size = width * height;
915 unsigned char *iV = yuv + size;
916 unsigned char *iU = yuv + ((val_5 * size) / val_4);
917 const unsigned int halfHeight = height / val_2, halfWidth = width / val_2;
918 const unsigned int val_128 = 128;
919 for (
unsigned int i = 0; i < halfHeight; ++i) {
920 for (
unsigned int j = 0; j < halfWidth; ++j) {
921 U =
static_cast<int>(((*iU) - val_128) * 0.354);
924 V =
static_cast<int>(((*iV) - val_128) * 0.707);
931 yuv = yuv + (width - 1);
935 yuv = (yuv - width) + 1;
950 *rgba++ =
static_cast<unsigned char>(R);
951 *rgba++ =
static_cast<unsigned char>(G);
952 *rgba++ =
static_cast<unsigned char>(B);
965 *rgba++ =
static_cast<unsigned char>(R);
966 *rgba++ =
static_cast<unsigned char>(G);
967 *rgba++ =
static_cast<unsigned char>(B);
969 rgba = rgba + ((val_4 * width) - val_7);
981 *rgba++ =
static_cast<unsigned char>(R);
982 *rgba++ =
static_cast<unsigned char>(G);
983 *rgba++ =
static_cast<unsigned char>(B);
996 *rgba++ =
static_cast<unsigned char>(R);
997 *rgba++ =
static_cast<unsigned char>(G);
998 *rgba++ =
static_cast<unsigned char>(B);
1000 rgba = (rgba - (val_4 * width)) + 1;
1003 rgba += val_4 * width;
1017 int U, V, R, G, B, V2, U5, UV;
1019 const unsigned int val_2 = 2;
1020 const unsigned int val_3 = 3;
1021 const unsigned int val_4 = 4;
1022 const unsigned int val_5 = 5;
1023 unsigned int size = width * height;
1024 unsigned char *iV = yuv + size;
1025 unsigned char *iU = yuv + ((val_5 * size) / val_4);
1026 const unsigned int halfHeight = height / val_2, halfWidth = width / val_2;
1027 const unsigned int val_128 = 128;
1028 for (
unsigned int i = 0; i < halfHeight; ++i) {
1029 for (
unsigned int j = 0; j < halfWidth; ++j) {
1030 U =
static_cast<int>(((*iU) - val_128) * 0.354);
1033 V =
static_cast<int>(((*iV) - val_128) * 0.707);
1040 yuv = yuv + (width - 1);
1044 yuv = (yuv - width) + 1;
1059 *rgb++ =
static_cast<unsigned char>(R);
1060 *rgb++ =
static_cast<unsigned char>(G);
1061 *rgb++ =
static_cast<unsigned char>(B);
1073 *rgb++ =
static_cast<unsigned char>(R);
1074 *rgb++ =
static_cast<unsigned char>(G);
1075 *rgb =
static_cast<unsigned char>(B);
1076 rgb = rgb + ((val_3 * width) - 5);
1088 *rgb++ =
static_cast<unsigned char>(R);
1089 *rgb++ =
static_cast<unsigned char>(G);
1090 *rgb++ =
static_cast<unsigned char>(B);
1102 *rgb++ =
static_cast<unsigned char>(R);
1103 *rgb++ =
static_cast<unsigned char>(G);
1104 *rgb =
static_cast<unsigned char>(B);
1105 rgb = (rgb - (val_3 * width)) + 1;
1108 rgb += val_3 * width;
1124 void YVU9ToRGBasubroutine(
unsigned char *rgba,
int R,
int G,
int B,
int a)
1129 *rgba++ =
static_cast<unsigned char>(R);
1130 *rgba++ =
static_cast<unsigned char>(G);
1131 *rgba++ =
static_cast<unsigned char>(B);
1147 int U, V, R, G, B, V2, U5, UV;
1148 int Y0, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10, Y11, Y12, Y13, Y14, Y15;
1149 const unsigned int val_2 = 2;
1150 const unsigned int val_3 = 3;
1151 const unsigned int val_4 = 4;
1152 const unsigned int val_5 = 5;
1153 const unsigned int val_12 = 12;
1154 const unsigned int val_15 = 15;
1155 const unsigned int val_16 = 16;
1156 const unsigned int val_17 = 17;
1157 unsigned int size = width * height;
1158 unsigned char *iV = yuv + size;
1159 unsigned char *iU = yuv + ((val_17 * size) / val_16);
1160 const unsigned int quarterHeight = height / val_4, quarterWidth = width / val_4;
1161 const unsigned int val_128 = 128;
1162 for (
unsigned int i = 0; i < quarterHeight; ++i) {
1163 for (
unsigned int j = 0; j < quarterWidth; ++j) {
1164 U =
static_cast<int>(((*iU) - val_128) * 0.354);
1167 V =
static_cast<int>(((*iV) - val_128) * 0.707);
1178 yuv = yuv + (width - val_3);
1186 yuv = yuv + (width - val_3);
1194 yuv = yuv + (width - val_3);
1202 yuv = (yuv - (val_3 * width)) + 1;
1230 rgba = rgba + ((val_4 * width) - val_15);
1254 rgba = rgba + ((val_4 * width) - val_15);
1278 rgba = rgba + ((val_4 * width) - val_15);
1302 rgba = (rgba - (val_12 * width)) + 1;
1304 yuv += val_3 * width;
1305 rgba += val_12 * width;
1320 void YVU9ToRGBsubroutine(
unsigned char *rgb,
int R,
int G,
int B)
1325 *rgb++ =
static_cast<unsigned char>(R);
1326 *rgb++ =
static_cast<unsigned char>(G);
1327 *rgb++ =
static_cast<unsigned char>(B);
1340 int U, V, R, G, B, V2, U5, UV;
1341 int Y0, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10, Y11, Y12, Y13, Y14, Y15;
1342 const unsigned int val_2 = 2;
1343 const unsigned int val_3 = 3;
1344 const unsigned int val_4 = 4;
1345 const unsigned int val_5 = 5;
1346 const unsigned int val_9 = 9;
1347 const unsigned int val_16 = 16;
1348 const unsigned int val_17 = 17;
1349 unsigned int size = width * height;
1350 unsigned char *iV = yuv + size;
1351 unsigned char *iU = yuv + ((val_17 * size) / val_16);
1352 const unsigned int quarterHeight = height / val_4, quarterWidth = width / val_4;
1353 const unsigned int val_128 = 128;
1354 for (
unsigned int i = 0; i < quarterHeight; ++i) {
1355 for (
unsigned int j = 0; j < quarterWidth; ++j) {
1356 U =
static_cast<int>((*iU - val_128) * 0.354);
1359 V =
static_cast<int>((*iV - val_128) * 0.707);
1370 yuv = yuv + (width - val_3);
1378 yuv = yuv + (width - val_3);
1386 yuv = yuv + (width - val_3);
1394 yuv = (yuv - (val_3 * width)) + 1;
1403 YVU9ToRGBsubroutine(rgb, R, G, B);
1409 YVU9ToRGBsubroutine(rgb, R, G, B);
1415 YVU9ToRGBsubroutine(rgb, R, G, B);
1421 YVU9ToRGBsubroutine(rgb, R, G, B);
1422 rgb = rgb + ((val_3 * width) - 11);
1427 YVU9ToRGBsubroutine(rgb, R, G, B);
1433 YVU9ToRGBsubroutine(rgb, R, G, B);
1439 YVU9ToRGBsubroutine(rgb, R, G, B);
1445 YVU9ToRGBsubroutine(rgb, R, G, B);
1446 rgb = rgb + ((val_3 * width) - 11);
1451 YVU9ToRGBsubroutine(rgb, R, G, B);
1457 YVU9ToRGBsubroutine(rgb, R, G, B);
1463 YVU9ToRGBsubroutine(rgb, R, G, B);
1469 YVU9ToRGBsubroutine(rgb, R, G, B);
1470 rgb = (rgb + (val_3 * width)) - 11;
1475 YVU9ToRGBsubroutine(rgb, R, G, B);
1481 YVU9ToRGBsubroutine(rgb, R, G, B);
1487 YVU9ToRGBsubroutine(rgb, R, G, B);
1493 YVU9ToRGBsubroutine(rgb, R, G, B);
1494 rgb = (rgb - (val_9 * width)) + 1;
1496 yuv += val_3 * width;
1497 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)