From ea397a3f552d2d0ca813d5c970e3f66bed4af1d9 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Wed, 3 Jul 2024 12:50:46 +0200 Subject: [PATCH] Fix vpImageConvert::YUYVToRGBa() and YUYVToRGB() color conversion --- modules/core/src/image/vpImageConvert_yuv.cpp | 42 ++++++++++--------- .../src/framegrabber/v4l2/vpV4l2Grabber.cpp | 3 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/modules/core/src/image/vpImageConvert_yuv.cpp b/modules/core/src/image/vpImageConvert_yuv.cpp index 5206a557dc..cea2ebd02a 100644 --- a/modules/core/src/image/vpImageConvert_yuv.cpp +++ b/modules/core/src/image/vpImageConvert_yuv.cpp @@ -44,12 +44,14 @@ namespace { void vpSAT(int &c) { - if (c < 0) { - c = 0; - } - else { - const unsigned int val_255 = 255; - c = val_255; + if (c & (~255)) { + if (c < 0) { + c = 0; + } + else { + const unsigned int val_255 = 255; + c = val_255; + } } } }; @@ -73,13 +75,13 @@ void vpImageConvert::YUYVToRGBa(unsigned char *yuyv, unsigned char *rgba, unsign unsigned char *d; int w, h; int r, g, b, cr, cg, cb, y1, y2; - const unsigned int val_2 = 2; - const unsigned int val_88 = 88; - const unsigned int val_128 = 128; - const unsigned int val_183 = 183; - const unsigned int val_256 = 256; - const unsigned int val_359 = 359; - const unsigned int val_454 = 454; + const int val_2 = 2; + const int val_88 = 88; + const int val_128 = 128; + const int val_183 = 183; + const int val_256 = 256; + const int val_359 = 359; + const int val_454 = 454; h = static_cast(height); w = static_cast(width); @@ -142,13 +144,13 @@ void vpImageConvert::YUYVToRGB(unsigned char *yuyv, unsigned char *rgb, unsigned unsigned char *d; int h, w; int r, g, b, cr, cg, cb, y1, y2; - const unsigned int val_2 = 2; - const unsigned int val_88 = 88; - const unsigned int val_128 = 128; - const unsigned int val_183 = 183; - const unsigned int val_256 = 256; - const unsigned int val_359 = 359; - const unsigned int val_454 = 454; + const int val_2 = 2; + const int val_88 = 88; + const int val_128 = 128; + const int val_183 = 183; + const int val_256 = 256; + const int val_359 = 359; + const int val_454 = 454; h = static_cast(height); w = static_cast(width); diff --git a/modules/sensor/src/framegrabber/v4l2/vpV4l2Grabber.cpp b/modules/sensor/src/framegrabber/v4l2/vpV4l2Grabber.cpp index 7d013bc268..ed2657017f 100644 --- a/modules/sensor/src/framegrabber/v4l2/vpV4l2Grabber.cpp +++ b/modules/sensor/src/framegrabber/v4l2/vpV4l2Grabber.cpp @@ -724,8 +724,9 @@ void vpV4l2Grabber::acquire(vpImage &I, struct timeval ×tamp, const vpImageTools::crop(bitmap, width, height, roi, I); break; case V4L2_RGB24_FORMAT: // tested - if (roi == vpRect()) + if (roi == vpRect()) { vpImageConvert::RGBToRGBa((unsigned char *)bitmap, (unsigned char *)I.bitmap, width * height); + } else { vpImage tmp(height, width); vpImageConvert::RGBToRGBa((unsigned char *)bitmap, (unsigned char *)tmp.bitmap, width * height);