[{"id":32265,"web_url":"https://patchwork.libcamera.org/comment/32265/","msgid":"<878qtfh5uu.fsf@redhat.com>","date":"2024-11-19T10:31:53","subject":"Re: [PATCH v3 12/17] ipa: ipu3: awb: Replace Awb::RGB class with\n\tipa::RGB","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:\n\n> Now that libipa has a generic RGB class, replaces the local\n> implementation from the IPU3 AWB algorithm.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\n> ---\n>  src/ipa/ipu3/algorithms/awb.cpp | 37 ++++++++++++++++++---------------\n>  src/ipa/ipu3/algorithms/awb.h   | 18 +++-------------\n>  2 files changed, 23 insertions(+), 32 deletions(-)\n>\n> diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp\n> index c3c8b0740f36..7c6bff09147c 100644\n> --- a/src/ipa/ipu3/algorithms/awb.cpp\n> +++ b/src/ipa/ipu3/algorithms/awb.cpp\n> @@ -309,15 +309,18 @@ void Awb::generateZones()\n>  \tzones_.clear();\n>  \n>  \tfor (unsigned int i = 0; i < kAwbStatsSizeX * kAwbStatsSizeY; i++) {\n> -\t\tRGB zone;\n>  \t\tdouble counted = awbStats_[i].counted;\n>  \t\tif (counted >= cellsPerZoneThreshold_) {\n> -\t\t\tzone.G = awbStats_[i].sum.green / counted;\n> -\t\t\tif (zone.G >= kMinGreenLevelInZone) {\n> -\t\t\t\tzone.R = awbStats_[i].sum.red / counted;\n> -\t\t\t\tzone.B = awbStats_[i].sum.blue / counted;\n> +\t\t\tRGB<double> zone{{\n> +\t\t\t\tstatic_cast<double>(awbStats_[i].sum.red),\n> +\t\t\t\tstatic_cast<double>(awbStats_[i].sum.green),\n> +\t\t\t\tstatic_cast<double>(awbStats_[i].sum.blue)\n> +\t\t\t}};\n> +\n> +\t\t\tzone /= counted;\n> +\n> +\t\t\tif (zone.g() >= kMinGreenLevelInZone)\n>  \t\t\t\tzones_.push_back(zone);\n> -\t\t\t}\n>  \t\t}\n>  \t}\n>  }\n> @@ -384,32 +387,32 @@ void Awb::awbGreyWorld()\n>  \t * consider some variations, such as normalising all the zones first, or\n>  \t * doing an L2 average etc.\n>  \t */\n> -\tstd::vector<RGB> &redDerivative(zones_);\n> -\tstd::vector<RGB> blueDerivative(redDerivative);\n> +\tstd::vector<RGB<double>> &redDerivative(zones_);\n> +\tstd::vector<RGB<double>> blueDerivative(redDerivative);\n>  \tstd::sort(redDerivative.begin(), redDerivative.end(),\n> -\t\t  [](RGB const &a, RGB const &b) {\n> -\t\t\t  return a.G * b.R < b.G * a.R;\n> +\t\t  [](RGB<double> const &a, RGB<double> const &b) {\n> +\t\t\t  return a.g() * b.r() < b.g() * a.r();\n>  \t\t  });\n>  \tstd::sort(blueDerivative.begin(), blueDerivative.end(),\n> -\t\t  [](RGB const &a, RGB const &b) {\n> -\t\t\t  return a.G * b.B < b.G * a.B;\n> +\t\t  [](RGB<double> const &a, RGB<double> const &b) {\n> +\t\t\t  return a.g() * b.b() < b.g() * a.b();\n>  \t\t  });\n>  \n>  \t/* Average the middle half of the values. */\n>  \tint discard = redDerivative.size() / 4;\n>  \n> -\tRGB sumRed(0, 0, 0);\n> -\tRGB sumBlue(0, 0, 0);\n> +\tRGB<double> sumRed{ 0.0 };\n> +\tRGB<double> sumBlue{ 0.0 };\n>  \tfor (auto ri = redDerivative.begin() + discard,\n>  \t\t  bi = blueDerivative.begin() + discard;\n>  \t     ri != redDerivative.end() - discard; ri++, bi++)\n>  \t\tsumRed += *ri, sumBlue += *bi;\n>  \n> -\tdouble redGain = sumRed.G / (sumRed.R + 1),\n> -\t       blueGain = sumBlue.G / (sumBlue.B + 1);\n> +\tdouble redGain = sumRed.g() / (sumRed.r() + 1),\n> +\t       blueGain = sumBlue.g() / (sumBlue.b() + 1);\n>  \n>  \t/* Color temperature is not relevant in Grey world but still useful to estimate it :-) */\n> -\tasyncResults_.temperatureK = estimateCCT(sumRed.R, sumRed.G, sumBlue.B);\n> +\tasyncResults_.temperatureK = estimateCCT(sumRed.r(), sumRed.g(), sumBlue.b());\n>  \n>  \t/*\n>  \t * Gain values are unsigned integer value ranging [0, 8) with 13 bit\n> diff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h\n> index a13c49acc1fe..1916990a5364 100644\n> --- a/src/ipa/ipu3/algorithms/awb.h\n> +++ b/src/ipa/ipu3/algorithms/awb.h\n> @@ -13,6 +13,8 @@\n>  \n>  #include <libcamera/geometry.h>\n>  \n> +#include \"libipa/vector.h\"\n> +\n>  #include \"algorithm.h\"\n>  \n>  namespace libcamera {\n> @@ -48,20 +50,6 @@ public:\n>  \t\t     ControlList &metadata) override;\n>  \n>  private:\n> -\t/* \\todo Make these structs available to all the ISPs ? */\n> -\tstruct RGB {\n> -\t\tRGB(double _R = 0, double _G = 0, double _B = 0)\n> -\t\t\t: R(_R), G(_G), B(_B)\n> -\t\t{\n> -\t\t}\n> -\t\tdouble R, G, B;\n> -\t\tRGB &operator+=(RGB const &other)\n> -\t\t{\n> -\t\t\tR += other.R, G += other.G, B += other.B;\n> -\t\t\treturn *this;\n> -\t\t}\n> -\t};\n> -\n>  \tstruct AwbStatus {\n>  \t\tdouble temperatureK;\n>  \t\tdouble redGain;\n> @@ -78,7 +66,7 @@ private:\n>  \tstatic constexpr uint16_t threshold(float value);\n>  \tstatic constexpr uint16_t gainValue(double gain);\n>  \n> -\tstd::vector<RGB> zones_;\n> +\tstd::vector<RGB<double>> zones_;\n>  \tAccumulator awbStats_[kAwbStatsSizeX * kAwbStatsSizeY];\n>  \tAwbStatus asyncResults_;","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 205FDC32F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 19 Nov 2024 10:32:04 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3C71065EF2;\n\tTue, 19 Nov 2024 11:32:03 +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 605C06589D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 19 Nov 2024 11:32:01 +0100 (CET)","from mail-wm1-f70.google.com (mail-wm1-f70.google.com\n\t[209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-219-yKuSKmzaOGe4vDS7OCGk1g-1; Tue, 19 Nov 2024 05:31:57 -0500","by mail-wm1-f70.google.com with SMTP id\n\t5b1f17b1804b1-4315b7b0c16so5871875e9.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 19 Nov 2024 02:31:57 -0800 (PST)","from nuthatch ([2a00:102a:400a:489a:34bf:5bf1:e776:7185])\n\tby smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-3823f72441bsm8020281f8f.101.2024.11.19.02.31.54\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 19 Nov 2024 02:31:55 -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=\"aDcsdCLB\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1732012320;\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=P10cP9IfZdhj1jmgzO2eCTq1CJoDshyoWSyB7V64pGQ=;\n\tb=aDcsdCLB+jjaI3I7ntAd+Dtam7qzuqPOvbN+x7Mw6+uOh+erIJ9rT1DQKWKPpggoNzOl6T\n\tZS41IdG483yj0FBZvLkz9yI4U+7VLA0p4Yxsc50WeqU4+8ny1cnsz/WbNONzpygE9oMUUV\n\taMg5KjW6O1sd+tQYrKOQFVCJmZcr7eE=","X-MC-Unique":"yKuSKmzaOGe4vDS7OCGk1g-1","X-Mimecast-MFC-AGG-ID":"yKuSKmzaOGe4vDS7OCGk1g","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1732012316; x=1732617116;\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=P10cP9IfZdhj1jmgzO2eCTq1CJoDshyoWSyB7V64pGQ=;\n\tb=hGQQee81UXOxVNBv0USWySx5xftZ54iSKxn1/eNew2YCriF+j5NPiwxv1QQOcV1yLI\n\tA7pY0UqBp79i4hjnV8dSoHOmONXnqWa+GYVYbt5G2dKuMcUM2X4R0NJDpvXTBjxeQwln\n\t1gNyjGjk5iBq2ZUoZCQ4IEkm1D0TyUUZeUU9qfR2zshan1MngRmBZCAAdrJ3no0rJ340\n\t2AlPeKsXGQ4toAKVWKiIohkwcFnoyDv+vfViI6Bq7BJ8DYhKdTRTNmI+1LjVRKOCk/qe\n\tcx9vK0OLLY3jiT5Pqzotqj2DU7cvnNMfg4DbU6gQMYNh8m2WaZkNC4NzkfRb0GstirHI\n\tUNJQ==","X-Gm-Message-State":"AOJu0Yybhf4BZh5+nBu7OEZ9X94/qnLm5tJro7ubF1XGPyxC5CPtFdJ+\n\tmpzB/0P1rY9ykZNzRs+mfF9P3iD6RAqGeyHjxsi3kXSMPxsQBXaZcpb3OF6Zs2ODmNz+tLN99ql\n\tBKrk18usQbMDj1mjKcZYk+k2OfXZgQOCK//XS2cdWn7o5dCmtY4cYTlykg7aQz0t+bSDsUJLrNd\n\t7tM2MjFqg0ZV+/DOKLIi/U2PzzSlpTdfegiwo4VPW1wpEFiItV7yj6TvM=","X-Received":["by 2002:a05:600c:3143:b0:428:f0c2:ef4a with SMTP id\n\t5b1f17b1804b1-432df7423d8mr134127485e9.13.1732012315897; \n\tTue, 19 Nov 2024 02:31:55 -0800 (PST)","by 2002:a05:600c:3143:b0:428:f0c2:ef4a with SMTP id\n\t5b1f17b1804b1-432df7423d8mr134127175e9.13.1732012315449; \n\tTue, 19 Nov 2024 02:31:55 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IF9niXU0V/Uw6n9Irzyt/1YYR3q5Qj8GlWB6+b2D0A9EBDJgq3gIgnNu9Q9XuaIwz24zpiX8w==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v3 12/17] ipa: ipu3: awb: Replace Awb::RGB class with\n\tipa::RGB","In-Reply-To":"<20241118221618.13953-13-laurent.pinchart@ideasonboard.com>\n\t(Laurent Pinchart's message of \"Tue, 19 Nov 2024 00:16:13 +0200\")","References":"<20241118221618.13953-1-laurent.pinchart@ideasonboard.com>\n\t<20241118221618.13953-13-laurent.pinchart@ideasonboard.com>","Date":"Tue, 19 Nov 2024 11:31:53 +0100","Message-ID":"<878qtfh5uu.fsf@redhat.com>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"aMbuDZvi0-PGLu5OYSV8DkIN0PvycxyAY_55EaPfmQ0_1732012316","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>"}}]