diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2018-01-09 16:54:09 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2018-01-10 16:06:17 +0100 |
commit | bec33a470ea600599d3ad9df472b815e7b46e824 (patch) | |
tree | 427f1a799d973a541e122c78207aaf76a7a98141 /source/pdf | |
parent | b70eb93f6936c03d8af52040bbca4d4a7db39079 (diff) | |
download | mupdf-bec33a470ea600599d3ad9df472b815e7b46e824.tar.xz |
Add colorspace type enum and use it instead of hardcoded checks on N.
Diffstat (limited to 'source/pdf')
-rw-r--r-- | source/pdf/pdf-colorspace.c | 7 | ||||
-rw-r--r-- | source/pdf/pdf-device.c | 19 | ||||
-rw-r--r-- | source/pdf/pdf-image.c | 81 | ||||
-rw-r--r-- | source/pdf/pdf-interpret.c | 2 | ||||
-rw-r--r-- | source/pdf/pdf-op-buffer.c | 2 |
5 files changed, 66 insertions, 45 deletions
diff --git a/source/pdf/pdf-colorspace.c b/source/pdf/pdf-colorspace.c index 44105f7b..44615977 100644 --- a/source/pdf/pdf-colorspace.c +++ b/source/pdf/pdf-colorspace.c @@ -173,14 +173,17 @@ load_devicen(fz_context *ctx, pdf_obj *array) pdf_obj *tintobj = pdf_array_get(ctx, array, 3); fz_colorspace *base; pdf_function *tint = NULL; + char *colorspace_name; int i, n; - char *colorspace_name = "DeviceN"; fz_var(tint); fz_var(devn); if (pdf_is_array(ctx, nameobj)) + { n = pdf_array_len(ctx, nameobj); + colorspace_name = "DeviceN"; + } else { n = 1; @@ -204,7 +207,7 @@ load_devicen(fz_context *ctx, pdf_obj *array) devn->base = fz_keep_colorspace(ctx, base); /* We drop it during the devn free... */ devn->tint = tint; - cs = fz_new_colorspace(ctx, colorspace_name, n, FZ_CS_SUBTRACTIVE | FZ_CS_DEVICE_N, + cs = fz_new_colorspace(ctx, colorspace_name, FZ_COLORSPACE_SEPARATION, 0, n, fz_colorspace_is_icc(ctx, fz_device_rgb(ctx)) ? devicen_to_alt : devicen_to_rgb, NULL, base_devicen, NULL, free_devicen, devn, sizeof(struct devicen) + base->size + pdf_function_size(ctx, tint)); diff --git a/source/pdf/pdf-device.c b/source/pdf/pdf-device.c index 314dc85e..c45dda40 100644 --- a/source/pdf/pdf-device.c +++ b/source/pdf/pdf-device.c @@ -567,19 +567,24 @@ pdf_dev_new_form(fz_context *ctx, pdf_obj **form_ref, pdf_device *pdev, const fz group = pdf_new_dict(ctx, doc, 5); fz_try(ctx) { - int n = fz_colorspace_n(ctx, colorspace); pdf_dict_put_drop(ctx, group, PDF_NAME_Type, PDF_NAME_Group); pdf_dict_put_drop(ctx, group, PDF_NAME_S, PDF_NAME_Transparency); pdf_dict_put_drop(ctx, group, PDF_NAME_K, pdf_new_bool(ctx, doc, knockout)); pdf_dict_put_drop(ctx, group, PDF_NAME_I, pdf_new_bool(ctx, doc, isolated)); - if (n == 0) - {} - if (n == 1) + switch (fz_colorspace_type(ctx, colorspace)) + { + case FZ_COLORSPACE_GRAY: pdf_dict_put_drop(ctx, group, PDF_NAME_CS, PDF_NAME_DeviceGray); - else if (n == 4) - pdf_dict_put_drop(ctx, group, PDF_NAME_CS, PDF_NAME_DeviceCMYK); - else + break; + case FZ_COLORSPACE_RGB: pdf_dict_put_drop(ctx, group, PDF_NAME_CS, PDF_NAME_DeviceRGB); + break; + case FZ_COLORSPACE_CMYK: + pdf_dict_put_drop(ctx, group, PDF_NAME_CS, PDF_NAME_DeviceCMYK); + break; + default: + break; + } group_ref = pdev->groups[num].ref = pdf_add_object(ctx, doc, group); } fz_always(ctx) diff --git a/source/pdf/pdf-image.c b/source/pdf/pdf-image.c index b7768074..eeb4f0f2 100644 --- a/source/pdf/pdf-image.c +++ b/source/pdf/pdf-image.c @@ -468,47 +468,58 @@ raw_or_unknown_compression: pdf_dict_put_drop(ctx, imobj, PDF_NAME_BitsPerComponent, pdf_new_int(ctx, doc, image->bpc)); cs = pixmap ? pixmap->colorspace : image->colorspace; - n = fz_colorspace_n(ctx, cs); - - if (fz_colorspace_is_indexed(ctx, cs)) + switch (fz_colorspace_type(ctx, cs)) { - fz_colorspace *basecs; - unsigned char *lookup = NULL; - int high = 0; - int basen; - pdf_obj *arr; - - lookup = fz_indexed_colorspace_palette(ctx, cs, &high); - basecs = fz_colorspace_base(ctx, cs); - basen = fz_colorspace_n(ctx, basecs); - - pdf_dict_put_drop(ctx, imobj, PDF_NAME_ColorSpace, arr = pdf_new_array(ctx, doc, 4)); - - pdf_array_put_drop(ctx, arr, 0, PDF_NAME_Indexed); - if (basen <= 1) - pdf_array_put_drop(ctx, arr, 1, PDF_NAME_DeviceGray); - else if (basen == 3) - // TODO: Lab colorspace? - pdf_array_put_drop(ctx, arr, 1, PDF_NAME_DeviceRGB); - else if (basen == 4) - pdf_array_put_drop(ctx, arr, 1, PDF_NAME_DeviceCMYK); - else - // TODO: convert to RGB! - fz_throw(ctx, FZ_ERROR_GENERIC, "only indexed Gray, RGB, and CMYK colorspaces supported"); - - pdf_array_put_drop(ctx, arr, 2, pdf_new_int(ctx, doc, high)); - pdf_array_put_drop(ctx, arr, 3, pdf_new_string(ctx, doc, (char *) lookup, basen * (high + 1))); - } - else if (n <= 1) + case FZ_COLORSPACE_INDEXED: + { + fz_colorspace *basecs; + unsigned char *lookup = NULL; + int high = 0; + int basen; + pdf_obj *arr; + + lookup = fz_indexed_colorspace_palette(ctx, cs, &high); + basecs = fz_colorspace_base(ctx, cs); + basen = fz_colorspace_n(ctx, basecs); + + pdf_dict_put_drop(ctx, imobj, PDF_NAME_ColorSpace, arr = pdf_new_array(ctx, doc, 4)); + + pdf_array_put_drop(ctx, arr, 0, PDF_NAME_Indexed); + switch (fz_colorspace_type(ctx, basecs)) + { + case FZ_COLORSPACE_GRAY: + pdf_array_put_drop(ctx, arr, 1, PDF_NAME_DeviceGray); + break; + case FZ_COLORSPACE_RGB: + pdf_array_put_drop(ctx, arr, 1, PDF_NAME_DeviceRGB); + break; + case FZ_COLORSPACE_CMYK: + pdf_array_put_drop(ctx, arr, 1, PDF_NAME_DeviceCMYK); + break; + default: + // TODO: convert to RGB! + fz_throw(ctx, FZ_ERROR_GENERIC, "only indexed Gray, RGB, and CMYK colorspaces supported"); + break; + } + + pdf_array_put_drop(ctx, arr, 2, pdf_new_int(ctx, doc, high)); + pdf_array_put_drop(ctx, arr, 3, pdf_new_string(ctx, doc, (char *) lookup, basen * (high + 1))); + } + break; + case FZ_COLORSPACE_GRAY: pdf_dict_put_drop(ctx, imobj, PDF_NAME_ColorSpace, PDF_NAME_DeviceGray); - else if (n == 3) - // TODO: Lab colorspace? + break; + case FZ_COLORSPACE_RGB: pdf_dict_put_drop(ctx, imobj, PDF_NAME_ColorSpace, PDF_NAME_DeviceRGB); - else if (n == 4) + break; + case FZ_COLORSPACE_CMYK: pdf_dict_put_drop(ctx, imobj, PDF_NAME_ColorSpace, PDF_NAME_DeviceCMYK); - else + break; + default: // TODO: convert to RGB! fz_throw(ctx, FZ_ERROR_GENERIC, "only Gray, RGB, and CMYK colorspaces supported"); + break; + } } if (image->mask) diff --git a/source/pdf/pdf-interpret.c b/source/pdf/pdf-interpret.c index 8b44079e..6ce63eb6 100644 --- a/source/pdf/pdf-interpret.c +++ b/source/pdf/pdf-interpret.c @@ -280,7 +280,7 @@ pdf_process_extgstate(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, pdf_ob /* Which in CMYK means not all zeros! This should really be * a test for subtractive color spaces, but this will have * to do for now. */ - if (colorspace == fz_device_cmyk(ctx)) + if (fz_colorspace_is_cmyk(ctx, colorspace)) softmask_bc[3] = 1.0f; fz_drop_colorspace(ctx, colorspace); diff --git a/source/pdf/pdf-op-buffer.c b/source/pdf/pdf-op-buffer.c index 69707843..95edea46 100644 --- a/source/pdf/pdf-op-buffer.c +++ b/source/pdf/pdf-op-buffer.c @@ -599,6 +599,8 @@ pdf_out_BI(fz_context *ctx, pdf_processor *proc, fz_image *img) fz_write_string(ctx, out, "/CS/CMYK\n"); else if (fz_colorspace_is_indexed(ctx, img->colorspace)) fz_write_string(ctx, out, "/CS/I\n"); + else + fz_throw(ctx, FZ_ERROR_GENERIC, "BI operator can only show mask, Gray, RGB, CMYK, or Indexed images"); if (img->interpolate) fz_write_string(ctx, out, "/I true\n"); fz_write_string(ctx, out, "/D["); |