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-luma.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'src/blind-set-luma.c') diff --git a/src/blind-set-luma.c b/src/blind-set-luma.c index 4500645..71bd59c 100644 --- a/src/blind-set-luma.c +++ b/src/blind-set-luma.c @@ -13,11 +13,44 @@ static void process_xyza(struct stream *colour, struct stream *luma, size_t n) { size_t i; - double a; + double a, y; for (i = 0; i < n; i += colour->pixel_size) { a = ((double *)(luma->buf + i))[1]; a *= ((double *)(luma->buf + i))[3]; - ((double *)(colour->buf + i))[1] *= a; + y = ((double *)(colour->buf + i))[1]; + ((double *)(colour->buf + i))[0] += y * a - y; + ((double *)(colour->buf + i))[1] = y * a; + ((double *)(colour->buf + i))[2] += y * a - y; + /* + * Note, this changes the luma only, not the saturation, + * so the result may look a bit weird. To change both + * you can use `blind-arithm mul`. + * + * Explaination: + * Y is the luma, but (X, Z) is not the chroma, + * but in CIELAB, L* is the luma and (a*, *b) is + * the chroma. Multiplying + * + * ⎛0 1 0⎞ + * ⎜1 −1 0⎟ + * ⎝0 1 −1⎠ + * + * (X Y Z)' gives a colour model similar to + * CIE L*a*b*: a model where each parameter is + * a linear transformation of the corresponding + * parameter in CIE L*a*b*. The inverse of that + * matrix is + * + * ⎛1 1 0⎞ + * ⎜1 0 0⎟ + * ⎝0 0 −1⎠ + * + * and + * + * ⎛1 1 0⎞⎛a 0 0⎞⎛0 1 0⎞ ⎛1 a−1 0⎞ + * ⎜1 0 0⎟⎜0 1 0⎟⎜1 −1 0⎟ = ⎜0 a 0⎟. + * ⎝0 0 −1⎠⎝0 0 1⎠⎝0 1 −1⎠ ⎝0 a−1 1⎠ + */ } } @@ -42,6 +75,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, &luma, STDOUT_FILENO, "", process); return 0; } -- cgit v1.2.3-70-g09d2