From be22d4aa77befb8b60ceb3607c2555959ac126ee Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sun, 4 Sep 2022 08:27:38 +0300 Subject: ipa: rkisp1: awb: Use Vector and Matrix for linear algebra Replace the manual vector and matrix calculations with usage of the Vector and Matrix classes. This simplifies the code and improves readability. Signed-off-by: Laurent Pinchart Reviewed-by: Milan Zamazal --- src/ipa/rkisp1/algorithms/awb.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index c330feff..26d7b813 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -203,9 +203,11 @@ void Awb::process(IPAContext &context, }}; } else { /* Get the YCbCr mean values */ - double yMean = awb->awb_mean[0].mean_y_or_g; - double cbMean = awb->awb_mean[0].mean_cb_or_b; - double crMean = awb->awb_mean[0].mean_cr_or_r; + Vector yuvMeans({ + static_cast(awb->awb_mean[0].mean_y_or_g), + static_cast(awb->awb_mean[0].mean_cb_or_b), + static_cast(awb->awb_mean[0].mean_cr_or_r) + }); /* * Convert from YCbCr to RGB. @@ -219,14 +221,16 @@ void Awb::process(IPAContext &context, * [1,1636, -0,4045, -0,7949] * [1,1636, 1,9912, -0,0250]] */ - yMean -= 16; - cbMean -= 128; - crMean -= 128; - rgbMeans = {{ - 1.1636 * yMean - 0.0623 * cbMean + 1.6008 * crMean, - 1.1636 * yMean - 0.4045 * cbMean - 0.7949 * crMean, - 1.1636 * yMean + 1.9912 * cbMean - 0.0250 * crMean - }}; + static const Matrix yuv2rgbMatrix({ + 1.1636, -0.0623, 1.6008, + 1.1636, -0.4045, -0.7949, + 1.1636, 1.9912, -0.0250 + }); + static const Vector yuv2rgbOffset({ + 16, 128, 128 + }); + + rgbMeans = yuv2rgbMatrix * (yuvMeans - yuv2rgbOffset); /* * Due to hardware rounding errors in the YCbCr means, the -- cgit v1.2.1