diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-05-03 20:20:12 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-05-03 20:20:12 +0200 |
| commit | 06b8e2576f952e8f8b097ee906f662d2ac38e2e8 (patch) | |
| tree | 35b0b9dc614f5f097ffb82e4c2d032958833fc3e | |
| parent | Fixes and improvements to stream.c (diff) | |
| download | blind-06b8e2576f952e8f8b097ee906f662d2ac38e2e8.tar.gz blind-06b8e2576f952e8f8b097ee906f662d2ac38e2e8.tar.bz2 blind-06b8e2576f952e8f8b097ee906f662d2ac38e2e8.tar.xz | |
Add constants D65_XYZ_X and D65_XYZ_Z
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
| -rw-r--r-- | src/blind-gauss-blur.c | 13 | ||||
| -rw-r--r-- | src/blind-invert-luma.c | 16 | ||||
| -rw-r--r-- | src/blind-set-saturation.c | 8 | ||||
| -rw-r--r-- | src/blind-single-colour.c | 6 | ||||
| -rw-r--r-- | src/util/colour.h | 3 |
5 files changed, 19 insertions, 27 deletions
diff --git a/src/blind-gauss-blur.c b/src/blind-gauss-blur.c index 2dc6d08..031860d 100644 --- 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 index b876967..9a8ac51 100644 --- 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 index 94e994c..ce0dd40 100644 --- 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 index 955511a..2a6511d 100644 --- 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 index 84c543c..ae50d32 100644 --- 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) { |
