Re: [PATCH] libv4l: Add support for 8-bits grey format (V4L2_PIX_FMT_GREY)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 12/08/2010 03:14 PM, Mauro Carvalho Chehab wrote:
Grey format is like YUV, with U/V channels with 0. Add the corresponding
bits to libv4l, for it to handle this format.

Signed-off-by: Mauro Carvalho Chehab<mchehab@xxxxxxxxxx>

diff --git a/lib/libv4lconvert/libv4lconvert-priv.h b/lib/libv4lconvert/libv4lconvert-priv.h
index 61a8c39..2680ed7 100644
--- a/lib/libv4lconvert/libv4lconvert-priv.h
+++ b/lib/libv4lconvert/libv4lconvert-priv.h
@@ -127,6 +127,15 @@ void v4lconvert_swap_rgb(const unsigned char *src, unsigned char *dst,
  void v4lconvert_swap_uv(const unsigned char *src, unsigned char *dst,
  		const struct v4l2_format *src_fmt);

+void v4lconvert_grey_to_rgb24(const unsigned char *src, unsigned char *dest,
+		int width, int height);
+
+void v4lconvert_grey_to_yuv420(const unsigned char *src, unsigned char *dest,
+                const struct v4l2_format *src_fmt);
+
+void v4lconvert_grey_to_rgb24(const unsigned char *src, unsigned char *dest,
+		int width, int height);
+
  void v4lconvert_rgb565_to_rgb24(const unsigned char *src, unsigned char *dest,
  		int width, int height);

diff --git a/lib/libv4lconvert/libv4lconvert.c b/lib/libv4lconvert/libv4lconvert.c
index f08996a..26a0978 100644
--- a/lib/libv4lconvert/libv4lconvert.c
+++ b/lib/libv4lconvert/libv4lconvert.c
@@ -43,6 +43,7 @@ static void v4lconvert_get_framesizes(struct v4lconvert_data *data,
     v4lconvert_try_format for low resolutions */
  static const struct v4lconvert_pixfmt supported_src_pixfmts[] = {
  	SUPPORTED_DST_PIXFMTS,
+	{ V4L2_PIX_FMT_GREY,         0 },
  	{ V4L2_PIX_FMT_YUYV,         0 },
  	{ V4L2_PIX_FMT_YVYU,         0 },
  	{ V4L2_PIX_FMT_UYVY,         0 },
@@ -839,6 +840,23 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data,
  		}
  		break;

+	case V4L2_PIX_FMT_GREY:
+		switch (dest_pix_fmt) {
+		case V4L2_PIX_FMT_RGB24:
+	        case V4L2_PIX_FMT_BGR24:
+			v4lconvert_grey_to_rgb24(src, dest, width, height);
+			break;
+		case V4L2_PIX_FMT_YUV420:
+		case V4L2_PIX_FMT_YVU420:
+			v4lconvert_grey_to_yuv420(src, dest, fmt);
+			break;
+		}
+		if (src_size<  (width * height)) {
+			V4LCONVERT_ERR("short grey data frame\n");
+			errno = EPIPE;
+			result = -1;
+		}
+		break;
  	case V4L2_PIX_FMT_RGB565:
  		switch (dest_pix_fmt) {
  		case V4L2_PIX_FMT_RGB24:
diff --git a/lib/libv4lconvert/rgbyuv.c b/lib/libv4lconvert/rgbyuv.c
index f205b39..c3b6235 100644
--- a/lib/libv4lconvert/rgbyuv.c
+++ b/lib/libv4lconvert/rgbyuv.c
@@ -575,3 +575,31 @@ void v4lconvert_rgb565_to_yuv420(const unsigned char *src, unsigned char *dest,
  		src += 2 * src_fmt->fmt.pix.bytesperline - 2 * src_fmt->fmt.pix.width;
  	}
  }
+
+void v4lconvert_grey_to_rgb24(const unsigned char *src, unsigned char *dest,
+		int width, int height)
+{
+	int j;
+	while (--height>= 0) {
+		for (j = 0; j<  width; j++) {
+			*dest++ = *src;
+			*dest++ = *src;
+			*dest++ = *src;
+			src++;
+		}
+	}
+}
+
+void v4lconvert_grey_to_yuv420(const unsigned char *src, unsigned char *dest,
+		const struct v4l2_format *src_fmt)
+{
+	int x, y;
+
+	/* Y */
+	for (y = 0; y<  src_fmt->fmt.pix.height; y++)
+		for (x = 0; x<  src_fmt->fmt.pix.width; x++)
+			*dest++ = *src++;
+
+	/* Clear U/V */
+	memset(dest, 0, src_fmt->fmt.pix.width * src_fmt->fmt.pix.height / 2);

This is wrong the "0" value for U/V is 0x80 (U and V are signed, but not two's
complement instead their range is up shifted by 0x80)

Otherwise the patch looks good.

Regards,

Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux