mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:37:45 +00:00
LibGfx/TIFF: Read and honor the FillOrder tag
This commit is contained in:
parent
6a0fe08604
commit
720187623b
2 changed files with 27 additions and 2 deletions
|
@ -336,6 +336,25 @@ private:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorOr<ByteBuffer> read_bytes_considering_fill_order(u32 bytes_to_read) const
|
||||||
|
{
|
||||||
|
auto const reverse_byte = [](u8 b) {
|
||||||
|
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
|
||||||
|
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
|
||||||
|
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
|
||||||
|
return b;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto const bytes = TRY(m_stream->read_in_place<u8 const>(bytes_to_read));
|
||||||
|
auto copy = TRY(ByteBuffer::copy(bytes));
|
||||||
|
if (m_metadata.fill_order() == FillOrder::RightToLeft) {
|
||||||
|
for (auto& byte : copy.bytes())
|
||||||
|
byte = reverse_byte(byte);
|
||||||
|
}
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOr<void> decode_frame_impl()
|
ErrorOr<void> decode_frame_impl()
|
||||||
{
|
{
|
||||||
switch (*m_metadata.compression()) {
|
switch (*m_metadata.compression()) {
|
||||||
|
@ -352,7 +371,7 @@ private:
|
||||||
|
|
||||||
ByteBuffer decoded_bytes {};
|
ByteBuffer decoded_bytes {};
|
||||||
auto decode_ccitt_rle_strip = [&](u32 num_bytes, u32 image_height) -> ErrorOr<ReadonlyBytes> {
|
auto decode_ccitt_rle_strip = [&](u32 num_bytes, u32 image_height) -> ErrorOr<ReadonlyBytes> {
|
||||||
auto const encoded_bytes = TRY(m_stream->read_in_place<u8 const>(num_bytes));
|
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, *m_metadata.image_width(), image_height));
|
||||||
return decoded_bytes;
|
return decoded_bytes;
|
||||||
};
|
};
|
||||||
|
@ -366,7 +385,7 @@ private:
|
||||||
auto const parameters = parse_t4_options(*m_metadata.t4_options());
|
auto const parameters = parse_t4_options(*m_metadata.t4_options());
|
||||||
ByteBuffer decoded_bytes {};
|
ByteBuffer decoded_bytes {};
|
||||||
auto decode_group3_strip = [&](u32 num_bytes, u32 strip_height) -> ErrorOr<ReadonlyBytes> {
|
auto decode_group3_strip = [&](u32 num_bytes, u32 strip_height) -> ErrorOr<ReadonlyBytes> {
|
||||||
auto const encoded_bytes = TRY(m_stream->read_in_place<u8 const>(num_bytes));
|
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, *m_metadata.image_width(), strip_height, parameters));
|
||||||
return decoded_bytes;
|
return decoded_bytes;
|
||||||
};
|
};
|
||||||
|
|
|
@ -73,6 +73,11 @@ class PhotometricInterpretation(EnumWithExportName):
|
||||||
CIELab = 8
|
CIELab = 8
|
||||||
|
|
||||||
|
|
||||||
|
class FillOrder(EnumWithExportName):
|
||||||
|
LeftToRight = 1
|
||||||
|
RightToLeft = 2
|
||||||
|
|
||||||
|
|
||||||
class Orientation(EnumWithExportName):
|
class Orientation(EnumWithExportName):
|
||||||
Default = 1
|
Default = 1
|
||||||
FlipHorizontally = 2
|
FlipHorizontally = 2
|
||||||
|
@ -124,6 +129,7 @@ known_tags: List[Tag] = [
|
||||||
Tag('259', [TIFFType.UnsignedShort], [1], None, "Compression", Compression, is_required=True),
|
Tag('259', [TIFFType.UnsignedShort], [1], None, "Compression", Compression, is_required=True),
|
||||||
Tag('262', [TIFFType.UnsignedShort], [1], None, "PhotometricInterpretation",
|
Tag('262', [TIFFType.UnsignedShort], [1], None, "PhotometricInterpretation",
|
||||||
PhotometricInterpretation, is_required=True),
|
PhotometricInterpretation, is_required=True),
|
||||||
|
Tag('266', [TIFFType.UnsignedShort], [1], FillOrder.LeftToRight, "FillOrder", FillOrder),
|
||||||
Tag('271', [TIFFType.ASCII], [], None, "Make"),
|
Tag('271', [TIFFType.ASCII], [], None, "Make"),
|
||||||
Tag('272', [TIFFType.ASCII], [], None, "Model"),
|
Tag('272', [TIFFType.ASCII], [], None, "Model"),
|
||||||
Tag('273', [TIFFType.UnsignedShort, TIFFType.UnsignedLong], [], None, "StripOffsets", is_required=True),
|
Tag('273', [TIFFType.UnsignedShort, TIFFType.UnsignedLong], [], None, "StripOffsets", is_required=True),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue