1 |
< |
/* Copyright (c) 1989 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 1440 /* 8" at 180 dpi */ |
19 |
|
|
38 |
|
{ |
39 |
|
FILE *input; |
40 |
|
int xres, yres; |
41 |
< |
COLOR scanline[NCOLS]; |
41 |
> |
COLR scanline[NCOLS]; |
42 |
|
int i; |
43 |
|
|
44 |
|
if (fname == NULL) { |
49 |
|
return(-1); |
50 |
|
} |
51 |
|
/* discard header */ |
52 |
< |
getheader(input, NULL); |
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 (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) { |
57 |
> |
if (fgetresolu(&xres, &yres, input) < 0) { |
58 |
|
fprintf(stderr, "%s: bad picture size\n", fname); |
59 |
|
return(-1); |
60 |
|
} |
69 |
|
((NCOLS-xres)>>4)<<5, xres); |
70 |
|
|
71 |
|
for (i = yres-1; i >= 0; i--) { |
72 |
< |
if (freadscan(scanline, xres, input) < 0) |
72 |
> |
if (freadcolrs(scanline, xres, input) < 0) |
73 |
|
return(-1); |
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 |
|
{ |
108 |
|
|
109 |
|
|
110 |
|
colbit(col, x, a) /* determine bit value for primary at x */ |
111 |
< |
COLOR col; |
111 |
> |
COLR col; |
112 |
|
register int x; |
113 |
|
register int a; |
114 |
|
{ |
115 |
< |
static float cerr[NCOLS][3]; |
116 |
< |
static double err[3]; |
117 |
< |
double b; |
115 |
> |
static int cerr[NCOLS][3]; |
116 |
> |
static int err[3], errp[3]; |
117 |
> |
int b; |
118 |
|
register int ison; |
119 |
|
|
120 |
< |
b = colval(col,a); |
121 |
< |
if (b > 1.0) b = 1.0; |
120 |
> |
b = col[a]; |
121 |
> |
errp[a] = err[a]; |
122 |
|
err[a] += b + cerr[x][a]; |
123 |
< |
ison = err[a] > 0.5; |
124 |
< |
if (ison) err[a] -= 1.0; |
125 |
< |
cerr[x][a] = err[a] *= 0.5; |
123 |
> |
ison = err[a] > 128; |
124 |
> |
if (ison) err[a] -= 256; |
125 |
> |
err[a] /= 3; |
126 |
> |
cerr[x][a] = err[a] + errp[a]; |
127 |
|
return(ison); |
128 |
|
} |