libcamera v0.0.1
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) override;
48
49private:
50 /* \todo Make these structs available to all the ISPs ? */
51 struct RGB {
52 RGB(double _R = 0, double _G = 0, double _B = 0)
53 : R(_R), G(_G), B(_B)
54 {
55 }
56 double R, G, B;
57 RGB &operator+=(RGB const &other)
58 {
59 R += other.R, G += other.G, B += other.B;
60 return *this;
61 }
62 };
63
64 struct AwbStatus {
65 double temperatureK;
66 double redGain;
67 double greenGain;
68 double blueGain;
69 };
70
71private:
72 void calculateWBGains(const ipu3_uapi_stats_3a *stats);
73 void generateZones();
74 void generateAwbStats(const ipu3_uapi_stats_3a *stats);
75 void clearAwbStats();
76 void awbGreyWorld();
77 uint32_t estimateCCT(double red, double green, double blue);
78 static constexpr uint16_t threshold(float value);
79 static constexpr uint16_t gainValue(double gain);
80
81 std::vector<RGB> zones_;
82 Accumulator awbStats_[kAwbStatsSizeX * kAwbStatsSizeY];
83 AwbStatus asyncResults_;
84
85 uint32_t stride_;
86 uint32_t cellsPerZoneX_;
87 uint32_t cellsPerZoneY_;
88 uint32_t cellsPerZoneThreshold_;
89};
90
91} /* namespace ipa::ipu3::algorithms */
92
93} /* namespace libcamera*/
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:199
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:433
void process(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, const ipu3_uapi_stats_3a *stats) override
Process ISP statistics, and run algorithm operations.
Definition: awb.cpp:390
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:56
Top-level libcamera namespace.
Definition: backtrace.h:17
Global IPA context data shared between all algorithms.
Definition: ipa_context.h:82
IPU3-specific FrameContext.
Definition: ipa_context.h:75
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::@2 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