From patchwork Fri Jun 17 08:32:11 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: 16256 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 D7EA9BD161 for ; Fri, 17 Jun 2022 08:32:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1637765635; Fri, 17 Jun 2022 10:32:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655454737; bh=u2KZRO1PCj4w/rZ+feY0qJJxmZl8esw7GAavvN9Q4Yw=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=tXUHW+ToGn0dPj3hcUkQI+D4wIYtmAODAFGODcPRzrWecwwdJIaJK9py0xGs3DA/l FSiuaTSYx9I0lrZSxujq4DCnUvovqQ7/hNrOptLL7K/sh66KozMQYV++vGDfGVuQse ha+1lhKKJ3VySWm0pJaCFPU+GQ1hTfinD+J2/E6okNOE0b91ECD6tb/ciCSf6wn/3y /Wv282qN7ZuYo3pp5NyeoSF58QsAgEau2b32RTja3a4T60/t6m34N9+uUGJFpBPg0x yMlAhtGUlPqydI4MhaKqWntbFCDgRaADyvHTcY3dO8sR8hv32TuffKp8g2xgDN7TiS fZ/tD2EQxFpSA== 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 CAE2460471 for ; Fri, 17 Jun 2022 10:32:15 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="PJeRUYxb"; dkim-atps=neutral Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:28e5:dce:57ec:634e]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 62EF22A5; Fri, 17 Jun 2022 10:32:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655454735; bh=u2KZRO1PCj4w/rZ+feY0qJJxmZl8esw7GAavvN9Q4Yw=; h=From:To:Cc:Subject:Date:From; b=PJeRUYxbhg4p+r8eZDS1WxXnlYiKaWubuLMIfmAbmplzMgq5YLarU7a6NGVNSHjG2 JRTh6ZVKA5Z9mlDUQeQb1KV7clJDt6vcmE4vzCraMv57FDghc4qy8DAaSlyZ4e5R1b oHQq705IknKsF2V20lBf5WN06tY2ZVjKHgSu/Ki4= To: libcamera-devel@lists.libcamera.org Date: Fri, 17 Jun 2022 10:32:11 +0200 Message-Id: <20220617083211.28407-1-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] ipa: ipu3: awb: Correct the coefficient factor 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 | 21 +++++++++++++++++---- src/ipa/ipu3/algorithms/awb.h | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp index 5c232d92..6abaf75f 100644 --- a/src/ipa/ipu3/algorithms/awb.cpp +++ b/src/ipa/ipu3/algorithms/awb.cpp @@ -409,6 +409,19 @@ constexpr uint16_t Awb::threshold(float value) return value * 8191; } +constexpr uint16_t Awb::fixedGain(double gain) +{ + /* + * For BNR parameters WB gain factor for the three channels + * [Ggr, Ggb, Gb, Gr]. Their precision is U3.13 and the range is (0, 8) + * and the actual gain is Gx + 1, it is typically Gx = 1. + * + * Pout = {Pin * (1 + Gx)}. + */ + gain = std::clamp((gain - 1.0), 0.0, 8.0); + return gain * 8192; +} + /** * \copydoc libcamera::ipa::Algorithm::prepare */ @@ -451,10 +464,10 @@ void Awb::prepare(IPAContext &context, ipu3_uapi_params *params) 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 = fixedGain(context.activeState.awb.gains.green); + params->acc_param.bnr.wb_gains.r = fixedGain(context.activeState.awb.gains.red); + params->acc_param.bnr.wb_gains.b = fixedGain(context.activeState.awb.gains.blue); + params->acc_param.bnr.wb_gains.gb = fixedGain(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..3154541d 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 fixedGain(double gain); std::vector zones_; Accumulator awbStats_[kAwbStatsSizeX * kAwbStatsSizeY];