commit 06b8e2576f952e8f8b097ee906f662d2ac38e2e8
parent 217491cf00c1b6f6b2a1a1e9fe0cc2fe32241b20
Author: Mattias Andrée <maandree@kth.se>
Date: Wed, 3 May 2017 20:20:12 +0200
Add constants D65_XYZ_X and D65_XYZ_Z
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat:
5 files changed, 19 insertions(+), 27 deletions(-)
diff --git a/src/blind-gauss-blur.c b/src/blind-gauss-blur.c
@@ -31,15 +31,12 @@ process_xyza(char *restrict output, char *restrict cbuf, char *restrict sbuf,
pixel_t *img = (pixel_t *)output;
pixel_t c, k;
size_t x1, y1, i1, x2, y2, i2;
- double d, m, X, Z;
+ double d, m;
int i, blurred, blur[3] = {0, 0, 0};
size_t start, end, x2start, x2end, y2start, y2end;
int is_master;
pid_t *children;
- X = D65_XYY_X / D65_XYY_Y;
- Z = 1 / D65_XYY_Y - 1 - X;
-
y2start = x2start = 0;
x2end = colour->width;
y2end = colour->height;
@@ -65,8 +62,8 @@ process_xyza(char *restrict output, char *restrict cbuf, char *restrict sbuf,
i1 = start * colour->width;
for (y1 = start; y1 < end; y1++) {
for (x1 = 0; x1 < colour->width; x1++, i1++) {
- clr[i1][0] = clr[i1][0] / X - clr[i1][1];
- clr[i1][2] = clr[i1][2] / Z - clr[i1][1];
+ clr[i1][0] = clr[i1][0] / D65_XYZ_X - clr[i1][1];
+ clr[i1][2] = clr[i1][2] / D65_XYZ_Z - clr[i1][1];
/*
* Explaination:
* Y is the luma and ((X / Xn - Y / Yn), (Z / Zn - Y / Yn))
@@ -260,8 +257,8 @@ process_xyza(char *restrict output, char *restrict cbuf, char *restrict sbuf,
i1 = start * colour->width;
for (y1 = start; y1 < end; y1++) {
for (x1 = 0; x1 < colour->width; x1++, i1++) {
- img[i1][0] = (img[i1][0] + img[i1][1]) * X;
- img[i1][2] = (img[i1][2] + img[i1][1]) * Z;
+ img[i1][0] = (img[i1][0] + img[i1][1]) * D65_XYZ_X;
+ img[i1][2] = (img[i1][2] + img[i1][1]) * D65_XYZ_Z;
}
}
}
diff --git a/src/blind-invert-luma.c b/src/blind-invert-luma.c
@@ -13,17 +13,15 @@ static void
process_xyza(struct stream *colour, struct stream *mask, size_t n)
{
size_t i;
- double w, y, yo, X, Z;
- X = D65_XYY_X / D65_XYY_Y;
- Z = 1 / D65_XYY_Y - 1 - X;
+ double w, y, yo;
for (i = 0; i < n; i += colour->pixel_size) {
w = ((double *)(mask->buf + i))[1];
w *= ((double *)(mask->buf + i))[3];
yo = ((double *)(colour->buf + i))[1];
y = (1 - yo) * w + yo * (1 - w);
- ((double *)(colour->buf + i))[0] += (y - yo) * X;
+ ((double *)(colour->buf + i))[0] += (y - yo) * D65_XYZ_X;
((double *)(colour->buf + i))[1] = y;
- ((double *)(colour->buf + i))[2] += (y - yo) * Z;
+ ((double *)(colour->buf + i))[2] += (y - yo) * D65_XYZ_Z;
/*
* Explaination:
* Y is the luma and ((X / Xn - Y / Yn), (Z / Zn - Y / Yn))
@@ -37,17 +35,15 @@ static void
process_xyza_i(struct stream *colour, struct stream *mask, size_t n)
{
size_t i;
- double w, y, yo, X, Z;
- X = D65_XYY_X / D65_XYY_Y;
- Z = 1 / D65_XYY_Y - 1 - X;
+ double w, y, yo;
for (i = 0; i < n; i += colour->pixel_size) {
w = 1 - ((double *)(mask->buf + i))[1];
w *= ((double *)(mask->buf + i))[3];
yo = ((double *)(colour->buf + i))[1];
y = (1 - yo) * w + yo * (1 - w);
- ((double *)(colour->buf + i))[0] += (y - yo) * X;
+ ((double *)(colour->buf + i))[0] += (y - yo) * D65_XYZ_X;
((double *)(colour->buf + i))[1] = y;
- ((double *)(colour->buf + i))[2] += (y - yo) * Z;
+ ((double *)(colour->buf + i))[2] += (y - yo) * D65_XYZ_Z;
}
}
diff --git a/src/blind-set-saturation.c b/src/blind-set-saturation.c
@@ -13,17 +13,15 @@ static void
process_xyza(struct stream *colour, struct stream *satur, size_t n)
{
size_t i;
- double s, *x, y, *z, X, Z;
- X = D65_XYY_X / D65_XYY_Y;
- Z = 1 / D65_XYY_Y - 1 - X;
+ double s, *x, y, *z;
for (i = 0; i < n; i += colour->pixel_size) {
s = ((double *)(satur->buf + i))[1];
s *= ((double *)(satur->buf + i))[3];
x = ((double *)(colour->buf + i)) + 0;
y = ((double *)(colour->buf + i))[1];
z = ((double *)(colour->buf + i)) + 2;
- *x = ((*x / X - y) * s + y) * X;
- *z = ((*z / Z - y) * s + y) * Z;
+ *x = ((*x / D65_XYZ_X - y) * s + y) * D65_XYZ_X;
+ *z = ((*z / D65_XYZ_Z - y) * s + y) * D65_XYZ_Z;
/*
* Explaination:
* Y is the luma and ((X / Xn - Y / Yn), (Z / Zn - Y / Yn))
diff --git a/src/blind-single-colour.c b/src/blind-single-colour.c
@@ -47,11 +47,9 @@ main(int argc, char *argv[])
usage();
if (argc < 3) {
- X = D65_XYY_X / D65_XYY_Y;
- Z = 1 / D65_XYY_Y - 1 - X;
Y = etolf_arg("the Y value", argv[0]);
- X *= Y;
- Z *= Y;
+ X = Y * D65_XYZ_X;
+ Z = Y * D65_XYZ_Z;
} else {
X = etolf_arg("the X value", argv[0]);
Y = etolf_arg("the Y value", argv[1]);
diff --git a/src/util/colour.h b/src/util/colour.h
@@ -4,6 +4,9 @@
#define D65_XYY_X 0.312726871026564878786047074755
#define D65_XYY_Y 0.329023206641284038376227272238
+#define D65_XYZ_X (D65_XYY_X / D65_XYY_Y)
+#define D65_XYZ_Z (1 / D65_XYY_Y - 1 - D65_XYZ_X)
+
static inline double
srgb_encode(double t)
{