mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 17:44:56 +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:
parent
e9dd1cda3e
commit
d57d676425
Notes:
sideshowbarker
2024-07-17 06:40:21 +09:00
Author: https://github.com/LucasChollet
Commit: d57d676425
Pull-request: https://github.com/SerenityOS/serenity/pull/23281
Reviewed-by: https://github.com/nico ✅
2 changed files with 26 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue