[{"id":25662,"web_url":"https://patchwork.libcamera.org/comment/25662/","msgid":"<166696082911.3974115.16373700041531279580@Monstersaurus>","date":"2022-10-28T12:40:29","subject":"Re: [libcamera-devel] [PATCH v4 7/7] ipa: raspberrypi: agc: Fix\n\tdigital gain calculation for manual mode","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Naushir Patuck via libcamera-devel (2022-10-19 10:01:07)\n> The digital gain calculation uses a total exposure value computed with the\n> current AGC state. However, this is wrong in the case of manual shutter/gain\n> controls, as the total exposure value used must be the value computed when the\n> AGC sent the manual shutter/gain controls to the pipeline handler to action.\n> \n> To fix this, the IPA now adds the historical AgcStatus structure to the metadata\n> (tagged with \"agc.delayed_status\"). This historical AgcStatus structure contains\n> the total exposure value calculated when the AGC sent the manual shutter/gain\n> controls to the pipeline handler.\n> \n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> Reviewed-by: David Plowman <david.plowman@raspberrypi.com>\n> Tested-by: David Plowman <david.plowman@raspberrypi.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  src/ipa/raspberrypi/controller/rpi/agc.cpp | 10 ++++++++--\n>  src/ipa/raspberrypi/raspberrypi.cpp        | 11 +++++++++++\n>  2 files changed, 19 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n> index bd54a639d637..b18bd7b5b19e 100644\n> --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp\n> +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n> @@ -408,6 +408,12 @@ void Agc::switchMode(CameraMode const &cameraMode,\n>  \n>  void Agc::prepare(Metadata *imageMetadata)\n>  {\n> +       Duration totalExposureValue = status_.totalExposureValue;\n> +       AgcStatus delayedStatus;\n> +\n> +       if (!imageMetadata->get(\"agc.delayed_status\", delayedStatus))\n> +               totalExposureValue = delayedStatus.totalExposureValue;\n> +\n>         status_.digitalGain = 1.0;\n>         fetchAwbStatus(imageMetadata); /* always fetch it so that Process knows it's been done */\n>  \n> @@ -418,8 +424,8 @@ void Agc::prepare(Metadata *imageMetadata)\n>                         Duration actualExposure = deviceStatus.shutterSpeed *\n>                                                   deviceStatus.analogueGain;\n>                         if (actualExposure) {\n> -                               status_.digitalGain = status_.totalExposureValue / actualExposure;\n> -                               LOG(RPiAgc, Debug) << \"Want total exposure \" << status_.totalExposureValue;\n> +                               status_.digitalGain = totalExposureValue / actualExposure;\n> +                               LOG(RPiAgc, Debug) << \"Want total exposure \" << totalExposureValue;\n>                                 /*\n>                                  * Never ask for a gain < 1.0, and also impose\n>                                  * some upper limit. Make it customisable?\n> diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\n> index aed8f68aded9..983745fcad98 100644\n> --- a/src/ipa/raspberrypi/raspberrypi.cpp\n> +++ b/src/ipa/raspberrypi/raspberrypi.cpp\n> @@ -1029,6 +1029,17 @@ void IPARPi::prepareISP(const ISPConfig &data)\n>                 embeddedBuffer = it->second.planes()[0];\n>         }\n>  \n> +       /*\n> +        * AGC wants to know the algorithm status from the time it actioned the\n> +        * sensor exposure/gain changes. So fetch it from the metadata list\n> +        * indexed by the IPA cookie returned, and put it in the current frame\n> +        * metadata.\n> +        */\n> +       AgcStatus agcStatus;\n> +       RPiController::Metadata &delayedMetadata = rpiMetadata_[data.delayCookie];\n> +       if (!delayedMetadata.get<AgcStatus>(\"agc.status\", agcStatus))\n> +               rpiMetadata.set(\"agc.delayed_status\", agcStatus);\n> +\n>         /*\n>          * This may overwrite the DeviceStatus using values from the sensor\n>          * metadata, and may also do additional custom processing.\n> -- \n> 2.25.1\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 6A89BBDB16\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 28 Oct 2022 12:40:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AB96162FDD;\n\tFri, 28 Oct 2022 14:40:33 +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 5E72561F4A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 Oct 2022 14:40:32 +0200 (CEST)","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 E333A2F5;\n\tFri, 28 Oct 2022 14:40:31 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1666960833;\n\tbh=dHXqtDYIwbHuONM2vivL/RSdNJDukY2XM5sj1TvVfEE=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=KPgkE9DfYoqKMxRt7ZZDX/yXfQfZOPWp4p1+gJPspKsLj6BzWKRHqwqlPv6U7CIcm\n\tTqdtj7/6qZBS4JfJhYNiYXDqfN9/WoniJQbWLD9SDOzKmgxPNNBPCeT64Q7qaMLxa5\n\tLs4py+dqJdZGEFnTLWG7A5RSTwanEnJtGKYEEB1uaZ72gc8lPWOT3wnGckPwp/yVIk\n\tJOxnafVtol+q8ooGXqysH1eRAS/ctcUryZnanDuKkrTjbyxHfplkkP3rSUgqhx09VE\n\tOyRv7/BsDPj64p1yV9xLV6rxdx6rn2KPXtxCqRY4JnkRPE0e8V85cbRakhyHCdzbwQ\n\t8QMXnSev3clLQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1666960832;\n\tbh=dHXqtDYIwbHuONM2vivL/RSdNJDukY2XM5sj1TvVfEE=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=o49NsLjQxc1uS8KNatQCoRadQZfTZv/q1rU4JX0a9rnV5SCeUYJ2g9NcDmhQ0+nac\n\tcXZndibXgcXTI89Zq/0c2Tk5GRaXKTerAfK+1h2SeD5vi98coZ8urLxtLVA87JjKAM\n\tttr9NPC3DRrNdSaMJVNxsS5FZW6B+rwsVaiUuMm4="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"o49NsLjQ\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20221019090107.19975-8-naush@raspberrypi.com>","References":"<20221019090107.19975-1-naush@raspberrypi.com>\n\t<20221019090107.19975-8-naush@raspberrypi.com>","To":"Naushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 28 Oct 2022 13:40:29 +0100","Message-ID":"<166696082911.3974115.16373700041531279580@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v4 7/7] ipa: raspberrypi: agc: Fix\n\tdigital gain calculation for manual mode","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>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]