From patchwork Tue Sep 7 00:20:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13705 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 32D9EBDC71 for ; Tue, 7 Sep 2021 00:21:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7DDB66916C; Tue, 7 Sep 2021 02:21:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="IUgHo/S9"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E5C1A69168 for ; Tue, 7 Sep 2021 02:21:07 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8A2BA891 for ; Tue, 7 Sep 2021 02:21:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1630974067; bh=yI7FDPFuliZmBZ0WCHAxF7tjPfiMMucGxtT5aeV7GT8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=IUgHo/S9DemX7LS7VmQ5TFmkKRLTYeeogQlcwmaAhu7zfQhAYiflKZt6gM7BgFWp2 mxenJVqwRuorw/N6IeEuOoLKUeMjYhWw9flM4EZIC3ffy7wcC6w5GPcVfG4GtlXJP1 cXnVDmpSmxPM1E3F94JGX8eB/He9/sUs/nLwhtiU= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 7 Sep 2021 03:20:41 +0300 Message-Id: <20210907002044.7319-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907002044.7319-1-laurent.pinchart@ideasonboard.com> References: <20210907002044.7319-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/5] qcam: format_converter: Add configurable stride support X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Make the stride configurable to support convertion of images with padding at the end of lines. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Paul Elder --- Changes since v1: - Fix bad rebase --- src/qcam/format_converter.cpp | 11 ++++++----- src/qcam/format_converter.h | 4 +++- src/qcam/viewfinder_qt.cpp | 5 ++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/qcam/format_converter.cpp b/src/qcam/format_converter.cpp index 673ad33e141d..b4c7b0ca0edf 100644 --- a/src/qcam/format_converter.cpp +++ b/src/qcam/format_converter.cpp @@ -30,7 +30,7 @@ #endif int FormatConverter::configure(const libcamera::PixelFormat &format, - const QSize &size) + const QSize &size, unsigned int stride) { switch (format) { case libcamera::formats::NV12: @@ -152,6 +152,7 @@ int FormatConverter::configure(const libcamera::PixelFormat &format, format_ = format; width_ = size.width(); height_ = size.height(); + stride_ = stride; return 0; } @@ -186,7 +187,7 @@ static void yuv_to_rgb(int y, int u, int v, int *r, int *g, int *b) void FormatConverter::convertNV(const Image *srcImage, unsigned char *dst) { - unsigned int c_stride = width_ * (2 / horzSubSample_); + unsigned int c_stride = stride_ * (2 / horzSubSample_); unsigned int c_inc = horzSubSample_ == 1 ? 2 : 0; unsigned int cb_pos = nvSwap_ ? 1 : 0; unsigned int cr_pos = nvSwap_ ? 0 : 1; @@ -195,7 +196,7 @@ void FormatConverter::convertNV(const Image *srcImage, unsigned char *dst) int r, g, b; for (unsigned int y = 0; y < height_; y++) { - const unsigned char *src_y = src + y * width_; + const unsigned char *src_y = src + y * stride_; const unsigned char *src_cb = src_c + (y / vertSubSample_) * c_stride + cb_pos; const unsigned char *src_cr = src_c + (y / vertSubSample_) * @@ -243,7 +244,7 @@ void FormatConverter::convertRGB(const Image *srcImage, unsigned char *dst) dst[4 * x + 3] = 0xff; } - src += width_ * bpp_; + src += stride_; dst += width_ * 4; } } @@ -258,7 +259,7 @@ void FormatConverter::convertYUV(const Image *srcImage, unsigned char *dst) int r, g, b, y, cr, cb; cr_pos = (cb_pos_ + 2) % 4; - src_stride = width_ * 2; + src_stride = stride_; dst_stride = width_ * 4; for (src_y = 0, dst_y = 0; dst_y < height_; src_y++, dst_y++) { diff --git a/src/qcam/format_converter.h b/src/qcam/format_converter.h index 2220a62b5f11..bb04aa959a1a 100644 --- a/src/qcam/format_converter.h +++ b/src/qcam/format_converter.h @@ -19,7 +19,8 @@ class QImage; class FormatConverter { public: - int configure(const libcamera::PixelFormat &format, const QSize &size); + int configure(const libcamera::PixelFormat &format, const QSize &size, + unsigned int stride); void convert(const Image *src, size_t size, QImage *dst); @@ -38,6 +39,7 @@ private: libcamera::PixelFormat format_; unsigned int width_; unsigned int height_; + unsigned int stride_; enum FormatFamily formatFamily_; diff --git a/src/qcam/viewfinder_qt.cpp b/src/qcam/viewfinder_qt.cpp index cd051760160c..a05c75ed9e12 100644 --- a/src/qcam/viewfinder_qt.cpp +++ b/src/qcam/viewfinder_qt.cpp @@ -52,8 +52,7 @@ const QList &ViewFinderQt::nativeFormats() const } int ViewFinderQt::setFormat(const libcamera::PixelFormat &format, - const QSize &size, - [[maybe_unused]] unsigned int stride) + const QSize &size, unsigned int stride) { image_ = QImage(); @@ -62,7 +61,7 @@ int ViewFinderQt::setFormat(const libcamera::PixelFormat &format, * the destination image. */ if (!::nativeFormats.contains(format)) { - int ret = converter_.configure(format, size); + int ret = converter_.configure(format, size, stride); if (ret < 0) return ret;