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 |
|
|
17 |
– |
|
18 |
|
#define NROWS 1440 /* 10" at 144 dpi */ |
19 |
|
#define NCOLS 960 /* 8" at 120 dpi */ |
20 |
|
|
24 |
|
|
25 |
|
#define sub_add(sub) (2-(sub)) /* map subtractive to additive pri. */ |
26 |
|
|
27 |
+ |
#ifdef BSD |
28 |
+ |
#define clearlbuf() bzero((char *)lpat, sizeof(lpat)) |
29 |
+ |
#else |
30 |
+ |
#define clearlbuf() (void)memset((char *)lpat, 0, sizeof(lpat)) |
31 |
+ |
#endif |
32 |
|
|
33 |
+ |
long lpat[NCOLS][3]; |
34 |
+ |
|
35 |
+ |
|
36 |
|
main(argc, argv) |
37 |
|
int argc; |
38 |
|
char *argv[]; |
53 |
|
{ |
54 |
|
FILE *input; |
55 |
|
int xres, yres; |
56 |
< |
COLOR scanline[NCOLS]; |
56 |
> |
COLR scanline[NCOLS]; |
57 |
|
int i; |
58 |
|
|
59 |
|
if (fname == NULL) { |
64 |
|
return(-1); |
65 |
|
} |
66 |
|
/* discard header */ |
67 |
< |
getheader(input, NULL); |
67 |
> |
if (checkheader(input, COLRFMT, NULL) < 0) { |
68 |
> |
fprintf(stderr, "%s: not a Radiance picture\n", fname); |
69 |
> |
return(-1); |
70 |
> |
} |
71 |
|
/* get picture dimensions */ |
72 |
< |
if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) { |
72 |
> |
if (fgetresolu(&xres, &yres, input) < 0) { |
73 |
|
fprintf(stderr, "%s: bad picture size\n", fname); |
74 |
|
return(-1); |
75 |
|
} |
78 |
|
return(-1); |
79 |
|
} |
80 |
|
/* set line spacing (overlap for knitting) */ |
81 |
< |
fputs("\0333\036", stdout); |
81 |
> |
fputs("\0333\042", stdout); |
82 |
> |
/* clear line buffer */ |
83 |
> |
clearlbuf(); |
84 |
|
/* put out scanlines */ |
85 |
|
for (i = yres-1; i >= 0; i--) { |
86 |
< |
if (freadscan(scanline, xres, input) < 0) { |
86 |
> |
if (freadcolrs(scanline, xres, input) < 0) { |
87 |
|
fprintf(stderr, "%s: read error (y=%d)\n", fname, i); |
88 |
|
return(-1); |
89 |
|
} |
90 |
+ |
normcolrs(scanline, xres, 0); |
91 |
|
plotscan(scanline, xres, i); |
92 |
|
} |
93 |
|
/* advance page */ |
100 |
|
|
101 |
|
|
102 |
|
plotscan(scan, len, y) /* plot a scanline */ |
103 |
< |
COLOR scan[]; |
103 |
> |
COLR scan[]; |
104 |
|
int len; |
105 |
|
int y; |
106 |
|
{ |
93 |
– |
static long pat[NCOLS][3]; |
107 |
|
int bpos; |
108 |
|
register long c; |
109 |
|
register int i, j; |
110 |
|
|
111 |
< |
if (bpos = y % 20) { |
111 |
> |
if (bpos = y % 23) { |
112 |
|
|
113 |
< |
if (y > 20 & bpos < 4) /* knit bits */ |
114 |
< |
for (j = 0; j < 3; j++) |
115 |
< |
for (i = 0; i < len; i++) |
103 |
< |
pat[i][j] |= (long)colbit(scan[i],i,j) |
104 |
< |
<< (i+j & 4 ? bpos+24 : bpos); |
105 |
< |
else |
106 |
< |
for (j = 0; j < 3; j++) |
107 |
< |
for (i = 0; i < len; i++) |
108 |
< |
pat[i][j] |= (long)colbit(scan[i],i,j) |
109 |
< |
<< bpos; |
113 |
> |
for (j = 0; j < 3; j++) |
114 |
> |
for (i = 0; i < len; i++) |
115 |
> |
lpat[i][j] |= (long)colbit(scan[i],i,j) << bpos; |
116 |
|
|
117 |
|
} else { |
118 |
|
|
120 |
|
|
121 |
|
for (j = 0; j < 3; j++) { |
122 |
|
fputs("\033%O", stdout); |
123 |
< |
putchar(len & 0xff); |
123 |
> |
putchar(len & 255); |
124 |
|
putchar(len >> 8); |
125 |
|
for (i = 0; i < len; i++) { |
126 |
< |
c = pat[i][j]; |
127 |
< |
pat[i][j] = c>>4 & 0xf00000; |
128 |
< |
if (i+j & 4) /* knit last bit */ |
129 |
< |
pat[i][j] |= colbit(scan[i],i,j) << 20; |
130 |
< |
else |
131 |
< |
c |= colbit(scan[i],i,j); |
126 |
< |
putchar(c>>16 & 0xff); |
127 |
< |
putchar(c>>8 & 0xff); |
128 |
< |
putchar(c & 0xff); |
126 |
> |
c = lpat[i][j] | colbit(scan[i],i,j); |
127 |
> |
/* repeat this row */ |
128 |
> |
lpat[i][j] = (c & 1) << 23; |
129 |
> |
putchar(c>>16); |
130 |
> |
putchar(c>>8 & 255); |
131 |
> |
putchar(c & 255); |
132 |
|
} |
133 |
|
putchar('\r'); |
134 |
|
} |
138 |
|
|
139 |
|
|
140 |
|
colbit(col, x, s) /* determine bit value for primary at x */ |
141 |
< |
COLOR col; |
141 |
> |
COLR col; |
142 |
|
register int x; |
143 |
|
int s; |
144 |
|
{ |
145 |
< |
static float cerr[NCOLS][3]; |
146 |
< |
static double err[3]; |
147 |
< |
double b; |
145 |
> |
static int cerr[NCOLS][3]; |
146 |
> |
static int err[3]; |
147 |
> |
int b, errp; |
148 |
|
register int a, ison; |
149 |
|
|
150 |
|
a = sub_add(s); /* use additive primary */ |
151 |
< |
b = colval(col,a); |
152 |
< |
if (b > 1.0) b = 1.0; |
151 |
> |
b = col[a]; |
152 |
> |
errp = err[a]; |
153 |
|
err[a] += b + cerr[x][a]; |
154 |
< |
ison = err[a] < 0.5; |
155 |
< |
if (!ison) err[a] -= 1.0; |
156 |
< |
cerr[x][a] = err[a] *= 0.5; |
154 |
> |
ison = err[a] < 128; |
155 |
> |
if (!ison) err[a] -= 256; |
156 |
> |
err[a] /= 3; |
157 |
> |
cerr[x][a] = err[a] + errp; |
158 |
|
return(ison); |
159 |
|
} |