ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_qtree.c
(Generate patch)

Comparing ray/src/hd/rhd_qtree.c (file contents):
Revision 3.4 by gregl, Fri Nov 21 09:52:06 1997 UTC vs.
Revision 3.23 by schorsch, Mon Jun 30 14:59:11 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1997 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Quadtree driver support routines.
6   */
7  
8 + #include <string.h>
9 +
10   #include "standard.h"
11   #include "rhd_qtree.h"
12 +                                /* quantity of leaves to free at a time */
13 + #ifndef LFREEPCT
14 + #define LFREEPCT        25
15 + #endif
16 +                                /* maximum allowed angle difference (deg.) */
17 + #ifndef MAXANG
18 + #define MAXANG          20
19 + #endif
20 + #if MAXANG>0
21 + #define MAXDIFF2        ( MAXANG*MAXANG * (PI*PI/180./180.))
22 + #endif
23  
24 + #define abs(i)          ((i) < 0 ? -(i) : (i))
25 +
26   RTREE   qtrunk;                 /* our quadtree trunk */
27 < double  qtDepthEps = .02;       /* epsilon to compare depths (z fraction) */
27 > double  qtDepthEps = .05;       /* epsilon to compare depths (z fraction) */
28   int     qtMinNodesiz = 2;       /* minimum node dimension (pixels) */
29 + struct rleaves  qtL;            /* our pile of leaves */
30  
31 < static RLEAF    *leafpile;      /* our collection of leaf values */
19 < static int      nleaves;        /* count of leaves in our pile */
20 < static int      bleaf, tleaf;   /* bottom and top (next) leaf index (ring) */
31 > int     rayqleft = 0;           /* rays left to queue before flush */
32  
33 + static int32    falleaves;      /* our list of fallen leaves */
34 +
35 + #define composted(li)   (qtL.bl <= qtL.tl ? \
36 +                                        ((li) < qtL.bl || (li) >= qtL.tl) : \
37 +                                        ((li) < qtL.bl && (li) >= qtL.tl))
38 +
39   #define TBUNDLESIZ      409     /* number of twigs in a bundle */
40  
41   static RTREE    **twigbundle;   /* free twig blocks (NULL term.) */
42   static int      nexttwig;       /* next free twig */
43  
27 static RTREE    emptytree;      /* empty tree for test below */
44  
29 #define is_stump(t)     (!bcmp((char *)(t), (char *)&emptytree, sizeof(RTREE)))
30
31
45   static RTREE *
46   newtwig()                       /* allocate a twig */
47   {
# Line 42 | Line 55 | newtwig()                      /* allocate a twig */
55          }
56          bi = nexttwig / TBUNDLESIZ;
57          if (twigbundle[bi] == NULL) {   /* new block */
58 <                twigbundle = (RTREE **)realloc((char *)twigbundle,
58 >                twigbundle = (RTREE **)realloc((void *)twigbundle,
59                                          (bi+2)*sizeof(RTREE *));
60                  if (twigbundle == NULL)
61                          goto memerr;
# Line 63 | Line 76 | int    really;
76   {
77          register int    i;
78  
79 <        tmClearHisto();
67 <        bzero((char *)&qtrunk, sizeof(RTREE));
68 <        nexttwig = 0;
79 >        qtrunk.flgs = CH_ANY;   /* chop down tree */
80          if (twigbundle == NULL)
81                  return;
82 +        i = (TBUNDLESIZ-1+nexttwig)/TBUNDLESIZ;
83 +        nexttwig = 0;
84          if (!really) {          /* just clear allocated blocks */
85 <                for (i = 0; twigbundle[i] != NULL; i++)
86 <                        bzero((char *)twigbundle[i], TBUNDLESIZ*sizeof(RTREE));
85 >                while (i--)
86 >                        memset((char *)twigbundle[i], '\0', TBUNDLESIZ*sizeof(RTREE));
87                  return;
88          }
89                                  /* else "really" means free up memory */
90          for (i = 0; twigbundle[i] != NULL; i++)
91 <                free((char *)twigbundle[i]);
92 <        free((char *)twigbundle);
91 >                free((void *)twigbundle[i]);
92 >        free((void *)twigbundle);
93          twigbundle = NULL;
94   }
95  
96  
97 < static RLEAF *
98 < newleaf()                       /* allocate a leaf from our pile */
86 < {
87 <        RLEAF   *lp;
88 <        
89 <        lp = leafpile + tleaf++;
90 <        if (tleaf >= nleaves)           /* get next leaf in ring */
91 <                tleaf = 0;
92 <        if (tleaf == bleaf)             /* need to shake some free */
93 <                qtCompost(LFREEPCT);
94 <        return(lp);
95 < }
97 > #define LEAFSIZ         (3*sizeof(float)+sizeof(int32)+\
98 >                        sizeof(TMbright)+6*sizeof(BYTE))
99  
97
100   int
101   qtAllocLeaves(n)                /* allocate space for n leaves */
102 < int     n;
102 > register int    n;
103   {
104          unsigned        nbytes;
105          register unsigned       i;
# Line 105 | Line 107 | int    n;
107          qtFreeTree(0);          /* make sure tree is empty */
108          if (n <= 0)
109                  return(0);
110 <        if (nleaves >= n)
111 <                return(nleaves);
112 <        else if (nleaves > 0)
113 <                free((char *)leafpile);
110 >        if (qtL.nl >= n)
111 >                return(qtL.nl);
112 >        else if (qtL.nl > 0)
113 >                free(qtL.base);
114                                  /* round space up to nearest power of 2 */
115 <        nbytes = n*sizeof(RLEAF) + 8;
115 >        nbytes = n*LEAFSIZ + 8;
116          for (i = 1024; nbytes > i; i <<= 1)
117                  ;
118 <        n = (i - 8) / sizeof(RLEAF);
119 <        leafpile = (RLEAF *)malloc(n*sizeof(RLEAF));
120 <        if (leafpile == NULL)
121 <                return(-1);
122 <        nleaves = n;
123 <        bleaf = tleaf = 0;
124 <        return(nleaves);
118 >        n = (i - 8) / LEAFSIZ;  /* should we make sure n is even? */
119 >        qtL.base = (char *)malloc(n*LEAFSIZ);
120 >        if (qtL.base == NULL)
121 >                return(0);
122 >                                /* assign larger alignment types earlier */
123 >        qtL.wp = (float (*)[3])qtL.base;
124 >        qtL.wd = (int32 *)(qtL.wp + n);
125 >        qtL.brt = (TMbright *)(qtL.wd + n);
126 >        qtL.chr = (BYTE (*)[3])(qtL.brt + n);
127 >        qtL.rgb = (BYTE (*)[3])(qtL.chr + n);
128 >        qtL.nl = n;
129 >        qtL.tml = qtL.bl = qtL.tl = 0;
130 >        falleaves = -1;
131 >        return(n);
132   }
133  
134 + #undef  LEAFSIZ
135  
136 +
137   qtFreeLeaves()                  /* free our allocated leaves and twigs */
138   {
139          qtFreeTree(1);          /* free tree also */
140 <        if (nleaves <= 0)
140 >        if (qtL.nl <= 0)
141                  return;
142 <        free((char *)leafpile);
143 <        leafpile = NULL;
144 <        nleaves = 0;
142 >        free(qtL.base);
143 >        qtL.base = NULL;
144 >        qtL.nl = 0;
145   }
146  
147  
# Line 141 | Line 152 | register RTREE *tp;
152          register int    i, li;
153  
154          for (i = 0; i < 4; i++)
155 <                if (tp->flgs & BRF(i))
155 >                if (tp->flgs & BRF(i)) {
156                          shaketree(tp->k[i].b);
157 <                else if (tp->k[i].l != NULL) {
158 <                        li = tp->k[i].l - leafpile;
159 <                        if (bleaf < tleaf ? (li < bleaf || li >= tleaf) :
160 <                                        (li < bleaf && li >= tleaf)) {
161 <                                tmAddHisto(&tp->k[i].l->brt, 1, -1);
162 <                                tp->k[i].l = NULL;
152 <                        }
157 >                        if (is_stump(tp->k[i].b))
158 >                                tp->flgs &= ~BRF(i);
159 >                } else if (tp->flgs & LFF(i)) {
160 >                        li = tp->k[i].li;
161 >                        if (composted(li))
162 >                                tp->flgs &= ~LFF(i);
163                  }
164   }
165  
# Line 158 | Line 168 | int
168   qtCompost(pct)                  /* free up some leaves */
169   int     pct;
170   {
171 <        int     nused, nclear;
172 <
163 <        if (is_stump(&qtrunk))
164 <                return(0);
171 >        register int32  *fl;
172 >        int     nused, nclear, nmapped;
173                                  /* figure out how many leaves to clear */
174 <        nclear = nleaves * pct / 100;
175 <        nused = tleaf > bleaf ? tleaf-bleaf : tleaf+nleaves-bleaf;
176 <        nclear -= nleaves - nused;      /* less what's already free */
174 >        nclear = qtL.nl * pct / 100;
175 >        nused = qtL.tl - qtL.bl;
176 >        if (nused <= 0) nused += qtL.nl;
177 >        nclear -= qtL.nl - nused;
178          if (nclear <= 0)
179                  return(0);
180          if (nclear >= nused) {  /* clear them all */
181                  qtFreeTree(0);
182 <                bleaf = tleaf = 0;
182 >                qtL.tml = qtL.bl = qtL.tl = 0;
183 >                falleaves = -1;
184                  return(nused);
185          }
186                                  /* else clear leaves from bottom */
187 <        bleaf += nclear;
188 <        if (bleaf >= nleaves) bleaf -= nleaves;
189 <        shaketree(&qtrunk);
187 >        nmapped = qtL.tml - qtL.bl;
188 >        if (nmapped < 0) nmapped += qtL.nl;
189 >        qtL.bl += nclear;
190 >        if (qtL.bl >= qtL.nl) qtL.bl -= qtL.nl;
191 >        if (nmapped <= nclear) qtL.tml = qtL.bl;
192 >        shaketree(&qtrunk);     /* dereference composted leaves */
193 >        for (fl = &falleaves; *fl >= 0; fl = qtL.wd + *fl)
194 >                while (composted(*fl))
195 >                        if ((*fl = qtL.wd[*fl]) < 0)
196 >                                return(nclear);
197          return(nclear);
198   }
199  
200  
201 < RLEAF *
201 > int
202   qtFindLeaf(x, y)                /* find closest leaf to (x,y) */
203   int     x, y;
204   {
205          register RTREE  *tp = &qtrunk;
206 <        RLEAF   *lp = NULL;
206 >        int     li = -1;
207          int     x0=0, y0=0, x1=odev.hres, y1=odev.vres;
208          int     mx, my;
209          register int    q;
210                                          /* check limits */
211          if (x < 0 || x >= odev.hres || y < 0 || y >= odev.vres)
212 <                return(NULL);
212 >                return(-1);
213                                          /* find nearby leaf in our tree */
214          for ( ; ; ) {
215                  for (q = 0; q < 4; q++)         /* find any leaf this level */
216 <                        if (!(tp->flgs & BRF(q)) && tp->k[q].l != NULL) {
217 <                                lp = tp->k[q].l;
216 >                        if (tp->flgs & LFF(q)) {
217 >                                li = tp->k[q].li;
218                                  break;
219                          }
220                  q = 0;                          /* which quadrant are we? */
# Line 211 | Line 228 | int    x, y;
228                          tp = tp->k[q].b;
229                          continue;
230                  }
231 <                if (tp->k[q].l != NULL)         /* good shot! */
232 <                        return(tp->k[q].l);
233 <                return(lp);                     /* else return what we have */
231 >                if (tp->flgs & LFF(q))          /* good shot! */
232 >                        return(tp->k[q].li);
233 >                return(li);                     /* else return what we have */
234          }
235   }
236  
237  
238   static
239 < addleaf(lp)                     /* add a leaf to our tree */
240 < RLEAF   *lp;
239 > putleaf(li, drop)               /* put a leaf in our tree */
240 > register int    li;
241 > int     drop;
242   {
243          register RTREE  *tp = &qtrunk;
244          int     x0=0, y0=0, x1=odev.hres, y1=odev.vres;
245 <        RLEAF   *lo = NULL;
245 >        register int    lo = -1;
246 >        double  d2;
247          int     x, y, mx, my;
248          double  z;
249 <        FVECT   ip, wp;
249 >        FVECT   ip, wp, vd;
250          register int    q;
251 <                                        /* compute leaf location */
252 <        VCOPY(wp, lp->wp);
251 >                                        /* check for dead leaf */
252 >        if (!qtL.chr[li][1] && !(qtL.chr[li][0] | qtL.chr[li][2]))
253 >                return(0);
254 >                                        /* compute leaf location in view */
255 >        VCOPY(wp, qtL.wp[li]);
256          viewloc(ip, &odev.v, wp);
257          if (ip[2] <= 0. || ip[0] < 0. || ip[0] >= 1.
258                          || ip[1] < 0. || ip[1] >= 1.)
259 <                return;
259 >                goto dropit;                    /* behind or outside view */
260 > #ifdef DEBUG
261 >        if (odev.v.type == VT_PAR | odev.v.vfore > FTINY)
262 >                error(INTERNAL, "bad view assumption in putleaf");
263 > #endif
264 >        for (q = 0; q < 3; q++)
265 >                vd[q] = (wp[q] - odev.v.vp[q])/ip[2];
266 >        d2 = fdir2diff(qtL.wd[li], vd);
267 > #ifdef MAXDIFF2
268 >        if (d2 > MAXDIFF2)
269 >                goto dropit;                    /* leaf dir. too far off */
270 > #endif
271          x = ip[0] * odev.hres;
272          y = ip[1] * odev.vres;
273          z = ip[2];
# Line 252 | Line 285 | RLEAF  *lp;
285                          tp = tp->k[q].b;
286                          continue;
287                  }
288 <                if (tp->k[q].l == NULL) {       /* found stem for leaf */
289 <                        tp->k[q].l = lp;
290 <                        tp->flgs |= CHF(q);
291 <                        break;
288 >                if (!(tp->flgs & LFF(q))) {     /* found stem for leaf */
289 >                        tp->k[q].li = li;
290 >                        tp->flgs |= CHLFF(q);
291 >                        return(1);
292                  }      
293 <                                                /* check existing leaf */
294 <                if (lo != tp->k[q].l) {
295 <                        lo = tp->k[q].l;
263 <                        VCOPY(wp, lo->wp);
293 >                if (lo != tp->k[q].li) {        /* check old leaf */
294 >                        lo = tp->k[q].li;
295 >                        VCOPY(wp, qtL.wp[lo]);
296                          viewloc(ip, &odev.v, wp);
297                  }
298                                                  /* is node minimum size? */
299 <                if (x1-x0 <= qtMinNodesiz || y1-y0 <= qtMinNodesiz) {
300 <                        if (z > (1.-qtDepthEps)*ip[2])  /* who is closer? */
301 <                                return;                 /* old one is */
302 <                        tp->k[q].l = lp;                /* new one is */
299 >                if (y1-y0 <= qtMinNodesiz || x1-x0 <= qtMinNodesiz) {
300 >                        if (z > (1.+qtDepthEps)*ip[2])
301 >                                break;                  /* old one closer */
302 >                        if (z >= (1.-qtDepthEps)*ip[2] &&
303 >                                        fdir2diff(qtL.wd[lo], vd) < d2)
304 >                                break;                  /* old one better */
305 >                        tp->k[q].li = li;               /* attach new */
306                          tp->flgs |= CHF(q);
307 <                        tmAddHisto(&lo->brt, 1, -1);    /* drop old one */
307 >                        li = lo;                        /* drop old... */
308                          break;
309                  }
310 <                tp->flgs |= CHBRF(q);           /* else grow tree */
310 >                tp->flgs &= ~LFF(q);            /* else grow tree */
311 >                tp->flgs |= CHBRF(q);
312                  tp = tp->k[q].b = newtwig();
277                tp->flgs |= CH_ANY;             /* all new */
313                  q = 0;                          /* old leaf -> new branch */
314                  mx = ip[0] * odev.hres;
315                  my = ip[1] * odev.vres;
316                  if (mx >= (x0 + x1) >> 1) q |= 01;
317                  if (my >= (y0 + y1) >> 1) q |= 02;
318 <                tp->k[q].l = lo;
318 >                tp->flgs = CH_ANY|LFF(q);       /* all new */
319 >                tp->k[q].li = lo;
320          }
321 <        tmAddHisto(&lp->brt, 1, 1);     /* add leaf to histogram */
321 > dropit:
322 >        if (drop)
323 >                if (li+1 == (qtL.tl ? qtL.tl : qtL.nl))
324 >                        qtL.tl = li;            /* special case */
325 >                else {
326 >                        qtL.chr[li][0] = qtL.chr[li][1] = qtL.chr[li][2] = 0;
327 >                        qtL.wd[li] = falleaves;
328 >                        falleaves = li;
329 >                }
330 >        return(li == lo);
331   }
332  
333  
334 < dev_value(c, p)                 /* add a pixel value to our output queue */
334 > dev_value(c, d, p)              /* add a pixel value to our quadtree */
335   COLR    c;
336 < FVECT   p;
336 > FVECT   d, p;
337   {
338 <        register RLEAF  *lp;
339 <
340 <        lp = newleaf();
341 <        VCOPY(lp->wp, p);
342 <        tmCvColrs(&lp->brt, lp->chr, c, 1);
343 <        addleaf(lp);
338 >        register int    li;
339 >        int     mapit;
340 >                                /* grab a leaf */
341 >        if (!imm_mode && falleaves >= 0) {      /* check for fallen leaves */
342 >                li = falleaves;
343 >                falleaves = qtL.wd[li];
344 >                mapit = qtL.tml <= qtL.tl ?
345 >                                (li < qtL.tml || li >= qtL.tl) :
346 >                                (li < qtL.tml && li >= qtL.tl) ;
347 >        } else {                                /* else allocate new one */
348 >                li = qtL.tl++;
349 >                if (qtL.tl >= qtL.nl)           /* next leaf in ring */
350 >                        qtL.tl = 0;
351 >                if (qtL.tl == qtL.bl)           /* need to shake some free */
352 >                        qtCompost(LFREEPCT);
353 >                mapit = 0;                      /* we'll map it later */
354 >        }
355 >        if (p == NULL)
356 >                VSUM(qtL.wp[li], odev.v.vp, d, FHUGE);
357 >        else
358 >                VCOPY(qtL.wp[li], p);
359 >        qtL.wd[li] = encodedir(d);
360 >        tmCvColrs(&qtL.brt[li], qtL.chr[li], (COLR *)c, 1);
361 >        if (putleaf(li, 1)) {
362 >                if (mapit)
363 >                        tmMapPixels((BYTE *)(qtL.rgb+li), qtL.brt+li,
364 >                                        (BYTE *)(qtL.chr+li), 1);
365 >                if (--rayqleft == 0)
366 >                        dev_flush();            /* flush output */
367 >        }
368   }
369  
370  
371   qtReplant()                     /* replant our tree using new view */
372   {
373          register int    i;
374 <
375 <        if (bleaf == tleaf)             /* anything to replant? */
374 >                                        /* anything to replant? */
375 >        if (qtL.bl == qtL.tl)
376                  return;
377 <        qtFreeTree(0);                  /* blow the tree away */
378 <                                        /* now rebuild it */
379 <        for (i = bleaf; i != tleaf; ) {
380 <                addleaf(leafpile+i);
381 <                if (++i >= nleaves) i = 0;
377 >        qtFreeTree(0);                  /* blow the old tree away */
378 >                                        /* regrow it in new place */
379 >        for (i = qtL.bl; i != qtL.tl; ) {
380 >                putleaf(i, 0);
381 >                if (++i >= qtL.nl) i = 0;
382          }
314        tmComputeMapping(0., 0., 0.);   /* update the display */
315        qtUpdate();
383   }
384  
385  
386 < static
387 < redraw(ca, tp, x0, y0, x1, y1, l)       /* redraw portion of a tree */
321 < BYTE    ca[3];          /* returned average color */
322 < register RTREE  *tp;
323 < int     x0, y0, x1, y1;
324 < int     l[2][2];
386 > qtMapLeaves(redo)               /* map our leaves to RGB */
387 > int     redo;
388   {
389 <        int     csm[3], nc;
390 <        BYTE    rgb[3];
391 <        int     quads = CH_ANY;
392 <        int     mx, my;
393 <        register int    i;
394 <                                        /* compute midpoint */
395 <        mx = (x0 + x1) >> 1;
396 <        my = (y0 + y1) >> 1;
397 <                                        /* see what to do */
398 <        if (l[0][0] >= mx)
399 <                quads &= ~(CHF(2)|CHF(0));
400 <        else if (l[0][1] <= mx)
338 <                quads &= ~(CHF(3)|CHF(1));
339 <        if (l[1][0] >= my)
340 <                quads &= ~(CHF(1)|CHF(0));
341 <        else if (l[1][1] <= my)
342 <                quads &= ~(CHF(3)|CHF(2));
343 <        tp->flgs &= ~quads;             /* mark them done */
344 <        csm[0] = csm[1] = csm[2] = nc = 0;
345 <                                        /* do leaves first */
346 <        for (i = 0; i < 4; i++)
347 <                if (quads & CHF(i) && !(tp->flgs & BRF(i)) &&
348 <                                tp->k[i].l != NULL) {
349 <                        tmMapPixels(rgb, &tp->k[i].l->brt, tp->k[i].l->chr, 1);
350 <                        dev_paintr(rgb, i&01 ? mx : x0, i&02 ? my : y0,
351 <                                        i&01 ? x1 : mx, i&02 ? y1 : my);
352 <                        csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2];
353 <                        nc++;
354 <                        quads &= ~CHF(i);
355 <                }
356 <                                        /* now do branches */
357 <        for (i = 0; i < 4; i++)
358 <                if (quads & CHF(i) && tp->flgs & BRF(i)) {
359 <                        redraw(rgb, tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0,
360 <                                        i&01 ? x1 : mx, i&02 ? y1 : my, l);
361 <                        csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2];
362 <                        nc++;
363 <                        quads &= ~CHF(i);
364 <                }
365 <        if (nc > 1) {
366 <                ca[0] = csm[0]/nc; ca[1] = csm[1]/nc; ca[2] = csm[2]/nc;
389 >        int     aorg, alen, borg, blen;
390 >                                        /* recompute mapping? */
391 >        if (redo)
392 >                qtL.tml = qtL.bl;
393 >                                        /* already done? */
394 >        if (qtL.tml == qtL.tl)
395 >                return(1);
396 >                                        /* compute segments */
397 >        aorg = qtL.tml;
398 >        if (qtL.tl >= aorg) {
399 >                alen = qtL.tl - aorg;
400 >                blen = 0;
401          } else {
402 <                ca[0] = csm[0]; ca[1] = csm[1]; ca[2] = csm[2];
402 >                alen = qtL.nl - aorg;
403 >                borg = 0;
404 >                blen = qtL.tl;
405          }
406 <        if (!quads) return;
407 <                                        /* fill in gaps with average */
408 <        for (i = 0; i < 4; i++)
409 <                if (quads & CHF(i))
410 <                        dev_paintr(ca, i&01 ? mx : x0, i&02 ? my : y0,
411 <                                        i&01 ? x1 : mx, i&02 ? y1 : my);
376 < }
377 <
378 <
379 < static
380 < update(ca, tp, x0, y0, x1, y1)  /* update tree display as needed */
381 < BYTE    ca[3];          /* returned average color */
382 < register RTREE  *tp;
383 < int     x0, y0, x1, y1;
384 < {
385 <        int     csm[3], nc;
386 <        BYTE    rgb[3];
387 <        int     gaps = 0;
388 <        int     mx, my;
389 <        register int    i;
390 <                                        /* compute midpoint */
391 <        mx = (x0 + x1) >> 1;
392 <        my = (y0 + y1) >> 1;
393 <        csm[0] = csm[1] = csm[2] = nc = 0;
394 <                                        /* do leaves first */
395 <        for (i = 0; i < 4; i++)
396 <                if ((tp->flgs & CHBRF(i)) == CHF(i)) {
397 <                        if (tp->k[i].l == NULL) {
398 <                                gaps |= 1<<i;   /* empty stem */
399 <                                continue;
400 <                        }
401 <                        tmMapPixels(rgb, &tp->k[i].l->brt, tp->k[i].l->chr, 1);
402 <                        dev_paintr(rgb, i&01 ? mx : x0, i&02 ? my : y0,
403 <                                        i&01 ? x1 : mx, i&02 ? y1 : my);
404 <                        csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2];
405 <                        nc++;
406 <                }
407 <                                        /* now do branches */
408 <        for (i = 0; i < 4; i++)
409 <                if ((tp->flgs & CHBRF(i)) == CHBRF(i)) {
410 <                        update(rgb, tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0,
411 <                                        i&01 ? x1 : mx, i&02 ? y1 : my);
412 <                        csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2];
413 <                        nc++;
414 <                }
415 <        if (nc > 1) {
416 <                ca[0] = csm[0]/nc; ca[1] = csm[1]/nc; ca[2] = csm[2]/nc;
417 <        } else {
418 <                ca[0] = csm[0]; ca[1] = csm[1]; ca[2] = csm[2];
419 <        }
420 <                                        /* fill in gaps with average */
421 <        for (i = 0; gaps && i < 4; gaps >>= 1, i++)
422 <                if (gaps & 01)
423 <                        dev_paintr(ca, i&01 ? mx : x0, i&02 ? my : y0,
424 <                                        i&01 ? x1 : mx, i&02 ? y1 : my);
425 <        tp->flgs &= ~CH_ANY;            /* all done */
426 < }
427 <
428 <
429 < qtRedraw(x0, y0, x1, y1)        /* redraw part of our screen */
430 < int     x0, y0, x1, y1;
431 < {
432 <        int     lim[2][2];
433 <        BYTE    ca[3];
434 <
435 <        if (is_stump(&qtrunk))
436 <                return;
437 <        if ((lim[0][0]=x0) <= 0 & (lim[1][0]=y0) <= 0 &
438 <                (lim[0][1]=x1) >= odev.hres-1 & (lim[1][1]=y1) >= odev.vres-1
439 <                        || tmTop->lumap == NULL)
406 >                                        /* (re)compute tone mapping? */
407 >        if (qtL.tml == qtL.bl) {
408 >                tmClearHisto();
409 >                tmAddHisto(qtL.brt+aorg, alen, 1);
410 >                if (blen > 0)
411 >                        tmAddHisto(qtL.brt+borg, blen, 1);
412                  if (tmComputeMapping(0., 0., 0.) != TM_E_OK)
413 <                        return;
414 <        redraw(ca, &qtrunk, 0, 0, odev.hres, odev.vres, lim);
415 < }
416 <
417 <
418 < qtUpdate()                      /* update our tree display */
419 < {
420 <        BYTE    ca[3];
421 <
422 <        if (is_stump(&qtrunk))
451 <                return;
452 <        if (tmTop->lumap == NULL)
453 <                tmComputeMapping(0., 0., 0.);
454 <        update(ca, &qtrunk, 0, 0, odev.hres, odev.vres);
413 >                        return(0);
414 >        }
415 >        if (tmMapPixels((BYTE *)(qtL.rgb+aorg), qtL.brt+aorg,
416 >                        (BYTE *)(qtL.chr+aorg), alen) != TM_E_OK)
417 >                return(0);
418 >        if (blen > 0)
419 >                tmMapPixels((BYTE *)(qtL.rgb+borg), qtL.brt+borg,
420 >                                (BYTE *)(qtL.chr+borg), blen);
421 >        qtL.tml = qtL.tl;
422 >        return(1);
423   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines