libcamera v0.7.2+rpt20260817
Supporting cameras in Linux since 2019
Loading...
Searching...
No Matches
libcamera::ipa::LscAlgorithm< U > Class Template Reference

libIPA LSC algorithm implementation More...

Inheritance diagram for libcamera::ipa::LscAlgorithm< U >:
Collaboration diagram for libcamera::ipa::LscAlgorithm< U >:

Public Member Functions

int configure (lsc::ActiveState &state, const Rectangle &analogCrop, const std::vector< double > &xPos, const std::vector< double > &yPos)
 Re-sample and quantize LSC data.
 
const Components interpolateComponents (unsigned int ct)
 Interpolate the LSC tables for a given colour temperature.
 
const ComponentsMap & getComponents () const
 Return the map of LSC data per-colour-temperature.
 
- Public Member Functions inherited from libcamera::ipa::LscAlgorithmBase
int init (const ValueNode &tuningData, ControlInfoMap::Map &controls, const LscDescriptor &descriptor)
 
void queueRequest (lsc::ActiveState &state, lsc::FrameContext &context, const ControlList &controls)
 Queue a request to the lsc algorithm.
 
void process (lsc::FrameContext &context, ControlList &metadata)
 Populate the list of lsc metadata.
 

Additional Inherited Members

- Protected Attributes inherited from libcamera::ipa::LscAlgorithmBase
std::unique_ptr< LscImplementationimpl_
 The LSC algorithm implementation.
 
bool polynomial_
 Boolean flag for polynomial LSC.
 

Detailed Description

template<typename U>
class libcamera::ipa::LscAlgorithm< U >

libIPA LSC algorithm implementation

Template Parameters
UThe platform fixed-point register format representation

Due to the optical characteristics of the lens, the light intensity received by the sensor is not uniform. The Lens Shading Correction algorithm applies multipliers to all pixels to compensate for the lens shading effect.

The LscAlgorithm implements the libipa Lens Shading Correction algorithm using an implementation of the LscImplementation interface.

This class provides support for parsing the tuning file content and generates tables indexed by colour temperature to store per-colour-channel gains for the IPA algorithm to be able to program the LSC engine.

The init() function parses the tuning file and loads the gain tables either in tabular form (LscTable) or as radial polynomials (LscPolynomial). The gain tables are indexed by colour temperature with per-colour-components vectors of gain values or polynomial coefficients.

The colour components names are IPA-implementation specific and depend on the ISP LSC engine design. Some LSC engine support 4 colour components (r, gr, gb, b), some only support 3 colour components (r, g, b). The name (and number) of the expected colour components shall be provided to LscAlgorithm::init() using the LscDescriptor::keys field.

Example of a tabular lens shading tuning file with 'r', 'g' and 'b' colour components. The gain table has been omitted here, but the expected number of entries has to be equal to LscDescriptor::numHSamples * LscDescriptor::numVSamples.

- Lsc:
sets:
- ct: 2500
r: [
.. gains table omitted..
]
g: [
.. gains table omitted..
]
b: [
.. gains table omitted..
]
- ct: 6500
r: [
.. gains table omitted..
]
g: [
.. gains table omitted..
]
b: [
.. gains table omitted..
]

Example of a polynomial lens shading tuning file with 'r', 'gr', 'gb' and 'b' colour components:

- Lsc:
type: "polynomial"
sets:
- ct: 2500
r:
cx: 0.5006571711950275
cy: 0.510093737499277
k0: 1.5393282208428813
k1: -1.1434559757908016
k2: 4.332602305814554
k3: 0.0
k4: 0.0
gr:
cx: 0.5009320529087338
cy: 0.511208038949085
k0: 1.5634738574805407
k1: -1.5623484259968348
k2: 4.846686073656501
k3: 0.0
k4: 0.0
gb:
cx: 0.5012013290343839
cy: 0.5128251541578288
k0: 1.526147944919103
k1: -1.4316976083689723
k2: 4.792604063222728
k3: 0.0
k4: 0.0
b:
cx: 0.49864139511067784
cy: 0.5162095081739346
k0: 1.0405245474038738
k1: 0.05618339879447103
k2: 1.8792813594001752
k3: 0.0
k4: 0.0
- ct: 6000
r:
cx: 0.5006202239353942
cy: 0.5099531318307661
k0: 1.4702946023945032
k1: -0.8893767547927631
k2: 3.920547732201387
k3: 0.0
k4: 0.0
gr:
cx: 0.500907874178317
cy: 0.511084916024106
k0: 1.5336172760559457
k1: -1.39964026514435
k2: 4.565487728954618
k3: 0.0
k4: 0.0
gb:
cx: 0.5011898608900477
cy: 0.5126797906745105
k0: 1.5013145790354843
k1: -1.2747407173754124
k2: 4.514682876897286
k3: 0.0
k4: 0.0
b:
cx: 0.4987561413116136
cy: 0.5159619420778772
k0: 1.0102986422191802
k1: 0.13263449763985727
k2: 1.686556107316064
k3: 0.0
k4: 0.0

The LSC polynomial definition is generated at tuning time in relation to the full sensor pixel array. This needs to be specified in LscDescriptor::sensorSize.

At LscAlgorithm::configure() time the LSC tables are re-sampled on the sensor's crop rectangle in use to adapt them to the configuration in use for a streaming session. Polynomial LSC tables support re-sampling and can be applied to any sensor configuration. Grid-based LSC tables cannot currently be re-sampled and the configuration as parsed from the tuning file is used for all sensor configurations providing best-effort results.

Todo:
Implement grid based re-sampling

After re-sampling, the LSC tables gain values are converted from their floating point representation (LscImplementation::Components) to the platform's register representation (lsc::Components<>). Grid-based LSC tables currently already contain gains represented in register format, so no quantization is necessary but only a simple cast is required.

Todo:
Express gains in floating point format for grid-based LSC tables

When the IPA algorithms wants to get access to the (re-sampled) tables to program its LSC engine, it uses LscAlgorithm::interpolateComponents() to get an LSC table interpolated by the LscAlgorithm class for the specified colour temperature. If the algorithm wants to access the non-interpolated tables it can retrieve them using LscAlgorithm::getComponents().

Member Function Documentation

◆ configure()

template<typename U >
libcamera::ipa::LscAlgorithm< U >::configure ( lsc::ActiveState state,
const Rectangle analogCrop,
const std::vector< double > &  xPos,
const std::vector< double > &  yPos 
)
inline

Re-sample and quantize LSC data.

Parameters
[in]stateThe LSC active state
[in]analogCropThe current sensor analog crop rectangle
[in]xPosList of horizontal positions of the LSC grid nodes
[in]yPosList of vertical positions of the LSC grid nodes

Re-sample the LSC data for an analogCrop and convert gains to their register representation using the class template paramter U.

LSC tables are generated at tuning time using a known sensor configuration. When a new streaming session is started, it might use a different sensor configuration for which the LSC tables need to be adjusted to.

This function re-generates the LSC tables to adapt them to a new sensor configuration, specifically it re-samples the LSC data for a new analogCrop on a grid specified by xPos and yPos. Re-sampling of LSC data is currently supported by polynomial-based LSC tables.

See also
LscImplementation::sampleForCrop

Once tables have been re-sampled, they get quantized to the platform's fixed-point register representation using the LscAlgorithm template parameter U.

Returns
0 on success, a negative error code otherwise

◆ getComponents()

template<typename U >
libcamera::ipa::LscAlgorithm< U >::getComponents ( ) const
inline

Return the map of LSC data per-colour-temperature.

Calling this function is only valid after LscAlgorithm::configure() has been called. An empty components list is returned otherwise.

Returns
The map of LSC gains tables per-colour-temperature

◆ interpolateComponents()

template<typename U >
libcamera::ipa::LscAlgorithm< U >::interpolateComponents ( unsigned int  ct)
inline

Interpolate the LSC tables for a given colour temperature.

Parameters
[in]ctThe colour temperature

LSC tables are generated using different colour temperatures during the tuning phase.

This function returns the interpolated LSC data for a given ct colour temperature.

IPA algorithm can use this function to obtain a list of per-colour-component gains to program their LSC engines with every time a significant enough change in colour temperature is detected.

Calling this function is only valid after LscAlgorithm::configure() has been called. An empty components list is returned otherwise.

Returns
The LSC gains table interpolated for temperature ct

The documentation for this class was generated from the following files: