[PATCH v4l-utils] libv4lconvert: Fix v4lconvert_grey_to_rgb24 not taking stride into account

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

 



Drivers are allowed to generate buffers where stride != width. Where as
v4lconvert_grey_to_rgb24() assumed that stride == width is always true.
This resulted in wrong frames for monochrome sensors, with padding bytes
being visible diagonally and messing up the image alignment.

Tested with rasbperry pi unicam driver using strides of 32 paired with
the st-vgxy61 driver, which native resolution is 1944x1204, producing a
frame of 1952x1204.

Signed-off-by: Benjamin Mugnier <benjamin.mugnier@xxxxxxxxxxx>
---
 lib/libv4lconvert/libv4lconvert-priv.h | 2 +-
 lib/libv4lconvert/libv4lconvert.c      | 2 +-
 lib/libv4lconvert/rgbyuv.c             | 3 ++-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/libv4lconvert/libv4lconvert-priv.h b/lib/libv4lconvert/libv4lconvert-priv.h
index 00a03f9e..0fd6a102 100644
--- a/lib/libv4lconvert/libv4lconvert-priv.h
+++ b/lib/libv4lconvert/libv4lconvert-priv.h
@@ -157,7 +157,7 @@ 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);
+		int width, int height, int stride);
 
 void v4lconvert_grey_to_yuv420(const unsigned char *src, unsigned char *dest,
 		const struct v4l2_format *src_fmt);
diff --git a/lib/libv4lconvert/libv4lconvert.c b/lib/libv4lconvert/libv4lconvert.c
index b07bf3ba..201dcf45 100644
--- a/lib/libv4lconvert/libv4lconvert.c
+++ b/lib/libv4lconvert/libv4lconvert.c
@@ -1245,7 +1245,7 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data,
 		switch (dest_pix_fmt) {
 		case V4L2_PIX_FMT_RGB24:
 	        case V4L2_PIX_FMT_BGR24:
-			v4lconvert_grey_to_rgb24(src, dest, width, height);
+			v4lconvert_grey_to_rgb24(src, dest, width, height, bytesperline);
 			break;
 		case V4L2_PIX_FMT_YUV420:
 		case V4L2_PIX_FMT_YVU420:
diff --git a/lib/libv4lconvert/rgbyuv.c b/lib/libv4lconvert/rgbyuv.c
index ce31a1ba..e2dceb3a 100644
--- a/lib/libv4lconvert/rgbyuv.c
+++ b/lib/libv4lconvert/rgbyuv.c
@@ -654,7 +654,7 @@ void v4lconvert_y16_to_yuv420(const unsigned char *src, unsigned char *dest,
 }
 
 void v4lconvert_grey_to_rgb24(const unsigned char *src, unsigned char *dest,
-		int width, int height)
+		int width, int height, int stride)
 {
 	int j;
 	while (--height >= 0) {
@@ -664,6 +664,7 @@ void v4lconvert_grey_to_rgb24(const unsigned char *src, unsigned char *dest,
 			*dest++ = *src;
 			src++;
 		}
+		src += stride - width;
 	}
 }
 
-- 
2.25.1




[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