From patchwork Fri Nov 20 11:42:33 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danius Kalvaitis X-Patchwork-Id: 29061 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 AC13AC3361 for ; Fri, 20 Nov 2026 11:43:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 98E756A93E; Fri, 20 Nov 2026 12:43:03 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=kurokesu.com header.i=@kurokesu.com header.b="qq4xHCTs"; dkim-atps=neutral Received: from srv2.kurokesu.com (srv2.kurokesu.com [89.47.166.45]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 696FC6A7EA for ; Fri, 20 Nov 2026 12:42:59 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by srv2.kurokesu.com (Postfix) with ESMTP id F1F937D28; Fri, 20 Nov 2026 13:42:58 +0200 (EET) Authentication-Results: srv2.kurokesu.com (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=kurokesu.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kurokesu.com; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from; s= default; t=1795174978; x=1796989379; bh=cwbEpjNSTe/VM4BLw0AFJD5d xUr7cvtd2Vayfk2qOvY=; b=qq4xHCTsBYXUM4BiJO1diYmGwKWJtFEkMxXKG5yN LWApUytNrn9zd5GtNLoSvUNJ+9x3OY6baVRXl81K3C6lksYC/+tw3RUY6TLSfumS tTkNmsZdVQR37rwlS81lr7d2yp6soNcEmMO73wRuvuYTj4BwYHOQVxJao2c2wc42 /VU= X-Virus-Scanned: Debian amavisd-new at srv2.kurokesu.com Received: from srv2.kurokesu.com ([127.0.0.1]) by localhost (srv2.kurokesu.com [127.0.0.1]) (amavisd-new, port 10026) with LMTP id pWZhDcM2KMup; Fri, 20 Nov 2026 13:42:58 +0200 (EET) Received: from shelfpi.vpn2.kurokesu.com (unknown [84.15.183.117]) (Authenticated sender: danius@kurokesu.com) by srv2.kurokesu.com (Postfix) with ESMTPSA id D4BF57D2A; Fri, 20 Nov 2026 13:42:57 +0200 (EET) From: Danius Kalvaitis To: libcamera-devel@lists.libcamera.org Cc: naush@raspberrypi.com, david.plowman@raspberrypi.com, laurent.pinchart@ideasonboard.com, jai.luthra@ideasonboard.com, aso.fam429@gmail.com, Danius Kalvaitis Subject: [PATCH 2/2] ipa: rpi: Get decompand curve from camera helper Date: Fri, 20 Nov 2026 13:42:33 +0200 Message-ID: <20261120114233.86270-3-danius@kurokesu.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261120114233.86270-1-danius@kurokesu.com> References: <20261120114233.86270-1-danius@kurokesu.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" Decompand curve is a sensor property and can depend on sensor mode, for example with sensor HDR enabled. The tuning file curve is currently selected by bit depth only and cannot follow a mode change that keeps bit depth. Add CamHelper::decompandCurve() to return the curve of a camera mode. It takes precedence over the tuning file one, which remains as fallback. rpi.decompand block is still needed to enable the algorithm but its decompand_curve entry is now optional. Signed-off-by: Danius Kalvaitis --- Tested on a Raspberry Pi CM5 with imx585 in 12-bit Clear HDR mode and an out-of-tree camera helper that returns the curve. Without a decompand curve AGC reads the scene about 24 times brighter than in linear mode. With the helper curve it meters within 4% of linear mode. A tuning file curve is still used when the helper returns none. Linear mode is unchanged. src/ipa/rpi/cam_helper/cam_helper.cpp | 5 +++++ src/ipa/rpi/cam_helper/cam_helper.h | 5 +++++ src/ipa/rpi/cam_helper/meson.build | 1 + src/ipa/rpi/common/ipa_base.cpp | 1 + src/ipa/rpi/common/meson.build | 1 + src/ipa/rpi/controller/camera_mode.h | 4 ++++ src/ipa/rpi/controller/rpi/decompand.cpp | 27 ++++++++++++++++-------- src/ipa/rpi/controller/rpi/decompand.h | 2 +- 8 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/ipa/rpi/cam_helper/cam_helper.cpp b/src/ipa/rpi/cam_helper/cam_helper.cpp index a480de004..12fbd05a0 100644 --- a/src/ipa/rpi/cam_helper/cam_helper.cpp +++ b/src/ipa/rpi/cam_helper/cam_helper.cpp @@ -177,6 +177,11 @@ double CamHelper::getModeSensitivity([[maybe_unused]] const CameraMode &mode) co return 1.0; } +ipa::Pwl CamHelper::decompandCurve([[maybe_unused]] const CameraMode &mode) const +{ + return {}; +} + unsigned int CamHelper::hideFramesStartup() const { /* diff --git a/src/ipa/rpi/cam_helper/cam_helper.h b/src/ipa/rpi/cam_helper/cam_helper.h index bbaf57a1f..78bf501ef 100644 --- a/src/ipa/rpi/cam_helper/cam_helper.h +++ b/src/ipa/rpi/cam_helper/cam_helper.h @@ -13,6 +13,8 @@ #include +#include + #include "controller/camera_mode.h" #include "controller/controller.h" #include "controller/metadata.h" @@ -40,6 +42,8 @@ namespace RPiController { * * A function to return the sensitivity of a given camera mode. * + * A function to return the decompand curve of a given camera mode. + * * A parser to parse the embedded data buffers provided by some sensors (for * example, the imx219 does; the ov5647 doesn't). This allows us to know for * sure the exposure and gain of the frame we're looking at. CamHelper @@ -94,6 +98,7 @@ public: virtual double gain(uint32_t gainCode) const = 0; virtual bool sensorEmbeddedDataPresent() const; virtual double getModeSensitivity(const CameraMode &mode) const; + virtual libcamera::ipa::Pwl decompandCurve(const CameraMode &mode) const; virtual unsigned int hideFramesStartup() const; virtual unsigned int hideFramesModeSwitch() const; virtual unsigned int mistrustMetadataStartup() const; diff --git a/src/ipa/rpi/cam_helper/meson.build b/src/ipa/rpi/cam_helper/meson.build index 6935cecf8..6c0c87bdb 100644 --- a/src/ipa/rpi/cam_helper/meson.build +++ b/src/ipa/rpi/cam_helper/meson.build @@ -24,6 +24,7 @@ rpi_ipa_cam_helper_sources = files([ rpi_ipa_cam_helper_includes = [ include_directories('..'), + libipa_includes, ] rpi_ipa_cam_helper_deps = [ diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp index 319d6bf44..c23c04fb4 100644 --- a/src/ipa/rpi/common/ipa_base.cpp +++ b/src/ipa/rpi/common/ipa_base.cpp @@ -216,6 +216,7 @@ int32_t IpaBase::configure(const IPACameraSensorInfo &sensorInfo, const ConfigPa mode_.transform = static_cast(params.transform); mode_.sensorHdr = params.sensorHdr; + mode_.decompandCurve = helper_->decompandCurve(mode_); /* Pass the camera mode to the CamHelper to setup algorithms. */ helper_->setCameraMode(mode_); diff --git a/src/ipa/rpi/common/meson.build b/src/ipa/rpi/common/meson.build index 73d2ee732..e4f804d70 100644 --- a/src/ipa/rpi/common/meson.build +++ b/src/ipa/rpi/common/meson.build @@ -6,6 +6,7 @@ rpi_ipa_common_sources = files([ rpi_ipa_common_includes = [ include_directories('..'), + libipa_includes, ] rpi_ipa_common_deps = [ diff --git a/src/ipa/rpi/controller/camera_mode.h b/src/ipa/rpi/controller/camera_mode.h index 5eb05705e..9c908ac16 100644 --- a/src/ipa/rpi/controller/camera_mode.h +++ b/src/ipa/rpi/controller/camera_mode.h @@ -10,6 +10,8 @@ #include +#include + /* * Description of a "camera mode", holding enough information for control * algorithms to adapt their behaviour to the different modes of the camera, @@ -58,4 +60,6 @@ struct CameraMode { double maxAnalogueGain; /* sensor HDR state */ bool sensorHdr; + /* decompand curve of this mode */ + libcamera::ipa::Pwl decompandCurve; }; diff --git a/src/ipa/rpi/controller/rpi/decompand.cpp b/src/ipa/rpi/controller/rpi/decompand.cpp index 185e06f91..ccf7ec0d9 100644 --- a/src/ipa/rpi/controller/rpi/decompand.cpp +++ b/src/ipa/rpi/controller/rpi/decompand.cpp @@ -27,8 +27,14 @@ char const *Decompand::name() const int Decompand::read(const libcamera::ValueNode ¶ms) { config_.bitdepth = params["bitdepth"].get(0); - config_.decompandCurve = params["decompand_curve"].get(ipa::Pwl{}); - return config_.decompandCurve.empty() ? -EINVAL : 0; + + if (params.contains("decompand_curve")) { + config_.decompandCurve = params["decompand_curve"].get(ipa::Pwl{}); + if (config_.decompandCurve.empty()) + return -EINVAL; + } + + return 0; } void Decompand::initialise() @@ -38,23 +44,26 @@ void Decompand::initialise() void Decompand::switchMode(CameraMode const &cameraMode, [[maybe_unused]] Metadata *metadata) { - mode_ = cameraMode; + /* Camera helper curve takes precedence over the tuning file. */ + if (!cameraMode.decompandCurve.empty()) + curve_ = cameraMode.decompandCurve; + else if (config_.bitdepth == 0 || cameraMode.bitdepth == config_.bitdepth) + curve_ = config_.decompandCurve; + else + curve_ = {}; } void Decompand::initialValues(libcamera::ipa::Pwl &decompandCurve) { - if (config_.bitdepth == 0 || mode_.bitdepth == config_.bitdepth) { - decompandCurve = config_.decompandCurve; - } else - decompandCurve = {}; + decompandCurve = curve_; } void Decompand::prepare(Metadata *imageMetadata) { DecompandStatus decompandStatus; - if (config_.bitdepth == 0 || mode_.bitdepth == config_.bitdepth) { - decompandStatus.decompandCurve = config_.decompandCurve; + if (!curve_.empty()) { + decompandStatus.decompandCurve = curve_; imageMetadata->set("decompand.status", decompandStatus); } } diff --git a/src/ipa/rpi/controller/rpi/decompand.h b/src/ipa/rpi/controller/rpi/decompand.h index 1a53de245..8e58f3ad7 100644 --- a/src/ipa/rpi/controller/rpi/decompand.h +++ b/src/ipa/rpi/controller/rpi/decompand.h @@ -25,8 +25,8 @@ public: void prepare(Metadata *imageMetadata) override; private: - CameraMode mode_; DecompandConfig config_; + libcamera::ipa::Pwl curve_; }; } /* namespace RPiController */