From patchwork Wed Jul 13 08:43:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16599 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 1EAACBD1F1 for ; Wed, 13 Jul 2022 08:43:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C007D63316; Wed, 13 Jul 2022 10:43:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657701814; bh=Z6UIHygHBeusnTkcZzxnyW6sRJdbI//0YB+aVUn9bIc=; 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=XzSkzyvpLBj7ojBmwo1vnRmzY+PIgOqA+PcnVyo7HYBeajv0fIg3qxb6nmtmvKW4u 4cmTW70chUiRzw1LvdV4OPRQUDa3R2/zrWgeTNGh5gmJ7ZVN13zx9On4R0n5ylDPX1 1FC1s34P0bApo1WifW08vI7KbOvQJJNQL/rmRFQ9+fOqkGv/gWNbFxTUKZ/sFHccLT yUENodR/EPlHMNpQMu014zZr0DnRa1h4ddV09dWhr2FF5FnPPU73Njl0osNCCj+psy vnu+NF4M4LOPXSVP0fIt22he+5YMJI/LEdC11oMFPfGTeVSvNfscziAndJ8y3C//Np Yodm1yr7RoJLw== Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A85E26330F for ; Wed, 13 Jul 2022 10:43:31 +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="Io0YScVo"; dkim-atps=neutral Received: by mail-wr1-x429.google.com with SMTP id r10so8317737wrv.4 for ; Wed, 13 Jul 2022 01:43:31 -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=rBAG5bRUFgIM+iLZJ9vSxX+TnEQEJKU6Yr47fYtwcvc=; b=Io0YScVotfbPuNL7+h3sy4cBhkEouAHEp6ObhC5H70jmxb48yY7baebtf6Z7srKx1A uKy3Y4OaneLBDro1gcih14FtfAcI998ogqWzp4c3sbyO/aV3EoWy+1Wtsjxhwf9ddXgC KM7ebJMoQwuYHVAIaWgmak7Vyr3PqeK/crxywFcSbhZiObIDUJ+udxLjez9loU8f/UY2 9YZN4SX4ADOud/JPesB/zNLgnIhMv962LV/Y7a8Y6qUqY7Uc7CmlbECbpsIqH9g07iTz 4XD7N2112VJS28GfgFQt9cCYpftrd0ofAJiECqrMHc8PnTU6zhXxnCJ7thY7mqxydddd aDFw== 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=rBAG5bRUFgIM+iLZJ9vSxX+TnEQEJKU6Yr47fYtwcvc=; b=Qr2hDNimUlLELg/ZHE0egYmj8PACswloIJHSXDSEUbC3KoSGNZh21LQ5MZ0jUP89N0 Eu5Fln/EpuMQh5bHnn8rnqNJ5xZkIEu97/Qb1JLHFAqu85ArLwLX1KrGaNXC/1eufas2 P6ZqKSxUx/ORrLwk226yDKsSnfW1bczm7vl7LUsid3/fHCTb5oJH2+atcl7GunnaWUsA j04Gaknvp7XbOBatyWoz4deEoYFDJjRVGVx3EwIMS//OL0DwLrNZBocpYqL9Ww48vQtZ oHJFr+yxE0+v/5cz+Gh0jTwKHiuEqJcWkMEAHnm9xefpKLmq71mQfQSNkNCWKTKbfDqc o6EQ== X-Gm-Message-State: AJIora86FYSwjEuQ1eB4gzU2U8igIDx5yo3UsDhGlitLSnNNCsTQnj1D S9gMJtCcSZg+4RqkZf0KvrDKywrOHaS9gg== X-Google-Smtp-Source: AGRyM1uZ7KAb+4IFsd1hKhYMEpE6/EWY9RwObZ/KihdSWM8XA2A/w56fHVb4OQ7CU8vjZys2LXveKw== X-Received: by 2002:adf:f9ce:0:b0:21d:68b7:e7af with SMTP id w14-20020adff9ce000000b0021d68b7e7afmr2065190wrr.236.1657701811409; Wed, 13 Jul 2022 01:43:31 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id bg32-20020a05600c3ca000b003a04d19dab3sm5667468wmb.3.2022.07.13.01.43.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 01:43:30 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Jul 2022 10:43:07 +0200 Message-Id: <20220713084317.24268-2-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713084317.24268-1-dse@thaumatec.com> References: <20220713084317.24268-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 01/11] 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 | 78 ++++++++++++++++++++++ src/ipa/libipa/algorithms/af_algorithm.h | 41 ++++++++++++ src/ipa/libipa/algorithms/meson.build | 9 +++ src/ipa/libipa/meson.build | 6 ++ 4 files changed, 134 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..47e54d5a --- /dev/null +++ b/src/ipa/libipa/algorithms/af_algorithm.cpp @@ -0,0 +1,78 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2022, Raspberry Pi (Trading) Limited + * Copyright (C) 2022, Theobroma Systems + * + * af_algorithm.cpp - Autofocus control 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..2862042b --- /dev/null +++ b/src/ipa/libipa/algorithms/af_algorithm.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2022, Raspberry Pi (Trading) Limited + * Copyright (C) 2022, Theobroma Systems + * + * af_algorithm.h - Autofocus control 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 Wed Jul 13 08:43:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16600 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 0D41EBD1F1 for ; Wed, 13 Jul 2022 08:43:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9E5E463319; Wed, 13 Jul 2022 10:43:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657701817; 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=k2miVst9SL3hCwD8lYMldzrU3Of9RoBla66gD8GFtGMGCB6UyI4e8aXSdY+UBRM83 dv3eY67H5cpuV37TEaGCUYjiTCqqQ3TIH7qwClWabWDBabWnoSziRjJLwV1/VDIlJv 1ljbnivMRMdza2+3M4BMV6XxyzRVsoZ7w6JDQ5dAw0eJbLk445MIuvU812CN034zn7 g/nLZg9sR9KyKtGBVCF9hHroohCi6exInNk/UaKWe7xPa1QSSvl6OR22eECjno9J4j MXCUMQMiGwUJh6o5K/OBI/Wd3s9iLfgy1YSUHBlR8Bs6gHPD9uLo4ypu8aLD0k8l4L If91KjjTIP8XA== Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E228B6330A for ; Wed, 13 Jul 2022 10:43:33 +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="LvjrvfO6"; dkim-atps=neutral Received: by mail-wr1-x436.google.com with SMTP id a5so14461594wrx.12 for ; Wed, 13 Jul 2022 01:43:33 -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=LvjrvfO6Q5m96JEft2bQ8SMvLJ81RkS1+hSF2oBC/k6z/yu//Vs16g0fiMcHoOZMJP N+RK7DM9YjO3vySdEKDU88KOzhC8LON7XcNpkyJvVPeB//t0IBJnnF53NQwfSoRyebXD oKKc9PAiWLCKcyJSkfQsaHMCxuHQS3IBRjR48TTAksJbqFhbkdda8eU68uvX/GUsGmgd 0TYl7cuYd0Tw5QQcjB0p0gUEDA+8TFAhWPohwdYG4AK0Ja64jWcWgELFiykveY+X2AuE KzB4W9AI7qyiVsi0/kEJPfvh6kKkCw02QNgP/xId2OAlKlYR08EYdZ/2b/U7p4YlrVDg i1Aw== 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=ks5IAxtMkZV/Ty8Ub0U/GvmD5C2wlKg8nAUHHVrr12zK35k/yUOfRhZJA8rjHLB9zY 7kWraipFIR9qZzEJLUFbaZmsr+ri4MmF9NS9H142GM3JOMagMRtoaTHcVcDkAxYkYqDo g3YLcg6+RcTJSxWEm0cgIjXoRBpvkQEg2jQ9tbT3qPjjg6lgW9dcMAFK/NV+K+mGg4mx CfTBonfWL5/qc9UW1W5BTKubsGDik5Ur8RmNKJQWpIhhK/i+GIykcfsXv3nIukZpZ++R iSrxOQTgU5A016Tz0/nhNSp1dFPvH9Rl3WcUg83OAdkxg6BuR1Zh5J9ik+Cl2l3gwLO6 h3mw== X-Gm-Message-State: AJIora8yXNxb4p7nWbA+bnSrAyk36zkDDWZ7+Q/4CYxfrk8dp5s1r/XV t97kXyj1Enq4gGFbBtXDlCWfgFJiE/G3/w== X-Google-Smtp-Source: AGRyM1uRW8Gkln72M96GJjPnrTxGNIb/K6x21RPSP8VyMNcfKwBQsY6dIpPtmUpsoc4KWx7V+rxIYg== X-Received: by 2002:adf:fd02:0:b0:21d:6f22:7857 with SMTP id e2-20020adffd02000000b0021d6f227857mr2118398wrr.633.1657701813553; Wed, 13 Jul 2022 01:43:33 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id bg32-20020a05600c3ca000b003a04d19dab3sm5667468wmb.3.2022.07.13.01.43.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 01:43:33 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Jul 2022 10:43:08 +0200 Message-Id: <20220713084317.24268-3-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713084317.24268-1-dse@thaumatec.com> References: <20220713084317.24268-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 02/11] 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 Wed Jul 13 08:43:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16601 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 89F99BD1F1 for ; Wed, 13 Jul 2022 08:43:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4C0DF6331B; Wed, 13 Jul 2022 10:43:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657701819; bh=3PwVJbBvJmfeOkck+hHDrKlm2mNGUdi/IampTEFq/pQ=; 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=0fH+pobQpcAfKxvWWjRB+vcdLd9SKoL4qiC+P4+HwQ35dYMjdSKPnjbvuDFDmJUw5 vWuTKhciGvUBZinj7FEEwHsiW69GhRoHK8G86LFBbdirIEwrwZ13ughHyTi4aVXA1i XiH/3CdRyMW3AuRMXCBbmNR+PnnTFs5QgzbsxgNVqHYe5x6O5GnvwwiL9LVg5bMoQq Ft+HWt5a52Za5ENXPw7THGAV7O5jcyPe5iVBlZ5vQoTPvKtIY28OT8Zuo7f+XfOd/x M0Wb68tnanCAVO8Jmxiq5wI8BeK97+j5/3SuyJ4hKif2A/byNSkLN/f9bJ1nvSesMn O1LtOUFFFzDaA== Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DF23063315 for ; Wed, 13 Jul 2022 10:43:36 +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="8EGeQgKO"; dkim-atps=neutral Received: by mail-wr1-x433.google.com with SMTP id d16so14448614wrv.10 for ; Wed, 13 Jul 2022 01:43:36 -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=LNUrI0Wv0kp01lau6uWaUf3XyBtzo2JjTSprG0e5S14=; b=8EGeQgKOOOisH7P0dTOndC1qlw2bK4ghXGI+UkDzvEMC+cN4F0gxaUKEa8jxjsP9gF r5W54MuvcPKYH1DRsV1TSrh3miFtfPYyG200zJiTo6h+zM5Ff7xJOcM5bXbm9qax64v4 T1JszZ4tNCe3aqvsYzlCCdOsPAF2wxna3ix4b3m9IREWliXu6YB7l7rRO33t6bIvm6WX u+wu1Z0X+bC3qv/cAkzolpHCECOyTOugqvLNN3NNR99pfZeqatKBq8CpeTVzuXWG45Ml ODE2uff+sXUo7aK+9iaiaQwqlzr0Sg+vGc8/Sc+bPSkNJ6YGfhCf2rl12stIy34Vp5KN PFSw== 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=LNUrI0Wv0kp01lau6uWaUf3XyBtzo2JjTSprG0e5S14=; b=Zy6l46vWPwrc9DtoUU9Z6AaLaRa6YQEOdgQHptbNE2Yr1qOaEbLk/4exQJ0/0u1b6k /OYqlyI8/uOqWpkosshfpKafV1K14Pr9lS5VOszJz6JkBpEJD2Q77F36esnB2tvMb6hW nyHcs1aXZLz5GLpw4QuIxrsTAVM0nJPXx2n0UTNrRkhxawqZU8GjJmxKMboRaoUJ/52F D/+2cC8A/wtwO46wCuWWlMvbmQV2Iuf0BQJbSE74fKsbpQxEU2KnCeoQDwmeLFUUxdG/ TL9bTUOIQv1y0JpvB2XqGdIT9AOH0wv6f3HHEN4HDDNeZle9Y/Dd+PzzOnGYUQRMX73m mCSA== X-Gm-Message-State: AJIora8ifm4eCJffFqzkfSGyozxhYCy4pFUE4fJfKnu1cawDdnLa4TQT 8Sccda7sEp/9466H9fKszJ0qPghsJHSjnA== X-Google-Smtp-Source: AGRyM1v5FO/Brnvq/4vMKsvTqkC++lddNc8hqxqWtIaz/2nIVBbfUMt25Dggj0QbBZjMPsfsEuFWUQ== X-Received: by 2002:a5d:530f:0:b0:21d:9669:1f44 with SMTP id e15-20020a5d530f000000b0021d96691f44mr2036275wrv.644.1657701816664; Wed, 13 Jul 2022 01:43:36 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id bg32-20020a05600c3ca000b003a04d19dab3sm5667468wmb.3.2022.07.13.01.43.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 01:43:36 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Jul 2022 10:43:09 +0200 Message-Id: <20220713084317.24268-4-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713084317.24268-1-dse@thaumatec.com> References: <20220713084317.24268-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 03/11] 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..6e047804 --- /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 - RkISP1 AF hill climbing based 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..e9afbb98 --- /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 - RkISP1 AF hill climbing based 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 Wed Jul 13 08:43:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16602 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 EE0C2BD1F1 for ; Wed, 13 Jul 2022 08:43:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AE0706331E; Wed, 13 Jul 2022 10:43:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657701820; 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=t94rEw0NGvvR/6ww987EXnunRV7v0jg1qUtagsuymKsF63FZr5fq4YHzWDDMPyO+S do8h2P0urrgNJriUKIBNggt70MPOCCzBUXSUmK0XdhzD9wp02H3C/z3egZtAcFLO2v QlndYbnUUAt7kZEyyHfuQIa6D5aqhtd3Zmiz2Bqs1FvjZJpNgAxHlXNvMqK02VvXzR tj83RpN/eOvUK6KWIRvELpylYzxftscM0xx2tLNAogplE5PjIUGZcT/RAq078YVgeP dhMOMgOIiaHKKfO0m+/QTJkyLWgeZ2ODqbqjWoAnB16ZVCxFMIV6IDRDDfiHxXAd7n ri7TODKXMJA7A== Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 238BA63317 for ; Wed, 13 Jul 2022 10:43:39 +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="vvt82O+L"; dkim-atps=neutral Received: by mail-wm1-x32b.google.com with SMTP id l68so6081686wml.3 for ; Wed, 13 Jul 2022 01:43:39 -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=vvt82O+Ldbf4Rubme4VYFzEDhrwdoywIilbXCVjttqW7l3bFOG9Vm7UGfgTkaW+Imi GgUyPpe5cSyLtMQXbxUkwnm1+wNXN4x9+tEBWbMi8LMt3JP/H6QkKfe9zmTDp5VsBN6/ IO3MZ0TAZNWFoYpKQyeIMRb3Ev+kz+FuqG07iLjsOv3dPgS5alViXr98LrKeD+531cbh wLNsBnSUcOkJ6HkBtAGHmkiWsmCJ9rhJ2L/Pu1CiQhTUXhoJPQTtI5MI0IBNyPsnClem 2ALBor2G2bPE91TkiJK9ry+7EYlJsCHJMBMnOWvBrKpXgU9Sv+vfTs+dQNKjeeGFwBgx 23ug== 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=Vg45KvbnmZD/vUShwA2/LsU59lv5KV1vsUPMq06jTiIno3lR5irotd0DPOebhJZugl HbqC7Z8O0+XJfH0Y4JJGRZhIQ633VaCLqYR6NkBORSHRJJkSmp0ktLWmardCkvAxkL3F ILtqzkS2XTOxuCYzpLu7w/gY+iVI8ORAvRku6xBscBS0iaiqOt+SschREvnYpULEUVLt n6IcVMIDN0nZ2w8hrPZH9Q0EPPWSnerJ+TdTUTgiyziYssXIQm8c+/cBDYIGDcoYYFO1 +cc1qFeMq5mGF1W6ka9a2tjfQWXvqAXcN+JaYuPgcJhOqb6QM8E6vft9MJ6+xuZkWn5R ZciA== X-Gm-Message-State: AJIora975i6QSBrAJG7sAwHA/oj0dTC+SEVUTqVQhLgEnhip80WTJksa oB7zM1a5nk9GYuUyXGkw/MUKGlv4cDYBCw== X-Google-Smtp-Source: AGRyM1s2kY5DTXOfYCst0RNoNZheBB6qwmiqItVrSoSYbIx+eBQmExVwfhhTEqRUhOpJ5qGuvisyYg== X-Received: by 2002:a05:600c:3d95:b0:3a2:e97b:f3ae with SMTP id bi21-20020a05600c3d9500b003a2e97bf3aemr8151749wmb.188.1657701818873; Wed, 13 Jul 2022 01:43:38 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id bg32-20020a05600c3ca000b003a04d19dab3sm5667468wmb.3.2022.07.13.01.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 01:43:38 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Jul 2022 10:43:10 +0200 Message-Id: <20220713084317.24268-5-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713084317.24268-1-dse@thaumatec.com> References: <20220713084317.24268-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 04/11] 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 Wed Jul 13 08:43:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16603 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 9322FBE173 for ; Wed, 13 Jul 2022 08:43:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 43B1363322; Wed, 13 Jul 2022 10:43:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657701824; 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=ATU5LOLO29+AZLbpDoBkOIyJrRRaMH+n5UnsDqCxLgLZiU3/TDYGh8ouJbU9JO+r1 mdDLhGzgDRw+F1rSnCYxL9SWYELB5kONwoWidpcHSFXaEQamryRGUcpDSrV6Ae6e3r gQgN0UY7lw2sPEiVUqckD/ymSEPdVsTjL/5Lk0AuWOpVq3jtKkMZaqBXpfQy+/qgT5 /qrqIv7S9GOp4hbo+l5ZsnTec7VSiZUfMxT66NaLp/xYqLP2WuE8n7mkzQwc4tVwU+ Pn+WniGgrxNxgd8JJbtRRE53QQ+5VOnatVMdw7xMGLIH6gc9lmuaZYf59lhZO2d/g6 yfK4AIw+90NCg== Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7E4A063317 for ; Wed, 13 Jul 2022 10:43:42 +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="ZZ5CBhwQ"; dkim-atps=neutral Received: by mail-wr1-x42d.google.com with SMTP id v14so14473691wra.5 for ; Wed, 13 Jul 2022 01:43:42 -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=ZZ5CBhwQawFHtX16y12lchrWFO8RUPBOZx4pRywl3ZIoS53/UHs5m9Qmn0GEdnCDm6 +EYncmZ57x0wvjeJQlVo5sXukJCgDiu/QtwSl0EV2pynS+Eb5c2EEExTxwtOfOUa9wLB WhuRxhp4hZLibRa3KgTgH8hL5iWc6dHZHwaEjGyIEY+wSLDw+ckp22GBrg1Dbu0yqiuK 8FSvoQbYF+Bx49p2J0XFbcDdaqxkWzFepsvISgohv+1wMiKWWLnh/DMZeA8g2LOgX7ZF d+eru6Zd5eVb4y9D7nM5mOoJtXVFPKUUHSn3c/DI7sTXw1v1dg+Fh9HPVIFT9909uh9U zuxA== 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=t1fb6KzRSUBjA0Lk2K7MKEGSOLoKBzoQvdPeEuZt8Bmk6G/uxKkaxa2PLSC2/n5ZnA UFMzXygi8ktbLWZkmcQ0PQ88sUi0TroVhdOYWxS5vwKvx+qesg1KxXhA1YpK1cy9GqMG xL5T6KAMMRDysVF1nXiSxWhaJ6XLyp4KEIQ2ALVtpuxMWsd2wX9PuyLaP9qcKd38cbHu 1u7OpabEJJpYpNWO74aTq5hE+mSoC62/TUOBjmp8SShP6md+soFHbwFXY94FFYtXET4F hh5BTNYtAOWDRfCj57AuWrrTHjX39rpStkx2uAhvHR3blISlVzx8INdnDcYTG5++AV0I dWbw== X-Gm-Message-State: AJIora+fF+4yeUhxFfrEd87e+4x/RvHSodzcCkQPcRlEsUrjl/gYfDgM 9H4bfeHrC2xbMZ/KVHRDCxA3J3IT+7FEVQ== X-Google-Smtp-Source: AGRyM1tVskmINzu3guNp1TFGe2rfjdThLbzDSzQRbGej+MsWh2cln3roVNIzjwfQXfpEWpxHZ8gXKA== X-Received: by 2002:adf:ed10:0:b0:21d:a9a1:3526 with SMTP id a16-20020adfed10000000b0021da9a13526mr2064015wro.403.1657701822265; Wed, 13 Jul 2022 01:43:42 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id bg32-20020a05600c3ca000b003a04d19dab3sm5667468wmb.3.2022.07.13.01.43.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 01:43:41 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Jul 2022 10:43:11 +0200 Message-Id: <20220713084317.24268-6-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713084317.24268-1-dse@thaumatec.com> References: <20220713084317.24268-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 05/11] 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 Wed Jul 13 08:43:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16604 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 1E749BE173 for ; Wed, 13 Jul 2022 08:43:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E03E963323; Wed, 13 Jul 2022 10:43:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657701825; 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=dklFeEKztKqrOdBJHuRuecmQwQmKdWNueGdmOJUf2p4NEAqqoc07vue+aE6wI4aIf 0ecEJFXpfgMbrVNRParB+V0y8h4BFj0IvFM/4N8MQw08aYkh0LiJ7YxrbfpHidreEi o8oHO4/xw+fwcJAzm4Qj3ysN1LhQmTRDCGPfopfLqOTLZW/xfVBSWo7gGCxcLYxdMC HVaRxxy457aHWlDqFKCdYsa/zQmAOQK7cCl1D0R2gBekky6WFmmQkk5tZr7plu5Pli 5kVOAwV/jGEk9OzJuQehglqj1bb0zXKsnPq+pkNjf6QFgD3ytHMRghov61Mq0NJkrz vj/76yMeOfysA== 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 A33B563318 for ; Wed, 13 Jul 2022 10:43:43 +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="Tu2QM8ly"; dkim-atps=neutral Received: by mail-wr1-x435.google.com with SMTP id q9so14475108wrd.8 for ; Wed, 13 Jul 2022 01:43:43 -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=Tu2QM8lym7p8bbY1fZl1QbWNKiUPncK9+P5Q1GKAcIIAsnIMs1B5DIyDviN0MuniEP vgEg0z6pLH2I/BnXftvMGVD3gcRqgOuhi/jBo8R2EMQyfIulXXeL3HmBr0WVf8HwhsBX ho/aJK53aE4Xi7OrXPNwwJYUYOG3+4nvM97GrjFcudRthxz1gqJunjo43jNBu/EDUcQY zE49KrdM7j1JORXTTT9OqFXUGhf6BtNGM90Gyp+tHrzCXX/CnfK+7inSJ232StK9nBxq hfGnGXCrBZLhNGs9aarsU1bnhxuWGgrQ63pZhqq1Vu6mJNu+jOW8EP8FFEVn+uxXUBtI SdaQ== 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=3Yc5zqNVhrRWDVCPvCqkoFWU9TFAukcygFYFKhIZwDiTDqDX1qKvcLYoGBYdlyGbp7 4C8O2JMj/ONwH/IUULqDiyh7/oAjK3Kxw8YdxWRo3n5vTk1FFMOEAtKN7RfiVOBy1nLY NAwqSe2JCcEF3z68dc+cJCp8pJblv4uYcBuUFf1DXxKdrMgfPl70LAf46nDaD9fSUgs3 um3bLvOo4hedlEVhC6YM/2tXTqbZfl5vcH+WeFCkkBJvLNhJj1t/uWWqk0Zd954ibfT4 gyDaVJShB0ooWknDGLeeTO1BW14WSJU+ycXAKtTxZ5Q+YibsmWet5KiSypFZrFaKCi66 vInw== X-Gm-Message-State: AJIora8xuSgl/jX6i3jDUrqgcb81/s032pYEAL0OeFD1Pp1BYnvMG+7b oX44LiU7TX+Z5R/PVeec446Fl6Tm5mSFFw== X-Google-Smtp-Source: AGRyM1teV2f4ICFHFEN5c8mXZ4BHPjYXCTYkO76ISZ3YHD5sQpTe8NBe0Mp8bEAMuOUf62RsHvihkQ== X-Received: by 2002:a5d:5984:0:b0:21d:7f3a:a153 with SMTP id n4-20020a5d5984000000b0021d7f3aa153mr2022311wri.568.1657701823480; Wed, 13 Jul 2022 01:43:43 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id bg32-20020a05600c3ca000b003a04d19dab3sm5667468wmb.3.2022.07.13.01.43.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 01:43:43 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Jul 2022 10:43:12 +0200 Message-Id: <20220713084317.24268-7-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713084317.24268-1-dse@thaumatec.com> References: <20220713084317.24268-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 06/11] 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 Wed Jul 13 08:43:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16605 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 066CBBE173 for ; Wed, 13 Jul 2022 08:43:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8E47363328; Wed, 13 Jul 2022 10:43:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657701826; 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=ianb8yIcipLcJCfRZ8qrcMu0Ft7nqHwoO6O20enWLCM72+7KnGBjayZkSotvG4X/E RsrR0B0v4Td6lHVVxkNB5z/IZHNfSGldKCvlooL8QMZSY6Z/A1HqRhg8etpdFw1vPu 5Xh36KzfSR+oidzMpL9WGstbu5K+73VyXPCi2DUDWLLYzE9ZPpdxCmr2rzu7R/J1W3 M2eAbSK8JGT6Dj3fzBCupKZnecvQPOpVvn1eoV9YGs5jWQsF+SnL5XxjbUd+08igZw sB+YaAxn0Af9HJAnrGHj1atP0ptS2NkdrFAvN5+ZBaP1e43ZR54NPvMwKxpx9Ghs7S sVPIo8tCwpu5g== Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 05E0A6331A for ; Wed, 13 Jul 2022 10:43:45 +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="ryeORJcs"; dkim-atps=neutral Received: by mail-wr1-x42a.google.com with SMTP id bu1so13291417wrb.9 for ; Wed, 13 Jul 2022 01:43:45 -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=ryeORJcsOjVDhtQcltyx6uILJ1G4GI/OKcDwsLkD+JkgWzueLrgFWUz7bRw3stJnvA LVO7St/B+NbOUb/RsZg5XvVANMWnYQDW+Rvu+icvTvTZTVDjwIdJws8swCZAG25zuzDb FKWploFzlsR7r0cD7LUGtLQMRf9RWfCvES7RVLCxl87VmTL/rE7Hn861xWz7J158E/fZ +Szapc+mKvjkFG87HCfJIbdRVCWMi+TqHsjaW/81QEoGx35TJFj/AtWVTHGiWQ4eA8o1 Wr+jqEtX7n/urfEVUo7f1cBkUj4fUtzEeJcQdQpt95+Wk4RXMEhPREBQouG12yzUrHWZ emCA== 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=bKEAuSOjlijTIiYQLUGf0QDIuG+jrn4vqGcY6kZEdznXs3EfymY5f9FbuXBJe8iuBg W9eNk+MIFmsmTVs67Bmn/+Qf/P0Hsv9ewiobjmBwUKs0rEfcrYWrHHsp6h4XEMBN3mSV /UwsmBQbwaunykKahPhxey7eOX+MIofJbjQOfe8MntGx077mpRnZ4COQARmFpP7tpJIf juUHwltq/4FLz85iHOq/YXkuavguhvOMx96OpkteIq8LUW3w+LJtxpnRoQfO2olryg38 wkuzmvnpjdJrInkzcLhrZkl/zzx9fj8juT+KRCrFjTZ64RFWpkldoKDrMjIm7Aj8p8aE 3AdA== X-Gm-Message-State: AJIora/wdP3I1x3CPCKgrPeryyCck+NCm0ORUwfnE8GAWviFY0qyTQFL 8KtmwDhv542kPYNRxjFxMjbezixMHfqqmg== X-Google-Smtp-Source: AGRyM1vTZ42OuG5SMCzNRpZI3dg0gpIATOqo/xv/iqacD8vFdgf7rlrVVbEnAtOIB0vQsTED56fD5Q== X-Received: by 2002:a05:6000:1a8b:b0:21d:9ae8:f8d9 with SMTP id f11-20020a0560001a8b00b0021d9ae8f8d9mr1984157wry.686.1657701824786; Wed, 13 Jul 2022 01:43:44 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id bg32-20020a05600c3ca000b003a04d19dab3sm5667468wmb.3.2022.07.13.01.43.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 01:43:44 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Jul 2022 10:43:13 +0200 Message-Id: <20220713084317.24268-8-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713084317.24268-1-dse@thaumatec.com> References: <20220713084317.24268-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 07/11] 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 Wed Jul 13 08:43:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16606 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 07578BE173 for ; Wed, 13 Jul 2022 08:43:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BD8E66332A; Wed, 13 Jul 2022 10:43:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657701828; bh=UvlVZ/vpdaAmDJy+dX5wpOU7CW0QJe5+AsRwk0vzqfQ=; 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=NGjRYbmKfAH7BUBdxp8u5jx+E/dUzaH4MYePSUNwcSrux2+yZHrNTeD1JNtRoIVbW OqlF4CW0kZ/E0mA//ICEKC2EASwmiL4X4uNmDWTrnEL0h1ioUMNiEvFDERWSPqYrxW XLWRy5WyogM9bHXSX22pZ4bQHsjLYPDQHQx5+8KFVmCWft4UmnScKN+qgV9H+WqsbO tUQK0FnW42bXum/9zXpcapu5oju5pELEz5JSYWpGMcneySWmnmC+aLiO3QdWYvI38v lhM4SX8zkqVHOaLpn3AF554GdLb2mRI+jEDNajG0Ub+XCjFtA7M9XfCehWp04Nxm0d gU294VZM96msg== Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6682F6330D for ; Wed, 13 Jul 2022 10:43:46 +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="V51P9+oo"; dkim-atps=neutral Received: by mail-wr1-x436.google.com with SMTP id o4so14493674wrh.3 for ; Wed, 13 Jul 2022 01:43:46 -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=TEqk0tsZjracHmr4JA/9Bxzjw1uP65H1h7ztdKdW0u4=; b=V51P9+oolwahP3K1nyP+nz/Iv1tNA4DV6iKNXUwxG/FsBtmmcpuHTKB2S9WX7Fn5Kz l+Iyh2L75uBHnY5wd0tPtmbp6Sd9zmlIob886QZO1SufiGNonhrLAsCBwyYwyp5qq9dM O6XWDLDoD2T6AOQW83TRw7+4Jdl2vL7evV0TTbucqSrNhU+kW4ESEVIbdaIcuCoSEloZ 90u5VVWt5ZG7vTVMOqEjdIhk6oFafCurH+Bc/3DCe3gkUYrcqgifpK2cMbCd3vohPP8I OV1zNlCnv9Xfif4wL2FDHtlw2lX90Bo4nMKKRzIgar5GmcnA3SrmXSa4hRox5Ap2eS0v 4rKA== 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=TEqk0tsZjracHmr4JA/9Bxzjw1uP65H1h7ztdKdW0u4=; b=vbeKE/uqS7ACR4uNlhtmdtkFtS55lLw05Udl0bfK2/CbCPO19js1D0SiP49LgLFmJx pNZX+p7hU238K6WoOf81afaocGoHzNnvP7BziY74P5q6RTTgq6pUa2B3CCHce1jLxfd5 oTCCZ/myRMy3aB0dSD/Q7cb/h98wZvv//zShCIHJpOYZ+sgV1L241Pr813EdhJ1Ep/rr +slmnFCaqOB0puCVpEDUb4tTon+bqTyPuyz903AqVCKyPyK5fFIbhOCXLUA38Ucxl1Uv IJKIrlk6QL9whdI9r80myFhWRpJ9gjxlI7TH/ODOkrd8I3biaavO/LFAtgG/CMOtz2Ul kZLw== X-Gm-Message-State: AJIora8sgu6PZtWZLLdXLiy1Sf3e19gvui6X/tXXzNkHd7l3lxoSjHkk 06XmCi81bEZ2FHpi3jA3nMOHHpd7ahw11A== X-Google-Smtp-Source: AGRyM1t5nR4OcZS72AFxvKwd5s4+Ok2rxNCuJHU7pNO//joGCIaZkNM5ZnvG5SLGIqpjaVzUTXYfgg== X-Received: by 2002:a05:6000:1849:b0:21d:9ad7:f27f with SMTP id c9-20020a056000184900b0021d9ad7f27fmr1990321wri.445.1657701825995; Wed, 13 Jul 2022 01:43:45 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id bg32-20020a05600c3ca000b003a04d19dab3sm5667468wmb.3.2022.07.13.01.43.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 01:43:45 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Jul 2022 10:43:14 +0200 Message-Id: <20220713084317.24268-9-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713084317.24268-1-dse@thaumatec.com> References: <20220713084317.24268-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 08/11] 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 6e047804..cd4f0e08 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 e9afbb98..eeb806c0 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) } }); From patchwork Wed Jul 13 08:43:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16607 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 BD29BBE173 for ; Wed, 13 Jul 2022 08:43:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4C9806332C; Wed, 13 Jul 2022 10:43:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657701829; bh=ie3aENqbC44ysjMYLpStHnU7FOOcWn4heFKrwvTdjYI=; 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=t/eYYLAmo7tEuITyi6T3pwLmw2yFN7Tthx6aEQZPWYyqEnXzfD6pSst2PX9nCCids MQV6tHq11k0UFeXmt6TMHY2bOO5+Zv5e0NoZ2OxXcanQaX6j2W+FhIdhbsp6S7/Mqv HAtO00I8uoZc+AcUaYx3Anpy+Po/Al5XXTW7DJtJ22himpgK/p92jn8cyLrLKtGDE6 vL5vdfGX28jnMfVy5BRikVze78kgVM2hVWRmvyh2ltGShhJuLVExoUGYPLGghcx9Nm bHGFnArYvTB3elB2ym5zE/MAgLCCjcPcs1VbsEBJfo/NfJ/SCiTuv+w2qizIeH9VjW rLtaQX66B+Cjg== Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B631F6330D for ; Wed, 13 Jul 2022 10:43:47 +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="O1WzAwMf"; dkim-atps=neutral Received: by mail-wm1-x333.google.com with SMTP id ay25so6092244wmb.1 for ; Wed, 13 Jul 2022 01:43:47 -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=EHJVI5NARITEoRsYFHX1Zu3g0dX4ygzx+AElRmV8oEA=; b=O1WzAwMf+mOLTIUZ1FLvwZ/bmJvRZSgfrzr5HpQLNuvgbXQno/F9WObTO6hVt0GPJF hCOwacYXWQMnGvjZLGWhUXUZcI9JdLLUVj0FvhAMwm1MHdTMY+J4jJfbIgh8nNAholWH mCae9L+2l1PWfVLBHOCrGPsWiWOpYbVw+6UfhJjK/pWqJ4bQTueWAHOrqdB4rEhUATiE kRHQhCs09M4Rfba9klxJNG+ihvsToEz2GB4GyB02hvRmYDz2T1XlwQ1UTV8pIkBLvreo +OeiQC1GNmzulMRDtduYCxiCIZOFG+3BDEtyI6HMeXms9SjFzz1B/YjtMeR5YfPGyeLn RUtA== 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=EHJVI5NARITEoRsYFHX1Zu3g0dX4ygzx+AElRmV8oEA=; b=6suac/I/6SnACOFprgdAhNMY1+7HwouSd1J5MaBy8354JNpz2m4qfjb1XjzCMReT+2 rXNAcnYc8TJVOLkZ5qjN+Xjf2X92NF+pzphfavcw7B7lDfzqq2n6FCQgzscv0mkpug6t KcCqhWdJS3o9WK+VpFtDkuPBx4yGs2J3+sHbJBHUfh0bGMbM3zPZAN3rtohb6V07PnAM /msBzuk29Sa3jllAfAMOlybxbJ0Lbw5AQ2V8WCSmEsRqWNO/yWt74Vap5vTWNUKaz7hU rFb6ibL1HWdcLw3u2MRNeO/9CB09Ct78VmgTq08kCPH4eNnjsIsNSpQ6WUZFSS4/6z4H FYqg== X-Gm-Message-State: AJIora8EvCsJsD86daJxKIhC8sbaj4JNy8pXaqfixogO4E7+8zj1pKn9 sKcZopxcaE9ei+0sucyzqg3OmVY4SZ4U4Q== X-Google-Smtp-Source: AGRyM1sYjbpxZjtcwZqdLAwM3LTx9cbwbxoR/cOoPYTs0hGZ518zfNJfGrxVVdXPp7LfE5iXKjn4NA== X-Received: by 2002:a05:600c:33a2:b0:3a2:fda9:6489 with SMTP id o34-20020a05600c33a200b003a2fda96489mr800546wmp.29.1657701827320; Wed, 13 Jul 2022 01:43:47 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id bg32-20020a05600c3ca000b003a04d19dab3sm5667468wmb.3.2022.07.13.01.43.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 01:43:46 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Jul 2022 10:43:15 +0200 Message-Id: <20220713084317.24268-10-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713084317.24268-1-dse@thaumatec.com> References: <20220713084317.24268-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 09/11] ipa: af_hill_climb: Skip the first frame after triggering auto focus 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" When AFTrigger is received, AF algorithm internal state is reset to initial values. If reset happens between frames, then first contrast value that arrives after this, is interpreted as contrast for initial position. This is wrong, because it was measured for lens position before the reset. Skip this first frame to allow correct contrast measure for the initial lens position. Signed-off-by: Daniel Semkowicz --- .../libipa/algorithms/af_hill_climbing.cpp | 8 +++++++ src/ipa/libipa/algorithms/af_hill_climbing.h | 23 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/ipa/libipa/algorithms/af_hill_climbing.cpp b/src/ipa/libipa/algorithms/af_hill_climbing.cpp index f666c6c2..28d09176 100644 --- a/src/ipa/libipa/algorithms/af_hill_climbing.cpp +++ b/src/ipa/libipa/algorithms/af_hill_climbing.cpp @@ -84,6 +84,14 @@ namespace ipa::common::algorithms { * \return New lens position calculated by AF algorithm */ +/** + * \fn AfHillClimbing::setFramesToSkip() + * \brief Request AF to skip n frames + * \param[in] n Number of frames to be skipped + * + * Requested number of frames will not be used for AF calculation. + */ + } /* 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 index db9fc058..e251f3eb 100644 --- a/src/ipa/libipa/algorithms/af_hill_climbing.h +++ b/src/ipa/libipa/algorithms/af_hill_climbing.h @@ -29,7 +29,7 @@ public: lensPosition_(0), bestPosition_(0), currentContrast_(0.0), previousContrast_(0.0), maxContrast_(0.0), maxStep_(0), coarseCompleted_(false), fineCompleted_(false), - lowStep_(0), highStep_(kMaxFocusSteps) + lowStep_(0), highStep_(kMaxFocusSteps), framesToSkip_(0) { } @@ -92,6 +92,9 @@ protected: { currentContrast_ = currentContrast; + if (shouldSkipFrame()) + return lensPosition_; + /* If we are in a paused state, we won't process the stats */ if (pauseState_ == libcamera::controls::AfPauseStatePaused) return lensPosition_; @@ -113,6 +116,12 @@ protected: return lensPosition_; } + void setFramesToSkip(uint32_t n) + { + if (n > framesToSkip_) + framesToSkip_ = n; + } + private: void afCoarseScan() { @@ -191,6 +200,7 @@ private: coarseCompleted_ = false; fineCompleted_ = false; maxContrast_ = 0.0; + setFramesToSkip(1); } bool afIsOutOfFocus() @@ -206,6 +216,16 @@ private: return false; } + bool shouldSkipFrame() + { + if (framesToSkip_ > 0) { + framesToSkip_--; + return true; + } + + return false; + } + controls::AfModeEnum mode_; controls::AfStateEnum state_; controls::AfPauseStateEnum pauseState_; @@ -229,6 +249,7 @@ private: uint32_t lowStep_; uint32_t highStep_; + uint32_t framesToSkip_; /* * Maximum focus steps of the VCM control From patchwork Wed Jul 13 08:43:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16608 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 5EF5FBE173 for ; Wed, 13 Jul 2022 08:43:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2C85C63313; Wed, 13 Jul 2022 10:43:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657701832; bh=m+Xj9uD9TyeuceKfbUq/i9CZdpOv8SWmTrnRRg9kaqQ=; 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=EOPf4IpTni0MbTve1H5U1Hv16pPLp7APovevYx5tDjmbPai4dzIPt3w35SqqZ3et/ HsaG62wzwZlronn3zb5l80KlswQhYyyJxX56jmp6tfWA9S2ZI3VcHgeqTBUG3gHl7x QWx6sKqDfYT9FyHpTMkTXU5YUWdYXKM01CEgpwhIMa0LMf7KRKutqq38jaVwUe5XEA E/3E6tmcW3pfP+hf1HNGKg3hULHlr1l7pLRlBUrpRifIB+HS/948fe+0G0uVCajaEI 5ZG/yIqw6tr4oIF9aZDl5Qy6q7LZ9egpUUyBjPd0QnhuMiWHqkAj9gURP6x9paZg8Z JS5hqZmSwBrBA== Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 035C36332B for ; Wed, 13 Jul 2022 10:43: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="j+SzsUAc"; dkim-atps=neutral Received: by mail-wr1-x42c.google.com with SMTP id v16so14439356wrd.13 for ; Wed, 13 Jul 2022 01:43:49 -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=TEGxL/naVQWQr6xucb2l/oPavSBpoOzBqH6+ELsxOok=; b=j+SzsUAcCBf5txDfkptZX1lcfIyqzZpFWNE8xooIov5+NSNLf/NZ1nlAPPU81ret8u wi8GLBtuNMGm3Z+zEWZ6wuTK8a0/JSktUS7eluXlH3oQqGohGJ89dBYR9GwTXV9kyNAC mxlGTpZ8pJhVndbU6EJ2tvpHZrm3xbMUHI6kjJdwrndZrEEjWDaefVOxSDBlBlGaiwso WerZdeAQErT/dy/vBRREceEybQgIBtU4b9+UZ4usue8T0glHqsQwl4tJ7SUPyaVTV7j5 aF168FNJ2fnn6QNGFbEsJYj8z1w0OrQWkLJ97aupQ2vh7KszaTrCVohOnEG46TgA2jvt P+DQ== 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=TEGxL/naVQWQr6xucb2l/oPavSBpoOzBqH6+ELsxOok=; b=HBCTrxKfhYwoG/Tq30gzk/a9x+EhIpd2McHLq9I1FS0uBN07dRAI01R5SSo6iqwFrc 6GOp31XwZYXLFXfyp7WK8Kh+98X7yiAAYfk81Y6IS+hksvPCtTmohgODXtohPyhvyyeG tfZR7h83dG8xyAF8YDtZ5/I2HmrQkvgSXi8Xm0++ZCn6QuVmJXsrmL2jkiOSVRL3vPCe frRsX7O7SnUogdbN3A1nKuxkc1jR+6CHYVKT5RKF01QRwt65IrPubhAWIRwLWy3KnGKf QIGCH2KlGQZ0l+ANrMuXJwFlFcs0pAAOazHwBNeHHhnG41SYoQBn6/Frz7MYxSIuRO1q V55Q== X-Gm-Message-State: AJIora+PuAkPCfhbJ6nVJM7yYoCMBO6MDPfYQ5vz/RSqwzR0cVjDfNk/ 1kB3VAnb5F0yJ5LE5W89IAikaRDBSUiJkA== X-Google-Smtp-Source: AGRyM1sXVokCw6nXi8XnVOHXewAKHrzTW+POJsPOPis6d+pRWu2r0rHfk5wviIW084OLqjW4ih2L3w== X-Received: by 2002:a5d:4344:0:b0:21d:578a:d8b7 with SMTP id u4-20020a5d4344000000b0021d578ad8b7mr2026751wrr.108.1657701828587; Wed, 13 Jul 2022 01:43:48 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id bg32-20020a05600c3ca000b003a04d19dab3sm5667468wmb.3.2022.07.13.01.43.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 01:43:48 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Jul 2022 10:43:16 +0200 Message-Id: <20220713084317.24268-11-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713084317.24268-1-dse@thaumatec.com> References: <20220713084317.24268-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 10/11] ipa: rkisp1: af: Skip few frames after changing lens position 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" With 30fps stream, lens movement takes more time than one frame. Skip few frames to allow lens to stabilize before calculating next contrast value. Signed-off-by: Daniel Semkowicz --- src/ipa/rkisp1/algorithms/af.cpp | 5 ++++- src/ipa/rkisp1/algorithms/af.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ipa/rkisp1/algorithms/af.cpp b/src/ipa/rkisp1/algorithms/af.cpp index cd4f0e08..a0d914e0 100644 --- a/src/ipa/rkisp1/algorithms/af.cpp +++ b/src/ipa/rkisp1/algorithms/af.cpp @@ -86,7 +86,10 @@ void Af::process(IPAContext &context, uint32_t lensPosition = processAutofocus(sharpness); - context.frameContext.af.focus = lensPosition; + if (lensPosition != context.frameContext.af.focus) { + context.frameContext.af.focus = lensPosition; + setFramesToSkip(kFLensWaitFrames); + } } void Af::setMetering(controls::AfMeteringEnum metering) diff --git a/src/ipa/rkisp1/algorithms/af.h b/src/ipa/rkisp1/algorithms/af.h index eeb806c0..36d0c9b0 100644 --- a/src/ipa/rkisp1/algorithms/af.h +++ b/src/ipa/rkisp1/algorithms/af.h @@ -36,6 +36,8 @@ private: Rectangle defaultWindow_; Rectangle userWindow_; bool updateAfwindow_ = false; + + static constexpr uint32_t kFLensWaitFrames = 2; }; } /* namespace libcamera::ipa::rkisp1::algorithms */ From patchwork Wed Jul 13 08:43:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16609 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 19948BE173 for ; Wed, 13 Jul 2022 08:43:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CA3436332B; Wed, 13 Jul 2022 10:43:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657701832; bh=fCrgdVHmSEufnXYcQdlMT2beO53VjtE+VMlao3J77LU=; 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=UEumBT40URmKujjTk4dg9ymaBXXIsdvnX2/J3awqaBv9lqV2AoEAvKNnsb0fQQNgv llNAEGYom1jnkOYcaEVzyO0aXIj5T5NDpr+cEmAItcm4Y0FWl3bQHrCzcCPxyK9Vp/ 6tzYynueEmGC8VL0aQGm5Hr4K4/BKN11GEPcz+IIkW1Nn3J0hbU/ji8c3p9VMOkSIx +vq3tpc54ZcufDdawJTCVPiYbqagTsfRznFfJ6mAZJgRMQ+ejeWkcN0Dc7fbIWtu8I /QsB9ttcWTIVdT9QiONpKn/DQ54DHsN1lwPkST5ZUUnHJQAMSS6IBnwL1GLK4CK3me 4gIUsO/PUIesw== Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0D1016332E for ; Wed, 13 Jul 2022 10:43: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="ww7JBy5e"; dkim-atps=neutral Received: by mail-wr1-x42a.google.com with SMTP id bu1so13291701wrb.9 for ; Wed, 13 Jul 2022 01:43:50 -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=d8/XWnx8OcFXS7ZpNMum4EPOd2lP94RlC727NCfsgp4=; b=ww7JBy5eKajwK1Wy+lPJ0/gdc5YpNsDcmYpQsiZYn5Llhco+sbEjRGkvb/x/SN4Zek IwZBq9jYkjmhoeyM8sVR4Jbo9dhi5TOqZF1/uR1v26dQT7yPnXj3mLRDcZ6B0Wk30RBd 1xnbLQTGzD4qAlzccwZim/L+SZ6R4Ck9QacILU1XZhIWROFBYWFnylKQsolwxydJYGCc jhwTj+cOV8TevydQ/cmEWfMPGbtqwd0WdGavqoaUsT2BHdYZQZ3mVXkpPol5liyqjlil uOdGenkhKM1m2QzGqWOA2fczwqrfOMeFnNuJ50bkS6jihwW38bqj9ygk1GfAX775EFa+ FqjA== 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=d8/XWnx8OcFXS7ZpNMum4EPOd2lP94RlC727NCfsgp4=; b=Y48LibCk3c5ipYv8O8cxB6/1H0sRppupBeELLYmVSfCryMM/A891Pw4kpvB5kyaYe4 jE8O06G2WOi5ZofkdXXpWp5OVKPeIpHXne3l9DZkMocwfX6nXZWz4JdFe4VsJ7xL1jxk mkCNKBOkOPpNdDBDcvKi1a1Oo+qdotuA1D8xZ6u309J8nvQ+u0mAJX8Y3KD+mPoae9zC f9JU/n7kbvrGDJa+f4zQwHvhu2XKRoK1imt9MVXC9bftF0h3HNiC+BqMWhQTlTKRylmA vlPvCel6yaa800PlBQYqd9Q9qX6CnUxP/dFb4y6fgU26U6tpjLJFvEY2FjRFWgYC3KkJ nguA== X-Gm-Message-State: AJIora9rnlKbY+hgt8nsnBozWBYBVb8WzNhbRYPI2y9Yfovx2yt9YFSp J57RqR45JLiP6c2cp8C6NUbZk5dFgYQW+w== X-Google-Smtp-Source: AGRyM1scGxjVmZsLnv8qklmd5IGXQKpPwJR5krhV+XX8yCXKHUHvXlpmNPB4qxbkmoqPmHMLhk6QGw== X-Received: by 2002:a5d:67c4:0:b0:21d:6d91:7b1a with SMTP id n4-20020a5d67c4000000b0021d6d917b1amr2060515wrw.313.1657701829882; Wed, 13 Jul 2022 01:43:49 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id bg32-20020a05600c3ca000b003a04d19dab3sm5667468wmb.3.2022.07.13.01.43.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 01:43:49 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Jul 2022 10:43:17 +0200 Message-Id: <20220713084317.24268-12-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713084317.24268-1-dse@thaumatec.com> References: <20220713084317.24268-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 11/11] ipa: rkisp1: af: Skip one frame after changing the AF window 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" Drop the first frame after the window change was requested to guarantee that sharpness level was calculated for the new window. Signed-off-by: Daniel Semkowicz --- src/ipa/rkisp1/algorithms/af.cpp | 1 + src/ipa/rkisp1/algorithms/af.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/ipa/rkisp1/algorithms/af.cpp b/src/ipa/rkisp1/algorithms/af.cpp index a0d914e0..e2769e69 100644 --- a/src/ipa/rkisp1/algorithms/af.cpp +++ b/src/ipa/rkisp1/algorithms/af.cpp @@ -128,6 +128,7 @@ void Af::updateCurrentWindow(const Rectangle &window) { currentWindow_ = window; updateAfwindow_ = true; + setFramesToSkip(kWindowWaitFrames); } REGISTER_IPA_ALGORITHM(Af, "Af") diff --git a/src/ipa/rkisp1/algorithms/af.h b/src/ipa/rkisp1/algorithms/af.h index 36d0c9b0..b2da4890 100644 --- a/src/ipa/rkisp1/algorithms/af.h +++ b/src/ipa/rkisp1/algorithms/af.h @@ -38,6 +38,7 @@ private: bool updateAfwindow_ = false; static constexpr uint32_t kFLensWaitFrames = 2; + static constexpr uint32_t kWindowWaitFrames = 1; }; } /* namespace libcamera::ipa::rkisp1::algorithms */