[{"id":25119,"web_url":"https://patchwork.libcamera.org/comment/25119/","msgid":"<CAHW6GYL6HTamVYAZuTR1_vSEfZrFg0FsKGK4kSOrxYAuMPWtuQ@mail.gmail.com>","date":"2022-09-23T10:47:01","subject":"Re: [libcamera-devel] [PATCH v2 7/7] ipa: raspberrypi: agc: Fix\n\tdigital gain calculation for manual mode","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"content":"Hi Naush\n\nThanks for the patch.\n\nOn Mon, 5 Sept 2022 at 08:40, Naushir Patuck via libcamera-devel\n<libcamera-devel@lists.libcamera.org> wrote:\n>\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\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\nTested-by: David Plowman <david.plowman@raspberrypi.com>\n\nThanks!\nDavid\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 0e80ef9c7b95..bc438e99eff6 100644\n> --- a/src/ipa/raspberrypi/raspberrypi.cpp\n> +++ b/src/ipa/raspberrypi/raspberrypi.cpp\n> @@ -1025,6 +1025,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.ipaCookie];\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 DFC74BD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 23 Sep 2022 10:47:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 61C706223A;\n\tFri, 23 Sep 2022 12:47:15 +0200 (CEST)","from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com\n\t[IPv6:2a00:1450:4864:20::12f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1EEFB621DD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 23 Sep 2022 12:47:13 +0200 (CEST)","by mail-lf1-x12f.google.com with SMTP id 10so1236212lfy.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 23 Sep 2022 03:47:13 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1663930035;\n\tbh=hm/qQ8pE2M0WLgwJkAHVCaQZFUoHzran+RuHyhgbPI8=;\n\th=References:In-Reply-To:Date:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=LQRpDLP63GeyPHMpij9V9HAZeIfaVXi5g4CPxZbErhKrH+h+tux6HUo8bPR/7gEdP\n\te1zIcZwn4BNGc1j0cbvBc1GsN/5qY0p8e+0lOTArihrrIVZa42ohqNjl8RU01t1XOr\n\tGbUl7RiT1wKcU6Ln9wI5PojVjMoyvHvYadwFX3jFfovf7qHCo9IPCexLfJMxkUAEP7\n\tav+ICalrW/dqNH59X7RnTjbKJtFRTgE5v4Z8jpM12VouFAcxKuaP987oJc3e1sjLEI\n\ttV0/kMuEKIaEPGf9LRcARyLYoqUaL33np8nQiOMHjmrowGupRek/AEeGzrb/v8VcM+\n\twHrcWg1rnkvCA==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date;\n\tbh=2GvYoQ6xrUGKhEuHTJrSQZiFAFG721s7zqS1ibXeYJY=;\n\tb=axHuCdJB8c+eqtVE+0Qa/mNsjhy0s8hdNMQMTfRWs7oPbbuqyjClfJ2aV5uBQMaLt+\n\tVy0A3pGSzrD0UPpfYbUSb72KSnbN8TTbiNwXblZKOlEWKITmp2cXmAplYyKukaLwT39Y\n\tIOtVB+rCb0OkRR6WHpp2DDkYzRyHu4G0wD725L0fM84EfYT19cdcpYWeTMe6c6SkxEG6\n\tGHZtllzZC3BdN1Yqr7v6ZhfwYXTCGW1MdF6h826qAU1RY1M7t9MLxreuDoW3sImmpgyS\n\t4OVDJGXAjXcvAJ1lRBukEmGnpoure2eK5qD51VwtgeC6hleHzxUGwjc1mkjUBESvARhh\n\tbN9g=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"axHuCdJB\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date;\n\tbh=2GvYoQ6xrUGKhEuHTJrSQZiFAFG721s7zqS1ibXeYJY=;\n\tb=MKToE4OmpVHwRAtBKmFPL7Gdh0GI1A6zQwnaOCXwdXbba1SdBzNgT4AjQVNCy04t98\n\tx6NauSx9OkEcXOChRKzVSUpgxX4dRCRlOKS4fILSsAGaWrTnXgOOZtsZbEqPypMPYQrf\n\tplXN4Dcm0b/ubNRVH/ZUdordO2iF4EOKkZ5A39ksf0nJMu51vmV04BbHQAvRbX1UBsLM\n\tvg41KmFllWdLRiHKJxiWQryo4dMYdD7Dht3hItqUuWyP6xM2bplJALXkLNUmyO255J4d\n\tsrvCTqD7MBN8HtZleOQlv4lc1ck5FgsFevHHvql2NieWbYgpRULdSOoRTTVEP2Fo7iuW\n\tS/JQ==","X-Gm-Message-State":"ACrzQf0hx03HuVITPAGqJKMNsTegxPH4jFvRh6oTH1OuCwjTjli102kV\n\t2grpfmiG3mUdekWBRdB4J+mXSN/mRBBBLkdWXsEmAfz3TeZYtg==","X-Google-Smtp-Source":"AMsMyM5x/kwa8hGFANHfYiSXbgxAM91Ds56EcagvbeUb6+ZKB9M85ZT3FWHoRUO4/a/xAnfVbLGcB5D2MT1AQu0K8YY=","X-Received":"by 2002:a05:6512:1585:b0:494:9fd0:2ca with SMTP id\n\tbp5-20020a056512158500b004949fd002camr2845275lfb.439.1663930032412;\n\tFri, 23 Sep 2022 03:47:12 -0700 (PDT)","MIME-Version":"1.0","References":"<20220905073956.7342-1-naush@raspberrypi.com>\n\t<20220905073956.7342-8-naush@raspberrypi.com>","In-Reply-To":"<20220905073956.7342-8-naush@raspberrypi.com>","Date":"Fri, 23 Sep 2022 11:47:01 +0100","Message-ID":"<CAHW6GYL6HTamVYAZuTR1_vSEfZrFg0FsKGK4kSOrxYAuMPWtuQ@mail.gmail.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH v2 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":"David Plowman via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"David Plowman <david.plowman@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]