1 |
– |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Radiance picture to PostScript file translator -- one way! |
6 |
|
*/ |
7 |
|
|
8 |
|
#include <stdio.h> |
9 |
+ |
#include <string.h> |
10 |
|
#include <math.h> |
11 |
|
#include <ctype.h> |
12 |
< |
#ifdef MSDOS |
13 |
< |
#include <fcntl.h> |
16 |
< |
#endif |
12 |
> |
|
13 |
> |
#include "platform.h" |
14 |
|
#include "color.h" |
15 |
+ |
#include "resolu.h" |
16 |
|
|
17 |
|
#define UPPER(c) ((c)&~0x20) /* ASCII trick */ |
18 |
|
|
59 |
|
|
60 |
|
int xmax, ymax; /* input image dimensions */ |
61 |
|
|
64 |
– |
extern char *malloc(); |
62 |
|
extern double unit2inch(); |
63 |
|
|
64 |
+ |
static gethfunc headline; |
65 |
|
|
66 |
< |
headline(s) /* check header line */ |
67 |
< |
char *s; |
66 |
> |
|
67 |
> |
static int |
68 |
> |
headline( /* check header line */ |
69 |
> |
char *s, |
70 |
> |
void *p |
71 |
> |
) |
72 |
|
{ |
73 |
|
char fmt[32]; |
74 |
|
|
77 |
|
wrongformat = strcmp(fmt, COLRFMT); |
78 |
|
} else if (isaspect(s)) |
79 |
|
pixaspect *= aspectval(s); |
80 |
+ |
return(0); |
81 |
|
} |
82 |
|
|
83 |
|
|
161 |
|
progname, argv[i+1]); |
162 |
|
exit(1); |
163 |
|
} |
164 |
< |
#ifdef MSDOS |
162 |
< |
setmode(fileno(stdin), O_BINARY); |
163 |
< |
#endif |
164 |
> |
SET_FILE_BINARY(stdin); |
165 |
|
/* get our header */ |
166 |
|
getheader(stdin, headline, NULL); |
167 |
|
if (wrongformat || fgetresolu(&xmax, &ymax, stdin) < 0) |
192 |
|
unit2inch(s) /* determine unit */ |
193 |
|
register char *s; |
194 |
|
{ |
195 |
< |
static struct unit {char n; float f} u[] = { |
196 |
< |
'i', 1., |
197 |
< |
'm', 1./25.4, |
198 |
< |
'c', 1./2.54, |
199 |
< |
'\0' }; |
195 |
> |
static struct unit {char n; float f;} u[] = { |
196 |
> |
{'i', 1.}, |
197 |
> |
{'m', 1./25.4}, |
198 |
> |
{'c', 1./2.54}, |
199 |
> |
{'\0',0} }; |
200 |
|
register struct unit *up; |
201 |
|
|
202 |
|
while (*s && !isalpha(*s)) |
231 |
|
char *ps; |
232 |
|
{ |
233 |
|
static struct psize {char n[12]; float w,h;} p[] = { |
234 |
< |
"envelope", 4.12, 9.5, |
235 |
< |
"executive", 7.25, 10.5, |
236 |
< |
"letter", 8.5, 11., |
237 |
< |
"lettersmall", 7.68, 10.16, |
238 |
< |
"legal", 8.5, 14., |
239 |
< |
"monarch", 3.87, 7.5, |
240 |
< |
"statement", 5.5, 8.5, |
241 |
< |
"tabloid", 11., 17., |
242 |
< |
"A3", 11.69, 16.54, |
243 |
< |
"A4", 8.27, 11.69, |
244 |
< |
"A4small", 7.47, 10.85, |
245 |
< |
"A5", 6.00, 8.27, |
246 |
< |
"A6", 4.13, 6.00, |
247 |
< |
"B4", 10.12, 14.33, |
248 |
< |
"B5", 7.17, 10.12, |
249 |
< |
"C5", 6.38, 9.01, |
250 |
< |
"C6", 4.49, 6.38, |
251 |
< |
"DL", 4.33, 8.66, |
252 |
< |
"hagaki", 3.94, 5.83, |
253 |
< |
"" }; |
234 |
> |
{"envelope", 4.12, 9.5}, |
235 |
> |
{"executive", 7.25, 10.5}, |
236 |
> |
{"letter", 8.5, 11.}, |
237 |
> |
{"lettersmall", 7.68, 10.16}, |
238 |
> |
{"legal", 8.5, 14.}, |
239 |
> |
{"monarch", 3.87, 7.5}, |
240 |
> |
{"statement", 5.5, 8.5}, |
241 |
> |
{"tabloid", 11., 17.}, |
242 |
> |
{"A3", 11.69, 16.54}, |
243 |
> |
{"A4", 8.27, 11.69}, |
244 |
> |
{"A4small", 7.47, 10.85}, |
245 |
> |
{"A5", 6.00, 8.27}, |
246 |
> |
{"A6", 4.13, 6.00}, |
247 |
> |
{"B4", 10.12, 14.33}, |
248 |
> |
{"B5", 7.17, 10.12}, |
249 |
> |
{"C5", 6.38, 9.01}, |
250 |
> |
{"C6", 4.49, 6.38}, |
251 |
> |
{"DL", 4.33, 8.66}, |
252 |
> |
{"hagaki", 3.94, 5.83}, |
253 |
> |
{"",0.0,0.0} }; |
254 |
|
register struct psize *pp; |
255 |
|
register char *s = ps; |
256 |
|
double d; |
263 |
|
height = atof(++s); |
264 |
|
width *= d; |
265 |
|
height *= d; |
266 |
< |
if (width >= 1. & height >= 1.) |
266 |
> |
if ((width >= 1.) & (height >= 1.)) |
267 |
|
return; |
268 |
|
} else /* check for match to standard size */ |
269 |
|
for (pp = p; pp->n[0]; pp++) |
304 |
|
/* EPS comments */ |
305 |
|
puts("%!PS-Adobe-2.0 EPSF-2.0"); |
306 |
|
printf("%%%%Title: "); printargs(ac, av, stdout); |
307 |
< |
printf("%%%%Creator: %s\n", SCCSid); |
307 |
> |
printf("%%%%Creator: %s\n", progname); |
308 |
|
printf("%%%%Pages: %d\n", ncopies); |
309 |
< |
if (landscape = xmax > pixaspect*ymax) |
309 |
> |
if ( (landscape = xmax > pixaspect*ymax) ) |
310 |
|
puts("%%Orientation: Landscape"); |
311 |
|
else |
312 |
|
puts("%%Orientation: Portrait"); |
313 |
< |
if (rotate = PWIDTH > PHEIGHT ^ landscape) { |
313 |
> |
if ( (rotate = (PWIDTH > PHEIGHT) ^ landscape) ) { |
314 |
|
pwidth = PHEIGHT; |
315 |
|
pheight = PWIDTH; |
316 |
|
} else { |
317 |
|
pwidth = PWIDTH; |
318 |
|
pheight = PHEIGHT; |
319 |
|
} |
320 |
< |
if (dpi > 100 && pixaspect >= 0.99 & pixaspect <= 1.01) |
320 |
> |
if (dpi > 100 && (pixaspect >= 0.99) & (pixaspect <= 1.01)) |
321 |
|
if (pheight/pwidth > ymax/xmax) { |
322 |
|
n = pwidth*dpi/xmax; /* floor */ |
323 |
|
iwidth = n > 0 ? (double)(n*xmax)/dpi : pwidth; |
473 |
|
} |
474 |
|
putchar('\n'); |
475 |
|
/* free scanline */ |
476 |
< |
free((char *)scanin); |
476 |
> |
free((void *)scanin); |
477 |
|
} |
478 |
|
|
479 |
|
|