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