[{"id":33252,"web_url":"https://patchwork.libcamera.org/comment/33252/","msgid":"<855xlrxq90.fsf@mzamazal-thinkpadp1gen3.tpbc.csb>","date":"2025-02-03T10:43:39","subject":"Re: [PATCH] ipa: libipa: vector: Add element-wise division operator","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Hi Laurent,\n\nthank you for the patch.\n\nLaurent Pinchart <laurent.pinchart@ideasonboard.com> writes:\n\n> Add an operator to divide a scaler by a vector element-wise. Use it in\n> the rkisp1 AWB algorithm to replace manual operation on individual RGB\n> components.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/ipa/libipa/vector.cpp         | 10 ++++++++++\n>  src/ipa/libipa/vector.h           | 11 +++++++++++\n>  src/ipa/rkisp1/algorithms/awb.cpp |  6 +-----\n>  3 files changed, 22 insertions(+), 5 deletions(-)\n>\n> diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp\n> index 8019f8cfdc85..f665813c24d6 100644\n> --- a/src/ipa/libipa/vector.cpp\n> +++ b/src/ipa/libipa/vector.cpp\n> @@ -312,6 +312,16 @@ namespace ipa {\n>   * \\return Product of matrix \\a m and vector \\a v\n>   */\n>\n> +/**\n> + * \\fn Vector<T, Rows> operator/(T scalar, const Vector<T, Rows> &vector)\n> + * \\brief Divide a scalar by a vector element-wise\n> + * \\tparam T Numerical type of the contents of the vector\n> + * \\tparam Rows The number of rows in the vector\n\nI'd rather see here \"The number of elements ...\" but not that important.\n\n> + * \\param scalar The scalar\n> + * \\param vector The vector\n> + * \\return The element-wise division of \\a scaler by the \\a vector\n> + */\n> +\n>  /**\n>   * \\typedef RGB\n>   * \\brief A Vector of 3 elements representing an RGB pixel value\n> diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h\n> index fe33c9d6fbd1..25882616ba8a 100644\n> --- a/src/ipa/libipa/vector.h\n> +++ b/src/ipa/libipa/vector.h\n> @@ -308,6 +308,17 @@ Vector<T, Rows> operator*(const Matrix<T, Rows, Cols> &m, const Vector<T, Cols>\n>  \treturn result;\n>  }\n>\n> +template<typename T, unsigned int Rows>\n> +Vector<T, Rows> operator/(T scalar, const Vector<T, Rows> &vector)\n> +{\n> +\tVector<T, Rows> result;\n> +\n> +\tfor (unsigned int i = 0; i < Rows; i++)\n> +\t\tresult[i] = scalar / vector[i];\n> +\n> +\treturn result;\n> +}\n> +\n>  template<typename T, unsigned int Rows>\n>  bool operator==(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs)\n>  {\n> diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp\n> index cffaa06a22c1..319f7e0b5ef2 100644\n> --- a/src/ipa/rkisp1/algorithms/awb.cpp\n> +++ b/src/ipa/rkisp1/algorithms/awb.cpp\n> @@ -316,11 +316,7 @@ void Awb::process(IPAContext &context,\n>  \t * gain is hardcoded to 1.0. Avoid divisions by zero by clamping the\n>  \t * divisor to a minimum value of 1.0.\n>  \t */\n> -\tRGB<double> gains({\n> -\t\trgbMeans.g() / std::max(rgbMeans.r(), 1.0),\n> -\t\t1.0,\n> -\t\trgbMeans.g() / std::max(rgbMeans.b(), 1.0)\n> -\t});\n> +\tRGB<double> gains = rgbMeans.g() / rgbMeans.max(1.0);\n\nHow about the corner case when rgbMeans.g() < 1.0?  Then gains.g() won't\nbe 1.0 anymore.  Does it matter?\n\n>  \t/*\n>  \t * Clamp the gain values to the hardware, which expresses gains as Q2.8\n>\n> base-commit: 9bc8b6a573a63b8c9f5588cdea6da5ae71abd138\n> --\n> Regards,\n>\n> Laurent Pinchart","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 44FB2C3260\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  3 Feb 2025 10:43:48 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0529168593;\n\tMon,  3 Feb 2025 11:43:48 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D62626858C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  3 Feb 2025 11:43:45 +0100 (CET)","from mail-ej1-f72.google.com (mail-ej1-f72.google.com\n\t[209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-149-5p9EqEdXNymGlP-sWoSfyQ-1; Mon, 03 Feb 2025 05:43:42 -0500","by mail-ej1-f72.google.com with SMTP id\n\ta640c23a62f3a-aaf901a0ef9so364147766b.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 03 Feb 2025 02:43:42 -0800 (PST)","from mzamazal-thinkpadp1gen3.tpbc.csb\n\t(ip-77-48-47-2.net.vodafone.cz. [77.48.47.2])\n\tby smtp.gmail.com with ESMTPSA id\n\ta640c23a62f3a-ab6e49ff774sm741243666b.92.2025.02.03.02.43.39\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 03 Feb 2025 02:43:40 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"Sv8CebMo\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1738579424;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=VuPGDy1N4cYYTxhDR9edYOHQGxFpN4OSsl5gkmezhDs=;\n\tb=Sv8CebMobGpGEB79dPkRSKJ7dBkG7TX0fCL+a82snKhmcQcYpLQkA6O+r/E17qpXlZWI/t\n\t7HDvDR1qqqiV3Vz1eL4Te82SkhY5FKGoQAVZa0G2hn4Lty0YSFzu/sqAdHrVOQzw1HpZNx\n\tjNEr6T9FwuT05SDtX4wD932BSDKK7CQ=","X-MC-Unique":"5p9EqEdXNymGlP-sWoSfyQ-1","X-Mimecast-MFC-AGG-ID":"5p9EqEdXNymGlP-sWoSfyQ","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1738579421; x=1739184221;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=VuPGDy1N4cYYTxhDR9edYOHQGxFpN4OSsl5gkmezhDs=;\n\tb=RGKGJfKoSR41no20z5S7KUB4fYX6seiB+klqtO+fGtyQ0G4dLWiX7puJgRAceuKHen\n\tyyAbv8YhCJOvEDpyhingZt3mcu8XqgYxUBiZeRuIJSrfkAcfFLK5bTbp/wS4IOx8bhXW\n\tLj6aP8kqnwbYbwq9ZDCgb7y166M80emhpXln+nMm7d4wGT3xh+tfjCfv1UwiOwV5Of6s\n\t4v2KVrJ65u+D/mRyjhyO5TIX0VLSQCrTsPq/6yOCidOqPHROPksHh2FU4gfmHFBXVcnP\n\t431tp+l9E3HNe+i0r7kAQroUng9XkTuhBdyQYUudcq6ieH/0XaYIdzNXl0smlmwHXGgn\n\tWWvQ==","X-Gm-Message-State":"AOJu0YxPPl/5HQ+NeDUwjTOI9IYBuO5VJMcVf3WDvYD0+6Lmb5+6musO\n\tllV6XncBaJ1/zof5PapGzdgZU82lxQhbA5WXiNMZdUXWIHAWW3w/SjAI7xxNdxdjRCGsJQGkFpt\n\tD6stB6PU7YI4mKiW5Q4sOH3I52joYy5JlwCGx34E6pj7LIcP3Y4aEZ+35A3QFJNu/vPElFapOvL\n\tnJJ3A4wsBHydFm9aA20J73iGWX56p3fKCSZBifJY/mo+Sev0QhRIZUypg=","X-Gm-Gg":"ASbGncvqN/ZRpnYVr7yy5doRlyNABtw+H9PIxDvWXNewFhebcbXc9qB6Ckca/G3bkSN\n\toSjjnhUgfA7oitdSdPrGzSWHNYu37B2szpv23V1K9iG5qGyFkTWiQWW+8Arp9SaL4LL4jOf6MM8\n\tJyMuhU/1+9XuASES283+3PsSRgYeLVhtT6zN4Wqr/w1ginQ8TXFs01z+jl6DcIhBaf6nQK3L8Kf\n\t/VYErWyYsvodyJWHcer0Vh4rqMs8bS904ORRvNLJroucfGQeIbjakwSz0HphIYuaa9J9ZlcmabQ\n\thdU2XwTBz8sGnXUVtiUkQvwki8hEvU3c6ax3U6+BUF9yuGVIHZFzJZL7ww==","X-Received":["by 2002:a17:907:9413:b0:ab6:f68c:746e with SMTP id\n\ta640c23a62f3a-ab6f68c7570mr1879600866b.41.1738579420978; \n\tMon, 03 Feb 2025 02:43:40 -0800 (PST)","by 2002:a17:907:9413:b0:ab6:f68c:746e with SMTP id\n\ta640c23a62f3a-ab6f68c7570mr1879597266b.41.1738579420533; \n\tMon, 03 Feb 2025 02:43:40 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IEKH5ZKOxa7fI6XutFc/4JOTqR8QFnnsKsk0GmVaYzlqrHuU4qZAAdWN2HxeMiWVhgCXU0q4g==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH] ipa: libipa: vector: Add element-wise division operator","In-Reply-To":"<20250202235634.3776-1-laurent.pinchart@ideasonboard.com>\n\t(Laurent Pinchart's message of \"Mon, 3 Feb 2025 01:56:34 +0200\")","References":"<20250202235634.3776-1-laurent.pinchart@ideasonboard.com>","Date":"Mon, 03 Feb 2025 11:43:39 +0100","Message-ID":"<855xlrxq90.fsf@mzamazal-thinkpadp1gen3.tpbc.csb>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"chHvqZp4D9XYF0KlWDrC8JjZ0UI_-mgl3Oxa08apqF4_1738579421","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":33350,"web_url":"https://patchwork.libcamera.org/comment/33350/","msgid":"<20250213215851.GC27260@pendragon.ideasonboard.com>","date":"2025-02-13T21:58:51","subject":"Re: [PATCH] ipa: libipa: vector: Add element-wise division operator","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Mon, Feb 03, 2025 at 11:43:39AM +0100, Milan Zamazal wrote:\n> Hi Laurent,\n> \n> thank you for the patch.\n> \n> Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:\n> \n> > Add an operator to divide a scaler by a vector element-wise. Use it in\n> > the rkisp1 AWB algorithm to replace manual operation on individual RGB\n> > components.\n> >\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  src/ipa/libipa/vector.cpp         | 10 ++++++++++\n> >  src/ipa/libipa/vector.h           | 11 +++++++++++\n> >  src/ipa/rkisp1/algorithms/awb.cpp |  6 +-----\n> >  3 files changed, 22 insertions(+), 5 deletions(-)\n> >\n> > diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp\n> > index 8019f8cfdc85..f665813c24d6 100644\n> > --- a/src/ipa/libipa/vector.cpp\n> > +++ b/src/ipa/libipa/vector.cpp\n> > @@ -312,6 +312,16 @@ namespace ipa {\n> >   * \\return Product of matrix \\a m and vector \\a v\n> >   */\n> >\n> > +/**\n> > + * \\fn Vector<T, Rows> operator/(T scalar, const Vector<T, Rows> &vector)\n> > + * \\brief Divide a scalar by a vector element-wise\n> > + * \\tparam T Numerical type of the contents of the vector\n> > + * \\tparam Rows The number of rows in the vector\n> \n> I'd rather see here \"The number of elements ...\" but not that important.\n> \n> > + * \\param scalar The scalar\n> > + * \\param vector The vector\n> > + * \\return The element-wise division of \\a scaler by the \\a vector\n> > + */\n> > +\n> >  /**\n> >   * \\typedef RGB\n> >   * \\brief A Vector of 3 elements representing an RGB pixel value\n> > diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h\n> > index fe33c9d6fbd1..25882616ba8a 100644\n> > --- a/src/ipa/libipa/vector.h\n> > +++ b/src/ipa/libipa/vector.h\n> > @@ -308,6 +308,17 @@ Vector<T, Rows> operator*(const Matrix<T, Rows, Cols> &m, const Vector<T, Cols>\n> >  \treturn result;\n> >  }\n> >\n> > +template<typename T, unsigned int Rows>\n> > +Vector<T, Rows> operator/(T scalar, const Vector<T, Rows> &vector)\n> > +{\n> > +\tVector<T, Rows> result;\n> > +\n> > +\tfor (unsigned int i = 0; i < Rows; i++)\n> > +\t\tresult[i] = scalar / vector[i];\n> > +\n> > +\treturn result;\n> > +}\n> > +\n> >  template<typename T, unsigned int Rows>\n> >  bool operator==(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs)\n> >  {\n> > diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp\n> > index cffaa06a22c1..319f7e0b5ef2 100644\n> > --- a/src/ipa/rkisp1/algorithms/awb.cpp\n> > +++ b/src/ipa/rkisp1/algorithms/awb.cpp\n> > @@ -316,11 +316,7 @@ void Awb::process(IPAContext &context,\n> >  \t * gain is hardcoded to 1.0. Avoid divisions by zero by clamping the\n> >  \t * divisor to a minimum value of 1.0.\n> >  \t */\n> > -\tRGB<double> gains({\n> > -\t\trgbMeans.g() / std::max(rgbMeans.r(), 1.0),\n> > -\t\t1.0,\n> > -\t\trgbMeans.g() / std::max(rgbMeans.b(), 1.0)\n> > -\t});\n> > +\tRGB<double> gains = rgbMeans.g() / rgbMeans.max(1.0);\n> \n> How about the corner case when rgbMeans.g() < 1.0?  Then gains.g() won't\n> be 1.0 anymore.  Does it matter?\n\nThat's a good point. I think I'll drop this patch for now.\n\n> >  \t/*\n> >  \t * Clamp the gain values to the hardware, which expresses gains as Q2.8\n> >\n> > base-commit: 9bc8b6a573a63b8c9f5588cdea6da5ae71abd138","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 6F27ABD7D8\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 13 Feb 2025 21:59:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 34DAF68640;\n\tThu, 13 Feb 2025 22:59:04 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 29E5A6185F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Feb 2025 22:59:03 +0100 (CET)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3B9BD6AF;\n\tThu, 13 Feb 2025 22:57:44 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"JZrCPuCR\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1739483864;\n\tbh=UZ/wIXii6z2pFLWvv/XCU//NwXERwd2oCSraGK73cV0=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=JZrCPuCRQGwyNkUtZ8S6a8TvSA2BcyV97VZKVfyexImWBGXtRslBnr76myFDexSqT\n\tfI9u/rJpqDEiVuxtSMlWtqdHTP7M7xR2bDta1PtiQ/0mLR26kE/RP6ZIQsNo/NVERm\n\t07EctPWPy10x5DbfWNFi2io/xhfutd/YDxR2xszs=","Date":"Thu, 13 Feb 2025 23:58:51 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Milan Zamazal <mzamazal@redhat.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH] ipa: libipa: vector: Add element-wise division operator","Message-ID":"<20250213215851.GC27260@pendragon.ideasonboard.com>","References":"<20250202235634.3776-1-laurent.pinchart@ideasonboard.com>\n\t<855xlrxq90.fsf@mzamazal-thinkpadp1gen3.tpbc.csb>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<855xlrxq90.fsf@mzamazal-thinkpadp1gen3.tpbc.csb>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]