summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mupdf/fitz/colorspace.h6
-rw-r--r--source/fitz/colorspace.c6
-rw-r--r--source/pdf/pdf-op-run.c14
3 files changed, 24 insertions, 2 deletions
diff --git a/include/mupdf/fitz/colorspace.h b/include/mupdf/fitz/colorspace.h
index 7676413a..cf635a8d 100644
--- a/include/mupdf/fitz/colorspace.h
+++ b/include/mupdf/fitz/colorspace.h
@@ -23,6 +23,12 @@ typedef struct fz_colorspace_s fz_colorspace;
int fz_colorspace_is_indexed(fz_context *ctx, fz_colorspace *cs);
/*
+ fz_colorspace_is_lab: Return true, iff a given colorspace is
+ lab.
+*/
+int fz_colorspace_is_lab(fz_context *ctx, fz_colorspace *cs);
+
+/*
fz_device_gray: Get colorspace representing device specific gray.
*/
fz_colorspace *fz_device_gray(fz_context *ctx);
diff --git a/source/fitz/colorspace.c b/source/fitz/colorspace.c
index 298c4712..c07d322b 100644
--- a/source/fitz/colorspace.c
+++ b/source/fitz/colorspace.c
@@ -277,6 +277,12 @@ fz_colorspace_is_indexed(fz_context *ctx, fz_colorspace *cs)
return (cs && !strcmp(cs->name, "Indexed"));
}
+int
+fz_colorspace_is_lab(fz_context *ctx, fz_colorspace *cs)
+{
+ return (cs && !strcmp(cs->name, "Lab"));
+}
+
/* Fast pixmap color conversions */
static void fast_gray_to_rgb(fz_pixmap *dst, fz_pixmap *src)
diff --git a/source/pdf/pdf-op-run.c b/source/pdf/pdf-op-run.c
index e502cf69..03b45725 100644
--- a/source/pdf/pdf-op-run.c
+++ b/source/pdf/pdf-op-run.c
@@ -1136,13 +1136,23 @@ pdf_set_color(fz_context *ctx, pdf_run_processor *pr, int what, float *v)
{
case PDF_MAT_PATTERN:
case PDF_MAT_COLOR:
+ /* ICC Colorspaces would be handled here too, if we handled them */
if (fz_colorspace_is_indexed(ctx, mat->colorspace))
{
mat->v[0] = fz_clamp(v[0], 0, 1) / 255;
break;
}
- for (i = 0; i < mat->colorspace->n; i++)
- mat->v[i] = fz_clamp(v[i], 0, 1);
+ else if (fz_colorspace_is_lab(ctx, mat->colorspace))
+ {
+ /* input is in range (0..100, -128..127, -128..127) not (0..1, 0..1, 0..1) */
+ for (i = 0; i < mat->colorspace->n; i++)
+ mat->v[i] = fz_clamp(v[i], i ? -128 : 0, i ? 127 : 100);
+ }
+ else
+ {
+ for (i = 0; i < mat->colorspace->n; i++)
+ mat->v[i] = fz_clamp(v[i], 0, 1);
+ }
break;
default:
fz_warn(ctx, "color incompatible with material");