45 |
|
{ |
46 |
|
FILE *input; |
47 |
|
int xres, yres; |
48 |
< |
COLOR scanline[NCOLS]; |
48 |
> |
COLR scanline[NCOLS]; |
49 |
|
int i; |
50 |
|
|
51 |
|
if (fname == NULL) { |
58 |
|
/* discard header */ |
59 |
|
getheader(input, NULL); |
60 |
|
/* get picture dimensions */ |
61 |
< |
if (fscanf(input, "-Y %d +X %d\n", &yres, &xres) != 2) { |
61 |
> |
if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) { |
62 |
|
fprintf(stderr, "%s: bad picture size\n", fname); |
63 |
|
return(-1); |
64 |
|
} |
66 |
|
fprintf(stderr, "%s: resolution mismatch\n", fname); |
67 |
|
return(-1); |
68 |
|
} |
69 |
< |
|
70 |
< |
fputs("\033A\014\0332", stdout); |
71 |
< |
|
69 |
> |
/* set line spacing (overlap for knitting) */ |
70 |
> |
fputs("\0333\042", stdout); |
71 |
> |
/* put out scanlines */ |
72 |
|
for (i = yres-1; i >= 0; i--) { |
73 |
< |
if (freadscan(scanline, xres, input) < 0) { |
73 |
> |
if (freadcolrs(scanline, xres, input) < 0) { |
74 |
|
fprintf(stderr, "%s: read error (y=%d)\n", fname, i); |
75 |
|
return(-1); |
76 |
|
} |
77 |
+ |
normscan(scanline, xres); |
78 |
|
plotscan(scanline, xres, i); |
79 |
|
} |
80 |
< |
|
80 |
> |
/* advance page */ |
81 |
|
putchar('\f'); |
82 |
|
|
83 |
|
fclose(input); |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
+ |
normscan(scan, len) /* normalize a scanline */ |
90 |
+ |
register COLR scan[]; |
91 |
+ |
int len; |
92 |
+ |
{ |
93 |
+ |
register int i; |
94 |
+ |
|
95 |
+ |
for (i = 0; i < len; i++) |
96 |
+ |
colr_norm(scan[i], scan[i]); |
97 |
+ |
} |
98 |
+ |
|
99 |
+ |
|
100 |
|
plotscan(scan, len, y) /* plot a scanline */ |
101 |
< |
COLOR scan[]; |
101 |
> |
COLR scan[]; |
102 |
|
int len; |
103 |
|
int y; |
104 |
|
{ |
107 |
|
register long c; |
108 |
|
register int i, j; |
109 |
|
|
110 |
< |
if (bpos = y % 24) { |
110 |
> |
if (bpos = y % 23) { |
111 |
|
|
112 |
|
for (j = 0; j < 3; j++) |
113 |
|
for (i = 0; i < len; i++) |
123 |
|
putchar(len >> 8); |
124 |
|
for (i = 0; i < len; i++) { |
125 |
|
c = pat[i][j] | colbit(scan[i],i,j); |
126 |
< |
pat[i][j] = 0; |
126 |
> |
/* repeat this row */ |
127 |
> |
pat[i][j] = (c & 1) << 23; |
128 |
|
putchar(c>>16); |
129 |
|
putchar(c>>8 & 255); |
130 |
|
putchar(c & 255); |
137 |
|
|
138 |
|
|
139 |
|
colbit(col, x, s) /* determine bit value for primary at x */ |
140 |
< |
COLOR col; |
140 |
> |
COLR col; |
141 |
|
register int x; |
142 |
|
int s; |
143 |
|
{ |
144 |
< |
static float cerr[NCOLS][3]; |
145 |
< |
static double err[3]; |
146 |
< |
double b; |
144 |
> |
static int cerr[NCOLS][3]; |
145 |
> |
static int err[3]; |
146 |
> |
int b; |
147 |
|
register int a, ison; |
148 |
|
|
149 |
|
a = sub_add(s); /* use additive primary */ |
150 |
< |
b = colval(col,a); |
138 |
< |
if (b > 1.0) b = 1.0; |
150 |
> |
b = col[a]; |
151 |
|
err[a] += b + cerr[x][a]; |
152 |
< |
ison = err[a] < 0.5; |
153 |
< |
if (!ison) err[a] -= 1.0; |
154 |
< |
cerr[x][a] = err[a] *= 0.5; |
152 |
> |
ison = err[a] < 128; |
153 |
> |
if (!ison) err[a] -= 256; |
154 |
> |
cerr[x][a] = err[a] /= 2; |
155 |
|
return(ison); |
156 |
|
} |