Browse Source

DebugTools: make CompareImage work with MutableImageView.

And test Image and Trade::ImageData inputs as well while at it, since
they were also not really verified before.
pull/168/head
Vladimír Vondruš 3 years ago
parent
commit
5835caffce
  1. 2
      doc/changelog.dox
  2. 4
      src/Magnum/DebugTools/CompareImage.h
  3. 77
      src/Magnum/DebugTools/Test/CompareImageTest.cpp

2
doc/changelog.dox

@ -525,6 +525,8 @@ See also:
- @ref DebugTools::CompareImage now supports comparing half-float pixel - @ref DebugTools::CompareImage now supports comparing half-float pixel
formats as well, pixel format autodetection for pixel views tries to formats as well, pixel format autodetection for pixel views tries to
match sRGB and normalization properties of the expected image format match sRGB and normalization properties of the expected image format
- @ref DebugTools::CompareImage now accepts @ref MutableImageView2D as well,
in addition to @ref Image2D, @ref ImageView2D and @ref Trade::ImageData2D
@subsubsection changelog-latest-changes-gl GL library @subsubsection changelog-latest-changes-gl GL library

4
src/Magnum/DebugTools/CompareImage.h

@ -174,7 +174,7 @@ namespace Implementation {
/* Explicit ComparatorTraits specialization because /* Explicit ComparatorTraits specialization because
Comparator<CompareImage>::operator() is overloaded */ Comparator<CompareImage>::operator() is overloaded */
template<class T> struct ComparatorTraits<Magnum::DebugTools::CompareImage, Magnum::ImageView2D, T> { template<class T, class U> struct ComparatorTraits<Magnum::DebugTools::CompareImage, Magnum::ImageView<2, U>, T> {
typedef Magnum::ImageView2D ActualType; typedef Magnum::ImageView2D ActualType;
typedef Magnum::ImageView2D ExpectedType; typedef Magnum::ImageView2D ExpectedType;
}; };
@ -187,7 +187,7 @@ template<class T, class U> struct ComparatorTraits<Magnum::DebugTools::CompareIm
/* Explicit ComparatorTraits specialization because /* Explicit ComparatorTraits specialization because
Comparator<CompareImageToFile>::operator() is overloaded */ Comparator<CompareImageToFile>::operator() is overloaded */
template<class T> struct ComparatorTraits<Magnum::DebugTools::CompareImageToFile, Magnum::ImageView2D, T> { template<class T, class U> struct ComparatorTraits<Magnum::DebugTools::CompareImageToFile, Magnum::ImageView<2, U>, T> {
typedef Magnum::ImageView2D ActualType; typedef Magnum::ImageView2D ActualType;
typedef Containers::StringView ExpectedType; typedef Containers::StringView ExpectedType;
}; };

77
src/Magnum/DebugTools/Test/CompareImageTest.cpp

@ -40,6 +40,7 @@
#include <Corrade/Utility/Path.h> #include <Corrade/Utility/Path.h>
#include <Corrade/Utility/String.h> /* replaceFirst() */ #include <Corrade/Utility/String.h> /* replaceFirst() */
#include "Magnum/Image.h"
#include "Magnum/ImageView.h" #include "Magnum/ImageView.h"
#include "Magnum/PixelFormat.h" #include "Magnum/PixelFormat.h"
#include "Magnum/DebugTools/CompareImage.h" #include "Magnum/DebugTools/CompareImage.h"
@ -48,6 +49,7 @@
#include "Magnum/Math/Half.h" #include "Magnum/Math/Half.h"
#include "Magnum/Trade/AbstractImageConverter.h" #include "Magnum/Trade/AbstractImageConverter.h"
#include "Magnum/Trade/AbstractImporter.h" #include "Magnum/Trade/AbstractImporter.h"
#include "Magnum/Trade/ImageData.h"
#include "configure.h" #include "configure.h"
@ -116,6 +118,9 @@ struct CompareImageTest: TestSuite::Tester {
void fileToImageActualLoadFailed(); void fileToImageActualLoadFailed();
void fileToImageActualIsCompressed(); void fileToImageActualIsCompressed();
void mutableImageViewImageImageData();
void mutableImageViewImageImageDataToFile();
template<unsigned dimensions> void pixelFormatFor(); template<unsigned dimensions> void pixelFormatFor();
void pixelFormatForColor(); void pixelFormatForColor();
@ -222,7 +227,13 @@ CompareImageTest::CompareImageTest() {
&CompareImageTest::setupExternalPluginManager, &CompareImageTest::setupExternalPluginManager,
&CompareImageTest::teardownExternalPluginManager); &CompareImageTest::teardownExternalPluginManager);
addTests({&CompareImageTest::fileToImageActualIsCompressed}); addTests({&CompareImageTest::fileToImageActualIsCompressed,
&CompareImageTest::mutableImageViewImageImageData});
addTests({&CompareImageTest::mutableImageViewImageImageDataToFile},
&CompareImageTest::setupExternalPluginManager,
&CompareImageTest::teardownExternalPluginManager);
addTests({&CompareImageTest::pixelFormatFor<1>, addTests({&CompareImageTest::pixelFormatFor<1>,
&CompareImageTest::pixelFormatFor<2>, &CompareImageTest::pixelFormatFor<2>,
@ -1688,6 +1699,70 @@ void CompareImageTest::fileToImageActualIsCompressed() {
"Actual image a (.../CompareImageCompressed.dds) is compressed, comparison not possible.\n"); "Actual image a (.../CompareImageCompressed.dds) is compressed, comparison not possible.\n");
} }
void CompareImageTest::mutableImageViewImageImageData() {
/* All other cases use an ImageView, so verify that the other variants all
compile too */
char pixels[]{
'\x56', '\xf8', '\x3a', '\x56', '\x47', '\xec', '\0', '\0',
'\x23', '\x57', '\x10', '\xab', '\xcd', '\x85', '\0', '\0'
};
MutableImageView2D view{PixelFormat::RGB8Unorm, {2, 2}, pixels};
Image2D image{PixelFormat::RGB8Unorm, {2, 2}, Containers::array({
'\x56', '\xf8', '\x3a', '\x56', '\x47', '\xec', '\0', '\0',
'\x23', '\x57', '\x10', '\xab', '\xcd', '\x85', '\0', '\0'
})};
Trade::ImageData2D data{PixelFormat::RGB8Unorm, {2, 2}, Trade::DataFlags{}, pixels};
CORRADE_COMPARE_AS(view, view, CompareImage);
CORRADE_COMPARE_AS(view, image, CompareImage);
CORRADE_COMPARE_AS(view, data, CompareImage);
CORRADE_COMPARE_AS(image, view, CompareImage);
CORRADE_COMPARE_AS(image, image, CompareImage);
CORRADE_COMPARE_AS(image, data, CompareImage);
CORRADE_COMPARE_AS(data, view, CompareImage);
CORRADE_COMPARE_AS(data, image, CompareImage);
CORRADE_COMPARE_AS(data, data, CompareImage);
}
void CompareImageTest::mutableImageViewImageImageDataToFile() {
if(!(_importerManager->loadState("AnyImageImporter") & PluginManager::LoadState::Loaded) ||
!(_importerManager->loadState("TgaImporter") & PluginManager::LoadState::Loaded))
CORRADE_SKIP("AnyImageImporter / TgaImporter plugins not found.");
/* All other cases use an ImageView, so verify that the other variants all
compile too */
char pixels[]{
'\x55', '\xf8', '\x3a', '\x56', '\x10', '\xed', '\0', '\0',
'\x23', '\x27', '\x10', '\xab', '\xcd', '\xfa', '\0', '\0'
};
MutableImageView2D view{PixelFormat::RGB8Unorm, {2, 2}, pixels};
Image2D image{PixelFormat::RGB8Unorm, {2, 2}, Containers::array({
'\x55', '\xf8', '\x3a', '\x56', '\x10', '\xed', '\0', '\0',
'\x23', '\x27', '\x10', '\xab', '\xcd', '\xfa', '\0', '\0'
})};
Trade::ImageData2D data{PixelFormat::RGB8Unorm, {2, 2}, Trade::DataFlags{}, pixels};
Containers::String filename = Utility::Path::join(DEBUGTOOLS_TEST_DIR, "CompareImageExpected.tga");
CORRADE_COMPARE_WITH(filename, view,
CompareFileToImage{*_importerManager});
CORRADE_COMPARE_WITH(filename, image,
CompareFileToImage{*_importerManager});
CORRADE_COMPARE_WITH(filename, data,
CompareFileToImage{*_importerManager});
CORRADE_COMPARE_WITH(view, filename,
CompareImageToFile{*_importerManager});
CORRADE_COMPARE_WITH(image, filename,
CompareImageToFile{*_importerManager});
CORRADE_COMPARE_WITH(data, filename,
CompareImageToFile{*_importerManager});
}
template<UnsignedInt dimensions> void CompareImageTest::pixelFormatFor() { template<UnsignedInt dimensions> void CompareImageTest::pixelFormatFor() {
setTestCaseTemplateName(Utility::format("{}", dimensions)); setTestCaseTemplateName(Utility::format("{}", dimensions));

Loading…
Cancel
Save