--- ray/src/rt/rpict.c 1992/08/08 18:45:02 2.10 +++ ray/src/rt/rpict.c 1992/11/10 21:24:34 2.18 @@ -18,7 +18,6 @@ static char SCCSid[] = "$SunId$ LBL"; #endif #include -#include #include "view.h" @@ -26,6 +25,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include "random.h" +#include "paths.h" + int dimlist[MAXDIM]; /* sampling dimensions */ int ndims = 0; /* number of sampling dimensions */ int samplendx; /* sample index number */ @@ -33,28 +34,28 @@ int samplendx; /* sample index number */ VIEW ourview = STDVIEW; /* view parameters */ int hresolu = 512; /* horizontal resolution */ int vresolu = 512; /* vertical resolution */ -double pixaspect = 1.0; /* pixel aspect ratio */ +double pixaspect = 1.0; /* pixel aspect ratio */ int psample = 4; /* pixel sample size */ -double maxdiff = .05; /* max. difference for interpolation */ -double dstrpix = 0.67; /* square pixel distribution */ +double maxdiff = .05; /* max. difference for interpolation */ +double dstrpix = 0.67; /* square pixel distribution */ -double dstrsrc = 0.0; /* square source distribution */ -double shadthresh = .05; /* shadow threshold */ -double shadcert = .5; /* shadow certainty */ +double dstrsrc = 0.0; /* square source distribution */ +double shadthresh = .05; /* shadow threshold */ +double shadcert = .5; /* shadow certainty */ int directrelay = 1; /* number of source relays */ int vspretest = 512; /* virtual source pretest density */ int directinvis = 0; /* sources invisible? */ -double srcsizerat = .25; /* maximum ratio source size/dist. */ +double srcsizerat = .25; /* maximum ratio source size/dist. */ -double specthresh = .15; /* specular sampling threshold */ -double specjitter = 1.; /* specular sampling jitter */ +double specthresh = .15; /* specular sampling threshold */ +double specjitter = 1.; /* specular sampling jitter */ int maxdepth = 6; /* maximum recursion depth */ -double minweight = 5e-3; /* minimum ray weight */ +double minweight = 5e-3; /* minimum ray weight */ COLOR ambval = BLKCOLOR; /* ambient value */ -double ambacc = 0.2; /* ambient accuracy */ +double ambacc = 0.2; /* ambient accuracy */ int ambres = 32; /* ambient resolution */ int ambdiv = 128; /* ambient divisions */ int ambssamp = 0; /* ambient super-samples */ @@ -62,9 +63,13 @@ int ambounce = 0; /* ambient bounces */ char *amblist[128]; /* ambient include/exclude list */ int ambincl = -1; /* include == 1, exclude == 0 */ +#ifdef MSDOS +int ralrm = 60; /* seconds between reports */ +#else int ralrm = 0; /* seconds between reports */ +#endif -double pctdone = 0.0; /* percentage done */ +double pctdone = 0.0; /* percentage done */ long tlastrept = 0L; /* time at last report */ @@ -73,12 +78,12 @@ extern long tstart; /* starting time */ extern long nrays; /* number of rays traced */ -#define MAXDIV 16 /* maximum sample size */ +#define MAXDIV 16 /* maximum sample size */ -#define pixjitter() (.5+dstrpix*(.5-frandom())) +#define pixjitter() (.5+dstrpix*(.5-frandom())) -#define RFTEMPLATE "rfXXXXXX" -#define HFTEMPLATE "/tmp/hfXXXXXX" +#define RFTEMPLATE "rfXXXXXX" +#define HFTEMPLATE TEMPLATE static char *hfname = NULL; /* header file name */ static FILE *hfp = NULL; /* header file pointer */ @@ -87,7 +92,7 @@ static int hres, vres; /* resolution for this frame extern char *mktemp(); -double pixvalue(); +double pixvalue(); quit(code) /* quit program */ @@ -108,7 +113,7 @@ int code; report() /* report progress */ { struct rusage rubuf; - double t; + double t; getrusage(RUSAGE_SELF, &rubuf); t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; @@ -144,20 +149,17 @@ openheader() /* save standard output to header file } -closeheader() /* done with header output */ -{ - if (hfname == NULL) - return; - if (fflush(stdout) == EOF || (hfp = fopen(hfname, "r")) == NULL) - error(SYSTEM, "error reopening header file"); -} - - dupheader() /* repeat header on standard output */ { register int c; - if (fseek(hfp, 0L, 0) < 0) + if (hfp == NULL) { + if ((hfp = fopen(hfname, "r")) == NULL) + error(SYSTEM, "error reopening header file"); +#ifdef MSDOS + setmode(fileno(hfp), O_BINARY); +#endif + } else if (fseek(hfp, 0L, 0) < 0) error(SYSTEM, "seek error on header file"); while ((c = getc(hfp)) != EOF) putchar(c); @@ -182,10 +184,8 @@ char *pout, *zout, *prvr; extern char *rindex(), *strncpy(), *strcat(); char fbuf[128], fbuf2[128]; register char *cp; - RESOLU rs; - double pa; - /* finished writing header */ - closeheader(); + RESOLU rs; + double pa; /* check sampling */ if (psample < 1) psample = 1; @@ -209,13 +209,15 @@ char *pout, *zout, *prvr; error(USER, "unexpected EOF on view input"); prvr = fbuf; /* mark for renaming */ } - if (pout != NULL) { + if (pout != NULL & prvr != NULL) { sprintf(fbuf, pout, seq); - if (prvr != NULL && !strcmp(prvr, fbuf)) { /* rename */ - fbuf2[0] = '\0'; - if ((cp = rindex(fbuf, '/')) != NULL) - strncpy(fbuf2, fbuf, cp-fbuf+1); - strcat(fbuf2, RFTEMPLATE); + if (!strcmp(prvr, fbuf)) { /* rename */ + strcpy(fbuf2, fbuf); + for (cp = fbuf2; *cp; cp++) + ; + while (cp > fbuf2 && !ISDIRSEP(cp[-1])) + cp--; + strcpy(cp, RFTEMPLATE); prvr = mktemp(fbuf2); if (rename(fbuf, prvr) < 0 && errno != ENOENT) { sprintf(errmsg, @@ -236,6 +238,9 @@ char *pout, *zout, *prvr; "cannot open output file \"%s\"", fbuf); error(SYSTEM, errmsg); } +#ifdef MSDOS + setmode(fileno(stdout), O_BINARY); +#endif dupheader(); } hres = hresolu; vres = vresolu; pa = pixaspect; @@ -255,8 +260,10 @@ char *pout, *zout, *prvr; normaspect(viewaspect(&ourview), &pa, &hres, &vres); if (seq) { if (ralrm > 0) { - sprintf(errmsg, "starting frame %d\n", seq); - eputs(errmsg); + fprintf(stderr, "FRAME %d:", seq); + fprintview(&ourview, stderr); + putc('\n', stderr); + fflush(stderr); } printf("FRAME=%d\n", seq); } @@ -325,6 +332,9 @@ char *zfile, *oldfile; sprintf(errmsg, "cannot open z file \"%s\"", zfile); error(SYSTEM, errmsg); } +#ifdef MSDOS + setmode(zfd, O_BINARY); +#endif for (i = 0; i <= psample; i++) { zbar[i] = (float *)malloc(hres*sizeof(float)); if (zbar[i] == NULL) @@ -345,7 +355,7 @@ char *zfile, *oldfile; pctdone = 100.0*i/vres; if (ralrm > 0) /* report init stats */ report(); -#ifndef BSD +#ifndef BSD else #endif signal(SIGALRM, report); @@ -370,7 +380,7 @@ char *zfile, *oldfile; /* fill bar */ fillscanbar(scanbar, zbar, hres, ypos, ystep); /* write it out */ -#ifndef BSD +#ifndef BSD signal(SIGALRM, SIG_IGN); /* don't interrupt writes */ #endif for (i = ystep; i > 0; i--) { @@ -387,7 +397,7 @@ char *zfile, *oldfile; pctdone = 100.0*(vres-1-ypos)/vres; if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm) report(); -#ifndef BSD +#ifndef BSD else signal(SIGALRM, report); #endif @@ -411,6 +421,8 @@ char *zfile, *oldfile; if (sampdens != NULL) free(sampdens); pctdone = 100.0; + if (ralrm > 0) + report(); return; writerr: error(SYSTEM, "write error in render"); @@ -420,14 +432,14 @@ memerr: fillscanline(scanline, zline, sd, xres, y, xstep) /* fill scan at y */ -register COLOR *scanline; -register float *zline; +register COLOR *scanline; +register float *zline; register char *sd; int xres, y, xstep; { static int nc = 0; /* number of calls */ int bl = xstep, b = xstep; - double z; + double z; register int i; z = pixvalue(scanline[0], 0, y); @@ -455,8 +467,8 @@ int xres, y, xstep; fillscanbar(scanbar, zbar, xres, y, ysize) /* fill interior */ -register COLOR *scanbar[]; -register float *zbar[]; +register COLOR *scanbar[]; +register float *zbar[]; int xres, y, ysize; { COLOR vline[MAXDIV+1]; @@ -486,16 +498,15 @@ int xres, y, ysize; int -fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */ -register COLOR *colline; -register float *zline; +fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */ +register COLOR *colline; +register float *zline; int x, y; int xlen, ylen; int b; { - extern double fabs(); - double ratio; - double z; + double ratio; + double z; COLOR ctmp; int ncut; register int len; @@ -581,6 +592,9 @@ char *oldfile; error(WARNING, errmsg); return(0); } +#ifdef MSDOS + setmode(fileno(fp), O_BINARY); +#endif /* discard header */ getheader(fp, NULL); /* get picture size */