From patchwork Fri Mar 31 08:19:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 18512 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 6D476C329F for ; Fri, 31 Mar 2023 08:19:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 300E26275E; Fri, 31 Mar 2023 10:19:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1680250797; bh=UhL1xu+M5DkWdlIAnFE96GJAJsI2ezOWH1CcduS/W6c=; 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=Etx/tDtCUgjfZLLmV0FmngAr68AK5kbzpbHRMKjA/wmDaOjvtOq7O/ZbN15deO37Q sUQg+ACpn9ATQLcjAwvq2dtuFISMgxlytrnCST9a9i3IGwQavGlxzbsw8qpz8IQ36z glZH6Jr6JKxZVQ87r2GlUgfpZiUSQpez52nx9pd631maw74w1a21AfangPoGliwdew aZbE45QlYnnWwuXNJ4J8gkWLVms/wQHE07nODbKOL0t9/WYhxfRCs0g8gD4Jqo1xN0 +13XoDpiSPLq71d94rC/tGHDD5FS7mDGutAPsb88j83LGbBjP7u9ylI+37XpB7WV3X 9VRZsBspjsG4g== Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 54E8362722 for ; Fri, 31 Mar 2023 10:19:50 +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="VmQdnUmV"; dkim-atps=neutral Received: by mail-lf1-x130.google.com with SMTP id h25so27886772lfv.6 for ; Fri, 31 Mar 2023 01:19:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; t=1680250789; x=1682842789; 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=euwlN3aSuvomdf/PRBNJbZXtWLrJyd6jWu6M9zlbGas=; b=VmQdnUmVoUf+M0W4FNUtyo5HPNp0OTg402wi7IrsygRYbMm021GAcb1/o6B5d++J8v CNpuj9w6cR190QlgD5gl0iDYN5fxI0ZqnUEwg9Utt7atsa1nPirClqq2ZL/jcq0sC4Ob 9moSi1PqGpMYUQ/kdPe1IZNxErfiUusFpbQNenLz/8P7iCoP9klQzoCLq4WAEz/0Sklf 9LOyfb1skS5mUkC6/H088ZpLY4hdiO6q/cE0Tqerhvwh3nLLaJwcypIcqE/BY/C904HD HGPmjz3jairIIw3KGGpqh9k0ADIGUkUm4PImXm/calsnLOJIzsUatonmZeyKEBo5ljFW UUtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680250789; x=1682842789; 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=euwlN3aSuvomdf/PRBNJbZXtWLrJyd6jWu6M9zlbGas=; b=zsCLt6qYq3Wlh7nYbX9Beta/oYreS4rABmQ7fWYM3KqSlyiBCoceY12NA+JDT07o5l iNXM8XV7DAamG1pYVSAryAVMY3y5f538XQL/LjnQnSTQGKajpFxzJxWZXIaCAuUSYpPE EE/9+fsjrBeHTIz3bOe9X0XMe8elVFaEwlfyntmwAjobt7S7V8ntx36+cp+vh+HO7JVo W3P+EGle4/26eLpCAHZTw3MEr8d+bzHJkxPQPPQ1Zcb/PQMSEiYMkg2q/jzM+3e531J8 RVer2CqMql+yjU0H6+G0vNq/oqDWS7pkfezj1Zhany4L4goXuaXaJtu/sMUKQ+KhlqtW wVpg== X-Gm-Message-State: AAQBX9dxV1W1Dba6s+6ouoceQ/1xXX8cX5WIddZEmPBckp7MkIOaTbPr enj1U0WLTm0H6shE4TqJrdQEsbGurEpqdYmXPAzqkQ== X-Google-Smtp-Source: AKy350YT3xInhHyUREfCj9LrlbRd5Zo57Kroyl+PYcdqWZSae4JN9XHtaHfxGY0rBQsHjHn3MItHCA== X-Received: by 2002:a19:f60e:0:b0:4a9:39f4:579a with SMTP id x14-20020a19f60e000000b004a939f4579amr7419903lfe.66.1680250789602; Fri, 31 Mar 2023 01:19:49 -0700 (PDT) Received: from localhost.localdomain ([91.90.166.178]) by smtp.gmail.com with ESMTPSA id t1-20020ac24c01000000b004e84a8c3d86sm281459lfq.42.2023.03.31.01.19.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 01:19:49 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 31 Mar 2023 10:19:25 +0200 Message-Id: <20230331081930.19289-6-dse@thaumatec.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230331081930.19289-1-dse@thaumatec.com> References: <20230331081930.19289-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 05/10] ipa: af_hill_climbing: Add "Windows" metering mode 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" Add support for setting user defined auto focus window in the AfHillClimbing. This enables usage of AfMetering and AfWindows controls. Each time, there is a need for changing the window configuration in the ISP, the signal is emitted. Platform layer that wants to use the "Windows" metering mode, needs to connect to this signal and configure the ISP on each emission. Currently only one window is supported. Signed-off-by: Daniel Semkowicz --- .../libipa/algorithms/af_hill_climbing.cpp | 62 +++++++++++++++++-- src/ipa/libipa/algorithms/af_hill_climbing.h | 10 +++ 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/src/ipa/libipa/algorithms/af_hill_climbing.cpp b/src/ipa/libipa/algorithms/af_hill_climbing.cpp index 244b8803..0fb17df3 100644 --- a/src/ipa/libipa/algorithms/af_hill_climbing.cpp +++ b/src/ipa/libipa/algorithms/af_hill_climbing.cpp @@ -63,9 +63,8 @@ LOG_DEFINE_CATEGORY(Af) * movement range rather than coarse search result. * \todo Implement setRange. * \todo Implement setSpeed. - * \todo Implement setMeteringMode. - * \todo Implement setWindows. * \todo Implement the AfPauseDeferred mode. + * \todo Implement support for multiple AF windows. */ /** @@ -99,6 +98,27 @@ int AfHillClimbing::init(int32_t minFocusPosition, int32_t maxFocusPosition, return 0; } +/** + * \brief Configure the AfHillClimbing with sensor information + * \param[in] outputSize Camera sensor output size + * + * This method should be called in the libcamera::ipa::Algorithm::configure() + * method of the platform layer. + */ +void AfHillClimbing::configure(const Size &outputSize) +{ + /* + * Default AF window of 3/4 size of the camera sensor output, + * placed at the center + */ + defaultWindow_ = Rectangle(static_cast(outputSize.width / 8), + static_cast(outputSize.height / 8), + 3 * outputSize.width / 4, + 3 * outputSize.height / 4); + + windowUpdateRequested.emit(defaultWindow_); +} + /** * \brief Run the auto focus algorithm loop * \param[in] currentContrast New value of contrast measured for current frame @@ -185,6 +205,14 @@ void AfHillClimbing::skipFrames(uint32_t n) framesToSkip_ = n; } +/** + * \var AfHillClimbing::windowUpdateRequested + * \brief Signal emitted when change in AF window was requested + * + * Platform layer supporting AF windows should connect to this signal + * and configure the ISP with new window on each emition. + */ + void AfHillClimbing::setMode(controls::AfModeEnum mode) { if (mode == mode_) @@ -210,14 +238,36 @@ void AfHillClimbing::setSpeed([[maybe_unused]] controls::AfSpeedEnum speed) LOG(Af, Error) << "setSpeed() not implemented!"; } -void AfHillClimbing::setMeteringMode([[maybe_unused]] controls::AfMeteringEnum metering) +void AfHillClimbing::setMeteringMode(controls::AfMeteringEnum metering) { - LOG(Af, Error) << "setMeteringMode() not implemented!"; + if (metering == meteringMode_) + return; + + meteringMode_ = metering; + + switch (metering) { + case controls::AfMeteringAuto: + windowUpdateRequested.emit(defaultWindow_); + break; + case controls::AfMeteringWindows: + windowUpdateRequested.emit(userWindow_); + break; + } } -void AfHillClimbing::setWindows([[maybe_unused]] Span windows) +void AfHillClimbing::setWindows(Span windows) { - LOG(Af, Error) << "setWindows() not implemented!"; + if (windows.size() != 1) { + LOG(Af, Error) << "Only one AF window is supported"; + return; + } + + LOG(Af, Debug) << "setWindows: " << windows[0]; + + userWindow_ = windows[0]; + + if (meteringMode_ == controls::AfMeteringWindows) + windowUpdateRequested.emit(userWindow_); } void AfHillClimbing::setTrigger(controls::AfTriggerEnum trigger) diff --git a/src/ipa/libipa/algorithms/af_hill_climbing.h b/src/ipa/libipa/algorithms/af_hill_climbing.h index 2147939b..0f7c65db 100644 --- a/src/ipa/libipa/algorithms/af_hill_climbing.h +++ b/src/ipa/libipa/algorithms/af_hill_climbing.h @@ -10,6 +10,7 @@ #pragma once #include +#include #include "af.h" @@ -26,12 +27,15 @@ class AfHillClimbing : public Af public: int init(int32_t minFocusPosition, int32_t maxFocusPosition, const YamlObject &tuningData); + void configure(const Size &outputSize); int32_t process(double currentContrast); void skipFrames(uint32_t n); controls::AfStateEnum state() override { return state_; } controls::AfPauseStateEnum pauseState() override { return pauseState_; } + Signal windowUpdateRequested; + private: void setMode(controls::AfModeEnum mode) override; void setRange(controls::AfRangeEnum range) override; @@ -54,6 +58,7 @@ private: controls::AfModeEnum mode_ = controls::AfModeManual; controls::AfStateEnum state_ = controls::AfStateIdle; controls::AfPauseStateEnum pauseState_ = controls::AfPauseStateRunning; + controls::AfMeteringEnum meteringMode_ = controls::AfMeteringAuto; /* Current focus lens position. */ int32_t lensPosition_ = 0; @@ -84,6 +89,11 @@ private: /* Max ratio of variance change, 0.0 < maxChange_ < 1.0. */ double maxChange_; + + /* Default AF window. */ + Rectangle defaultWindow_; + /* AF window set by user using AF_WINDOWS control. */ + Rectangle userWindow_; }; } /* namespace ipa::algorithms */