1 |
greg |
1.1 |
/* Copyright (c) 1987 Regents of the University of California */ |
2 |
|
|
|
3 |
|
|
#ifndef lint |
4 |
|
|
static char SCCSid[] = "$SunId$ LBL"; |
5 |
|
|
#endif |
6 |
|
|
|
7 |
|
|
/* |
8 |
|
|
* colorscale.c - program to produce color pallets |
9 |
|
|
* |
10 |
|
|
* 9/9/87 |
11 |
|
|
*/ |
12 |
|
|
|
13 |
|
|
#include <stdio.h> |
14 |
|
|
|
15 |
greg |
2.3 |
#include <math.h> |
16 |
|
|
|
17 |
greg |
1.1 |
#include "color.h" |
18 |
|
|
|
19 |
|
|
int primary = -1; |
20 |
|
|
double prival = 0.0; |
21 |
|
|
|
22 |
|
|
|
23 |
|
|
main(argc, argv) |
24 |
|
|
int argc; |
25 |
|
|
char *argv[]; |
26 |
|
|
{ |
27 |
|
|
int i; |
28 |
|
|
|
29 |
|
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
30 |
|
|
switch (argv[i][1]) { |
31 |
|
|
case 'r': |
32 |
|
|
primary = RED; |
33 |
|
|
prival = atof(argv[++i]); |
34 |
|
|
break; |
35 |
|
|
case 'g': |
36 |
|
|
primary = GRN; |
37 |
|
|
prival = atof(argv[++i]); |
38 |
|
|
break; |
39 |
|
|
case 'b': |
40 |
|
|
primary = BLU; |
41 |
|
|
prival = atof(argv[++i]); |
42 |
|
|
break; |
43 |
|
|
default: |
44 |
|
|
goto userr; |
45 |
|
|
} |
46 |
|
|
if (primary < 0 || i < argc) |
47 |
|
|
goto userr; |
48 |
|
|
printargs(argc, argv, stdout); |
49 |
|
|
printf("\n"); |
50 |
|
|
printf("-Y 256 +X 256\n"); |
51 |
|
|
colorscale(); |
52 |
|
|
exit(0); |
53 |
|
|
userr: |
54 |
|
|
fprintf(stderr, "Usage: %s -r|-g|-b value\n", argv[0]); |
55 |
|
|
exit(1); |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
|
59 |
|
|
colorscale() /* output our color scale */ |
60 |
|
|
{ |
61 |
|
|
COLOR scanline[256]; |
62 |
|
|
int j; |
63 |
|
|
register int i; |
64 |
|
|
|
65 |
|
|
for (j = 256-1; j >= 0; j--) { |
66 |
|
|
for (i = 0; i < 256; i++) |
67 |
|
|
switch (primary) { |
68 |
|
|
case RED: |
69 |
|
|
setcolor(scanline[i],prival,i/256.0,j/256.0); |
70 |
|
|
break; |
71 |
|
|
case GRN: |
72 |
|
|
setcolor(scanline[i],i/256.0,prival,j/256.0); |
73 |
|
|
break; |
74 |
|
|
case BLU: |
75 |
|
|
setcolor(scanline[i],i/256.0,j/256.0,prival); |
76 |
|
|
break; |
77 |
|
|
} |
78 |
|
|
if (fwritescan(scanline, 256, stdout) < 0) |
79 |
|
|
goto writerr; |
80 |
|
|
} |
81 |
|
|
return; |
82 |
|
|
writerr: |
83 |
|
|
fprintf(stderr, "write error in colorscale\n"); |
84 |
|
|
exit(1); |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
|
88 |
|
|
printargs(ac, av, fp) /* print arguments to a file */ |
89 |
|
|
int ac; |
90 |
|
|
char **av; |
91 |
|
|
FILE *fp; |
92 |
|
|
{ |
93 |
|
|
while (ac-- > 0) { |
94 |
|
|
fputs(*av++, fp); |
95 |
|
|
putc(' ', fp); |
96 |
|
|
} |
97 |
|
|
putc('\n', fp); |
98 |
|
|
} |