1 |
– |
/* Copyright (c) 1991 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 |
6 |
|
*/ |
7 |
|
|
8 |
|
#include <stdio.h> |
9 |
+ |
#ifdef MSDOS |
10 |
+ |
#include <fcntl.h> |
11 |
+ |
#endif |
12 |
+ |
#include <time.h> |
13 |
|
|
14 |
|
#include "color.h" |
15 |
|
#include "resolu.h" |
16 |
|
|
17 |
< |
#define NROWS 1440 /* 10" at 144 dpi */ |
18 |
< |
#define NCOLS 960 /* 8" at 120 dpi */ |
17 |
> |
#define NROWS 1440 /* 10" at 144 dpi */ |
18 |
> |
#define NCOLS 960 /* 8" at 120 dpi */ |
19 |
|
|
20 |
+ |
#define ASPECT (120./144.) /* pixel aspect ratio */ |
21 |
+ |
|
22 |
+ |
#define FILTER "pfilt -1 -x %d -y %d -p %f %s",NCOLS,NROWS,ASPECT |
23 |
+ |
|
24 |
|
/* |
25 |
< |
* Subtractive primaries are ordered: Yellow, Magenta, Cyan. |
25 |
> |
* Subtractive primaries are ordered: Yellow, Magenta, Cyan. |
26 |
|
*/ |
27 |
|
|
28 |
< |
#define sub_add(sub) (2-(sub)) /* map subtractive to additive pri. */ |
28 |
> |
#define sub_add(sub) (2-(sub)) /* map subtractive to additive pri. */ |
29 |
|
|
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 |
– |
|
30 |
|
long lpat[NCOLS][3]; |
31 |
|
|
32 |
+ |
int dofilter = 0; /* filter through pfilt first? */ |
33 |
|
|
34 |
+ |
extern FILE *popen(); |
35 |
+ |
|
36 |
+ |
|
37 |
|
main(argc, argv) |
38 |
|
int argc; |
39 |
|
char *argv[]; |
40 |
|
{ |
41 |
|
int i, status = 0; |
42 |
< |
|
42 |
> |
#ifdef MSDOS |
43 |
> |
extern int _fmode; |
44 |
> |
_fmode = O_BINARY; |
45 |
> |
setmode(fileno(stdin), O_BINARY); |
46 |
> |
setmode(fileno(stdout), O_BINARY); |
47 |
> |
#endif |
48 |
> |
if (argc > 1 && !strcmp(argv[1], "-p")) { |
49 |
> |
dofilter++; |
50 |
> |
argv++; argc--; |
51 |
> |
} |
52 |
|
if (argc < 2) |
53 |
|
status = printp(NULL) == -1; |
54 |
|
else |
61 |
|
printp(fname) /* print a picture */ |
62 |
|
char *fname; |
63 |
|
{ |
64 |
+ |
char buf[64]; |
65 |
|
FILE *input; |
66 |
|
int xres, yres; |
67 |
|
COLR scanline[NCOLS]; |
68 |
|
int i; |
69 |
|
|
70 |
< |
if (fname == NULL) { |
70 |
> |
if (dofilter) { |
71 |
> |
if (fname == NULL) { |
72 |
> |
sprintf(buf, FILTER, ""); |
73 |
> |
fname = "<stdin>"; |
74 |
> |
} else |
75 |
> |
sprintf(buf, FILTER, fname); |
76 |
> |
if ((input = popen(buf, "r")) == NULL) { |
77 |
> |
fprintf(stderr, "Cannot execute: %s\n", buf); |
78 |
> |
return(-1); |
79 |
> |
} |
80 |
> |
} else if (fname == NULL) { |
81 |
|
input = stdin; |
82 |
|
fname = "<stdin>"; |
83 |
|
} else if ((input = fopen(fname, "r")) == NULL) { |
94 |
|
fprintf(stderr, "%s: bad picture size\n", fname); |
95 |
|
return(-1); |
96 |
|
} |
97 |
< |
if (xres > NCOLS || yres > NROWS) { |
97 |
> |
if (xres > NCOLS) { |
98 |
|
fprintf(stderr, "%s: resolution mismatch\n", fname); |
99 |
|
return(-1); |
100 |
|
} |
101 |
|
/* set line spacing (overlap for knitting) */ |
102 |
|
fputs("\0333\042", stdout); |
82 |
– |
/* clear line buffer */ |
83 |
– |
clearlbuf(); |
103 |
|
/* put out scanlines */ |
104 |
|
for (i = yres-1; i >= 0; i--) { |
105 |
|
if (freadcolrs(scanline, xres, input) < 0) { |
112 |
|
/* advance page */ |
113 |
|
putchar('\f'); |
114 |
|
|
115 |
< |
fclose(input); |
115 |
> |
if (dofilter) |
116 |
> |
pclose(input); |
117 |
> |
else |
118 |
> |
fclose(input); |
119 |
|
|
120 |
|
return(0); |
121 |
|
} |
135 |
|
for (j = 0; j < 3; j++) |
136 |
|
for (i = 0; i < len; i++) |
137 |
|
lpat[i][j] |= (long)colbit(scan[i],i,j) << bpos; |
138 |
+ |
return; |
139 |
+ |
} |
140 |
+ |
fputs("\033\031", stdout); |
141 |
|
|
142 |
< |
} else { |
143 |
< |
|
144 |
< |
fputs("\033\031", stdout); |
145 |
< |
|
146 |
< |
for (j = 0; j < 3; j++) { |
147 |
< |
fputs("\033%O", stdout); |
148 |
< |
putchar(len & 255); |
149 |
< |
putchar(len >> 8); |
150 |
< |
for (i = 0; i < len; i++) { |
151 |
< |
c = lpat[i][j] | colbit(scan[i],i,j); |
152 |
< |
/* repeat this row */ |
142 |
> |
for (j = 0; j < 3; j++) { |
143 |
> |
i = (NCOLS + len)/2; /* center image */ |
144 |
> |
fputs("\033%O", stdout); |
145 |
> |
putchar(i & 255); |
146 |
> |
putchar(i >> 8); |
147 |
> |
while (i-- > len) { |
148 |
> |
putchar(0); |
149 |
> |
putchar(0); |
150 |
> |
putchar(0); |
151 |
> |
} |
152 |
> |
for (i = 0; i < len; i++) { |
153 |
> |
c = lpat[i][j] | colbit(scan[i],i,j); |
154 |
> |
putchar((int)(c>>16)); |
155 |
> |
putchar((int)(c>>8 & 255)); |
156 |
> |
putchar((int)(c & 255)); |
157 |
> |
if (y) /* repeat this row */ |
158 |
|
lpat[i][j] = (c & 1) << 23; |
159 |
< |
putchar(c>>16); |
160 |
< |
putchar(c>>8 & 255); |
131 |
< |
putchar(c & 255); |
132 |
< |
} |
133 |
< |
putchar('\r'); |
159 |
> |
else /* or clear for next image */ |
160 |
> |
lpat[i][j] = 0L; |
161 |
|
} |
162 |
< |
putchar('\n'); |
162 |
> |
putchar('\r'); |
163 |
|
} |
164 |
+ |
putchar('\n'); |
165 |
+ |
fflush(stdout); |
166 |
|
} |
167 |
|
|
168 |
|
|