libcamera  v0.0.0
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 
18 namespace libcamera {
19 
20 namespace ipa::ipu3::algorithms {
21 
22 /* Region size for the statistics generation algorithm */
23 static constexpr uint32_t kAwbStatsSizeX = 16;
24 static constexpr uint32_t kAwbStatsSizeY = 12;
25 
26 struct Accumulator {
27  unsigned int counted;
28  struct {
29  uint64_t red;
30  uint64_t green;
31  uint64_t blue;
32  } sum;
33 };
34 
35 class Awb : public Algorithm
36 {
37 public:
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, const ipu3_uapi_stats_3a *stats) override;
44 
45 private:
46  /* \todo Make these structs available to all the ISPs ? */
47  struct RGB {
48  RGB(double _R = 0, double _G = 0, double _B = 0)
49  : R(_R), G(_G), B(_B)
50  {
51  }
52  double R, G, B;
53  RGB &operator+=(RGB const &other)
54  {
55  R += other.R, G += other.G, B += other.B;
56  return *this;
57  }
58  };
59 
60  struct AwbStatus {
61  double temperatureK;
62  double redGain;
63  double greenGain;
64  double blueGain;
65  };
66 
67 private:
68  void calculateWBGains(const ipu3_uapi_stats_3a *stats);
69  void generateZones();
70  void generateAwbStats(const ipu3_uapi_stats_3a *stats);
71  void clearAwbStats();
72  void awbGreyWorld();
73  uint32_t estimateCCT(double red, double green, double blue);
74  static constexpr uint16_t threshold(float value);
75 
76  std::vector<RGB> zones_;
77  Accumulator awbStats_[kAwbStatsSizeX * kAwbStatsSizeY];
78  AwbStatus asyncResults_;
79 
80  uint32_t stride_;
81  uint32_t cellsPerZoneX_;
82  uint32_t cellsPerZoneY_;
83  uint32_t cellsPerZoneThreshold_;
84 };
85 
86 } /* namespace ipa::ipu3::algorithms */
87 
88 } /* namespace libcamera*/
The base class for all IPA algorithms.
Definition: algorithm.h:15
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, ipu3_uapi_params *params) override
Fill the params buffer with ISP processing parameters for a frame.
Definition: awb.cpp:406
void process(IPAContext &context, const ipu3_uapi_stats_3a *stats) override
Process ISP statistics, and run algorithm operations.
Definition: awb.cpp:382
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:54
Top-level libcamera namespace.
Definition: backtrace.h:17
Global IPA context data shared between all algorithms.
Definition: ipa_context.h:63
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::@3 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