summaryrefslogtreecommitdiff
path: root/src/qcam/format_converter.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-03-29 17:20:07 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-04-02 17:24:41 +0300
commit80e236e19b61a1267948433fd6855da138d6f527 (patch)
treef2ff6a8311b5c4d4cef65e4a7260e75c84aee6ec /src/qcam/format_converter.cpp
parent29f323eea84c5bf5037658b0042478124ed58ff1 (diff)
qcam: Add JPEG format support
When the camera provides MJPEG, use the QImage JPEG decompression code to convert that to RGB. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'src/qcam/format_converter.cpp')
-rw-r--r--src/qcam/format_converter.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/qcam/format_converter.cpp b/src/qcam/format_converter.cpp
index 6979a054..bda9057e 100644
--- a/src/qcam/format_converter.cpp
+++ b/src/qcam/format_converter.cpp
@@ -9,6 +9,8 @@
#include <linux/videodev2.h>
+#include <QImage>
+
#include "format_converter.h"
#define RGBSHIFT 8
@@ -45,16 +47,28 @@ int FormatConverter::configure(unsigned int format, unsigned int width,
y_pos_ = 0;
cb_pos_ = 1;
break;
+ case V4L2_PIX_FMT_MJPEG:
+ break;
default:
return -EINVAL;
};
+ format_ = format;
width_ = width;
height_ = height;
return 0;
}
+void FormatConverter::convert(const unsigned char *src, size_t size,
+ QImage *dst)
+{
+ if (format_ == V4L2_PIX_FMT_MJPEG)
+ dst->loadFromData(src, size, "JPEG");
+ else
+ convertYUV(src, dst->bits());
+}
+
static void yuv_to_rgb(int y, int u, int v, int *r, int *g, int *b)
{
int c = y - 16;
@@ -65,7 +79,7 @@ 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::convert(const unsigned char *src, unsigned char *dst)
+void FormatConverter::convertYUV(const unsigned char *src, unsigned char *dst)
{
unsigned int src_x, src_y, dst_x, dst_y;
unsigned int src_stride;