libcamera v0.7.2+rpt20260817
Supporting cameras in Linux since 2019
Loading...
Searching...
No Matches
lsc.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2026 Ideas on Board Oy
4 *
5 * libIPA Lsc algorithm
6 */
7
8#pragma once
9
10#include <memory>
11#include <vector>
12
13#include <libcamera/controls.h>
14#include <libcamera/geometry.h>
15
17
18#include "interpolator.h"
19#include "lsc_base.h"
20
21namespace libcamera {
22
23namespace ipa {
24
25namespace lsc {
26
28 bool enabled;
29};
30
32 bool enabled;
33 bool update;
34};
35
36template<typename T>
37using Components = std::map<std::string, std::vector<T>, std::less<>>;
38
39template<typename T>
40using ComponentsMap = std::map<unsigned int, Components<T>>;
41
42} /* namespace lsc */
43
44#ifndef __DOXYGEN__
45template<>
47 interpolate(const lsc::Components<uint16_t> &a,
50 double lambda);
51
52template<>
54 interpolate(const lsc::Components<uint8_t> &a,
57 double lambda);
58#endif /* __DOXYGEN__ */
59
61{
62public:
63 int init(const ValueNode &tuningData, ControlInfoMap::Map &controls,
64 const LscDescriptor &descriptor);
65
67 const ControlList &controls);
68 void process(lsc::FrameContext &context, ControlList &metadata);
69
70protected:
71 LscAlgorithmBase() = default;
72
73 std::unique_ptr<LscImplementation> impl_;
75};
76
77template<typename U>
79{
80private:
83
84public:
85 LscAlgorithm() = default;
86
87 int configure(lsc::ActiveState &state, const Rectangle &analogCrop,
88 const std::vector<double> &xPos,
89 const std::vector<double> &yPos)
90 {
92 impl_->sampleForCrop(analogCrop, xPos, yPos);
93
94 ComponentsMap lscData;
95 for (const auto &[t, c] : data) {
96 Components &comp = lscData[t];
97
98 for (const auto &[k, gains] : c) {
99 auto &quantizedGains = comp[k];
100 quantizedGains.reserve(gains.size());
101
102 for (const float &gain : gains) {
103 /*
104 * Tabular LSC tables already store
105 * quantized values.
106 */
107 if (polynomial_)
108 quantizedGains.push_back(U(gain).quantized());
109 else
110 quantizedGains.push_back(gain);
111 }
112 }
113 }
114
115 sets_.setData(std::move(lscData));
116 state.enabled = true;
117
118 return 0;
119 }
120
121 const Components interpolateComponents(unsigned int ct)
122 {
123 return sets_.getInterpolated(ct);
124 }
125
126 const ComponentsMap &getComponents() const
127 {
128 return sets_.data();
129 }
130
131private:
133};
134
135} /* namespace ipa */
136
137} /* namespace libcamera */
std::unordered_map< const ControlId *, ControlInfo > Map
The base std::unsorted_map<> container.
Definition controls.h:367
Associate a list of ControlId with their values for an object.
Definition controls.h:409
Describe a rectangle's position and dimensions.
Definition geometry.h:247
A class representing a tree structure of values.
Definition value_node.h:27
Class for storing, retrieving, and interpolating objects.
Definition interpolator.h:28
const T & getInterpolated(unsigned int key)
Retrieve an interpolated value for the given key.
Definition interpolator.h:87
const std::map< unsigned int, T > & data() const
Access the internal map.
Definition interpolator.h:82
void setData(std::map< unsigned int, T > &&data)
Set the internal map.
Definition interpolator.h:76
Base class for LscAlgorithm.
Definition lsc.h:61
void queueRequest(lsc::ActiveState &state, lsc::FrameContext &context, const ControlList &controls)
Queue a request to the lsc algorithm.
Definition lsc.cpp:179
int init(const ValueNode &tuningData, ControlInfoMap::Map &controls, const LscDescriptor &descriptor)
Definition lsc.cpp:135
std::unique_ptr< LscImplementation > impl_
The LSC algorithm implementation.
Definition lsc.h:73
bool polynomial_
Boolean flag for polynomial LSC.
Definition lsc.h:74
void process(lsc::FrameContext &context, ControlList &metadata)
Populate the list of lsc metadata.
Definition lsc.cpp:204
libIPA LSC algorithm implementation
Definition lsc.h:79
int configure(lsc::ActiveState &state, const Rectangle &analogCrop, const std::vector< double > &xPos, const std::vector< double > &yPos)
Re-sample and quantize LSC data.
Definition lsc.h:87
const ComponentsMap & getComponents() const
Return the map of LSC data per-colour-temperature.
Definition lsc.h:126
const Components interpolateComponents(unsigned int ct)
Interpolate the LSC tables for a given colour temperature.
Definition lsc.h:121
std::map< unsigned int, Components > ComponentsMap
Associate a colour temperature to a LSC table.
Definition lsc_base.h:38
Framework to manage controls related to an object.
Data structures related to geometric objects.
Helper class for linear interpolating a set of objects.
std::map< std::string, std::vector< T >, std::less<> > Components
Associate colour components with a list of gains in register format.
Definition lsc.h:37
std::map< unsigned int, Components< T > > ComponentsMap
Associate a colour temperature to a LSC table.
Definition lsc.h:40
Base types and definitions for LscImplementation class hierarchy.
Top-level libcamera namespace.
Definition backtrace.h:17
Describe the ISP LSC engine.
Definition lsc_base.h:27
The LSC active state.
Definition lsc.h:27
bool enabled
Boolean flag for the LscAlgorithm enable status.
Definition lsc.h:28
The LSC frame context.
Definition lsc.h:31
bool update
Boolean flag for the LscAlgorithm updated status.
Definition lsc.h:33
bool enabled
Boolean flag for the LscAlgorithm enable status.
Definition lsc.h:32
Data structure to manage tree of values.