1 |
greg |
1.1 |
#ifndef lint |
2 |
schorsch |
2.7 |
static const char RCSid[] = "$Id: greyscale.c,v 2.6 2003/02/22 02:07:27 greg Exp $"; |
3 |
greg |
1.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* greyscale.c - program to produce grey test levels. |
6 |
|
|
* |
7 |
|
|
* 4/21/86 |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
#include <stdio.h> |
11 |
|
|
|
12 |
greg |
2.3 |
#include <math.h> |
13 |
|
|
|
14 |
greg |
1.1 |
#include "color.h" |
15 |
|
|
|
16 |
|
|
|
17 |
|
|
double minlog = 0.0; /* minimum for log scale (0 == linear) */ |
18 |
|
|
|
19 |
schorsch |
2.7 |
static void greyscale(COLOR col0); |
20 |
|
|
static void printargs(int ac, char **av, FILE *fp); |
21 |
greg |
1.1 |
|
22 |
schorsch |
2.7 |
|
23 |
|
|
int |
24 |
|
|
main( |
25 |
|
|
int argc, |
26 |
|
|
char *argv[] |
27 |
|
|
) |
28 |
greg |
1.1 |
{ |
29 |
|
|
COLOR col; |
30 |
greg |
2.3 |
double d1,d2,d3; |
31 |
greg |
1.1 |
int i; |
32 |
|
|
|
33 |
|
|
printargs(argc, argv, stdout); |
34 |
|
|
|
35 |
|
|
setcolor(col, 1.0, 1.0, 1.0); |
36 |
|
|
|
37 |
|
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
38 |
|
|
switch (argv[i][1]) { |
39 |
|
|
case 'c': |
40 |
|
|
d1 = atof(argv[++i]); |
41 |
|
|
d2 = atof(argv[++i]); |
42 |
|
|
d3 = atof(argv[++i]); |
43 |
|
|
setcolor(col, d1, d2, d3); |
44 |
|
|
break; |
45 |
|
|
case 'l': |
46 |
|
|
d1 = atof(argv[++i]); |
47 |
|
|
if (d1 <= 0.0) |
48 |
|
|
minlog = 0.0; |
49 |
|
|
else |
50 |
|
|
minlog = log(d1); |
51 |
|
|
break; |
52 |
|
|
default: |
53 |
|
|
fprintf(stderr, "%s: unknown option \"%s\"\n", |
54 |
|
|
argv[0], argv[i]); |
55 |
|
|
exit(1); |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
printf("\n"); |
59 |
|
|
printf("-Y 512 +X 512\n"); |
60 |
|
|
greyscale(col); |
61 |
schorsch |
2.7 |
return 0; |
62 |
greg |
1.1 |
} |
63 |
|
|
|
64 |
|
|
|
65 |
schorsch |
2.7 |
static void |
66 |
|
|
greyscale( /* output our grey scale */ |
67 |
|
|
COLOR col0 |
68 |
|
|
) |
69 |
greg |
1.1 |
{ |
70 |
|
|
COLOR col1, col2, scanline[512]; |
71 |
|
|
double x; |
72 |
|
|
int j; |
73 |
|
|
register int i, k; |
74 |
|
|
|
75 |
|
|
for (j = 0; j < 512; j += 32) { |
76 |
|
|
for (k = 0; k < 512; k++) |
77 |
|
|
setcolor(scanline[k], 0.0, 0.0, 0.0); |
78 |
|
|
for (k = 0; k < 4; k++) |
79 |
|
|
if (fwritescan(scanline, 512, stdout) < 0) |
80 |
|
|
goto writerr; |
81 |
|
|
x = j/32 / 16.0; |
82 |
|
|
if (minlog != 0.0) |
83 |
|
|
x = exp((1.0-x)*minlog); |
84 |
|
|
setcolor(col1, x, x, x); |
85 |
|
|
|
86 |
|
|
for (i = 0; i < 512; i += 32) { |
87 |
|
|
for (k = 0; k < 4; k++) |
88 |
|
|
setcolor(scanline[i+k], 0.0, 0.0, 0.0); |
89 |
|
|
x = i/32 / 255.0; |
90 |
|
|
if (minlog != 0.0) { |
91 |
|
|
x = exp(-x*minlog); |
92 |
|
|
setcolor(col2, x, x, x); |
93 |
|
|
multcolor(col2, col1); |
94 |
|
|
} else { |
95 |
|
|
setcolor(col2, x, x, x); |
96 |
|
|
addcolor(col2, col1); |
97 |
|
|
} |
98 |
|
|
multcolor(col2, col0); |
99 |
|
|
for (k = 4; k < 32; k++) |
100 |
|
|
copycolor(scanline[i+k], col2); |
101 |
|
|
} |
102 |
|
|
for (i = 0; i < 28; i++) |
103 |
|
|
if (fwritescan(scanline, 512, stdout) < 0) |
104 |
|
|
goto writerr; |
105 |
|
|
} |
106 |
|
|
return; |
107 |
|
|
writerr: |
108 |
|
|
fprintf(stderr, "write error in greyscale\n"); |
109 |
|
|
exit(1); |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
|
113 |
schorsch |
2.7 |
static void |
114 |
|
|
printargs( /* print arguments to a file */ |
115 |
|
|
int ac, |
116 |
|
|
char **av, |
117 |
|
|
FILE *fp |
118 |
|
|
) |
119 |
greg |
1.1 |
{ |
120 |
|
|
while (ac-- > 0) { |
121 |
|
|
fputs(*av++, fp); |
122 |
|
|
putc(' ', fp); |
123 |
|
|
} |
124 |
|
|
putc('\n', fp); |
125 |
|
|
} |