ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/slide.c
Revision: 1.2
Committed: Thu Feb 2 14:10:41 1989 UTC (35 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +3 -1 lines
Log Message:
Fixed SCCSid

File Contents

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