From patchwork Wed Oct 21 07:59:47 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 28542 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 13C39C3302 for ; Wed, 21 Oct 2026 08:00:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 369B868F2C; Wed, 21 Oct 2026 10:00:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="UnswMlDT"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 48A3668F25 for ; Wed, 21 Oct 2026 10:00:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792569618; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5C8yuOe8K7piUL1jlph79dtj+SgM/MSQLIhnbnkMGMk=; b=UnswMlDTYx45KCcOykVH+8h+6dB7r775mKIKLQa/U2Zn5aDEUYhv78+AnS5f0qbUK06Tq0 k0aALeEKCM6kJ7mtMSq22X8bDtE6x0W9aRHdSZaE40d315Qt7zs1XNpSiX0t04ovOf+q1H BAMnLHJA0o+XoVSl0u+ApAlMrAQa8OE= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-584-TZ7XRbv3OGKfk1Dm9LWW2A-1; Wed, 21 Oct 2026 08:00:16 +0000 X-MC-Unique: TZ7XRbv3OGKfk1Dm9LWW2A-1 X-Mimecast-MFC-AGG-ID: TZ7XRbv3OGKfk1Dm9LWW2A_1792569615 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AB35818007F7 for ; Wed, 21 Oct 2026 08:00:15 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.43.17.75]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DF1C2180029C; Wed, 21 Oct 2026 08:00:14 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH 7/7] ipa: libipa: Use autofocus limits if available Date: Wed, 21 Oct 2026 09:59:47 +0200 Message-ID: <20261021080000.16624-8-mzamazal@redhat.com> In-Reply-To: <20261021080000.16624-1-mzamazal@redhat.com> References: <20261021080000.16624-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: aYeYMOcc309WHS-BLG21zIg1VCmN-AslKGJOg3GGYyM_1792569615 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true 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" Let's try to set the maximum and the initial focusing positions rather than using hard-wired values. Signed-off-by: Milan Zamazal --- src/ipa/ipu3/algorithms/af.cpp | 2 +- src/ipa/libipa/af.cpp | 26 +++++++++++++++++++++----- src/ipa/libipa/af.h | 5 ++++- src/ipa/softisp/algorithms/af.cpp | 5 ++--- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp index bb412e165..f79ef4b99 100644 --- a/src/ipa/ipu3/algorithms/af.cpp +++ b/src/ipa/ipu3/algorithms/af.cpp @@ -141,7 +141,7 @@ int Af::configure(IPAContext &context, const IPAConfigInfo &configInfo) grid.y_start = utils::alignDown(start.y, 2); grid.y_start |= IPU3_UAPI_GRID_Y_START_EN; - afAlgo_.configure(context.activeState.af); + afAlgo_.configure(context.activeState.af, configInfo.lensControls); return 0; } diff --git a/src/ipa/libipa/af.cpp b/src/ipa/libipa/af.cpp index 492d65d1e..fc71bcd7b 100644 --- a/src/ipa/libipa/af.cpp +++ b/src/ipa/libipa/af.cpp @@ -7,6 +7,8 @@ #include "af.h" +#include + namespace libcamera { namespace ipa { @@ -40,8 +42,7 @@ namespace af { */ /** - * Maximum focus steps of the VCM control - * \todo should be obtained from the VCM driver + * Default maximum focus steps of the VCM control */ static constexpr uint32_t kMaxFocusSteps = 1023; @@ -135,7 +136,7 @@ void AfAlgorithm::afReset(af::ActiveState &state) previousVariance_ = 0.0; coarseCompleted_ = false; fineCompleted_ = false; - maxStep_ = kMaxFocusSteps; + maxStep_ = initMaxStep_; } /** @@ -244,14 +245,15 @@ bool AfAlgorithm::afIsOutOfFocus(af::ActiveState &state) /** * \brief Configure the algorithm and \a state * \param[in] state The autofocus state + * \param[in] lensControls The lens controls * * The method just sets some initial variable values rather than performing real * configuration but it is supposed to be called from IPA's `configure`. */ -void AfAlgorithm::configure(af::ActiveState &state) +void AfAlgorithm::configure(af::ActiveState &state, const ControlInfoMap &lensControls) { /* Initial max focus step */ - maxStep_ = kMaxFocusSteps; + initMaxStep_ = kMaxFocusSteps; /* Initial frame ignore counter */ afIgnoreFrameReset(); @@ -262,6 +264,20 @@ void AfAlgorithm::configure(af::ActiveState &state) state.maxVariance = 0; /* The stable AF value flag. if it is true, the AF should be in a stable state. */ state.stable = false; + + const auto it = lensControls.find(V4L2_CID_FOCUS_ABSOLUTE); + if (it != lensControls.end()) { + const ControlInfo &focusInfo = it->second; + if (!focusInfo.max().isNone()) + initMaxStep_ = static_cast(focusInfo.max().get()); + if (!focusInfo.def().isNone()) + state.focus = static_cast(focusInfo.def().get()); + } + + maxStep_ = initMaxStep_; + + LOG(Af, Debug) << "Configured focus parameters: max=" << initMaxStep_ + << " focus=" << state.focus; } /** diff --git a/src/ipa/libipa/af.h b/src/ipa/libipa/af.h index c902b434c..0b2587ed9 100644 --- a/src/ipa/libipa/af.h +++ b/src/ipa/libipa/af.h @@ -10,6 +10,7 @@ #include #include +#include namespace libcamera { @@ -32,7 +33,7 @@ class AfAlgorithm public: AfAlgorithm(); - void configure(af::ActiveState &state); + void configure(af::ActiveState &state, const ControlInfoMap &lensControls); void process(af::ActiveState &state, double variance); bool coarseCompleted() { return coarseCompleted_; } @@ -58,6 +59,8 @@ private: double previousVariance_; /* The designated maximum range of focus scanning. */ uint32_t maxStep_; + /* Initial value of maxStep_ */ + uint32_t initMaxStep_; /* If the coarse scan completes, it is set to true. */ bool coarseCompleted_; /* If the fine scan completes, it is set to true. */ diff --git a/src/ipa/softisp/algorithms/af.cpp b/src/ipa/softisp/algorithms/af.cpp index 557cca004..4fb834f8c 100644 --- a/src/ipa/softisp/algorithms/af.cpp +++ b/src/ipa/softisp/algorithms/af.cpp @@ -27,10 +27,9 @@ int Af::init(IPAContext &context, [[maybe_unused]] const ValueNode &tuningData) return 0; } -int Af::configure(IPAContext &context, - [[maybe_unused]] const IPAConfigInfo &configInfo) +int Af::configure(IPAContext &context, const IPAConfigInfo &configInfo) { - afAlgo_.configure(context.activeState.af); + afAlgo_.configure(context.activeState.af, configInfo.lensControls); return 0; }