37 |
|
#define CNODE short |
38 |
|
#define set_branch(p,c) ((c)<<2|(p)) |
39 |
|
#define set_pval(pv) ((pv)<<2|3) |
40 |
+ |
#define is_branch(cn) (((cn)&3)!=3) |
41 |
|
#define is_pval(cn) (((cn)&3)==3) |
42 |
|
#define part(cn) ((cn)>>2) |
43 |
|
#define prim(cn) ((cn)&3) |
69 |
|
/* clear color table */ |
70 |
|
bzero(clrtab, sizeof(clrtab)); |
71 |
|
/* partition color space */ |
72 |
< |
cut(ctree, FBDEPTH, CLRCUBE, 0, ncolors); |
72 |
> |
cut(ctree, 0, CLRCUBE, 0, ncolors); |
73 |
|
/* clear histogram */ |
74 |
|
bzero(histo, sizeof(histo)); |
75 |
|
/* return number of colors used */ |
97 |
|
/* add to histogram */ |
98 |
|
histo[cv[RED]][cv[GRN]][cv[BLU]]++; |
99 |
|
/* find pixel in tree */ |
100 |
< |
p.t = ctree; |
100 |
< |
for (h = FBDEPTH; h > 0; h--) { |
101 |
< |
if (is_pval(*p.t)) |
102 |
< |
break; |
100 |
> |
for (p.t = ctree, h = 0; is_branch(*p.t); h++) |
101 |
|
if (cv[prim(*p.t)] < part(*p.t)) |
102 |
< |
p.t++; /* left branch */ |
102 |
> |
p.t += 1<<h; /* left branch */ |
103 |
|
else |
104 |
< |
p.t += 1<<h; /* right branch */ |
107 |
< |
} |
104 |
> |
p.t += 1<<(h+1); /* right branch */ |
105 |
|
h = pval(*p.t); |
106 |
|
/* add to color table */ |
107 |
|
p.e = clrtab + h; |
155 |
|
|
156 |
|
|
157 |
|
static |
158 |
< |
cut(tree, height, box, c0, c1) /* partition color space */ |
158 |
> |
cut(tree, level, box, c0, c1) /* partition color space */ |
159 |
|
register CNODE *tree; |
160 |
< |
int height; |
160 |
> |
int level; |
161 |
|
register int box[3][2]; |
162 |
|
int c0, c1; |
163 |
|
{ |
172 |
|
bcopy(box, kb, sizeof(kb)); |
173 |
|
/* do left (lesser) branch */ |
174 |
|
kb[prim(*tree)][1] = part(*tree); |
175 |
< |
cut(tree+1, height-1, kb, c0, (c0+c1)>>1); |
175 |
> |
cut(tree+(1<<level), level+1, kb, c0, (c0+c1)>>1); |
176 |
|
/* do right branch */ |
177 |
|
kb[prim(*tree)][0] = part(*tree); |
178 |
|
kb[prim(*tree)][1] = box[prim(*tree)][1]; |
179 |
< |
cut(tree+(1<<height), height-1, kb, (c0+c1)>>1, c1); |
179 |
> |
cut(tree+(1<<(level+1)), level+1, kb, (c0+c1)>>1, c1); |
180 |
|
} |
181 |
|
|
182 |
|
|