From patchwork Tue Sep 8 15:07:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 9544 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com 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 0ABEDBDB1C for ; Tue, 8 Sep 2020 15:08:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C9CD362C30; Tue, 8 Sep 2020 17:08:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="KRbd+D+x"; dkim-atps=neutral Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 40D6A6056C for ; Tue, 8 Sep 2020 17:08:10 +0200 (CEST) Received: by mail-lf1-x142.google.com with SMTP id u8so3834227lff.1 for ; Tue, 08 Sep 2020 08:08:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jtE0KsyuA8WbherHcyBIpGQCxZtUBIpqvnIW7vCbHPw=; b=KRbd+D+xJMuxvi6r1yFdJskxc0IBSlkqDXWq12KlQkMQQBrkXKiO2/fCfGuN70KAdC MdWw8kSjbuYH6q6/QntvmaF9kFWHY7QlEX3KvpQgBpoe6J4DFEPuVWL7CX1kzuRt/RCa ysjRKTF+ppwhfkLfpcD89hsnLk/9FIreVFYWQfBgrMdm6uxQzrXwOSaMtfcHzRlDREtK v1z6DvZH+d3/xT0Hc2ifhbsq+WX6uVh0BNJ47K6JjBr4+s90y/DTT+z25N40s8KRsUVk ElILLD6MFIpI8iptx3fwunsNScAVpwE1wh3eCBzvWaa0xfaTqH4FN+qK9oLidh5IYOyb 4sJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jtE0KsyuA8WbherHcyBIpGQCxZtUBIpqvnIW7vCbHPw=; b=pNeS1ZzOyd76cHWVJOPdDlWoOJr1ir8bGPHQFUr443p/z6oT+m0s6e/3XaiXTKfVUO dAN5f3+aqLlvU4ENBBL8ho+oKg9UuU1ocfaXg8U3bOLmA2EmVs8eBQNV1+2AKiAoPab5 dmv1EQAz7wWEgWeGmE59SQ/uwWez2oCvKdsNb7Agb9SHP9XR+fLMDKmO1k337qAxQ1Mq EA3zjMGeRsaS1pUK4RWRnZAEPdOcmzEnAl/PHoF4ldp1zcjFgHlAATYPav4TNKUeHweV 42cGAoh4WFs5x9ENLv2p7xg+W4Tp4rAxr6+yLkoFBgkapttMgOKjy/kaVRQqZdXEueNI ROYA== X-Gm-Message-State: AOAM530MrvGqstlyElRBwirOGTqWIt3HMNyK5jZnuzlQ5fz6zfFN4DZd JjH02WnxL0x+7FG89nG1Ce6I8/6Wy9Jdyw== X-Google-Smtp-Source: ABdhPJwWa74NrKwieKk1Ydj5/JY9X3+tCixDa5kvP1oPf3DR6+opQgbiRd8bZlmv9WBDXu4NAPBirA== X-Received: by 2002:a19:d11:: with SMTP id 17mr12889863lfn.0.1599577689084; Tue, 08 Sep 2020 08:08:09 -0700 (PDT) Received: from localhost.localdomain (37-144-159-139.broadband.corbina.ru. [37.144.159.139]) by smtp.googlemail.com with ESMTPSA id f19sm10614121lfs.85.2020.09.08.08.08.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 08:08:08 -0700 (PDT) From: Andrey Konovalov To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Sep 2020 18:07:38 +0300 Message-Id: <20200908150739.1552-2-andrey.konovalov@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200908150739.1552-1-andrey.konovalov@linaro.org> References: <20200908150739.1552-1-andrey.konovalov@linaro.org> Subject: [libcamera-devel] [RFC PATCH v2 1/2] qcam: format_converter: put parameters of different formats into union 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: , MIME-Version: 1.0 Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" As the number of supported formats in the converter grows, having the format-specific parameters in a union makes the code cleaner, and save some amount of memory. Signed-off-by: Andrey Konovalov --- src/qcam/format_converter.cpp | 133 ++++++++++++++++++---------------- src/qcam/format_converter.h | 37 ++++++---- 2 files changed, 92 insertions(+), 78 deletions(-) diff --git a/src/qcam/format_converter.cpp b/src/qcam/format_converter.cpp index 4b9722d..3481330 100644 --- a/src/qcam/format_converter.cpp +++ b/src/qcam/format_converter.cpp @@ -33,103 +33,103 @@ int FormatConverter::configure(const libcamera::PixelFormat &format, switch (format) { case libcamera::formats::NV12: formatFamily_ = NV; - horzSubSample_ = 2; - vertSubSample_ = 2; - nvSwap_ = false; + params_.nv.horzSubSample = 2; + params_.nv.vertSubSample = 2; + params_.nv.nvSwap = false; break; case libcamera::formats::NV21: formatFamily_ = NV; - horzSubSample_ = 2; - vertSubSample_ = 2; - nvSwap_ = true; + params_.nv.horzSubSample = 2; + params_.nv.vertSubSample = 2; + params_.nv.nvSwap = true; break; case libcamera::formats::NV16: formatFamily_ = NV; - horzSubSample_ = 2; - vertSubSample_ = 1; - nvSwap_ = false; + params_.nv.horzSubSample = 2; + params_.nv.vertSubSample = 1; + params_.nv.nvSwap = false; break; case libcamera::formats::NV61: formatFamily_ = NV; - horzSubSample_ = 2; - vertSubSample_ = 1; - nvSwap_ = true; + params_.nv.horzSubSample = 2; + params_.nv.vertSubSample = 1; + params_.nv.nvSwap = true; break; case libcamera::formats::NV24: formatFamily_ = NV; - horzSubSample_ = 1; - vertSubSample_ = 1; - nvSwap_ = false; + params_.nv.horzSubSample = 1; + params_.nv.vertSubSample = 1; + params_.nv.nvSwap = false; break; case libcamera::formats::NV42: formatFamily_ = NV; - horzSubSample_ = 1; - vertSubSample_ = 1; - nvSwap_ = true; + params_.nv.horzSubSample = 1; + params_.nv.vertSubSample = 1; + params_.nv.nvSwap = true; break; case libcamera::formats::RGB888: formatFamily_ = RGB; - r_pos_ = 2; - g_pos_ = 1; - b_pos_ = 0; - bpp_ = 3; + params_.rgb.r_pos = 2; + params_.rgb.g_pos = 1; + params_.rgb.b_pos = 0; + params_.rgb.bpp = 3; break; case libcamera::formats::BGR888: formatFamily_ = RGB; - r_pos_ = 0; - g_pos_ = 1; - b_pos_ = 2; - bpp_ = 3; + params_.rgb.r_pos = 0; + params_.rgb.g_pos = 1; + params_.rgb.b_pos = 2; + params_.rgb.bpp = 3; break; case libcamera::formats::ARGB8888: formatFamily_ = RGB; - r_pos_ = 2; - g_pos_ = 1; - b_pos_ = 0; - bpp_ = 4; + params_.rgb.r_pos = 2; + params_.rgb.g_pos = 1; + params_.rgb.b_pos = 0; + params_.rgb.bpp = 4; break; case libcamera::formats::RGBA8888: formatFamily_ = RGB; - r_pos_ = 3; - g_pos_ = 2; - b_pos_ = 1; - bpp_ = 4; + params_.rgb.r_pos = 3; + params_.rgb.g_pos = 2; + params_.rgb.b_pos = 1; + params_.rgb.bpp = 4; break; case libcamera::formats::ABGR8888: formatFamily_ = RGB; - r_pos_ = 0; - g_pos_ = 1; - b_pos_ = 2; - bpp_ = 4; + params_.rgb.r_pos = 0; + params_.rgb.g_pos = 1; + params_.rgb.b_pos = 2; + params_.rgb.bpp = 4; break; case libcamera::formats::BGRA8888: formatFamily_ = RGB; - r_pos_ = 1; - g_pos_ = 2; - b_pos_ = 3; - bpp_ = 4; + params_.rgb.r_pos = 1; + params_.rgb.g_pos = 2; + params_.rgb.b_pos = 3; + params_.rgb.bpp = 4; break; case libcamera::formats::VYUY: formatFamily_ = YUV; - y_pos_ = 1; - cb_pos_ = 2; + params_.yuv.y_pos = 1; + params_.yuv.cb_pos = 2; break; case libcamera::formats::YVYU: formatFamily_ = YUV; - y_pos_ = 0; - cb_pos_ = 3; + params_.yuv.y_pos = 0; + params_.yuv.cb_pos = 3; break; case libcamera::formats::UYVY: formatFamily_ = YUV; - y_pos_ = 1; - cb_pos_ = 0; + params_.yuv.y_pos = 1; + params_.yuv.cb_pos = 0; break; case libcamera::formats::YUYV: formatFamily_ = YUV; - y_pos_ = 0; - cb_pos_ = 1; + params_.yuv.y_pos = 0; + params_.yuv.cb_pos = 1; break; case libcamera::formats::MJPEG: @@ -178,18 +178,20 @@ static void yuv_to_rgb(int y, int u, int v, int *r, int *g, int *b) void FormatConverter::convertNV(const unsigned char *src, unsigned char *dst) { - unsigned int c_stride = width_ * (2 / horzSubSample_); - unsigned int c_inc = horzSubSample_ == 1 ? 2 : 0; - unsigned int cb_pos = nvSwap_ ? 1 : 0; - unsigned int cr_pos = nvSwap_ ? 0 : 1; + unsigned int c_stride = width_ * (2 / params_.nv.horzSubSample); + unsigned int c_inc = params_.nv.horzSubSample == 1 ? 2 : 0; + unsigned int cb_pos = params_.nv.nvSwap ? 1 : 0; + unsigned int cr_pos = params_.nv.nvSwap ? 0 : 1; const unsigned char *src_c = src + width_ * height_; int r, g, b; for (unsigned int y = 0; y < height_; y++) { const unsigned char *src_y = src + y * width_; - const unsigned char *src_cb = src_c + (y / vertSubSample_) * + const unsigned char *src_cb = src_c + + (y / params_.nv.vertSubSample) * c_stride + cb_pos; - const unsigned char *src_cr = src_c + (y / vertSubSample_) * + const unsigned char *src_cr = src_c + + (y / params_.nv.vertSubSample) * c_stride + cr_pos; for (unsigned int x = 0; x < width_; x += 2) { @@ -223,9 +225,9 @@ void FormatConverter::convertRGB(const unsigned char *src, unsigned char *dst) for (y = 0; y < height_; y++) { for (x = 0; x < width_; x++) { - r = src[bpp_ * x + r_pos_]; - g = src[bpp_ * x + g_pos_]; - b = src[bpp_ * x + b_pos_]; + r = src[params_.rgb.bpp * x + params_.rgb.r_pos]; + g = src[params_.rgb.bpp * x + params_.rgb.g_pos]; + b = src[params_.rgb.bpp * x + params_.rgb.b_pos]; dst[4 * x + 0] = b; dst[4 * x + 1] = g; @@ -233,7 +235,7 @@ void FormatConverter::convertRGB(const unsigned char *src, unsigned char *dst) dst[4 * x + 3] = 0xff; } - src += width_ * bpp_; + src += width_ * params_.rgb.bpp; dst += width_ * 4; } } @@ -246,16 +248,18 @@ void FormatConverter::convertYUV(const unsigned char *src, unsigned char *dst) unsigned int cr_pos; int r, g, b, y, cr, cb; - cr_pos = (cb_pos_ + 2) % 4; + cr_pos = (params_.yuv.cb_pos + 2) % 4; src_stride = width_ * 2; dst_stride = width_ * 4; for (src_y = 0, dst_y = 0; dst_y < height_; src_y++, dst_y++) { for (src_x = 0, dst_x = 0; dst_x < width_; ) { - cb = src[src_y * src_stride + src_x * 4 + cb_pos_]; + cb = src[src_y * src_stride + src_x * 4 + + params_.yuv.cb_pos]; cr = src[src_y * src_stride + src_x * 4 + cr_pos]; - y = src[src_y * src_stride + src_x * 4 + y_pos_]; + y = src[src_y * src_stride + src_x * 4 + + params_.yuv.y_pos]; yuv_to_rgb(y, cb, cr, &r, &g, &b); dst[dst_y * dst_stride + 4 * dst_x + 0] = b; dst[dst_y * dst_stride + 4 * dst_x + 1] = g; @@ -263,7 +267,8 @@ void FormatConverter::convertYUV(const unsigned char *src, unsigned char *dst) dst[dst_y * dst_stride + 4 * dst_x + 3] = 0xff; dst_x++; - y = src[src_y * src_stride + src_x * 4 + y_pos_ + 2]; + y = src[src_y * src_stride + src_x * 4 + + params_.yuv.y_pos + 2]; yuv_to_rgb(y, cb, cr, &r, &g, &b); dst[dst_y * dst_stride + 4 * dst_x + 0] = b; dst[dst_y * dst_stride + 4 * dst_x + 1] = g; diff --git a/src/qcam/format_converter.h b/src/qcam/format_converter.h index e389b24..c53fa28 100644 --- a/src/qcam/format_converter.h +++ b/src/qcam/format_converter.h @@ -40,20 +40,29 @@ private: enum FormatFamily formatFamily_; - /* NV parameters */ - unsigned int horzSubSample_; - unsigned int vertSubSample_; - bool nvSwap_; - - /* RGB parameters */ - unsigned int bpp_; - unsigned int r_pos_; - unsigned int g_pos_; - unsigned int b_pos_; - - /* YUV parameters */ - unsigned int y_pos_; - unsigned int cb_pos_; + union { + /* NV parameters */ + struct nv_params { + unsigned int horzSubSample; + unsigned int vertSubSample; + bool nvSwap; + } nv; + + /* RGB parameters */ + struct rgb_params { + unsigned int bpp; + unsigned int r_pos; + unsigned int g_pos; + unsigned int b_pos; + } rgb; + + /* YUV parameters */ + struct yuv_params { + unsigned int y_pos; + unsigned int cb_pos; + } yuv; + } params_; + }; #endif /* __QCAM_FORMAT_CONVERTER_H__ */ From patchwork Tue Sep 8 15:07:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 9545 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com 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 5FEAFBDB1C for ; Tue, 8 Sep 2020 15:08:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2CE2062CB2; Tue, 8 Sep 2020 17:08:14 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Fh6/Ow8F"; dkim-atps=neutral Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0648D6056C for ; Tue, 8 Sep 2020 17:08:13 +0200 (CEST) Received: by mail-lj1-x244.google.com with SMTP id w3so20482003ljo.5 for ; Tue, 08 Sep 2020 08:08:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hOBNU2TJIcHiBs8ViVf9SAf9Eo1RLhlaLf8wscXGp18=; b=Fh6/Ow8F1T5o1AjkL0r+YV775lGNy1pXhzKi1xiIw6MI9YffmgJauNyIEBibpnjqtO 4YmGUJ/U1aRbQv9kc4bVfpJZZcf2A6ASAVRC8Coz00mb/T0ohvT7UPmqVWs+jY0P50bu 5qSAhgjRk1R0FT8xnJIr+fandkd0UfS6r9NAB9W2hpHBTMflKP/cLnhrvt7F4lVi1Y2q kWfakRcFtf2VA8Vm/ev0SL5kboDn1Q1qUeAPuMCCVUdyjfajQMFMZczCPfqhPP4t7EiV M1gakU9p1sui5wiac+RbB3nMvyKZsxQKKJ4joKs9g+6C56Y+ECh65N8VJ5WecJOtIxGE 7NiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hOBNU2TJIcHiBs8ViVf9SAf9Eo1RLhlaLf8wscXGp18=; b=rLlUPqasnirgFitrlCJWMypiDxSCqeHmpG5zT1nEfjT0oBitKV0fzWi0xIQsK5gkT2 i2qbayP66iuKAYN+0tyKTOfhh2ed0LNoaNZTZSLHiWu0Q9LwGNzmcJWWmIr0lmZQjiFp RSjlQiHHyo/6Mc7TFKFmPW556EplvH2UdqcPmh/noOPVdokyC4dDRtfD41zZEu2+WYqo sxKcTgi9KiMjexW4jN7Bq24LWs0H1dIPf9yUfUs3D5GjXLfrc1vZoy+VGHUijPNQ3Kn4 JfMC4xSBt57tMiwCGfhlT+M2Kih+EJTR1wKDx88h6QOBLYkpEcOuB0kfLW4aFaYEhbu+ iNZQ== X-Gm-Message-State: AOAM53212olPR0phUotxQsMei20OEr2F1Qd5oB7di5kljjpMs/xVTjKV /sNXqIx5Ur1Stv9VEBdNOD8NX2IyEWiCZQ== X-Google-Smtp-Source: ABdhPJwYJ9aKfz6cmxT/WtAtjlITz0SVZkIJcOvqOEH9FJE7WIBnhbf+vQxaBIlY5zJFwlfrZHBGmA== X-Received: by 2002:a2e:5051:: with SMTP id v17mr12239180ljd.295.1599577691919; Tue, 08 Sep 2020 08:08:11 -0700 (PDT) Received: from localhost.localdomain (37-144-159-139.broadband.corbina.ru. [37.144.159.139]) by smtp.googlemail.com with ESMTPSA id f19sm10614121lfs.85.2020.09.08.08.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 08:08:11 -0700 (PDT) From: Andrey Konovalov To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Sep 2020 18:07:39 +0300 Message-Id: <20200908150739.1552-3-andrey.konovalov@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200908150739.1552-1-andrey.konovalov@linaro.org> References: <20200908150739.1552-1-andrey.konovalov@linaro.org> Subject: [libcamera-devel] [RFC PATCH v2 2/2] qcam: format_converter: add 10 and 12 bit packed raw Bayer formats 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: , MIME-Version: 1.0 Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" No interpolation is used to get more speed by the price of lower image quality. In qcam format_converter is used for viewfinder only, and in this case lower lag is more important than the image quality. Signed-off-by: Andrey Konovalov --- src/qcam/format_converter.cpp | 138 ++++++++++++++++++++++++++++++++++ src/qcam/format_converter.h | 21 ++++++ 2 files changed, 159 insertions(+) diff --git a/src/qcam/format_converter.cpp b/src/qcam/format_converter.cpp index 3481330..f370907 100644 --- a/src/qcam/format_converter.cpp +++ b/src/qcam/format_converter.cpp @@ -10,6 +10,7 @@ #include #include +#include #include @@ -132,6 +133,62 @@ int FormatConverter::configure(const libcamera::PixelFormat &format, params_.yuv.cb_pos = 1; break; + case libcamera::formats::SRGGB10_CSI2P: + formatFamily_ = RAW_CSI2P; + params_.rawp.bpp_numer = 5; /* 1.25 bytes per pixel */ + params_.rawp.bpp_denom = 4; + params_.rawp.r_pos = 0; + break; + + case libcamera::formats::SGRBG10_CSI2P: + formatFamily_ = RAW_CSI2P; + params_.rawp.bpp_numer = 5; + params_.rawp.bpp_denom = 4; + params_.rawp.r_pos = 1; + break; + + case libcamera::formats::SGBRG10_CSI2P: + formatFamily_ = RAW_CSI2P; + params_.rawp.bpp_numer = 5; + params_.rawp.bpp_denom = 4; + params_.rawp.r_pos = 2; + break; + + case libcamera::formats::SBGGR10_CSI2P: + formatFamily_ = RAW_CSI2P; + params_.rawp.bpp_numer = 5; + params_.rawp.bpp_denom = 4; + params_.rawp.r_pos = 3; + break; + + case libcamera::formats::SRGGB12_CSI2P: + formatFamily_ = RAW_CSI2P; + params_.rawp.bpp_numer = 3; /* 1.5 bytes per pixel */ + params_.rawp.bpp_denom = 2; + params_.rawp.r_pos = 0; + break; + + case libcamera::formats::SGRBG12_CSI2P: + formatFamily_ = RAW_CSI2P; + params_.rawp.bpp_numer = 3; + params_.rawp.bpp_denom = 2; + params_.rawp.r_pos = 1; + break; + + case libcamera::formats::SGBRG12_CSI2P: + formatFamily_ = RAW_CSI2P; + params_.rawp.bpp_numer = 3; + params_.rawp.bpp_denom = 2; + params_.rawp.r_pos = 2; + break; + + case libcamera::formats::SBGGR12_CSI2P: + formatFamily_ = RAW_CSI2P; + params_.rawp.bpp_numer = 3; + params_.rawp.bpp_denom = 2; + params_.rawp.r_pos = 3; + break; + case libcamera::formats::MJPEG: formatFamily_ = MJPEG; break; @@ -144,6 +201,45 @@ int FormatConverter::configure(const libcamera::PixelFormat &format, width_ = size.width(); height_ = size.height(); + if (formatFamily_ == RAW_CSI2P) { + /* + * For RAW_CSI2P the assumption is that height_ and width_ + * are even numbers. + */ + if ( width_ % 2 != 0 || height_ % 2 != 0 ) { + qWarning() << "Image width or height isn't even number"; + return -EINVAL; + } + + params_.rawp.srcLineLength = width_ * params_.rawp.bpp_numer / + params_.rawp.bpp_denom; + + /* + * Calculate [g1,g2,b]_pos based on r_pos. + * On entrance, r_pos is the position of red pixel in the + * 2-by-2 pixel Bayer pattern, and is from 0 to 3 range: + * +---+---+ + * | 0 | 1 | + * +---+---+ + * | 2 | 3 | + * +---+---+ + * At exit, [r,g1,g2,b]_pos are offsetts of the color + * values in the source buffer. + */ + if (params_.rawp.r_pos > 1) { + params_.rawp.r_pos = params_.rawp.r_pos - 2 + + params_.rawp.srcLineLength; + params_.rawp.b_pos = 3 - params_.rawp.r_pos; + } else { + params_.rawp.b_pos = 1 - params_.rawp.r_pos + + params_.rawp.srcLineLength; + } + params_.rawp.g1_pos = (params_.rawp.r_pos == 0 || + params_.rawp.b_pos == 0) ? 1 : 0; + params_.rawp.g2_pos = 1 - params_.rawp.g1_pos + + params_.rawp.srcLineLength; + } + return 0; } @@ -163,9 +259,51 @@ void FormatConverter::convert(const unsigned char *src, size_t size, case NV: convertNV(src, dst->bits()); break; + case RAW_CSI2P: + convertRawCSI2P(src, dst->bits()); + break; }; } +void FormatConverter::convertRawCSI2P(const unsigned char *src, + unsigned char *dst) +{ + unsigned int g; + static unsigned char dst_buf[8] = { 0, 0, 0, 0xff }; + unsigned int dstLineLength = width_ * 4; + + for (unsigned int y = 0; y < height_; y += 2) { + for (unsigned x = 0; x < width_; x += params_.rawp.bpp_denom) { + for (unsigned int i = 0; i < params_.rawp.bpp_denom ; + i += 2) { + /* + * Process the current 2x2 group. + * Use the average of the two green pixels as + * the green value for all the pixels in the + * group. + */ + dst_buf[0] = src[params_.rawp.b_pos]; + g = src[params_.rawp.g1_pos]; + g = (g + src[params_.rawp.g2_pos]) >> 1; + dst_buf[1] = (unsigned char)g; + dst_buf[2] = src[params_.rawp.r_pos]; + src += 2; + + memcpy(dst_buf + 4, dst_buf, 4); + memcpy(dst, dst_buf, 8); + memcpy(dst + dstLineLength, dst_buf, 8); + dst += 8; + } + src += params_.rawp.bpp_numer - params_.rawp.bpp_denom; + } + /* odd lines are copies of the even lines they follow: */ + memcpy(dst, dst-dstLineLength, dstLineLength); + /* move to the next even line: */ + src += params_.rawp.srcLineLength; + dst += dstLineLength; + } +} + static void yuv_to_rgb(int y, int u, int v, int *r, int *g, int *b) { int c = y - 16; diff --git a/src/qcam/format_converter.h b/src/qcam/format_converter.h index c53fa28..dc20e0d 100644 --- a/src/qcam/format_converter.h +++ b/src/qcam/format_converter.h @@ -26,11 +26,13 @@ private: enum FormatFamily { MJPEG, NV, + RAW_CSI2P, RGB, YUV, }; void convertNV(const unsigned char *src, unsigned char *dst); + void convertRawCSI2P(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); @@ -48,6 +50,25 @@ private: bool nvSwap; } nv; + /* RAW Bayer CSI2P parameters */ + struct raw_csi2p_params { + /* + * Bytes per pixel is a fractional number, and is + * represented by integer numerator and denominator. + */ + unsigned int bpp_numer; + unsigned int bpp_denom; + unsigned int r_pos; + /* + * The fields below are used to hold the values computed + * in configure() based on r_pos and width_. + */ + unsigned int g1_pos; + unsigned int g2_pos; + unsigned int b_pos; + unsigned int srcLineLength; + } rawp; + /* RGB parameters */ struct rgb_params { unsigned int bpp;