summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNancy Durgin <nancy.durgin@artifex.com>2021-03-23 14:48:07 -0700
committerNancy Durgin <nancy.durgin@artifex.com>2021-03-24 08:37:10 -0700
commitde5b3cdcd4b2af9468fc15c9e8c20d13d163f552 (patch)
treee0cff2e483bc65c6bb2b0269d024793e1fb73dd3
parent893394eb46ed81e1a7964b510f1ed1bebb3b8dd0 (diff)
downloadghostpdl-de5b3cdcd4b2af9468fc15c9e8c20d13d163f552.tar.gz
Support for JPXDecode colorspaces
Partial implementation to support the JPXDecode enum colorspaces This puts in the mapping that is in jp2_csp_dict in the gs code. It tries to load this colorspace by name (which will fail) and then loads the backup colorspace, which should do the same as it did before. Need to implement support for these in pdf_colour.c, however this is best done. It looks like pdfi_create_icc() supports the GSICC_STANDARD_PROFILES, so the bottom piece is in place, just lacking some plumbing in between. gs code is scattered around in gs_res.ps and gs_lvl2.ps.
-rw-r--r--pdf/ghostpdf.c2
-rw-r--r--pdf/ghostpdf.h3
-rw-r--r--pdf/pdf_image.c65
3 files changed, 51 insertions, 19 deletions
diff --git a/pdf/ghostpdf.c b/pdf/ghostpdf.c
index 6967a2912..d68a0f76d 100644
--- a/pdf/ghostpdf.c
+++ b/pdf/ghostpdf.c
@@ -357,6 +357,8 @@ pdfi_report_errors(pdf_context *ctx)
dmprintf(ctx->memory, "\tAn invalid transparency group XObject was ignored.\n");
if (ctx->pdf_errors & E_PDF_NO_SUBTYPE)
dmprintf(ctx->memory, "\tAn object was missing the required /Subtype.\n");
+ if (ctx->pdf_errors & E_PDF_IMAGECOLOR_ERROR)
+ dmprintf(ctx->memory, "\tAn image had an unknown or invalid colorspace.\n");
}
if (ctx->pdf_warnings != W_PDF_NOWARNING) {
diff --git a/pdf/ghostpdf.h b/pdf/ghostpdf.h
index 9f6cc25c3..c8cc46b1e 100644
--- a/pdf/ghostpdf.h
+++ b/pdf/ghostpdf.h
@@ -132,7 +132,8 @@ typedef enum pdf_error_flag_e {
E_PDF_INHERITED_STREAM_RESOURCE = E_PDF_NOHEADER << 27,
E_PDF_DEREF_FREE_OBJ = E_PDF_NOHEADER << 28,
E_PDF_INVALID_TRANS_XOBJECT = E_PDF_NOHEADER << 29,
- E_PDF_NO_SUBTYPE = E_PDF_NOHEADER << 30
+ E_PDF_NO_SUBTYPE = E_PDF_NOHEADER << 30,
+ E_PDF_IMAGECOLOR_ERROR = E_PDF_NOHEADER << 31
} pdf_error_flag;
typedef enum pdf_warning_flag_e {
diff --git a/pdf/pdf_image.c b/pdf/pdf_image.c
index 4c86c0bd6..0cb081f71 100644
--- a/pdf/pdf_image.c
+++ b/pdf/pdf_image.c
@@ -1146,6 +1146,8 @@ pdfi_image_get_color(pdf_context *ctx, pdf_c_stream *source, pdfi_image_info_t *
int code = 0;
pdfi_jpx_info_t *jpx_info = &image_info->jpx_info;
pdf_obj *ColorSpace = NULL;
+ char *backup_color_name = NULL;
+ bool using_enum_cs = false;
/* NOTE: Spec says ImageMask and ColorSpace mutually exclusive */
if (image_info->ImageMask) {
@@ -1186,33 +1188,40 @@ pdfi_image_get_color(pdf_context *ctx, pdf_c_stream *source, pdfi_image_info_t *
} else {
char *color_str;
- /* TODO: Hackity BS here, just trying to pull out a reasonable color for now */
+ /* TODO: These colorspace names are pulled from the gs code (jp2_csp_dict), but need
+ * to be implemented to actually work.
+ */
+ backup_color_name = (char *)"DeviceRGB";
switch(jpx_info->cs_enum) {
case 12:
color_str = (char *)"DeviceCMYK";
break;
+ case 14:
+ /* TODO: set WhitePoint somehow? */
+ color_str = (char *)"LAB";
+ break;
case 16:
- case 18:
- color_str = (char *)"DeviceRGB";
+ color_str = (char *)"sRGBICC";
break;
case 17:
- color_str = (char *)"DeviceGray";
+ color_str = (char *)"sGrayICC";
+ backup_color_name = (char *)"DeviceGray";
+ break;
+ case 18:
+ color_str = (char *)"DeviceRGB";
break;
case 20:
case 24:
- /* TODO: gs Implementation assumes these are DeviceRGB.
- * We can do same and get matching output (but is it correct?)
- * (should probably look at num comps, but gs code doesn't)
- */
- if (ctx->args.pdfdebug)
- dmprintf1(ctx->memory,
- "WARNING JPXDecode: Unsupported EnumCS %d, assuming DeviceRGB\n",
- jpx_info->cs_enum);
- color_str = (char *)"DeviceRGB";
+ color_str = (char *)"esRGBICC";
+ break;
+ case 21:
+ color_str = (char *)"rommRGBICC";
break;
default:
+ /* TODO: Could try DeviceRGB instead of erroring out? */
dmprintf1(ctx->memory,
- "WARNING JPXDecode: Unsupported EnumCS %d\n", jpx_info->cs_enum);
+ "**** Error: JPXDecode: Unsupported EnumCS %d\n", jpx_info->cs_enum);
+ ctx->pdf_warnings |= E_PDF_IMAGECOLOR_ERROR;
goto cleanupExit;
}
@@ -1221,6 +1230,7 @@ pdfi_image_get_color(pdf_context *ctx, pdf_c_stream *source, pdfi_image_info_t *
if (code < 0)
goto cleanupExit;
pdfi_countup(ColorSpace);
+ using_enum_cs = true;
}
} else {
/* Assume DeviceRGB colorspace */
@@ -1243,11 +1253,10 @@ pdfi_image_get_color(pdf_context *ctx, pdf_c_stream *source, pdfi_image_info_t *
code = pdfi_create_colorspace(ctx, ColorSpace,
image_info->stream_dict, image_info->page_dict,
pcs, image_info->inline_image);
- /* TODO: image_2bpp.pdf has an image in there somewhere that fails on this call (probably ColorN) */
if (code < 0) {
dmprintf(ctx->memory, "WARNING: Image has unsupported ColorSpace ");
- if (image_info->ColorSpace->type == PDF_NAME) {
- pdf_name *name = (pdf_name *)image_info->ColorSpace;
+ if (ColorSpace->type == PDF_NAME) {
+ pdf_name *name = (pdf_name *)ColorSpace;
char str[100];
memcpy(str, (const char *)name->data, name->length);
str[name->length] = '\0';
@@ -1255,7 +1264,27 @@ pdfi_image_get_color(pdf_context *ctx, pdf_c_stream *source, pdfi_image_info_t *
} else {
dmprintf(ctx->memory, "(not a name)\n");
}
- goto cleanupExit;
+
+ /* If we were trying an enum_cs, attempt to use backup_color_name instead */
+ if (using_enum_cs) {
+ pdfi_countdown(ColorSpace);
+ code = pdfi_name_alloc(ctx, (byte *)backup_color_name, strlen(backup_color_name), &ColorSpace);
+ if (code < 0)
+ goto cleanupExit;
+ pdfi_countup(ColorSpace);
+ /* Try to set the backup name */
+ code = pdfi_create_colorspace(ctx, ColorSpace,
+ image_info->stream_dict, image_info->page_dict,
+ pcs, image_info->inline_image);
+
+ if (code < 0) {
+ ctx->pdf_warnings |= E_PDF_IMAGECOLOR_ERROR;
+ goto cleanupExit;
+ }
+ } else {
+ ctx->pdf_warnings |= E_PDF_IMAGECOLOR_ERROR;
+ goto cleanupExit;
+ }
}
*comps = gs_color_space_num_components(*pcs);