qcam: Use QSize through the code base

Qt has a QSize class to store sizes. Use it to replace width and height
where applicable.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Laurent Pinchart 2020-03-22 12:53:13 +02:00
parent ac02d741dc
commit acd02afab0
5 changed files with 19 additions and 20 deletions

View file

@ -26,7 +26,7 @@
#endif #endif
int FormatConverter::configure(const libcamera::PixelFormat &format, int FormatConverter::configure(const libcamera::PixelFormat &format,
unsigned int width, unsigned int height) const QSize &size)
{ {
switch (format) { switch (format) {
case DRM_FORMAT_NV12: case DRM_FORMAT_NV12:
@ -139,8 +139,8 @@ int FormatConverter::configure(const libcamera::PixelFormat &format,
}; };
format_ = format; format_ = format;
width_ = width; width_ = size.width();
height_ = height; height_ = size.height();
return 0; return 0;
} }

View file

@ -9,6 +9,8 @@
#include <stddef.h> #include <stddef.h>
#include <QSize>
#include <libcamera/pixelformats.h> #include <libcamera/pixelformats.h>
class QImage; class QImage;
@ -16,8 +18,7 @@ class QImage;
class FormatConverter class FormatConverter
{ {
public: public:
int configure(const libcamera::PixelFormat &format, unsigned int width, int configure(const libcamera::PixelFormat &format, const QSize &size);
unsigned int height);
void convert(const unsigned char *src, size_t size, QImage *dst); void convert(const unsigned char *src, size_t size, QImage *dst);

View file

@ -232,8 +232,8 @@ int MainWindow::startCapture()
} }
Stream *stream = cfg.stream(); Stream *stream = cfg.stream();
ret = viewfinder_->setFormat(cfg.pixelFormat, cfg.size.width, ret = viewfinder_->setFormat(cfg.pixelFormat,
cfg.size.height); QSize(cfg.size.width, cfg.size.height));
if (ret < 0) { if (ret < 0) {
std::cout << "Failed to set viewfinder format" << std::endl; std::cout << "Failed to set viewfinder format" << std::endl;
return ret; return ret;

View file

@ -15,7 +15,7 @@
#include "format_converter.h" #include "format_converter.h"
ViewFinder::ViewFinder(QWidget *parent) ViewFinder::ViewFinder(QWidget *parent)
: QWidget(parent), format_(0), width_(0), height_(0), image_(nullptr) : QWidget(parent), format_(0), image_(nullptr)
{ {
} }
@ -46,20 +46,19 @@ QImage ViewFinder::getCurrentImage()
} }
int ViewFinder::setFormat(const libcamera::PixelFormat &format, int ViewFinder::setFormat(const libcamera::PixelFormat &format,
unsigned int width, unsigned int height) const QSize &size)
{ {
int ret; int ret;
ret = converter_.configure(format, width, height); ret = converter_.configure(format, size);
if (ret < 0) if (ret < 0)
return ret; return ret;
format_ = format; format_ = format;
width_ = width; size_ = size;
height_ = height;
delete image_; delete image_;
image_ = new QImage(width, height, QImage::Format_RGB32); image_ = new QImage(size_, QImage::Format_RGB32);
updateGeometry(); updateGeometry();
return 0; return 0;
@ -73,5 +72,5 @@ void ViewFinder::paintEvent(QPaintEvent *)
QSize ViewFinder::sizeHint() const QSize ViewFinder::sizeHint() const
{ {
return image_ ? image_->size() : QSize(640, 480); return size_.isValid() ? size_ : QSize(640, 480);
} }

View file

@ -8,6 +8,7 @@
#define __QCAM_VIEWFINDER_H__ #define __QCAM_VIEWFINDER_H__
#include <QMutex> #include <QMutex>
#include <QSize>
#include <QWidget> #include <QWidget>
#include <libcamera/pixelformats.h> #include <libcamera/pixelformats.h>
@ -22,8 +23,7 @@ public:
ViewFinder(QWidget *parent); ViewFinder(QWidget *parent);
~ViewFinder(); ~ViewFinder();
int setFormat(const libcamera::PixelFormat &format, unsigned int width, int setFormat(const libcamera::PixelFormat &format, const QSize &size);
unsigned int height);
void display(const unsigned char *rgb, size_t size); void display(const unsigned char *rgb, size_t size);
QImage getCurrentImage(); QImage getCurrentImage();
@ -33,12 +33,11 @@ protected:
QSize sizeHint() const override; QSize sizeHint() const override;
private: private:
libcamera::PixelFormat format_;
unsigned int width_;
unsigned int height_;
FormatConverter converter_; FormatConverter converter_;
libcamera::PixelFormat format_;
QSize size_;
QImage *image_; QImage *image_;
QMutex mutex_; /* Prevent concurrent access to image_ */ QMutex mutex_; /* Prevent concurrent access to image_ */
}; };