libcamera v0.1.0+127-8e215127-dirty (2023-12-02T01:06:12+00:00)
Supporting cameras in Linux since 2019
awb.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2021, Ideas On Board
4 *
5 * awb.h - IPU3 AWB control algorithm
6 */
7
8#pragma once
9
10#include <vector>
11
12#include <linux/intel-ipu3.h>
13
14#include <libcamera/geometry.h>
15
16#include "algorithm.h"
17
18namespace libcamera {
19
20namespace ipa::ipu3::algorithms {
21
22/* Region size for the statistics generation algorithm */
23static constexpr uint32_t kAwbStatsSizeX = 16;
24static constexpr uint32_t kAwbStatsSizeY = 12;
25
27 unsigned int counted;
28 struct {
29 uint64_t red;
30 uint64_t green;
31 uint64_t blue;
32 } sum;
33};
34
35class Awb : public Algorithm
36{
37public:
38 Awb();
39 ~Awb();
40
41 int configure(IPAContext &context, const IPAConfigInfo &configInfo) override;
42 void prepare(IPAContext &context, const uint32_t frame,
43 IPAFrameContext &frameContext,
44 ipu3_uapi_params *params) override;
45 void process(IPAContext &context, const uint32_t frame,
46 IPAFrameContext &frameContext,
47 const ipu3_uapi_stats_3a *stats,
48 ControlList &metadata) override;
49
50private:
51 /* \todo Make these structs available to all the ISPs ? */
52 struct RGB {
53 RGB(double _R = 0, double _G = 0, double _B = 0)
54 : R(_R), G(_G), B(_B)
55 {
56 }
57 double R, G, B;
58 RGB &operator+=(RGB const &other)
59 {
60 R += other.R, G += other.G, B += other.B;
61 return *this;
62 }
63 };
64
65 struct AwbStatus {
66 double temperatureK;
67 double redGain;
68 double greenGain;
69 double blueGain;
70 };
71
72private:
73 void calculateWBGains(const ipu3_uapi_stats_3a *stats);
74 void generateZones();
75 void generateAwbStats(const ipu3_uapi_stats_3a *stats);
76 void clearAwbStats();
77 void awbGreyWorld();
78 uint32_t estimateCCT(double red, double green, double blue);
79 static constexpr uint16_t threshold(float value);
80 static constexpr uint16_t gainValue(double gain);
81
82 std::vector<RGB> zones_;
83 Accumulator awbStats_[kAwbStatsSizeX * kAwbStatsSizeY];
84 AwbStatus asyncResults_;
85
86 uint32_t stride_;
87 uint32_t cellsPerZoneX_;
88 uint32_t cellsPerZoneY_;
89 uint32_t cellsPerZoneThreshold_;
90};
91
92} /* namespace ipa::ipu3::algorithms */
93
94} /* namespace libcamera*/
Associate a list of ControlId with their values for an object.
Definition: controls.h:350
The base class for all IPA algorithms.
Definition: algorithm.h:23
A Grey world white balance correction algorithm.
Definition: awb.h:36
int configure(IPAContext &context, const IPAConfigInfo &configInfo) override
Configure the Algorithm given an IPAConfigInfo.
Definition: awb.cpp:201
void prepare(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, ipu3_uapi_params *params) override
Fill the params buffer with ISP processing parameters for a frame.
Definition: awb.cpp:247
void process(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, const ipu3_uapi_stats_3a *stats, ControlList &metadata) override
Process ISP statistics, and run algorithm operations.
Definition: awb.cpp:475
Data structures related to geometric objects.
Algorithm common interface.
@ RGB
Sensor is not Bayer; output has 3 16-bit values for each pixel, instead of just 1 16-bit value per pi...
Definition: property_ids.h:66
Top-level libcamera namespace.
Definition: backtrace.h:17
Global IPA context data shared between all algorithms.
Definition: ipa_context.h:83
IPU3-specific FrameContext.
Definition: ipa_context.h:76
RGB statistics for a given zone.
Definition: awb.h:26
unsigned int counted
Number of unsaturated cells used to calculate the sums.
Definition: awb.h:27
uint64_t red
Sum of the average red values of each unsaturated cell in the zone.
Definition: awb.h:29
struct libcamera::ipa::ipu3::algorithms::Accumulator::@4 sum
A structure containing the average red, green and blue sums.
uint64_t blue
Sum of the average blue values of each unsaturated cell in the zone.
Definition: awb.h:31
uint64_t green
Sum of the average green values of each unsaturated cell in the zone.
Definition: awb.h:30