From patchwork Fri Oct 18 14:12:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 21678 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 5F142C32AF for ; Fri, 18 Oct 2024 14:12:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E82DF65390; Fri, 18 Oct 2024 16:12:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="UnedXMl6"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 780A1633C7 for ; Fri, 18 Oct 2024 16:12:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729260773; 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=3hZJJLmYTWm1UwQqDZvSjDIm8JP9eB9aG7yKCReA0xc=; b=UnedXMl6hPQ2TROY4X9+YhSPn2vu3C6Rvuc+OnzWKhi7IrHUdmNd+dXM5wWe+jPG5BRCKp yj8/lglqlsCKV7B4jjaGTa/t5DwTPR2fre3yCWoeEmMF8zxUzkcHVFVKcZ9aVJnOWIcofm Jj5LGRExfLVVXzgqkmZ6bCAkzifRDcs= Received: from mx-prod-mc-02.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-686-V_lvWWSvO2SrRC6jCpjZtw-1; Fri, 18 Oct 2024 10:12:52 -0400 X-MC-Unique: V_lvWWSvO2SrRC6jCpjZtw-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E460919560A7; Fri, 18 Oct 2024 14:12:50 +0000 (UTC) Received: from nuthatch.redhat.com (unknown [10.45.225.61]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 995BC1955EAB; Fri, 18 Oct 2024 14:12:48 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Daniel Scally , Kieran Bingham , Robert Mader Subject: [PATCH v6 1/2] libcamera: software_isp: Get black level from the camera helper Date: Fri, 18 Oct 2024 16:12:36 +0200 Message-ID: <20241018141241.948698-2-mzamazal@redhat.com> In-Reply-To: <20241018141241.948698-1-mzamazal@redhat.com> References: <20241018141241.948698-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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" The black level in software ISP is unconditionally guessed from the obtained frames. CameraSensorHelper optionally provides the black level from camera specifications now. Let's use the value if available. If the black level is not available from the given CameraSensorHelper instance, it's still determined on the fly. Signed-off-by: Milan Zamazal Reviewed-by: Kieran Bingham Tested-by: Robert Mader --- src/ipa/simple/algorithms/blc.cpp | 6 +++++- src/ipa/simple/ipa_context.h | 4 ++++ src/ipa/simple/soft_simple.cpp | 10 ++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/ipa/simple/algorithms/blc.cpp b/src/ipa/simple/algorithms/blc.cpp index b9f2aaa6d..a7af2e12c 100644 --- a/src/ipa/simple/algorithms/blc.cpp +++ b/src/ipa/simple/algorithms/blc.cpp @@ -24,7 +24,8 @@ BlackLevel::BlackLevel() int BlackLevel::configure(IPAContext &context, [[maybe_unused]] const IPAConfigInfo &configInfo) { - context.activeState.blc.level = 255; + context.activeState.blc.level = + context.configuration.black.level.value_or(255); return 0; } @@ -34,6 +35,9 @@ void BlackLevel::process(IPAContext &context, const SwIspStats *stats, [[maybe_unused]] ControlList &metadata) { + if (context.configuration.black.level.has_value()) + return; + if (frameContext.sensor.exposure == exposure_ && frameContext.sensor.gain == gain_) { return; diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h index 3519f20f6..fd121eebe 100644 --- a/src/ipa/simple/ipa_context.h +++ b/src/ipa/simple/ipa_context.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include @@ -22,6 +23,9 @@ struct IPASessionConfiguration { int32_t exposureMin, exposureMax; double againMin, againMax, againMinStep; } agc; + struct { + std::optional level; + } black; }; struct IPAActiveState { diff --git a/src/ipa/simple/soft_simple.cpp b/src/ipa/simple/soft_simple.cpp index b28c7039f..e96e65bd1 100644 --- a/src/ipa/simple/soft_simple.cpp +++ b/src/ipa/simple/soft_simple.cpp @@ -201,6 +201,16 @@ int IPASoftSimple::configure(const IPAConfigInfo &configInfo) (context_.configuration.agc.againMax - context_.configuration.agc.againMin) / 100.0; + if (camHelper_->blackLevel().has_value()) { + /* + * The black level from camHelper_ is a 16 bit value, software ISP + * works with 8 bit pixel values, both regardless of the actual + * sensor pixel width. Hence we obtain the pixel-based black value + * by dividing the value from the helper by 256. + */ + context_.configuration.black.level = + camHelper_->blackLevel().value() / 256; + } } else { /* * The camera sensor gain (g) is usually not equal to the value written From patchwork Fri Oct 18 14:12:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 21679 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 7E0BCC32AF for ; Fri, 18 Oct 2024 14:13:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1F32965392; Fri, 18 Oct 2024 16:13:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="KCdcbq0A"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EE9406538A for ; Fri, 18 Oct 2024 16:12:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729260778; 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=EEZ+B/UVPYXndgHgbDQcXLxw5iqIACdXZ6S+NUjzvkI=; b=KCdcbq0ATPD0EHtEpIZMVgkZziZzVeQNxP7zPJ10YVffYBSn0wpOvSps8cAFVh3I2TS46F eN8kq1ERDfj4zLLQxIAPDoOJoIz1B0SRTaY7U7kKzuwO8QJUVBTm4CMp9YEf+MbEXIfzhZ ci9cgdwh9V7oKoMAPhMQIHqJOCetSGM= Received: from mx-prod-mc-01.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-146-rTSRtwuhNX2zf2WlCv2NQQ-1; Fri, 18 Oct 2024 10:12:54 -0400 X-MC-Unique: rTSRtwuhNX2zf2WlCv2NQQ-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 924FB1955D42; Fri, 18 Oct 2024 14:12:53 +0000 (UTC) Received: from nuthatch.redhat.com (unknown [10.45.225.61]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8CCB419560A2; Fri, 18 Oct 2024 14:12:51 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Daniel Scally , Kieran Bingham , Robert Mader Subject: [PATCH v6 2/2] libcamera: software_isp: Black level from tuning file Date: Fri, 18 Oct 2024 16:12:37 +0200 Message-ID: <20241018141241.948698-3-mzamazal@redhat.com> In-Reply-To: <20241018141241.948698-1-mzamazal@redhat.com> References: <20241018141241.948698-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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" This patch allows obtaining a black level from a tuning file in addition to the camera sensor helper. If both of them define a black level, the one from the tuning file takes precedence. The use cases are: - A user wants to use a different black level, for whatever reason. - There is a sensor without known gains but with a known black level. Because a camera sensor helper cannot be defined without specifying gains, the only way to specify the black level is using the tuning file. Software ISP uses its fallback gain handling in such a case. Signed-off-by: Milan Zamazal Reviewed-by: Kieran Bingham --- src/ipa/simple/algorithms/blc.cpp | 13 +++++++++++++ src/ipa/simple/algorithms/blc.h | 1 + src/ipa/simple/soft_simple.cpp | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ipa/simple/algorithms/blc.cpp b/src/ipa/simple/algorithms/blc.cpp index a7af2e12c..b4e32fe1c 100644 --- a/src/ipa/simple/algorithms/blc.cpp +++ b/src/ipa/simple/algorithms/blc.cpp @@ -21,6 +21,19 @@ BlackLevel::BlackLevel() { } +int BlackLevel::init(IPAContext &context, const YamlObject &tuningData) +{ + auto blackLevel = tuningData["blackLevel"].get(); + if (blackLevel.has_value()) { + /* + * Convert 16 bit values from the tuning file to 8 bit black + * level for the SoftISP. + */ + context.configuration.black.level = blackLevel.value() >> 8; + } + return 0; +} + int BlackLevel::configure(IPAContext &context, [[maybe_unused]] const IPAConfigInfo &configInfo) { diff --git a/src/ipa/simple/algorithms/blc.h b/src/ipa/simple/algorithms/blc.h index 828ad8b18..2cf2a8774 100644 --- a/src/ipa/simple/algorithms/blc.h +++ b/src/ipa/simple/algorithms/blc.h @@ -19,6 +19,7 @@ public: BlackLevel(); ~BlackLevel() = default; + int init(IPAContext &context, const YamlObject &tuningData) override; int configure(IPAContext &context, const IPAConfigInfo &configInfo) override; void process(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, diff --git a/src/ipa/simple/soft_simple.cpp b/src/ipa/simple/soft_simple.cpp index e96e65bd1..03525b2f2 100644 --- a/src/ipa/simple/soft_simple.cpp +++ b/src/ipa/simple/soft_simple.cpp @@ -201,7 +201,8 @@ int IPASoftSimple::configure(const IPAConfigInfo &configInfo) (context_.configuration.agc.againMax - context_.configuration.agc.againMin) / 100.0; - if (camHelper_->blackLevel().has_value()) { + if (!context_.configuration.black.level.has_value() && + camHelper_->blackLevel().has_value()) { /* * The black level from camHelper_ is a 16 bit value, software ISP * works with 8 bit pixel values, both regardless of the actual