From patchwork Mon Nov 18 22:16:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 21976 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 5E4CEC32EA for ; Mon, 18 Nov 2024 22:17:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D043F65EE3; Mon, 18 Nov 2024 23:17:04 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="rwuWEl2r"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 16B71658F7 for ; Mon, 18 Nov 2024 23:16:50 +0100 (CET) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0353E8DB for ; Mon, 18 Nov 2024 23:16:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1731968193; bh=RNPG53cFIFiGz2WIvN4/531MeaV0mTQfhxjMRxaZ+DA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rwuWEl2r96rXNTZJGQ1PQrpXFw5oncuhMBA3e2Vrf9x/f6lLPd0lEM3pfFv0BP7Yj jKYVYmz11dGUvYx7kMDrmCZqJzvu2qHH3WmkcbPkAf1vEPAz3igLWBpNmzosUfjW8l BXKmWxSwWjBnaMzLX/ekiUUNMobX2pGJKZ/+QPdo= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH v3 16/17] ipa: rkisp1: awb: Use Vector and Matrix for linear algebra Date: Tue, 19 Nov 2024 00:16:17 +0200 Message-ID: <20241118221618.13953-17-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241118221618.13953-1-laurent.pinchart@ideasonboard.com> References: <20241118221618.13953-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 --- Changes since v2: - Split colour temperature estimation to separate patch - Update commit message Changes since v1: - Adapt to Vector::normalize() being dropped --- 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 c330feff9f5d..26d7b8138f17 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