ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/greyscale.c
Revision: 2.5
Committed: Sun Jun 4 08:27:43 1995 UTC (28 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.4: +0 -1 lines
Log Message:
removed unnecessary redeclaration of exp()

File Contents

# User Rev Content
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     COLOR col1, col2, scanline[512];
66     double x;
67     int j;
68     register int i, k;
69    
70     for (j = 0; j < 512; j += 32) {
71     for (k = 0; k < 512; k++)
72     setcolor(scanline[k], 0.0, 0.0, 0.0);
73     for (k = 0; k < 4; k++)
74     if (fwritescan(scanline, 512, stdout) < 0)
75     goto writerr;
76     x = j/32 / 16.0;
77     if (minlog != 0.0)
78     x = exp((1.0-x)*minlog);
79     setcolor(col1, x, x, x);
80    
81     for (i = 0; i < 512; i += 32) {
82     for (k = 0; k < 4; k++)
83     setcolor(scanline[i+k], 0.0, 0.0, 0.0);
84     x = i/32 / 255.0;
85     if (minlog != 0.0) {
86     x = exp(-x*minlog);
87     setcolor(col2, x, x, x);
88     multcolor(col2, col1);
89     } else {
90     setcolor(col2, x, x, x);
91     addcolor(col2, col1);
92     }
93     multcolor(col2, col0);
94     for (k = 4; k < 32; k++)
95     copycolor(scanline[i+k], col2);
96     }
97     for (i = 0; i < 28; i++)
98     if (fwritescan(scanline, 512, stdout) < 0)
99     goto writerr;
100     }
101     return;
102     writerr:
103     fprintf(stderr, "write error in greyscale\n");
104     exit(1);
105     }
106    
107    
108     printargs(ac, av, fp) /* print arguments to a file */
109     int ac;
110     char **av;
111     FILE *fp;
112     {
113     while (ac-- > 0) {
114     fputs(*av++, fp);
115     putc(' ', fp);
116     }
117     putc('\n', fp);
118     }