From patchwork Fri Jan 17 14:34:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Scally X-Patchwork-Id: 22582 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 D021CBD7D8 for ; Fri, 17 Jan 2025 14:34:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A9EC068549; Fri, 17 Jan 2025 15:34:26 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DBDaRhQN"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 951456851D for ; Fri, 17 Jan 2025 15:34:21 +0100 (CET) Received: from mail.ideasonboard.com (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 49C27CE6; Fri, 17 Jan 2025 15:33:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1737124402; bh=fEvddwlwSY6laB9o9fibIRkBZw8Bd0TVC8qqw3R32mk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DBDaRhQNIc3yqFghK1x1Pl35nVmz3arsuRSZvlfXSGtPq3Bs0lDKGcSsUQe3dncTe uR5P8y42gszZ4XffYTrfnONnJR3K4QF8xGkSf69dWtw3eShbaPy3KPXUlnfAhQAV6W c9DpLemKKaQ9dhw8X8Nv+EK3QXx9ldCE06iux9mM= From: Daniel Scally To: libcamera-devel@lists.libcamera.org Cc: Daniel Scally Subject: [PATCH 2/3] ipa: libipa: Adjust for flicker in ExposureModeHelper Date: Fri, 17 Jan 2025 14:34:09 +0000 Message-Id: <20250117143410.20363-3-dan.scally@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250117143410.20363-1-dan.scally@ideasonboard.com> References: <20250117143410.20363-1-dan.scally@ideasonboard.com> 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" Update the ExposureModeHelper class to compensate for flickering light sources in the ::splitExposure() function. The adjustment simply caps exposure time at a multiple of the given flicker period and compensates for any loss in the effective exposure value by increasing analogue and then digital gain. Initially in the one call-site for this function, a flicker period of 0us is passed, making this a no-op. Signed-off-by: Daniel Scally --- src/ipa/libipa/agc_mean_luminance.cpp | 2 +- src/ipa/libipa/exposure_mode_helper.cpp | 20 +++++++++++++++++++- src/ipa/libipa/exposure_mode_helper.h | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp index 02555a44..b5e6afe3 100644 --- a/src/ipa/libipa/agc_mean_luminance.cpp +++ b/src/ipa/libipa/agc_mean_luminance.cpp @@ -560,7 +560,7 @@ AgcMeanLuminance::calculateNewEv(uint32_t constraintModeIndex, newExposureValue = filterExposure(newExposureValue); frameCount_++; - return exposureModeHelper->splitExposure(newExposureValue); + return exposureModeHelper->splitExposure(newExposureValue, 0us); } /** diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp index f235316d..038aa33c 100644 --- a/src/ipa/libipa/exposure_mode_helper.cpp +++ b/src/ipa/libipa/exposure_mode_helper.cpp @@ -121,6 +121,7 @@ double ExposureModeHelper::clampGain(double gain) const /** * \brief Split exposure into exposure time and gain * \param[in] exposure Exposure value + * \param[in] flickerPeriod The period of a flickering light source * * This function divides a given exposure into exposure time, analogue and * digital gain by iterating through stages of exposure time and gain limits. @@ -147,10 +148,15 @@ double ExposureModeHelper::clampGain(double gain) const * required exposure, the helper falls-back to simply maximising the exposure * time first, followed by analogue gain, followed by digital gain. * + * Once the exposure time has been determined from the modes, an adjustment is + * made to compensate for a flickering light source by fixing the exposure time + * to an exact multiple of the flicker period. Any effective exposure value that + * is lost is added back via analogue and digital gain. + * * \return Tuple of exposure time, analogue gain, and digital gain */ std::tuple -ExposureModeHelper::splitExposure(utils::Duration exposure) const +ExposureModeHelper::splitExposure(utils::Duration exposure, utils::Duration flickerPeriod) const { ASSERT(maxExposureTime_); ASSERT(maxGain_); @@ -205,6 +211,18 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const * exposure time is maxed before gain is touched at all. */ exposureTime = clampExposureTime(exposure / clampGain(stageGain)); + + /* + * Finally, if we have been given a flicker period we need to reduce the + * exposure time to be a multiple of that period (if possible). The + * effect of this should be to hide the flicker. + */ + if (flickerPeriod > 0us && flickerPeriod < exposureTime) { + unsigned int flickerPeriods = exposureTime / flickerPeriod; + if (flickerPeriods) + exposureTime = flickerPeriods * flickerPeriod; + } + gain = clampGain(exposure / exposureTime); return { exposureTime, gain, exposure / (exposureTime * gain) }; diff --git a/src/ipa/libipa/exposure_mode_helper.h b/src/ipa/libipa/exposure_mode_helper.h index c5be1b67..a5fcc366 100644 --- a/src/ipa/libipa/exposure_mode_helper.h +++ b/src/ipa/libipa/exposure_mode_helper.h @@ -28,7 +28,7 @@ public: double minGain, double maxGain); std::tuple - splitExposure(utils::Duration exposure) const; + splitExposure(utils::Duration exposure, utils::Duration flickerPeriod) const; utils::Duration minExposureTime() const { return minExposureTime_; } utils::Duration maxExposureTime() const { return maxExposureTime_; }