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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "libcolour.h"
#define TYPE_COLOUR libcolour_colour_llf_t
#define TYPE_PRINTF ".10Lf"
#define TYPE_STRTOD strtold
const char *argv0;
static void
get_colour_space(char ***argvp, TYPE_COLOUR *cs)
{
#define argv (*argvp)
if (!strcasecmp(*argv, "srgb")) {
argv++;
cs->model = LIBCOLOUR_SRGB;
if (!*argv || !**argv) exit(2);
cs->srgb.with_transfer = !!strchr("yYtT", **argv);
argv++;
} else if (!strcasecmp(*argv, "xyy") || !strcasecmp(*argv, "ciexyy")) {
argv++;
cs->model = LIBCOLOUR_CIEXYY;
} else if (!strcasecmp(*argv, "xyz") || !strcasecmp(*argv, "ciexyz")) {
argv++;
cs->model = LIBCOLOUR_CIEXYZ;
} else if (!strcasecmp(*argv, "lab") || !strcasecmp(*argv, "cielab")) {
argv++;
cs->model = LIBCOLOUR_CIELAB;
} else if (!strcasecmp(*argv, "yiq")) {
argv++;
cs->model = LIBCOLOUR_YIQ;
} else if (!strcasecmp(*argv, "ydbdr")) {
argv++;
cs->model = LIBCOLOUR_YDBDR;
} else if (!strcasecmp(*argv, "yuv")) {
argv++;
cs->model = LIBCOLOUR_YUV;
} else if (!strcasecmp(*argv, "ypbpr")) {
argv++;
cs->model = LIBCOLOUR_YPBPR;
} else if (!strcasecmp(*argv, "ycgco")) {
argv++;
cs->model = LIBCOLOUR_YCGCO;
} else if (!strcasecmp(*argv, "cie1960ucs") || !strcasecmp(*argv, "cieucs") || !strcasecmp(*argv, "ucs")) {
argv++;
cs->model = LIBCOLOUR_CIE1960UCS;
} else if (!strcasecmp(*argv, "cieuvw") || !strcasecmp(*argv, "uvw")) {
argv++;
cs->model = LIBCOLOUR_CIEUVW;
if (!*argv) exit(2);
cs->cieuvw.u0 = TYPE_STRTOD(*argv++, NULL);
if (!*argv) exit(2);
cs->cieuvw.v0 = TYPE_STRTOD(*argv++, NULL);
} else if (!strcasecmp(*argv, "cieluv") || !strcasecmp(*argv, "luv")) {
argv++;
cs->model = LIBCOLOUR_CIELUV;
cs->cieluv.white.model = LIBCOLOUR_CIEXYZ;
if (!*argv) exit(2);
cs->cieluv.white.X = TYPE_STRTOD(*argv++, NULL);
if (!*argv) exit(2);
cs->cieluv.white.Y = TYPE_STRTOD(*argv++, NULL);
if (!*argv) exit(2);
cs->cieluv.white.Z = TYPE_STRTOD(*argv++, NULL);
} else if (!strcasecmp(*argv, "cielchuv") || !strcasecmp(*argv, "lchuv")) {
argv++;
cs->model = LIBCOLOUR_CIELCHUV;
cs->cielchuv.white.model = LIBCOLOUR_CIEXYZ;
if (!*argv) exit(2);
cs->cielchuv.white.X = TYPE_STRTOD(*argv++, NULL);
if (!*argv) exit(2);
cs->cielchuv.white.Y = TYPE_STRTOD(*argv++, NULL);
if (!*argv) exit(2);
cs->cielchuv.white.Z = TYPE_STRTOD(*argv++, NULL);
if (!*argv) exit(2);
cs->cielchuv.one_revolution = TYPE_STRTOD(*argv++, NULL);
} else if (!strcasecmp(*argv, "yes")) {
argv++;
cs->model = LIBCOLOUR_YES;
}
#undef argv
}
int
main(int argc, char *argv[])
{
TYPE_COLOUR from, to;
if (!*argv) return 2;
argv0 = *argv++;
if (!*argv) return 2;
get_colour_space(&argv, &from);
if (!*argv) return 2;
from.srgb.R = TYPE_STRTOD(*argv++, NULL);
if (!*argv) return 2;
from.srgb.G = TYPE_STRTOD(*argv++, NULL);
if (!*argv) return 2;
from.srgb.B = TYPE_STRTOD(*argv++, NULL);
if (!*argv) return 2;
get_colour_space(&argv, &to);
if (*argv) return 2;
if (libcolour_convert(&from, &to)) return 1;
printf("%"TYPE_PRINTF" %"TYPE_PRINTF" %"TYPE_PRINTF"\n", to.srgb.R, to.srgb.G, to.srgb.B);
fflush(stdout);
if (ferror(stdout))
return 2;
return 0;
(void) argc;
}
|