From patchwork Fri Oct 24 08:50:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 24782 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 18521C3259 for ; Fri, 24 Oct 2025 08:52:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D1648608C7; Fri, 24 Oct 2025 10:52:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="PWa59Yl3"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 65549608C3 for ; Fri, 24 Oct 2025 10:52:25 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:7edc:62f4:c118:1549]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id CFDA921D0; Fri, 24 Oct 2025 10:50:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761295839; bh=StDPAkMOQOA6KWKzAM3YzShSQyu0YbgvwZMApLh/oac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PWa59Yl3A66Xj1gH6KJDzAJYAbOBbphoGX8/8K+6cnJSpr+sNNRJhN/EejKtEP3Su K3PSLwkISGLva1JMJ1KeB0JNk2s1rjUk7VA+4m9tYoyE4bgqlr7xrffuP5vw3aaJfx ZKOdlrIxSt8ehQAvAVVNhPrdGQhELHxsMvWajMlY= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v1 16/35] ipa: rkisp1: agc: Process frame duration at the right time Date: Fri, 24 Oct 2025 10:50:40 +0200 Message-ID: <20251024085130.995967-17-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251024085130.995967-1-stefan.klug@ideasonboard.com> References: <20251024085130.995967-1-stefan.klug@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" The frame duration and vblank should not be calculated during process() but within prepare(), where the data for that frame get's computed. Signed-off-by: Stefan Klug --- src/ipa/rkisp1/algorithms/agc.cpp | 20 ++++++++++---------- src/ipa/rkisp1/algorithms/agc.h | 3 +-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp index c67106339ef8..5ce77b7672f2 100644 --- a/src/ipa/rkisp1/algorithms/agc.cpp +++ b/src/ipa/rkisp1/algorithms/agc.cpp @@ -383,6 +383,12 @@ void Agc::prepare(IPAContext &context, const uint32_t frame, frameContext.agc.yTarget = context.activeState.agc.automatic.yTarget; + /* + * Expand the target frame duration so that we do not run faster than + * the minimum frame duration when we have short exposures. + */ + processFrameDuration(context, frameContext); + if (frame > 0 && !frameContext.agc.updateMetering) return; @@ -511,11 +517,13 @@ double Agc::estimateLuminance(double gain) const * Compute and populate vblank from the target frame duration. */ void Agc::processFrameDuration(IPAContext &context, - IPAFrameContext &frameContext, - utils::Duration frameDuration) + IPAFrameContext &frameContext) { IPACameraSensorInfo &sensorInfo = context.sensorInfo; utils::Duration lineDuration = context.configuration.sensor.lineDuration; + utils::Duration frameDuration = frameContext.agc.exposure * lineDuration; + + frameDuration = std::max(frameDuration, frameContext.agc.minFrameDuration); frameContext.agc.vblank = (frameDuration / lineDuration) - sensorInfo.outputSize.height; @@ -539,8 +547,6 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, ControlList &metadata) { if (!stats) { - processFrameDuration(context, frameContext, - frameContext.agc.minFrameDuration); fillMetadata(context, frameContext, metadata); return; } @@ -641,12 +647,6 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, activeState.agc.automatic.gain = aGain; activeState.agc.automatic.quantizationGain = qGain; activeState.agc.automatic.yTarget = effectiveYTarget(); - /* - * Expand the target frame duration so that we do not run faster than - * the minimum frame duration when we have short exposures. - */ - processFrameDuration(context, frameContext, - std::max(frameContext.agc.minFrameDuration, newExposureTime)); fillMetadata(context, frameContext, metadata); expMeans_ = {}; diff --git a/src/ipa/rkisp1/algorithms/agc.h b/src/ipa/rkisp1/algorithms/agc.h index 7867eed9c4e3..4432711f43af 100644 --- a/src/ipa/rkisp1/algorithms/agc.h +++ b/src/ipa/rkisp1/algorithms/agc.h @@ -51,8 +51,7 @@ private: ControlList &metadata); double estimateLuminance(double gain) const override; void processFrameDuration(IPAContext &context, - IPAFrameContext &frameContext, - utils::Duration frameDuration); + IPAFrameContext &frameContext); Span expMeans_; Span weights_;