From d54dbdae5e2dd34f8db3697010a878eced5c9758 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Thu, 15 Feb 2024 15:56:27 -0500 Subject: [PATCH] LibGfx/CCITT: Introduce the `invert` helper This function turns Black into White and White into Black. --- Userland/Libraries/LibGfx/ImageFormats/CCITTDecoder.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/CCITTDecoder.cpp b/Userland/Libraries/LibGfx/ImageFormats/CCITTDecoder.cpp index 2850b77cb8..6f13eee587 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/CCITTDecoder.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/CCITTDecoder.cpp @@ -267,6 +267,11 @@ Optional get_terminal_code(Color color, u16 code_word, u8 code_size) constexpr auto const ccitt_white = Color::NamedColor::White; constexpr auto const ccitt_black = Color::NamedColor::Black; +Color invert(Color current_color) +{ + return current_color == ccitt_white ? ccitt_black : ccitt_white; +} + ErrorOr decode_single_ccitt3_1d_line(BigEndianInputBitStream& input_bit_stream, BigEndianOutputBitStream& decoded_bits, u32 image_width) { // We always flip the color when entering the loop, so let's initialize the @@ -284,7 +289,7 @@ ErrorOr decode_single_ccitt3_1d_line(BigEndianInputBitStream& input_bit_st continue; } - current_color = current_color == ccitt_white ? ccitt_black : ccitt_white; + current_color = invert(current_color); u8 size {}; u16 potential_code {};