1 |
– |
/* Copyright (c) 1987 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* rv2.c - command routines used in tracing a view. |
6 |
|
* |
7 |
< |
* 3/24/87 |
7 |
> |
* External symbols declared in rpaint.h |
8 |
|
*/ |
9 |
|
|
10 |
< |
#include "ray.h" |
10 |
> |
#include "copyright.h" |
11 |
|
|
12 |
< |
#include "octree.h" |
12 |
> |
#include <ctype.h> |
13 |
> |
#include <string.h> |
14 |
|
|
15 |
+ |
#include "platform.h" |
16 |
+ |
#include "rtprocess.h" /* win_popen() */ |
17 |
+ |
#include "paths.h" |
18 |
+ |
#include "ray.h" |
19 |
+ |
#include "source.h" |
20 |
+ |
#include "ambient.h" |
21 |
|
#include "otypes.h" |
18 |
– |
|
22 |
|
#include "rpaint.h" |
23 |
|
|
24 |
< |
#include <ctype.h> |
24 |
> |
extern int psample; /* pixel sample size */ |
25 |
> |
extern double maxdiff; /* max. sample difference */ |
26 |
|
|
27 |
< |
#define CTRL(c) ('c'-'@') |
27 |
> |
#define CTRL(c) ((c)-'@') |
28 |
|
|
29 |
+ |
#ifdef SMLFLT |
30 |
+ |
#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) |
31 |
+ |
#else |
32 |
+ |
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
33 |
+ |
#endif |
34 |
+ |
|
35 |
+ |
extern char rifname[128]; /* rad input file name */ |
36 |
+ |
|
37 |
|
extern char *progname; |
38 |
+ |
extern char *octname; |
39 |
|
|
40 |
|
|
41 |
< |
getframe(s) /* get a new frame */ |
42 |
< |
char *s; |
41 |
> |
void |
42 |
> |
getframe( /* get a new frame */ |
43 |
> |
char *s |
44 |
> |
) |
45 |
|
{ |
46 |
|
if (getrect(s, &pframe) < 0) |
47 |
|
return; |
49 |
|
} |
50 |
|
|
51 |
|
|
52 |
< |
getrepaint(s) /* get area and repaint */ |
53 |
< |
char *s; |
52 |
> |
void |
53 |
> |
getrepaint( /* get area and repaint */ |
54 |
> |
char *s |
55 |
> |
) |
56 |
|
{ |
57 |
|
RECT box; |
58 |
|
|
59 |
|
if (getrect(s, &box) < 0) |
60 |
|
return; |
61 |
< |
paintrect(&ptrunk, 0, 0, hresolu, vresolu, &box); |
61 |
> |
paintrect(&ptrunk, &box); |
62 |
|
} |
63 |
|
|
64 |
|
|
65 |
< |
getview(s) /* get/show view parameters */ |
66 |
< |
char *s; |
65 |
> |
void |
66 |
> |
getview( /* get/show/save view parameters */ |
67 |
> |
char *s |
68 |
> |
) |
69 |
|
{ |
70 |
|
FILE *fp; |
71 |
|
char buf[128]; |
72 |
|
char *fname; |
73 |
|
int change = 0; |
74 |
< |
VIEW nv; |
74 |
> |
VIEW nv = ourview; |
75 |
|
|
76 |
< |
if (sscanf(s, "%s", buf) == 1) { /* write parameters to a file */ |
76 |
> |
while (isspace(*s)) |
77 |
> |
s++; |
78 |
> |
if (*s == '-') { /* command line parameters */ |
79 |
> |
if (sscanview(&nv, s)) |
80 |
> |
newview(&nv); |
81 |
> |
else |
82 |
> |
error(COMMAND, "bad view option(s)"); |
83 |
> |
return; |
84 |
> |
} |
85 |
> |
if (nextword(buf, sizeof(buf), s) != NULL) { /* write to a file */ |
86 |
|
if ((fname = getpath(buf, NULL, 0)) == NULL || |
87 |
|
(fp = fopen(fname, "a")) == NULL) { |
88 |
|
sprintf(errmsg, "cannot open \"%s\"", buf); |
92 |
|
fputs(progname, fp); |
93 |
|
fprintview(&ourview, fp); |
94 |
|
fputs(sskip(s), fp); |
95 |
< |
fputs("\n", fp); |
95 |
> |
putc('\n', fp); |
96 |
|
fclose(fp); |
97 |
|
return; |
98 |
|
} |
99 |
|
sprintf(buf, "view type (%c): ", ourview.type); |
100 |
|
(*dev->comout)(buf); |
101 |
|
(*dev->comin)(buf, NULL); |
102 |
< |
if (buf[0] == CTRL(C)) return; |
102 |
> |
if (buf[0] == CTRL('C')) return; |
103 |
|
if (buf[0] && buf[0] != ourview.type) { |
104 |
|
nv.type = buf[0]; |
105 |
|
change++; |
106 |
< |
} else |
79 |
< |
nv.type = ourview.type; |
106 |
> |
} |
107 |
|
sprintf(buf, "view point (%.6g %.6g %.6g): ", |
108 |
|
ourview.vp[0], ourview.vp[1], ourview.vp[2]); |
109 |
|
(*dev->comout)(buf); |
110 |
|
(*dev->comin)(buf, NULL); |
111 |
< |
if (buf[0] == CTRL(C)) return; |
112 |
< |
if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3) |
111 |
> |
if (buf[0] == CTRL('C')) return; |
112 |
> |
if (sscanvec(buf, nv.vp)) |
113 |
|
change++; |
87 |
– |
else |
88 |
– |
VCOPY(nv.vp, ourview.vp); |
114 |
|
sprintf(buf, "view direction (%.6g %.6g %.6g): ", |
115 |
< |
ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]); |
115 |
> |
ourview.vdir[0]*ourview.vdist, |
116 |
> |
ourview.vdir[1]*ourview.vdist, |
117 |
> |
ourview.vdir[2]*ourview.vdist); |
118 |
|
(*dev->comout)(buf); |
119 |
|
(*dev->comin)(buf, NULL); |
120 |
< |
if (buf[0] == CTRL(C)) return; |
121 |
< |
if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3) |
120 |
> |
if (buf[0] == CTRL('C')) return; |
121 |
> |
if (sscanvec(buf, nv.vdir)) { |
122 |
> |
nv.vdist = 1.; |
123 |
|
change++; |
124 |
< |
else |
97 |
< |
VCOPY(nv.vdir, ourview.vdir); |
124 |
> |
} |
125 |
|
sprintf(buf, "view up (%.6g %.6g %.6g): ", |
126 |
|
ourview.vup[0], ourview.vup[1], ourview.vup[2]); |
127 |
|
(*dev->comout)(buf); |
128 |
|
(*dev->comin)(buf, NULL); |
129 |
< |
if (buf[0] == CTRL(C)) return; |
130 |
< |
if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3) |
129 |
> |
if (buf[0] == CTRL('C')) return; |
130 |
> |
if (sscanvec(buf, nv.vup)) |
131 |
|
change++; |
105 |
– |
else |
106 |
– |
VCOPY(nv.vup, ourview.vup); |
132 |
|
sprintf(buf, "view horiz and vert size (%.6g %.6g): ", |
133 |
|
ourview.horiz, ourview.vert); |
134 |
|
(*dev->comout)(buf); |
135 |
|
(*dev->comin)(buf, NULL); |
136 |
< |
if (buf[0] == CTRL(C)) return; |
136 |
> |
if (buf[0] == CTRL('C')) return; |
137 |
|
if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2) |
138 |
|
change++; |
139 |
< |
else { |
140 |
< |
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
141 |
< |
} |
139 |
> |
sprintf(buf, "fore and aft clipping plane (%.6g %.6g): ", |
140 |
> |
ourview.vfore, ourview.vaft); |
141 |
> |
(*dev->comout)(buf); |
142 |
> |
(*dev->comin)(buf, NULL); |
143 |
> |
if (buf[0] == CTRL('C')) return; |
144 |
> |
if (sscanf(buf, "%lf %lf", &nv.vfore, &nv.vaft) == 2) |
145 |
> |
change++; |
146 |
|
sprintf(buf, "view shift and lift (%.6g %.6g): ", |
147 |
|
ourview.hoff, ourview.voff); |
148 |
|
(*dev->comout)(buf); |
149 |
|
(*dev->comin)(buf, NULL); |
150 |
< |
if (buf[0] == CTRL(C)) return; |
150 |
> |
if (buf[0] == CTRL('C')) return; |
151 |
|
if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2) |
152 |
|
change++; |
124 |
– |
else { |
125 |
– |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
126 |
– |
} |
153 |
|
if (change) |
154 |
|
newview(&nv); |
155 |
|
} |
156 |
|
|
157 |
|
|
158 |
< |
lastview(s) /* return to a previous view */ |
159 |
< |
char *s; |
158 |
> |
void |
159 |
> |
lastview( /* return to a previous view */ |
160 |
> |
char *s |
161 |
> |
) |
162 |
|
{ |
163 |
|
char buf[128]; |
164 |
|
char *fname; |
165 |
|
int success; |
166 |
|
VIEW nv; |
167 |
< |
|
168 |
< |
if (sscanf(s, "%s", buf) == 1) { /* get parameters from a file */ |
169 |
< |
copystruct(&nv, &stdview); |
170 |
< |
if ((fname = getpath(buf, NULL, 0)) == NULL || |
171 |
< |
(success = viewfile(fname, &nv, 0, 0)) == -1) { |
167 |
> |
/* get parameters from a file */ |
168 |
> |
if (nextword(buf, sizeof(buf), s) != NULL) { |
169 |
> |
nv = stdview; |
170 |
> |
if ((fname = getpath(buf, "", R_OK)) == NULL || |
171 |
> |
(success = viewfile(fname, &nv, NULL)) == -1) { |
172 |
|
sprintf(errmsg, "cannot open \"%s\"", buf); |
173 |
|
error(COMMAND, errmsg); |
174 |
|
return; |
179 |
|
newview(&nv); |
180 |
|
return; |
181 |
|
} |
182 |
< |
if (oldview.horiz == 0) { /* no old view! */ |
182 |
> |
if (oldview.type == 0) { /* no old view! */ |
183 |
|
error(COMMAND, "no previous view"); |
184 |
|
return; |
185 |
|
} |
186 |
< |
copystruct(&nv, &ourview); |
187 |
< |
copystruct(&ourview, &oldview); |
188 |
< |
copystruct(&oldview, &nv); |
189 |
< |
newimage(); |
186 |
> |
nv = ourview; |
187 |
> |
ourview = oldview; |
188 |
> |
oldview = nv; |
189 |
> |
newimage(NULL); |
190 |
|
} |
191 |
|
|
192 |
|
|
193 |
< |
getaim(s) /* aim camera */ |
194 |
< |
char *s; |
193 |
> |
void |
194 |
> |
saveview( /* save view to rad file */ |
195 |
> |
char *s |
196 |
> |
) |
197 |
|
{ |
198 |
< |
extern double tan(), atan(); |
199 |
< |
double zfact; |
198 |
> |
char view[64]; |
199 |
> |
char *fname; |
200 |
> |
FILE *fp; |
201 |
> |
|
202 |
> |
if (*atos(view, sizeof(view), s)) { |
203 |
> |
if (isint(view)) { |
204 |
> |
error(COMMAND, "cannot write view by number"); |
205 |
> |
return; |
206 |
> |
} |
207 |
> |
s = sskip(s); |
208 |
> |
} |
209 |
> |
if (nextword(rifname, sizeof(rifname), s) == NULL && !rifname[0]) { |
210 |
> |
error(COMMAND, "no previous rad file"); |
211 |
> |
return; |
212 |
> |
} |
213 |
> |
if ((fname = getpath(rifname, NULL, 0)) == NULL || |
214 |
> |
(fp = fopen(fname, "a")) == NULL) { |
215 |
> |
sprintf(errmsg, "cannot open \"%s\"", rifname); |
216 |
> |
error(COMMAND, errmsg); |
217 |
> |
return; |
218 |
> |
} |
219 |
> |
fputs("view= ", fp); |
220 |
> |
fputs(view, fp); |
221 |
> |
fprintview(&ourview, fp); |
222 |
> |
putc('\n', fp); |
223 |
> |
fclose(fp); |
224 |
> |
} |
225 |
> |
|
226 |
> |
|
227 |
> |
void |
228 |
> |
loadview( /* load view from rad file */ |
229 |
> |
char *s |
230 |
> |
) |
231 |
> |
{ |
232 |
> |
char buf[512]; |
233 |
> |
char *fname; |
234 |
> |
FILE *fp; |
235 |
|
VIEW nv; |
236 |
|
|
237 |
< |
if (getinterest(s, 1, nv.vdir, &zfact) < 0) |
237 |
> |
strcpy(buf, "rad -n -s -V -v "); |
238 |
> |
if (sscanf(s, "%s", buf+strlen(buf)) == 1) |
239 |
> |
s = sskip(s); |
240 |
> |
else |
241 |
> |
strcat(buf, "1"); |
242 |
> |
if (nextword(rifname, sizeof(rifname), s) == NULL && !rifname[0]) { |
243 |
> |
error(COMMAND, "no previous rad file"); |
244 |
|
return; |
174 |
– |
VCOPY(nv.vp, ourview.vp); |
175 |
– |
VCOPY(nv.vup, ourview.vup); |
176 |
– |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
177 |
– |
if ((nv.type = ourview.type) == VT_PAR) { |
178 |
– |
nv.horiz = ourview.horiz / zfact; |
179 |
– |
nv.vert = ourview.vert / zfact; |
180 |
– |
} else { |
181 |
– |
nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) / |
182 |
– |
(PI/180./2.); |
183 |
– |
nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) / |
184 |
– |
(PI/180./2.); |
245 |
|
} |
246 |
+ |
if ((fname = getpath(rifname, "", R_OK)) == NULL) { |
247 |
+ |
sprintf(errmsg, "cannot access \"%s\"", rifname); |
248 |
+ |
error(COMMAND, errmsg); |
249 |
+ |
return; |
250 |
+ |
} |
251 |
+ |
sprintf(buf+strlen(buf), " %s", fname); |
252 |
+ |
if ((fp = popen(buf, "r")) == NULL) { |
253 |
+ |
error(COMMAND, "cannot run rad"); |
254 |
+ |
return; |
255 |
+ |
} |
256 |
+ |
buf[0] = '\0'; |
257 |
+ |
fgets(buf, sizeof(buf), fp); |
258 |
+ |
pclose(fp); |
259 |
+ |
nv = stdview; |
260 |
+ |
if (!sscanview(&nv, buf)) { |
261 |
+ |
error(COMMAND, "rad error -- no such view?"); |
262 |
+ |
return; |
263 |
+ |
} |
264 |
|
newview(&nv); |
265 |
|
} |
266 |
|
|
267 |
|
|
268 |
< |
getmove(s) /* move camera */ |
269 |
< |
char *s; |
268 |
> |
void |
269 |
> |
getaim( /* aim camera */ |
270 |
> |
char *s |
271 |
> |
) |
272 |
|
{ |
273 |
+ |
VIEW nv = ourview; |
274 |
+ |
double zfact; |
275 |
+ |
|
276 |
+ |
if (getinterest(s, 1, nv.vdir, &zfact) < 0) |
277 |
+ |
return; |
278 |
+ |
zoomview(&nv, zfact); |
279 |
+ |
newview(&nv); |
280 |
+ |
} |
281 |
+ |
|
282 |
+ |
|
283 |
+ |
void |
284 |
+ |
getfocus( /* set focus distance */ |
285 |
+ |
char *s |
286 |
+ |
) |
287 |
+ |
{ |
288 |
+ |
char buf[64]; |
289 |
+ |
double dist; |
290 |
+ |
|
291 |
+ |
if (sscanf(s, "%lf", &dist) < 1) { |
292 |
+ |
int x, y; |
293 |
+ |
RAY thisray; |
294 |
+ |
if (dev->getcur == NULL) |
295 |
+ |
return; |
296 |
+ |
(*dev->comout)("Pick focus point\n"); |
297 |
+ |
if ((*dev->getcur)(&x, &y) == ABORT) |
298 |
+ |
return; |
299 |
+ |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, |
300 |
+ |
&ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) { |
301 |
+ |
error(COMMAND, "not on image"); |
302 |
+ |
return; |
303 |
+ |
} |
304 |
+ |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
305 |
+ |
if (!localhit(&thisray, &thescene)) { |
306 |
+ |
error(COMMAND, "not a local object"); |
307 |
+ |
return; |
308 |
+ |
} |
309 |
+ |
dist = thisray.rot; |
310 |
+ |
} else if (dist <= .0) { |
311 |
+ |
error(COMMAND, "focus distance must be positive"); |
312 |
+ |
return; |
313 |
+ |
} |
314 |
+ |
ourview.vdist = dist; |
315 |
+ |
sprintf(buf, "Focus distance set to %f\n", dist); |
316 |
+ |
(*dev->comout)(buf); |
317 |
+ |
} |
318 |
+ |
|
319 |
+ |
|
320 |
+ |
void |
321 |
+ |
getmove( /* move camera */ |
322 |
+ |
char *s |
323 |
+ |
) |
324 |
+ |
{ |
325 |
|
FVECT vc; |
326 |
|
double mag; |
327 |
|
|
331 |
|
} |
332 |
|
|
333 |
|
|
334 |
< |
getrotate(s) /* rotate camera */ |
335 |
< |
char *s; |
334 |
> |
void |
335 |
> |
getrotate( /* rotate camera */ |
336 |
> |
char *s |
337 |
> |
) |
338 |
|
{ |
339 |
< |
extern double normalize(), tan(), atan(); |
206 |
< |
VIEW nv; |
207 |
< |
FVECT v1; |
339 |
> |
VIEW nv = ourview; |
340 |
|
double angle, elev, zfact; |
341 |
|
|
342 |
|
elev = 0.0; zfact = 1.0; |
344 |
|
error(COMMAND, "missing angle"); |
345 |
|
return; |
346 |
|
} |
215 |
– |
VCOPY(nv.vp, ourview.vp); |
216 |
– |
VCOPY(nv.vup, ourview.vup); |
217 |
– |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
347 |
|
spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); |
348 |
< |
if (elev != 0.0) { |
349 |
< |
fcross(v1, nv.vdir, ourview.vup); |
350 |
< |
normalize(v1); |
351 |
< |
spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); |
223 |
< |
} |
224 |
< |
if ((nv.type = ourview.type) == VT_PAR) { |
225 |
< |
nv.horiz = ourview.horiz / zfact; |
226 |
< |
nv.vert = ourview.vert / zfact; |
227 |
< |
} else { |
228 |
< |
nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) / |
229 |
< |
(PI/180./2.); |
230 |
< |
nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) / |
231 |
< |
(PI/180./2.); |
232 |
< |
} |
348 |
> |
if (elev != 0.0) |
349 |
> |
geodesic(nv.vdir, nv.vdir, nv.vup, elev*(PI/180.), GEOD_RAD); |
350 |
> |
|
351 |
> |
zoomview(&nv, zfact); |
352 |
|
newview(&nv); |
353 |
|
} |
354 |
|
|
355 |
|
|
356 |
< |
getpivot(s) /* pivot viewpoint */ |
357 |
< |
register char *s; |
356 |
> |
void |
357 |
> |
getpivot( /* pivot viewpoint */ |
358 |
> |
char *s |
359 |
> |
) |
360 |
|
{ |
361 |
|
FVECT vc; |
362 |
|
double angle, elev, mag; |
366 |
|
error(COMMAND, "missing angle"); |
367 |
|
return; |
368 |
|
} |
369 |
< |
if (getinterest(sskip(sskip(s)), 0, vc, &mag) < 0) |
369 |
> |
if (getinterest(sskip2(s,2), 0, vc, &mag) < 0) |
370 |
|
return; |
371 |
|
moveview(angle, elev, mag, vc); |
372 |
|
} |
373 |
|
|
374 |
|
|
375 |
< |
getexposure(s) /* get new exposure */ |
376 |
< |
char *s; |
375 |
> |
void |
376 |
> |
getexposure( /* get new exposure */ |
377 |
> |
char *s |
378 |
> |
) |
379 |
|
{ |
257 |
– |
double atof(), pow(), fabs(); |
380 |
|
char buf[128]; |
381 |
< |
register char *cp; |
260 |
< |
register PNODE *p; |
261 |
< |
RECT r; |
381 |
> |
char *cp; |
382 |
|
int x, y; |
383 |
< |
double e; |
383 |
> |
PNODE *p = &ptrunk; |
384 |
> |
int adapt = 0; |
385 |
> |
double e = 1.0; |
386 |
|
|
387 |
|
for (cp = s; isspace(*cp); cp++) |
388 |
|
; |
389 |
+ |
if (*cp == '@') { |
390 |
+ |
adapt++; |
391 |
+ |
while (isspace(*++cp)) |
392 |
+ |
; |
393 |
+ |
} |
394 |
|
if (*cp == '\0') { /* normalize to point */ |
395 |
|
if (dev->getcur == NULL) |
396 |
|
return; |
397 |
|
(*dev->comout)("Pick point for exposure\n"); |
398 |
|
if ((*dev->getcur)(&x, &y) == ABORT) |
399 |
|
return; |
400 |
< |
r.l = r.d = 0; |
274 |
< |
r.r = hresolu; r.u = vresolu; |
275 |
< |
p = findrect(x, y, &ptrunk, &r, -1); |
276 |
< |
e = 1.0; |
400 |
> |
p = findrect(x, y, &ptrunk, -1); |
401 |
|
} else { |
402 |
|
if (*cp == '=') { /* absolute setting */ |
403 |
|
p = NULL; |
405 |
|
for (cp++; isspace(*cp); cp++) |
406 |
|
; |
407 |
|
if (*cp == '\0') { /* interactive */ |
408 |
< |
sprintf(buf, "exposure (%lf): ", exposure); |
408 |
> |
sprintf(buf, "exposure (%f): ", exposure); |
409 |
|
(*dev->comout)(buf); |
410 |
|
(*dev->comin)(buf, NULL); |
411 |
|
for (cp = buf; isspace(*cp); cp++) |
413 |
|
if (*cp == '\0') |
414 |
|
return; |
415 |
|
} |
292 |
– |
} else { /* normalize to average */ |
293 |
– |
p = &ptrunk; |
294 |
– |
e = 1.0; |
416 |
|
} |
417 |
|
if (*cp == '+' || *cp == '-') /* f-stops */ |
418 |
|
e *= pow(2.0, atof(cp)); |
420 |
|
e *= atof(cp); |
421 |
|
} |
422 |
|
if (p != NULL) { /* relative setting */ |
423 |
< |
if (bright(p->v) <= FTINY) { |
423 |
> |
compavg(p); |
424 |
> |
if (bright(p->v) < 1e-15) { |
425 |
|
error(COMMAND, "cannot normalize to zero"); |
426 |
|
return; |
427 |
|
} |
428 |
< |
e *= 0.5 / bright(p->v); |
428 |
> |
if (adapt) |
429 |
> |
e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure; |
430 |
> |
else |
431 |
> |
e *= 0.5 / bright(p->v); |
432 |
|
} |
433 |
|
if (e <= FTINY || fabs(1.0 - e) <= FTINY) |
434 |
|
return; |
437 |
|
redraw(); |
438 |
|
} |
439 |
|
|
440 |
+ |
typedef union {int i; double d; COLOR C;} *MyUptr; |
441 |
+ |
#define FEQ(x,y) (fabs((x)-(y)) <= FTINY) |
442 |
|
|
443 |
< |
setparam(s) /* get/set program parameter */ |
444 |
< |
register char *s; |
443 |
> |
int |
444 |
> |
getparam( /* get variable from user */ |
445 |
> |
char *str, |
446 |
> |
char *dsc, |
447 |
> |
int typ, |
448 |
> |
void *p |
449 |
> |
) |
450 |
|
{ |
451 |
< |
extern int psample; |
320 |
< |
extern double maxdiff; |
321 |
< |
extern double minweight; |
322 |
< |
extern int maxdepth; |
323 |
< |
extern double dstrsrc; |
324 |
< |
extern double shadthresh; |
325 |
< |
extern double shadcert; |
326 |
< |
extern COLOR ambval; |
327 |
< |
extern double ambacc; |
328 |
< |
extern double minarad; |
329 |
< |
extern int ambres; |
330 |
< |
extern int ambdiv; |
331 |
< |
extern int ambssamp; |
332 |
< |
extern int ambounce; |
451 |
> |
MyUptr ptr = (MyUptr)p; |
452 |
|
int i0; |
453 |
|
double d0, d1, d2; |
454 |
+ |
char buf[48]; |
455 |
+ |
|
456 |
+ |
switch (typ) { |
457 |
+ |
case 'i': /* integer */ |
458 |
+ |
if (sscanf(str, "%d", &i0) != 1) { |
459 |
+ |
(*dev->comout)(dsc); |
460 |
+ |
sprintf(buf, " (%d): ", ptr->i); |
461 |
+ |
(*dev->comout)(buf); |
462 |
+ |
(*dev->comin)(buf, NULL); |
463 |
+ |
if (sscanf(buf, "%d", &i0) != 1) |
464 |
+ |
return(0); |
465 |
+ |
} |
466 |
+ |
if (ptr->i == i0) |
467 |
+ |
return(0); |
468 |
+ |
ptr->i = i0; |
469 |
+ |
break; |
470 |
+ |
case 'r': /* real */ |
471 |
+ |
if (sscanf(str, "%lf", &d0) != 1) { |
472 |
+ |
(*dev->comout)(dsc); |
473 |
+ |
sprintf(buf, " (%.6g): ", ptr->d); |
474 |
+ |
(*dev->comout)(buf); |
475 |
+ |
(*dev->comin)(buf, NULL); |
476 |
+ |
if (sscanf(buf, "%lf", &d0) != 1) |
477 |
+ |
return(0); |
478 |
+ |
} |
479 |
+ |
if (FEQ(ptr->d, d0)) |
480 |
+ |
return(0); |
481 |
+ |
ptr->d = d0; |
482 |
+ |
break; |
483 |
+ |
case 'b': /* boolean */ |
484 |
+ |
if (sscanf(str, "%1s", buf) != 1) { |
485 |
+ |
(*dev->comout)(dsc); |
486 |
+ |
sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n'); |
487 |
+ |
(*dev->comout)(buf); |
488 |
+ |
(*dev->comin)(buf, NULL); |
489 |
+ |
if (buf[0] == '\0') |
490 |
+ |
return(0); |
491 |
+ |
} |
492 |
+ |
if (strchr("yY+1tTnN-0fF", buf[0]) == NULL) |
493 |
+ |
return(0); |
494 |
+ |
i0 = strchr("yY+1tT", buf[0]) != NULL; |
495 |
+ |
if (ptr->i == i0) |
496 |
+ |
return(0); |
497 |
+ |
ptr->i = i0; |
498 |
+ |
break; |
499 |
+ |
case 'C': /* color */ |
500 |
+ |
if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
501 |
+ |
(*dev->comout)(dsc); |
502 |
+ |
sprintf(buf, " (%.6g %.6g %.6g): ", |
503 |
+ |
colval(ptr->C,RED), |
504 |
+ |
colval(ptr->C,GRN), |
505 |
+ |
colval(ptr->C,BLU)); |
506 |
+ |
(*dev->comout)(buf); |
507 |
+ |
(*dev->comin)(buf, NULL); |
508 |
+ |
if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3) |
509 |
+ |
return(0); |
510 |
+ |
} |
511 |
+ |
if (FEQ(colval(ptr->C,RED), d0) && |
512 |
+ |
FEQ(colval(ptr->C,GRN), d1) && |
513 |
+ |
FEQ(colval(ptr->C,BLU), d2)) |
514 |
+ |
return(0); |
515 |
+ |
setcolor(ptr->C, d0, d1, d2); |
516 |
+ |
break; |
517 |
+ |
default: |
518 |
+ |
return(0); /* shouldn't happen */ |
519 |
+ |
} |
520 |
+ |
newparam++; |
521 |
+ |
return(1); |
522 |
+ |
} |
523 |
+ |
|
524 |
+ |
|
525 |
+ |
void |
526 |
+ |
setparam( /* get/set program parameter */ |
527 |
+ |
char *s |
528 |
+ |
) |
529 |
+ |
{ |
530 |
+ |
int prev_newp = newparam; |
531 |
|
char buf[128]; |
532 |
|
|
533 |
|
if (s[0] == '\0') { |
534 |
< |
(*dev->comout)("aa ab ad ar as av dc dj dt lr lw sp st: "); |
534 |
> |
(*dev->comout)( |
535 |
> |
"aa ab ad ar as av aw b bv dc dv dj ds dt i lr lw me ma mg ms ps pt ss st u: "); |
536 |
|
(*dev->comin)(buf, NULL); |
537 |
|
s = buf; |
538 |
|
} |
539 |
|
switch (s[0]) { |
540 |
+ |
case 'u': /* uncorrelated sampling */ |
541 |
+ |
getparam(s+1, "uncorrelated sampling", 'b', |
542 |
+ |
(void *)&rand_samp); |
543 |
+ |
break; |
544 |
|
case 'l': /* limit */ |
545 |
|
switch (s[1]) { |
546 |
|
case 'w': /* weight */ |
547 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
548 |
< |
sprintf(buf, "limit weight (%.6g): ", |
348 |
< |
minweight); |
349 |
< |
(*dev->comout)(buf); |
350 |
< |
(*dev->comin)(buf, NULL); |
351 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
352 |
< |
break; |
353 |
< |
} |
354 |
< |
minweight = d0; |
547 |
> |
getparam(s+2, "limit weight", 'r', |
548 |
> |
(void *)&minweight); |
549 |
|
break; |
550 |
|
case 'r': /* reflection */ |
551 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
552 |
< |
sprintf(buf, "limit reflection (%d): ", |
359 |
< |
maxdepth); |
360 |
< |
(*dev->comout)(buf); |
361 |
< |
(*dev->comin)(buf, NULL); |
362 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
363 |
< |
break; |
364 |
< |
} |
365 |
< |
maxdepth = i0; |
551 |
> |
getparam(s+2, "limit reflection", 'i', |
552 |
> |
(void *)&maxdepth); |
553 |
|
break; |
554 |
|
default: |
555 |
|
goto badparam; |
558 |
|
case 'd': /* direct */ |
559 |
|
switch (s[1]) { |
560 |
|
case 'j': /* jitter */ |
561 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
562 |
< |
sprintf(buf, "direct jitter (%.6g): ", |
376 |
< |
dstrsrc); |
377 |
< |
(*dev->comout)(buf); |
378 |
< |
(*dev->comin)(buf, NULL); |
379 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
380 |
< |
break; |
381 |
< |
} |
382 |
< |
dstrsrc = d0; |
561 |
> |
getparam(s+2, "direct jitter", 'r', |
562 |
> |
(void *)&dstrsrc); |
563 |
|
break; |
564 |
|
case 'c': /* certainty */ |
565 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
566 |
< |
sprintf(buf, "direct certainty (%.6g): ", |
387 |
< |
shadcert); |
388 |
< |
(*dev->comout)(buf); |
389 |
< |
(*dev->comin)(buf, NULL); |
390 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
391 |
< |
break; |
392 |
< |
} |
393 |
< |
shadcert = d0; |
565 |
> |
getparam(s+2, "direct certainty", 'r', |
566 |
> |
(void *)&shadcert); |
567 |
|
break; |
568 |
|
case 't': /* threshold */ |
569 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
570 |
< |
sprintf(buf, "direct threshold (%.6g): ", |
398 |
< |
shadthresh); |
399 |
< |
(*dev->comout)(buf); |
400 |
< |
(*dev->comin)(buf, NULL); |
401 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
402 |
< |
break; |
403 |
< |
} |
404 |
< |
shadthresh = d0; |
569 |
> |
getparam(s+2, "direct threshold", 'r', |
570 |
> |
(void *)&shadthresh); |
571 |
|
break; |
572 |
+ |
case 'v': /* visibility */ |
573 |
+ |
getparam(s+2, "direct visibility", 'b', |
574 |
+ |
(void *)&directvis); |
575 |
+ |
break; |
576 |
+ |
case 's': /* sampling */ |
577 |
+ |
getparam(s+2, "direct sampling", 'r', |
578 |
+ |
(void *)&srcsizerat); |
579 |
+ |
break; |
580 |
|
default: |
581 |
|
goto badparam; |
582 |
|
} |
583 |
|
break; |
584 |
+ |
case 'b': /* back faces or black and white */ |
585 |
+ |
switch (s[1]) { |
586 |
+ |
case 'v': /* back face visibility */ |
587 |
+ |
getparam(s+2, "back face visibility", 'b', |
588 |
+ |
(void *)&backvis); |
589 |
+ |
break; |
590 |
+ |
case '\0': /* black and white */ |
591 |
+ |
case ' ': |
592 |
+ |
case 'y': case 'Y': case 't': case 'T': case '1': case '+': |
593 |
+ |
case 'n': case 'N': case 'f': case 'F': case '0': case '-': |
594 |
+ |
getparam(s+1, "black and white", 'b', |
595 |
+ |
(void *)&greyscale); |
596 |
+ |
newparam = prev_newp; |
597 |
+ |
break; |
598 |
+ |
default: |
599 |
+ |
goto badparam; |
600 |
+ |
} |
601 |
+ |
break; |
602 |
+ |
case 'i': /* irradiance */ |
603 |
+ |
getparam(s+1, "irradiance", 'b', |
604 |
+ |
(void *)&do_irrad); |
605 |
+ |
break; |
606 |
|
case 'a': /* ambient */ |
607 |
|
switch (s[1]) { |
608 |
|
case 'v': /* value */ |
609 |
< |
if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
610 |
< |
sprintf(buf, |
415 |
< |
"ambient value (%.6g %.6g %.6g): ", |
416 |
< |
colval(ambval,RED), |
417 |
< |
colval(ambval,GRN), |
418 |
< |
colval(ambval,BLU)); |
419 |
< |
(*dev->comout)(buf); |
420 |
< |
(*dev->comin)(buf, NULL); |
421 |
< |
if (sscanf(buf, "%lf %lf %lf", |
422 |
< |
&d0, &d1, &d2) != 3) |
423 |
< |
break; |
424 |
< |
} |
425 |
< |
setcolor(ambval, d0, d1, d2); |
609 |
> |
getparam(s+2, "ambient value", 'C', |
610 |
> |
(void *)ambval); |
611 |
|
break; |
612 |
+ |
case 'w': /* weight */ |
613 |
+ |
getparam(s+2, "ambient value weight", 'i', |
614 |
+ |
(void *)&ambvwt); |
615 |
+ |
break; |
616 |
|
case 'a': /* accuracy */ |
617 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
618 |
< |
sprintf(buf, "ambient accuracy (%.6g): ", |
619 |
< |
ambacc); |
431 |
< |
(*dev->comout)(buf); |
432 |
< |
(*dev->comin)(buf, NULL); |
433 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
434 |
< |
break; |
435 |
< |
} |
436 |
< |
ambacc = d0; |
617 |
> |
if (getparam(s+2, "ambient accuracy", 'r', |
618 |
> |
(void *)&ambacc)) |
619 |
> |
setambacc(ambacc); |
620 |
|
break; |
621 |
|
case 'd': /* divisions */ |
622 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
623 |
< |
sprintf(buf, "ambient divisions (%d): ", |
441 |
< |
ambdiv); |
442 |
< |
(*dev->comout)(buf); |
443 |
< |
(*dev->comin)(buf, NULL); |
444 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
445 |
< |
break; |
446 |
< |
} |
447 |
< |
ambdiv = i0; |
622 |
> |
getparam(s+2, "ambient divisions", 'i', |
623 |
> |
(void *)&ambdiv); |
624 |
|
break; |
625 |
|
case 's': /* samples */ |
626 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
627 |
< |
sprintf(buf, "ambient super-samples (%d): ", |
452 |
< |
ambssamp); |
453 |
< |
(*dev->comout)(buf); |
454 |
< |
(*dev->comin)(buf, NULL); |
455 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
456 |
< |
break; |
457 |
< |
} |
458 |
< |
ambssamp = i0; |
626 |
> |
getparam(s+2, "ambient super-samples", 'i', |
627 |
> |
(void *)&ambssamp); |
628 |
|
break; |
629 |
|
case 'b': /* bounces */ |
630 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
631 |
< |
sprintf(buf, "ambient bounces (%d): ", |
463 |
< |
ambounce); |
464 |
< |
(*dev->comout)(buf); |
465 |
< |
(*dev->comin)(buf, NULL); |
466 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
467 |
< |
break; |
468 |
< |
} |
469 |
< |
ambounce = i0; |
630 |
> |
getparam(s+2, "ambient bounces", 'i', |
631 |
> |
(void *)&ambounce); |
632 |
|
break; |
633 |
|
case 'r': |
634 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
635 |
< |
sprintf(buf, "ambient resolution (%d): ", |
636 |
< |
ambres); |
475 |
< |
(*dev->comout)(buf); |
476 |
< |
(*dev->comin)(buf, NULL); |
477 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
478 |
< |
break; |
479 |
< |
} |
480 |
< |
ambres = i0; |
481 |
< |
minarad = ambres > 0 ? thescene.cusize/ambres : 0.0; |
634 |
> |
if (getparam(s+2, "ambient resolution", 'i', |
635 |
> |
(void *)&ambres)) |
636 |
> |
setambres(ambres); |
637 |
|
break; |
638 |
|
default: |
639 |
|
goto badparam; |
640 |
|
} |
641 |
|
break; |
642 |
< |
case 's': /* sample */ |
642 |
> |
case 'm': /* medium */ |
643 |
|
switch (s[1]) { |
644 |
< |
case 'p': /* pixel */ |
645 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
646 |
< |
sprintf(buf, "sample pixel (%d): ", psample); |
492 |
< |
(*dev->comout)(buf); |
493 |
< |
(*dev->comin)(buf, NULL); |
494 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
495 |
< |
break; |
496 |
< |
} |
497 |
< |
psample = i0; |
498 |
< |
pdepth = 0; |
644 |
> |
case 'e': /* extinction coefficient */ |
645 |
> |
getparam(s+2, "extinction coefficient", 'C', |
646 |
> |
(void *)cextinction); |
647 |
|
break; |
648 |
+ |
case 'a': /* scattering albedo */ |
649 |
+ |
getparam(s+2, "scattering albedo", 'C', |
650 |
+ |
(void *)salbedo); |
651 |
+ |
break; |
652 |
+ |
case 'g': /* scattering eccentricity */ |
653 |
+ |
getparam(s+2, "scattering eccentricity", 'r', |
654 |
+ |
(void *)&seccg); |
655 |
+ |
break; |
656 |
+ |
case 's': /* sampling distance */ |
657 |
+ |
getparam(s+2, "mist sampling distance", 'r', |
658 |
+ |
(void *)&ssampdist); |
659 |
+ |
break; |
660 |
+ |
default: |
661 |
+ |
goto badparam; |
662 |
+ |
} |
663 |
+ |
break; |
664 |
+ |
case 'p': /* pixel */ |
665 |
+ |
switch (s[1]) { |
666 |
+ |
case 's': /* sample */ |
667 |
+ |
if (getparam(s+2, "pixel sample", 'i', |
668 |
+ |
(void *)&psample)) |
669 |
+ |
pdepth = 0; |
670 |
+ |
break; |
671 |
|
case 't': /* threshold */ |
672 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
673 |
< |
sprintf(buf, "sample threshold (%.6g): ", |
674 |
< |
maxdiff); |
504 |
< |
(*dev->comout)(buf); |
505 |
< |
(*dev->comin)(buf, NULL); |
506 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
507 |
< |
break; |
508 |
< |
} |
509 |
< |
maxdiff = d0; |
510 |
< |
pdepth = 0; |
672 |
> |
if (getparam(s+2, "pixel threshold", 'r', |
673 |
> |
(void *)&maxdiff)) |
674 |
> |
pdepth = 0; |
675 |
|
break; |
676 |
|
default: |
677 |
|
goto badparam; |
678 |
|
} |
679 |
+ |
newparam = prev_newp; |
680 |
|
break; |
681 |
+ |
case 's': /* specular */ |
682 |
+ |
switch (s[1]) { |
683 |
+ |
case 's': /* sampling */ |
684 |
+ |
getparam(s+2, "specular sampling", 'r', |
685 |
+ |
(void *)&specjitter); |
686 |
+ |
break; |
687 |
+ |
case 't': /* threshold */ |
688 |
+ |
getparam(s+2, "specular threshold", 'r', |
689 |
+ |
(void *)&specthresh); |
690 |
+ |
break; |
691 |
+ |
default: |
692 |
+ |
goto badparam; |
693 |
+ |
} |
694 |
+ |
break; |
695 |
|
case '\0': /* nothing */ |
696 |
|
break; |
697 |
|
default:; |
698 |
|
badparam: |
699 |
+ |
*sskip(s) = '\0'; |
700 |
|
sprintf(errmsg, "%s: unknown variable", s); |
701 |
|
error(COMMAND, errmsg); |
702 |
|
break; |
704 |
|
} |
705 |
|
|
706 |
|
|
707 |
< |
traceray(s) /* trace a single ray */ |
708 |
< |
char *s; |
707 |
> |
void |
708 |
> |
traceray( /* trace a single ray */ |
709 |
> |
char *s |
710 |
> |
) |
711 |
|
{ |
712 |
< |
char buf[128]; |
713 |
< |
int x, y; |
532 |
< |
RAY thisray; |
712 |
> |
RAY thisray; |
713 |
> |
char buf[512]; |
714 |
|
|
715 |
< |
if (sscanf(s, "%lf %lf %lf %lf %lf %lf", |
535 |
< |
&thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2], |
536 |
< |
&thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) { |
715 |
> |
thisray.rmax = 0.0; |
716 |
|
|
717 |
+ |
if (!sscanvec(s, thisray.rorg) || |
718 |
+ |
!sscanvec(sskip2(s,3), thisray.rdir)) { |
719 |
+ |
int x, y; |
720 |
+ |
|
721 |
|
if (dev->getcur == NULL) |
722 |
|
return; |
723 |
|
(*dev->comout)("Pick ray\n"); |
724 |
|
if ((*dev->getcur)(&x, &y) == ABORT) |
725 |
|
return; |
726 |
|
|
727 |
< |
viewray(thisray.rorg, thisray.rdir, &ourview, |
728 |
< |
(x+.5)/hresolu, (y+.5)/vresolu); |
729 |
< |
|
727 |
> |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, |
728 |
> |
&ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) { |
729 |
> |
error(COMMAND, "not on image"); |
730 |
> |
return; |
731 |
> |
} |
732 |
> |
|
733 |
|
} else if (normalize(thisray.rdir) == 0.0) { |
734 |
|
error(COMMAND, "zero ray direction"); |
735 |
|
return; |
736 |
|
} |
737 |
|
|
738 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
553 |
< |
|
554 |
< |
rayvalue(&thisray); |
738 |
> |
ray_trace(&thisray); |
739 |
|
|
740 |
|
if (thisray.ro == NULL) |
741 |
|
(*dev->comout)("ray hit nothing"); |
742 |
|
else { |
743 |
< |
sprintf(buf, "ray hit %s %s \"%s\"", |
744 |
< |
objptr(thisray.ro->omod)->oname, |
743 |
> |
OBJREC *mat = NULL; |
744 |
> |
OBJREC *mod = NULL; |
745 |
> |
char matspec[256]; |
746 |
> |
OBJREC *ino; |
747 |
> |
|
748 |
> |
matspec[0] = '\0'; |
749 |
> |
if (thisray.ro->omod != OVOID) { |
750 |
> |
mod = objptr(thisray.ro->omod); |
751 |
> |
mat = findmaterial(mod); |
752 |
> |
} |
753 |
> |
if (thisray.rod < 0.0) |
754 |
> |
strcpy(matspec, "back of "); |
755 |
> |
if (mod != NULL) { |
756 |
> |
strcat(matspec, mod->oname); |
757 |
> |
if (mat != mod && mat != NULL) |
758 |
> |
sprintf(matspec+strlen(matspec), |
759 |
> |
" (%s)", mat->oname); |
760 |
> |
} else |
761 |
> |
strcat(matspec, VOIDID); |
762 |
> |
sprintf(buf, "ray hit %s %s \"%s\"", matspec, |
763 |
|
ofun[thisray.ro->otype].funame, |
764 |
|
thisray.ro->oname); |
765 |
+ |
if ((ino = objptr(thisray.robj)) != thisray.ro) |
766 |
+ |
sprintf(buf+strlen(buf), " in %s \"%s\"", |
767 |
+ |
ofun[ino->otype].funame, ino->oname); |
768 |
|
(*dev->comout)(buf); |
769 |
|
(*dev->comin)(buf, NULL); |
770 |
|
if (thisray.rot >= FHUGE) |
771 |
|
(*dev->comout)("at infinity"); |
772 |
|
else { |
773 |
< |
sprintf(buf, "at (%.6g %.6g %.6g)", thisray.rop[0], |
774 |
< |
thisray.rop[1], thisray.rop[2]); |
773 |
> |
sprintf(buf, "at (%.6g %.6g %.6g) (%.6g)", |
774 |
> |
thisray.rop[0], thisray.rop[1], |
775 |
> |
thisray.rop[2], thisray.rt); |
776 |
|
(*dev->comout)(buf); |
777 |
|
} |
778 |
|
(*dev->comin)(buf, NULL); |
779 |
< |
sprintf(buf, "with value (%.6g %.6g %.6g)", |
779 |
> |
sprintf(buf, "value (%.5g %.5g %.5g) (%.3gL)", |
780 |
|
colval(thisray.rcol,RED), |
781 |
|
colval(thisray.rcol,GRN), |
782 |
< |
colval(thisray.rcol,BLU)); |
782 |
> |
colval(thisray.rcol,BLU), |
783 |
> |
luminance(thisray.rcol)); |
784 |
|
(*dev->comout)(buf); |
785 |
|
} |
786 |
|
(*dev->comin)(buf, NULL); |
787 |
|
} |
788 |
|
|
789 |
|
|
790 |
< |
writepict(s) /* write the picture to a file */ |
791 |
< |
char *s; |
790 |
> |
void |
791 |
> |
writepict( /* write the picture to a file */ |
792 |
> |
char *s |
793 |
> |
) |
794 |
|
{ |
795 |
|
static char buf[128]; |
796 |
|
char *fname; |
797 |
|
FILE *fp; |
798 |
|
COLR *scanline; |
799 |
|
int y; |
800 |
< |
|
801 |
< |
if (sscanf(s, "%s", buf) != 1 && buf[0] == '\0') { |
800 |
> |
/* XXX relies on words.c 2.11 behavior */ |
801 |
> |
if (nextword(buf, sizeof(buf), s) == NULL && !buf[0]) { |
802 |
|
error(COMMAND, "no file"); |
803 |
|
return; |
804 |
|
} |
808 |
|
error(COMMAND, errmsg); |
809 |
|
return; |
810 |
|
} |
811 |
+ |
SET_FILE_BINARY(fp); |
812 |
|
(*dev->comout)("writing \""); |
813 |
|
(*dev->comout)(fname); |
814 |
|
(*dev->comout)("\"...\n"); |
815 |
|
/* write header */ |
816 |
+ |
newheader("RADIANCE", fp); |
817 |
|
fputs(progname, fp); |
818 |
|
fprintview(&ourview, fp); |
819 |
< |
putc('\n', fp); |
819 |
> |
if (octname != NULL) |
820 |
> |
fprintf(fp, " %s\n", octname); |
821 |
> |
else |
822 |
> |
putc('\n', fp); |
823 |
> |
fprintf(fp, "SOFTWARE= %s\n", VersionID); |
824 |
> |
fputnow(fp); |
825 |
|
if (exposure != 1.0) |
826 |
|
fputexpos(exposure, fp); |
827 |
|
if (dev->pixaspect != 1.0) |
828 |
|
fputaspect(dev->pixaspect, fp); |
829 |
+ |
fputformat(COLRFMT, fp); |
830 |
|
putc('\n', fp); |
831 |
< |
fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp); |
831 |
> |
fprtresolu(hresolu, vresolu, fp); |
832 |
|
|
833 |
|
scanline = (COLR *)malloc(hresolu*sizeof(COLR)); |
834 |
< |
if (scanline == NULL) |
835 |
< |
error(SYSTEM, "out of memory in writepict"); |
834 |
> |
if (scanline == NULL) { |
835 |
> |
error(COMMAND, "not enough memory!"); |
836 |
> |
fclose(fp); |
837 |
> |
unlink(fname); |
838 |
> |
return; |
839 |
> |
} |
840 |
|
for (y = vresolu-1; y >= 0; y--) { |
841 |
|
getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu); |
842 |
|
if (fwritecolrs(scanline, hresolu, fp) < 0) |
843 |
|
break; |
844 |
|
} |
845 |
+ |
free((void *)scanline); |
846 |
|
if (fclose(fp) < 0) |
847 |
|
error(COMMAND, "write error"); |
626 |
– |
free((char *)scanline); |
848 |
|
} |