--- ray/src/hd/rhd_qtree.c 2003/07/21 22:30:18 3.24 +++ ray/src/hd/rhd_qtree.c 2011/05/20 02:06:39 3.27 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rhd_qtree.c,v 3.24 2003/07/21 22:30:18 schorsch Exp $"; +static const char RCSid[] = "$Id: rhd_qtree.c,v 3.27 2011/05/20 02:06:39 greg Exp $"; #endif /* * Quadtree driver support routines. @@ -41,9 +41,14 @@ static int32 falleaves; /* our list of fallen leaves * static RTREE **twigbundle; /* free twig blocks (NULL term.) */ static int nexttwig; /* next free twig */ +static RTREE *newtwig(void); +static void qtFreeTree(int really); +static void shaketree(RTREE *tp); +static int putleaf(int li, int drop); + static RTREE * -newtwig() /* allocate a twig */ +newtwig(void) /* allocate a twig */ { register int bi; @@ -68,11 +73,14 @@ newtwig() /* allocate a twig */ return(twigbundle[bi] + (nexttwig++ - bi*TBUNDLESIZ)); memerr: error(SYSTEM, "out of memory in newtwig"); + return NULL; /* pro forma return */ } -qtFreeTree(really) /* free allocated twigs */ -int really; +static void +qtFreeTree( /* free allocated twigs */ + int really +) { register int i; @@ -95,11 +103,12 @@ int really; #define LEAFSIZ (3*sizeof(float)+sizeof(int32)+\ - sizeof(TMbright)+6*sizeof(BYTE)) + sizeof(TMbright)+6*sizeof(uby8)) -int -qtAllocLeaves(n) /* allocate space for n leaves */ -register int n; +extern int +qtAllocLeaves( /* allocate space for n leaves */ + register int n +) { unsigned nbytes; register unsigned i; @@ -123,8 +132,8 @@ register int n; qtL.wp = (float (*)[3])qtL.base; qtL.wd = (int32 *)(qtL.wp + n); qtL.brt = (TMbright *)(qtL.wd + n); - qtL.chr = (BYTE (*)[3])(qtL.brt + n); - qtL.rgb = (BYTE (*)[3])(qtL.chr + n); + qtL.chr = (uby8 (*)[3])(qtL.brt + n); + qtL.rgb = (uby8 (*)[3])(qtL.chr + n); qtL.nl = n; qtL.tml = qtL.bl = qtL.tl = 0; falleaves = -1; @@ -134,7 +143,8 @@ register int n; #undef LEAFSIZ -qtFreeLeaves() /* free our allocated leaves and twigs */ +extern void +qtFreeLeaves(void) /* free our allocated leaves and twigs */ { qtFreeTree(1); /* free tree also */ if (qtL.nl <= 0) @@ -145,9 +155,10 @@ qtFreeLeaves() /* free our allocated leaves and twig } -static -shaketree(tp) /* shake dead leaves from tree */ -register RTREE *tp; +static void +shaketree( /* shake dead leaves from tree */ + register RTREE *tp +) { register int i, li; @@ -164,9 +175,10 @@ register RTREE *tp; } -int -qtCompost(pct) /* free up some leaves */ -int pct; +extern int +qtCompost( /* free up some leaves */ + int pct +) { register int32 *fl; int nused, nclear, nmapped; @@ -198,9 +210,11 @@ int pct; } -int -qtFindLeaf(x, y) /* find closest leaf to (x,y) */ -int x, y; +extern int +qtFindLeaf( /* find closest leaf to (x,y) */ + int x, + int y +) { register RTREE *tp = &qtrunk; int li = -1; @@ -235,10 +249,11 @@ int x, y; } -static -putleaf(li, drop) /* put a leaf in our tree */ -register int li; -int drop; +static int +putleaf( /* put a leaf in our tree */ + register int li, + int drop +) { register RTREE *tp = &qtrunk; int x0=0, y0=0, x1=odev.hres, y1=odev.vres; @@ -332,9 +347,12 @@ dropit: } -dev_value(c, d, p) /* add a pixel value to our quadtree */ -COLR c; -FVECT d, p; +extern void +dev_value( /* add a pixel value to our quadtree */ + COLR c, + FVECT d, + FVECT p +) { register int li; int mapit; @@ -358,18 +376,19 @@ FVECT d, p; else VCOPY(qtL.wp[li], p); qtL.wd[li] = encodedir(d); - tmCvColrs(&qtL.brt[li], qtL.chr[li], (COLR *)c, 1); + tmCvColrs(tmGlobal, &qtL.brt[li], qtL.chr[li], (COLR *)c, 1); if (putleaf(li, 1)) { if (mapit) - tmMapPixels((BYTE *)(qtL.rgb+li), qtL.brt+li, - (BYTE *)(qtL.chr+li), 1); + tmMapPixels(tmGlobal, (uby8 *)(qtL.rgb+li), qtL.brt+li, + (uby8 *)(qtL.chr+li), 1); if (--rayqleft == 0) dev_flush(); /* flush output */ } } -qtReplant() /* replant our tree using new view */ +extern void +qtReplant(void) /* replant our tree using new view */ { register int i; /* anything to replant? */ @@ -384,8 +403,10 @@ qtReplant() /* replant our tree using new view */ } -qtMapLeaves(redo) /* map our leaves to RGB */ -int redo; +extern int +qtMapLeaves( /* map our leaves to RGB */ + int redo +) { int aorg, alen, borg, blen; /* recompute mapping? */ @@ -406,19 +427,19 @@ int redo; } /* (re)compute tone mapping? */ if (qtL.tml == qtL.bl) { - tmClearHisto(); - tmAddHisto(qtL.brt+aorg, alen, 1); + tmClearHisto(tmGlobal); + tmAddHisto(tmGlobal, qtL.brt+aorg, alen, 1); if (blen > 0) - tmAddHisto(qtL.brt+borg, blen, 1); - if (tmComputeMapping(0., 0., 0.) != TM_E_OK) + tmAddHisto(tmGlobal, qtL.brt+borg, blen, 1); + if (tmComputeMapping(tmGlobal, 0., 0., 0.) != TM_E_OK) return(0); } - if (tmMapPixels((BYTE *)(qtL.rgb+aorg), qtL.brt+aorg, - (BYTE *)(qtL.chr+aorg), alen) != TM_E_OK) + if (tmMapPixels(tmGlobal, (uby8 *)(qtL.rgb+aorg), qtL.brt+aorg, + (uby8 *)(qtL.chr+aorg), alen) != TM_E_OK) return(0); if (blen > 0) - tmMapPixels((BYTE *)(qtL.rgb+borg), qtL.brt+borg, - (BYTE *)(qtL.chr+borg), blen); + tmMapPixels(tmGlobal, (uby8 *)(qtL.rgb+borg), qtL.brt+borg, + (uby8 *)(qtL.chr+borg), blen); qtL.tml = qtL.tl; return(1); }