From patchwork Mon May 6 20:15:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 1161 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9020560E63 for ; Mon, 6 May 2019 22:15:36 +0200 (CEST) Received: from localhost.localdomain (unknown [96.44.9.117]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7F238115F; Mon, 6 May 2019 22:15:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1557173736; bh=tmRxzJV3lTiNIIItR6qG7wfVGpb0rmD0IWQS01wB06g=; h=From:To:Cc:Subject:Date:From; b=Ei8c6RS0fh8XFhhzB7/RAvac/8JbjMyJA6doOkPDqpDKJXD0aR4INgwQFOovmoEEd vvsuo2ti+FOl8xzNkO3c6b/6E/YUQu4/QkT7JFO6KTAKMiaaJAj7eVYeLb8JEG9MpN p5N9hA4Y3P36FW338uDmuVa2n0hVvVwTHpIXzA08= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Mon, 6 May 2019 16:15:27 -0400 Message-Id: <20190506201528.24445-1-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/2] qcam: format_converter: Add formatFamily enum X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 May 2019 20:15:36 -0000 It is not sustainable to add a new flag for every new video format family (eg. YUYV, RGB, NV, MJPEG, etc), so add a formatFamily enum to indicate these in the FormatConverter. Note that formats are grouped into families based on if they are able to share a set of parameters for conversion. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- Changes in v2: rename enum formatFamily to enum FormatFamily src/qcam/format_converter.cpp | 27 ++++++++++++++++----------- src/qcam/format_converter.h | 11 ++++++++++- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/qcam/format_converter.cpp b/src/qcam/format_converter.cpp index d9088c3..192767c 100644 --- a/src/qcam/format_converter.cpp +++ b/src/qcam/format_converter.cpp @@ -32,48 +32,48 @@ int FormatConverter::configure(unsigned int format, unsigned int width, { switch (format) { case V4L2_PIX_FMT_BGR24: - yuv_ = false; + formatFamily_ = RGB; r_pos_ = 2; g_pos_ = 1; b_pos_ = 0; bpp_ = 3; break; case V4L2_PIX_FMT_RGB24: - yuv_ = false; + formatFamily_ = RGB; r_pos_ = 0; g_pos_ = 1; b_pos_ = 2; bpp_ = 3; break; case V4L2_PIX_FMT_ARGB32: - yuv_ = false; + formatFamily_ = RGB; r_pos_ = 1; g_pos_ = 2; b_pos_ = 3; bpp_ = 4; break; case V4L2_PIX_FMT_VYUY: - yuv_ = true; + formatFamily_ = YUV; y_pos_ = 1; cb_pos_ = 2; break; case V4L2_PIX_FMT_YVYU: - yuv_ = true; + formatFamily_ = YUV; y_pos_ = 0; cb_pos_ = 3; break; case V4L2_PIX_FMT_UYVY: - yuv_ = true; + formatFamily_ = YUV; y_pos_ = 1; cb_pos_ = 0; break; case V4L2_PIX_FMT_YUYV: - yuv_ = true; + formatFamily_ = YUV; y_pos_ = 0; cb_pos_ = 1; break; case V4L2_PIX_FMT_MJPEG: - yuv_ = false; + formatFamily_ = MJPEG; break; default: return -EINVAL; @@ -89,12 +89,17 @@ int FormatConverter::configure(unsigned int format, unsigned int width, void FormatConverter::convert(const unsigned char *src, size_t size, QImage *dst) { - if (format_ == V4L2_PIX_FMT_MJPEG) + switch (formatFamily_) { + case MJPEG: dst->loadFromData(src, size, "JPEG"); - else if (yuv_) + break; + case YUV: convertYUV(src, dst->bits()); - else + break; + case RGB: convertRGB(src, dst->bits()); + break; + }; } void FormatConverter::convertRGB(const unsigned char *src, unsigned char *dst) diff --git a/src/qcam/format_converter.h b/src/qcam/format_converter.h index 76cd9f1..c18871e 100644 --- a/src/qcam/format_converter.h +++ b/src/qcam/format_converter.h @@ -14,6 +14,12 @@ class QImage; class FormatConverter { public: + enum FormatFamily { + MJPEG, + RGB, + YUV, + }; + int configure(unsigned int format, unsigned int width, unsigned int height); @@ -27,12 +33,15 @@ private: unsigned int width_; unsigned int height_; + enum FormatFamily formatFamily_; + + /* RGB parameters */ unsigned int bpp_; unsigned int r_pos_; unsigned int g_pos_; unsigned int b_pos_; - bool yuv_; + /* YUV parameters */ unsigned int y_pos_; unsigned int cb_pos_; };