From 76cdf509b36bb0012cde9bc1760cdf3b26874af2 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 9 Jan 2017 03:51:26 +0100 Subject: Use CIE XYZ instead of sRGB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/vu-colour-srgb.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/vu-colour-srgb.c (limited to 'src/vu-colour-srgb.c') diff --git a/src/vu-colour-srgb.c b/src/vu-colour-srgb.c new file mode 100644 index 0000000..164c6ae --- /dev/null +++ b/src/vu-colour-srgb.c @@ -0,0 +1,57 @@ +/* See LICENSE file for copyright and license details. */ +#include "arg.h" +#include "util.h" + +static void +usage(void) +{ + eprintf("usage: %s [-d depth] [-l] red green blue\n", argv0); +} + +int +main(int argc, char *argv[]) +{ + unsigned long long int max; + double red, green, blue, X, Y, Z; + int depth = 8; + int linear = 0; + + ARGBEGIN { + case 'd': + if (toi(EARGF(usage()), 1, 64, &depth)) + eprintf("argument of -d must be an integer in [1, 64]\n"); + break; + case 'l': + linear = 1; + break; + default: + usage(); + } ARGEND; + + if (argc != 3) + usage(); + + if (tolf(argv[0], &red)) + eprintf("the X value must be a floating-point value\n"); + if (tolf(argv[1], &green)) + eprintf("the Y value must be a floating-point value\n"); + if (tolf(argv[2], &blue)) + eprintf("the Z value must be a floating-point value\n"); + + max = 1ULL << (depth - 1); + max |= max - 1; + red /= max; + green /= max; + blue /= max; + if (!linear) { + red = srgb_decode(red); + green = srgb_decode(green); + blue = srgb_decode(blue); + } + + srgb_to_ciexyz(red, green, blue, &X, &Y, &Z); + printf("%lf %lf %lf\n", X, Y, Z); + efshut(stdout, ""); + + return 0; +} -- cgit v1.2.3-70-g09d2