Browse Source

AnyImageImporter: recognize ASTC files and data.

ktx1-detection
Vladimír Vondruš 4 years ago
parent
commit
cdfe668d58
  1. 10
      doc/file-formats.dox
  2. 10
      src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp
  3. 3
      src/MagnumPlugins/AnyImageImporter/AnyImageImporter.h
  4. BIN
      src/MagnumPlugins/AnyImageImporter/Test/8x8.astc
  5. 2
      src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp
  6. 2
      src/MagnumPlugins/AnyImageImporter/Test/CMakeLists.txt

10
doc/file-formats.dox

@ -70,6 +70,16 @@ Together with @ref file-formats-scene-importers "scene importers" derived from
</tr> </tr>
<tr><td colspan="6"></td></tr> <tr><td colspan="6"></td></tr>
<tr>
<th>ASTC (`*.astc`)</th>
<td>`AstcImporter`</td>
<td>@relativeref{Trade,AstcImporter}</td>
<td class="m-text-center m-dim">@ref Trade-AstcImporter-behavior "none"</td>
<td class="m-text-center">@m_span{m-text m-dim} none @m_endspan </td>
<td class="m-text-center"></td>
</tr>
<tr><td colspan="6"></td></tr>
<tr> <tr>
<th>Basis Universal (`*.basis`)</th> <th>Basis Universal (`*.basis`)</th>
<td>`BasisImporter`</td> <td>`BasisImporter`</td>

10
src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp

@ -71,7 +71,9 @@ void AnyImageImporter::doOpenFile(const Containers::StringView filename) {
/* Detect the plugin from extension */ /* Detect the plugin from extension */
Containers::StringView plugin; Containers::StringView plugin;
if(normalizedExtension == ".basis"_s) if(normalizedExtension == ".astc"_s)
plugin = "AstcImporter"_s;
else if(normalizedExtension == ".basis"_s)
plugin = "BasisImporter"_s; plugin = "BasisImporter"_s;
else if(normalizedExtension == ".bmp"_s) else if(normalizedExtension == ".bmp"_s)
plugin = "BmpImporter"_s; plugin = "BmpImporter"_s;
@ -173,8 +175,12 @@ void AnyImageImporter::doOpenData(Containers::Array<char>&& data, DataFlags) {
const Containers::StringView dataString = dataView; const Containers::StringView dataString = dataView;
Containers::StringView plugin; 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 */ /* 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; plugin = "BasisImporter"_s;
/* https://en.wikipedia.org/wiki/BMP_file_format#Bitmap_file_header */ /* https://en.wikipedia.org/wiki/BMP_file_format#Bitmap_file_header */
else if(dataString.hasPrefix("BM"_s)) else if(dataString.hasPrefix("BM"_s))

3
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. file, loads corresponding plugin and then tries to open the file with it.
Supported formats: 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 - Basis Universal (`*.basis` or data with corresponding signature), loaded
with @ref BasisImporter or any other plugin that provides it with @ref BasisImporter or any other plugin that provides it
- Windows Bitmap (`*.bmp` or data with corresponding signature), loaded with - Windows Bitmap (`*.bmp` or data with corresponding signature), loaded with

BIN
src/MagnumPlugins/AnyImageImporter/Test/8x8.astc

Binary file not shown.

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

@ -102,6 +102,8 @@ constexpr struct {
bool asData; bool asData;
const char* plugin; const char* plugin;
} DetectData[]{ } DetectData[]{
{"ASTC", "8x8.astc", false, "AstcImporter"},
{"ASTC data", "8x8.astc", true, "AstcImporter"},
{"PNG", "rgb.png", false, "PngImporter"}, {"PNG", "rgb.png", false, "PngImporter"},
{"PNG data", "rgb.png", true, "PngImporter"}, {"PNG data", "rgb.png", true, "PngImporter"},
{"JPEG", "gray.jpg", false, "JpegImporter"}, {"JPEG", "gray.jpg", false, "JpegImporter"},

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

@ -61,6 +61,8 @@ file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/configure.h
corrade_add_test(AnyImageImporterTest AnyImageImporterTest.cpp corrade_add_test(AnyImageImporterTest AnyImageImporterTest.cpp
LIBRARIES MagnumTrade MagnumDebugTools LIBRARIES MagnumTrade MagnumDebugTools
FILES FILES
# From AstcImporter test data (in magnum-plugins)
8x8.astc
# Generated by AnyImageConverterTest::propagateConfiguration2D() # Generated by AnyImageConverterTest::propagateConfiguration2D()
depth32f-custom-channels.exr depth32f-custom-channels.exr
# Generated by AnyImageConverterTest::convert{1D,3D}() # Generated by AnyImageConverterTest::convert{1D,3D}()

Loading…
Cancel
Save