From edffdc35a9bceeb60bcf26dbf4670c516ffba1bd Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Mon, 15 Jan 2024 00:46:10 -0500 Subject: [PATCH] LibGfx/TIFF+CCITT: Clarify naming of compression type 2 Type 2 <=> One-dimensional Group3, customized for TIFF Type 3 <=> Two-dimensional Group3, uses the original 1D internally Type 4 <=> Two-dimensional Group4 So let's clarify that this is not Group3 1D but the TIFF variant, which is called `CCITTRLE` in libtiff. So let's stick with this name to avoid confusion. --- Tests/LibGfx/TestImageDecoder.cpp | 4 ++-- .../tiff/{ccitt3_1d.tiff => ccitt_rle.tiff} | Bin .../Libraries/LibGfx/ImageFormats/CCITTDecoder.cpp | 2 +- .../Libraries/LibGfx/ImageFormats/CCITTDecoder.h | 2 +- .../Libraries/LibGfx/ImageFormats/TIFFLoader.cpp | 8 ++++---- Userland/Libraries/LibGfx/TIFFGenerator.py | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) rename Tests/LibGfx/test-inputs/tiff/{ccitt3_1d.tiff => ccitt_rle.tiff} (100%) diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp index dec10f5141..02b8480138 100644 --- a/Tests/LibGfx/TestImageDecoder.cpp +++ b/Tests/LibGfx/TestImageDecoder.cpp @@ -543,9 +543,9 @@ TEST_CASE(test_tiff_uncompressed) EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red); } -TEST_CASE(test_tiff_ccitt3_1d) +TEST_CASE(test_tiff_ccitt_rle) { - auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/ccitt3_1d.tiff"sv))); + auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/ccitt_rle.tiff"sv))); EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes())); auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes())); diff --git a/Tests/LibGfx/test-inputs/tiff/ccitt3_1d.tiff b/Tests/LibGfx/test-inputs/tiff/ccitt_rle.tiff similarity index 100% rename from Tests/LibGfx/test-inputs/tiff/ccitt3_1d.tiff rename to Tests/LibGfx/test-inputs/tiff/ccitt_rle.tiff diff --git a/Userland/Libraries/LibGfx/ImageFormats/CCITTDecoder.cpp b/Userland/Libraries/LibGfx/ImageFormats/CCITTDecoder.cpp index 5a7715b01b..3a529be8bf 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/CCITTDecoder.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/CCITTDecoder.cpp @@ -266,7 +266,7 @@ Optional get_terminal_code(Color color, u16 code_word, u8 code_size) } -ErrorOr decode_ccitt3_1d(ReadonlyBytes bytes, u32 image_width, u32 image_height) +ErrorOr decode_ccitt_rle(ReadonlyBytes bytes, u32 image_width, u32 image_height) { auto strip_stream = make(bytes); auto bit_stream = make(MaybeOwned(*strip_stream)); diff --git a/Userland/Libraries/LibGfx/ImageFormats/CCITTDecoder.h b/Userland/Libraries/LibGfx/ImageFormats/CCITTDecoder.h index b4cd56b93f..05e42ff2da 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/CCITTDecoder.h +++ b/Userland/Libraries/LibGfx/ImageFormats/CCITTDecoder.h @@ -21,6 +21,6 @@ namespace Gfx::CCITT { // However, this function implements the TIFF variant (see TIFFLoader.h for a spec link), // differences are detailed in section: // Section 10: Modified Huffman Compression -ErrorOr decode_ccitt3_1d(ReadonlyBytes bytes, u32 image_width, u32 image_height); +ErrorOr decode_ccitt_rle(ReadonlyBytes bytes, u32 image_width, u32 image_height); } diff --git a/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp index 38b61d1f6c..8bd5b77d22 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp @@ -281,17 +281,17 @@ private: TRY(loop_over_pixels(move(identity))); break; } - case Compression::CCITT: { + case Compression::CCITTRLE: { TRY(ensure_tags_are_correct_for_ccitt()); ByteBuffer decoded_bytes {}; - auto decode_ccitt_1D_strip = [&](u32 num_bytes) -> ErrorOr { + auto decode_ccitt_rle_strip = [&](u32 num_bytes) -> ErrorOr { auto const encoded_bytes = TRY(m_stream->read_in_place(num_bytes)); - decoded_bytes = TRY(CCITT::decode_ccitt3_1d(encoded_bytes, *m_metadata.image_width(), *m_metadata.rows_per_strip())); + decoded_bytes = TRY(CCITT::decode_ccitt_rle(encoded_bytes, *m_metadata.image_width(), *m_metadata.rows_per_strip())); return decoded_bytes; }; - TRY(loop_over_pixels(move(decode_ccitt_1D_strip))); + TRY(loop_over_pixels(move(decode_ccitt_rle_strip))); break; } case Compression::LZW: { diff --git a/Userland/Libraries/LibGfx/TIFFGenerator.py b/Userland/Libraries/LibGfx/TIFFGenerator.py index fdfdff7b3f..ff38bb6092 100755 --- a/Userland/Libraries/LibGfx/TIFFGenerator.py +++ b/Userland/Libraries/LibGfx/TIFFGenerator.py @@ -51,7 +51,7 @@ class Predictor(EnumWithExportName): class Compression(EnumWithExportName): NoCompression = 1 - CCITT = 2 + CCITTRLE = 2 Group3Fax = 3 Group4Fax = 4 LZW = 5