Skip to contentSkip to conversation

libv4lconvert: Add support for V4L2_PIX_FMT_NV16

PATCH In review Niklas Söderlund 3 participants 4 messages Mar 11, 2016 – Mar 12, 2016 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libv4lconvert: Add support for V4L2_PIX_FMT_NV16

NV16 are two-plane versions of the YUV 4:2:2 format (V4L2_PIX_FMT_YUVU). Support it by merging the two planes into a one YUVU plane and falling through to the V4L2_PIX_FMT_YUVU code path.

---

I'm sorry this is a bit of a hack. The support for NV16 are scarce and this allowed me use it in qv4l2 so I thought it might help someone else. I'm not to sure about the entry in supported_src_pixfmts[] is it correct to set 'needs conversion' for my use case?

 lib/libv4lconvert/libv4lconvert-priv.h |  3 +++
 lib/libv4lconvert/libv4lconvert.c      | 15 +++++++++++++++
 lib/libv4lconvert/rgbyuv.c             | 17 +++++++++++++++++
 3 files changed, 35 insertions(+)
lib/libv4lconvert/libv4lconvert-priv.h +3 -0
index b77e3d3..1740efc 100644
@@ -129,6 +129,9 @@ void v4lconvert_yuyv_to_bgr24(const unsigned char *src, unsigned char *dst,
 void v4lconvert_yuyv_to_yuv420(const unsigned char *src, unsigned char *dst,
 		int width, int height, int stride, int yvu);
 
+void v4lconvert_nv16_to_yuyv(const unsigned char *src, unsigned char *dest,
+		int width, int height);
+
 void v4lconvert_yvyu_to_rgb24(const unsigned char *src, unsigned char *dst,
 		int width, int height, int stride);
 
lib/libv4lconvert/libv4lconvert.c +15 -0
index f62aea1..5426cb2 100644
@@ -98,6 +98,7 @@ static const struct v4lconvert_pixfmt supported_src_pixfmts[] = {
 	{ V4L2_PIX_FMT_YUYV,		16,	 5,	 4,	0 },
 	{ V4L2_PIX_FMT_YVYU,		16,	 5,	 4,	0 },
 	{ V4L2_PIX_FMT_UYVY,		16,	 5,	 4,	0 },
+	{ V4L2_PIX_FMT_NV16,		16,	 5,	 4,	1 },
 	/* yuv 4:2:0 formats */
 	{ V4L2_PIX_FMT_SPCA501,		12,      6,	 3,	1 },
 	{ V4L2_PIX_FMT_SPCA505,		12,	 6,	 3,	1 },
@@ -1229,6 +1230,20 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data,
 		}
 		break;
 
+	case V4L2_PIX_FMT_NV16: {
+		unsigned char *tmpbuf;
+
+		tmpbuf = v4lconvert_alloc_buffer(width * height * 2,
+				&data->convert_pixfmt_buf, &data->convert_pixfmt_buf_size);
+		if (!tmpbuf)
+			return v4lconvert_oom_error(data);
+
+		v4lconvert_nv16_to_yuyv(src, tmpbuf, width, height);
+		src_pix_fmt = V4L2_PIX_FMT_YUYV;
+		src = tmpbuf;
+		bytesperline = bytesperline * 2;
+		/* fall through */
+	}
 	case V4L2_PIX_FMT_YUYV:
 		if (src_size < (width * height * 2)) {
 			V4LCONVERT_ERR("short yuyv data frame\n");
lib/libv4lconvert/rgbyuv.c +17 -0
index 695255a..a9d6f5b 100644
@@ -295,6 +295,23 @@ void v4lconvert_yuyv_to_yuv420(const unsigned char *src, unsigned char *dest,
 	}
 }
 
+void v4lconvert_nv16_to_yuyv(const unsigned char *src, unsigned char *dest,
+		int width, int height)
+{
+	const unsigned char *y, *cbcr;
+	int count;
+
+	y = src;
+	cbcr = src + width*height;
+	count = 0;
+
+	while (count++ < width*height) {
+		*dest++ = *y++;
+		*dest++ = *cbcr++;
+	}
+
+}
+
 void v4lconvert_yvyu_to_bgr24(const unsigned char *src, unsigned char *dest,
 		int width, int height, int stride)
 {

--
2.7.2

#1 lore raw
Quoted 3 lines · Niklas Söderlund

NV16 are two-plane versions of the YUV 4:2:2 format (V4L2_PIX_FMT_YUVU). Support it by merging the two planes into a one YUVU plane and falling through to the V4L2_PIX_FMT_YUVU code path.

s/YUVU/YUYV/g

Can you add support for NV61 as well? Should be trivial.

Regards,

Hans

Quoted 97 lines

---

I'm sorry this is a bit of a hack. The support for NV16 are scarce and this allowed me use it in qv4l2 so I thought it might help someone else. I'm not to sure about the entry in supported_src_pixfmts[] is it correct to set 'needs conversion' for my use case?

 lib/libv4lconvert/libv4lconvert-priv.h |  3 +++
 lib/libv4lconvert/libv4lconvert.c      | 15 +++++++++++++++
 lib/libv4lconvert/rgbyuv.c             | 17 +++++++++++++++++
 3 files changed, 35 insertions(+)
lib/libv4lconvert/libv4lconvert-priv.h +3 -0
index b77e3d3..1740efc 100644
@@ -129,6 +129,9 @@ void v4lconvert_yuyv_to_bgr24(const unsigned char *src, unsigned char *dst,
 void v4lconvert_yuyv_to_yuv420(const unsigned char *src, unsigned char *dst,
 		int width, int height, int stride, int yvu);
 
+void v4lconvert_nv16_to_yuyv(const unsigned char *src, unsigned char *dest,
+		int width, int height);
+
 void v4lconvert_yvyu_to_rgb24(const unsigned char *src, unsigned char *dst,
 		int width, int height, int stride);
 
lib/libv4lconvert/libv4lconvert.c +15 -0
index f62aea1..5426cb2 100644
@@ -98,6 +98,7 @@ static const struct v4lconvert_pixfmt supported_src_pixfmts[] = {
 	{ V4L2_PIX_FMT_YUYV,		16,	 5,	 4,	0 },
 	{ V4L2_PIX_FMT_YVYU,		16,	 5,	 4,	0 },
 	{ V4L2_PIX_FMT_UYVY,		16,	 5,	 4,	0 },
+	{ V4L2_PIX_FMT_NV16,		16,	 5,	 4,	1 },
 	/* yuv 4:2:0 formats */
 	{ V4L2_PIX_FMT_SPCA501,		12,      6,	 3,	1 },
 	{ V4L2_PIX_FMT_SPCA505,		12,	 6,	 3,	1 },
@@ -1229,6 +1230,20 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data,
 		}
 		break;
 
+	case V4L2_PIX_FMT_NV16: {
+		unsigned char *tmpbuf;
+
+		tmpbuf = v4lconvert_alloc_buffer(width * height * 2,
+				&data->convert_pixfmt_buf, &data->convert_pixfmt_buf_size);
+		if (!tmpbuf)
+			return v4lconvert_oom_error(data);
+
+		v4lconvert_nv16_to_yuyv(src, tmpbuf, width, height);
+		src_pix_fmt = V4L2_PIX_FMT_YUYV;
+		src = tmpbuf;
+		bytesperline = bytesperline * 2;
+		/* fall through */
+	}
 	case V4L2_PIX_FMT_YUYV:
 		if (src_size < (width * height * 2)) {
 			V4LCONVERT_ERR("short yuyv data frame\n");
lib/libv4lconvert/rgbyuv.c +17 -1
index 695255a..a9d6f5b 100644
@@ -295,6 +295,23 @@ void v4lconvert_yuyv_to_yuv420(const unsigned char *src, unsigned char *dest,
 	}
 }
 
+void v4lconvert_nv16_to_yuyv(const unsigned char *src, unsigned char *dest,
+		int width, int height)
+{
+	const unsigned char *y, *cbcr;
+	int count;
+
+	y = src;
+	cbcr = src + width*height;
+	count = 0;
+
+	while (count++ < width*height) {
+		*dest++ = *y++;
+		*dest++ = *cbcr++;
+	}
+
+}
+
 void v4lconvert_yvyu_to_bgr24(const unsigned char *src, unsigned char *dest,
 		int width, int height, int stride)
 {
--

2.7.2

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

#2 lore raw

PATCH v2 1/1 libv4lconvert: Add support for V4L2_PIX_FMT_{NV16,NV61}

NV16 and NV61 are two-plane versions of the YUV 4:2:2 formats YUYV and YVYU. Support both formats by merging the two planes into a one and falling through to the V4L2_PIX_FMT_{YUYV,YVYU} code path.

---

I'm sorry this is a bit of a hack. The support for NV16 are scarce and this allowed me use it in qv4l2 so I thought it might help someone else. I'm not to sure about the entry in supported_src_pixfmts[] is it correct to set 'needs conversion' for my use case?

Changes since v1
- Add NV61 support
- Fixed s/YUVU/YUYV/g in commit message

 lib/libv4lconvert/libv4lconvert-priv.h |  3 +++
 lib/libv4lconvert/libv4lconvert.c      | 31 +++++++++++++++++++++++++++++++
 lib/libv4lconvert/rgbyuv.c             | 15 +++++++++++++++
 3 files changed, 49 insertions(+)
lib/libv4lconvert/libv4lconvert-priv.h +3 -0
index b77e3d3..1740efc 100644
@@ -129,6 +129,9 @@ void v4lconvert_yuyv_to_bgr24(const unsigned char *src, unsigned char *dst,
 void v4lconvert_yuyv_to_yuv420(const unsigned char *src, unsigned char *dst,
 		int width, int height, int stride, int yvu);
 
+void v4lconvert_nv16_to_yuyv(const unsigned char *src, unsigned char *dest,
+		int width, int height);
+
 void v4lconvert_yvyu_to_rgb24(const unsigned char *src, unsigned char *dst,
 		int width, int height, int stride);
 
lib/libv4lconvert/libv4lconvert.c +31 -0
index f62aea1..d3d8936 100644
@@ -98,6 +98,8 @@ static const struct v4lconvert_pixfmt supported_src_pixfmts[] = {
 	{ V4L2_PIX_FMT_YUYV,		16,	 5,	 4,	0 },
 	{ V4L2_PIX_FMT_YVYU,		16,	 5,	 4,	0 },
 	{ V4L2_PIX_FMT_UYVY,		16,	 5,	 4,	0 },
+	{ V4L2_PIX_FMT_NV16,		16,	 5,	 4,	1 },
+	{ V4L2_PIX_FMT_NV61,		16,	 5,	 4,	1 },
 	/* yuv 4:2:0 formats */
 	{ V4L2_PIX_FMT_SPCA501,		12,      6,	 3,	1 },
 	{ V4L2_PIX_FMT_SPCA505,		12,	 6,	 3,	1 },
@@ -1229,6 +1231,20 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data,
 		}
 		break;
 
+	case V4L2_PIX_FMT_NV16: {
+		unsigned char *tmpbuf;
+
+		tmpbuf = v4lconvert_alloc_buffer(width * height * 2,
+				&data->convert_pixfmt_buf, &data->convert_pixfmt_buf_size);
+		if (!tmpbuf)
+			return v4lconvert_oom_error(data);
+
+		v4lconvert_nv16_to_yuyv(src, tmpbuf, width, height);
+		src_pix_fmt = V4L2_PIX_FMT_YUYV;
+		src = tmpbuf;
+		bytesperline = bytesperline * 2;
+		/* fall through */
+	}
 	case V4L2_PIX_FMT_YUYV:
 		if (src_size < (width * height * 2)) {
 			V4LCONVERT_ERR("short yuyv data frame\n");
@@ -1251,6 +1267,21 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data,
 		}
 		break;
 
+	case V4L2_PIX_FMT_NV61: {
+		unsigned char *tmpbuf;
+
+		tmpbuf = v4lconvert_alloc_buffer(width * height * 2,
+				&data->convert_pixfmt_buf, &data->convert_pixfmt_buf_size);
+		if (!tmpbuf)
+			return v4lconvert_oom_error(data);
+
+		/* Note NV61 is NV16 with U and V swapped so this becomes yvyu. */
+		v4lconvert_nv16_to_yuyv(src, tmpbuf, width, height);
+		src_pix_fmt = V4L2_PIX_FMT_YVYU;
+		src = tmpbuf;
+		bytesperline = bytesperline * 2;
+		/* fall through */
+	}
 	case V4L2_PIX_FMT_YVYU:
 		if (src_size < (width * height * 2)) {
 			V4LCONVERT_ERR("short yvyu data frame\n");
lib/libv4lconvert/rgbyuv.c +15 -0
index 695255a..a0f8256 100644
@@ -295,6 +295,21 @@ void v4lconvert_yuyv_to_yuv420(const unsigned char *src, unsigned char *dest,
 	}
 }
 
+void v4lconvert_nv16_to_yuyv(const unsigned char *src, unsigned char *dest,
+		int width, int height)
+{
+	const unsigned char *y, *cbcr;
+	int count = 0;
+
+	y = src;
+	cbcr = src + width*height;
+
+	while (count++ < width*height) {
+		*dest++ = *y++;
+		*dest++ = *cbcr++;
+	}
+}
+
 void v4lconvert_yvyu_to_bgr24(const unsigned char *src, unsigned char *dest,
 		int width, int height, int stride)
 {

--
2.7.2

Acked-by on v2 1/1
#3 lore raw

Re: [v4l-utils PATCHv2] libv4lconvert: Add support for V4L2_PIX_FMT_{NV16,NV61}

Hi,

Quoted 11 lines · Niklas Söderlund

NV16 and NV61 are two-plane versions of the YUV 4:2:2 formats YUYV and YVYU. Support both formats by merging the two planes into a one and falling through to the V4L2_PIX_FMT_{YUYV,YVYU} code path.

---

I'm sorry this is a bit of a hack. The support for NV16 are scarce and this allowed me use it in qv4l2 so I thought it might help someone else. I'm not to sure about the entry in supported_src_pixfmts[] is it correct to set 'needs conversion' for my use case?

needs_conversion is set on formats which apps are unlikely to support natively, so yes it is correct to set it.

Patch looks good to me:

Hans Verkuil, if you're happy with this version feel free to push it.

Regards,

Hans

Quoted 115 lines

Changes since v1
- Add NV61 support
- Fixed s/YUVU/YUYV/g in commit message

  lib/libv4lconvert/libv4lconvert-priv.h |  3 +++
  lib/libv4lconvert/libv4lconvert.c      | 31 +++++++++++++++++++++++++++++++
  lib/libv4lconvert/rgbyuv.c             | 15 +++++++++++++++
  3 files changed, 49 insertions(+)
lib/libv4lconvert/libv4lconvert-priv.h +3 -0
index b77e3d3..1740efc 100644
@@ -129,6 +129,9 @@ void v4lconvert_yuyv_to_bgr24(const unsigned char *src, unsigned char *dst,
  void v4lconvert_yuyv_to_yuv420(const unsigned char *src, unsigned char *dst,
  		int width, int height, int stride, int yvu);
 
+void v4lconvert_nv16_to_yuyv(const unsigned char *src, unsigned char *dest,
+		int width, int height);
+
  void v4lconvert_yvyu_to_rgb24(const unsigned char *src, unsigned char *dst,
  		int width, int height, int stride);
 
lib/libv4lconvert/libv4lconvert.c +31 -0
index f62aea1..d3d8936 100644
@@ -98,6 +98,8 @@ static const struct v4lconvert_pixfmt supported_src_pixfmts[] = {
  	{ V4L2_PIX_FMT_YUYV,		16,	 5,	 4,	0 },
  	{ V4L2_PIX_FMT_YVYU,		16,	 5,	 4,	0 },
  	{ V4L2_PIX_FMT_UYVY,		16,	 5,	 4,	0 },
+	{ V4L2_PIX_FMT_NV16,		16,	 5,	 4,	1 },
+	{ V4L2_PIX_FMT_NV61,		16,	 5,	 4,	1 },
  	/* yuv 4:2:0 formats */
  	{ V4L2_PIX_FMT_SPCA501,		12,      6,	 3,	1 },
  	{ V4L2_PIX_FMT_SPCA505,		12,	 6,	 3,	1 },
@@ -1229,6 +1231,20 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data,
  		}
  		break;
 
+	case V4L2_PIX_FMT_NV16: {
+		unsigned char *tmpbuf;
+
+		tmpbuf = v4lconvert_alloc_buffer(width * height * 2,
+				&data->convert_pixfmt_buf, &data->convert_pixfmt_buf_size);
+		if (!tmpbuf)
+			return v4lconvert_oom_error(data);
+
+		v4lconvert_nv16_to_yuyv(src, tmpbuf, width, height);
+		src_pix_fmt = V4L2_PIX_FMT_YUYV;
+		src = tmpbuf;
+		bytesperline = bytesperline * 2;
+		/* fall through */
+	}
  	case V4L2_PIX_FMT_YUYV:
  		if (src_size < (width * height * 2)) {
  			V4LCONVERT_ERR("short yuyv data frame\n");
@@ -1251,6 +1267,21 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data,
  		}
  		break;
 
+	case V4L2_PIX_FMT_NV61: {
+		unsigned char *tmpbuf;
+
+		tmpbuf = v4lconvert_alloc_buffer(width * height * 2,
+				&data->convert_pixfmt_buf, &data->convert_pixfmt_buf_size);
+		if (!tmpbuf)
+			return v4lconvert_oom_error(data);
+
+		/* Note NV61 is NV16 with U and V swapped so this becomes yvyu. */
+		v4lconvert_nv16_to_yuyv(src, tmpbuf, width, height);
+		src_pix_fmt = V4L2_PIX_FMT_YVYU;
+		src = tmpbuf;
+		bytesperline = bytesperline * 2;
+		/* fall through */
+	}
  	case V4L2_PIX_FMT_YVYU:
  		if (src_size < (width * height * 2)) {
  			V4LCONVERT_ERR("short yvyu data frame\n");
lib/libv4lconvert/rgbyuv.c +15 -1
index 695255a..a0f8256 100644
@@ -295,6 +295,21 @@ void v4lconvert_yuyv_to_yuv420(const unsigned char *src, unsigned char *dest,
  	}
  }
 
+void v4lconvert_nv16_to_yuyv(const unsigned char *src, unsigned char *dest,
+		int width, int height)
+{
+	const unsigned char *y, *cbcr;
+	int count = 0;
+
+	y = src;
+	cbcr = src + width*height;
+
+	while (count++ < width*height) {
+		*dest++ = *y++;
+		*dest++ = *cbcr++;
+	}
+}
+
  void v4lconvert_yvyu_to_bgr24(const unsigned char *src, unsigned char *dest,
  		int width, int height, int stride)
  {
--

2.7.2

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