[graphics/krita] libs/image/tests: Add test for KisContentLightLevelProcessingVistor.
Wolthera van Hövell <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 5407bdda7ca501c6a90aaac3cfeaf1dd4f22d33e by Wolthera van Hövell, on behalf of Wolthera van Hövell tot Westerflier.
Committed on 07/08/2026 at 09:24.
Pushed by woltherav into branch 'master'.
Add test for KisContentLightLevelProcessingVistor.
M +1 -0 libs/image/tests/CMakeLists.txt
A +141 -0 libs/image/tests/KisContentLightLevelProcessingVisitorTest.cpp [License: GPL(v2.0+)]
A +22 -0 libs/image/tests/KisContentLightLevelProcessingVisitorTest.h [License: GPL(v2.0+)]
https://invent.kde.org/graphics/krita/-/commit/5407bdda7ca501c6a90aaac3cfeaf1dd4f22d33e
diff --git a/libs/image/tests/CMakeLists.txt b/libs/image/tests/CMakeLists.txt
index 8596093cab0..10d9e41d03f 100644
--- a/libs/image/tests/CMakeLists.txt
+++ b/libs/image/tests/CMakeLists.txt
@@ -129,6 +129,7 @@ kis_add_tests(
KisFourPointInterpolatorTest.cpp
KisSpatialContainerTest.cpp
KisGridInterpolationToolsTest.cpp
+ KisContentLightLevelProcessingVisitorTest.cpp
LINK_LIBRARIES kritaimage kritatestsdk
)
diff --git a/libs/image/tests/KisContentLightLevelProcessingVisitorTest.cpp b/libs/image/tests/KisContentLightLevelProcessingVisitorTest.cpp
new file mode 100644
index 00000000000..3ef0464abe1
--- /dev/null
+++ b/libs/image/tests/KisContentLightLevelProcessingVisitorTest.cpp
@@ -0,0 +1,141 @@
+/*
+ * SPDX-FileCopyrightText: 2026 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include "KisContentLightLevelProcessingVisitorTest.h"
+
+#include <KoColorSpaceRegistry.h>
+#include "kis_paint_layer.h"
+#include "kis_paint_device.h"
+#include <kis_group_layer.h>
+#include <kis_types.h>
+#include <KisContentLightLevelProcessingVistor.h>
+
+#include "kis_undo_stores.h"
+#include "kis_image.h"
+#include <kis_processing_applicator.h>
+#include <kis_hdr_metadata.h>
+
+
+
+KisImageSP createImage() {
+ KisSurrogateUndoStore *undoStore = new KisSurrogateUndoStore();
+ const KoColorSpace *cs = KoColorSpaceRegistry::instance()->colorSpace(RGBAColorModelID.id(), Float32BitsColorDepthID.id());
+ KisImageSP image = new KisImage(undoStore, 300, 300, cs, "test");
+
+ QRect fillRect1(50,50,100,100);
+ QRect fillRect2(75,75,50,50);
+ KisPaintLayerSP paintLayer1 = new KisPaintLayer(image, "paint1", OPACITY_OPAQUE_U8);
+ KisPaintLayerSP paintLayer2 = new KisPaintLayer(image, "paint2", OPACITY_OPAQUE_U8);
+
+ paintLayer1->paintDevice()->fill(fillRect1, KoColor(Qt::green, cs));
+ paintLayer2->paintDevice()->fill(fillRect2, KoColor(Qt::red, cs));
+
+ image->addNode(paintLayer1, image->rootLayer());
+ image->addNode(paintLayer2, image->rootLayer());
+
+ image->initialRefreshGraph();
+ return image;
+}
+
+
+void KisContentLightLevelProcessingVisitorTest::testRgbColorSpace_data()
+{
+ QTest::addColumn<KisRelativeContentLightLevelInformation::CalculationType>("type");
+ QTest::addColumn<double>("expectedMaxCLL");
+ QTest::addColumn<double>("expectedMaxFALL");
+
+ QTest::addRow("XYZ Luminance") << KisRelativeContentLightLevelInformation::XYZLuminance << 0.716905 << 0.0659222;
+ QTest::addRow("Rec2020 Component") << KisRelativeContentLightLevelInformation::Rec2020Component << 0.919528 << 0.0940548;
+ QTest::addRow("RGB Component") << KisRelativeContentLightLevelInformation::RGBComponent << 1.00002 << 0.111112;
+}
+
+void KisContentLightLevelProcessingVisitorTest::testRgbColorSpace()
+{
+ QFETCH(KisRelativeContentLightLevelInformation::CalculationType, type);
+ QFETCH(double, expectedMaxCLL);
+ QFETCH(double, expectedMaxFALL);
+
+ KisImageSP image = createImage();
+
+
+ KisProcessingApplicator::ProcessingFlags signalFlags = KisProcessingApplicator::NO_UI_UPDATES | KisProcessingApplicator::RECURSIVE_FRAME_TIMES;
+ KisProcessingApplicator applicator(image, image->rootLayer(),
+ signalFlags);
+
+ KisSharedPtr<KisContentLightLevelProcessingVistor> visitor =
+ new KisContentLightLevelProcessingVistor(type, image->bounds());
+ applicator.applyVisitorAllFrames(visitor, KisStrokeJobData::SEQUENTIAL);
+ applicator.end();
+
+ image->waitForDone();
+
+ KisRelativeContentLightLevelInformation info = visitor->contentLightLevelInformation();
+
+
+ QVERIFY(info.maxContentLightLevel - expectedMaxCLL < 0.00001);
+ QVERIFY(info.maxFrameAverageLightLevel - expectedMaxFALL < 0.00001);
+
+}
+
+void KisContentLightLevelProcessingVisitorTest::testCmykColorSpace_data()
+{
+ QTest::addColumn<KisRelativeContentLightLevelInformation::CalculationType>("type");
+ QTest::addColumn<double>("expectedMaxCLL");
+ QTest::addColumn<double>("expectedMaxFALL");
+
+ QTest::addRow("XYZ Luminance") << KisRelativeContentLightLevelInformation::XYZLuminance << 0.360151 << 0.0195933;
+ QTest::addRow("Rec2020 Component") << KisRelativeContentLightLevelInformation::Rec2020Component << 0.514917 << 0.0538389;
+ // Because we're testing cmyk, and not rgb, this will fallback onto xyzLuminance.
+ QTest::addRow("RGB Component") << KisRelativeContentLightLevelInformation::RGBComponent << 0.360151 << 0.0195933;
+}
+
+void KisContentLightLevelProcessingVisitorTest::testCmykColorSpace()
+{
+ QFETCH(KisRelativeContentLightLevelInformation::CalculationType, type);
+ QFETCH(double, expectedMaxCLL);
+ QFETCH(double, expectedMaxFALL);
+ KisImageSP image = createImage();
+ const KoColorSpace *cmyk = KoColorSpaceRegistry::instance()->colorSpace(CMYKAColorModelID.id(), Float32BitsColorDepthID.id(), "Chemical proof");
+ image->convertImageColorSpace(cmyk, KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::internalConversionFlags());
+
+
+ KisProcessingApplicator::ProcessingFlags signalFlags = KisProcessingApplicator::NO_UI_UPDATES | KisProcessingApplicator::RECURSIVE_FRAME_TIMES;
+ KisProcessingApplicator applicator(image, image->rootLayer(),
+ signalFlags);
+
+ KisSharedPtr<KisContentLightLevelProcessingVistor> visitor =
+ new KisContentLightLevelProcessingVistor(type, image->bounds());
+ applicator.applyVisitorAllFrames(visitor, KisStrokeJobData::SEQUENTIAL);
+ applicator.end();
+
+ image->waitForDone();
+
+ KisRelativeContentLightLevelInformation info = visitor->contentLightLevelInformation();
+
+ QVERIFY(info.maxContentLightLevel - expectedMaxCLL < 0.00001);
+ QVERIFY(info.maxFrameAverageLightLevel - expectedMaxFALL < 0.00001);
+}
+
+void KisContentLightLevelProcessingVisitorTest::testEmptyDocument()
+{
+ KisSurrogateUndoStore *undoStore = new KisSurrogateUndoStore();
+ const KoColorSpace *cs = KoColorSpaceRegistry::instance()->colorSpace(RGBAColorModelID.id(), Float32BitsColorDepthID.id());
+ KisImageSP image = new KisImage(undoStore, 300, 300, cs, "test");
+
+ //-----------------------//
+
+ KisProcessingApplicator::ProcessingFlags signalFlags = KisProcessingApplicator::NO_UI_UPDATES | KisProcessingApplicator::RECURSIVE_FRAME_TIMES;
+ KisProcessingApplicator applicator(image, image->rootLayer(),
+ signalFlags);
+
+ KisSharedPtr<KisContentLightLevelProcessingVistor> visitor =
+ new KisContentLightLevelProcessingVistor(KisRelativeContentLightLevelInformation::XYZLuminance, image->bounds());
+ applicator.applyVisitorAllFrames(visitor, KisStrokeJobData::SEQUENTIAL);
+ applicator.end();
+
+ image->waitForDone();
+}
+
+SIMPLE_TEST_MAIN(KisContentLightLevelProcessingVisitorTest)
diff --git a/libs/image/tests/KisContentLightLevelProcessingVisitorTest.h b/libs/image/tests/KisContentLightLevelProcessingVisitorTest.h
new file mode 100644
index 00000000000..4eeeb4c3364
--- /dev/null
+++ b/libs/image/tests/KisContentLightLevelProcessingVisitorTest.h
@@ -0,0 +1,22 @@
+/*
+ * SPDX-FileCopyrightText: 2026 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef KISCONTENTLIGHTLEVELPROCESSINGVISITORTEST_H
+#define KISCONTENTLIGHTLEVELPROCESSINGVISITORTEST_H
+
+#include <simpletest.h>
+
+class KisContentLightLevelProcessingVisitorTest : public QObject
+{
+ Q_OBJECT
+private Q_SLOTS:
+ void testRgbColorSpace_data();
+ void testRgbColorSpace();
+ void testCmykColorSpace_data();
+ void testCmykColorSpace();
+ void testEmptyDocument();
+};
+
+#endif // KISCONTENTLIGHTLEVELPROCESSINGVISITORTEST_H