diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-01-15 20:52:36 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-01-15 20:52:36 +0100 |
| commit | 076d0dc569608c276b25742605d35b0ac44dbf46 (patch) | |
| tree | 4efc85c365a5574e9216a93067031966efabff2a /src/blind-set-luma.c | |
| parent | Fix some minor errors (diff) | |
| download | blind-076d0dc569608c276b25742605d35b0ac44dbf46.tar.gz blind-076d0dc569608c276b25742605d35b0ac44dbf46.tar.bz2 blind-076d0dc569608c276b25742605d35b0ac44dbf46.tar.xz | |
Fix errors
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/blind-set-luma.c')
| -rw-r--r-- | src/blind-set-luma.c | 39 |
1 files changed, 37 insertions, 2 deletions
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, "<stdout>"); process_two_streams(&colour, &luma, STDOUT_FILENO, "<stdout>", process); return 0; } |
