From patchwork Fri Feb 19 17:22:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Michel Hautbois X-Patchwork-Id: 11346 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 8D7C9BD1F6 for ; Fri, 19 Feb 2021 17:22:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5BDA4689E2; Fri, 19 Feb 2021 18:22:29 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Vuc7rExO"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4976C689DC for ; Fri, 19 Feb 2021 18:22:27 +0100 (CET) Received: from localhost.localdomain (unknown [IPv6:2a01:e0a:169:7140:e9be:2a73:b117:75b1]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A82FA879; Fri, 19 Feb 2021 18:22:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1613755345; bh=smpJF0r+ABg5KBioHkwRWdRiJSeSxoS98FvuUwR+lBQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vuc7rExOdWMUkjGRE8O56B/bnyLO+ITjGHPNdJFNvyeUCylUWjnwzLAqTogZ1bAPO a60uVCkQfaXeWuq2Fzqu8/xkddp1weWYLvx8uROjcJ3zVigisZ8TAsm8pZ12opULBO yDqQQHhlr4CcTOaRuGqZx5+netPQCpH3QpT9Z0wc= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Fri, 19 Feb 2021 18:22:23 +0100 Message-Id: <20210219172224.69862-2-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210219172224.69862-1-jeanmichel.hautbois@ideasonboard.com> References: <20210219172224.69862-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 1/2] WIP: ipa: Add Controller and Algorithm skeleton 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In order to instanciate and control IPA algorithms (AWB, AGC, etc.) there is a need for an IPA algorithm class to define mandatory methods, and an IPA controller class to operate algorithms together. Instead of reinventing the wheel, reuse what Raspberry Pi has done and adapt to the minimum requirements expected. Signed-off-by: Jean-Michel Hautbois --- include/libcamera/ipa/agc_algorithm.h | 32 ++++++++++++++++++ include/libcamera/ipa/awb_algorithm.h | 27 +++++++++++++++ include/libcamera/ipa/ipa_algorithm.h | 46 ++++++++++++++++++++++++++ include/libcamera/ipa/ipa_controller.h | 39 ++++++++++++++++++++++ include/libcamera/ipa/meson.build | 4 +++ src/ipa/libipa/ipa_algorithm.cpp | 20 +++++++++++ src/ipa/libipa/ipa_controller.cpp | 45 +++++++++++++++++++++++++ src/ipa/libipa/meson.build | 2 ++ 8 files changed, 215 insertions(+) create mode 100644 include/libcamera/ipa/agc_algorithm.h create mode 100644 include/libcamera/ipa/awb_algorithm.h create mode 100644 include/libcamera/ipa/ipa_algorithm.h create mode 100644 include/libcamera/ipa/ipa_controller.h create mode 100644 src/ipa/libipa/ipa_algorithm.cpp create mode 100644 src/ipa/libipa/ipa_controller.cpp diff --git a/include/libcamera/ipa/agc_algorithm.h b/include/libcamera/ipa/agc_algorithm.h new file mode 100644 index 00000000..4dd17103 --- /dev/null +++ b/include/libcamera/ipa/agc_algorithm.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * agc_algorithm.h - AGC/AEC control algorithm interface + */ +#ifndef __LIBCAMERA_AGC_ALGORITHM_H__ +#define __LIBCAMERA_AGC_ALGORITHM_H__ + +#include + +namespace libcamera { + +class AgcAlgorithm : public IPAAlgorithm +{ +public: + AgcAlgorithm(IPAController *controller) + : IPAAlgorithm(controller) {} + /* An AGC algorithm must provide the following: */ + virtual unsigned int GetConvergenceFrames() const = 0; + virtual void SetEv(double ev) = 0; + virtual void SetFlickerPeriod(double flicker_period) = 0; + virtual void SetFixedShutter(double fixed_shutter) = 0; // microseconds + virtual void SetMaxShutter(double max_shutter) = 0; // microseconds + virtual void SetFixedAnalogueGain(double fixed_analogue_gain) = 0; + virtual void SetMeteringMode(std::string const &metering_mode_name) = 0; + virtual void SetExposureMode(std::string const &exposure_mode_name) = 0; +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_AGC_ALGORITHM_H__ */ diff --git a/include/libcamera/ipa/awb_algorithm.h b/include/libcamera/ipa/awb_algorithm.h new file mode 100644 index 00000000..37464d12 --- /dev/null +++ b/include/libcamera/ipa/awb_algorithm.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * awb_algorithm.h - AWB control algorithm interface + */ +#ifndef __LIBCAMERA_AWB_ALGORITHM_H__ +#define __LIBCAMERA_AWB_ALGORITHM_H__ + +#include + +namespace libcamera { + +class AwbAlgorithm : public IPAAlgorithm +{ +public: + AwbAlgorithm(IPAController *controller) + : IPAAlgorithm(controller) {} + /* An AWB algorithm must provide the following: */ + virtual unsigned int GetConvergenceFrames() const = 0; + virtual void SetMode(std::string const &mode_name) = 0; + virtual void SetManualGains(double manual_r, double manual_b) = 0; +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_AWB_ALGORITHM_H__ */ diff --git a/include/libcamera/ipa/ipa_algorithm.h b/include/libcamera/ipa/ipa_algorithm.h new file mode 100644 index 00000000..e48b99a6 --- /dev/null +++ b/include/libcamera/ipa/ipa_algorithm.h @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * ipa_algorithm.h - ISP control algorithm interface + */ +#ifndef __LIBCAMERA_IPA_ALGORITHM_H__ +#define __LIBCAMERA_IPA_ALGORITHM_H__ + +/* All algorithms should be derived from this class and made available to the + * Controller. */ + +#include +#include +#include + +#include "ipa_controller.h" + +namespace libcamera { + +/* This defines the basic interface for all control algorithms. */ + +class IPAAlgorithm +{ +public: + IPAAlgorithm(IPAController *controller) + : controller_(controller), paused_(false) + { + } + virtual ~IPAAlgorithm() = default; + virtual char const *Name() const = 0; + virtual bool IsPaused() const { return paused_; } + virtual void Pause() { paused_ = true; } + virtual void Resume() { paused_ = false; } + virtual void Initialise(); + virtual void Prepare(); + virtual void Process(); + +private: + [[maybe_unused]] IPAController *controller_; + bool paused_; +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_IPA_ALGORITHM_H__ */ diff --git a/include/libcamera/ipa/ipa_controller.h b/include/libcamera/ipa/ipa_controller.h new file mode 100644 index 00000000..953cad4a --- /dev/null +++ b/include/libcamera/ipa/ipa_controller.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * ipa_controller.h - ISP controller interface + */ +#ifndef __LIBCAMERA_IPA_CONTROLLER_H__ +#define __LIBCAMERA_IPA_CONTROLLER_H__ + +// The Controller is simply a container for a collecting together a number of +// "control algorithms" (such as AWB etc.) and for running them all in a +// convenient manner. + +#include +#include + +namespace libcamera { + +class IPAAlgorithm; +typedef std::unique_ptr IPAAlgorithmPtr; + +class IPAController +{ +public: + IPAController(); + ~IPAController(); + IPAAlgorithm *CreateAlgorithm(char const *name); + void Initialise(); + void Prepare(); + void Process(); + IPAAlgorithm *GetAlgorithm(std::string const &name) const; + +protected: + std::vector algorithms_; +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_IPA_CONTROLLER_H__ */ diff --git a/include/libcamera/ipa/meson.build b/include/libcamera/ipa/meson.build index a4d3f868..e56d8b00 100644 --- a/include/libcamera/ipa/meson.build +++ b/include/libcamera/ipa/meson.build @@ -1,6 +1,10 @@ # SPDX-License-Identifier: CC0-1.0 libcamera_ipa_headers = files([ + 'agc_algorithm.h', + 'awb_algorithm.h', + 'ipa_algorithm.h', + 'ipa_controller.h', 'ipa_controls.h', 'ipa_interface.h', 'ipa_module_info.h', diff --git a/src/ipa/libipa/ipa_algorithm.cpp b/src/ipa/libipa/ipa_algorithm.cpp new file mode 100644 index 00000000..16fb29ce --- /dev/null +++ b/src/ipa/libipa/ipa_algorithm.cpp @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * ipa_algorithm.cpp - ISP control algorithms + */ +#include + +#include + +using namespace libcamera; + +void IPAAlgorithm::Initialise() +{ + std::cout << "Entering: " << __func__ << std::endl; +} + +void IPAAlgorithm::Prepare() {} + +void IPAAlgorithm::Process() {} diff --git a/src/ipa/libipa/ipa_controller.cpp b/src/ipa/libipa/ipa_controller.cpp new file mode 100644 index 00000000..e2cde8ce --- /dev/null +++ b/src/ipa/libipa/ipa_controller.cpp @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * ipa_controller.cpp - ISP controller + */ + +#include "libcamera/internal/log.h" + +#include +#include + +using namespace libcamera; + +LOG_DEFINE_CATEGORY(IPAController) + +IPAController::IPAController() {} + +IPAController::~IPAController() {} + +IPAAlgorithm *IPAController::CreateAlgorithm(char const *name) +{ + LOG(IPAController, Error) << "Create algorithm " << name; + return nullptr; +} + +void IPAController::Initialise() +{ + for (auto &algo : algorithms_) + algo->Initialise(); +} + +void IPAController::Prepare() +{ + for (auto &algo : algorithms_) + if (!algo->IsPaused()) + algo->Prepare(); +} + +void IPAController::Process() +{ + for (auto &algo : algorithms_) + if (!algo->IsPaused()) + algo->Process(); +} diff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build index b29ef0f4..1693e489 100644 --- a/src/ipa/libipa/meson.build +++ b/src/ipa/libipa/meson.build @@ -4,6 +4,8 @@ libipa_headers = files([ ]) libipa_sources = files([ + 'ipa_algorithm.cpp', + 'ipa_controller.cpp', ]) libipa_includes = include_directories('..')