Skip to contentSkip to conversation

libv4l decoding to rgb24

PATCH In review Jean-Francois Moine 2 participants 2 messages Aug 1, 2008 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libv4l decoding to rgb24

The RGB24 pixel format is often used in X11 applications. This patch adds it to the V4L library.

--

v4l2-apps/lib/libv4l/libv4lconvert/bayer.c +23 -7
diff -r cfa0097c9e85 v4l2-apps/lib/libv4l/libv4lconvert/bayer.c
@@ -163,14 +163,10 @@
 }
 
 /* From libdc1394, which on turn was based on OpenCV's Bayer decoding */
-void v4lconvert_bayer_to_bgr24(const unsigned char *bayer,
-  unsigned char *bgr, int width, int height, unsigned int pixfmt)
+static void bayer_to_rgbbgr24(const unsigned char *bayer,
+  unsigned char *bgr, int width, int height, unsigned int pixfmt,
+	int start_with_green, int blue_line)
 {
-    int blue_line = pixfmt == V4L2_PIX_FMT_SBGGR8
-	|| pixfmt == V4L2_PIX_FMT_SGBRG8;
-    int start_with_green = pixfmt == V4L2_PIX_FMT_SGBRG8
-	|| pixfmt == V4L2_PIX_FMT_SGRBG8;
-
     /* render the first line */
     v4lconvert_border_bayer_line_to_bgr24(bayer, bayer + width, bgr, width,
       start_with_green, blue_line);
@@ -315,6 +311,26 @@
     /* render the last line */
     v4lconvert_border_bayer_line_to_bgr24(bayer + width, bayer, bgr, width,
       !start_with_green, !blue_line);
+}
+
+void v4lconvert_bayer_to_rgb24(const unsigned char *bayer,
+  unsigned char *bgr, int width, int height, unsigned int pixfmt)
+{
+	bayer_to_rgbbgr24(bayer, bgr, width, height, pixfmt,
+		pixfmt == V4L2_PIX_FMT_SGBRG8		/* start with green */
+			|| pixfmt == V4L2_PIX_FMT_SGRBG8,
+		pixfmt != V4L2_PIX_FMT_SBGGR8		/* blue line */
+			&& pixfmt != V4L2_PIX_FMT_SGBRG8);
+}
+
+void v4lconvert_bayer_to_bgr24(const unsigned char *bayer,
+  unsigned char *bgr, int width, int height, unsigned int pixfmt)
+{
+	bayer_to_rgbbgr24(bayer, bgr, width, height, pixfmt,
+		pixfmt == V4L2_PIX_FMT_SGBRG8		/* start with green */
+			|| pixfmt == V4L2_PIX_FMT_SGRBG8,
+		pixfmt == V4L2_PIX_FMT_SBGGR8		/* blue line */
+			|| pixfmt == V4L2_PIX_FMT_SGBRG8);
 }
 
 static void v4lconvert_border_bayer_line_to_y(
v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert-priv.h +6 -0
diff -r cfa0097c9e85 v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert-priv.h
@@ -71,6 +71,9 @@
 };
 
 
+void v4lconvert_yuv420_to_rgb24(const unsigned char *src, unsigned char *dst,
+  int width, int height);
+
 void v4lconvert_yuv420_to_bgr24(const unsigned char *src, unsigned char *dst,
   int width, int height);
 
@@ -92,6 +95,9 @@
 void v4lconvert_decode_pac207(const unsigned char *src, unsigned char *dst,
   int width, int height);
 
+void v4lconvert_bayer_to_rgb24(const unsigned char *bayer,
+  unsigned char *rgb, int width, int height, unsigned int pixfmt);
+
 void v4lconvert_bayer_to_bgr24(const unsigned char *bayer,
   unsigned char *rgb, int width, int height, unsigned int pixfmt);
 
v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert.c +42 -10

114 lines not on this page · raw message

v4l2-apps/lib/libv4l/libv4lconvert/rgbyuv.c +26 -4
diff -r cfa0097c9e85 v4l2-apps/lib/libv4l/libv4lconvert/rgbyuv.c
@@ -34,14 +34,24 @@
 
 #define CLIP(color) (unsigned char)(((color)>0xFF)?0xff:(((color)<0)?0:(color)))
 
-void v4lconvert_yuv420_to_bgr24(const unsigned char *src, unsigned char *dest,
-  int width, int height)
+static void yuv420_to_rgbbgr24(const unsigned char *src,
+				unsigned char *dest,
+				int width, int height,
+				int bgr)
 {
   int i,j;
 
   const unsigned char *ysrc = src;
-  const unsigned char *usrc = src + width * height;
-  const unsigned char *vsrc = usrc + (width * height) / 4;
+  const unsigned char *usrc;
+  const unsigned char *vsrc;
+
+	if (bgr) {
+		vsrc = src + width * height;
+		usrc = vsrc + (width * height) / 4;
+	} else {
+		usrc = src + width * height;
+		vsrc = usrc + (width * height) / 4;
+	}
 
   for (i = 0; i < height; i++) {
     for (j = 0; j < width; j += 2) {
@@ -80,3 +90,15 @@
     }
   }
 }
+
+void v4lconvert_yuv420_to_rgb24(const unsigned char *src, unsigned char *dest,
+  int width, int height)
+{
+	yuv420_to_rgbbgr24(src, dest, width, height, 0);
+}
+
+void v4lconvert_yuv420_to_bgr24(const unsigned char *src, unsigned char *dest,
+  int width, int height)
+{
+	yuv420_to_rgbbgr24(src, dest, width, height, 1);
+}
Signature · 8 lines
Ken ar c'hentañ |             ** Breizh ha Linux atav! **
Jef             |               http://moinejf.free.fr/


--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
#1 lore raw
Quoted 5 lines · Jean-Francois Moine

The RGB24 pixel format is often used in X11 applications. This patch adds it to the V4L library.

Thanks, the yuv part of the patch is not correct as u and v have different weight factors in the conversion so simply swapping them is not correct, but I'll fix that myself.

Regards,

Hans

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list