{"id":23862,"url":"https://patchwork.libcamera.org/api/patches/23862/?format=json","web_url":"https://patchwork.libcamera.org/patch/23862/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20250721074853.1463358-4-naush@raspberrypi.com>","date":"2025-07-21T07:47:23","name":"[v2,3/7] ipa: rpi: agc: Rename \"analogue gain\" to \"gain\" where appropriate","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"c6d0d381833bf30f33634197d65b54b07245f316","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/23862/mbox/","series":[{"id":5303,"url":"https://patchwork.libcamera.org/api/series/5303/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5303","date":"2025-07-21T07:47:20","name":"Raspberry Pi AEC/AGC update","version":2,"mbox":"https://patchwork.libcamera.org/series/5303/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/23862/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/23862/checks/","tags":{},"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 DA6AAC3323\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 21 Jul 2025 07:49:07 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1E66468FD7;\n\tMon, 21 Jul 2025 09:49:05 +0200 (CEST)","from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com\n\t[IPv6:2a00:1450:4864:20::32b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0E8A968FC0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Jul 2025 09:48:58 +0200 (CEST)","by mail-wm1-x32b.google.com with SMTP id\n\t5b1f17b1804b1-456053b5b8cso1734675e9.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Jul 2025 00:48:58 -0700 (PDT)","from NAUSH-P-DELL.pitowers.org ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-4562e802afasm151101765e9.12.2025.07.21.00.48.56\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 21 Jul 2025 00:48:56 -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=\"mYnA71VF\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1753084137; x=1753688937;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=zocCf5y6pEDwCbRf0ZnxWaN++n1LhwhYJvqr+OSo1EI=;\n\tb=mYnA71VFpCzY90V5e0ce5f/OFpsWvInkJvimxmohgfzMkm/ceOAOkEdjXio2FjSGlD\n\t+Wed/EuooJvVEdOQ4RzqyGFhXjiSKiEg0pZ1BPL1BKAigPLloNeNKqVTroVyZIK2ks6A\n\t58HngNEA8fvyIggtGwI+7kXaxplwz326XXo5YqcQfE3hmZGkQ9EbKM/ekt78rHifcsFD\n\tGohQOAZGG7L5e3/REAig2g6AbUm5oNEUiMiMQ2tXZcLqMXeHjqwxR8y8IBuYw2rJV9aR\n\tqbLRMr/JyRW/DQ+VcUfwSvsZuZVyTC4QoBRRAuDJjTELRoTc1D1w3OiRCiCkFtahfFgs\n\tobgQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1753084137; x=1753688937;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=zocCf5y6pEDwCbRf0ZnxWaN++n1LhwhYJvqr+OSo1EI=;\n\tb=XKifTdMKUtTzgK5jVbe9e1TKpfruFIXvOBR+eIvWtS4XUxUVurxUhKEA291luS4M2B\n\tCmi4xQDGCT3dABSsGOD7mSG+BwjPqs4D7Sx1J5GICMEm8eVHvo5rwlLbNt9Uxk8Xrthj\n\t9TP0yHXmuYGDn2hcSfuU6M/T+I/dPuUaVmKtO0JiWumhw12R4QZUR++p6e45DAeFpuaq\n\tQaV+EySigth+o78F18r5TCHfb0Tt73O5VGFNFqcc71oEtcZJ4hJhesJIPoanzqU9AHSH\n\t4xXO7pyj9N0tDdsZipEDzf6SSgRiqBbMrMBuw2/iv4f+T9E/c4m6mSqHtf7sVc0V24gU\n\tSigA==","X-Gm-Message-State":"AOJu0YxX8H+QqZXVmxg7dZE0EvMEigDkRTlgZ3SlRYA0UW4f+9o9wzGV\n\tqeP72T0Pvu6YB9qrdJxJS2IuNkM/10rXagKc0s7gXljiaojvDUlYBuIPFDEEFD7CDBSYXmfGQCV\n\tOGUUMUlw=","X-Gm-Gg":"ASbGnctPHwDXabAGSUc18qm/GZeRrTrhquP9KT9Mwez4xJP1huAoDXt0b/Z7pbEmlrK\n\ttnRrsWZgplHVNKXExk0LdH78vJEAaTR9j5pE0+J+gv7zf50+fIzDxuydRTgtQYfMIgiQZ0CbjT5\n\tFtUfNJKbSlH29/reZuALIpnQ4P8XNrMrXm8I5WGcnxQdjWEQfLAa3krxnNYQVPNucsJ9UkFIBpj\n\tULxwh5kHHzHkBIC/jc7ok+fiJjEm63UMaUZkOtDX5l9hDoskvG2op9RgpqImnfn/vtu1h4f2mbi\n\twIsYydHZg1gD1vEESxjV3sp+zIyeS29Oc5LyZDM4bvxLuJKbMmttwyecRXmmFQlNC8Jq2zOipat\n\tpCCpHXatJkKqrS5pYgm1TrmV5S3hcTAhLFqCt4LN6KA==","X-Google-Smtp-Source":"AGHT+IH+dvz9E4Wr3yabDL+um9sPjYqyvgTX627dCnnmbH5oAEcrvW/XAb6Zc4uZ4yJheV50S34Tkw==","X-Received":"by 2002:a05:600c:1e20:b0:456:11a6:a50a with SMTP id\n\t5b1f17b1804b1-4562dff98c2mr87505875e9.2.1753084137194; \n\tMon, 21 Jul 2025 00:48:57 -0700 (PDT)","From":"Naushir Patuck <naush@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"David Plowman <david.plowman@raspberrypi.com>,\n\tNaushir Patuck <naush@raspberrypi.com>","Subject":"[PATCH v2 3/7] ipa: rpi: agc: Rename \"analogue gain\" to \"gain\" where\n\tappropriate","Date":"Mon, 21 Jul 2025 08:47:23 +0100","Message-ID":"<20250721074853.1463358-4-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20250721074853.1463358-1-naush@raspberrypi.com>","References":"<20250721074853.1463358-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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>"},"content":"From: David Plowman <david.plowman@raspberrypi.com>\n\nMuch of the time we use the term \"analogue gain\" where we really mean\nthe combined analogue and digital gain (because the digital gain will\nmake up whatever the analogue gain can't deliver).\n\nThis commit replaces the use of \"analogue gain\" by just \"gain\" in\nplaces where we really mean the combined gain. There are a couple of\nprinciple areas:\n\n1. Where we previously talked about the \"fixedAnalaogueGain\"\n(including setting it \"manually\") this is now just the \"fixedGain\"\n(because it always encompassed both analogue and digital gain).\n\nAlong with this, the setfixedExposureTime/Gain functions no longer\nupdate the output status directly. Applications should wait in the\nusual way for AGC/AEC changes to take effect, and this \"shortcut\"\nactually doesn't fit well with the gain being the combined gain.\n\n2. The divideUpExposure method is adjusted to be clearer that it's\nsetting the combined gain, and it's prepare() that will discover later\nwhat the analogue gain actually delivered.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n---\n src/ipa/rpi/common/ipa_base.cpp            |  2 +-\n src/ipa/rpi/controller/agc_algorithm.h     |  2 +-\n src/ipa/rpi/controller/agc_status.h        |  2 +-\n src/ipa/rpi/controller/rpi/agc.cpp         |  6 +-\n src/ipa/rpi/controller/rpi/agc.h           |  4 +-\n src/ipa/rpi/controller/rpi/agc_channel.cpp | 77 +++++++++++-----------\n src/ipa/rpi/controller/rpi/agc_channel.h   |  4 +-\n 7 files changed, 48 insertions(+), 49 deletions(-)","diff":"diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp\nindex a5bdcbb5838c..8b4eb75e7e6b 100644\n--- a/src/ipa/rpi/common/ipa_base.cpp\n+++ b/src/ipa/rpi/common/ipa_base.cpp\n@@ -868,7 +868,7 @@ void IpaBase::applyControls(const ControlList &controls)\n \t\t\tif (agc->autoGainEnabled())\n \t\t\t\tbreak;\n \n-\t\t\tagc->setFixedAnalogueGain(0, ctrl.second.get<float>());\n+\t\t\tagc->setFixedGain(0, ctrl.second.get<float>());\n \n \t\t\tlibcameraMetadata_.set(controls::AnalogueGain,\n \t\t\t\t\t       ctrl.second.get<float>());\ndiff --git a/src/ipa/rpi/controller/agc_algorithm.h b/src/ipa/rpi/controller/agc_algorithm.h\nindex fdaa10e6c176..9fa2bd205160 100644\n--- a/src/ipa/rpi/controller/agc_algorithm.h\n+++ b/src/ipa/rpi/controller/agc_algorithm.h\n@@ -26,7 +26,7 @@ public:\n \tvirtual void setFixedExposureTime(unsigned int channel,\n \t\t\t\t\t  libcamera::utils::Duration fixedExposureTime) = 0;\n \tvirtual void setMaxExposureTime(libcamera::utils::Duration maxExposureTime) = 0;\n-\tvirtual void setFixedAnalogueGain(unsigned int channel, double fixedAnalogueGain) = 0;\n+\tvirtual void setFixedGain(unsigned int channel, double fixedGain) = 0;\n \tvirtual void setMeteringMode(std::string const &meteringModeName) = 0;\n \tvirtual void setExposureMode(std::string const &exposureModeName) = 0;\n \tvirtual void setConstraintMode(std::string const &contraintModeName) = 0;\ndiff --git a/src/ipa/rpi/controller/agc_status.h b/src/ipa/rpi/controller/agc_status.h\nindex 9308b156051c..d4cedcf49c3c 100644\n--- a/src/ipa/rpi/controller/agc_status.h\n+++ b/src/ipa/rpi/controller/agc_status.h\n@@ -37,7 +37,7 @@ struct AgcStatus {\n \tlibcamera::utils::Duration flickerPeriod;\n \tint floatingRegionEnable;\n \tlibcamera::utils::Duration fixedExposureTime;\n-\tdouble fixedAnalogueGain;\n+\tdouble fixedGain;\n \tunsigned int channel;\n \tHdrStatus hdr;\n };\ndiff --git a/src/ipa/rpi/controller/rpi/agc.cpp b/src/ipa/rpi/controller/rpi/agc.cpp\nindex 02bfdb4a5e22..afda2e364f64 100644\n--- a/src/ipa/rpi/controller/rpi/agc.cpp\n+++ b/src/ipa/rpi/controller/rpi/agc.cpp\n@@ -184,14 +184,14 @@ void Agc::setFixedExposureTime(unsigned int channelIndex, Duration fixedExposure\n \tchannelData_[channelIndex].channel.setFixedExposureTime(fixedExposureTime);\n }\n \n-void Agc::setFixedAnalogueGain(unsigned int channelIndex, double fixedAnalogueGain)\n+void Agc::setFixedGain(unsigned int channelIndex, double fixedGain)\n {\n \tif (checkChannel(channelIndex))\n \t\treturn;\n \n-\tLOG(RPiAgc, Debug) << \"setFixedAnalogueGain \" << fixedAnalogueGain\n+\tLOG(RPiAgc, Debug) << \"setFixedGain \" << fixedGain\n \t\t\t   << \" for channel \" << channelIndex;\n-\tchannelData_[channelIndex].channel.setFixedAnalogueGain(fixedAnalogueGain);\n+\tchannelData_[channelIndex].channel.setFixedGain(fixedGain);\n }\n \n void Agc::setMeteringMode(std::string const &meteringModeName)\ndiff --git a/src/ipa/rpi/controller/rpi/agc.h b/src/ipa/rpi/controller/rpi/agc.h\nindex c3a940bf697a..966630a26303 100644\n--- a/src/ipa/rpi/controller/rpi/agc.h\n+++ b/src/ipa/rpi/controller/rpi/agc.h\n@@ -35,8 +35,8 @@ public:\n \tvoid setMaxExposureTime(libcamera::utils::Duration maxExposureTime) override;\n \tvoid setFixedExposureTime(unsigned int channelIndex,\n \t\t\t\t  libcamera::utils::Duration fixedExposureTime) override;\n-\tvoid setFixedAnalogueGain(unsigned int channelIndex,\n-\t\t\t\t  double fixedAnalogueGain) override;\n+\tvoid setFixedGain(unsigned int channelIndex,\n+\t\t\t  double fixedGain) override;\n \tvoid setMeteringMode(std::string const &meteringModeName) override;\n \tvoid setExposureMode(std::string const &exposureModeName) override;\n \tvoid setConstraintMode(std::string const &contraintModeName) override;\ndiff --git a/src/ipa/rpi/controller/rpi/agc_channel.cpp b/src/ipa/rpi/controller/rpi/agc_channel.cpp\nindex f6a191d50fb3..9e4661616051 100644\n--- a/src/ipa/rpi/controller/rpi/agc_channel.cpp\n+++ b/src/ipa/rpi/controller/rpi/agc_channel.cpp\n@@ -275,7 +275,7 @@ AgcChannel::AgcChannel()\n \t: meteringMode_(nullptr), exposureMode_(nullptr), constraintMode_(nullptr),\n \t  frameCount_(0), lockCount_(0),\n \t  lastTargetExposure_(0s), ev_(1.0), flickerPeriod_(0s),\n-\t  maxExposureTime_(0s), fixedExposureTime_(0s), fixedAnalogueGain_(0.0)\n+\t  maxExposureTime_(0s), fixedExposureTime_(0s), fixedGain_(0.0)\n {\n \t/* Set AWB default values in case early frames have no updates in metadata. */\n \tawb_.gainR = 1.0;\n@@ -339,17 +339,17 @@ bool AgcChannel::autoExposureEnabled() const\n \n void AgcChannel::disableAutoGain()\n {\n-\tfixedAnalogueGain_ = status_.analogueGain;\n+\tfixedGain_ = status_.analogueGain;\n }\n \n void AgcChannel::enableAutoGain()\n {\n-\tfixedAnalogueGain_ = 0;\n+\tfixedGain_ = 0;\n }\n \n bool AgcChannel::autoGainEnabled() const\n {\n-\treturn fixedAnalogueGain_ == 0;\n+\treturn fixedGain_ == 0;\n }\n \n unsigned int AgcChannel::getConvergenceFrames() const\n@@ -358,7 +358,7 @@ unsigned int AgcChannel::getConvergenceFrames() const\n \t * If exposure time and gain have been explicitly set, there is no\n \t * convergence to happen, so no need to drop any frames - return zero.\n \t */\n-\tif (fixedExposureTime_ && fixedAnalogueGain_)\n+\tif (fixedExposureTime_ && fixedGain_)\n \t\treturn 0;\n \telse\n \t\treturn config_.convergenceFrames;\n@@ -398,11 +398,9 @@ void AgcChannel::setFixedExposureTime(Duration fixedExposureTime)\n \tstatus_.exposureTime = limitExposureTime(fixedExposureTime_);\n }\n \n-void AgcChannel::setFixedAnalogueGain(double fixedAnalogueGain)\n+void AgcChannel::setFixedGain(double fixedGain)\n {\n-\tfixedAnalogueGain_ = fixedAnalogueGain;\n-\t/* Set this in case someone calls disableAuto() straight after. */\n-\tstatus_.analogueGain = limitGain(fixedAnalogueGain);\n+\tfixedGain_ = fixedGain;\n }\n \n void AgcChannel::setMeteringMode(std::string const &meteringModeName)\n@@ -436,9 +434,9 @@ void AgcChannel::switchMode(CameraMode const &cameraMode,\n \tmode_ = cameraMode;\n \n \tDuration fixedExposureTime = limitExposureTime(fixedExposureTime_);\n-\tif (fixedExposureTime && fixedAnalogueGain_) {\n+\tif (fixedExposureTime && fixedGain_) {\n \t\t/* This is the equivalent of computeTargetExposure and applyDigitalGain. */\n-\t\ttarget_.totalExposureNoDG = fixedExposureTime_ * fixedAnalogueGain_;\n+\t\ttarget_.totalExposureNoDG = fixedExposureTime_ * fixedGain_;\n \t\ttarget_.totalExposure = target_.totalExposureNoDG;\n \n \t\t/* Equivalent of filterExposure. This resets any \"history\". */\n@@ -446,7 +444,7 @@ void AgcChannel::switchMode(CameraMode const &cameraMode,\n \n \t\t/* Equivalent of divideUpExposure. */\n \t\tfiltered_.exposureTime = fixedExposureTime;\n-\t\tfiltered_.analogueGain = fixedAnalogueGain_;\n+\t\tfiltered_.analogueGain = fixedGain_;\n \t} else if (status_.totalExposureValue) {\n \t\t/*\n \t\t * On a mode switch, various things could happen:\n@@ -476,7 +474,7 @@ void AgcChannel::switchMode(CameraMode const &cameraMode,\n \n \t\t/* Equivalent of divideUpExposure. */\n \t\tfiltered_.exposureTime = fixedExposureTime ? fixedExposureTime : config_.defaultExposureTime;\n-\t\tfiltered_.analogueGain = fixedAnalogueGain_ ? fixedAnalogueGain_ : config_.defaultAnalogueGain;\n+\t\tfiltered_.analogueGain = fixedGain_ ? fixedGain_ : config_.defaultAnalogueGain;\n \t}\n \n \twriteAndFinish(metadata, false);\n@@ -608,11 +606,11 @@ void AgcChannel::housekeepConfig()\n \t/* First fetch all the up-to-date settings, so no one else has to do it. */\n \tstatus_.ev = ev_;\n \tstatus_.fixedExposureTime = limitExposureTime(fixedExposureTime_);\n-\tstatus_.fixedAnalogueGain = fixedAnalogueGain_;\n+\tstatus_.fixedGain = fixedGain_;\n \tstatus_.flickerPeriod = flickerPeriod_;\n \tLOG(RPiAgc, Debug) << \"ev \" << status_.ev << \" fixedExposureTime \"\n-\t\t\t   << status_.fixedExposureTime << \" fixedAnalogueGain \"\n-\t\t\t   << status_.fixedAnalogueGain;\n+\t\t\t   << status_.fixedExposureTime << \" fixedGain \"\n+\t\t\t   << status_.fixedGain;\n \t/*\n \t * Make sure the \"mode\" pointers point to the up-to-date things, if\n \t * they've changed.\n@@ -799,9 +797,9 @@ void AgcChannel::computeGain(StatisticsPtr &statistics, Metadata *imageMetadata,\n \n void AgcChannel::computeTargetExposure(double gain)\n {\n-\tif (status_.fixedExposureTime && status_.fixedAnalogueGain) {\n+\tif (status_.fixedExposureTime && status_.fixedGain) {\n \t\ttarget_.totalExposure =\n-\t\t\tstatus_.fixedExposureTime * status_.fixedAnalogueGain;\n+\t\t\tstatus_.fixedExposureTime * status_.fixedGain;\n \t} else {\n \t\t/*\n \t\t * The statistics reflect the image without digital gain, so the final\n@@ -815,8 +813,8 @@ void AgcChannel::computeTargetExposure(double gain)\n \t\tmaxExposureTime = limitExposureTime(maxExposureTime);\n \t\tDuration maxTotalExposure =\n \t\t\tmaxExposureTime *\n-\t\t\t(status_.fixedAnalogueGain != 0.0\n-\t\t\t\t ? status_.fixedAnalogueGain\n+\t\t\t(status_.fixedGain != 0.0\n+\t\t\t\t ? status_.fixedGain\n \t\t\t\t : exposureMode_->gain.back());\n \t\ttarget_.totalExposure = std::min(target_.totalExposure, maxTotalExposure);\n \t}\n@@ -896,7 +894,7 @@ void AgcChannel::filterExposure()\n \t * region, because we want to reflect any user exposure/gain updates,\n \t * however small.\n \t */\n-\tif ((status_.fixedExposureTime && status_.fixedAnalogueGain) ||\n+\tif ((status_.fixedExposureTime && status_.fixedGain) ||\n \t    frameCount_ <= config_.startupFrames) {\n \t\tspeed = 1.0;\n \t\tstableRegion = 0.0;\n@@ -930,63 +928,64 @@ void AgcChannel::divideUpExposure()\n \t */\n \tDuration exposureValue = filtered_.totalExposureNoDG;\n \tDuration exposureTime;\n-\tdouble analogueGain;\n+\tdouble gain;\n \texposureTime = status_.fixedExposureTime ? status_.fixedExposureTime\n \t\t\t\t\t\t : exposureMode_->exposureTime[0];\n \texposureTime = limitExposureTime(exposureTime);\n-\tanalogueGain = status_.fixedAnalogueGain != 0.0 ? status_.fixedAnalogueGain\n-\t\t\t\t\t\t\t: exposureMode_->gain[0];\n-\tanalogueGain = limitGain(analogueGain);\n-\tif (exposureTime * analogueGain < exposureValue) {\n+\tgain = status_.fixedGain != 0.0 ? status_.fixedGain\n+\t\t: exposureMode_->gain[0];\n+\tgain = limitGain(gain);\n+\tif (exposureTime * gain < exposureValue) {\n \t\tfor (unsigned int stage = 1;\n \t\t     stage < exposureMode_->gain.size(); stage++) {\n \t\t\tif (!status_.fixedExposureTime) {\n \t\t\t\tDuration stageExposureTime =\n \t\t\t\t\tlimitExposureTime(exposureMode_->exposureTime[stage]);\n-\t\t\t\tif (stageExposureTime * analogueGain >= exposureValue) {\n-\t\t\t\t\texposureTime = exposureValue / analogueGain;\n+\t\t\t\tif (stageExposureTime * gain >= exposureValue) {\n+\t\t\t\t\texposureTime = exposureValue / gain;\n \t\t\t\t\tbreak;\n \t\t\t\t}\n \t\t\t\texposureTime = stageExposureTime;\n \t\t\t}\n-\t\t\tif (status_.fixedAnalogueGain == 0.0) {\n+\t\t\tif (status_.fixedGain == 0.0) {\n \t\t\t\tif (exposureMode_->gain[stage] * exposureTime >= exposureValue) {\n-\t\t\t\t\tanalogueGain = exposureValue / exposureTime;\n+\t\t\t\t\tgain = exposureValue / exposureTime;\n \t\t\t\t\tbreak;\n \t\t\t\t}\n-\t\t\t\tanalogueGain = exposureMode_->gain[stage];\n-\t\t\t\tanalogueGain = limitGain(analogueGain);\n+\t\t\t\tgain = exposureMode_->gain[stage];\n+\t\t\t\tgain = limitGain(gain);\n \t\t\t}\n \t\t}\n \t}\n \tLOG(RPiAgc, Debug)\n \t\t<< \"Divided up exposure time and gain are \" << exposureTime\n-\t\t<< \" and \" << analogueGain;\n+\t\t<< \" and \" << gain;\n \t/*\n \t * Finally adjust exposure time for flicker avoidance (require both\n \t * exposure time and gain not to be fixed).\n \t */\n-\tif (!status_.fixedExposureTime && !status_.fixedAnalogueGain &&\n+\tif (!status_.fixedExposureTime && !status_.fixedGain &&\n \t    status_.flickerPeriod) {\n \t\tint flickerPeriods = exposureTime / status_.flickerPeriod;\n \t\tif (flickerPeriods) {\n \t\t\tDuration newExposureTime = flickerPeriods * status_.flickerPeriod;\n-\t\t\tanalogueGain *= exposureTime / newExposureTime;\n+\t\t\tgain *= exposureTime / newExposureTime;\n \t\t\t/*\n \t\t\t * We should still not allow the ag to go over the\n \t\t\t * largest value in the exposure mode. Note that this\n \t\t\t * may force more of the total exposure into the digital\n \t\t\t * gain as a side-effect.\n \t\t\t */\n-\t\t\tanalogueGain = std::min(analogueGain, exposureMode_->gain.back());\n-\t\t\tanalogueGain = limitGain(analogueGain);\n+\t\t\tgain = std::min(gain, exposureMode_->gain.back());\n+\t\t\tgain = limitGain(gain);\n \t\t\texposureTime = newExposureTime;\n \t\t}\n \t\tLOG(RPiAgc, Debug) << \"After flicker avoidance, exposure time \"\n-\t\t\t\t   << exposureTime << \" gain \" << analogueGain;\n+\t\t\t\t   << exposureTime << \" gain \" << gain;\n \t}\n \tfiltered_.exposureTime = exposureTime;\n-\tfiltered_.analogueGain = analogueGain;\n+\t/* We ask for all the gain as analogue gain; prepare() will be told what we got. */\n+\tfiltered_.analogueGain = gain;\n }\n \n void AgcChannel::writeAndFinish(Metadata *imageMetadata, bool desaturate)\ndiff --git a/src/ipa/rpi/controller/rpi/agc_channel.h b/src/ipa/rpi/controller/rpi/agc_channel.h\nindex e3475d864b0b..93229128abf1 100644\n--- a/src/ipa/rpi/controller/rpi/agc_channel.h\n+++ b/src/ipa/rpi/controller/rpi/agc_channel.h\n@@ -93,7 +93,7 @@ public:\n \tvoid setFlickerPeriod(libcamera::utils::Duration flickerPeriod);\n \tvoid setMaxExposureTime(libcamera::utils::Duration maxExposureTime);\n \tvoid setFixedExposureTime(libcamera::utils::Duration fixedExposureTime);\n-\tvoid setFixedAnalogueGain(double fixedAnalogueGain);\n+\tvoid setFixedGain(double fixedGain);\n \tvoid setMeteringMode(std::string const &meteringModeName);\n \tvoid setExposureMode(std::string const &exposureModeName);\n \tvoid setConstraintMode(std::string const &contraintModeName);\n@@ -153,7 +153,7 @@ private:\n \tlibcamera::utils::Duration flickerPeriod_;\n \tlibcamera::utils::Duration maxExposureTime_;\n \tlibcamera::utils::Duration fixedExposureTime_;\n-\tdouble fixedAnalogueGain_;\n+\tdouble fixedGain_;\n };\n \n } /* namespace RPiController */\n","prefixes":["v2","3/7"]}