diff --git a/doc/changelog.dox b/doc/changelog.dox index f4c48821a..641b2e1b7 100644 --- a/doc/changelog.dox +++ b/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)) diff --git a/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp b/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp index e0bf814cd..673b1fc34 100644 --- a/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp +++ b/src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp @@ -215,8 +215,16 @@ void AnyImageImporter::doOpenData(Containers::Array&& 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)) diff --git a/src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp b/src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp index 20251d3de..52816d70c 100644 --- a/src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp +++ b/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"}, diff --git a/src/MagnumPlugins/AnyImageImporter/Test/CMakeLists.txt b/src/MagnumPlugins/AnyImageImporter/Test/CMakeLists.txt index eec68ce62..bbef10477 100644 --- a/src/MagnumPlugins/AnyImageImporter/Test/CMakeLists.txt +++ b/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 diff --git a/src/MagnumPlugins/AnyImageImporter/Test/rgb.2.hdr b/src/MagnumPlugins/AnyImageImporter/Test/rgb.2.hdr new file mode 100644 index 000000000..d1a9dc535 Binary files /dev/null and b/src/MagnumPlugins/AnyImageImporter/Test/rgb.2.hdr differ