Browse Source

AnyImageImporter: recognize also the other Radiance HDR file signature.

pull/653/head
Vladimír Vondruš 2 years ago
parent
commit
f91638c461
  1. 2
      doc/changelog.dox
  2. 12
      src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp
  3. 2
      src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp
  4. 2
      src/MagnumPlugins/AnyImageImporter/Test/CMakeLists.txt
  5. BIN
      src/MagnumPlugins/AnyImageImporter/Test/rgb.2.hdr

2
doc/changelog.dox

@ -944,6 +944,8 @@ See also:
- Recognizing BMP and TIFF file header magic in @relativeref{Trade,AnyImageImporter}
- Recognizing ASTC and WebP files and data in
@relativeref{Trade,AnyImageImporter}
- Recognizing also a second variant of Radiance HDR file headers in
@relativeref{Trade,AnyImageImporter} (see [mosra/magnum#652](https://github.com/mosra/magnum/issues/652))
- Recognizing KTX2 files and data in @relativeref{Trade,AnyImageImporter} and
@relativeref{Trade,AnyImageConverter} (see also
[mosra/magnum#529](https://github.com/mosra/magnum/pull/529))

12
src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp

@ -215,8 +215,16 @@ void AnyImageImporter::doOpenData(Containers::Array<char>&& data, DataFlags) {
/* http://www.openexr.com/openexrfilelayout.pdf */
else if(dataString.hasPrefix("\x76\x2f\x31\x01"_s))
plugin = "OpenExrImporter"_s;
/* https://en.wikipedia.org/wiki/Radiance_(software)#HDR_image_format */
else if(dataString.hasPrefix("#?RADIANCE"_s))
/* https://en.wikipedia.org/wiki/Radiance_(software)#HDR_image_format and
https://en.wikipedia.org/wiki/RGBE_image_format which lists also the \n
at the end. There's also a RGBE signature that isn't mentioned on
Wikipedia, at https://paulbourke.net/dataformats/pic/ or used by the
file utility https://github.com/file/file/blob/0fa2c8c3e64c372d038d46969bafaaa09a13a87b/magic/Magdir/images#L2755-L2759
but is used by https://www.graphics.cornell.edu/~bjw/rgbe/rgbe.c which
is subsequently derived from in e.g. https://github.com/kopaka1822/ImageViewer/blob/5ec358cf5c3f818c0cc4c363f5ec0c61aa99d372/dependencies/hdr/rgbe.h#L210
and stb_image recognizes that as well. */
else if(dataString.hasPrefix("#?RADIANCE\n"_s) ||
dataString.hasPrefix("#?RGBE\n"_s))
plugin = "HdrImporter"_s;
/* https://en.wikipedia.org/wiki/JPEG#Syntax_and_structure */
else if(dataString.hasPrefix("\xff\xd8\xff"_s))

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

@ -102,6 +102,7 @@ constexpr struct {
{"JPEG2000", "image.jp2", false, "Jpeg2000Importer"},
{"HDR", "rgb.hdr", false, "HdrImporter"},
{"HDR data", "rgb.hdr", true, "HdrImporter"},
{"HDR data, different signature", "rgb.2.hdr", true, "HdrImporter"},
{"ICO", "pngs.ico", false, "IcoImporter"},
{"DDS", "rgba_dxt1.dds", false, "DdsImporter"},
{"DDS data", "rgba_dxt1.dds", true, "DdsImporter"},
@ -159,6 +160,7 @@ const struct {
{"just one byte", "\x33"_s, "33"},
{"just one zero byte", "\x00"_s, "00"},
{"DDS, but no space", "DDS!"_s, "44445321"},
{"HDR, but without the trailing newline", "#?RADIANCE."_s, "233f5241"},
{"TIFF, but too short", "II\x2a"_s, "49492a"},
{"TIFF, but no zero byte", "MM\xff\x2a"_s, "4d4dff2a"},
{"KTX, but wrong version", "\xabKTX 30\xbb\r\n\x1a\n"_s, "ab4b5458"},

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

@ -67,6 +67,8 @@ corrade_add_test(AnyImageImporterTest AnyImageImporterTest.cpp
rgb.basis
rgb.bmp
rgb.hdr
# Created using https://github.com/kopaka1822/ImageViewer/
rgb.2.hdr
rgb.png
rgb.tga
rgba_dxt1.dds

BIN
src/MagnumPlugins/AnyImageImporter/Test/rgb.2.hdr

Binary file not shown.
Loading…
Cancel
Save