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