37 |
|
{ |
38 |
|
FILE *input; |
39 |
|
int xres, yres; |
40 |
< |
COLOR scanline[NCOLS]; |
40 |
> |
COLR scanline[NCOLS]; |
41 |
|
int i; |
42 |
|
|
43 |
|
if (fname == NULL) { |
48 |
|
return(-1); |
49 |
|
} |
50 |
|
/* discard header */ |
51 |
< |
getheader(input, NULL); |
51 |
> |
if (checkheader(input, COLRFMT, NULL) < 0) { |
52 |
> |
fprintf(stderr, "%s: not a Radiance picture\n", fname); |
53 |
> |
return(-1); |
54 |
> |
} |
55 |
|
/* get picture dimensions */ |
56 |
|
if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) { |
57 |
|
fprintf(stderr, "%s: bad picture size\n", fname); |
68 |
|
((NCOLS-xres)>>4)<<5, xres); |
69 |
|
|
70 |
|
for (i = yres-1; i >= 0; i--) { |
71 |
< |
if (freadscan(scanline, xres, input) < 0) |
71 |
> |
if (freadcolrs(scanline, xres, input) < 0) |
72 |
|
return(-1); |
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 |
|
{ |
107 |
|
|
108 |
|
|
109 |
|
colbit(col, x, a) /* determine bit value for primary at x */ |
110 |
< |
COLOR col; |
110 |
> |
COLR col; |
111 |
|
register int x; |
112 |
|
register int a; |
113 |
|
{ |
114 |
< |
static float cerr[NCOLS][3]; |
115 |
< |
static double err[3]; |
116 |
< |
double b; |
114 |
> |
static int cerr[NCOLS][3]; |
115 |
> |
static int err[3]; |
116 |
> |
int b; |
117 |
|
register int ison; |
118 |
|
|
119 |
< |
b = colval(col,a); |
116 |
< |
if (b > 1.0) b = 1.0; |
119 |
> |
b = col[a]; |
120 |
|
err[a] += b + cerr[x][a]; |
121 |
< |
ison = err[a] > 0.5; |
122 |
< |
if (ison) err[a] -= 1.0; |
123 |
< |
cerr[x][a] = err[a] *= 0.5; |
121 |
> |
ison = err[a] > 128; |
122 |
> |
if (ison) err[a] -= 256; |
123 |
> |
cerr[x][a] = err[a] /= 2; |
124 |
|
return(ison); |
125 |
|
} |