libcamera: software_isp: Fix CCM multiplication

A colour correction matrix (CCM) is applied like this to an RGB pixel
vector P:

  CCM * P

White balance must be applied before CCM.  If CCM is used, software ISP
makes a combined matrix by multiplying the CCM by a white balance gains
CCM-like matrix (WBG).  The multiplication should be as follows to do it
in the correct order:

  CCM * (WBG * P) = (CCM * WBG) * P

The multiplication order in Lut software ISP algorithm is reversed,
resulting in colour casts.  Let's fix the order.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Milan Zamazal 2025-04-14 19:32:44 +02:00 committed by Kieran Bingham
parent 78d9f7bb75
commit 026ed62739

View file

@ -122,7 +122,7 @@ void Lut::prepare(IPAContext &context,
Matrix<float, 3, 3> gainCcm = { { gains.r(), 0, 0, Matrix<float, 3, 3> gainCcm = { { gains.r(), 0, 0,
0, gains.g(), 0, 0, gains.g(), 0,
0, 0, gains.b() } }; 0, 0, gains.b() } };
auto ccm = gainCcm * context.activeState.ccm.ccm; auto ccm = context.activeState.ccm.ccm * gainCcm;
auto &red = params->redCcm; auto &red = params->redCcm;
auto &green = params->greenCcm; auto &green = params->greenCcm;
auto &blue = params->blueCcm; auto &blue = params->blueCcm;