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.3 by gregl, Thu Nov 20 18:03:43 1997 UTC vs.
Revision 3.18 by gwlarson, Mon Aug 10 18:39:46 1998 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines