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 */ |
22 |
> |
#define DEFGGAM 1.0 /* greyscale device gamma */ |
23 |
> |
#define DEFCGAM 1.8 /* color device gamma */ |
24 |
|
|
25 |
|
#define GRY -1 /* artificial index for grey */ |
26 |
|
|
43 |
|
int wrongformat = 0; /* input in wrong format? */ |
44 |
|
double pixaspect = 1.0; /* pixel aspect ratio */ |
45 |
|
|
46 |
< |
double devgam = DEFDGAM; /* device gamma response */ |
46 |
> |
double devgam = 0.; /* device gamma response */ |
47 |
|
double hmarg = DEFMARG, |
48 |
|
vmarg = DEFMARG; /* horizontal and vertical margins */ |
49 |
|
double width = DEFWIDTH, |
50 |
|
height = DEFHEIGHT; /* default paper width and height */ |
51 |
< |
int docolor = 0; /* produce color image? */ |
51 |
> |
double dpi = 0; /* print density (0 if unknown) */ |
52 |
> |
int docolor = 1; /* produce color image? */ |
53 |
|
int bradj = 0; /* brightness adjustment */ |
54 |
|
int ncopies = 1; /* number of copies */ |
55 |
|
|
59 |
|
|
60 |
|
char *progname; |
61 |
|
|
62 |
< |
int xmax, ymax; |
62 |
> |
int xmax, ymax; /* input image dimensions */ |
63 |
|
|
64 |
|
extern char *malloc(); |
65 |
|
extern double unit2inch(); |
66 |
|
|
67 |
|
|
68 |
+ |
int |
69 |
|
headline(s) /* check header line */ |
70 |
|
char *s; |
71 |
|
{ |
76 |
|
wrongformat = strcmp(fmt, COLRFMT); |
77 |
|
} else if (isaspect(s)) |
78 |
|
pixaspect *= aspectval(s); |
79 |
+ |
return(0); |
80 |
|
} |
81 |
|
|
82 |
|
|
107 |
|
case 'C': /* compressed ASCII encoding */ |
108 |
|
putprim = Cputprim; |
109 |
|
break; |
110 |
+ |
case 'd': /* print density */ |
111 |
+ |
dpi = atof(argv[++i]); |
112 |
+ |
break; |
113 |
|
case 'g': /* device gamma adjustment */ |
114 |
|
devgam = atof(argv[++i]); |
115 |
|
break; |
168 |
|
if (wrongformat || fgetresolu(&xmax, &ymax, stdin) < 0) |
169 |
|
quiterr("bad picture format"); |
170 |
|
/* gamma compression */ |
171 |
+ |
if (devgam <= 0.05) |
172 |
+ |
devgam = docolor ? DEFCGAM : DEFGGAM; |
173 |
|
if (putprim == Cputprim) |
174 |
< |
setcolrgam(CODE6GAM/devgam); |
174 |
> |
setcolrgam(CODE6GAM); |
175 |
|
else if (devgam != 1.) |
176 |
< |
setcolrgam(1./devgam); |
176 |
> |
setcolrgam(devgam); |
177 |
|
/* write header */ |
178 |
< |
PSheader(i <= argc-1 ? argv[i] : "<stdin>"); |
178 |
> |
PSheader(argc, argv); |
179 |
|
/* convert file */ |
180 |
|
ra2ps(); |
181 |
|
/* write trailer */ |
183 |
|
exit(0); |
184 |
|
userr: |
185 |
|
fprintf(stderr, |
186 |
< |
"Usage: %s [-b|c][-A|B|C][-e +/-stops][-p paper][-m[h|v] margin][-g gamma] [input [output]]\n", |
186 |
> |
"Usage: %s [-b|c][-A|B|C][-e +/-stops][-p paper][-m[h|v] margin][-d dpi][-g gamma] [input [output]]\n", |
187 |
|
progname); |
188 |
|
exit(1); |
189 |
|
} |
193 |
|
unit2inch(s) /* determine unit */ |
194 |
|
register char *s; |
195 |
|
{ |
196 |
< |
static struct unit {char n; float f} u[] = { |
196 |
> |
static struct unit {char n; float f;} u[] = { |
197 |
|
'i', 1., |
198 |
|
'm', 1./25.4, |
199 |
|
'c', 1./2.54, |
232 |
|
char *ps; |
233 |
|
{ |
234 |
|
static struct psize {char n[12]; float w,h;} p[] = { |
235 |
+ |
"envelope", 4.12, 9.5, |
236 |
+ |
"executive", 7.25, 10.5, |
237 |
|
"letter", 8.5, 11., |
238 |
+ |
"lettersmall", 7.68, 10.16, |
239 |
|
"legal", 8.5, 14., |
228 |
– |
"executive", 7.25, 10.5, |
229 |
– |
"envelope", 4.12, 9.5, |
240 |
|
"monarch", 3.87, 7.5, |
241 |
+ |
"statement", 5.5, 8.5, |
242 |
|
"tabloid", 11., 17., |
243 |
|
"A3", 11.69, 16.54, |
244 |
|
"A4", 8.27, 11.69, |
245 |
+ |
"A4small", 7.47, 10.85, |
246 |
|
"A5", 6.00, 8.27, |
247 |
|
"A6", 4.13, 6.00, |
248 |
|
"B4", 10.12, 14.33, |
249 |
|
"B5", 7.17, 10.12, |
238 |
– |
"DL", 4.33, 8.66, |
250 |
|
"C5", 6.38, 9.01, |
251 |
|
"C6", 4.49, 6.38, |
252 |
+ |
"DL", 4.33, 8.66, |
253 |
|
"hagaki", 3.94, 5.83, |
254 |
|
"" }; |
255 |
|
register struct psize *pp; |
278 |
|
fprintf(stderr, "_Name________Width_Height_(inches)\n"); |
279 |
|
for (pp = p; pp->n[0]; pp++) |
280 |
|
fprintf(stderr, "%-11s %5.2f %5.2f\n", pp->n, pp->w, pp->h); |
281 |
+ |
fprintf(stderr, "Or use WWxHH size specification\n"); |
282 |
|
exit(1); |
283 |
|
} |
284 |
|
|
294 |
|
} |
295 |
|
|
296 |
|
|
297 |
< |
PSheader(name) /* print PostScript header */ |
298 |
< |
char *name; |
297 |
> |
PSheader(ac, av) /* print PostScript header */ |
298 |
> |
int ac; |
299 |
> |
char **av; |
300 |
|
{ |
301 |
|
char *rstr; |
302 |
< |
int landscape = 0; |
302 |
> |
int landscape, rotate, n; |
303 |
|
double pwidth, pheight; |
304 |
|
double iwidth, iheight; |
305 |
|
/* EPS comments */ |
306 |
|
puts("%!PS-Adobe-2.0 EPSF-2.0"); |
307 |
< |
printf("%%%%Title: %s\n", name); |
308 |
< |
printf("%%%%Creator: %s = %s\n", progname, SCCSid); |
307 |
> |
printf("%%%%Title: "); printargs(ac, av, stdout); |
308 |
> |
printf("%%%%Creator: %s\n", SCCSid); |
309 |
|
printf("%%%%Pages: %d\n", ncopies); |
310 |
|
if (landscape = xmax > pixaspect*ymax) |
311 |
|
puts("%%Orientation: Landscape"); |
312 |
|
else |
313 |
|
puts("%%Orientation: Portrait"); |
314 |
< |
if (PWIDTH > PHEIGHT ^ landscape) { |
314 |
> |
if (rotate = PWIDTH > PHEIGHT ^ landscape) { |
315 |
|
pwidth = PHEIGHT; |
316 |
|
pheight = PWIDTH; |
317 |
|
} else { |
318 |
|
pwidth = PWIDTH; |
319 |
|
pheight = PHEIGHT; |
320 |
|
} |
321 |
< |
if (pheight/pwidth > pixaspect*ymax/xmax) { |
322 |
< |
iwidth = pwidth; |
323 |
< |
iheight = pwidth*pixaspect*ymax/xmax; |
324 |
< |
} else { |
325 |
< |
iheight = pheight; |
326 |
< |
iwidth = pheight*xmax/(pixaspect*ymax); |
327 |
< |
} |
328 |
< |
if (pwidth == PHEIGHT) |
321 |
> |
if (dpi > 100 && pixaspect >= 0.99 & pixaspect <= 1.01) |
322 |
> |
if (pheight/pwidth > ymax/xmax) { |
323 |
> |
n = pwidth*dpi/xmax; /* floor */ |
324 |
> |
iwidth = n > 0 ? (double)(n*xmax)/dpi : pwidth; |
325 |
> |
iheight = iwidth*ymax/xmax; |
326 |
> |
} else { |
327 |
> |
n = pheight*dpi/ymax; /* floor */ |
328 |
> |
iheight = n > 0 ? (double)(n*ymax)/dpi : pheight; |
329 |
> |
iwidth = iheight*xmax/ymax; |
330 |
> |
} |
331 |
> |
else |
332 |
> |
if (pheight/pwidth > pixaspect*ymax/xmax) { |
333 |
> |
iwidth = pwidth; |
334 |
> |
iheight = iwidth*pixaspect*ymax/xmax; |
335 |
> |
} else { |
336 |
> |
iheight = pheight; |
337 |
> |
iwidth = iheight*xmax/(pixaspect*ymax); |
338 |
> |
} |
339 |
> |
if (rotate) |
340 |
|
printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n", |
341 |
|
HMARGIN+(pheight-iheight)*.5, |
342 |
|
VMARGIN+(pwidth-iwidth)*.5, |
363 |
|
PSprocdef("read6bitRLE"); |
364 |
|
/* set up transformation matrix */ |
365 |
|
printf("%f %f translate\n", HMARGIN, VMARGIN); |
366 |
< |
if (pwidth == PHEIGHT) { |
366 |
> |
if (rotate) { |
367 |
|
printf("%f 0 translate\n", PWIDTH); |
368 |
|
puts("90 rotate"); |
369 |
|
} |
414 |
|
for (i = 0; i < 128; i++) /* clear */ |
415 |
|
itab[i] = -1; |
416 |
|
for (i = 1; i < 63; i++) /* assign greys */ |
417 |
< |
itab[code[i]] = 256.0*pow((i+.5)/64.0, CODE6GAM); |
417 |
> |
itab[code[i]] = 256.0*pow((i+.5)/64.0, CODE6GAM/devgam); |
418 |
|
itab[code[0]] = 0; /* black is black */ |
419 |
|
itab[code[63]] = 255; /* and white is white */ |
420 |
|
printf("/codetab ["); |