From patchwork Mon Sep 6 02:01:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13626 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 DE120C3255 for ; Mon, 6 Sep 2021 02:01:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 65D9F6919A; Mon, 6 Sep 2021 04:01:46 +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="OXd8D5y0"; 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 81AEB69168 for ; Mon, 6 Sep 2021 04:01:31 +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 1B1EB8D7; Mon, 6 Sep 2021 04:01:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1630893691; bh=nU44O2CRh0Z7L7TY3mzq8q94t1OYxvVKQ6Xr8p9WQGM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OXd8D5y0tb/+SBQ0npZRv4wq3yG5ohcj9xjOduIxj7UxtVkd9whSVKHJmDQ7Me1F3 2g/IbqhzFnZEq6MAwa38bG86FZOm4V/otcKu2Wo/jx70RX7pRYuoXMum1zOwbYXwbj tTicQOnKh6vm+aIw6Lp5basE4pNj2VqD66UUFdmc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 6 Sep 2021 05:01:00 +0300 Message-Id: <20210906020100.14430-28-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210906020100.14430-1-laurent.pinchart@ideasonboard.com> References: <20210906020100.14430-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 27/27] qcam: viewfinder_qt: Support multi-planar buffers 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" Now that the ViewFinderQt receives an Image, move the Converter API to take an Image as well, and enable multi-planar buffer support. Signed-off-by: Laurent Pinchart Reviewed-by: Jean-Michel Hautbois --- src/qcam/format_converter.cpp | 18 +++++++++++------- src/qcam/format_converter.h | 9 +++++---- src/qcam/viewfinder_qt.cpp | 14 +++++--------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/qcam/format_converter.cpp b/src/qcam/format_converter.cpp index 973966f6afc1..673ad33e141d 100644 --- a/src/qcam/format_converter.cpp +++ b/src/qcam/format_converter.cpp @@ -13,6 +13,8 @@ #include +#include "../cam/image.h" + #define RGBSHIFT 8 #ifndef MAX #define MAX(a,b) ((a)>(b)?(a):(b)) @@ -154,12 +156,11 @@ int FormatConverter::configure(const libcamera::PixelFormat &format, return 0; } -void FormatConverter::convert(const unsigned char *src, size_t size, - QImage *dst) +void FormatConverter::convert(const Image *src, size_t size, QImage *dst) { switch (formatFamily_) { case MJPEG: - dst->loadFromData(src, size, "JPEG"); + dst->loadFromData(src->data(0).data(), size, "JPEG"); break; case YUV: convertYUV(src, dst->bits()); @@ -183,13 +184,14 @@ static void yuv_to_rgb(int y, int u, int v, int *r, int *g, int *b) *b = CLIP(( 298 * c + 516 * d + 128) >> RGBSHIFT); } -void FormatConverter::convertNV(const unsigned char *src, unsigned char *dst) +void FormatConverter::convertNV(const Image *srcImage, unsigned char *dst) { unsigned int c_stride = width_ * (2 / horzSubSample_); unsigned int c_inc = horzSubSample_ == 1 ? 2 : 0; unsigned int cb_pos = nvSwap_ ? 1 : 0; unsigned int cr_pos = nvSwap_ ? 0 : 1; - const unsigned char *src_c = src + width_ * height_; + const unsigned char *src = srcImage->data(0).data(); + const unsigned char *src_c = srcImage->data(1).data(); int r, g, b; for (unsigned int y = 0; y < height_; y++) { @@ -223,8 +225,9 @@ void FormatConverter::convertNV(const unsigned char *src, unsigned char *dst) } } -void FormatConverter::convertRGB(const unsigned char *src, unsigned char *dst) +void FormatConverter::convertRGB(const Image *srcImage, unsigned char *dst) { + const unsigned char *src = srcImage->data(0).data(); unsigned int x, y; int r, g, b; @@ -245,8 +248,9 @@ void FormatConverter::convertRGB(const unsigned char *src, unsigned char *dst) } } -void FormatConverter::convertYUV(const unsigned char *src, unsigned char *dst) +void FormatConverter::convertYUV(const Image *srcImage, unsigned char *dst) { + const unsigned char *src = srcImage->data(0).data(); unsigned int src_x, src_y, dst_x, dst_y; unsigned int src_stride; unsigned int dst_stride; diff --git a/src/qcam/format_converter.h b/src/qcam/format_converter.h index e389b24a69f7..2220a62b5f11 100644 --- a/src/qcam/format_converter.h +++ b/src/qcam/format_converter.h @@ -13,6 +13,7 @@ #include +class Image; class QImage; class FormatConverter @@ -20,7 +21,7 @@ class FormatConverter public: int configure(const libcamera::PixelFormat &format, const QSize &size); - void convert(const unsigned char *src, size_t size, QImage *dst); + void convert(const Image *src, size_t size, QImage *dst); private: enum FormatFamily { @@ -30,9 +31,9 @@ private: YUV, }; - void convertNV(const unsigned char *src, unsigned char *dst); - void convertRGB(const unsigned char *src, unsigned char *dst); - void convertYUV(const unsigned char *src, unsigned char *dst); + void convertNV(const Image *src, unsigned char *dst); + void convertRGB(const Image *src, unsigned char *dst); + void convertYUV(const Image *src, unsigned char *dst); libcamera::PixelFormat format_; unsigned int width_; diff --git a/src/qcam/viewfinder_qt.cpp b/src/qcam/viewfinder_qt.cpp index fef6d53eef5e..0d357d860014 100644 --- a/src/qcam/viewfinder_qt.cpp +++ b/src/qcam/viewfinder_qt.cpp @@ -7,6 +7,7 @@ #include "viewfinder_qt.h" +#include #include #include @@ -81,12 +82,6 @@ int ViewFinderQt::setFormat(const libcamera::PixelFormat &format, void ViewFinderQt::render(libcamera::FrameBuffer *buffer, Image *image) { - if (buffer->planes().size() != 1) { - qWarning() << "Multi-planar buffers are not supported"; - return; - } - - unsigned char *memory = image->data(0).data(); size_t size = buffer->metadata().planes()[0].bytesused; { @@ -103,8 +98,9 @@ void ViewFinderQt::render(libcamera::FrameBuffer *buffer, Image *image) * \todo Get the stride from the buffer instead of * computing it naively */ - image_ = QImage(memory, size_.width(), size_.height(), - size / size_.height(), + assert(buffer->planes().size() == 1); + image_ = QImage(image->data(0).data(), size_.width(), + size_.height(), size / size_.height(), ::nativeFormats[format_]); std::swap(buffer, buffer_); } else { @@ -112,7 +108,7 @@ void ViewFinderQt::render(libcamera::FrameBuffer *buffer, Image *image) * Otherwise, convert the format and release the frame * buffer immediately. */ - converter_.convert(memory, size, &image_); + converter_.convert(image, size, &image_); } }