libcamera v0.7.2+rpt20261009
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 <span>
12#include <vector>
13
14#include <libcamera/base/log.h>
15
17
19
20#include "fixedpoint.h"
21
22namespace libcamera {
23
24namespace ipa {
25
27
28namespace gamma {
29
31 float gamma;
32};
33
35 float gamma;
36 bool update;
37};
38
39} /* namespace gamma */
40
42{
43public:
44 GammaAlgorithmBase(unsigned int nLutNodes)
45 : nLutNodes_(nLutNodes), kneePoints_(nLutNodes)
46 {
47 }
48
49 int init(ControlInfoMap::Map &controls, const ValueNode &tuningData,
50 std::span<unsigned int> segments = {});
51
52 void configure(gamma::ActiveState &state);
53 void queueRequest(gamma::ActiveState &state, const uint32_t frame,
54 gamma::FrameContext &context, const ControlList &controls);
55 void process(gamma::FrameContext &context, ControlList &metadata);
56
57protected:
58 unsigned int nLutNodes_;
60 std::vector<float> kneePoints_;
61};
62
63template<unsigned int NLutNodes, typename UQ>
65{
66public:
68 : GammaAlgorithmBase(NLutNodes)
69 {
70 }
71
72 template<typename T>
73 void prepare(gamma::FrameContext &context, std::span<T, NLutNodes> lut)
74 {
75 for (unsigned int i = 0; i < nLutNodes_; i++) {
76 float gamma = std::pow(kneePoints_[i], 1.0f / context.gamma);
77 lut[i] = UQ(gamma).quantized();
78
79 LOG(Gamma, Debug) << "LUT[" << i << "]=" << gamma
80 << "(" << lut[i] << ")";
81 }
82 }
83};
84
85} /* namespace ipa */
86
87} /* 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:42
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:178
int init(ControlInfoMap::Map &controls, const ValueNode &tuningData, std::span< unsigned int > segments={})
Initialise the algorithm with the given tuning data.
Definition gamma.cpp:111
GammaAlgorithmBase(unsigned int nLutNodes)
Construct an instance of the class.
Definition gamma.h:44
void configure(gamma::ActiveState &state)
Configure the gamma correction algorithm.
Definition gamma.cpp:155
float defaultGamma_
The default gamma parameter.
Definition gamma.h:59
unsigned int nLutNodes_
The number of gamma LUT sampling points.
Definition gamma.h:58
void process(gamma::FrameContext &context, ControlList &metadata)
Populate metadata with the gamma correction values for a frame.
Definition gamma.cpp:204
std::vector< float > kneePoints_
a vector holding the X-position of the knee points of the curve
Definition gamma.h:60
The libipa gamma correction algorithm.
Definition gamma.h:65
void prepare(gamma::FrameContext &context, std::span< T, NLutNodes > lut)
Definition gamma.h:73
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:107
Top-level libcamera namespace.
Definition backtrace.h:17
Active gamma correction algorithm state.
Definition gamma.h:30
float gamma
The gamma correction value.
Definition gamma.h:31
Per-frame gamma correction settings.
Definition gamma.h:34
bool update
A flag instructing the algorithm to push an update to the hardware.
Definition gamma.h:36
float gamma
The gamma correction value applied for this frame.
Definition gamma.h:35
Data structure to manage tree of values.