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 |
+ |
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 |
|
|
44 |
< |
#define is_stump(t) (!((t)->flgs & (BR_ANY|LF_ANY))) |
44 |
> |
static RTREE *newtwig(void); |
45 |
> |
static void qtFreeTree(int really); |
46 |
> |
static void shaketree(RTREE *tp); |
47 |
> |
static int putleaf(int li, int drop); |
48 |
|
|
49 |
|
|
50 |
|
static RTREE * |
51 |
< |
newtwig() /* allocate a twig */ |
51 |
> |
newtwig(void) /* allocate a twig */ |
52 |
|
{ |
53 |
|
register int bi; |
54 |
|
|
60 |
|
} |
61 |
|
bi = nexttwig / TBUNDLESIZ; |
62 |
|
if (twigbundle[bi] == NULL) { /* new block */ |
63 |
< |
twigbundle = (RTREE **)realloc((char *)twigbundle, |
63 |
> |
twigbundle = (RTREE **)realloc((void *)twigbundle, |
64 |
|
(bi+2)*sizeof(RTREE *)); |
65 |
|
if (twigbundle == NULL) |
66 |
|
goto memerr; |
73 |
|
return(twigbundle[bi] + (nexttwig++ - bi*TBUNDLESIZ)); |
74 |
|
memerr: |
75 |
|
error(SYSTEM, "out of memory in newtwig"); |
76 |
+ |
return NULL; /* pro forma return */ |
77 |
|
} |
78 |
|
|
79 |
|
|
80 |
< |
qtFreeTree(really) /* free allocated twigs */ |
81 |
< |
int really; |
80 |
> |
static void |
81 |
> |
qtFreeTree( /* free allocated twigs */ |
82 |
> |
int really |
83 |
> |
) |
84 |
|
{ |
85 |
|
register int i; |
86 |
|
|
87 |
< |
qtrunk.flgs = CH_ANY; |
66 |
< |
nexttwig = 0; |
87 |
> |
qtrunk.flgs = CH_ANY; /* chop down tree */ |
88 |
|
if (twigbundle == NULL) |
89 |
|
return; |
90 |
+ |
i = (TBUNDLESIZ-1+nexttwig)/TBUNDLESIZ; |
91 |
+ |
nexttwig = 0; |
92 |
|
if (!really) { /* just clear allocated blocks */ |
93 |
< |
for (i = 0; twigbundle[i] != NULL; i++) |
94 |
< |
bzero((char *)twigbundle[i], TBUNDLESIZ*sizeof(RTREE)); |
93 |
> |
while (i--) |
94 |
> |
memset((char *)twigbundle[i], '\0', TBUNDLESIZ*sizeof(RTREE)); |
95 |
|
return; |
96 |
|
} |
97 |
|
/* else "really" means free up memory */ |
98 |
|
for (i = 0; twigbundle[i] != NULL; i++) |
99 |
< |
free((char *)twigbundle[i]); |
100 |
< |
free((char *)twigbundle); |
99 |
> |
free((void *)twigbundle[i]); |
100 |
> |
free((void *)twigbundle); |
101 |
|
twigbundle = NULL; |
102 |
|
} |
103 |
|
|
104 |
|
|
105 |
< |
static int |
106 |
< |
newleaf() /* allocate a leaf from our pile */ |
84 |
< |
{ |
85 |
< |
int li; |
86 |
< |
|
87 |
< |
li = qtL.tl++; |
88 |
< |
if (qtL.tl >= qtL.nl) /* get next leaf in ring */ |
89 |
< |
qtL.tl = 0; |
90 |
< |
if (qtL.tl == qtL.bl) /* need to shake some free */ |
91 |
< |
qtCompost(LFREEPCT); |
92 |
< |
return(li); |
93 |
< |
} |
105 |
> |
#define LEAFSIZ (3*sizeof(float)+sizeof(int32)+\ |
106 |
> |
sizeof(TMbright)+6*sizeof(BYTE)) |
107 |
|
|
108 |
< |
|
109 |
< |
#define LEAFSIZ (3*sizeof(float)+sizeof(TMbright)+6*sizeof(BYTE)) |
110 |
< |
|
111 |
< |
int |
99 |
< |
qtAllocLeaves(n) /* allocate space for n leaves */ |
100 |
< |
register int n; |
108 |
> |
extern int |
109 |
> |
qtAllocLeaves( /* allocate space for n leaves */ |
110 |
> |
register int n |
111 |
> |
) |
112 |
|
{ |
113 |
|
unsigned nbytes; |
114 |
|
register unsigned i; |
130 |
|
return(0); |
131 |
|
/* assign larger alignment types earlier */ |
132 |
|
qtL.wp = (float (*)[3])qtL.base; |
133 |
< |
qtL.brt = (TMbright *)(qtL.wp + n); |
133 |
> |
qtL.wd = (int32 *)(qtL.wp + n); |
134 |
> |
qtL.brt = (TMbright *)(qtL.wd + n); |
135 |
|
qtL.chr = (BYTE (*)[3])(qtL.brt + n); |
136 |
|
qtL.rgb = (BYTE (*)[3])(qtL.chr + n); |
137 |
|
qtL.nl = n; |
138 |
|
qtL.tml = qtL.bl = qtL.tl = 0; |
139 |
+ |
falleaves = -1; |
140 |
|
return(n); |
141 |
|
} |
142 |
|
|
143 |
|
#undef LEAFSIZ |
144 |
|
|
145 |
|
|
146 |
< |
qtFreeLeaves() /* free our allocated leaves and twigs */ |
146 |
> |
extern void |
147 |
> |
qtFreeLeaves(void) /* free our allocated leaves and twigs */ |
148 |
|
{ |
149 |
|
qtFreeTree(1); /* free tree also */ |
150 |
|
if (qtL.nl <= 0) |
155 |
|
} |
156 |
|
|
157 |
|
|
158 |
< |
static |
159 |
< |
shaketree(tp) /* shake dead leaves from tree */ |
160 |
< |
register RTREE *tp; |
158 |
> |
static void |
159 |
> |
shaketree( /* shake dead leaves from tree */ |
160 |
> |
register RTREE *tp |
161 |
> |
) |
162 |
|
{ |
163 |
|
register int i, li; |
164 |
|
|
169 |
|
tp->flgs &= ~BRF(i); |
170 |
|
} else if (tp->flgs & LFF(i)) { |
171 |
|
li = tp->k[i].li; |
172 |
< |
if (qtL.bl < qtL.tl ? |
158 |
< |
(li < qtL.bl || li >= qtL.tl) : |
159 |
< |
(li < qtL.bl && li >= qtL.tl)) |
172 |
> |
if (composted(li)) |
173 |
|
tp->flgs &= ~LFF(i); |
174 |
|
} |
175 |
|
} |
176 |
|
|
177 |
|
|
178 |
< |
int |
179 |
< |
qtCompost(pct) /* free up some leaves */ |
180 |
< |
int pct; |
178 |
> |
extern int |
179 |
> |
qtCompost( /* free up some leaves */ |
180 |
> |
int pct |
181 |
> |
) |
182 |
|
{ |
183 |
+ |
register int32 *fl; |
184 |
|
int nused, nclear, nmapped; |
170 |
– |
|
185 |
|
/* figure out how many leaves to clear */ |
186 |
|
nclear = qtL.nl * pct / 100; |
187 |
|
nused = qtL.tl - qtL.bl; |
192 |
|
if (nclear >= nused) { /* clear them all */ |
193 |
|
qtFreeTree(0); |
194 |
|
qtL.tml = qtL.bl = qtL.tl = 0; |
195 |
+ |
falleaves = -1; |
196 |
|
return(nused); |
197 |
|
} |
198 |
|
/* else clear leaves from bottom */ |
201 |
|
qtL.bl += nclear; |
202 |
|
if (qtL.bl >= qtL.nl) qtL.bl -= qtL.nl; |
203 |
|
if (nmapped <= nclear) qtL.tml = qtL.bl; |
204 |
< |
shaketree(&qtrunk); |
204 |
> |
shaketree(&qtrunk); /* dereference composted leaves */ |
205 |
> |
for (fl = &falleaves; *fl >= 0; fl = qtL.wd + *fl) |
206 |
> |
while (composted(*fl)) |
207 |
> |
if ((*fl = qtL.wd[*fl]) < 0) |
208 |
> |
return(nclear); |
209 |
|
return(nclear); |
210 |
|
} |
211 |
|
|
212 |
|
|
213 |
< |
int |
214 |
< |
qtFindLeaf(x, y) /* find closest leaf to (x,y) */ |
215 |
< |
int x, y; |
213 |
> |
extern int |
214 |
> |
qtFindLeaf( /* find closest leaf to (x,y) */ |
215 |
> |
int x, |
216 |
> |
int y |
217 |
> |
) |
218 |
|
{ |
219 |
|
register RTREE *tp = &qtrunk; |
220 |
|
int li = -1; |
249 |
|
} |
250 |
|
|
251 |
|
|
252 |
< |
static |
253 |
< |
addleaf(li) /* add a leaf to our tree */ |
254 |
< |
int li; |
252 |
> |
static int |
253 |
> |
putleaf( /* put a leaf in our tree */ |
254 |
> |
register int li, |
255 |
> |
int drop |
256 |
> |
) |
257 |
|
{ |
258 |
|
register RTREE *tp = &qtrunk; |
259 |
|
int x0=0, y0=0, x1=odev.hres, y1=odev.vres; |
260 |
< |
int lo = -1; |
260 |
> |
register int lo = -1; |
261 |
> |
double d2; |
262 |
|
int x, y, mx, my; |
263 |
|
double z; |
264 |
< |
FVECT ip, wp; |
264 |
> |
FVECT ip, wp, vd; |
265 |
|
register int q; |
266 |
< |
/* compute leaf location */ |
266 |
> |
/* check for dead leaf */ |
267 |
> |
if (!qtL.chr[li][1] && !(qtL.chr[li][0] | qtL.chr[li][2])) |
268 |
> |
return(0); |
269 |
> |
/* compute leaf location in view */ |
270 |
|
VCOPY(wp, qtL.wp[li]); |
271 |
|
viewloc(ip, &odev.v, wp); |
272 |
|
if (ip[2] <= 0. || ip[0] < 0. || ip[0] >= 1. |
273 |
|
|| ip[1] < 0. || ip[1] >= 1.) |
274 |
< |
return; |
274 |
> |
goto dropit; /* behind or outside view */ |
275 |
> |
#ifdef DEBUG |
276 |
> |
if (odev.v.type == VT_PAR | odev.v.vfore > FTINY) |
277 |
> |
error(INTERNAL, "bad view assumption in putleaf"); |
278 |
> |
#endif |
279 |
> |
for (q = 0; q < 3; q++) |
280 |
> |
vd[q] = (wp[q] - odev.v.vp[q])/ip[2]; |
281 |
> |
d2 = fdir2diff(qtL.wd[li], vd); |
282 |
> |
#ifdef MAXDIFF2 |
283 |
> |
if (d2 > MAXDIFF2) |
284 |
> |
goto dropit; /* leaf dir. too far off */ |
285 |
> |
#endif |
286 |
|
x = ip[0] * odev.hres; |
287 |
|
y = ip[1] * odev.vres; |
288 |
|
z = ip[2]; |
303 |
|
if (!(tp->flgs & LFF(q))) { /* found stem for leaf */ |
304 |
|
tp->k[q].li = li; |
305 |
|
tp->flgs |= CHLFF(q); |
306 |
< |
break; |
306 |
> |
return(1); |
307 |
|
} |
308 |
< |
/* check existing leaf */ |
271 |
< |
if (lo != tp->k[q].li) { |
308 |
> |
if (lo != tp->k[q].li) { /* check old leaf */ |
309 |
|
lo = tp->k[q].li; |
310 |
|
VCOPY(wp, qtL.wp[lo]); |
311 |
|
viewloc(ip, &odev.v, wp); |
312 |
|
} |
313 |
|
/* is node minimum size? */ |
314 |
< |
if (x1-x0 <= qtMinNodesiz || y1-y0 <= qtMinNodesiz) { |
315 |
< |
if (z > (1.-qtDepthEps)*ip[2]) /* who is closer? */ |
316 |
< |
return; /* old one is */ |
317 |
< |
tp->k[q].li = li; /* new one is */ |
314 |
> |
if (y1-y0 <= qtMinNodesiz || x1-x0 <= qtMinNodesiz) { |
315 |
> |
if (z > (1.+qtDepthEps)*ip[2]) |
316 |
> |
break; /* old one closer */ |
317 |
> |
if (z >= (1.-qtDepthEps)*ip[2] && |
318 |
> |
fdir2diff(qtL.wd[lo], vd) < d2) |
319 |
> |
break; /* old one better */ |
320 |
> |
tp->k[q].li = li; /* attach new */ |
321 |
|
tp->flgs |= CHF(q); |
322 |
+ |
li = lo; /* drop old... */ |
323 |
|
break; |
324 |
|
} |
325 |
|
tp->flgs &= ~LFF(q); /* else grow tree */ |
330 |
|
my = ip[1] * odev.vres; |
331 |
|
if (mx >= (x0 + x1) >> 1) q |= 01; |
332 |
|
if (my >= (y0 + y1) >> 1) q |= 02; |
333 |
+ |
tp->flgs = CH_ANY|LFF(q); /* all new */ |
334 |
|
tp->k[q].li = lo; |
293 |
– |
tp->flgs |= LFF(q)|CH_ANY; /* all new */ |
335 |
|
} |
336 |
+ |
dropit: |
337 |
+ |
if (drop) { |
338 |
+ |
if (li+1 == (qtL.tl ? qtL.tl : qtL.nl)) |
339 |
+ |
qtL.tl = li; /* special case */ |
340 |
+ |
else { |
341 |
+ |
qtL.chr[li][0] = qtL.chr[li][1] = qtL.chr[li][2] = 0; |
342 |
+ |
qtL.wd[li] = falleaves; |
343 |
+ |
falleaves = li; |
344 |
+ |
} |
345 |
+ |
} |
346 |
+ |
return(li == lo); |
347 |
|
} |
348 |
|
|
349 |
|
|
350 |
< |
dev_value(c, p) /* add a pixel value to our output queue */ |
351 |
< |
COLR c; |
352 |
< |
FVECT p; |
350 |
> |
extern void |
351 |
> |
dev_value( /* add a pixel value to our quadtree */ |
352 |
> |
COLR c, |
353 |
> |
FVECT d, |
354 |
> |
FVECT p |
355 |
> |
) |
356 |
|
{ |
357 |
|
register int li; |
358 |
< |
|
359 |
< |
li = newleaf(); |
360 |
< |
VCOPY(qtL.wp[li], p); |
361 |
< |
tmCvColrs(&qtL.brt[li], qtL.chr[li], c, 1); |
362 |
< |
addleaf(li); |
358 |
> |
int mapit; |
359 |
> |
/* grab a leaf */ |
360 |
> |
if (!imm_mode && falleaves >= 0) { /* check for fallen leaves */ |
361 |
> |
li = falleaves; |
362 |
> |
falleaves = qtL.wd[li]; |
363 |
> |
mapit = qtL.tml <= qtL.tl ? |
364 |
> |
(li < qtL.tml || li >= qtL.tl) : |
365 |
> |
(li < qtL.tml && li >= qtL.tl) ; |
366 |
> |
} else { /* else allocate new one */ |
367 |
> |
li = qtL.tl++; |
368 |
> |
if (qtL.tl >= qtL.nl) /* next leaf in ring */ |
369 |
> |
qtL.tl = 0; |
370 |
> |
if (qtL.tl == qtL.bl) /* need to shake some free */ |
371 |
> |
qtCompost(LFREEPCT); |
372 |
> |
mapit = 0; /* we'll map it later */ |
373 |
> |
} |
374 |
> |
if (p == NULL) |
375 |
> |
VSUM(qtL.wp[li], odev.v.vp, d, FHUGE); |
376 |
> |
else |
377 |
> |
VCOPY(qtL.wp[li], p); |
378 |
> |
qtL.wd[li] = encodedir(d); |
379 |
> |
tmCvColrs(&qtL.brt[li], qtL.chr[li], (COLR *)c, 1); |
380 |
> |
if (putleaf(li, 1)) { |
381 |
> |
if (mapit) |
382 |
> |
tmMapPixels((BYTE *)(qtL.rgb+li), qtL.brt+li, |
383 |
> |
(BYTE *)(qtL.chr+li), 1); |
384 |
> |
if (--rayqleft == 0) |
385 |
> |
dev_flush(); /* flush output */ |
386 |
> |
} |
387 |
|
} |
388 |
|
|
389 |
|
|
390 |
< |
qtReplant() /* replant our tree using new view */ |
390 |
> |
extern void |
391 |
> |
qtReplant(void) /* replant our tree using new view */ |
392 |
|
{ |
393 |
|
register int i; |
394 |
|
/* anything to replant? */ |
397 |
|
qtFreeTree(0); /* blow the old tree away */ |
398 |
|
/* regrow it in new place */ |
399 |
|
for (i = qtL.bl; i != qtL.tl; ) { |
400 |
< |
addleaf(i); |
400 |
> |
putleaf(i, 0); |
401 |
|
if (++i >= qtL.nl) i = 0; |
402 |
|
} |
403 |
|
} |
404 |
|
|
405 |
|
|
406 |
< |
qtMapLeaves(redo) /* map our leaves to RGB */ |
407 |
< |
int redo; |
406 |
> |
extern int |
407 |
> |
qtMapLeaves( /* map our leaves to RGB */ |
408 |
> |
int redo |
409 |
> |
) |
410 |
|
{ |
411 |
|
int aorg, alen, borg, blen; |
412 |
|
/* recompute mapping? */ |
434 |
|
if (tmComputeMapping(0., 0., 0.) != TM_E_OK) |
435 |
|
return(0); |
436 |
|
} |
437 |
< |
if (tmMapPixels(qtL.rgb+aorg, qtL.brt+aorg, |
438 |
< |
qtL.chr+aorg, alen) != TM_E_OK) |
437 |
> |
if (tmMapPixels((BYTE *)(qtL.rgb+aorg), qtL.brt+aorg, |
438 |
> |
(BYTE *)(qtL.chr+aorg), alen) != TM_E_OK) |
439 |
|
return(0); |
440 |
|
if (blen > 0) |
441 |
< |
tmMapPixels(qtL.rgb+borg, qtL.brt+borg, |
442 |
< |
qtL.chr+borg, blen); |
441 |
> |
tmMapPixels((BYTE *)(qtL.rgb+borg), qtL.brt+borg, |
442 |
> |
(BYTE *)(qtL.chr+borg), blen); |
443 |
|
qtL.tml = qtL.tl; |
444 |
|
return(1); |
363 |
– |
} |
364 |
– |
|
365 |
– |
|
366 |
– |
static |
367 |
– |
redraw(ca, tp, x0, y0, x1, y1, l) /* redraw portion of a tree */ |
368 |
– |
BYTE ca[3]; /* returned average color */ |
369 |
– |
register RTREE *tp; |
370 |
– |
int x0, y0, x1, y1; |
371 |
– |
int l[2][2]; |
372 |
– |
{ |
373 |
– |
int csm[3], nc; |
374 |
– |
register BYTE *cp; |
375 |
– |
BYTE rgb[3]; |
376 |
– |
int quads = CH_ANY; |
377 |
– |
int mx, my; |
378 |
– |
register int i; |
379 |
– |
/* compute midpoint */ |
380 |
– |
mx = (x0 + x1) >> 1; |
381 |
– |
my = (y0 + y1) >> 1; |
382 |
– |
/* see what to do */ |
383 |
– |
if (l[0][0] >= mx) |
384 |
– |
quads &= ~(CHF(2)|CHF(0)); |
385 |
– |
else if (l[0][1] <= mx) |
386 |
– |
quads &= ~(CHF(3)|CHF(1)); |
387 |
– |
if (l[1][0] >= my) |
388 |
– |
quads &= ~(CHF(1)|CHF(0)); |
389 |
– |
else if (l[1][1] <= my) |
390 |
– |
quads &= ~(CHF(3)|CHF(2)); |
391 |
– |
tp->flgs &= ~quads; /* mark them done */ |
392 |
– |
csm[0] = csm[1] = csm[2] = nc = 0; |
393 |
– |
/* do leaves first */ |
394 |
– |
for (i = 0; i < 4; i++) |
395 |
– |
if (quads & CHF(i) && tp->flgs & LFF(i)) { |
396 |
– |
dev_paintr(cp=qtL.rgb[tp->k[i].li], |
397 |
– |
i&01 ? mx : x0, i&02 ? my : y0, |
398 |
– |
i&01 ? x1 : mx, i&02 ? y1 : my); |
399 |
– |
csm[0] += cp[0]; csm[1] += cp[1]; csm[2] += cp[2]; |
400 |
– |
nc++; |
401 |
– |
quads &= ~CHF(i); |
402 |
– |
} |
403 |
– |
/* now do branches */ |
404 |
– |
for (i = 0; i < 4; i++) |
405 |
– |
if (quads & CHF(i) && tp->flgs & BRF(i)) { |
406 |
– |
redraw(rgb, tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0, |
407 |
– |
i&01 ? x1 : mx, i&02 ? y1 : my, l); |
408 |
– |
csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2]; |
409 |
– |
nc++; |
410 |
– |
quads &= ~CHF(i); |
411 |
– |
} |
412 |
– |
if (nc > 1) { |
413 |
– |
ca[0] = csm[0]/nc; ca[1] = csm[1]/nc; ca[2] = csm[2]/nc; |
414 |
– |
} else { |
415 |
– |
ca[0] = csm[0]; ca[1] = csm[1]; ca[2] = csm[2]; |
416 |
– |
} |
417 |
– |
if (!quads) return; |
418 |
– |
/* fill in gaps with average */ |
419 |
– |
for (i = 0; i < 4; i++) |
420 |
– |
if (quads & CHF(i)) |
421 |
– |
dev_paintr(ca, i&01 ? mx : x0, i&02 ? my : y0, |
422 |
– |
i&01 ? x1 : mx, i&02 ? y1 : my); |
423 |
– |
} |
424 |
– |
|
425 |
– |
|
426 |
– |
static |
427 |
– |
update(ca, tp, x0, y0, x1, y1) /* update tree display as needed */ |
428 |
– |
BYTE ca[3]; /* returned average color */ |
429 |
– |
register RTREE *tp; |
430 |
– |
int x0, y0, x1, y1; |
431 |
– |
{ |
432 |
– |
int csm[3], nc; |
433 |
– |
register BYTE *cp; |
434 |
– |
BYTE rgb[3]; |
435 |
– |
int gaps = 0; |
436 |
– |
int mx, my; |
437 |
– |
register int i; |
438 |
– |
/* compute midpoint */ |
439 |
– |
mx = (x0 + x1) >> 1; |
440 |
– |
my = (y0 + y1) >> 1; |
441 |
– |
csm[0] = csm[1] = csm[2] = nc = 0; |
442 |
– |
/* do leaves first */ |
443 |
– |
for (i = 0; i < 4; i++) { |
444 |
– |
if (!(tp->flgs & CHF(i))) |
445 |
– |
continue; |
446 |
– |
if (tp->flgs & LFF(i)) { |
447 |
– |
dev_paintr(cp=qtL.rgb[tp->k[i].li], |
448 |
– |
i&01 ? mx : x0, i&02 ? my : y0, |
449 |
– |
i&01 ? x1 : mx, i&02 ? y1 : my); |
450 |
– |
csm[0] += cp[0]; csm[1] += cp[1]; csm[2] += cp[2]; |
451 |
– |
nc++; |
452 |
– |
} else if (!(tp->flgs & BRF(i))) |
453 |
– |
gaps |= 1<<i; /* empty stem */ |
454 |
– |
} |
455 |
– |
/* now do branches */ |
456 |
– |
for (i = 0; i < 4; i++) |
457 |
– |
if ((tp->flgs & CHBRF(i)) == CHBRF(i)) { |
458 |
– |
update(rgb, tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0, |
459 |
– |
i&01 ? x1 : mx, i&02 ? y1 : my); |
460 |
– |
csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2]; |
461 |
– |
nc++; |
462 |
– |
} |
463 |
– |
if (nc > 1) { |
464 |
– |
ca[0] = csm[0]/nc; ca[1] = csm[1]/nc; ca[2] = csm[2]/nc; |
465 |
– |
} else { |
466 |
– |
ca[0] = csm[0]; ca[1] = csm[1]; ca[2] = csm[2]; |
467 |
– |
} |
468 |
– |
/* fill in gaps with average */ |
469 |
– |
for (i = 0; gaps && i < 4; gaps >>= 1, i++) |
470 |
– |
if (gaps & 01) |
471 |
– |
dev_paintr(ca, i&01 ? mx : x0, i&02 ? my : y0, |
472 |
– |
i&01 ? x1 : mx, i&02 ? y1 : my); |
473 |
– |
tp->flgs &= ~CH_ANY; /* all done */ |
474 |
– |
} |
475 |
– |
|
476 |
– |
|
477 |
– |
qtRedraw(x0, y0, x1, y1) /* redraw part or all of our screen */ |
478 |
– |
int x0, y0, x1, y1; |
479 |
– |
{ |
480 |
– |
int lim[2][2]; |
481 |
– |
BYTE ca[3]; |
482 |
– |
|
483 |
– |
if (is_stump(&qtrunk)) |
484 |
– |
return; |
485 |
– |
if (!qtMapLeaves((lim[0][0]=x0) <= 0 & (lim[1][0]=y0) <= 0 & |
486 |
– |
(lim[0][1]=x1) >= odev.hres-1 & (lim[1][1]=y1) >= odev.vres-1)) |
487 |
– |
return; |
488 |
– |
redraw(ca, &qtrunk, 0, 0, odev.hres, odev.vres, lim); |
489 |
– |
} |
490 |
– |
|
491 |
– |
|
492 |
– |
qtUpdate() /* update our tree display */ |
493 |
– |
{ |
494 |
– |
BYTE ca[3]; |
495 |
– |
|
496 |
– |
if (is_stump(&qtrunk)) |
497 |
– |
return; |
498 |
– |
if (!qtMapLeaves(0)) |
499 |
– |
return; |
500 |
– |
update(ca, &qtrunk, 0, 0, odev.hres, odev.vres); |
445 |
|
} |