From patchwork Thu Jun 30 14:35:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16483 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 49A43BE173 for ; Thu, 30 Jun 2022 14:35:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F3D1B65633; Thu, 30 Jun 2022 16:35:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656599755; bh=6vuxPUsFppSJnT7Dl58T841m9nlsFUiJheooK2pk4Jo=; 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=WCk6GGjBRb9A5e2J1m5PP6WnfmJZBolYvwJLVBkIcB4MJ+B2CXDiotcCpttVyrgwG NSdHa7Oybu+dgfQR2y2CT6ZiJ/p9YkaKbUzrnM6U3jow8FsMQgLAA/gQQlHoYRNdLV 7yrqfwYwWhj8squzk5FLgkMeQAmix+bl5V5GoJwqNl6yUMckwV6liYHUZrxEpOM8Z8 0YxE7d6Yye41nOB+Yepew2DaMenUd5Ts+ub3gSVeLsyXZfO3Ix2VROEGMDfhfSbQ0V b11YJGxpmbOtDJ4OaQfy3+pqImsRzZAWeQGMx6uip0GoNJMY0KiRh2QUCa71cEFSxy UBSXJdgSxSehA== Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EC16565633 for ; Thu, 30 Jun 2022 16:35: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="xTVj8s70"; dkim-atps=neutral Received: by mail-wr1-x42f.google.com with SMTP id v14so27588240wra.5 for ; Thu, 30 Jun 2022 07:35:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=s9hXRdoqeXHWPH716obtEfzwRxtV5yA4ljxL4a2zDs0=; b=xTVj8s70Sc8u4qsU0D5et4tq5eCLPNLFEx+M+k9lasnM3G11vCTeWPK4XXlBqtxBLC aN8O//fN8CXmgyRbe9QoOpKiwPNxDvnnTan/fBG/h1uSJdc52YwVnrp7ycfeFZkplf8S pycX7OVEKcBuM5fzT4UMsSnYvDoXbGU1W/p8Ns74PGCoOkDcHPq6K1tBVtYbJi1RNjIH ZPEBbzOEnTZbmH19g/mxdKqghZBk0L2hozFz90LpuQNUkyM/wtbbgl71zbBMnG1TnR3D 5Dp3OZzoEvdXeD6I33egiy+Sj7AJfT46uscOB3r23Jf0+bt4fvyYxgWeM0Yg1Vn7X/AK MDXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=s9hXRdoqeXHWPH716obtEfzwRxtV5yA4ljxL4a2zDs0=; b=F4b6MKZTQ96XMvD0y5qqoSrB6kjEICCFgTVA+c+8iFw8xWo4U/AgvA9z46LWdnmRCj +bM19eXd83T11DRdOT+OchXD9iNRUl1x1N6KX8EuNcSycsVVxC2WsDBlC2JtHFUPhWVJ NFsHd3os/RWBvvAE3Akm2ekBwW3B7kEK/yc/AfCxCvoDaELcBjreM6vRXzO8Q9/OVMTo BA1OMDZDXuMas2Ys1B2Me+yhk27Lxpep0ujsAKN7o1L1epJ6U2gSsbEVPTQI/3rSfADn JWDeqs0UpF/gDbyetsxQMVi/nwZZkV06hpSM3kR64QKlTtDkuPrSyO0DFyYV46zrG4U6 Lltg== X-Gm-Message-State: AJIora/6hlHFpQ3N/F+W42eRx6LDD1HHyrbBuLfGd34AabCzKaXHrWcN Q/AFlxOG6+0Zfo2r3fQlb6lmw2LWNb+OgQ== X-Google-Smtp-Source: AGRyM1tZIkgZYXu3aDCo43nuaE7SfxWcl+f/yPE+i95qaCKlTXokDkEpdGb4KsGV8kTQvMotbXEUKA== X-Received: by 2002:adf:f34c:0:b0:21b:9938:b7d0 with SMTP id e12-20020adff34c000000b0021b9938b7d0mr8636965wrp.215.1656599751654; Thu, 30 Jun 2022 07:35:51 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id r5-20020a05600c320500b0039db500714fsm6405945wmp.6.2022.06.30.07.35.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 07:35:50 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 30 Jun 2022 16:35:36 +0200 Message-Id: <20220630143543.39599-2-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220630143543.39599-1-dse@thaumatec.com> References: <20220630143543.39599-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/8] 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 basic functions that should be supported by Auto Focus algorithms. Signed-off-by: Daniel Semkowicz --- src/ipa/libipa/algorithms/af_algorithm.cpp | 77 ++++++++++++++++++++++ src/ipa/libipa/algorithms/af_algorithm.h | 39 +++++++++++ src/ipa/libipa/algorithms/meson.build | 9 +++ src/ipa/libipa/meson.build | 6 ++ 4 files changed, 131 insertions(+) create mode 100644 src/ipa/libipa/algorithms/af_algorithm.cpp create mode 100644 src/ipa/libipa/algorithms/af_algorithm.h create mode 100644 src/ipa/libipa/algorithms/meson.build diff --git a/src/ipa/libipa/algorithms/af_algorithm.cpp b/src/ipa/libipa/algorithms/af_algorithm.cpp new file mode 100644 index 00000000..1c4d981a --- /dev/null +++ b/src/ipa/libipa/algorithms/af_algorithm.cpp @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2022, Theobroma Systems + * + * af_algorithm.cpp - autofocus algorithm interface + */ + +#include "af_algorithm.h" + +/** + * \file af_algorithm.h + * \brief AF algorithm common interface + */ + +namespace libcamera::ipa::common::algorithms { + +/** + * \class AfAlgorithm + * \brief Common interface for auto-focus algorithms + * \tparam Module The IPA module type for this class of algorithms + * + * The AfAlgorithm class defines a standard interface for IPA auto focus + * algorithms. + */ + +/** + * \fn AfAlgorithm::setMode() + * \brief Set auto focus mode + * \param[in] mode AF mode + */ + +/** + * \fn AfAlgorithm::setRange() + * \brief set the range of focus distances that is scanned + * \param[in] range AF range + */ + +/** + * \fn AfAlgorithm::setSpeed() + * \brief Set how fast algorithm should move the lens + * \param[in] speed Lens move speed + */ + +/** + * \fn AfAlgorithm::setMetering() + * \brief Set AF metering mode + * \param[in] metering AF metering mode + */ + +/** + * \fn AfAlgorithm::setWindows() + * \brief Set AF windows + * \param[in] windows AF windows + * + * Sets the focus windows used by the AF algorithm when AfMetering is set + * to AfMeteringWindows. + */ + +/** + * \fn AfAlgorithm::setTrigger() + * \brief Starts or cancels the autofocus scan + * \param[in] trigger Trigger mode + */ + +/** + * \fn AfAlgorithm::setPause() + * \brief Pause the autofocus while in AfModeContinuous mode. + * \param[in] pause Pause mode + */ + +/** + * \fn AfAlgorithm::setLensPosition() + * \brief Set the lens position while in AfModeManual + * \param[in] lensPosition Lens position + */ + +} /* namespace libcamera::ipa::common::algorithms */ diff --git a/src/ipa/libipa/algorithms/af_algorithm.h b/src/ipa/libipa/algorithms/af_algorithm.h new file mode 100644 index 00000000..89db591b --- /dev/null +++ b/src/ipa/libipa/algorithms/af_algorithm.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2022, Theobroma Systems + * + * af_algorithm.h - autofocus algorithm interface + */ +#pragma once + +#include + +#include "../algorithm.h" + +namespace libcamera::ipa::common::algorithms { + +template +class AfAlgorithm : public Algorithm +{ +public: + AfAlgorithm() = default; + virtual ~AfAlgorithm() {} + + virtual void setMode(controls::AfModeEnum mode) = 0; + + virtual void setRange(controls::AfRangeEnum range) = 0; + + virtual void setSpeed(controls::AfSpeedEnum speed) = 0; + + virtual void setMetering(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; +}; + +} /* namespace libcamera::ipa::common::algorithms */ diff --git a/src/ipa/libipa/algorithms/meson.build b/src/ipa/libipa/algorithms/meson.build new file mode 100644 index 00000000..ab8da13a --- /dev/null +++ b/src/ipa/libipa/algorithms/meson.build @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: CC0-1.0 + +common_ipa_algorithms_headers = files([ + 'af_algorithm.h', +]) + +common_ipa_algorithms_sources = files([ + 'af_algorithm.cpp', +]) diff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build index fb894bc6..1fc3fd56 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', @@ -7,6 +9,8 @@ libipa_headers = files([ 'module.h', ]) +libipa_headers += common_ipa_algorithms_headers + libipa_sources = files([ 'algorithm.cpp', 'camera_sensor_helper.cpp', @@ -14,6 +18,8 @@ libipa_sources = files([ 'module.cpp', ]) +libipa_sources += common_ipa_algorithms_sources + libipa_includes = include_directories('..') libipa = static_library('ipa', [libipa_sources, libipa_headers], From patchwork Thu Jun 30 14:35:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16484 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 0D57FBE173 for ; Thu, 30 Jun 2022 14:35:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9C47F65655; Thu, 30 Jun 2022 16:35:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656599756; bh=xJQKTbPa0U71qrWmVARk9zMH1wWKhZ5GxYAjkWdD+fM=; 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=ja1u1CSxw/tFcORG5fF1YpRJgaADIuA7RowVhtFm4AlgRqDWhlTpsxCVNt7F7y8BV d+rps9Ip7nlrm615yzt6jDM3zIKJKlnGDQR0NOg1IUnYwgbGRC5T7z3NjkOE7VecJr 6rHZqrLc1ZY2NU9YqB0+OeS9Tb6V+M0+u9EJWj1AAQt7WTY6nnyzjRkwb7AAez1LlB t1O7X9qd8sk51Ss0jw5yRXRuRd5bd050q2ymCXbCWXMaVkfcy77GEXogJ3BRYwXS4Y CbH/YogC3VamChD3LPIp27LOdI9aTxNZ9vZ9ONVS99UUqSScI+DcmU3ghTFMUirYI3 5Il04mLpis1cw== Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7C5006559A for ; Thu, 30 Jun 2022 16:35:54 +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="r7/K7epq"; dkim-atps=neutral Received: by mail-wr1-x434.google.com with SMTP id k7so3132398wrc.12 for ; Thu, 30 Jun 2022 07:35:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3vGUXRY/JNfBGnbAekBFLY5gOvcKq1MkRAcEHZoXKQA=; b=r7/K7epqpu2MQHPeoJdWSDbafZoufzopMdr/flmZrsckp7QdBta1o3KJ5UQoZNsMlL 7va0whqb2QxngOXT1LfHsTRGVZDP61SLfUW71c8CvOLXFrD0DSjUWB7m6Sovz+Xv1cFD ksc8VJujbNYQZcTMZ//Ogc1vZx4mG9dugRVaLeLoQ5EKsIUdY4kdGv4uBYGAHTod+zbk q7RNsX4iXOL66tf+wCpupkETv8srTG49xLaOK3lpPpxAmFB38RlmhPnKVNXnn8FqRm7J fcCYkjU/SuyRF9t6RiQWtn6jReJnc/UglvnRAy2esbXjDRrYP6HQT5oQ3emvzka3D96i S/gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3vGUXRY/JNfBGnbAekBFLY5gOvcKq1MkRAcEHZoXKQA=; b=UeP3u+SqWemUk8boIhdNWXGOaGm52oe2KLjTsv2+MEOOKID5duyw0WhggW1TOkFiVV XOuRlMdbKtkOpQE9nGy+cUwXkSejGN0g+m+vg+svdnaYE05xVr0cF4IFPAtJitbe7r7t 8wtW1GOFPK9RoNj7ZCR2xRO1381fhGBHQ3vREGwyJwm8lrJK566SZGuJsrcpVAJHzDnH Ccu87C7EdFt0qHhEiULQqqrf5BGCxjV1hr9csPeTMyhsRDLB7+UXEzJaJK0/jvXYuUUE Ge6350QinPTUj1NIMxDBz6j8eFIss7yA4Idc0NWo/Axo3UNG/4DPndbW5X7ARzJ+HTKq je/g== X-Gm-Message-State: AJIora/fpjyhJiS2QpdU3CfVsZkdmSD9j/4I+fxWJtKRouqmuuJkAmLQ MrorKPxX8SB+0jUdYfzWP+ctZ2Dk9EpKEA== X-Google-Smtp-Source: AGRyM1tfpNIwosB4i6pPq/Sfof3lP6BOo9e4beU4vjpA2+6YajPMTucz1jI4M/JhcFOLGRSbExrsDA== X-Received: by 2002:a5d:6d46:0:b0:21b:933d:7950 with SMTP id k6-20020a5d6d46000000b0021b933d7950mr8749978wri.679.1656599754093; Thu, 30 Jun 2022 07:35:54 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id r5-20020a05600c320500b0039db500714fsm6405945wmp.6.2022.06.30.07.35.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 07:35:53 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 30 Jun 2022 16:35:37 +0200 Message-Id: <20220630143543.39599-3-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220630143543.39599-1-dse@thaumatec.com> References: <20220630143543.39599-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/8] ipa: Add class that implements base AF control algorithm 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" Move the code that was common for IPU3 and RPi AF algorithms to a separate class independent of platform specific code. This way each platform can just implement contrast calculation and run the AF control loop basing on this class. Signed-off-by: Daniel Semkowicz --- .../libipa/algorithms/af_hill_climbing.cpp | 89 +++++++ src/ipa/libipa/algorithms/af_hill_climbing.h | 251 ++++++++++++++++++ src/ipa/libipa/algorithms/meson.build | 2 + 3 files changed, 342 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..f666c6c2 --- /dev/null +++ b/src/ipa/libipa/algorithms/af_hill_climbing.cpp @@ -0,0 +1,89 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Red Hat + * Copyright (C) 2022, Ideas On Board + * Copyright (C) 2022, Theobroma Systems + * + * af_hill_climbing.cpp - AF Hill Climbing common algorithm + */ + +#include "af_hill_climbing.h" + +/** + * \file af_hill_climbing.h + * \brief AF Hill Climbing common algorithm + */ + +namespace libcamera { + +LOG_DEFINE_CATEGORY(Af) + +namespace ipa::common::algorithms { + +/** + * \class AfHillClimbing + * \brief The base class implementing hill climbing AF control algorithm + * \tparam Module The IPA module type for this class of algorithms + * + * Control part of auto focus algorithm. It calculates the lens position basing + * on contrast measure supplied by the higher level. This way it is independent + * from the platform. + * + * Derived class should call processAutofocus() for each measured contrast value + * and set the lens to the calculated position. + */ + +/** + * \fn AfHillClimbing::setMode() + * \copydoc libcamera::ipa::common::algorithms::AfAlgorithm::setMode + */ + +/** + * \fn AfHillClimbing::setRange() + * \copydoc libcamera::ipa::common::algorithms::AfAlgorithm::setRange + */ + +/** + * \fn AfHillClimbing::setSpeed() + * \copydoc libcamera::ipa::common::algorithms::AfAlgorithm::setSpeed + */ + +/** + * \fn AfHillClimbing::setMetering() + * \copydoc libcamera::ipa::common::algorithms::AfAlgorithm::setMetering + */ + +/** + * \fn AfHillClimbing::setWindows() + * \copydoc libcamera::ipa::common::algorithms::AfAlgorithm::setWindows + */ + +/** + * \fn AfHillClimbing::setTrigger() + * \copydoc libcamera::ipa::common::algorithms::AfAlgorithm::setTrigger + */ + +/** + * \fn AfHillClimbing::setPause() + * \copydoc libcamera::ipa::common::algorithms::AfAlgorithm::setPause + */ + +/** + * \fn AfHillClimbing::setLensPosition() + * \copydoc libcamera::ipa::common::algorithms::AfAlgorithm::setLensPosition + */ + +/** + * \fn AfHillClimbing::processAutofocus() + * \brief Run the auto focus algorithm loop + * \param[in] currentContrast New value of contrast measured for current frame + * + * This method should be called for each new contrast value that was measured, + * usually in the process() method. + * + * \return New lens position calculated by AF algorithm + */ + +} /* namespace ipa::common::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..db9fc058 --- /dev/null +++ b/src/ipa/libipa/algorithms/af_hill_climbing.h @@ -0,0 +1,251 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Red Hat + * Copyright (C) 2022, Ideas On Board + * Copyright (C) 2022, Theobroma Systems + * + * af_hill_climbing.h - AF Hill Climbing common algorithm + */ + +#pragma once + +#include + +#include "af_algorithm.h" + +namespace libcamera { + +LOG_DECLARE_CATEGORY(Af) + +namespace ipa::common::algorithms { + +template +class AfHillClimbing : public AfAlgorithm +{ +public: + AfHillClimbing() + : mode_(controls::AfModeAuto), state_(controls::AfStateIdle), + pauseState_(controls::AfPauseStateRunning), + lensPosition_(0), bestPosition_(0), currentContrast_(0.0), + previousContrast_(0.0), maxContrast_(0.0), maxStep_(0), + coarseCompleted_(false), fineCompleted_(false), + lowStep_(0), highStep_(kMaxFocusSteps) + { + } + + virtual ~AfHillClimbing() {} + + void setMode(controls::AfModeEnum mode) final + { + if (mode != mode_) { + LOG(Af, Debug) << "Switched AF mode from " << mode_ + << " to " << mode; + pauseState_ = libcamera::controls::AfPauseStateRunning; + mode_ = mode; + } + } + + void setRange([[maybe_unused]] controls::AfRangeEnum range) final + { + LOG(Af, Error) << __FUNCTION__ << " not implemented!"; + } + + void setSpeed([[maybe_unused]] controls::AfSpeedEnum speed) final + { + LOG(Af, Error) << __FUNCTION__ << " not implemented!"; + } + + void setTrigger(controls::AfTriggerEnum trigger) final + { + LOG(Af, Debug) << "Trigger called in mode " << mode_ + << " with " << trigger; + if (mode_ == libcamera::controls::AfModeAuto) { + if (trigger == libcamera::controls::AfTriggerStart) + afReset(); + else + state_ = libcamera::controls::AfStateIdle; + } + } + + void setPause(controls::AfPauseEnum pause) final + { + /* \todo: add the AfPauseDeferred mode */ + if (mode_ == libcamera::controls::AfModeContinuous) { + if (pause == libcamera::controls::AfPauseImmediate) + pauseState_ = libcamera::controls::AfPauseStatePaused; + else if (pause == libcamera::controls::AfPauseResume) + pauseState_ = libcamera::controls::AfPauseStateRunning; + } + } + + void setLensPosition([[maybe_unused]] float lensPosition) final + { + LOG(Af, Error) << __FUNCTION__ << " not implemented!"; + } + + /* These methods should be implemented by derived class */ + virtual void setMetering(controls::AfMeteringEnum metering) = 0; + virtual void setWindows(Span windows) = 0; + +protected: + uint32_t processAutofocus(double currentContrast) + { + currentContrast_ = currentContrast; + + /* If we are in a paused state, we won't process the stats */ + if (pauseState_ == libcamera::controls::AfPauseStatePaused) + return lensPosition_; + + /* Depending on the mode, we may or may not process the stats */ + if (state_ == libcamera::controls::AfStateIdle) + return lensPosition_; + + if (state_ != libcamera::controls::AfStateFocused) { + afCoarseScan(); + afFineScan(); + } else { + /* We can re-start the scan at any moment in AfModeContinuous */ + if (mode_ == libcamera::controls::AfModeContinuous) + if (afIsOutOfFocus()) + afReset(); + } + + return lensPosition_; + } + +private: + void afCoarseScan() + { + if (coarseCompleted_) + return; + + if (afScan(kCoarseSearchStep)) { + coarseCompleted_ = true; + maxContrast_ = 0; + lensPosition_ = lensPosition_ - (lensPosition_ * kFineRange); + previousContrast_ = 0; + maxStep_ = std::clamp(lensPosition_ + static_cast((lensPosition_ * kFineRange)), + 0U, highStep_); + } + } + + void afFineScan() + { + if (!coarseCompleted_) + return; + + if (afScan(kFineSearchStep)) { + LOG(Af, Debug) << "AF found the best focus position !"; + state_ = libcamera::controls::AfStateFocused; + fineCompleted_ = true; + } + } + + bool afScan(uint32_t minSteps) + { + if (lensPosition_ + minSteps > maxStep_) { + /* If the max step is reached, move lens to the position. */ + lensPosition_ = bestPosition_; + return true; + } else { + /* + * 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_ += minSteps; + 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; + } + } + + previousContrast_ = currentContrast_; + LOG(Af, Debug) << " Previous step is " << bestPosition_ + << " Current step is " << lensPosition_; + return false; + } + + void afReset() + { + LOG(Af, Debug) << "Reset AF parameters"; + lensPosition_ = lowStep_; + maxStep_ = highStep_; + state_ = libcamera::controls::AfStateScanning; + previousContrast_ = 0.0; + coarseCompleted_ = false; + fineCompleted_ = false; + maxContrast_ = 0.0; + } + + bool afIsOutOfFocus() + { + const uint32_t diff_var = std::abs(currentContrast_ - + maxContrast_); + const double var_ratio = diff_var / maxContrast_; + LOG(Af, Debug) << "Variance change rate: " << var_ratio + << " Current VCM step: " << lensPosition_; + if (var_ratio > kMaxChange) + return true; + else + return false; + } + + controls::AfModeEnum mode_; + controls::AfStateEnum state_; + controls::AfPauseStateEnum pauseState_; + + /* VCM step configuration. It is the current setting of the VCM step. */ + uint32_t lensPosition_; + /* The best VCM step. It is a local optimum VCM step during scanning. */ + uint32_t bestPosition_; + + /* Current AF statistic contrast. */ + double currentContrast_; + /* It is used to determine the derivative during scanning */ + double previousContrast_; + double maxContrast_; + /* The designated maximum range of focus scanning. */ + uint32_t maxStep_; + /* If the coarse scan completes, it is set to true. */ + bool coarseCompleted_; + /* If the fine scan completes, it is set to true. */ + bool fineCompleted_; + + uint32_t lowStep_; + uint32_t highStep_; + + /* + * Maximum focus steps of the VCM control + * \todo should be obtained from the VCM driver + */ + static constexpr uint32_t kMaxFocusSteps = 1023; + + /* Minimum focus step for searching appropriate focus */ + static constexpr uint32_t kCoarseSearchStep = 30; + static constexpr uint32_t kFineSearchStep = 1; + + /* Max ratio of variance change, 0.0 < kMaxChange < 1.0 */ + static constexpr double kMaxChange = 0.5; + + /* Fine scan range 0 < kFineRange < 1 */ + static constexpr double kFineRange = 0.05; +}; + +} /* namespace ipa::common::algorithms */ +} /* namespace libcamera */ diff --git a/src/ipa/libipa/algorithms/meson.build b/src/ipa/libipa/algorithms/meson.build index ab8da13a..860dc199 100644 --- a/src/ipa/libipa/algorithms/meson.build +++ b/src/ipa/libipa/algorithms/meson.build @@ -2,8 +2,10 @@ common_ipa_algorithms_headers = files([ 'af_algorithm.h', + 'af_hill_climbing.h', ]) common_ipa_algorithms_sources = files([ 'af_algorithm.cpp', + 'af_hill_climbing.cpp', ]) From patchwork Thu Jun 30 14:35:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16485 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 CD4DEBE173 for ; Thu, 30 Jun 2022 14:35:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 458CC65654; Thu, 30 Jun 2022 16:35:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656599757; bh=D6mWfExN4PL82RnT4O1sKrGXxjVAv1vqtWJnSUSNSUk=; 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=rbVuy3OSj9X2lvTCSU/DmuArQryWE268MQLNHJmKcpSmtZ+gXa6ml+1F4LNlrlIMA FjNn/Usd4DLXkpgTBB+tFS92q62LZ1EatVK/7Lm9wAO6cKLSBMIOM6tDtXRrBqoMXl xpkVOlTiIzf988vwaoQD86kQWfRXDdu8DC97Huj/qPAwe7vYxNvhVMLTfbsI/aJk0P K2ujQQIltST2dY80QANlb1E7MN0ciyZ/uER3vV11f/+ID+xeWBuWThu1W6J1pvlfoc quTcBJ1kGZS2RTkbDmA4jTkANMDQBdSApA/qPAbdBr4N9Sxksr4CTGQ0UJBGLGbtKt 6i7dRf1v+s/CQ== Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 343A565652 for ; Thu, 30 Jun 2022 16:35:56 +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="zRstArdb"; dkim-atps=neutral Received: by mail-wm1-x335.google.com with SMTP id n185so11466745wmn.4 for ; Thu, 30 Jun 2022 07:35:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cluHbp3ZozxQ7erXZ6WbYUVfdEdHHTItUQcZGF8SkjE=; b=zRstArdb4ZGRNC8LnMSsbTCyWLgSSOi1s22LuC/C+FlydU3ZEnTZXw0PirbSbJTNp3 lgRDoIKbTUFQKsvmq+Azj4n8NIvMyc8Mu5n0wOAcVZiniV4smjFcJU0m/VrHH3sz1tFk YZNfmJm/Ap54p6eaj/YxN7VpML5KdVCvjsVxEZmvQ/F4KKim/t7N53w6SWyXxihezj+j q9AInIN3ht2hek7F+VCJIOAe474NEeGVhc7RSg/XVy59SNz2uS0LzBFrtYMFbxPhytOG lFgaDwg0+tgiI9etrc8ZI3NqrPMiZ1rwMhVICfSh5hcH6lioTEEgOJXq1QhsmB+3m+fM QN3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cluHbp3ZozxQ7erXZ6WbYUVfdEdHHTItUQcZGF8SkjE=; b=pLW8RCHd+L7OlK0wnNVNTIPx5HyzMEem6B9B7c4O7rGoRI/MRxdoh2/GCwi6AKauRL cdU3r5FVI5tUgQ0oQtzOIzCSvmML1YYzimMNgLwHq7vYgBJWrCovmkUGiSaSdj3oF3tN 4IZnnQd4T5HVT5mutxdPEmtgJRveLVugyGDXwYFblcxhg/t9Y8ZFZu3U8aiirjHGiOGL CJqxDN4nZFrCV04Ghe8aAEUyvZ2R0dYQl131RZ+TdHRmx6Y3+vWXapMkFdD8/xFOfIOF hcu58IRTkw3ftFDvCe2EDQZHJRWC94MoH/p/6YoyFmL4oLl3ZO9slt8Mv7IzSDx1n9IY qKpg== X-Gm-Message-State: AJIora+WTqBwliBY55CgI4OTD98mCpaJkyV4HSuX1eEgnftUTU78XKx2 /GJ0CsnrKzrc9Bpb8wd9jNCtM/JgLo69Lw== X-Google-Smtp-Source: AGRyM1vNhcSQ4cLesuGgv3qkfE3jY1AKVsWNIcxW+BBa7sx88QElYkvOiAzS9DiPMgbPJJK3sw+ieQ== X-Received: by 2002:a1c:f60f:0:b0:3a0:3e0c:1de1 with SMTP id w15-20020a1cf60f000000b003a03e0c1de1mr12642265wmc.56.1656599755952; Thu, 30 Jun 2022 07:35:55 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id r5-20020a05600c320500b0039db500714fsm6405945wmp.6.2022.06.30.07.35.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 07:35:55 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 30 Jun 2022 16:35:38 +0200 Message-Id: <20220630143543.39599-4-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220630143543.39599-1-dse@thaumatec.com> References: <20220630143543.39599-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/8] ipa: rkisp1: Add AF algorithm basing on common AfHillClimbing class 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" 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 --- src/ipa/rkisp1/algorithms/af.cpp | 70 +++++++++++++++++++++++++++ src/ipa/rkisp1/algorithms/af.h | 32 ++++++++++++ src/ipa/rkisp1/algorithms/meson.build | 1 + 3 files changed, 103 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..8da970e3 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/af.cpp @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Theobroma Systems + * + * af.cpp - AF control algorithm + */ + +#include "af.h" + +/** + * \file af.h + */ + +namespace libcamera::ipa::rkisp1::algorithms { + +/** + * \class Af + * \brief AF control algorithm + */ + +LOG_DEFINE_CATEGORY(RkISP1Af) + +/** + * \copydoc libcamera::ipa::Algorithm::configure + */ +int Af::configure([[maybe_unused]] IPAContext &context, + [[maybe_unused]] const IPACameraSensorInfo &configInfo) +{ + return 0; +} + +/** + * \copydoc libcamera::ipa::Algorithm::prepare + */ +void Af::prepare([[maybe_unused]] IPAContext &context, [[maybe_unused]] rkisp1_params_cfg *params) +{ +} + +/** + * \copydoc libcamera::ipa::Algorithm::process + */ +void Af::process(IPAContext &context, + [[maybe_unused]] IPAFrameContext *frameCtx, + const rkisp1_stat_buffer *stats) +{ + uint32_t sharpness = stats->params.af.window[0].sum; + uint32_t luminance = stats->params.af.window[0].lum; + + LOG(RkISP1Af, Debug) << "lensPosition: " << context.frameContext.af.focus + << ", Sharpness: " << sharpness + << ", Luminance: " << luminance; + + uint32_t lensPosition = processAutofocus(sharpness); + + context.frameContext.af.focus = lensPosition; +} + +void Af::setMetering([[maybe_unused]] controls::AfMeteringEnum metering) +{ + LOG(RkISP1Af, Error) << __FUNCTION__ << " not implemented!"; +} + +void Af::setWindows([[maybe_unused]] Span windows) +{ + LOG(RkISP1Af, Error) << __FUNCTION__ << " not implemented!"; +} + +REGISTER_IPA_ALGORITHM(Af, "Af") + +} /* namespace libcamera::ipa::rkisp1::algorithms */ diff --git a/src/ipa/rkisp1/algorithms/af.h b/src/ipa/rkisp1/algorithms/af.h new file mode 100644 index 00000000..c470c9b2 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/af.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Theobroma Systems + * + * af.h - AF control algorithm + */ + +#pragma once + +#include + +#include "libipa/algorithms/af_hill_climbing.h" +#include "module.h" + +namespace libcamera::ipa::rkisp1::algorithms { + +class Af : public ipa::common::algorithms::AfHillClimbing +{ +public: + Af() = default; + ~Af() = default; + + int configure(IPAContext &context, const IPACameraSensorInfo &configInfo) override; + void prepare(IPAContext &context, rkisp1_params_cfg *params) override; + void process(IPAContext &context, IPAFrameContext *frameCtx, + const rkisp1_stat_buffer *stats) override; + + void setMetering(controls::AfMeteringEnum metering) override; + void setWindows(Span windows) override; +}; + +} /* namespace libcamera::ipa::rkisp1::algorithms */ diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build index 7ec53d89..81addcc9 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', From patchwork Thu Jun 30 14:35:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16486 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 245EDBE173 for ; Thu, 30 Jun 2022 14:36:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C915C6565B; Thu, 30 Jun 2022 16:35:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656599759; bh=a02j7m+LCJXnGBRYohDsOE13qJPexul5dyO/pjASgNs=; 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=GjE28zlJgP7TxexJo4/5CqG0L0myt7jAZ9oJ7v6BFKQipWf1LKTg3t6LwiwDzyXlk oNq8XhflQ4jmcfsEqV7q6ZgSv3lGgyotpZ+nd/KdBfV5zTkDS4yXxN7qdE6chBb2aJ OJ7oN4m+KX0ZAZb1+jtbATdYb5oZpqMfASOB8X8IBGfsHFuhjHrgpsmJcuZtwaKmlh HAsxXKhRTn1O+EOXLEH9aPRzjC9TLdg3oiV6/HK/CJoVl/aWinFXW6m3AEo2ZtqQxL QI9vs2Uf1dyqq6FKCquH79KCmlB395HYnvSS6/X73I9/JYiCAOGj4nc2otGvDpvI+x LoTwZjwxkA9jg== Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E61D865651 for ; Thu, 30 Jun 2022 16:35:57 +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="xLfjPOF8"; dkim-atps=neutral Received: by mail-wm1-x334.google.com with SMTP id be14-20020a05600c1e8e00b003a04a458c54so1804509wmb.3 for ; Thu, 30 Jun 2022 07:35:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JpO4KM67IDVW3tNGmALv7h4/iatJGTjwtytTMopFnkA=; b=xLfjPOF8MnILcT3w556LpyJw3UVpxSRaGPPkl5oSjVun7DZRoPxFDNta61KI1TMIJh sPqJs2qlk6S07sXogIgYvMbQvdJm+RGEyEGuTJOd83VNN5ciVfId/wyet6m6YhTi169S XPLQvmaBVXSNWHep4i82nD2ynL3EcmO7vlpeAuyJxeFeocbmJCY6vMMhu1N/eMVMcQWx 6SRJ9rCzvCk/1sAdR5cbhf45seIB5Z2UWNPCVdMtO9TNgMbB7dpjD/8IIt5TrNp308Tq xCWq8BDS3cmf56E0gBApykb3fWKWlBkDxCJaN4/fgcQ6KlummvjVSMtw8LZ0GDb2GawU C1ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JpO4KM67IDVW3tNGmALv7h4/iatJGTjwtytTMopFnkA=; b=XBnCLsZxktP7AXIEf49V4Z13PhbEeHuwwel8ZREPBsOxUMs0EkI9bGOHcYj2GgV3VK 9GUr744ZmqUftL38LFF7F1ZE4Coc1shnqnEDO71h2JvdhblnYDd+2bzeAHBp9ptdBg1G pgoJ3OmCo38z5X3//Y+N5b+DWMkPy29CwYMENTSyXUIW++PvUzpGUsOc+TDnv3eAMzx5 p0NEFiDTMNM2ZaEU5XKAHcOlKqds1ws2FFKMSYoaAjFxLHCotQC2TnvWqVJZMEhsPu6S Ff21p9JwEgHcT26KBclNJRRw6X71bHbsKIDSlYo2W/H82fEqkMCOluzkg/X4rZrIKkEG h3aA== X-Gm-Message-State: AJIora+6VYJUF8iUGQl92UXVHANsY/dknt4xdP06MFC+j5jy7Pp2Ug5I dqGijpXcB1BzD4X0LDHdC70aYWl4EfT2hw== X-Google-Smtp-Source: AGRyM1tGT9hQWX7iz39420v0oBkgyQxOdG1ybSbzl86sJ1tpLs9J3GzUoEr0iz8tT9LHP2S5ehh4pQ== X-Received: by 2002:a05:600c:34c9:b0:3a0:5072:9abe with SMTP id d9-20020a05600c34c900b003a050729abemr10244078wmq.8.1656599757689; Thu, 30 Jun 2022 07:35:57 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id r5-20020a05600c320500b0039db500714fsm6405945wmp.6.2022.06.30.07.35.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 07:35:57 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 30 Jun 2022 16:35:39 +0200 Message-Id: <20220630143543.39599-5-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220630143543.39599-1-dse@thaumatec.com> References: <20220630143543.39599-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/8] pipeline: rkisp1: Add basic AF controls to the supported controls list 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" This will expose the AF controls and will allow controlling them using the top level API. Signed-off-by: Daniel Semkowicz --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 7ee80192..99d66b1d 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -958,10 +958,12 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor) std::unique_ptr data = std::make_unique(this, &mainPath_, &selfPath_); - ControlInfoMap::Map ctrls; - ctrls.emplace(std::piecewise_construct, - std::forward_as_tuple(&controls::AeEnable), - std::forward_as_tuple(false, true)); + ControlInfoMap::Map ctrls({ + { &controls::AeEnable, ControlInfo(false, true) }, + { &controls::AfMode, ControlInfo(controls::AfModeValues) }, + { &controls::AfTrigger, ControlInfo(controls::AfTriggerValues) }, + { &controls::AfPause, ControlInfo(controls::AfPauseValues) } + }); data->controlInfo_ = ControlInfoMap(std::move(ctrls), controls::controls); From patchwork Thu Jun 30 14:35:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16487 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 3CDFCBE173 for ; Thu, 30 Jun 2022 14:36:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E25316565D; Thu, 30 Jun 2022 16:36:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656599761; bh=tePFJbqNxQG4rqyc5U31SCyuAbtuxBb9RDJ4Ws7GtgI=; 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=Zde3PUg9gvAtZDfpSZOs/TjWF0my0gIXxghAqgmkNSNWnCY5+yZbGUvWOAD7oolcf GWhW+6bTyDMKn26q5jg9bPXNrvR7AlczYeAZpuGs0I5lh27GdaNUohELLtWlucO+wo OS0nlQuRRAPuH6EFlTiNtKCRpBbVR4Wk3pNga8EjjDztyE/jCk+La3lePrl3HAPzMd bQbeOOMrgJv/DfIbEVqVT/k9tGyhdjovjddeCpSiiAFZk5Z6As/YhTGRPapSjY9Uiy aeXi1ncqjacXR2HezUCVoZoHGm2YnGVYKZbBL7rEx2Ik2aFMfAP7h2IlAkJCoJfCYq nK2pBFrAXYRig== Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BFE1F6565A for ; Thu, 30 Jun 2022 16:35:59 +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="O1a/ofYv"; dkim-atps=neutral Received: by mail-wr1-x435.google.com with SMTP id i1so23120751wrb.11 for ; Thu, 30 Jun 2022 07:35:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X7GLsLrVPX5OXkhXrPOHqOO0DAVsribVHxl4TC4vZMA=; b=O1a/ofYvJwKSRGJT/783DvV0l7NdDQ89KfDHOl8gxmIn7siIqS6/XTmkQu7/OZ9fFF m9FkzP6awWnYNOmgvqwWvilNdOwOFhdWCz3sWlrrXu7qcQacr332G3s6+O+7AqXUFLlb cSIFUPnXLZVlNgE900EszMPRyV4+stFbW9+p4q8l1wuZXvicUM4W7PxaVWVIQvkLcAMI aPayjQCfgyyUlWuAnMLEU22hEf6j9KvTHLKH+EvITAYwnOo23itylGoSSDAuOdskaBn2 Ay34+/NUz2vf85nTtWpKMyeZSr8o4PSXLRs8HpUmJxloT4Cx33TFl5goMrRQIM6vQsWZ Iz6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X7GLsLrVPX5OXkhXrPOHqOO0DAVsribVHxl4TC4vZMA=; b=HYbEvXGquN4CAb08pH6tqh6R/Fwv+WnuST4sNbMU8U73rJl4FtlJEJaP3T0sjjv9hz vpcKmDWbDblrsoPc4DnoGroFFHiepYkK4Zl7MjIMvJ9AbziaGvuRyAUff9emfjmf1WhG 3srVhwO9gXPU95XG8KlwIWdEZF992DnZsmim7reCbDnYKinc/kHh7JPWG6BQHVA0bcc6 uFKewyZiO8rDpuZMeZ/nviQDmqNdCnc6KF9vjo/q0vKIxznyGmtA0gB1NeR+KYwwufg5 tn4ysCwyw+f3HPJ20Ma21K+m1AMZjIKKfz4OTtl7rEAX/Oykmo//hTtKb3HZcMMjILXU 6Vww== X-Gm-Message-State: AJIora8WcPfsCYqWO2HojIrS7467krLwnCqyaaW6z77dycis4E5RmqQi BYi6s+0OjVuArzJRc0PxKVyuuoAEpCHAHA== X-Google-Smtp-Source: AGRyM1t2Avvl71wftwk5/F6VKjqGAcb5Dfm7AHuDfcCbTEsSiczmjx+C0FbA3ytS7gDZd8Plq9ritA== X-Received: by 2002:a5d:534f:0:b0:21a:3695:f52 with SMTP id t15-20020a5d534f000000b0021a36950f52mr8504858wrv.620.1656599759490; Thu, 30 Jun 2022 07:35:59 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id r5-20020a05600c320500b0039db500714fsm6405945wmp.6.2022.06.30.07.35.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 07:35:59 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 30 Jun 2022 16:35:40 +0200 Message-Id: <20220630143543.39599-6-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220630143543.39599-1-dse@thaumatec.com> References: <20220630143543.39599-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/8] ipa: module: Add getAlgorithm() method 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" This function allows to get pointer to the algorithm of specific type from the list of loaded algorithms. Signed-off-by: Daniel Semkowicz --- src/ipa/libipa/module.cpp | 7 +++++++ src/ipa/libipa/module.h | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/ipa/libipa/module.cpp b/src/ipa/libipa/module.cpp index 77352104..7c0680fd 100644 --- a/src/ipa/libipa/module.cpp +++ b/src/ipa/libipa/module.cpp @@ -83,6 +83,13 @@ namespace ipa { * \return The list of instantiated algorithms */ +/** + * \fn Module::getAlgorithm() + * \brief Find and return the algorithm of requested type + * \tparam AlgoType Algorithm type you want to retrieve + * \return Pointer to the algorithm if found, else nullptr + */ + /** * \fn Module::createAlgorithms() * \brief Create algorithms from YAML configuration data diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h index 4149a353..c4974635 100644 --- a/src/ipa/libipa/module.h +++ b/src/ipa/libipa/module.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -43,6 +44,22 @@ public: return algorithms_; } + template + AlgoType *getAlgorithm() const + { + auto isSameType = [](const std::unique_ptr> &algoPtr) { + return typeid(*algoPtr.get()) == typeid(AlgoType); + }; + + auto result = std::find_if(begin(algorithms_), end(algorithms_), isSameType); + + if (result != std::end(algorithms_)) { + return static_cast(result->get()); + } else { + return nullptr; + } + } + int createAlgorithms(Context &context, const YamlObject &algorithms) { const auto &list = algorithms.asList(); From patchwork Thu Jun 30 14:35:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16488 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 0D379BE173 for ; Thu, 30 Jun 2022 14:36:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B1A996564E; Thu, 30 Jun 2022 16:36:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656599764; bh=8AicMXYKV9hDctL83gvVRZlocz4NCdSpDdvYqi6X+ME=; 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=sBgclG8RGyPStTxsJGpAL8e1wiNqpp+6z6BGgp+gt17JpduxgNx3nv3lMi2t5qODb r3G1ycs8f6ZmPdUF3aBS0STsTgbjYy6SupjekMYyKJ3JXYTpFPS/AmwTEPdUEeM/8z 0PdcwiGpRj1lS30SaTHB6oMTsVR+B0dpTQfrXJyWmFAWTKZrSXf5BnseAt1Qg8IqEP PY0wUW8CVjSIMU6Rs+C6bRRqV7jcRVFFDeOq6br7VH4PiWyRuK5Rzb+ctP9eCy8fTo 2WCVhwF+NtgSdw+iunkvzx4D9NvBEzxquvaOwrHChXgqwwoqmnv2FqxXh9vUYLF2IG f5zF3c3yUvH1g== Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6E55F65657 for ; Thu, 30 Jun 2022 16:36:01 +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="hVQ5qB/Q"; dkim-atps=neutral Received: by mail-wm1-x335.google.com with SMTP id o16-20020a05600c379000b003a02eaea815so2751580wmr.0 for ; Thu, 30 Jun 2022 07:36:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WLYgX0MOK5dxYWvj13HoLuJzqbo6TzjvgYk9MSezfsA=; b=hVQ5qB/QYpBBC4/0Hjj+Q/EUKDKXy4OXGVAQTdBaEjNysa59hmG5dbrpA8AXhDxEcm oGMDtorol7AZMesjJ4Vu3C2ctrMOXPUvPkZxwbcXw39kMmilaSi020n0e9PAYzRt8zRJ fUBACUkgnCrGed/C3hEI3Ycrfc/FJT7gKlcNU8rOzKSkTAcuXwjnSBQdLwJtv0Vgs0Yu AztsuUJPPaj5X6WsfNwqww/4pym7uzKX5bOXhov4g2o2GrsTSLxq7x8caLrJ5aGP9W1E i8QbTOYWFI4V5cDQ7eIE7/TvtW7T2ObfFPOWxUjVtIzVU5bSjUqF/szsIqZdVOCAikD5 CkhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WLYgX0MOK5dxYWvj13HoLuJzqbo6TzjvgYk9MSezfsA=; b=nYiU6bgogYNv1Fh237v4RRbMRBqsCpXTR/nWqvhv0CtWpda1Xf1nug8DhitOmU4PDR Ttrc7bQrcsj9Ub1p2SLr9jcindNm1w6OzL6LaWyfmXgKTuxC/VXzqGxz2tx0ZyBanaIf zCpOTQLssi9HqG4mzQOFsQMa+Jy9OQCY/cDnhVYwMMJAXk5/ie0IWHbbUjzcZC62lhC3 5aMdNSYN9Vd7sA91ngFfsIkpKexmtsVgtQmXEG+/Wt9loZ8CqTzT8j6t8AwH83SSpOW0 vu2xly7KajHMVCgMT3gQFASMnsNF3dOwiLVL2Xcr6mOExf6/2GeDY0DHYtBph/CaAHw2 75Nw== X-Gm-Message-State: AJIora+iPFetd5xsEJKVlv8w+eHphXZlo+06HKLz2PA9+PjbNH1OCt0c bAxnbqrQ3tGr1whSEsy1ITlral8ftI7Qgw== X-Google-Smtp-Source: AGRyM1ujyMr63jZD745Vx9rWXilAiRp06oj9CHO5tnf7+on1a2znNB+hXVsOHOviTb/joSkL0C9aRw== X-Received: by 2002:a7b:c003:0:b0:39c:5642:e415 with SMTP id c3-20020a7bc003000000b0039c5642e415mr12198498wmb.111.1656599761227; Thu, 30 Jun 2022 07:36:01 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id r5-20020a05600c320500b0039db500714fsm6405945wmp.6.2022.06.30.07.36.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 07:36:00 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 30 Jun 2022 16:35:41 +0200 Message-Id: <20220630143543.39599-7-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220630143543.39599-1-dse@thaumatec.com> References: <20220630143543.39599-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 6/8] ipa: rkisp1: Pass requests setting AF controls to the AF algorithm 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" Pass the controls set by top level API to the AF algorithm if it was enabled. Signed-off-by: Daniel Semkowicz --- src/ipa/rkisp1/rkisp1.cpp | 52 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 01bb54fb..53b53f12 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -28,6 +28,7 @@ #include "libcamera/internal/mapped_framebuffer.h" #include "libcamera/internal/yaml_parser.h" +#include "algorithms/af.h" #include "algorithms/agc.h" #include "algorithms/algorithm.h" #include "algorithms/awb.h" @@ -295,9 +296,56 @@ void IPARkISP1::unmapBuffers(const std::vector &ids) } void IPARkISP1::queueRequest([[maybe_unused]] const uint32_t frame, - [[maybe_unused]] const ControlList &controls) + const ControlList &controls) { - /* \todo Start processing for 'frame' based on 'controls'. */ + using namespace algorithms; + + for (auto const &ctrl : controls) { + unsigned int ctrlEnum = ctrl.first; + const ControlValue &ctrlValue = ctrl.second; + + LOG(IPARkISP1, Debug) << "Request ctrl: " + << controls::controls.at(ctrlEnum)->name() + << " = " << ctrlValue.toString(); + + switch (ctrlEnum) { + case controls::AF_MODE: { + Af *af = getAlgorithm(); + if (!af) { + LOG(IPARkISP1, Warning) << "Could not set AF_MODE - no AF algorithm"; + break; + } + + af->setMode(static_cast(ctrlValue.get())); + break; + } + case controls::AF_TRIGGER: { + Af *af = getAlgorithm(); + if (!af) { + LOG(IPARkISP1, Warning) << "Could not set AF_TRIGGER - no AF algorithm"; + break; + } + + af->setTrigger(static_cast(ctrlValue.get())); + break; + } + case controls::AF_PAUSE: { + Af *af = getAlgorithm(); + if (!af) { + LOG(IPARkISP1, Warning) << "Could not set AF_TRIGGER - no AF algorithm"; + break; + } + + af->setPause(static_cast(ctrlValue.get())); + break; + } + default: + LOG(IPARkISP1, Warning) + << "Ctrl " << controls::controls.at(ctrlEnum)->name() + << " is not handled."; + break; + } + } } void IPARkISP1::fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) From patchwork Thu Jun 30 14:35:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16489 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 A038ABE173 for ; Thu, 30 Jun 2022 14:36:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6956965656; Thu, 30 Jun 2022 16:36:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656599765; bh=ixBMBqERWPCiWh6yp9RxuI2rMhp3mGakgppB/VCrPSc=; 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=dnXXnWSxHwc+pdm+4QN9JPxLGzFzVvSRR8+F6T4yoQEqOhG+HsLV6zMD6aNvXDnU6 usSwNF4+g3eYkLaAarCVwcrUdEDqkXCXieGyxGXMX6iqlyw2SEcN35EKS6QDLOvJo0 wOUSar8DUq6CYLK1njBFiROzLQqc5O6g8DFN202kIm9ky3pPkNAha7Ea1Uyh44lbQa 0rE6u9JMK2yfeaWRUzCgJwLXnvApbDEfb1jGJhUldNIBIhhVp/BINPIvM5pD7kcci/ dMtnHWaVFT14elNXJqs7HiC0LQ6DZ6S49MqRjMR1zUoNG6Yof6BpIembouvUl9c3zt q4D2f30oX2mAg== Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0DD386564F for ; Thu, 30 Jun 2022 16:36:03 +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="aazVRqF0"; dkim-atps=neutral Received: by mail-wm1-x335.google.com with SMTP id o16-20020a05600c379000b003a02eaea815so2751616wmr.0 for ; Thu, 30 Jun 2022 07:36:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z19KJ+kxM+aOymXuMrwH22hdJRp8FmlFeWR+ImjWoX4=; b=aazVRqF0SbGyLVtDQWFV2gcdjQPIcwRun3HBj+Xuss9l8y+5K+vP4ckA5XYKmIMt2W wyMg1Of05iqqAnNuUJlPBowWzJ31k5oh9Dv0U1yaeIANHPlV9gy4k4xC5H4Vzk0pQi/m hndtkRmZ9RO8E6Jsqgxkc8H9oDxnXI4uW4pg656xzBxF/sdXXmnwGQcgNBaim4V3n7S/ LXPDD9yXfMOxT6NtDzIjKu8Dl2QKsBVJnNoux29fXTil4322eyjTtKOq++CJV9ZFTxMG t4PSDTPW/DD1wwEcPHaDXcOleozvTdtBTm4in7jBbFUyJZGFQgX62W7wUkKgExd8Vjc2 U8rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z19KJ+kxM+aOymXuMrwH22hdJRp8FmlFeWR+ImjWoX4=; b=7fFoUFKT/FCdO+1U5TxNHWjQ8ye6vCbTg341xaqNOdjTRpitHnYufmjoB4/mD1Yype 73m0xMouIDO4FRBjv7Abasj8tOFcPQ1BeLVipVSuZg0PRHuFNY1jVa1DWpI/GaIPjZx3 fFyxMxcRfnIpbLNiCWlAwD7QraFo/bW4DfsdsN00ClVaIJ30tp0XtBJWtbQrPuDP8Pg+ BCcV3H9zfCpDlBzk0zmL8uk5Y2LMgafNIsJGQypgIMcNptBYmcLhEAZI3EaD81Ax45Au 0vxWXaHmm1UWpWFH4FT3QhBTzgPCKjTnYTTkI6UmeJ2gT4uMIYmhiD8wNFlLxv4ablgd c++g== X-Gm-Message-State: AJIora/m11rV13n1TX3TEe68xIyPg2Ae78YqUX8IFci2WEy0kh0+6q2Q 6p/i40JurQ+29ycomIPfR/VMQr9J38ddBg== X-Google-Smtp-Source: AGRyM1uSPPfiHNvKAhN4fdXkgRX1M0iTRHf6xwNGA6TEh+XyXYFSJUyESLcp++j6j2u87I5sWJeZUg== X-Received: by 2002:a1c:f018:0:b0:3a0:3f8d:d71e with SMTP id a24-20020a1cf018000000b003a03f8dd71emr10757162wmb.104.1656599762861; Thu, 30 Jun 2022 07:36:02 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id r5-20020a05600c320500b0039db500714fsm6405945wmp.6.2022.06.30.07.36.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 07:36:02 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 30 Jun 2022 16:35:42 +0200 Message-Id: <20220630143543.39599-8-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220630143543.39599-1-dse@thaumatec.com> References: <20220630143543.39599-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 7/8] 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 --- src/ipa/rkisp1/data/meson.build | 1 + src/ipa/rkisp1/data/ov5675.yaml | 12 ++++++++++++ 2 files changed, 13 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 c3b4e388..03d71cbf 100644 --- a/src/ipa/rkisp1/data/meson.build +++ b/src/ipa/rkisp1/data/meson.build @@ -3,6 +3,7 @@ conf_files = files([ 'imx219.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..82b2caaf --- /dev/null +++ b/src/ipa/rkisp1/data/ov5675.yaml @@ -0,0 +1,12 @@ +--- +version: 1 +algorithms: + - Af: + - Agc: + - Awb: + - BlackLevelCorrection: + R: 256 + Gr: 256 + Gb: 256 + B: 256 +... From patchwork Thu Jun 30 14:35:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16490 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 24A82BE173 for ; Thu, 30 Jun 2022 14:36:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D7DB96564C; Thu, 30 Jun 2022 16:36:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656599767; bh=n4X3SEbhaRTmUqd2WK/p86Vgax6EYiFiLNeERaiLxkQ=; 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=N3xe4j3nfbcIAy+gtRt84z9oYYcf4Qfseijrf4cDslif704V0w3X3AAq444sqMe02 o2z2FwOK94kb4nUd2kZxMMCtWkv5dgAXP4wRcO63jixjwoqfJorVQIh7rO2lguLm6e 4+g303+v4s9QRnF5UogCSy/7ZgXJaEtZ5dl/c1jLBQVsnBFwI+MfSCa/P76oxEDD8d 1C/s4Tesctjx3mSNJF9WiXuCnjui2J0I/CMEKkQHielmn09OSCVYha16V5Yd5jtSNp lqOzWaTeZVDU+TklGXIbDu6wtRSemhH9xmLpqQREr8c1bFxN0EodyLllqkHJPKVNmV J8vVSKIoAuoTQ== Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 136DD6564C for ; Thu, 30 Jun 2022 16:36:05 +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="Gd0TpMAG"; dkim-atps=neutral Received: by mail-wm1-x32e.google.com with SMTP id o19-20020a05600c4fd300b003a0489f414cso1796450wmq.4 for ; Thu, 30 Jun 2022 07:36:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nyiOgrJW6e4HOWfmcUP3xJpxFA0ukWTwpc62dxzTC18=; b=Gd0TpMAG2rviMugW24pCgYzVZC+2IaMnqo2hgfzvQmtVRvDDomCW9b/Gr2R/5HQ9Fv bz9LCpR7J+IVpp/l6V0mjtmLwSI1aZhJFzF6c4cdrO+zsLjBnq6Loxo9K0F7lzJ/q5e4 NUZ6kBI8wu5zd9GbLNmw8GlPW9zwdJovJG9Y9+Z1uGkzOle9bQ/0gZ8nJXmTQ8eVNfuP PRSr+iJWrecOcPZgLgRBXDdQnhKUWfbP5uKFPDolGG4TGP+urduh/kVs4bHQV+SBwLGr ZxDvVkKKD29/hWhLIVNgypQhM2rmEUpgfqukEo2D3ZhxXg/fBL7MtUWMEhc3FDN7SdnE k+nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nyiOgrJW6e4HOWfmcUP3xJpxFA0ukWTwpc62dxzTC18=; b=BeuOn8OFUk4Ih5zfiZhyYPBp0XBewcMZviS9YSdwfjNFDWE1nMYLmhtfFeXaFVw38L URpudvTnLIFqsNYoyIrNxD59bUrXdLtFgbDk5pcTA1IxExWCkB4i2yWRAMXOUs7EGK7K fb6aU56nl4vyI75lVMrlzMsZUzCbxrW9v4IGF9iwy1PCIqXyt1Z7whXt/CZQsoJeGz4V hzkfF4+sgWW4/50M8ejie7S86PjTEzFY5fauqOpl718A3WhJrcsZsf0yxYV3B8rCv+iU izevuHc4BXHR7nA124C/hGBnvyRpLrP0HG05L15icizbPCJ6Kp8LAIhc+idGuUT9n46G zDfA== X-Gm-Message-State: AJIora9jXF12ixdX+jIlQijoJbZPFRZfwPdVJM0PGfr2HXntfvsAK1n1 DYy54gRX2Io9HwpFC85+GS0tYUiJYz6YGg== X-Google-Smtp-Source: AGRyM1vbLeWdjZ4sSz8HQeAgDofLfyaV0jJ/lCVaagsOmxUxgNF+1JIkgo5QRFXI7x9qAjMBIO/Ztg== X-Received: by 2002:a1c:7c18:0:b0:3a0:39b1:3403 with SMTP id x24-20020a1c7c18000000b003a039b13403mr13072413wmc.84.1656599764584; Thu, 30 Jun 2022 07:36:04 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id r5-20020a05600c320500b0039db500714fsm6405945wmp.6.2022.06.30.07.36.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 07:36:04 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 30 Jun 2022 16:35:43 +0200 Message-Id: <20220630143543.39599-9-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220630143543.39599-1-dse@thaumatec.com> References: <20220630143543.39599-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 8/8] ipa: rkisp1: Add "Windows" Metering mode to auto focus algorithm 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 manually setting auto focus window. 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 | 74 ++++++++++++++++++++++-- src/ipa/rkisp1/algorithms/af.h | 9 +++ src/ipa/rkisp1/rkisp1.cpp | 20 +++++++ src/libcamera/pipeline/rkisp1/rkisp1.cpp | 2 + 4 files changed, 99 insertions(+), 6 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/af.cpp b/src/ipa/rkisp1/algorithms/af.cpp index 8da970e3..22507918 100644 --- a/src/ipa/rkisp1/algorithms/af.cpp +++ b/src/ipa/rkisp1/algorithms/af.cpp @@ -20,20 +20,54 @@ namespace libcamera::ipa::rkisp1::algorithms { LOG_DEFINE_CATEGORY(RkISP1Af) + +static rkisp1_cif_isp_window rectangleToIspWindow(const Rectangle &rectangle) +{ + rkisp1_cif_isp_window ispwindow; + + ispwindow.h_offs = rectangle.x; + ispwindow.v_offs = rectangle.y; + ispwindow.h_size = rectangle.width; + ispwindow.v_size = rectangle.height; + + return ispwindow; +} + /** * \copydoc libcamera::ipa::Algorithm::configure */ int Af::configure([[maybe_unused]] IPAContext &context, - [[maybe_unused]] const IPACameraSensorInfo &configInfo) + const IPACameraSensorInfo &configInfo) { + /* Default AF window of 3/4 size of the screen placed at the center */ + defaultWindow_ = Rectangle(configInfo.outputSize.width / 8, + configInfo.outputSize.height / 8, + 3 * configInfo.outputSize.width / 4, + 3 * configInfo.outputSize.height / 4); + updateCurrentWindow(defaultWindow_); + return 0; } /** * \copydoc libcamera::ipa::Algorithm::prepare */ -void Af::prepare([[maybe_unused]] IPAContext &context, [[maybe_unused]] rkisp1_params_cfg *params) +void Af::prepare([[maybe_unused]] IPAContext &context, rkisp1_params_cfg *params) { + if (updateAfwindow_) { + params->meas.afc_config.num_afm_win = 1; + params->meas.afc_config.thres = 128; + params->meas.afc_config.var_shift = 4; + /* \todo Allow setting thres and var_shift in tuning file */ + + params->meas.afc_config.afm_win[0] = rectangleToIspWindow(currentWindow_); + + 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; + + updateAfwindow_ = false; + } } /** @@ -55,14 +89,42 @@ void Af::process(IPAContext &context, context.frameContext.af.focus = lensPosition; } -void Af::setMetering([[maybe_unused]] controls::AfMeteringEnum metering) +void Af::setMetering(controls::AfMeteringEnum metering) { - LOG(RkISP1Af, Error) << __FUNCTION__ << " not implemented!"; + if (metering == meteringMode_) + return; + + if (metering == controls::AfMeteringWindows) { + updateCurrentWindow(userWindow_); + } else { + updateCurrentWindow(defaultWindow_); + } + + meteringMode_ = metering; +} + +void Af::setWindows(Span windows) +{ + if (windows.size() != 1) { + LOG(RkISP1Af, Error) << "Only one AF window is supported"; + return; + } + + /* \todo Check if window size is valid for ISP */ + + LOG(RkISP1Af, Debug) << "setWindows: " << userWindow_; + + userWindow_ = windows[0]; + + if (meteringMode_ == controls::AfMeteringWindows) { + updateCurrentWindow(userWindow_); + } } -void Af::setWindows([[maybe_unused]] Span windows) +void Af::updateCurrentWindow(const Rectangle &window) { - LOG(RkISP1Af, Error) << __FUNCTION__ << " not implemented!"; + currentWindow_ = window; + updateAfwindow_ = true; } REGISTER_IPA_ALGORITHM(Af, "Af") diff --git a/src/ipa/rkisp1/algorithms/af.h b/src/ipa/rkisp1/algorithms/af.h index c470c9b2..c709ee98 100644 --- a/src/ipa/rkisp1/algorithms/af.h +++ b/src/ipa/rkisp1/algorithms/af.h @@ -27,6 +27,15 @@ public: void setMetering(controls::AfMeteringEnum metering) override; void setWindows(Span windows) override; + +private: + void updateCurrentWindow(const Rectangle &window); + + controls::AfMeteringEnum meteringMode_ = controls::AfMeteringAuto; + Rectangle currentWindow_; + Rectangle defaultWindow_; + Rectangle userWindow_; + bool updateAfwindow_ = false; }; } /* namespace libcamera::ipa::rkisp1::algorithms */ diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 53b53f12..99ac1fb7 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -319,6 +319,26 @@ void IPARkISP1::queueRequest([[maybe_unused]] const uint32_t frame, af->setMode(static_cast(ctrlValue.get())); break; } + case controls::AF_METERING: { + Af *af = getAlgorithm(); + if (!af) { + LOG(IPARkISP1, Warning) << "Could not set AF_WINDOWS - no AF algorithm"; + break; + } + + af->setMetering(static_cast(ctrlValue.get())); + break; + } + case controls::AF_WINDOWS: { + Af *af = getAlgorithm(); + if (!af) { + LOG(IPARkISP1, Warning) << "Could not set AF_WINDOWS - no AF algorithm"; + break; + } + + af->setWindows(ctrlValue.get>()); + break; + } case controls::AF_TRIGGER: { Af *af = getAlgorithm(); if (!af) { diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 99d66b1d..7ab03057 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -961,6 +961,8 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor) ControlInfoMap::Map ctrls({ { &controls::AeEnable, ControlInfo(false, true) }, { &controls::AfMode, ControlInfo(controls::AfModeValues) }, + { &controls::AfMetering, ControlInfo(controls::AfMeteringValues) }, + { &controls::AfWindows, ControlInfo(Rectangle{}, Rectangle(65535, 65535, 65535, 65535), Rectangle{}) }, { &controls::AfTrigger, ControlInfo(controls::AfTriggerValues) }, { &controls::AfPause, ControlInfo(controls::AfPauseValues) } });