From patchwork Mon Jun 20 01:42:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16271 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 82CE4BE173 for ; Mon, 20 Jun 2022 01:43:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 906CC65643; Mon, 20 Jun 2022 03:43:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655689408; bh=Vd+XJWO6S5AqcMr1huCj18B9BE1RIuOG/mFoRE3RFXE=; 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=jrN4UROenJrMc8Yk1Kp7AEXmAC7mmnXZidF44yQ8BHUgdPav7PzoZxY6l7GoQV4zP B2EZHsq5k2N81q/l/Uv+sEUkn4pIOT1gjzndiAKTyJ2tT1NWdw6idUfpCIkV/EZSOB BNXqSZu9BccJUwMu363S+zhMoia1ndoKG+BA13VWN+v5WrKM9l94jCVBzukw8oGzVr TKukD3DyRIfQRkHNxh20yohSybMxNRZ0y6HKo9CReQswDLTXd7jgsfcyYdPk9mYn9G 2KH7h/qUfLkY4JPINyh8f2Sl1VkWAhBX/gKLswXafQ6jPeaW/MzfTU8IQgXAgL9LY3 iUaMYcHV7OhWQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 771ED601F1 for ; Mon, 20 Jun 2022 03:43:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="CTh1xJc3"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D31D4883; Mon, 20 Jun 2022 03:43:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655689405; bh=Vd+XJWO6S5AqcMr1huCj18B9BE1RIuOG/mFoRE3RFXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CTh1xJc3MlmTiuRP6JyJk/KZW/YgDx5mxCdfryUfDa4CCbKyAKV+5Zc3/BqRWhjC2 set2OfjXS6GUyOzFvUyUckNsh4TvzRmf6Faqx6FL2fCnN5Ahn2acqCsW4uFsn5VSqW KxKX3enzYTrpIRCh/80WUjdd4LnM4vLaINYfvfRo= To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jun 2022 04:42:54 +0300 Message-Id: <20220620014305.26778-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> References: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 01/12] ipa: libipa: Introduce a Module class template 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" libipa defines an abstract Algorithm class template that is specialized by IPA modules. IPA modules then instantiate and manage algorithms internally, without help from libipa. With ongoing work on tuning data support for the RkISP1, and future similar work for the IPU3, more code duplication for algorithms management is expected. To address this and share code between multiple IPA modules, introduce a new Module class template that will define and manage top-level concepts for the IPA module. The Module class template needs to be specialized with the same types as the Algorithm class. To avoid manual specialization of both classes, store the types in the Module class, and replace the template arguments of the Algorithm class with a single Module argument from which the other types are retrieved. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder --- src/ipa/ipu3/algorithms/algorithm.h | 8 +-- src/ipa/ipu3/module.h | 27 ++++++++++ src/ipa/libipa/algorithm.cpp | 17 ++++--- src/ipa/libipa/algorithm.h | 17 +++---- src/ipa/libipa/meson.build | 5 +- src/ipa/libipa/module.cpp | 73 +++++++++++++++++++++++++++ src/ipa/libipa/module.h | 30 +++++++++++ src/ipa/rkisp1/algorithms/algorithm.h | 10 +--- src/ipa/rkisp1/module.h | 27 ++++++++++ 9 files changed, 183 insertions(+), 31 deletions(-) create mode 100644 src/ipa/ipu3/module.h create mode 100644 src/ipa/libipa/module.cpp create mode 100644 src/ipa/libipa/module.h create mode 100644 src/ipa/rkisp1/module.h diff --git a/src/ipa/ipu3/algorithms/algorithm.h b/src/ipa/ipu3/algorithms/algorithm.h index 234b2bd77f72..ae134a9404fe 100644 --- a/src/ipa/ipu3/algorithms/algorithm.h +++ b/src/ipa/ipu3/algorithms/algorithm.h @@ -7,19 +7,15 @@ #pragma once -#include - #include -#include "ipa_context.h" +#include "module.h" namespace libcamera { namespace ipa::ipu3 { -using Algorithm = libcamera::ipa::Algorithm; +using Algorithm = libcamera::ipa::Algorithm; } /* namespace ipa::ipu3 */ diff --git a/src/ipa/ipu3/module.h b/src/ipa/ipu3/module.h new file mode 100644 index 000000000000..d94fc4594871 --- /dev/null +++ b/src/ipa/ipu3/module.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Ideas On Board + * + * module.h - IPU3 IPA Module + */ + +#pragma once + +#include + +#include + +#include + +#include "ipa_context.h" + +namespace libcamera { + +namespace ipa::ipu3 { + +using Module = ipa::Module; + +} /* namespace ipa::ipu3 */ + +} /* namespace libcamera*/ diff --git a/src/ipa/libipa/algorithm.cpp b/src/ipa/libipa/algorithm.cpp index cce2ed62986d..2df91e5d8fed 100644 --- a/src/ipa/libipa/algorithm.cpp +++ b/src/ipa/libipa/algorithm.cpp @@ -19,14 +19,17 @@ namespace ipa { /** * \class Algorithm * \brief The base class for all IPA algorithms - * \tparam Context The type of shared IPA context - * \tparam Config The type of the IPA configuration data - * \tparam Params The type of the ISP specific parameters - * \tparam Stats The type of the IPA statistics and ISP results + * \tparam Module The IPA module type for this class of algorithms * - * The Algorithm class defines a standard interface for IPA algorithms. By - * abstracting algorithms, it makes possible the implementation of generic code - * to manage algorithms regardless of their specific type. + * The Algorithm class defines a standard interface for IPA algorithms + * compatible with the \a Module. By abstracting algorithms, it makes possible + * the implementation of generic code to manage algorithms regardless of their + * specific type. + * + * To specialize the Algorithm class template, an IPA module shall specialize + * the Module class template with module-specific context and configuration + * types, and pass the specialized Module class as the \a Module template + * argument. */ /** diff --git a/src/ipa/libipa/algorithm.h b/src/ipa/libipa/algorithm.h index 032a05b56635..fd2ffcfbc900 100644 --- a/src/ipa/libipa/algorithm.h +++ b/src/ipa/libipa/algorithm.h @@ -10,27 +10,26 @@ namespace libcamera { namespace ipa { -template +template class Algorithm { public: virtual ~Algorithm() {} - virtual int configure([[maybe_unused]] Context &context, - [[maybe_unused]] const Config &configInfo) + virtual int configure([[maybe_unused]] typename Module::Context &context, + [[maybe_unused]] const typename Module::Config &configInfo) { return 0; } - virtual void prepare([[maybe_unused]] Context &context, - [[maybe_unused]] Params *params) + virtual void prepare([[maybe_unused]] typename Module::Context &context, + [[maybe_unused]] typename Module::Params *params) { } - virtual void process([[maybe_unused]] Context &context, - [[maybe_unused]] FrameContext *frameContext, - [[maybe_unused]] const Stats *stats) + virtual void process([[maybe_unused]] typename Module::Context &context, + [[maybe_unused]] typename Module::FrameContext *frameContext, + [[maybe_unused]] const typename Module::Stats *stats) { } }; diff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build index 161cc5a1f0d0..465cf7d6c4a7 100644 --- a/src/ipa/libipa/meson.build +++ b/src/ipa/libipa/meson.build @@ -3,13 +3,16 @@ libipa_headers = files([ 'algorithm.h', 'camera_sensor_helper.h', - 'histogram.h' + 'histogram.h', + 'module.h', ]) libipa_sources = files([ + 'algorithm.cpp', 'camera_sensor_helper.cpp', 'histogram.cpp', 'libipa.cpp', + 'module.cpp', ]) libipa_includes = include_directories('..') diff --git a/src/ipa/libipa/module.cpp b/src/ipa/libipa/module.cpp new file mode 100644 index 000000000000..5a6f49a80e6d --- /dev/null +++ b/src/ipa/libipa/module.cpp @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Ideas On Board + * + * module.cpp - IPA Module + */ + +#include "module.h" + +/** + * \file module.h + * \brief IPA Module common interface + */ + +namespace libcamera { + +namespace ipa { + +/** + * \class Module + * \brief The base class for all IPA modules + * \tparam Context The type of the shared IPA context + * \tparam FrameContext The type of the frame context + * \tparam Config The type of the IPA configuration data + * \tparam Params The type of the ISP specific parameters + * \tparam Stats The type of the IPA statistics and ISP results + * + * The Module class template defines a standard internal interface between IPA + * modules and libipa. + * + * While IPA modules are platform-specific, many of their internal functions are + * conceptually similar, even if they take different types of platform-specifc + * parameters. For instance, IPA modules could share code that instantiates, + * initializes and run algorithms if it wasn't for the fact that the the format + * of ISP parameters or statistics passed to the related functions is + * device-dependent. + * + * To enable a shared implementation of those common tasks in libipa, the Module + * class template defines a standard internal interface between IPA modules and + * libipa. The template parameters specify the types of module-dependent data. + * IPA modules shall create a specialization of the Module class template in + * their namespace, and use it to specialize other classes of libipa, such as + * the Algorithm class. + */ + +/** + * \typedef Module::Context + * \brief The type of the shared IPA context + */ + +/** + * \typedef Module::FrameContext + * \brief The type of the frame context + */ + +/** + * \typedef Module::Config + * \brief The type of the IPA configuration data + */ + +/** + * \typedef Module::Params + * \brief The type of the ISP specific parameters + */ + +/** + * \typedef Module::Stats + * \brief The type of the IPA statistics and ISP results + */ + +} /* namespace ipa */ + +} /* namespace libcamera */ diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h new file mode 100644 index 000000000000..c4d778120408 --- /dev/null +++ b/src/ipa/libipa/module.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Ideas On Board + * + * module.h - IPA module + */ + +#pragma once + +namespace libcamera { + +namespace ipa { + +template +class Module +{ +public: + using Context = _Context; + using FrameContext = _FrameContext; + using Config = _Config; + using Params = _Params; + using Stats = _Stats; + + virtual ~Module() {} +}; + +} /* namespace ipa */ + +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/algorithm.h b/src/ipa/rkisp1/algorithms/algorithm.h index 68e3a44e19b4..c3212cff76fe 100644 --- a/src/ipa/rkisp1/algorithms/algorithm.h +++ b/src/ipa/rkisp1/algorithms/algorithm.h @@ -7,21 +7,15 @@ #pragma once -#include - -#include - #include -#include "ipa_context.h" +#include "module.h" namespace libcamera { namespace ipa::rkisp1 { -using Algorithm = libcamera::ipa::Algorithm; +using Algorithm = libcamera::ipa::Algorithm; } /* namespace ipa::rkisp1 */ diff --git a/src/ipa/rkisp1/module.h b/src/ipa/rkisp1/module.h new file mode 100644 index 000000000000..89f83208a75c --- /dev/null +++ b/src/ipa/rkisp1/module.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Ideas On Board + * + * module.h - RkISP1 IPA Module + */ + +#pragma once + +#include + +#include + +#include + +#include "ipa_context.h" + +namespace libcamera { + +namespace ipa::rkisp1 { + +using Module = ipa::Module; + +} /* namespace ipa::rkisp1 */ + +} /* namespace libcamera*/ From patchwork Mon Jun 20 01:42:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16272 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 A04B0BE173 for ; Mon, 20 Jun 2022 01:43:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4E88C65648; Mon, 20 Jun 2022 03:43:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655689409; bh=oCOhFtxVSryoQnb8LtgrbwXQVOLE/FSIDXX+AGuIDP4=; 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=jlwxklg5eKBi0+fDE8dVDmlNEkF2GzKM6xCVYk4D5PtKHwHcygMfsrfh4GwwuMtE6 iFDXwc836ELh6qYQbpgdL8W8142h0cSACIm/83Hzp/L+4ZzdQ52To6trIxs2j+JQyx umcIGRPrALE/GU4vdqNeUe8RtoEN1ttSV4VW8xEwhOczYXMhqeyTsZVXtLtEiZGLe7 mTG597c06KwCHOB/93WG9kTkpphKOzw7HII0yg3H90ZrfsV+eksErXHdUBqJqz5dSb DH5A8n+3NaSiah26rJh4Z0t4+XXMCvf2YFN/inzs84yItgCuunsrSxcmnnsBFPTrQR 0gIsMsif5e6qA== 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 D4A9F601F1 for ; Mon, 20 Jun 2022 03:43:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Dfjrqor4"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5A27B892; Mon, 20 Jun 2022 03:43:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655689405; bh=oCOhFtxVSryoQnb8LtgrbwXQVOLE/FSIDXX+AGuIDP4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dfjrqor4bwgLvytWEkHMk138RPeJ0xHankh9ny+DPL3p29ZzF8OIMudfhLrYdD4jk MAByyJ15P07I4Gdi8F4UXgVCQIHEsKhqK5ixh0OcEvowoV3U0McM4eRKt8cXbpcgAT AsF4JBwEOCZgSLmlFZOBd2+M0kUQS8CiAHcSKNLY= To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jun 2022 04:42:55 +0300 Message-Id: <20220620014305.26778-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> References: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 02/12] ipa: libipa: Move ipa namespace documentation to module.cpp 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The libipa.cpp file exists for the sole purpose of documentating the ipa namespace. As we now have a top-level module.cpp file in libipa, move the documentation there, and drop libipa.cpp. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder --- src/ipa/libipa/libipa.cpp | 22 ---------------------- src/ipa/libipa/meson.build | 1 - src/ipa/libipa/module.cpp | 7 +++++++ 3 files changed, 7 insertions(+), 23 deletions(-) delete mode 100644 src/ipa/libipa/libipa.cpp diff --git a/src/ipa/libipa/libipa.cpp b/src/ipa/libipa/libipa.cpp deleted file mode 100644 index 08bc3541f4eb..000000000000 --- a/src/ipa/libipa/libipa.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2021, Ideas On Board - * - * libipa.cpp - libipa interface - */ - -namespace libcamera { - -/** - * \brief The IPA namespace - * - * The IPA namespace groups all types specific to IPA modules. It serves as the - * top-level namespace for the IPA library libipa, and also contains - * module-specific namespaces for IPA modules. - */ -namespace ipa { - -} /* namespace ipa */ - -} /* namespace libcamera */ - diff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build index 465cf7d6c4a7..fb894bc614af 100644 --- a/src/ipa/libipa/meson.build +++ b/src/ipa/libipa/meson.build @@ -11,7 +11,6 @@ libipa_sources = files([ 'algorithm.cpp', 'camera_sensor_helper.cpp', 'histogram.cpp', - 'libipa.cpp', 'module.cpp', ]) diff --git a/src/ipa/libipa/module.cpp b/src/ipa/libipa/module.cpp index 5a6f49a80e6d..d03cc8ef03ed 100644 --- a/src/ipa/libipa/module.cpp +++ b/src/ipa/libipa/module.cpp @@ -14,6 +14,13 @@ namespace libcamera { +/** + * \brief The IPA namespace + * + * The IPA namespace groups all types specific to IPA modules. It serves as the + * top-level namespace for the IPA library libipa, and also contains + * module-specific namespaces for IPA modules. + */ namespace ipa { /** From patchwork Mon Jun 20 01:42:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16273 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 20B5ABE173 for ; Mon, 20 Jun 2022 01:43:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6A3D365641; Mon, 20 Jun 2022 03:43:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655689410; bh=rIw0/l9qlrC1FD0Xq8PBMm5KK4qQtlgKRmBJ8tSg8Eg=; 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=SzdwS8VN0b28sexQlTKqkquVGBmPA5o8vbBYMGojINeKufDZdl3bnBKQ4e7vzHl5X hjeg5z1/BTLnJj3a69GtJU/uubguD8C4g/5EvDbfl43ILxrnSqLJLrEH94rFQsHl0Q zHTxzwbo85BT11P4akV8ZcnIjID8rK4xnpHA9IQAEXYmH8nP8X/ypzIs7cAjQrL9xZ bs4DTxukLtuFfDK2mnqFDaI/wy/zU0v3aRSEgJZp7qeFjG/3vKeAhUGiCz09GMnmX0 nHQgMy8XSUFLP3UiwXCj3UcfS3MWHzElc78YxyH1VG7aTfSNPmKAIFq4MANJTjKWUt 6iyGVXi2hcKKg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 48309601F1 for ; Mon, 20 Jun 2022 03:43:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="q1hOo3VJ"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CE42425E; Mon, 20 Jun 2022 03:43:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655689406; bh=rIw0/l9qlrC1FD0Xq8PBMm5KK4qQtlgKRmBJ8tSg8Eg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q1hOo3VJzQWvpJ7PNKKGw1Kn5qw+CFPjfbHGRQGmES6cLBN0IkhbEjdz4h/JAxv1T 3BNX9gwxjfOOL7ffX48I8GRIlOt1ezUWu8kYgCcbGhL8tI3wQMStf43zOB7iF7seSE 0DxWnV9QsQiDo58NBU2GTgseyjmXZ4QF5hxSOs/U= To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jun 2022 04:42:56 +0300 Message-Id: <20220620014305.26778-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> References: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 03/12] ipa: libipa: algorithm: Add an algorithm registration mechanism 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In order to allow dynamic instantiation of algorithms based on tuning data files, add a mechanism to register algorithms with the IPA module. The implementation relies on an AlgorithmFactory class and a registration macro, similar to the pipeline handler registration mechanism. The main difference is that the algorithm registration and instantiation are implemented in the Module class instead of the AlgorithmFactory class, making the factory an internal implementation detail. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder --- src/ipa/libipa/algorithm.cpp | 54 ++++++++++++++++++++++++++++++++++++ src/ipa/libipa/algorithm.h | 41 ++++++++++++++++++++++++++- src/ipa/libipa/module.cpp | 24 ++++++++++++++++ src/ipa/libipa/module.h | 33 ++++++++++++++++++++++ 4 files changed, 151 insertions(+), 1 deletion(-) diff --git a/src/ipa/libipa/algorithm.cpp b/src/ipa/libipa/algorithm.cpp index 2df91e5d8fed..6e0bba56ecb2 100644 --- a/src/ipa/libipa/algorithm.cpp +++ b/src/ipa/libipa/algorithm.cpp @@ -32,6 +32,11 @@ namespace ipa { * argument. */ +/** + * \typedef Algorithm::Module + * \brief The IPA module type for this class of algorithms + */ + /** * \fn Algorithm::configure() * \brief Configure the Algorithm given an IPAConfigInfo @@ -94,6 +99,55 @@ namespace ipa { * such that the algorithms use up to date state as required. */ +/** + * \class AlgorithmFactory + * \brief Registration of Algorithm classes and creation of instances + * + * To facilitate instantiation of Algorithm classes, the AlgorithmFactory class + * implements auto-registration of algorithms with the IPA Module class. Each + * Algorithm subclass shall register itself using the REGISTER_IPA_ALGORITHM() + * macro, which will create a corresponding instance of an AlgorithmFactory + * subclass and register it with the IPA Module. + */ + +/** + * \fn AlgorithmFactory::AlgorithmFactory() + * \brief Construct an algorithm factory + * \param[in] name Name of the algorithm class + * + * Creating an instance of the factory automatically registers is with the IPA + * Module class, enabling creation of algorithm instances through + * Module::createAlgorithm(). + * + * The factory \a name identifies the algorithm and shall be unique. + */ + +/** + * \fn AlgorithmFactory::name() + * \brief Retrieve the factory name + * \return The factory name + */ + +/** + * \fn AlgorithmFactory::create() + * \brief Create an instance of the Algorithm corresponding to the factory + * + * This virtual function is implemented by the REGISTER_IPA_ALGORITHM() + * macro. It creates an algorithm instance. + * + * \return A pointer to a newly constructed instance of the Algorithm subclass + * corresponding to the factory + */ + +/** + * \def REGISTER_IPA_ALGORITHM + * \brief Register an algorithm with the IPA module + * \param[in] algorithm Class name of Algorithm derived class to register + * + * Register an Algorithm subclass with the IPA module to make it available for + * instantiation through Module::createAlgorithm(). + */ + } /* namespace ipa */ } /* namespace libcamera */ diff --git a/src/ipa/libipa/algorithm.h b/src/ipa/libipa/algorithm.h index fd2ffcfbc900..356c094976d4 100644 --- a/src/ipa/libipa/algorithm.h +++ b/src/ipa/libipa/algorithm.h @@ -6,14 +6,19 @@ */ #pragma once +#include +#include + namespace libcamera { namespace ipa { -template +template class Algorithm { public: + using Module = _Module; + virtual ~Algorithm() {} virtual int configure([[maybe_unused]] typename Module::Context &context, @@ -34,6 +39,40 @@ public: } }; +template +class AlgorithmFactory +{ +public: + AlgorithmFactory(const char *name) + : name_(name) + { + Module::registerAlgorithm(this); + } + + virtual ~AlgorithmFactory() = default; + + const std::string &name() const { return name_; } + + virtual std::unique_ptr> create() const = 0; + +private: + std::string name_; +}; + +#define REGISTER_IPA_ALGORITHM(algorithm) \ +class algorithm##Factory final : public AlgorithmFactory \ +{ \ +public: \ + algorithm##Factory() : AlgorithmFactory(#algorithm) {} \ + \ + std::unique_ptr> create() const \ + { \ + return std::make_unique(); \ + } \ +}; \ + \ +static algorithm##Factory global_##algorithm##Factory; + } /* namespace ipa */ } /* namespace libcamera */ diff --git a/src/ipa/libipa/module.cpp b/src/ipa/libipa/module.cpp index d03cc8ef03ed..451614fd04da 100644 --- a/src/ipa/libipa/module.cpp +++ b/src/ipa/libipa/module.cpp @@ -75,6 +75,30 @@ namespace ipa { * \brief The type of the IPA statistics and ISP results */ +/** + * \fn Module::createAlgorithm() + * \brief Create an instance of an Algorithm by name + * \param[in] name The algorithm name + * + * This function is the entry point to algorithm instantiation for the IPA + * module. It creates and returns an instance of an algorithm identified by its + * \a name. If no such algorithm exists, the function returns nullptr. + * + * To make an algorithm available to the IPA module, it shall be registered with + * the REGISTER_IPA_ALGORITHM() macro. + * + * \return A new instance of the Algorithm subclass corresponding to the \a name + */ + +/** + * \fn Module::registerAlgorithm() + * \brief Add an algorithm factory class to the list of available algorithms + * \param[in] factory Factory to use to construct the algorithm + * + * This function registers an algorithm factory. It is meant to be called by the + * AlgorithmFactory constructor only. + */ + } /* namespace ipa */ } /* namespace libcamera */ diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h index c4d778120408..f30fc33711bb 100644 --- a/src/ipa/libipa/module.h +++ b/src/ipa/libipa/module.h @@ -7,6 +7,12 @@ #pragma once +#include +#include +#include + +#include "algorithm.h" + namespace libcamera { namespace ipa { @@ -23,6 +29,33 @@ public: using Stats = _Stats; virtual ~Module() {} + + static std::unique_ptr> createAlgorithm(const std::string &name) + { + for (const AlgorithmFactory *factory : factories()) { + if (factory->name() == name) + return factory->create(); + } + + return nullptr; + } + + static void registerAlgorithm(AlgorithmFactory *factory) + { + factories().push_back(factory); + } + +private: + static std::vector *> &factories() + { + /* + * The static factories map is defined inside the function to ensure + * it gets initialized on first use, without any dependency on + * link order. + */ + static std::vector *> factories; + return factories; + } }; } /* namespace ipa */ From patchwork Mon Jun 20 01:42:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16274 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 4C427BE173 for ; Mon, 20 Jun 2022 01:43:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9349D65633; Mon, 20 Jun 2022 03:43:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655689412; bh=Xxl+STqEGupZEhYQYUvsvYDr2vDwbtwqtSyAbTNUD/U=; 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=vAcYR3HgPbQBudJozWnD4aC/dF09kkezX4AzCvGSELxqp+0GyANthN4lJXb9aYzDF spPAKLYbFud5fjjE36bDRoXkmXcFAJ53kbUNfacC+c4fNzGTih63SNy6xYolOaIEfS lcBM/cVjLN5cQFC09JfoF5cwssT2+/JxTpfOB4sAjvRcY60oGg3vZ+z8R5RHDjgr8q CjnYAwUOjxUMy1RFMJyHgfA7wqlxjS2NXdVmWlYrCjNhstIkBeV8VnF8z7SicLnhRs bcQGHIQQiab46QtXh2DtPg+Hdqke8EWOtWo0yWF3e+0/yuG193gNLbC7IcvQpTX5UM P98V9eQmVmXvQ== 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 DD9B865639 for ; Mon, 20 Jun 2022 03:43:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="FkMWohu1"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 520FD883; Mon, 20 Jun 2022 03:43:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655689406; bh=Xxl+STqEGupZEhYQYUvsvYDr2vDwbtwqtSyAbTNUD/U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FkMWohu1GQVxO1xKwH+kz7nGH23pOxKMzt46FP6JK1hXeLJ3VLK307O/JOAKHqpLV WPFpofBxDbIg3XwDhY58RVdNg1cn73ZBGO7ZO0Km189hXtrb2UYhYPB/TDxf4OFeWg Iv+biqjy3MV7VMfbu3i6ePvsXT/57CnK7EIMVnPE= To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jun 2022 04:42:57 +0300 Message-Id: <20220620014305.26778-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> References: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 04/12] ipa: libipa: algorithm: Add init() function to the Algorithm 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Florian Sylvestre Add the init() function that will be called during algorithm initialization to provide each algorithm the list of algorithms tuning data. Signed-off-by: Florian Sylvestre Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder Signed-off-by: Laurent Pinchart --- Changes since v3: - Hardcode YamlObject as the data type of tuning data - Reword the Algorithm::init() documentation - Pass the algorithm-specific data to the init() function instead of the global tuning data --- src/ipa/libipa/algorithm.cpp | 13 +++++++++++++ src/ipa/libipa/algorithm.h | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/src/ipa/libipa/algorithm.cpp b/src/ipa/libipa/algorithm.cpp index 6e0bba56ecb2..1b1fd80fb7b0 100644 --- a/src/ipa/libipa/algorithm.cpp +++ b/src/ipa/libipa/algorithm.cpp @@ -37,6 +37,19 @@ namespace ipa { * \brief The IPA module type for this class of algorithms */ +/** + * \fn Algorithm::init() + * \brief Initialize the Algorithm with tuning data + * \param[in] context The shared IPA context + * \param[in] tuningData The tuning data for the algorithm + * + * This function is called once, when the IPA module is initialized, to + * initialize the algorithm. The \a tuningData YamlObject contains the tuning + * data for algorithm. + * + * \return 0 if successful, an error code otherwise + */ + /** * \fn Algorithm::configure() * \brief Configure the Algorithm given an IPAConfigInfo diff --git a/src/ipa/libipa/algorithm.h b/src/ipa/libipa/algorithm.h index 356c094976d4..47cb3c01d2ce 100644 --- a/src/ipa/libipa/algorithm.h +++ b/src/ipa/libipa/algorithm.h @@ -11,6 +11,8 @@ namespace libcamera { +class YamlObject; + namespace ipa { template @@ -21,6 +23,12 @@ public: virtual ~Algorithm() {} + virtual int init([[maybe_unused]] typename Module::Context &context, + [[maybe_unused]] const YamlObject &tuningData) + { + return 0; + } + virtual int configure([[maybe_unused]] typename Module::Context &context, [[maybe_unused]] const typename Module::Config &configInfo) { From patchwork Mon Jun 20 01:42:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16275 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 2A215BE173 for ; Mon, 20 Jun 2022 01:43:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7B6776564D; Mon, 20 Jun 2022 03:43:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655689413; bh=iiTYs60suiRgZIa1iHO3GmUnotFsLAIBsnwonLylSjA=; 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=czDUGEv2lNsOQzyzpiMoqDjDgeC5vvX3o8QMYY7HMlkB4xZTv5dwJZ0Jcaw1OHAJm hb5QDgVx0RXeHrGQMJqJ8N8MyF1//78lbzMAdDzoSq4bT+MmoSOeyG6Paxu8LZ5BzW 2dyAbLzYTA1zGY9WF9fk/rT8tal9F5rQF6Qr4+Du3GOyaMXdvLceNbp3n8INTc7gvs 47Bo6bGt6k9UJ1S32yFx9munO7uvPHmJGe1Mfn38jG/ljtGwuU27/4OY7avVJGmIWF hwBPvRaTKv/eNv11NrBV7Rn3HcQwababUTN2QL6YnS7f0v7j6kVVIaXMfOE85wVs8H 3aJcxgWuCkdCQ== 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 4529E6563B for ; Mon, 20 Jun 2022 03:43:27 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="lB6NE2jw"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C530A25E; Mon, 20 Jun 2022 03:43:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655689407; bh=iiTYs60suiRgZIa1iHO3GmUnotFsLAIBsnwonLylSjA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lB6NE2jwKOgKqjigca1uug5aCUL2yFTHT9eWYqNRcf2A3yqaefY7K6or9kwi3zfjC LsViq6/8kbBuh1HNaJ7XYV026nZw9J+Fassfm7BTK9T+HZtKk0lykZKMAtXbDhWCM6 QuHJULMVoupO6LnClD4+dvXlkUqROvkgTpPHVFic= To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jun 2022 04:42:58 +0300 Message-Id: <20220620014305.26778-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> References: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 05/12] ipa: libipa: module: Add support for instantiation from YAML 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a Module::createAlgorithms() function to instantiate algorithms from a YamlObject. The instantiated algorithms are stored in a private member variable list, exposed through the Module::algorithms() function. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder --- src/ipa/libipa/module.cpp | 42 ++++++++++++++++------ src/ipa/libipa/module.h | 73 +++++++++++++++++++++++++++++++++++---- 2 files changed, 99 insertions(+), 16 deletions(-) diff --git a/src/ipa/libipa/module.cpp b/src/ipa/libipa/module.cpp index 451614fd04da..7735210444b6 100644 --- a/src/ipa/libipa/module.cpp +++ b/src/ipa/libipa/module.cpp @@ -14,6 +14,8 @@ namespace libcamera { +LOG_DEFINE_CATEGORY(IPAModuleAlgo) + /** * \brief The IPA namespace * @@ -76,7 +78,36 @@ namespace ipa { */ /** - * \fn Module::createAlgorithm() + * \fn Module::algorithms() + * \brief Retrieve the list of instantiated algorithms + * \return The list of instantiated algorithms + */ + +/** + * \fn Module::createAlgorithms() + * \brief Create algorithms from YAML configuration data + * \param[in] context The IPA context + * \param[in] algorithms Algorithms configuration data as a parsed YamlObject + * + * This function iterates over the list of \a algorithms parsed from the YAML + * configuration file, and instantiates and initializes the corresponding + * algorithms. The configuration data is expected to be correct, any error + * causes the function to fail and return immediately. + * + * \return 0 on success, or a negative error code on failure + */ + +/** + * \fn Module::registerAlgorithm() + * \brief Add an algorithm factory class to the list of available algorithms + * \param[in] factory Factory to use to construct the algorithm + * + * This function registers an algorithm factory. It is meant to be called by the + * AlgorithmFactory constructor only. + */ + +/** + * \fn Module::createAlgorithm(const std::string &name) * \brief Create an instance of an Algorithm by name * \param[in] name The algorithm name * @@ -90,15 +121,6 @@ namespace ipa { * \return A new instance of the Algorithm subclass corresponding to the \a name */ -/** - * \fn Module::registerAlgorithm() - * \brief Add an algorithm factory class to the list of available algorithms - * \param[in] factory Factory to use to construct the algorithm - * - * This function registers an algorithm factory. It is meant to be called by the - * AlgorithmFactory constructor only. - */ - } /* namespace ipa */ } /* namespace libcamera */ diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h index f30fc33711bb..00d5785e1aa0 100644 --- a/src/ipa/libipa/module.h +++ b/src/ipa/libipa/module.h @@ -7,14 +7,22 @@ #pragma once +#include #include #include #include +#include +#include + +#include "libcamera/internal/yaml_parser.h" + #include "algorithm.h" namespace libcamera { +LOG_DECLARE_CATEGORY(IPAModuleAlgo) + namespace ipa { template>> &algorithms() const + { + return algorithms_; + } + + int createAlgorithms(Context &context, const YamlObject &algorithms) + { + const auto &list = algorithms.asList(); + + for (const auto &[i, algo] : utils::enumerate(list)) { + if (!algo.isDictionary()) { + LOG(IPAModuleAlgo, Error) + << "Invalid YAML syntax for algorithm " << i; + algorithms_.clear(); + return -EINVAL; + } + + int ret = createAlgorithm(context, algo); + if (ret) { + algorithms_.clear(); + return ret; + } + } + + return 0; + } + + static void registerAlgorithm(AlgorithmFactory *factory) + { + factories().push_back(factory); + } + +private: + int createAlgorithm(Context &context, const YamlObject &data) + { + const auto &[name, algoData] = *data.asDict().begin(); + std::unique_ptr> algo = createAlgorithm(name); + if (!algo) { + LOG(IPAModuleAlgo, Error) + << "Algorithm '" << name << "' not found"; + return -EINVAL; + } + + int ret = algo->init(context, algoData); + if (ret) { + LOG(IPAModuleAlgo, Error) + << "Algorithm '" << name << "' failed to initialize"; + return ret; + } + + LOG(IPAModuleAlgo, Debug) + << "Instantiated algorithm '" << name << "'"; + + algorithms_.push_back(std::move(algo)); + return 0; + } + static std::unique_ptr> createAlgorithm(const std::string &name) { for (const AlgorithmFactory *factory : factories()) { @@ -40,12 +105,6 @@ public: return nullptr; } - static void registerAlgorithm(AlgorithmFactory *factory) - { - factories().push_back(factory); - } - -private: static std::vector *> &factories() { /* @@ -56,6 +115,8 @@ private: static std::vector *> factories; return factories; } + + std::list>> algorithms_; }; } /* namespace ipa */ From patchwork Mon Jun 20 01:42:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16276 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 D34A3BE173 for ; Mon, 20 Jun 2022 01:43:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2AAA96564E; Mon, 20 Jun 2022 03:43:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655689414; bh=Mw30lJmx6lnvS/qiZ70akxS3ydRLDhZuzOmTHoIqg7M=; 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=XW3solDbi1NibWaG7ECrjP34VjHcqnTJZFtJ+iTr2jbetF690fQPh0eDdGvn85xz4 eS/l3zaF9e56u7XppxO1FA6h0Nk/09zkKeg29wzMoWekEQUh2cFwnCRv1R6VsMCWdX 8YswiSg/yduTdaQXC2dMoDLtIO4da718pgYh5402rTJsMQWSTaF9fKu+m326pbuSil dMvhGH/xAgjL0Qblk6aiPOryqa6Qe4zY5o2JTwgMHlIgaAlzhY/vi/pPJVsCO6pYx+ DdLUPzQGdxPVC+dmRbB8cAls2zc/5sBbWxz8qMFIrk70EJHpxFXap4QPXvRW37fQ3W 99/qZ4KxqdpGw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CAF9B601F1 for ; Mon, 20 Jun 2022 03:43:27 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="J053lGhH"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 48A29883; Mon, 20 Jun 2022 03:43:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655689407; bh=Mw30lJmx6lnvS/qiZ70akxS3ydRLDhZuzOmTHoIqg7M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J053lGhHHzfQP7Yhi+kMBrU4N+D1fRGt0FB4eiM3XEx0ZRJd987/gCYIvy0pXJDGG 6rQGnLwbGZxw0I1LeBOMxcqyzM5LRXurN2Jjv70LkhL5XboqrEQENZ7N2hZIEvWIuM 6fy6WmO4HrAE3ncJXipr//0W6a8sK1ZlOVSMq6cM= To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jun 2022 04:42:59 +0300 Message-Id: <20220620014305.26778-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> References: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 06/12] ipa: libipa: module: Make the Module class Loggable 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" To help attribute messages logged by the Module class to a particular IPA module, make the class loggable and add a name argument to its constructor to specify the log prefix. Signed-off-by: Laurent Pinchart --- src/ipa/libipa/module.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h index 00d5785e1aa0..cd67912f1b0c 100644 --- a/src/ipa/libipa/module.h +++ b/src/ipa/libipa/module.h @@ -27,7 +27,7 @@ namespace ipa { template -class Module +class Module : public Loggable { public: using Context = _Context; From patchwork Mon Jun 20 01:43:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16277 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 3CEE7BE173 for ; Mon, 20 Jun 2022 01:43:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E7B4265659; Mon, 20 Jun 2022 03:43:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655689416; bh=UPriGi3kAiPOyjE60UQB1y3ZwvSU/cinXkjFxXoNTh4=; 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=efVL3AJMjPEIsmg9Om8lomKH0+oZdLXblLwQq9oTDhcmXXDhLcLFECGTtfY6p64en suXVrzKcpmUWpv6SayGcWEEpnVTPSe2/o3CBgLrZQu2UAu06aL1cpHxLuHL/g39S4h R+1RrUxCA+RHqONkvRNiGgG+TvptKtFeCgBb8UXaFAe4D0Hh8mOI6QYbWuR3nvB0dE f7gae2zLKWu1SvnaV5w6WJxFliNCK8eF9enFDPllAzR8P6QMyNeq1VQVQzB+RZvEdc DBxB+3Rjlut/pcmwxHebsPZ4MZonOZ8HbZY/EW3aYS1bVqacx8+v7jB29oYp6m4Se1 eGFEuABssxW/g== 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 422BF60471 for ; Mon, 20 Jun 2022 03:43:28 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="PlO6ATYv"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C517E25E; Mon, 20 Jun 2022 03:43:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655689408; bh=UPriGi3kAiPOyjE60UQB1y3ZwvSU/cinXkjFxXoNTh4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PlO6ATYvwvO8tNNKtjn8h3sFJTpIFr/eTy5jZhfbvq7Lvdb5tNhSdY450atIrKoVs vKmLTHcpB8zo6AdcWCLhFkGCh3hY+RTf0HIdXkg6381u/YXPPMTBFQ6UMvVm8Fmfhp W2RgUdkAS1JveUP1T7mEFWyxK8HF/f1I0iLC/LZU= To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jun 2022 04:43:00 +0300 Message-Id: <20220620014305.26778-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> References: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 07/12] pipeline: rkisp1: Support IPA 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Florian Sylvestre Pass the path name of the YAML IPA tuning file to the IPA module. The file name is derived from the sensor name ("${sensor_name}.yaml"), with a fallback to "uncalibrated.yaml". The tuning file name can be manually overridden with the LIBCAMERA_RKISP1_TUNING_FILE environment variable. Signed-off-by: Florian Sylvestre Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder Signed-off-by: Laurent Pinchart --- Changes since v3: - Fix typo in ipaTuningFile - Fall back to "uncalibrated.yaml" --- src/ipa/rkisp1/data/meson.build | 8 ++++++++ src/ipa/rkisp1/data/uncalibrated.yaml | 8 ++++++++ src/libcamera/pipeline/rkisp1/rkisp1.cpp | 20 +++++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/ipa/rkisp1/data/meson.build create mode 100644 src/ipa/rkisp1/data/uncalibrated.yaml diff --git a/src/ipa/rkisp1/data/meson.build b/src/ipa/rkisp1/data/meson.build new file mode 100644 index 000000000000..e5b945966625 --- /dev/null +++ b/src/ipa/rkisp1/data/meson.build @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: CC0-1.0 + +conf_files = files([ + 'uncalibrated.yaml', +]) + +install_data(conf_files, + install_dir : ipa_data_dir / 'rkisp1') diff --git a/src/ipa/rkisp1/data/uncalibrated.yaml b/src/ipa/rkisp1/data/uncalibrated.yaml new file mode 100644 index 000000000000..bdbd5fda7eaf --- /dev/null +++ b/src/ipa/rkisp1/data/uncalibrated.yaml @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: CC0-1.0 +%YAML 1.2 +--- +version: 1 +algorithms: + - Agc: + - Awb: +... diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 4b3d2cf77039..72689c8832eb 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -322,7 +322,25 @@ int RkISP1CameraData::loadIPA(unsigned int hwRevision) ipa_->paramsBufferReady.connect(this, &RkISP1CameraData::paramFilled); ipa_->metadataReady.connect(this, &RkISP1CameraData::metadataReady); - int ret = ipa_->init(IPASettings{ "", sensor_->model() }, hwRevision); + /* + * The API tuning file is made from the sensor name unless the + * environment variable overrides it. If + */ + std::string ipaTuningFile; + char const *configFromEnv = utils::secure_getenv("LIBCAMERA_RKISP1_TUNING_FILE"); + if (!configFromEnv || *configFromEnv == '\0') { + ipaTuningFile = ipa_->configurationFile(sensor_->model() + ".yaml"); + /* + * If the tuning file isn't found, fall back to the + * 'uncalibrated' configuration file. + */ + if (ipaTuningFile.empty()) + ipaTuningFile = ipa_->configurationFile("uncalibrated.yaml"); + } else { + ipaTuningFile = std::string(configFromEnv); + } + + int ret = ipa_->init({ ipaTuningFile, sensor_->model() }, hwRevision); if (ret < 0) { LOG(RkISP1, Error) << "IPA initialization failure"; return ret; From patchwork Mon Jun 20 01:43:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16278 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 F369DBE173 for ; Mon, 20 Jun 2022 01:43:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 977EF65647; Mon, 20 Jun 2022 03:43:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655689417; bh=M4w1H+jmyVZ2LSQfVgXAT+hHM17N/I3m3Jl9XgRhV38=; 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=aly7WXuYE2OngeqvM3tRHrfIak4y/X+KmVIfCOhTdHDbQ0KU38OH8901ECqD941dK +7X1MMIDTtkWsr9HrUgXaNPrcDAFPp/WFKmLFU62Ch6q/WZ8AhjokeYxznU8kNlyR8 Ed7J+zjOrzp4WaNeOJoPRSKtELDp6iCGBAHrc1QywpVB4mNAgNc9G1dxSdon8TEaN+ 6L50Ng+mKpauwtxUvYDxKGs1kD0NgImLSSZQDODcC+iyre4ma/7QKJ1hty+QPcAVML 1B2Gy8P/HZTGs5sT9qvSZ1bYPne+W8Pi3Q1kfM8EyVwHvp8a+h3Lo5EB0QwvVmLyjc bM8eKHTGjxTcg== 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 B726B6563D for ; Mon, 20 Jun 2022 03:43:28 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="M6HFHvBh"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 45246892; Mon, 20 Jun 2022 03:43:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655689408; bh=M4w1H+jmyVZ2LSQfVgXAT+hHM17N/I3m3Jl9XgRhV38=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M6HFHvBhq9Rm6FPWXWVq8SdSxlXINg0zg8F9w+rp7f9g0J1TNocDM12WBJzyNuxQZ W0SyzWOJE0B+E1T8ul7gM8mTtlXOBTfP6EpePi4/ScX5H87hcPNaTPs44Pb4zhF8Cz 2zcjsueRSmYfmMBEHdsTe7r+QOAH+ZJ239S2u8mI= To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jun 2022 04:43:01 +0300 Message-Id: <20220620014305.26778-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> References: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 08/12] ipa: rkisp1: Register algorithms 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" To prepare for dynamic instantiation of algorithms from the tuning file, register the algorithms with the Module class. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder --- src/ipa/rkisp1/algorithms/agc.cpp | 2 ++ src/ipa/rkisp1/algorithms/awb.cpp | 2 ++ src/ipa/rkisp1/algorithms/blc.cpp | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp index 9a12e93ae4c7..6bfe4375b396 100644 --- a/src/ipa/rkisp1/algorithms/agc.cpp +++ b/src/ipa/rkisp1/algorithms/agc.cpp @@ -355,6 +355,8 @@ void Agc::prepare(IPAContext &context, rkisp1_params_cfg *params) params->module_en_update |= RKISP1_CIF_ISP_MODULE_HST; } +REGISTER_IPA_ALGORITHM(Agc) + } /* namespace ipa::rkisp1::algorithms */ } /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index 884413828d1d..852d8559aa8a 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -175,6 +175,8 @@ void Awb::process([[maybe_unused]] IPAContext &context, << " and for blue: " << context.frameContext.awb.gains.blue; } +REGISTER_IPA_ALGORITHM(Awb) + } /* namespace ipa::rkisp1::algorithms */ } /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/blc.cpp b/src/ipa/rkisp1/algorithms/blc.cpp index 0c5948ff2c02..ea9611bd712e 100644 --- a/src/ipa/rkisp1/algorithms/blc.cpp +++ b/src/ipa/rkisp1/algorithms/blc.cpp @@ -52,6 +52,8 @@ void BlackLevelCorrection::prepare(IPAContext &context, params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_BLS; } +REGISTER_IPA_ALGORITHM(BlackLevelCorrection) + } /* namespace ipa::rkisp1::algorithms */ } /* namespace libcamera */ From patchwork Mon Jun 20 01:43:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16280 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 B7239BE173 for ; Mon, 20 Jun 2022 01:43:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 68E3665649; Mon, 20 Jun 2022 03:43:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655689419; bh=cxWIUnrRlxP3K/1kfvgY5SFRsC7hk7Y0HgKsXMiv6hc=; 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=VgDWoH2hIUhC35KbxYQh3Wm04Gge88UE6VCbgJBgCawziCUWV14ZQdnc20ux7dEIZ BBAqNje8LN3bnZ32eG14LWxvgIwswjrIG4WEHAIkjmP6PmZnVIQYrLLTy3NhNrYRMe aBH0yE6L74W5YFeu7djfJtepjxmmvznxQ6s1c7WJouJk2so5Nfi4JH8ooFAzFOUwvj DJJ9v6M0Oqthd+GR07YQCuE66nh5Vs/k8FVueQehBAd1TzZrr1Ezh2pQZLiBhu61JD lPirOaihmKPb1dbxxudiGDrLPfeItnGROOT+q2EDMyLtTqiN7wWUF8CrLHSWHjU0aS oMVWbK0vyN2xg== 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 3912665647 for ; Mon, 20 Jun 2022 03:43:29 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="JJyQ/eb4"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B9087929; Mon, 20 Jun 2022 03:43:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655689409; bh=cxWIUnrRlxP3K/1kfvgY5SFRsC7hk7Y0HgKsXMiv6hc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JJyQ/eb4+Hx3EkkTer2ctvVuYn2kaKFj95G3p4iBe490C+2Yjf2ELSN52/DK2Kl7I rcZBDRCfTJuBMZA2rqwhb0lGCxadx/pNpG9/kxld6gKAtBnbd6PxLkiMyUfXjZ7btA eJg0yoo7cu6DLzldUNmND4SxrrckBaCh3AlPo+5c= To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jun 2022 04:43:02 +0300 Message-Id: <20220620014305.26778-10-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> References: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 09/12] ipa: rkisp1: Add YAML tuning file support 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Florian Sylvestre Retrieve root node in YAML tuning file and provide to each algorithm this YamlObject to allow them to grab their default parameters by calling init() function. Signed-off-by: Florian Sylvestre Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder Signed-off-by: Laurent Pinchart --- Changes since v3: - Instantiate algorithms dynamically from tuning file --- src/ipa/rkisp1/rkisp1.cpp | 54 ++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 61a3bab90ccf..d052954e75b5 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -24,6 +25,7 @@ #include #include "libcamera/internal/mapped_framebuffer.h" +#include "libcamera/internal/yaml_parser.h" #include "algorithms/agc.h" #include "algorithms/algorithm.h" @@ -41,7 +43,7 @@ using namespace std::literals::chrono_literals; namespace ipa::rkisp1 { -class IPARkISP1 : public IPARkISP1Interface +class IPARkISP1 : public IPARkISP1Interface, public Module { public: int init(const IPASettings &settings, unsigned int hwRevision) override; @@ -58,6 +60,10 @@ public: void fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) override; void processStatsBuffer(const uint32_t frame, const uint32_t bufferId, const ControlList &sensorControls) override; + +protected: + std::string logPrefix() const override; + private: void setControls(unsigned int frame); void prepareMetadata(unsigned int frame, unsigned int aeState); @@ -81,11 +87,13 @@ private: /* Local parameter storage */ struct IPAContext context_; - - /* Maintain the algorithms used by the IPA */ - std::list> algorithms_; }; +std::string IPARkISP1::logPrefix() const +{ + return "rkisp1"; +} + int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision) { /* \todo Add support for other revisions */ @@ -121,12 +129,34 @@ int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision) return -ENODEV; } - /* Construct our Algorithms */ - algorithms_.push_back(std::make_unique()); - algorithms_.push_back(std::make_unique()); - algorithms_.push_back(std::make_unique()); + /* Load the tuning data file. */ + File file(settings.configurationFile.c_str()); + if (!file.open(File::OpenModeFlag::ReadOnly)) { + int ret = file.error(); + LOG(IPARkISP1, Error) + << "Failed to open configuration file " + << settings.configurationFile << ": " << strerror(-ret); + return ret; + } - return 0; + std::unique_ptr data = YamlParser::parse(file); + if (!data) + return -EINVAL; + + unsigned int version = (*data)["version"].get(0); + if (version != 1) { + LOG(IPARkISP1, Error) + << "Invalid tuning file version " << version; + return -EINVAL; + } + + if (!data->contains("algorithms")) { + LOG(IPARkISP1, Error) + << "Tuning file doesn't contain any algorithm"; + return -EINVAL; + } + + return createAlgorithms(context_, (*data)["algorithms"]); } int IPARkISP1::start() @@ -197,7 +227,7 @@ int IPARkISP1::configure([[maybe_unused]] const IPACameraSensorInfo &info, context_.frameContext.frameCount = 0; - for (auto const &algo : algorithms_) { + for (auto const &algo : algorithms()) { int ret = algo->configure(context_, info); if (ret) return ret; @@ -251,7 +281,7 @@ void IPARkISP1::fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) /* Prepare parameters buffer. */ memset(params, 0, sizeof(*params)); - for (auto const &algo : algorithms_) + for (auto const &algo : algorithms()) algo->prepare(context_, params); paramsBufferReady.emit(frame); @@ -272,7 +302,7 @@ void IPARkISP1::processStatsBuffer(const uint32_t frame, const uint32_t bufferId unsigned int aeState = 0; - for (auto const &algo : algorithms_) + for (auto const &algo : algorithms()) algo->process(context_, nullptr, stats); setControls(frame); From patchwork Mon Jun 20 01:43:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16279 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 D6F21BE173 for ; Mon, 20 Jun 2022 01:43:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8B8E665653; Mon, 20 Jun 2022 03:43:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655689418; bh=vLnEgWPZQhWYs0vrNqay6Vp8reQyRSThmzMSMIpI0W0=; 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=l8xDaU86tHmGkFbUvjiiYaTaC/83F1/MjohSiK/tOYnVdYax0GotG7HH13zkOMvOA sRDXP8qK8KStLp22XyqtHWFg3jlkNlV0a/NVUf7IWuYLBCguHLoJj/AV2R28LO7OsC 5Nsh4hCaG+TD9Clk5S4ECun044iejm+NUonhYfLHrnvxPO3ENq8f3772MeP7T1joW1 owmuGaWlChsA/8xoSfD9XwjP7xvm4C0xG5fYwf699WkxFjOmE6cPxLe5l8ZuVFmS19 XSAwt3yctY9ANLzzJluo3x/s+rdnjRdjO3FoD0H8d27TjAL3swXX3Pq/oikmwxt67S IHnouKe/rUHMA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BECFA6563E for ; Mon, 20 Jun 2022 03:43:29 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="sMnEAY3T"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3C49025E; Mon, 20 Jun 2022 03:43:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655689409; bh=vLnEgWPZQhWYs0vrNqay6Vp8reQyRSThmzMSMIpI0W0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sMnEAY3TEN0xJDqoxy0HRRrRLyRCo+n/p8ieKSQ8t7JKRU8QLzVy2nmB/GqzV3qGV gtMfGMAHLqsBHw9EYTIodP5+4YApLfdDXXPCl31Y8nmu6BGEIAflohg7XC2q4gLHbt BcHa2RPnCrH4VR0TdM4HIi/CJu5e6+Ass6DRsH3g= To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jun 2022 04:43:03 +0300 Message-Id: <20220620014305.26778-11-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> References: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 10/12] ipa: rkisp1: Add IMX219 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a skeleton for the IMX219 tuning file, with data for the BLC algorithm. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder --- src/ipa/rkisp1/data/imx219.yaml | 13 +++++++++++++ src/ipa/rkisp1/data/meson.build | 1 + 2 files changed, 14 insertions(+) create mode 100644 src/ipa/rkisp1/data/imx219.yaml diff --git a/src/ipa/rkisp1/data/imx219.yaml b/src/ipa/rkisp1/data/imx219.yaml new file mode 100644 index 000000000000..232d8ae8d58b --- /dev/null +++ b/src/ipa/rkisp1/data/imx219.yaml @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: CC0-1.0 +%YAML 1.2 +--- +version: 1 +algorithms: + - Agc: + - Awb: + - BlackLevelCorrection: + R: 256 + Gr: 256 + Gb: 256 + B: 256 +... diff --git a/src/ipa/rkisp1/data/meson.build b/src/ipa/rkisp1/data/meson.build index e5b945966625..53ef7fe28e1d 100644 --- a/src/ipa/rkisp1/data/meson.build +++ b/src/ipa/rkisp1/data/meson.build @@ -1,6 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 conf_files = files([ + 'imx219.yaml', 'uncalibrated.yaml', ]) From patchwork Mon Jun 20 01:43:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16281 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 36848BE173 for ; Mon, 20 Jun 2022 01:43:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D7B6A6564B; Mon, 20 Jun 2022 03:43:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655689420; bh=9355/k5sv3E+w7xzjqszBidVdZgPRGh9jEMeXm1tWeI=; 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=MkVf7cODBtXavfgVrnL0zHvIVdgSxAFZslZOZVw47e+MToscdlXJHGk6v+NGx/fcz 1JvDODZglUsOPyM2TIkpkqQeVhvqBzQlNM/FCueftmRM+L1OTlMPE7+dFS/DsMKJch mLWh5CLWodtCA7Lzbhjb9cH2MVnqLPQt1p/3JjeXceCvppHT7eqY35k1tTEQ4GbFwX 2q364wG9gYfCnYm0BbCfiSlG6UlbI0YDFPEmx3Xx5rnxJCV7v0gcLi+NzpctPbDK7D 2ndpEj7vQcEqBHuVjwQDUALpBXJap77t6HsuPU6aXTfHK8+cmRtt8jXCfU1kdEgsmi 19WrHfG3bIG4g== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 417AD6563F for ; Mon, 20 Jun 2022 03:43:30 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="o96/R6Xb"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B98F9883; Mon, 20 Jun 2022 03:43:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655689410; bh=9355/k5sv3E+w7xzjqszBidVdZgPRGh9jEMeXm1tWeI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o96/R6XbCcJ9uLbWLZPQXhmJt85xaqoHNMVKYzSitRNuWbf2JzFJL7zSVb0J/LdxU bwVOO05sZpLbUDUZBxzwVuBRUUoXyjKwtzkZzbei2XFeRmJRl2Dt1TA4RwnlYnHqgo Xe7tp7N0DThq7x8xDaImv/BvKbikfIbSmZAfHhos= To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jun 2022 04:43:04 +0300 Message-Id: <20220620014305.26778-12-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> References: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 11/12] ipa: rkisp1: Add OV5640 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Florian Sylvestre Add the OV5640 tuning file containing default values for 'black level correction' algorithm. Signed-off-by: Florian Sylvestre Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder Signed-off-by: Laurent Pinchart --- Changes since v3: - Add %YAML 1.2 tag - Fix indentiation in BLC parameters --- src/ipa/rkisp1/data/meson.build | 1 + src/ipa/rkisp1/data/ov5640.yaml | 13 +++++++++++++ src/ipa/rkisp1/meson.build | 1 + 3 files changed, 15 insertions(+) create mode 100644 src/ipa/rkisp1/data/ov5640.yaml diff --git a/src/ipa/rkisp1/data/meson.build b/src/ipa/rkisp1/data/meson.build index 53ef7fe28e1d..c3b4e3886490 100644 --- a/src/ipa/rkisp1/data/meson.build +++ b/src/ipa/rkisp1/data/meson.build @@ -2,6 +2,7 @@ conf_files = files([ 'imx219.yaml', + 'ov5640.yaml', 'uncalibrated.yaml', ]) diff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml new file mode 100644 index 000000000000..232d8ae8d58b --- /dev/null +++ b/src/ipa/rkisp1/data/ov5640.yaml @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: CC0-1.0 +%YAML 1.2 +--- +version: 1 +algorithms: + - Agc: + - Awb: + - BlackLevelCorrection: + R: 256 + Gr: 256 + Gb: 256 + B: 256 +... diff --git a/src/ipa/rkisp1/meson.build b/src/ipa/rkisp1/meson.build index 8c822fbb9b1f..ccb84b27525b 100644 --- a/src/ipa/rkisp1/meson.build +++ b/src/ipa/rkisp1/meson.build @@ -1,6 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 subdir('algorithms') +subdir('data') ipa_name = 'ipa_rkisp1' From patchwork Mon Jun 20 01:43:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16282 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 B337EBE173 for ; Mon, 20 Jun 2022 01:43:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6D88D65657; Mon, 20 Jun 2022 03:43:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655689421; bh=bVO1xzyMqTUKvU/3ZETsERx9YLdNjt3hyUWoPxtLoz4=; 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=EGef8Qvga9RFhGzVOCygVeIWSRniX93w3IUD4hDDwsAnG8K3oUpEyqnlyfPe3NJYj D5VNlkgJ5rm8MznCzgihpUG6Idgbepmu66D6DUtpypPGy8eEuUDcTfWp6gM0bD818F f30HqMBzDqHffy3AnwkaiHTYxYQ89zmiFEZzzUFOuKMHnHSzhxHvUSXhoL1hOqp6cH W+sI0dGIQE+ne5sqZLAii34NNLw/pqsXj9gEhT6D4XXHXbRfdfAp8J4YwFSQtjLhoC NtHID/yucCR3l9xkc0JtbBXCLle/rQNAQ8Wi+a66qwM6wj5ch5tKr8Z7rbsdhWFOH+ gX2jObIbL3xlA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B65ED6564B for ; Mon, 20 Jun 2022 03:43:30 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="XMDw4RLW"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3ED3225E; Mon, 20 Jun 2022 03:43:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655689410; bh=bVO1xzyMqTUKvU/3ZETsERx9YLdNjt3hyUWoPxtLoz4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XMDw4RLWjNcVWF0Xq9nsA72b38vgtIgBMlKaN5ncXs+pMqpESDQukrJWae6KAODs2 2jABJel57UvufewKVyk2sBAJT8UcndpD5HowTcE4WyBnRklw48thaAb0t8F0oBvVoC 6gKSjlesR3TiWn3uxR7MmNc7mAV1CscKixE/OhrM= To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jun 2022 04:43:05 +0300 Message-Id: <20220620014305.26778-13-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> References: <20220620014305.26778-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 12/12] ipa: rkisp1: Add support of Black Level Correction tuning 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Florian Sylvestre Get the Black Level Correction algorithm parameters from YAML tuning data. Signed-off-by: Florian Sylvestre Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder Signed-off-by: Laurent Pinchart --- Changes since v3: - Adapt to new init() API --- src/ipa/rkisp1/algorithms/blc.cpp | 49 ++++++++++++++++++++++++++----- src/ipa/rkisp1/algorithms/blc.h | 10 ++++++- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/blc.cpp b/src/ipa/rkisp1/algorithms/blc.cpp index ea9611bd712e..56c2b047df72 100644 --- a/src/ipa/rkisp1/algorithms/blc.cpp +++ b/src/ipa/rkisp1/algorithms/blc.cpp @@ -7,6 +7,10 @@ #include "blc.h" +#include + +#include "libcamera/internal/yaml_parser.h" + /** * \file blc.h */ @@ -29,6 +33,35 @@ namespace ipa::rkisp1::algorithms { * isn't currently supported. */ +LOG_DEFINE_CATEGORY(RkISP1Blc) + +BlackLevelCorrection::BlackLevelCorrection() + : tuningParameters_(false) +{ +} + +/** + * \copydoc libcamera::ipa::Algorithm::init + */ +int BlackLevelCorrection::init([[maybe_unused]] IPAContext &context, + const YamlObject &tuningData) +{ + blackLevelRed_ = tuningData["R"].get(256); + blackLevelGreenR_ = tuningData["Gr"].get(256); + blackLevelGreenB_ = tuningData["Gb"].get(256); + blackLevelBlue_ = tuningData["B"].get(256); + + tuningParameters_ = true; + + LOG(RkISP1Blc, Debug) + << "Black levels: red " << blackLevelRed_ + << ", green (red) " << blackLevelGreenR_ + << ", green (blue) " << blackLevelGreenB_ + << ", blue " << blackLevelBlue_; + + return 0; +} + /** * \copydoc libcamera::ipa::Algorithm::prepare */ @@ -37,15 +70,15 @@ void BlackLevelCorrection::prepare(IPAContext &context, { if (context.frameContext.frameCount > 0) return; - /* - * Substract fixed values taken from imx219 tuning file. - * \todo Use a configuration file for it ? - */ + + if (!tuningParameters_) + return; + params->others.bls_config.enable_auto = 0; - params->others.bls_config.fixed_val.r = 256; - params->others.bls_config.fixed_val.gr = 256; - params->others.bls_config.fixed_val.gb = 256; - params->others.bls_config.fixed_val.b = 256; + params->others.bls_config.fixed_val.r = blackLevelRed_; + params->others.bls_config.fixed_val.gr = blackLevelGreenR_; + params->others.bls_config.fixed_val.gb = blackLevelGreenB_; + params->others.bls_config.fixed_val.b = blackLevelBlue_; params->module_en_update |= RKISP1_CIF_ISP_MODULE_BLS; params->module_ens |= RKISP1_CIF_ISP_MODULE_BLS; diff --git a/src/ipa/rkisp1/algorithms/blc.h b/src/ipa/rkisp1/algorithms/blc.h index 69874d8f5e18..c2649dd7736e 100644 --- a/src/ipa/rkisp1/algorithms/blc.h +++ b/src/ipa/rkisp1/algorithms/blc.h @@ -20,10 +20,18 @@ namespace ipa::rkisp1::algorithms { class BlackLevelCorrection : public Algorithm { public: - BlackLevelCorrection() = default; + BlackLevelCorrection(); ~BlackLevelCorrection() = default; + int init(IPAContext &context, const YamlObject &tuningData) override; void prepare(IPAContext &context, rkisp1_params_cfg *params) override; + +private: + bool tuningParameters_; + int16_t blackLevelRed_; + int16_t blackLevelGreenR_; + int16_t blackLevelGreenB_; + int16_t blackLevelBlue_; }; } /* namespace ipa::rkisp1::algorithms */