From patchwork Fri Mar 24 14:29:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 18446 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 11E83C0F2A for ; Fri, 24 Mar 2023 14:29:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E882B62710; Fri, 24 Mar 2023 15:29:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1679668171; bh=VvBr+2AA6dPAeiFBn7TRelJf2b2z8dbF/ClemE/ynww=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ajYGHm/W4MiMHrLc6EQtOtFf1qqpQBsQxeln+KL9sfVzsn6Y+XdqtLgnrtGLUb3w3 uOxt/as7YPULvszN2ynYesutZspjN/YVyy2R5Fi7WA1/Vis+9koqmGpWnGO2tNKF28 AX0GmcLvpcYiIsO3rqSo4DOEvP4T2RPoXrkcmIbzvpb23oIYU8QeD0hnyA0+NmHgHw bjdVz1+/rzqBGEeRWbMP06i6+hr9uhfRZmkypJaJ1yA1jBk67JvrYr5kqXKp0Y1ulj qQdHz72Ai8VHcr5d/hL57kudMvYUp5OUPWzc+k9HAyxH7jINDtBELdpePl/OeTjA3m IW5cnhlAjRWvQ== Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8F0E061ECF for ; Fri, 24 Mar 2023 15:29:26 +0100 (CET) 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="0wLdG1u1"; dkim-atps=neutral Received: by mail-lj1-x235.google.com with SMTP id a11so1912949lji.6 for ; Fri, 24 Mar 2023 07:29:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; t=1679668166; 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=p3ktg7MZDXz8/FGb1gjNfXnLADZbV4jL8TI3FRHHtyk=; b=0wLdG1u1gTAQYhkQyOwaltTyFMF9MFpAJsDWLYIwHaxYGKTwaXLiLSOEsdq7MhEroD 4UJTUt6ybmqWJJsDkdXRzyKJ7+Kza2dYkgMkw7nnOa/54MMqkSWbk3r9ewrfle3s22er dIjAEqkauajShbb8cDQVnaDIbSLTwDHCBZ67O8ETzfL98tJgwmsopScwLWErcPRtIkNQ 39GGiparp7bMYA5bJVX+JGY7JJ9KGCxS3DjKUsTLTFaSjuFXnMUnHmQhgYQmt4ygzE5M s13at2d7twU1NBmHaBHEJf10F5dvUEVvp9+tKKRaije9WR4gIWTsy89vGChKh7yhRdDN F49Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679668166; 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=p3ktg7MZDXz8/FGb1gjNfXnLADZbV4jL8TI3FRHHtyk=; b=E67cTqy9zeVAthTjcoyH9pmXtNlsoPPpQTxzwzoDs2XJeEqm63iPDdabEiP4KAJefw Du3/2cqoXNlzB5O2LdVyvj2HfTofepHYEMfcvMBbuF3NpIOe3qepo1jJThEUoahn6pWa kHwoGXsSvqHBAH6JGvAIrpdLaAGzj2L/2wXNVN2x9HcQqa4FAThDNSNeR4fK0yQZq98W p2JKjwCtriRP0W8kdNTPPblkH7o5STj0JkAuL8ECbRUQPtGng8kwbla6E8QKS+Xxxiuh f2pzNXI9qx8ce3CsDmhz3bIOCHgS1EcfsrDXj6P2FKJq0R5iCALqi7c7FUYKtO+hy//S cPiA== X-Gm-Message-State: AAQBX9cDQ+vpVMktc+yw0MdGk0C4dOyrEdz8/SYd0encFRSyoSMBCpip Y0879a7wRl17BZ09TC8TRE/Lc1xn2vUvsl5TadY= X-Google-Smtp-Source: AKy350YHxv2Uc5CxDB65tD42VSneyoi48539GgdeEoo1yKbdJlZqQrgnCTU1D7xDGNsmWvvsovjF2Q== X-Received: by 2002:a2e:988c:0:b0:298:9fb6:77a with SMTP id b12-20020a2e988c000000b002989fb6077amr940020ljj.32.1679668165802; Fri, 24 Mar 2023 07:29:25 -0700 (PDT) Received: from localhost.localdomain ([91.90.166.178]) by smtp.gmail.com with ESMTPSA id j21-20020a2e8515000000b002a10b2ea089sm981714lji.16.2023.03.24.07.29.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 07:29:25 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 24 Mar 2023 15:29:01 +0100 Message-Id: <20230324142908.64224-4-dse@thaumatec.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230324142908.64224-1-dse@thaumatec.com> References: <20230324142908.64224-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 Cc: jacopo.mondi@ideasonboard.com 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 --- src/ipa/libipa/algorithms/af.cpp | 159 ++++++++++++++++++++++++++ src/ipa/libipa/algorithms/af.h | 45 ++++++++ src/ipa/libipa/algorithms/meson.build | 9 ++ src/ipa/libipa/meson.build | 6 + 4 files changed, 219 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..4fd16ac2 --- /dev/null +++ b/src/ipa/libipa/algorithms/af.h @@ -0,0 +1,45 @@ +/* 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],