diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-03-23 03:50:53 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-03-24 11:10:52 +0200 |
commit | f890a57b7a06c0fab3bea593e4c0040bc5fcfd42 (patch) | |
tree | 49c6d99b3f8a9b55fa195019ce3b5c9e3e06b674 /src/qcam/viewfinder.cpp | |
parent | cb6395599e843241710f1d7224ce94fd28fbae80 (diff) |
qcam: viewfinder: Add support for more native formats
Qt supports more 24-bit and 32-bit RGB formats for native painting. If
the frame buffer pixel format matches any of them, disable the converter
and create a QImage in the appropriate format.
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.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/qcam/viewfinder.cpp b/src/qcam/viewfinder.cpp index 45e226b5..c7c6d099 100644 --- a/src/qcam/viewfinder.cpp +++ b/src/qcam/viewfinder.cpp @@ -7,16 +7,30 @@ #include "viewfinder.h" +#include <stdint.h> #include <utility> #include <QImage> #include <QImageWriter> +#include <QMap> #include <QMutexLocker> #include <QPainter> #include <QtDebug> #include "format_converter.h" +static const QMap<uint32_t, QImage::Format> nativeFormats +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) + { DRM_FORMAT_ABGR8888, QImage::Format_RGBA8888 }, +#endif + { DRM_FORMAT_ARGB8888, QImage::Format_RGB32 }, +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + { DRM_FORMAT_BGR888, QImage::Format_BGR888 }, +#endif + { DRM_FORMAT_RGB888, QImage::Format_RGB888 }, +}; + ViewFinder::ViewFinder(QWidget *parent) : QWidget(parent), buffer_(nullptr) { @@ -36,7 +50,7 @@ int ViewFinder::setFormat(const libcamera::PixelFormat &format, * If format conversion is needed, configure the converter and allocate * the destination image. */ - if (format != DRM_FORMAT_ARGB8888) { + if (!nativeFormats.contains(format)) { int ret = converter_.configure(format, size); if (ret < 0) return ret; @@ -64,7 +78,7 @@ void ViewFinder::render(libcamera::FrameBuffer *buffer, MappedBuffer *map) { QMutexLocker locker(&mutex_); - if (format_ == DRM_FORMAT_ARGB8888) { + if (nativeFormats.contains(format_)) { /* * If the frame format is identical to the display * format, create a QImage that references the frame @@ -76,7 +90,8 @@ void ViewFinder::render(libcamera::FrameBuffer *buffer, MappedBuffer *map) * computing it naively */ image_ = QImage(memory, size_.width(), size_.height(), - size / size_.height(), QImage::Format_RGB32); + size / size_.height(), + nativeFormats[format_]); std::swap(buffer, buffer_); } else { /* |