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? */ |
31 |
|
char *argv[]; |
32 |
|
{ |
33 |
|
int i, status = 0; |
34 |
< |
|
34 |
> |
SET_DEFAULT_BINARY(); |
35 |
> |
SET_FILE_BINARY(stdin); |
36 |
> |
SET_FILE_BINARY(stdout); |
37 |
|
if (argc > 1 && !strcmp(argv[1], "-p")) { |
38 |
|
dofilter++; |
39 |
|
argv++; argc--; |
40 |
|
} |
46 |
– |
#ifdef _IOLBF |
47 |
– |
stdout->_flag &= ~_IOLBF; |
48 |
– |
#endif |
41 |
|
if (argc < 2) |
42 |
|
status = printp(NULL) == -1; |
43 |
|
else |
50 |
|
printp(fname) /* print a picture */ |
51 |
|
char *fname; |
52 |
|
{ |
53 |
< |
char buf[64]; |
53 |
> |
char buf[PATH_MAX]; |
54 |
|
FILE *input; |
55 |
|
int xres, yres; |
56 |
|
COLR scanline[NCOLS]; |
57 |
|
int i; |
58 |
|
|
59 |
|
if (dofilter) { |
60 |
< |
if (fname == NULL) |
61 |
< |
fname = ""; |
62 |
< |
sprintf(buf, FILTER, fname); |
60 |
> |
if (fname == NULL) { |
61 |
> |
sprintf(buf, FILTER); |
62 |
> |
fname = "<stdin>"; |
63 |
> |
} else |
64 |
> |
sprintf(buf, FILTER_F, fname); |
65 |
|
if ((input = popen(buf, "r")) == NULL) { |
66 |
|
fprintf(stderr, "Cannot execute: %s\n", buf); |
67 |
|
return(-1); |
68 |
|
} |
75 |
– |
fname = buf; |
69 |
|
} else if (fname == NULL) { |
70 |
|
input = stdin; |
71 |
|
fname = "<stdin>"; |
83 |
|
fprintf(stderr, "%s: bad picture size\n", fname); |
84 |
|
return(-1); |
85 |
|
} |
86 |
< |
if (xres > NCOLS || yres > NROWS) { |
86 |
> |
if (xres > NCOLS) { |
87 |
|
fprintf(stderr, "%s: resolution mismatch\n", fname); |
88 |
|
return(-1); |
89 |
|
} |
90 |
|
/* set line spacing (overlap for knitting) */ |
91 |
< |
fputs("\0333\042", stdout); |
99 |
< |
/* clear line buffer */ |
100 |
< |
clearlbuf(); |
91 |
> |
fputs("\0333\042\022", stdout); |
92 |
|
/* put out scanlines */ |
93 |
|
for (i = yres-1; i >= 0; i--) { |
94 |
|
if (freadcolrs(scanline, xres, input) < 0) { |
115 |
|
int len; |
116 |
|
int y; |
117 |
|
{ |
118 |
< |
int bpos; |
118 |
> |
int bpos, start, end; |
119 |
|
register long c; |
120 |
|
register int i; |
121 |
|
|
122 |
< |
if (bpos = y % 23) { |
122 |
> |
bpos = y % 23; |
123 |
> |
for (i = 0; i < len; i++) |
124 |
> |
lpat[i] |= (long)bit(scan[i],i) << bpos; |
125 |
|
|
126 |
< |
for (i = 0; i < len; i++) |
127 |
< |
lpat[i] |= (long)bit(scan[i],i) << bpos; |
128 |
< |
|
129 |
< |
} else { |
130 |
< |
|
131 |
< |
fputs("\033%O", stdout); |
132 |
< |
putchar(len & 255); |
140 |
< |
putchar(len >> 8); |
141 |
< |
for (i = 0; i < len; i++) { |
142 |
< |
c = lpat[i] | bit(scan[i],i); |
143 |
< |
/* repeat this row */ |
144 |
< |
lpat[i] = (c & 1) << 23; |
145 |
< |
putchar(c>>16); |
146 |
< |
putchar(c>>8 & 255); |
147 |
< |
putchar(c & 255); |
126 |
> |
if (bpos) |
127 |
> |
return; |
128 |
> |
/* find limits of non-zero print buffer */ |
129 |
> |
for (i = 0; lpat[i] == 0; i++) |
130 |
> |
if (i == len-1) { |
131 |
> |
putchar('\n'); |
132 |
> |
return; |
133 |
|
} |
134 |
< |
putchar('\r'); |
135 |
< |
putchar('\n'); |
136 |
< |
fflush(stdout); |
134 |
> |
start = i - i%12; |
135 |
> |
i = len; |
136 |
> |
while (lpat[--i] == 0) |
137 |
> |
; |
138 |
> |
end = i; |
139 |
> |
/* skip to start position */ |
140 |
> |
for (i = start/12; i-- > 0; ) |
141 |
> |
putchar(' '); |
142 |
> |
/* print non-zero portion of buffer */ |
143 |
> |
fputs("\033%O", stdout); |
144 |
> |
i = end+1-start; |
145 |
> |
putchar(i & 255); |
146 |
> |
putchar(i >> 8); |
147 |
> |
for (i = start; i <= end; i++) { |
148 |
> |
c = lpat[i]; |
149 |
> |
putchar((int)(c>>16)); |
150 |
> |
putchar((int)(c>>8 & 255)); |
151 |
> |
putchar((int)(c & 255)); |
152 |
> |
if (y) /* repeat this row next time */ |
153 |
> |
lpat[i] = (c & 1) << 23; |
154 |
> |
else /* or clear for next image */ |
155 |
> |
lpat[i] = 0L; |
156 |
|
} |
157 |
+ |
putchar('\r'); |
158 |
+ |
putchar('\n'); |
159 |
+ |
fflush(stdout); |
160 |
|
} |
161 |
|
|
162 |
|
|