| 5 |
|
* Radiance holodeck picture generator |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
+ |
#include <string.h> |
| 9 |
+ |
#include "paths.h" |
| 10 |
+ |
#include "platform.h" |
| 11 |
+ |
#include "rterror.h" |
| 12 |
|
#include "rholo.h" |
| 9 |
– |
#include "view.h" |
| 13 |
|
|
| 11 |
– |
char *progname; /* our program name */ |
| 14 |
|
char *hdkfile; /* holodeck file name */ |
| 15 |
|
char gargc; /* global argc */ |
| 16 |
|
char **gargv; /* global argv */ |
| 30 |
|
|
| 31 |
|
extern int nowarn; /* turn warnings off? */ |
| 32 |
|
|
| 33 |
+ |
static void dopicture(int fn); |
| 34 |
+ |
static void render_frame(PACKHEAD *bl, int nb); |
| 35 |
+ |
static void startpicture(int fn); |
| 36 |
+ |
static int endpicture(void); |
| 37 |
+ |
static void initialize(void); |
| 38 |
+ |
/* from rhpict2.c */ |
| 39 |
+ |
extern void pixFinish(double ransamp); |
| 40 |
+ |
extern void pixBeam(BEAM *bp, HDBEAMI *hb); |
| 41 |
|
|
| 42 |
< |
main(argc, argv) |
| 43 |
< |
int argc; |
| 44 |
< |
char *argv[]; |
| 42 |
> |
|
| 43 |
> |
int |
| 44 |
> |
main( |
| 45 |
> |
int argc, |
| 46 |
> |
char *argv[] |
| 47 |
> |
) |
| 48 |
|
{ |
| 49 |
|
int i, rval; |
| 50 |
|
|
| 51 |
|
gargc = argc; gargv = argv; |
| 52 |
< |
progname = argv[0]; /* get arguments */ |
| 52 |
> |
fixargv0(argv[0]); /* get arguments */ |
| 53 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) { |
| 54 |
|
rval = getviewopt(&myview, argc-i, argv+i); |
| 55 |
|
if (rval >= 0) { /* view option */ |
| 67 |
|
pixaspect = atof(argv[++i]); |
| 68 |
|
else if (argv[i][2] == 'e') { |
| 69 |
|
expval = atof(argv[++i]); |
| 70 |
< |
if (argv[i][0] == '-' | argv[i][0] == '+') |
| 70 |
> |
if ((argv[i][0] == '-') | (argv[i][0] == '+')) |
| 71 |
|
expval = pow(2., expval); |
| 72 |
|
} else |
| 73 |
|
goto userr; |
| 135 |
|
"Usage: %s [-w][-r rf][-pa pa][-pe ex][-x hr][-y vr][-S stfn][-o outp][view] input.hdk\n", |
| 136 |
|
progname); |
| 137 |
|
quit(1); |
| 138 |
+ |
return 1; /* pro forma return */ |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
|
| 142 |
< |
dopicture(fn) /* render view from holodeck */ |
| 143 |
< |
int fn; |
| 142 |
> |
static void |
| 143 |
> |
dopicture( /* render view from holodeck */ |
| 144 |
> |
int fn |
| 145 |
> |
) |
| 146 |
|
{ |
| 147 |
|
char *err; |
| 148 |
|
int rval; |
| 179 |
|
} |
| 180 |
|
|
| 181 |
|
|
| 182 |
< |
render_frame(bl, nb) /* render frame from beam values */ |
| 183 |
< |
register PACKHEAD *bl; |
| 184 |
< |
int nb; |
| 182 |
> |
static void |
| 183 |
> |
render_frame( /* render frame from beam values */ |
| 184 |
> |
PACKHEAD *bl, |
| 185 |
> |
int nb |
| 186 |
> |
) |
| 187 |
|
{ |
| 188 |
< |
extern int pixBeam(); |
| 189 |
< |
register HDBEAMI *bil; |
| 172 |
< |
register int i; |
| 188 |
> |
HDBEAMI *bil; |
| 189 |
> |
int i; |
| 190 |
|
|
| 191 |
|
if (nb <= 0) return; |
| 192 |
|
if ((bil = (HDBEAMI *)malloc(nb*sizeof(HDBEAMI))) == NULL) |
| 201 |
|
} |
| 202 |
|
|
| 203 |
|
|
| 204 |
< |
startpicture(fn) /* initialize picture for rendering & output */ |
| 205 |
< |
int fn; |
| 204 |
> |
static void |
| 205 |
> |
startpicture( /* initialize picture for rendering & output */ |
| 206 |
> |
int fn |
| 207 |
> |
) |
| 208 |
|
{ |
| 209 |
|
extern char VersionID[]; |
| 210 |
|
double pa = pixaspect; |
| 215 |
|
/* prepare output */ |
| 216 |
|
if (outspec != NULL) { |
| 217 |
|
sprintf(fname, outspec, fn); |
| 218 |
< |
if (freopen(fname, "w", stdout) == NULL) { |
| 218 |
> |
if (freopen(fname, "wb", stdout) == NULL) { |
| 219 |
|
sprintf(errmsg, "cannot open output \"%s\"", fname); |
| 220 |
|
error(SYSTEM, errmsg); |
| 221 |
|
} |
| 229 |
|
fputs(VIEWSTR, stdout); |
| 230 |
|
fprintview(&myview, stdout); |
| 231 |
|
fputc('\n', stdout); |
| 232 |
< |
if (pa < 0.99 | pa > 1.01) |
| 232 |
> |
if ((pa < 0.99) | (pa > 1.01)) |
| 233 |
|
fputaspect(pa, stdout); |
| 234 |
< |
if (expval < 0.99 | expval > 1.01) |
| 234 |
> |
if ((expval < 0.99) | (expval > 1.01)) |
| 235 |
|
fputexpos(expval, stdout); |
| 236 |
|
fputformat(COLRFMT, stdout); |
| 237 |
|
fputc('\n', stdout); |
| 238 |
|
/* write resolution (standard order) */ |
| 239 |
|
fprtresolu(hres, vres, stdout); |
| 240 |
|
/* prepare image buffers */ |
| 241 |
< |
bzero((char *)mypixel, hres*vres*sizeof(COLOR)); |
| 242 |
< |
bzero((char *)myweight, hres*vres*sizeof(float)); |
| 243 |
< |
bzero((char *)mydepth, hres*vres*sizeof(float)); |
| 241 |
> |
memset((char *)mypixel, '\0', hres*vres*sizeof(COLOR)); |
| 242 |
> |
memset((char *)myweight, '\0', hres*vres*sizeof(float)); |
| 243 |
> |
memset((char *)mydepth, '\0', hres*vres*sizeof(float)); |
| 244 |
|
} |
| 245 |
|
|
| 246 |
|
|
| 247 |
< |
int |
| 248 |
< |
endpicture() /* finish and write out pixels */ |
| 247 |
> |
static int |
| 248 |
> |
endpicture(void) /* finish and write out pixels */ |
| 249 |
|
{ |
| 250 |
|
int lastr = -1, nunrend = 0; |
| 251 |
< |
int4 lastp, lastrp; |
| 252 |
< |
register int4 p; |
| 253 |
< |
register double d; |
| 251 |
> |
int32 lastp, lastrp; |
| 252 |
> |
int32 p; |
| 253 |
> |
double d; |
| 254 |
|
/* compute final pixel values */ |
| 255 |
|
for (p = hres*vres; p--; ) { |
| 256 |
|
if (myweight[p] <= FTINY) { |
| 257 |
< |
if (lastr >= 0) |
| 257 |
> |
if (lastr >= 0) { |
| 258 |
|
if (p/hres == lastp/hres) |
| 259 |
|
copycolor(mypixel[p], mypixel[lastp]); |
| 260 |
|
else |
| 261 |
|
copycolor(mypixel[p], mypixel[lastrp]); |
| 262 |
+ |
} |
| 263 |
|
nunrend++; |
| 264 |
|
continue; |
| 265 |
|
} |
| 278 |
|
} |
| 279 |
|
|
| 280 |
|
|
| 281 |
< |
initialize() /* initialize holodeck and buffers */ |
| 281 |
> |
static void |
| 282 |
> |
initialize(void) /* initialize holodeck and buffers */ |
| 283 |
|
{ |
| 284 |
|
int fd; |
| 285 |
|
FILE *fp; |
| 286 |
|
int n; |
| 287 |
< |
int4 nextloc; |
| 287 |
> |
off_t nextloc; |
| 288 |
|
/* open holodeck file */ |
| 289 |
< |
if ((fp = fopen(hdkfile, "r")) == NULL) { |
| 289 |
> |
if ((fp = fopen(hdkfile, "rb")) == NULL) { |
| 290 |
|
sprintf(errmsg, "cannot open \"%s\" for reading", hdkfile); |
| 291 |
|
error(SYSTEM, errmsg); |
| 292 |
|
} |
| 302 |
|
fd = dup(fileno(fp)); /* dup file descriptor */ |
| 303 |
|
fclose(fp); /* done with stdio */ |
| 304 |
|
for (n = 0; nextloc > 0L; n++) { /* initialize each section */ |
| 305 |
< |
lseek(fd, (off_t)nextloc, 0); |
| 305 |
> |
lseek(fd, nextloc, SEEK_SET); |
| 306 |
|
read(fd, (char *)&nextloc, sizeof(nextloc)); |
| 307 |
|
hdinit(fd, NULL); |
| 308 |
|
} |
| 310 |
|
mypixel = (COLOR *)bmalloc(xres*yres*sizeof(COLOR)); |
| 311 |
|
myweight = (float *)bmalloc(xres*yres*sizeof(float)); |
| 312 |
|
mydepth = (float *)bmalloc(xres*yres*sizeof(float)); |
| 313 |
< |
if (mypixel == NULL | myweight == NULL | mydepth == NULL) |
| 313 |
> |
if ((mypixel == NULL) | (myweight == NULL) | (mydepth == NULL)) |
| 314 |
|
error(SYSTEM, "out of memory in initialize"); |
| 315 |
|
} |
| 316 |
|
|
| 317 |
|
|
| 318 |
|
void |
| 319 |
< |
eputs(s) /* put error message to stderr */ |
| 299 |
< |
register char *s; |
| 319 |
> |
eputs(const char *s) /* put error message to stderr */ |
| 320 |
|
{ |
| 321 |
|
static int midline = 0; |
| 322 |
|
|