[{"id":34202,"web_url":"https://patchwork.libcamera.org/comment/34202/","msgid":"<174705354159.521251.10316650001635354290@pyrite.rasen.tech>","date":"2025-05-12T12:39:01","subject":"Re: [PATCH 4/8] ipa: rkisp1: Add correction for exposure\n\tquantization","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Hi Stefan,\n\nThanks for the patch.\n\nQuoting Stefan Klug (2025-04-11 15:04:11)\n> When WDR regulation is active, it can happen that exposure times get set\n> to very low values (Sometimes 2-3 lines). This intentionally introduced\n> underexposure is corrected by the GWDR module. As exposure time is\n> quantized by lines, the smalles possible change in exposure time now\n\ns/smalles/smallest/\n\n> results in a quite visible change in perceived brightness.\n\nI see, at very low exposure then gainLostInExposureQuantization becomes quite\nsignificant. \n\n> Mitigate that by applying a small global gain to account for the error\n> introduced by the exposure quantization.\n\nAnd we want to set it globally in awb for lower latency as opposed to in the\nsensor, ok. I suppose this is how we'd do digital gain eventually too maybe.\n\n> ToDo: This needs perfect frame synchronous control of the sensor to work\n> properly which is not guaranteed in all cases. It still improves the\n> behavior with the current regulation.\n\nWould this be good to capture as a comment? Or maybe it's fine because it's a\ngeneral pfc problem. Either way is fine.\n\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> ---\n>  src/ipa/rkisp1/algorithms/agc.cpp |  2 ++\n>  src/ipa/rkisp1/algorithms/awb.cpp | 12 ++++++++----\n>  src/ipa/rkisp1/ipa_context.h      |  2 ++\n>  3 files changed, 12 insertions(+), 4 deletions(-)\n> \n> diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\n> index 8e77455e7afd..0e4fd3663167 100644\n> --- a/src/ipa/rkisp1/algorithms/agc.cpp\n> +++ b/src/ipa/rkisp1/algorithms/agc.cpp\n> @@ -583,6 +583,8 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n>         activeState.agc.automatic.exposure = newExposureTime / lineDuration;\n>         activeState.agc.automatic.gain = aGain;\n>  \n> +       activeState.agc.automatic.gainLostInExposureQuantization =\n\nDoesn't this need to be initialized to 1.0 in configure() ?\n\n\nPaul\n\n> +               newExposureTime / (activeState.agc.automatic.exposure * lineDuration);\n>         /*\n>          * Expand the target frame duration so that we do not run faster than\n>          * the minimum frame duration when we have short exposures.\n> diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp\n> index 84aa1d29419d..cc78136a22c8 100644\n> --- a/src/ipa/rkisp1/algorithms/awb.cpp\n> +++ b/src/ipa/rkisp1/algorithms/awb.cpp\n> @@ -170,6 +170,7 @@ void Awb::queueRequest(IPAContext &context,\n>         awbAlgo_->handleControls(controls);\n>  \n>         frameContext.awb.autoEnabled = awb.autoEnabled;\n> +       frameContext.awb.additionalGain = 1.0;\n>  \n>         if (awb.autoEnabled)\n>                 return;\n> @@ -218,15 +219,18 @@ void Awb::prepare(IPAContext &context, const uint32_t frame,\n>                 auto &awb = context.activeState.awb;\n>                 frameContext.awb.gains = awb.automatic.gains;\n>                 frameContext.awb.temperatureK = awb.automatic.temperatureK;\n> +               frameContext.awb.additionalGain =\n> +                       context.activeState.agc.automatic.gainLostInExposureQuantization;\n>         }\n>  \n> +       auto gains = frameContext.awb.gains * frameContext.awb.additionalGain;\n>         auto gainConfig = params->block<BlockType::AwbGain>();\n>         gainConfig.setEnabled(true);\n>  \n> -       gainConfig->gain_green_b = std::clamp<int>(256 * frameContext.awb.gains.g(), 0, 0x3ff);\n> -       gainConfig->gain_blue = std::clamp<int>(256 * frameContext.awb.gains.b(), 0, 0x3ff);\n> -       gainConfig->gain_red = std::clamp<int>(256 * frameContext.awb.gains.r(), 0, 0x3ff);\n> -       gainConfig->gain_green_r = std::clamp<int>(256 * frameContext.awb.gains.g(), 0, 0x3ff);\n> +       gainConfig->gain_green_b = std::clamp<int>(256 * gains.g(), 0, 0x3ff);\n> +       gainConfig->gain_blue = std::clamp<int>(256 * gains.b(), 0, 0x3ff);\n> +       gainConfig->gain_red = std::clamp<int>(256 * gains.r(), 0, 0x3ff);\n> +       gainConfig->gain_green_r = std::clamp<int>(256 * gains.g(), 0, 0x3ff);\n>  \n>         /* If we have already set the AWB measurement parameters, return. */\n>         if (frame > 0)\n> diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\n> index 7ccc7b501aff..182203880ac9 100644\n> --- a/src/ipa/rkisp1/ipa_context.h\n> +++ b/src/ipa/rkisp1/ipa_context.h\n> @@ -76,6 +76,7 @@ struct IPAActiveState {\n>                 } manual;\n>                 struct {\n>                         uint32_t exposure;\n> +                       double gainLostInExposureQuantization;\n>                         double gain;\n>                 } automatic;\n>  \n> @@ -149,6 +150,7 @@ struct IPAFrameContext : public FrameContext {\n>                 RGB<double> gains;\n>                 bool autoEnabled;\n>                 unsigned int temperatureK;\n> +               double additionalGain;\n>         } awb;\n>  \n>         struct {\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 88E0FC3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 12 May 2025 12:39:07 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E45FB68B40;\n\tMon, 12 May 2025 14:39:05 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 58055614E3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 May 2025 14:39:04 +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 3F77B4C9;\n\tMon, 12 May 2025 14:38:49 +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=\"KJ5+tOQC\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1747053529;\n\tbh=EQzM+Z0i5UaeMm4daCUrQMpaGSMsXGam2M9XlbeQ4uA=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=KJ5+tOQCQeq41OiYUmYICMpMnPCglg0RqV5+CkKM0jvar4EV3CB00xEKyCG04MbTT\n\tpad4STGVMkkPOf7fVoIyaFoZ2rbYw347Rj6orbNHXBSbIdmE8nuXOKXiPl5mLXOYb1\n\tclVQGedxrYQfwPctU/2OHDzyg2H92t5s0T53rEBA=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250411130423.2164577-5-stefan.klug@ideasonboard.com>","References":"<20250411130423.2164577-1-stefan.klug@ideasonboard.com>\n\t<20250411130423.2164577-5-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH 4/8] ipa: rkisp1: Add correction for exposure\n\tquantization","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 14:39:01 +0200","Message-ID":"<174705354159.521251.10316650001635354290@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>"}}]