1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
6 |
|
|
7 |
|
/* |
8 |
|
* oki20c.c - program to dump pixel file to OkiMate 20 color printer. |
9 |
– |
* |
10 |
– |
* 6/10/87 |
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 |
|
|
26 |
|
/* |
27 |
< |
* Subtractive primaries are ordered: Yellow, Magenta, Cyan. |
27 |
> |
* Subtractive primaries are ordered: Yellow, Magenta, Cyan. |
28 |
|
*/ |
29 |
|
|
30 |
< |
#define sub_add(sub) (2-(sub)) /* map subtractive to additive pri. */ |
30 |
> |
#define sub_add(sub) (2-(sub)) /* map subtractive to additive pri. */ |
31 |
|
|
31 |
– |
#ifdef BSD |
32 |
– |
#define clearlbuf() bzero((char *)lpat, sizeof(lpat)) |
33 |
– |
#else |
34 |
– |
#define clearlbuf() (void)memset((char *)lpat, 0, sizeof(lpat)) |
35 |
– |
#endif |
36 |
– |
|
32 |
|
long lpat[NCOLS][3]; |
33 |
|
|
34 |
|
int dofilter = 0; /* filter through pfilt first? */ |
35 |
|
|
36 |
+ |
extern FILE *popen(); |
37 |
|
|
38 |
+ |
|
39 |
|
main(argc, argv) |
40 |
|
int argc; |
41 |
|
char *argv[]; |
42 |
|
{ |
43 |
|
int i, status = 0; |
44 |
< |
|
44 |
> |
#ifdef MSDOS |
45 |
> |
extern int _fmode; |
46 |
> |
_fmode = O_BINARY; |
47 |
> |
setmode(fileno(stdin), O_BINARY); |
48 |
> |
setmode(fileno(stdout), O_BINARY); |
49 |
> |
#endif |
50 |
|
if (argc > 1 && !strcmp(argv[1], "-p")) { |
51 |
|
dofilter++; |
52 |
|
argv++; argc--; |
70 |
|
int i; |
71 |
|
|
72 |
|
if (dofilter) { |
73 |
< |
if (fname == NULL) |
74 |
< |
fname = ""; |
75 |
< |
sprintf(buf, FILTER, fname); |
73 |
> |
if (fname == NULL) { |
74 |
> |
sprintf(buf, FILTER, ""); |
75 |
> |
fname = "<stdin>"; |
76 |
> |
} else |
77 |
> |
sprintf(buf, FILTER, fname); |
78 |
|
if ((input = popen(buf, "r")) == NULL) { |
79 |
|
fprintf(stderr, "Cannot execute: %s\n", buf); |
80 |
|
return(-1); |
81 |
|
} |
78 |
– |
fname = buf; |
82 |
|
} else if (fname == NULL) { |
83 |
|
input = stdin; |
84 |
|
fname = "<stdin>"; |
96 |
|
fprintf(stderr, "%s: bad picture size\n", fname); |
97 |
|
return(-1); |
98 |
|
} |
99 |
< |
if (xres > NCOLS || yres > NROWS) { |
99 |
> |
if (xres > NCOLS) { |
100 |
|
fprintf(stderr, "%s: resolution mismatch\n", fname); |
101 |
|
return(-1); |
102 |
|
} |
103 |
|
/* set line spacing (overlap for knitting) */ |
104 |
|
fputs("\0333\042", stdout); |
102 |
– |
/* clear line buffer */ |
103 |
– |
clearlbuf(); |
104 |
– |
#ifdef _IOLBF |
105 |
– |
stdout->_flag &= ~_IOLBF; |
106 |
– |
#endif |
105 |
|
/* put out scanlines */ |
106 |
|
for (i = yres-1; i >= 0; i--) { |
107 |
|
if (freadcolrs(scanline, xres, input) < 0) { |
137 |
|
for (j = 0; j < 3; j++) |
138 |
|
for (i = 0; i < len; i++) |
139 |
|
lpat[i][j] |= (long)colbit(scan[i],i,j) << bpos; |
140 |
+ |
return; |
141 |
+ |
} |
142 |
+ |
fputs("\033\031", stdout); |
143 |
|
|
144 |
< |
} else { |
145 |
< |
|
146 |
< |
fputs("\033\031", stdout); |
147 |
< |
|
148 |
< |
for (j = 0; j < 3; j++) { |
149 |
< |
fputs("\033%O", stdout); |
150 |
< |
putchar(len & 255); |
151 |
< |
putchar(len >> 8); |
152 |
< |
for (i = 0; i < len; i++) { |
153 |
< |
c = lpat[i][j] | colbit(scan[i],i,j); |
154 |
< |
/* repeat this row */ |
144 |
> |
for (j = 0; j < 3; j++) { |
145 |
> |
i = (NCOLS + len)/2; /* center image */ |
146 |
> |
fputs("\033%O", stdout); |
147 |
> |
putchar(i & 255); |
148 |
> |
putchar(i >> 8); |
149 |
> |
while (i-- > len) { |
150 |
> |
putchar(0); |
151 |
> |
putchar(0); |
152 |
> |
putchar(0); |
153 |
> |
} |
154 |
> |
for (i = 0; i < len; i++) { |
155 |
> |
c = lpat[i][j] | colbit(scan[i],i,j); |
156 |
> |
putchar((int)(c>>16)); |
157 |
> |
putchar((int)(c>>8 & 255)); |
158 |
> |
putchar((int)(c & 255)); |
159 |
> |
if (y) /* repeat this row */ |
160 |
|
lpat[i][j] = (c & 1) << 23; |
161 |
< |
putchar(c>>16); |
162 |
< |
putchar(c>>8 & 255); |
157 |
< |
putchar(c & 255); |
158 |
< |
} |
159 |
< |
putchar('\r'); |
161 |
> |
else /* or clear for next image */ |
162 |
> |
lpat[i][j] = 0L; |
163 |
|
} |
164 |
< |
putchar('\n'); |
162 |
< |
fflush(stdout); |
164 |
> |
putchar('\r'); |
165 |
|
} |
166 |
+ |
putchar('\n'); |
167 |
+ |
fflush(stdout); |
168 |
|
} |
169 |
|
|
170 |
|
|