| 1 |
greg |
1.1 |
#ifndef lint |
| 2 |
schorsch |
2.3 |
static const char RCSid[] = "$Id: t4027.c,v 2.2 2003/02/22 02:07:28 greg Exp $"; |
| 3 |
greg |
1.1 |
#endif |
| 4 |
|
|
/* |
| 5 |
|
|
* t4027.c - program to dump pixel file to Tektronix 4027. |
| 6 |
|
|
* |
| 7 |
|
|
* 8/15/85 |
| 8 |
|
|
*/ |
| 9 |
|
|
|
| 10 |
|
|
#include <stdio.h> |
| 11 |
|
|
|
| 12 |
|
|
#include "color.h" |
| 13 |
|
|
|
| 14 |
|
|
|
| 15 |
|
|
#define NROWS 462 |
| 16 |
|
|
#define NCOLS 640 |
| 17 |
|
|
|
| 18 |
|
|
#define COM 31 /* command character */ |
| 19 |
|
|
|
| 20 |
|
|
char *progname; |
| 21 |
|
|
|
| 22 |
|
|
|
| 23 |
|
|
main(argc, argv) |
| 24 |
|
|
int argc; |
| 25 |
|
|
char **argv; |
| 26 |
|
|
{ |
| 27 |
|
|
int xres, yres; |
| 28 |
|
|
COLOR scanline[NCOLS]; |
| 29 |
|
|
char sbuf[128]; |
| 30 |
|
|
FILE *fp; |
| 31 |
|
|
register int i; |
| 32 |
|
|
|
| 33 |
|
|
progname = argv[0]; |
| 34 |
|
|
|
| 35 |
|
|
if (argc < 2) |
| 36 |
|
|
fp = stdin; |
| 37 |
|
|
else if ((fp = fopen(argv[1], "r")) == NULL) { |
| 38 |
|
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
| 39 |
|
|
progname, argv[1]); |
| 40 |
|
|
exit(1); |
| 41 |
|
|
} |
| 42 |
|
|
/* discard header */ |
| 43 |
|
|
while (fgets(sbuf, sizeof(sbuf), fp) != NULL && sbuf[0] != '\n') |
| 44 |
|
|
; |
| 45 |
|
|
/* get picture dimensions */ |
| 46 |
|
|
if (fgets(sbuf, sizeof(sbuf), fp) == NULL || |
| 47 |
|
|
sscanf(sbuf, "-Y %d +X %d\n", &yres, &xres) != 2) { |
| 48 |
|
|
fprintf(stderr, "%s: bad picture size\n", progname); |
| 49 |
|
|
exit(1); |
| 50 |
|
|
} |
| 51 |
|
|
if (xres > NCOLS || yres > NROWS) { |
| 52 |
|
|
fprintf(stderr, "%s: resolution mismatch\n", progname); |
| 53 |
|
|
exit(1); |
| 54 |
|
|
} |
| 55 |
|
|
|
| 56 |
|
|
printf("%cMON1H", COM); |
| 57 |
|
|
printf("%cGRA1 33", COM); |
| 58 |
|
|
|
| 59 |
|
|
for (i = 0; i < yres; i++) { |
| 60 |
|
|
if (freadscan(scanline, xres, fp) < 0) { |
| 61 |
|
|
fprintf(stderr, "%s: read error\n", progname); |
| 62 |
|
|
exit(1); |
| 63 |
|
|
} |
| 64 |
|
|
plotscan(scanline, xres, NROWS-1-i); |
| 65 |
|
|
} |
| 66 |
|
|
fclose(fp); |
| 67 |
|
|
|
| 68 |
|
|
if (isatty(fileno(stdout))) { |
| 69 |
|
|
printf("Hit return when done: "); |
| 70 |
|
|
fflush(stdout); |
| 71 |
|
|
fp = fopen("/dev/tty", "r"); |
| 72 |
|
|
getc(fp); |
| 73 |
|
|
fclose(fp); |
| 74 |
|
|
printf("%cMON34", COM); |
| 75 |
|
|
} |
| 76 |
|
|
putchar('\r'); |
| 77 |
|
|
|
| 78 |
|
|
exit(0); |
| 79 |
|
|
} |
| 80 |
|
|
|
| 81 |
|
|
|
| 82 |
|
|
plotscan(scan, len, y) /* plot a scanline */ |
| 83 |
|
|
COLOR scan[]; |
| 84 |
|
|
int len; |
| 85 |
|
|
int y; |
| 86 |
|
|
{ |
| 87 |
|
|
int color, lastcolor = -1; |
| 88 |
|
|
int lastpos = -1; |
| 89 |
|
|
register int i; |
| 90 |
|
|
|
| 91 |
|
|
for (i = 0; i < len; i++) { |
| 92 |
|
|
|
| 93 |
|
|
color = colormap(scan[i]); |
| 94 |
|
|
if (color != lastcolor) { |
| 95 |
|
|
if (lastpos >= 0) { |
| 96 |
|
|
setdcolr(lastcolor); |
| 97 |
|
|
vector(lastpos, y, i, y); |
| 98 |
|
|
} |
| 99 |
|
|
lastcolor = color; |
| 100 |
|
|
lastpos = i; |
| 101 |
|
|
} |
| 102 |
|
|
} |
| 103 |
|
|
setdcolr(lastcolor); |
| 104 |
|
|
vector(lastpos, y, len-1, y); |
| 105 |
|
|
} |
| 106 |
|
|
|
| 107 |
|
|
|
| 108 |
|
|
int |
| 109 |
|
|
colormap(col) /* compute 4027 color value for col */ |
| 110 |
|
|
COLOR col; |
| 111 |
|
|
{ |
| 112 |
|
|
register int red, grn, blu; |
| 113 |
|
|
|
| 114 |
|
|
red = col[RED] >= 1.0 ? 3 : col[RED]*4; |
| 115 |
|
|
grn = col[GRN] >= 1.0 ? 3 : col[GRN]*4; |
| 116 |
|
|
blu = col[BLU] >= 1.0 ? 3 : col[BLU]*4; |
| 117 |
|
|
|
| 118 |
|
|
return(red<<4 | grn<<2 | blu); |
| 119 |
|
|
} |
| 120 |
|
|
|
| 121 |
|
|
|
| 122 |
|
|
vector(x0, y0, x1, y1) /* output a vector */ |
| 123 |
|
|
int x0, y0, x1, y1; |
| 124 |
|
|
{ |
| 125 |
|
|
printf("%cVEC%d %d %d %d", COM, x0, y0, x1, y1); |
| 126 |
|
|
} |
| 127 |
|
|
|
| 128 |
|
|
|
| 129 |
|
|
setdcolr(col) /* set dithered pattern for terminal */ |
| 130 |
|
|
int col; |
| 131 |
|
|
{ |
| 132 |
|
|
static int cmask[3][4] = { |
| 133 |
|
|
{ 0, 0x88, 0xca, 0xff }, |
| 134 |
|
|
{ 0, 0x44, 0xb2, 0xff }, |
| 135 |
|
|
{ 0, 0x22, 0x2d, 0xff } |
| 136 |
|
|
}; |
| 137 |
schorsch |
2.3 |
/* isset is a common bitmap related macro in <sys/param.h> */ |
| 138 |
|
|
static short cisset[64]; |
| 139 |
greg |
1.1 |
int pat; |
| 140 |
|
|
register int r, g, b; |
| 141 |
|
|
|
| 142 |
schorsch |
2.3 |
if (cisset[col]) { |
| 143 |
greg |
1.1 |
printf("%cCOL P%d", COM, col); |
| 144 |
|
|
return; |
| 145 |
|
|
} |
| 146 |
|
|
|
| 147 |
|
|
printf("%cPAT P%d C7", COM, col); |
| 148 |
|
|
|
| 149 |
|
|
r = cmask[0][col>>4]; |
| 150 |
|
|
g = cmask[1][(col>>2) & 03]; |
| 151 |
|
|
b = cmask[2][col & 03]; |
| 152 |
|
|
|
| 153 |
|
|
pat = r & ~(g|b); |
| 154 |
|
|
if (pat) { |
| 155 |
|
|
printf(" C1"); /* red */ |
| 156 |
|
|
printpat(pat); |
| 157 |
|
|
} |
| 158 |
|
|
pat = g & ~(r|b); |
| 159 |
|
|
if (pat) { |
| 160 |
|
|
printf(" C2"); /* green */ |
| 161 |
|
|
printpat(pat); |
| 162 |
|
|
} |
| 163 |
|
|
pat = b & ~(r|g); |
| 164 |
|
|
if (pat) { |
| 165 |
|
|
printf(" C3"); /* blue */ |
| 166 |
|
|
printpat(pat); |
| 167 |
|
|
} |
| 168 |
|
|
pat = r & g & ~b; |
| 169 |
|
|
if (pat) { |
| 170 |
|
|
printf(" C4"); /* yellow */ |
| 171 |
|
|
printpat(pat); |
| 172 |
|
|
} |
| 173 |
|
|
pat = r & b & ~g; |
| 174 |
|
|
if (pat) { |
| 175 |
|
|
printf(" C6"); /* magenta */ |
| 176 |
|
|
printpat(pat); |
| 177 |
|
|
} |
| 178 |
|
|
pat = g & b & ~r; |
| 179 |
|
|
if (pat) { |
| 180 |
|
|
printf(" C5"); /* cyan */ |
| 181 |
|
|
printpat(pat); |
| 182 |
|
|
} |
| 183 |
|
|
pat = r & g & b; |
| 184 |
|
|
if (pat) { |
| 185 |
|
|
printf(" C0"); /* white */ |
| 186 |
|
|
printpat(pat); |
| 187 |
|
|
} |
| 188 |
schorsch |
2.3 |
cisset[col] = 1; |
| 189 |
greg |
1.1 |
printf("%cCOL P%d", COM, col); |
| 190 |
|
|
} |
| 191 |
|
|
|
| 192 |
|
|
|
| 193 |
|
|
printpat(p) /* print out a pattern */ |
| 194 |
|
|
register int p; |
| 195 |
|
|
{ |
| 196 |
|
|
register int i; |
| 197 |
|
|
|
| 198 |
|
|
for (i = 0; i < 14; i++) { /* 14 rows */ |
| 199 |
|
|
|
| 200 |
|
|
printf(",%d", p); |
| 201 |
|
|
p = rorb(rorb(rorb(p))); /* rotate 3 bits */ |
| 202 |
|
|
} |
| 203 |
|
|
} |
| 204 |
|
|
|
| 205 |
|
|
|
| 206 |
|
|
int |
| 207 |
|
|
rorb(b) /* rotate a byte to the right */ |
| 208 |
|
|
register int b; |
| 209 |
|
|
{ |
| 210 |
|
|
b |= (b&01) << 8; |
| 211 |
|
|
b >>= 1; |
| 212 |
|
|
return(b); |
| 213 |
|
|
} |