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