diff mbox

libv4l: Add support for 8-bits grey format (V4L2_PIX_FMT_GREY)

Message ID 4CFF92B7.4060106@redhat.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Mauro Carvalho Chehab Dec. 8, 2010, 2:14 p.m. UTC
None
diff mbox

Patch

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);
+}