From patchwork Wed Mar 26 09:08:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 23037 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 13149C3213 for ; Wed, 26 Mar 2025 09:09:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C1D1068967; Wed, 26 Mar 2025 10:09:12 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="YvW1mq0d"; 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 C094F6895A for ; Wed, 26 Mar 2025 10:09:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1742980147; 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=uA0MTtC+dCigDrmLKMhXZ3B9Lc9EQDHtJTE7E7GptxE=; b=YvW1mq0dy6snSFTWA8IecY2V40sm1DVed256EWVsemCeSdfx/gLYN/MXS4WkAexplEAC0J XmfEIytFPefurI3QzDCe1FC4JTLbZW6ULXExB/qhON9XuwMSU7v7sGDxkoNawiBmDiT75i qLWLDjR/tw+OC+33a7BLZWha54adgJU= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-365-iVG7DYtUMESVzuzU1dwQKw-1; Wed, 26 Mar 2025 05:09:04 -0400 X-MC-Unique: iVG7DYtUMESVzuzU1dwQKw-1 X-Mimecast-MFC-AGG-ID: iVG7DYtUMESVzuzU1dwQKw_1742980143 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9D3ED1809CA3; Wed, 26 Mar 2025 09:09:03 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.44.34.15]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4ACAD1801747; Wed, 26 Mar 2025 09:09:01 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Robert Mader , Hans de Goede , Laurent Pinchart , Kieran Bingham Subject: [PATCH v8 02/10] libcamera: software_isp: Use RGB type to represent gains Date: Wed, 26 Mar 2025 10:08:39 +0100 Message-ID: <20250326090849.15494-3-mzamazal@redhat.com> In-Reply-To: <20250326090849.15494-1-mzamazal@redhat.com> References: <20250326090849.15494-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: c6mS_jA8Sl4Gy_VR4rfH65zNltk-LSsjJO3bmg3kmWw_1742980143 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" Rather than using a custom struct to represent RGB values, let's use the corresponding type and its facilities. Signed-off-by: Milan Zamazal Reviewed-by: Laurent Pinchart Signed-off-by: Milan Zamazal Reviewed-by: Kieran Bingham --- src/ipa/simple/algorithms/awb.cpp | 16 +++++++++------- src/ipa/simple/algorithms/lut.cpp | 14 ++++---------- src/ipa/simple/ipa_context.h | 8 +++----- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/ipa/simple/algorithms/awb.cpp b/src/ipa/simple/algorithms/awb.cpp index 1efc7090..310be6a7 100644 --- a/src/ipa/simple/algorithms/awb.cpp +++ b/src/ipa/simple/algorithms/awb.cpp @@ -25,7 +25,7 @@ int Awb::configure(IPAContext &context, [[maybe_unused]] const IPAConfigInfo &configInfo) { auto &gains = context.activeState.awb.gains; - gains.red = gains.green = gains.blue = 1.0; + gains = { { 1.0, 1.0, 1.0 } }; return 0; } @@ -56,16 +56,18 @@ void Awb::process(IPAContext &context, * Clamp max gain at 4.0, this also avoids 0 division. */ auto &gains = context.activeState.awb.gains; - gains.red = sumR <= sumG / 4 ? 4.0 : static_cast(sumG) / sumR; - gains.blue = sumB <= sumG / 4 ? 4.0 : static_cast(sumG) / sumB; - /* Green gain is fixed to 1.0 */ + gains = { { + sumR <= sumG / 4 ? 4.0 : static_cast(sumG) / sumR, + 1.0, + sumB <= sumG / 4 ? 4.0 : static_cast(sumG) / sumB, + } }; - RGB rgbGains{ { 1 / gains.red, 1 / gains.green, 1 / gains.blue } }; + RGB rgbGains{ { 1 / gains.r(), 1 / gains.g(), 1 / gains.b() } }; context.activeState.awb.temperatureK = estimateCCT(rgbGains); LOG(IPASoftAwb, Debug) - << "gain R/B: " << gains.red << "/" << gains.blue - << "; temperature: " << context.activeState.awb.temperatureK; + << "gain R/B: " << gains << "; temperature: " + << context.activeState.awb.temperatureK; } REGISTER_IPA_ALGORITHM(Awb, "Awb") diff --git a/src/ipa/simple/algorithms/lut.cpp b/src/ipa/simple/algorithms/lut.cpp index a2e11d3b..83df71a9 100644 --- a/src/ipa/simple/algorithms/lut.cpp +++ b/src/ipa/simple/algorithms/lut.cpp @@ -103,16 +103,10 @@ void Lut::prepare(IPAContext &context, const double div = static_cast(DebayerParams::kRGBLookupSize) / gammaTableSize; /* Apply gamma after gain! */ - unsigned int idx; - idx = std::min({ static_cast(i * gains.red / div), - gammaTableSize - 1 }); - params->red[i] = gammaTable[idx]; - idx = std::min({ static_cast(i * gains.green / div), - gammaTableSize - 1 }); - params->green[i] = gammaTable[idx]; - idx = std::min({ static_cast(i * gains.blue / div), - gammaTableSize - 1 }); - params->blue[i] = gammaTable[idx]; + const RGB lutGains = (gains * i / div).min(gammaTableSize - 1); + params->red[i] = gammaTable[static_cast(lutGains.r())]; + params->green[i] = gammaTable[static_cast(lutGains.g())]; + params->blue[i] = gammaTable[static_cast(lutGains.b())]; } } diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h index 607af45a..6a285414 100644 --- a/src/ipa/simple/ipa_context.h +++ b/src/ipa/simple/ipa_context.h @@ -13,6 +13,8 @@ #include +#include "libcamera/internal/vector.h" + #include namespace libcamera { @@ -36,11 +38,7 @@ struct IPAActiveState { } blc; struct { - struct { - double red; - double green; - double blue; - } gains; + RGB gains; unsigned int temperatureK; } awb;