From patchwork Mon Mar 23 14:22:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3259 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 E298A62C0E for ; Mon, 23 Mar 2020 15:22:23 +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 79AC5308 for ; Mon, 23 Mar 2020 15:22:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1584973343; bh=SQpup1GvmigzZjuo3rNPDe1Qr86L5ep1mOvu+Nb2uWI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=v1dQ3Bo35QlkI8Iqqks0ZwxcN+tei7vhErzYOlWmx+bb8OG8rBOtkVbXrVOLF2JuX dIouXiej2LgpLoal3iLsk+r/kGSyj+JOsh0W1M7zsQN1zZB7zlp4Lhe2+25xja7aOV FBG94Sa44Duzb5NCB5u2lhTLLfiffDT/iexLduH4= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Mar 2020 16:22:00 +0200 Message-Id: <20200323142205.28342-17-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200323142205.28342-1-laurent.pinchart@ideasonboard.com> References: <20200323142205.28342-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 16/21] qcam: viewfinder: Embed QImage in ViewFinder 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 14:22:28 -0000 The QImage class is a thin wrapper that uses implicit sharing. We can thus embed it in the ViewFinder class instead of allocating it dynamically, and assign it at runtime. This simplifies the code. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/qcam/viewfinder.cpp | 12 +++++------- src/qcam/viewfinder.h | 3 ++- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/qcam/viewfinder.cpp b/src/qcam/viewfinder.cpp index 2a35932e0b79..e7b12015d8f6 100644 --- a/src/qcam/viewfinder.cpp +++ b/src/qcam/viewfinder.cpp @@ -16,13 +16,12 @@ #include "format_converter.h" ViewFinder::ViewFinder(QWidget *parent) - : QWidget(parent), format_(0), image_(nullptr) + : QWidget(parent), format_(0) { } ViewFinder::~ViewFinder() { - delete image_; } void ViewFinder::render(libcamera::FrameBuffer *buffer, MappedBuffer *map) @@ -41,7 +40,7 @@ void ViewFinder::render(libcamera::FrameBuffer *buffer, MappedBuffer *map) */ converter_.convert(static_cast(map->memory), - buffer->metadata().planes[0].bytesused, image_); + buffer->metadata().planes[0].bytesused, &image_); update(); renderComplete(buffer); @@ -51,7 +50,7 @@ QImage ViewFinder::getCurrentImage() { QMutexLocker locker(&mutex_); - return image_->copy(); + return image_.copy(); } int ViewFinder::setFormat(const libcamera::PixelFormat &format, @@ -66,8 +65,7 @@ int ViewFinder::setFormat(const libcamera::PixelFormat &format, format_ = format; size_ = size; - delete image_; - image_ = new QImage(size_, QImage::Format_RGB32); + image_ = QImage(size_, QImage::Format_RGB32); updateGeometry(); return 0; @@ -76,7 +74,7 @@ int ViewFinder::setFormat(const libcamera::PixelFormat &format, void ViewFinder::paintEvent(QPaintEvent *) { QPainter painter(this); - painter.drawImage(rect(), *image_, image_->rect()); + painter.drawImage(rect(), image_, image_.rect()); } QSize ViewFinder::sizeHint() const diff --git a/src/qcam/viewfinder.h b/src/qcam/viewfinder.h index 784fcceda5bd..54c0fa9dd7a0 100644 --- a/src/qcam/viewfinder.h +++ b/src/qcam/viewfinder.h @@ -9,6 +9,7 @@ #include +#include #include #include #include @@ -51,7 +52,7 @@ private: libcamera::PixelFormat format_; QSize size_; - QImage *image_; + QImage image_; QMutex mutex_; /* Prevent concurrent access to image_ */ };