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 |
48 |
|
FILE *input; |
49 |
|
int xres, yres; |
50 |
|
COLR scanline[NCOLS]; |
42 |
– |
char sbuf[256]; |
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 (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) { |
66 |
> |
if (fgetresolu(&xres, &yres, input) < 0) { |
67 |
|
fprintf(stderr, "%s: bad picture size\n", fname); |
68 |
|
return(-1); |
69 |
|
} |
79 |
|
fprintf(stderr, "%s: read error (y=%d)\n", fname, i); |
80 |
|
return(-1); |
81 |
|
} |
82 |
+ |
normcolrs(scanline, xres, 0); |
83 |
|
plotscan(scanline, xres, i); |
84 |
|
} |
85 |
|
|
118 |
|
} |
119 |
|
putchar('\r'); |
120 |
|
putchar('\n'); |
121 |
+ |
fflush(stdout); |
122 |
|
} |
123 |
|
} |
124 |
|
|
129 |
|
{ |
130 |
|
static int cerr[NCOLS]; |
131 |
|
static int err; |
132 |
< |
COLR nclr; |
121 |
< |
int b; |
132 |
> |
int b, errp; |
133 |
|
register int isblack; |
134 |
|
|
135 |
< |
colr_norm(clr, nclr); |
136 |
< |
b = norm_bright(nclr); |
135 |
> |
b = normbright(clr); |
136 |
> |
errp = err; |
137 |
|
err += b + cerr[x]; |
138 |
|
isblack = err < 128; |
139 |
|
if (!isblack) err -= 256; |
140 |
< |
cerr[x] = err /= 2; |
140 |
> |
err /= 3; |
141 |
> |
cerr[x] = err + errp; |
142 |
|
return(isblack); |
143 |
|
} |