From patchwork Mon May 4 18:26:52 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 26618 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 E7FF6C32F6 for ; Mon, 4 May 2026 18:27:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8857263025; Mon, 4 May 2026 20:27:24 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="jOX9oLI6"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F1CF063025 for ; Mon, 4 May 2026 20:27:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777919241; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/4SRSFW2CabW6xnK7ScaXSfCdyrKnii9ObIH+MGlG4o=; b=jOX9oLI6eL4Yeg1vCqDIu/Jx0Cdyh+lOEVCvjMt9JqIjjaco6RqvS7pOEqX5Uh/jRLot6y LfsC5pDD52GwX0II3MtHHS5xeT5W/J5o5uzoAXsqz7mrgWXTrWBqtHqhR1m+JEVs7lsuQy OXIosSmEtTpUI33GpwMPOQC4HlbSO2A= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-465-ZSUQ5-VRO9upOYyD71qj0A-1; Mon, 04 May 2026 14:27:18 -0400 X-MC-Unique: ZSUQ5-VRO9upOYyD71qj0A-1 X-Mimecast-MFC-AGG-ID: ZSUQ5-VRO9upOYyD71qj0A_1777919237 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 36A20195605E; Mon, 4 May 2026 18:27:17 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.44.32.69]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EC64A1800480; Mon, 4 May 2026 18:27:14 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Bryan O'Donoghue , Hans de Goede , Laurent Pinchart Subject: [RFC PATCH v4 3/7] ipa: simple: Introduce default temperature value Date: Mon, 4 May 2026 20:26:52 +0200 Message-ID: <20260504182658.590233-4-mzamazal@redhat.com> In-Reply-To: <20260504182658.590233-1-mzamazal@redhat.com> References: <20260504182658.590233-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: hVZbTnd6uD2BuYUyQ_H3FpkG5AiVvk8EpM2f1q5DArk_1777919237 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true 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" Some algorithms use interpolated values based on temperature. Temperature is computed in the AWB algorithm. Technically, the AWB algorithm can be disabled and then no temperature is computed. Let's avoid implicit assumptions and introduce a constant for a default temperature value and make the temperature value optional. This is currently used by the CCM algorithm. It will be used also by the LSC algorithm in the followup patch. The default temperature value of 6500 is just a common value, there is no special reason to use this or another value. Signed-off-by: Milan Zamazal --- src/ipa/simple/algorithms/awb.cpp | 4 ++-- src/ipa/simple/algorithms/awb.h | 4 +++- src/ipa/simple/algorithms/ccm.cpp | 5 ++++- src/ipa/simple/ipa_context.h | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/ipa/simple/algorithms/awb.cpp b/src/ipa/simple/algorithms/awb.cpp index f5c88ea6f..961126c0d 100644 --- a/src/ipa/simple/algorithms/awb.cpp +++ b/src/ipa/simple/algorithms/awb.cpp @@ -96,11 +96,11 @@ void Awb::process(IPAContext &context, RGB rgbGains{ { 1 / gains.r(), 1 / gains.g(), 1 / gains.b() } }; context.activeState.awb.temperatureK = estimateCCT(rgbGains); - metadata.set(controls::ColourTemperature, context.activeState.awb.temperatureK); + metadata.set(controls::ColourTemperature, context.activeState.awb.temperatureK.value_or(0)); LOG(IPASoftAwb, Debug) << "gain R/B: " << gains << "; temperature: " - << context.activeState.awb.temperatureK; + << context.activeState.awb.temperatureK.value_or(0); } REGISTER_IPA_ALGORITHM(Awb, "Awb") diff --git a/src/ipa/simple/algorithms/awb.h b/src/ipa/simple/algorithms/awb.h index ad993f39c..df46baee4 100644 --- a/src/ipa/simple/algorithms/awb.h +++ b/src/ipa/simple/algorithms/awb.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* - * Copyright (C) 2024-2025 Red Hat Inc. + * Copyright (C) 2024-2026 Red Hat Inc. * * Auto white balance */ @@ -13,6 +13,8 @@ namespace libcamera { namespace ipa::soft::algorithms { +constexpr unsigned int kDefaultTemperature = 6500; + class Awb : public Algorithm { public: diff --git a/src/ipa/simple/algorithms/ccm.cpp b/src/ipa/simple/algorithms/ccm.cpp index ace9c35dc..6f566ccdc 100644 --- a/src/ipa/simple/algorithms/ccm.cpp +++ b/src/ipa/simple/algorithms/ccm.cpp @@ -15,6 +15,8 @@ #include "libcamera/internal/matrix.h" +#include "awb.h" + namespace { constexpr unsigned int kTemperatureThreshold = 100; @@ -44,7 +46,8 @@ int Ccm::init([[maybe_unused]] IPAContext &context, const ValueNode &tuningData) void Ccm::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame, IPAFrameContext &frameContext, [[maybe_unused]] DebayerParams *params) { - const unsigned int ct = context.activeState.awb.temperatureK; + const unsigned int ct = + context.activeState.awb.temperatureK.value_or(kDefaultTemperature); /* Change CCM only on bigger temperature changes. */ if (!currentCcm_ || diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h index 34f7403a4..c4bd91bb0 100644 --- a/src/ipa/simple/ipa_context.h +++ b/src/ipa/simple/ipa_context.h @@ -50,7 +50,7 @@ struct IPAActiveState { struct { RGB gains; - unsigned int temperatureK; + std::optional temperatureK; } awb; Matrix combinedMatrix;