[{"id":17381,"web_url":"https://patchwork.libcamera.org/comment/17381/","msgid":"<CAEmqJPqO7xEN2GoBNbfi-0_TUMXQ2bd14r_WEyONFjMRLFbRig@mail.gmail.com>","date":"2021-06-02T10:03:32","subject":"Re: [libcamera-devel] [PATCH 2/2] ipa: raspberrypi: AGC: handle\n\tmodes with different sensitivities","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi David,\n\nThank you for your work.\n\nOn Thu, 27 May 2021 at 09:45, David Plowman <david.plowman@raspberrypi.com>\nwrote:\n\n> When the sensor is switched to a mode with a different sensitivity,\n> the target exposure values need to be adjusted proportionately to\n> maintain the same image brightness.\n>\n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n>\n\nThese changes look sensible to me.\n\nReviewed-by: Naushir Patuck <naush@raspberrpi.com>\n\n\n> ---\n>  src/ipa/raspberrypi/controller/rpi/agc.cpp | 25 +++++++++++++++++-----\n>  src/ipa/raspberrypi/controller/rpi/agc.hpp |  1 +\n>  2 files changed, 21 insertions(+), 5 deletions(-)\n>\n> diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp\n> b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n> index f4cd5d26..6f0e9702 100644\n> --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp\n> +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n> @@ -155,7 +155,7 @@ Agc::Agc(Controller *controller)\n>         : AgcAlgorithm(controller), metering_mode_(nullptr),\n>           exposure_mode_(nullptr), constraint_mode_(nullptr),\n>           frame_count_(0), lock_count_(0),\n> -         last_target_exposure_(0.0),\n> +         last_target_exposure_(0.0), last_sensitivity_(0.0),\n>           ev_(1.0), flicker_period_(0.0),\n>           max_shutter_(0), fixed_shutter_(0), fixed_analogue_gain_(0.0)\n>  {\n> @@ -261,7 +261,7 @@ void Agc::SetConstraintMode(std::string const\n> &constraint_mode_name)\n>         constraint_mode_name_ = constraint_mode_name;\n>  }\n>\n> -void Agc::SwitchMode([[maybe_unused]] CameraMode const &camera_mode,\n> +void Agc::SwitchMode(CameraMode const &camera_mode,\n>                      Metadata *metadata)\n>  {\n>         housekeepConfig();\n> @@ -285,9 +285,20 @@ void Agc::SwitchMode([[maybe_unused]] CameraMode\n> const &camera_mode,\n>                 filtered_.shutter = fixed_shutter;\n>                 filtered_.analogue_gain = fixed_analogue_gain_;\n>         } else if (status_.total_exposure_value) {\n> -               // On a mode switch, it's possible the exposure profile\n> could change,\n> -               // or a fixed exposure/gain might be set so we divide up\n> the exposure/\n> -               // gain again, but we don't change any target values.\n> +               // On a mode switch, various things could happen:\n> +               // - the exposure profile might change\n> +               // - a fixed exposure or gain might be set\n> +               // - the new mode's sensitivity might be different\n> +               // We cope with the last of these by scaling the target\n> values. After\n> +               // that we just need to re-divide the exposure/gain\n> according to the\n> +               // current exposure profile, which takes care of\n> everything else.\n> +\n> +               double ratio = last_sensitivity_ / camera_mode.sensitivity;\n> +               target_.total_exposure_no_dg *= ratio;\n> +               target_.total_exposure *= ratio;\n> +               filtered_.total_exposure_no_dg *= ratio;\n> +               filtered_.total_exposure *= ratio;\n> +\n>                 divideUpExposure();\n>         } else {\n>                 // We come through here on startup, when at least one of\n> the shutter\n> @@ -301,6 +312,10 @@ void Agc::SwitchMode([[maybe_unused]] CameraMode\n> const &camera_mode,\n>         }\n>\n>         writeAndFinish(metadata, false);\n> +\n> +       // We must remember the sensitivity of this mode for the next\n> SwitchMode.\n> +       ASSERT(camera_mode.sensitivity != 0.0);\n> +       last_sensitivity_ = camera_mode.sensitivity;\n>  }\n>\n>  void Agc::Prepare(Metadata *image_metadata)\n> diff --git a/src/ipa/raspberrypi/controller/rpi/agc.hpp\n> b/src/ipa/raspberrypi/controller/rpi/agc.hpp\n> index 0427fb59..025878a2 100644\n> --- a/src/ipa/raspberrypi/controller/rpi/agc.hpp\n> +++ b/src/ipa/raspberrypi/controller/rpi/agc.hpp\n> @@ -122,6 +122,7 @@ private:\n>         int lock_count_;\n>         DeviceStatus last_device_status_;\n>         double last_target_exposure_;\n> +       double last_sensitivity_; // sensitivity of the previous camera\n> mode\n>         // Below here the \"settings\" that applications can change.\n>         std::string metering_mode_name_;\n>         std::string exposure_mode_name_;\n> --\n> 2.20.1\n>\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 5FA6DC3208\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  2 Jun 2021 10:03:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CACD76050E;\n\tWed,  2 Jun 2021 12:03:50 +0200 (CEST)","from mail-lj1-x236.google.com (mail-lj1-x236.google.com\n\t[IPv6:2a00:1450:4864:20::236])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 593B3602A4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  2 Jun 2021 12:03:49 +0200 (CEST)","by mail-lj1-x236.google.com with SMTP id e11so1818732ljn.13\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 02 Jun 2021 03:03:49 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"BjFU+/rt\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=pc2Le6cPUkg3O2PEapBJYkJPNJjUAXoQhUFhN5lxpHM=;\n\tb=BjFU+/rtq/hX7v+NXrHMEU96ut2Yq8iPBEuOmGICEO+p5pgbbBUSwtamdWlodFl6bP\n\tMwKm6pDkYwqH2cvczZiGNMvEVTdyzSPokCVDzUzczm3eH/PF59VlWBlUYDS1s21qPcpc\n\t+o6s5NhadDNScEt8TglhHoUyTiREUq8E1+90Ux65gkwATOEoBykssFfFG167rRsuJ2u5\n\twtr2aR4XNoIrwMOPBJgJnwpS3NNs2gc9FIwPr9FMAKoHqBx1T1wE5klKG31ik/zxdLx0\n\t8LqIuX04h2BNcMgtjWQDRjZ+qArvVP9UwQqE/saUKsUlXILzfiR27gQ5O2f5OzNoB/gG\n\tVkgA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=pc2Le6cPUkg3O2PEapBJYkJPNJjUAXoQhUFhN5lxpHM=;\n\tb=l5K+VZAtKiAzLvwRbWlEtDzdM1lX8rQji0eMZxNzJjDTzCoXzKMMwDCOlnmhZV9BPC\n\t4h38h/AHN2sWj0OskYyBhVUbgpGsStNANgxFV0Xqk40s+FVxVlvEm+2Y5utmVVchr/DK\n\tpid7kvAEB4wGRcLlw2XoC5UmNQhl7b78YLO9CYDuXZ05HipWz/P5/gTdZ+l4KYhijzvE\n\tHWWGL7wHitVSpQTZTXOzyvbFtDbb2tueWuwLNfS9s2t/E2Shb/DgS4imXxWbdwphdIPZ\n\tei/Q2yBSnUXDxjAdKgoFdpER4Yx1sAwC+nRxj10AzWKRGdct9BsqOUmBEXAFd7VtCX3i\n\tkjMA==","X-Gm-Message-State":"AOAM531wbxnpqTj4o5QLOsNNMTcdONtZJPdzIr0/nooLvibndNDjCeGD\n\tYATtE1dQ6A9haB1QeJBPl3xCvmpieJvZYa4KM8FEFg==","X-Google-Smtp-Source":"ABdhPJzZoDKL8lMtYqEsRPO3B+QFrzvitKOFRKOfOPNu/axAbcod/BamFf7jb4TgV43wegSRh5e7VOjmgA8HMt3dtM4=","X-Received":"by 2002:a2e:8e78:: with SMTP id\n\tt24mr15496644ljk.499.1622628228421; \n\tWed, 02 Jun 2021 03:03:48 -0700 (PDT)","MIME-Version":"1.0","References":"<20210527084540.9983-1-david.plowman@raspberrypi.com>\n\t<20210527084540.9983-3-david.plowman@raspberrypi.com>","In-Reply-To":"<20210527084540.9983-3-david.plowman@raspberrypi.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Wed, 2 Jun 2021 11:03:32 +0100","Message-ID":"<CAEmqJPqO7xEN2GoBNbfi-0_TUMXQ2bd14r_WEyONFjMRLFbRig@mail.gmail.com>","To":"David Plowman <david.plowman@raspberrypi.com>","Content-Type":"multipart/alternative; boundary=\"0000000000002870a005c3c59376\"","Subject":"Re: [libcamera-devel] [PATCH 2/2] ipa: raspberrypi: AGC: handle\n\tmodes with different sensitivities","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 <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]