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.1 by gregl, Wed Nov 19 18:01:03 1997 UTC vs.
Revision 3.17 by gregl, Thu Jan 1 13:00:15 1998 UTC

# 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 < static RLEAF    *leafpile;      /* our collection of leaf values */
15 < static int      nleaves;        /* count of leaves in our pile */
16 < static int      bleaf, tleaf;   /* bottom and top (next) leaf index (ring) */
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 + 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 58 | Line 72 | memerr:
72   }
73  
74  
75 < static
62 < freetwigs(really)               /* free allocated twigs */
75 > qtFreeTree(really)              /* free allocated twigs */
76   int     really;
77   {
78          register int    i;
79  
80 <        if (tmTop != NULL)
68 <                tmClearHisto();
69 <        bzero((char *)&qtrunk, sizeof(RTREE));
70 <        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 83 | Line 95 | int    really;
95   }
96  
97  
98 < static RLEAF *
99 < newleaf()                       /* allocate a leaf from our pile */
88 < {
89 <        if (tleaf++ >= nleaves)         /* get next leaf in ring */
90 <                tleaf = 0;
91 <        if (tleaf == bleaf)             /* need to shake some free */
92 <                qtCompost(LFREEPCT);
93 <        return(leafpile + tleaf);
94 < }
98 > #define LEAFSIZ         (3*sizeof(float)+sizeof(int4)+\
99 >                        sizeof(TMbright)+6*sizeof(BYTE))
100  
96
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;
107  
108 <        freetwigs(0);           /* make sure tree is empty */
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 <        freetwigs(1);           /* free tree also */
141 <        if (nleaves <= 0)
140 >        qtFreeTree(1);          /* free tree also */
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 141 | Line 154 | register RTREE *tp;
154  
155          for (i = 0; i < 4; i++)
156                  if (tp->flgs & BRF(i)) {
157 <                        if (shaketree(tp->k[i].b))
158 <                                tp->flgs |= CHF(i);
159 <                } else if (tp->k[i].l != NULL) {
160 <                        li = tp->k[i].l - leafpile;
161 <                        if (bleaf < tleaf ? (li < bleaf || li >= tleaf) :
162 <                                        (li < bleaf && li >= tleaf)) {
163 <                                tmAddHisto(&tp->k[i].l->brt, 1, -1);
151 <                                tp->k[i].l = NULL;
152 <                                tp->flgs |= CHF(i);
153 <                        }
157 >                        shaketree(tp->k[i].b);
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                  }
155        return(tp->flgs & CH_ANY);
165   }
166  
167  
# Line 160 | 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);
168        nused = tleaf > bleaf ? tleaf-bleaf : tleaf+nleaves-bleaf;
181          if (nclear >= nused) {  /* clear them all */
182 <                freetwigs(0);
183 <                bleaf = tleaf = 0;
182 >                qtFreeTree(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 + int
203 + qtFindLeaf(x, y)                /* find closest leaf to (x,y) */
204 + int     x, y;
205 + {
206 +        register RTREE  *tp = &qtrunk;
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(-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 & LFF(q)) {
218 +                                li = tp->k[q].li;
219 +                                break;
220 +                        }
221 +                q = 0;                          /* which quadrant are we? */
222 +                mx = (x0 + x1) >> 1;
223 +                my = (y0 + y1) >> 1;
224 +                if (x < mx) x1 = mx;
225 +                else {x0 = mx; q |= 01;}
226 +                if (y < my) y1 = my;
227 +                else {y0 = my; q |= 02;}
228 +                if (tp->flgs & BRF(q)) {        /* branch down if not a leaf */
229 +                        tp = tp->k[q].b;
230 +                        continue;
231 +                }
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 212 | 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;
223 <                        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();
237                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, p, v)              /* add a pixel value to our quadtree */
336   COLR    c;
337 < FVECT   p;
337 > FVECT   p, v;
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 >        VCOPY(qtL.wp[li], p);
357 >        qtL.wd[li] = encodedir(v);
358 >        tmCvColrs(&qtL.brt[li], qtL.chr[li], c, 1);
359 >        if (putleaf(li, 1)) {
360 >                if (mapit)
361 >                        tmMapPixels(qtL.rgb+li, qtL.brt+li, qtL.chr+li, 1);
362 >                if (--rayqleft == 0)
363 >                        dev_flush();            /* flush output */
364 >        }
365   }
366  
367  
368   qtReplant()                     /* replant our tree using new view */
369   {
370          register int    i;
371 <
372 <        if (bleaf == tleaf)             /* anything to replant? */
371 >                                        /* anything to replant? */
372 >        if (qtL.bl == qtL.tl)
373                  return;
374 <        freetwigs(0);                   /* blow the tree away */
375 <                                        /* now rebuild it */
376 <        for (i = bleaf; i != tleaf; ) {
377 <                addleaf(leafpile+i);
378 <                if (++i >= nleaves) i = 0;
374 >        qtFreeTree(0);                  /* blow the old tree away */
375 >                                        /* regrow it in new place */
376 >        for (i = qtL.bl; i != qtL.tl; ) {
377 >                putleaf(i, 0);
378 >                if (++i >= qtL.nl) i = 0;
379          }
274        tmComputeMapping(0., 0., 0.);   /* update the display */
275        qtUpdate();
380   }
381  
382  
383 < static
384 < redraw(ca, tp, x0, y0, x1, y1, l)       /* redraw portion of a tree */
281 < BYTE    ca[3];          /* returned average color */
282 < register RTREE  *tp;
283 < int     x0, y0, x1, y1;
284 < int     l[2][2];
383 > qtMapLeaves(redo)               /* map our leaves to RGB */
384 > int     redo;
385   {
386 <        int     csm[3], nc;
387 <        BYTE    rgb[3];
388 <        int     quads = CH_ANY;
389 <        int     mx, my;
390 <        register int    i;
391 <                                        /* compute midpoint */
392 <        mx = (x0 + x1) >> 1;
393 <        my = (y0 + y1) >> 1;
394 <                                        /* see what to do */
395 <        if (l[0][0] >= mx)
396 <                quads &= ~(CHF(2)|CHF(0));
397 <        else if (l[0][1] <= mx)
298 <                quads &= ~(CHF(3)|CHF(1));
299 <        if (l[1][0] >= my)
300 <                quads &= ~(CHF(1)|CHF(0));
301 <        else if (l[1][1] <= my)
302 <                quads &= ~(CHF(3)|CHF(2));
303 <        tp->flgs &= ~quads;             /* mark them done */
304 <        csm[0] = csm[1] = csm[2] = nc = 0;
305 <                                        /* do leaves first */
306 <        for (i = 0; i < 4; i++)
307 <                if (quads & CHF(i) && !(tp->flgs & BRF(i)) &&
308 <                                tp->k[i].l != NULL) {
309 <                        tmMapPixels(rgb, &tp->k[i].l->brt, tp->k[i].l->chr, 1);
310 <                        dev_paintr(rgb, i&01 ? mx : x0, i&02 ? my : y0,
311 <                                        i&01 ? x1 : mx, i&02 ? y1 : my);
312 <                        csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2];
313 <                        nc++;
314 <                        quads &= ~CHF(i);
315 <                }
316 <                                        /* now do branches */
317 <        for (i = 0; i < 4; i++)
318 <                if (quads & CHF(i) && tp->flgs & BRF(i)) {
319 <                        redraw(rgb, tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0,
320 <                                        i&01 ? x1 : mx, i&02 ? y1 : my, l);
321 <                        csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2];
322 <                        nc++;
323 <                        quads &= ~CHF(i);
324 <                }
325 <        if (nc > 1) {
326 <                ca[0] = csm[0]/nc; ca[1] = csm[1]/nc; ca[2] = csm[2]/nc;
386 >        int     aorg, alen, borg, blen;
387 >                                        /* recompute mapping? */
388 >        if (redo)
389 >                qtL.tml = qtL.bl;
390 >                                        /* already done? */
391 >        if (qtL.tml == qtL.tl)
392 >                return(1);
393 >                                        /* compute segments */
394 >        aorg = qtL.tml;
395 >        if (qtL.tl >= aorg) {
396 >                alen = qtL.tl - aorg;
397 >                blen = 0;
398          } else {
399 <                ca[0] = csm[0]; ca[1] = csm[1]; ca[2] = csm[2];
399 >                alen = qtL.nl - aorg;
400 >                borg = 0;
401 >                blen = qtL.tl;
402          }
403 <        if (!quads) return;
404 <                                        /* fill in gaps with average */
405 <        for (i = 0; i < 4; i++)
406 <                if (quads & CHF(i))
407 <                        dev_paintr(ca, i&01 ? mx : x0, i&02 ? my : y0,
408 <                                        i&01 ? x1 : mx, i&02 ? y1 : my);
409 < }
410 <
338 <
339 < static
340 < update(ca, tp, x0, y0, x1, y1)  /* update tree display as needed */
341 < BYTE    ca[3];          /* returned average color */
342 < register RTREE  *tp;
343 < int     x0, y0, x1, y1;
344 < {
345 <        int     csm[3], nc;
346 <        BYTE    rgb[3];
347 <        int     gaps = 0;
348 <        int     mx, my;
349 <        register int    i;
350 <                                        /* compute midpoint */
351 <        mx = (x0 + x1) >> 1;
352 <        my = (y0 + y1) >> 1;
353 <        csm[0] = csm[1] = csm[2] = nc = 0;
354 <                                        /* do leaves first */
355 <        for (i = 0; i < 4; i++)
356 <                if ((tp->flgs & CHBRF(i)) == CHF(i)) {
357 <                        if (tp->k[i].l == NULL) {
358 <                                gaps |= 1<<i;   /* empty stem */
359 <                                continue;
360 <                        }
361 <                        tmMapPixels(rgb, &tp->k[i].l->brt, tp->k[i].l->chr, 1);
362 <                        dev_paintr(rgb, i&01 ? mx : x0, i&02 ? my : y0,
363 <                                        i&01 ? x1 : mx, i&02 ? y1 : my);
364 <                        csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2];
365 <                        nc++;
366 <                }
367 <                                        /* now do branches */
368 <        for (i = 0; i < 4; i++)
369 <                if ((tp->flgs & CHBRF(i)) == CHBRF(i)) {
370 <                        update(rgb, tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0,
371 <                                        i&01 ? x1 : mx, i&02 ? y1 : my);
372 <                        csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2];
373 <                        nc++;
374 <                }
375 <        if (nc > 1) {
376 <                ca[0] = csm[0]/nc; ca[1] = csm[1]/nc; ca[2] = csm[2]/nc;
377 <        } else {
378 <                ca[0] = csm[0]; ca[1] = csm[1]; ca[2] = csm[2];
403 >                                        /* (re)compute tone mapping? */
404 >        if (qtL.tml == qtL.bl) {
405 >                tmClearHisto();
406 >                tmAddHisto(qtL.brt+aorg, alen, 1);
407 >                if (blen > 0)
408 >                        tmAddHisto(qtL.brt+borg, blen, 1);
409 >                if (tmComputeMapping(0., 0., 0.) != TM_E_OK)
410 >                        return(0);
411          }
412 <                                        /* fill in gaps with average */
413 <        for (i = 0; gaps && i < 4; gaps >>= 1, i++)
414 <                if (gaps & 01)
415 <                        dev_paintr(ca, i&01 ? mx : x0, i&02 ? my : y0,
416 <                                        i&01 ? x1 : mx, i&02 ? y1 : my);
417 <        tp->flgs &= ~CH_ANY;            /* all done */
418 < }
419 <
388 <
389 < qtRedraw(x0, y0, x1, y1)        /* redraw part of our screen */
390 < int     x0, y0, x1, y1;
391 < {
392 <        int     lim[2][2];
393 <        BYTE    ca[3];
394 <
395 <        if (is_stump(&qtrunk))
396 <                return;
397 <        if ((lim[0][0]=x0) == 0 & (lim[1][0]=y0) == 0 &
398 <                (lim[0][1]=x1) == odev.hres & (lim[1][1]=y1) == odev.vres ||
399 <                        tmTop->lumap == NULL)
400 <                tmComputeMapping(0., 0., 0.);
401 <        redraw(ca, &qtrunk, 0, 0, odev.hres, odev.vres, lim);
402 < }
403 <
404 <
405 < qtUpdate()                      /* update our tree display */
406 < {
407 <        BYTE    ca[3];
408 <
409 <        if (is_stump(&qtrunk))
410 <                return;
411 <        if (tmTop->lumap == NULL)
412 <                tmComputeMapping(0., 0., 0.);
413 <        update(ca, &qtrunk, 0, 0, odev.hres, odev.vres);
412 >        if (tmMapPixels(qtL.rgb+aorg, qtL.brt+aorg,
413 >                        qtL.chr+aorg, alen) != TM_E_OK)
414 >                return(0);
415 >        if (blen > 0)
416 >                tmMapPixels(qtL.rgb+borg, qtL.brt+borg,
417 >                                qtL.chr+borg, blen);
418 >        qtL.tml = qtL.tl;
419 >        return(1);
420   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines