ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/greyscale.c
Revision: 2.1
Committed: Tue Nov 12 16:05:23 1991 UTC (32 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +0 -0 lines
Log Message:
updated revision number for release 2.0

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