{"id":24798,"url":"https://patchwork.libcamera.org/api/patches/24798/?format=json","web_url":"https://patchwork.libcamera.org/patch/24798/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20251024085130.995967-33-stefan.klug@ideasonboard.com>","date":"2025-10-24T08:50:56","name":"[v1,32/35] WIP: rkisp1: agc: Add digital gain","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"9a432c67507cae242087f2cf5f65d66dfeed8615","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/?format=json","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/24798/mbox/","series":[{"id":5524,"url":"https://patchwork.libcamera.org/api/series/5524/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5524","date":"2025-10-24T08:50:24","name":"rkisp1: pipeline rework for PFC","version":1,"mbox":"https://patchwork.libcamera.org/series/5524/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/24798/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/24798/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 37722BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 24 Oct 2025 08:53:17 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EF71960963;\n\tFri, 24 Oct 2025 10:53:16 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 069A460938\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Oct 2025 10:53:16 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:7edc:62f4:c118:1549])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 6978A4B21; \n\tFri, 24 Oct 2025 10:51:30 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"V6xCDXc7\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1761295890;\n\tbh=I0b9uqNMOZGYBj1FqNrnQcqrUz1g8S0QfRsDzYkpU/M=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=V6xCDXc7MK8pTxyZ7Q5+BgPsu5Kds/CAX5iyJNCzg+wUK5QEFfZoacX92ChzD9psM\n\thfVqR1YXEi0VJwd6ERkzPdIDkPyvR38CHyAL/6CreH9vH4IdehF+GISH0K7OB2asyy\n\tVKdLqU3XKgbwLe4tRm4cu0WP95RA6MiSniNz9HRU=","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","Subject":"[PATCH v1 32/35] WIP: rkisp1: agc: Add digital gain","Date":"Fri, 24 Oct 2025 10:50:56 +0200","Message-ID":"<20251024085130.995967-33-stefan.klug@ideasonboard.com>","X-Mailer":"git-send-email 2.48.1","In-Reply-To":"<20251024085130.995967-1-stefan.klug@ideasonboard.com>","References":"<20251024085130.995967-1-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Add a manual only digital gain control.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n---\n src/ipa/rkisp1/algorithms/agc.cpp | 22 ++++++++++++++++++++--\n src/ipa/rkisp1/ipa_context.h      |  2 ++\n 2 files changed, 22 insertions(+), 2 deletions(-)","diff":"diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\nindex 7629066b9876..71ad3a01d90c 100644\n--- a/src/ipa/rkisp1/algorithms/agc.cpp\n+++ b/src/ipa/rkisp1/algorithms/agc.cpp\n@@ -158,6 +158,7 @@ int Agc::init(IPAContext &context, const YamlObject &tuningData)\n \t/* \\todo Move this to the Camera class */\n \tcontext.ctrlMap[&controls::AeEnable] = ControlInfo(false, true, true);\n \tcontext.ctrlMap[&controls::ExposureValue] = ControlInfo(-8.0f, 8.0f, 0.0f);\n+\tcontext.ctrlMap[&controls::DigitalGain] = ControlInfo(1.0f, 64.0f, 1.0f);\n \tcontext.ctrlMap.merge(controls());\n \n \treturn 0;\n@@ -179,6 +180,7 @@ int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)\n \tcontext.activeState.agc.automatic.quantizationGain = 1.0;\n \tcontext.activeState.agc.manual.gain = context.activeState.agc.automatic.gain;\n \tcontext.activeState.agc.manual.exposure = context.activeState.agc.automatic.exposure;\n+\tcontext.activeState.agc.manual.digitalGain = 1.0;\n \tcontext.activeState.agc.autoExposureEnabled = !context.configuration.raw;\n \tcontext.activeState.agc.autoGainEnabled = !context.configuration.raw;\n \tcontext.activeState.agc.exposureValue = 0.0;\n@@ -281,6 +283,15 @@ void Agc::queueRequest(IPAContext &context,\n \t\tLOG(RkISP1Agc, Debug) << \"Set gain to \" << agc.manual.gain;\n \t}\n \n+\tconst auto &digitalGain = controls.get(controls::DigitalGain);\n+\tif (digitalGain) {\n+\t\tagc.manual.digitalGain = *digitalGain;\n+\n+\t\tLOG(RkISP1Agc, Debug) << \"Set digital gain to \" << agc.manual.digitalGain;\n+\t}\n+\n+\tframeContext.agc.digitalGain = agc.manual.digitalGain;\n+\n \tframeContext.agc.autoExposureEnabled = agc.autoExposureEnabled;\n \tframeContext.agc.autoGainEnabled = agc.autoGainEnabled;\n \n@@ -381,7 +392,7 @@ void Agc::prepare(IPAContext &context, const uint32_t frame,\n \n \tif (context.configuration.compress.supported) {\n \t\tframeContext.compress.enable = true;\n-\t\tframeContext.compress.gain = frameContext.agc.quantizationGain;\n+\t\tframeContext.compress.gain = frameContext.agc.quantizationGain * frameContext.agc.digitalGain;\n \t}\n \n \tframeContext.agc.yTarget = context.activeState.agc.automatic.yTarget;\n@@ -469,7 +480,14 @@ void Agc::fillMetadata(IPAContext &context, IPAFrameContext &frameContext,\n \tmetadata.set(controls::AeConstraintMode, frameContext.agc.constraintMode);\n \tmetadata.set(controls::ExposureValue, frameContext.agc.exposureValue);\n \n-\tmetadata.set(controls::DigitalGain, frameContext.agc.quantizationGain);\n+\t/*\n+\t * \\todo Add the quantization gain to the digital gain metadata, so that\n+\t * we don't apply any hidden gains. This might however create issues\n+\t * with applications trying to match a digital gain control with the\n+\t * metadata.\n+\t */\n+\tmetadata.set(controls::DigitalGain,\n+\t\t     frameContext.agc.quantizationGain * frameContext.agc.digitalGain);\n }\n \n /**\ndiff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\nindex 185951fb8286..ba320b9e3e92 100644\n--- a/src/ipa/rkisp1/ipa_context.h\n+++ b/src/ipa/rkisp1/ipa_context.h\n@@ -79,6 +79,7 @@ struct IPAActiveState {\n \t\tstruct {\n \t\t\tuint32_t exposure;\n \t\t\tdouble gain;\n+\t\t\tdouble digitalGain;\n \t\t} manual;\n \t\tstruct {\n \t\t\tuint32_t exposure;\n@@ -160,6 +161,7 @@ struct IPAFrameContext : public FrameContext {\n \t\tbool updateMetering;\n \t\tbool autoExposureModeChange;\n \t\tbool autoGainModeChange;\n+\t\tdouble digitalGain;\n \t} agc;\n \n \tstruct {\n","prefixes":["v1","32/35"]}