From patchwork Sun Oct 16 17:57:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 615953 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B463EC4332F for ; Sun, 16 Oct 2022 17:57:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229748AbiJPR5r (ORCPT ); Sun, 16 Oct 2022 13:57:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbiJPR5q (ORCPT ); Sun, 16 Oct 2022 13:57:46 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42C8929355 for ; Sun, 16 Oct 2022 10:57:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665943063; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9S6KHRZorxW9iRfuype592okm6l1ei31+q0809xnIlU=; b=Zq5buMDCyjC8q0xUBI4V2qm/UBtukuVcLpFQjzrM609VyTf2jXwU+x1L9sqIOGwEGHEqvt Slxmh5N8w+dDHgo25Gg1Gu7jqcioDn5ImtsXJTxRF33nTGXQYdPV2LFmSUnznZf01h9If2 sc9LkWcVMOmO8e2idr81/m4Sag7v3Dk= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-375-5FTx-dafMeuEYumGUAY1uA-1; Sun, 16 Oct 2022 13:57:41 -0400 X-MC-Unique: 5FTx-dafMeuEYumGUAY1uA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8AA553803904; Sun, 16 Oct 2022 17:57:41 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0296414A815; Sun, 16 Oct 2022 17:57:40 +0000 (UTC) From: Hans de Goede To: Hans Verkuil , linux-media@vger.kernel.org Cc: Hans de Goede Subject: [PATCH v4l-utils 1/4] libv4lconvert: Fix v4lconvert_yuv420_to_rgb/bgr24() not taking stride into account Date: Sun, 16 Oct 2022 19:57:26 +0200 Message-Id: <20221016175729.187258-2-hdegoede@redhat.com> In-Reply-To: <20221016175729.187258-1-hdegoede@redhat.com> References: <20221016175729.187258-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The atomisp driver can generate V4L2_PIX_FMT_YUV420 buffers where stride != width. Where as v4lconvert_yuv420_to_rgb/bgr24() assumed that stride == width is always true. Add a stride argument to v4lconvert_yuv420_to_rgb/bgr24() to fix this. Signed-off-by: Hans de Goede --- lib/libv4lconvert/libv4lconvert-priv.h | 4 ++-- lib/libv4lconvert/libv4lconvert.c | 12 +++++------ lib/libv4lconvert/rgbyuv.c | 30 ++++++++++++++++---------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/lib/libv4lconvert/libv4lconvert-priv.h b/lib/libv4lconvert/libv4lconvert-priv.h index 6b9128ce..495f726d 100644 --- a/lib/libv4lconvert/libv4lconvert-priv.h +++ b/lib/libv4lconvert/libv4lconvert-priv.h @@ -118,10 +118,10 @@ void v4lconvert_rgb24_to_yuv420(const unsigned char *src, unsigned char *dest, const struct v4l2_format *src_fmt, int bgr, int yvu, int bpp); void v4lconvert_yuv420_to_rgb24(const unsigned char *src, unsigned char *dst, - int width, int height, int yvu); + int width, int height, int stride, int yvu); void v4lconvert_yuv420_to_bgr24(const unsigned char *src, unsigned char *dst, - int width, int height, int yvu); + int width, int height, int stride, int yvu); void v4lconvert_yuyv_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 e794ec00..e5d5ddde 100644 --- a/lib/libv4lconvert/libv4lconvert.c +++ b/lib/libv4lconvert/libv4lconvert.c @@ -905,11 +905,11 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data, switch (dest_pix_fmt) { case V4L2_PIX_FMT_RGB24: v4lconvert_yuv420_to_rgb24(data->convert_pixfmt_buf, dest, width, - height, yvu); + height, bytesperline, yvu); break; case V4L2_PIX_FMT_BGR24: v4lconvert_yuv420_to_bgr24(data->convert_pixfmt_buf, dest, width, - height, yvu); + height, bytesperline, yvu); break; } break; @@ -1398,11 +1398,11 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data, switch (dest_pix_fmt) { case V4L2_PIX_FMT_RGB24: v4lconvert_yuv420_to_rgb24(src, dest, width, - height, 0); + height, bytesperline, 0); break; case V4L2_PIX_FMT_BGR24: v4lconvert_yuv420_to_bgr24(src, dest, width, - height, 0); + height, bytesperline, 0); break; case V4L2_PIX_FMT_YUV420: memcpy(dest, src, width * height * 3 / 2); @@ -1422,11 +1422,11 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data, switch (dest_pix_fmt) { case V4L2_PIX_FMT_RGB24: v4lconvert_yuv420_to_rgb24(src, dest, width, - height, 1); + height, bytesperline, 1); break; case V4L2_PIX_FMT_BGR24: v4lconvert_yuv420_to_bgr24(src, dest, width, - height, 1); + height, bytesperline, 1); break; case V4L2_PIX_FMT_YUV420: v4lconvert_swap_uv(src, dest, fmt); diff --git a/lib/libv4lconvert/rgbyuv.c b/lib/libv4lconvert/rgbyuv.c index b54b4577..1ca821ab 100644 --- a/lib/libv4lconvert/rgbyuv.c +++ b/lib/libv4lconvert/rgbyuv.c @@ -93,7 +93,7 @@ void v4lconvert_rgb24_to_yuv420(const unsigned char *src, unsigned char *dest, #define CLIP(color) (unsigned char)(((color) > 0xFF) ? 0xff : (((color) < 0) ? 0 : (color))) void v4lconvert_yuv420_to_bgr24(const unsigned char *src, unsigned char *dest, - int width, int height, int yvu) + int width, int height, int stride, int yvu) { int i, j; @@ -101,11 +101,11 @@ void v4lconvert_yuv420_to_bgr24(const unsigned char *src, unsigned char *dest, const unsigned char *usrc, *vsrc; if (yvu) { - vsrc = src + width * height; - usrc = vsrc + (width * height) / 4; + vsrc = src + stride * height; + usrc = vsrc + (stride * height) / 4; } else { - usrc = src + width * height; - vsrc = usrc + (width * height) / 4; + usrc = src + stride * height; + vsrc = usrc + (stride * height) / 4; } for (i = 0; i < height; i++) { @@ -138,16 +138,20 @@ void v4lconvert_yuv420_to_bgr24(const unsigned char *src, unsigned char *dest, usrc++; vsrc++; } + ysrc += stride - width; /* Rewind u and v for next line */ if (!(i & 1)) { usrc -= width / 2; vsrc -= width / 2; + } else { + usrc += (stride - width) / 2; + vsrc += (stride - width) / 2; } } } void v4lconvert_yuv420_to_rgb24(const unsigned char *src, unsigned char *dest, - int width, int height, int yvu) + int width, int height, int stride, int yvu) { int i, j; @@ -155,11 +159,11 @@ void v4lconvert_yuv420_to_rgb24(const unsigned char *src, unsigned char *dest, const unsigned char *usrc, *vsrc; if (yvu) { - vsrc = src + width * height; - usrc = vsrc + (width * height) / 4; + vsrc = src + stride * height; + usrc = vsrc + (stride * height) / 4; } else { - usrc = src + width * height; - vsrc = usrc + (width * height) / 4; + usrc = src + stride * height; + vsrc = usrc + (stride * height) / 4; } for (i = 0; i < height; i++) { @@ -192,10 +196,14 @@ void v4lconvert_yuv420_to_rgb24(const unsigned char *src, unsigned char *dest, usrc++; vsrc++; } + ysrc += stride - width; /* Rewind u and v for next line */ - if (!(i&1)) { + if (!(i & 1)) { usrc -= width / 2; vsrc -= width / 2; + } else { + usrc += (stride - width) / 2; + vsrc += (stride - width) / 2; } } } From patchwork Sun Oct 16 17:57:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 615951 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6991C433FE for ; Sun, 16 Oct 2022 17:57:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229618AbiJPR5u (ORCPT ); Sun, 16 Oct 2022 13:57:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229597AbiJPR5t (ORCPT ); Sun, 16 Oct 2022 13:57:49 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCAED29355 for ; Sun, 16 Oct 2022 10:57:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665943067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bxHYaconQiDBKCZQGex41zM7Q2tL5c2N/0UkwfLa4Ak=; b=Y+ftMytlDJzyaGP/GH4y1EUfBJROIrgTlFqHNFYL5o8VZcdZI0XYKTjYHZOMrDMStFXOdW aUsrKBGmBqKTe/ZhFzNN9paSoZuuiuGGk4RnEelBpz9j1CcSrytao1p2a2QAgDVA969yUS 6NtSblcJKmJ0Qvwpqp1Gwq0bi1ZrlPI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-177-7rPxGP4AOI6Y4UZZpXjD2Q-1; Sun, 16 Oct 2022 13:57:42 -0400 X-MC-Unique: 7rPxGP4AOI6Y4UZZpXjD2Q-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 58EA13C01D82; Sun, 16 Oct 2022 17:57:42 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0D8A414A815; Sun, 16 Oct 2022 17:57:41 +0000 (UTC) From: Hans de Goede To: Hans Verkuil , linux-media@vger.kernel.org Cc: Hans de Goede Subject: [PATCH v4l-utils 2/4] libv4lconvert: Fix v4lconvert_rgb565_to_rgb/bgr24() not taking stride into account Date: Sun, 16 Oct 2022 19:57:27 +0200 Message-Id: <20221016175729.187258-3-hdegoede@redhat.com> In-Reply-To: <20221016175729.187258-1-hdegoede@redhat.com> References: <20221016175729.187258-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The atomisp driver can generate V4L2_PIX_FMT_RGB565 buffers where stride != width. Where as v4lconvert_rgb565_to_rgb/bgr24() assumed that stride == width is always true. Add a stride argument to v4lconvert_rgb565_to_rgb/bgr24() to fix this. Signed-off-by: Hans de Goede --- lib/libv4lconvert/libv4lconvert-priv.h | 4 ++-- lib/libv4lconvert/libv4lconvert.c | 4 ++-- lib/libv4lconvert/rgbyuv.c | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/libv4lconvert/libv4lconvert-priv.h b/lib/libv4lconvert/libv4lconvert-priv.h index 495f726d..f87a43a4 100644 --- a/lib/libv4lconvert/libv4lconvert-priv.h +++ b/lib/libv4lconvert/libv4lconvert-priv.h @@ -178,10 +178,10 @@ int v4lconvert_y10b_to_yuv420(struct v4lconvert_data *data, 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); + int width, int height, int stride); void v4lconvert_rgb565_to_bgr24(const unsigned char *src, unsigned char *dest, - int width, int height); + int width, int height, int stride); void v4lconvert_rgb565_to_yuv420(const unsigned char *src, unsigned char *dest, const struct v4l2_format *src_fmt, int yvu); diff --git a/lib/libv4lconvert/libv4lconvert.c b/lib/libv4lconvert/libv4lconvert.c index e5d5ddde..77f9eca5 100644 --- a/lib/libv4lconvert/libv4lconvert.c +++ b/lib/libv4lconvert/libv4lconvert.c @@ -1282,10 +1282,10 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data, } switch (dest_pix_fmt) { case V4L2_PIX_FMT_RGB24: - v4lconvert_rgb565_to_rgb24(src, dest, width, height); + v4lconvert_rgb565_to_rgb24(src, dest, width, height, bytesperline); break; case V4L2_PIX_FMT_BGR24: - v4lconvert_rgb565_to_bgr24(src, dest, width, height); + v4lconvert_rgb565_to_bgr24(src, dest, width, height, bytesperline); break; case V4L2_PIX_FMT_YUV420: v4lconvert_rgb565_to_yuv420(src, dest, fmt, 0); diff --git a/lib/libv4lconvert/rgbyuv.c b/lib/libv4lconvert/rgbyuv.c index 1ca821ab..f9017016 100644 --- a/lib/libv4lconvert/rgbyuv.c +++ b/lib/libv4lconvert/rgbyuv.c @@ -511,7 +511,7 @@ void v4lconvert_swap_uv(const unsigned char *src, unsigned char *dest, } void v4lconvert_rgb565_to_rgb24(const unsigned char *src, unsigned char *dest, - int width, int height) + int width, int height, int stride) { int j; while (--height >= 0) { @@ -525,11 +525,12 @@ void v4lconvert_rgb565_to_rgb24(const unsigned char *src, unsigned char *dest, src += 2; } + src += stride - 2 * width; } } void v4lconvert_rgb565_to_bgr24(const unsigned char *src, unsigned char *dest, - int width, int height) + int width, int height, int stride) { int j; while (--height >= 0) { @@ -543,6 +544,7 @@ void v4lconvert_rgb565_to_bgr24(const unsigned char *src, unsigned char *dest, src += 2; } + src += stride - 2 * width; } } From patchwork Sun Oct 16 17:57:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 615606 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46698C43217 for ; Sun, 16 Oct 2022 17:57:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229683AbiJPR5t (ORCPT ); Sun, 16 Oct 2022 13:57:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbiJPR5r (ORCPT ); Sun, 16 Oct 2022 13:57:47 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F197B2A25B for ; Sun, 16 Oct 2022 10:57:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665943065; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c0pDNIoMwucOc74WiAOiC0DMsLVoxDkWz0MmjdoLFSA=; b=VPCWHQYwdQ/NRGQzi30cm/YCjK+b2mqo83ZxPPh0KZeLDHDHG/MB5VHQhg8vW/8GmfTdzq i0DoqVdynMH+0FjEmMUPUcdyELjWUapyfiSXE5oBl6c/06npo75GZ8RmquPL4bWzvoKtVg uNVmHpg/0ctEY982/C/b6ZXPXyu1ewg= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-32-H9IAv7KDOfaclKd_wN1p0A-1; Sun, 16 Oct 2022 13:57:43 -0400 X-MC-Unique: H9IAv7KDOfaclKd_wN1p0A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2AF7729AA2E3; Sun, 16 Oct 2022 17:57:43 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FAB2414A815; Sun, 16 Oct 2022 17:57:42 +0000 (UTC) From: Hans de Goede To: Hans Verkuil , linux-media@vger.kernel.org Cc: Hans de Goede Subject: [PATCH v4l-utils 3/4] libv4lconvert: Fix v4lconvert_nv12_*() not taking stride into account Date: Sun, 16 Oct 2022 19:57:28 +0200 Message-Id: <20221016175729.187258-4-hdegoede@redhat.com> In-Reply-To: <20221016175729.187258-1-hdegoede@redhat.com> References: <20221016175729.187258-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The atomisp driver can generate V4L2_PIX_FMT_NV12 buffers where stride != width. Where as v4lconvert_nv12_*() assumed that stride == width is always true. Add a stride argument to v4lconvert_nv12_*() to fix this. Signed-off-by: Hans de Goede --- lib/libv4lconvert/libv4lconvert-priv.h | 4 ++-- lib/libv4lconvert/libv4lconvert.c | 8 ++++---- lib/libv4lconvert/rgbyuv.c | 18 +++++++++++++----- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/libv4lconvert/libv4lconvert-priv.h b/lib/libv4lconvert/libv4lconvert-priv.h index f87a43a4..f361f2a0 100644 --- a/lib/libv4lconvert/libv4lconvert-priv.h +++ b/lib/libv4lconvert/libv4lconvert-priv.h @@ -287,10 +287,10 @@ void v4lconvert_hsv_to_rgb24(const unsigned char *src, unsigned char *dest, int width, int height, int bgr, int Xin, unsigned char hsv_enc); void v4lconvert_nv12_to_rgb24(const unsigned char *src, unsigned char *dest, - int width, int height, int bgr); + int width, int height, int stride, int bgr); void v4lconvert_nv12_to_yuv420(const unsigned char *src, unsigned char *dest, - int width, int height, int yvu); + int width, int height, int stride, int yvu); void v4lconvert_rotate90(unsigned char *src, unsigned char *dest, struct v4l2_format *fmt); diff --git a/lib/libv4lconvert/libv4lconvert.c b/lib/libv4lconvert/libv4lconvert.c index 77f9eca5..d0d38286 100644 --- a/lib/libv4lconvert/libv4lconvert.c +++ b/lib/libv4lconvert/libv4lconvert.c @@ -937,16 +937,16 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data, case V4L2_PIX_FMT_NV12: switch (dest_pix_fmt) { case V4L2_PIX_FMT_RGB24: - v4lconvert_nv12_to_rgb24(src, dest, width, height, 0); + v4lconvert_nv12_to_rgb24(src, dest, width, height, bytesperline, 0); break; case V4L2_PIX_FMT_BGR24: - v4lconvert_nv12_to_rgb24(src, dest, width, height, 1); + v4lconvert_nv12_to_rgb24(src, dest, width, height, bytesperline, 1); break; case V4L2_PIX_FMT_YUV420: - v4lconvert_nv12_to_yuv420(src, dest, width, height, 0); + v4lconvert_nv12_to_yuv420(src, dest, width, height, bytesperline, 0); break; case V4L2_PIX_FMT_YVU420: - v4lconvert_nv12_to_yuv420(src, dest, width, height, 1); + v4lconvert_nv12_to_yuv420(src, dest, width, height, bytesperline, 1); break; } break; diff --git a/lib/libv4lconvert/rgbyuv.c b/lib/libv4lconvert/rgbyuv.c index f9017016..e9fe6df9 100644 --- a/lib/libv4lconvert/rgbyuv.c +++ b/lib/libv4lconvert/rgbyuv.c @@ -857,11 +857,11 @@ void v4lconvert_hsv_to_rgb24(const unsigned char *src, unsigned char *dest, } void v4lconvert_nv12_to_rgb24(const unsigned char *src, unsigned char *dest, - int width, int height, int bgr) + int width, int height, int stride, int bgr) { int i, j; const unsigned char *ysrc = src; - const unsigned char *uvsrc = src + width * height; + const unsigned char *uvsrc = src + stride * height; for (i = 0; i < height; i++) { for (j = 0; j < width; j ++) { @@ -879,18 +879,21 @@ void v4lconvert_nv12_to_rgb24(const unsigned char *src, unsigned char *dest, uvsrc += 2; } + ysrc += stride - width; /* Rewind u and v for next line */ if (!(i&1)) uvsrc -= width; + else + uvsrc += stride - width; } } void v4lconvert_nv12_to_yuv420(const unsigned char *src, unsigned char *dest, - int width, int height, int yvu) + int width, int height, int stride, int yvu) { int i, j; const unsigned char *ysrc = src; - const unsigned char *uvsrc = src + width * height; + const unsigned char *uvsrc = src + stride * height; unsigned char *ydst = dest; unsigned char *udst, *vdst; @@ -902,7 +905,7 @@ void v4lconvert_nv12_to_yuv420(const unsigned char *src, unsigned char *dest, vdst = udst + ((width / 2) * (height / 2)); } - for (i = 0; i < height; i++) + for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { *ydst++ = *ysrc++; if (((i % 2) == 0) && ((j % 2) == 0)) { @@ -910,4 +913,9 @@ void v4lconvert_nv12_to_yuv420(const unsigned char *src, unsigned char *dest, *vdst++ = *uvsrc++; } } + + ysrc += stride - width; + if ((i % 2) == 0) + uvsrc += stride - width; + } } From patchwork Sun Oct 16 17:57:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 615952 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF1FFC43219 for ; Sun, 16 Oct 2022 17:57:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229747AbiJPR5t (ORCPT ); Sun, 16 Oct 2022 13:57:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229755AbiJPR5s (ORCPT ); Sun, 16 Oct 2022 13:57:48 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7191127B32 for ; Sun, 16 Oct 2022 10:57:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665943066; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IEgD/0FzmuJFLFm6IjmCQ72R2L0S86C4niRmtB+En8Q=; b=jJlW7MTThFGtDv6UVVFB3DcVzcbfQwwa114LvR9UJkURMOQKOjY9J3u//4AZJPI0wKm4YA LiQHiPs5EXsYkNF2BRYXx8qkQpdiIFK7x8bW6xQ3srmLEDhhboLC697cz8c4YIB4DP0I4s P9TtQF7avJQ3OA9E2zyKWumrsv7p2a4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-669-Ry5lIAs_OGeubWQf9-83BA-1; Sun, 16 Oct 2022 13:57:44 -0400 X-MC-Unique: Ry5lIAs_OGeubWQf9-83BA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ECF7C833AEC; Sun, 16 Oct 2022 17:57:43 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F7F1414A815; Sun, 16 Oct 2022 17:57:43 +0000 (UTC) From: Hans de Goede To: Hans Verkuil , linux-media@vger.kernel.org Cc: Hans de Goede Subject: [PATCH v4l-utils 4/4] libv4lconvert: Fix v4lconvert_nv16_to_yuyv() not taking stride into account Date: Sun, 16 Oct 2022 19:57:29 +0200 Message-Id: <20221016175729.187258-5-hdegoede@redhat.com> In-Reply-To: <20221016175729.187258-1-hdegoede@redhat.com> References: <20221016175729.187258-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 --- lib/libv4lconvert/libv4lconvert-priv.h | 2 +- lib/libv4lconvert/libv4lconvert.c | 8 ++++---- lib/libv4lconvert/rgbyuv.c | 16 ++++++++++------ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/libv4lconvert/libv4lconvert-priv.h b/lib/libv4lconvert/libv4lconvert-priv.h index f361f2a0..00a03f9e 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 d0d38286..b07bf3ba 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; } }