Show a patch.

GET /api/1.1/patches/21165/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 21165,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/21165/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/21165/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20240905162508.4169-2-laurent.pinchart@ideasonboard.com>",
    "date": "2024-09-05T16:25:07",
    "name": "[1/2] qcam: viewfinder_qt: Draw the letterbox background black",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "083889492ec8dba4190cbaa851281a1a0f1af1bd",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/21165/mbox/",
    "series": [
        {
            "id": 4563,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4563/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4563",
            "date": "2024-09-05T16:25:06",
            "name": "qcam: Use black background",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4563/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/21165/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/21165/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id C5057BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  5 Sep 2024 16:25:16 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 00C2C634E9;\n\tThu,  5 Sep 2024 18:25:13 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 66073634CB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  5 Sep 2024 18:25:12 +0200 (CEST)",
            "from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id ECC7D3E6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  5 Sep 2024 18:23:58 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"FjlT33Kz\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1725553439;\n\tbh=CUvxoFWmsE7KuM4Eq+QJKQtXe10D6VN2V5WKyJLRloA=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=FjlT33KzrypGFAgi3/LuZq/WUS7DcUF+/BFrbQ//ne4hUHa56y8ZjvUablmADRcnM\n\tJIRAfUzZChjL8Wxr0YBfI592nSoDYkfTLOrtT5B4XHRPM6a92KzzyV9OM/N0lkxYYh\n\tEFA82pJ/BdGsXM3/pGyyzBCZtxtAB4NQ9Ntts430=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "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",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "<libcamera-devel.lists.libcamera.org>",
        "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>",
        "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>",
        "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>",
        "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "When the widget's aspect ratio doesn't match the camera aspect ratio,\nthe viewfinder is rendered letter-boxed. The side rectangles are not\npainted by the viewfinder, and Qt thus renders the parent widget\nbackground to fill that space.\n\nTo make it black, we have two options:\n\n- The simplest option is to set the widget's autoFillBackground property\n  to true. This causes Qt to paint the whole widget with its background\n  colour before calling paintEvent(). As the camera image typically\n  covers most (if not all) of the viewfinder widget, this is less\n  efficient.\n\n- The more complicated option is to pain the letterbox rectangles\n  manually. We can additionally set the widget's WA_OpaquePaintEvent\n  attribute to instruct Qt to skip painting the parent widget. This\n  reduces CPU usage by about 1% (and may reduce GPU usage as well).\n\nNote that the WA_OpaquePaintEvent attribute has to be disabled when we\nrender the stopped icon, as the icon has a transparent background.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/apps/qcam/viewfinder_qt.cpp | 23 +++++++++++++++++++++--\n 1 file changed, 21 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/src/apps/qcam/viewfinder_qt.cpp b/src/apps/qcam/viewfinder_qt.cpp\nindex 492648cfa2ff..62b6f27fa23e 100644\n--- a/src/apps/qcam/viewfinder_qt.cpp\n+++ b/src/apps/qcam/viewfinder_qt.cpp\n@@ -44,6 +44,10 @@ ViewFinderQt::ViewFinderQt(QWidget *parent)\n \t: QWidget(parent), place_(rect()), buffer_(nullptr)\n {\n \ticon_ = QIcon(\":camera-off.svg\");\n+\n+\tQPalette pal = palette();\n+\tpal.setColor(QPalette::Window, Qt::black);\n+\tsetPalette(pal);\n }\n \n ViewFinderQt::~ViewFinderQt()\n@@ -118,6 +122,7 @@ void ViewFinderQt::render(libcamera::FrameBuffer *buffer, Image *image)\n \t\t}\n \t}\n \n+\tsetAttribute(Qt::WA_OpaquePaintEvent, true);\n \tupdate();\n \n \tif (buffer)\n@@ -133,6 +138,7 @@ void ViewFinderQt::stop()\n \t\tbuffer_ = nullptr;\n \t}\n \n+\tsetAttribute(Qt::WA_OpaquePaintEvent, false);\n \tupdate();\n }\n \n@@ -147,8 +153,22 @@ void ViewFinderQt::paintEvent(QPaintEvent *)\n {\n \tQPainter painter(this);\n \n-\t/* If we have an image, draw it. */\n+\tpainter.setBrush(palette().window());\n+\n+\t/* If we have an image, draw it, with black letterbox rectangles. */\n \tif (!image_.isNull()) {\n+\t\tif (place_.width() < width()) {\n+\t\t\tQRect rect{ 0, 0, (width() - place_.width()) / 2, height() };\n+\t\t\tpainter.drawRect(rect);\n+\t\t\trect.moveLeft(place_.right());\n+\t\t\tpainter.drawRect(rect);\n+\t\t} else {\n+\t\t\tQRect rect{ 0, 0, width(), (height() - place_.height()) / 2 };\n+\t\t\tpainter.drawRect(rect);\n+\t\t\trect.moveTop(place_.bottom());\n+\t\t\tpainter.drawRect(rect);\n+\t\t}\n+\n \t\tpainter.drawImage(place_, image_, image_.rect());\n \t\treturn;\n \t}\n@@ -174,7 +194,6 @@ void ViewFinderQt::paintEvent(QPaintEvent *)\n \telse\n \t\tpoint.setY((height() - pixmap_.height()) / 2);\n \n-\tpainter.setBackgroundMode(Qt::OpaqueMode);\n \tpainter.drawPixmap(point, pixmap_);\n }\n \n",
    "prefixes": [
        "1/2"
    ]
}