summaryrefslogtreecommitdiff
path: root/src/ipa/ipu3/ipu3_awb.h
diff options
context:
space:
mode:
authorJean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>2021-03-16 21:27:27 +0100
committerKieran Bingham <kieran.bingham@ideasonboard.com>2021-04-22 10:12:53 +0100
commitb2ddc9b11815976ec0bdf741fded993b8bc9ef4d (patch)
treef21468f97357e817bf04e9dfed5c90a7654c9fc5 /src/ipa/ipu3/ipu3_awb.h
parent3ebb692f323eaace79ae4932bd119df2de361650 (diff)
ipa: ipu3: Add support for IPU3 AWB algorithm
The IPA will locally modify the parameters before they are passed down to the ImgU. Use a local parameter object to give a reference to those algorithms. Inherit from the Algorithm class to implement basic AWB functions. The configure() call will set exposure and gain to their minimum value, so while AGC is not there, the frames will be dark. Once AWB is done, a color temperature is estimated and a default CCM matrix will be used (yet to be tuned). Implement a basic "grey-world" AWB algorithm just for demonstration purpose. The BDS output size is passed by the pipeline handler to the IPA. The best grid is then calculated to maximize the number of pixels taken into account in each cells. As commented in the source code, it can be improved, as it has (at least) one limitation: if a cell is big (say 128 pixels wide) and indicated as saturated, it won't be taken into account at all. Maybe is it possible to have a smaller one, at the cost of a few pixels to lose, in which case we can center the grid using the x_start and y_start parameters. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Tested-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/ipa/ipu3/ipu3_awb.h')
-rw-r--r--src/ipa/ipu3/ipu3_awb.h91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/ipa/ipu3/ipu3_awb.h b/src/ipa/ipu3/ipu3_awb.h
new file mode 100644
index 00000000..122cf68c
--- /dev/null
+++ b/src/ipa/ipu3/ipu3_awb.h
@@ -0,0 +1,91 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2021, Ideas On Board
+ *
+ * ipu3_awb.h - IPU3 AWB control algorithm
+ */
+#ifndef __LIBCAMERA_IPU3_AWB_H__
+#define __LIBCAMERA_IPU3_AWB_H__
+
+#include <vector>
+
+#include <linux/intel-ipu3.h>
+
+#include <libcamera/geometry.h>
+
+#include "libipa/algorithm.h"
+
+namespace libcamera {
+
+namespace ipa::ipu3 {
+
+/* Region size for the statistics generation algorithm */
+static constexpr uint32_t kAwbStatsSizeX = 16;
+static constexpr uint32_t kAwbStatsSizeY = 12;
+
+class IPU3Awb : public Algorithm
+{
+public:
+ IPU3Awb();
+ ~IPU3Awb();
+
+ void initialise(ipu3_uapi_params &params, const Size &bdsOutputSize, struct ipu3_uapi_grid_config &bdsGrid);
+ void calculateWBGains(const ipu3_uapi_stats_3a *stats);
+ void updateWbParameters(ipu3_uapi_params &params, double agcGamma);
+
+ struct Ipu3AwbCell {
+ unsigned char greenRedAvg;
+ unsigned char redAvg;
+ unsigned char blueAvg;
+ unsigned char greenBlueAvg;
+ unsigned char satRatio;
+ unsigned char padding[3];
+ } __attribute__((packed));
+
+ /* \todo Make these three structs available to all the ISPs ? */
+ struct RGB {
+ RGB(double _R = 0, double _G = 0, double _B = 0)
+ : R(_R), G(_G), B(_B)
+ {
+ }
+ double R, G, B;
+ RGB &operator+=(RGB const &other)
+ {
+ R += other.R, G += other.G, B += other.B;
+ return *this;
+ }
+ };
+
+ struct IspStatsRegion {
+ unsigned int counted;
+ unsigned int uncounted;
+ unsigned long long rSum;
+ unsigned long long gSum;
+ unsigned long long bSum;
+ };
+
+ struct AwbStatus {
+ double temperatureK;
+ double redGain;
+ double greenGain;
+ double blueGain;
+ };
+
+private:
+ void generateZones(std::vector<RGB> &zones);
+ void generateAwbStats(const ipu3_uapi_stats_3a *stats);
+ void clearAwbStats();
+ void awbGreyWorld();
+ uint32_t estimateCCT(double red, double green, double blue);
+
+ struct ipu3_uapi_grid_config awbGrid_;
+
+ std::vector<RGB> zones_;
+ IspStatsRegion awbStats_[kAwbStatsSizeX * kAwbStatsSizeY];
+ AwbStatus asyncResults_;
+};
+
+} /* namespace ipa::ipu3 */
+
+} /* namespace libcamera*/
+#endif /* __LIBCAMERA_IPU3_AWB_H__ */