libcamera  v0.4.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  * 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 "libipa/vector.h"
17 
18 #include "algorithm.h"
19 
20 namespace libcamera {
21 
22 namespace ipa::ipu3::algorithms {
23 
24 /* Region size for the statistics generation algorithm */
25 static constexpr uint32_t kAwbStatsSizeX = 16;
26 static constexpr uint32_t kAwbStatsSizeY = 12;
27 
28 struct Accumulator {
29  unsigned int counted;
30  struct {
31  uint64_t red;
32  uint64_t green;
33  uint64_t blue;
34  } sum;
35 };
36 
37 class Awb : public Algorithm
38 {
39 public:
40  Awb();
41  ~Awb();
42 
43  int configure(IPAContext &context, const IPAConfigInfo &configInfo) override;
44  void prepare(IPAContext &context, const uint32_t frame,
45  IPAFrameContext &frameContext,
46  ipu3_uapi_params *params) override;
47  void process(IPAContext &context, const uint32_t frame,
48  IPAFrameContext &frameContext,
49  const ipu3_uapi_stats_3a *stats,
50  ControlList &metadata) override;
51 
52 private:
53  struct AwbStatus {
54  double temperatureK;
55  double redGain;
56  double greenGain;
57  double blueGain;
58  };
59 
60 private:
61  void calculateWBGains(const ipu3_uapi_stats_3a *stats);
62  void generateZones();
63  void generateAwbStats(const ipu3_uapi_stats_3a *stats);
64  void clearAwbStats();
65  void awbGreyWorld();
66  static constexpr uint16_t threshold(float value);
67  static constexpr uint16_t gainValue(double gain);
68 
69  std::vector<RGB<double>> zones_;
70  Accumulator awbStats_[kAwbStatsSizeX * kAwbStatsSizeY];
71  AwbStatus asyncResults_;
72 
73  uint32_t stride_;
74  uint32_t cellsPerZoneX_;
75  uint32_t cellsPerZoneY_;
76  uint32_t cellsPerZoneThreshold_;
77 };
78 
79 } /* namespace ipa::ipu3::algorithms */
80 
81 } /* namespace libcamera*/
Associate a list of ControlId with their values for an object.
Definition: controls.h:411
The base class for all IPA algorithms.
Definition: algorithm.h:23
A Grey world white balance correction algorithm.
Definition: awb.h:38
int configure(IPAContext &context, const IPAConfigInfo &configInfo) override
Configure the Algorithm given an IPAConfigInfo.
Definition: awb.cpp:203
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:249
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:450
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:86
IPU3-specific FrameContext.
Definition: ipa_context.h:79
RGB statistics for a given zone.
Definition: awb.h:28
unsigned int counted
Number of unsaturated cells used to calculate the sums.
Definition: awb.h:29
uint64_t red
Sum of the average red values of each unsaturated cell in the zone.
Definition: awb.h:31
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:33
uint64_t green
Sum of the average green values of each unsaturated cell in the zone.
Definition: awb.h:32
Vector class.