--- ray/src/hd/rhpict.c 1999/03/04 10:30:04 3.1 +++ ray/src/hd/rhpict.c 2003/07/21 22:30:18 3.13 @@ -1,29 +1,31 @@ -/* Copyright (c) 1999 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rhpict.c,v 3.13 2003/07/21 22:30:18 schorsch Exp $"; #endif - /* * Radiance holodeck picture generator */ +#include + #include "rholo.h" #include "view.h" -#include "resolu.h" char *progname; /* our program name */ char *hdkfile; /* holodeck file name */ +char gargc; /* global argc */ +char **gargv; /* global argv */ VIEW myview = STDVIEW; /* current output view */ int xres = 512, yres = 512; /* max. horizontal and vertical resolution */ char *outspec = NULL; /* output file specification */ +double randfrac = -1.; /* random resampling fraction */ double pixaspect = 1.; /* pixel aspect ratio */ int seqstart = 0; /* sequence start frame */ double expval = 1.; /* exposure value */ COLOR *mypixel; /* pixels being rendered */ float *myweight; /* weights (used to compute final pixels) */ +float *mydepth; /* depth values (visibility culling) */ int hres, vres; /* current horizontal and vertical res. */ extern int nowarn; /* turn warnings off? */ @@ -35,6 +37,7 @@ char *argv[]; { int i, rval; + gargc = argc; gargv = argv; progname = argv[0]; /* get arguments */ for (i = 1; i < argc && argv[i][0] == '-'; i++) { rval = getviewopt(&myview, argc-i, argv+i); @@ -49,9 +52,9 @@ char *argv[]; case 'p': /* pixel aspect/exposure */ if (badarg(argc-i-1,argv+i+1,"f")) goto userr; - if (argv[i][1] == 'a') + if (argv[i][2] == 'a') pixaspect = atof(argv[++i]); - else if (argv[i][1] == 'e') { + else if (argv[i][2] == 'e') { expval = atof(argv[++i]); if (argv[i][0] == '-' | argv[i][0] == '+') expval = pow(2., expval); @@ -73,13 +76,21 @@ char *argv[]; goto userr; outspec = argv[++i]; break; + case 'r': /* random sampling */ + if (badarg(argc-i-1,argv+i+1,"f")) + goto userr; + randfrac = atof(argv[++i]); + break; + case 's': /* smooth sampling */ + randfrac = -1.; + break; case 'S': /* sequence start */ if (badarg(argc-i-1,argv+i+1,"i")) goto userr; seqstart = atoi(argv[++i]); break; case 'v': /* view file */ - if (argv[i][1]!='f' || badarg(argc-i-1,argv+i+1,"s")) + if (argv[i][2]!='f' || badarg(argc-i-1,argv+i+1,"s")) goto userr; rval = viewfile(argv[++i], &myview, NULL); if (rval < 0) { @@ -97,9 +108,9 @@ char *argv[]; } } /* open holodeck file */ - if (i >= argc) + if (i != argc-1) goto userr; - hdkfile = argv[i++]; + hdkfile = argv[i]; initialize(); /* render picture(s) */ if (seqstart <= 0) @@ -110,7 +121,7 @@ char *argv[]; quit(0); /* all done! */ userr: fprintf(stderr, -"Usage: %s [-w][-pa pa][-pe ex][-x hr][-y vr][-S stfn][-o outp][view] input.hdk\n", +"Usage: %s [-w][-r rf][-pa pa][-pe ex][-x hr][-y vr][-S stfn][-o outp][view] input.hdk\n", progname); quit(1); } @@ -134,7 +145,7 @@ int fn; /* render image */ if (blist.nb > 0) { render_frame(blist.bl, blist.nb); - free((char *)blist.bl); + free((void *)blist.bl); } else { sprintf(errmsg, "no section visible in frame %d", fn); error(WARNING, errmsg); @@ -144,11 +155,13 @@ int fn; sprintf(errmsg, "error writing frame %d", fn); error(SYSTEM, errmsg); } +#ifdef DEBUG if (blist.nb > 0 & rval > 0) { - sprintf(errmsg, "%.1f%% unrendered pixels in frame %d", - 100.*rval/(hres*vres), fn); + sprintf(errmsg, "%d unrendered pixels in frame %d (%.1f%%)", + rval, fn, 100.*rval/(hres*vres)); error(WARNING, errmsg); } +#endif } @@ -156,7 +169,7 @@ render_frame(bl, nb) /* render frame from beam values register PACKHEAD *bl; int nb; { - extern int render_beam(); + extern void pixBeam(); register HDBEAMI *bil; register int i; @@ -167,8 +180,9 @@ int nb; bil[i].h = hdlist[bl[i].hd]; bil[i].b = bl[i].bi; } - hdloadbeams(bil, nb, render_beam); - free((char *)bil); + hdloadbeams(bil, nb, pixBeam); + pixFinish(randfrac); + free((void *)bil); } @@ -192,7 +206,7 @@ int fn; /* write header */ newheader("RADIANCE", stdout); printf("SOFTWARE= %s\n", VersionID); - printf("%s %s\n", progname, hdkfile); + printargs(gargc, gargv, stdout); if (fn) printf("FRAME=%d\n", fn); fputs(VIEWSTR, stdout); @@ -207,30 +221,39 @@ int fn; /* write resolution (standard order) */ fprtresolu(hres, vres, stdout); /* prepare image buffers */ - bzero((char *)mypixel, hres*vres*sizeof(COLOR)); - bzero((char *)myweight, hres*vres*sizeof(float)); + memset((char *)mypixel, '\0', hres*vres*sizeof(COLOR)); + memset((char *)myweight, '\0', hres*vres*sizeof(float)); + memset((char *)mydepth, '\0', hres*vres*sizeof(float)); } int endpicture() /* finish and write out pixels */ { - int nunrend = 0; - int v; + int lastr = -1, nunrend = 0; + int32 lastp, lastrp; + register int32 p; register double d; - register int p; /* compute final pixel values */ for (p = hres*vres; p--; ) { if (myweight[p] <= FTINY) { + if (lastr >= 0) { + if (p/hres == lastp/hres) + copycolor(mypixel[p], mypixel[lastp]); + else + copycolor(mypixel[p], mypixel[lastrp]); + } nunrend++; continue; } d = expval/myweight[p]; scalecolor(mypixel[p], d); + if ((lastp=p)/hres != lastr) + lastr = (lastrp=p)/hres; } /* write each scanline */ - for (v = vres; v--; ) - if (fwritescan(mypixel+v*hres, hres, stdout) < 0) + for (p = vres; p--; ) + if (fwritescan(mypixel+p*hres, hres, stdout) < 0) return(-1); if (fflush(stdout) == EOF) return(-1); @@ -240,11 +263,10 @@ endpicture() /* finish and write out pixels */ initialize() /* initialize holodeck and buffers */ { - extern long ftell(); int fd; FILE *fp; int n; - int4 nextloc; + int32 nextloc; /* open holodeck file */ if ((fp = fopen(hdkfile, "r")) == NULL) { sprintf(errmsg, "cannot open \"%s\" for reading", hdkfile); @@ -262,18 +284,20 @@ initialize() /* initialize holodeck and buffers */ fd = dup(fileno(fp)); /* dup file descriptor */ fclose(fp); /* done with stdio */ for (n = 0; nextloc > 0L; n++) { /* initialize each section */ - lseek(fd, (long)nextloc, 0); + lseek(fd, (off_t)nextloc, 0); read(fd, (char *)&nextloc, sizeof(nextloc)); hdinit(fd, NULL); } /* allocate picture buffer */ mypixel = (COLOR *)bmalloc(xres*yres*sizeof(COLOR)); myweight = (float *)bmalloc(xres*yres*sizeof(float)); - if (mypixel == NULL | myweight == NULL) + mydepth = (float *)bmalloc(xres*yres*sizeof(float)); + if (mypixel == NULL | myweight == NULL | mydepth == NULL) error(SYSTEM, "out of memory in initialize"); } +void eputs(s) /* put error message to stderr */ register char *s; {