1 |
– |
/* Copyright (c) 1987 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* aed.c - driver for AED 512 terminal. |
9 |
– |
* |
10 |
– |
* 2/2/87 |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include "copyright.h" |
9 |
+ |
|
10 |
|
#include <stdio.h> |
11 |
|
|
12 |
|
#include "driver.h" |
43 |
|
#define string(s) fputs(s, stdout) |
44 |
|
#define flush() fflush(stdout) |
45 |
|
|
46 |
< |
#define GAMMA 2.0 /* exponent for color correction */ |
46 |
> |
#define GAMMA 2.5 /* exponent for color correction */ |
47 |
|
|
48 |
< |
#define MINCOLOR 8 /* start of device color table */ |
48 |
> |
#define NCOLORS 248 /* our color table size */ |
49 |
> |
#define MINPIX 8 /* minimum hardware color */ |
50 |
|
|
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 |
– |
|
51 |
|
#define NCOLS 512 /* maximum # columns for output */ |
52 |
< |
#define NROWS 512-COMHT /* maximum # rows for output */ |
52 |
> |
#define NROWS 483-COMHT /* maximum # rows for output */ |
53 |
|
#define COMHT 16 /* height of command line */ |
54 |
|
#define COMCW 63 /* maximum chars on command line */ |
55 |
|
|
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 |
– |
|
56 |
|
int aed_close(), aed_clear(), aed_paintr(), |
57 |
|
aed_getcur(), aed_comout(), aed_errout(); |
58 |
|
|
59 |
|
static struct driver aed_driver = { |
60 |
|
aed_close, aed_clear, aed_paintr, aed_getcur, |
61 |
< |
aed_comout, NULL, |
62 |
< |
NCOLS, NROWS |
61 |
> |
aed_comout, NULL, NULL, |
62 |
> |
1.0, NCOLS, NROWS |
63 |
|
}; |
64 |
|
|
65 |
|
|
66 |
|
struct driver * |
67 |
< |
aed_init(name) /* open AED */ |
68 |
< |
char *name; |
67 |
> |
aed_init(name, id) /* open AED */ |
68 |
> |
char *name, *id; |
69 |
|
{ |
70 |
|
if (ttyset(&aed_driver, fileno(stdin)) < 0) { /* set tty driver */ |
71 |
< |
stderr_v("cannot access terminal\n"); |
71 |
> |
eputs("cannot access terminal\n"); |
72 |
|
return(NULL); |
73 |
|
} |
74 |
|
command(RST); /* reset AED */ |
83 |
|
byte(BLK); byte(WHT); byte(15); |
84 |
|
command(SCP); |
85 |
|
byte('+'); byte(0); byte(1); |
86 |
< |
errvec = aed_errout; /* set error vector */ |
87 |
< |
cmdvec = aed_errout; |
88 |
< |
if (wrnvec != NULL) |
89 |
< |
wrnvec = aed_errout; |
86 |
> |
make_gmap(GAMMA); /* make color map */ |
87 |
> |
erract[USER].pf = /* set error vector */ |
88 |
> |
erract[SYSTEM].pf = |
89 |
> |
erract[INTERNAL].pf = |
90 |
> |
erract[CONSISTENCY].pf = aed_errout; |
91 |
> |
erract[COMMAND].pf = aed_errout; |
92 |
> |
if (erract[WARNING].pf != NULL) |
93 |
> |
erract[WARNING].pf = aed_errout; |
94 |
|
return(&aed_driver); |
95 |
|
} |
96 |
|
|
98 |
|
static |
99 |
|
aed_close() /* close AED */ |
100 |
|
{ |
101 |
< |
errvec = stderr_v; /* reset error vector */ |
102 |
< |
cmdvec = NULL; |
103 |
< |
if (wrnvec != NULL) |
104 |
< |
wrnvec = stderr_v; |
101 |
> |
erract[USER].pf = /* reset error vector */ |
102 |
> |
erract[SYSTEM].pf = |
103 |
> |
erract[INTERNAL].pf = |
104 |
> |
erract[CONSISTENCY].pf = eputs; |
105 |
> |
erract[COMMAND].pf = NULL; |
106 |
> |
if (erract[WARNING].pf != NULL) |
107 |
> |
erract[WARNING].pf = wputs; |
108 |
|
aedsetcap(0, 0); /* go to bottom */ |
109 |
|
command(SEC); |
110 |
|
byte(WHT); /* white text */ |
120 |
|
int x, y; |
121 |
|
{ |
122 |
|
command(FFD); |
123 |
+ |
new_ctab(NCOLORS); /* init color table */ |
124 |
|
flush(); |
129 |
– |
makemap(); /* init color map */ |
125 |
|
} |
126 |
|
|
127 |
|
|
130 |
|
COLOR col; |
131 |
|
int xmin, ymin, xmax, ymax; |
132 |
|
{ |
133 |
+ |
extern int anewcolr(); |
134 |
|
int ndx; |
135 |
|
|
136 |
< |
if ((ndx = colindex(col)) < 0) { /* full table? */ |
137 |
< |
colres >>= 1; |
138 |
< |
redraw(); |
143 |
< |
return; |
144 |
< |
} |
145 |
< |
command(SEC); /* draw rectangle */ |
146 |
< |
byte(ndx+MINCOLOR); |
136 |
> |
ndx = get_pixel(col, anewcolr); /* calls anewcolr() */ |
137 |
> |
command(SEC); /* draw rectangle */ |
138 |
> |
byte(ndx+MINPIX); |
139 |
|
aedsetcap(xmin, ymin+COMHT); |
140 |
|
command(DFR); |
141 |
|
aedcoord(xmax-1, ymax+(-1+COMHT)); |
253 |
|
} |
254 |
|
|
255 |
|
|
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 |
– |
|
256 |
|
static |
257 |
< |
newcolr(index, clr) /* enter a color into our table */ |
257 |
> |
anewcolr(index, r, g, b) /* enter a color into our table */ |
258 |
|
int index; |
259 |
< |
COLR clr; |
259 |
> |
int r, g, b; |
260 |
|
{ |
261 |
|
command(SCT); |
262 |
< |
byte(index+MINCOLOR); |
262 |
> |
byte((index+MINPIX)&255); |
263 |
|
byte(1); |
264 |
< |
byte(clr[RED]); |
265 |
< |
byte(clr[GRN]); |
266 |
< |
byte(clr[BLU]); |
264 |
> |
byte(r); |
265 |
> |
byte(g); |
266 |
> |
byte(b); |
267 |
|
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; |
268 |
|
} |
269 |
|
|
270 |
|
|