From patchwork Thu May 12 08:42:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 15894 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 A5A12C0F2A for ; Thu, 12 May 2022 08:43:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CBFC36565B; Thu, 12 May 2022 10:43:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652344983; bh=L5h0ZAe/G5JFrDNuWcHKooNkZSDGkSvSM7FkmL9S2Gc=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=HsYg6WSsC1mh9fu7RRFvwRCqBn9ovwTbMtWZGKQ273wWn4C54PQsgU51PXI9l5Gkr 4jBG7pQgFizLv4KWo207qHkJ5NVHwGp38LCTAYDFOOXPSzhZxfThZjkSyr3l/6lExa zgnNsrRFNV3CPup7h+lnnqwu2r15hbGEPoTZPrvLnr+Af/eykByb2cNA8tJA+3BTGH /6nLSy2hiG11K0oYpimHuBSAgJwVw190I9AY6E0WxK409Hpaks4XEZnDKUNJmc2f2n 0MPc2Dsm6eQwPIq3opU3xnAL9SNk5Y/U5J1xCNDiMW3H+P2/YHrbOa4YvmNcU3/lgX DVWfpzGwk2hxA== Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A591A6150E for ; Thu, 12 May 2022 10:43:01 +0200 (CEST) Received: (Authenticated sender: foss@0leil.net) by mail.gandi.net (Postfix) with ESMTPSA id 31E4E240010; Thu, 12 May 2022 08:42:59 +0000 (UTC) To: Date: Thu, 12 May 2022 10:42:43 +0200 Message-Id: <20220512084244.1833554-1-foss+libcamera@0leil.net> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 1/2] ipa: rkisp1: awb: add support for RGB means 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: , X-Patchwork-Original-From: Quentin Schulz via libcamera-devel From: Quentin Schulz Reply-To: Quentin Schulz Cc: libcamera-devel@lists.libcamera.org Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Quentin Schulz RkISP actually supports two modes for color means, RGB and YCbCr. The variables where the means are stored are identically named regardless of the color means mode that's been selected. Since the gains are computed in RGB mode, a conversion needs to be done when the mode is YCbCr, which is unnecessary when RGB mode is selected. This adds support for RGB means mode too, by checking at runtime which mode is selected at a given time. Cc: Quentin Schulz Signed-off-by: Quentin Schulz --- To be decided if we want to keep supporting both modes or only one? (Given that at the moment we harcode which mode is used at compile time, I'm not sure it's worth keeping dead code around) src/ipa/rkisp1/algorithms/awb.cpp | 57 ++++++++++++++++++------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index be4585c6..df749b9b 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -124,30 +124,39 @@ void Awb::process([[maybe_unused]] IPAContext &context, const rkisp1_stat_buffer const rkisp1_cif_isp_stat *params = &stats->params; const rkisp1_cif_isp_awb_stat *awb = ¶ms->awb; IPAFrameContext &frameContext = context.frameContext; - - /* Get the YCbCr mean values */ - double yMean = awb->awb_mean[0].mean_y_or_g; - double crMean = awb->awb_mean[0].mean_cr_or_r; - double cbMean = awb->awb_mean[0].mean_cb_or_b; - - /* - * Convert from YCbCr to RGB. - * The hardware uses the following formulas: - * Y = 16 + 0.2500 R + 0.5000 G + 0.1094 B - * Cb = 128 - 0.1406 R - 0.2969 G + 0.4375 B - * Cr = 128 + 0.4375 R - 0.3750 G - 0.0625 B - * - * The inverse matrix is thus: - * [[1,1636, -0,0623, 1,6008] - * [1,1636, -0,4045, -0,7949] - * [1,1636, 1,9912, -0,0250]] - */ - yMean -= 16; - cbMean -= 128; - crMean -= 128; - double redMean = 1.1636 * yMean - 0.0623 * cbMean + 1.6008 * crMean; - double greenMean = 1.1636 * yMean - 0.4045 * cbMean - 0.7949 * crMean; - double blueMean = 1.1636 * yMean + 1.9912 * cbMean - 0.0250 * crMean; + double greenMean; + double redMean; + double blueMean; + + if (params->meas.awb_meas_config.awb_mode == RKISP1_CIF_ISP_AWB_MODE_RGB) { + greenMean = awb->awb_mean[0].mean_y_or_g; + redMean = awb->awb_mean[0].mean_cr_or_r; + blueMean = awb->awb_mean[0].mean_cb_or_b; + } else { + /* Get the YCbCr mean values */ + double yMean = awb->awb_mean[0].mean_y_or_g; + double crMean = awb->awb_mean[0].mean_cr_or_r; + double cbMean = awb->awb_mean[0].mean_cb_or_b; + + /* + * Convert from YCbCr to RGB. + * The hardware uses the following formulas: + * Y = 16 + 0.2500 R + 0.5000 G + 0.1094 B + * Cb = 128 - 0.1406 R - 0.2969 G + 0.4375 B + * Cr = 128 + 0.4375 R - 0.3750 G - 0.0625 B + * + * The inverse matrix is thus: + * [[1,1636, -0,0623, 1,6008] + * [1,1636, -0,4045, -0,7949] + * [1,1636, 1,9912, -0,0250]] + */ + yMean -= 16; + cbMean -= 128; + crMean -= 128; + redMean = 1.1636 * yMean - 0.0623 * cbMean + 1.6008 * crMean; + greenMean = 1.1636 * yMean - 0.4045 * cbMean - 0.7949 * crMean; + blueMean = 1.1636 * yMean + 1.9912 * cbMean - 0.0250 * crMean; + } /* Estimate the red and blue gains to apply in a grey world. */ double redGain = greenMean / (redMean + 1); From patchwork Thu May 12 08:42:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 15895 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 889E3C0F2A for ; Thu, 12 May 2022 08:43:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 468C665660; Thu, 12 May 2022 10:43:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652344986; bh=PX69UFpuMSHjrcirpY5K/3ghK75/te/8KG7hMP5G5BY=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=tggs9GEihZAT5F5ZycNw3EgGgCN9uDxdM+Vr35O5MXCReSlFek59UuO2+ZyAPebmh ciaxkFQpwdmGQLBgSk2y3HJk5tePMBxUUzBvAl54OFImcjA9qya9M6wedkbVpplkbL 5BxtJ+BeGl0uEiBiasJi8BYYMsGx7BpwUgZPgMRGI3igok8Jek0/YPjmwXPM+fIq+m JjZsx2EM1BmJJ5lGIdOrZG9NDna+lp65k9IfZ9z/A0D8zl9ulTQRRHnpRoOSKGhQYB 3D+zkk2ZVyoh7YN8f3lu31mqo+sxLAE6dbWbRgR2ELJWZgvKh69Vf43jwB+5dcO2o5 cRcLtRnVGfGFg== Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::221]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 41D296565A for ; Thu, 12 May 2022 10:43:04 +0200 (CEST) Received: (Authenticated sender: foss@0leil.net) by mail.gandi.net (Postfix) with ESMTPSA id CCD0D24000A; Thu, 12 May 2022 08:43:01 +0000 (UTC) To: Date: Thu, 12 May 2022 10:42:44 +0200 Message-Id: <20220512084244.1833554-2-foss+libcamera@0leil.net> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220512084244.1833554-1-foss+libcamera@0leil.net> References: <20220512084244.1833554-1-foss+libcamera@0leil.net> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 2/2] ipa: rkisp1: awb: switch to RGB means mode 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: , X-Patchwork-Original-From: Quentin Schulz via libcamera-devel From: Quentin Schulz Reply-To: Quentin Schulz Cc: libcamera-devel@lists.libcamera.org Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Quentin Schulz While YCbCr means mode works just fine, it requires a conversion to RGB before computing necessary RGB gains. By using RGB means mode directly, this conversion can be spared. This was tested on a Rockchip PX30-based custom board and on a Theobroma Puma SoM + Haikou devkit and all fitted with an OV5675 sensor, using custom kernels based on upstream Linux kernel (respectively) 5.10 (with most upstream patches for rkisp1 from newer kernels applied) and 5.13. Cc: Quentin Schulz Signed-off-by: Quentin Schulz --- We probably need to triple check the other parameters right after (e.g. the Cr/Cb references, the Y and Cb+Cr min/max values) too. This is basically so people can check whether it works properly on the same hardware they said it didn't work when initially adding support for AWB on RkISP. src/ipa/rkisp1/algorithms/awb.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index df749b9b..5dea5c13 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -91,11 +91,8 @@ void Awb::prepare(IPAContext &context, rkisp1_params_cfg *params) /* Configure the measure window for AWB. */ params->meas.awb_meas_config.awb_wnd = context.configuration.awb.measureWindow; - /* - * Measure Y, Cr and Cb means. - * \todo RGB is not working, the kernel seems to not configure it ? - */ - params->meas.awb_meas_config.awb_mode = RKISP1_CIF_ISP_AWB_MODE_YCBCR; + /* Measure RGB means. */ + params->meas.awb_meas_config.awb_mode = RKISP1_CIF_ISP_AWB_MODE_RGB; /* Reference Cr and Cb. */ params->meas.awb_meas_config.awb_ref_cb = 128; params->meas.awb_meas_config.awb_ref_cr = 128;