1 |
– |
/* Copyright (c) 1999 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Radiance holodeck picture generator |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include <string.h> |
9 |
+ |
|
10 |
|
#include "rholo.h" |
11 |
|
#include "view.h" |
13 |
– |
#include "resolu.h" |
12 |
|
|
13 |
|
char *progname; /* our program name */ |
14 |
|
char *hdkfile; /* holodeck file name */ |
15 |
+ |
char gargc; /* global argc */ |
16 |
+ |
char **gargv; /* global argv */ |
17 |
|
|
18 |
|
VIEW myview = STDVIEW; /* current output view */ |
19 |
|
int xres = 512, yres = 512; /* max. horizontal and vertical resolution */ |
20 |
|
char *outspec = NULL; /* output file specification */ |
21 |
+ |
double randfrac = -1.; /* random resampling fraction */ |
22 |
|
double pixaspect = 1.; /* pixel aspect ratio */ |
23 |
|
int seqstart = 0; /* sequence start frame */ |
24 |
|
double expval = 1.; /* exposure value */ |
37 |
|
{ |
38 |
|
int i, rval; |
39 |
|
|
40 |
+ |
gargc = argc; gargv = argv; |
41 |
|
progname = argv[0]; /* get arguments */ |
42 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) { |
43 |
|
rval = getviewopt(&myview, argc-i, argv+i); |
52 |
|
case 'p': /* pixel aspect/exposure */ |
53 |
|
if (badarg(argc-i-1,argv+i+1,"f")) |
54 |
|
goto userr; |
55 |
< |
if (argv[i][1] == 'a') |
55 |
> |
if (argv[i][2] == 'a') |
56 |
|
pixaspect = atof(argv[++i]); |
57 |
< |
else if (argv[i][1] == 'e') { |
57 |
> |
else if (argv[i][2] == 'e') { |
58 |
|
expval = atof(argv[++i]); |
59 |
|
if (argv[i][0] == '-' | argv[i][0] == '+') |
60 |
|
expval = pow(2., expval); |
76 |
|
goto userr; |
77 |
|
outspec = argv[++i]; |
78 |
|
break; |
79 |
+ |
case 'r': /* random sampling */ |
80 |
+ |
if (badarg(argc-i-1,argv+i+1,"f")) |
81 |
+ |
goto userr; |
82 |
+ |
randfrac = atof(argv[++i]); |
83 |
+ |
break; |
84 |
+ |
case 's': /* smooth sampling */ |
85 |
+ |
randfrac = -1.; |
86 |
+ |
break; |
87 |
|
case 'S': /* sequence start */ |
88 |
|
if (badarg(argc-i-1,argv+i+1,"i")) |
89 |
|
goto userr; |
90 |
|
seqstart = atoi(argv[++i]); |
91 |
|
break; |
92 |
|
case 'v': /* view file */ |
93 |
< |
if (argv[i][1]!='f' || badarg(argc-i-1,argv+i+1,"s")) |
93 |
> |
if (argv[i][2]!='f' || badarg(argc-i-1,argv+i+1,"s")) |
94 |
|
goto userr; |
95 |
|
rval = viewfile(argv[++i], &myview, NULL); |
96 |
|
if (rval < 0) { |
108 |
|
} |
109 |
|
} |
110 |
|
/* open holodeck file */ |
111 |
< |
if (i >= argc) |
111 |
> |
if (i != argc-1) |
112 |
|
goto userr; |
113 |
< |
hdkfile = argv[i++]; |
113 |
> |
hdkfile = argv[i]; |
114 |
|
initialize(); |
115 |
|
/* render picture(s) */ |
116 |
|
if (seqstart <= 0) |
121 |
|
quit(0); /* all done! */ |
122 |
|
userr: |
123 |
|
fprintf(stderr, |
124 |
< |
"Usage: %s [-w][-pa pa][-pe ex][-x hr][-y vr][-S stfn][-o outp][view] input.hdk\n", |
124 |
> |
"Usage: %s [-w][-r rf][-pa pa][-pe ex][-x hr][-y vr][-S stfn][-o outp][view] input.hdk\n", |
125 |
|
progname); |
126 |
|
quit(1); |
127 |
|
} |
145 |
|
/* render image */ |
146 |
|
if (blist.nb > 0) { |
147 |
|
render_frame(blist.bl, blist.nb); |
148 |
< |
free((char *)blist.bl); |
148 |
> |
free((void *)blist.bl); |
149 |
|
} else { |
150 |
|
sprintf(errmsg, "no section visible in frame %d", fn); |
151 |
|
error(WARNING, errmsg); |
155 |
|
sprintf(errmsg, "error writing frame %d", fn); |
156 |
|
error(SYSTEM, errmsg); |
157 |
|
} |
158 |
+ |
#ifdef DEBUG |
159 |
|
if (blist.nb > 0 & rval > 0) { |
160 |
< |
sprintf(errmsg, "%.1f%% unrendered pixels in frame %d", |
161 |
< |
100.*rval/(hres*vres), fn); |
160 |
> |
sprintf(errmsg, "%d unrendered pixels in frame %d (%.1f%%)", |
161 |
> |
rval, fn, 100.*rval/(hres*vres)); |
162 |
|
error(WARNING, errmsg); |
163 |
|
} |
164 |
+ |
#endif |
165 |
|
} |
166 |
|
|
167 |
|
|
181 |
|
bil[i].b = bl[i].bi; |
182 |
|
} |
183 |
|
hdloadbeams(bil, nb, pixBeam); |
184 |
< |
pixFlush(); |
185 |
< |
free((char *)bil); |
184 |
> |
pixFinish(randfrac); |
185 |
> |
free((void *)bil); |
186 |
|
} |
187 |
|
|
188 |
|
|
206 |
|
/* write header */ |
207 |
|
newheader("RADIANCE", stdout); |
208 |
|
printf("SOFTWARE= %s\n", VersionID); |
209 |
< |
printf("%s %s\n", progname, hdkfile); |
209 |
> |
printargs(gargc, gargv, stdout); |
210 |
|
if (fn) |
211 |
|
printf("FRAME=%d\n", fn); |
212 |
|
fputs(VIEWSTR, stdout); |
221 |
|
/* write resolution (standard order) */ |
222 |
|
fprtresolu(hres, vres, stdout); |
223 |
|
/* prepare image buffers */ |
224 |
< |
bzero((char *)mypixel, hres*vres*sizeof(COLOR)); |
225 |
< |
bzero((char *)myweight, hres*vres*sizeof(float)); |
226 |
< |
bzero((char *)mydepth, hres*vres*sizeof(float)); |
224 |
> |
memset((char *)mypixel, '\0', hres*vres*sizeof(COLOR)); |
225 |
> |
memset((char *)myweight, '\0', hres*vres*sizeof(float)); |
226 |
> |
memset((char *)mydepth, '\0', hres*vres*sizeof(float)); |
227 |
|
} |
228 |
|
|
229 |
|
|
230 |
|
int |
231 |
|
endpicture() /* finish and write out pixels */ |
232 |
|
{ |
233 |
< |
int nunrend = 0; |
234 |
< |
int v; |
233 |
> |
int lastr = -1, nunrend = 0; |
234 |
> |
int32 lastp, lastrp; |
235 |
> |
register int32 p; |
236 |
|
register double d; |
224 |
– |
register int p; |
237 |
|
/* compute final pixel values */ |
238 |
|
for (p = hres*vres; p--; ) { |
239 |
|
if (myweight[p] <= FTINY) { |
240 |
+ |
if (lastr >= 0) |
241 |
+ |
if (p/hres == lastp/hres) |
242 |
+ |
copycolor(mypixel[p], mypixel[lastp]); |
243 |
+ |
else |
244 |
+ |
copycolor(mypixel[p], mypixel[lastrp]); |
245 |
|
nunrend++; |
246 |
|
continue; |
247 |
|
} |
248 |
|
d = expval/myweight[p]; |
249 |
|
scalecolor(mypixel[p], d); |
250 |
+ |
if ((lastp=p)/hres != lastr) |
251 |
+ |
lastr = (lastrp=p)/hres; |
252 |
|
} |
253 |
|
/* write each scanline */ |
254 |
< |
for (v = vres; v--; ) |
255 |
< |
if (fwritescan(mypixel+v*hres, hres, stdout) < 0) |
254 |
> |
for (p = vres; p--; ) |
255 |
> |
if (fwritescan(mypixel+p*hres, hres, stdout) < 0) |
256 |
|
return(-1); |
257 |
|
if (fflush(stdout) == EOF) |
258 |
|
return(-1); |
262 |
|
|
263 |
|
initialize() /* initialize holodeck and buffers */ |
264 |
|
{ |
246 |
– |
extern long ftell(); |
265 |
|
int fd; |
266 |
|
FILE *fp; |
267 |
|
int n; |
268 |
< |
int4 nextloc; |
268 |
> |
int32 nextloc; |
269 |
|
/* open holodeck file */ |
270 |
|
if ((fp = fopen(hdkfile, "r")) == NULL) { |
271 |
|
sprintf(errmsg, "cannot open \"%s\" for reading", hdkfile); |
283 |
|
fd = dup(fileno(fp)); /* dup file descriptor */ |
284 |
|
fclose(fp); /* done with stdio */ |
285 |
|
for (n = 0; nextloc > 0L; n++) { /* initialize each section */ |
286 |
< |
lseek(fd, (long)nextloc, 0); |
286 |
> |
lseek(fd, (off_t)nextloc, 0); |
287 |
|
read(fd, (char *)&nextloc, sizeof(nextloc)); |
288 |
|
hdinit(fd, NULL); |
289 |
|
} |
296 |
|
} |
297 |
|
|
298 |
|
|
299 |
+ |
void |
300 |
|
eputs(s) /* put error message to stderr */ |
301 |
|
register char *s; |
302 |
|
{ |