38 |
|
{ |
39 |
|
FILE *input; |
40 |
|
int xres, yres; |
41 |
< |
COLOR scanline[NCOLS]; |
42 |
< |
char sbuf[256]; |
41 |
> |
COLR scanline[NCOLS]; |
42 |
|
int i; |
43 |
|
|
44 |
|
if (fname == NULL) { |
49 |
|
return(-1); |
50 |
|
} |
51 |
|
/* discard header */ |
52 |
< |
while (fgets(sbuf, sizeof(sbuf), input) != NULL && sbuf[0] != '\n') |
54 |
< |
; |
52 |
> |
getheader(input, NULL); |
53 |
|
/* get picture dimensions */ |
54 |
< |
if (fgets(sbuf, sizeof(sbuf), input) == NULL || |
57 |
< |
sscanf(sbuf, "-Y %d +X %d\n", &yres, &xres) != 2) { |
54 |
> |
if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) { |
55 |
|
fprintf(stderr, "%s: bad picture size\n", fname); |
56 |
|
return(-1); |
57 |
|
} |
63 |
|
fputs("\033[6~\033[7z", stdout); |
64 |
|
|
65 |
|
for (i = yres-1; i >= 0; i--) { |
66 |
< |
if (freadscan(scanline, xres, input) < 0) { |
66 |
> |
if (freadcolrs(scanline, xres, input) < 0) { |
67 |
|
fprintf(stderr, "%s: read error (y=%d)\n", fname, i); |
68 |
|
return(-1); |
69 |
|
} |
70 |
+ |
normcolrs(scanline, xres); |
71 |
|
plotscan(scanline, xres, i); |
72 |
|
} |
73 |
|
|
80 |
|
|
81 |
|
|
82 |
|
plotscan(scan, len, y) /* plot a scanline */ |
83 |
< |
COLOR scan[]; |
83 |
> |
COLR scan[]; |
84 |
|
int len; |
85 |
|
int y; |
86 |
|
{ |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
< |
bit(col, x) /* return bit for color at x */ |
114 |
< |
COLOR col; |
113 |
> |
bit(clr, x) /* return bit for color at x */ |
114 |
> |
COLR clr; |
115 |
|
register int x; |
116 |
|
{ |
117 |
< |
static float cerr[NCOLS]; |
118 |
< |
static double err; |
119 |
< |
double b; |
117 |
> |
static int cerr[NCOLS]; |
118 |
> |
static int err; |
119 |
> |
int b; |
120 |
|
register int isblack; |
121 |
|
|
122 |
< |
b = bright(col); |
125 |
< |
if (b > 1.0) b = 1.0; |
122 |
> |
b = normbright(clr); |
123 |
|
err += b + cerr[x]; |
124 |
< |
isblack = err < 0.5; |
125 |
< |
if (!isblack) err -= 1.0; |
126 |
< |
cerr[x] = err *= 0.5; |
124 |
> |
isblack = err < 128; |
125 |
> |
if (!isblack) err -= 256; |
126 |
> |
cerr[x] = err /= 2; |
127 |
|
return(isblack); |
128 |
|
} |