{"id":22012,"url":"https://patchwork.libcamera.org/api/1.1/patches/22012/?format=json","web_url":"https://patchwork.libcamera.org/patch/22012/","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-15-laurent.pinchart@ideasonboard.com>","date":"2024-11-19T12:19:25","name":"[v4,14/17] ipa: libipa: colour: Use Vector and Matrix for linear algebra","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"28f8d99061a337c4501ba571c58378c7245a1e41","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/22012/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/22012/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/22012/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 D2316C32F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 19 Nov 2024 12:20:28 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 46BD565F3B;\n\tTue, 19 Nov 2024 13:20:28 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EFB9265F38\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 19 Nov 2024 13:20:21 +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 1DBB91A4A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 19 Nov 2024 13:20:04 +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=\"k/s2eCss\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1732018804;\n\tbh=0iZYBaR+o5G70ZHH7Vi/NBicWWhhajdjTWCDkTGSmBI=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=k/s2eCss3cIqK0mDBZGafHYCb2U1Wndw7mNYVxFBY40E0gbq37OssGQX3zVS2ofqN\n\tDUlEmUNNIwDh0Ufzi1b8JtXsvr5YNrAuaIGCbJ3YdC6YUmX60X7CQmkU6pixem5tNG\n\tFEMLkv8p9R09LvbF8CvXP1N8vmHxKohJLXSKwTJg=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[PATCH v4 14/17] ipa: libipa: colour: Use Vector and Matrix for\n\tlinear algebra","Date":"Tue, 19 Nov 2024 14:19:25 +0200","Message-ID":"<20241119121928.30939-15-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":"Replace the manual vector and matrix calculations with usage of the\nVector and Matrix classes. This simplifies the code and improves\nreadability.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n---\n src/ipa/libipa/colours.cpp | 26 +++++++++++++++++---------\n 1 file changed, 17 insertions(+), 9 deletions(-)","diff":"diff --git a/src/ipa/libipa/colours.cpp b/src/ipa/libipa/colours.cpp\nindex 6c597093ddf8..97124cf460d4 100644\n--- a/src/ipa/libipa/colours.cpp\n+++ b/src/ipa/libipa/colours.cpp\n@@ -31,7 +31,11 @@ namespace ipa {\n  */\n double rec601LuminanceFromRGB(const RGB<double> &rgb)\n {\n-\treturn (rgb.r() * .299) + (rgb.g() * .587) + (rgb.b() * .114);\n+\tstatic const Vector<double, 3> rgb2y{{\n+\t\t0.299, 0.587, 0.114\n+\t}};\n+\n+\treturn rgb.dot(rgb2y);\n }\n \n /**\n@@ -54,17 +58,21 @@ double rec601LuminanceFromRGB(const RGB<double> &rgb)\n  */\n uint32_t estimateCCT(const RGB<double> &rgb)\n {\n-\t/* Convert the RGB values to CIE tristimulus values (XYZ) */\n-\tdouble X = (-0.14282) * rgb.r() + (1.54924) * rgb.g() + (-0.95641) * rgb.b();\n-\tdouble Y = (-0.32466) * rgb.r() + (1.57837) * rgb.g() + (-0.73191) * rgb.b();\n-\tdouble Z = (-0.68202) * rgb.r() + (0.77073) * rgb.g() + (0.56332) * rgb.b();\n+\t/*\n+\t * Convert the RGB values to CIE tristimulus values (XYZ) and divide by\n+\t * the sum of X, Y and Z to calculate the CIE xy chromaticity.\n+\t */\n+\tstatic const Matrix<double, 3, 3> rgb2xyz({\n+\t\t-0.14282, 1.54924, -0.95641,\n+\t\t-0.32466, 1.57837, -0.73191,\n+\t\t-0.68202, 0.77073,  0.56332\n+\t});\n \n-\t/* Calculate the normalized chromaticity values */\n-\tdouble x = X / (X + Y + Z);\n-\tdouble y = Y / (X + Y + Z);\n+\tVector<double, 3> xyz = rgb2xyz * rgb;\n+\txyz /= xyz.sum();\n \n \t/* Calculate CCT */\n-\tdouble n = (x - 0.3320) / (0.1858 - y);\n+\tdouble n = (xyz.x() - 0.3320) / (0.1858 - xyz.y());\n \treturn 449 * n * n * n + 3525 * n * n + 6823.3 * n + 5520.33;\n }\n \n","prefixes":["v4","14/17"]}