93 |
|
{ |
94 |
|
int r, g, b; |
95 |
|
int cv[3]; |
96 |
< |
register union { CNODE *t; struct tabent *e; } p; |
96 |
> |
register CNODE *tp; |
97 |
|
register int h; |
98 |
|
/* map color */ |
99 |
|
r = map_col(col,RED); |
106 |
|
/* add to histogram */ |
107 |
|
histo[cv[RED]][cv[GRN]][cv[BLU]]++; |
108 |
|
/* find pixel in tree */ |
109 |
< |
for (p.t = ctree, h = 0; is_branch(*p.t); h++) |
110 |
< |
if (cv[prim(*p.t)] < part(*p.t)) |
111 |
< |
p.t += 1<<h; /* left branch */ |
109 |
> |
for (tp = ctree, h = 0; is_branch(*tp); h++) |
110 |
> |
if (cv[prim(*tp)] < part(*tp)) |
111 |
> |
tp += 1<<h; /* left branch */ |
112 |
|
else |
113 |
< |
p.t += 1<<(h+1); /* right branch */ |
114 |
< |
h = pval(*p.t); |
113 |
> |
tp += 1<<(h+1); /* right branch */ |
114 |
> |
h = pval(*tp); |
115 |
|
/* add to color table */ |
116 |
< |
p.e = clrtab + h; |
117 |
< |
/* add to sum */ |
118 |
< |
p.e->sum[RED] += r; |
119 |
< |
p.e->sum[GRN] += g; |
120 |
< |
p.e->sum[BLU] += b; |
121 |
< |
p.e->n++; |
116 |
> |
clrtab[h].sum[RED] += r; |
117 |
> |
clrtab[h].sum[GRN] += g; |
118 |
> |
clrtab[h].sum[BLU] += b; |
119 |
> |
clrtab[h].n++; |
120 |
|
/* recompute average */ |
121 |
< |
r = p.e->sum[RED] / p.e->n; |
122 |
< |
g = p.e->sum[GRN] / p.e->n; |
123 |
< |
b = p.e->sum[BLU] / p.e->n; |
121 |
> |
r = clrtab[h].sum[RED] / clrtab[h].n; |
122 |
> |
g = clrtab[h].sum[GRN] / clrtab[h].n; |
123 |
> |
b = clrtab[h].sum[BLU] / clrtab[h].n; |
124 |
|
/* check for movement */ |
125 |
< |
if (p.e->n == 1 || |
126 |
< |
(r-p.e->ent[RED])*(r-p.e->ent[RED]) + |
127 |
< |
(g-p.e->ent[GRN])*(g-p.e->ent[GRN]) + |
128 |
< |
(b-p.e->ent[BLU])*(b-p.e->ent[BLU]) > MAXDST2) { |
129 |
< |
p.e->ent[RED] = r; |
130 |
< |
p.e->ent[GRN] = g; /* reassign pixel */ |
131 |
< |
p.e->ent[BLU] = b; |
125 |
> |
if (clrtab[h].n == 1 || |
126 |
> |
(r-clrtab[h].ent[RED])*(r-clrtab[h].ent[RED]) + |
127 |
> |
(g-clrtab[h].ent[GRN])*(g-clrtab[h].ent[GRN]) + |
128 |
> |
(b-clrtab[h].ent[BLU])*(b-clrtab[h].ent[BLU]) > MAXDST2) { |
129 |
> |
clrtab[h].ent[RED] = r; |
130 |
> |
clrtab[h].ent[GRN] = g; /* reassign pixel */ |
131 |
> |
clrtab[h].ent[BLU] = b; |
132 |
|
#ifdef notdef |
133 |
|
printf("pixel %d = (%d,%d,%d) (%d refs)\n", |
134 |
< |
h, r, g, b, p.e->n); |
134 |
> |
h, r, g, b, clrtab[h].n); |
135 |
|
#endif |
136 |
|
(*set_pixel)(h, r, g, b); |
137 |
|
} |