Skip to content

Commit 15fc703

Browse files
committed
LibGfx/CCITT: Move EOL detection code to its own function
1 parent 3b86c41 commit 15fc703

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

Userland/Libraries/LibGfx/ImageFormats/CCITTDecoder.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,19 @@ struct CCITTStatus {
420420
bool has_reached_eol { false };
421421
};
422422

423+
ErrorOr<void> ensure_invalid_result_is_actually_eol(BigEndianInputBitStream& input_bit_stream, InvalidResult partially_read_eol)
424+
{
425+
if (partially_read_eol != 0)
426+
return Error::from_string_literal("CCITTDecoder: Unable to find the correct mode");
427+
428+
auto const remaining_eol = TRY(input_bit_stream.read_bits(5));
429+
if (remaining_eol != 1) {
430+
return Error::from_string_literal("CCITTDecoder: Unable to find the correct mode");
431+
}
432+
433+
return {};
434+
}
435+
423436
ErrorOr<CCITTStatus> decode_single_ccitt_2d_line(BigEndianInputBitStream& input_bit_stream, BigEndianOutputBitStream& decoded_bits, ReferenceLine&& reference_line, u32 image_width)
424437
{
425438
CCITTStatus status {};
@@ -470,14 +483,7 @@ ErrorOr<CCITTStatus> decode_single_ccitt_2d_line(BigEndianInputBitStream& input_
470483
auto const maybe_mode = TRY(read_mode(input_bit_stream));
471484

472485
if (maybe_mode.has<InvalidResult>()) {
473-
auto const partially_read_eol = maybe_mode.get<InvalidResult>();
474-
475-
if (partially_read_eol != 0)
476-
return Error::from_string_literal("CCITTDecoder: Unable to find the correct mode");
477-
478-
auto const remaining_eol = TRY(input_bit_stream.read_bits(5));
479-
if (remaining_eol != 1)
480-
return Error::from_string_literal("CCITTDecoder: Unable to find the correct mode");
486+
TRY(ensure_invalid_result_is_actually_eol(input_bit_stream, maybe_mode.get<InvalidResult>()));
481487

482488
// We reached EOL
483489
status.has_reached_eol = true;

0 commit comments

Comments
 (0)