summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2010-10-20 23:03:50 +0000
committerTor Andersson <tor@ghostscript.com>2010-10-20 23:03:50 +0000
commit3a67269b466ada017058faa8ebed2df10f12c5f4 (patch)
treec97bfb36f91f30030aeeb6ee0c2d1d02d721ea6f
parentebf0fd7b216f3753e4c7f4ae3e8f1ce4b03e00c6 (diff)
downloadmupdf-3a67269b466ada017058faa8ebed2df10f12c5f4.tar.xz
Fix Lab colorspace conversions.
-rw-r--r--fitz/res_colorspace.c2
-rw-r--r--mupdf/pdf_colorspace.c31
2 files changed, 16 insertions, 17 deletions
diff --git a/fitz/res_colorspace.c b/fitz/res_colorspace.c
index 2ce4525a..f770bbcb 100644
--- a/fitz/res_colorspace.c
+++ b/fitz/res_colorspace.c
@@ -347,6 +347,8 @@ fz_stdconvpixmap(fz_pixmap *src, fz_pixmap *dst)
srcn = ss->n;
dstn = ds->n;
+ /* TODO: special case Lab colorspace (scaling of components to float) */
+
/* Brute-force for small images */
if (src->w * src->h < 256)
{
diff --git a/mupdf/pdf_colorspace.c b/mupdf/pdf_colorspace.c
index e0a3ab8e..447b3047 100644
--- a/mupdf/pdf_colorspace.c
+++ b/mupdf/pdf_colorspace.c
@@ -41,17 +41,14 @@ static inline float invg(float x)
static void
labtoxyz(fz_colorspace *cs, float *lab, float *xyz)
{
+ /* input is in range (0..100, -128..127, -128..127) not (0..1, 0..1, 0..1) */
float lstar, astar, bstar, l, m, n;
- float tmp[3];
- tmp[0] = lab[0] * 100;
- tmp[1] = lab[1] * 200 - 100;
- tmp[2] = lab[2] * 200 - 100;
- lstar = tmp[0];
- astar = CLAMP(tmp[1], -100, 100);
- bstar = CLAMP(tmp[2], -100, 100);
- l = (lstar + 16) / 116 + astar / 500;
+ lstar = lab[0];
+ astar = lab[1];
+ bstar = lab[2];
m = (lstar + 16) / 116;
- n = (lstar + 16) / 116 - bstar / 200;
+ l = m + astar / 500;
+ n = m - bstar / 200;
xyz[0] = fung(l);
xyz[1] = fung(m);
xyz[2] = fung(n);
@@ -60,17 +57,17 @@ labtoxyz(fz_colorspace *cs, float *lab, float *xyz)
static void
xyztolab(fz_colorspace *cs, float *xyz, float *lab)
{
- float tmp[3];
+ float lstar, astar, bstar;
float yyn = xyz[1];
if (yyn < 0.008856f)
- tmp[0] = 116.0f * yyn * (1.0f / 3.0f) - 16.0f;
+ lstar = 116.0f * yyn * (1.0f / 3.0f) - 16.0f;
else
- tmp[0] = 903.3f * yyn;
- tmp[1] = 500 * (invg(xyz[0]) - invg(xyz[1]));
- tmp[2] = 200 * (invg(xyz[1]) - invg(xyz[2]));
- lab[0] = tmp[0] / 100;
- lab[1] = (tmp[1] + 100) / 200;
- lab[2] = (tmp[2] + 100) / 200;
+ lstar = 903.3f * yyn;
+ astar = 500 * (invg(xyz[0]) - invg(xyz[1]));
+ bstar = 200 * (invg(xyz[1]) - invg(xyz[2]));
+ lab[0] = lstar;
+ lab[1] = astar;
+ lab[2] = bstar;
}
static fz_colorspace kdevicelab = { -1, "Lab", 3, labtoxyz, xyztolab };