From patchwork Mon Sep 6 23:04:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13700 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id C8DA8BDC71 for ; Mon, 6 Sep 2021 23:05:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8D33F6917E; Tue, 7 Sep 2021 01:05:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="K0aBUOT7"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0C5D26916A for ; Tue, 7 Sep 2021 01:04:59 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B24BC993 for ; Tue, 7 Sep 2021 01:04:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1630969498; bh=StNEg6YOM8TKLj/oK4v6Tok/KcvPCqE3ulbnmsBWz0o=; h=From:To:Subject:Date:In-Reply-To:References:From; b=K0aBUOT7whiO7iDM7KJlwUv2Ij6R5vu9JACc/aXZTo3+YOmLeIS4nziYJjLAtWRLS U7saIq/8mhU7DU1rQWNczvo2PWzIfqXuXsJD/dtQTX/NlQlizY2Kh7+qu7pFGVU9sK ESEBLvJPi1AZeUPzlihDozdWBDZR2jfeatL3u7qg= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 7 Sep 2021 02:04:34 +0300 Message-Id: <20210906230436.17106-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210906230436.17106-1-laurent.pinchart@ideasonboard.com> References: <20210906230436.17106-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 3/5] qcam: format_converter: Rename YUV and NV to YUVPacked and YUVSemiPlanar X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" To prepare for fully-planar YUV support, rename the existing format families YUV and NV to YUVPacked and YUVSemiPlanar respectively. Signed-off-by: Laurent Pinchart --- src/qcam/format_converter.cpp | 106 +++++++++++++++++----------------- src/qcam/format_converter.h | 8 +-- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/qcam/format_converter.cpp b/src/qcam/format_converter.cpp index 7f7ddb2dc77b..7979ea8a77ff 100644 --- a/src/qcam/format_converter.cpp +++ b/src/qcam/format_converter.cpp @@ -34,37 +34,37 @@ int FormatConverter::configure(const libcamera::PixelFormat &format, { switch (format) { case libcamera::formats::NV12: - formatFamily_ = NV; + formatFamily_ = YUVSemiPlanar; horzSubSample_ = 2; vertSubSample_ = 2; nvSwap_ = false; break; case libcamera::formats::NV21: - formatFamily_ = NV; + formatFamily_ = YUVSemiPlanar; horzSubSample_ = 2; vertSubSample_ = 2; nvSwap_ = true; break; case libcamera::formats::NV16: - formatFamily_ = NV; + formatFamily_ = YUVSemiPlanar; horzSubSample_ = 2; vertSubSample_ = 1; nvSwap_ = false; break; case libcamera::formats::NV61: - formatFamily_ = NV; + formatFamily_ = YUVSemiPlanar; horzSubSample_ = 2; vertSubSample_ = 1; nvSwap_ = true; break; case libcamera::formats::NV24: - formatFamily_ = NV; + formatFamily_ = YUVSemiPlanar; horzSubSample_ = 1; vertSubSample_ = 1; nvSwap_ = false; break; case libcamera::formats::NV42: - formatFamily_ = NV; + formatFamily_ = YUVSemiPlanar; horzSubSample_ = 1; vertSubSample_ = 1; nvSwap_ = true; @@ -163,14 +163,14 @@ void FormatConverter::convert(const Image *src, size_t size, QImage *dst) case MJPEG: dst->loadFromData(src->data(0).data(), size, "JPEG"); break; - case YUV: - convertYUV(src, dst->bits()); - break; case RGB: convertRGB(src, dst->bits()); break; - case NV: - convertNV(src, dst->bits()); + case YUVPacked: + convertYUVPacked(src, dst->bits()); + break; + case YUVSemiPlanar: + convertYUVSemiPlanar(src, dst->bits()); break; }; } @@ -185,47 +185,6 @@ 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::convertNV(const Image *srcImage, unsigned char *dst) -{ - 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; - const unsigned char *src = srcImage->data(0).data(); - const unsigned char *src_c = srcImage->data(1).data(); - int r, g, b; - - for (unsigned int y = 0; y < height_; y++) { - 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_) * - c_stride + cr_pos; - - for (unsigned int x = 0; x < width_; x += 2) { - yuv_to_rgb(*src_y, *src_cb, *src_cr, &r, &g, &b); - dst[0] = b; - dst[1] = g; - dst[2] = r; - dst[3] = 0xff; - src_y++; - src_cb += c_inc; - src_cr += c_inc; - dst += 4; - - yuv_to_rgb(*src_y, *src_cb, *src_cr, &r, &g, &b); - dst[0] = b; - dst[1] = g; - dst[2] = r; - dst[3] = 0xff; - src_y++; - src_cb += 2; - src_cr += 2; - dst += 4; - } - } -} - void FormatConverter::convertRGB(const Image *srcImage, unsigned char *dst) { const unsigned char *src = srcImage->data(0).data(); @@ -249,7 +208,7 @@ void FormatConverter::convertRGB(const Image *srcImage, unsigned char *dst) } } -void FormatConverter::convertYUV(const Image *srcImage, unsigned char *dst) +void FormatConverter::convertYUVPacked(const Image *srcImage, unsigned char *dst) { const unsigned char *src = srcImage->data(0).data(); unsigned int src_x, src_y, dst_x, dst_y; @@ -287,3 +246,44 @@ void FormatConverter::convertYUV(const Image *srcImage, unsigned char *dst) } } } + +void FormatConverter::convertYUVSemiPlanar(const Image *srcImage, unsigned char *dst) +{ + 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; + const unsigned char *src = srcImage->data(0).data(); + const unsigned char *src_c = srcImage->data(1).data(); + int r, g, b; + + for (unsigned int y = 0; y < height_; y++) { + 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_) * + c_stride + cr_pos; + + for (unsigned int x = 0; x < width_; x += 2) { + yuv_to_rgb(*src_y, *src_cb, *src_cr, &r, &g, &b); + dst[0] = b; + dst[1] = g; + dst[2] = r; + dst[3] = 0xff; + src_y++; + src_cb += c_inc; + src_cr += c_inc; + dst += 4; + + yuv_to_rgb(*src_y, *src_cb, *src_cr, &r, &g, &b); + dst[0] = b; + dst[1] = g; + dst[2] = r; + dst[3] = 0xff; + src_y++; + src_cb += 2; + src_cr += 2; + dst += 4; + } + } +} diff --git a/src/qcam/format_converter.h b/src/qcam/format_converter.h index bb04aa959a1a..9ce2cc6da7f2 100644 --- a/src/qcam/format_converter.h +++ b/src/qcam/format_converter.h @@ -27,14 +27,14 @@ public: private: enum FormatFamily { MJPEG, - NV, RGB, - YUV, + YUVPacked, + YUVSemiPlanar, }; - void convertNV(const Image *src, unsigned char *dst); void convertRGB(const Image *src, unsigned char *dst); - void convertYUV(const Image *src, unsigned char *dst); + void convertYUVPacked(const Image *src, unsigned char *dst); + void convertYUVSemiPlanar(const Image *src, unsigned char *dst); libcamera::PixelFormat format_; unsigned int width_;