aboutsummaryrefslogtreecommitdiffstats
diff options
authorHans de Goede <hdegoede@redhat.com>2022-10-16 19:57:29 +0200
committerMauro Carvalho Chehab <mchehab@kernel.org>2022-11-14 21:04:48 +0000
commit80e27b5fde28fa3ef76da88c1e7530ee6c776e70 (patch)
tree6c6857d1f67b887801edbb680ca5ec93204b2fbb
parent14b3ecc7bd144efc94cdac1c51e91ebba3f9879b (diff)
libv4lconvert: Fix v4lconvert_nv16_to_yuyv() not taking stride into accountstable-1.18
The atomisp driver can generate V4L2_PIX_FMT_NV16 buffers where stride != width. Where as v4lconvert_nv16_to_yuyv() assumed that stride == width is always true. Add a stride argument to v4lconvert_nv16_to_yuyv() to fix this. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
-rw-r--r--lib/libv4lconvert/libv4lconvert-priv.h2
-rw-r--r--lib/libv4lconvert/libv4lconvert.c8
-rw-r--r--lib/libv4lconvert/rgbyuv.c16
3 files changed, 15 insertions, 11 deletions
diff --git a/lib/libv4lconvert/libv4lconvert-priv.h b/lib/libv4lconvert/libv4lconvert-priv.h
index d4e8310b..dd0c86d0 100644
--- a/lib/libv4lconvert/libv4lconvert-priv.h
+++ b/lib/libv4lconvert/libv4lconvert-priv.h
@@ -133,7 +133,7 @@ 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);
+ int width, int height, int stride);
void v4lconvert_yvyu_to_rgb24(const unsigned char *src, unsigned char *dst,
int width, int height, int stride);
diff --git a/lib/libv4lconvert/libv4lconvert.c b/lib/libv4lconvert/libv4lconvert.c
index fc9287c9..02ea0906 100644
--- a/lib/libv4lconvert/libv4lconvert.c
+++ b/lib/libv4lconvert/libv4lconvert.c
@@ -1445,10 +1445,10 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data,
if (!tmpbuf)
return v4lconvert_oom_error(data);
- v4lconvert_nv16_to_yuyv(src, tmpbuf, width, height);
+ v4lconvert_nv16_to_yuyv(src, tmpbuf, width, height, bytesperline);
src_pix_fmt = V4L2_PIX_FMT_YUYV;
src = tmpbuf;
- bytesperline = bytesperline * 2;
+ bytesperline = width * 2;
/* fall through */
}
case V4L2_PIX_FMT_YUYV:
@@ -1482,10 +1482,10 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data,
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);
+ v4lconvert_nv16_to_yuyv(src, tmpbuf, width, height, bytesperline);
src_pix_fmt = V4L2_PIX_FMT_YVYU;
src = tmpbuf;
- bytesperline = bytesperline * 2;
+ bytesperline = width * 2;
/* fall through */
}
case V4L2_PIX_FMT_YVYU:
diff --git a/lib/libv4lconvert/rgbyuv.c b/lib/libv4lconvert/rgbyuv.c
index e9fe6df9..ce31a1ba 100644
--- a/lib/libv4lconvert/rgbyuv.c
+++ b/lib/libv4lconvert/rgbyuv.c
@@ -304,17 +304,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)
+ int width, int height, int stride)
{
const unsigned char *y, *cbcr;
- int count = 0;
+ int i, j;
y = src;
- cbcr = src + width*height;
+ cbcr = src + stride * height;
- while (count++ < width*height) {
- *dest++ = *y++;
- *dest++ = *cbcr++;
+ for (i = 0; i < height; i++) {
+ for (j = 0; j < width; j++) {
+ *dest++ = *y++;
+ *dest++ = *cbcr++;
+ }
+ y += stride - width;
+ cbcr += stride - width;
}
}

Privacy Policy

close