diff --git a/src/MagnumPlugins/AnyImageConverter/AnyImageConverter.cpp b/src/MagnumPlugins/AnyImageConverter/AnyImageConverter.cpp index 1a1ba784e..91e468a62 100644 --- a/src/MagnumPlugins/AnyImageConverter/AnyImageConverter.cpp +++ b/src/MagnumPlugins/AnyImageConverter/AnyImageConverter.cpp @@ -73,7 +73,8 @@ bool AnyImageConverter::doConvertToFile(const ImageView1D& image, const Containe /* Detect the plugin from extension */ Containers::StringView plugin; - if(normalizedExtension == ".ktx2"_s) + if(normalizedExtension == ".ktx"_s || + normalizedExtension == ".ktx2"_s) plugin = "KtxImageConverter"_s; else { Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a 1D image"; @@ -129,7 +130,8 @@ bool AnyImageConverter::doConvertToFile(const ImageView2D& image, const Containe normalizedExtension == ".jpeg"_s || normalizedExtension == ".jpe"_s) plugin = "JpegImageConverter"_s; - else if(normalizedExtension == ".ktx2"_s) + else if(normalizedExtension == ".ktx"_s || + normalizedExtension == ".ktx2"_s) plugin = "KtxImageConverter"_s; else if(normalizedExtension == ".png"_s) plugin = "PngImageConverter"_s; @@ -184,7 +186,8 @@ bool AnyImageConverter::doConvertToFile(const ImageView3D& image, const Containe plugin = "BasisImageConverter"_s; else if(normalizedExtension == ".exr"_s) plugin = "OpenExrImageConverter"_s; - else if(normalizedExtension == ".ktx2"_s) + else if(normalizedExtension == ".ktx"_s || + normalizedExtension == ".ktx2"_s) plugin = "KtxImageConverter"_s; else if(normalizedExtension == ".vdb"_s) plugin = "OpenVdbImageConverter"_s; @@ -230,7 +233,8 @@ bool AnyImageConverter::doConvertToFile(const CompressedImageView1D& image, cons /* Detect the plugin from extension */ Containers::StringView plugin; - if(normalizedExtension == ".ktx2"_s) + if(normalizedExtension == ".ktx"_s || + normalizedExtension == ".ktx2"_s) plugin = "KtxImageConverter"_s; else { Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a compressed 1D image"; @@ -274,7 +278,8 @@ bool AnyImageConverter::doConvertToFile(const CompressedImageView2D& image, cons /* Detect the plugin from extension */ Containers::StringView plugin; - if(normalizedExtension == ".ktx2"_s) + if(normalizedExtension == ".ktx"_s || + normalizedExtension == ".ktx2"_s) plugin = "KtxImageConverter"_s; else { Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a compressed 2D image"; @@ -318,7 +323,8 @@ bool AnyImageConverter::doConvertToFile(const CompressedImageView3D& image, cons /* Detect the plugin from extension */ Containers::StringView plugin; - if(normalizedExtension == ".ktx2"_s) + if(normalizedExtension == ".ktx"_s || + normalizedExtension == ".ktx2"_s) plugin = "KtxImageConverter"_s; else { Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a compressed 3D image"; @@ -362,7 +368,8 @@ bool AnyImageConverter::doConvertToFile(const Containers::ArrayView&& data, DataFlags) { /* https://en.wikipedia.org/wiki/JPEG#Syntax_and_structure */ else if(dataString.hasPrefix("\xff\xd8\xff"_s)) plugin = "JpegImporter"_s; - /* https://github.khronos.org/KTX-Specification/#_identifier */ - else if(dataString.hasPrefix("\xabKTX 20\xbb\r\n\x1a\n"_s)) + /* https://github.khronos.org/KTX-Specification/#_identifier and + https://www.khronos.org/registry/KTX/specs/1.0/ktxspec_v1.html */ + else if(dataString.hasPrefix("\xabKTX 20\xbb\r\n\x1a\n"_s) || + dataString.hasPrefix("\xabKTX 11\xbb\r\n\x1a\n"_s)) plugin = "KtxImporter"_s; /* https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header */ else if(dataString.hasPrefix("\x89PNG\x0d\x0a\x1a\x0a"_s)) diff --git a/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.h b/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.h index 1878e6eb1..9e1406142 100644 --- a/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.h +++ b/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.h @@ -78,8 +78,8 @@ Supported formats: loaded with @ref JpegImporter or any other plugin that provides it - JPEG 2000 (`*.jp2`), loaded with any plugin that provides `Jpeg2000Importer` -- KTX2 (`*.ktx2` or data with corresponding signature), loaded with - @ref KtxImporter or any other plugin that provides it +- KTX and KTX2 (`*.ktx`, `*.ktx2` or data with corresponding signature), + loaded with @ref KtxImporter or any other plugin that provides it - Multiple-image Network Graphics (`*.mng`), loaded with any plugin that provides `MngImporter` - Portable Bitmap (`*.pbm`), loaded with any plugin that provides `PbmImporter` diff --git a/src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp b/src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp index 93e8a73e3..047ea057a 100644 --- a/src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp +++ b/src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp @@ -110,6 +110,8 @@ constexpr struct { {"JPEG data", "gray.jpg", true, "JpegImporter"}, {"JPEG uppercase", "uppercase.JPG", false, "JpegImporter"}, {"JPEG2000", "image.jp2", false, "Jpeg2000Importer"}, + {"KTX1", "version1.ktx", false, "KtxImporter"}, + {"KTX1 data", "version1.ktx", true, "KtxImporter"}, {"HDR", "rgb.hdr", false, "HdrImporter"}, {"HDR data", "rgb.hdr", true, "HdrImporter"}, {"ICO", "pngs.ico", false, "IcoImporter"}, diff --git a/src/MagnumPlugins/AnyImageImporter/Test/CMakeLists.txt b/src/MagnumPlugins/AnyImageImporter/Test/CMakeLists.txt index 9638be446..b77a3f438 100644 --- a/src/MagnumPlugins/AnyImageImporter/Test/CMakeLists.txt +++ b/src/MagnumPlugins/AnyImageImporter/Test/CMakeLists.txt @@ -68,6 +68,8 @@ corrade_add_test(AnyImageImporterTest AnyImageImporterTest.cpp # Generated by AnyImageConverterTest::convert{1D,3D}() 1d.ktx2 3d.ktx2 + # From KtxImporter test data (in magnum-plugins) + version1.ktx gray.jpg image.exr image.tiff diff --git a/src/MagnumPlugins/AnyImageImporter/Test/version1.ktx b/src/MagnumPlugins/AnyImageImporter/Test/version1.ktx new file mode 100644 index 000000000..d8ce8e4de Binary files /dev/null and b/src/MagnumPlugins/AnyImageImporter/Test/version1.ktx differ