ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/greyscale.c
Revision: 2.6
Committed: Sat Feb 22 02:07:27 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.5: +1 -4 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

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