libcamera: software_isp: Determine color temperature

The AWB algorithm has data to determine color temperature of the image.
Let's compute the temperature from it and store it into the context.
This piece of information is currently unused but it will be needed in a
followup patch introducing support for color correction matrix.

Let's store the white balance related information under `awb' subsection
of the active state, as the hardware pipelines do.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Milan Zamazal 2025-03-26 10:08:38 +01:00 committed by Kieran Bingham
parent d505bd5360
commit 84f82c6b3c
3 changed files with 17 additions and 8 deletions

View file

@ -12,6 +12,7 @@
#include <libcamera/base/log.h>
#include "libipa/colours.h"
#include "simple/ipa_context.h"
namespace libcamera {
@ -23,7 +24,7 @@ namespace ipa::soft::algorithms {
int Awb::configure(IPAContext &context,
[[maybe_unused]] const IPAConfigInfo &configInfo)
{
auto &gains = context.activeState.gains;
auto &gains = context.activeState.awb.gains;
gains.red = gains.green = gains.blue = 1.0;
return 0;
@ -54,12 +55,17 @@ 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;
auto &gains = context.activeState.awb.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;
RGB<double> rgbGains{ { 1 / gains.red, 1 / gains.green, 1 / gains.blue } };
context.activeState.awb.temperatureK = estimateCCT(rgbGains);
LOG(IPASoftAwb, Debug)
<< "gain R/B: " << gains.red << "/" << gains.blue
<< "; temperature: " << context.activeState.awb.temperatureK;
}
REGISTER_IPA_ALGORITHM(Awb, "Awb")

View file

@ -95,7 +95,7 @@ void Lut::prepare(IPAContext &context,
context.activeState.gamma.contrast != context.activeState.knobs.contrast)
updateGammaTable(context);
auto &gains = context.activeState.gains;
auto &gains = context.activeState.awb.gains;
auto &gammaTable = context.activeState.gamma.gammaTable;
const unsigned int gammaTableSize = gammaTable.size();

View file

@ -35,11 +35,14 @@ struct IPAActiveState {
uint8_t level;
} blc;
struct {
struct {
double red;
double green;
double blue;
} gains;
unsigned int temperatureK;
} awb;
static constexpr unsigned int kGammaLookupSize = 1024;
struct {