[{"id":36918,"web_url":"https://patchwork.libcamera.org/comment/36918/","msgid":"<176356172959.1127434.2961337798503122678@ping.linuxembedded.co.uk>","date":"2025-11-19T14:15:29","subject":"Re: [PATCH v3 2/4] ipa: rkisp1: lux: Properly handle frame context\n\tand active state","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-11-19 13:22:11)\n> WIth the upcoming regulation rework the processing order in the IPA is\n\ns/WIth/With/\n\n> updated a bit so that process() updates the active state with new\n> measurements and fills the metadata with the data from the corresponding\n> frame context. In prepare() all parameters for one frame are tied\n> together using the most up to date values from active state.\n> \n> Change the lux algorithm to support that order of events. Also prepare\n> for cases where stats can be null which can happen with the upcoming\n> regulation rework.\n> \n> While at it fix a formatting issue reported by checkstyle and drop a\n> unnecessary local variable.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> \n> ---\n> \n> Changes in v3:\n> - Added this patch in response to the comment from Kieran in\n>   https://patchwork.libcamera.org/patch/24982/#36740\n> ---\n>  src/ipa/rkisp1/algorithms/lux.cpp | 23 ++++++++++++++++++-----\n>  src/ipa/rkisp1/algorithms/lux.h   |  3 +++\n>  src/ipa/rkisp1/ipa_context.h      |  4 ++++\n>  3 files changed, 25 insertions(+), 5 deletions(-)\n> \n> diff --git a/src/ipa/rkisp1/algorithms/lux.cpp b/src/ipa/rkisp1/algorithms/lux.cpp\n> index e8da69810008..bc714b7a82c6 100644\n> --- a/src/ipa/rkisp1/algorithms/lux.cpp\n> +++ b/src/ipa/rkisp1/algorithms/lux.cpp\n> @@ -46,6 +46,16 @@ int Lux::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData\n>         return lux_.parseTuningData(tuningData);\n>  }\n>  \n> +/**\n> + * \\copydoc libcamera::ipa::Algorithm::prepare\n> + */\n> +void Lux::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n> +                 IPAFrameContext &frameContext,\n> +                 [[maybe_unused]] RkISP1Params *params)\n> +{\n> +       frameContext.lux.lux = context.activeState.lux.lux;\n\nI'm worried that this is predicting the physics of the future ;-)\nBut that's because my mental model of how all of this works is out of\ndate.\n\nWhat I would do to get a slideshow presentation with animations of how\nall the pieces move around for the IPA in general ;-)\n\nDo we know any good animators?\n\n\n\n> +}\n> +\n>  /**\n>   * \\copydoc libcamera::ipa::Algorithm::process\n>   */\n> @@ -55,8 +65,13 @@ void Lux::process(IPAContext &context,\n>                   const rkisp1_stat_buffer *stats,\n>                   ControlList &metadata)\n>  {\n> -       utils::Duration exposureTime = context.configuration.sensor.lineDuration\n> -                                    * frameContext.sensor.exposure;\n> +       metadata.set(controls::Lux, frameContext.lux.lux);\n\nI think if this line stays here - we need a banner comment saying \"This\nis reporting the lux level that was used at the time of\npreparing the algorithms. Otherwise brains will break in the time\ndilation distortion....\n\nPerhaps just:\n\n\t/*\n\t * Report the lux level used by algorithms to prepare this frame\n\t * not the lux level *of* this frame.\n\t */\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> +\n> +       if (!stats)\n> +               return;\n> +\n> +       utils::Duration exposureTime = context.configuration.sensor.lineDuration *\n> +                                      frameContext.sensor.exposure;\n>         double gain = frameContext.sensor.gain;\n>  \n>         /* \\todo Deduplicate the histogram calculation from AGC */\n> @@ -64,9 +79,7 @@ void Lux::process(IPAContext &context,\n>         Histogram yHist({ params->hist.hist_bins, context.hw.numHistogramBins },\n>                         [](uint32_t x) { return x >> 4; });\n>  \n> -       double lux = lux_.estimateLux(exposureTime, gain, 1.0, yHist);\n> -       frameContext.lux.lux = lux;\n> -       metadata.set(controls::Lux, lux);\n> +       context.activeState.lux.lux = lux_.estimateLux(exposureTime, gain, 1.0, yHist);\n>  }\n>  \n>  REGISTER_IPA_ALGORITHM(Lux, \"Lux\")\n> diff --git a/src/ipa/rkisp1/algorithms/lux.h b/src/ipa/rkisp1/algorithms/lux.h\n> index 8dcadc284a84..e0239848e252 100644\n> --- a/src/ipa/rkisp1/algorithms/lux.h\n> +++ b/src/ipa/rkisp1/algorithms/lux.h\n> @@ -23,6 +23,9 @@ public:\n>         Lux();\n>  \n>         int init(IPAContext &context, const YamlObject &tuningData) override;\n> +       void prepare(IPAContext &context, const uint32_t frame,\n> +                    IPAFrameContext &frameContext,\n> +                    RkISP1Params *params) override;\n>         void process(IPAContext &context, const uint32_t frame,\n>                      IPAFrameContext &frameContext,\n>                      const rkisp1_stat_buffer *stats,\n> diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\n> index f85a130d9c23..b257cee55379 100644\n> --- a/src/ipa/rkisp1/ipa_context.h\n> +++ b/src/ipa/rkisp1/ipa_context.h\n> @@ -133,6 +133,10 @@ struct IPAActiveState {\n>                 double gamma;\n>         } goc;\n>  \n> +       struct {\n> +               double lux;\n> +       } lux;\n> +\n>         struct {\n>                 controls::WdrModeEnum mode;\n>                 AgcMeanLuminance::AgcConstraint constraint;\n> -- \n> 2.51.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 DAA78BD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 19 Nov 2025 14:15:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E117060A8B;\n\tWed, 19 Nov 2025 15:15:34 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3116B606A0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 19 Nov 2025 15:15:33 +0100 (CET)","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 5240FDD9;\n\tWed, 19 Nov 2025 15:13:28 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"H+kHcYAa\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1763561608;\n\tbh=VSvTgf3FS4yGn64UoDDSK6DeBQQjscqVV66Lh0qGURs=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=H+kHcYAaV55LSp1eOcAsDS0Hbfoaj44I9OMMAeclzI+hNPRhgBIg+d1cuW0YIDqBN\n\tgMdInnUyKkOMJ6BFwE5KIvYT2pe69tCm4Mq7LlV6uAzFNaAWqKOGMBhxTdFcoPfz70\n\ttdVYetfUcJakwmlm8cOwgMDWpn+SL6Uc/ywJhH6k=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20251119132221.2088013-3-stefan.klug@ideasonboard.com>","References":"<20251119132221.2088013-1-stefan.klug@ideasonboard.com>\n\t<20251119132221.2088013-3-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v3 2/4] ipa: rkisp1: lux: Properly handle frame context\n\tand active state","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":"Wed, 19 Nov 2025 14:15:29 +0000","Message-ID":"<176356172959.1127434.2961337798503122678@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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>"}}]