summaryrefslogtreecommitdiff
path: root/src/qcam/viewfinder.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-03-23 02:34:36 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-03-24 10:34:05 +0200
commitc6cbe507c1b741c145df015fe8fa73faa35c6c1a (patch)
tree815c900b238c6be544edf22a65b22eafdba6ca36 /src/qcam/viewfinder.cpp
parent615f7438ad6bf49bd213e7ae4f9f3fe334edeb67 (diff)
qcam: viewfinder: Embed QImage in ViewFinder
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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/qcam/viewfinder.cpp')
-rw-r--r--src/qcam/viewfinder.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/qcam/viewfinder.cpp b/src/qcam/viewfinder.cpp
index 2a35932e..e7b12015 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<unsigned char *>(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