libcamera v0.0.0
Supporting cameras in Linux since 2019
Loading...
Searching...
No Matches
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, ipu3_uapi_params *params) override;
43 void process(IPAContext &context, IPAFrameContext *frameContext,
44 const ipu3_uapi_stats_3a *stats) override;
45
46private:
47 /* \todo Make these structs available to all the ISPs ? */
48 struct RGB {
49 RGB(double _R = 0, double _G = 0, double _B = 0)
50 : R(_R), G(_G), B(_B)
51 {
52 }
53 double R, G, B;
54 RGB &operator+=(RGB const &other)
55 {
56 R += other.R, G += other.G, B += other.B;
57 return *this;
58 }
59 };
60
61 struct AwbStatus {
62 double temperatureK;
63 double redGain;
64 double greenGain;
65 double blueGain;
66 };
67
68private:
69 void calculateWBGains(const ipu3_uapi_stats_3a *stats);
70 void generateZones();
71 void generateAwbStats(const ipu3_uapi_stats_3a *stats);
72 void clearAwbStats();
73 void awbGreyWorld();
74 uint32_t estimateCCT(double red, double green, double blue);
75 static constexpr uint16_t threshold(float value);
76 static constexpr uint16_t gainValue(double gain);
77
78 std::vector<RGB> zones_;
79 Accumulator awbStats_[kAwbStatsSizeX * kAwbStatsSizeY];
80 AwbStatus asyncResults_;
81
82 uint32_t stride_;
83 uint32_t cellsPerZoneX_;
84 uint32_t cellsPerZoneY_;
85 uint32_t cellsPerZoneThreshold_;
86};
87
88} /* namespace ipa::ipu3::algorithms */
89
90} /* namespace libcamera*/
The base class for all IPA algorithms.
Definition: algorithm.h:22
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 process(IPAContext &context, IPAFrameContext *frameContext, const ipu3_uapi_stats_3a *stats) override
Process ISP statistics, and run algorithm operations.
Definition: awb.cpp:390
void prepare(IPAContext &context, ipu3_uapi_params *params) override
Fill the params buffer with ISP processing parameters for a frame.
Definition: awb.cpp:432
Data structures related to geometric objects.
Algorithm common interface.
Top-level libcamera namespace.
Definition: backtrace.h:17
Global IPA context data shared between all algorithms.
Definition: ipa_context.h:92
Context for a frame.
Definition: ipa_context.h:79
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