From: Yusuke Suzuki Date: Mon, 3 Nov 2014 08:48:10 +0000 (+0900) Subject: add V4L2_PIX_FMT_RGB24 convert code X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~2854^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9cd08c662c169b6a9cf352b9642388249c514794;p=platform%2Fupstream%2Fopencv.git add V4L2_PIX_FMT_RGB24 convert code --- diff --git a/modules/videoio/src/cap_v4l.cpp b/modules/videoio/src/cap_v4l.cpp index efa9a8b..a0fe8f1 100644 --- a/modules/videoio/src/cap_v4l.cpp +++ b/modules/videoio/src/cap_v4l.cpp @@ -294,7 +294,8 @@ enum PALETTE_TYPE { PALETTE_SBGGR8, PALETTE_SN9C10X, PALETTE_MJPEG, - PALETTE_SGBRG + PALETTE_SGBRG, + PALETTE_RGB24 }; typedef struct CvCaptureCAM_V4L @@ -588,6 +589,10 @@ static int autosetup_capture_mode_v4l2(CvCaptureCAM_V4L* capture) { capture->palette = PALETTE_SGBRG; } + else if (try_palette_v4l2(capture, V4L2_PIX_FMT_RGB24) == 0) + { + capture->palette = PALETTE_RGB24; + } else { fprintf(stderr, "VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV\n"); @@ -1916,6 +1921,18 @@ static void sgbrg2rgb24(long int WIDTH, long int HEIGHT, unsigned char *src, uns } } +static void +rgb24_to_rgb24 (int width, int height, unsigned char *src, unsigned char *dst) +{ + const int size = width * height; + for(int i = 0; i < size; ++i, src += 3, dst += 3) + { + *(dst + 0) = *(src + 2); + *(dst + 1) = *(src + 1); + *(dst + 2) = *(src + 0); + } +} + #define CLAMP(x) ((x)<0?0:((x)>255)?255:(x)) typedef struct { @@ -2219,6 +2236,12 @@ static IplImage* icvRetrieveFrameCAM_V4L( CvCaptureCAM_V4L* capture, int) { (unsigned char*)capture->buffers[(capture->bufferIndex+1) % capture->req.count].start, (unsigned char*)capture->frame.imageData); break; + case PALETTE_RGB24: + rgb24_to_rgb24(capture->form.fmt.pix.width, + capture->form.fmt.pix.height, + (unsigned char*)capture->buffers[(capture->bufferIndex+1) % capture->req.count].start, + (unsigned char*)capture->frame.imageData); + break; } } #endif /* HAVE_CAMV4L2 */