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 */ |
55 |
> |
#define NROWS 483-COMHT /* maximum # rows for output */ |
56 |
|
#define COMHT 16 /* height of command line */ |
57 |
|
#define COMCW 63 /* maximum chars on command line */ |
58 |
|
|
62 |
– |
static COLR colrmap[256]; /* our color map */ |
63 |
– |
|
64 |
– |
static COLR colrtbl[NCOLORS]; /* our color table */ |
65 |
– |
|
66 |
– |
static int colres = 64; /* color resolution */ |
67 |
– |
|
59 |
|
int aed_close(), aed_clear(), aed_paintr(), |
60 |
|
aed_getcur(), aed_comout(), aed_errout(); |
61 |
|
|
62 |
|
static struct driver aed_driver = { |
63 |
|
aed_close, aed_clear, aed_paintr, aed_getcur, |
64 |
|
aed_comout, NULL, |
65 |
< |
NCOLS, NROWS |
65 |
> |
1.0, NCOLS, NROWS |
66 |
|
}; |
67 |
|
|
68 |
|
|
69 |
|
struct driver * |
70 |
< |
aed_init(name) /* open AED */ |
71 |
< |
char *name; |
70 |
> |
aed_init(name, id) /* open AED */ |
71 |
> |
char *name, *id; |
72 |
|
{ |
73 |
|
if (ttyset(&aed_driver, fileno(stdin)) < 0) { /* set tty driver */ |
74 |
|
stderr_v("cannot access terminal\n"); |
86 |
|
byte(BLK); byte(WHT); byte(15); |
87 |
|
command(SCP); |
88 |
|
byte('+'); byte(0); byte(1); |
89 |
+ |
make_gmap(GAMMA); /* make color map */ |
90 |
|
errvec = aed_errout; /* set error vector */ |
91 |
|
cmdvec = aed_errout; |
92 |
|
if (wrnvec != NULL) |
117 |
|
int x, y; |
118 |
|
{ |
119 |
|
command(FFD); |
120 |
+ |
new_ctab(NCOLORS); /* init color table */ |
121 |
|
flush(); |
129 |
– |
makemap(); /* init color map */ |
122 |
|
} |
123 |
|
|
124 |
|
|
127 |
|
COLOR col; |
128 |
|
int xmin, ymin, xmax, ymax; |
129 |
|
{ |
130 |
+ |
extern int anewcolr(); |
131 |
|
int ndx; |
132 |
|
|
133 |
< |
if ((ndx = colindex(col)) < 0) { /* full table? */ |
134 |
< |
colres >>= 1; |
135 |
< |
redraw(); |
143 |
< |
return; |
144 |
< |
} |
145 |
< |
command(SEC); /* draw rectangle */ |
146 |
< |
byte(ndx+MINCOLOR); |
133 |
> |
ndx = get_pixel(col, anewcolr); /* calls anewcolr() */ |
134 |
> |
command(SEC); /* draw rectangle */ |
135 |
> |
byte(ndx+MINPIX); |
136 |
|
aedsetcap(xmin, ymin+COMHT); |
137 |
|
command(DFR); |
138 |
|
aedcoord(xmax-1, ymax+(-1+COMHT)); |
250 |
|
} |
251 |
|
|
252 |
|
|
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 |
– |
|
253 |
|
static |
254 |
< |
newcolr(index, clr) /* enter a color into our table */ |
254 |
> |
anewcolr(index, r, g, b) /* enter a color into our table */ |
255 |
|
int index; |
256 |
< |
COLR clr; |
256 |
> |
int r, g, b; |
257 |
|
{ |
258 |
|
command(SCT); |
259 |
< |
byte(index+MINCOLOR); |
259 |
> |
byte((index+MINPIX)&255); |
260 |
|
byte(1); |
261 |
< |
byte(clr[RED]); |
262 |
< |
byte(clr[GRN]); |
263 |
< |
byte(clr[BLU]); |
261 |
> |
byte(r); |
262 |
> |
byte(g); |
263 |
> |
byte(b); |
264 |
|
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; |
265 |
|
} |
266 |
|
|
267 |
|
|