16 |
|
* except there is no color mapping, since the tm library is used. |
17 |
|
*/ |
18 |
|
|
19 |
+ |
#include <string.h> |
20 |
+ |
|
21 |
|
#include "standard.h" |
22 |
+ |
#include "rhdisp.h" |
23 |
|
#include "color.h" |
24 |
|
/* histogram resolution */ |
25 |
|
#define NRED 24 |
43 |
|
static struct tabent { |
44 |
|
long sum[3]; /* sum of colors using this entry */ |
45 |
|
int n; /* number of colors */ |
46 |
< |
BYTE ent[3]; /* current table value */ |
46 |
> |
uby8 ent[3]; /* current table value */ |
47 |
|
} *clrtab = NULL; |
48 |
|
/* color cube partition */ |
49 |
|
static CNODE *ctree = NULL; |
52 |
|
/* initial color cube boundary */ |
53 |
|
static int CLRCUBE[3][2] = {{0,NRED},{0,NGRN},{0,NBLU}}; |
54 |
|
|
55 |
< |
static int split(), cut(); |
55 |
> |
static void cut(CNODE *tree, int level, int box[3][2], int c0, int c1); |
56 |
> |
static int split(int box[3][2]); |
57 |
|
|
58 |
|
|
59 |
+ |
|
60 |
|
int |
61 |
< |
new_ctab(ncolors) /* start new color table with max ncolors */ |
62 |
< |
int ncolors; |
61 |
> |
new_ctab( /* start new color table with max ncolors */ |
62 |
> |
int ncolors |
63 |
> |
) |
64 |
|
{ |
65 |
|
int treesize; |
66 |
|
|
82 |
|
/* partition color space */ |
83 |
|
cut(ctree, 0, CLRCUBE, 0, ncolors); |
84 |
|
/* clear histogram */ |
85 |
< |
bzero((void *)histo, sizeof(histo)); |
85 |
> |
memset((void *)histo, '\0', sizeof(histo)); |
86 |
|
/* return number of colors used */ |
87 |
|
return(ncolors); |
88 |
|
} |
89 |
|
|
90 |
|
|
91 |
|
int |
92 |
< |
get_pixel(rgb, set_pixel) /* get pixel for color */ |
93 |
< |
BYTE rgb[3]; |
94 |
< |
int (*set_pixel)(); |
92 |
> |
get_pixel( /* get pixel for color */ |
93 |
> |
uby8 rgb[3], |
94 |
> |
void (*set_pixel)(int h, int r, int g, int b) |
95 |
> |
) |
96 |
|
{ |
90 |
– |
extern char errmsg[]; |
97 |
|
int r, g, b; |
98 |
|
int cv[3]; |
99 |
< |
register CNODE *tp; |
100 |
< |
register int h; |
99 |
> |
CNODE *tp; |
100 |
> |
int h; |
101 |
|
/* get desired color */ |
102 |
|
r = rgb[RED]; |
103 |
|
g = rgb[GRN]; |
133 |
|
clrtab[h].ent[GRN] = g; /* reassign pixel */ |
134 |
|
clrtab[h].ent[BLU] = b; |
135 |
|
#ifdef DEBUG |
136 |
< |
sprintf(errmsg, "pixel %d = (%d,%d,%d) (%d refs)\n", |
137 |
< |
h, r, g, b, clrtab[h].n); |
138 |
< |
eputs(errmsg); |
136 |
> |
{ |
137 |
> |
extern char errmsg[]; |
138 |
> |
sprintf(errmsg, "pixel %d = (%d,%d,%d) (%d refs)\n", |
139 |
> |
h, r, g, b, clrtab[h].n); |
140 |
> |
eputs(errmsg); |
141 |
> |
} |
142 |
|
#endif |
143 |
|
(*set_pixel)(h, r, g, b); |
144 |
|
} |
146 |
|
} |
147 |
|
|
148 |
|
|
149 |
< |
static |
150 |
< |
cut(tree, level, box, c0, c1) /* partition color space */ |
151 |
< |
register CNODE *tree; |
152 |
< |
int level; |
153 |
< |
register int box[3][2]; |
154 |
< |
int c0, c1; |
149 |
> |
static void |
150 |
> |
cut( /* partition color space */ |
151 |
> |
CNODE *tree, |
152 |
> |
int level, |
153 |
> |
int box[3][2], |
154 |
> |
int c0, |
155 |
> |
int c1 |
156 |
> |
) |
157 |
|
{ |
158 |
|
int kb[3][2]; |
159 |
|
|
163 |
|
} |
164 |
|
/* split box */ |
165 |
|
*tree = split(box); |
166 |
< |
bcopy((void *)box, (void *)kb, sizeof(kb)); |
166 |
> |
memcpy((void *)kb, (void *)box, sizeof(kb)); |
167 |
|
/* do left (lesser) branch */ |
168 |
|
kb[prim(*tree)][1] = part(*tree); |
169 |
|
cut(tree+(1<<level), level+1, kb, c0, (c0+c1)>>1); |
175 |
|
|
176 |
|
|
177 |
|
static int |
178 |
< |
split(box) /* find median cut for box */ |
179 |
< |
register int box[3][2]; |
178 |
> |
split( /* find median cut for box */ |
179 |
> |
int box[3][2] |
180 |
> |
) |
181 |
|
{ |
182 |
|
#define c0 r |
183 |
< |
register int r, g, b; |
183 |
> |
int r, g, b; |
184 |
|
int pri; |
185 |
|
long t[HMAX], med; |
186 |
|
/* find dominant axis */ |