{"id":26646,"url":"https://patchwork.libcamera.org/api/patches/26646/?format=json","web_url":"https://patchwork.libcamera.org/patch/26646/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20260506221758.880117-1-devve.3@gmail.com>","date":"2026-05-06T22:17:57","name":"[v2] test: ipa: libipa: Add CCM row-sum validation test","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"2a1dfe0c28955f2f7cd242968cf52fdd2511a821","submitter":{"id":271,"url":"https://patchwork.libcamera.org/api/people/271/?format=json","name":"devve","email":"devve.3@gmail.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/26646/mbox/","series":[{"id":5912,"url":"https://patchwork.libcamera.org/api/series/5912/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5912","date":"2026-05-06T22:17:57","name":"[v2] test: ipa: libipa: Add CCM row-sum validation test","version":2,"mbox":"https://patchwork.libcamera.org/series/5912/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/26646/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/26646/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 8F3DABDCB5\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  6 May 2026 22:18:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 83A8063022;\n\tThu,  7 May 2026 00:18:02 +0200 (CEST)","from mail-wr1-x429.google.com (mail-wr1-x429.google.com\n\t[IPv6:2a00:1450:4864:20::429])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5CC0E6301A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  7 May 2026 00:18:01 +0200 (CEST)","by mail-wr1-x429.google.com with SMTP id\n\tffacd0b85a97d-44c4cc7c1cfso140116f8f.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 06 May 2026 15:18:01 -0700 (PDT)","from dexps.speedport.ip\n\t(p200300eda74453cf3cf3f7929e513b94.dip0.t-ipconnect.de.\n\t[2003:ed:a744:53cf:3cf3:f792:9e51:3b94])\n\tby smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-450524833e1sm15709388f8f.2.2026.05.06.15.18.00\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 06 May 2026 15:18:00 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"HzP9EGjn\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=gmail.com; s=20251104; t=1778105881; x=1778710681;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=iuKxaCdLNK1rpp1md2t0A+vNdZQgr0zrLCF8pVdKmlk=;\n\tb=HzP9EGjnAb17i0l7vXAKldiFblIqOyPyYvu60lser9iaZhMzRNuKC/LGAVqZx+2cVs\n\t1cqkBTQ0qroMF8OAFmjkgt1hq1m9DKwRYaXZsm3aZGOBzY+eZvnBgXi2SQcWA0EcX7r+\n\t6a1izcUPUj9hAh05eTmPk1PBH4+IWnQ+xaqsmoVznjLX+VBo9HQGn3lRRfdBgbcyZNQh\n\tUbvbtB/wn/i+Tu4EAtVkfR9btjD8+IKeAmEw7Ol/eGGnjvBvs00iKC9Xkk3hqcBOEU9Y\n\tTKQJGBXEmeZ/I+3PKKnb9TorAQWBe3o7j+1Ahz5R6jmcHvqwyaw0TscsKjOF/sTiCcr0\n\tnu2w==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20251104; t=1778105881; x=1778710681;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n\t:to:cc:subject:date:message-id:reply-to;\n\tbh=iuKxaCdLNK1rpp1md2t0A+vNdZQgr0zrLCF8pVdKmlk=;\n\tb=BwxVJ1dXynKAPhCnKbKeoT8Xwtbng/WSuVNhGH2qAtIAAwuN8rVXTjG8qwqfUEMPBG\n\tP5fEcZj/UdUxB9kVySp8yvy8u1vda4FFXTXzcW+g7aQ+0X0v3RTwrElHFSeq3eEeHKgZ\n\tgIx+WsGK/t6EjNv9a2EgWD67GR1sCrDEoPKTP92exjayW8Ds1LxO3ju5Yp7kk3RPGg1Q\n\t6TCIflBUOR8RBhflfzVGoeFIEvKujOo8EOAW6XL+g8BBLI91IN2diOL2hvcsY7hIOx8G\n\tqf1UoIiu/+RY76cF0/AJX7td+E6FSruB5BanqJGoiCtbXOcX8TyfGBwXKIKn0cYzn1XZ\n\tyPyg==","X-Gm-Message-State":"AOJu0YwHXJnzaz1jSEHB7AAe0i/xhhHCe94QHeVoIFrHcWn+0XnadbMa\n\tfrR489RMzDm+CFcfoAiwqiX2AuvFTwpqBYRr0FspK6Nz/d+7/wi19d9ot/gZZQ==","X-Gm-Gg":"AeBDievA5oBINVlTNmAT6Bpxm1nZtjBZ0blHwK/+GwRyOAJJl4YoWDZVdXz53LEaKQn\n\tqgBAgHH08joD+UcGLx/F0VwfVe92U3YRai+De/YEz3bTQE9kvp0vBsLjDAcWT2TuLhar4bf9Xq1\n\twhYwAypM23dBA0WoFnbIVb3z7TF8Be58V8XdiER2u8zwU4O1jakmOhmlDfqdIxDVWUg6GI9eot4\n\tZb1rspUlnskIBVjedliVQ98AsqD1JYGIpexNg6S1gFssy4HEdzi62otW/xGOwn/re7K9zCuz2lj\n\tee4WGW158YZHvycQN7v8adXNxUGMr6nsj2eYmyoIrnRGN7Ex1gYnGMXm8+wLsoklJmWt49qMtfm\n\tJ2BnP9zCvm7fLfqnlnp8H0B5+zc4kgIAmNb0r8e6j/nstmQyNj3vuGbpkfAsMpODN5sso1HFqUW\n\tn8Z77e+5+26SIhvhICriRaQ68zaSHfqxW5Gm996gRQzk1CTSPoD+rJUkl7lor0IebFMEHWsbg8G\n\tR+ol6g+/Gl3H6o97TyVuZctVMAEAHer","X-Received":"by 2002:a05:6000:611:b0:44a:247e:67b4 with SMTP id\n\tffacd0b85a97d-4515b9f31camr9070930f8f.18.1778105880763; \n\tWed, 06 May 2026 15:18:00 -0700 (PDT)","From":"d3vv3 <devve.3@gmail.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"d3vv3 <devve.3@gmail.com>","Subject":"[PATCH v2] test: ipa: libipa: Add CCM row-sum validation test","Date":"Thu,  7 May 2026 00:17:57 +0200","Message-ID":"<20260506221758.880117-1-devve.3@gmail.com>","X-Mailer":"git-send-email 2.54.0","In-Reply-To":"<20260501191400.985920-3-devve.3@gmail.com>","References":"<20260501191400.985920-3-devve.3@gmail.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":"Verify that each row of a colour correction matrix sums to 1.0\n(luminance preservation property). Tests cover:\n- identity and known-bad inline matrices\n- a real OV01A10 D65 calibrated CCM\n- parsing a multi-entry CCM YAML table via Interpolator<Matrix>\n- detection of a bad entry in YAML\n\nTolerance is 5e-4 to accommodate 4-decimal-place rounding in tuning files.\n\nSigned-off-by: d3vv3 <devve.3@gmail.com>\n---\n test/ipa/libipa/ccm.cpp     | 158 ++++++++++++++++++++++++++++++++++++\n test/ipa/libipa/meson.build |   1 +\n 2 files changed, 159 insertions(+)\n create mode 100644 test/ipa/libipa/ccm.cpp","diff":"diff --git a/test/ipa/libipa/ccm.cpp b/test/ipa/libipa/ccm.cpp\nnew file mode 100644\nindex 00000000..efc0035a\n--- /dev/null\n+++ b/test/ipa/libipa/ccm.cpp\n@@ -0,0 +1,158 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2024-2026, Red Hat Inc.\n+ *\n+ * CCM matrix row-sum validation tests\n+ *\n+ * Each row of a colour correction matrix must sum to 1.0 (luminance\n+ * preservation).  This test verifies that property for inline matrix data\n+ * and for matrices parsed from a YAML CCM table.\n+ */\n+\n+#include \"../../../src/ipa/libipa/interpolator.h\"\n+\n+#include <cmath>\n+#include <iostream>\n+#include <string>\n+#include <unistd.h>\n+\n+#include \"libcamera/base/file.h\"\n+#include \"libcamera/internal/matrix.h\"\n+#include \"libcamera/internal/yaml_parser.h\"\n+\n+#include \"test.h\"\n+\n+using namespace std;\n+using namespace libcamera;\n+using namespace ipa;\n+\n+/* Tolerance for floating-point row-sum comparison.\n+ * CCM values in tuning files are typically given to 4 decimal places,\n+ * which can introduce up to ~0.5e-3 rounding error per row. */\n+static constexpr float kRowSumTolerance = 5e-4f;\n+\n+#define ASSERT_TRUE(cond)                             \\\n+\tdo {                                          \\\n+\t\tif (!(cond)) {                        \\\n+\t\t\tcerr << \"FAIL: \" #cond \"\\n\";  \\\n+\t\t\treturn TestFail;              \\\n+\t\t}                                     \\\n+\t} while (0)\n+\n+static bool allRowsSumToOne(const Matrix<float, 3, 3> &m)\n+{\n+\tfor (unsigned int row = 0; row < 3; row++) {\n+\t\tfloat sum = 0.0f;\n+\t\tfor (unsigned int col = 0; col < 3; col++)\n+\t\t\tsum += m[row][col];\n+\t\tif (std::abs(sum - 1.0f) > kRowSumTolerance)\n+\t\t\treturn false;\n+\t}\n+\treturn true;\n+}\n+\n+class CcmRowSumTest : public Test\n+{\n+protected:\n+\tbool writeTempYaml(const std::string &content, std::string &filename)\n+\t{\n+\t\tfilename = \"/tmp/libcamera.ccm.test.XXXXXX\";\n+\t\tint fd = mkstemp(&filename.front());\n+\t\tif (fd == -1)\n+\t\t\treturn false;\n+\t\tssize_t ret = write(fd, content.c_str(), content.size());\n+\t\tclose(fd);\n+\t\treturn ret == static_cast<ssize_t>(content.size());\n+\t}\n+\n+\tstd::unique_ptr<ValueNode> parseYaml(const std::string &content)\n+\t{\n+\t\tstd::string filename;\n+\t\tif (!writeTempYaml(content, filename))\n+\t\t\treturn nullptr;\n+\n+\t\tFile file{ filename };\n+\t\tif (!file.open(File::OpenModeFlag::ReadOnly))\n+\t\t\treturn nullptr;\n+\n+\t\tauto root = YamlParser::parse(file);\n+\t\tunlink(filename.c_str());\n+\t\treturn root;\n+\t}\n+\n+\tint run()\n+\t{\n+\t\t/* --- 1. Known-good identity matrix --- */\n+\t\tMatrix<float, 3, 3> identity{ { 1, 0, 0,\n+\t\t\t\t\t\t0, 1, 0,\n+\t\t\t\t\t\t0, 0, 1 } };\n+\t\tASSERT_TRUE(allRowsSumToOne(identity));\n+\n+\t\t/* --- 2. Known-bad matrix (rows do not sum to 1) --- */\n+\t\tMatrix<float, 3, 3> bad{ { 2, 0, 0,\n+\t\t\t\t\t   0, 1, 0,\n+\t\t\t\t\t   0, 0, 1 } };\n+\t\tASSERT_TRUE(!allRowsSumToOne(bad));\n+\n+\t\t/* --- 3. Typical calibrated CCM (D65, OV01A10) --- */\n+\t\tMatrix<float, 3, 3> d65{ {  1.8163f, -0.7062f, -0.1100f,\n+\t\t\t\t\t   -0.1640f,  1.5736f, -0.4096f,\n+\t\t\t\t\t   -0.0084f, -0.8294f,  1.8378f } };\n+\t\tASSERT_TRUE(allRowsSumToOne(d65));\n+\n+\t\t/* --- 4. Parse a valid CCM table from YAML and validate --- */\n+\t\tconst std::string validYaml =\n+\t\t\t\"- ct: 2856\\n\"\n+\t\t\t\"  ccm: [  1.1248,  0.2210, -0.3458,\\n\"\n+\t\t\t\"         -0.4616,  1.7736, -0.3120,\\n\"\n+\t\t\t\"         -0.4342, -0.9348,  2.3690 ]\\n\"\n+\t\t\t\"- ct: 6500\\n\"\n+\t\t\t\"  ccm: [  1.8163, -0.7062, -0.1100,\\n\"\n+\t\t\t\"         -0.1640,  1.5736, -0.4096,\\n\"\n+\t\t\t\"         -0.0084, -0.8294,  1.8378 ]\\n\"\n+\t\t\t\"- ct: 7500\\n\"\n+\t\t\t\"  ccm: [  1.8953, -0.7980, -0.0973,\\n\"\n+\t\t\t\"         -0.1539,  1.6001, -0.4462,\\n\"\n+\t\t\t\"         -0.0101, -0.7800,  1.7902 ]\\n\";\n+\n+\t\tauto root = parseYaml(validYaml);\n+\t\tASSERT_TRUE(root);\n+\n+\t\tInterpolator<Matrix<float, 3, 3>> interp;\n+\t\tASSERT_TRUE(interp.readYaml(*root, \"ct\", \"ccm\") == 0);\n+\t\tASSERT_TRUE(interp.data().size() == 3);\n+\n+\t\tfor (const auto &[ct, m] : interp.data()) {\n+\t\t\tif (!allRowsSumToOne(m)) {\n+\t\t\t\tcerr << \"CCM at ct=\" << ct\n+\t\t\t\t     << \" has a row that does not sum to 1.0\\n\";\n+\t\t\t\treturn TestFail;\n+\t\t\t}\n+\t\t}\n+\n+\t\t/* --- 5. Detect a bad entry in YAML --- */\n+\t\tconst std::string badYaml =\n+\t\t\t\"- ct: 5000\\n\"\n+\t\t\t\"  ccm: [  2.0000, -0.7062, -0.1100,\\n\"\n+\t\t\t\"         -0.1640,  1.5736, -0.4096,\\n\"\n+\t\t\t\"         -0.0084, -0.8294,  1.8378 ]\\n\";\n+\n+\t\tauto badRoot = parseYaml(badYaml);\n+\t\tASSERT_TRUE(badRoot);\n+\n+\t\tInterpolator<Matrix<float, 3, 3>> badInterp;\n+\t\tASSERT_TRUE(badInterp.readYaml(*badRoot, \"ct\", \"ccm\") == 0);\n+\n+\t\tfor (const auto &[ct, m] : badInterp.data()) {\n+\t\t\tif (allRowsSumToOne(m)) {\n+\t\t\t\tcerr << \"Expected bad CCM at ct=\" << ct\n+\t\t\t\t     << \" to fail row-sum check, but it passed\\n\";\n+\t\t\t\treturn TestFail;\n+\t\t\t}\n+\t\t}\n+\n+\t\treturn TestPass;\n+\t}\n+};\n+\n+TEST_REGISTER(CcmRowSumTest)\ndiff --git a/test/ipa/libipa/meson.build b/test/ipa/libipa/meson.build\nindex c3e25587..8c36800c 100644\n--- a/test/ipa/libipa/meson.build\n+++ b/test/ipa/libipa/meson.build\n@@ -1,6 +1,7 @@\n # SPDX-License-Identifier: CC0-1.0\n \n libipa_test = [\n+    {'name': 'ccm', 'sources': ['ccm.cpp']},\n     {'name': 'fixedpoint', 'sources': ['fixedpoint.cpp']},\n     {'name': 'histogram', 'sources': ['histogram.cpp']},\n     {'name': 'interpolator', 'sources': ['interpolator.cpp']},\n","prefixes":["v2"]}