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

Comparing ray/src/px/closest.c (file contents):
Revision 1.2 by greg, Thu Feb 2 14:10:34 1989 UTC vs.
Revision 1.3 by ph, Fri Apr 7 16:36:15 1989 UTC

# Line 18 | Line 18 | Paul Heckbert
18   #include "ciq.h"
19  
20   #define inf 3*256*256
21 < #define key ((r&0xe0)<<1|(g&0xe0)>>2|(b&0xe0)>>5)    /* hash key: rrrgggbbb */
21 > #define key(r,g,b) (((r)&0xe0)<<1|((g)&0xe0)>>2|((b)&0xe0)>>5)  
22 >    /* 9-bit hash key: rrrgggbbb */
23  
24 < static struct thing {int mindist,pv;} space[512*257],*next=space,*bucket[512];
24 > static struct thing {int mindist,pv;} space[512*257],*next,*bucket[512];
25                                          /* sorted lists of colors */
26  
27 < static int nfill=0,tests=0,calls=0;
27 > static int nfill,tests,calls;
28   static char filled[512];                /* has bucket[key] been filled yet? */
29   static int sq[511];
30  
31 < initialize() {                          /* reset the buckets */
31 > initializeclosest() {                   /* reset the buckets */
32      int k;
33      nfill = tests = calls = 0;
34      for (k=0; k<512; k++) filled[k] = 0;
# Line 38 | Line 39 | closest(r,g,b)         /* find pv of colormap color closest t
39   int r,g,b;
40   {
41      register struct thing *p;
42 <    register int *rsq,*gsq,*bsq,dist,min,best;
42 >    register int *rsq,*gsq,*bsq,dist,min;
43 >    int best,k;
44      struct thing *p0;
45  
46 <    if (!filled[key]) fillbucket(key);
46 >    k = key(r,g,b);
47 >    if (!filled[k]) fillbucket(k);
48      min = inf;
49      rsq = sq+255-r;
50      gsq = sq+255-g;
51      bsq = sq+255-b;
52  
53      /* stop looking when best is closer than next could be */
54 <    for (p0=p=bucket[key]; min>p->mindist; p++) {
54 >    for (p0=p=bucket[k]; min>p->mindist; p++) {
55          dist = rsq[color[0][p->pv]] + gsq[color[1][p->pv]] +
56              bsq[color[2][p->pv]];
57          if (dist<min) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines