From patchwork Wed Jan 21 17:37:31 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 25919 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 3D247BDCBF for ; Wed, 21 Jan 2026 17:38:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 17C5E61FD9; Wed, 21 Jan 2026 18:38:00 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="m3gyzqQx"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1648761FCE for ; Wed, 21 Jan 2026 18:37:45 +0100 (CET) Received: from Monstersaurus.hippo-penny.ts.net (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 12950250A; Wed, 21 Jan 2026 18:37:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1769017033; bh=cXsmpqFcPSIlu4xwR5TnKmghrvaU2bOqX4277Jb8v9I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m3gyzqQxzzewZnJZ1m57GRpvxWpWktSOaBe2yRhEjsdOIP+EEMdZBrWsX/xjV1dty a1oEmAvVZzucQipVj0tG4399JnrPEjDhN0uTysEajT6KU5SSvCCl1T9nT51lnOhSy8 ybjvOFAWZ6FoHmETVHDVqVJelv1VjWjN1DyG5vtg= From: Kieran Bingham To: libcamera devel Cc: Kieran Bingham , Isaac Scott , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v6 12/16] ipa: mali-c55: Convert AWB to UQ<4, 8> usage Date: Wed, 21 Jan 2026 17:37:31 +0000 Message-ID: <20260121173737.376113-13-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260121173737.376113-1-kieran.bingham@ideasonboard.com> References: <20260121173737.376113-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 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" Utilise the new FixedPoint type to explicitly calculate gains for AWB in Q4.8 format. This ensures that reporting of gains in metadata reflect the true AWB gains applied. Reviewed-by: Isaac Scott Reviewed-by: Barnabás Pőcze Signed-off-by: Kieran Bingham --- v5: - Use UQ<4, 8> directly - Change debug prints to use operator<< - Now based on top of float types instead of doubles Signed-off-by: Kieran Bingham --- src/ipa/mali-c55/algorithms/awb.cpp | 36 ++++++++++++++--------------- src/ipa/mali-c55/ipa_context.h | 10 ++++---- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/ipa/mali-c55/algorithms/awb.cpp b/src/ipa/mali-c55/algorithms/awb.cpp index b179dd7f0c1c..a5150bbf3d97 100644 --- a/src/ipa/mali-c55/algorithms/awb.cpp +++ b/src/ipa/mali-c55/algorithms/awb.cpp @@ -37,8 +37,8 @@ int Awb::configure([[maybe_unused]] IPAContext &context, * for the first frame we will make no assumptions and leave the R/B * channels unmodified. */ - context.activeState.awb.rGain = 1.0; - context.activeState.awb.bGain = 1.0; + context.activeState.awb.rGain = 1.0f; + context.activeState.awb.bGain = 1.0f; return 0; } @@ -46,8 +46,8 @@ int Awb::configure([[maybe_unused]] IPAContext &context, void Awb::fillGainsParamBlock(MaliC55Params *params, IPAContext &context, IPAFrameContext &frameContext) { - double rGain = context.activeState.awb.rGain; - double bGain = context.activeState.awb.bGain; + UQ<4, 8> rGain = context.activeState.awb.rGain; + UQ<4, 8> bGain = context.activeState.awb.bGain; /* * The gains here map as follows: @@ -61,10 +61,10 @@ void Awb::fillGainsParamBlock(MaliC55Params *params, IPAContext &context, */ auto block = params->block(); - block->gain00 = floatingToFixedPoint<4, 8, uint16_t, double>(rGain); - block->gain01 = floatingToFixedPoint<4, 8, uint16_t, double>(1.0); - block->gain10 = floatingToFixedPoint<4, 8, uint16_t, double>(1.0); - block->gain11 = floatingToFixedPoint<4, 8, uint16_t, double>(bGain); + block->gain00 = rGain.quantized(); + block->gain01 = UQ<4, 8>(1.0f).quantized(); + block->gain10 = UQ<4, 8>(1.0f).quantized(); + block->gain11 = bGain.quantized(); frameContext.awb.rGain = rGain; frameContext.awb.bGain = bGain; @@ -140,18 +140,18 @@ void Awb::process(IPAContext &context, const uint32_t frame, * gain figures that we can apply to approximate a grey world. */ unsigned int counted_zones = 0; - double rgSum = 0, bgSum = 0; + float rgSum = 0, bgSum = 0; for (unsigned int i = 0; i < 225; i++) { if (!awb_ratios[i].num_pixels) continue; /* - * The statistics are in Q4.8 format, so we convert to double + * The statistics are in Q4.8 format, so we convert to float * here. */ - rgSum += fixedToFloatingPoint<4, 8, double, uint16_t>(awb_ratios[i].avg_rg_gr); - bgSum += fixedToFloatingPoint<4, 8, double, uint16_t>(awb_ratios[i].avg_bg_br); + rgSum += UQ<4, 8>(awb_ratios[i].avg_rg_gr).value(); + bgSum += UQ<4, 8>(awb_ratios[i].avg_bg_br).value(); counted_zones++; } @@ -174,8 +174,8 @@ void Awb::process(IPAContext &context, const uint32_t frame, * figure by the gains that were applied when the statistics for this * frame were generated. */ - float rRatio = rgAvg / frameContext.awb.rGain; - float bRatio = bgAvg / frameContext.awb.bGain; + float rRatio = rgAvg / frameContext.awb.rGain.value(); + float bRatio = bgAvg / frameContext.awb.bGain.value(); /* * And then we can simply invert the ratio to find the gain we should @@ -191,15 +191,15 @@ void Awb::process(IPAContext &context, const uint32_t frame, * want to fix the miscolouring as quickly as possible. */ float speed = frame < kNumStartupFrames ? 1.0 : 0.2; - rGain = speed * rGain + context.activeState.awb.rGain * (1.0 - speed); - bGain = speed * bGain + context.activeState.awb.bGain * (1.0 - speed); + rGain = speed * rGain + context.activeState.awb.rGain.value() * (1.0 - speed); + bGain = speed * bGain + context.activeState.awb.bGain.value() * (1.0 - speed); context.activeState.awb.rGain = rGain; context.activeState.awb.bGain = bGain; metadata.set(controls::ColourGains, { - static_cast(frameContext.awb.rGain), - static_cast(frameContext.awb.bGain), + frameContext.awb.rGain.value(), + frameContext.awb.bGain.value(), }); LOG(MaliC55Awb, Debug) << "For frame number " << frame << ": " diff --git a/src/ipa/mali-c55/ipa_context.h b/src/ipa/mali-c55/ipa_context.h index 13885eb83b5c..08f78e4f74ce 100644 --- a/src/ipa/mali-c55/ipa_context.h +++ b/src/ipa/mali-c55/ipa_context.h @@ -14,6 +14,8 @@ #include +#include "libipa/fixedpoint.h" + namespace libcamera { namespace ipa::mali_c55 { @@ -53,8 +55,8 @@ struct IPAActiveState { } agc; struct { - double rGain; - double bGain; + UQ<4, 8> rGain; + UQ<4, 8> bGain; } awb; }; @@ -66,8 +68,8 @@ struct IPAFrameContext : public FrameContext { } agc; struct { - double rGain; - double bGain; + UQ<4, 8> rGain; + UQ<4, 8> bGain; } awb; };