libcamera v0.8.0+1-3c8337a0-nvm
Supporting cameras in Linux since 2019
Loading...
Searching...
No Matches
gamma.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 Gamma correction algorithm
6 */
7
8#pragma once
9
10#include <cmath>
11#include <optional>
12#include <span>
13#include <vector>
14
15#include <libcamera/base/log.h>
16
18
20
21#include "fixedpoint.h"
22
23namespace libcamera {
24
25namespace ipa {
26
28
29namespace gamma {
30
32 float gamma;
33};
34
36 float gamma;
37 bool update;
38};
39
40} /* namespace gamma */
41
43{
44public:
45 GammaAlgorithmBase(unsigned int nLutNodes)
46 : nLutNodes_(nLutNodes), kneePoints_(nLutNodes)
47 {
48 }
49
50 void configure(gamma::ActiveState &state);
51 void queueRequest(gamma::ActiveState &state, const uint32_t frame,
52 gamma::FrameContext &context, const ControlList &controls);
53 void process(gamma::FrameContext &context, ControlList &metadata);
54
55protected:
56 int init(ControlInfoMap::Map &controls, const ValueNode &tuningData,
57 std::span<const unsigned int> segments);
58
59 unsigned int nLutNodes_;
61 std::vector<float> kneePoints_;
62};
63
64template<unsigned int NLutNodes, typename UQ>
66{
67 static_assert(NLutNodes >= 2);
68
69public:
71 : GammaAlgorithmBase(NLutNodes)
72 {
73 }
74
75 int init(ControlInfoMap::Map &controls, const ValueNode &tuningData,
76 std::optional<std::span<const unsigned int, NLutNodes - 1>> segments = {})
77 {
79 controls, tuningData,
80 segments ? *segments : std::span<const unsigned int>{});
81 }
82
83 template<typename T>
84 void prepare(gamma::FrameContext &context, std::span<T, NLutNodes> lut)
85 {
86 for (unsigned int i = 0; i < nLutNodes_; i++) {
87 float gamma = std::pow(kneePoints_[i], 1.0f / context.gamma);
88 lut[i] = UQ(gamma).quantized();
89
90 LOG(Gamma, Debug) << "LUT[" << i << "]=" << gamma
91 << "(" << lut[i] << ")";
92 }
93 }
94};
95
96} /* namespace ipa */
97
98} /* 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
A class representing a tree structure of values.
Definition value_node.h:27
Base class for GammaAlgorithm to implement non-templated functions.
Definition gamma.h:43
void queueRequest(gamma::ActiveState &state, const uint32_t frame, gamma::FrameContext &context, const ControlList &controls)
Queue a request to the gamma correction algorithm.
Definition gamma.cpp:147
int init(ControlInfoMap::Map &controls, const ValueNode &tuningData, std::span< const unsigned int > segments)
Initialise the algorithm with the given tuning data.
Definition gamma.cpp:80
GammaAlgorithmBase(unsigned int nLutNodes)
Construct an instance of the class.
Definition gamma.h:45
void configure(gamma::ActiveState &state)
Configure the gamma correction algorithm.
Definition gamma.cpp:124
float defaultGamma_
The default gamma parameter.
Definition gamma.h:60
unsigned int nLutNodes_
The number of gamma LUT sampling points.
Definition gamma.h:59
void process(gamma::FrameContext &context, ControlList &metadata)
Populate metadata with the gamma correction values for a frame.
Definition gamma.cpp:173
std::vector< float > kneePoints_
a vector holding the X-position of the knee points of the curve
Definition gamma.h:61
The libipa gamma correction algorithm.
Definition gamma.h:66
int init(ControlInfoMap::Map &controls, const ValueNode &tuningData, std::optional< std::span< const unsigned int, NLutNodes - 1 > > segments={})
Initialise the algorithm with the given tuning data.
Definition gamma.h:75
void prepare(gamma::FrameContext &context, std::span< T, NLutNodes > lut)
Definition gamma.h:84
Camera controls identifiers.
Logging infrastructure.
#define LOG_DECLARE_CATEGORY(name)
Declare a category of log messages.
Definition log.h:51
#define LOG(category, severity)
Log a message.
Definition log.h:155
Quantized< FixedPointQTraits< I, F, std::make_unsigned_t< decltype(details::qtype< I+F >())> > > UQ
Define an unsigned fixed-point quantized type with automatic storage width.
Definition fixedpoint.h:111
Top-level libcamera namespace.
Definition backtrace.h:17
Active gamma correction algorithm state.
Definition gamma.h:31
float gamma
The gamma correction value.
Definition gamma.h:32
Per-frame gamma correction settings.
Definition gamma.h:35
bool update
A flag instructing the algorithm to push an update to the hardware.
Definition gamma.h:37
float gamma
The gamma correction value applied for this frame.
Definition gamma.h:36
Data structure to manage tree of values.