From 9ec34802076b73ed65109ee961115a98341d09e8 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Thu, 15 Feb 2024 19:47:44 -0500 Subject: [PATCH] LibGfx/TIFF: Add support for Group4Fax encoded images Note that we don't parse the T6 option group yet. The test case was generated with GIMP. --- Tests/LibGfx/TestImageDecoder.cpp | 12 ++++++++++++ Tests/LibGfx/test-inputs/tiff/ccitt4.tiff | Bin 0 -> 621 bytes .../Libraries/LibGfx/ImageFormats/TIFFLoader.cpp | 14 ++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 Tests/LibGfx/test-inputs/tiff/ccitt4.tiff diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp index 7e8a63048f..48cd495193 100644 --- a/Tests/LibGfx/TestImageDecoder.cpp +++ b/Tests/LibGfx/TestImageDecoder.cpp @@ -654,6 +654,18 @@ TEST_CASE(test_tiff_ccitt3_2d_fill) EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Black); } +TEST_CASE(test_tiff_ccitt4) +{ + auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/ccitt4.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::Black); +} + TEST_CASE(test_tiff_lzw) { auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/lzw.tiff"sv))); diff --git a/Tests/LibGfx/test-inputs/tiff/ccitt4.tiff b/Tests/LibGfx/test-inputs/tiff/ccitt4.tiff new file mode 100644 index 0000000000000000000000000000000000000000..418b5cc244ce31b62a3d5f784c27b3056a149900 GIT binary patch literal 621 zcmebD)M6-OWMKFY1Ctu;tyz>eXt^EuusrENdorWS3^^WwiTBuwx3HbiE6ZX%xxn;P zfenvZP_s_w<`uaY*&gxknA)J%qSL&jLW%dZhxD5)7wIP&W*)h3RyKWbFei7Hv`6q<9h2JnZuxPWDSxz)CS6UVz{?GpRr&RA>&i}uI zP5A#m{yLQL|NmDIYyJQK|Nqwi|9|~INXdSX(Erz9k^1ld-~RvqyZ-Rq~Yi$i0rjs`;mhuX2_t@0qLKMW2m3<3-cjLZy-3=9kt z7#SECp==#S1_mZ58zjdJWwS6aFt9<{3=9kmf{ZK-%nS?+5ljpWLQrv#dQl{{7?j<> zz`!65Rqw;Zz#zrQ3bxmViGe{H%64I5V32{T2bm+w$i%?Oz`&5g#K52d6=z~#U ErrorOr { + auto const encoded_bytes = TRY(read_bytes_considering_fill_order(num_bytes)); + decoded_bytes = TRY(CCITT::decode_ccitt_group4(encoded_bytes, segment_size.width(), segment_size.height())); + return decoded_bytes; + }; + + TRY(loop_over_pixels(move(decode_group3_segment))); + break; + } case Compression::LZW: { ByteBuffer decoded_bytes {}; auto decode_lzw_segment = [&](u32 num_bytes, IntSize) -> ErrorOr {