From patchwork Fri Sep 16 10:37:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kate Hsuan X-Patchwork-Id: 17377 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 49D9FC3272 for ; Fri, 16 Sep 2022 10:37:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E8CAC6208F; Fri, 16 Sep 2022 12:37:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1663324668; bh=EzhGxGjctKdsR7YJHD/qd9HhfmpwnUT20OnjG62q8UE=; 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=PSV/xpMtFslgr7Nnjrmuxet3eyVk4xhs7sgfpgrKs4bQtIte/lA4dLDmPo4XbqTlP WTSFMvD9/hfDLVq07bS4DXF666pJJprI+U5gGfINyVUq8NfSZSbF3f/4deAneyzbyx oeVVrUL1hHUcM3DyHxPKhKBu7Vu0qT0JY0/G5gayqk8f7SytNGzeYFS806/zcLEKih dWn6hvX9THrIB4a47MfAOzYtjhOfac3xG/tH4F4aT+wQ2kcedyyUQduXrAfKFt3lY/ LWGQovGQQ2AUMBWpcnrU+3U/Adj4e49ANHsJ0unw+ggRy6hi9BIj9QWpVE+HQwObNf gKzgy6so/86YQ== 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 60F2761FB7 for ; Fri, 16 Sep 2022 12:37:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="RaPxFG2X"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663324666; 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=LHGod8qOBDpSdbsgZjzmaChqt6EtIlH8wVkl3t9neO0=; b=RaPxFG2XzLcwVnuev1ZrWSSP6UQ9S/MqzsMs7u5w/uGN8JmjRHPwlWycxKwPqHa5EtD+tN QQfmR570oIM5fYxdCqq4PDTXQA8ikDno79rDN0XEbPv5PeMEQIJXheLT2oOfTaArgz0PVi 02Cc2mnnxQUplKlTzo8TFxhNSIV52AQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-312-Z8fWpUbWPeudzNX4Rnhdww-1; Fri, 16 Sep 2022 06:37:45 -0400 X-MC-Unique: Z8fWpUbWPeudzNX4Rnhdww-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 497DD101A528 for ; Fri, 16 Sep 2022 10:37:45 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.39.193.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id 35BA040C83EB; Fri, 16 Sep 2022 10:37:42 +0000 (UTC) To: libcamera devel , Hans De Goede Date: Fri, 16 Sep 2022 18:37:13 +0800 Message-Id: <20220916103713.21132-4-hpa@redhat.com> In-Reply-To: <20220916103713.21132-1-hpa@redhat.com> References: <20220916103713.21132-1-hpa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [libcamera-devel] [PATCH 3/3] ipa: ipu3: af: AfMode and LensPosition control implementation 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: Kate Hsuan via libcamera-devel From: Kate Hsuan Reply-To: Kate Hsuan Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" AfMode controls include manual, auto, and continuous modes. For auto and continuous modes, both of the algorithms try to keep the image focused. The difference between them is that continuous mode has higher sensitivity to the change of image variance than auto mode. So, the AF is frequently triggered in continuous mode. The user-defined lens position can only be set in manual mode. Signed-off-by: Kate Hsuan --- src/ipa/ipu3/algorithms/af.cpp | 106 ++++++++++++++++++++++++++++----- src/ipa/ipu3/algorithms/af.h | 15 +++++ 2 files changed, 105 insertions(+), 16 deletions(-) diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp index 4835a034..c57d3e18 100644 --- a/src/ipa/ipu3/algorithms/af.cpp +++ b/src/ipa/ipu3/algorithms/af.cpp @@ -21,6 +21,8 @@ #include +#include + #include #include "libipa/histogram.h" @@ -109,7 +111,8 @@ static struct ipu3_uapi_af_filter_config afFilterConfigDefault = { */ Af::Af() : focus_(0), bestFocus_(0), currentVariance_(0.0), previousVariance_(0.0), - coarseCompleted_(false), fineCompleted_(false) + coarseCompleted_(false), fineCompleted_(false), maxChange_(kMaxChange), + afMode_(controls::AfModeAuto) { } @@ -194,6 +197,69 @@ int Af::configure(IPAContext &context, const IPAConfigInfo &configInfo) return 0; } +/** + * \brief AF controls handler + * + * Put the control parameter to the corresponding variables when receiving the controls + * from the user. + * \param[in] context The shared IPA context + * \param[in] frame Frame number + * \param[in] controls control list of the request + */ +void Af::queueRequest([[maybe_unused]] IPAContext &context, + [[maybe_unused]] const uint32_t frame, + const ControlList &controls) +{ + for (auto const &ctrl : controls) { + unsigned int ctrlEnum = ctrl.first; + const ControlValue &ctrlValue = ctrl.second; + + switch (ctrlEnum) { + case controls::AF_MODE: + afModeSet(ctrlValue.get()); + break; + case controls::LENS_POSITION: + lensPosition_ = ctrlValue.get(); + } + } +} + +/** + * \brief AF Mode set + * + * Set AF mode, including manual, auto, and continuous. + * + * \param[in] AF operation mode 0, 1, 2 are manual, auto, and continuous, respectively. + */ + +void Af::afModeSet(uint32_t mode) +{ + switch (mode) { + case controls::AfModeManual: + case controls::AfModeAuto: + afMode_ = mode; + break; + case controls::AfModeContinuous: + afMode_ = mode; + maxChange_ = 0.05; + break; + default: + afMode_ = controls::AfModeAuto; + } + + LOG(IPU3Af, Debug) << "AfMode set " << mode; +} + +/** + * \brief Set lens position + * + * Set user-defined lens position to the focus steps. + */ +void Af::afLensPositionSet(IPAContext &context) +{ + context.activeState.af.focus = kMaxFocusSteps * lensPosition_; +} + /** * \brief AF coarse scan * @@ -397,7 +463,7 @@ bool Af::afIsOutOfFocus(IPAContext context) << " Current VCM step: " << context.activeState.af.focus; - if (var_ratio > kMaxChange) + if (var_ratio > maxChange_) return true; else return false; @@ -432,21 +498,29 @@ void Af::process(IPAContext &context, [[maybe_unused]] IPAFrameContext *frameCon Span y_items(reinterpret_cast(&stats->af_raw_buffer.y_table), afRawBufferLen); - /* - * Calculate the mean and the variance of AF statistics for a given grid. - * For coarse: y1 are used. - * For fine: y2 results are used. - */ - currentVariance_ = afEstimateVariance(y_items, !coarseCompleted_); + switch (afMode_) { + case controls::AfModeManual: + afLensPositionSet(context); + break; + case controls::AfModeContinuous: + case controls::AfModeAuto: + default: + /* + * Calculate the mean and the variance of AF statistics for a given grid. + * For coarse: y1 are used. + * For fine: y2 results are used. + */ + currentVariance_ = afEstimateVariance(y_items, !coarseCompleted_); - if (!context.activeState.af.stable) { - afCoarseScan(context); - afFineScan(context); - } else { - if (afIsOutOfFocus(context)) - afReset(context); - else - afIgnoreFrameReset(); + if (!context.activeState.af.stable) { + afCoarseScan(context); + afFineScan(context); + } else { + if (afIsOutOfFocus(context)) + afReset(context); + else + afIgnoreFrameReset(); + } } } diff --git a/src/ipa/ipu3/algorithms/af.h b/src/ipa/ipu3/algorithms/af.h index ccf015f3..77bab2a7 100644 --- a/src/ipa/ipu3/algorithms/af.h +++ b/src/ipa/ipu3/algorithms/af.h @@ -26,6 +26,7 @@ class Af : public Algorithm uint16_t y1_avg; uint16_t y2_avg; } y_table_item_t; + public: Af(); ~Af() = default; @@ -34,6 +35,9 @@ public: int configure(IPAContext &context, const IPAConfigInfo &configInfo) override; void process(IPAContext &context, IPAFrameContext *frameContext, const ipu3_uapi_stats_3a *stats) override; + void queueRequest([[maybe_unused]] IPAContext &context, + [[maybe_unused]] const uint32_t frame, + [[maybe_unused]] const ControlList &controls) override; private: void afCoarseScan(IPAContext &context); @@ -46,6 +50,11 @@ private: bool afIsOutOfFocus(IPAContext context); + void afModeSet(uint32_t mode); + void afModeGet(); + + void afLensPositionSet(IPAContext &context); + /* VCM step configuration. It is the current setting of the VCM step. */ uint32_t focus_; /* The best VCM step. It is a local optimum VCM step during scanning. */ @@ -62,6 +71,12 @@ private: bool coarseCompleted_; /* If the fine scan completes, it is set to true. */ bool fineCompleted_; + /* Max focus change ratio to determine */ + double maxChange_; + /* Relative lens position in percentage. */ + double lensPosition_; + /* Af operation mode. */ + uint32_t afMode_; }; } /* namespace ipa::ipu3::algorithms */