[{"id":15959,"web_url":"https://patchwork.libcamera.org/comment/15959/","msgid":"<YF63nf8pQcDOXqcD@pendragon.ideasonboard.com>","date":"2021-03-27T04:42:05","subject":"Re: [libcamera-devel] [PATCH] qcam: viewfinder: Maintain aspect\n\tratio","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch.\n\nOn Fri, Mar 26, 2021 at 10:05:40PM +0000, Kieran Bingham wrote:\n> Keep the image aspect ratio when displaying in the viewfinder.\n> \n> When the window is adjusted to a size that differs in aspect ratio to\n> the image, keep the image centered in the main viewpoint while\n> maintaining the image's aspect ratio.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n> It's been really annoying me that the QCam viewfinder can scale to fit\n> the window, but that it breaks the aspect ratio of the image it\n> contains.\n> \n> I can't imagine why we would want to viewfind with an incorrect aspect\n> ratio, but if we do we can add that as an option later. For now -\n> enforce aspect ratio on the QT viewfinder.\n> \n> Of course I'm aware that this doesn't cover the GL viewfinder. That can\n> either be handled on top, or independently if this is deemed a worthy\n> feature.\n> \n> \n>  src/qcam/viewfinder_qt.cpp | 19 +++++++++++++++++--\n>  src/qcam/viewfinder_qt.h   |  2 ++\n>  2 files changed, 19 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/qcam/viewfinder_qt.cpp b/src/qcam/viewfinder_qt.cpp\n> index e436714c6bdb..f6ca6793b4e4 100644\n> --- a/src/qcam/viewfinder_qt.cpp\n> +++ b/src/qcam/viewfinder_qt.cpp\n> @@ -15,6 +15,7 @@\n>  #include <QMap>\n>  #include <QMutexLocker>\n>  #include <QPainter>\n> +#include <QResizeEvent>\n>  #include <QtDebug>\n>  \n>  #include <libcamera/formats.h>\n> @@ -34,7 +35,7 @@ static const QMap<libcamera::PixelFormat, QImage::Format> nativeFormats\n>  };\n>  \n>  ViewFinderQt::ViewFinderQt(QWidget *parent)\n> -\t: QWidget(parent), buffer_(nullptr)\n> +\t: QWidget(parent), place_(rect()), buffer_(nullptr)\n>  {\n>  \ticon_ = QIcon(\":camera-off.svg\");\n>  }\n> @@ -146,7 +147,7 @@ void ViewFinderQt::paintEvent(QPaintEvent *)\n>  \n>  \t/* If we have an image, draw it. */\n>  \tif (!image_.isNull()) {\n> -\t\tpainter.drawImage(rect(), image_, image_.rect());\n> +\t\tpainter.drawImage(place_, image_, image_.rect());\n>  \t\treturn;\n\nI'm tempted by a black background ;-)\n\n>  \t}\n>  \n> @@ -179,3 +180,17 @@ QSize ViewFinderQt::sizeHint() const\n>  {\n>  \treturn size_.isValid() ? size_ : QSize(640, 480);\n>  }\n> +\n> +void ViewFinderQt::resizeEvent(QResizeEvent *event)\n> +{\n> +\tif (!size_.isValid()) {\n> +\t\tevent->accept();\n\nI don't think there's a need to accept the event.\n\n> +\t\treturn;\n> +\t}\n> +\n> +\tQPoint zero(0, 0);\n> +\tplace_ = QRect(zero, size_.scaled(event->size(), Qt::KeepAspectRatio));\n> +\tplace_.moveCenter(QRect(zero, size()).center());\n\nThis can be simplified:\n\n\tplace_.setSize(size_.scaled(event->size(), Qt::KeepAspectRatio));\n\tplace_.moveCenter(rect().center());\n\n> +\n> +\tevent->accept();\n> +}\n> diff --git a/src/qcam/viewfinder_qt.h b/src/qcam/viewfinder_qt.h\n> index d755428887c0..bf31b81b3437 100644\n> --- a/src/qcam/viewfinder_qt.h\n> +++ b/src/qcam/viewfinder_qt.h\n> @@ -42,6 +42,7 @@ Q_SIGNALS:\n>  \n>  protected:\n>  \tvoid paintEvent(QPaintEvent *) override;\n> +\tvoid resizeEvent(QResizeEvent *) override;\n>  \tQSize sizeHint() const override;\n>  \n>  private:\n> @@ -49,6 +50,7 @@ private:\n>  \n>  \tlibcamera::PixelFormat format_;\n>  \tQSize size_;\n> +\tQRect place_;\n>  \n>  \t/* Camera stopped icon */\n>  \tQSize vfSize_;","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 5642DC32ED\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 27 Mar 2021 04:42:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 94BE268D6C;\n\tSat, 27 Mar 2021 05:42:51 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C4E2C602D4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 27 Mar 2021 05:42:49 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3CD898B7;\n\tSat, 27 Mar 2021 05:42:49 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"RXl9zZfg\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1616820169;\n\tbh=nXiS1MDXs0mOhJJtt5GfW7V86SKlr1jiDol3JBwzrQY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=RXl9zZfgASY2kUuzwKfVRZeK+7/XMMm33+1MnEHpiPUqK/jxeuP2oW6yckzR43vWz\n\t6o+CJhyxrPjk+LK/AU1Gk92PZ0kTea/1/MwnhZBEq+EcRvyPfqQzm30pmnKKFpD4S8\n\t8vUrCrsdc7f5LLLPn+83yPb/D+wqnL4r6LmX4X7c=","Date":"Sat, 27 Mar 2021 06:42:05 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<YF63nf8pQcDOXqcD@pendragon.ideasonboard.com>","References":"<20210326220540.1479330-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210326220540.1479330-1-kieran.bingham@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH] qcam: viewfinder: Maintain aspect\n\tratio","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>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]