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