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') |
53 |
< |
; |
52 |
> |
if (checkheader(input, COLRFMT, NULL) < 0) { |
53 |
> |
fprintf(stderr, "%s: not a Radiance picture\n", fname); |
54 |
> |
return(-1); |
55 |
> |
} |
56 |
|
/* get picture dimensions */ |
57 |
< |
if (fgets(sbuf, sizeof(sbuf), input) == NULL || |
57 |
< |
sscanf(sbuf, "-Y %d +X %d\n", &yres, &xres) != 2) { |
57 |
> |
if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) { |
58 |
|
fprintf(stderr, "%s: bad picture size\n", fname); |
59 |
|
return(-1); |
60 |
|
} |
66 |
|
fputs("\033[6~\033[7z", stdout); |
67 |
|
|
68 |
|
for (i = yres-1; i >= 0; i--) { |
69 |
< |
if (freadscan(scanline, xres, input) < 0) { |
69 |
> |
if (freadcolrs(scanline, xres, input) < 0) { |
70 |
|
fprintf(stderr, "%s: read error (y=%d)\n", fname, i); |
71 |
|
return(-1); |
72 |
|
} |
73 |
+ |
normcolrs(scanline, xres, 0); |
74 |
|
plotscan(scanline, xres, i); |
75 |
|
} |
76 |
|
|
83 |
|
|
84 |
|
|
85 |
|
plotscan(scan, len, y) /* plot a scanline */ |
86 |
< |
COLOR scan[]; |
86 |
> |
COLR scan[]; |
87 |
|
int len; |
88 |
|
int y; |
89 |
|
{ |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
< |
bit(col, x) /* return bit for color at x */ |
117 |
< |
COLOR col; |
116 |
> |
bit(clr, x) /* return bit for color at x */ |
117 |
> |
COLR clr; |
118 |
|
register int x; |
119 |
|
{ |
120 |
< |
static float cerr[NCOLS]; |
121 |
< |
static double err; |
122 |
< |
double b; |
120 |
> |
static int cerr[NCOLS]; |
121 |
> |
static int err; |
122 |
> |
int b; |
123 |
|
register int isblack; |
124 |
|
|
125 |
< |
b = bright(col); |
125 |
< |
if (b > 1.0) b = 1.0; |
125 |
> |
b = normbright(clr); |
126 |
|
err += b + cerr[x]; |
127 |
< |
isblack = err < 0.5; |
128 |
< |
if (!isblack) err -= 1.0; |
129 |
< |
cerr[x] = err *= 0.5; |
127 |
> |
isblack = err < 128; |
128 |
> |
if (!isblack) err -= 256; |
129 |
> |
cerr[x] = err /= 2; |
130 |
|
return(isblack); |
131 |
|
} |