| 25 |
|
static RTREE **twigbundle; /* free twig blocks (NULL term.) */ |
| 26 |
|
static int nexttwig; /* next free twig */ |
| 27 |
|
|
| 28 |
– |
#define is_stump(t) (!((t)->flgs & (BR_ANY|LF_ANY))) |
| 28 |
|
|
| 30 |
– |
|
| 29 |
|
static RTREE * |
| 30 |
|
newtwig() /* allocate a twig */ |
| 31 |
|
{ |
| 294 |
|
} |
| 295 |
|
|
| 296 |
|
|
| 297 |
< |
dev_value(c, p) /* add a pixel value to our output queue */ |
| 297 |
> |
dev_value(c, p) /* add a pixel value to our quadtree */ |
| 298 |
|
COLR c; |
| 299 |
|
FVECT p; |
| 300 |
|
{ |
| 359 |
|
qtL.chr+borg, blen); |
| 360 |
|
qtL.tml = qtL.tl; |
| 361 |
|
return(1); |
| 364 |
– |
} |
| 365 |
– |
|
| 366 |
– |
|
| 367 |
– |
static |
| 368 |
– |
redraw(tp, x0, y0, x1, y1, l) /* mark portion of a tree for redraw */ |
| 369 |
– |
register RTREE *tp; |
| 370 |
– |
int x0, y0, x1, y1; |
| 371 |
– |
int l[2][2]; |
| 372 |
– |
{ |
| 373 |
– |
int quads = CH_ANY; |
| 374 |
– |
int mx, my; |
| 375 |
– |
register int i; |
| 376 |
– |
/* compute midpoint */ |
| 377 |
– |
mx = (x0 + x1) >> 1; |
| 378 |
– |
my = (y0 + y1) >> 1; |
| 379 |
– |
/* see what to do */ |
| 380 |
– |
if (l[0][0] >= mx) |
| 381 |
– |
quads &= ~(CHF(2)|CHF(0)); |
| 382 |
– |
else if (l[0][1] < mx) |
| 383 |
– |
quads &= ~(CHF(3)|CHF(1)); |
| 384 |
– |
if (l[1][0] >= my) |
| 385 |
– |
quads &= ~(CHF(1)|CHF(0)); |
| 386 |
– |
else if (l[1][1] < my) |
| 387 |
– |
quads &= ~(CHF(3)|CHF(2)); |
| 388 |
– |
tp->flgs |= quads; /* mark quadrants for update */ |
| 389 |
– |
/* climb the branches */ |
| 390 |
– |
for (i = 0; i < 4; i++) |
| 391 |
– |
if (tp->flgs & BRF(i) && quads & CHF(i)) |
| 392 |
– |
redraw(tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0, |
| 393 |
– |
i&01 ? x1 : mx, i&02 ? y1 : my, l); |
| 394 |
– |
} |
| 395 |
– |
|
| 396 |
– |
|
| 397 |
– |
static |
| 398 |
– |
update(ca, tp, x0, y0, x1, y1) /* update tree display as needed */ |
| 399 |
– |
BYTE ca[3]; /* returned average color */ |
| 400 |
– |
register RTREE *tp; |
| 401 |
– |
int x0, y0, x1, y1; |
| 402 |
– |
{ |
| 403 |
– |
int csm[3], nc; |
| 404 |
– |
register BYTE *cp; |
| 405 |
– |
BYTE rgb[3]; |
| 406 |
– |
int gaps = 0; |
| 407 |
– |
int mx, my; |
| 408 |
– |
register int i; |
| 409 |
– |
/* compute midpoint */ |
| 410 |
– |
mx = (x0 + x1) >> 1; |
| 411 |
– |
my = (y0 + y1) >> 1; |
| 412 |
– |
csm[0] = csm[1] = csm[2] = nc = 0; |
| 413 |
– |
/* do leaves first */ |
| 414 |
– |
for (i = 0; i < 4; i++) { |
| 415 |
– |
if (tp->flgs & LFF(i)) { |
| 416 |
– |
cp = qtL.rgb[tp->k[i].li]; |
| 417 |
– |
csm[0] += cp[0]; csm[1] += cp[1]; csm[2] += cp[2]; |
| 418 |
– |
nc++; |
| 419 |
– |
if (tp->flgs & CHF(i)) |
| 420 |
– |
dev_paintr(cp, i&01 ? mx : x0, i&02 ? my : y0, |
| 421 |
– |
i&01 ? x1 : mx, i&02 ? y1 : my); |
| 422 |
– |
} else if ((tp->flgs & CHBRF(i)) == CHF(i)) |
| 423 |
– |
gaps |= 1<<i; /* empty stem */ |
| 424 |
– |
} |
| 425 |
– |
/* now do branches */ |
| 426 |
– |
for (i = 0; i < 4; i++) |
| 427 |
– |
if ((tp->flgs & CHBRF(i)) == CHBRF(i)) { |
| 428 |
– |
update(rgb, tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0, |
| 429 |
– |
i&01 ? x1 : mx, i&02 ? y1 : my); |
| 430 |
– |
csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2]; |
| 431 |
– |
nc++; |
| 432 |
– |
} |
| 433 |
– |
if (nc > 1) { |
| 434 |
– |
ca[0] = csm[0]/nc; ca[1] = csm[1]/nc; ca[2] = csm[2]/nc; |
| 435 |
– |
} else { |
| 436 |
– |
ca[0] = csm[0]; ca[1] = csm[1]; ca[2] = csm[2]; |
| 437 |
– |
} |
| 438 |
– |
/* fill in gaps with average */ |
| 439 |
– |
for (i = 0; gaps && i < 4; gaps >>= 1, i++) |
| 440 |
– |
if (gaps & 01) |
| 441 |
– |
dev_paintr(ca, i&01 ? mx : x0, i&02 ? my : y0, |
| 442 |
– |
i&01 ? x1 : mx, i&02 ? y1 : my); |
| 443 |
– |
tp->flgs &= ~CH_ANY; /* all done */ |
| 444 |
– |
} |
| 445 |
– |
|
| 446 |
– |
|
| 447 |
– |
qtRedraw(x0, y0, x1, y1) /* redraw part or all of our screen */ |
| 448 |
– |
int x0, y0, x1, y1; |
| 449 |
– |
{ |
| 450 |
– |
int lim[2][2]; |
| 451 |
– |
|
| 452 |
– |
if (is_stump(&qtrunk)) |
| 453 |
– |
return; |
| 454 |
– |
if (!qtMapLeaves((lim[0][0]=x0) <= 0 & (lim[1][0]=y0) <= 0 & |
| 455 |
– |
(lim[0][1]=x1) >= odev.hres-1 & (lim[1][1]=y1) >= odev.vres-1)) |
| 456 |
– |
return; |
| 457 |
– |
redraw(&qtrunk, 0, 0, odev.hres, odev.vres, lim); |
| 458 |
– |
} |
| 459 |
– |
|
| 460 |
– |
|
| 461 |
– |
qtUpdate() /* update our tree display */ |
| 462 |
– |
{ |
| 463 |
– |
BYTE ca[3]; |
| 464 |
– |
|
| 465 |
– |
if (is_stump(&qtrunk)) |
| 466 |
– |
return; |
| 467 |
– |
if (!qtMapLeaves(0)) |
| 468 |
– |
return; |
| 469 |
– |
update(ca, &qtrunk, 0, 0, odev.hres, odev.vres); |
| 362 |
|
} |