From patchwork Mon Mar 23 23:17:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3289 Return-Path: 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 B2D3460417 for ; Tue, 24 Mar 2020 00:17:15 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 28B53308 for ; Tue, 24 Mar 2020 00:17:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1585005435; bh=UZ+P5wkSWcg5lU517NyR3bJrf2sdmb1GujI3mgzSR6U=; h=From:To:Subject:Date:In-Reply-To:References:From; b=SIOHTHJ3VKs30j5Ttc2Maz3AL+mjAvPjxGNhR3V+IElPgrAMvrDwZH+H4tu8encng dOjcR0NlPBU9Si09U4F1hrJ7SX7G+zMUdEmvUUZhSZRIPgSoOsg+NYhjBV3JCVF3lc V5qRlvVk6BLunXQjIKOCSqOd5Ti+dvJKoVV3xQGM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 24 Mar 2020 01:17:10 +0200 Message-Id: <20200323231710.10935-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200323173559.21109-1-laurent.pinchart@ideasonboard.com> References: MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2.1 21/21] qcam: viewfinder: Add support for more native formats 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: , X-List-Received-Date: Mon, 23 Mar 2020 23:17:15 -0000 Qt supports more 24-bit and 32-bit RGB formats for native painting. If the frame buffer pixel format matches any of them, disable the converter and create a QImage in the appropriate format. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- Changes since v2: - Add more formats Changes since v1: - Rename formats to nativeFormats --- src/qcam/viewfinder.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/qcam/viewfinder.cpp b/src/qcam/viewfinder.cpp index 45e226b58135..e7e023eff98d 100644 --- a/src/qcam/viewfinder.cpp +++ b/src/qcam/viewfinder.cpp @@ -7,16 +7,33 @@ #include "viewfinder.h" +#include #include #include #include +#include #include #include #include #include "format_converter.h" +static const QMap nativeFormats{ +#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)) +#if (QBYTE_ORDER == Q_LITTLE_ENDIAN) + { DRM_FORMAT_ABGR8888, QImage::Format_RGBA8888 }, +#else + { DRM_FORMAT_RGBA8888, QImage::Format_RGBA8888 }, +#endif +#endif + { DRM_FORMAT_ARGB8888, QImage::Format_RGB32 }, +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + { DRM_FORMAT_BGR888, QImage::Format_BGR888 }, +#endif + { DRM_FORMAT_RGB888, QImage::Format_RGB888 }, +}; + ViewFinder::ViewFinder(QWidget *parent) : QWidget(parent), buffer_(nullptr) { @@ -36,7 +53,7 @@ int ViewFinder::setFormat(const libcamera::PixelFormat &format, * If format conversion is needed, configure the converter and allocate * the destination image. */ - if (format != DRM_FORMAT_ARGB8888) { + if (!nativeFormats.contains(format)) { int ret = converter_.configure(format, size); if (ret < 0) return ret; @@ -64,7 +81,7 @@ void ViewFinder::render(libcamera::FrameBuffer *buffer, MappedBuffer *map) { QMutexLocker locker(&mutex_); - if (format_ == DRM_FORMAT_ARGB8888) { + if (nativeFormats.contains(format_)) { /* * If the frame format is identical to the display * format, create a QImage that references the frame @@ -76,7 +93,8 @@ void ViewFinder::render(libcamera::FrameBuffer *buffer, MappedBuffer *map) * computing it naively */ image_ = QImage(memory, size_.width(), size_.height(), - size / size_.height(), QImage::Format_RGB32); + size / size_.height(), + nativeFormats[format_]); std::swap(buffer, buffer_); } else { /*