libcamera: src/ipa/ipu3/algorithms/awb.h Source File

libcamera v0.0.4 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
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{
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,
48 ControlList &metadata) override;
49
50private:
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
72private:
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 uint32_t estimateCCT(double red, double green, double blue);
79 static constexpr uint16_t threshold(float value);
80 static constexpr uint16_t gainValue(double gain);
81
82 std::vector<RGB> zones_;
83 Accumulator awbStats_[kAwbStatsSizeX * kAwbStatsSizeY];
84 AwbStatus asyncResults_;
85
86 uint32_t stride_;
87 uint32_t cellsPerZoneX_;
88 uint32_t cellsPerZoneY_;
89 uint32_t cellsPerZoneThreshold_;
90};
91
92} /* namespace ipa::ipu3::algorithms */
93
94} /* namespace libcamera*/
libcamera::ControlList
Associate a list of ControlId with their values for an object.
Definition: controls.h:350
libcamera::ipa::Algorithm
The base class for all IPA algorithms.
Definition: algorithm.h:23
libcamera::ipa::ipu3::algorithms::Awb
A Grey world white balance correction algorithm.
Definition: awb.h:36
libcamera::ipa::ipu3::algorithms::Awb::configure
int configure(IPAContext &context, const IPAConfigInfo &configInfo) override
Configure the Algorithm given an IPAConfigInfo.
Definition: awb.cpp:201
libcamera::ipa::ipu3::algorithms::Awb::prepare
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:247
libcamera::ipa::ipu3::algorithms::Awb::process
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:475
geometry.h
Data structures related to geometric objects.
algorithm.h
Algorithm common interface.
libcamera
Top-level libcamera namespace.
Definition: backtrace.h:17
libcamera::ipa::ipu3::IPAContext
Global IPA context data shared between all algorithms.
Definition: ipa_context.h:83
libcamera::ipa::ipu3::IPAFrameContext
IPU3-specific FrameContext.
Definition: ipa_context.h:76
libcamera::ipa::ipu3::algorithms::Accumulator
RGB statistics for a given zone.
Definition: awb.h:26
libcamera::ipa::ipu3::algorithms::Accumulator::counted
unsigned int counted
Number of unsaturated cells used to calculate the sums.
Definition: awb.h:27
libcamera::ipa::ipu3::algorithms::Accumulator::red
uint64_t red
Sum of the average red values of each unsaturated cell in the zone.
Definition: awb.h:29
libcamera::ipa::ipu3::algorithms::Accumulator::sum
struct libcamera::ipa::ipu3::algorithms::Accumulator::@2 sum
A structure containing the average red, green and blue sums.
libcamera::ipa::ipu3::algorithms::Accumulator::blue
uint64_t blue
Sum of the average blue values of each unsaturated cell in the zone.
Definition: awb.h:31
libcamera::ipa::ipu3::algorithms::Accumulator::green
uint64_t green
Sum of the average green values of each unsaturated cell in the zone.
Definition: awb.h:30