46 |
|
#define string(s) fputs(s, stdout) |
47 |
|
#define flush() fflush(stdout) |
48 |
|
|
49 |
< |
#define GAMMA 2.0 /* exponent for color correction */ |
49 |
> |
#define GAMMA 2.5 /* exponent for color correction */ |
50 |
|
|
51 |
< |
#define MINCOLOR 8 /* start of device color table */ |
51 |
> |
#define NCOLORS 248 /* our color table size */ |
52 |
> |
#define MINPIX 8 /* minimum hardware color */ |
53 |
|
|
53 |
– |
#define NCOLORS 241 /* our color table size (prime) */ |
54 |
– |
|
55 |
– |
#define hashcolr(c) ((67*(c)[RED]+59*(c)[GRN]+71*(c)[BLU])%NCOLORS) |
56 |
– |
|
54 |
|
#define NCOLS 512 /* maximum # columns for output */ |
55 |
|
#define NROWS 512-COMHT /* maximum # rows for output */ |
56 |
|
#define COMHT 16 /* height of command line */ |
57 |
|
#define COMCW 63 /* maximum chars on command line */ |
58 |
|
|
59 |
< |
static COLR colrmap[256]; /* our color map */ |
59 |
> |
int anewcolr(); |
60 |
|
|
64 |
– |
static COLR colrtbl[NCOLORS]; /* our color table */ |
65 |
– |
|
66 |
– |
static int colres = 64; /* color resolution */ |
67 |
– |
|
61 |
|
int aed_close(), aed_clear(), aed_paintr(), |
62 |
|
aed_getcur(), aed_comout(), aed_errout(); |
63 |
|
|
88 |
|
byte(BLK); byte(WHT); byte(15); |
89 |
|
command(SCP); |
90 |
|
byte('+'); byte(0); byte(1); |
91 |
+ |
make_cmap(GAMMA); /* make color map */ |
92 |
|
errvec = aed_errout; /* set error vector */ |
93 |
|
cmdvec = aed_errout; |
94 |
|
if (wrnvec != NULL) |
119 |
|
int x, y; |
120 |
|
{ |
121 |
|
command(FFD); |
122 |
+ |
new_ctab(NCOLORS, anewcolr); /* init color table */ |
123 |
|
flush(); |
129 |
– |
makemap(); /* init color map */ |
124 |
|
} |
125 |
|
|
126 |
|
|
131 |
|
{ |
132 |
|
int ndx; |
133 |
|
|
134 |
< |
if ((ndx = colindex(col)) < 0) { /* full table? */ |
135 |
< |
colres >>= 1; |
136 |
< |
redraw(); |
143 |
< |
return; |
144 |
< |
} |
145 |
< |
command(SEC); /* draw rectangle */ |
146 |
< |
byte(ndx+MINCOLOR); |
134 |
> |
ndx = get_pixel(col); /* may call anewcolr() */ |
135 |
> |
command(SEC); /* draw rectangle */ |
136 |
> |
byte(ndx+MINPIX); |
137 |
|
aedsetcap(xmin, ymin+COMHT); |
138 |
|
command(DFR); |
139 |
|
aedcoord(xmax-1, ymax+(-1+COMHT)); |
251 |
|
} |
252 |
|
|
253 |
|
|
264 |
– |
static int |
265 |
– |
colindex(col) /* return table index for color */ |
266 |
– |
COLOR col; |
267 |
– |
{ |
268 |
– |
static COLR clr; |
269 |
– |
int hval; |
270 |
– |
register int ndx, i; |
271 |
– |
|
272 |
– |
mapcolor(clr, col); |
273 |
– |
|
274 |
– |
hval = ndx = hashcolr(clr); |
275 |
– |
|
276 |
– |
for (i = 1; i < NCOLORS; i++) { |
277 |
– |
if (colrtbl[ndx][EXP] == 0) { |
278 |
– |
colrtbl[ndx][RED] = clr[RED]; |
279 |
– |
colrtbl[ndx][GRN] = clr[GRN]; |
280 |
– |
colrtbl[ndx][BLU] = clr[BLU]; |
281 |
– |
colrtbl[ndx][EXP] = COLXS; |
282 |
– |
newcolr(ndx, clr); |
283 |
– |
return(ndx); |
284 |
– |
} |
285 |
– |
if ( colrtbl[ndx][RED] == clr[RED] && |
286 |
– |
colrtbl[ndx][GRN] == clr[GRN] && |
287 |
– |
colrtbl[ndx][BLU] == clr[BLU] ) |
288 |
– |
return(ndx); |
289 |
– |
ndx = (hval + i*i) % NCOLORS; |
290 |
– |
} |
291 |
– |
return(-1); |
292 |
– |
} |
293 |
– |
|
294 |
– |
|
254 |
|
static |
255 |
< |
newcolr(index, clr) /* enter a color into our table */ |
255 |
> |
anewcolr(index, r, g, b) /* enter a color into our table */ |
256 |
|
int index; |
257 |
< |
COLR clr; |
257 |
> |
int r, g, b; |
258 |
|
{ |
259 |
|
command(SCT); |
260 |
< |
byte(index+MINCOLOR); |
260 |
> |
byte((index+MINPIX)&255); |
261 |
|
byte(1); |
262 |
< |
byte(clr[RED]); |
263 |
< |
byte(clr[GRN]); |
264 |
< |
byte(clr[BLU]); |
262 |
> |
byte(r); |
263 |
> |
byte(g); |
264 |
> |
byte(b); |
265 |
|
flush(); |
307 |
– |
} |
308 |
– |
|
309 |
– |
|
310 |
– |
static |
311 |
– |
mapcolor(clr, col) /* map to our color space */ |
312 |
– |
COLR clr; |
313 |
– |
COLOR col; |
314 |
– |
{ |
315 |
– |
register int i, p; |
316 |
– |
/* compute color table value */ |
317 |
– |
for (i = 0; i < 3; i++) { |
318 |
– |
p = colval(col,i) * 256.0; |
319 |
– |
if (p < 0) p = 0; |
320 |
– |
else if (p >= 256) p = 255; |
321 |
– |
clr[i] = colrmap[p][i]; |
322 |
– |
} |
323 |
– |
clr[EXP] = COLXS; |
324 |
– |
} |
325 |
– |
|
326 |
– |
|
327 |
– |
static |
328 |
– |
makemap() /* initialize the color map */ |
329 |
– |
{ |
330 |
– |
double pow(); |
331 |
– |
int val; |
332 |
– |
register int i; |
333 |
– |
|
334 |
– |
for (i = 0; i < 256; i++) { |
335 |
– |
val = pow(i/256.0, 1.0/GAMMA) * colres; |
336 |
– |
val = (val*256 + 128) / colres; |
337 |
– |
colrmap[i][RED] = colrmap[i][GRN] = colrmap[i][BLU] = val; |
338 |
– |
colrmap[i][EXP] = COLXS; |
339 |
– |
} |
340 |
– |
for (i = 0; i < NCOLORS; i++) |
341 |
– |
colrtbl[i][EXP] = 0; |
266 |
|
} |
267 |
|
|
268 |
|
|