summaryrefslogtreecommitdiff
path: root/src/qcam/format_converter.cpp
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/format_converter.cpp
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/format_converter.cpp')
-rw-r--r--src/qcam/format_converter.cpp11
1 files changed, 6 insertions, 5 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++) {