1 |
– |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
< |
* oki20c.c - program to dump pixel file to OkiMate 20 color printer. |
9 |
< |
* |
10 |
< |
* 6/10/87 |
5 |
> |
* oki20.c - program to dump pixel file to OkiMate 20 printer. |
6 |
|
*/ |
7 |
|
|
8 |
|
#include <stdio.h> |
9 |
+ |
#include <time.h> |
10 |
|
|
11 |
+ |
#include "platform.h" |
12 |
+ |
#include "rtprocess.h" |
13 |
|
#include "color.h" |
14 |
|
#include "resolu.h" |
15 |
|
|
16 |
< |
#define NROWS 1440 /* 10" at 144 dpi */ |
17 |
< |
#define NCOLS 960 /* 8" at 120 dpi */ |
16 |
> |
#define NROWS 1440 /* 10" at 144 dpi */ |
17 |
> |
#define NCOLS 960 /* 8" at 120 dpi */ |
18 |
|
|
19 |
< |
#define ASPECT (120./144.) /* pixel aspect ratio */ |
19 |
> |
#define ASPECT (120./144.) /* pixel aspect ratio */ |
20 |
|
|
21 |
< |
#define FILTER "pfilt -1 -x %d -y %d -p %f %s",NCOLS,NROWS,ASPECT |
21 |
> |
#define FILTER "pfilt -1 -x %d -y %d -p %f",NCOLS,NROWS,ASPECT |
22 |
> |
#define FILTER_F "pfilt -1 -x %d -y %d -p %f \"%s\"",NCOLS,NROWS,ASPECT |
23 |
|
|
25 |
– |
#ifdef BSD |
26 |
– |
#define clearlbuf() bzero((char *)lpat, sizeof(lpat)) |
27 |
– |
#else |
28 |
– |
#define clearlbuf() (void)memset((char *)lpat, 0, sizeof(lpat)) |
29 |
– |
#endif |
30 |
– |
|
24 |
|
long lpat[NCOLS]; |
25 |
|
|
26 |
|
int dofilter = 0; /* filter through pfilt first? */ |
27 |
|
|
28 |
+ |
static int printp(char *fname); |
29 |
+ |
static void plotscan(COLR scan[], int len, int y); |
30 |
+ |
static int bit(COLR col, int x); |
31 |
|
|
32 |
< |
main(argc, argv) |
33 |
< |
int argc; |
34 |
< |
char *argv[]; |
32 |
> |
|
33 |
> |
int |
34 |
> |
main( |
35 |
> |
int argc, |
36 |
> |
char *argv[] |
37 |
> |
) |
38 |
|
{ |
39 |
|
int i, status = 0; |
40 |
< |
|
40 |
> |
SET_DEFAULT_BINARY(); |
41 |
> |
SET_FILE_BINARY(stdin); |
42 |
> |
SET_FILE_BINARY(stdout); |
43 |
|
if (argc > 1 && !strcmp(argv[1], "-p")) { |
44 |
|
dofilter++; |
45 |
|
argv++; argc--; |
46 |
|
} |
46 |
– |
#ifdef _IOLBF |
47 |
– |
stdout->_flag &= ~_IOLBF; |
48 |
– |
#endif |
47 |
|
if (argc < 2) |
48 |
|
status = printp(NULL) == -1; |
49 |
|
else |
53 |
|
} |
54 |
|
|
55 |
|
|
56 |
< |
printp(fname) /* print a picture */ |
57 |
< |
char *fname; |
56 |
> |
static int |
57 |
> |
printp( /* print a picture */ |
58 |
> |
char *fname |
59 |
> |
) |
60 |
|
{ |
61 |
< |
char buf[64]; |
61 |
> |
char buf[PATH_MAX]; |
62 |
|
FILE *input; |
63 |
|
int xres, yres; |
64 |
|
COLR scanline[NCOLS]; |
66 |
|
|
67 |
|
if (dofilter) { |
68 |
|
if (fname == NULL) { |
69 |
< |
sprintf(buf, FILTER, ""); |
69 |
> |
sprintf(buf, FILTER); |
70 |
|
fname = "<stdin>"; |
71 |
|
} else |
72 |
< |
sprintf(buf, FILTER, fname); |
72 |
> |
sprintf(buf, FILTER_F, fname); |
73 |
|
if ((input = popen(buf, "r")) == NULL) { |
74 |
|
fprintf(stderr, "Cannot execute: %s\n", buf); |
75 |
|
return(-1); |
91 |
|
fprintf(stderr, "%s: bad picture size\n", fname); |
92 |
|
return(-1); |
93 |
|
} |
94 |
< |
if (xres > NCOLS || yres > NROWS) { |
94 |
> |
if (xres > NCOLS) { |
95 |
|
fprintf(stderr, "%s: resolution mismatch\n", fname); |
96 |
|
return(-1); |
97 |
|
} |
98 |
|
/* set line spacing (overlap for knitting) */ |
99 |
< |
fputs("\0333\042", stdout); |
100 |
< |
/* clear line buffer */ |
101 |
< |
clearlbuf(); |
99 |
> |
fputs("\0333\042\022", stdout); |
100 |
|
/* put out scanlines */ |
101 |
|
for (i = yres-1; i >= 0; i--) { |
102 |
|
if (freadcolrs(scanline, xres, input) < 0) { |
118 |
|
} |
119 |
|
|
120 |
|
|
121 |
< |
plotscan(scan, len, y) /* plot a scanline */ |
122 |
< |
COLR scan[]; |
123 |
< |
int len; |
124 |
< |
int y; |
121 |
> |
static void |
122 |
> |
plotscan( /* plot a scanline */ |
123 |
> |
COLR scan[], |
124 |
> |
int len, |
125 |
> |
int y |
126 |
> |
) |
127 |
|
{ |
128 |
< |
int bpos; |
128 |
> |
int bpos, start, end; |
129 |
|
register long c; |
130 |
|
register int i; |
131 |
|
|
132 |
< |
if (bpos = y % 23) { |
132 |
> |
bpos = y % 23; |
133 |
> |
for (i = 0; i < len; i++) |
134 |
> |
lpat[i] |= (long)bit(scan[i],i) << bpos; |
135 |
|
|
136 |
< |
for (i = 0; i < len; i++) |
137 |
< |
lpat[i] |= (long)bit(scan[i],i) << bpos; |
138 |
< |
|
139 |
< |
} else { |
140 |
< |
|
141 |
< |
fputs("\033%O", stdout); |
142 |
< |
putchar(len & 255); |
141 |
< |
putchar(len >> 8); |
142 |
< |
for (i = 0; i < len; i++) { |
143 |
< |
c = lpat[i] | bit(scan[i],i); |
144 |
< |
/* repeat this row */ |
145 |
< |
lpat[i] = (c & 1) << 23; |
146 |
< |
putchar(c>>16); |
147 |
< |
putchar(c>>8 & 255); |
148 |
< |
putchar(c & 255); |
136 |
> |
if (bpos) |
137 |
> |
return; |
138 |
> |
/* find limits of non-zero print buffer */ |
139 |
> |
for (i = 0; lpat[i] == 0; i++) |
140 |
> |
if (i == len-1) { |
141 |
> |
putchar('\n'); |
142 |
> |
return; |
143 |
|
} |
144 |
< |
putchar('\r'); |
145 |
< |
putchar('\n'); |
146 |
< |
fflush(stdout); |
144 |
> |
start = i - i%12; |
145 |
> |
i = len; |
146 |
> |
while (lpat[--i] == 0) |
147 |
> |
; |
148 |
> |
end = i; |
149 |
> |
/* skip to start position */ |
150 |
> |
for (i = start/12; i-- > 0; ) |
151 |
> |
putchar(' '); |
152 |
> |
/* print non-zero portion of buffer */ |
153 |
> |
fputs("\033%O", stdout); |
154 |
> |
i = end+1-start; |
155 |
> |
putchar(i & 255); |
156 |
> |
putchar(i >> 8); |
157 |
> |
for (i = start; i <= end; i++) { |
158 |
> |
c = lpat[i]; |
159 |
> |
putchar((int)(c>>16)); |
160 |
> |
putchar((int)(c>>8 & 255)); |
161 |
> |
putchar((int)(c & 255)); |
162 |
> |
if (y) /* repeat this row next time */ |
163 |
> |
lpat[i] = (c & 1) << 23; |
164 |
> |
else /* or clear for next image */ |
165 |
> |
lpat[i] = 0L; |
166 |
|
} |
167 |
+ |
putchar('\r'); |
168 |
+ |
putchar('\n'); |
169 |
+ |
fflush(stdout); |
170 |
|
} |
171 |
|
|
172 |
|
|
173 |
< |
bit(col, x) /* determine bit value for pixel at x */ |
174 |
< |
COLR col; |
175 |
< |
register int x; |
173 |
> |
static int |
174 |
> |
bit( /* determine bit value for pixel at x */ |
175 |
> |
COLR col, |
176 |
> |
register int x |
177 |
> |
) |
178 |
|
{ |
179 |
|
static int cerr[NCOLS]; |
180 |
|
static int err; |