1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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, "<stdout>");
return 0;
}
|