mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-16 08:55:06 +03:00
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>
This commit is contained in:
parent
615f7438ad
commit
c6cbe507c1
2 changed files with 7 additions and 8 deletions
|
@ -16,13 +16,12 @@
|
||||||
#include "format_converter.h"
|
#include "format_converter.h"
|
||||||
|
|
||||||
ViewFinder::ViewFinder(QWidget *parent)
|
ViewFinder::ViewFinder(QWidget *parent)
|
||||||
: QWidget(parent), format_(0), image_(nullptr)
|
: QWidget(parent), format_(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewFinder::~ViewFinder()
|
ViewFinder::~ViewFinder()
|
||||||
{
|
{
|
||||||
delete image_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewFinder::render(libcamera::FrameBuffer *buffer, MappedBuffer *map)
|
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),
|
converter_.convert(static_cast<unsigned char *>(map->memory),
|
||||||
buffer->metadata().planes[0].bytesused, image_);
|
buffer->metadata().planes[0].bytesused, &image_);
|
||||||
update();
|
update();
|
||||||
|
|
||||||
renderComplete(buffer);
|
renderComplete(buffer);
|
||||||
|
@ -51,7 +50,7 @@ QImage ViewFinder::getCurrentImage()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mutex_);
|
QMutexLocker locker(&mutex_);
|
||||||
|
|
||||||
return image_->copy();
|
return image_.copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ViewFinder::setFormat(const libcamera::PixelFormat &format,
|
int ViewFinder::setFormat(const libcamera::PixelFormat &format,
|
||||||
|
@ -66,8 +65,7 @@ int ViewFinder::setFormat(const libcamera::PixelFormat &format,
|
||||||
format_ = format;
|
format_ = format;
|
||||||
size_ = size;
|
size_ = size;
|
||||||
|
|
||||||
delete image_;
|
image_ = QImage(size_, QImage::Format_RGB32);
|
||||||
image_ = new QImage(size_, QImage::Format_RGB32);
|
|
||||||
|
|
||||||
updateGeometry();
|
updateGeometry();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -76,7 +74,7 @@ int ViewFinder::setFormat(const libcamera::PixelFormat &format,
|
||||||
void ViewFinder::paintEvent(QPaintEvent *)
|
void ViewFinder::paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.drawImage(rect(), *image_, image_->rect());
|
painter.drawImage(rect(), image_, image_.rect());
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize ViewFinder::sizeHint() const
|
QSize ViewFinder::sizeHint() const
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include <QImage>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
@ -51,7 +52,7 @@ private:
|
||||||
libcamera::PixelFormat format_;
|
libcamera::PixelFormat format_;
|
||||||
QSize size_;
|
QSize size_;
|
||||||
|
|
||||||
QImage *image_;
|
QImage image_;
|
||||||
QMutex mutex_; /* Prevent concurrent access to image_ */
|
QMutex mutex_; /* Prevent concurrent access to image_ */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue