From patchwork Tue Sep 7 00:20:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13704 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 C9A2FBDC71 for ; Tue, 7 Sep 2021 00:21:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C0AF069178; Tue, 7 Sep 2021 02:21:10 +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="mYu+n1A1"; 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 A563069167 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 3D124993 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=62WmNlGgrpwlRornY2x0Y+b25WlZ4o246XoUY+EFKw8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=mYu+n1A1JAY3mRAo1F/l/sVbLLrQ6UhjiDODIOKxbEcUewkP2hTAIDk7938E1E0SN 2P9XznVbNizlzwscKJtUYxfA5o6uDHh9oZaMhyK8RwcPB/9IgPnDTTy64bb1Wz8gKK R9Q5S8GcTUXFBgSSvKG43YJ19MzhPw5VNnnzJXYU= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 7 Sep 2021 03:20:40 +0300 Message-Id: <20210907002044.7319-2-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 1/5] qcam: viewfinder: Pass stride value to viewfinder 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" qcam currently assumes that no padding is used at end of lines, and uses the image width as the stride. This leads to rendering failures with some formats on some platforms. To prepare for stride support, add a stride parameter to the ViewFinder::setFormat() function to pass the stride from the stream configuration to the viewfinder. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Paul Elder --- src/qcam/main_window.cpp | 3 ++- src/qcam/viewfinder.h | 3 ++- src/qcam/viewfinder_gl.cpp | 7 ++----- src/qcam/viewfinder_gl.h | 3 ++- src/qcam/viewfinder_qt.cpp | 3 ++- src/qcam/viewfinder_qt.h | 3 ++- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 168dd5ce30e3..bb6b03993add 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -448,7 +448,8 @@ int MainWindow::startCapture() /* Configure the viewfinder. */ ret = viewfinder_->setFormat(vfConfig.pixelFormat, - QSize(vfConfig.size.width, vfConfig.size.height)); + QSize(vfConfig.size.width, vfConfig.size.height), + vfConfig.stride); if (ret < 0) { qInfo() << "Failed to set viewfinder format"; return ret; diff --git a/src/qcam/viewfinder.h b/src/qcam/viewfinder.h index fb462835fb5f..4c2102a6ed04 100644 --- a/src/qcam/viewfinder.h +++ b/src/qcam/viewfinder.h @@ -23,7 +23,8 @@ public: virtual const QList &nativeFormats() const = 0; - virtual int setFormat(const libcamera::PixelFormat &format, const QSize &size) = 0; + virtual int setFormat(const libcamera::PixelFormat &format, const QSize &size, + unsigned int stride) = 0; virtual void render(libcamera::FrameBuffer *buffer, Image *image) = 0; virtual void stop() = 0; diff --git a/src/qcam/viewfinder_gl.cpp b/src/qcam/viewfinder_gl.cpp index 32232faa2ad8..aeb1ea02d2d5 100644 --- a/src/qcam/viewfinder_gl.cpp +++ b/src/qcam/viewfinder_gl.cpp @@ -72,7 +72,7 @@ const QList &ViewFinderGL::nativeFormats() const } int ViewFinderGL::setFormat(const libcamera::PixelFormat &format, - const QSize &size) + const QSize &size, unsigned int stride) { if (format != format_) { /* @@ -92,6 +92,7 @@ int ViewFinderGL::setFormat(const libcamera::PixelFormat &format, } size_ = size; + stride_ = stride; updateGeometry(); return 0; @@ -119,10 +120,6 @@ void ViewFinderGL::render(libcamera::FrameBuffer *buffer, Image *image) renderComplete(buffer_); image_ = image; - /* - * \todo Get the stride from the buffer instead of computing it naively - */ - stride_ = buffer->metadata().planes()[0].bytesused / size_.height(); update(); buffer_ = buffer; } diff --git a/src/qcam/viewfinder_gl.h b/src/qcam/viewfinder_gl.h index 72a60ecb9159..2b2b1e86035a 100644 --- a/src/qcam/viewfinder_gl.h +++ b/src/qcam/viewfinder_gl.h @@ -38,7 +38,8 @@ public: const QList &nativeFormats() const override; - int setFormat(const libcamera::PixelFormat &format, const QSize &size) override; + int setFormat(const libcamera::PixelFormat &format, const QSize &size, + unsigned int stride) override; void render(libcamera::FrameBuffer *buffer, Image *image) override; void stop() override; diff --git a/src/qcam/viewfinder_qt.cpp b/src/qcam/viewfinder_qt.cpp index 0d357d860014..cd051760160c 100644 --- a/src/qcam/viewfinder_qt.cpp +++ b/src/qcam/viewfinder_qt.cpp @@ -52,7 +52,8 @@ const QList &ViewFinderQt::nativeFormats() const } int ViewFinderQt::setFormat(const libcamera::PixelFormat &format, - const QSize &size) + const QSize &size, + [[maybe_unused]] unsigned int stride) { image_ = QImage(); diff --git a/src/qcam/viewfinder_qt.h b/src/qcam/viewfinder_qt.h index 6b48ef48a7d1..756f3fa33055 100644 --- a/src/qcam/viewfinder_qt.h +++ b/src/qcam/viewfinder_qt.h @@ -31,7 +31,8 @@ public: const QList &nativeFormats() const override; - int setFormat(const libcamera::PixelFormat &format, const QSize &size) override; + int setFormat(const libcamera::PixelFormat &format, const QSize &size, + unsigned int stride) override; void render(libcamera::FrameBuffer *buffer, Image *image) override; void stop() override;