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],