From patchwork Fri Sep 27 13:46:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 21408 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 AB0F1C3257 for ; Fri, 27 Sep 2024 13:47:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4F96A63539; Fri, 27 Sep 2024 15:47:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="SWxaFVYv"; 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 9F8F063529 for ; Fri, 27 Sep 2024 15:47:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727444833; 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=IZA+la+cP0x0ZgQIv5P6iy3VhCrcN7t/N+1wUC5/BY4=; b=SWxaFVYvKqSxYePiHS8hibL7UNn5F7yzxJT1b7XHvSiIWJ7ZwqM7E5dxcImpiFx3qoOVmy 2qdM2V+iPNEW7TherUiIyFSJ0nplbrj6a3QkLGvmcrypkfFOgW/jw9hn49ZykINddD/6i/ UKUSLCHF1skPOIHOz+RtUJOkkk93G00= 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-83-hqVpr_-DONOAdH94qNLd2Q-1; Fri, 27 Sep 2024 09:47:11 -0400 X-MC-Unique: hqVpr_-DONOAdH94qNLd2Q-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.40]) (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 7731718B0692; Fri, 27 Sep 2024 13:47:09 +0000 (UTC) Received: from nuthatch.redhat.com (unknown [10.45.224.123]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 35B761956054; Fri, 27 Sep 2024 13:47:06 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Umang Jain , Laurent Pinchart , Daniel Scally , Kieran Bingham Subject: [PATCH v8 15/18] libcamera: software_isp: Use floating point for color parameters Date: Fri, 27 Sep 2024 15:46:21 +0200 Message-ID: <20240927134624.801004-16-mzamazal@redhat.com> In-Reply-To: <20240927134624.801004-1-mzamazal@redhat.com> References: <20240927134624.801004-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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" It's more natural to represent color gains as floating point numbers rather than using a particular pixel-related representation. double is used rather than float because it's a more common floating point type in libcamera algorithms. Otherwise there is no obvious reason to select one over the other here. The constructed color tables still use integer representation for efficiency. Black level still uses pixel (integer) values, for consistency with other libcamera parts. Signed-off-by: Milan Zamazal Reviewed-by: Kieran Bingham Reviewed-by: Umang Jain --- src/ipa/simple/algorithms/awb.cpp | 9 ++++----- src/ipa/simple/algorithms/lut.cpp | 13 ++++++++----- src/ipa/simple/ipa_context.h | 6 +++--- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/ipa/simple/algorithms/awb.cpp b/src/ipa/simple/algorithms/awb.cpp index 3d76cc2f7..195de41dc 100644 --- a/src/ipa/simple/algorithms/awb.cpp +++ b/src/ipa/simple/algorithms/awb.cpp @@ -24,7 +24,7 @@ int Awb::configure(IPAContext &context, [[maybe_unused]] const IPAConfigInfo &configInfo) { auto &gains = context.activeState.gains; - gains.red = gains.green = gains.blue = 256; + gains.red = gains.green = gains.blue = 1.0; return 0; } @@ -53,12 +53,11 @@ void Awb::process(IPAContext &context, /* * Calculate red and blue gains for AWB. * Clamp max gain at 4.0, this also avoids 0 division. - * Gain: 128 = 0.5, 256 = 1.0, 512 = 2.0, etc. */ auto &gains = context.activeState.gains; - gains.red = sumR <= sumG / 4 ? 1024 : 256 * sumG / sumR; - gains.blue = sumB <= sumG / 4 ? 1024 : 256 * sumG / sumB; - /* Green gain is fixed to 256 */ + 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 */ LOG(IPASoftAwb, Debug) << "gain R/B " << gains.red << "/" << gains.blue; } diff --git a/src/ipa/simple/algorithms/lut.cpp b/src/ipa/simple/algorithms/lut.cpp index 644b4f84a..9744e773a 100644 --- a/src/ipa/simple/algorithms/lut.cpp +++ b/src/ipa/simple/algorithms/lut.cpp @@ -63,15 +63,18 @@ void Lut::prepare(IPAContext &context, const unsigned int gammaTableSize = gammaTable.size(); for (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++) { - const unsigned int div = static_cast(DebayerParams::kRGBLookupSize) * - 256 / gammaTableSize; + const double div = static_cast(DebayerParams::kRGBLookupSize) / + gammaTableSize; /* Apply gamma after gain! */ unsigned int idx; - idx = std::min({ i * gains.red / div, gammaTableSize - 1 }); + idx = std::min({ static_cast(i * gains.red / div), + gammaTableSize - 1 }); params->red[i] = gammaTable[idx]; - idx = std::min({ i * gains.green / div, gammaTableSize - 1 }); + idx = std::min({ static_cast(i * gains.green / div), + gammaTableSize - 1 }); params->green[i] = gammaTable[idx]; - idx = std::min({ i * gains.blue / div, gammaTableSize - 1 }); + idx = std::min({ static_cast(i * gains.blue / div), + gammaTableSize - 1 }); params->blue[i] = gammaTable[idx]; } } diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h index 737bbbc37..cf1ef3fd8 100644 --- a/src/ipa/simple/ipa_context.h +++ b/src/ipa/simple/ipa_context.h @@ -26,9 +26,9 @@ struct IPAActiveState { } blc; struct { - unsigned int red; - unsigned int green; - unsigned int blue; + double red; + double green; + double blue; } gains; static constexpr unsigned int kGammaLookupSize = 1024;