1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
11 |
|
*/ |
12 |
|
|
13 |
|
#include <stdio.h> |
14 |
+ |
#ifdef MSDOS |
15 |
+ |
#include <fcntl.h> |
16 |
+ |
#endif |
17 |
|
|
18 |
|
#include "color.h" |
19 |
+ |
#include "resolu.h" |
20 |
|
|
21 |
< |
#define NCOLS 880 /* for wide carriage */ |
21 |
> |
#define NCOLS 880 /* for wide carriage */ |
22 |
|
|
23 |
|
|
24 |
|
main(argc, argv) |
27 |
|
{ |
28 |
|
int i; |
29 |
|
int status = 0; |
30 |
< |
|
30 |
> |
#ifdef MSDOS |
31 |
> |
extern int _fmode; |
32 |
> |
_fmode = O_BINARY; |
33 |
> |
setmode(fileno(stdin), O_BINARY); |
34 |
> |
setmode(fileno(stdout), O_BINARY); |
35 |
> |
#endif |
36 |
|
if (argc < 2) |
37 |
|
status += printp(NULL) == -1; |
38 |
|
else |
47 |
|
{ |
48 |
|
FILE *input; |
49 |
|
int xres, yres; |
50 |
< |
COLOR scanline[NCOLS]; |
42 |
< |
char sbuf[256]; |
50 |
> |
COLR scanline[NCOLS]; |
51 |
|
int i; |
52 |
< |
|
52 |
> |
|
53 |
|
if (fname == NULL) { |
54 |
|
input = stdin; |
55 |
|
fname = "<stdin>"; |
58 |
|
return(-1); |
59 |
|
} |
60 |
|
/* discard header */ |
61 |
< |
while (fgets(sbuf, sizeof(sbuf), input) != NULL && sbuf[0] != '\n') |
62 |
< |
; |
61 |
> |
if (checkheader(input, COLRFMT, NULL) < 0) { |
62 |
> |
fprintf(stderr, "%s: not a Radiance picture\n", fname); |
63 |
> |
return(-1); |
64 |
> |
} |
65 |
|
/* get picture dimensions */ |
66 |
< |
if (fgets(sbuf, sizeof(sbuf), input) == NULL || |
57 |
< |
sscanf(sbuf, "-Y %d +X %d\n", &yres, &xres) != 2) { |
66 |
> |
if (fgetresolu(&xres, &yres, input) < 0) { |
67 |
|
fprintf(stderr, "%s: bad picture size\n", fname); |
68 |
|
return(-1); |
69 |
|
} |
73 |
|
} |
74 |
|
|
75 |
|
fputs("\033[6~\033[7z", stdout); |
76 |
+ |
#ifdef _IOLBF |
77 |
+ |
stdout->_flag &= ~_IOLBF; |
78 |
+ |
#endif |
79 |
|
|
80 |
|
for (i = yres-1; i >= 0; i--) { |
81 |
< |
if (freadscan(scanline, xres, input) < 0) { |
81 |
> |
if (freadcolrs(scanline, xres, input) < 0) { |
82 |
|
fprintf(stderr, "%s: read error (y=%d)\n", fname, i); |
83 |
|
return(-1); |
84 |
|
} |
85 |
+ |
normcolrs(scanline, xres, 0); |
86 |
|
plotscan(scanline, xres, i); |
87 |
|
} |
88 |
|
|
95 |
|
|
96 |
|
|
97 |
|
plotscan(scan, len, y) /* plot a scanline */ |
98 |
< |
COLOR scan[]; |
98 |
> |
COLR scan[]; |
99 |
|
int len; |
100 |
|
int y; |
101 |
|
{ |
121 |
|
} |
122 |
|
putchar('\r'); |
123 |
|
putchar('\n'); |
124 |
+ |
fflush(stdout); |
125 |
|
} |
126 |
|
} |
127 |
|
|
128 |
|
|
129 |
< |
bit(col, x) /* return bit for color at x */ |
130 |
< |
COLOR col; |
129 |
> |
bit(clr, x) /* return bit for color at x */ |
130 |
> |
COLR clr; |
131 |
|
register int x; |
132 |
|
{ |
133 |
< |
static float cerr[NCOLS]; |
134 |
< |
static double err; |
135 |
< |
double b; |
133 |
> |
static int cerr[NCOLS]; |
134 |
> |
static int err; |
135 |
> |
int b, errp; |
136 |
|
register int isblack; |
137 |
|
|
138 |
< |
b = bright(col); |
139 |
< |
if (b > 1.0) b = 1.0; |
138 |
> |
b = normbright(clr); |
139 |
> |
errp = err; |
140 |
|
err += b + cerr[x]; |
141 |
< |
isblack = err < 0.5; |
142 |
< |
if (!isblack) err -= 1.0; |
143 |
< |
cerr[x] = err *= 0.5; |
141 |
> |
isblack = err < 128; |
142 |
> |
if (!isblack) err -= 256; |
143 |
> |
err /= 3; |
144 |
> |
cerr[x] = err + errp; |
145 |
|
return(isblack); |
146 |
|
} |