{"id":2655,"url":"https://patchwork.libcamera.org/api/1.1/patches/2655/?format=json","web_url":"https://patchwork.libcamera.org/patch/2655/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200117005420.18210-1-laurent.pinchart@ideasonboard.com>","date":"2020-01-17T00:54:20","name":"[libcamera-devel] qcam: Support scaling of the viewfinder","commit_ref":"9977fc3fcbfa0a6aaab04118fc67f0b9b9627570","pull_url":null,"state":"accepted","archived":false,"hash":"3034a2c90faa26974117feacc13144964489823a","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/2655/mbox/","series":[{"id":631,"url":"https://patchwork.libcamera.org/api/1.1/series/631/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=631","date":"2020-01-17T00:54:20","name":"[libcamera-devel] qcam: Support scaling of the viewfinder","version":1,"mbox":"https://patchwork.libcamera.org/series/631/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2655/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2655/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["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 9F7E86075C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 17 Jan 2020 01:54:38 +0100 (CET)","from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 23D6A9DA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 17 Jan 2020 01:54:38 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1579222478;\n\tbh=XXy1QdxQmvzRaCi5GdCGYGriofS1D+o7NCilHiJ9fG0=;\n\th=From:To:Subject:Date:From;\n\tb=k/V45s2oGj59wzKpungWaNVUNI5UQ1wjev8P34aouoO5EghlK0JhDcLOsUaydT61t\n\te1O5WlgAKZjvvxtWGSulYCEK2ZiPSazST5UTpG1F+iGZujWfBODOFR5QixXpfIUHj9\n\tPDfZQ55U0xZ3DzLuxgmv5rVDsyDrnvSjYPPvbHUk=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 17 Jan 2020 02:54:20 +0200","Message-Id":"<20200117005420.18210-1-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.24.1","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH] qcam: Support scaling of the viewfinder","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>","X-List-Received-Date":"Fri, 17 Jan 2020 00:54:38 -0000"},"content":"The viewfinder is drawn using a QLabel. This could support scaling\nthrough QLabel::setScaledContents(), but in a very inefficient way. To\nmaintain reasonable efficiency, turn the viewfinder into a QWidget and\ndraw the image directly using a QPainter.\n\nNo performance change was noticed running on a fast x86 machine, and\nperformance was 60% higher when scaling up to full screen compared to\nQLabel.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/qcam/main_window.cpp |  1 -\n src/qcam/viewfinder.cpp  | 22 +++++++++++++++-------\n src/qcam/viewfinder.h    |  8 ++++++--\n 3 files changed, 21 insertions(+), 10 deletions(-)","diff":"diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\nindex 1d9c756f147a..df51fa888342 100644\n--- a/src/qcam/main_window.cpp\n+++ b/src/qcam/main_window.cpp\n@@ -33,7 +33,6 @@ MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options)\n \n \tviewfinder_ = new ViewFinder(this);\n \tsetCentralWidget(viewfinder_);\n-\tviewfinder_->setFixedSize(500, 500);\n \tadjustSize();\n \n \tret = openCamera(cm);\ndiff --git a/src/qcam/viewfinder.cpp b/src/qcam/viewfinder.cpp\nindex 98a8ab68e5f6..6de284d1b782 100644\n--- a/src/qcam/viewfinder.cpp\n+++ b/src/qcam/viewfinder.cpp\n@@ -6,13 +6,13 @@\n  */\n \n #include <QImage>\n-#include <QPixmap>\n+#include <QPainter>\n \n #include \"format_converter.h\"\n #include \"viewfinder.h\"\n \n ViewFinder::ViewFinder(QWidget *parent)\n-\t: QLabel(parent), format_(0), width_(0), height_(0), image_(nullptr)\n+\t: QWidget(parent), format_(0), width_(0), height_(0), image_(nullptr)\n {\n }\n \n@@ -24,9 +24,7 @@ ViewFinder::~ViewFinder()\n void ViewFinder::display(const unsigned char *raw, size_t size)\n {\n \tconverter_.convert(raw, size, image_);\n-\n-\tQPixmap pixmap = QPixmap::fromImage(*image_);\n-\tsetPixmap(pixmap);\n+\tupdate();\n }\n \n int ViewFinder::setFormat(unsigned int format, unsigned int width,\n@@ -42,10 +40,20 @@ int ViewFinder::setFormat(unsigned int format, unsigned int width,\n \twidth_ = width;\n \theight_ = height;\n \n-\tsetFixedSize(width, height);\n-\n \tdelete image_;\n \timage_ = new QImage(width, height, QImage::Format_RGB32);\n \n+\tupdateGeometry();\n \treturn 0;\n }\n+\n+void ViewFinder::paintEvent(QPaintEvent *)\n+{\n+\tQPainter painter(this);\n+\tpainter.drawImage(rect(), *image_, image_->rect());\n+}\n+\n+QSize ViewFinder::sizeHint() const\n+{\n+\treturn image_ ? image_->size() : QSize(640, 480);\n+}\ndiff --git a/src/qcam/viewfinder.h b/src/qcam/viewfinder.h\nindex 33bdb1460f84..ef5fd45b264a 100644\n--- a/src/qcam/viewfinder.h\n+++ b/src/qcam/viewfinder.h\n@@ -7,13 +7,13 @@\n #ifndef __QCAM_VIEWFINDER_H__\n #define __QCAM_VIEWFINDER_H__\n \n-#include <QLabel>\n+#include <QWidget>\n \n #include \"format_converter.h\"\n \n class QImage;\n \n-class ViewFinder : public QLabel\n+class ViewFinder : public QWidget\n {\n public:\n \tViewFinder(QWidget *parent);\n@@ -23,6 +23,10 @@ public:\n \t\t      unsigned int height);\n \tvoid display(const unsigned char *rgb, size_t size);\n \n+protected:\n+\tvoid paintEvent(QPaintEvent *) override;\n+\tQSize sizeHint() const override;\n+\n private:\n \tunsigned int format_;\n \tunsigned int width_;\n","prefixes":["libcamera-devel"]}