27 |
|
/* minimum box count for adaptive partition */ |
28 |
|
#define MINSAMP 7 |
29 |
|
/* maximum distance^2 before color reassign */ |
30 |
< |
#define MAXDST2 5 |
30 |
> |
#define MAXDST2 12 |
31 |
|
/* maximum frame buffer depth */ |
32 |
|
#define FBDEPTH 8 |
33 |
– |
/* color map resolution */ |
34 |
– |
#define MAPSIZ 256 |
33 |
|
/* map a color */ |
34 |
< |
#define map_col(c,p) clrmap[ colval(c,p)<1. ? \ |
35 |
< |
(int)(colval(c,p)*MAPSIZ) : MAPSIZ-1 ] |
34 |
> |
#define map_col(c,p) clrmap[p][ colval(c,p)<1. ? \ |
35 |
> |
(int)(colval(c,p)*256.) : 255 ] |
36 |
|
/* color partition tree */ |
37 |
|
#define CNODE short |
38 |
|
#define set_branch(p,c) ((c)<<2|(p)) |
42 |
|
#define prim(cn) ((cn)&3) |
43 |
|
#define pval(cn) ((cn)>>2) |
44 |
|
/* our color table */ |
45 |
< |
struct tabent { |
45 |
> |
static struct tabent { |
46 |
|
long sum[3]; /* sum of colors using this entry */ |
47 |
|
long n; /* number of colors */ |
48 |
|
short ent[3]; /* current table value */ |
49 |
|
} clrtab[1<<FBDEPTH]; |
50 |
|
/* our color correction map */ |
51 |
< |
static BYTE clrmap[MAPSIZ]; |
51 |
> |
static BYTE clrmap[3][256]; |
52 |
|
/* histogram of colors used */ |
53 |
|
static unsigned histo[NRED][NGRN][NBLU]; |
54 |
|
/* initial color cube boundaries */ |
55 |
|
static int CLRCUBE[3][2] = {0,NRED,0,NGRN,0,NBLU}; |
56 |
|
/* color cube partition */ |
57 |
|
static CNODE ctree[1<<(FBDEPTH+1)]; |
60 |
– |
/* callback for pixel assignment */ |
61 |
– |
static int (*set_pixel)(); |
58 |
|
|
59 |
|
|
60 |
|
int |
61 |
< |
new_ctab(ncolors, cset) /* start new color table with max ncolors */ |
61 |
> |
new_ctab(ncolors) /* start new color table with max ncolors */ |
62 |
|
int ncolors; |
67 |
– |
int (*cset)(); |
63 |
|
{ |
64 |
< |
if (ncolors < 1 || ncolors > 1<<FBDEPTH || cset == NULL) |
64 |
> |
if (ncolors < 1) |
65 |
|
return(0); |
66 |
< |
/* assign pixel callback routine */ |
67 |
< |
set_pixel = cset; |
66 |
> |
if (ncolors > 1<<FBDEPTH) |
67 |
> |
ncolors = 1<<FBDEPTH; |
68 |
|
/* clear color table */ |
69 |
|
bzero(clrtab, sizeof(clrtab)); |
70 |
|
/* partition color space */ |
77 |
|
|
78 |
|
|
79 |
|
int |
80 |
< |
get_pixel(col) /* get pixel for color */ |
80 |
> |
get_pixel(col, set_pixel) /* get pixel for color */ |
81 |
|
COLOR col; |
82 |
+ |
int (*set_pixel)(); |
83 |
|
{ |
84 |
|
int r, g, b; |
85 |
|
int cv[3]; |
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
< |
make_cmap(gam) /* make gamma correction map */ |
138 |
> |
make_gmap(gam) /* make gamma correction map */ |
139 |
|
double gam; |
140 |
|
{ |
141 |
|
extern double pow(); |
142 |
|
register int i; |
143 |
|
|
144 |
< |
for (i = 0; i < MAPSIZ; i++) |
145 |
< |
clrmap[i] = 256.0 * pow(i/(double)MAPSIZ, 1.0/gam); |
144 |
> |
for (i = 0; i < 256; i++) |
145 |
> |
clrmap[RED][i] = |
146 |
> |
clrmap[GRN][i] = |
147 |
> |
clrmap[BLU][i] = 256.0 * pow(i/256.0, 1.0/gam); |
148 |
> |
} |
149 |
> |
|
150 |
> |
|
151 |
> |
set_cmap(rmap, gmap, bmap) /* set custom color correction map */ |
152 |
> |
BYTE *rmap, *gmap, *bmap; |
153 |
> |
{ |
154 |
> |
bcopy(rmap, clrmap[RED], 256); |
155 |
> |
bcopy(gmap, clrmap[GRN], 256); |
156 |
> |
bcopy(bmap, clrmap[BLU], 256); |
157 |
|
} |
158 |
|
|
159 |
|
|