[{"id":20721,"web_url":"https://patchwork.libcamera.org/comment/20721/","msgid":"<163638521602.275423.5956759091507808263@Monstersaurus>","date":"2021-11-08T15:26:56","subject":"Re: [libcamera-devel] [PATCH 09/22] ipa: ipu3: agc: Use exposure in\n\ttime for storage","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Jean-Michel Hautbois (2021-11-08 13:13:37)\n> The minimum and maximum exposure are stored in lines. Replace it by\n> values in time, which removes a bit of code.\n\ns/, which removes a bit of code/ to simplify the calculations./ ?\n\n\n> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> ---\n>  src/ipa/ipu3/algorithms/agc.cpp | 21 +++++++++------------\n>  src/ipa/ipu3/algorithms/agc.h   |  4 ++--\n>  2 files changed, 11 insertions(+), 14 deletions(-)\n> \n> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\n> index 475e715f..3a15f5d9 100644\n> --- a/src/ipa/ipu3/algorithms/agc.cpp\n> +++ b/src/ipa/ipu3/algorithms/agc.cpp\n> @@ -68,8 +68,8 @@ static constexpr uint32_t kMinCellsPerZoneRatio = 255 * 20 / 100;\n>  static constexpr uint32_t kNumStartupFrames = 10;\n>  \n>  Agc::Agc()\n> -       : frameCount_(0), iqMean_(0.0), lineDuration_(0s), minExposureLines_(0),\n> -         maxExposureLines_(0), filteredExposure_(0s), currentExposure_(0s),\n> +       : frameCount_(0), iqMean_(0.0), lineDuration_(0s), minShutterSpeed_(0s),\n> +         maxShutterSpeed_(0s), filteredExposure_(0s), currentExposure_(0s),\n>           prevExposureValue_(0s)\n>  {\n>  }\n> @@ -89,17 +89,16 @@ int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n>         lineDuration_ = configInfo.sensorInfo.lineLength * 1.0s\n>                       / configInfo.sensorInfo.pixelRate;\n>  \n> -       /* \\todo replace the exposure in lines storage with time based ones. */\n> -       minExposureLines_ = context.configuration.agc.minShutterSpeed / lineDuration_;\n> -       maxExposureLines_ = std::min(context.configuration.agc.maxShutterSpeed / lineDuration_,\n> -                                    kMaxShutterSpeed / lineDuration_);\n> +       minShutterSpeed_ = context.configuration.agc.minShutterSpeed;\n> +       maxShutterSpeed_ = std::min(context.configuration.agc.maxShutterSpeed,\n> +                                   kMaxShutterSpeed);\n>  \n>         minAnalogueGain_ = std::max(context.configuration.agc.minAnalogueGain, kMinAnalogueGain);\n>         maxAnalogueGain_ = std::min(context.configuration.agc.maxAnalogueGain, kMaxAnalogueGain);\n>  \n>         /* Configure the default exposure and gain. */\n>         context.frameContext.agc.gain = minAnalogueGain_;\n> -       context.frameContext.agc.exposure = minExposureLines_;\n> +       context.frameContext.agc.exposure = minShutterSpeed_ / lineDuration_;\n>  \n>         prevExposureValue_ = context.frameContext.agc.gain\n>                            * context.frameContext.agc.exposure\n> @@ -217,11 +216,9 @@ void Agc::computeExposure(uint32_t &exposure, double &analogueGain, double curre\n>          * exposure value applied multiplied by the new estimated gain.\n>          */\n>         currentExposure_ = prevExposureValue_ * evGain;\n> -       utils::Duration minShutterSpeed = minExposureLines_ * lineDuration_;\n> -       utils::Duration maxShutterSpeed = maxExposureLines_ * lineDuration_;\n>  \n>         /* Clamp the exposure value to the min and max authorized */\n> -       utils::Duration maxTotalExposure = maxShutterSpeed * maxAnalogueGain_;\n> +       utils::Duration maxTotalExposure = maxShutterSpeed_ * maxAnalogueGain_;\n>         currentExposure_ = std::min(currentExposure_, maxTotalExposure);\n>         LOG(IPU3Agc, Debug) << \"Target total exposure \" << currentExposure_\n>                             << \", maximum is \" << maxTotalExposure;\n> @@ -231,14 +228,14 @@ void Agc::computeExposure(uint32_t &exposure, double &analogueGain, double curre\n>  \n>         /* Divide the exposure value as new exposure and gain values */\n>         utils::Duration exposureValue = filteredExposure_;\n> -       utils::Duration shutterTime = minShutterSpeed;\n> +       utils::Duration shutterTime = minShutterSpeed_;\n\nI think this gets set immediately from the line below, so we don't need\nto initialise it to a specific minimum?\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n>  \n>         /*\n>         * Push the shutter time up to the maximum first, and only then\n>         * increase the gain.\n>         */\n>         shutterTime = std::clamp<utils::Duration>(exposureValue / minAnalogueGain_,\n> -                                                 minShutterSpeed, maxShutterSpeed);\n> +                                                 minShutterSpeed_, maxShutterSpeed_);\n>         double stepGain = std::clamp(exposureValue / shutterTime,\n>                                      minAnalogueGain_, maxAnalogueGain_);\n>         LOG(IPU3Agc, Debug) << \"Divided up shutter and gain are \"\n> diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h\n> index 0a9152a9..6f5d71e0 100644\n> --- a/src/ipa/ipu3/algorithms/agc.h\n> +++ b/src/ipa/ipu3/algorithms/agc.h\n> @@ -46,8 +46,8 @@ private:\n>         double iqMean_;\n>  \n>         utils::Duration lineDuration_;\n> -       uint32_t minExposureLines_;\n> -       uint32_t maxExposureLines_;\n> +       utils::Duration minShutterSpeed_;\n> +       utils::Duration maxShutterSpeed_;\n>  \n>         double minAnalogueGain_;\n>         double maxAnalogueGain_;\n> -- \n> 2.32.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 437D6BDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  8 Nov 2021 15:27:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8EF5A6035D;\n\tMon,  8 Nov 2021 16:26:59 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8A4536032C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  8 Nov 2021 16:26:58 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2F3FB18CE;\n\tMon,  8 Nov 2021 16:26:58 +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=\"A1I5NX7C\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1636385218;\n\tbh=VH2CiFpfcWNd3KbFPbRsG3DR5tFdS1+6z4WDlXUxO1c=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=A1I5NX7CvrhwIBZQO0DSwhUdWbjXw/Tcpab1DKMrpEC2G92okYIZUfQfbqzBTj1Iz\n\tEoJJyg2dLcvcAOVSxoGMmq5o4bjXSCPsqZ4vKh/h8/QEzzBGNTsXTyfRYtnBJHHe40\n\tr+H94RqjE4Tl++bwAAXZMSBz+BnAd9EyhsiXsosI=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20211108131350.130665-10-jeanmichel.hautbois@ideasonboard.com>","References":"<20211108131350.130665-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20211108131350.130665-10-jeanmichel.hautbois@ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 08 Nov 2021 15:26:56 +0000","Message-ID":"<163638521602.275423.5956759091507808263@Monstersaurus>","User-Agent":"alot/0.9.1","Subject":"Re: [libcamera-devel] [PATCH 09/22] ipa: ipu3: agc: Use exposure in\n\ttime for storage","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>"}}]