LibGfx/TIFF: Make decoders take an IntSize

They will also need the width of the sub-image when we will add support
for tiles.
This commit is contained in:
Lucas CHOLLET 2024-02-09 21:42:02 -05:00 committed by Jelle Raaijmakers
parent 7b510c3876
commit 18871e23d7
Notes: sideshowbarker 2024-07-17 05:09:48 +09:00

View File

@ -262,7 +262,7 @@ private:
return CMYK { first_component, second_component, third_component, fourth_component };
}
template<CallableAs<ErrorOr<ReadonlyBytes>, u32, u32> StripDecoder>
template<CallableAs<ErrorOr<ReadonlyBytes>, u32, IntSize> StripDecoder>
ErrorOr<void> loop_over_pixels(StripDecoder&& strip_decoder)
{
auto const strips_offset = *m_metadata.strip_offsets();
@ -278,8 +278,10 @@ private:
for (u32 strip_index = 0; strip_index < strips_offset.size(); ++strip_index) {
TRY(m_stream->seek(strips_offset[strip_index]));
auto const strip_width = *m_metadata.image_width();
auto const rows_in_strip = strip_index < strips_offset.size() - 1 ? rows_per_strip : *m_metadata.image_length() - rows_per_strip * strip_index;
auto const decoded_bytes = TRY(strip_decoder(strip_byte_counts[strip_index], rows_in_strip));
auto const decoded_bytes = TRY(strip_decoder(strip_byte_counts[strip_index], {strip_width, rows_in_strip}));
auto decoded_strip = make<FixedMemoryStream>(decoded_bytes);
auto decoded_stream = make<BigEndianInputBitStream>(move(decoded_strip));
@ -359,7 +361,7 @@ private:
{
switch (*m_metadata.compression()) {
case Compression::NoCompression: {
auto identity = [&](u32 num_bytes, u32) {
auto identity = [&](u32 num_bytes, IntSize) {
return m_stream->read_in_place<u8 const>(num_bytes);
};
@ -370,9 +372,9 @@ private:
TRY(ensure_tags_are_correct_for_ccitt());
ByteBuffer decoded_bytes {};
auto decode_ccitt_rle_strip = [&](u32 num_bytes, u32 image_height) -> ErrorOr<ReadonlyBytes> {
auto decode_ccitt_rle_strip = [&](u32 num_bytes, IntSize image_size) -> ErrorOr<ReadonlyBytes> {
auto const encoded_bytes = TRY(read_bytes_considering_fill_order(num_bytes));
decoded_bytes = TRY(CCITT::decode_ccitt_rle(encoded_bytes, *m_metadata.image_width(), image_height));
decoded_bytes = TRY(CCITT::decode_ccitt_rle(encoded_bytes, image_size.width(), image_size.height()));
return decoded_bytes;
};
@ -384,9 +386,9 @@ private:
auto const parameters = parse_t4_options(*m_metadata.t4_options());
ByteBuffer decoded_bytes {};
auto decode_group3_strip = [&](u32 num_bytes, u32 strip_height) -> ErrorOr<ReadonlyBytes> {
auto decode_group3_strip = [&](u32 num_bytes, IntSize image_size) -> ErrorOr<ReadonlyBytes> {
auto const encoded_bytes = TRY(read_bytes_considering_fill_order(num_bytes));
decoded_bytes = TRY(CCITT::decode_ccitt_group3(encoded_bytes, *m_metadata.image_width(), strip_height, parameters));
decoded_bytes = TRY(CCITT::decode_ccitt_group3(encoded_bytes, image_size.width(), image_size.height(), parameters));
return decoded_bytes;
};
@ -395,7 +397,7 @@ private:
}
case Compression::LZW: {
ByteBuffer decoded_bytes {};
auto decode_lzw_strip = [&](u32 num_bytes, u32) -> ErrorOr<ReadonlyBytes> {
auto decode_lzw_strip = [&](u32 num_bytes, IntSize) -> ErrorOr<ReadonlyBytes> {
auto const encoded_bytes = TRY(m_stream->read_in_place<u8 const>(num_bytes));
if (encoded_bytes.is_empty())
@ -424,7 +426,7 @@ private:
// This is an extension from the Technical Notes from 2002:
// https://web.archive.org/web/20160305055905/http://partners.adobe.com/public/developer/en/tiff/TIFFphotoshop.pdf
ByteBuffer decoded_bytes {};
auto decode_zlib = [&](u32 num_bytes, u32) -> ErrorOr<ReadonlyBytes> {
auto decode_zlib = [&](u32 num_bytes, IntSize) -> ErrorOr<ReadonlyBytes> {
auto stream = make<ConstrainedStream>(MaybeOwned<Stream>(*m_stream), num_bytes);
auto decompressed_stream = TRY(Compress::ZlibDecompressor::create(move(stream)));
decoded_bytes = TRY(decompressed_stream->read_until_eof(4096));
@ -438,7 +440,7 @@ private:
// Section 9: PackBits Compression
ByteBuffer decoded_bytes {};
auto decode_packbits_strip = [&](u32 num_bytes, u32) -> ErrorOr<ReadonlyBytes> {
auto decode_packbits_strip = [&](u32 num_bytes, IntSize) -> ErrorOr<ReadonlyBytes> {
auto const encoded_bytes = TRY(m_stream->read_in_place<u8 const>(num_bytes));
decoded_bytes = TRY(Compress::PackBits::decode_all(encoded_bytes));
return decoded_bytes;