summaryrefslogtreecommitdiff
path: root/src/ipa/simple/algorithms/awb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ipa/simple/algorithms/awb.cpp')
-rw-r--r--src/ipa/simple/algorithms/awb.cpp50
1 files changed, 40 insertions, 10 deletions
diff --git a/src/ipa/simple/algorithms/awb.cpp b/src/ipa/simple/algorithms/awb.cpp
index 195de41d..55719059 100644
--- a/src/ipa/simple/algorithms/awb.cpp
+++ b/src/ipa/simple/algorithms/awb.cpp
@@ -12,8 +12,13 @@
#include <libcamera/base/log.h>
+#include <libcamera/control_ids.h>
+
+#include "libipa/colours.h"
#include "simple/ipa_context.h"
+#include "control_ids.h"
+
namespace libcamera {
LOG_DEFINE_CATEGORY(IPASoftAwb)
@@ -23,21 +28,38 @@ namespace ipa::soft::algorithms {
int Awb::configure(IPAContext &context,
[[maybe_unused]] const IPAConfigInfo &configInfo)
{
- auto &gains = context.activeState.gains;
- gains.red = gains.green = gains.blue = 1.0;
+ auto &gains = context.activeState.awb.gains;
+ gains = { { 1.0, 1.0, 1.0 } };
return 0;
}
+void Awb::prepare(IPAContext &context,
+ [[maybe_unused]] const uint32_t frame,
+ IPAFrameContext &frameContext,
+ [[maybe_unused]] DebayerParams *params)
+{
+ auto &gains = context.activeState.awb.gains;
+ frameContext.gains.red = gains.r();
+ frameContext.gains.blue = gains.b();
+}
+
void Awb::process(IPAContext &context,
[[maybe_unused]] const uint32_t frame,
- [[maybe_unused]] IPAFrameContext &frameContext,
+ IPAFrameContext &frameContext,
const SwIspStats *stats,
- [[maybe_unused]] ControlList &metadata)
+ ControlList &metadata)
{
const SwIspStats::Histogram &histogram = stats->yHistogram;
const uint8_t blackLevel = context.activeState.blc.level;
+ const float maxGain = 1024.0;
+ const float mdGains[] = {
+ static_cast<float>(frameContext.gains.red / maxGain),
+ static_cast<float>(frameContext.gains.blue / maxGain)
+ };
+ metadata.set(controls::ColourGains, mdGains);
+
/*
* Black level must be subtracted to get the correct AWB ratios, they
* would be off if they were computed from the whole brightness range
@@ -54,12 +76,20 @@ void Awb::process(IPAContext &context,
* Calculate red and blue gains for AWB.
* Clamp max gain at 4.0, this also avoids 0 division.
*/
- auto &gains = context.activeState.gains;
- gains.red = sumR <= sumG / 4 ? 4.0 : static_cast<double>(sumG) / sumR;
- gains.blue = sumB <= sumG / 4 ? 4.0 : static_cast<double>(sumG) / sumB;
- /* Green gain is fixed to 1.0 */
-
- LOG(IPASoftAwb, Debug) << "gain R/B " << gains.red << "/" << gains.blue;
+ auto &gains = context.activeState.awb.gains;
+ gains = { {
+ sumR <= sumG / 4 ? 4.0f : static_cast<float>(sumG) / sumR,
+ 1.0,
+ sumB <= sumG / 4 ? 4.0f : static_cast<float>(sumG) / sumB,
+ } };
+
+ RGB<double> rgbGains{ { 1 / gains.r(), 1 / gains.g(), 1 / gains.b() } };
+ context.activeState.awb.temperatureK = estimateCCT(rgbGains);
+ metadata.set(controls::ColourTemperature, context.activeState.awb.temperatureK);
+
+ LOG(IPASoftAwb, Debug)
+ << "gain R/B: " << gains << "; temperature: "
+ << context.activeState.awb.temperatureK;
}
REGISTER_IPA_ALGORITHM(Awb, "Awb")