1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

LibGfx/CCITT: Add support for Group4

The API is currently pretty raw. Group4 has a bunch of options that we
don't support yet.
This commit is contained in:
Lucas CHOLLET 2024-02-15 19:46:25 -05:00 committed by Jelle Raaijmakers
parent e9dd1cda3e
commit d57d676425
Notes: sideshowbarker 2024-07-17 06:40:21 +09:00
2 changed files with 26 additions and 0 deletions

View file

@ -563,4 +563,25 @@ ErrorOr<ByteBuffer> decode_ccitt_group3(ReadonlyBytes bytes, u32 image_width, u3
return decoded_bytes;
}
ErrorOr<ByteBuffer> decode_ccitt_group4(ReadonlyBytes bytes, u32 image_width, u32 image_height)
{
auto strip_stream = make<FixedMemoryStream>(bytes);
auto bit_stream = make<BigEndianInputBitStream>(MaybeOwned<Stream>(*strip_stream));
// Note: We put image_height extra-space to handle at most one alignment to byte boundary per line.
ByteBuffer decoded_bytes = TRY(ByteBuffer::create_zeroed(ceil_div(image_width * image_height, 8) + image_height));
auto output_stream = make<FixedMemoryStream>(decoded_bytes.bytes());
auto decoded_bits = make<BigEndianOutputBitStream>(MaybeOwned<Stream>(*output_stream));
// T.6 2.2.1 Principle of the coding scheme
// The reference line for the first coding line in a page is an imaginary white line.
ReferenceLine reference_line;
TRY(reference_line.try_empend(ccitt_black, image_width));
for (u32 i = 0; i < image_height; ++i)
reference_line = TRY(decode_single_ccitt_2d_line(*bit_stream, *decoded_bits, move(reference_line), image_width));
return decoded_bytes;
}
}

View file

@ -16,6 +16,9 @@ namespace Gfx::CCITT {
// The CCITT3 specification is accessible at this page:
// https://www.itu.int/rec/T-REC-T.4/en
// And CCITT4's specification is available here:
// https://www.itu.int/rec/T-REC-T.6/en
// The unidimensional scheme is originally described in:
// 4.1 One-dimensional coding scheme
// However, this function implements the TIFF variant (see TIFFLoader.h for a spec link),
@ -47,4 +50,6 @@ struct Group3Options {
ErrorOr<ByteBuffer> decode_ccitt_group3(ReadonlyBytes bytes, u32 image_width, u32 image_height, Group3Options const& options);
ErrorOr<ByteBuffer> decode_ccitt_group4(ReadonlyBytes bytes, u32 image_width, u32 image_height);
}