--- ray/src/hd/rhd_qtree.c 2003/06/20 00:25:49 3.22 +++ ray/src/hd/rhd_qtree.c 2005/01/07 20:33:02 3.26 @@ -1,10 +1,12 @@ #ifndef lint -static const char RCSid[] = "$Id: rhd_qtree.c,v 3.22 2003/06/20 00:25:49 greg Exp $"; +static const char RCSid[] = "$Id: rhd_qtree.c,v 3.26 2005/01/07 20:33:02 greg Exp $"; #endif /* * Quadtree driver support routines. */ +#include + #include "standard.h" #include "rhd_qtree.h" /* quantity of leaves to free at a time */ @@ -39,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; @@ -66,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; @@ -81,7 +91,7 @@ int really; nexttwig = 0; if (!really) { /* just clear allocated blocks */ while (i--) - bzero((char *)twigbundle[i], TBUNDLESIZ*sizeof(RTREE)); + memset((char *)twigbundle[i], '\0', TBUNDLESIZ*sizeof(RTREE)); return; } /* else "really" means free up memory */ @@ -95,9 +105,10 @@ int really; #define LEAFSIZ (3*sizeof(float)+sizeof(int32)+\ sizeof(TMbright)+6*sizeof(BYTE)) -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; @@ -132,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) @@ -143,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; @@ -162,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; @@ -196,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; @@ -233,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; @@ -317,7 +334,7 @@ int drop; tp->k[q].li = lo; } dropit: - if (drop) + if (drop) { if (li+1 == (qtL.tl ? qtL.tl : qtL.nl)) qtL.tl = li; /* special case */ else { @@ -325,13 +342,17 @@ dropit: qtL.wd[li] = falleaves; falleaves = li; } + } return(li == lo); } -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; @@ -355,10 +376,10 @@ 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, + tmMapPixels(tmGlobal, (BYTE *)(qtL.rgb+li), qtL.brt+li, (BYTE *)(qtL.chr+li), 1); if (--rayqleft == 0) dev_flush(); /* flush output */ @@ -366,7 +387,8 @@ FVECT d, p; } -qtReplant() /* replant our tree using new view */ +extern void +qtReplant(void) /* replant our tree using new view */ { register int i; /* anything to replant? */ @@ -381,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? */ @@ -403,18 +427,18 @@ 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, + if (tmMapPixels(tmGlobal, (BYTE *)(qtL.rgb+aorg), qtL.brt+aorg, (BYTE *)(qtL.chr+aorg), alen) != TM_E_OK) return(0); if (blen > 0) - tmMapPixels((BYTE *)(qtL.rgb+borg), qtL.brt+borg, + tmMapPixels(tmGlobal, (BYTE *)(qtL.rgb+borg), qtL.brt+borg, (BYTE *)(qtL.chr+borg), blen); qtL.tml = qtL.tl; return(1);