libcamera v0.8.0+rpt20261104
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 <span>
12#include <vector>
13
14#include <libcamera/controls.h>
15#include <libcamera/geometry.h>
16
18
19#include "interpolator.h"
20#include "lsc_base.h"
21
22namespace libcamera {
23
24namespace ipa {
25
26namespace lsc {
27
29 bool enabled;
30};
31
33 bool enabled;
34 bool update;
35};
36
37template<typename T>
38using Components = std::map<std::string, std::vector<T>, std::less<>>;
39
40template<typename T>
41using ComponentsMap = std::map<unsigned int, Components<T>>;
42
43} /* namespace lsc */
44
45#ifndef __DOXYGEN__
46template<>
48 interpolate(const lsc::Components<uint16_t> &a,
51 double lambda);
52
53template<>
55 interpolate(const lsc::Components<uint8_t> &a,
58 double lambda);
59#endif /* __DOXYGEN__ */
60
62{
63public:
64 int init(const ValueNode &tuningData, ControlInfoMap::Map &controls,
65 const LscDescriptor &descriptor);
66
68 const ControlList &controls);
69 void process(lsc::FrameContext &context, ControlList &metadata);
70
71protected:
72 LscAlgorithmBase() = default;
73
74 std::unique_ptr<LscImplementation> impl_;
76};
77
78template<typename U>
80{
81private:
84
85public:
86 LscAlgorithm() = default;
87
88 int configure(lsc::ActiveState &state, const Rectangle &analogCrop,
89 std::span<const double> xPos,
90 std::span<const double> yPos)
91 {
93 impl_->sampleForCrop(analogCrop, xPos, yPos);
94
95 ComponentsMap lscData;
96 for (const auto &[t, c] : data) {
97 Components &comp = lscData[t];
98
99 for (const auto &[k, gains] : c) {
100 auto &quantizedGains = comp[k];
101 quantizedGains.reserve(gains.size());
102
103 for (const float &gain : gains) {
104 /*
105 * Tabular LSC tables already store
106 * quantized values.
107 */
108 if (polynomial_)
109 quantizedGains.push_back(U(gain).quantized());
110 else
111 quantizedGains.push_back(gain);
112 }
113 }
114 }
115
116 sets_.setData(std::move(lscData));
117 state.enabled = true;
118
119 return 0;
120 }
121
122 const Components &interpolateComponents(unsigned int ct)
123 {
124 return sets_.getInterpolated(ct);
125 }
126
127 const ComponentsMap &getComponents() const
128 {
129 return sets_.data();
130 }
131
132private:
134};
135
136} /* namespace ipa */
137
138} /* namespace libcamera */
std::unordered_map< const ControlId *, ControlInfo > Map
The base std::unsorted_map<> container.
Definition controls.h:411
Associate a list of ControlId with their values for an object.
Definition controls.h:453
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:62
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:74
bool polynomial_
Boolean flag for polynomial LSC.
Definition lsc.h:75
void process(lsc::FrameContext &context, ControlList &metadata)
Populate the list of lsc metadata.
Definition lsc.cpp:204
libIPA LSC algorithm implementation
Definition lsc.h:80
int configure(lsc::ActiveState &state, const Rectangle &analogCrop, std::span< const double > xPos, std::span< const double > yPos)
Re-sample and quantize LSC data.
Definition lsc.h:88
const ComponentsMap & getComponents() const
Return the map of LSC data per-colour-temperature.
Definition lsc.h:127
const Components & interpolateComponents(unsigned int ct)
Interpolate the LSC tables for a given colour temperature.
Definition lsc.h:122
std::map< unsigned int, Components > ComponentsMap
Associate a colour temperature to a LSC table.
Definition lsc_base.h:37
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:38
std::map< unsigned int, Components< T > > ComponentsMap
Associate a colour temperature to a LSC table.
Definition lsc.h:41
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:26
The LSC active state.
Definition lsc.h:28
bool enabled
Boolean flag for the LscAlgorithm enable status.
Definition lsc.h:29
The LSC frame context.
Definition lsc.h:32
bool update
Boolean flag for the LscAlgorithm updated status.
Definition lsc.h:34
bool enabled
Boolean flag for the LscAlgorithm enable status.
Definition lsc.h:33
Data structure to manage tree of values.