diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2021-09-06 01:43:36 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2021-09-07 19:18:54 +0300 |
commit | a339d055cc7ebd92b89adadd3044f69f8f9653b8 (patch) | |
tree | 82015eaf6aa67ac9d4e542a1ee7bc91af4b6f609 | |
parent | c20ad98c2a96d31847b0ef4b500e1e7a221b67c0 (diff) |
qcam: viewfinder_qt: Support multi-planar buffers
Now that the ViewFinderQt receives an Image, move the Converter API to
take an Image as well, and enable multi-planar buffer support.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
-rw-r--r-- | src/qcam/format_converter.cpp | 18 | ||||
-rw-r--r-- | src/qcam/format_converter.h | 9 | ||||
-rw-r--r-- | src/qcam/viewfinder_qt.cpp | 14 |
3 files changed, 21 insertions, 20 deletions
diff --git a/src/qcam/format_converter.cpp b/src/qcam/format_converter.cpp index 973966f6..673ad33e 100644 --- a/src/qcam/format_converter.cpp +++ b/src/qcam/format_converter.cpp @@ -13,6 +13,8 @@ #include <libcamera/formats.h> +#include "../cam/image.h" + #define RGBSHIFT 8 #ifndef MAX #define MAX(a,b) ((a)>(b)?(a):(b)) @@ -154,12 +156,11 @@ int FormatConverter::configure(const libcamera::PixelFormat &format, return 0; } -void FormatConverter::convert(const unsigned char *src, size_t size, - QImage *dst) +void FormatConverter::convert(const Image *src, size_t size, QImage *dst) { switch (formatFamily_) { case MJPEG: - dst->loadFromData(src, size, "JPEG"); + dst->loadFromData(src->data(0).data(), size, "JPEG"); break; case YUV: convertYUV(src, dst->bits()); @@ -183,13 +184,14 @@ static void yuv_to_rgb(int y, int u, int v, int *r, int *g, int *b) *b = CLIP(( 298 * c + 516 * d + 128) >> RGBSHIFT); } -void FormatConverter::convertNV(const unsigned char *src, unsigned char *dst) +void FormatConverter::convertNV(const Image *srcImage, unsigned char *dst) { unsigned int c_stride = width_ * (2 / horzSubSample_); unsigned int c_inc = horzSubSample_ == 1 ? 2 : 0; unsigned int cb_pos = nvSwap_ ? 1 : 0; unsigned int cr_pos = nvSwap_ ? 0 : 1; - const unsigned char *src_c = src + width_ * height_; + const unsigned char *src = srcImage->data(0).data(); + const unsigned char *src_c = srcImage->data(1).data(); int r, g, b; for (unsigned int y = 0; y < height_; y++) { @@ -223,8 +225,9 @@ void FormatConverter::convertNV(const unsigned char *src, unsigned char *dst) } } -void FormatConverter::convertRGB(const unsigned char *src, unsigned char *dst) +void FormatConverter::convertRGB(const Image *srcImage, unsigned char *dst) { + const unsigned char *src = srcImage->data(0).data(); unsigned int x, y; int r, g, b; @@ -245,8 +248,9 @@ void FormatConverter::convertRGB(const unsigned char *src, unsigned char *dst) } } -void FormatConverter::convertYUV(const unsigned char *src, unsigned char *dst) +void FormatConverter::convertYUV(const Image *srcImage, unsigned char *dst) { + const unsigned char *src = srcImage->data(0).data(); unsigned int src_x, src_y, dst_x, dst_y; unsigned int src_stride; unsigned int dst_stride; diff --git a/src/qcam/format_converter.h b/src/qcam/format_converter.h index e389b24a..2220a62b 100644 --- a/src/qcam/format_converter.h +++ b/src/qcam/format_converter.h @@ -13,6 +13,7 @@ #include <libcamera/pixel_format.h> +class Image; class QImage; class FormatConverter @@ -20,7 +21,7 @@ class FormatConverter public: int configure(const libcamera::PixelFormat &format, const QSize &size); - void convert(const unsigned char *src, size_t size, QImage *dst); + void convert(const Image *src, size_t size, QImage *dst); private: enum FormatFamily { @@ -30,9 +31,9 @@ private: YUV, }; - void convertNV(const unsigned char *src, unsigned char *dst); - void convertRGB(const unsigned char *src, unsigned char *dst); - void convertYUV(const unsigned char *src, unsigned char *dst); + void convertNV(const Image *src, unsigned char *dst); + void convertRGB(const Image *src, unsigned char *dst); + void convertYUV(const Image *src, unsigned char *dst); libcamera::PixelFormat format_; unsigned int width_; diff --git a/src/qcam/viewfinder_qt.cpp b/src/qcam/viewfinder_qt.cpp index fef6d53e..0d357d86 100644 --- a/src/qcam/viewfinder_qt.cpp +++ b/src/qcam/viewfinder_qt.cpp @@ -7,6 +7,7 @@ #include "viewfinder_qt.h" +#include <assert.h> #include <stdint.h> #include <utility> @@ -81,12 +82,6 @@ int ViewFinderQt::setFormat(const libcamera::PixelFormat &format, void ViewFinderQt::render(libcamera::FrameBuffer *buffer, Image *image) { - if (buffer->planes().size() != 1) { - qWarning() << "Multi-planar buffers are not supported"; - return; - } - - unsigned char *memory = image->data(0).data(); size_t size = buffer->metadata().planes()[0].bytesused; { @@ -103,8 +98,9 @@ void ViewFinderQt::render(libcamera::FrameBuffer *buffer, Image *image) * \todo Get the stride from the buffer instead of * computing it naively */ - image_ = QImage(memory, size_.width(), size_.height(), - size / size_.height(), + assert(buffer->planes().size() == 1); + image_ = QImage(image->data(0).data(), size_.width(), + size_.height(), size / size_.height(), ::nativeFormats[format_]); std::swap(buffer, buffer_); } else { @@ -112,7 +108,7 @@ void ViewFinderQt::render(libcamera::FrameBuffer *buffer, Image *image) * Otherwise, convert the format and release the frame * buffer immediately. */ - converter_.convert(memory, size, &image_); + converter_.convert(image, size, &image_); } } |