From patchwork Sat May 4 20:33:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 1159 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CD81860E54 for ; Sat, 4 May 2019 22:34:10 +0200 (CEST) Received: from localhost.localdomain (unknown [96.44.9.117]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CB50ED5; Sat, 4 May 2019 22:34:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1557002050; bh=FPP91rWSqJ3l1bSo7B0dzdZZk7e5xiWmXoNgWofCbB8=; h=From:To:Cc:Subject:Date:From; b=S9KauegDfJTFLxJCgrG4MnfaprzaOkRLw2/P56Kbc7Vw4qO0S8Rk14zUZd7c9e7jR fZ0LnUfYXL1vad50vfb/8D8D7LyPVJh4R7PVOkrBKdsT5P0n5P9sa8EBDushZXEXP5 h5I+FyC5F31baHLXUwdsEDyu40Qi06Uw+6EzbxsI= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Sat, 4 May 2019 16:33:53 -0400 Message-Id: <20190504203354.20870-1-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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: Sat, 04 May 2019 20:34:11 -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 --- 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..9820982 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_; }; From patchwork Sat May 4 20:33:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 1160 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3FFB060E54 for ; Sat, 4 May 2019 22:34:11 +0200 (CEST) Received: from localhost.localdomain (unknown [96.44.9.117]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8EEFC33D; Sat, 4 May 2019 22:34:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1557002051; bh=/nMgt4qoWRA31V0Dyd+fmYxbnf7p6ARyyhYdP6j36N4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ENWkIK31uetPbo2uv2KsctdldtpgGPACVUzxWABcn/I/tOVfKJgR1nbez7Ja24/bH iz60WD/j3fUHUzRgrK1KFyx/ddAUIoX6Szw6Ui1BjiKn5Vtx0dFAhPX6AwmJWsIh+g ZntH/YA1ZObcX9YnjNLLUqbfQzxanqOOfsniG3mQ= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Sat, 4 May 2019 16:33:54 -0400 Message-Id: <20190504203354.20870-2-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190504203354.20870-1-paul.elder@ideasonboard.com> References: <20190504203354.20870-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] qcam: format_converter: Add NV formats support 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: Sat, 04 May 2019 20:34:11 -0000 Add support for some NV formats: - V4L2_PIX_FMT_NV12, V4L2_PIX_FMT_NV21 - V4L2_PIX_FMT_NV16, V4L2_PIX_FMT_NV61 - V4L2_PIX_FMT_NV24, V4L2_PIX_FMT_NV42 Signed-off-by: Paul Elder --- src/qcam/format_converter.cpp | 62 +++++++++++++++++++++++++++++++++++ src/qcam/format_converter.h | 7 ++++ 2 files changed, 69 insertions(+) diff --git a/src/qcam/format_converter.cpp b/src/qcam/format_converter.cpp index 192767c..ca91c7e 100644 --- a/src/qcam/format_converter.cpp +++ b/src/qcam/format_converter.cpp @@ -72,6 +72,42 @@ int FormatConverter::configure(unsigned int format, unsigned int width, y_pos_ = 0; cb_pos_ = 1; break; + case V4L2_PIX_FMT_NV12: + formatFamily_ = NV; + xDownSample_ = 2; + yDownSample_ = 2; + nvSwap_ = false; + break; + case V4L2_PIX_FMT_NV21: + formatFamily_ = NV; + xDownSample_ = 2; + yDownSample_ = 2; + nvSwap_ = true; + break; + case V4L2_PIX_FMT_NV16: + formatFamily_ = NV; + xDownSample_ = 2; + yDownSample_ = 1; + nvSwap_ = false; + break; + case V4L2_PIX_FMT_NV61: + formatFamily_ = NV; + xDownSample_ = 2; + yDownSample_ = 1; + nvSwap_ = true; + break; + case V4L2_PIX_FMT_NV24: + formatFamily_ = NV; + xDownSample_ = 1; + yDownSample_ = 1; + nvSwap_ = false; + break; + case V4L2_PIX_FMT_NV42: + formatFamily_ = NV; + xDownSample_ = 1; + yDownSample_ = 1; + nvSwap_ = true; + break; case V4L2_PIX_FMT_MJPEG: formatFamily_ = MJPEG; break; @@ -99,6 +135,9 @@ void FormatConverter::convert(const unsigned char *src, size_t size, case RGB: convertRGB(src, dst->bits()); break; + case NV: + convertNV(src, dst->bits()); + break; }; } @@ -171,3 +210,26 @@ void FormatConverter::convertYUV(const unsigned char *src, unsigned char *dst) } } } + +void FormatConverter::convertNV(const unsigned char *src, unsigned char *dst) +{ + unsigned int i, j; + int r, g, b, y, cr, cb, loc; + + for (j = 0; j < height_; j++) { + for (i = 0; i < width_; i++) { + y = src[j * width_ + i]; + loc = height_ * width_ + + (j / yDownSample_) * width_ * 2 / xDownSample_ + + (i & -xDownSample_) * 2 / xDownSample_; + cb = nvSwap_ ? src[loc + 1] : src[loc]; + cr = nvSwap_ ? src[loc] : src[loc + 1]; + + yuv_to_rgb(y, cb, cr, &r, &g, &b); + dst[j * width_ * 4 + i * 4 + 0] = b; + dst[j * width_ * 4 + i * 4 + 1] = g; + dst[j * width_ * 4 + i * 4 + 2] = r; + dst[j * width_ * 4 + i * 4 + 3] = 0xff; + } + } +} diff --git a/src/qcam/format_converter.h b/src/qcam/format_converter.h index 9820982..48af0fc 100644 --- a/src/qcam/format_converter.h +++ b/src/qcam/format_converter.h @@ -16,6 +16,7 @@ class FormatConverter public: enum formatFamily { MJPEG, + NV, RGB, YUV, }; @@ -26,6 +27,7 @@ public: void convert(const unsigned char *src, size_t size, QImage *dst); private: + 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); @@ -35,6 +37,11 @@ private: enum formatFamily formatFamily_; + /* NV parameters */ + unsigned int xDownSample_; + unsigned int yDownSample_; + bool nvSwap_; + /* RGB parameters */ unsigned int bpp_; unsigned int r_pos_;