1 |
greg |
2.8 |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
greg |
1.1 |
|
3 |
|
|
#ifndef lint |
4 |
|
|
static char SCCSid[] = "$SunId$ LBL"; |
5 |
|
|
#endif |
6 |
|
|
|
7 |
|
|
/* |
8 |
|
|
* oki20c.c - program to dump pixel file to OkiMate 20 color printer. |
9 |
|
|
*/ |
10 |
|
|
|
11 |
|
|
#include <stdio.h> |
12 |
|
|
|
13 |
|
|
#include "color.h" |
14 |
greg |
1.12 |
#include "resolu.h" |
15 |
greg |
1.1 |
|
16 |
|
|
#define NROWS 1440 /* 10" at 144 dpi */ |
17 |
|
|
#define NCOLS 960 /* 8" at 120 dpi */ |
18 |
|
|
|
19 |
greg |
2.3 |
#define ASPECT (120./144.) /* pixel aspect ratio */ |
20 |
|
|
|
21 |
|
|
#define FILTER "pfilt -1 -x %d -y %d -p %f %s",NCOLS,NROWS,ASPECT |
22 |
|
|
|
23 |
greg |
1.1 |
/* |
24 |
|
|
* Subtractive primaries are ordered: Yellow, Magenta, Cyan. |
25 |
|
|
*/ |
26 |
|
|
|
27 |
|
|
#define sub_add(sub) (2-(sub)) /* map subtractive to additive pri. */ |
28 |
|
|
|
29 |
greg |
1.9 |
long lpat[NCOLS][3]; |
30 |
|
|
|
31 |
greg |
2.3 |
int dofilter = 0; /* filter through pfilt first? */ |
32 |
greg |
1.9 |
|
33 |
greg |
2.3 |
|
34 |
greg |
1.1 |
main(argc, argv) |
35 |
|
|
int argc; |
36 |
|
|
char *argv[]; |
37 |
|
|
{ |
38 |
|
|
int i, status = 0; |
39 |
|
|
|
40 |
greg |
2.3 |
if (argc > 1 && !strcmp(argv[1], "-p")) { |
41 |
|
|
dofilter++; |
42 |
|
|
argv++; argc--; |
43 |
|
|
} |
44 |
greg |
2.5 |
#ifdef _IOLBF |
45 |
|
|
stdout->_flag &= ~_IOLBF; |
46 |
|
|
#endif |
47 |
greg |
1.1 |
if (argc < 2) |
48 |
|
|
status = printp(NULL) == -1; |
49 |
|
|
else |
50 |
|
|
for (i = 1; i < argc; i++) |
51 |
|
|
status += printp(argv[i]) == -1; |
52 |
|
|
exit(status); |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
|
56 |
|
|
printp(fname) /* print a picture */ |
57 |
|
|
char *fname; |
58 |
|
|
{ |
59 |
greg |
2.3 |
char buf[64]; |
60 |
greg |
1.1 |
FILE *input; |
61 |
|
|
int xres, yres; |
62 |
greg |
1.6 |
COLR scanline[NCOLS]; |
63 |
greg |
1.1 |
int i; |
64 |
|
|
|
65 |
greg |
2.3 |
if (dofilter) { |
66 |
greg |
2.6 |
if (fname == NULL) { |
67 |
|
|
sprintf(buf, FILTER, ""); |
68 |
|
|
fname = "<stdin>"; |
69 |
|
|
} else |
70 |
|
|
sprintf(buf, FILTER, fname); |
71 |
greg |
2.3 |
if ((input = popen(buf, "r")) == NULL) { |
72 |
|
|
fprintf(stderr, "Cannot execute: %s\n", buf); |
73 |
|
|
return(-1); |
74 |
|
|
} |
75 |
|
|
} else if (fname == NULL) { |
76 |
greg |
1.1 |
input = stdin; |
77 |
|
|
fname = "<stdin>"; |
78 |
|
|
} else if ((input = fopen(fname, "r")) == NULL) { |
79 |
|
|
fprintf(stderr, "%s: cannot open\n", fname); |
80 |
|
|
return(-1); |
81 |
|
|
} |
82 |
|
|
/* discard header */ |
83 |
greg |
1.10 |
if (checkheader(input, COLRFMT, NULL) < 0) { |
84 |
|
|
fprintf(stderr, "%s: not a Radiance picture\n", fname); |
85 |
|
|
return(-1); |
86 |
|
|
} |
87 |
greg |
1.1 |
/* get picture dimensions */ |
88 |
greg |
1.12 |
if (fgetresolu(&xres, &yres, input) < 0) { |
89 |
greg |
1.1 |
fprintf(stderr, "%s: bad picture size\n", fname); |
90 |
|
|
return(-1); |
91 |
|
|
} |
92 |
greg |
2.7 |
if (xres > NCOLS) { |
93 |
greg |
1.1 |
fprintf(stderr, "%s: resolution mismatch\n", fname); |
94 |
|
|
return(-1); |
95 |
|
|
} |
96 |
greg |
1.3 |
/* set line spacing (overlap for knitting) */ |
97 |
greg |
1.5 |
fputs("\0333\042", stdout); |
98 |
greg |
1.3 |
/* put out scanlines */ |
99 |
greg |
1.1 |
for (i = yres-1; i >= 0; i--) { |
100 |
greg |
1.6 |
if (freadcolrs(scanline, xres, input) < 0) { |
101 |
greg |
1.1 |
fprintf(stderr, "%s: read error (y=%d)\n", fname, i); |
102 |
|
|
return(-1); |
103 |
|
|
} |
104 |
greg |
1.8 |
normcolrs(scanline, xres, 0); |
105 |
greg |
1.1 |
plotscan(scanline, xres, i); |
106 |
|
|
} |
107 |
greg |
1.3 |
/* advance page */ |
108 |
greg |
1.1 |
putchar('\f'); |
109 |
|
|
|
110 |
greg |
2.3 |
if (dofilter) |
111 |
|
|
pclose(input); |
112 |
|
|
else |
113 |
|
|
fclose(input); |
114 |
greg |
1.1 |
|
115 |
|
|
return(0); |
116 |
greg |
1.6 |
} |
117 |
|
|
|
118 |
|
|
|
119 |
greg |
1.1 |
plotscan(scan, len, y) /* plot a scanline */ |
120 |
greg |
1.6 |
COLR scan[]; |
121 |
greg |
1.1 |
int len; |
122 |
|
|
int y; |
123 |
|
|
{ |
124 |
|
|
int bpos; |
125 |
|
|
register long c; |
126 |
|
|
register int i, j; |
127 |
|
|
|
128 |
greg |
1.5 |
if (bpos = y % 23) { |
129 |
greg |
1.1 |
|
130 |
greg |
1.5 |
for (j = 0; j < 3; j++) |
131 |
|
|
for (i = 0; i < len; i++) |
132 |
greg |
1.9 |
lpat[i][j] |= (long)colbit(scan[i],i,j) << bpos; |
133 |
greg |
2.8 |
return; |
134 |
|
|
} |
135 |
|
|
fputs("\033\031", stdout); |
136 |
greg |
1.1 |
|
137 |
greg |
2.8 |
for (j = 0; j < 3; j++) { |
138 |
|
|
i = (NCOLS + len)/2; /* center image */ |
139 |
|
|
fputs("\033%O", stdout); |
140 |
|
|
putchar(i & 255); |
141 |
|
|
putchar(i >> 8); |
142 |
|
|
while (i-- > len) { |
143 |
|
|
putchar(0); |
144 |
|
|
putchar(0); |
145 |
|
|
putchar(0); |
146 |
|
|
} |
147 |
|
|
for (i = 0; i < len; i++) { |
148 |
|
|
c = lpat[i][j] | colbit(scan[i],i,j); |
149 |
|
|
putchar(c>>16); |
150 |
|
|
putchar(c>>8 & 255); |
151 |
|
|
putchar(c & 255); |
152 |
|
|
if (y) /* repeat this row */ |
153 |
greg |
1.9 |
lpat[i][j] = (c & 1) << 23; |
154 |
greg |
2.8 |
else /* or clear for next image */ |
155 |
|
|
lpat[i][j] = 0L; |
156 |
greg |
1.1 |
} |
157 |
greg |
2.8 |
putchar('\r'); |
158 |
greg |
1.1 |
} |
159 |
greg |
2.8 |
putchar('\n'); |
160 |
|
|
fflush(stdout); |
161 |
greg |
1.1 |
} |
162 |
|
|
|
163 |
|
|
|
164 |
|
|
colbit(col, x, s) /* determine bit value for primary at x */ |
165 |
greg |
1.6 |
COLR col; |
166 |
greg |
1.1 |
register int x; |
167 |
|
|
int s; |
168 |
|
|
{ |
169 |
greg |
1.6 |
static int cerr[NCOLS][3]; |
170 |
greg |
2.2 |
static int err[3]; |
171 |
|
|
int b, errp; |
172 |
greg |
1.1 |
register int a, ison; |
173 |
|
|
|
174 |
|
|
a = sub_add(s); /* use additive primary */ |
175 |
greg |
1.6 |
b = col[a]; |
176 |
greg |
2.2 |
errp = err[a]; |
177 |
greg |
1.1 |
err[a] += b + cerr[x][a]; |
178 |
greg |
1.6 |
ison = err[a] < 128; |
179 |
|
|
if (!ison) err[a] -= 256; |
180 |
greg |
1.11 |
err[a] /= 3; |
181 |
greg |
2.2 |
cerr[x][a] = err[a] + errp; |
182 |
greg |
1.1 |
return(ison); |
183 |
|
|
} |