mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 12:57:34 +00:00
LibGfx/GIF: Use LZWDecoder::decode_all()
This commit is contained in:
parent
cc816b486c
commit
ce6cd4f45f
1 changed files with 25 additions and 46 deletions
|
@ -184,38 +184,18 @@ static ErrorOr<void> decode_frame(GIFLoadingContext& context, size_t frame_index
|
||||||
if (image->lzw_min_code_size > 8)
|
if (image->lzw_min_code_size > 8)
|
||||||
return Error::from_string_literal("LZW minimum code size is greater than 8");
|
return Error::from_string_literal("LZW minimum code size is greater than 8");
|
||||||
|
|
||||||
FixedMemoryStream stream { image->lzw_encoded_bytes, FixedMemoryStream::Mode::ReadOnly };
|
auto decoded_stream = TRY(Compress::LZWDecoder<LittleEndianInputBitStream>::decode_all(image->lzw_encoded_bytes, image->lzw_min_code_size));
|
||||||
auto bit_stream = make<LittleEndianInputBitStream>(MaybeOwned<Stream>(stream));
|
|
||||||
|
|
||||||
Compress::LZWDecoder decoder(MaybeOwned<LittleEndianInputBitStream> { move(bit_stream) }, image->lzw_min_code_size);
|
|
||||||
|
|
||||||
// Add GIF-specific control codes
|
|
||||||
int const clear_code = decoder.add_control_code();
|
|
||||||
int const end_of_information_code = decoder.add_control_code();
|
|
||||||
|
|
||||||
auto const& color_map = image->use_global_color_map ? context.logical_screen.color_map : image->color_map;
|
auto const& color_map = image->use_global_color_map ? context.logical_screen.color_map : image->color_map;
|
||||||
|
|
||||||
int pixel_index = 0;
|
int pixel_index = 0;
|
||||||
int row = 0;
|
int row = 0;
|
||||||
int interlace_pass = 0;
|
int interlace_pass = 0;
|
||||||
while (true) {
|
|
||||||
ErrorOr<u16> code = decoder.next_code();
|
|
||||||
if (code.is_error()) {
|
|
||||||
dbgln_if(GIF_DEBUG, "Unexpectedly reached end of gif frame data");
|
|
||||||
return code.release_error();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (code.value() == clear_code) {
|
|
||||||
decoder.reset();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (code.value() == end_of_information_code)
|
|
||||||
break;
|
|
||||||
if (!image->width)
|
if (!image->width)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto colors = decoder.get_output();
|
for (auto const& color : decoded_stream.bytes()) {
|
||||||
for (auto const& color : colors) {
|
|
||||||
auto c = color_map[color];
|
auto c = color_map[color];
|
||||||
|
|
||||||
int x = pixel_index % image->width + image->x;
|
int x = pixel_index % image->width + image->x;
|
||||||
|
@ -242,7 +222,6 @@ static ErrorOr<void> decode_frame(GIFLoadingContext& context, size_t frame_index
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
context.current_frame = i;
|
context.current_frame = i;
|
||||||
context.state = GIFLoadingContext::State::FrameComplete;
|
context.state = GIFLoadingContext::State::FrameComplete;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue