summaryrefslogtreecommitdiff
path: root/src/qcam
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-09-06 22:15:35 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-09-22 10:58:38 +0300
commit4abbd832feb9999824c8b7d1ba8bd5319e8d640a (patch)
tree8a3d45cf7347340528de204637434e5d01801edd /src/qcam
parentf3671b33d90cf2bb13ee59ac83822a3294689b22 (diff)
qcam: format_converter: Add configurable stride support
Make the stride configurable to support conversion of images with padding at the end of lines. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Diffstat (limited to 'src/qcam')
-rw-r--r--src/qcam/format_converter.cpp11
-rw-r--r--src/qcam/format_converter.h4
-rw-r--r--src/qcam/viewfinder_qt.cpp5
3 files changed, 11 insertions, 9 deletions
diff --git a/src/qcam/format_converter.cpp b/src/qcam/format_converter.cpp
index 673ad33e..b4c7b0ca 100644
--- a/src/qcam/format_converter.cpp
+++ b/src/qcam/format_converter.cpp
@@ -30,7 +30,7 @@
#endif
int FormatConverter::configure(const libcamera::PixelFormat &format,
- const QSize &size)
+ const QSize &size, unsigned int stride)
{
switch (format) {
case libcamera::formats::NV12:
@@ -152,6 +152,7 @@ int FormatConverter::configure(const libcamera::PixelFormat &format,
format_ = format;
width_ = size.width();
height_ = size.height();
+ stride_ = stride;
return 0;
}
@@ -186,7 +187,7 @@ static void yuv_to_rgb(int y, int u, int v, int *r, int *g, int *b)
void FormatConverter::convertNV(const Image *srcImage, unsigned char *dst)
{
- unsigned int c_stride = width_ * (2 / horzSubSample_);
+ unsigned int c_stride = stride_ * (2 / horzSubSample_);
unsigned int c_inc = horzSubSample_ == 1 ? 2 : 0;
unsigned int cb_pos = nvSwap_ ? 1 : 0;
unsigned int cr_pos = nvSwap_ ? 0 : 1;
@@ -195,7 +196,7 @@ void FormatConverter::convertNV(const Image *srcImage, unsigned char *dst)
int r, g, b;
for (unsigned int y = 0; y < height_; y++) {
- const unsigned char *src_y = src + y * width_;
+ const unsigned char *src_y = src + y * stride_;
const unsigned char *src_cb = src_c + (y / vertSubSample_) *
c_stride + cb_pos;
const unsigned char *src_cr = src_c + (y / vertSubSample_) *
@@ -243,7 +244,7 @@ void FormatConverter::convertRGB(const Image *srcImage, unsigned char *dst)
dst[4 * x + 3] = 0xff;
}
- src += width_ * bpp_;
+ src += stride_;
dst += width_ * 4;
}
}
@@ -258,7 +259,7 @@ void FormatConverter::convertYUV(const Image *srcImage, unsigned char *dst)
int r, g, b, y, cr, cb;
cr_pos = (cb_pos_ + 2) % 4;
- src_stride = width_ * 2;
+ src_stride = stride_;
dst_stride = width_ * 4;
for (src_y = 0, dst_y = 0; dst_y < height_; src_y++, dst_y++) {
diff --git a/src/qcam/format_converter.h b/src/qcam/format_converter.h
index 2220a62b..bb04aa95 100644
--- a/src/qcam/format_converter.h
+++ b/src/qcam/format_converter.h
@@ -19,7 +19,8 @@ class QImage;
class FormatConverter
{
public:
- int configure(const libcamera::PixelFormat &format, const QSize &size);
+ int configure(const libcamera::PixelFormat &format, const QSize &size,
+ unsigned int stride);
void convert(const Image *src, size_t size, QImage *dst);
@@ -38,6 +39,7 @@ private:
libcamera::PixelFormat format_;
unsigned int width_;
unsigned int height_;
+ unsigned int stride_;
enum FormatFamily formatFamily_;
diff --git a/src/qcam/viewfinder_qt.cpp b/src/qcam/viewfinder_qt.cpp
index cd051760..a05c75ed 100644
--- a/src/qcam/viewfinder_qt.cpp
+++ b/src/qcam/viewfinder_qt.cpp
@@ -52,8 +52,7 @@ const QList<libcamera::PixelFormat> &ViewFinderQt::nativeFormats() const
}
int ViewFinderQt::setFormat(const libcamera::PixelFormat &format,
- const QSize &size,
- [[maybe_unused]] unsigned int stride)
+ const QSize &size, unsigned int stride)
{
image_ = QImage();
@@ -62,7 +61,7 @@ int ViewFinderQt::setFormat(const libcamera::PixelFormat &format,
* the destination image.
*/
if (!::nativeFormats.contains(format)) {
- int ret = converter_.configure(format, size);
+ int ret = converter_.configure(format, size, stride);
if (ret < 0)
return ret;