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 "platform.h" |
11 |
+ |
#include "rterror.h" |
12 |
|
#include "rholo.h" |
13 |
|
#include "view.h" |
13 |
– |
#include "resolu.h" |
14 |
|
|
15 |
|
char *progname; /* our program name */ |
16 |
|
char *hdkfile; /* holodeck file name */ |
17 |
+ |
char gargc; /* global argc */ |
18 |
+ |
char **gargv; /* global argv */ |
19 |
|
|
20 |
|
VIEW myview = STDVIEW; /* current output view */ |
21 |
|
int xres = 512, yres = 512; /* max. horizontal and vertical resolution */ |
22 |
|
char *outspec = NULL; /* output file specification */ |
23 |
+ |
double randfrac = -1.; /* random resampling fraction */ |
24 |
|
double pixaspect = 1.; /* pixel aspect ratio */ |
25 |
|
int seqstart = 0; /* sequence start frame */ |
26 |
|
double expval = 1.; /* exposure value */ |
32 |
|
|
33 |
|
extern int nowarn; /* turn warnings off? */ |
34 |
|
|
35 |
+ |
static void dopicture(int fn); |
36 |
+ |
static void render_frame(PACKHEAD *bl, int nb); |
37 |
+ |
static void startpicture(int fn); |
38 |
+ |
static int endpicture(void); |
39 |
+ |
static void initialize(void); |
40 |
+ |
/* from rhpict2.c */ |
41 |
+ |
extern void pixFinish(double ransamp); |
42 |
+ |
extern void pixBeam(BEAM *bp, HDBEAMI *hb); |
43 |
|
|
44 |
< |
main(argc, argv) |
45 |
< |
int argc; |
46 |
< |
char *argv[]; |
44 |
> |
|
45 |
> |
int |
46 |
> |
main( |
47 |
> |
int argc, |
48 |
> |
char *argv[] |
49 |
> |
) |
50 |
|
{ |
51 |
|
int i, rval; |
52 |
|
|
53 |
+ |
gargc = argc; gargv = argv; |
54 |
|
progname = argv[0]; /* get arguments */ |
55 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) { |
56 |
|
rval = getviewopt(&myview, argc-i, argv+i); |
69 |
|
pixaspect = atof(argv[++i]); |
70 |
|
else if (argv[i][2] == 'e') { |
71 |
|
expval = atof(argv[++i]); |
72 |
< |
if (argv[i][0] == '-' | argv[i][0] == '+') |
72 |
> |
if ((argv[i][0] == '-') | (argv[i][0] == '+')) |
73 |
|
expval = pow(2., expval); |
74 |
|
} else |
75 |
|
goto userr; |
89 |
|
goto userr; |
90 |
|
outspec = argv[++i]; |
91 |
|
break; |
92 |
+ |
case 'r': /* random sampling */ |
93 |
+ |
if (badarg(argc-i-1,argv+i+1,"f")) |
94 |
+ |
goto userr; |
95 |
+ |
randfrac = atof(argv[++i]); |
96 |
+ |
break; |
97 |
+ |
case 's': /* smooth sampling */ |
98 |
+ |
randfrac = -1.; |
99 |
+ |
break; |
100 |
|
case 'S': /* sequence start */ |
101 |
|
if (badarg(argc-i-1,argv+i+1,"i")) |
102 |
|
goto userr; |
103 |
|
seqstart = atoi(argv[++i]); |
104 |
|
break; |
105 |
|
case 'v': /* view file */ |
106 |
< |
if (argv[i][1]!='f' || badarg(argc-i-1,argv+i+1,"s")) |
106 |
> |
if (argv[i][2]!='f' || badarg(argc-i-1,argv+i+1,"s")) |
107 |
|
goto userr; |
108 |
|
rval = viewfile(argv[++i], &myview, NULL); |
109 |
|
if (rval < 0) { |
134 |
|
quit(0); /* all done! */ |
135 |
|
userr: |
136 |
|
fprintf(stderr, |
137 |
< |
"Usage: %s [-w][-pa pa][-pe ex][-x hr][-y vr][-S stfn][-o outp][view] input.hdk\n", |
137 |
> |
"Usage: %s [-w][-r rf][-pa pa][-pe ex][-x hr][-y vr][-S stfn][-o outp][view] input.hdk\n", |
138 |
|
progname); |
139 |
|
quit(1); |
140 |
+ |
return 1; /* pro forma return */ |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
< |
dopicture(fn) /* render view from holodeck */ |
145 |
< |
int fn; |
144 |
> |
static void |
145 |
> |
dopicture( /* render view from holodeck */ |
146 |
> |
int fn |
147 |
> |
) |
148 |
|
{ |
149 |
|
char *err; |
150 |
|
int rval; |
161 |
|
/* render image */ |
162 |
|
if (blist.nb > 0) { |
163 |
|
render_frame(blist.bl, blist.nb); |
164 |
< |
free((char *)blist.bl); |
164 |
> |
free((void *)blist.bl); |
165 |
|
} else { |
166 |
|
sprintf(errmsg, "no section visible in frame %d", fn); |
167 |
|
error(WARNING, errmsg); |
181 |
|
} |
182 |
|
|
183 |
|
|
184 |
< |
render_frame(bl, nb) /* render frame from beam values */ |
185 |
< |
register PACKHEAD *bl; |
186 |
< |
int nb; |
184 |
> |
static void |
185 |
> |
render_frame( /* render frame from beam values */ |
186 |
> |
register PACKHEAD *bl, |
187 |
> |
int nb |
188 |
> |
) |
189 |
|
{ |
162 |
– |
extern int pixBeam(); |
190 |
|
register HDBEAMI *bil; |
191 |
|
register int i; |
192 |
|
|
198 |
|
bil[i].b = bl[i].bi; |
199 |
|
} |
200 |
|
hdloadbeams(bil, nb, pixBeam); |
201 |
< |
pixFlush(); |
202 |
< |
free((char *)bil); |
201 |
> |
pixFinish(randfrac); |
202 |
> |
free((void *)bil); |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
< |
startpicture(fn) /* initialize picture for rendering & output */ |
207 |
< |
int fn; |
206 |
> |
static void |
207 |
> |
startpicture( /* initialize picture for rendering & output */ |
208 |
> |
int fn |
209 |
> |
) |
210 |
|
{ |
211 |
|
extern char VersionID[]; |
212 |
|
double pa = pixaspect; |
225 |
|
/* write header */ |
226 |
|
newheader("RADIANCE", stdout); |
227 |
|
printf("SOFTWARE= %s\n", VersionID); |
228 |
< |
printf("%s %s\n", progname, hdkfile); |
228 |
> |
printargs(gargc, gargv, stdout); |
229 |
|
if (fn) |
230 |
|
printf("FRAME=%d\n", fn); |
231 |
|
fputs(VIEWSTR, stdout); |
232 |
|
fprintview(&myview, stdout); |
233 |
|
fputc('\n', stdout); |
234 |
< |
if (pa < 0.99 | pa > 1.01) |
234 |
> |
if ((pa < 0.99) | (pa > 1.01)) |
235 |
|
fputaspect(pa, stdout); |
236 |
< |
if (expval < 0.99 | expval > 1.01) |
236 |
> |
if ((expval < 0.99) | (expval > 1.01)) |
237 |
|
fputexpos(expval, stdout); |
238 |
|
fputformat(COLRFMT, stdout); |
239 |
|
fputc('\n', stdout); |
240 |
|
/* write resolution (standard order) */ |
241 |
|
fprtresolu(hres, vres, stdout); |
242 |
|
/* prepare image buffers */ |
243 |
< |
bzero((char *)mypixel, hres*vres*sizeof(COLOR)); |
244 |
< |
bzero((char *)myweight, hres*vres*sizeof(float)); |
245 |
< |
bzero((char *)mydepth, hres*vres*sizeof(float)); |
243 |
> |
memset((char *)mypixel, '\0', hres*vres*sizeof(COLOR)); |
244 |
> |
memset((char *)myweight, '\0', hres*vres*sizeof(float)); |
245 |
> |
memset((char *)mydepth, '\0', hres*vres*sizeof(float)); |
246 |
|
} |
247 |
|
|
248 |
|
|
249 |
< |
int |
250 |
< |
endpicture() /* finish and write out pixels */ |
249 |
> |
static int |
250 |
> |
endpicture(void) /* finish and write out pixels */ |
251 |
|
{ |
252 |
< |
int nunrend = 0; |
253 |
< |
int v; |
252 |
> |
int lastr = -1, nunrend = 0; |
253 |
> |
int32 lastp, lastrp; |
254 |
> |
register int32 p; |
255 |
|
register double d; |
226 |
– |
register int p; |
256 |
|
/* compute final pixel values */ |
257 |
|
for (p = hres*vres; p--; ) { |
258 |
|
if (myweight[p] <= FTINY) { |
259 |
+ |
if (lastr >= 0) { |
260 |
+ |
if (p/hres == lastp/hres) |
261 |
+ |
copycolor(mypixel[p], mypixel[lastp]); |
262 |
+ |
else |
263 |
+ |
copycolor(mypixel[p], mypixel[lastrp]); |
264 |
+ |
} |
265 |
|
nunrend++; |
266 |
|
continue; |
267 |
|
} |
268 |
|
d = expval/myweight[p]; |
269 |
|
scalecolor(mypixel[p], d); |
270 |
+ |
if ((lastp=p)/hres != lastr) |
271 |
+ |
lastr = (lastrp=p)/hres; |
272 |
|
} |
273 |
|
/* write each scanline */ |
274 |
< |
for (v = vres; v--; ) |
275 |
< |
if (fwritescan(mypixel+v*hres, hres, stdout) < 0) |
274 |
> |
for (p = vres; p--; ) |
275 |
> |
if (fwritescan(mypixel+p*hres, hres, stdout) < 0) |
276 |
|
return(-1); |
277 |
|
if (fflush(stdout) == EOF) |
278 |
|
return(-1); |
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
< |
initialize() /* initialize holodeck and buffers */ |
283 |
> |
static void |
284 |
> |
initialize(void) /* initialize holodeck and buffers */ |
285 |
|
{ |
248 |
– |
extern long ftell(); |
286 |
|
int fd; |
287 |
|
FILE *fp; |
288 |
|
int n; |
289 |
< |
int4 nextloc; |
289 |
> |
int32 nextloc; |
290 |
|
/* open holodeck file */ |
291 |
|
if ((fp = fopen(hdkfile, "r")) == NULL) { |
292 |
|
sprintf(errmsg, "cannot open \"%s\" for reading", hdkfile); |
304 |
|
fd = dup(fileno(fp)); /* dup file descriptor */ |
305 |
|
fclose(fp); /* done with stdio */ |
306 |
|
for (n = 0; nextloc > 0L; n++) { /* initialize each section */ |
307 |
< |
lseek(fd, (long)nextloc, 0); |
307 |
> |
lseek(fd, (off_t)nextloc, SEEK_SET); |
308 |
|
read(fd, (char *)&nextloc, sizeof(nextloc)); |
309 |
|
hdinit(fd, NULL); |
310 |
|
} |
312 |
|
mypixel = (COLOR *)bmalloc(xres*yres*sizeof(COLOR)); |
313 |
|
myweight = (float *)bmalloc(xres*yres*sizeof(float)); |
314 |
|
mydepth = (float *)bmalloc(xres*yres*sizeof(float)); |
315 |
< |
if (mypixel == NULL | myweight == NULL | mydepth == NULL) |
315 |
> |
if ((mypixel == NULL) | (myweight == NULL) | (mydepth == NULL)) |
316 |
|
error(SYSTEM, "out of memory in initialize"); |
317 |
|
} |
318 |
|
|
319 |
|
|
320 |
+ |
void |
321 |
|
eputs(s) /* put error message to stderr */ |
322 |
|
register char *s; |
323 |
|
{ |