From 656a429a8813c2cec2d1c3e51649cf587e99a017 Mon Sep 17 00:00:00 2001 From: Squareys Date: Tue, 27 Aug 2019 18:48:15 +0200 Subject: [PATCH] AnyImageImporter: Delegate .basis files to BasisImporterEtc2 Signed-off-by: Squareys --- .../AnyImageImporter/AnyImageImporter.cpp | 12 ++++++++++-- .../AnyImageImporter/AnyImageImporter.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp b/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp index 797463fbca..e6139b06be 100644 --- a/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp +++ b/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp @@ -57,7 +57,12 @@ void AnyImageImporter::doOpenFile(const std::string& filename) { /* Detect type from extension */ std::string plugin; - if(Utility::String::endsWith(normalized, ".bmp")) + if(Utility::String::endsWith(normalized, ".basis")) + /* Basis may be transcoded to various target formats. + To ensure consistent output format, it makes sense + to specify it as Etc2 here. */ + plugin = "BasisImporterEtc2"; + else if(Utility::String::endsWith(normalized, ".bmp")) plugin = "BmpImporter"; else if(Utility::String::endsWith(normalized, ".dds")) plugin = "DdsImporter"; @@ -128,8 +133,11 @@ void AnyImageImporter::doOpenData(Containers::ArrayView data) { CORRADE_INTERNAL_ASSERT(manager()); std::string plugin; + /* https://github.com/BinomialLLC/basis_universal/blob/7d784c728844c007d8c95d63231f7adcc0f65364/transcoder/basisu_file_headers.h#L78 */ + if(Utility::String::viewBeginsWith(data, "sB\0\x16") + plugin = "BasisImporterEtc2"; /* https://docs.microsoft.com/cs-cz/windows/desktop/direct3ddds/dx-graphics-dds-pguide */ - if(Utility::String::viewBeginsWith(data, "DDS ")) + else if(Utility::String::viewBeginsWith(data, "DDS ")) plugin = "DdsImporter"; /* http://www.openexr.com/openexrfilelayout.pdf */ else if(Utility::String::viewBeginsWith(data, "\x76\x2f\x31\x01")) diff --git a/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.h b/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.h index 403228edc0..d28a3ed541 100644 --- a/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.h +++ b/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.h @@ -66,6 +66,7 @@ of the `Magnum` package and link to the `Magnum::AnyImageImporter` target. See Supported formats: +- Basis Universal (`*.basis`), loaded with any plugin that provides `BasisImporterEtc2` - Windows Bitmap (`*.bmp`), loaded with any plugin that provides `BmpImporter` - DirectDraw Surface (`*.dds` or data with corresponding signature), loaded with @ref DdsImporter or any other plugin that provides it