summaryrefslogtreecommitdiff
path: root/source/pdf/pdf-image.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2014-03-14 20:01:32 +0000
committerRobin Watts <robin.watts@artifex.com>2014-03-18 17:48:40 +0000
commit4c2715a0bcecfed6ebdfee901920631b09364d7e (patch)
treeb0e5aa723719159a779425329ddc6ce48b8af0ce /source/pdf/pdf-image.c
parent551de42088c58dc69fba06fb53e36c2ddb12367f (diff)
downloadmupdf-4c2715a0bcecfed6ebdfee901920631b09364d7e.tar.xz
Fix operator buffering of inline images.
Previously pdf_process buffer did not understand inline images. In order to make this work without needlessly duplicating complex code from within pdf-op-run, the parsing of inline images has been moved to happen in pdf-interpret.c. When the op_table entry for BI is called it now expects the inline image to be in csi->img and the dictionary object to be in csi->obj. To make this work, we have had to improve the handling of inline images in general. While non-inline images have been loaded and held in memory in their compressed form and only decoded when required, until now we have always loaded and decoded inline images immediately. This has been due to the difficulty in knowing how many bytes of data to read from the stream - we know the length of the stream once uncompressed, but relating this to the compressed length is hard. To cure this we introduce a new type of filter stream, a 'leecher'. We insert a leecher stream before we build the filters required to decode the image. We then read and discard the appropriate number of uncompressed bytes from the filters. This pulls the compressed data through the leecher stream, which stores it in an fz_buffer. Thus images are now always held in their compressed forms in memory. The pdf-op-run implementation is now trivial. The only real complexity in the pdf-op-buffer implementation is the need to ensure that the /Filter entry in the dictionary object matches the exact point at which we backstopped the decompression.
Diffstat (limited to 'source/pdf/pdf-image.c')
-rw-r--r--source/pdf/pdf-image.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/source/pdf/pdf-image.c b/source/pdf/pdf-image.c
index c329c1a7..bb663ba2 100644
--- a/source/pdf/pdf-image.c
+++ b/source/pdf/pdf-image.c
@@ -22,6 +22,7 @@ pdf_load_image_imp(pdf_document *doc, pdf_obj *rdb, pdf_obj *dict, fz_stream *cs
int i;
fz_context *ctx = doc->ctx;
+ fz_compressed_buffer *buffer;
fz_var(stm);
fz_var(mask);
@@ -133,26 +134,24 @@ pdf_load_image_imp(pdf_document *doc, pdf_obj *rdb, pdf_obj *dict, fz_stream *cs
}
}
- /* Now, do we load a ref, or do we load the actual thing? */
+ /* Do we load from a ref, or do we load an inline stream? */
if (cstm == NULL)
{
/* Just load the compressed image data now and we can
* decode it on demand. */
int num = pdf_to_num(dict);
int gen = pdf_to_gen(dict);
- fz_compressed_buffer *buffer = pdf_load_compressed_stream(doc, num, gen);
+ buffer = pdf_load_compressed_stream(doc, num, gen);
image = fz_new_image(ctx, w, h, bpc, colorspace, 96, 96, interpolate, imagemask, decode, usecolorkey ? colorkey : NULL, buffer, mask);
- break; /* Out of fz_try */
+ }
+ else
+ {
+ /* Inline stream */
+ stride = (w * n * bpc + 7) / 8;
+ image = fz_new_image(ctx, w, h, bpc, colorspace, 96, 96, interpolate, imagemask, decode, usecolorkey ? colorkey : NULL, NULL, mask);
+ pdf_load_compressed_inline_image(doc, dict, stride * h, cstm, indexed, image);
}
- /* We need to decompress the image now */
- stride = (w * n * bpc + 7) / 8;
- stm = pdf_open_inline_stream(doc, dict, stride * h, cstm, NULL);
-
- image = fz_new_image(ctx, w, h, bpc, colorspace, 96, 96, interpolate, imagemask, decode, usecolorkey ? colorkey : NULL, NULL, mask);
- colorspace = NULL;
- mask = NULL;
- image->tile = fz_decomp_image_from_stream(ctx, stm, image, indexed, 0, 0);
}
fz_catch(ctx)
{