5 |
|
#endif |
6 |
|
|
7 |
|
/* |
8 |
< |
* oki20c.c - program to dump pixel file to OkiMate 20 color printer. |
9 |
< |
* |
10 |
< |
* 6/10/87 |
8 |
> |
* oki20.c - program to dump pixel file to OkiMate 20 printer. |
9 |
|
*/ |
10 |
|
|
11 |
|
#include <stdio.h> |
12 |
+ |
#ifdef MSDOS |
13 |
+ |
#include <fcntl.h> |
14 |
+ |
#endif |
15 |
|
|
16 |
|
#include "color.h" |
17 |
|
#include "resolu.h" |
18 |
|
|
19 |
< |
#define NROWS 1440 /* 10" at 144 dpi */ |
20 |
< |
#define NCOLS 960 /* 8" at 120 dpi */ |
19 |
> |
#define NROWS 1440 /* 10" at 144 dpi */ |
20 |
> |
#define NCOLS 960 /* 8" at 120 dpi */ |
21 |
|
|
22 |
< |
#define ASPECT (120./144.) /* pixel aspect ratio */ |
22 |
> |
#define ASPECT (120./144.) /* pixel aspect ratio */ |
23 |
|
|
24 |
< |
#define FILTER "pfilt -1 -x %d -y %d -p %f %s",NCOLS,NROWS,ASPECT |
24 |
> |
#define FILTER "pfilt -1 -x %d -y %d -p %f %s",NCOLS,NROWS,ASPECT |
25 |
|
|
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 |
– |
|
26 |
|
long lpat[NCOLS]; |
27 |
|
|
28 |
|
int dofilter = 0; /* filter through pfilt first? */ |
29 |
|
|
30 |
+ |
extern FILE *popen(); |
31 |
|
|
32 |
+ |
|
33 |
|
main(argc, argv) |
34 |
|
int argc; |
35 |
|
char *argv[]; |
36 |
|
{ |
37 |
|
int i, status = 0; |
38 |
< |
|
38 |
> |
#ifdef MSDOS |
39 |
> |
extern int _fmode; |
40 |
> |
_fmode = O_BINARY; |
41 |
> |
setmode(fileno(stdin), O_BINARY); |
42 |
> |
setmode(fileno(stdout), O_BINARY); |
43 |
> |
#endif |
44 |
|
if (argc > 1 && !strcmp(argv[1], "-p")) { |
45 |
|
dofilter++; |
46 |
|
argv++; argc--; |
93 |
|
fprintf(stderr, "%s: bad picture size\n", fname); |
94 |
|
return(-1); |
95 |
|
} |
96 |
< |
if (xres > NCOLS || yres > NROWS) { |
96 |
> |
if (xres > NCOLS) { |
97 |
|
fprintf(stderr, "%s: resolution mismatch\n", fname); |
98 |
|
return(-1); |
99 |
|
} |
100 |
|
/* set line spacing (overlap for knitting) */ |
101 |
< |
fputs("\0333\042", stdout); |
100 |
< |
/* clear line buffer */ |
101 |
< |
clearlbuf(); |
101 |
> |
fputs("\0333\042\022", stdout); |
102 |
|
/* put out scanlines */ |
103 |
|
for (i = yres-1; i >= 0; i--) { |
104 |
|
if (freadcolrs(scanline, xres, input) < 0) { |
125 |
|
int len; |
126 |
|
int y; |
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 |
|
|