diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2011-04-06 16:24:42 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2011-04-06 16:24:42 +0200 |
commit | 83bf72e448e26f5b9c77abf0e646ec75ffc04c98 (patch) | |
tree | e93810ce13827bdbdadb8c630e414a841d75c59d | |
parent | d1ca1560865a196d1caa10a27110880b58905db3 (diff) | |
download | mupdf-83bf72e448e26f5b9c77abf0e646ec75ffc04c98.tar.xz |
Rename internal color conversion functions to reflect what they do.
We used to convert through the XYZ colorspace. For various reasons we
changed to convert through RGB instead, but the function names didn't
follow suit.
-rw-r--r-- | fitz/fitz.h | 4 | ||||
-rw-r--r-- | fitz/res_colorspace.c | 91 | ||||
-rw-r--r-- | pdf/pdf_colorspace.c | 42 |
3 files changed, 58 insertions, 79 deletions
diff --git a/fitz/fitz.h b/fitz/fitz.h index 4833ffd6..6e53a271 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -713,8 +713,8 @@ struct fz_colorspace_s int refs; char name[16]; int n; - void (*to_xyz)(fz_colorspace *, float *src, float *xyz); - void (*from_xyz)(fz_colorspace *, float *xyz, float *dst); + void (*to_rgb)(fz_colorspace *, float *src, float *rgb); + void (*from_rgb)(fz_colorspace *, float *rgb, float *dst); void (*free_data)(fz_colorspace *); void *data; }; diff --git a/fitz/res_colorspace.c b/fitz/res_colorspace.c index a98d568b..0add872a 100644 --- a/fitz/res_colorspace.c +++ b/fitz/res_colorspace.c @@ -9,8 +9,8 @@ fz_new_colorspace(char *name, int n) cs->refs = 1; fz_strlcpy(cs->name, name, sizeof cs->name); cs->n = n; - cs->to_xyz = NULL; - cs->from_xyz = NULL; + cs->to_rgb = NULL; + cs->from_rgb = NULL; cs->free_data = NULL; cs->data = NULL; return cs; @@ -40,50 +40,43 @@ fz_drop_colorspace(fz_colorspace *cs) /* Device colorspace definitions */ -static void gray_to_xyz(fz_colorspace *cs, float *gray, float *xyz) +static void gray_to_rgb(fz_colorspace *cs, float *gray, float *rgb) { - xyz[0] = gray[0]; - xyz[1] = gray[0]; - xyz[2] = gray[0]; + rgb[0] = gray[0]; + rgb[1] = gray[0]; + rgb[2] = gray[0]; } -static void xyz_to_gray(fz_colorspace *cs, float *xyz, float *gray) +static void rgb_to_gray(fz_colorspace *cs, float *rgb, float *gray) { - float r = xyz[0]; - float g = xyz[1]; - float b = xyz[2]; + float r = rgb[0]; + float g = rgb[1]; + float b = rgb[2]; gray[0] = r * 0.3f + g * 0.59f + b * 0.11f; } -static void rgb_to_xyz(fz_colorspace *cs, float *rgb, float *xyz) +static void rgb_to_rgb(fz_colorspace *cs, float *rgb, float *xyz) { xyz[0] = rgb[0]; xyz[1] = rgb[1]; xyz[2] = rgb[2]; } -static void xyz_to_rgb(fz_colorspace *cs, float *xyz, float *rgb) +static void bgr_to_rgb(fz_colorspace *cs, float *bgr, float *rgb) { - rgb[0] = xyz[0]; - rgb[1] = xyz[1]; - rgb[2] = xyz[2]; + rgb[0] = bgr[2]; + rgb[1] = bgr[1]; + rgb[2] = bgr[0]; } -static void bgr_to_xyz(fz_colorspace *cs, float *bgr, float *xyz) +static void rgb_to_bgr(fz_colorspace *cs, float *rgb, float *bgr) { - xyz[0] = bgr[2]; - xyz[1] = bgr[1]; - xyz[2] = bgr[0]; + bgr[0] = rgb[2]; + bgr[1] = rgb[1]; + bgr[2] = rgb[0]; } -static void xyz_to_bgr(fz_colorspace *cs, float *xyz, float *bgr) -{ - bgr[0] = xyz[2]; - bgr[1] = xyz[1]; - bgr[2] = xyz[0]; -} - -static void cmyk_to_xyz(fz_colorspace *cs, float *cmyk, float *xyz) +static void cmyk_to_rgb(fz_colorspace *cs, float *cmyk, float *rgb) { #ifdef SLOWCMYK /* from poppler */ float c = cmyk[0], m = cmyk[1], y = cmyk[2], k = cmyk[3]; @@ -136,22 +129,22 @@ static void cmyk_to_xyz(fz_colorspace *cs, float *cmyk, float *xyz) g += 0.2119 * x; b += 0.2235 * x; - xyz[0] = CLAMP(r, 0, 1); - xyz[1] = CLAMP(g, 0, 1); - xyz[2] = CLAMP(b, 0, 1); + rgb[0] = CLAMP(r, 0, 1); + rgb[1] = CLAMP(g, 0, 1); + rgb[2] = CLAMP(b, 0, 1); #else - xyz[0] = 1 - MIN(1, cmyk[0] + cmyk[3]); - xyz[1] = 1 - MIN(1, cmyk[1] + cmyk[3]); - xyz[2] = 1 - MIN(1, cmyk[2] + cmyk[3]); + rgb[0] = 1 - MIN(1, cmyk[0] + cmyk[3]); + rgb[1] = 1 - MIN(1, cmyk[1] + cmyk[3]); + rgb[2] = 1 - MIN(1, cmyk[2] + cmyk[3]); #endif } -static void xyz_to_cmyk(fz_colorspace *cs, float *xyz, float *cmyk) +static void rgb_to_cmyk(fz_colorspace *cs, float *rgb, float *cmyk) { float c, m, y, k; - c = 1 - xyz[0]; - m = 1 - xyz[1]; - y = 1 - xyz[2]; + c = 1 - rgb[0]; + m = 1 - rgb[1]; + y = 1 - rgb[2]; k = MIN(c, MIN(m, y)); cmyk[0] = c - k; cmyk[1] = m - k; @@ -159,10 +152,10 @@ static void xyz_to_cmyk(fz_colorspace *cs, float *xyz, float *cmyk) cmyk[3] = k; } -static fz_colorspace k_device_gray = { -1, "DeviceGray", 1, gray_to_xyz, xyz_to_gray }; -static fz_colorspace k_device_rgb = { -1, "DeviceRGB", 3, rgb_to_xyz, xyz_to_rgb }; -static fz_colorspace k_device_bgr = { -1, "DeviceRGB", 3, bgr_to_xyz, xyz_to_bgr }; -static fz_colorspace k_device_cmyk = { -1, "DeviceCMYK", 4, cmyk_to_xyz, xyz_to_cmyk }; +static fz_colorspace k_device_gray = { -1, "DeviceGray", 1, gray_to_rgb, rgb_to_gray }; +static fz_colorspace k_device_rgb = { -1, "DeviceRGB", 3, rgb_to_rgb, rgb_to_rgb }; +static fz_colorspace k_device_bgr = { -1, "DeviceRGB", 3, bgr_to_rgb, rgb_to_bgr }; +static fz_colorspace k_device_cmyk = { -1, "DeviceCMYK", 4, cmyk_to_rgb, rgb_to_cmyk }; fz_colorspace *fz_device_gray = &k_device_gray; fz_colorspace *fz_device_rgb = &k_device_rgb; @@ -304,7 +297,7 @@ static void fast_cmyk_to_rgb(fz_pixmap *src, fz_pixmap *dst) cmyk[1] = s[1] / 255.0f; cmyk[2] = s[2] / 255.0f; cmyk[3] = s[3] / 255.0f; - cmyk_to_xyz(NULL, cmyk, rgb); + cmyk_to_rgb(NULL, cmyk, rgb); d[0] = rgb[0] * 255; d[1] = rgb[1] * 255; d[2] = rgb[2] * 255; @@ -332,7 +325,7 @@ static void fast_cmyk_to_bgr(fz_pixmap *src, fz_pixmap *dst) cmyk[1] = s[1] / 255.0f; cmyk[2] = s[2] / 255.0f; cmyk[3] = s[3] / 255.0f; - cmyk_to_xyz(NULL, cmyk, rgb); + cmyk_to_rgb(NULL, cmyk, rgb); d[0] = rgb[2] * 255; d[1] = rgb[1] * 255; d[2] = rgb[0] * 255; @@ -541,14 +534,14 @@ fz_convert_pixmap(fz_pixmap *sp, fz_pixmap *dp) static void fz_std_conv_color(fz_colorspace *srcs, float *srcv, fz_colorspace *dsts, float *dstv) { - float xyz[3]; + float rgb[3]; int i; if (srcs != dsts) { - assert(srcs->to_xyz && dsts->from_xyz); - srcs->to_xyz(srcs, srcv, xyz); - dsts->from_xyz(dsts, xyz, dstv); + assert(srcs->to_rgb && dsts->from_rgb); + srcs->to_rgb(srcs, srcv, rgb); + dsts->from_rgb(dsts, rgb, dstv); for (i = 0; i < dsts->n; i++) dstv[i] = CLAMP(dstv[i], 0, 1); } @@ -647,7 +640,7 @@ fz_convert_color(fz_colorspace *ss, float *sv, fz_colorspace *ds, float *dv) else if (ds == fz_device_rgb) { #ifdef SLOWCMYK - cmyk_to_xyz(NULL, sv, dv); + cmyk_to_rgb(NULL, sv, dv); #else dv[0] = 1 - MIN(sv[0] + sv[3], 1); dv[1] = 1 - MIN(sv[1] + sv[3], 1); @@ -658,7 +651,7 @@ fz_convert_color(fz_colorspace *ss, float *sv, fz_colorspace *ds, float *dv) { #ifdef SLOWCMYK float rgb[3]; - cmyk_to_xyz(NULL, sv, rgb); + cmyk_to_rgb(NULL, sv, rgb); dv[0] = rgb[2]; dv[1] = rgb[1]; dv[2] = rgb[0]; diff --git a/pdf/pdf_colorspace.c b/pdf/pdf_colorspace.c index a98e649b..26be83d4 100644 --- a/pdf/pdf_colorspace.c +++ b/pdf/pdf_colorspace.c @@ -31,15 +31,8 @@ static inline float fung(float x) return (108.0f / 841.0f) * (x - (4.0f / 29.0f)); } -static inline float invg(float x) -{ - if (x > 0.008856f) - return powf(x, 1.0f / 3.0f); - return (7.787f * x) + (16.0f / 116.0f); -} - static void -lab_to_xyz(fz_colorspace *cs, float *lab, float *rgb) +lab_to_rgb(fz_colorspace *cs, float *lab, float *rgb) { /* input is in range (0..100, -128..127, -128..127) not (0..1, 0..1, 0..1) */ float lstar, astar, bstar, l, m, n, x, y, z, r, g, b; @@ -61,22 +54,15 @@ lab_to_xyz(fz_colorspace *cs, float *lab, float *rgb) } static void -xyz_to_lab(fz_colorspace *cs, float *xyz, float *lab) +rgb_to_lab(fz_colorspace *cs, float *rgb, float *lab) { - float lstar, astar, bstar; - float yyn = xyz[1]; - if (yyn < 0.008856f) - lstar = 116.0f * yyn * (1.0f / 3.0f) - 16.0f; - else - 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; + fz_warn("cannot convert into L*a*b colorspace"); + lab[0] = rgb[0]; + lab[1] = rgb[1]; + lab[2] = rgb[2]; } -static fz_colorspace k_device_lab = { -1, "Lab", 3, lab_to_xyz, xyz_to_lab }; +static fz_colorspace k_device_lab = { -1, "Lab", 3, lab_to_rgb, rgb_to_lab }; static fz_colorspace *fz_device_lab = &k_device_lab; /* Separation and DeviceN */ @@ -88,12 +74,12 @@ struct separation }; static void -separation_to_xyz(fz_colorspace *cs, float *color, float *xyz) +separation_to_rgb(fz_colorspace *cs, float *color, float *rgb) { struct separation *sep = cs->data; float alt[FZ_MAX_COLORS]; pdf_eval_function(sep->tint, color, cs->n, alt, sep->base->n); - sep->base->to_xyz(sep->base, alt, xyz); + sep->base->to_rgb(sep->base, alt, rgb); } static void @@ -146,7 +132,7 @@ load_separation(fz_colorspace **csp, pdf_xref *xref, fz_obj *array) sep->tint = tint; cs = fz_new_colorspace(n == 1 ? "Separation" : "DeviceN", n); - cs->to_xyz = separation_to_xyz; + cs->to_rgb = separation_to_rgb; cs->free_data = free_separation; cs->data = sep; @@ -166,7 +152,7 @@ struct indexed }; static void -indexed_to_xyz(fz_colorspace *cs, float *color, float *xyz) +indexed_to_rgb(fz_colorspace *cs, float *color, float *rgb) { struct indexed *idx = cs->data; float alt[FZ_MAX_COLORS]; @@ -175,7 +161,7 @@ indexed_to_xyz(fz_colorspace *cs, float *color, float *xyz) i = CLAMP(i, 0, idx->high); for (k = 0; k < idx->base->n; k++) alt[k] = idx->lookup[i * idx->base->n + k] / 255.0f; - idx->base->to_xyz(idx->base, alt, xyz); + idx->base->to_rgb(idx->base, alt, rgb); } static void @@ -197,7 +183,7 @@ pdf_expand_indexed_pixmap(fz_pixmap *src) int y, x, k, n, high; unsigned char *lookup; - assert(src->colorspace->to_xyz == indexed_to_xyz); + assert(src->colorspace->to_rgb == indexed_to_rgb); assert(src->n == 2); idx = src->colorspace->data; @@ -258,7 +244,7 @@ load_indexed(fz_colorspace **csp, pdf_xref *xref, fz_obj *array) memset(idx->lookup, 0, n); cs = fz_new_colorspace("Indexed", 1); - cs->to_xyz = indexed_to_xyz; + cs->to_rgb = indexed_to_rgb; cs->free_data = free_indexed; cs->data = idx; |