diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp index 267b871db0..e309bd6ec3 100644 --- a/Tests/LibGfx/TestImageDecoder.cpp +++ b/Tests/LibGfx/TestImageDecoder.cpp @@ -462,6 +462,18 @@ TEST_CASE(test_tiff_lzw) EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red); } +TEST_CASE(test_tiff_defalte) +{ + auto file = MUST(Core::MappedFile::map(TEST_INPUT("tiff/deflate.tiff"sv))); + EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes())); + + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 400, 300 })); + + EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White); + EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red); +} + TEST_CASE(test_tiff_packed_bits) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("tiff/packed_bits.tiff"sv))); diff --git a/Tests/LibGfx/test-inputs/tiff/deflate.tiff b/Tests/LibGfx/test-inputs/tiff/deflate.tiff new file mode 100644 index 0000000000..4c471cb9a4 Binary files /dev/null and b/Tests/LibGfx/test-inputs/tiff/deflate.tiff differ diff --git a/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp index 4297cd3754..8f7ffc85fe 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp @@ -5,11 +5,13 @@ */ #include "TIFFLoader.h" +#include #include #include #include #include #include +#include #include #include @@ -280,6 +282,20 @@ private: TRY(loop_over_pixels(move(decode_lzw_strip))); break; } + case Compression::AdobeDeflate: { + // This is an extension from the Technical Notes from 2002: + // https://web.archive.org/web/20160305055905/http://partners.adobe.com/public/developer/en/tiff/TIFFphotoshop.pdf + ByteBuffer decoded_bytes {}; + auto decode_zlib = [&](u32 num_bytes) -> ErrorOr { + auto stream = make(MaybeOwned(*m_stream), num_bytes); + auto decompressed_stream = TRY(Compress::ZlibDecompressor::create(move(stream))); + decoded_bytes = TRY(decompressed_stream->read_until_eof(4096)); + return decoded_bytes; + }; + + TRY(loop_over_pixels(move(decode_zlib))); + break; + } case Compression::PackBits: { // Section 9: PackBits Compression ByteBuffer decoded_bytes {}; diff --git a/Userland/Libraries/LibGfx/TIFFGenerator.py b/Userland/Libraries/LibGfx/TIFFGenerator.py index 0fcaffbadd..d821119ebf 100755 --- a/Userland/Libraries/LibGfx/TIFFGenerator.py +++ b/Userland/Libraries/LibGfx/TIFFGenerator.py @@ -47,6 +47,7 @@ class Compression(EnumWithExportName): Group4Fax = 4 LZW = 5 JPEG = 6 + AdobeDeflate = 8 PackBits = 32773