1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
13 |
|
#include <stdio.h> |
14 |
|
|
15 |
|
#include "color.h" |
16 |
+ |
#include "resolu.h" |
17 |
|
|
18 |
|
#define NCOLS 880 /* for wide carriage */ |
19 |
|
|
39 |
|
{ |
40 |
|
FILE *input; |
41 |
|
int xres, yres; |
42 |
< |
COLOR scanline[NCOLS]; |
42 |
< |
char sbuf[256]; |
42 |
> |
COLR scanline[NCOLS]; |
43 |
|
int i; |
44 |
|
|
45 |
|
if (fname == NULL) { |
50 |
|
return(-1); |
51 |
|
} |
52 |
|
/* discard header */ |
53 |
< |
while (fgets(sbuf, sizeof(sbuf), input) != NULL && sbuf[0] != '\n') |
54 |
< |
; |
53 |
> |
if (checkheader(input, COLRFMT, NULL) < 0) { |
54 |
> |
fprintf(stderr, "%s: not a Radiance picture\n", fname); |
55 |
> |
return(-1); |
56 |
> |
} |
57 |
|
/* get picture dimensions */ |
58 |
< |
if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) { |
58 |
> |
if (fgetresolu(&xres, &yres, input) < 0) { |
59 |
|
fprintf(stderr, "%s: bad picture size\n", fname); |
60 |
|
return(-1); |
61 |
|
} |
67 |
|
fputs("\033[6~\033[7z", stdout); |
68 |
|
|
69 |
|
for (i = yres-1; i >= 0; i--) { |
70 |
< |
if (freadscan(scanline, xres, input) < 0) { |
70 |
> |
if (freadcolrs(scanline, xres, input) < 0) { |
71 |
|
fprintf(stderr, "%s: read error (y=%d)\n", fname, i); |
72 |
|
return(-1); |
73 |
|
} |
74 |
+ |
normcolrs(scanline, xres, 0); |
75 |
|
plotscan(scanline, xres, i); |
76 |
|
} |
77 |
|
|
84 |
|
|
85 |
|
|
86 |
|
plotscan(scan, len, y) /* plot a scanline */ |
87 |
< |
COLOR scan[]; |
87 |
> |
COLR scan[]; |
88 |
|
int len; |
89 |
|
int y; |
90 |
|
{ |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
< |
bit(col, x) /* return bit for color at x */ |
118 |
< |
COLOR col; |
117 |
> |
bit(clr, x) /* return bit for color at x */ |
118 |
> |
COLR clr; |
119 |
|
register int x; |
120 |
|
{ |
121 |
< |
static float cerr[NCOLS]; |
122 |
< |
static double err; |
123 |
< |
double b; |
121 |
> |
static int cerr[NCOLS]; |
122 |
> |
static int err, errp; |
123 |
> |
int b; |
124 |
|
register int isblack; |
125 |
|
|
126 |
< |
b = bright(col); |
127 |
< |
if (b > 1.0) b = 1.0; |
126 |
> |
b = normbright(clr); |
127 |
> |
errp = err; |
128 |
|
err += b + cerr[x]; |
129 |
< |
isblack = err < 0.5; |
130 |
< |
if (!isblack) err -= 1.0; |
131 |
< |
cerr[x] = err *= 0.5; |
129 |
> |
isblack = err < 128; |
130 |
> |
if (!isblack) err -= 256; |
131 |
> |
err /= 3; |
132 |
> |
cerr[x] = err + errp; |
133 |
|
return(isblack); |
134 |
|
} |