From patchwork Thu Sep 5 16:25:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 21165 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 C5057BF415 for ; Thu, 5 Sep 2024 16:25:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 00C2C634E9; Thu, 5 Sep 2024 18:25:13 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="FjlT33Kz"; 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 66073634CB for ; Thu, 5 Sep 2024 18:25:12 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id ECC7D3E6 for ; Thu, 5 Sep 2024 18:23:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1725553439; bh=CUvxoFWmsE7KuM4Eq+QJKQtXe10D6VN2V5WKyJLRloA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=FjlT33KzrypGFAgi3/LuZq/WUS7DcUF+/BFrbQ//ne4hUHa56y8ZjvUablmADRcnM JIRAfUzZChjL8Wxr0YBfI592nSoDYkfTLOrtT5B4XHRPM6a92KzzyV9OM/N0lkxYYh EFA82pJ/BdGsXM3/pGyyzBCZtxtAB4NQ9Ntts430= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 1/2] qcam: viewfinder_qt: Draw the letterbox background black Date: Thu, 5 Sep 2024 19:25:07 +0300 Message-ID: <20240905162508.4169-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240905162508.4169-1-laurent.pinchart@ideasonboard.com> References: <20240905162508.4169-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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" When the widget's aspect ratio doesn't match the camera aspect ratio, the viewfinder is rendered letter-boxed. The side rectangles are not painted by the viewfinder, and Qt thus renders the parent widget background to fill that space. To make it black, we have two options: - The simplest option is to set the widget's autoFillBackground property to true. This causes Qt to paint the whole widget with its background colour before calling paintEvent(). As the camera image typically covers most (if not all) of the viewfinder widget, this is less efficient. - The more complicated option is to pain the letterbox rectangles manually. We can additionally set the widget's WA_OpaquePaintEvent attribute to instruct Qt to skip painting the parent widget. This reduces CPU usage by about 1% (and may reduce GPU usage as well). Note that the WA_OpaquePaintEvent attribute has to be disabled when we render the stopped icon, as the icon has a transparent background. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/apps/qcam/viewfinder_qt.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/apps/qcam/viewfinder_qt.cpp b/src/apps/qcam/viewfinder_qt.cpp index 492648cfa2ff..62b6f27fa23e 100644 --- a/src/apps/qcam/viewfinder_qt.cpp +++ b/src/apps/qcam/viewfinder_qt.cpp @@ -44,6 +44,10 @@ ViewFinderQt::ViewFinderQt(QWidget *parent) : QWidget(parent), place_(rect()), buffer_(nullptr) { icon_ = QIcon(":camera-off.svg"); + + QPalette pal = palette(); + pal.setColor(QPalette::Window, Qt::black); + setPalette(pal); } ViewFinderQt::~ViewFinderQt() @@ -118,6 +122,7 @@ void ViewFinderQt::render(libcamera::FrameBuffer *buffer, Image *image) } } + setAttribute(Qt::WA_OpaquePaintEvent, true); update(); if (buffer) @@ -133,6 +138,7 @@ void ViewFinderQt::stop() buffer_ = nullptr; } + setAttribute(Qt::WA_OpaquePaintEvent, false); update(); } @@ -147,8 +153,22 @@ void ViewFinderQt::paintEvent(QPaintEvent *) { QPainter painter(this); - /* If we have an image, draw it. */ + painter.setBrush(palette().window()); + + /* If we have an image, draw it, with black letterbox rectangles. */ if (!image_.isNull()) { + if (place_.width() < width()) { + QRect rect{ 0, 0, (width() - place_.width()) / 2, height() }; + painter.drawRect(rect); + rect.moveLeft(place_.right()); + painter.drawRect(rect); + } else { + QRect rect{ 0, 0, width(), (height() - place_.height()) / 2 }; + painter.drawRect(rect); + rect.moveTop(place_.bottom()); + painter.drawRect(rect); + } + painter.drawImage(place_, image_, image_.rect()); return; } @@ -174,7 +194,6 @@ void ViewFinderQt::paintEvent(QPaintEvent *) else point.setY((height() - pixmap_.height()) / 2); - painter.setBackgroundMode(Qt::OpaqueMode); painter.drawPixmap(point, pixmap_); } From patchwork Thu Sep 5 16:25:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 21166 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 88403BF415 for ; Thu, 5 Sep 2024 16:25:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1DBD1634EC; Thu, 5 Sep 2024 18:25:18 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="RDivcgmZ"; 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 CAF24634E3 for ; Thu, 5 Sep 2024 18:25:13 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 47DAE3E6 for ; Thu, 5 Sep 2024 18:24:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1725553440; bh=VeyMbtIOBmVq2alwV85YSVU9tXQDafkh1F25AlrJ7VU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RDivcgmZz/gsq1xivBZwSF+lHGmdLUC8J+CGxYf58FWsTRxPt0FpblooA2amkNUmA OjxGkg+KacEaU+OqZohaL/38b0LCKaR4AW5+WQkuqNiHmGVO3IQvS14DVAvnzu3291 OnZ0CpALligmBf9qsa8gKVqqVw9o6efqlH0za61Q= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 2/2] qcam: viewfinder_qt: Render stopped icon on a black background Date: Thu, 5 Sep 2024 19:25:08 +0300 Message-ID: <20240905162508.4169-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240905162508.4169-1-laurent.pinchart@ideasonboard.com> References: <20240905162508.4169-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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" To match the black letterboxes, render the stoppid icon on a black background. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/apps/qcam/assets/feathericons/camera-off.svg | 2 +- src/apps/qcam/viewfinder_qt.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/apps/qcam/assets/feathericons/camera-off.svg b/src/apps/qcam/assets/feathericons/camera-off.svg index daa3e25f0c1d..2d36b59c8b52 100644 --- a/src/apps/qcam/assets/feathericons/camera-off.svg +++ b/src/apps/qcam/assets/feathericons/camera-off.svg @@ -1 +1 @@ - \ No newline at end of file + diff --git a/src/apps/qcam/viewfinder_qt.cpp b/src/apps/qcam/viewfinder_qt.cpp index 62b6f27fa23e..b0d63f3fa5ea 100644 --- a/src/apps/qcam/viewfinder_qt.cpp +++ b/src/apps/qcam/viewfinder_qt.cpp @@ -48,6 +48,8 @@ ViewFinderQt::ViewFinderQt(QWidget *parent) QPalette pal = palette(); pal.setColor(QPalette::Window, Qt::black); setPalette(pal); + + setAttribute(Qt::WA_OpaquePaintEvent, true); } ViewFinderQt::~ViewFinderQt() @@ -122,7 +124,6 @@ void ViewFinderQt::render(libcamera::FrameBuffer *buffer, Image *image) } } - setAttribute(Qt::WA_OpaquePaintEvent, true); update(); if (buffer) @@ -138,7 +139,6 @@ void ViewFinderQt::stop() buffer_ = nullptr; } - setAttribute(Qt::WA_OpaquePaintEvent, false); update(); } @@ -194,6 +194,7 @@ void ViewFinderQt::paintEvent(QPaintEvent *) else point.setY((height() - pixmap_.height()) / 2); + painter.drawRect(rect()); painter.drawPixmap(point, pixmap_); }