From patchwork Wed May 20 08:44:51 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 26786 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 22776BDCBD for ; Wed, 20 May 2026 08:46:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CCFCB62FEC; Wed, 20 May 2026 10:46:35 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="VLi5gl+u"; dkim-atps=neutral Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1A97762FB1 for ; Wed, 20 May 2026 10:46:34 +0200 (CEST) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-48984d29fe3so50773695e9.0 for ; Wed, 20 May 2026 01:46:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1779266793; x=1779871593; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=0TNnQQuRZgvX93hig0Bt1QH7dApXyB7b9HO3dA6S3zw=; b=VLi5gl+uKzgprQG0mEdkonhMhlgjHcB7bHbk6/re1ixFekazD9RhCHn4vFtHQVv9u6 64pr/5wAsEgMlix/SWDh8nAhPCS6PeVI3rHZC2AkYf0z03nS/BpI/c13DV3ba1GYn30d pvSGhx1vjs+vrc8x04ZlWq4cUlDMetLnFeChbsmdeNM4spvXAThO4fXq/9AQXz3wLgfa K/DfUalDyrqRIbxdKGG7yd3Su0AJNs0JgeIlJKCJ/Cl35F1e3txVFsFrEm8d0RusIK/r tDniWNmeH+cWlZ1Klr59de2LGE08m4ClxX7p2GBB2hu/QhoGzlqNwxxEZIXS6ztP8fZS w/yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779266793; x=1779871593; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=0TNnQQuRZgvX93hig0Bt1QH7dApXyB7b9HO3dA6S3zw=; b=GCINPzsld42FvWc3qjVrxaHP5j5cLm51aLb+WPcyamBNg9nstZHSkWKZ8IcFiaeJDe cIRkDXbtvovVKqQORmk7XahNsxr6qm6NAmO7FJy+UHdD5qe879uFFPG7WXuP0ibtcQyp hL3lZxn8fdNTrqMCwlymM2CdqKL+aGmcADYZVYoHUruF8cLazuo4g1yPfiGNY3PrmGq7 WhA9s89qC9nhkNEltkxuOoB24kuUe8/QBvxhqBPDmki/lS49zwZN1wiJ/cBA//SYSwxe 6JDpVrP04CIGkIxLVr/E+kmEGtrL4zZm+jSeaS95/cHIas7CFyvz+WvevUyrwhfFAFiA 6SQw== X-Gm-Message-State: AOJu0YwUwMwOndJPhohzLS9jHNlhnWi86kN2ebStcJGGoiMj9uOCuDef dsMAA66BSHOB8gbw+Lf9/vucX0YKsQCw0CvtjeKISL2lGBHSDzZ1Kh749eDXmqTW2gA7m1sPee4 UjBo/V6c= X-Gm-Gg: Acq92OF+lOzD7BW22bPZIQVfNMNTnU/ojmXgsS/NTVDW1bP+VyvoA66WtX93sNJ+VyE Sft/q5HRvbQu7sJAa4M81abW9IUp2fXC92wf4c3lkYcPwkQQAdrxK3HpbEnB0YAuAQQ6xtX3YLS OclGPOTHV8fOZJZsiLfPZbasJ59iAB1G/yv6rUs9Vg8S816K1ioOhmS77ccP0vSxJnrcK3XCJbS andv2//dN2Fv09g+lRyD2ozLNXscW/MOidzQpNrMG60I2QLt5XrlrjYGR3ErLTUM9FmObwYX5Cl 9KOGHwKdnvXdA7zFsaewWdJ6iDVsV9Igd4PbXgiSrEXRz0DkytEmMaIGLXmVek3WmPXqt/qGEMp YvQvwomCHJxZDNDbEv7lJi/2q353AU6c48CpYkoQsb18O368NarhItGNbkdKIgZXB4KMLU+YiQf SgsAw42NbvtLA6jbCv83lrVnrq8DUrugmQMEEMlh3dbmrZB4qrGV8Cw7KRDQGS0jLmm3TeKJa0w fxB8LhqmNN6xIom3lthtYwdR/OYktVOQDNXt8RSwjnEkqb4gunwVntVDc7YQwg= X-Received: by 2002:a05:600c:a406:b0:48e:82cc:4d4c with SMTP id 5b1f17b1804b1-48fe6514939mr280677245e9.23.1779266793299; Wed, 20 May 2026 01:46:33 -0700 (PDT) Received: from davidp-pi5.pitowers.org ([2a00:1098:3142:1f:88ea:c658:5b20:5e46]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48fe5cab818sm397888535e9.14.2026.05.20.01.46.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 01:46:33 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman Subject: [PATCH v1] ipa: rpi: agc: Clamp digital gain to avoid saturation issues Date: Wed, 20 May 2026 09:44:51 +0100 Message-ID: <20260520084631.3440-1-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Digital gain is used to adjust overall image exposure when the target exposure cannot be achieved (for example, cannot go high enough). But when the target exposure is lower than we can achieve, the digital gain was being set to values less than unity, causing saturation problems. The fix is simply to clamp the digital gain at the bottom to 1.0, resulting in images that, while "too bright", saturate correctly. Signed-off-by: David Plowman Reviewed-by: Alen Karnil Tested-by: Alen Karnil --- src/ipa/rpi/controller/rpi/agc_channel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ipa/rpi/controller/rpi/agc_channel.cpp b/src/ipa/rpi/controller/rpi/agc_channel.cpp index cf0e77bd..c9462eed 100644 --- a/src/ipa/rpi/controller/rpi/agc_channel.cpp +++ b/src/ipa/rpi/controller/rpi/agc_channel.cpp @@ -941,8 +941,8 @@ void AgcChannel::divideUpExposure() /* Finally work out the digital gain that we will need. */ filtered_.totalExposureNoDG = analogueGain * exposureTime; double digitalGain = filtered_.totalExposure / filtered_.totalExposureNoDG; - /* Limit dg by what is allowed. */ - digitalGain = std::min(digitalGain, config_.maxDigitalGain); + /* Limit dg by what is allowed (and to 1.0 to avoid saturation issues). */ + digitalGain = std::clamp(digitalGain, 1.0, config_.maxDigitalGain); /* Update total exposure, in case the dg went down. */ filtered_.totalExposure = filtered_.totalExposureNoDG * digitalGain;