diff options
author | Robin Watts <robin.watts@artifex.com> | 2013-06-25 17:50:39 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-06-25 18:28:42 +0100 |
commit | a9e56e9f94515c109a912a50b4bc80466a11b075 (patch) | |
tree | 92d31f23c2c56e86867ff23aa6fbd95ca3251e43 /source/pdf | |
parent | 148e6b9dae3900f1acd053df10bc41f06be5c507 (diff) | |
download | mupdf-a9e56e9f94515c109a912a50b4bc80466a11b075.tar.xz |
Rework storing internal flags in PDF objects.
Before we render a page we need to evaluate whether we need
transparency or not. To establish this, we recursively walk the
resources looking for certain markers (blend modes, alpha levels,
smasks etc). To avoid doing this repeatedly we'd like to stash
the results somewhere.
Currently we write a '.useBM' entry into the top level dictionary
object, but with the recent changes to support incremental update
this is not ideal - it has the effect of forcing all resources
into the new section of the xref.
So we avoid that horrible hack and use a different one; we make use
of the new flags word in the pdf_obj structure. 1 bit is used to
indicate whether we have stashed a (boolean) value here, and another
bit is used to indicate what that value was.
Diffstat (limited to 'source/pdf')
-rw-r--r-- | source/pdf/pdf-object.c | 23 | ||||
-rw-r--r-- | source/pdf/pdf-page.c | 28 |
2 files changed, 25 insertions, 26 deletions
diff --git a/source/pdf/pdf-object.c b/source/pdf/pdf-object.c index a6b3f1ac..aa20b79e 100644 --- a/source/pdf/pdf-object.c +++ b/source/pdf/pdf-object.c @@ -22,7 +22,9 @@ struct keyval enum { PDF_FLAGS_MARKED = 1, - PDF_FLAGS_SORTED = 2 + PDF_FLAGS_SORTED = 2, + PDF_FLAGS_STASH = 4, + PDF_FLAGS_STASH_BOOL = 8 }; struct pdf_obj_s @@ -1188,6 +1190,25 @@ pdf_obj_unmark(pdf_obj *obj) obj->flags &= ~PDF_FLAGS_MARKED; } +void +pdf_obj_stash(pdf_obj *obj, int stash) +{ + obj->flags |= PDF_FLAGS_STASH; + if (stash) + obj->flags |= PDF_FLAGS_STASH_BOOL; + else + obj->flags &= ~PDF_FLAGS_STASH_BOOL; +} + +int +pdf_obj_stashed(pdf_obj *obj, int *stash) +{ + if (!(obj->flags & PDF_FLAGS_STASH)) + return 0; + *stash = !!(obj->flags & PDF_FLAGS_STASH_BOOL); + return 1; +} + static void pdf_free_array(pdf_obj *obj) { diff --git a/source/pdf/pdf-page.c b/source/pdf/pdf-page.c index 12e38b5f..82c7aa5c 100644 --- a/source/pdf/pdf-page.c +++ b/source/pdf/pdf-page.c @@ -8,27 +8,6 @@ struct info pdf_obj *rotate; }; -static void -put_marker_bool(pdf_document *doc, pdf_obj *rdb, char *marker, int val) -{ - pdf_obj *tmp; - fz_context *ctx = doc->ctx; - - tmp = pdf_new_bool(doc, val); - fz_try(ctx) - { - pdf_dict_puts(rdb, marker, tmp); - } - fz_always(ctx) - { - pdf_drop_obj(tmp); - } - fz_catch(ctx) - { - fz_rethrow(ctx); - } -} - typedef struct pdf_page_load_s pdf_page_load; struct pdf_page_load_s @@ -240,9 +219,8 @@ pdf_resources_use_blending(pdf_document *doc, pdf_obj *rdb) return 0; /* Have we been here before and stashed an answer? */ - obj = pdf_dict_gets(rdb, ".useBM"); - if (obj) - return pdf_to_bool(obj); + if (pdf_obj_stashed(rdb, &useBM)) + return useBM; /* stop on cyclic resource dependencies */ if (pdf_obj_mark(rdb)) @@ -282,7 +260,7 @@ found: fz_rethrow(ctx); } - put_marker_bool(doc, rdb, ".useBM", useBM); + pdf_obj_stash(rdb, useBM); return useBM; } |