10 |
|
|
11 |
|
#include <stdio.h> |
12 |
|
#include <math.h> |
13 |
+ |
#include <ctype.h> |
14 |
|
#ifdef MSDOS |
15 |
|
#include <fcntl.h> |
16 |
|
#endif |
17 |
|
#include "color.h" |
18 |
|
|
19 |
+ |
#define UPPER(c) ((c)&~0x20) /* ASCII trick */ |
20 |
+ |
|
21 |
|
#define CODE6GAM 1.47 /* gamma for 6-bit codes */ |
22 |
|
#define DEFDGAM 1.0 /* default device gamma */ |
23 |
|
|
24 |
|
#define GRY -1 /* artificial index for grey */ |
25 |
|
|
26 |
< |
#define HMARGIN (.5*72) /* horizontal margin */ |
27 |
< |
#define VMARGIN (.5*72) /* vertical margin */ |
28 |
< |
#define PWIDTH (8.5*72-2*HMARGIN) /* width of device */ |
29 |
< |
#define PHEIGHT (11*72-2*VMARGIN) /* height of device */ |
26 |
> |
#define DEFMARG 0.5 /* default margin (inches) */ |
27 |
> |
#define DEFWIDTH 8.5 /* default page width */ |
28 |
> |
#define DEFHEIGHT 11 /* default page height */ |
29 |
> |
#define HMARGIN (hmarg*72) /* horizontal margin */ |
30 |
> |
#define VMARGIN (vmarg*72) /* vertical margin */ |
31 |
> |
#define PWIDTH (width*72-2*HMARGIN) /* width of device */ |
32 |
> |
#define PHEIGHT (height*72-2*VMARGIN) /* height of device */ |
33 |
|
|
34 |
|
#define RUNCHR '*' /* character to start rle */ |
35 |
|
#define MINRUN 4 /* minimum run-length */ |
43 |
|
double pixaspect = 1.0; /* pixel aspect ratio */ |
44 |
|
|
45 |
|
double devgam = DEFDGAM; /* device gamma response */ |
46 |
+ |
double hmarg = DEFMARG, |
47 |
+ |
vmarg = DEFMARG; /* horizontal and vertical margins */ |
48 |
+ |
double width = DEFWIDTH, |
49 |
+ |
height = DEFHEIGHT; /* default paper width and height */ |
50 |
|
int docolor = 0; /* produce color image? */ |
51 |
|
int bradj = 0; /* brightness adjustment */ |
52 |
|
int ncopies = 1; /* number of copies */ |
60 |
|
int xmax, ymax; |
61 |
|
|
62 |
|
extern char *malloc(); |
63 |
+ |
extern double unit2inch(); |
64 |
|
|
65 |
|
|
66 |
|
headline(s) /* check header line */ |
81 |
|
char *argv[]; |
82 |
|
{ |
83 |
|
int i; |
84 |
+ |
double d; |
85 |
|
|
86 |
|
progname = argv[0]; |
87 |
|
|
103 |
|
case 'C': /* compressed ASCII encoding */ |
104 |
|
putprim = Cputprim; |
105 |
|
break; |
106 |
< |
case 'g': |
106 |
> |
case 'g': /* device gamma adjustment */ |
107 |
|
devgam = atof(argv[++i]); |
108 |
|
break; |
109 |
+ |
case 'p': /* paper size */ |
110 |
+ |
parsepaper(argv[++i]); |
111 |
+ |
break; |
112 |
+ |
case 'm': /* margin */ |
113 |
+ |
d = atof(argv[i+1]); |
114 |
+ |
d *= unit2inch(argv[i+1]); |
115 |
+ |
switch (argv[i][2]) { |
116 |
+ |
case '\0': |
117 |
+ |
hmarg = vmarg = d; |
118 |
+ |
break; |
119 |
+ |
case 'h': |
120 |
+ |
hmarg = d; |
121 |
+ |
break; |
122 |
+ |
case 'v': |
123 |
+ |
vmarg = d; |
124 |
+ |
break; |
125 |
+ |
default: |
126 |
+ |
goto userr; |
127 |
+ |
} |
128 |
+ |
i++; |
129 |
+ |
break; |
130 |
|
case 'e': /* exposure adjustment */ |
131 |
|
if (argv[i+1][0] != '+' && argv[i+1][0] != '-') |
132 |
|
goto userr; |
173 |
|
PStrailer(); |
174 |
|
exit(0); |
175 |
|
userr: |
176 |
< |
fprintf(stderr, "Usage: %s [-b|c][-A|B|C][-e +/-stops][-g gamma] [input [output]]\n", |
176 |
> |
fprintf(stderr, |
177 |
> |
"Usage: %s [-b|c][-A|B|C][-e +/-stops][-p paper][-m[h|v] margin][-g gamma] [input [output]]\n", |
178 |
|
progname); |
179 |
+ |
exit(1); |
180 |
+ |
} |
181 |
+ |
|
182 |
+ |
|
183 |
+ |
double |
184 |
+ |
unit2inch(s) /* determine unit */ |
185 |
+ |
register char *s; |
186 |
+ |
{ |
187 |
+ |
static struct unit {char n; float f} u[] = { |
188 |
+ |
'i', 1., |
189 |
+ |
'm', 1./25.4, |
190 |
+ |
'c', 1./2.54, |
191 |
+ |
'\0' }; |
192 |
+ |
register struct unit *up; |
193 |
+ |
|
194 |
+ |
while (*s && !isalpha(*s)) |
195 |
+ |
s++; |
196 |
+ |
for (up = u; up->n; up++) |
197 |
+ |
if (up->n == *s) |
198 |
+ |
return(up->f); |
199 |
+ |
return(1.); |
200 |
+ |
} |
201 |
+ |
|
202 |
+ |
|
203 |
+ |
int |
204 |
+ |
matchid(name, id) /* see if name matches id (case insensitive) */ |
205 |
+ |
char *name; |
206 |
+ |
register char *id; |
207 |
+ |
{ |
208 |
+ |
register char *s = name; |
209 |
+ |
|
210 |
+ |
while (*s) { |
211 |
+ |
if (isalpha(*s)) { |
212 |
+ |
if (!isalpha(*id) || UPPER(*s) != UPPER(*id)) |
213 |
+ |
return(0); |
214 |
+ |
} else if (*s != *id) |
215 |
+ |
return(0); |
216 |
+ |
s++; id++; |
217 |
+ |
} |
218 |
+ |
return(!*id || s-name >= 3); /* substrings >= 3 chars OK */ |
219 |
+ |
} |
220 |
+ |
|
221 |
+ |
|
222 |
+ |
parsepaper(ps) /* determine paper size from name */ |
223 |
+ |
char *ps; |
224 |
+ |
{ |
225 |
+ |
static struct psize {char n[12]; float w,h;} p[] = { |
226 |
+ |
"letter", 8.5, 11., |
227 |
+ |
"legal", 8.5, 14., |
228 |
+ |
"executive", 7.25, 10.5, |
229 |
+ |
"envelope", 4.12, 9.5, |
230 |
+ |
"monarch", 3.87, 7.5, |
231 |
+ |
"tabloid", 11., 17., |
232 |
+ |
"A3", 11.69, 16.54, |
233 |
+ |
"A4", 8.27, 11.69, |
234 |
+ |
"A5", 6.00, 8.27, |
235 |
+ |
"A6", 4.13, 6.00, |
236 |
+ |
"B4", 10.12, 14.33, |
237 |
+ |
"B5", 7.17, 10.12, |
238 |
+ |
"DL", 4.33, 8.66, |
239 |
+ |
"C5", 6.38, 9.01, |
240 |
+ |
"C6", 4.49, 6.38, |
241 |
+ |
"hagaki", 3.94, 5.83, |
242 |
+ |
"" }; |
243 |
+ |
register struct psize *pp; |
244 |
+ |
register char *s = ps; |
245 |
+ |
double d; |
246 |
+ |
|
247 |
+ |
if (isdigit(*s)) { /* check for WWxHH specification */ |
248 |
+ |
width = atof(s); |
249 |
+ |
while (*s && !isalpha(*s)) |
250 |
+ |
s++; |
251 |
+ |
d = unit2inch(s); |
252 |
+ |
height = atof(++s); |
253 |
+ |
width *= d; |
254 |
+ |
height *= d; |
255 |
+ |
if (width >= 1. & height >= 1.) |
256 |
+ |
return; |
257 |
+ |
} else /* check for match to standard size */ |
258 |
+ |
for (pp = p; pp->n[0]; pp++) |
259 |
+ |
if (matchid(s, pp->n)) { |
260 |
+ |
width = pp->w; |
261 |
+ |
height = pp->h; |
262 |
+ |
return; |
263 |
+ |
} |
264 |
+ |
fprintf(stderr, "%s: unknown paper size \"%s\" -- known sizes:\n", |
265 |
+ |
progname, ps); |
266 |
+ |
fprintf(stderr, "_Name________Width_Height_(inches)\n"); |
267 |
+ |
for (pp = p; pp->n[0]; pp++) |
268 |
+ |
fprintf(stderr, "%-11s %5.2f %5.2f\n", pp->n, pp->w, pp->h); |
269 |
|
exit(1); |
270 |
|
} |
271 |
|
|