[{"id":33938,"web_url":"https://patchwork.libcamera.org/comment/33938/","msgid":"<174456650955.3333606.11427465827526106112@ping.linuxembedded.co.uk>","date":"2025-04-13T17:48:29","subject":"Re: [PATCH v2 9/9] ipa: rkisp1: agc: Implement ExposureValue control","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-04-11 13:36:37)\n> Now that agc_mean_luminance supports exposure correction, implement the\n> corresponding ExposureValue control for rkisp1.\n\nDefinitely looking forward to the control initialisation and handling of\ncontext/state somehow being managed by the agc_mean_luminence algorithm\ndirectly sometime so that all of the users of agc_mean_luminence also\ncan support this control.\n\nShould we already add this to IPU3 and Mali-C55 explicitly?\n\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  src/ipa/rkisp1/algorithms/agc.cpp | 10 ++++++++++\n>  src/ipa/rkisp1/ipa_context.h      |  2 ++\n>  2 files changed, 12 insertions(+)\n> \n> diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\n> index b3ac9400b74f..8e77455e7afd 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>                             ControlValue(controls::AnalogueGainModeAuto));\n>         /* \\todo Move this to the Camera class */\n>         context.ctrlMap[&controls::AeEnable] = ControlInfo(false, true, true);\n> +       context.ctrlMap[&controls::ExposureValue] = ControlInfo(-8.0f, 8.0f, 0.0f);\n>         context.ctrlMap.merge(controls());\n>  \n>         return 0;\n> @@ -180,6 +181,7 @@ int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)\n>         context.activeState.agc.manual.exposure = context.activeState.agc.automatic.exposure;\n>         context.activeState.agc.autoExposureEnabled = !context.configuration.raw;\n>         context.activeState.agc.autoGainEnabled = !context.configuration.raw;\n> +       context.activeState.agc.exposureValue = 0.0;\n>  \n>         context.activeState.agc.constraintMode =\n>                 static_cast<controls::AeConstraintModeEnum>(constraintModes().begin()->first);\n> @@ -302,6 +304,11 @@ void Agc::queueRequest(IPAContext &context,\n>                         static_cast<controls::AeConstraintModeEnum>(*constraintMode);\n>         frameContext.agc.constraintMode = agc.constraintMode;\n>  \n> +       const auto &exposureValue = controls.get(controls::ExposureValue);\n> +       if (exposureValue)\n> +               agc.exposureValue = *exposureValue;\n> +       frameContext.agc.exposureValue = agc.exposureValue;\n> +\n>         const auto &frameDurationLimits = controls.get(controls::FrameDurationLimits);\n>         if (frameDurationLimits) {\n>                 /* Limit the control value to the limits in ControlInfo */\n> @@ -408,6 +415,7 @@ void Agc::fillMetadata(IPAContext &context, IPAFrameContext &frameContext,\n>         metadata.set(controls::AeMeteringMode, frameContext.agc.meteringMode);\n>         metadata.set(controls::AeExposureMode, frameContext.agc.exposureMode);\n>         metadata.set(controls::AeConstraintMode, frameContext.agc.constraintMode);\n> +       metadata.set(controls::ExposureValue, frameContext.agc.exposureValue);\n>  }\n>  \n>  /**\n> @@ -557,6 +565,8 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n>         double analogueGain = frameContext.sensor.gain;\n>         utils::Duration effectiveExposureValue = exposureTime * analogueGain;\n>  \n> +       setExposureCompensation(pow(2.0, frameContext.agc.exposureValue));\n> +\n>         utils::Duration newExposureTime;\n>         double aGain, dGain;\n>         std::tie(newExposureTime, aGain, dGain) =\n> diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\n> index f0d504215d34..7ccc7b501aff 100644\n> --- a/src/ipa/rkisp1/ipa_context.h\n> +++ b/src/ipa/rkisp1/ipa_context.h\n> @@ -81,6 +81,7 @@ struct IPAActiveState {\n>  \n>                 bool autoExposureEnabled;\n>                 bool autoGainEnabled;\n> +               double exposureValue;\n>                 controls::AeConstraintModeEnum constraintMode;\n>                 controls::AeExposureModeEnum exposureMode;\n>                 controls::AeMeteringModeEnum meteringMode;\n> @@ -129,6 +130,7 @@ struct IPAFrameContext : public FrameContext {\n>         struct {\n>                 uint32_t exposure;\n>                 double gain;\n> +               double exposureValue;\n>                 uint32_t vblank;\n>                 bool autoExposureEnabled;\n>                 bool autoGainEnabled;\n> -- \n> 2.43.0\n>","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 BE879C327D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 13 Apr 2025 17:48:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D0F2D68AB4;\n\tSun, 13 Apr 2025 19:48:34 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 06BC468A99\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 13 Apr 2025 19:48:33 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DC67D520;\n\tSun, 13 Apr 2025 19:46:31 +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=\"peq1nVMn\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1744566391;\n\tbh=/Vrxb5S524RYhVJZOGt+A8VjUsvZ7XLCPb0Fkhy2liY=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=peq1nVMnse92P+dqoiqNs/r0r0wtzJvA7QXjkOpuZTuORA2rnz6fkSZ9Lv6kEWtSd\n\tly4gSkJl+ld7LkXHZbWPR9hEnMFLhn7qIeV4s81OYie7elWr35aiUMxdONLm5/y9Zb\n\toQCj9EB+/fhsxUVOXvWoljs4GdKZXFdwWw0Xt5mI=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250411123641.2144530-10-stefan.klug@ideasonboard.com>","References":"<20250411123641.2144530-1-stefan.klug@ideasonboard.com>\n\t<20250411123641.2144530-10-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v2 9/9] ipa: rkisp1: agc: Implement ExposureValue control","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Sun, 13 Apr 2025 18:48:29 +0100","Message-ID":"<174456650955.3333606.11427465827526106112@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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>"}},{"id":34195,"web_url":"https://patchwork.libcamera.org/comment/34195/","msgid":"<174700477800.116187.9359055383187446578@pyrite.rasen.tech>","date":"2025-05-11T23:06:18","subject":"Re: [PATCH v2 9/9] ipa: rkisp1: agc: Implement ExposureValue control","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-04-11 14:36:37)\n> Now that agc_mean_luminance supports exposure correction, implement the\n> corresponding ExposureValue control for rkisp1.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  src/ipa/rkisp1/algorithms/agc.cpp | 10 ++++++++++\n>  src/ipa/rkisp1/ipa_context.h      |  2 ++\n>  2 files changed, 12 insertions(+)\n> \n> diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\n> index b3ac9400b74f..8e77455e7afd 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>                             ControlValue(controls::AnalogueGainModeAuto));\n>         /* \\todo Move this to the Camera class */\n>         context.ctrlMap[&controls::AeEnable] = ControlInfo(false, true, true);\n> +       context.ctrlMap[&controls::ExposureValue] = ControlInfo(-8.0f, 8.0f, 0.0f);\n>         context.ctrlMap.merge(controls());\n>  \n>         return 0;\n> @@ -180,6 +181,7 @@ int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)\n>         context.activeState.agc.manual.exposure = context.activeState.agc.automatic.exposure;\n>         context.activeState.agc.autoExposureEnabled = !context.configuration.raw;\n>         context.activeState.agc.autoGainEnabled = !context.configuration.raw;\n> +       context.activeState.agc.exposureValue = 0.0;\n>  \n>         context.activeState.agc.constraintMode =\n>                 static_cast<controls::AeConstraintModeEnum>(constraintModes().begin()->first);\n> @@ -302,6 +304,11 @@ void Agc::queueRequest(IPAContext &context,\n>                         static_cast<controls::AeConstraintModeEnum>(*constraintMode);\n>         frameContext.agc.constraintMode = agc.constraintMode;\n>  \n> +       const auto &exposureValue = controls.get(controls::ExposureValue);\n> +       if (exposureValue)\n> +               agc.exposureValue = *exposureValue;\n> +       frameContext.agc.exposureValue = agc.exposureValue;\n> +\n>         const auto &frameDurationLimits = controls.get(controls::FrameDurationLimits);\n>         if (frameDurationLimits) {\n>                 /* Limit the control value to the limits in ControlInfo */\n> @@ -408,6 +415,7 @@ void Agc::fillMetadata(IPAContext &context, IPAFrameContext &frameContext,\n>         metadata.set(controls::AeMeteringMode, frameContext.agc.meteringMode);\n>         metadata.set(controls::AeExposureMode, frameContext.agc.exposureMode);\n>         metadata.set(controls::AeConstraintMode, frameContext.agc.constraintMode);\n> +       metadata.set(controls::ExposureValue, frameContext.agc.exposureValue);\n>  }\n>  \n>  /**\n> @@ -557,6 +565,8 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n>         double analogueGain = frameContext.sensor.gain;\n>         utils::Duration effectiveExposureValue = exposureTime * analogueGain;\n>  \n> +       setExposureCompensation(pow(2.0, frameContext.agc.exposureValue));\n> +\n>         utils::Duration newExposureTime;\n>         double aGain, dGain;\n>         std::tie(newExposureTime, aGain, dGain) =\n> diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\n> index f0d504215d34..7ccc7b501aff 100644\n> --- a/src/ipa/rkisp1/ipa_context.h\n> +++ b/src/ipa/rkisp1/ipa_context.h\n> @@ -81,6 +81,7 @@ struct IPAActiveState {\n>  \n>                 bool autoExposureEnabled;\n>                 bool autoGainEnabled;\n> +               double exposureValue;\n>                 controls::AeConstraintModeEnum constraintMode;\n>                 controls::AeExposureModeEnum exposureMode;\n>                 controls::AeMeteringModeEnum meteringMode;\n> @@ -129,6 +130,7 @@ struct IPAFrameContext : public FrameContext {\n>         struct {\n>                 uint32_t exposure;\n>                 double gain;\n> +               double exposureValue;\n>                 uint32_t vblank;\n>                 bool autoExposureEnabled;\n>                 bool autoGainEnabled;\n> -- \n> 2.43.0\n>","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 A19EAC3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 11 May 2025 23:06:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6913B68B60;\n\tMon, 12 May 2025 01:06:22 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9494268B60\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 May 2025 01:06:20 +0200 (CEST)","from pyrite.rasen.tech (unknown\n\t[IPv6:2001:861:3a80:3300:4f2f:8c2c:b3ef:17d4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C9D25605;\n\tMon, 12 May 2025 01:06:05 +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=\"QUr7t5Sm\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1747004765;\n\tbh=ZN0eVQN9KJeMV+63DWkvvHs/GHOFXkkEA8RugLnPe7U=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=QUr7t5SmNcAp9ckrg4oCG3fvTJDLtSeVz82EbTeEm2TKW2k27GJSGVLZmtvbsvJ6e\n\tTMvdJxVJhKlJgfA9qUJ59/kbPoZmB4YvcBKyfopr8rfGRNH2AWPxJso4UeFrumz1PO\n\tHodL7u1FWbDYbIsHYCOKbBbQ6cNFPD7BJ36MUFus=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250411123641.2144530-10-stefan.klug@ideasonboard.com>","References":"<20250411123641.2144530-1-stefan.klug@ideasonboard.com>\n\t<20250411123641.2144530-10-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v2 9/9] ipa: rkisp1: agc: Implement ExposureValue control","From":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 12 May 2025 01:06:18 +0200","Message-ID":"<174700477800.116187.9359055383187446578@pyrite.rasen.tech>","User-Agent":"alot/0.0.0","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>"}}]