From patchwork Fri Jun 20 12:42:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 23613 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 30CBCBDE6B for ; Fri, 20 Jun 2025 12:45:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 378E268DF5; Fri, 20 Jun 2025 14:45:10 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="HPdXYfRo"; dkim-atps=neutral Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DD1D468DC6 for ; Fri, 20 Jun 2025 14:45:00 +0200 (CEST) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3a4e57d018cso300746f8f.1 for ; Fri, 20 Jun 2025 05:45:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1750423500; x=1751028300; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=24KjDT2YWBwBNbd3x7CDgdf7GATAgEkVdmI8IyKPmTk=; b=HPdXYfRo2ks970/Fft3QaFiIH73SI5e46U2u6ZTWGQ4d+O5APdXdSpTNDVYtLiP2sK XiMbyxEHxEGn0EWb4ntC48Rm7nnMoys0mfog1RMSIEygaYKOWCNJqXlIYBcQMjzCq50p Fj8blBwpI0uGMIH6aYAOKOoMFMKEmcC0uoygYJBePrBaCrobmXy27MqB0F2nFhnqagEn jccWoQoqyQWUpf2rY2uycuGZxGt+SWAEKT8BZ5zKy+fRY4NEuAcpAIhMqwVBFAynknmY En0ARGU6w18WD2s7k+YwKHFkOBXhAJ9kwxVJbTxGWrHGDwbap9Xw8LprYt7ALqpbxGLb DgEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750423500; x=1751028300; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=24KjDT2YWBwBNbd3x7CDgdf7GATAgEkVdmI8IyKPmTk=; b=uk81i1IjqmJuAQm/lsitdWNZdiOoiYqAVvnvaO3xsBwMB4uQznV0nQg5zOUfwvtHdk iMMtYdJSx5ESHoNcjkcsnzSxujzGQ+LXy5uTOaZy+NGozvKrA+y5UsYexCHSjwyPeNoC QjiyZ2K3QzbfWmbmx5iUFd00O7CSznF9tbNBbjKRFipJoDR0atMP1xdCKm9M5mXipLmo 1Mi3H7LvgY7cRVC6px65NoLDxgZrMmH86Q23BpjiTa8fLpSnBLhEtvrL1Dr5KbTQHpSH ZXdiJ4AM2yxUftwX1fR52g6QWcvB2S+lubxZ3TGGvLapVnmrZVRD4Jt3JZJZHND3aUlX vE7A== X-Gm-Message-State: AOJu0YzPSGv9SOuPlwoWuufKWqXsvqtRluM+unNV/l/iWHwMT48IZOnb u89gLANeFbnouLuzKNIc/u2SBvsDRvBT9LSHmRJsSnvLKUs23UxVRuvk7hV4eJO49XafcHi2FFT egDYi X-Gm-Gg: ASbGncuymL5oLAxDzZHRZP+UMp7jIrA61egGp+8EcJVBxFL8mdYXGXU1XQ11dFBSwdp YJGa9ZXPLYM9sLd4qS6nx/bhcjCKDvWi1o4xFshdJIIDwSuCkTo0ONYjux6AHKyF1ZXGOeTaOln wOpogYY1k/x4weKiZlq/6n5+cbj7SbnMgXG9/pYRF9W8q7XF0CNurmtpoDI4fmkFcTElsHwxjDd B7sBMRXP7NhHyBWjJzEGfSNngDCU3TqOSJuVCaJuy9Syp5ZmMCuJnS4dQEyVM0Qk5HvlphzxDXd MW3MjMIEqErv2GUajRF1j1rTUbWhecm7TBPVSQP/23AA4mVyB94zSE6qdmVieM8F7dkGpeQL1s6 fSt8+Qw== X-Google-Smtp-Source: AGHT+IHBgECgTN4VV0Cclz5AavamnOvPTx3PmVkiyqVoabLjkewYkt8veSsk0wosL4yQYHTE5lZfVQ== X-Received: by 2002:a05:6000:2211:b0:3a5:7875:576 with SMTP id ffacd0b85a97d-3a6d12d737bmr901101f8f.1.1750423500172; Fri, 20 Jun 2025 05:45:00 -0700 (PDT) Received: from NAUSH-P-DELL.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45361461375sm41561525e9.14.2025.06.20.05.44.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jun 2025 05:44:59 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Nick Hollinghurst , Naushir Patuck Subject: [PATCH v1 5/8] ipa: rpi: controller: AutoFocus tweak earlyTerminationByPhase() Date: Fri, 20 Jun 2025 13:42:26 +0100 Message-ID: <20250620124452.557855-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250620124452.557855-1-naush@raspberrypi.com> References: <20250620124452.557855-1-naush@raspberrypi.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" From: Nick Hollinghurst Increase threshold for ETBP, from "confEpsilon" to "confThresh". Correct sign test to take account of pdafGain sign (typically -ve). Reduce allowed extrapolation range, but relax the check in the case of Continuous AF, when we go back into the PDAF closed loop. Signed-off-by: Nick Hollinghurst Signed-off-by: Naushir Patuck Reviewed-by: Naushir Patuck --- src/ipa/rpi/controller/rpi/af.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ipa/rpi/controller/rpi/af.cpp b/src/ipa/rpi/controller/rpi/af.cpp index 3b2d6167df61..ecc0fc4175a7 100644 --- a/src/ipa/rpi/controller/rpi/af.cpp +++ b/src/ipa/rpi/controller/rpi/af.cpp @@ -411,7 +411,7 @@ void Af::doPDAF(double phase, double conf) bool Af::earlyTerminationByPhase(double phase) { if (scanData_.size() > 0 && - scanData_[scanData_.size() - 1].conf >= cfg_.confEpsilon) { + scanData_[scanData_.size() - 1].conf >= cfg_.confThresh) { double oldFocus = scanData_[scanData_.size() - 1].focus; double oldPhase = scanData_[scanData_.size() - 1].phase; @@ -420,11 +420,12 @@ bool Af::earlyTerminationByPhase(double phase) * Interpolate/extrapolate the lens position for zero phase. * Check that the extrapolation is well-conditioned. */ - if ((ftarget_ - oldFocus) * (phase - oldPhase) > 0.0) { + if ((ftarget_ - oldFocus) * (phase - oldPhase) * cfg_.speeds[speed_].pdafGain < 0.0) { double param = phase / (phase - oldPhase); - if (-3.0 <= param && param <= 3.5) { - ftarget_ += param * (oldFocus - ftarget_); + if ((-2.5 <= param || mode_ == AfModeContinuous) && param <= 3.0) { LOG(RPiAf, Debug) << "ETBP: param=" << param; + param = std::max(param, -2.5); + ftarget_ += param * (oldFocus - ftarget_); return true; } } @@ -562,7 +563,7 @@ void Af::doAF(double contrast, double phase, double conf) else scanState_ = ScanState::Idle; scanData_.clear(); - } else if (conf >= cfg_.confEpsilon && earlyTerminationByPhase(phase)) { + } else if (conf >= cfg_.confThresh && earlyTerminationByPhase(phase)) { scanState_ = ScanState::Settle; stepCount_ = (mode_ == AfModeContinuous) ? 0 : cfg_.speeds[speed_].stepFrames;