From patchwork Mon Sep 6 23:04:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13699 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 3EFD7BDC71 for ; Mon, 6 Sep 2021 23:05:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0FF866917D; Tue, 7 Sep 2021 01:05:02 +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="cOolbyoV"; 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 BFF4E69168 for ; Tue, 7 Sep 2021 01:04:58 +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 58B03891 for ; Tue, 7 Sep 2021 01:04:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1630969498; bh=Z83PIaP09KFY28WYWIkdx85GOIobhHjMjp31AF7XX00=; h=From:To:Subject:Date:In-Reply-To:References:From; b=cOolbyoVxWclzJ94GmJPVUHXaWhcBAaB7xBcB0/B/P3A0LNlyWLj/ycSxx+Lgsq6e 6mdG8ZopOCgmmCfc4DLuju67CWbHq1O7d4dr9HgCmp7r/RqZqpStP+mgAoTzZX5dX1 FTDoT4vQtxbTueIlptkwGprJkakf0XXndA3ZRVi8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 7 Sep 2021 02:04:33 +0300 Message-Id: <20210906230436.17106-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210906230436.17106-1-laurent.pinchart@ideasonboard.com> References: <20210906230436.17106-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 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 --- src/qcam/format_converter.cpp | 19 ++++++++++--------- src/qcam/format_converter.h | 4 +++- src/qcam/viewfinder_qt.cpp | 5 ++--- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/qcam/format_converter.cpp b/src/qcam/format_converter.cpp index 673ad33e141d..7f7ddb2dc77b 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: @@ -121,22 +121,22 @@ int FormatConverter::configure(const libcamera::PixelFormat &format, break; case libcamera::formats::VYUY: - formatFamily_ = YUV; + formatFamily_ = YUVPacked; y_pos_ = 1; cb_pos_ = 2; break; case libcamera::formats::YVYU: - formatFamily_ = YUV; + formatFamily_ = YUVPacked; y_pos_ = 0; cb_pos_ = 3; break; case libcamera::formats::UYVY: - formatFamily_ = YUV; + formatFamily_ = YUVPacked; y_pos_ = 1; cb_pos_ = 0; break; case libcamera::formats::YUYV: - formatFamily_ = YUV; + formatFamily_ = YUVPacked; y_pos_ = 0; cb_pos_ = 1; break; @@ -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;