[gs-commits] ghostpdl branch, pdfi, updated. jbig2dec-0.14-2217-gc736da7
[email protected] (Nancy Durgin)
| Newsgroups | gmane.comp.printing.ghostscript.cvs |
|---|---|
| Message-ID | <[email protected]> |
The ghostpdl branch, pdfi has been updated
via c736da72fd191e8bfe114ec0c9db26f39fa20f29 (commit)
from 3eb0029e1044fa72f5c221ffe69b25c15f12d3fb (commit)
----------------------------------------------------------------------
commit c736da72fd191e8bfe114ec0c9db26f39fa20f29
Author: Nancy Durgin <[email protected]>
Date: Thu Sep 19 14:13:00 2019 -0700
Cleanup transparency/spot code
Cleaned up pdfi_check_transparency_spots() error-handling, etc.
No functional changes.
Fixed uninitialized variable and warning in ghostpdf.c
But the uninitialized variable would only matter for PDFINFO mode.
diff --git a/pdf/ghostpdf.c b/pdf/ghostpdf.c
index 442455f..018fdd5 100644
--- a/pdf/ghostpdf.c
+++ b/pdf/ghostpdf.c
@@ -33,6 +33,7 @@
#include "pdf_text.h"
#include "pdf_page.h"
#include "pdf_check.h"
+#include "pdf_optcontent.h"
/*
* Convenience routine to check if a given string exists in a dictionary
@@ -190,7 +191,7 @@ static int pdfi_dump_box(pdf_context *ctx, pdf_dict *page_dict, const char *Key)
*/
static int pdfi_output_page_info(pdf_context *ctx, uint64_t page_num)
{
- int code, spots;
+ int code, spots = 0;
bool known = false, transparent = false;
double f;
uint64_t page_offset = 0;
diff --git a/pdf/pdf_check.c b/pdf/pdf_check.c
index ea6bfb1..8c9c269 100644
--- a/pdf/pdf_check.c
+++ b/pdf/pdf_check.c
@@ -846,108 +846,105 @@ exit:
int pdfi_check_transparency_spots(pdf_context *ctx)
{
int code = 0;
+ pdf_dict *page_dict = NULL;
+ uint64_t page_offset = 0;
+ bool uses_transparency = false;
+ int spots = 0;
+ uint64_t ix;
+ int bytes;
+
+ if (ctx->num_pages == 0)
+ return 0;
/* Loop round all the pages looking for spot colours and transparency. We only check
* for spot colours if the device is capable of spot colours (the code checks). We
* only store the transparency setting if NOTRANSPARENCY is not set
*/
- if (ctx->num_pages) {
- pdf_dict *page_dict = NULL;
- uint64_t page_offset = 0;
- bool uses_transparency = false;
- int spots = 0;
- uint64_t ix;
-
- int bytes = (int)ceil((float)ctx->num_pages / 8.0f);
- ctx->PageTransparencyArray = (char *)gs_alloc_bytes(ctx->memory, bytes, "pdfi_process_file, allocate page transparency tracking array");
- memset(ctx->PageTransparencyArray, 0x00, bytes);
-
- code = pdfi_alloc_object(ctx, PDF_DICT, 32, (pdf_obj **)&ctx->SpotNames);
+
+ bytes = (int)ceil((float)ctx->num_pages / 8.0f);
+ ctx->PageTransparencyArray =
+ (char *)gs_alloc_bytes(ctx->memory, bytes,
+ "pdfi_process_file, allocate page transparency tracking array");
+ memset(ctx->PageTransparencyArray, 0x00, bytes);
+
+ /* NOTE: This SpotNames dict is just used during this function, to aid in counting unique spots */
+ ctx->SpotNames = NULL;
+ code = pdfi_alloc_object(ctx, PDF_DICT, 32, (pdf_obj **)&ctx->SpotNames);
+ if (code < 0)
+ goto exit;
+ pdfi_countup(ctx->SpotNames);
+
+ for (ix=0;ix < ctx->num_pages;ix++) {
+ if (ctx->pdfdebug)
+ dmprintf1(ctx->memory, "%% Checking Page %"PRIi64" for transparency and spot plates\n", ix + 1);
+
+ uses_transparency = false;
+
+ /* Get the page dictionary */
+ code = pdfi_loop_detector_mark(ctx);
if (code < 0)
goto exit;
- pdfi_countup(ctx->SpotNames);
-
- for (ix=0;ix < ctx->num_pages;ix++) {
- if (ctx->pdfdebug)
- dmprintf1(ctx->memory, "%% Checking Page %"PRIi64" for transparency and spot plates\n", ix + 1);
-
- uses_transparency = false;
-
- /* Get the page dictionary */
- code = pdfi_loop_detector_mark(ctx);
- if (code < 0)
- goto exit;
-
- code = pdfi_loop_detector_add_object(ctx, ctx->Pages->object_num);
- if (code < 0) {
- pdfi_loop_detector_cleartomark(ctx);
- goto exit;
- }
-
- page_offset = 0;
- code = pdfi_get_page_dict(ctx, ctx->Pages, ix, &page_offset, &page_dict, NULL);
+ code = pdfi_loop_detector_add_object(ctx, ctx->Pages->object_num);
+ if (code < 0) {
pdfi_loop_detector_cleartomark(ctx);
- if (code < 0) {
- if (code == gs_error_VMerror || ctx->pdfstoponerror)
- goto exit;
- return 0;
- }
-
- if (code > 0) {
- /* This can happen if the number of declared pages (/Count) is larger than the number of pages in the Pages array
- * We'll ignore that for the purposes of transparency checking. If the user tries to render this
- * page it'll fail in the page rendering code.
- */
- pdfi_countdown(page_dict);
- page_dict = NULL;
- break;
- }
+ goto exit;
+ }
- /* Check the page dictionary for spots and transparency */
- code = pdfi_check_page_transparency(ctx, page_dict, &uses_transparency, &spots);
- if (code < 0) {
- pdfi_countdown(ctx->SpotNames);
- pdfi_countdown(page_dict);
- ctx->SpotNames = NULL;
+ page_offset = 0;
+ code = pdfi_get_page_dict(ctx, ctx->Pages, ix, &page_offset, &page_dict, NULL);
+ pdfi_loop_detector_cleartomark(ctx);
+ if (code < 0) {
+ if (code == gs_error_VMerror || ctx->pdfstoponerror)
goto exit;
- }
- if (uses_transparency && !ctx->notransparency) {
- uint64_t index = ix >> 3;
- char value = 0x80 >> (ix % 8);
+ return 0;
+ }
- ctx->PageTransparencyArray[index] |= value;
- }
- pdfi_countdown(page_dict);
- page_dict = NULL;
+ if (code > 0) {
+ /* This can happen if the number of declared pages (/Count) is larger than the number of pages in the Pages array
+ * We'll ignore that for the purposes of transparency checking. If the user tries to render this
+ * page it'll fail in the page rendering code.
+ */
+ break;
}
- pdfi_countdown(ctx->SpotNames);
- ctx->SpotNames = NULL;
+ /* Check the page dictionary for spots and transparency */
+ code = pdfi_check_page_transparency(ctx, page_dict, &uses_transparency, &spots);
+ if (code < 0)
+ goto exit;
+ if (uses_transparency && !ctx->notransparency) {
+ uint64_t index = ix >> 3;
+ char value = 0x80 >> (ix % 8);
+
+ ctx->PageTransparencyArray[index] |= value;
+ }
+ pdfi_countdown(page_dict);
+ page_dict = NULL;
+ }
- /* If there are spot colours (and by inference, the device renders spot plates) then
- * send the number of Spots to the device, so it can setup correctly.
- */
- if (spots > 0) {
- gs_c_param_list_write(&ctx->pdfi_param_list, ctx->memory);
- param_write_int((gs_param_list *)&ctx->pdfi_param_list, "PageSpotColors", &spots);
- gs_c_param_list_read(&ctx->pdfi_param_list);
- code = gs_putdeviceparams(ctx->pgs->device, (gs_param_list *)&ctx->pdfi_param_list);
- if (code > 0) {
- /* The device was closed, we need to reopen it */
- code = gs_setdevice_no_erase(ctx->pgs, ctx->pgs->device);
- if (code < 0) {
- if (uses_transparency)
- (void)gs_abort_pdf14trans_device(ctx->pgs);
- pdfi_countdown(ctx->SpotNames);
- pdfi_countdown(page_dict);
- goto exit;
- }
- gs_erasepage(ctx->pgs);
+ /* If there are spot colours (and by inference, the device renders spot plates) then
+ * send the number of Spots to the device, so it can setup correctly.
+ */
+ if (spots > 0) {
+ gs_c_param_list_write(&ctx->pdfi_param_list, ctx->memory);
+ param_write_int((gs_param_list *)&ctx->pdfi_param_list, "PageSpotColors", &spots);
+ gs_c_param_list_read(&ctx->pdfi_param_list);
+ code = gs_putdeviceparams(ctx->pgs->device, (gs_param_list *)&ctx->pdfi_param_list);
+ if (code > 0) {
+ /* The device was closed, we need to reopen it */
+ code = gs_setdevice_no_erase(ctx->pgs, ctx->pgs->device);
+ if (code < 0) {
+ if (uses_transparency)
+ (void)gs_abort_pdf14trans_device(ctx->pgs);
+ goto exit;
}
+ gs_erasepage(ctx->pgs);
}
}
exit:
+ pdfi_countdown(ctx->SpotNames);
+ pdfi_countdown(page_dict);
+ ctx->SpotNames = NULL;
return code;
}
Summary of changes:
pdf/ghostpdf.c | 3 +-
pdf/pdf_check.c | 157 +++++++++++++++++++++++++++-----------------------------
2 files changed, 79 insertions(+), 81 deletions(-)