ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/slide.c
Revision: 1.1
Committed: Thu Feb 2 10:49:39 1989 UTC (35 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

# User Rev Content
1 greg 1.1 /*
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6     * slide.c - driver for dicomed film recorder using GRAFPAC under VMS.
7     *
8     * 2/19/86
9     *
10     * Version for color slide ouput.
11     * Link with grafpac driver "DS":
12     * link slide.obj,color.obj,sys_grafpac:ds/lib
13     */
14    
15     #include <stdio.h>
16    
17     #include "color.h"
18    
19     #include "random.h"
20    
21    
22     #define XSIZE 4096 /* device width */
23     #define YSIZE 4096 /* device length */
24    
25     #define NCOLS 4018 /* maximum # columns for output */
26     #define NROWS 2712 /* maximum # rows for output */
27    
28     #define XCENTER 2048 /* center for x */
29     #define YCENTER 2048 /* center for y */
30    
31     int nrows; /* number of rows for output */
32     int ncols; /* number of columns for output */
33    
34     int xoffset; /* offset for x */
35     int yoffset; /* offset for y */
36    
37     #define RSIZ 17 /* size of response map */
38    
39     float rmap[2*RSIZ] = { /* response map */
40     .0, .0,
41     .0004, .059,
42     .0008, .122,
43     .0018, .184,
44     .0033, .247,
45     .0061, .310,
46     .0119, .373,
47     .0202, .435,
48     .0373, .498,
49     .065, .561,
50     .113, .624,
51     .199, .686,
52     .300, .749,
53     .432, .812,
54     .596, .875,
55     .767, .937,
56     1.000, 1.000,
57     };
58    
59    
60     main(argc, argv)
61     int argc;
62     char **argv;
63     {
64     extern char *malloc();
65     FILE *fin;
66     COLOR scanline[NCOLS];
67     int mult;
68     char sbuf[128];
69     int i, j;
70    
71     /*
72     for (i = 1; i < argc; i++)
73     if (argv[i][0] == '-')
74     switch (argv[i][1]) {
75     default:
76     fprintf(stderr, "unknown option: %s\n", argv[i]);
77     exit(1);
78     break;
79     }
80     else
81     break;
82    
83     */
84     argc = 2;
85     argv[1] = "pixfile";
86     i = 1;
87    
88     if (argc - i < 1)
89     fin = 0;
90     else if ((fin = fopen(argv[i], "r")) == NULL) {
91     fprintf(stderr, "%s: can't open file \"%s\"\n",
92     argv[0], argv[i]);
93     exit(1);
94     }
95    
96     /* discard header */
97     while (fgets(sbuf, sizeof(sbuf), fin) != NULL && sbuf[0] != '\n')
98     ;
99     /* get picture size */
100     if (fgets(sbuf, sizeof(sbuf), fin) == NULL ||
101     sscanf(sbuf, "-Y %d +X %d\n", &nrows, &ncols) != 2) {
102     fprintf(stderr, "%s: bad picture size\n", argv[0]);
103     exit(1);
104     }
105    
106     if (ncols > NCOLS || nrows > NROWS) {
107     fprintf(stderr, "%s: resolution mismatch\n", argv[0]);
108     exit(1);
109     }
110    
111     mult = NCOLS/ncols;
112     if (NROWS/nrows < mult)
113     mult = NROWS/nrows;
114    
115     xoffset = XCENTER/mult - ncols/2;
116     yoffset = YCENTER/mult - nrows/2;
117    
118     tvinit();
119     i = XSIZE/mult; j = YSIZE/mult; tvvrs(&i, &j);
120     i = 12; tvset("ifile", &i);
121     tvset("nrco", "rgb");
122    
123     for (i = nrows-1; i >= 0; i--) {
124     if (freadscan(scanline, ncols, fin) < 0) {
125     fprintf(stderr, "%s: read error in row %d\n",
126     argv[0], i);
127     exit(1);
128     }
129     scanout(scanline, i);
130     }
131    
132     tvsend();
133     tvend();
134    
135     return(0);
136     }
137    
138    
139     scanout(scan, y) /* output scan line */
140     register COLOR *scan;
141     int y;
142     {
143     static int zero;
144     static float rgb[3][NCOLS];
145     int i;
146     register int j;
147    
148     zero = xoffset;
149     y += yoffset;
150    
151     for (j = 0; j < ncols; j++) {
152     mapcolor(scan[j], scan[j]);
153     for (i = 0; i < 3; i++)
154     rgb[i][j] = scan[j][i] + (.5-frandom())/255.0;
155     }
156     tvrstc(&zero, &y, rgb[0], rgb[1], rgb[2], &ncols);
157     }
158    
159    
160     mapcolor(c1, c2) /* map c1 into c2 */
161     register COLOR c1;
162     COLOR c2;
163     {
164     static float *mp[3] = {rmap, rmap, rmap};
165     double x;
166     register int i;
167    
168     for (i = 0; i < 3; i++) {
169     if (colval(c1,i) >= 1.0) {
170     colval(c2,i) = 1.0;
171     continue;
172     }
173     while (colval(c1,i) >= mp[i][2])
174     mp[i] += 2;
175     while (colval(c1,i) < mp[i][0])
176     mp[i] -= 2;
177     x = (colval(c1,i) - mp[i][0]) / (mp[i][2] - mp[i][0]);
178     colval(c2,i) = (1.0-x)*mp[i][1] + x*mp[i][3];
179     }
180     }