LibGfx/JBIG2: Scan for page size of page "1"

Sounds like the spec guarantees that that's the number of the first
page.

(In practice, all but one of all jbig2 files I've found contain just
page 1. PDFs almost always contain just page 1, and very rarely a
page 0 for globally shared parameters.)
This commit is contained in:
Nico Weber 2024-03-07 20:13:58 -05:00 committed by Tim Flynn
parent 842caf5e8c
commit af20ebe4a0
Notes: sideshowbarker 2024-07-16 23:05:02 +09:00

View file

@ -58,7 +58,11 @@ struct SegmentHeader {
u32 segment_number;
SegmentType type;
Vector<u32> referred_to_segment_numbers;
// 7.2.6 Segment page association
// "The first page must be numbered "1". This field may contain a value of zero; this value indicates that this segment is not associated with any page."
u32 page_association;
Optional<u32> data_length;
};
@ -289,13 +293,13 @@ static ErrorOr<void> scan_for_page_size(JBIG2LoadingContext& context)
{
// We only decode the first page at the moment.
for (auto const& segment : context.segments) {
if (segment.header.type != SegmentType::PageInformation)
if (segment.header.type != SegmentType::PageInformation || segment.header.page_association != 1)
continue;
auto page_information = TRY(decode_page_information_segment(segment.data));
context.size = { page_information.bitmap_width, page_information.bitmap_height };
return {};
}
return Error::from_string_literal("JBIG2ImageDecoderPlugin: No page information segment found");
return Error::from_string_literal("JBIG2ImageDecoderPlugin: No page information segment found for page 1");
}
JBIG2ImageDecoderPlugin::JBIG2ImageDecoderPlugin()