From 076d0dc569608c276b25742605d35b0ac44dbf46 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 15 Jan 2017 20:52:36 +0100 Subject: Fix errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/blind-set-saturation.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/blind-set-saturation.c') diff --git a/src/blind-set-saturation.c b/src/blind-set-saturation.c index 1d3ed83..3dffff0 100644 --- a/src/blind-set-saturation.c +++ b/src/blind-set-saturation.c @@ -13,16 +13,23 @@ static void process_xyza(struct stream *colour, struct stream *satur, size_t n) { size_t i; - double s, *x, *z, X, Z; + double s, *x, y, *z, X, Z; X = D65_XYY_X / D65_XYY_Y; Z = 1 / D65_XYY_Y - 1 - X; 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) * s + X; - *z = (*z - Z) * s + Z; + *x = ((*x / X - y) * s + y) * X; + *z = ((*z / Z - y) * s + y) * Z; + /* + * Explaination: + * Y is the luma and ((X / Xn - Y / Yn), (Z / Zn - Y / Yn)) + * is the chroma (according to CIELAB), where (Xn, Yn, Zn) + * is the white point. + */ } } @@ -30,16 +37,17 @@ static void process_xyza_w(struct stream *colour, struct stream *satur, size_t n) { size_t i; - double s, *x, *z, X, Z; + double s, *x, y, *z, X, Z; for (i = 0; i < n; i += colour->pixel_size) { X = ((double *)(satur->buf + i))[0]; Z = ((double *)(satur->buf + i))[2]; 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) * s + X; - *z = (*z - Z) * s + Z; + *x = ((*x / X - y) * s + y) * X; + *z = ((*z / Z - y) * s + y) * Z; } } @@ -74,6 +82,8 @@ main(int argc, char *argv[]) else eprintf("pixel format %s is not supported, try xyza\n", colour.pixfmt); + fprint_stream_head(stdout, &colour); + efflush(stdout, ""); process_two_streams(&colour, &satur, STDOUT_FILENO, "", process); return 0; } -- cgit v1.2.3-70-g09d2