libcamera: src/ipa/libipa/algorithm.h Source File

libcamera v0.7.2 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
algorithm.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2021, Ideas On Board
4 *
5 * ISP control algorithm interface
6 */
7#pragma once
8
9#include <memory>
10#include <stdint.h>
11#include <string>
12
13#include <libcamera/controls.h>
14
15namespace libcamera {
16
17class ValueNode;
18
19namespace ipa {
20
21template<typename _Module>
22 class Algorithm
23{
24public:
25 using Module = _Module;
26
27 virtual ~Algorithm() {}
28
29 virtual int init([[maybe_unused]] typename Module::Context &context,
30 [[maybe_unused]] const ValueNode &tuningData)
31 {
32 return 0;
33 }
34
35 virtual int configure([[maybe_unused]] typename Module::Context &context,
36 [[maybe_unused]] const typename Module::Config &configInfo)
37 {
38 return 0;
39 }
40
41 virtual void queueRequest([[maybe_unused]] typename Module::Context &context,
42 [[maybe_unused]] const uint32_t frame,
43 [[maybe_unused]] typename Module::FrameContext &frameContext,
44 [[maybe_unused]] const ControlList &controls)
45 {
46 }
47
48 virtual void prepare([[maybe_unused]] typename Module::Context &context,
49 [[maybe_unused]] const uint32_t frame,
50 [[maybe_unused]] typename Module::FrameContext &frameContext,
51 [[maybe_unused]] typename Module::Params *params)
52 {
53 }
54
55 virtual void process([[maybe_unused]] typename Module::Context &context,
56 [[maybe_unused]] const uint32_t frame,
57 [[maybe_unused]] typename Module::FrameContext &frameContext,
58 [[maybe_unused]] const typename Module::Stats *stats,
59 [[maybe_unused]] ControlList &metadata)
60 {
61 }
62};
63
64template<typename _Module>
65class AlgorithmFactoryBase
66{
67public:
68 AlgorithmFactoryBase(const char *name)
69 : name_(name)
70 {
71 _Module::registerAlgorithm(this);
72 }
73
74 virtual ~AlgorithmFactoryBase() = default;
75
76 const std::string &name() const { return name_; }
77
78 virtual std::unique_ptr<Algorithm<_Module>> create() const = 0;
79
80private:
81 std::string name_;
82};
83
84template<typename _Algorithm>
85 class AlgorithmFactory : public AlgorithmFactoryBase<typename _Algorithm::Module>
86{
87public:
88 AlgorithmFactory(const char *name)
89 : AlgorithmFactoryBase<typename _Algorithm::Module>(name)
90 {
91 }
92
93 ~AlgorithmFactory() = default;
94
95 std::unique_ptr<Algorithm<typename _Algorithm::Module>> create() const override
96 {
97 return std::make_unique<_Algorithm>();
98 }
99};
100
101#define REGISTER_IPA_ALGORITHM(algorithm, name) \
102static AlgorithmFactory<algorithm> global_##algorithm##Factory(name);
103
104} /* namespace ipa */
105
106} /* namespace libcamera */
libcamera::ControlList
Associate a list of ControlId with their values for an object.
Definition controls.h:409
libcamera::ValueNode
A class representing a tree structure of values.
Definition value_node.h:27
libcamera::ipa::AlgorithmFactory
Registration of Algorithm classes and creation of instances.
Definition algorithm.h:86
libcamera::ipa::AlgorithmFactory::create
std::unique_ptr< Algorithm< typename _Algorithm::Module > > create() const override
Create an instance of the Algorithm corresponding to the factory.
Definition algorithm.h:95
libcamera::ipa::AlgorithmFactory::AlgorithmFactory
AlgorithmFactory(const char *name)
Construct an algorithm factory.
Definition algorithm.h:88
libcamera::ipa::Algorithm
The base class for all IPA algorithms.
Definition algorithm.h:23
libcamera::ipa::Algorithm::init
virtual int init(typename Module::Context &context, const ValueNode &tuningData)
Initialize the Algorithm with tuning data.
Definition algorithm.h:29
libcamera::ipa::Algorithm::process
virtual void process(typename Module::Context &context, const uint32_t frame, typename Module::FrameContext &frameContext, const typename Module::Stats *stats, ControlList &metadata)
Process ISP statistics, and run algorithm operations.
Definition algorithm.h:55
libcamera::ipa::Algorithm< Module >::Module
Module Module
Definition algorithm.h:25
libcamera::ipa::Algorithm::configure
virtual int configure(typename Module::Context &context, const typename Module::Config &configInfo)
Configure the Algorithm given an IPAConfigInfo.
Definition algorithm.h:35
libcamera::ipa::Algorithm::prepare
virtual void prepare(typename Module::Context &context, const uint32_t frame, typename Module::FrameContext &frameContext, typename Module::Params *params)
Fill the params buffer with ISP processing parameters for a frame.
Definition algorithm.h:48
libcamera::ipa::Algorithm::queueRequest
virtual void queueRequest(typename Module::Context &context, const uint32_t frame, typename Module::FrameContext &frameContext, const ControlList &controls)
Provide control values to the algorithm.
Definition algorithm.h:41
libcamera::ipa::Module
The base class for all IPA modules.
Definition module.h:31
libcamera::ipa::Module::FrameContext
_FrameContext FrameContext
The type of the frame context.
Definition module.h:34
libcamera::ipa::Module::Params
_Params Params
The type of the ISP specific parameters.
Definition module.h:36
libcamera::ipa::Module::Context
_Context Context
The type of the shared IPA context.
Definition module.h:33
libcamera::ipa::Module::Stats
_Stats Stats
The type of the IPA statistics and ISP results.
Definition module.h:37
libcamera::ipa::Module::Config
_Config Config
The type of the IPA configuration data.
Definition module.h:35
controls.h
Framework to manage controls related to an object.
libcamera::controls
Namespace for libcamera controls.
Definition control_ids.h:22
libcamera::ipa
The IPA (Image Processing Algorithm) namespace.
Definition af.cpp:58
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17