summaryrefslogtreecommitdiff
path: root/pdf/pdf_write.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-07-04 16:49:01 +0100
committerRobin Watts <robin.watts@artifex.com>2012-07-05 11:01:50 +0100
commit808e051272c2a0b1e32e252fd14cdaf65c452132 (patch)
treec442fb203eda5c724fda652819098ee37c03e22a /pdf/pdf_write.c
parent05908e59a3db355cd8cbaab99406bb401d3afa2d (diff)
downloadmupdf-808e051272c2a0b1e32e252fd14cdaf65c452132.tar.xz
Improve detection of images for pdfwrite.
In pdfwrite we have a flag to say "don't expand images", but this isn't always honoured because we don't know that a stream is an image (for instance the corrupt fax stream used as a thumbnail in normal_439.pdf). Here we update the code to spot that streams are likely to be images based on the filters in use, or on the presence of both Width and Height tags.
Diffstat (limited to 'pdf/pdf_write.c')
-rw-r--r--pdf/pdf_write.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/pdf/pdf_write.c b/pdf/pdf_write.c
index 8334e92a..566b9c0e 100644
--- a/pdf/pdf_write.c
+++ b/pdf/pdf_write.c
@@ -1514,6 +1514,34 @@ static void expandstream(pdf_document *xref, pdf_write_options *opts, pdf_obj *o
pdf_drop_obj(obj);
}
+static int is_image_filter(char *s)
+{
+ if ( !strcmp(s, "CCITTFaxDecode") || !strcmp(s, "CCF") ||
+ !strcmp(s, "DCTDecode") || !strcmp(s, "DCT") ||
+ !strcmp(s, "RunLengthDecode") || !strcmp(s, "RL") ||
+ !strcmp(s, "JBIG2Decode") ||
+ !strcmp(s, "JPXDecode"))
+ return 1;
+ return 0;
+}
+
+static int filter_implies_image(pdf_document *xref, pdf_obj *o)
+{
+ if (!o)
+ return 0;
+ if (pdf_is_name(o))
+ return is_image_filter(pdf_to_name(o));
+ if (pdf_is_array(o))
+ {
+ int i, len;
+ len = pdf_array_len(o);
+ for (i = 0; i < len; i++)
+ if (is_image_filter(pdf_to_name(pdf_array_get(o, i))))
+ return 1;
+ }
+ return 0;
+}
+
static void writeobject(pdf_document *xref, pdf_write_options *opts, int num, int gen)
{
pdf_obj *obj;
@@ -1576,6 +1604,10 @@ static void writeobject(pdf_document *xref, pdf_write_options *opts, int num, in
dontexpand = !(opts->do_expand & fz_expand_fonts);
if (o = pdf_dict_gets(obj, "Subtype"), !strcmp(pdf_to_name(o), "CIDFontType0C"))
dontexpand = !(opts->do_expand & fz_expand_fonts);
+ if (o = pdf_dict_gets(obj, "Filter"), filter_implies_image(xref, o))
+ dontexpand = !(opts->do_expand & fz_expand_images);
+ if (pdf_dict_gets(obj, "Width") != NULL && pdf_dict_gets(obj, "Height") != NULL)
+ dontexpand = !(opts->do_expand & fz_expand_images);
}
if (opts->do_expand && !dontexpand && !pdf_is_jpx_image(ctx, obj))
expandstream(xref, opts, obj, num, gen);