From patchwork Wed Jul 13 08:43:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16607 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 BD29BBE173 for ; Wed, 13 Jul 2022 08:43:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4C9806332C; Wed, 13 Jul 2022 10:43:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657701829; bh=ie3aENqbC44ysjMYLpStHnU7FOOcWn4heFKrwvTdjYI=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=t/eYYLAmo7tEuITyi6T3pwLmw2yFN7Tthx6aEQZPWYyqEnXzfD6pSst2PX9nCCids MQV6tHq11k0UFeXmt6TMHY2bOO5+Zv5e0NoZ2OxXcanQaX6j2W+FhIdhbsp6S7/Mqv HAtO00I8uoZc+AcUaYx3Anpy+Po/Al5XXTW7DJtJ22himpgK/p92jn8cyLrLKtGDE6 vL5vdfGX28jnMfVy5BRikVze78kgVM2hVWRmvyh2ltGShhJuLVExoUGYPLGghcx9Nm bHGFnArYvTB3elB2ym5zE/MAgLCCjcPcs1VbsEBJfo/NfJ/SCiTuv+w2qizIeH9VjW rLtaQX66B+Cjg== Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B631F6330D for ; Wed, 13 Jul 2022 10:43:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=thaumatec-com.20210112.gappssmtp.com header.i=@thaumatec-com.20210112.gappssmtp.com header.b="O1WzAwMf"; dkim-atps=neutral Received: by mail-wm1-x333.google.com with SMTP id ay25so6092244wmb.1 for ; Wed, 13 Jul 2022 01:43:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EHJVI5NARITEoRsYFHX1Zu3g0dX4ygzx+AElRmV8oEA=; b=O1WzAwMf+mOLTIUZ1FLvwZ/bmJvRZSgfrzr5HpQLNuvgbXQno/F9WObTO6hVt0GPJF hCOwacYXWQMnGvjZLGWhUXUZcI9JdLLUVj0FvhAMwm1MHdTMY+J4jJfbIgh8nNAholWH mCae9L+2l1PWfVLBHOCrGPsWiWOpYbVw+6UfhJjK/pWqJ4bQTueWAHOrqdB4rEhUATiE kRHQhCs09M4Rfba9klxJNG+ihvsToEz2GB4GyB02hvRmYDz2T1XlwQ1UTV8pIkBLvreo +OeiQC1GNmzulMRDtduYCxiCIZOFG+3BDEtyI6HMeXms9SjFzz1B/YjtMeR5YfPGyeLn RUtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EHJVI5NARITEoRsYFHX1Zu3g0dX4ygzx+AElRmV8oEA=; b=6suac/I/6SnACOFprgdAhNMY1+7HwouSd1J5MaBy8354JNpz2m4qfjb1XjzCMReT+2 rXNAcnYc8TJVOLkZ5qjN+Xjf2X92NF+pzphfavcw7B7lDfzqq2n6FCQgzscv0mkpug6t KcCqhWdJS3o9WK+VpFtDkuPBx4yGs2J3+sHbJBHUfh0bGMbM3zPZAN3rtohb6V07PnAM /msBzuk29Sa3jllAfAMOlybxbJ0Lbw5AQ2V8WCSmEsRqWNO/yWt74Vap5vTWNUKaz7hU rFb6ibL1HWdcLw3u2MRNeO/9CB09Ct78VmgTq08kCPH4eNnjsIsNSpQ6WUZFSS4/6z4H FYqg== X-Gm-Message-State: AJIora8EvCsJsD86daJxKIhC8sbaj4JNy8pXaqfixogO4E7+8zj1pKn9 sKcZopxcaE9ei+0sucyzqg3OmVY4SZ4U4Q== X-Google-Smtp-Source: AGRyM1sYjbpxZjtcwZqdLAwM3LTx9cbwbxoR/cOoPYTs0hGZ518zfNJfGrxVVdXPp7LfE5iXKjn4NA== X-Received: by 2002:a05:600c:33a2:b0:3a2:fda9:6489 with SMTP id o34-20020a05600c33a200b003a2fda96489mr800546wmp.29.1657701827320; Wed, 13 Jul 2022 01:43:47 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id bg32-20020a05600c3ca000b003a04d19dab3sm5667468wmb.3.2022.07.13.01.43.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 01:43:46 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Jul 2022 10:43:15 +0200 Message-Id: <20220713084317.24268-10-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713084317.24268-1-dse@thaumatec.com> References: <20220713084317.24268-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 09/11] ipa: af_hill_climb: Skip the first frame after triggering auto focus 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: , X-Patchwork-Original-From: Daniel Semkowicz via libcamera-devel From: Daniel Semkowicz Reply-To: Daniel Semkowicz Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When AFTrigger is received, AF algorithm internal state is reset to initial values. If reset happens between frames, then first contrast value that arrives after this, is interpreted as contrast for initial position. This is wrong, because it was measured for lens position before the reset. Skip this first frame to allow correct contrast measure for the initial lens position. Signed-off-by: Daniel Semkowicz --- .../libipa/algorithms/af_hill_climbing.cpp | 8 +++++++ src/ipa/libipa/algorithms/af_hill_climbing.h | 23 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/ipa/libipa/algorithms/af_hill_climbing.cpp b/src/ipa/libipa/algorithms/af_hill_climbing.cpp index f666c6c2..28d09176 100644 --- a/src/ipa/libipa/algorithms/af_hill_climbing.cpp +++ b/src/ipa/libipa/algorithms/af_hill_climbing.cpp @@ -84,6 +84,14 @@ namespace ipa::common::algorithms { * \return New lens position calculated by AF algorithm */ +/** + * \fn AfHillClimbing::setFramesToSkip() + * \brief Request AF to skip n frames + * \param[in] n Number of frames to be skipped + * + * Requested number of frames will not be used for AF calculation. + */ + } /* namespace ipa::common::algorithms */ } /* namespace libcamera */ diff --git a/src/ipa/libipa/algorithms/af_hill_climbing.h b/src/ipa/libipa/algorithms/af_hill_climbing.h index db9fc058..e251f3eb 100644 --- a/src/ipa/libipa/algorithms/af_hill_climbing.h +++ b/src/ipa/libipa/algorithms/af_hill_climbing.h @@ -29,7 +29,7 @@ public: lensPosition_(0), bestPosition_(0), currentContrast_(0.0), previousContrast_(0.0), maxContrast_(0.0), maxStep_(0), coarseCompleted_(false), fineCompleted_(false), - lowStep_(0), highStep_(kMaxFocusSteps) + lowStep_(0), highStep_(kMaxFocusSteps), framesToSkip_(0) { } @@ -92,6 +92,9 @@ protected: { currentContrast_ = currentContrast; + if (shouldSkipFrame()) + return lensPosition_; + /* If we are in a paused state, we won't process the stats */ if (pauseState_ == libcamera::controls::AfPauseStatePaused) return lensPosition_; @@ -113,6 +116,12 @@ protected: return lensPosition_; } + void setFramesToSkip(uint32_t n) + { + if (n > framesToSkip_) + framesToSkip_ = n; + } + private: void afCoarseScan() { @@ -191,6 +200,7 @@ private: coarseCompleted_ = false; fineCompleted_ = false; maxContrast_ = 0.0; + setFramesToSkip(1); } bool afIsOutOfFocus() @@ -206,6 +216,16 @@ private: return false; } + bool shouldSkipFrame() + { + if (framesToSkip_ > 0) { + framesToSkip_--; + return true; + } + + return false; + } + controls::AfModeEnum mode_; controls::AfStateEnum state_; controls::AfPauseStateEnum pauseState_; @@ -229,6 +249,7 @@ private: uint32_t lowStep_; uint32_t highStep_; + uint32_t framesToSkip_; /* * Maximum focus steps of the VCM control