From f5e7ee8d4a0433103d6269e57197bf24127bd4b7 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Sun, 11 Feb 2024 23:14:44 -0500 Subject: [PATCH] LibGfx/CCITT: Don't be fooled by black-starting lines The first marker is always white in CCITT streams, so lines starting with a black pixel encodes a symbol meaning 0 white pixels. Then, the decoding would proceed with a black symbol. We used to set the symbol's color based on `column == 0`, which is wrong in this situation. --- Userland/Libraries/LibGfx/ImageFormats/CCITTDecoder.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/CCITTDecoder.cpp b/Userland/Libraries/LibGfx/ImageFormats/CCITTDecoder.cpp index cadc90d582..529a9d2990 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/CCITTDecoder.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/CCITTDecoder.cpp @@ -269,7 +269,9 @@ ErrorOr decode_single_ccitt3_1d_line(BigEndianInputBitStream& input_bit_st auto const ccitt_white = Color::NamedColor::White; auto const ccitt_black = Color::NamedColor::Black; - Color current_color { ccitt_white }; + // We always flip the color when entering the loop, so let's initialize the + // color with black to make the first marker actually be white. + Color current_color { ccitt_black }; u32 run_length = 0; u32 column = 0; @@ -284,10 +286,6 @@ ErrorOr decode_single_ccitt3_1d_line(BigEndianInputBitStream& input_bit_st current_color = current_color == ccitt_white ? ccitt_black : ccitt_white; - if (column == 0) { - current_color = ccitt_white; - } - u8 size {}; u16 potential_code {}; while (size < 14) {