From 5719b8fb3076d3d5ae0bfc7e67f51d1e899d5ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 5 Apr 2021 18:21:19 +0200 Subject: [PATCH] DebugTools: support half-float formats in CompareImage. --- doc/changelog.dox | 5 ++ src/Magnum/DebugTools/CompareImage.cpp | 18 +++---- src/Magnum/DebugTools/CompareImage.h | 12 ++--- .../DebugTools/Test/CompareImageTest.cpp | 53 +++++++++++++------ 4 files changed, 56 insertions(+), 32 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 0e656a333..ba9d293a0 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -209,6 +209,11 @@ See also: @subsection changelog-latest-changes Changes and improvements +@subsubsection changelog-latest-changes-debugtools DebugTools library + +- @ref DebugTools::CompareImage now supports comparing half-float pixel + formats as well + @subsubsection changelog-latest-changes-gl GL library - The @ref GL::Context class got significantly optimized in terms of compile diff --git a/src/Magnum/DebugTools/CompareImage.cpp b/src/Magnum/DebugTools/CompareImage.cpp index 9a79fae4d..73a37e779 100644 --- a/src/Magnum/DebugTools/CompareImage.cpp +++ b/src/Magnum/DebugTools/CompareImage.cpp @@ -38,6 +38,7 @@ #include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" #include "Magnum/Math/Functions.h" +#include "Magnum/Math/Half.h" #include "Magnum/Math/Color.h" #include "Magnum/Math/Algorithms/KahanSum.h" #include "Magnum/Trade/AbstractImageConverter.h" @@ -166,6 +167,10 @@ std::tuple, Float, Float> calculateImageDelta(const Pix _c(RG32I, 2, Int) _c(RGB32I, 3, Int) _c(RGBA32I, 4, Int) + _c(R16F, 1, Half) + _c(RG16F, 2, Half) + _c(RGB16F, 3, Half) + _c(RGBA16F, 4, Half) _d(R32F, Depth32F, 1, Float) _c(RG32F, 2, Float) _c(RGB32F, 3, Float) @@ -176,11 +181,6 @@ std::tuple, Float, Float> calculateImageDelta(const Pix #undef _d #undef _c - case PixelFormat::R16F: - case PixelFormat::RG16F: - case PixelFormat::RGB16F: - case PixelFormat::RGBA16F: - CORRADE_ASSERT_UNREACHABLE("DebugTools::CompareImage: half-float formats are not supported yet", {}); case PixelFormat::Depth16UnormStencil8UI: case PixelFormat::Depth24UnormStencil8UI: case PixelFormat::Depth32FStencil8UI: @@ -311,6 +311,10 @@ void printPixelAt(Debug& out, const Containers::StridedArrayView3D& _c(RG32I, 2, Int) _c(RGB32I, 3, Int) _c(RGBA32I, 4, Int) + _c(R16F, 1, Half) + _c(RG16F, 2, Half) + _c(RGB16F, 3, Half) + _c(RGBA16F, 4, Half) _d(R32F, Depth32F, 1, Float) _c(RG32F, 2, Float) _c(RGB32F, 3, Float) @@ -331,10 +335,6 @@ void printPixelAt(Debug& out, const Containers::StridedArrayView3D& out << *reinterpret_cast(pixel); break; - case PixelFormat::R16F: - case PixelFormat::RG16F: - case PixelFormat::RGB16F: - case PixelFormat::RGBA16F: case PixelFormat::Depth16UnormStencil8UI: case PixelFormat::Depth24UnormStencil8UI: case PixelFormat::Depth32FStencil8UI: diff --git a/src/Magnum/DebugTools/CompareImage.h b/src/Magnum/DebugTools/CompareImage.h index 489c19fa7..3bc9c71f2 100644 --- a/src/Magnum/DebugTools/CompareImage.h +++ b/src/Magnum/DebugTools/CompareImage.h @@ -236,14 +236,14 @@ Supports the following formats: @ref PixelFormat::RGBA32UI and their one-/two-/three-component versions - @ref PixelFormat::RGBA8I, @ref PixelFormat::RGBA16I, @ref PixelFormat::RGBA32I and their one-/two-/three-component versions +- @ref PixelFormat::RGBA16F and its one-/two-/three-component versions - @ref PixelFormat::RGBA32F and its one-/two-/three-component versions -@ref PixelFormat::RGBA16F and other half-float formats are not supported at the -moment. Packed depth/stencil formats are not supported at the moment, -however you can work around that by making separate depth/stencil pixel -views and @ref DebugTools-CompareImage-pixels "comparing those" to a -depth/stencil-only ground truth images. Implementation-specific pixel -formats can't be supported. +Packed depth/stencil formats are not supported at the moment, however you can +work around that by making separate depth/stencil pixel views and +@ref DebugTools-CompareImage-pixels "comparing the views" to a +depth/stencil-only ground truth images. Implementation-specific pixel formats +can't be supported. Supports all @ref PixelStorage parameters. The images don't need to have the same pixel storage parameters, meaning you are able to compare different diff --git a/src/Magnum/DebugTools/Test/CompareImageTest.cpp b/src/Magnum/DebugTools/Test/CompareImageTest.cpp index 29df8251a..ceaee77fc 100644 --- a/src/Magnum/DebugTools/Test/CompareImageTest.cpp +++ b/src/Magnum/DebugTools/Test/CompareImageTest.cpp @@ -40,8 +40,9 @@ #include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" #include "Magnum/DebugTools/CompareImage.h" -#include "Magnum/Math/Functions.h" #include "Magnum/Math/Color.h" +#include "Magnum/Math/Functions.h" +#include "Magnum/Math/Half.h" #include "Magnum/Trade/AbstractImageConverter.h" #include "Magnum/Trade/AbstractImporter.h" @@ -53,7 +54,6 @@ struct CompareImageTest: TestSuite::Tester { explicit CompareImageTest(); void formatUnknown(); - void formatHalf(); void formatPackedDepthStencil(); void formatImplementationSpecific(); @@ -70,6 +70,7 @@ struct CompareImageTest: TestSuite::Tester { void pixelDelta(); void pixelDeltaEmpty(); void pixelDeltaOverflow(); + void pixelDeltaHalf(); void pixelDeltaSpecials(); void compareDifferentSize(); @@ -125,7 +126,6 @@ struct CompareImageTest: TestSuite::Tester { CompareImageTest::CompareImageTest() { addTests({&CompareImageTest::formatUnknown, - &CompareImageTest::formatHalf, &CompareImageTest::formatPackedDepthStencil, &CompareImageTest::formatImplementationSpecific, @@ -142,6 +142,7 @@ CompareImageTest::CompareImageTest() { &CompareImageTest::pixelDelta, &CompareImageTest::pixelDeltaEmpty, &CompareImageTest::pixelDeltaOverflow, + &CompareImageTest::pixelDeltaHalf, &CompareImageTest::pixelDeltaSpecials, &CompareImageTest::compareDifferentSize, @@ -218,6 +219,8 @@ CompareImageTest::CompareImageTest() { setupExternalPluginManager() function */ } +using namespace Math::Literals; + const Float ActualRedData[] = { 0.3f, 1.0f, 0.9f, 0.9f, 0.6f, 0.2f, @@ -253,20 +256,6 @@ void CompareImageTest::formatUnknown() { CORRADE_COMPARE(out.str(), "DebugTools::CompareImage: unknown format PixelFormat(0xdead)\n"); } -void CompareImageTest::formatHalf() { - #ifdef CORRADE_NO_ASSERT - CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); - #endif - - std::ostringstream out; - Error redirectError{&out}; - - ImageView2D image{PixelFormat::RG16F, {}}; - Implementation::calculateImageDelta(image.format(), image.pixels(), image); - - CORRADE_COMPARE(out.str(), "DebugTools::CompareImage: half-float formats are not supported yet\n"); -} - void CompareImageTest::formatPackedDepthStencil() { #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); @@ -532,6 +521,36 @@ void CompareImageTest::pixelDeltaOverflow() { " [2,0] Vector(0.9), expected Vector(0.6) (Δ = 0.3)"); } +const Vector2h ActualHalfData[]{ + {0.3_h, 1.0_h}, { 0.9_h, 0.9_h}, + {0.6_h, 0.2_h}, {-0.1_h, 1.0_h}, +}; + +const Vector2h ExpectedHalfData[]{ + {0.65_h, 1.0_h}, {0.6_h, 0.91_h}, + {0.6_h, 0.1_h}, {0.02_h, 0.0_h} +}; + +const Float DeltaHalf[] { + 0.35f/2.0f, 0.31f/2.0f, + 0.01f/2.0f, 0.22f/2.0f +}; + +const ImageView2D ActualHalf{PixelFormat::RG16F, {2, 2}, ActualHalfData}; +const ImageView2D ExpectedHalf{PixelFormat::RG16F, {2, 2}, ExpectedHalfData}; + +void CompareImageTest::pixelDeltaHalf() { + std::ostringstream out; + Debug d{&out, Debug::Flag::DisableColors}; + Implementation::printPixelDeltas(d, DeltaHalf, ActualHalf.format(), ActualHalf.pixels(), ExpectedHalf.pixels(), 0.5f, 0.1f, 10); + + CORRADE_COMPARE(out.str(), "\n" + " Pixels above max/mean threshold:\n" + " [0,0] Vector(0.3, 1), expected Vector(0.6499, 1) (Δ = 0.175)\n" + " [1,0] Vector(0.8999, 0.8999), expected Vector(0.6001, 0.9102) (Δ = 0.155)\n" + " [1,1] Vector(-0.09998, 1), expected Vector(0.02, 0) (Δ = 0.11)"); +} + void CompareImageTest::pixelDeltaSpecials() { std::ostringstream out; Debug d{&out, Debug::Flag::DisableColors};