{"id":22895,"url":"https://patchwork.libcamera.org/api/1.1/patches/22895/?format=json","web_url":"https://patchwork.libcamera.org/patch/22895/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20250227195821.3172905-1-stefan.klug@ideasonboard.com>","date":"2025-02-27T19:58:10","name":"ipa: libipa: Fix bug in ExposureModeHelper that leads to oscillations in AEGC","commit_ref":"eb550486c737305dd7e86187e9d76d95d35a9cfd","pull_url":null,"state":"accepted","archived":false,"hash":"b39df860f3ddcb523081bfbbe06b7a908e3239b8","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/1.1/people/184/?format=json","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/22895/mbox/","series":[{"id":5028,"url":"https://patchwork.libcamera.org/api/1.1/series/5028/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5028","date":"2025-02-27T19:58:10","name":"ipa: libipa: Fix bug in ExposureModeHelper that leads to oscillations in AEGC","version":1,"mbox":"https://patchwork.libcamera.org/series/5028/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/22895/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/22895/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 492CABE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 27 Feb 2025 19:58:33 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 07F3A6875A;\n\tThu, 27 Feb 2025 20:58:33 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B175D60322\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 27 Feb 2025 20:58:30 +0100 (CET)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:a3f5:6799:2ce9:5b66])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0711511D8;\n\tThu, 27 Feb 2025 20:57:01 +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=\"vwUG5N9q\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1740686222;\n\tbh=mAiZ4bkUh/Fvif1YkbafGywPZeG8xdmKUVhWSezepGk=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=vwUG5N9q9sPBiEDLX/JgP1iUOOIfMcf7wSH9yz67XOJgaDjkJngZWJBAtG0SaP50K\n\tekmTInuOa21YYq3KjnQOvfiIf/qPkT9sWX5FYFJ1JCMZ8PTsSYKem67ULfkLHxvVVu\n\tn+EAsmVxUZKeC4deIAuaCsY8qmdBYwrWcq18/Bh4=","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","Subject":"[PATCH] ipa: libipa: Fix bug in ExposureModeHelper that leads to\n\toscillations in AEGC","Date":"Thu, 27 Feb 2025 20:58:10 +0100","Message-ID":"<20250227195821.3172905-1-stefan.klug@ideasonboard.com>","X-Mailer":"git-send-email 2.43.0","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":"The ExposureModeHelper::splitExposures() runs through the configured\nstages to find the best gain/exposure time pair. It first raises the\nexposure time until it reaches the limit of the current stage. Then it\nraises the gain until that also reaches the limit of the current stage.\nAfter that it continues with the next stage until a match is found.\n\nDue to a slight mistake in the initial code, the second step doesn't\nwork as expected because the exposure time gets divided by the gain of\nthe current stage, effectively leading to a jump of the gain value from\nthe maximum gain of the last stage to the maximum gain of the current\nstage instead of gradually increasing the gain value.\n\nDepending on the tuning file this leads to very visible oscillations and\njumps in the brightness.\n\nFix by clamping the exposure time in the second step to the maximum\nexposure time of the current stage.\n\nWhile at it, add two comments for easier understanding.\n\nFixes: 34c9ab62827b (\"ipa: libipa: Add ExposureModeHelper\")\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n---\n src/ipa/libipa/exposure_mode_helper.cpp | 4 +++-\n 1 file changed, 3 insertions(+), 1 deletion(-)","diff":"diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp\nindex f235316d3539..0c1e99e31a47 100644\n--- a/src/ipa/libipa/exposure_mode_helper.cpp\n+++ b/src/ipa/libipa/exposure_mode_helper.cpp\n@@ -182,6 +182,7 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const\n \t\t * the stage limits are initialised.\n \t\t */\n \n+\t\t/* Clamp the gain to lastStageGain and regulate exposureTime. */\n \t\tif (stageExposureTime * lastStageGain >= exposure) {\n \t\t\texposureTime = clampExposureTime(exposure / clampGain(lastStageGain));\n \t\t\tgain = clampGain(exposure / exposureTime);\n@@ -189,8 +190,9 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const\n \t\t\treturn { exposureTime, gain, exposure / (exposureTime * gain) };\n \t\t}\n \n+\t\t/* Clamp the exposureTime to stageExposureTime and regulate gain. */\n \t\tif (stageExposureTime * stageGain >= exposure) {\n-\t\t\texposureTime = clampExposureTime(exposure / clampGain(stageGain));\n+\t\t\texposureTime = clampExposureTime(stageExposureTime);\n \t\t\tgain = clampGain(exposure / exposureTime);\n \n \t\t\treturn { exposureTime, gain, exposure / (exposureTime * gain) };\n","prefixes":[]}