[{"id":20350,"web_url":"https://patchwork.libcamera.org/comment/20350/","msgid":"<YXDSxlYu7bZ+rDQI@pendragon.ideasonboard.com>","date":"2021-10-21T02:39:02","subject":"Re: [libcamera-devel] [PATCH v2 13/13] ipa: ipu3: Use sensor limits\n\tfor analogue gain","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jean-Michel,\n\nThank you for the patch.\n\nOn Wed, Oct 20, 2021 at 05:46:07PM +0200, Jean-Michel Hautbois wrote:\n> Instead of using constants for the analogue gains limits, use the\n> minimum and maximum from the configured sensor.\n> \n> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> ---\n>  src/ipa/ipu3/algorithms/agc.cpp | 25 +++++++++++++------------\n>  src/ipa/ipu3/algorithms/agc.h   |  3 +++\n>  2 files changed, 16 insertions(+), 12 deletions(-)\n> \n> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\n> index fc37eca4..690ad7e6 100644\n> --- a/src/ipa/ipu3/algorithms/agc.cpp\n> +++ b/src/ipa/ipu3/algorithms/agc.cpp\n> @@ -30,10 +30,9 @@ static constexpr uint32_t kInitialFrameMinAECount = 4;\n>  /* Number of frames to wait between new gain/exposure estimations */\n>  static constexpr uint32_t kFrameSkipCount = 6;\n>  \n> -/* Maximum analogue gain value\n> - * \\todo grab it from a camera helper */\n> -static constexpr double kMinGain = 1.0;\n> -static constexpr double kMaxGain = 8.0;\n> +/* Limits for analogue gain values */\n> +static constexpr double kMinAnalogueGain = 1.0;\n> +static constexpr double kMaxAnalogueGain = 16.0;\n\nShould we keep 8.0, or is there a reason to allow gains up to 16.0 ? It\nseems like it will add lots of noise.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  \n>  /* Histogram constants */\n>  static constexpr uint32_t knumHistogramBins = 256;\n> @@ -53,15 +52,17 @@ int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n>  \tlineDuration_ = configInfo.sensorInfo.lineLength * 1.0s\n>  \t\t      / configInfo.sensorInfo.pixelRate;\n>  \n> -\t/* Configure the default exposure and gain */\n> -\tcontext.frameContext.agc.gain =\n> -\t\tcontext.configuration.agc.minAnalogueGain;\n> -\tcontext.frameContext.agc.exposure = minExposureLines_;\n> -\n>  \t/* \\todo replace the exposure in lines storage with time based ones */\n>  \tminExposureLines_ = context.configuration.agc.minShutterSpeed / lineDuration_;\n>  \tmaxExposureLines_ = context.configuration.agc.maxShutterSpeed / lineDuration_;\n>  \n> +\tminAnalogueGain_ = std::max(context.configuration.agc.minAnalogueGain, kMinAnalogueGain);\n> +\tmaxAnalogueGain_ = std::min(context.configuration.agc.maxAnalogueGain, kMaxAnalogueGain);\n> +\n> +\t/* Configure the default exposure and gain */\n> +\tcontext.frameContext.agc.gain = minAnalogueGain_;\n> +\tcontext.frameContext.agc.exposure = minExposureLines_;\n> +\n>  \tprevExposureValue_ = context.frameContext.agc.gain\n>  \t\t\t   * context.frameContext.agc.exposure\n>  \t\t\t   * lineDuration_;\n> @@ -139,7 +140,7 @@ void Agc::lockExposureGain(uint32_t &exposure, double &analogueGain)\n>  \tutils::Duration minShutterSpeed = minExposureLines_ * lineDuration_;\n>  \tutils::Duration maxShutterSpeed = maxExposureLines_ * lineDuration_;\n>  \n> -\tutils::Duration maxTotalExposure = maxShutterSpeed * kMaxGain;\n> +\tutils::Duration maxTotalExposure = maxShutterSpeed * maxAnalogueGain_;\n>  \tcurrentExposure_ = std::min(currentExposure_, maxTotalExposure);\n>  \tLOG(IPU3Agc, Debug) << \"Target total exposure \" << currentExposure_\n>  \t\t\t    << \", maximum is \" << maxTotalExposure;\n> @@ -154,10 +155,10 @@ void Agc::lockExposureGain(uint32_t &exposure, double &analogueGain)\n>  \t* Push the shutter time up to the maximum first, and only then\n>  \t* increase the gain.\n>  \t*/\n> -\tshutterTime = std::clamp<utils::Duration>(exposureValue / kMinGain,\n> +\tshutterTime = std::clamp<utils::Duration>(exposureValue / minAnalogueGain_,\n>  \t\t\t\t\t\t  minShutterSpeed, maxShutterSpeed);\n>  \tdouble stepGain = std::clamp(exposureValue / shutterTime,\n> -\t\t\t\t     kMinGain, kMaxGain);\n> +\t\t\t\t     minAnalogueGain_, maxAnalogueGain_);\n>  \tLOG(IPU3Agc, Debug) << \"Divided up shutter and gain are \"\n>  \t\t\t    << shutterTime << \" and \"\n>  \t\t\t    << stepGain;\n> diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h\n> index ad133b98..1840205b 100644\n> --- a/src/ipa/ipu3/algorithms/agc.h\n> +++ b/src/ipa/ipu3/algorithms/agc.h\n> @@ -45,6 +45,9 @@ private:\n>  \tuint32_t minExposureLines_;\n>  \tuint32_t maxExposureLines_;\n>  \n> +\tdouble minAnalogueGain_;\n> +\tdouble maxAnalogueGain_;\n> +\n>  \tutils::Duration filteredExposure_;\n>  \tutils::Duration currentExposure_;\n>  \tutils::Duration prevExposureValue_;","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 1E89CBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 21 Oct 2021 02:39:24 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7BE6368F58;\n\tThu, 21 Oct 2021 04:39:23 +0200 (CEST)","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 5522260124\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 21 Oct 2021 04:39:22 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B9B15326;\n\tThu, 21 Oct 2021 04:39:21 +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=\"pMG31Wx+\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1634783962;\n\tbh=TcKoeo3h0U3GAwV1EbHvTeOU+W0EPyLcZAmbWgCaqLI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=pMG31Wx+csJ1cPD9Llr8eWNaNvUioPrgppUIzEKuW2EQMmVvPUcTD95p3qrixVNEr\n\tE0bhbEcuNrUJK1RiDwH9DKUW0ng3evLwnnTRvn+VE1Bc6XgWLsayLfinMInfhkrBST\n\tzJC35Z1zp7ZYTQfeYSQ8ReKA6Ak1Zn01EECBNNrg=","Date":"Thu, 21 Oct 2021 05:39:02 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","Message-ID":"<YXDSxlYu7bZ+rDQI@pendragon.ideasonboard.com>","References":"<20211020154607.180161-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20211020154607.180161-14-jeanmichel.hautbois@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211020154607.180161-14-jeanmichel.hautbois@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2 13/13] ipa: ipu3: Use sensor limits\n\tfor analogue gain","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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":20352,"web_url":"https://patchwork.libcamera.org/comment/20352/","msgid":"<1c5353dd-0ad5-caa4-c145-4e77e57f8160@ideasonboard.com>","date":"2021-10-21T05:45:44","subject":"Re: [libcamera-devel] [PATCH v2 13/13] ipa: ipu3: Use sensor limits\n\tfor analogue gain","submitter":{"id":75,"url":"https://patchwork.libcamera.org/api/people/75/","name":"Jean-Michel Hautbois","email":"jeanmichel.hautbois@ideasonboard.com"},"content":"Hi Laurent,\n\nOn 21/10/2021 04:39, Laurent Pinchart wrote:\n> Hi Jean-Michel,\n> \n> Thank you for the patch.\n> \n> On Wed, Oct 20, 2021 at 05:46:07PM +0200, Jean-Michel Hautbois wrote:\n>> Instead of using constants for the analogue gains limits, use the\n>> minimum and maximum from the configured sensor.\n>>\n>> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n>> ---\n>>   src/ipa/ipu3/algorithms/agc.cpp | 25 +++++++++++++------------\n>>   src/ipa/ipu3/algorithms/agc.h   |  3 +++\n>>   2 files changed, 16 insertions(+), 12 deletions(-)\n>>\n>> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\n>> index fc37eca4..690ad7e6 100644\n>> --- a/src/ipa/ipu3/algorithms/agc.cpp\n>> +++ b/src/ipa/ipu3/algorithms/agc.cpp\n>> @@ -30,10 +30,9 @@ static constexpr uint32_t kInitialFrameMinAECount = 4;\n>>   /* Number of frames to wait between new gain/exposure estimations */\n>>   static constexpr uint32_t kFrameSkipCount = 6;\n>>   \n>> -/* Maximum analogue gain value\n>> - * \\todo grab it from a camera helper */\n>> -static constexpr double kMinGain = 1.0;\n>> -static constexpr double kMaxGain = 8.0;\n>> +/* Limits for analogue gain values */\n>> +static constexpr double kMinAnalogueGain = 1.0;\n>> +static constexpr double kMaxAnalogueGain = 16.0;\n> \n> Should we keep 8.0, or is there a reason to allow gains up to 16.0 ? It\n> seems like it will add lots of noise.\n\nIt is a clamp value, there is only one sensor I tested which can do more \nthan 8.0 which is the ov5670 (I believe because of a broken driver). We \ncould keep 8.0 indeed.\n\n> \n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n>>   \n>>   /* Histogram constants */\n>>   static constexpr uint32_t knumHistogramBins = 256;\n>> @@ -53,15 +52,17 @@ int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n>>   \tlineDuration_ = configInfo.sensorInfo.lineLength * 1.0s\n>>   \t\t      / configInfo.sensorInfo.pixelRate;\n>>   \n>> -\t/* Configure the default exposure and gain */\n>> -\tcontext.frameContext.agc.gain =\n>> -\t\tcontext.configuration.agc.minAnalogueGain;\n>> -\tcontext.frameContext.agc.exposure = minExposureLines_;\n>> -\n>>   \t/* \\todo replace the exposure in lines storage with time based ones */\n>>   \tminExposureLines_ = context.configuration.agc.minShutterSpeed / lineDuration_;\n>>   \tmaxExposureLines_ = context.configuration.agc.maxShutterSpeed / lineDuration_;\n>>   \n>> +\tminAnalogueGain_ = std::max(context.configuration.agc.minAnalogueGain, kMinAnalogueGain);\n>> +\tmaxAnalogueGain_ = std::min(context.configuration.agc.maxAnalogueGain, kMaxAnalogueGain);\n>> +\n>> +\t/* Configure the default exposure and gain */\n>> +\tcontext.frameContext.agc.gain = minAnalogueGain_;\n>> +\tcontext.frameContext.agc.exposure = minExposureLines_;\n>> +\n>>   \tprevExposureValue_ = context.frameContext.agc.gain\n>>   \t\t\t   * context.frameContext.agc.exposure\n>>   \t\t\t   * lineDuration_;\n>> @@ -139,7 +140,7 @@ void Agc::lockExposureGain(uint32_t &exposure, double &analogueGain)\n>>   \tutils::Duration minShutterSpeed = minExposureLines_ * lineDuration_;\n>>   \tutils::Duration maxShutterSpeed = maxExposureLines_ * lineDuration_;\n>>   \n>> -\tutils::Duration maxTotalExposure = maxShutterSpeed * kMaxGain;\n>> +\tutils::Duration maxTotalExposure = maxShutterSpeed * maxAnalogueGain_;\n>>   \tcurrentExposure_ = std::min(currentExposure_, maxTotalExposure);\n>>   \tLOG(IPU3Agc, Debug) << \"Target total exposure \" << currentExposure_\n>>   \t\t\t    << \", maximum is \" << maxTotalExposure;\n>> @@ -154,10 +155,10 @@ void Agc::lockExposureGain(uint32_t &exposure, double &analogueGain)\n>>   \t* Push the shutter time up to the maximum first, and only then\n>>   \t* increase the gain.\n>>   \t*/\n>> -\tshutterTime = std::clamp<utils::Duration>(exposureValue / kMinGain,\n>> +\tshutterTime = std::clamp<utils::Duration>(exposureValue / minAnalogueGain_,\n>>   \t\t\t\t\t\t  minShutterSpeed, maxShutterSpeed);\n>>   \tdouble stepGain = std::clamp(exposureValue / shutterTime,\n>> -\t\t\t\t     kMinGain, kMaxGain);\n>> +\t\t\t\t     minAnalogueGain_, maxAnalogueGain_);\n>>   \tLOG(IPU3Agc, Debug) << \"Divided up shutter and gain are \"\n>>   \t\t\t    << shutterTime << \" and \"\n>>   \t\t\t    << stepGain;\n>> diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h\n>> index ad133b98..1840205b 100644\n>> --- a/src/ipa/ipu3/algorithms/agc.h\n>> +++ b/src/ipa/ipu3/algorithms/agc.h\n>> @@ -45,6 +45,9 @@ private:\n>>   \tuint32_t minExposureLines_;\n>>   \tuint32_t maxExposureLines_;\n>>   \n>> +\tdouble minAnalogueGain_;\n>> +\tdouble maxAnalogueGain_;\n>> +\n>>   \tutils::Duration filteredExposure_;\n>>   \tutils::Duration currentExposure_;\n>>   \tutils::Duration prevExposureValue_;\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 91701BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 21 Oct 2021 05:45:49 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 01A6368F58;\n\tThu, 21 Oct 2021 07:45:49 +0200 (CEST)","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 431DF60124\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 21 Oct 2021 07:45:47 +0200 (CEST)","from [IPV6:2a01:e0a:169:7140:f9d:5926:ad90:4996] (unknown\n\t[IPv6:2a01:e0a:169:7140:f9d:5926:ad90:4996])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D2D172BA;\n\tThu, 21 Oct 2021 07:45:46 +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=\"NBGR4jj6\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1634795146;\n\tbh=mZUoKFqHB/S4d76IKImMmMN6Kt+dGc6yn752e+hmJu8=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=NBGR4jj6UR8YXMXap6oQNGavJDEjWxaySslrpHWVD9ohme+dOu2s0w/Vii1+p553N\n\tSGqyEXm5QYKwXqO6SbfaHG+li3EfBLeQtbbfQCvgmF5bFPxb5Y5EO0rEbov+GNOWWi\n\tvbK2DT0jmvpV2DzsB1lEv50gxP7DKj/xxBYCmEJk=","Message-ID":"<1c5353dd-0ad5-caa4-c145-4e77e57f8160@ideasonboard.com>","Date":"Thu, 21 Oct 2021 07:45:44 +0200","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101\n\tThunderbird/91.1.2","Content-Language":"en-US","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","References":"<20211020154607.180161-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20211020154607.180161-14-jeanmichel.hautbois@ideasonboard.com>\n\t<YXDSxlYu7bZ+rDQI@pendragon.ideasonboard.com>","From":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","In-Reply-To":"<YXDSxlYu7bZ+rDQI@pendragon.ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH v2 13/13] ipa: ipu3: Use sensor limits\n\tfor analogue gain","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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]