Browse Source

AnyImageConverter: recognize KTX2 for basically all image types.

pull/542/merge
Vladimír Vondruš 4 years ago
parent
commit
9fbc637f76
  1. 2
      doc/changelog.dox
  2. 336
      src/MagnumPlugins/AnyImageConverter/AnyImageConverter.cpp
  3. 24
      src/MagnumPlugins/AnyImageConverter/AnyImageConverter.h
  4. 868
      src/MagnumPlugins/AnyImageConverter/Test/AnyImageConverterTest.cpp
  5. 3
      src/MagnumPlugins/AnyImageConverter/Test/CMakeLists.txt
  6. 1
      src/MagnumPlugins/AnyImageConverter/Test/configure.h.cmake
  7. BIN
      src/MagnumPlugins/AnyImageImporter/Test/1d.ktx2
  8. 37
      src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp
  9. 5
      src/MagnumPlugins/AnyImageImporter/Test/CMakeLists.txt
  10. 1
      src/MagnumPlugins/AnyImageImporter/Test/configure.h.cmake

2
doc/changelog.dox

@ -402,6 +402,8 @@ See also:
- Recognizing KTX2 files and data in @relativeref{Trade,AnyImageImporter} and
@relativeref{Trade,AnyImageConverter} (see also
[mosra/magnum#529](https://github.com/mosra/magnum/pull/529))
- Recognizing KTX2 for (compressed) 1D/2D/3D and multi-level 1D/2D/3D images
in @relativeref{Trade,AnyImageConverter}
- @ref Audio::AnyImporter "AnyAudioImporter",
@relativeref{Trade,AnyImageImporter}, @relativeref{Trade,AnyImageConverter},
@relativeref{Trade,AnySceneImporter}, @relativeref{Trade,AnySceneConverter}

336
src/MagnumPlugins/AnyImageConverter/AnyImageConverter.cpp

@ -62,13 +62,47 @@ ImageConverterFeatures AnyImageConverter::doFeatures() const {
ImageConverterFeature::ConvertCompressedLevels3DToFile;
}
bool AnyImageConverter::doConvertToFile(const ImageView1D&, const Containers::StringView filename) {
bool AnyImageConverter::doConvertToFile(const ImageView1D& image, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/* No file formats to store 1D data yet */
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s))
plugin = "KtxImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a 1D image";
return false;
}
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a 1D image";
return false;
/* Try to load the plugin */
if(!(manager()->load(plugin) & PluginManager::LoadState::Loaded)) {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot load the" << plugin << "plugin";
return false;
}
const PluginManager::PluginMetadata* const metadata = manager()->metadata(plugin);
CORRADE_INTERNAL_ASSERT(metadata);
if(flags() & ImageConverterFlag::Verbose) {
Debug d;
d << "Trade::AnyImageConverter::convertToFile(): using" << plugin;
if(plugin != metadata->name())
d << "(provided by" << metadata->name() << Debug::nospace << ")";
}
/* Instantiate the plugin, propagate flags */
Containers::Pointer<AbstractImageConverter> converter = static_cast<PluginManager::Manager<AbstractImageConverter>*>(manager())->instantiate(plugin);
converter->setFlags(flags());
/* Propagate configuration */
Magnum::Implementation::propagateConfiguration("Trade::AnyImageConverter::convertToFile():", {}, metadata->name(), configuration(), converter->configuration());
/* Try to convert the file (error output should be printed by the plugin
itself) */
return converter->convertToFile(image, filename);
}
bool AnyImageConverter::doConvertToFile(const ImageView2D& image, const Containers::StringView filename) {
@ -178,40 +212,176 @@ bool AnyImageConverter::doConvertToFile(const ImageView3D& image, const Containe
return converter->convertToFile(image, filename);
}
bool AnyImageConverter::doConvertToFile(const CompressedImageView1D&, const Containers::StringView filename) {
bool AnyImageConverter::doConvertToFile(const CompressedImageView1D& image, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/* No file formats to store compressed 1D data yet */
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s))
plugin = "KtxImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a compressed 1D image";
return false;
}
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a compressed 1D image";
return false;
/* Try to load the plugin */
if(!(manager()->load(plugin) & PluginManager::LoadState::Loaded)) {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot load the" << plugin << "plugin";
return false;
}
const PluginManager::PluginMetadata* const metadata = manager()->metadata(plugin);
CORRADE_INTERNAL_ASSERT(metadata);
if(flags() & ImageConverterFlag::Verbose) {
Debug d;
d << "Trade::AnyImageConverter::convertToFile(): using" << plugin;
if(plugin != metadata->name())
d << "(provided by" << metadata->name() << Debug::nospace << ")";
}
/* Instantiate the plugin, propagate flags */
Containers::Pointer<AbstractImageConverter> converter = static_cast<PluginManager::Manager<AbstractImageConverter>*>(manager())->instantiate(plugin);
converter->setFlags(flags());
/* Propagate configuration */
Magnum::Implementation::propagateConfiguration("Trade::AnyImageConverter::convertToFile():", {}, metadata->name(), configuration(), converter->configuration());
/* Try to convert the file (error output should be printed by the plugin
itself) */
return converter->convertToFile(image, filename);
}
bool AnyImageConverter::doConvertToFile(const CompressedImageView2D&, const Containers::StringView filename) {
bool AnyImageConverter::doConvertToFile(const CompressedImageView2D& image, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/* No file formats to store compressed 2D data yet */
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s))
plugin = "KtxImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a compressed 2D image";
return false;
}
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a compressed 2D image";
return false;
/* Try to load the plugin */
if(!(manager()->load(plugin) & PluginManager::LoadState::Loaded)) {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot load the" << plugin << "plugin";
return false;
}
const PluginManager::PluginMetadata* const metadata = manager()->metadata(plugin);
CORRADE_INTERNAL_ASSERT(metadata);
if(flags() & ImageConverterFlag::Verbose) {
Debug d;
d << "Trade::AnyImageConverter::convertToFile(): using" << plugin;
if(plugin != metadata->name())
d << "(provided by" << metadata->name() << Debug::nospace << ")";
}
/* Instantiate the plugin, propagate flags */
Containers::Pointer<AbstractImageConverter> converter = static_cast<PluginManager::Manager<AbstractImageConverter>*>(manager())->instantiate(plugin);
converter->setFlags(flags());
/* Propagate configuration */
Magnum::Implementation::propagateConfiguration("Trade::AnyImageConverter::convertToFile():", {}, metadata->name(), configuration(), converter->configuration());
/* Try to convert the file (error output should be printed by the plugin
itself) */
return converter->convertToFile(image, filename);
}
bool AnyImageConverter::doConvertToFile(const CompressedImageView3D&, const Containers::StringView filename) {
bool AnyImageConverter::doConvertToFile(const CompressedImageView3D& image, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/* No file formats to store compressed 3D data yet */
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s))
plugin = "KtxImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a compressed 3D image";
return false;
}
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a compressed 3D image";
return false;
/* Try to load the plugin */
if(!(manager()->load(plugin) & PluginManager::LoadState::Loaded)) {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot load the" << plugin << "plugin";
return false;
}
const PluginManager::PluginMetadata* const metadata = manager()->metadata(plugin);
CORRADE_INTERNAL_ASSERT(metadata);
if(flags() & ImageConverterFlag::Verbose) {
Debug d;
d << "Trade::AnyImageConverter::convertToFile(): using" << plugin;
if(plugin != metadata->name())
d << "(provided by" << metadata->name() << Debug::nospace << ")";
}
/* Instantiate the plugin, propagate flags */
Containers::Pointer<AbstractImageConverter> converter = static_cast<PluginManager::Manager<AbstractImageConverter>*>(manager())->instantiate(plugin);
converter->setFlags(flags());
/* Propagate configuration */
Magnum::Implementation::propagateConfiguration("Trade::AnyImageConverter::convertToFile():", {}, metadata->name(), configuration(), converter->configuration());
/* Try to convert the file (error output should be printed by the plugin
itself) */
return converter->convertToFile(image, filename);
}
bool AnyImageConverter::doConvertToFile(Containers::ArrayView<const ImageView1D>, const Containers::StringView filename) {
bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const ImageView1D> imageLevels, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/* No file formats to store multi-level 1D data yet */
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s))
plugin = "KtxImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level 1D image";
return false;
}
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level 1D image";
return false;
/* Try to load the plugin */
if(!(manager()->load(plugin) & PluginManager::LoadState::Loaded)) {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot load the" << plugin << "plugin";
return false;
}
const PluginManager::PluginMetadata* const metadata = manager()->metadata(plugin);
CORRADE_INTERNAL_ASSERT(metadata);
if(flags() & ImageConverterFlag::Verbose) {
Debug d;
d << "Trade::AnyImageConverter::convertToFile(): using" << plugin;
if(plugin != metadata->name())
d << "(provided by" << metadata->name() << Debug::nospace << ")";
}
/* Instantiate the plugin, propagate flags */
Containers::Pointer<AbstractImageConverter> converter = static_cast<PluginManager::Manager<AbstractImageConverter>*>(manager())->instantiate(plugin);
converter->setFlags(flags());
/* Propagate configuration */
Magnum::Implementation::propagateConfiguration("Trade::AnyImageConverter::convertToFile():", {}, metadata->name(), configuration(), converter->configuration());
/* Try to convert the file (error output should be printed by the plugin
itself) */
return converter->convertToFile(imageLevels, filename);
}
bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const ImageView2D> imageLevels, const Containers::StringView filename) {
@ -306,31 +476,133 @@ bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const ImageV
return converter->convertToFile(imageLevels, filename);
}
bool AnyImageConverter::doConvertToFile(Containers::ArrayView<const CompressedImageView1D>, const Containers::StringView filename) {
bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const CompressedImageView1D> imageLevels, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/* No file formats to store multi-level compressed 1D data yet */
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s))
plugin = "KtxImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level compressed 1D image";
return false;
}
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level compressed 1D image";
return false;
/* Try to load the plugin */
if(!(manager()->load(plugin) & PluginManager::LoadState::Loaded)) {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot load the" << plugin << "plugin";
return false;
}
const PluginManager::PluginMetadata* const metadata = manager()->metadata(plugin);
CORRADE_INTERNAL_ASSERT(metadata);
if(flags() & ImageConverterFlag::Verbose) {
Debug d;
d << "Trade::AnyImageConverter::convertToFile(): using" << plugin;
if(plugin != metadata->name())
d << "(provided by" << metadata->name() << Debug::nospace << ")";
}
/* Instantiate the plugin, propagate flags */
Containers::Pointer<AbstractImageConverter> converter = static_cast<PluginManager::Manager<AbstractImageConverter>*>(manager())->instantiate(plugin);
converter->setFlags(flags());
/* Propagate configuration */
Magnum::Implementation::propagateConfiguration("Trade::AnyImageConverter::convertToFile():", {}, metadata->name(), configuration(), converter->configuration());
/* Try to convert the file (error output should be printed by the plugin
itself) */
return converter->convertToFile(imageLevels, filename);
}
bool AnyImageConverter::doConvertToFile(Containers::ArrayView<const CompressedImageView2D>, const Containers::StringView filename) {
bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const CompressedImageView2D> imageLevels, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/* No file formats to store multi-level compressed 2D data yet */
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s))
plugin = "KtxImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level compressed 2D image";
return false;
}
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level compressed 2D image";
return false;
/* Try to load the plugin */
if(!(manager()->load(plugin) & PluginManager::LoadState::Loaded)) {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot load the" << plugin << "plugin";
return false;
}
const PluginManager::PluginMetadata* const metadata = manager()->metadata(plugin);
CORRADE_INTERNAL_ASSERT(metadata);
if(flags() & ImageConverterFlag::Verbose) {
Debug d;
d << "Trade::AnyImageConverter::convertToFile(): using" << plugin;
if(plugin != metadata->name())
d << "(provided by" << metadata->name() << Debug::nospace << ")";
}
/* Instantiate the plugin, propagate flags */
Containers::Pointer<AbstractImageConverter> converter = static_cast<PluginManager::Manager<AbstractImageConverter>*>(manager())->instantiate(plugin);
converter->setFlags(flags());
/* Propagate configuration */
Magnum::Implementation::propagateConfiguration("Trade::AnyImageConverter::convertToFile():", {}, metadata->name(), configuration(), converter->configuration());
/* Try to convert the file (error output should be printed by the plugin
itself) */
return converter->convertToFile(imageLevels, filename);
}
bool AnyImageConverter::doConvertToFile(Containers::ArrayView<const CompressedImageView3D>, const Containers::StringView filename) {
bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const CompressedImageView3D> imageLevels, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager());
/* No file formats to store multi-level compressed 3D data yet */
/** @todo once Directory is std::string-free, use splitExtension(), but
only if we don't detect more than one extension yet */
const Containers::String normalized = Utility::String::lowercase(filename);
/* Detect the plugin from extension */
Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s))
plugin = "KtxImageConverter"_s;
else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level compressed 3D image";
return false;
}
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level compressed 3D image";
return false;
/* Try to load the plugin */
if(!(manager()->load(plugin) & PluginManager::LoadState::Loaded)) {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot load the" << plugin << "plugin";
return false;
}
const PluginManager::PluginMetadata* const metadata = manager()->metadata(plugin);
CORRADE_INTERNAL_ASSERT(metadata);
if(flags() & ImageConverterFlag::Verbose) {
Debug d;
d << "Trade::AnyImageConverter::convertToFile(): using" << plugin;
if(plugin != metadata->name())
d << "(provided by" << metadata->name() << Debug::nospace << ")";
}
/* Instantiate the plugin, propagate flags */
Containers::Pointer<AbstractImageConverter> converter = static_cast<PluginManager::Manager<AbstractImageConverter>*>(manager())->instantiate(plugin);
converter->setFlags(flags());
/* Propagate configuration */
Magnum::Implementation::propagateConfiguration("Trade::AnyImageConverter::convertToFile():", {}, metadata->name(), configuration(), converter->configuration());
/* Try to convert the file (error output should be printed by the plugin
itself) */
return converter->convertToFile(imageLevels, filename);
}
}}

24
src/MagnumPlugins/AnyImageConverter/AnyImageConverter.h

@ -57,24 +57,28 @@ Detects file type based on file extension, loads corresponding plugin and then
tries to convert the file with it. Supported formats for uncompressed data:
- Basis Universal (`*.basis`), converted with @ref BasisImageConverter or any
other plugin that provides it
other plugin that provides it. Only uncompressed 2D and multi-level 2D
images.
- Windows Bitmap (`*.bmp`), converted with any plugin that provides
`BmpImageConverter`
`BmpImageConverter`. Only uncompressed 2D images.
- OpenEXR (`*.exr`), converted with any plugin that provides
`OpenExrImageConverter`
`OpenExrImageConverter`. Only uncompressed 2D/3D and multi-level 2D/3D
images.
- Radiance HDR (`*.hdr`), converted with any plugin that provides
`HdrImageConverter`
`HdrImageConverter`. Only uncompressed 2D images.
- JPEG (`*.jpg`, `*.jpe`, `*.jpeg`), converted with @ref JpegImageConverter
or any other plugin that provides it
or any other plugin that provides it. Only uncompressed 2D images.
- KTX2 (`*.ktx2`), converted with @ref KtxImageConverter or any other plugin
that provides it
that provides it. Uncompressed, compressed, 1D/2D/3D and multi-level
1D/2D/3D images.
- Portable Network Graphics (`*.png`), converted with @ref PngImageConverter
or any other plugin that provides it
or any other plugin that provides it. Only uncompressed 2D images.
- Truevision TGA (`*.tga`, `*.vda`, `*.icb`, `*.vst`), converted with
@ref TgaImageConverter or any other plugin that provides it
@ref TgaImageConverter or any other plugin that provides it. Only
uncompressed 2D images.
No supported formats for compressed data yet. Only exporting to files is
supported.
As the converter plugin is picked based on file extension, only saving to files
is supported.
@section Trade-AnyImageConverter-usage Usage

868
src/MagnumPlugins/AnyImageConverter/Test/AnyImageConverterTest.cpp

File diff suppressed because it is too large Load Diff

3
src/MagnumPlugins/AnyImageConverter/Test/CMakeLists.txt

@ -29,10 +29,12 @@ find_package(Threads REQUIRED)
if(CORRADE_TARGET_EMSCRIPTEN OR CORRADE_TARGET_ANDROID)
set(ANYIMAGECONVERTER_TEST_OUTPUT_DIR "write")
set(KTX_1D_FILE 1d.ktx2)
set(KTX_3D_FILE 3d.ktx2)
set(EXR_FILE depth32f-custom-channels.exr)
else()
set(ANYIMAGECONVERTER_TEST_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(KTX_1D_FILE ${PROJECT_SOURCE_DIR}/src/MagnumPlugins/AnyImageImporter/Test/1d.ktx2)
set(KTX_3D_FILE ${PROJECT_SOURCE_DIR}/src/MagnumPlugins/AnyImageImporter/Test/3d.ktx2)
set(EXR_FILE ${PROJECT_SOURCE_DIR}/src/MagnumPlugins/AnyImageImporter/Test/depth32f-custom-channels.exr)
endif()
@ -62,6 +64,7 @@ corrade_add_test(AnyImageConverterTest AnyImageConverterTest.cpp
# now
Threads::Threads
FILES
../../AnyImageImporter/Test/1d.ktx2
../../AnyImageImporter/Test/3d.ktx2
../../AnyImageImporter/Test/depth32f-custom-channels.exr)
target_include_directories(AnyImageConverterTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)

1
src/MagnumPlugins/AnyImageConverter/Test/configure.h.cmake

@ -26,6 +26,7 @@
#cmakedefine ANYIMAGECONVERTER_PLUGIN_FILENAME "${ANYIMAGECONVERTER_PLUGIN_FILENAME}"
#cmakedefine TGAIMAGECONVERTER_PLUGIN_FILENAME "${TGAIMAGECONVERTER_PLUGIN_FILENAME}"
#define ANYIMAGECONVERTER_TEST_OUTPUT_DIR "${ANYIMAGECONVERTER_TEST_OUTPUT_DIR}"
#define KTX_1D_FILE "${KTX_1D_FILE}"
#define KTX_3D_FILE "${KTX_3D_FILE}"
#define EXR_FILE "${EXR_FILE}"

BIN
src/MagnumPlugins/AnyImageImporter/Test/1d.ktx2

Binary file not shown.

37
src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp

@ -70,6 +70,16 @@ Containers::Optional<Containers::ArrayView<const char>> fileCallback(const std::
return Containers::ArrayView<const char>{storage};
}
constexpr struct {
const char* name;
const char* filename;
Containers::Optional<Containers::ArrayView<const char>>(*callback)(const std::string&, InputFileCallbackPolicy, Containers::Array<char>&);
const char* messageFunctionName;
} Load1DData[]{
{"KTX2", KTX_1D_FILE, nullptr, "KtxImporter"},
{"KTX2 data", KTX_1D_FILE, fileCallback, "KtxImporter"},
};
constexpr struct {
const char* name;
const char* filename;
@ -149,7 +159,8 @@ constexpr struct {
};
AnyImageImporterTest::AnyImageImporterTest() {
addTests({&AnyImageImporterTest::load1D});
addInstancedTests({&AnyImageImporterTest::load1D},
Containers::arraySize(Load1DData));
addInstancedTests({&AnyImageImporterTest::load2D},
Containers::arraySize(Load2DData));
@ -188,7 +199,29 @@ AnyImageImporterTest::AnyImageImporterTest() {
}
void AnyImageImporterTest::load1D() {
CORRADE_SKIP("No file formats supporting 1D images yet.");
auto&& data = Load1DData[testCaseInstanceId()];
setTestCaseDescription(data.name);
PluginManager::Manager<AbstractImporter> manager{MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR};
#ifdef ANYIMAGEIMPORTER_PLUGIN_FILENAME
CORRADE_VERIFY(manager.load(ANYIMAGEIMPORTER_PLUGIN_FILENAME) & PluginManager::LoadState::Loaded);
#endif
if(manager.loadState("KtxImporter") < PluginManager::LoadState::Loaded)
CORRADE_SKIP("KtxImporter plugin can't be loaded.");
Containers::Pointer<AbstractImporter> importer = manager.instantiate("AnyImageImporter");
Containers::Array<char> storage;
importer->setFileCallback(data.callback, storage);
CORRADE_VERIFY(importer->openFile(data.filename));
CORRADE_COMPARE(importer->image1DCount(), 1);
/* Check only size, as it is good enough proof that it is working */
Containers::Optional<ImageData1D> image = importer->image1D(0);
CORRADE_VERIFY(image);
CORRADE_COMPARE(image->size(), 2);
}
void AnyImageImporterTest::load2D() {

5
src/MagnumPlugins/AnyImageImporter/Test/CMakeLists.txt

@ -26,11 +26,13 @@
if(CORRADE_TARGET_EMSCRIPTEN OR CORRADE_TARGET_ANDROID)
set(TEST_FILE_DIR .)
set(TGA_FILE rgb.tga)
set(KTX_1D_FILE 1d.ktx2)
set(KTX_3D_FILE 3d.ktx2)
set(EXR_FILE depth32f-custom-channels.exr)
else()
set(TEST_FILE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(TGA_FILE ${CMAKE_CURRENT_SOURCE_DIR}/rgb.tga)
set(KTX_1D_FILE ${CMAKE_CURRENT_SOURCE_DIR}/1d.ktx2)
set(KTX_3D_FILE ${CMAKE_CURRENT_SOURCE_DIR}/3d.ktx2)
set(EXR_FILE ${CMAKE_CURRENT_SOURCE_DIR}/depth32f-custom-channels.exr)
endif()
@ -57,7 +59,8 @@ corrade_add_test(AnyImageImporterTest AnyImageImporterTest.cpp
FILES
# Generated by AnyImageConverterTest::propagateConfiguration2D()
depth32f-custom-channels.exr
# Generated by AnyImageConverterTest::convert3D()
# Generated by AnyImageConverterTest::convert{1D,3D}()
1d.ktx2
3d.ktx2
gray.jpg
image.exr

1
src/MagnumPlugins/AnyImageImporter/Test/configure.h.cmake

@ -27,6 +27,7 @@
#cmakedefine TGAIMPORTER_PLUGIN_FILENAME "${TGAIMPORTER_PLUGIN_FILENAME}"
#define TGA_FILE "${TGA_FILE}"
#define TEST_FILE_DIR "${TEST_FILE_DIR}"
#define KTX_1D_FILE "${KTX_1D_FILE}"
#define KTX_3D_FILE "${KTX_3D_FILE}"
#define EXR_FILE "${EXR_FILE}"

Loading…
Cancel
Save