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.1 by greg, Thu Feb 2 10:49:10 1989 UTC vs.
Revision 2.3 by schorsch, Sun Jul 27 22:12:03 2003 UTC

# Line 1 | Line 1
1 /*
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
4 + /*
5   CLOSEST - nearest-color lookup by locally ordered search
6   we use distance in rgb space as color metric
7  
# Line 16 | Line 15 | Paul Heckbert
15   #include "ciq.h"
16  
17   #define inf 3*256*256
18 < #define key ((r&0xe0)<<1|(g&0xe0)>>2|(b&0xe0)>>5)    /* hash key: rrrgggbbb */
18 > #define key(r,g,b) (((r)&0xe0)<<1|((g)&0xe0)>>2|((b)&0xe0)>>5)  
19 >    /* 9-bit hash key: rrrgggbbb */
20  
21 < static struct thing {int mindist,pv;} space[512*257],*next=space,*bucket[512];
21 > static struct thing {int mindist,pv;} space[512*257],*next,*bucket[512];
22                                          /* sorted lists of colors */
23  
24 < static int nfill=0,tests=0,calls=0;
24 > static int nfill,tests,calls;
25   static char filled[512];                /* has bucket[key] been filled yet? */
26   static int sq[511];
27  
28 < initialize() {                          /* reset the buckets */
28 > initializeclosest() {                   /* reset the buckets */
29      int k;
30      nfill = tests = calls = 0;
31      for (k=0; k<512; k++) filled[k] = 0;
# Line 36 | Line 36 | closest(r,g,b)         /* find pv of colormap color closest t
36   int r,g,b;
37   {
38      register struct thing *p;
39 <    register int *rsq,*gsq,*bsq,dist,min,best;
39 >    register int *rsq,*gsq,*bsq,dist,min;
40 >    int best,k;
41      struct thing *p0;
42  
43 <    if (!filled[key]) fillbucket(key);
43 >    k = key(r,g,b);
44 >    if (!filled[k]) fillbucket(k);
45      min = inf;
46      rsq = sq+255-r;
47      gsq = sq+255-g;
48      bsq = sq+255-b;
49  
50      /* stop looking when best is closer than next could be */
51 <    for (p0=p=bucket[key]; min>p->mindist; p++) {
51 >    for (p0=p=bucket[k]; min>p->mindist; p++) {
52          dist = rsq[color[0][p->pv]] + gsq[color[1][p->pv]] +
53              bsq[color[2][p->pv]];
54          if (dist<min) {
# Line 75 | Line 77 | int k;         /* matches for colors in bucket #k */
77  
78      if (!sq[0]) for (j= -255; j<256; j++) sq[j+255] = j*j;
79  
80 <    r = k>>1&0xe0|H;                    /* center of 32x32x32 cubical bucket */
81 <    g = k<<2&0xe0|H;
82 <    b = k<<5&0xe0|H;
80 >    r = (k>>1&0xe0)|H;                  /* center of 32x32x32 cubical bucket */
81 >    g = (k<<2&0xe0)|H;
82 >    b = (k<<5&0xe0)|H;
83      rsq = sq+255-r;
84      gsq = sq+255-g;
85      bsq = sq+255-b;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines