{"id":22010,"url":"https://patchwork.libcamera.org/api/1.1/patches/22010/?format=json","web_url":"https://patchwork.libcamera.org/patch/22010/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20241119121928.30939-13-laurent.pinchart@ideasonboard.com>","date":"2024-11-19T12:19:23","name":"[v4,12/17] ipa: ipu3: awb: Replace Awb::RGB class with ipa::RGB","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"48de9c8d46afecd26ad9452021ec0768c2d33126","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/22010/mbox/","series":[{"id":4804,"url":"https://patchwork.libcamera.org/api/1.1/series/4804/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4804","date":"2024-11-19T12:19:11","name":"Improve linear algebra helpers in libipa","version":4,"mbox":"https://patchwork.libcamera.org/series/4804/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/22010/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/22010/checks/","tags":{},"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 5D8A2C32F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 19 Nov 2024 12:20:21 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C807D65F2C;\n\tTue, 19 Nov 2024 13:20:20 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2E23165F2C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 19 Nov 2024 13:20:15 +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 8068A193C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 19 Nov 2024 13:19:57 +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=\"v4S9jlkM\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1732018797;\n\tbh=x92FWgz5sWXwcAsuTW8GFvy7arSFrnaSK63WkfOYu3I=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=v4S9jlkM887IK+5XdTDr9ZaHA8jmeTWEsGDsKMlBBOMxBFJfTSoRl5vU5eD2d7WrT\n\tZDRTb9btVUxEcK4mM3ZksrlsTMZVR66eH2qxxiutsD8LW7ynPxvfcL+sa5mgZ5gZRw\n\ttxRkRVckiTK6DvrNkbLNbJ9isy5ekh0dlGTFBIHI=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[PATCH v4 12/17] ipa: ipu3: awb: Replace Awb::RGB class with\n\tipa::RGB","Date":"Tue, 19 Nov 2024 14:19:23 +0200","Message-ID":"<20241119121928.30939-13-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.45.2","In-Reply-To":"<20241119121928.30939-1-laurent.pinchart@ideasonboard.com>","References":"<20241119121928.30939-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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>"},"content":"Now that libipa has a generic RGB class, replaces the local\nimplementation from the IPU3 AWB algorithm.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\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(-)","diff":"diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp\nindex 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\ndiff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h\nindex 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_;\n \n","prefixes":["v4","12/17"]}