libcamera  v0.3.2+116-83c5ad0f
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  * 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, 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 
50 private:
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 
72 private:
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  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*/
Global IPA context data shared between all algorithms.
Definition: ipa_context.h:86
A Grey world white balance correction algorithm.
Definition: awb.h:35
uint64_t green
Sum of the average green values of each unsaturated cell in the zone.
Definition: awb.h:30
Top-level libcamera namespace.
Definition: backtrace.h:17
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:73
uint64_t red
Sum of the average red values of each unsaturated cell in the zone.
Definition: awb.h:29
unsigned int counted
Number of unsaturated cells used to calculate the sums.
Definition: awb.h:27
IPU3-specific FrameContext.
Definition: ipa_context.h:79
RGB statistics for a given zone.
Definition: awb.h:26
struct libcamera::ipa::ipu3::algorithms::Accumulator::@4 sum
A structure containing the average red, green and blue sums.
Associate a list of ControlId with their values for an object.
Definition: controls.h:380
The base class for all IPA algorithms.
Definition: algorithm.h:22
Data structures related to geometric objects.
uint64_t blue
Sum of the average blue values of each unsaturated cell in the zone.
Definition: awb.h:31