[{"id":33686,"web_url":"https://patchwork.libcamera.org/comment/33686/","msgid":"<3898e25d-e007-40aa-90fb-22af252484e8@ideasonboard.com>","date":"2025-03-24T07:37:50","subject":"Re: [PATCH 1/2] ipa: rkisp1: agc: Fix metering modes","submitter":{"id":156,"url":"https://patchwork.libcamera.org/api/people/156/","name":"Dan Scally","email":"dan.scally@ideasonboard.com"},"content":"Hi Stefan\n\nOn 19/03/2025 16:01, Stefan Klug wrote:\n> The weights for a given metering mode are applied to the histogram data\n> inside the histogram statistics block. The AE statistics do not contain\n> any weights. Therefore the weights are honored when AgcMeanLuminance\n> calculates the upper or lower constraints, but ignored in the\n> calculation of the frame luminance. Fix that by manually applying the\n> weights in the luminance calculation.\n>\n> Fixes: 4c5152843a2a (\"ipa: rkisp1: Derive rkisp1::algorithms::Agc from AgcMeanLuminance\")\n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> ---\n\nLooks good to me:\n\n\nReviewed-by: Daniel Scally <dan.scally@ideasonboard.com>\n\n>   src/ipa/rkisp1/algorithms/agc.cpp | 13 ++++++++++---\n>   src/ipa/rkisp1/algorithms/agc.h   |  1 +\n>   2 files changed, 11 insertions(+), 3 deletions(-)\n>\n> diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\n> index 5a3ba0131cf1..101cad5d0893 100644\n> --- a/src/ipa/rkisp1/algorithms/agc.cpp\n> +++ b/src/ipa/rkisp1/algorithms/agc.cpp\n> @@ -439,15 +439,20 @@ void Agc::fillMetadata(IPAContext &context, IPAFrameContext &frameContext,\n>    */\n>   double Agc::estimateLuminance(double gain) const\n>   {\n> +\tASSERT(expMeans_.size() == weights_.size());\n>   \tdouble ySum = 0.0;\n> +\tdouble wSum = 0.0;\n>   \n>   \t/* Sum the averages, saturated to 255. */\n> -\tfor (uint8_t expMean : expMeans_)\n> -\t\tySum += std::min(expMean * gain, 255.0);\n> +\tfor (unsigned i = 0; i < expMeans_.size(); i++) {\n> +\t\tdouble w = weights_[i];\n> +\t\tySum += std::min(expMeans_[i] * gain, 255.0) * w;\n> +\t\twSum += w;\n> +\t}\n>   \n>   \t/* \\todo Weight with the AWB gains */\n>   \n> -\treturn ySum / expMeans_.size() / 255;\n> +\treturn ySum / wSum / 255;\n>   }\n>   \n>   /**\n> @@ -515,6 +520,8 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n>   \tHistogram hist({ params->hist.hist_bins, context.hw->numHistogramBins },\n>   \t\t       [](uint32_t x) { return x >> 4; });\n>   \texpMeans_ = { params->ae.exp_mean, context.hw->numAeCells };\n> +\tstd::vector<uint8_t> &modeWeights = meteringModes_.at(frameContext.agc.meteringMode);\n> +\tweights_ = { modeWeights.data(), modeWeights.size() };\n>   \n>   \t/*\n>   \t * Set the AGC limits using the fixed exposure time and/or gain in\n> diff --git a/src/ipa/rkisp1/algorithms/agc.h b/src/ipa/rkisp1/algorithms/agc.h\n> index 62bcde999fe3..7867eed9c4e3 100644\n> --- a/src/ipa/rkisp1/algorithms/agc.h\n> +++ b/src/ipa/rkisp1/algorithms/agc.h\n> @@ -55,6 +55,7 @@ private:\n>   \t\t\t\t  utils::Duration frameDuration);\n>   \n>   \tSpan<const uint8_t> expMeans_;\n> +\tSpan<const uint8_t> weights_;\n>   \n>   \tstd::map<int32_t, std::vector<uint8_t>> meteringModes_;\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 B5F3BBD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 24 Mar 2025 07:37:56 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D86AB68951;\n\tMon, 24 Mar 2025 08:37:55 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 258DD61868\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 24 Mar 2025 08:37:53 +0100 (CET)","from [192.168.0.43]\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B5489455\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 24 Mar 2025 08:36:06 +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=\"b2OAdX09\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1742801766;\n\tbh=/twOZet91/6lfWvILhYeW5R6Eo0Hy/Y/vXf4MGPTCEM=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=b2OAdX09qx1XgIGoQbZ1K31QRlB4YpZDmNuJoBIRUc3vaN72nIn5mLGpipfo8pY/J\n\tuepxWkDHb9js6FHsVg+bXrjPkPuCBmlwZKkdrnB+yNrNTfJkASCmR5bdpVPi3YUgsy\n\t/PaJxWJC3Aj0iWAnD8rT4rnm5ZQUroN4IE5pqTiE=","Message-ID":"<3898e25d-e007-40aa-90fb-22af252484e8@ideasonboard.com>","Date":"Mon, 24 Mar 2025 07:37:50 +0000","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH 1/2] ipa: rkisp1: agc: Fix metering modes","To":"libcamera-devel@lists.libcamera.org","References":"<20250319160146.61751-1-stefan.klug@ideasonboard.com>\n\t<20250319160146.61751-2-stefan.klug@ideasonboard.com>","Content-Language":"en-US","From":"Dan Scally <dan.scally@ideasonboard.com>","Autocrypt":"addr=dan.scally@ideasonboard.com; keydata=\n\txsFNBGLydl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ain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","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":33697,"web_url":"https://patchwork.libcamera.org/comment/33697/","msgid":"<174289792672.670680.9402975314057572515@ping.linuxembedded.co.uk>","date":"2025-03-25T10:18:46","subject":"Re: [PATCH 1/2] ipa: rkisp1: agc: Fix metering modes","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-03-19 16:01:36)\n> The weights for a given metering mode are applied to the histogram data\n> inside the histogram statistics block. The AE statistics do not contain\n> any weights. Therefore the weights are honored when AgcMeanLuminance\n> calculates the upper or lower constraints, but ignored in the\n> calculation of the frame luminance. Fix that by manually applying the\n> weights in the luminance calculation.\n> \n> Fixes: 4c5152843a2a (\"ipa: rkisp1: Derive rkisp1::algorithms::Agc from AgcMeanLuminance\")\n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> ---\n>  src/ipa/rkisp1/algorithms/agc.cpp | 13 ++++++++++---\n>  src/ipa/rkisp1/algorithms/agc.h   |  1 +\n>  2 files changed, 11 insertions(+), 3 deletions(-)\n> \n> diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\n> index 5a3ba0131cf1..101cad5d0893 100644\n> --- a/src/ipa/rkisp1/algorithms/agc.cpp\n> +++ b/src/ipa/rkisp1/algorithms/agc.cpp\n> @@ -439,15 +439,20 @@ void Agc::fillMetadata(IPAContext &context, IPAFrameContext &frameContext,\n>   */\n>  double Agc::estimateLuminance(double gain) const\n>  {\n> +       ASSERT(expMeans_.size() == weights_.size());\n>         double ySum = 0.0;\n> +       double wSum = 0.0;\n>  \n>         /* Sum the averages, saturated to 255. */\n> -       for (uint8_t expMean : expMeans_)\n> -               ySum += std::min(expMean * gain, 255.0);\n> +       for (unsigned i = 0; i < expMeans_.size(); i++) {\n> +               double w = weights_[i];\n> +               ySum += std::min(expMeans_[i] * gain, 255.0) * w;\n> +               wSum += w;\n> +       }\n>  \n>         /* \\todo Weight with the AWB gains */\n>  \n> -       return ySum / expMeans_.size() / 255;\n> +       return ySum / wSum / 255;\n>  }\n>  \n>  /**\n> @@ -515,6 +520,8 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n>         Histogram hist({ params->hist.hist_bins, context.hw->numHistogramBins },\n>                        [](uint32_t x) { return x >> 4; });\n>         expMeans_ = { params->ae.exp_mean, context.hw->numAeCells };\n> +       std::vector<uint8_t> &modeWeights = meteringModes_.at(frameContext.agc.meteringMode);\n\nWhere do the weights come from? Are they always guaranteed to be\navailable at this point ?\n\n> +       weights_ = { modeWeights.data(), modeWeights.size() };\n>  \n>         /*\n>          * Set the AGC limits using the fixed exposure time and/or gain in\n> diff --git a/src/ipa/rkisp1/algorithms/agc.h b/src/ipa/rkisp1/algorithms/agc.h\n> index 62bcde999fe3..7867eed9c4e3 100644\n> --- a/src/ipa/rkisp1/algorithms/agc.h\n> +++ b/src/ipa/rkisp1/algorithms/agc.h\n> @@ -55,6 +55,7 @@ private:\n>                                   utils::Duration frameDuration);\n>  \n>         Span<const uint8_t> expMeans_;\n> +       Span<const uint8_t> weights_;\n>  \n>         std::map<int32_t, std::vector<uint8_t>> meteringModes_;\n>  };\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 75F69C0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 25 Mar 2025 10:18:53 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 97A1568951;\n\tTue, 25 Mar 2025 11:18:52 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AD99E614E9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 25 Mar 2025 11:18:50 +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 15752E45;\n\tTue, 25 Mar 2025 11:17:03 +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=\"bNUhoTWY\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1742897823;\n\tbh=IQA4ehC7pWOm181LVsqoUe9ndmy7AlE0eKvNU8bz4vQ=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=bNUhoTWYgxofymAofLSqazm9p+tHQokWXnreLjT+s7VoAis9rSHmNwAtYw3t/3AA5\n\trKlGxhADWE/0MtygxvAOsG5TXdzpvB+Z9g4YnzkqKAHxkrTgz5vQDTmVKVK/NfYA5G\n\tYeHfMwnmx+Uy/A2AnjNe7jCXHLvJl/NoJyohqY1k=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250319160146.61751-2-stefan.klug@ideasonboard.com>","References":"<20250319160146.61751-1-stefan.klug@ideasonboard.com>\n\t<20250319160146.61751-2-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH 1/2] ipa: rkisp1: agc: Fix metering modes","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":"Tue, 25 Mar 2025 10:18:46 +0000","Message-ID":"<174289792672.670680.9402975314057572515@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":33698,"web_url":"https://patchwork.libcamera.org/comment/33698/","msgid":"<174291077630.3394313.17705727626581864673@ping.linuxembedded.co.uk>","date":"2025-03-25T13:52:56","subject":"Re: [PATCH 1/2] ipa: rkisp1: agc: Fix metering modes","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-03-25 13:46:12)\n> Hi Kieran,\n> \n> Thank you for the review.\n> \n> On Tue, Mar 25, 2025 at 10:18:46AM +0000, Kieran Bingham wrote:\n> > Quoting Stefan Klug (2025-03-19 16:01:36)\n> > > The weights for a given metering mode are applied to the histogram data\n> > > inside the histogram statistics block. The AE statistics do not contain\n> > > any weights. Therefore the weights are honored when AgcMeanLuminance\n> > > calculates the upper or lower constraints, but ignored in the\n> > > calculation of the frame luminance. Fix that by manually applying the\n> > > weights in the luminance calculation.\n> > > \n> > > Fixes: 4c5152843a2a (\"ipa: rkisp1: Derive rkisp1::algorithms::Agc from AgcMeanLuminance\")\n> > > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> > > ---\n> > >  src/ipa/rkisp1/algorithms/agc.cpp | 13 ++++++++++---\n> > >  src/ipa/rkisp1/algorithms/agc.h   |  1 +\n> > >  2 files changed, 11 insertions(+), 3 deletions(-)\n> > > \n> > > diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\n> > > index 5a3ba0131cf1..101cad5d0893 100644\n> > > --- a/src/ipa/rkisp1/algorithms/agc.cpp\n> > > +++ b/src/ipa/rkisp1/algorithms/agc.cpp\n> > > @@ -439,15 +439,20 @@ void Agc::fillMetadata(IPAContext &context, IPAFrameContext &frameContext,\n> > >   */\n> > >  double Agc::estimateLuminance(double gain) const\n> > >  {\n> > > +       ASSERT(expMeans_.size() == weights_.size());\n> > >         double ySum = 0.0;\n> > > +       double wSum = 0.0;\n> > >  \n> > >         /* Sum the averages, saturated to 255. */\n> > > -       for (uint8_t expMean : expMeans_)\n> > > -               ySum += std::min(expMean * gain, 255.0);\n> > > +       for (unsigned i = 0; i < expMeans_.size(); i++) {\n> > > +               double w = weights_[i];\n> > > +               ySum += std::min(expMeans_[i] * gain, 255.0) * w;\n> > > +               wSum += w;\n> > > +       }\n> > >  \n> > >         /* \\todo Weight with the AWB gains */\n> > >  \n> > > -       return ySum / expMeans_.size() / 255;\n> > > +       return ySum / wSum / 255;\n> > >  }\n> > >  \n> > >  /**\n> > > @@ -515,6 +520,8 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n> > >         Histogram hist({ params->hist.hist_bins, context.hw->numHistogramBins },\n> > >                        [](uint32_t x) { return x >> 4; });\n> > >         expMeans_ = { params->ae.exp_mean, context.hw->numAeCells };\n> > > +       std::vector<uint8_t> &modeWeights = meteringModes_.at(frameContext.agc.meteringMode);\n> > \n> > Where do the weights come from? Are they always guaranteed to be\n> > available at this point ?\n> \n> The weights come from the tuning file. The libtuning agc module contains\n> hardcoded values for centre weighted, spot and matrix. If there are no\n> metering modes in the tuning file, a matrix mode is generated within\n> parseMeteringModes().  So yes, they are always available at this point.\n\nThen I'm happy:\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> \n> Best regards,\n> Stefan\n> \n> > \n> > > +       weights_ = { modeWeights.data(), modeWeights.size() };\n> > >  \n> > >         /*\n> > >          * Set the AGC limits using the fixed exposure time and/or gain in\n> > > diff --git a/src/ipa/rkisp1/algorithms/agc.h b/src/ipa/rkisp1/algorithms/agc.h\n> > > index 62bcde999fe3..7867eed9c4e3 100644\n> > > --- a/src/ipa/rkisp1/algorithms/agc.h\n> > > +++ b/src/ipa/rkisp1/algorithms/agc.h\n> > > @@ -55,6 +55,7 @@ private:\n> > >                                   utils::Duration frameDuration);\n> > >  \n> > >         Span<const uint8_t> expMeans_;\n> > > +       Span<const uint8_t> weights_;\n> > >  \n> > >         std::map<int32_t, std::vector<uint8_t>> meteringModes_;\n> > >  };\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 679A8C3213\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 25 Mar 2025 13:53:02 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3242A68955;\n\tTue, 25 Mar 2025 14:53:01 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 79992600EB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 25 Mar 2025 14:52:59 +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 30312353;\n\tTue, 25 Mar 2025 14:51:12 +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=\"rKzS4mJJ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1742910672;\n\tbh=hH8bbNhAFBTzVrRMLxc6V/hhEEXKOR7YjQZJE7H2Tas=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=rKzS4mJJC17SlHuyeOtOaH7liW4ZXAz53i6Ek0Nf+anzyUvmmsEWgGXJQjNa70V0o\n\t6DAoYgzkBhVX06HBBAvfJEMz8YTeg4tiRlvGA35v9lP3/G55GrzjzvmkaTRGCqvDRZ\n\tJz5a9oi+RXodbqnKsEPSZiHMPth2fY2BVAkubd+o=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<47aha3dsrunys2tddb75h6uwa534l4wzpi7ftw5eovsmvdczef@kn6zta33h3c6>","References":"<20250319160146.61751-1-stefan.klug@ideasonboard.com>\n\t<20250319160146.61751-2-stefan.klug@ideasonboard.com>\n\t<174289792672.670680.9402975314057572515@ping.linuxembedded.co.uk>\n\t<47aha3dsrunys2tddb75h6uwa534l4wzpi7ftw5eovsmvdczef@kn6zta33h3c6>","Subject":"Re: [PATCH 1/2] ipa: rkisp1: agc: Fix metering modes","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Date":"Tue, 25 Mar 2025 13:52:56 +0000","Message-ID":"<174291077630.3394313.17705727626581864673@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>"}}]