From patchwork Sun Feb 2 23:56:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 22721 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 E77BCC0F1B for ; Sun, 2 Feb 2025 23:56:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F055868576; Mon, 3 Feb 2025 00:56:39 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="clZMBHvg"; 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 EEF2361876 for ; Mon, 3 Feb 2025 00:56:37 +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 77D6A227 for ; Mon, 3 Feb 2025 00:55:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1738540526; bh=by8ucSt7EqFqhlnCLqxZWVt9KdRo9gwU078KUcOkFV4=; h=From:To:Subject:Date:From; b=clZMBHvg6QWK8pzYyyS7YCAcxVQaPIoNMsQ2BarmadHWNNpzM4CAvq1jpc5bzPYpq fcgNgTfQsC76SDGKQCP90LwxRmGWQOugmvAJPFlnQQHGlYI1HjscidRMsCDV2Z9XyO N/bUY4nmK7dZgPhl/QpUrj8BxOdcmsvExgCwkRI8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH] ipa: libipa: vector: Add element-wise division operator Date: Mon, 3 Feb 2025 01:56:34 +0200 Message-ID: <20250202235634.3776-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.45.3 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" Add an operator to divide a scaler by a vector element-wise. Use it in the rkisp1 AWB algorithm to replace manual operation on individual RGB components. Signed-off-by: Laurent Pinchart --- src/ipa/libipa/vector.cpp | 10 ++++++++++ src/ipa/libipa/vector.h | 11 +++++++++++ src/ipa/rkisp1/algorithms/awb.cpp | 6 +----- 3 files changed, 22 insertions(+), 5 deletions(-) base-commit: 9bc8b6a573a63b8c9f5588cdea6da5ae71abd138 -- Regards, Laurent Pinchart diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp index 8019f8cfdc85..f665813c24d6 100644 --- a/src/ipa/libipa/vector.cpp +++ b/src/ipa/libipa/vector.cpp @@ -312,6 +312,16 @@ namespace ipa { * \return Product of matrix \a m and vector \a v */ +/** + * \fn Vector operator/(T scalar, const Vector &vector) + * \brief Divide a scalar by a vector element-wise + * \tparam T Numerical type of the contents of the vector + * \tparam Rows The number of rows in the vector + * \param scalar The scalar + * \param vector The vector + * \return The element-wise division of \a scaler by the \a vector + */ + /** * \typedef RGB * \brief A Vector of 3 elements representing an RGB pixel value diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h index fe33c9d6fbd1..25882616ba8a 100644 --- a/src/ipa/libipa/vector.h +++ b/src/ipa/libipa/vector.h @@ -308,6 +308,17 @@ Vector operator*(const Matrix &m, const Vector return result; } +template +Vector operator/(T scalar, const Vector &vector) +{ + Vector result; + + for (unsigned int i = 0; i < Rows; i++) + result[i] = scalar / vector[i]; + + return result; +} + template bool operator==(const Vector &lhs, const Vector &rhs) { diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index cffaa06a22c1..319f7e0b5ef2 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -316,11 +316,7 @@ void Awb::process(IPAContext &context, * gain is hardcoded to 1.0. Avoid divisions by zero by clamping the * divisor to a minimum value of 1.0. */ - RGB gains({ - rgbMeans.g() / std::max(rgbMeans.r(), 1.0), - 1.0, - rgbMeans.g() / std::max(rgbMeans.b(), 1.0) - }); + RGB gains = rgbMeans.g() / rgbMeans.max(1.0); /* * Clamp the gain values to the hardware, which expresses gains as Q2.8