{"id":21974,"url":"https://patchwork.libcamera.org/api/1.1/patches/21974/?format=json","web_url":"https://patchwork.libcamera.org/patch/21974/","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":"<20241118221618.13953-15-laurent.pinchart@ideasonboard.com>","date":"2024-11-18T22:16:15","name":"[v3,14/17] ipa: libipa: colour: Use Vector and Matrix for linear algebra","commit_ref":null,"pull_url":null,"state":"superseded","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/21974/mbox/","series":[{"id":4798,"url":"https://patchwork.libcamera.org/api/1.1/series/4798/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4798","date":"2024-11-18T22:16:01","name":"Improve linear algebra helpers in libipa","version":3,"mbox":"https://patchwork.libcamera.org/series/4798/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/21974/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/21974/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 C015EC32EA\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 18 Nov 2024 22:17:01 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2D64565EDE;\n\tMon, 18 Nov 2024 23:17:01 +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 4D4B565ED7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Nov 2024 23:16:47 +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 403F16DE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Nov 2024 23:16:30 +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=\"DtUGI5cu\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1731968190;\n\tbh=N9tLch1jQfpIYwSzEcB9jFULCeIarc+8nDnmozhrnrQ=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=DtUGI5cugpLpXFhpicXlvCr2O/sUtsdEFIuqWFZHB0+NlP1BLcQ7H3eqE+TF6qrBe\n\t/nOMCx4mNT92HYjsNEc/pDLAaznmzEuSOSpgZtF+Vjx28QrvELtCWUSN93i8mI0Q/n\n\t4e3uEUcRF4rli9h5OSTDcGlHgQLT85XIKa7gKquA=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[PATCH v3 14/17] ipa: libipa: colour: Use Vector and Matrix for\n\tlinear algebra","Date":"Tue, 19 Nov 2024 00:16:15 +0200","Message-ID":"<20241118221618.13953-15-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.45.2","In-Reply-To":"<20241118221618.13953-1-laurent.pinchart@ideasonboard.com>","References":"<20241118221618.13953-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>\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":["v3","14/17"]}