diff options
author | Robin Watts <robin.watts@artifex.com> | 2017-06-20 19:43:09 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2017-07-19 19:41:23 +0100 |
commit | 3d6cf4e4e543ce0d204db71ef8d0b9277219f250 (patch) | |
tree | f501d7bf12c00066bde1a4dc1bfc2e6bd6e0137b /source | |
parent | 041df2bd7029d436767ec5bfb4227dc1cdb30afc (diff) | |
download | mupdf-3d6cf4e4e543ce0d204db71ef8d0b9277219f250.tar.xz |
Rejig page separations interface.
Specifically this is aimed so we can efficiently get separation
details for PDF files (which may require a lengthy search process).
Diffstat (limited to 'source')
-rw-r--r-- | source/fitz/document.c | 29 | ||||
-rw-r--r-- | source/fitz/separation.c | 14 | ||||
-rw-r--r-- | source/gprf/gprf-doc.c | 27 | ||||
-rw-r--r-- | source/pdf/pdf-page.c | 49 |
4 files changed, 81 insertions, 38 deletions
diff --git a/source/fitz/document.c b/source/fitz/document.c index ceccd26d..c03012f2 100644 --- a/source/fitz/document.c +++ b/source/fitz/document.c @@ -483,31 +483,10 @@ fz_page_presentation(fz_context *ctx, fz_page *page, fz_transition *transition, return NULL; } -int fz_count_separations_on_page(fz_context *ctx, fz_page *page) +fz_separations * +fz_page_separations(fz_context *ctx, fz_page *page) { - if (page && page->count_separations) - return page->count_separations(ctx, page); - return 0; -} - -void fz_control_separation_on_page(fz_context *ctx, fz_page *page, int sep, int disable) -{ - if (page && page->control_separation) - page->control_separation(ctx, page, sep, disable); -} - -int fz_separation_disabled_on_page (fz_context *ctx, fz_page *page, int sep) -{ - if (page && page->separation_disabled) - return page->separation_disabled(ctx, page, sep); - return 0; -} - -const char *fz_get_separation_on_page(fz_context *ctx, fz_page *page, int sep, uint32_t *rgba, uint32_t *cmyk) -{ - if (page && page->get_separation) - return page->get_separation(ctx, page, sep, rgba, cmyk); - *rgba = 0; - *cmyk = 0; + if (page && page->separations) + return page->separations(ctx, page); return NULL; } diff --git a/source/fitz/separation.c b/source/fitz/separation.c index 3c6efc03..039223a9 100644 --- a/source/fitz/separation.c +++ b/source/fitz/separation.c @@ -4,18 +4,20 @@ struct fz_separations_s { int refs; int num_separations; + int controllable; uint32_t disabled[(FZ_MAX_SEPARATIONS + 31) / 32]; uint32_t equiv_rgb[FZ_MAX_SEPARATIONS]; uint32_t equiv_cmyk[FZ_MAX_SEPARATIONS]; char *name[FZ_MAX_SEPARATIONS]; }; -fz_separations *fz_new_separations(fz_context *ctx) +fz_separations *fz_new_separations(fz_context *ctx, int controllable) { fz_separations *sep; sep = fz_malloc_struct(ctx, fz_separations); sep->refs = 1; + sep->controllable = controllable; return sep; } @@ -36,7 +38,7 @@ void fz_drop_separations(fz_context *ctx, fz_separations *sep) } } -void fz_add_separation(fz_context *ctx, fz_separations *sep, uint32_t rgb, uint32_t cmyk, char *name) +void fz_add_separation(fz_context *ctx, fz_separations *sep, uint32_t rgb, uint32_t cmyk, const char *name) { int n; @@ -54,6 +56,11 @@ void fz_add_separation(fz_context *ctx, fz_separations *sep, uint32_t rgb, uint3 sep->num_separations++; } +int fz_separations_controllable(fz_context *ctx, fz_separations *sep) +{ + return (!sep || sep->controllable); +} + void fz_control_separation(fz_context *ctx, fz_separations *sep, int separation, int disable) { int bit; @@ -61,6 +68,9 @@ void fz_control_separation(fz_context *ctx, fz_separations *sep, int separation, if (!sep || separation < 0 || separation >= sep->num_separations) fz_throw(ctx, FZ_ERROR_GENERIC, "can't control non-existent separation"); + if (!sep->controllable) + fz_throw(ctx, FZ_ERROR_GENERIC, "can't control separations on this page"); + bit = 1<<(separation & 31); separation >>= 5; diff --git a/source/gprf/gprf-doc.c b/source/gprf/gprf-doc.c index 34a293bd..a7c46524 100644 --- a/source/gprf/gprf-doc.c +++ b/source/gprf/gprf-doc.c @@ -175,7 +175,7 @@ fz_drop_image_gprf_imp(fz_context *ctx, fz_storable *image_) fz_drop_gprf_file(ctx, image->file); fz_drop_separations(ctx, image->separations); - fz_drop_image_base(ctx, image->super); + fz_drop_image_base(ctx, &image->super); } static inline unsigned char *cmyk_to_rgba(unsigned char *out, uint32_t c, uint32_t m, uint32_t y, uint32_t k) @@ -511,8 +511,7 @@ fz_system(fz_context *ctx, const char *cmd) if (ret != 0) fz_throw(ctx, FZ_ERROR_GENERIC, "child process reported error %d", ret); } -#endif - +#else static int GSDLLCALL gsdll_stdout(void *instance, const char *str, int len) { @@ -556,6 +555,7 @@ gsdll_stderr(void *instance, const char *str, int len) #endif return len; } +#endif static void generate_page(fz_context *ctx, gprf_page *page) @@ -737,7 +737,7 @@ read_tiles(fz_context *ctx, gprf_page *page) /* Skip to the separations */ fz_seek(ctx, file, 64, SEEK_SET); - page->separations = fz_new_separations(ctx); + page->separations = fz_new_separations(ctx, 1); for (i = 0; i < num_seps; i++) { char blatter[4096]; @@ -861,24 +861,29 @@ static const char *gprf_get_separation(fz_context *ctx, fz_page *page_, int sep, return fz_get_separation(ctx, page->separations, sep, rgba, cmyk); } +static fz_separations * +gprf_separations(fz_context *ctx, fz_page *page_) +{ + gprf_page *page = (gprf_page *)page_; + + return fz_keep_separations(ctx, page->separations); +} + static fz_page * gprf_load_page(fz_context *ctx, fz_document *doc_, int number) { gprf_document *doc = (gprf_document*)doc_; - gprf_page *page = fz_new_page(ctx, gprf_page); + gprf_page *page = fz_new_derived_page(ctx, gprf_page); fz_try(ctx) { page->super.bound_page = gprf_bound_page; page->super.run_page_contents = gprf_run_page; page->super.drop_page = gprf_drop_page_imp; - page->super.count_separations = gprf_count_separations; - page->super.control_separation = gprf_control_separation; - page->super.separation_disabled = gprf_separation_disabled; - page->super.get_separation = gprf_get_separation; + page->super.separations = gprf_separations; page->doc = (gprf_document *)fz_keep_document(ctx, &doc->super); page->number = number; - page->separations = fz_new_separations(ctx); + page->separations = fz_new_separations(ctx, 1); page->width = doc->page_dims[number].w; page->height = doc->page_dims[number].h; page->tile_width = (page->width + GPRF_TILESIZE-1)/GPRF_TILESIZE; @@ -919,7 +924,7 @@ gprf_open_document_with_stream(fz_context *ctx, fz_stream *file) { gprf_document *doc; - doc = fz_new_document(ctx, gprf_document); + doc = fz_new_derived_document(ctx, gprf_document); doc->super.drop_document = gprf_close_document; doc->super.count_pages = gprf_count_pages; doc->super.load_page = gprf_load_page; diff --git a/source/pdf/pdf-page.c b/source/pdf/pdf-page.c index 1830409a..cb60634c 100644 --- a/source/pdf/pdf-page.c +++ b/source/pdf/pdf-page.c @@ -638,6 +638,54 @@ pdf_page_transform(fz_context *ctx, pdf_page *page, fz_rect *page_mediabox, fz_m pdf_page_obj_transform(ctx, page->obj, page_mediabox, page_ctm); } +fz_separations * +pdf_page_separations(fz_context *ctx, pdf_page *page) +{ + pdf_obj *res = pdf_page_resources(ctx, page); + fz_separations *seps = NULL; + int i, len; + + res = pdf_dict_get(ctx, res, PDF_NAME_ColorSpace); + if (!res) + return NULL; + + fz_var(seps); + fz_var(i); + + len = pdf_dict_len(ctx, res); + + i = 0; + while (i < len) + { + fz_try(ctx) + { + do + { + pdf_obj *obj; + i++; + obj = pdf_dict_get_val(ctx, res, i-1); + + if (pdf_name_eq(ctx, pdf_array_get(ctx, obj, 0), PDF_NAME_Separation)) + { + uint32_t rgba = 0; /* FIXME */ + uint32_t cmyk = 0; /* FIXME */ + const char *name = pdf_to_name(ctx, pdf_array_get(ctx, obj, 1)); + if (!seps) + seps = fz_new_separations(ctx, 0); + fz_add_separation(ctx, seps, rgba, cmyk, name); + } + } + while (i < len); + } + fz_catch(ctx) + { + /* Don't die because a single separation failed to load */ + } + } + + return seps; +} + static void pdf_drop_page_imp(fz_context *ctx, pdf_page *page) { @@ -670,6 +718,7 @@ pdf_new_page(fz_context *ctx, pdf_document *doc) page->super.first_annot = (fz_page_first_annot_fn*)pdf_first_annot; page->super.run_page_contents = (fz_page_run_page_contents_fn*)pdf_run_page_contents; page->super.page_presentation = (fz_page_page_presentation_fn*)pdf_page_presentation; + page->super.separations = (fz_page_separations_fn *)pdf_page_separations; page->obj = NULL; |