-
Notifications
You must be signed in to change notification settings - Fork 5
/
palette.c
75 lines (66 loc) · 1.89 KB
/
palette.c
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
#include<stdio.h>
struct color {
double r, g, b;
} out[65536];
struct interp {
double pos;
double r, g, b;
};
struct interp jet[] = {
{ 0.000, 0.0, 0.0, 0.5 },
{ 1./8., 0.0, 0.0, 1.0 },
{ 2./8., 0.0, 0.5, 1.0 },
{ 3./8., 0.0, 1.0, 1.0 },
{ 4./8., 0.5, 1.0, 0.5 },
{ 5./8., 1.0, 1.0, 0.0 },
{ 6./8., 1.0, 0.5, 0.0 },
{ 7./8., 1.0, 0.0, 0.0 },
{ 1.000, 0.5, 0.0, 0.0 },
};
struct interp cool[] = {
{ 0.000, 0.0, 1.0, 1.0 },
{ 1.000, 1.0, 0.0, 1.0 },
};
struct interp hot[] = {
{ 0.000, 0.0, 0.0, 0.0 },
{ 1./3., 1.0, 0.0, 0.0 },
{ 2./3., 1.0, 1.0, 0.0 },
{ 1.000, 1.0, 1.0, 1.0 },
};
struct interp hsv[] = {
{ 0.000, 1.0, 0.0, 0.0 },
{ 1./6., 1.0, 1.0, 0.0 },
{ 2./6., 0.0, 1.0, 0.0 },
{ 3./6., 0.0, 1.0, 1.0 },
{ 4./6., 0.0, 0.0, 1.0 },
{ 5./6., 1.0, 0.0, 1.0 },
{ 1.000, 1.0, 0.0, 0.0 },
};
void do_interp(struct interp *interp, char *file, int len)
{
int i, p;
double f;
FILE *fp = fopen(file, "w");
for (i = 0, p = 0; i <= len; i++) {
if (i >= interp[p].pos * len)
p++;
f = ((double) i) / len;
out[i].r = (interp[p-1].r + (interp[p].r - interp[p-1].r) * (f - interp[p-1].pos) /
(interp[p].pos - interp[p-1].pos));
out[i].g = (interp[p-1].g + (interp[p].g - interp[p-1].g) * (f - interp[p-1].pos) /
(interp[p].pos - interp[p-1].pos));
out[i].b = (interp[p-1].b + (interp[p].b - interp[p-1].b) * (f - interp[p-1].pos) /
(interp[p].pos - interp[p-1].pos));
}
for (i = 0; i <= len; i++) {
fprintf(fp, " %13.7e %13.7e %13.7e\n", out[i].r, out[i].g, out[i].b);
}
fclose(fp);
}
int main(int argc, char **argv)
{
do_interp(jet, "jet.txt", 65535);
do_interp(cool, "cool.txt", 65535);
do_interp(hot, "hot.txt", 65535);
do_interp(hsv, "hsv.txt", 65535);
}