From cdfe668d584dab419e72b98b183beaf5a3a312af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 27 May 2022 23:47:21 +0200 Subject: [PATCH] AnyImageImporter: recognize ASTC files and data. --- doc/file-formats.dox | 10 ++++++++++ .../AnyImageImporter/AnyImageImporter.cpp | 10 ++++++++-- .../AnyImageImporter/AnyImageImporter.h | 3 +++ src/MagnumPlugins/AnyImageImporter/Test/8x8.astc | Bin 0 -> 528 bytes .../Test/AnyImageImporterTest.cpp | 2 ++ .../AnyImageImporter/Test/CMakeLists.txt | 2 ++ 6 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/MagnumPlugins/AnyImageImporter/Test/8x8.astc diff --git a/doc/file-formats.dox b/doc/file-formats.dox index 4121002b5..03cefba62 100644 --- a/doc/file-formats.dox +++ b/doc/file-formats.dox @@ -70,6 +70,16 @@ Together with @ref file-formats-scene-importers "scene importers" derived from + +ASTC (`*.astc`) +`AstcImporter` +@relativeref{Trade,AstcImporter} +@ref Trade-AstcImporter-behavior "none" +@m_span{m-text m-dim} none @m_endspan + + + + Basis Universal (`*.basis`) `BasisImporter` diff --git a/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp b/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp index 90fd1fd10..d8cdfcd55 100644 --- a/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp +++ b/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp @@ -71,7 +71,9 @@ void AnyImageImporter::doOpenFile(const Containers::StringView filename) { /* Detect the plugin from extension */ Containers::StringView plugin; - if(normalizedExtension == ".basis"_s) + if(normalizedExtension == ".astc"_s) + plugin = "AstcImporter"_s; + else if(normalizedExtension == ".basis"_s) plugin = "BasisImporter"_s; else if(normalizedExtension == ".bmp"_s) plugin = "BmpImporter"_s; @@ -173,8 +175,12 @@ void AnyImageImporter::doOpenData(Containers::Array&& data, DataFlags) { const Containers::StringView dataString = dataView; Containers::StringView plugin; + /* https://stackoverflow.com/questions/22600678/determine-internal-format-of-given-astc-compressed-image-through-its-header + unfortunately it being in LE means it's SCALABLE in reverse :) */ + if(dataString.hasPrefix("\x13\xAB\xA1\x5C"_s)) + plugin = "AstcImporter"_s; /* https://github.com/BinomialLLC/basis_universal/blob/7d784c728844c007d8c95d63231f7adcc0f65364/transcoder/basisu_file_headers.h#L78 */ - if(dataString.hasPrefix("sB"_s)) + else if(dataString.hasPrefix("sB"_s)) plugin = "BasisImporter"_s; /* https://en.wikipedia.org/wiki/BMP_file_format#Bitmap_file_header */ else if(dataString.hasPrefix("BM"_s)) diff --git a/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.h b/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.h index d312b60a9..d13fe634b 100644 --- a/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.h +++ b/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.h @@ -57,6 +57,9 @@ Detects file type based on file extension or a signature at the start of the file, loads corresponding plugin and then tries to open the file with it. Supported formats: +- Adaptive Scalable Texture Compression (`*.astc` or data with corresponding + signature), loaded with @ref AstcImporter or any other plugin that provides + it - Basis Universal (`*.basis` or data with corresponding signature), loaded with @ref BasisImporter or any other plugin that provides it - Windows Bitmap (`*.bmp` or data with corresponding signature), loaded with diff --git a/src/MagnumPlugins/AnyImageImporter/Test/8x8.astc b/src/MagnumPlugins/AnyImageImporter/Test/8x8.astc new file mode 100644 index 0000000000000000000000000000000000000000..e5d4d0fef4b8d1a355b8022a8ff47ad0658f424e GIT binary patch literal 528 zcmWe$y)cG@gVBM3L4kpRk%3`u%k;(Rd1)~&G53ULr!aqTX?~hJ?WvIn*Z)7iKY#!J z*`;;r>08$pX#BUo{~id=qpPoLjE`eupE+~kUZ7zP(<<{hTdp4X^V#f}%jT`e6oTff zw&<>P{lD(asS~S!;D0^3dcW4`^D{FNQj+Qz81B04W+0spvVZ#Q#<`3K&L~~o?$=5x zzrTO}!uYsH-xv-U3$8lj*Gd}yoa^k&q#ud3j0cW9d3X2ke^U7%`{n}e|Ha4X@IP%P z152x?^@W=<-uLbQ13~|Pm)4n+?;raiUvIyE{{8p-|IyX^wa%WKo|Tm35DW7EU1MPU i`2yoFPyEl%-`{`#`R~%KncMc%NKYITe?UXg)dK(!QVEy< literal 0 HcmV?d00001 diff --git a/src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp b/src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp index 6142d1270..cb5409e04 100644 --- a/src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp +++ b/src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp @@ -102,6 +102,8 @@ constexpr struct { bool asData; const char* plugin; } DetectData[]{ + {"ASTC", "8x8.astc", false, "AstcImporter"}, + {"ASTC data", "8x8.astc", true, "AstcImporter"}, {"PNG", "rgb.png", false, "PngImporter"}, {"PNG data", "rgb.png", true, "PngImporter"}, {"JPEG", "gray.jpg", false, "JpegImporter"}, diff --git a/src/MagnumPlugins/AnyImageImporter/Test/CMakeLists.txt b/src/MagnumPlugins/AnyImageImporter/Test/CMakeLists.txt index 0ca0f3e3f..aebfd7699 100644 --- a/src/MagnumPlugins/AnyImageImporter/Test/CMakeLists.txt +++ b/src/MagnumPlugins/AnyImageImporter/Test/CMakeLists.txt @@ -61,6 +61,8 @@ file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/$/configure.h corrade_add_test(AnyImageImporterTest AnyImageImporterTest.cpp LIBRARIES MagnumTrade MagnumDebugTools FILES + # From AstcImporter test data (in magnum-plugins) + 8x8.astc # Generated by AnyImageConverterTest::propagateConfiguration2D() depth32f-custom-channels.exr # Generated by AnyImageConverterTest::convert{1D,3D}()