mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:37:35 +00:00
LibPDF+LibGfx: Pass jbig2-filtered data to JBIG2ImageDecoderPlugin
Except for /JBIG2Globals, which we bail out on for now. In my 1000 files, 13 use JBIG2, and of those, 2 use JBIG2Globals (0000372.pdf e.g. page 11 and 0000857.pdf e.g. page 1), and only one (the latter) of the two uses the same JBIG2Globals stream for more than a single image. JBIG2ImageDecoderPlugin cannot decode the data yet, so no behavior change, but with `#define JBIG2_DEBUG 1` at the top of that file, it now prints segment header info for PDFs containing JBIG2 data :^)
This commit is contained in:
parent
bd60d1db7e
commit
953f6c5d9b
5 changed files with 26 additions and 5 deletions
|
@ -180,7 +180,10 @@ static ErrorOr<SegmentHeader> decode_segment_header(SeekableStream& stream)
|
|||
|
||||
static ErrorOr<void> decode_segment_headers(JBIG2LoadingContext& context)
|
||||
{
|
||||
FixedMemoryStream stream(context.data.slice(sizeof(id_string) + sizeof(u8) + (context.number_of_pages.has_value() ? sizeof(u32) : 0)));
|
||||
ReadonlyBytes data = context.data;
|
||||
if (context.organization != Organization::Embedded)
|
||||
data = data.slice(sizeof(id_string) + sizeof(u8) + (context.number_of_pages.has_value() ? sizeof(u32) : 0));
|
||||
FixedMemoryStream stream(data);
|
||||
while (!stream.is_eof()) {
|
||||
auto segment_header = TRY(decode_segment_header(stream));
|
||||
if (context.organization != Organization::RandomAccess) {
|
||||
|
@ -232,4 +235,12 @@ ErrorOr<ImageFrameDescriptor> JBIG2ImageDecoderPlugin::frame(size_t index, Optio
|
|||
return Error::from_string_literal("JBIG2ImageDecoderPlugin: Draw the rest of the owl");
|
||||
}
|
||||
|
||||
ErrorOr<ByteBuffer> JBIG2ImageDecoderPlugin::decode_embedded(ReadonlyBytes data)
|
||||
{
|
||||
auto plugin = TRY(adopt_nonnull_own_or_enomem(new (nothrow) JBIG2ImageDecoderPlugin(data)));
|
||||
plugin->m_context->organization = Organization::Embedded;
|
||||
TRY(decode_segment_headers(*plugin->m_context));
|
||||
return Error::from_string_literal("JBIG2ImageDecoderPlugin: Cannot decode embedded JBIG2 yet");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue