Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnyImageImporter: detect KTX2 #529

Merged
merged 1 commit into from
Jul 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ void AnyImageImporter::doOpenFile(const std::string& filename) {
plugin = "JpegImporter";
else if(Utility::String::endsWith(normalized, ".jp2"))
plugin = "Jpeg2000Importer";
else if(Utility::String::endsWith(normalized, ".ktx2"))
plugin = "KtxImporter";
else if(Utility::String::endsWith(normalized, ".mng"))
plugin = "MngImporter";
else if(Utility::String::endsWith(normalized, ".pbm"))
Expand Down Expand Up @@ -177,6 +179,9 @@ void AnyImageImporter::doOpenData(Containers::ArrayView<const char> data) {
/* https://en.wikipedia.org/wiki/JPEG#Syntax_and_structure */
else if(dataString.hasPrefix("\xff\xd8\xff"_s))
plugin = "JpegImporter";
/* https://github.khronos.org/KTX-Specification/#_identifier */
else if(dataString.hasPrefix("\xabKTX 20\xbb\r\n\x1a\n"_s))
plugin = "KtxImporter";
/* https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header */
else if(dataString.hasPrefix("\x89PNG\x0d\x0a\x1a\x0a"_s))
plugin = "PngImporter";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ constexpr struct {
{"JPEG data", "gray.jpg", fileCallback, "JpegImporter"},
{"JPEG uppercase", "uppercase.JPG", nullptr, "JpegImporter"},
{"JPEG2000", "image.jp2", nullptr, "Jpeg2000Importer"},
{"KTX", "image.ktx2", nullptr, "KtxImporter"},
{"EXR", "image.exr", nullptr, "OpenExrImporter"},
{"EXR data", "image.exr", fileCallback, "OpenExrImporter"},
{"HDR", "rgb.hdr", nullptr, "HdrImporter"},
Expand Down Expand Up @@ -123,7 +124,8 @@ const struct {
{"just one zero byte", "\x00"_s, "00"},
{"DDS, but no space", "DDS!"_s, "44445321"},
{"TIFF, but too short", "II\x2a"_s, "49492a"},
{"TIFF, but no zero byte", "MM\xff\x2a"_s, "4d4dff2a"}
{"TIFF, but no zero byte", "MM\xff\x2a"_s, "4d4dff2a"},
{"KTX, but wrong version", "\xabKTX 30\xbb\r\n\x1a\n"_s, "ab4b5458"}
};

constexpr struct {
Expand Down