From patchwork Fri Jun 17 21:28:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Michel Hautbois X-Patchwork-Id: 16269 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 E9A8ABD808 for ; Fri, 17 Jun 2022 21:29:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 52E1065633; Fri, 17 Jun 2022 23:29:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655501341; bh=sbhHyIi+zg22qUphlR1OGHJzHiyg9bsDbXNXocO3Ytg=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=EzvdtXOAofmrKfscE5hBo7wMIVfddBBNeN71ezKn51a97WXZaMyQQZKzrm32xL14Y MlwuRQ6paScND1DafKhwR/2HAe0Du1ZcL2by5Tm5C0P1U0TvwH+snFGXAqnzZmN+0l 6MSekRzqKZUbFUm3BOylKhyMyC14vNEUVHM2vH24/39N/hF74tXk51Q/NYAVtxI7+n /lxOA7DFGGSpr8vDdncHe+Ba3vcr113vc4ll8If0KePGMsliSt6emVLc1LRDyjwiuD vTQYnvfXZQQPmQYX2U92ZpCNCIHmQ5JuNq9DWUAR+k+R8ZFgRRO5b5cGYjMCurOi2r VkcK2l2rzDJSA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 92B5065632 for ; Fri, 17 Jun 2022 23:28:59 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="VbkRAeu5"; dkim-atps=neutral Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:dd2e:f9c7:5350:5a2c]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 19FC6268; Fri, 17 Jun 2022 23:28:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655501339; bh=sbhHyIi+zg22qUphlR1OGHJzHiyg9bsDbXNXocO3Ytg=; h=From:To:Cc:Subject:Date:From; b=VbkRAeu5vwSGhATqjzMQKVTSwl316eIXQvSk8KdTeDJAOWzljh6jfchjm2vnug9r4 iCK/Z97q/HooKJpFKr6g77vtPk01lgsWMCAhvBUQlTzHOMEElcGxctiy3JWofjT/W4 kAAizykiPs4rFM+qtPHrorzs43Znn5R8LPWSdA0c= To: libcamera-devel@lists.libcamera.org Date: Fri, 17 Jun 2022 23:28:54 +0200 Message-Id: <20220617212854.11369-1-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] ipa: ipu3: awb: Correct the gains calculation 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: Jean-Michel Hautbois via libcamera-devel From: Jean-Michel Hautbois Reply-To: Jean-Michel Hautbois Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The factor used right now in the IPU3 is 8192, as a multiplier of the estimated gain. This is wrong, as the isp is adding 1.0 to the gain applied, ie Pout = { Pin * (1 + Gx) }. Fix it, and to ease the reading, introduce a small helper function. Signed-off-by: Jean-Michel Hautbois Reviewed-by: Laurent Pinchart --- src/ipa/ipu3/algorithms/awb.cpp | 27 ++++++++++++++++++++++----- src/ipa/ipu3/algorithms/awb.h | 1 + 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp index 5c232d92..70426722 100644 --- a/src/ipa/ipu3/algorithms/awb.cpp +++ b/src/ipa/ipu3/algorithms/awb.cpp @@ -409,6 +409,23 @@ constexpr uint16_t Awb::threshold(float value) return value * 8191; } +constexpr uint16_t Awb::gainValue(double gain) +{ + /* + * The colour gains applied by the BNR for the four channels (Gr, R, B + * and Gb) are expressed in the parameters structure as 16-bit integers + * that store a fixed-point U3.13 value in the range [0, 8[. + * + * The real gain value is equal to the gain parameter plus one, i.e. + * + * Pout = Pin * (1 + gain / 8192) + * + * where 'Pin' is the input pixel value, 'Pout' the output pixel value, + * and 'gain' the gain in the parameters structure as a 16-bit integer. + */ + return std::clamp((gain - 1.0) * 8192, 0.0, 65535.0); +} + /** * \copydoc libcamera::ipa::Algorithm::prepare */ @@ -450,11 +467,11 @@ void Awb::prepare(IPAContext &context, ipu3_uapi_params *params) * params->acc_param.bnr.opt_center.x_reset; params->acc_param.bnr.opt_center_sqr.y_sqr_reset = params->acc_param.bnr.opt_center.y_reset * params->acc_param.bnr.opt_center.y_reset; - /* Convert to u3.13 fixed point values */ - params->acc_param.bnr.wb_gains.gr = 8192 * context.activeState.awb.gains.green; - params->acc_param.bnr.wb_gains.r = 8192 * context.activeState.awb.gains.red; - params->acc_param.bnr.wb_gains.b = 8192 * context.activeState.awb.gains.blue; - params->acc_param.bnr.wb_gains.gb = 8192 * context.activeState.awb.gains.green; + + params->acc_param.bnr.wb_gains.gr = gainValue(context.activeState.awb.gains.green); + params->acc_param.bnr.wb_gains.r = gainValue(context.activeState.awb.gains.red); + params->acc_param.bnr.wb_gains.b = gainValue(context.activeState.awb.gains.blue); + params->acc_param.bnr.wb_gains.gb = gainValue(context.activeState.awb.gains.green); LOG(IPU3Awb, Debug) << "Color temperature estimated: " << asyncResults_.temperatureK; diff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h index 9a50a985..0acd2148 100644 --- a/src/ipa/ipu3/algorithms/awb.h +++ b/src/ipa/ipu3/algorithms/awb.h @@ -73,6 +73,7 @@ private: void awbGreyWorld(); uint32_t estimateCCT(double red, double green, double blue); static constexpr uint16_t threshold(float value); + static constexpr uint16_t gainValue(double gain); std::vector zones_; Accumulator awbStats_[kAwbStatsSizeX * kAwbStatsSizeY];