diff options
author | Robin Watts <robin.watts@artifex.com> | 2017-08-02 18:17:41 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2017-10-24 15:16:35 +0100 |
commit | cbdb9dc747ff7e7c9e187e056c4077edae629729 (patch) | |
tree | 800d473527ee866b91fe9fcdce8ee6930f1c058b | |
parent | 3e6e2464b32ca6d9fdc9cfc8c80c33aace8ec5e0 (diff) | |
download | mupdf-cbdb9dc747ff7e7c9e187e056c4077edae629729.tar.xz |
Don't apply default decode array to ICC Lab image data.
Adjust the decode array to allow for the fact that the default
decode is done by the ICC code.
-rw-r--r-- | include/mupdf/fitz/colorspace.h | 1 | ||||
-rw-r--r-- | source/fitz/colorspace.c | 2 | ||||
-rw-r--r-- | source/fitz/image.c | 15 | ||||
-rw-r--r-- | source/pdf/pdf-image.c | 9 |
4 files changed, 25 insertions, 2 deletions
diff --git a/include/mupdf/fitz/colorspace.h b/include/mupdf/fitz/colorspace.h index 3c393caa..068ec896 100644 --- a/include/mupdf/fitz/colorspace.h +++ b/include/mupdf/fitz/colorspace.h @@ -148,6 +148,7 @@ void fz_drop_colorspace_imp(fz_context *ctx, fz_storable *colorspace); fz_colorspace *fz_colorspace_base(fz_context *ctx, const fz_colorspace *cs); int fz_colorspace_is_icc(fz_context *ctx, const fz_colorspace *cs); +int fz_colorspace_is_lab(fz_context *ctx, const fz_colorspace *cs); int fz_colorspace_is_lab_icc(fz_context *ctx, const fz_colorspace *cs); int fz_colorspace_is_cal(fz_context *ctx, const fz_colorspace *cs); int fz_colorspace_is_indexed(fz_context *ctx, const fz_colorspace *cs); diff --git a/source/fitz/colorspace.c b/source/fitz/colorspace.c index ceec805e..9d5c93ab 100644 --- a/source/fitz/colorspace.c +++ b/source/fitz/colorspace.c @@ -679,7 +679,7 @@ clamp_lab(const fz_colorspace *cs, const float *src, float *dst) dst[i] = fz_clamp(src[i], i ? -128 : 0, i ? 127 : 100); } -static int fz_colorspace_is_lab(fz_context *ctx, const fz_colorspace *cs) +int fz_colorspace_is_lab(fz_context *ctx, const fz_colorspace *cs) { return cs && cs->to_ccs == lab_to_rgb; } diff --git a/source/fitz/image.c b/source/fitz/image.c index 2e59e401..b4fd2112 100644 --- a/source/fitz/image.c +++ b/source/fitz/image.c @@ -803,9 +803,22 @@ fz_new_image_of_size(fz_context *ctx, int w, int h, int bpc, fz_colorspace *colo image->decode[2*i+1] = maxval; } } + /* ICC spaces have the default decode arrays pickled into them. + * For most spaces this is fine, because [ 0 1 0 1 0 1 ] is + * idempotent. For Lab, however, we need to adjust it. */ + if (fz_colorspace_is_lab_icc(ctx, colorspace)) + { + /* Undo the default decode array of [0 100 -128 127 -128 127] */ + image->decode[0] = image->decode[0]/100.0f; + image->decode[1] = image->decode[1]/100.0f; + image->decode[2] = (image->decode[2]+128)/255.0f; + image->decode[3] = (image->decode[3]+128)/255.0f; + image->decode[4] = (image->decode[4]+128)/255.0f; + image->decode[5] = (image->decode[5]+128)/255.0f; + } for (i = 0; i < image->n; i++) { - if (image->decode[i * 2] * 255 != 0 || image->decode[i * 2 + 1] * 255 != 255) + if (image->decode[i * 2] != 0 || image->decode[i * 2 + 1] != 1) break; } if (i != image->n) diff --git a/source/pdf/pdf-image.c b/source/pdf/pdf-image.c index 48c78d96..b7768074 100644 --- a/source/pdf/pdf-image.c +++ b/source/pdf/pdf-image.c @@ -115,6 +115,15 @@ pdf_load_image_imp(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *di for (i = 0; i < n * 2; i++) decode[i] = pdf_to_real(ctx, pdf_array_get(ctx, obj, i)); } + else if (fz_colorspace_is_lab(ctx, colorspace) || fz_colorspace_is_lab_icc(ctx, colorspace)) + { + decode[0] = 0; + decode[1] = 100; + decode[2] = -128; + decode[3] = 127; + decode[4] = -128; + decode[5] = 127; + } else { float maxval = indexed ? (1 << bpc) - 1 : 1; |