25 |
|
#define part(cn) ((cn)>>2) |
26 |
|
#define prim(cn) ((cn)&3) |
27 |
|
/* our color table (global) */ |
28 |
< |
extern BYTE clrtab[256][3]; |
28 |
> |
extern uby8 clrtab[256][3]; |
29 |
|
/* histogram of colors / color assignments */ |
30 |
|
static unsigned histo[NRED][NGRN][NBLU]; |
31 |
|
#define cndx(c) histo[((c)[RED]*NRED)>>8][((c)[GRN]*NGRN)>>8][((c)[BLU]*NBLU)>>8] |
41 |
|
|
42 |
|
#ifdef CLOSEST |
43 |
|
static void closest(int n); |
44 |
< |
static void setclosest(BYTE *nl[], int r, int g, int b); |
45 |
< |
static void addneigh(BYTE *nl[], int i, int j); |
46 |
< |
static unsigned int dist(BYTE col[3], int r, int g, int b); |
44 |
> |
static void setclosest(uby8 *nl[], int r, int g, int b); |
45 |
> |
static void addneigh(uby8 *nl[], int i, int j); |
46 |
> |
static unsigned int dist(uby8 col[3], int r, int g, int b); |
47 |
|
#endif |
48 |
|
static void cut(int box[3][2], int c0, int c1); |
49 |
|
static int split(int box[3][2]); |
62 |
|
|
63 |
|
extern void |
64 |
|
cnt_pixel( /* add pixel to our histogram */ |
65 |
< |
register BYTE col[] |
65 |
> |
register uby8 col[] |
66 |
|
) |
67 |
|
{ |
68 |
|
cndx(col)++; |
97 |
|
closest(ncolors); /* ensure colors picked are closest */ |
98 |
|
#endif |
99 |
|
/* reset dithering function */ |
100 |
< |
dith_colrs((BYTE *)NULL, (COLR *)NULL, 0); |
100 |
> |
dith_colrs((uby8 *)NULL, (COLR *)NULL, 0); |
101 |
|
/* return new color table size */ |
102 |
|
return(ncolors); |
103 |
|
} |
105 |
|
|
106 |
|
extern int |
107 |
|
map_pixel( /* get pixel for color */ |
108 |
< |
register BYTE col[] |
108 |
> |
register uby8 col[] |
109 |
|
) |
110 |
|
{ |
111 |
|
return(cndx(col)); |
114 |
|
|
115 |
|
extern void |
116 |
|
map_colrs( /* convert a scanline to color index values */ |
117 |
< |
register BYTE *bs, |
117 |
> |
register uby8 *bs, |
118 |
|
register COLR *cs, |
119 |
|
register int n |
120 |
|
) |
128 |
|
|
129 |
|
extern void |
130 |
|
dith_colrs( /* convert scanline to dithered index values */ |
131 |
< |
register BYTE *bs, |
131 |
> |
register uby8 *bs, |
132 |
|
register COLR *cs, |
133 |
|
int n |
134 |
|
) |
311 |
|
int n |
312 |
|
) |
313 |
|
{ |
314 |
< |
BYTE *neigh[256]; |
314 |
> |
uby8 *neigh[256]; |
315 |
|
register int r, g, b; |
316 |
|
#define i r |
317 |
|
/* get space for neighbor lists */ |
318 |
|
for (i = 0; i < n; i++) { |
319 |
< |
if ((neigh[i] = (BYTE *)malloc(NBSIZ)) == NULL) { |
319 |
> |
if ((neigh[i] = (uby8 *)malloc(NBSIZ)) == NULL) { |
320 |
|
while (i--) |
321 |
|
free(neigh[i]); |
322 |
|
return; /* ENOMEM -- abandon effort */ |
348 |
|
|
349 |
|
static void |
350 |
|
addneigh( /* i and j are neighbors; add them to list */ |
351 |
< |
register BYTE *nl[], |
351 |
> |
register uby8 *nl[], |
352 |
|
register int i, |
353 |
|
int j |
354 |
|
) |
368 |
|
t+NBSIZ)) == NULL) |
369 |
|
t--; |
370 |
|
else |
371 |
< |
nl[i] = (BYTE *)nnl; |
371 |
> |
nl[i] = (uby8 *)nnl; |
372 |
|
} |
373 |
|
nl[i][t] = i; /* terminator */ |
374 |
|
} |
379 |
|
|
380 |
|
static unsigned int |
381 |
|
dist( /* find distance from clrtab entry to r,g,b */ |
382 |
< |
register BYTE col[3], |
382 |
> |
register uby8 col[3], |
383 |
|
int r, |
384 |
|
int g, |
385 |
|
int b |
400 |
|
|
401 |
|
static void |
402 |
|
setclosest( /* find index closest to color and assign */ |
403 |
< |
BYTE *nl[], |
403 |
> |
uby8 *nl[], |
404 |
|
int r, |
405 |
|
int g, |
406 |
|
int b |
409 |
|
int ident; |
410 |
|
unsigned min; |
411 |
|
register unsigned d; |
412 |
< |
register BYTE *p; |
412 |
> |
register uby8 *p; |
413 |
|
/* get starting value */ |
414 |
|
min = dist(clrtab[ident=histo[r][g][b]], r, g, b); |
415 |
|
/* find minimum */ |