--- ray/src/rt/rview.c 1989/10/27 11:48:25 1.8 +++ ray/src/rt/rview.c 1991/05/03 15:22:24 1.12 @@ -20,7 +20,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include -VIEW ourview = STDVIEW(470); /* viewing parameters */ +VIEW ourview = STDVIEW; /* viewing parameters */ +int hresolu, vresolu; /* image resolution */ int psample = 8; /* pixel sample size */ double maxdiff = .15; /* max. sample difference */ @@ -44,7 +45,7 @@ char *amblist[128]; /* ambient include/exclude list int ambincl = -1; /* include == 1, exclude == 0 */ int greyscale = 0; /* map colors to brightness? */ -char *devname = "X"; /* output device name */ +char *devname = dev_default; /* output device name */ struct driver *dev = NULL; /* driver functions */ @@ -54,6 +55,10 @@ PNODE ptrunk; /* the base of our image */ RECT pframe; /* current frame boundaries */ int pdepth; /* image depth in current frame */ +static char *reserve_mem = NULL; /* pre-allocated reserve memory */ + +#define RESERVE_AMT 8192 /* amount of memory to reserve */ + #define CTRL(c) ('c'-'@') @@ -114,20 +119,19 @@ rview() /* do a view */ newimage(); /* set up image */ for ( ; ; ) { /* quit in command() */ - while (ourview.hresolu <= 1<comout)(buf); rsample(); } else { sprintf(buf, "%d refining...\n", 1<comout)(buf); - refine(&ptrunk, 0, 0, ourview.hresolu, - ourview.vresolu, pdepth+1); + refine(&ptrunk, 0, 0, hresolu, vresolu, pdepth+1); } if (dev->inpready) command(": "); @@ -137,6 +141,28 @@ rview() /* do a view */ } +memreserve() /* fill memory reserves */ +{ + if (reserve_mem != NULL) + return; /* got some already */ + reserve_mem = malloc(RESERVE_AMT); +} + + +memerror(detail) /* try and rescue a memory error */ +char *detail; +{ + if (reserve_mem == NULL) { + sprintf(errmsg, "out of memory %s", detail); + error(SYSTEM, errmsg); + } + free(reserve_mem); + reserve_mem = NULL; + for ( ; ; ) + command("out of memory: "); +} + + command(prompt) /* get/execute command */ char *prompt; { @@ -145,8 +171,7 @@ char *prompt; char inpbuf[256]; char *args; again: - (*dev->comout)(prompt); /* get command + arguments */ - (*dev->comin)(inpbuf); + (*dev->comin)(inpbuf, prompt); /* get command + arguments */ for (args = inpbuf; *args && *args != ' '; args++) ; if (*args) *args++ = '\0'; @@ -266,24 +291,24 @@ rsample() /* sample the image */ * difference, we subsample the super-pixels. The testing process * includes initialization of the next row. */ - xsiz = (((pframe.r-pframe.l)<>pdepth), + rl[x].r = hresolu; rl[x].u = vresolu; + pl[x] = findrect(pframe.l+((x*hresolu)>>pdepth), pframe.d, &ptrunk, rl+x, pdepth); } /* sample the image */ @@ -311,9 +336,9 @@ rsample() /* sample the image */ * Find super-pixel at this position in next row. */ r.l = r.d = 0; - r.r = ourview.hresolu; r.u = ourview.vresolu; - p = findrect(pframe.l+((x*ourview.hresolu)>>pdepth), - pframe.d+(((y+1)*ourview.vresolu)>>pdepth), + r.r = hresolu; r.u = vresolu; + p = findrect(pframe.l+((x*hresolu)>>pdepth), + pframe.d+(((y+1)*vresolu)>>pdepth), &ptrunk, &r, pdepth); /* * Test super-pixel in next row. @@ -360,7 +385,7 @@ int pd; if (p->kid == NULL) { /* subdivide */ if ((p->kid = newptree()) == NULL) - error(SYSTEM, "out of memory in refine"); + memerror("in refine"); /* * The following paint order can leave a black pixel * when redraw() is called in (*dev->paintr)().