From patchwork Fri Mar 31 08:19:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 18507 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 1AD34C0F2A for ; Fri, 31 Mar 2023 08:19:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A4DFD62765; Fri, 31 Mar 2023 10:19:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1680250791; bh=Xlqry35QGeFgO4MUhQSMCzZgAwW0xH4op2wpXaof5SI=; 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=28JzW9ojSIzqM50aLuUkV/1ST0HiMM93gmi7gVQ6eo5trE7som0bojToXw2Ok15zO 5Lt1HdanUE3+DS6yVyb/dnzEdhef80iNccFMgCpDdsybvUUWr9oWY+DFMw5LNWKT69 S4v2V2WO9Ii1ipMX4YLVWsUr3xL0jxSpPxDGbPy56004h5NBbYtphpP8yDvvhwXsCp 5L5XNssvxSi9vE41/5JKFJXMtS5OX6xsdCdERnGZEtX8K2DuB3hbo0nMsGRGeuNmqb lXvwhXT6x0WT9MDDsj+tVxbHp6KrE+yNvCCIiQ3J+YBbqbYBksX6EJgnBzQIRUJI3N JyOW4duvi7yKQ== Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3943B62722 for ; Fri, 31 Mar 2023 10:19:48 +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="XXo306x9"; dkim-atps=neutral Received: by mail-lf1-x12f.google.com with SMTP id x17so27907439lfu.5 for ; Fri, 31 Mar 2023 01:19:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; t=1680250787; x=1682842787; 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=0mu1r/8wM3TSeApccdh7KohQ9GGVjjXXDk4nYZ77Uw4=; b=XXo306x9bzwQhtX18eYwi0leWk1OQXZJzW8ehBwAudTiBsjQACBtkvidqz/QhDk47p Aarj+YlpVDrwM7/Kx3FezVu/tbL1Lsb4gJX9NgKJ42Fer38RWMBIREQ/68C9EP/UbZZ6 HrPI8idfzW8X0dfzhSYodQx2+r/jOpqQOMRUCKSpaxE3UxT+l7BzfisfDAGpu0Ka6G9c qgssZUf2VtaG/STFz5NxmINBrWAr/YVD/TtsEcledhbBpFZTj9H0tvpnbgFbwvuxm4S/ blfjneDvX3DlvapcRvj4JSX7E8ezDIgJX1o/qs9xmsOh/kybEAGzx4svIbKRKnvQu/sZ vlkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680250787; x=1682842787; 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=0mu1r/8wM3TSeApccdh7KohQ9GGVjjXXDk4nYZ77Uw4=; b=mxXwJtlD44ZqYDTry20AtB3B1fh1FMeVxJA0FjkSddCNnxWOb6KNW2V+9uFc2ZIpd7 y26cIyya7oefsMSjo8911PG3EhopZ6mPR/IX8O8ZSogZLTqIbonFChN2dwYyWD5zMdF5 iu0Fw5yf3AJhfucld5XcNwtrjFwdou0a4rAtZKa/fJ4Pl8vPu0YETEBZtyM0u5ZrnAea 7ll2sNt+n2XxEH5eW3P+6hLh/jaKnBaHvwlfjssVbuqnItik+MgflnxFXP2irh2ycBWI lpKDl4hHHu7y4HxcDIaR0N+k1RrX0WVUgvKqrwEmN4UQAitp4ZcYZ7im3mTd+TszpPgo OCqw== X-Gm-Message-State: AAQBX9caMck2hn54AV43s9gq4I132bYm3M0E4htEtW7jVaSpNnxSxFCu 8ZadB/nPX5VOhTcqQgGt0s5rH5IjdtZPLM/dvIu6Pw== X-Google-Smtp-Source: AKy350YdiPXfx3nTDhJ0x1Uvr9yCk1ifa+etFlfDLBYqW/8foVk4q81chuKXPp+422qVb4QXJPLf6g== X-Received: by 2002:ac2:5983:0:b0:4eb:30f9:eeca with SMTP id w3-20020ac25983000000b004eb30f9eecamr160713lfn.28.1680250787615; Fri, 31 Mar 2023 01:19:47 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 01:19:47 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 31 Mar 2023 10:19:21 +0200 Message-Id: <20230331081930.19289-2-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 01/10] rkisp1: Add camera lens to PH and expose it to the IPA 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" Extend the IPA init() function by additional lensControls input parameter. Check in pipeline handler if camera lens exists, and expose its controls to the IPA using the new parameter. Signed-off-by: Daniel Semkowicz Reviewed-by: Jacopo Mondi --- include/libcamera/ipa/rkisp1.mojom | 3 ++- src/ipa/rkisp1/rkisp1.cpp | 7 +++++++ src/libcamera/pipeline/rkisp1/rkisp1.cpp | 9 ++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/libcamera/ipa/rkisp1.mojom b/include/libcamera/ipa/rkisp1.mojom index 1009e970..d4ff1230 100644 --- a/include/libcamera/ipa/rkisp1.mojom +++ b/include/libcamera/ipa/rkisp1.mojom @@ -17,7 +17,8 @@ interface IPARkISP1Interface { init(libcamera.IPASettings settings, uint32 hwRevision, libcamera.IPACameraSensorInfo sensorInfo, - libcamera.ControlInfoMap sensorControls) + libcamera.ControlInfoMap sensorControls, + libcamera.ControlInfoMap lensControls) => (int32 ret, libcamera.ControlInfoMap ipaControls); start() => (int32 ret); stop(); diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 6544c925..d338d374 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -52,6 +53,7 @@ public: int init(const IPASettings &settings, unsigned int hwRevision, const IPACameraSensorInfo &sensorInfo, const ControlInfoMap &sensorControls, + const ControlInfoMap &lensControls, ControlInfoMap *ipaControls) override; int start() override; void stop() override; @@ -80,6 +82,7 @@ private: std::map mappedBuffers_; ControlInfoMap sensorControls_; + std::optional lensControls_; /* revision-specific data */ rkisp1_cif_isp_version hwRevision_; @@ -123,6 +126,7 @@ std::string IPARkISP1::logPrefix() const int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision, const IPACameraSensorInfo &sensorInfo, const ControlInfoMap &sensorControls, + const ControlInfoMap &lensControls, ControlInfoMap *ipaControls) { /* \todo Add support for other revisions */ @@ -160,6 +164,9 @@ int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision, context_.configuration.sensor.lineDuration = sensorInfo.minLineLength * 1.0s / sensorInfo.pixelRate; + if (!lensControls.empty()) + lensControls_ = lensControls; + /* Load the tuning data file. */ File file(settings.configurationFile); if (!file.open(File::OpenModeFlag::ReadOnly)) { diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 8a30fe06..f966254a 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -32,6 +32,7 @@ #include #include "libcamera/internal/camera.h" +#include "libcamera/internal/camera_lens.h" #include "libcamera/internal/camera_sensor.h" #include "libcamera/internal/delayed_controls.h" #include "libcamera/internal/device_enumerator.h" @@ -367,8 +368,14 @@ int RkISP1CameraData::loadIPA(unsigned int hwRevision) return ret; } + ControlInfoMap lensControls; + CameraLens *lens = sensor_->focusLens(); + if (lens) + lensControls = lens->controls(); + ret = ipa_->init({ ipaTuningFile, sensor_->model() }, hwRevision, - sensorInfo, sensor_->controls(), &controlInfo_); + sensorInfo, sensor_->controls(), lensControls, + &controlInfo_); if (ret < 0) { LOG(RkISP1, Error) << "IPA initialization failure"; return ret; From patchwork Fri Mar 31 08:19:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 18509 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 8144EC329D for ; Fri, 31 Mar 2023 08:19:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2E10262724; Fri, 31 Mar 2023 10:19:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1680250794; bh=VUG4UFjzIQCeqV4WxyY3nTBPu3yS2LvNEUV/9j13dF0=; 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=Uz2oXma9PqJwMOLfViQZKcZb4Pxzon17U/oTiAeA760KX3uOKtxZbT+uJEqsSKndf lrruzckPQsPEpOgjiaxv558TQ+RTnrzpX2QmnNfdcayiGbbh+FWa5MrmN11tknD94I 5W2GYxZWbcy/3PqaisDLNV77XSxD5UM2kXUEwobLgErP26Redv8wc4WJ69OxbBFGZI BXqraFqUUyzEI6ugeS76wAASrMgoaFkZCGmFQ8NYM0p0v6PQHAKX9ZC79rQBrFV7l7 KhX/Px/q60aaXI0wyrxrw/MSZiiX+BlZnxFC+PlPGKZsd79LjL6trt85IcejnPGBeF 4cXZhJIMA3+YA== Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F0AD562724 for ; Fri, 31 Mar 2023 10:19:48 +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="6gOvMZPr"; dkim-atps=neutral Received: by mail-lf1-x131.google.com with SMTP id q16so27863204lfe.10 for ; Fri, 31 Mar 2023 01:19:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; t=1680250788; x=1682842788; 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=J1b/IOB9ADFX+04pgjf6PbC5dFg/NgQJ2Yx90sri+kU=; b=6gOvMZPre612Ot5Qk2NnnuUgVBt+kKWCoqZE+A372ISKJJRCBfmd2qTLIF91ejr7o9 ytmmjmQvK/F0n+dHX0iwp14VsO+Yt1rqnJV0QU38cf6DLamMAdop0bTx+obo3yB8u++f 8E3xGaR9qpHU6vL9MRtCPKbVxGZcdsmQXFW9QsAvmrDzcZhvBNcmw7ZDDTcL2nNh2BZg zFwX5YaYymQ666cj0aqv0Io5KU0mkKDcoFS8H+vy7pZbz6DskD+tdyROHsN5RBUbc8ol SbgTAx6ITPopiKrE0OwdzBR6ufH3vVsu95JlYC/o3I7xGfSIgtx+qLZtsy96sknpl61w f7Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680250788; x=1682842788; 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=J1b/IOB9ADFX+04pgjf6PbC5dFg/NgQJ2Yx90sri+kU=; b=K9H+mdFQ26Owl1McSCNWLdITHKdCjmVQAjRc9Z29hIU20DMY/vhiFHhfiiEvvBRpFW Drhu5DFRSt0nbGHTEqHmI8rU94IRHHs1mA6WmoBaeZHbR05WrdtE3278ke43wkjEH/x/ BYwHTt/mCuaZbtFQR2GNVl2xVpt/gfB8Anc7SggexOl3Ow4/a/jZuStwoymnZTjn8Fwc 9crwDXcfiaMUQW0ODP4FXCJ/3qLqOqcYO5k/rj0qhlCsRKi6U9JHQGix7XVKwOPL/PHh UvU5KIp5Gl2LnWKLpKjgh4N7kmh1PQWn/JRRhRMLqII/yPVAFvpUsuseJD+H4atLw97/ ud4A== X-Gm-Message-State: AAQBX9f0JVBOvwV3/bHYREpeT+FlPYvyrNNV/QxCHSgmtQv4Rv7aZpFT eHjbsBT4opR0RQiQN1Qpx44Q/37NtP+lONZSpHPIPQ== X-Google-Smtp-Source: AKy350YhfL62OPs61OKTiSesHBgpnH8rk5py+PO8xzKk+uUfd92q+EESdGoQhiKaQOLxS0Oz3OlssA== X-Received: by 2002:ac2:522e:0:b0:4ea:f6ad:2977 with SMTP id i14-20020ac2522e000000b004eaf6ad2977mr7626143lfl.38.1680250788099; Fri, 31 Mar 2023 01:19:48 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 01:19:47 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 31 Mar 2023 10:19:22 +0200 Message-Id: <20230331081930.19289-3-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 02/10] ipa: rkisp1: Add lens limits to the session config 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 information about focus lens position limits to the IPA session configuration. These information can then be used by IPA algorithms to know which focus positions are valid. Signed-off-by: Daniel Semkowicz --- src/ipa/rkisp1/ipa_context.cpp | 17 +++++++++++++++++ src/ipa/rkisp1/ipa_context.h | 9 +++++++++ src/ipa/rkisp1/rkisp1.cpp | 23 ++++++++++++++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/ipa/rkisp1/ipa_context.cpp b/src/ipa/rkisp1/ipa_context.cpp index 9bbf3684..aea99299 100644 --- a/src/ipa/rkisp1/ipa_context.cpp +++ b/src/ipa/rkisp1/ipa_context.cpp @@ -14,6 +14,18 @@ namespace libcamera::ipa::rkisp1 { +/** + * \struct LensConfiguration + * \brief Lens-specific parameters + * + * \var LensConfiguration::minFocusPosition + * \brief Minimum position supported by the camera focus lens + * + * \var LensConfiguration::maxFocusPosition + * \brief Maximum position supported by the camera focus lens + * + */ + /** * \struct IPASessionConfiguration * \brief Session configuration for the IPA module @@ -89,6 +101,11 @@ namespace libcamera::ipa::rkisp1 { * \brief Sensor output resolution */ +/** + * \var IPASessionConfiguration::lens + * \brief Contains lens-specific parameters if lens was detected + */ + /** * \var IPASessionConfiguration::raw * \brief Indicates if the camera is configured to capture raw frames diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index b9b20653..65b3fbfe 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -8,6 +8,8 @@ #pragma once +#include + #include #include @@ -20,6 +22,11 @@ namespace libcamera { namespace ipa::rkisp1 { +struct LensConfiguration { + int32_t minFocusPosition = 0; + int32_t maxFocusPosition = 0; +}; + struct IPASessionConfiguration { struct { struct rkisp1_cif_isp_window measureWindow; @@ -45,6 +52,8 @@ struct IPASessionConfiguration { Size size; } sensor; + std::optional lens; + struct { rkisp1_cif_isp_version revision; } hw; diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index d338d374..292768cf 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -164,9 +164,21 @@ int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision, context_.configuration.sensor.lineDuration = sensorInfo.minLineLength * 1.0s / sensorInfo.pixelRate; - if (!lensControls.empty()) + if (!lensControls.empty()) { lensControls_ = lensControls; + const ControlInfo &focusAbsolute = + lensControls_->at(V4L2_CID_FOCUS_ABSOLUTE); + + LOG(IPARkISP1, Debug) + << "Focus lens: " << focusAbsolute.toString(); + + context_.configuration.lens = { + .minFocusPosition = focusAbsolute.min().get(), + .maxFocusPosition = focusAbsolute.max().get() + }; + } + /* Load the tuning data file. */ File file(settings.configurationFile); if (!file.open(File::OpenModeFlag::ReadOnly)) { @@ -234,6 +246,13 @@ int IPARkISP1::configure(const IPAConfigInfo &ipaConfig, << "Exposure: [" << minExposure << ", " << maxExposure << "], gain: [" << minGain << ", " << maxGain << "]"; + /* + * Save the existing lens configuration and restore it after context + * reset. It does not change since init(). + */ + const std::optional lensConfig = + context_.configuration.lens; + /* Clear the IPA context before the streaming session. */ context_.configuration = {}; context_.activeState = {}; @@ -272,6 +291,8 @@ int IPARkISP1::configure(const IPAConfigInfo &ipaConfig, return format.colourEncoding == PixelFormatInfo::ColourEncodingRAW; }); + context_.configuration.lens = lensConfig; + for (auto const &a : algorithms()) { Algorithm *algo = static_cast(a.get()); From patchwork Fri Mar 31 08:19:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 18510 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 D25EFC329E for ; Fri, 31 Mar 2023 08:19:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 152A362767; Fri, 31 Mar 2023 10:19:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1680250795; bh=hddsXWR2vySXjVpsnZ93ib9JXqd0WuueVyXpXXwMAIg=; 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=InR8s/ms3HKvAIa5bOtGKC8w3wgSvAYSsT4Zfiwgu0oDTAH+RrOCiIHiITCZoTZUO jLeJ6KCX8dsGEw4fsBNAPrt9986xSavWBVE+aoF9RlIStruHkwOA5b78a9BjbEdU/O DepvKPMku1tZbAtDe0lYSDOKwJXilGd+MwkXVMv8qzs/1AWf6pB/du+09hlrd/nVCk 7YdHa6s4GbYilI3NH4lfyxoJY2pLggxg0i95+nuSkY5iAFpa6AcEY7PqxJp9TaIrGR i1+9hpn56t9uCsL7GNs6Z/auFnTcBBoJngWzaMv51r4U7QHZUS5ATmuagGCPLrqb09 J8Z++EVMfe7DA== Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7A41162742 for ; Fri, 31 Mar 2023 10:19:49 +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="GFqxRz6A"; dkim-atps=neutral Received: by mail-lf1-x12e.google.com with SMTP id c29so27905491lfv.3 for ; Fri, 31 Mar 2023 01:19:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; t=1680250788; x=1682842788; 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=0vjSIcrrdh6zimT8RPShagomw5h++foc4CCMLhkKG50=; b=GFqxRz6ARcwppcy/nd1I82yb70ASUoklnz78O7wjUPdgqE0MUiK60kd3jj+vvuS3c5 qpYFZ2E7XAEyAHSD6AfsLE9k6QvBEaVGAZb6LQU92TSmTVOHvw3hxTdGlUdfr3q3DQwU 2/OzjhtlIDZfpNCWloNsmw+27bPCvipHLPnCkiDeSMvKKCbdg925N89ERy31UfYBGdzO u4lOPDeW0sMQGV/KA7fqWBpbMLtHPMAGObJfSLmpIUXpXWRWuOubD1agT+0tTS65z6RO 13P73i4RDl6yhUg2HauaLTMGOWL/Y8b4qFtAPFjSCcVnYJfz78SDPKHswojfRbBY3DCc D3Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680250788; x=1682842788; 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=0vjSIcrrdh6zimT8RPShagomw5h++foc4CCMLhkKG50=; b=rFFNOddB9EKHrYQwD2dUap/YzfE4Z1hOP5b2fwK2tV7d8gL/1NJOicVgv9UFduWGyO tQmvV+YzWXnGbrq++fwaeCfbRl6q34isADf+McAoGgDxTi/QRex2WfKZrUBV9KyAdJr7 1ePOA6x8IwA1wXpMptKOtV6gQ/VrDl+a5bCkTwgM5dU+HIB6LqUuMFLyDc2DLYvUEA9d 33joGroK69W/Q4wV+qVqm1W92AVBvKfB6w4z+XCz2OCbtLEBTyHjTjBdzbkgiO2XndTq FEcsdiVxKgQJmbGqsKPpfCgEZN4QW8dj3oF0NnS2wxIKbGyLzN9zw2Xnm1GmfxizM4Ry jIxg== X-Gm-Message-State: AAQBX9dWPOOg/yl5S4VJMLleHpkvrSEyJR0O0sVJ8Gh5lLL4YtWA5hE6 skIPuBP5P5zzP2mE6RtD1wu/ehLBQ9SmAVoamSPf5Q== X-Google-Smtp-Source: AKy350Z1ISVxuzW5Txws0lxFTK5jUukRI9XoexXbTKfPV6QWt3xF629JwEQbo1ERMHQ2NOeWXgbELQ== X-Received: by 2002:ac2:494f:0:b0:4eb:2523:e929 with SMTP id o15-20020ac2494f000000b004eb2523e929mr2228196lfi.43.1680250788593; Fri, 31 Mar 2023 01:19:48 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 01:19:48 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 31 Mar 2023 10:19:23 +0200 Message-Id: <20230331081930.19289-4-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 03/10] ipa: Add base class defining AF algorithm interface 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" Define common interface with pure virtual methods that should be implemented by the Auto Focus algorithm implementations. Interface methods match the AF controls that can be set in the frame request. Common implementation of controls parsing is provided, so the AF algorithms deriving from this interface should be able to reuse it. Signed-off-by: Daniel Semkowicz Reviewed-by: Jacopo Mondi --- src/ipa/libipa/algorithms/af.cpp | 159 ++++++++++++++++++++++++++ src/ipa/libipa/algorithms/af.h | 46 ++++++++ src/ipa/libipa/algorithms/meson.build | 9 ++ src/ipa/libipa/meson.build | 6 + 4 files changed, 220 insertions(+) create mode 100644 src/ipa/libipa/algorithms/af.cpp create mode 100644 src/ipa/libipa/algorithms/af.h create mode 100644 src/ipa/libipa/algorithms/meson.build diff --git a/src/ipa/libipa/algorithms/af.cpp b/src/ipa/libipa/algorithms/af.cpp new file mode 100644 index 00000000..0808aa3f --- /dev/null +++ b/src/ipa/libipa/algorithms/af.cpp @@ -0,0 +1,159 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2023, Theobroma Systems + * + * af.cpp - Autofocus control algorithm interface + */ + +#include "af.h" + +/** + * \file af.h + * \brief AF algorithm common interface + */ + +namespace libcamera { + +namespace ipa::algorithms { + +/** + * \class Af + * \brief Common interface for auto-focus algorithms + * + * The Af class defines a standard interface for IPA auto focus algorithms. + */ + +/** + * \brief Provide control values to the algorithm + * \param[in] controls The list of user controls + * + * This method should be called in the libcamera::ipa::Algorithm::queueRequest() + * method of the platform layer. + */ +void Af::queueRequest(const ControlList &controls) +{ + using namespace controls; + + for (auto const &[id, value] : controls) { + switch (id) { + case AF_MODE: { + setMode(static_cast(value.get())); + break; + } + case AF_RANGE: { + setRange(static_cast(value.get())); + break; + } + case AF_SPEED: { + setSpeed(static_cast(value.get())); + break; + } + case AF_METERING: { + setMeteringMode(static_cast(value.get())); + break; + } + case AF_WINDOWS: { + setWindows(value.get>()); + break; + } + case AF_TRIGGER: { + setTrigger(static_cast(value.get())); + break; + } + case AF_PAUSE: { + setPause(static_cast(value.get())); + break; + } + case LENS_POSITION: { + setLensPosition(value.get()); + break; + } + default: + break; + } + } +} + +/** + * \fn Af::setMode() + * \brief Set auto focus mode + * \param[in] mode AF mode + * + * \sa libcamera::controls::AfMode + */ + +/** + * \fn Af::setRange() + * \brief Set the range of focus distances that is scanned + * \param[in] range AF range + * + * \sa libcamera::controls::AfRange + */ + +/** + * \fn Af::setSpeed() + * \brief Set how fast algorithm should move the lens + * \param[in] speed Lens move speed + * +* \sa libcamera::controls::AfSpeed + */ + +/** + * \fn Af::setMeteringMode() + * \brief Set AF metering mode + * \param[in] metering AF metering mode + * + * \sa libcamera::controls::AfMetering + */ + +/** + * \fn Af::setWindows() + * \brief Set AF windows + * \param[in] windows AF windows + * + * \sa libcamera::controls::AfWindows + */ + +/** + * \fn Af::setTrigger() + * \brief Starts or cancels the autofocus scan + * \param[in] trigger Trigger mode + * + * \sa libcamera::controls::AfTrigger + */ + +/** + * \fn Af::setPause() + * \brief Pause the autofocus while in AfModeContinuous mode + * \param[in] pause Pause mode + * + * \sa libcamera::controls::AfPause + */ + +/** + * \fn Af::setLensPosition() + * \brief Set the lens position while in AfModeManual + * \param[in] lensPosition Lens position + * + * \sa libcamera::controls::LensPosition + */ + +/** + * \fn Af::state() + * \brief Get the current state of the AF algorithm + * \return AF state + * + * \sa libcamera::controls::AfState + */ + +/** + * \fn Af::pauseState() + * \brief Get the current pause state of the AF algorithm + * \return AF pause state + * + * \sa libcamera::controls::AfPauseState + */ + +} /* namespace ipa::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/libipa/algorithms/af.h b/src/ipa/libipa/algorithms/af.h new file mode 100644 index 00000000..47c919fe --- /dev/null +++ b/src/ipa/libipa/algorithms/af.h @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2023, Theobroma Systems + * + * af.h - Autofocus control algorithm interface + */ + +#pragma once + +#include + +namespace libcamera { + +namespace ipa::algorithms { + +class Af +{ +public: + virtual ~Af() = default; + + void queueRequest(const ControlList &controls); + + virtual void setMode(controls::AfModeEnum mode) = 0; + + virtual void setRange(controls::AfRangeEnum range) = 0; + + virtual void setSpeed(controls::AfSpeedEnum speed) = 0; + + virtual void setMeteringMode(controls::AfMeteringEnum metering) = 0; + + virtual void setWindows(Span windows) = 0; + + virtual void setTrigger(controls::AfTriggerEnum trigger) = 0; + + virtual void setPause(controls::AfPauseEnum pause) = 0; + + virtual void setLensPosition(float lensPosition) = 0; + + virtual controls::AfStateEnum state() = 0; + + virtual controls::AfPauseStateEnum pauseState() = 0; +}; + +} /* namespace ipa::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/libipa/algorithms/meson.build b/src/ipa/libipa/algorithms/meson.build new file mode 100644 index 00000000..3df4798f --- /dev/null +++ b/src/ipa/libipa/algorithms/meson.build @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: CC0-1.0 + +libipa_algorithms_headers = files([ + 'af.h', +]) + +libipa_algorithms_sources = files([ + 'af.cpp', +]) diff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build index 016b8e0e..134c2dba 100644 --- a/src/ipa/libipa/meson.build +++ b/src/ipa/libipa/meson.build @@ -1,5 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 +subdir('algorithms') + libipa_headers = files([ 'algorithm.h', 'camera_sensor_helper.h', @@ -8,6 +10,8 @@ libipa_headers = files([ 'module.h', ]) +libipa_headers += libipa_algorithms_headers + libipa_sources = files([ 'algorithm.cpp', 'camera_sensor_helper.cpp', @@ -16,6 +20,8 @@ libipa_sources = files([ 'module.cpp', ]) +libipa_sources += libipa_algorithms_sources + libipa_includes = include_directories('..') libipa = static_library('ipa', [libipa_sources, libipa_headers], From patchwork Fri Mar 31 08:19:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 18511 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 8977BC0F2A for ; Fri, 31 Mar 2023 08:19:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A837562759; Fri, 31 Mar 2023 10:19:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1680250795; bh=ZcXuYhFhh+Ks84tb0THDp7ea7naY2RPfb87KMg8BHRc=; 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=LCMTgJMYAXbn5yMsa60ZkKm4gerW/m95CoEW9NvWEyuIWVqwH2XE6rGaW6Xk/IA3U t+XTSoZSHiAwSuRXnXptfLQq0qnTQknysy0qZBT3MHvrf7FXLQ2RvGu35DYw2C1gp4 UVKEPY5GH9+iVGP8Ex2o+nKqv+Na2HonOkT5CaCuemqSB3H/BRwuC0D7C0kQ/f6XBz I7QRxZw4aMdiQ8fNAvRJgo2pGInrdgFoxD/PUBQ+++X8RerYbE4nBIi4y7lSArCQie G29+Qpg6uXlzytew+9Qu1HgTLljwY7/98LfUHwXf5iMCiWe0GPiWQCUWVEj0OZgL/n +7vvKI6NkwWKg== Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6B0906272A for ; Fri, 31 Mar 2023 10:19:49 +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="rfDNwqcN"; dkim-atps=neutral Received: by mail-lf1-x12f.google.com with SMTP id x17so27907493lfu.5 for ; Fri, 31 Mar 2023 01:19:49 -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=T2FBUpno9JtExitqdiT9DzuEnSZAMPrZpLm+AIRTzrE=; b=rfDNwqcNBxl97glwh7ZKuMEuVQCN1tWeAIuvpp2xCIzfQJhMGXz2mgMT/lX1dzbrBT azMl7C5KkV316VDiqf7WQlN6izDYKZ1C7fPO3/5ExHkVIbaiM1IXdqh9kflxYacyV6I9 XIJG/sanW395OvtbAcJkf9oWUiCRZUri1tzip+Xx72+3IuO/V7QRKA+Uqc7CF06voOqN tLyWjWnVm5ASUa5IFcjqZcASmnkdw+h4wMDEgkbEO2YyZQOYkeK+OuW/X8mxdeKpbC7S NUY9AvpAHXkdmSWyLmgQFYsvV4RT4HYPCBI7hTEd6fGcWwd6YKr72r0yr3hpN0vZRztd mKyw== 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=T2FBUpno9JtExitqdiT9DzuEnSZAMPrZpLm+AIRTzrE=; b=tSZRakZVRpSuBgwh1F6qDTCZrZz5Q+aLqZwgVwr56E8RcHxmXNHw0C7PpNXgyS0gPv 36RHr5sRYPrnt8WWsBMd2fFwPbzAF7bWoQtV/2b1EJVwawuNP7nSYwKrrg1joXioCkvA H7dQcLLYRDrEjI5x7IR0fZi6Ie6CYbNkhBouT/3mbkLb+L+5ULC3c8jRy838Y8wx8UVZ WL8qSKG1nUah8uuABI5iFzCkhuzG9MXr3fUz+rWG8LRn/ORF9aE5FZkw4ttBZTx7laui NmNa0RoQHTIt3VAU9R06txGFRc/PqMy3jMXM5LKlYncHSPfeP240KLfmsBjNcNadsd6C tU4g== X-Gm-Message-State: AAQBX9fEGLiTeeGmTEs4lptlgLEW3N2w/hhSr+HXACiunz0DggQRzbm3 4aEtYmX5xIwUlvJVKD9Vj5GZeNMtnirAcv7wJF7QLg== X-Google-Smtp-Source: AKy350bsU/G8/Gi72uWXV6ZXR58ce7qwZS8Xd5K8VYIob1cAxjwHDj/+TpK5lyZWpJAkPZMNdxJ1mQ== X-Received: by 2002:ac2:5df0:0:b0:4dd:cb1d:b3cc with SMTP id z16-20020ac25df0000000b004ddcb1db3ccmr8000541lfq.11.1680250789091; 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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 01:19:48 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 31 Mar 2023 10:19:24 +0200 Message-Id: <20230331081930.19289-5-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 04/10] ipa: Add common contrast based AF 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: Daniel Semkowicz via libcamera-devel From: Daniel Semkowicz Reply-To: Daniel Semkowicz Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Create a new class with contrast based Auto Focus implementation using hill climbing algorithm. This common implementation is independent of platform specific code. This way, each platform can just implement contrast calculation and run the AF control loop basing on this class. This implementation is based on the code that was common for IPU3 and RPi AF algorithms. Signed-off-by: Daniel Semkowicz Reviewed-by: Jacopo Mondi --- .../libipa/algorithms/af_hill_climbing.cpp | 374 ++++++++++++++++++ src/ipa/libipa/algorithms/af_hill_climbing.h | 91 +++++ src/ipa/libipa/algorithms/meson.build | 2 + 3 files changed, 467 insertions(+) create mode 100644 src/ipa/libipa/algorithms/af_hill_climbing.cpp create mode 100644 src/ipa/libipa/algorithms/af_hill_climbing.h diff --git a/src/ipa/libipa/algorithms/af_hill_climbing.cpp b/src/ipa/libipa/algorithms/af_hill_climbing.cpp new file mode 100644 index 00000000..244b8803 --- /dev/null +++ b/src/ipa/libipa/algorithms/af_hill_climbing.cpp @@ -0,0 +1,374 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Red Hat + * Copyright (C) 2022, Ideas On Board + * Copyright (C) 2023, Theobroma Systems + * + * af_hill_climbing.cpp - AF contrast based hill climbing common algorithm + */ + +#include "af_hill_climbing.h" + +#include "libcamera/internal/yaml_parser.h" + +/** + * \file af_hill_climbing.h + * \brief AF contrast based hill climbing common algorithm + */ + +namespace libcamera { + +namespace ipa::algorithms { + +LOG_DEFINE_CATEGORY(Af) + +/** + * \class AfHillClimbing + * \brief Contrast based hill climbing auto focus control algorithm + * implementation + * + * Control part of the auto focus algorithm. It calculates the lens position + * based on the contrast measure supplied by the platform-specific + * implementation. This way it is independent from the platform. + * + * Platform layer that use this algorithm should call process() function + * for each each frame and set the lens to the calculated position. + * + * Focus search is divided into two phases: + * 1. coarse search, + * 2. fine search. + * + * In the first phase, the lens is moved with bigger steps to quickly find + * a rough position for the best focus. Then, based on the outcome of coarse + * search, the second phase is executed. Lens is moved with smaller steps + * in a limited range within the rough position to find the exact position + * for best focus. + * + * Tuning file parameters: + * - **coarse-search-step:** The value by which the lens position will change + * in one step in the *coarse search* phase. Unit is lens specific. + * - **fine-search-step:** The value by which the lens position will change + * in one step in the *fine search* phase. Unit is lens specific. + * - **fine-search-range:** Search range in the *fine search* phase, expressed + * as a percentage of the coarse search result. Valid values are + * in the [0, 100] interval. Value 5 means 5%. If coarse search stopped + * at value 200, the fine search range will be [190, 210]. + * - **max-variance-change:** ratio of contrast variance change in the + * *continuous mode* needed for triggering the focus change. When the variance + * change exceeds this value, focus search will be triggered. Valid values are + * in the [0.0, 1.0] interval. + * . + * + * \todo Search range in the *fine search* phase should depend on the lens + * movement range rather than coarse search result. + * \todo Implement setRange. + * \todo Implement setSpeed. + * \todo Implement setMeteringMode. + * \todo Implement setWindows. + * \todo Implement the AfPauseDeferred mode. + */ + +/** + * \brief Initialize the AfHillClimbing with lens configuration and tuning data + * \param[in] minFocusPosition Minimum position supported by camera lens + * \param[in] maxFocusPosition Maximum position supported by camera lens + * \param[in] tuningData The tuning data for the algorithm + * + * This method should be called in the libcamera::ipa::Algorithm::init() + * method of the platform layer. + * + * \return 0 if successful, an error code otherwise + */ +int AfHillClimbing::init(int32_t minFocusPosition, int32_t maxFocusPosition, + const YamlObject &tuningData) +{ + minLensPosition_ = minFocusPosition; + maxLensPosition_ = maxFocusPosition; + + coarseSearchStep_ = tuningData["coarse-search-step"].get(30); + fineSearchStep_ = tuningData["fine-search-step"].get(1); + fineRange_ = tuningData["fine-search-range"].get(5); + fineRange_ /= 100; + maxChange_ = tuningData["max-variance-change"].get(0.5); + + LOG(Af, Debug) << "coarseSearchStep_: " << coarseSearchStep_ + << ", fineSearchStep_: " << fineSearchStep_ + << ", fineRange_: " << fineRange_ + << ", maxChange_: " << maxChange_; + + return 0; +} + +/** + * \brief Run the auto focus algorithm loop + * \param[in] currentContrast New value of contrast measured for current frame + * + * This method should be called in the libcamera::ipa::Algorithm::process() + * method of the platform layer for each frame. + * + * Contrast value supplied in the \p currentContrast parameter can be platform + * specific. The only requirement is the contrast value must increase with + * the increasing image focus. Contrast value must be highest when image is in + * focus. + * + * \return New lens position calculated by the AF algorithm + */ +int32_t AfHillClimbing::process(double currentContrast) +{ + currentContrast_ = currentContrast; + + if (shouldSkipFrame()) + return lensPosition_; + + switch (mode_) { + case controls::AfModeManual: + /* Nothing to process. */ + break; + case controls::AfModeAuto: + processAutoMode(); + break; + case controls::AfModeContinuous: + processContinuousMode(); + break; + } + + return lensPosition_; +} + +void AfHillClimbing::processAutoMode() +{ + if (state_ == controls::AfStateScanning) { + afCoarseScan(); + afFineScan(); + } +} + +void AfHillClimbing::processContinuousMode() +{ + /* If we are in a paused state, we won't process the stats. */ + if (pauseState_ == controls::AfPauseStatePaused) + return; + + if (state_ == controls::AfStateScanning) { + afCoarseScan(); + afFineScan(); + return; + } + + /* + * AF scan can be started at any moment in AfModeContinuous, + * except when the state is already AfStateScanning. + */ + if (afIsOutOfFocus()) + afReset(); +} + +/** + * \brief Request AF to skip n frames + * \param[in] n Number of frames to be skipped + * + * For the requested number of frames, the AF calculation will be skipped + * and lens position will not change. The platform layer still needs to + * call process() function for each frame during this time. + * This function can be used by the platform layer if the hardware needs more + * time for some operations. + * + * The number of the requested frames (\p n) will be applied only if \p n has + * higher value than the number of frames already requested to be skipped. + * For example, if *skipFrames(5)* was already called for the current frame, + * then calling *skipFrames(3)* will not override the previous request + * and 5 frames will be skipped. + */ +void AfHillClimbing::skipFrames(uint32_t n) +{ + if (n > framesToSkip_) + framesToSkip_ = n; +} + +void AfHillClimbing::setMode(controls::AfModeEnum mode) +{ + if (mode == mode_) + return; + + LOG(Af, Debug) << "Switched AF mode from " << mode_ << " to " << mode; + mode_ = mode; + + state_ = controls::AfStateIdle; + pauseState_ = controls::AfPauseStateRunning; + + if (mode_ == controls::AfModeContinuous) + afReset(); +} + +void AfHillClimbing::setRange([[maybe_unused]] controls::AfRangeEnum range) +{ + LOG(Af, Error) << "setRange() not implemented!"; +} + +void AfHillClimbing::setSpeed([[maybe_unused]] controls::AfSpeedEnum speed) +{ + LOG(Af, Error) << "setSpeed() not implemented!"; +} + +void AfHillClimbing::setMeteringMode([[maybe_unused]] controls::AfMeteringEnum metering) +{ + LOG(Af, Error) << "setMeteringMode() not implemented!"; +} + +void AfHillClimbing::setWindows([[maybe_unused]] Span windows) +{ + LOG(Af, Error) << "setWindows() not implemented!"; +} + +void AfHillClimbing::setTrigger(controls::AfTriggerEnum trigger) +{ + if (mode_ != controls::AfModeAuto) { + LOG(Af, Warning) + << "setTrigger() not valid in mode " << mode_; + return; + } + + LOG(Af, Debug) << "Trigger called with " << trigger; + + switch (trigger) { + case controls::AfTriggerStart: + afReset(); + break; + case controls::AfTriggerCancel: + state_ = controls::AfStateIdle; + break; + } +} + +void AfHillClimbing::setPause(controls::AfPauseEnum pause) +{ + if (mode_ != controls::AfModeContinuous) { + LOG(Af, Warning) + << "setPause() not valid in mode " << mode_; + return; + } + + switch (pause) { + case controls::AfPauseImmediate: + pauseState_ = controls::AfPauseStatePaused; + break; + case controls::AfPauseDeferred: + LOG(Af, Warning) << "AfPauseDeferred is not supported!"; + break; + case controls::AfPauseResume: + pauseState_ = controls::AfPauseStateRunning; + break; + } +} + +void AfHillClimbing::setLensPosition(float lensPosition) +{ + if (mode_ != controls::AfModeManual) { + LOG(Af, Warning) + << "setLensPosition() not valid in mode " << mode_; + return; + } + + lensPosition_ = static_cast(lensPosition); + + LOG(Af, Debug) << "Requesting lens position " << lensPosition_; +} + +void AfHillClimbing::afCoarseScan() +{ + if (coarseCompleted_) + return; + + if (afScan(coarseSearchStep_)) { + coarseCompleted_ = true; + maxContrast_ = 0; + const auto diff = static_cast( + std::abs(lensPosition_) * fineRange_); + lensPosition_ = std::max(lensPosition_ - diff, minLensPosition_); + maxStep_ = std::min(lensPosition_ + diff, maxLensPosition_); + } +} + +void AfHillClimbing::afFineScan() +{ + if (!coarseCompleted_) + return; + + if (afScan(fineSearchStep_)) { + LOG(Af, Debug) << "AF found the best focus position!"; + state_ = controls::AfStateFocused; + } +} + +bool AfHillClimbing::afScan(uint32_t steps) +{ + if (lensPosition_ + static_cast(steps) > maxStep_) { + /* If the max step is reached, move lens to the position. */ + lensPosition_ = bestPosition_; + return true; + } + + /* + * Find the maximum of the variance by estimating its derivative. + * If the direction changes, it means we have passed a maximum one step + * before. + */ + if ((currentContrast_ - maxContrast_) >= -(maxContrast_ * 0.1)) { + /* + * Positive and zero derivative: + * The variance is still increasing. The focus could be + * increased for the next comparison. Also, the max variance + * and previous focus value are updated. + */ + bestPosition_ = lensPosition_; + lensPosition_ += static_cast(steps); + maxContrast_ = currentContrast_; + } else { + /* + * Negative derivative: + * The variance starts to decrease, which means the maximum + * variance is found. Set focus step to previous good one, + * then return immediately. + */ + lensPosition_ = bestPosition_; + return true; + } + + LOG(Af, Debug) << "Previous step is " << bestPosition_ + << ", Current step is " << lensPosition_; + return false; +} + +void AfHillClimbing::afReset() +{ + LOG(Af, Debug) << "Reset AF parameters"; + lensPosition_ = minLensPosition_; + maxStep_ = maxLensPosition_; + state_ = controls::AfStateScanning; + coarseCompleted_ = false; + maxContrast_ = 0.0; + skipFrames(1); +} + +bool AfHillClimbing::afIsOutOfFocus() const +{ + const double diff_var = std::abs(currentContrast_ - maxContrast_); + const double var_ratio = diff_var / maxContrast_; + LOG(Af, Debug) << "Variance change rate: " << var_ratio + << ", Current lens step: " << lensPosition_; + return var_ratio > maxChange_; +} + +bool AfHillClimbing::shouldSkipFrame() +{ + if (framesToSkip_ > 0) { + framesToSkip_--; + return true; + } + + return false; +} + +} /* namespace ipa::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/libipa/algorithms/af_hill_climbing.h b/src/ipa/libipa/algorithms/af_hill_climbing.h new file mode 100644 index 00000000..2147939b --- /dev/null +++ b/src/ipa/libipa/algorithms/af_hill_climbing.h @@ -0,0 +1,91 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Red Hat + * Copyright (C) 2022, Ideas On Board + * Copyright (C) 2023, Theobroma Systems + * + * af_hill_climbing.h - AF contrast based hill climbing common algorithm + */ + +#pragma once + +#include + +#include "af.h" + +namespace libcamera { + +class YamlObject; + +namespace ipa::algorithms { + +LOG_DECLARE_CATEGORY(Af) + +class AfHillClimbing : public Af +{ +public: + int init(int32_t minFocusPosition, int32_t maxFocusPosition, + const YamlObject &tuningData); + int32_t process(double currentContrast); + void skipFrames(uint32_t n); + + controls::AfStateEnum state() override { return state_; } + controls::AfPauseStateEnum pauseState() override { return pauseState_; } + +private: + void setMode(controls::AfModeEnum mode) override; + void setRange(controls::AfRangeEnum range) override; + void setSpeed(controls::AfSpeedEnum speed) override; + void setMeteringMode(controls::AfMeteringEnum metering) override; + void setWindows(Span windows) override; + void setTrigger(controls::AfTriggerEnum trigger) override; + void setPause(controls::AfPauseEnum pause) override; + void setLensPosition(float lensPosition) override; + + void processAutoMode(); + void processContinuousMode(); + void afCoarseScan(); + void afFineScan(); + bool afScan(uint32_t steps); + void afReset(); + [[nodiscard]] bool afIsOutOfFocus() const; + bool shouldSkipFrame(); + + controls::AfModeEnum mode_ = controls::AfModeManual; + controls::AfStateEnum state_ = controls::AfStateIdle; + controls::AfPauseStateEnum pauseState_ = controls::AfPauseStateRunning; + + /* Current focus lens position. */ + int32_t lensPosition_ = 0; + /* Local optimum focus lens position during scanning. */ + int32_t bestPosition_ = 0; + + /* Current AF statistic contrast. */ + double currentContrast_ = 0; + /* It is used to determine the derivative during scanning */ + double maxContrast_ = 0; + /* The designated maximum range of focus scanning. */ + int32_t maxStep_ = 0; + /* If the coarse scan completes, it is set to true. */ + bool coarseCompleted_ = false; + + uint32_t framesToSkip_ = 0; + + /* Position limits of the focus lens. */ + int32_t minLensPosition_; + int32_t maxLensPosition_; + + /* Minimum position step for searching appropriate focus. */ + uint32_t coarseSearchStep_; + uint32_t fineSearchStep_; + + /* Fine scan range 0 < fineRange_ < 1. */ + double fineRange_; + + /* Max ratio of variance change, 0.0 < maxChange_ < 1.0. */ + double maxChange_; +}; + +} /* namespace ipa::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/libipa/algorithms/meson.build b/src/ipa/libipa/algorithms/meson.build index 3df4798f..20e437fc 100644 --- a/src/ipa/libipa/algorithms/meson.build +++ b/src/ipa/libipa/algorithms/meson.build @@ -2,8 +2,10 @@ libipa_algorithms_headers = files([ 'af.h', + 'af_hill_climbing.h', ]) libipa_algorithms_sources = files([ 'af.cpp', + 'af_hill_climbing.cpp', ]) 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 */ From patchwork Fri Mar 31 08:19:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 18513 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 2C096C32A0 for ; Fri, 31 Mar 2023 08:19:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B942462750; Fri, 31 Mar 2023 10:19:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1680250798; bh=cvm0p2xzbPrL3WWPGL+Zj+DNBa64YRXSKp2GZkL4TUQ=; 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=zGmoralrNUqXJFr7hZ4h0Xasbc2cGUH5Xj/30qu5AZtldwcOU1JtN+nPyOfPfrJF7 hNqh/lCL0rlweKXtRe3ockl4F7ca1wX4zsNdg+TvdOl6Tven7sv901A46VasjEYoAe K1EQwITosVKPzuWSRxj7NHbRyUzCkTNXMUbI+S59jWRM1CHRGIAcV08Jf9bC2rJXOH 2WLhQ1zljdMr1o3gbWQVlCGd2jRumW34VKUNiqExX+zRO8B6LHFk1RTVIqebsMjLxn lAAO84mmHiAX6aF9kgzPOTMZ9ZcuYhdxkHz62mnPNH8i/2f931WhJYfNTdwWYmzx3a h7/sNEGIU1aAw== Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DC9BA62756 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="vmRApNIr"; dkim-atps=neutral Received: by mail-lf1-x129.google.com with SMTP id g17so27898114lfv.4 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=1680250790; x=1682842790; 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=KuEVT9yr3uileFamXcqJ52XI9cacPgm5UgjSltD6O0I=; b=vmRApNIrNh7EjBdIfPm3URfxDuWXBNkpn/4xjM34Maa7FNeJVU9//mzTX8IvaEbssc taSchExq/1Z6DR9QjnV8Aw/klwdAeuJCugdqjx5tFYVB5sCStU5ZOvLIG8+HcKLe4RuT /U29xYtACWRYPPq+Rj2rCWorTfhIwNNHS5reseEcQfuuGlscfVLDVixIqnW9c7qrTx6v NLD+O2Ssnrhkt/eHBNFRxBPq07nf99vTC5htu9lkEDUbC1oppsoOq0+ERueDgdJx9fxq hOWpP10ffKkBsq/AFaqUBgR+BCuS4VrKqwsrJEYTVITS/6Skw1K56mIDSgi78RVi9RZ/ HFGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680250790; x=1682842790; 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=KuEVT9yr3uileFamXcqJ52XI9cacPgm5UgjSltD6O0I=; b=7Qe6cHOP66fp0B2NbsLemf0vl9fmz0liZyKjwrWoBrouNnOarizBqYvXQ6vxVk70Vh 1CJ7OIRWvZhb2eIktUQD+9yp5s6z/y9st+wctP8wxvCkyf2zPj/3m3Q/dlACffALl682 /DRw8NfTzAPxFisD9/5iQj+/uRchQl2nOPFEFN1G+3DmorGZiDQGoVRSxZqAKrdWPK0H uZLmuSYZ/udBxpadbRwsCciB3h1iURA++uubkj8j3SBFslMFSnjTmTPvDLikXpETtWKJ FO2Sq7UA8leIGHokhErYwk2v7+COdTitnqauJTgA7NWSfCCuntbcLYdC/UXXQ7k+XAdH ckFA== X-Gm-Message-State: AAQBX9c5gg47tzzkf/ZUwwMPxyo6perGJy6d2sF1d2aFDVE0/HnLhWda emhGxGGKem37ln0Zc9R/rkhsgvwLEpWtYcyipa5nNQ== X-Google-Smtp-Source: AKy350Zl/hVLFcg7uKKOC7EiEHmz2EfBLTeaJVNhAge0Jqgf54mhaU0urN1dtW/4XNvOR0P4POrLIw== X-Received: by 2002:a19:ad47:0:b0:4ea:c730:aac3 with SMTP id s7-20020a19ad47000000b004eac730aac3mr2335520lfd.3.1680250790194; Fri, 31 Mar 2023 01:19:50 -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:26 +0200 Message-Id: <20230331081930.19289-7-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 06/10] ipa: rkisp1: Add AF algorithm based on AfHillClimbing 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 contrast based auto focus implementation for rkisp1 platform using the common AfHillClimbing algorithm. Rockchip ISP AF block allows calculation of sharpness and luminance in up to three user defined windows. If no windows are set, there are some default settings applied for the first window and exposed through the driver. For each frame, use the sharpness value calculated for this default window and feed the hill climbing algorithm with them. Then set the lens position to value calculated by the algorithm. Signed-off-by: Daniel Semkowicz Reviewed-by: Jacopo Mondi --- src/ipa/rkisp1/algorithms/af.cpp | 121 ++++++++++++++++++++++++++ src/ipa/rkisp1/algorithms/af.h | 43 +++++++++ src/ipa/rkisp1/algorithms/meson.build | 1 + src/ipa/rkisp1/ipa_context.cpp | 13 +++ src/ipa/rkisp1/ipa_context.h | 5 ++ 5 files changed, 183 insertions(+) create mode 100644 src/ipa/rkisp1/algorithms/af.cpp create mode 100644 src/ipa/rkisp1/algorithms/af.h diff --git a/src/ipa/rkisp1/algorithms/af.cpp b/src/ipa/rkisp1/algorithms/af.cpp new file mode 100644 index 00000000..fde924d4 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/af.cpp @@ -0,0 +1,121 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2023, Theobroma Systems + * + * af.cpp - RkISP1 AF hill climbing based control algorithm + */ + +#include "af.h" + +/** + * \file af.h + */ + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +/** + * \class Af + * \brief AF contrast based hill climbing control algorithm for RkISP platforms + * + * Auto focus algorithm for RkISP platforms, based on the common hill climbing + * auto focus implementation (libcamera::ipa::algorithms::AfHillClimbing). + * + * This is the platform layer of the algorithm. + * + * Tuning file parameters: + * - **wait-frames-lens:** Number of frames that should be skipped when lens + * position is changed. Lens movement takes some time and statistics measured + * during the lens movement are unstable. Currently there is no way to know + * when lens movement finished and this is a workaround for this. Wait a fixed + * amount of time on each movement. This parameter should be set according + * to the worst case - the number of frames it takes to move lens between + * limit positions. + * . + * \sa libcamera::ipa::algorithms::AfHillClimbing for additional tuning + * parameters. + * + * \todo Model the lens delay as number of frames required for the lens position + * to stabilize in the CameraLens class. + */ + +LOG_DEFINE_CATEGORY(RkISP1Af) + +/** + * \copydoc libcamera::ipa::Algorithm::init + */ +int Af::init(IPAContext &context, const YamlObject &tuningData) +{ + const auto &lensConfig = context.configuration.lens; + if (!lensConfig) { + LOG(RkISP1Af, Error) << "Lens not found"; + return 1; + } + + waitFramesLens_ = tuningData["wait-frames-lens"].get(1); + + LOG(RkISP1Af, Debug) << "waitFramesLens_: " << waitFramesLens_; + + return af.init(lensConfig->minFocusPosition, + lensConfig->maxFocusPosition, tuningData); +} + +/** + * \copydoc libcamera::ipa::Algorithm::configure + */ +int Af::configure(IPAContext &context, + const IPACameraSensorInfo &configInfo) +{ + /* + * Lens position is unknown at the startup, so initialize + * the current position to something out of range. + */ + context.activeState.af.lensPosition = + context.configuration.lens->maxFocusPosition + 1; + + af.configure(configInfo.outputSize); + return 0; +} + +/** + * \copydoc libcamera::ipa::Algorithm::queueRequest + */ +void Af::queueRequest([[maybe_unused]] IPAContext &context, + [[maybe_unused]] const uint32_t frame, + [[maybe_unused]] IPAFrameContext &frameContext, + const ControlList &controls) +{ + af.queueRequest(controls); +} + +/** + * \copydoc libcamera::ipa::Algorithm::process + */ +void Af::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, + [[maybe_unused]] IPAFrameContext &frameContext, + const rkisp1_stat_buffer *stats, + [[maybe_unused]] ControlList &metadata) +{ + uint32_t sharpness = stats->params.af.window[0].sum; + uint32_t luminance = stats->params.af.window[0].lum; + + LOG(RkISP1Af, Debug) + << "lensPosition: " << context.activeState.af.lensPosition + << ", Sharpness: " << sharpness + << ", Luminance: " << luminance; + + int32_t newLensPosition = af.process(sharpness); + + if (newLensPosition != context.activeState.af.lensPosition) { + context.activeState.af.lensPosition = newLensPosition; + context.activeState.af.applyLensCtrls = true; + af.skipFrames(waitFramesLens_); + } +} + +REGISTER_IPA_ALGORITHM(Af, "Af") + +} /* namespace ipa::rkisp1::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/af.h b/src/ipa/rkisp1/algorithms/af.h new file mode 100644 index 00000000..3ba66d38 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/af.h @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2023, Theobroma Systems + * + * af.h - RkISP1 AF hill climbing based control algorithm + */ + +#pragma once + +#include + +#include "libipa/algorithms/af_hill_climbing.h" + +#include "algorithm.h" + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +class Af : public Algorithm +{ +public: + int init(IPAContext &context, const YamlObject &tuningData) override; + int configure(IPAContext &context, + const IPACameraSensorInfo &configInfo) override; + void queueRequest(IPAContext &context, uint32_t frame, + IPAFrameContext &frameContext, + const ControlList &controls) override; + void process(IPAContext &context, uint32_t frame, + IPAFrameContext &frameContext, + const rkisp1_stat_buffer *stats, + ControlList &metadata) override; + +private: + ipa::algorithms::AfHillClimbing af; + + /* Wait number of frames after changing lens position */ + uint32_t waitFramesLens_ = 0; +}; + +} /* namespace ipa::rkisp1::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build index 93a48329..ab7e44f3 100644 --- a/src/ipa/rkisp1/algorithms/meson.build +++ b/src/ipa/rkisp1/algorithms/meson.build @@ -1,6 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 rkisp1_ipa_algorithms = files([ + 'af.cpp', 'agc.cpp', 'awb.cpp', 'blc.cpp', diff --git a/src/ipa/rkisp1/ipa_context.cpp b/src/ipa/rkisp1/ipa_context.cpp index aea99299..d80a7b1b 100644 --- a/src/ipa/rkisp1/ipa_context.cpp +++ b/src/ipa/rkisp1/ipa_context.cpp @@ -139,6 +139,19 @@ namespace libcamera::ipa::rkisp1 { * member may be read by any algorithm, but shall only be written by its owner. */ +/** + * \var IPAActiveState::af + * \brief State for the Automatic Focus Control algorithm + * + * \var IPAActiveState::af.lensPosition + * \brief Lens position calculated by the AF algorithm + * + * \var IPAActiveState::af.applyLensCtrls + * \brief Whether the lens position should be applied + * + * If true, IPA should send new controls to the PH to set new lens position. + */ + /** * \var IPAActiveState::agc * \brief State for the Automatic Gain Control algorithm diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index 65b3fbfe..3dcc5aa0 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -62,6 +62,11 @@ struct IPASessionConfiguration { }; struct IPAActiveState { + struct { + int32_t lensPosition; + bool applyLensCtrls; + } af; + struct { struct { uint32_t exposure; From patchwork Fri Mar 31 08:19:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 18514 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 C088FC329C for ; Fri, 31 Mar 2023 08:19:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 819906276E; Fri, 31 Mar 2023 10:19:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1680250799; bh=5I/UFgqh1r9xAS4KT5H61rUndV9Jb7t0H6WnthnATRc=; 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=s8s41oJ9vUBskioX5dwXudBJbPmWKKOmgUDFP90pGP0vbvHNRKM2+9WciJqZhzvKd glDCzUoMVv0N7CEK7i8XM3uiZih1as094xWomQMgtDzSHMFirdodrqcuBoVC+O8k3m 6hb3XfasEAvM3DQMM9L/V4NkkDhKOMwcuYZ3nvGQ2f5qwURA8eWePhUklsPCLbRIhq lU3n6jDGAq40CpTQBD5kxfY3/etCYvzdKJNsPVtpRXjEn7zeq09adrg1fv7wTQScxA C2Gj/iyhURww0totKJCLOufYgF0LsoWSd3Gh3D8ZCcjR4VOwpE2ZhD0CJIgmW5APUs sSe3JkzL1Zscw== 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 50CF462756 for ; Fri, 31 Mar 2023 10:19:51 +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="pMGgcgmw"; dkim-atps=neutral Received: by mail-lf1-x130.google.com with SMTP id h11so20918204lfu.8 for ; Fri, 31 Mar 2023 01:19:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; t=1680250790; x=1682842790; 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=i7HiaDitI9UaV/98RgLZ0YhDRIfpVqYfYoOGSzOSw40=; b=pMGgcgmwYMfr5vOy/3rcnpQzUqu7FUfOIzLRe+/aq5m9EbXwLvExIp10wd+mkccwke 8vxTLGri/MXTQGMh20dikuQ8t52eyxm+Gi2+KbXFglKddZibFE1O/vL9XecMdbPHz++L +jqddpLL9ULZNiKMZkb2YaO5iVSZ4Yqu9U3AUqHz30pzqvkV/xs/PFE3RadQTgpl0eY4 a482OHTJi+4hJzzr0LLmqpW7EIWYO7Zh/KnzqapTKoPOD9jR624HUOdFUE0U6ANJrbsH miMN6BUe9Mz5sXR+LTH2Y8NGYuUdKmprUfcQYkPxFCsVctZbIEj1P4YGMImQg7ujSihV TdRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680250790; x=1682842790; 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=i7HiaDitI9UaV/98RgLZ0YhDRIfpVqYfYoOGSzOSw40=; b=fKoY66pFRhDGCXAmRDA04k3+j5YW3ersd4xYGgMC7PnDHxD12LAEFQ2YoJo0V7T6QQ koGuihIdTUqL/roEcMIso8B5BOt9pZ9eyhVLV9tdGZUDnoS6YVO/6h43QwynHFB92/zP sK52j9UO88D5b7VtpXklXoISoYHOnR/B/JGtfLjKIBZLrGVauaZmmDO4wwZX0rF8jxHc sTc9podMvCRNnx1lxSq8fdDgrHavhT6NzEiclwxUt4lNaqvH1Hx0P0RHnRYyrOzCq6BC 48XNwyNhEfOr9wZ00IbZHADh9pBmyt1GzjUNPFA90PYB+wvDEtJJEoaGucbDh2XAOLEb UB8w== X-Gm-Message-State: AAQBX9eukUbwxwOxIAQUaw9zV/aJOb3/BY53uatmCse5aA9JKZSBbuDz ASSqcs3TqayYZOCnnPBMJZLMtot7JH4psQokdB00Ow== X-Google-Smtp-Source: AKy350aE9pmcBoveZkTN/KNl4GjPYLmh2+veYU6HM/qnXb1q3G6mFWiqgAEVhUcPSkfAZDORRIOPJg== X-Received: by 2002:a19:5502:0:b0:4ea:e262:b94e with SMTP id n2-20020a195502000000b004eae262b94emr7132028lfe.21.1680250790693; Fri, 31 Mar 2023 01:19:50 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 01:19:50 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 31 Mar 2023 10:19:27 +0200 Message-Id: <20230331081930.19289-8-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 07/10] ipa: rkisp1: af: 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 platform related code for configuring auto focus window on the rkisp1. Connect to the windowUpdateRequested() signal exposed by the AfHillClimbing and configure the window on each signal emission. This enables support of AfMetering and AfWindows controls on the rkisp1 platform. Currently, only one window is enabled, but ISP allows up to three of them. Signed-off-by: Daniel Semkowicz --- src/ipa/rkisp1/algorithms/af.cpp | 64 +++++++++++++++++++++++++++++++- src/ipa/rkisp1/algorithms/af.h | 13 ++++++- 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/af.cpp b/src/ipa/rkisp1/algorithms/af.cpp index fde924d4..b6f6eee4 100644 --- a/src/ipa/rkisp1/algorithms/af.cpp +++ b/src/ipa/rkisp1/algorithms/af.cpp @@ -32,16 +32,43 @@ namespace ipa::rkisp1::algorithms { * amount of time on each movement. This parameter should be set according * to the worst case - the number of frames it takes to move lens between * limit positions. + * - **isp-threshold:** Threshold used for minimizing the influence of noise. + * This affects the ISP sharpness calculation. + * - **isp-var-shift:** The number of bits for the shift operation at the end + * of the calculation chain. This affects the ISP sharpness calculation. * . * \sa libcamera::ipa::algorithms::AfHillClimbing for additional tuning * parameters. * * \todo Model the lens delay as number of frames required for the lens position * to stabilize in the CameraLens class. + * \todo Check if requested window size is valid. RkISP supports AF window size + * few pixels smaller than sensor output size. + * \todo Implement support for all available AF windows. RkISP supports up to 3 + * AF windows. */ LOG_DEFINE_CATEGORY(RkISP1Af) +namespace { + +constexpr rkisp1_cif_isp_window rectangleToIspWindow(const Rectangle &rectangle) +{ + return rkisp1_cif_isp_window{ + .h_offs = static_cast(rectangle.x), + .v_offs = static_cast(rectangle.y), + .h_size = static_cast(rectangle.width), + .v_size = static_cast(rectangle.height) + }; +} + +} /* namespace */ + +Af::Af() +{ + af.windowUpdateRequested.connect(this, &Af::updateCurrentWindow); +} + /** * \copydoc libcamera::ipa::Algorithm::init */ @@ -54,8 +81,12 @@ int Af::init(IPAContext &context, const YamlObject &tuningData) } waitFramesLens_ = tuningData["wait-frames-lens"].get(1); + ispThreshold_ = tuningData["isp-threshold"].get(128); + ispVarShift_ = tuningData["isp-var-shift"].get(4); - LOG(RkISP1Af, Debug) << "waitFramesLens_: " << waitFramesLens_; + LOG(RkISP1Af, Debug) << "waitFramesLens_: " << waitFramesLens_ + << ", ispThreshold_: " << ispThreshold_ + << ", ispVarShift_: " << ispVarShift_; return af.init(lensConfig->minFocusPosition, lensConfig->maxFocusPosition, tuningData); @@ -89,6 +120,32 @@ void Af::queueRequest([[maybe_unused]] IPAContext &context, af.queueRequest(controls); } +/** + * \copydoc libcamera::ipa::Algorithm::prepare + */ +void Af::prepare([[maybe_unused]] IPAContext &context, + [[maybe_unused]] const uint32_t frame, + [[maybe_unused]] IPAFrameContext &frameContext, + rkisp1_params_cfg *params) +{ + if (updateWindow_) { + params->meas.afc_config.num_afm_win = 1; + params->meas.afc_config.thres = ispThreshold_; + params->meas.afc_config.var_shift = ispVarShift_; + params->meas.afc_config.afm_win[0] = + rectangleToIspWindow(*updateWindow_); + + params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_AFC; + params->module_ens |= RKISP1_CIF_ISP_MODULE_AFC; + params->module_en_update |= RKISP1_CIF_ISP_MODULE_AFC; + + updateWindow_.reset(); + + /* Wait one frame for the ISP to apply changes. */ + af.skipFrames(1); + } +} + /** * \copydoc libcamera::ipa::Algorithm::process */ @@ -114,6 +171,11 @@ void Af::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, } } +void Af::updateCurrentWindow(const Rectangle &window) +{ + updateWindow_ = window; +} + REGISTER_IPA_ALGORITHM(Af, "Af") } /* namespace ipa::rkisp1::algorithms */ diff --git a/src/ipa/rkisp1/algorithms/af.h b/src/ipa/rkisp1/algorithms/af.h index 3ba66d38..6f5adb19 100644 --- a/src/ipa/rkisp1/algorithms/af.h +++ b/src/ipa/rkisp1/algorithms/af.h @@ -20,21 +20,32 @@ namespace ipa::rkisp1::algorithms { class Af : public Algorithm { public: + Af(); + int init(IPAContext &context, const YamlObject &tuningData) override; int configure(IPAContext &context, const IPACameraSensorInfo &configInfo) override; void queueRequest(IPAContext &context, uint32_t frame, IPAFrameContext &frameContext, const ControlList &controls) override; + void prepare(IPAContext &context, uint32_t frame, + IPAFrameContext &frameContext, + rkisp1_params_cfg *params) override; void process(IPAContext &context, uint32_t frame, IPAFrameContext &frameContext, const rkisp1_stat_buffer *stats, ControlList &metadata) override; private: + void updateCurrentWindow(const Rectangle &window); + ipa::algorithms::AfHillClimbing af; - /* Wait number of frames after changing lens position */ + std::optional updateWindow_; + uint32_t ispThreshold_ = 0; + uint32_t ispVarShift_ = 0; + + /* Wait number of frames after changing lens position. */ uint32_t waitFramesLens_ = 0; }; From patchwork Fri Mar 31 08:19:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 18516 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 1A67FC32A2 for ; Fri, 31 Mar 2023 08:20:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B650B627B4; Fri, 31 Mar 2023 10:20:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1680250800; bh=ddO7lhcTqPn3VTiQbDIp4Kz85JQMSb4v8yRyNascC0w=; 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=RZ/h4Ej1AUO7BKMfcdK7fNEGdOTK7gluACtM/HCI2QtUa/lsCdn1BD7dkNljs0qqm JqeN2jtoIAcb9HSn+AXi+du8lTRAieAOXQWv2NN5AQpE0LzOrNelrUhgck2IOP+TcW 4mSOEoZGpf2w7S5IGfBf+XAcB5o6TTyAaNqM6aoPWI3Y2ixWpINbce5Y5osd2Uo8Y8 h2WwLM+ehAdwfdg8aBkSLP+eAYY51Psst3Dpz06N0VW/Ng0VZCyyHknS3TT2VE93JE 1HjlxXGPjqYP1pdMzvZW7NvRPGP5bgj5dhf1cD5qSipi2dp+CFDvIrihBmefxv2l15 GFt+EDBEMCBqw== Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D7C4962767 for ; Fri, 31 Mar 2023 10:19:51 +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="6Bn+nXjL"; dkim-atps=neutral Received: by mail-lf1-x12c.google.com with SMTP id bi9so27854895lfb.12 for ; Fri, 31 Mar 2023 01:19:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; t=1680250791; x=1682842791; 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=+vsWWrTWtLRSMEpTx2i8HEygt1ysKs5UmI4Wea6ETIw=; b=6Bn+nXjLWAjkd3aJSiMG8AO7xb57/xyzy65JVYi+mGHrmqZIGTkcdhsqwG0V7fhLyb E8xLVX2vmM1aM9Z50UVnnLdU4osgt4hR0xScKO7gt43EuDF6PnVIEfqZurWWL7wJ06ok HWU2FQu6QnTy86h87WNPq+3OfQuUC4ayKfuwI1kcWtVs9RMSLQi0eA+vlM5rqFt48iBZ Se4T0SBiwftzkOKCqd7nrN5gKWlNOB5kd43t5lDevEDSRjfc0/fcFM/JTtnFguMmt24A sLiOB6oRQtkOB7rgtLVYW4AJpcuk203l1bbTw9SaTbjagQd6waCw3ld61b9LQwpLTziS s7bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680250791; x=1682842791; 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=+vsWWrTWtLRSMEpTx2i8HEygt1ysKs5UmI4Wea6ETIw=; b=MdYI13BcNjCVRZeoVKhrfBmRJDGZ5zrmiL22UnPWtzdasUdv+BGUlt0D70S+lQrrxf mve8vPsEeVqWrx4uw/hSWmXfP2oNYaqZhRWEIjit/w7FQkqVIUvnarX5kBGbCX7p0LTi LbSl9FpH2/l577NygFWjVs/3qEY46fJGMiLfQoty9UDftwD7Egvy7QUkVSVMikzdEf0r hduD/MeuCcOkHBCuYQJiC6GroklmJWyqIgjpsYprNHGoowhk4oZE2US1HVgO34zERKLh 7dlUJbUgkpIxvxwBYgznjjzVWYDcVG2xOLDi+swyFlHXUTH0Wj05xJmKyo6/2elZLkzX 7UVg== X-Gm-Message-State: AAQBX9esQo0DHxMhI0FfiP1b6T+tbsEY2u56DqD60zvSf/lTD8VM9O5X G/8lMSP7OnNmY1fQRIX1+JUSpYdaGy+4iGLP5FHT/A== X-Google-Smtp-Source: AKy350b/a2EP7/0m0rW+nFgsiFQJSCb8H2hu/nQeai9m1NRY66+bpER/mczdOfWroh/fIbtXe5KxIg== X-Received: by 2002:ac2:5551:0:b0:4dd:cef0:c27c with SMTP id l17-20020ac25551000000b004ddcef0c27cmr7147849lfk.33.1680250791173; Fri, 31 Mar 2023 01:19:51 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 01:19:50 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 31 Mar 2023 10:19:28 +0200 Message-Id: <20230331081930.19289-9-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 08/10] ipa: rkisp1: Add AF controls to the RkISP1 IPA 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 controls supported by the AF algorithm to the list of controls supported by the RkISP1 IPA. This exposes the AF controls to the user and allows controlling the AF algorithm using the top level API. Signed-off-by: Daniel Semkowicz Reviewed-by: Jacopo Mondi --- src/ipa/rkisp1/rkisp1.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 292768cf..9c8b4a82 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -456,6 +456,28 @@ void IPARkISP1::updateControls(const IPACameraSensorInfo &sensorInfo, frameDurations[1], frameDurations[2]); + if (lensControls_) { + const ControlInfo &focusAbsolute = + lensControls_->at(V4L2_CID_FOCUS_ABSOLUTE); + + using namespace controls; + + ctrlMap[&AfMetering] = ControlInfo(AfMeteringValues); + ctrlMap[&AfMode] = ControlInfo(AfModeValues); + ctrlMap[&AfPause] = ControlInfo( + Span{ + { static_cast(AfPauseImmediate), + static_cast(AfPauseResume) } }); + ctrlMap[&AfTrigger] = ControlInfo(AfTriggerValues); + ctrlMap[&AfWindows] = ControlInfo( + Rectangle(), Rectangle(sensorInfo.outputSize), + Rectangle()); + ctrlMap[&LensPosition] = ControlInfo( + static_cast(focusAbsolute.min().get()), + static_cast(focusAbsolute.max().get()), + static_cast(focusAbsolute.def().get())); + } + *ipaControls = ControlInfoMap(std::move(ctrlMap), controls::controls); } From patchwork Fri Mar 31 08:19:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 18515 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 7E925C32A1 for ; Fri, 31 Mar 2023 08:20:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 205FC627AF; Fri, 31 Mar 2023 10:20:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1680250800; bh=bLqSmcHJss4tPX5K00bkSod/puYdxUrHTNdIMYC+T4g=; 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=sXhfkpM497wNlQGQbZY4bxxdTaVPfBA4Ox7wwTi6jMsJ7Dv1U8Mgk7yPQzxsooz73 wWQW+XBAM72DUNChEccaRiVDf8H++ljW8p2xOM8BnSWR9S8co7yTIzA/7Y4obo0YVJ LMpLMIWwJfVznW2Asmu6pWOZWd25RTI0VmQlK76SEneebK8Sq8BYJ6hFs2ALahAj6Z mODIbcbwRWAKpSua9y8jo+c30R+1s5K+IamKA+ITbBrQo8NbeyaUg6fUvIAnGvbuO9 8kt0rzwDLdJAJDJ1g4+HYbhPLpAS9gA29NiuERj4Fmu0YCL28JGK2DoYaarNare3i0 zdQmO9PJ+eAMA== Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DECD662768 for ; Fri, 31 Mar 2023 10:19:51 +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="znrHpllc"; dkim-atps=neutral Received: by mail-lf1-x12f.google.com with SMTP id g19so14771264lfr.9 for ; Fri, 31 Mar 2023 01:19:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; t=1680250791; x=1682842791; 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=bF+pQHcoCZEIwhlblfRqtcMkef8BVDr4E6eAf4PH+RY=; b=znrHpllc/gKHFg1K8WJR7uyIq4CeBOOdmjIpwWkQ/XVYF8FyhwuClI/KjMXOmUZMQF 2tBv6QeCRKo0xexKroLjxj5lbL5kb09deqFIBGRoNdevQD8egrCiUikeW8CyWZi1p4iW +hJD4qz2vB9URkr3qnlJePS9nYQuQb/RRnUsIIGf+H4yzu/vsE5ZM3188gO4fAB7N1dO OrGCrgF/sgSGQ5hNnRDV1oTbvuzdCZQ1Ew16yZ67kxznRfBG2V7O78GA39taV3gGp+TG RfwtDya2G3YVscWz/0fMdAGLeqERiwy32yvkxJHOtC4ZALFI7M1NOCft08kADB8pIWzF 2xIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680250791; x=1682842791; 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=bF+pQHcoCZEIwhlblfRqtcMkef8BVDr4E6eAf4PH+RY=; b=KIrcJ1s9hBLTgPA1mV105PM7Ps/9V9fexhad6rX9tGusaS+kZeUX9IAd1zw1CEPytp Ybp/sXFNciSMZwzBjx1c1kiGTDPMI1GhIgn3s6T9c+n/N69uBchgFWH22xLWayYkd8HQ enObf0Bhwa/teo7ZNPIm9pBpzxvhlimHreTHqV6UsRD5l13kWs3u+1FVwRuGFDYphjH+ ISjZ/hV1m3mG6bxxU4IOYnmX+mZQoaxVKyqDflKc4Z1cz8iDFcBkkv5h+n2ay28pZAV/ Yfweg1nmrEs0bEnQddB4CA2seXABcF11i+mrM4N5+sHyh2N4FE38xgYfuEuQ2H8cOEgO ce7A== X-Gm-Message-State: AAQBX9ebMmbFvIX46jkYym1t4pgjHs4OcZEwcRSxp9zx8/UqM+giF+M2 pZzWyotoOfUBCBekx/9IE2uQAEx0f29UOA8v5XwQfw== X-Google-Smtp-Source: AKy350Y+tZRguc0e8D/rHEZCEx/JwaHZshapC/da2YrZ7emqoyDIAmS+v9QF0H5KIvPzaXVUFyOF6A== X-Received: by 2002:a19:f519:0:b0:4eb:304f:66f3 with SMTP id j25-20020a19f519000000b004eb304f66f3mr232857lfb.22.1680250791671; Fri, 31 Mar 2023 01:19:51 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 01:19:51 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 31 Mar 2023 10:19:29 +0200 Message-Id: <20230331081930.19289-10-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 09/10] rkisp1: Control camera lens position from IPA 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" Allow control of lens position from the IPA, by setting corresponding af fields in the IPAFrameContext structure. Controls are then passed to the pipeline handler, which sets the lens position in CameraLens. Signed-off-by: Daniel Semkowicz Reviewed-by: Jacopo Mondi --- include/libcamera/ipa/rkisp1.mojom | 1 + src/ipa/rkisp1/rkisp1.cpp | 8 ++++++++ src/libcamera/pipeline/rkisp1/rkisp1.cpp | 13 +++++++++++++ 3 files changed, 22 insertions(+) diff --git a/include/libcamera/ipa/rkisp1.mojom b/include/libcamera/ipa/rkisp1.mojom index d4ff1230..dc6a8ffc 100644 --- a/include/libcamera/ipa/rkisp1.mojom +++ b/include/libcamera/ipa/rkisp1.mojom @@ -39,5 +39,6 @@ interface IPARkISP1Interface { interface IPARkISP1EventInterface { paramsBufferReady(uint32 frame); setSensorControls(uint32 frame, libcamera.ControlList sensorControls); + setLensControls(libcamera.ControlList lensControls); metadataReady(uint32 frame, libcamera.ControlList metadata); }; diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 9c8b4a82..37b1e0a8 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -497,6 +497,14 @@ void IPARkISP1::setControls(unsigned int frame) ctrls.set(V4L2_CID_ANALOGUE_GAIN, static_cast(gain)); setSensorControls.emit(frame, ctrls); + + if (lensControls_ && context_.activeState.af.applyLensCtrls) { + context_.activeState.af.applyLensCtrls = false; + ControlList lensCtrls(*lensControls_); + lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, + context_.activeState.af.lensPosition); + setLensControls.emit(lensCtrls); + } } } /* namespace ipa::rkisp1 */ diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index f966254a..f42a8368 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -114,6 +114,7 @@ private: void paramFilled(unsigned int frame); void setSensorControls(unsigned int frame, const ControlList &sensorControls); + void setLensControls(const ControlList &lensControls); void metadataReady(unsigned int frame, const ControlList &metadata); }; @@ -340,6 +341,8 @@ int RkISP1CameraData::loadIPA(unsigned int hwRevision) return -ENOENT; ipa_->setSensorControls.connect(this, &RkISP1CameraData::setSensorControls); + if (sensor_->focusLens()) + ipa_->setLensControls.connect(this, &RkISP1CameraData::setLensControls); ipa_->paramsBufferReady.connect(this, &RkISP1CameraData::paramFilled); ipa_->metadataReady.connect(this, &RkISP1CameraData::metadataReady); @@ -409,6 +412,16 @@ void RkISP1CameraData::setSensorControls([[maybe_unused]] unsigned int frame, delayedCtrls_->push(sensorControls); } +void RkISP1CameraData::setLensControls(const ControlList &lensControls) +{ + CameraLens *focusLens = sensor_->focusLens(); + + for (auto const &[id, value] : lensControls) { + if (id == V4L2_CID_FOCUS_ABSOLUTE) + focusLens->setFocusPosition(value.get()); + } +} + void RkISP1CameraData::metadataReady(unsigned int frame, const ControlList &metadata) { RkISP1FrameInfo *info = frameInfo_.find(frame); From patchwork Fri Mar 31 08:19:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 18517 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 1C008C32A3 for ; Fri, 31 Mar 2023 08:20:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 713AE627B7; Fri, 31 Mar 2023 10:20:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1680250801; bh=x0R9Qqic00qgo35ORUHPibHmiHSvzEH9VdtJbsiB1p4=; 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=Dv2MVC47pNYqgu6uTjfS3GgCG834P2LNBmf4JgaCKFxR0nsJ314znXf27OMbDFmt9 cPRFKUJWbXLwDA5Zbr1eUo3cKvEtTxlnJYzETc/FMVD2Dry8CA64RGcyZNF5lEZu29 yBJaRTxD4+taQOuCqItPC4iQIEJZlCvLolwtpKgTPs1RCDX2uiuOtuqZQZdcZTH6Oh sF6oZ1gba4jdX1RtaoY1Km/ZNIs6WkTlmoKbrotfcWERf8B2POKGq5xEy2sZchhQzC qv4Gio8+mdB8Ev5gSZy0V2QN1YednaH9w0YdBmzVbCmrcJFYPXU7bSWSpKIk5bCABi vuAQVqDsvIjdg== Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E2DA762750 for ; Fri, 31 Mar 2023 10:19:52 +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="HIPOzk4J"; dkim-atps=neutral Received: by mail-lf1-x129.google.com with SMTP id k37so27939751lfv.0 for ; Fri, 31 Mar 2023 01:19:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; t=1680250792; x=1682842792; 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=mLZm2INCozHNI1ySEb1DUhlrc5wmxjKjFeWdt7Y767s=; b=HIPOzk4J9jgaLPj8sKU6nEuU/l/JBOBUR+D0OHXoNsCYuHpBKgX4M4/Ln54DTezRoz Wucav2oOBVJuPCk7KEJnDzpkBU8bESkScc0q1wRUWtTUN829wt/f0oQN6DQd1kdfyWau UCUf8RZdZV4tpf0VTlq04zZJ3GYc9ysw6rxqWXw6YMVqBMlIojEteZSq6b1Hyb4D0JsR OpI86REYlDztYu9iQXo2GZnI66uowAnd8RlyfPh+Y65aEX9hz8rXl1GKPDiYgF98eALX Gg0b+IpgYJHqn3TUYoiMkSuKjUPkdUxFEkQ9Mqr5e7oUk9V7ymL+w1gvrLNIVdb5Ggb9 R/QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680250792; x=1682842792; 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=mLZm2INCozHNI1ySEb1DUhlrc5wmxjKjFeWdt7Y767s=; b=4+LEi1ijcY+KrmhoWkGC9RG5qDva7w7RX/oVC+A/rtCJDMpEoIB1sPg3StHnGsoKZi Z74ZhUIx+zItyPwZC/ZxKiNV/3luBf45Fs67dsUQyiTHdjjeDm42q36AaT0qOqLP2NhH CBYErTvwZD+ak2+o52H1RTiJxkLAd6ONx/WzgEB36R8QHDkAqtjGXwiNd1UA0Y44t0zF 9GNhfMi54Jd8wGIqx5vtthpzdEGA0OEVU3CGrXHrad+dZV1cSBSEhN4kxHH8fl0U2Nap UAqywrdae/KGrdFox1XMSoB1HeZrXcMumfupDb8aFd+g+8EZdsuEvoaiE9IrM4ZLRcHR EEmA== X-Gm-Message-State: AAQBX9fNqa+xmhYUQPCTF21lZ6Ip7jKeXZfewYBg7x2zWy1InPFTXIGj 2g2rkMjapa2GPJ53aFYuwiaVJEOokWZWhfkbmUEyxQ== X-Google-Smtp-Source: AKy350a4vEpmdXQ6PA+E/udb6YlnoSkaqyZYA3BT+3ZfV18rsoe17uvg7JVVywJMBwEhNl0nqkV5gA== X-Received: by 2002:a19:f51a:0:b0:4bb:9415:38a2 with SMTP id j26-20020a19f51a000000b004bb941538a2mr7291186lfb.51.1680250792241; Fri, 31 Mar 2023 01:19:52 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 01:19:51 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 31 Mar 2023 10:19:30 +0200 Message-Id: <20230331081930.19289-11-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 10/10] ipa: rkisp1: Add OV5675 tuning file 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 the OV5675 tuning file with default values and enabled AF algorithm. Signed-off-by: Daniel Semkowicz Reviewed-by: Jacopo Mondi --- src/ipa/rkisp1/data/meson.build | 1 + src/ipa/rkisp1/data/ov5675.yaml | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/ipa/rkisp1/data/ov5675.yaml diff --git a/src/ipa/rkisp1/data/meson.build b/src/ipa/rkisp1/data/meson.build index f5e9fa75..1fdce2c9 100644 --- a/src/ipa/rkisp1/data/meson.build +++ b/src/ipa/rkisp1/data/meson.build @@ -4,6 +4,7 @@ conf_files = files([ 'imx219.yaml', 'ov4689.yaml', 'ov5640.yaml', + 'ov5675.yaml', 'uncalibrated.yaml', ]) diff --git a/src/ipa/rkisp1/data/ov5675.yaml b/src/ipa/rkisp1/data/ov5675.yaml new file mode 100644 index 00000000..4f3da897 --- /dev/null +++ b/src/ipa/rkisp1/data/ov5675.yaml @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: CC0-1.0 +%YAML 1.1 +--- +version: 1 +algorithms: + - Af: + coarse-search-step: 30 + fine-search-step: 1 + fine-search-range: 5 + max-variance-change: 0.5 + wait-frames-lens: 2 # tuned for 30fps stream + isp-threshold: 128 + isp-var-shift: 4 + - Agc: + - Awb: + - BlackLevelCorrection: + - ColorProcessing: +...