--- ray/src/px/ra_ps.c 1997/09/26 14:20:38 2.20 +++ ray/src/px/ra_ps.c 2004/01/02 12:47:01 2.27 @@ -1,25 +1,24 @@ -/* Copyright (c) 1997 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: ra_ps.c,v 2.27 2004/01/02 12:47:01 schorsch Exp $"; #endif - /* * Radiance picture to PostScript file translator -- one way! */ #include +#include #include #include -#ifdef MSDOS -#include -#endif + +#include "platform.h" #include "color.h" +#include "resolu.h" #define UPPER(c) ((c)&~0x20) /* ASCII trick */ #define CODE6GAM 1.47 /* gamma for 6-bit codes */ -#define DEFDGAM 1.0 /* default device gamma */ +#define DEFGGAM 1.0 /* greyscale device gamma */ +#define DEFCGAM 1.8 /* color device gamma */ #define GRY -1 /* artificial index for grey */ @@ -42,13 +41,13 @@ char code[] = /* 6-bit code lookup table */ int wrongformat = 0; /* input in wrong format? */ double pixaspect = 1.0; /* pixel aspect ratio */ -double devgam = DEFDGAM; /* device gamma response */ +double devgam = 0.; /* device gamma response */ double hmarg = DEFMARG, vmarg = DEFMARG; /* horizontal and vertical margins */ double width = DEFWIDTH, height = DEFHEIGHT; /* default paper width and height */ double dpi = 0; /* print density (0 if unknown) */ -int docolor = 0; /* produce color image? */ +int docolor = 1; /* produce color image? */ int bradj = 0; /* brightness adjustment */ int ncopies = 1; /* number of copies */ @@ -60,12 +59,16 @@ char *progname; int xmax, ymax; /* input image dimensions */ -extern char *malloc(); extern double unit2inch(); +static gethfunc headline; -headline(s) /* check header line */ -char *s; + +static int +headline( /* check header line */ + char *s, + void *p +) { char fmt[32]; @@ -74,6 +77,7 @@ char *s; wrongformat = strcmp(fmt, COLRFMT); } else if (isaspect(s)) pixaspect *= aspectval(s); + return(0); } @@ -157,20 +161,20 @@ char *argv[]; progname, argv[i+1]); exit(1); } -#ifdef MSDOS - setmode(fileno(stdin), O_BINARY); -#endif + SET_FILE_BINARY(stdin); /* get our header */ getheader(stdin, headline, NULL); if (wrongformat || fgetresolu(&xmax, &ymax, stdin) < 0) quiterr("bad picture format"); /* gamma compression */ + if (devgam <= 0.05) + devgam = docolor ? DEFCGAM : DEFGGAM; if (putprim == Cputprim) setcolrgam(CODE6GAM); else if (devgam != 1.) setcolrgam(devgam); /* write header */ - PSheader(i <= argc-1 ? argv[i] : ""); + PSheader(argc, argv); /* convert file */ ra2ps(); /* write trailer */ @@ -188,11 +192,11 @@ double unit2inch(s) /* determine unit */ register char *s; { - static struct unit {char n; float f} u[] = { - 'i', 1., - 'm', 1./25.4, - 'c', 1./2.54, - '\0' }; + static struct unit {char n; float f;} u[] = { + {'i', 1.}, + {'m', 1./25.4}, + {'c', 1./2.54}, + {'\0',0} }; register struct unit *up; while (*s && !isalpha(*s)) @@ -227,26 +231,26 @@ parsepaper(ps) /* determine paper size from name */ char *ps; { static struct psize {char n[12]; float w,h;} p[] = { - "envelope", 4.12, 9.5, - "executive", 7.25, 10.5, - "letter", 8.5, 11., - "lettersmall", 7.68, 10.16, - "legal", 8.5, 14., - "monarch", 3.87, 7.5, - "statement", 5.5, 8.5, - "tabloid", 11., 17., - "A3", 11.69, 16.54, - "A4", 8.27, 11.69, - "A4small", 7.47, 10.85, - "A5", 6.00, 8.27, - "A6", 4.13, 6.00, - "B4", 10.12, 14.33, - "B5", 7.17, 10.12, - "C5", 6.38, 9.01, - "C6", 4.49, 6.38, - "DL", 4.33, 8.66, - "hagaki", 3.94, 5.83, - "" }; + {"envelope", 4.12, 9.5}, + {"executive", 7.25, 10.5}, + {"letter", 8.5, 11.}, + {"lettersmall", 7.68, 10.16}, + {"legal", 8.5, 14.}, + {"monarch", 3.87, 7.5}, + {"statement", 5.5, 8.5}, + {"tabloid", 11., 17.}, + {"A3", 11.69, 16.54}, + {"A4", 8.27, 11.69}, + {"A4small", 7.47, 10.85}, + {"A5", 6.00, 8.27}, + {"A6", 4.13, 6.00}, + {"B4", 10.12, 14.33}, + {"B5", 7.17, 10.12}, + {"C5", 6.38, 9.01}, + {"C6", 4.49, 6.38}, + {"DL", 4.33, 8.66}, + {"hagaki", 3.94, 5.83}, + {"",0.0,0.0} }; register struct psize *pp; register char *s = ps; double d; @@ -259,7 +263,7 @@ char *ps; height = atof(++s); width *= d; height *= d; - if (width >= 1. & height >= 1.) + if ((width >= 1.) & (height >= 1.)) return; } else /* check for match to standard size */ for (pp = p; pp->n[0]; pp++) @@ -289,8 +293,9 @@ char *err; } -PSheader(name) /* print PostScript header */ -char *name; +PSheader(ac, av) /* print PostScript header */ +int ac; +char **av; { char *rstr; int landscape, rotate, n; @@ -298,21 +303,21 @@ char *name; double iwidth, iheight; /* EPS comments */ puts("%!PS-Adobe-2.0 EPSF-2.0"); - printf("%%%%Title: %s\n", name); - printf("%%%%Creator: %s = %s\n", progname, SCCSid); + printf("%%%%Title: "); printargs(ac, av, stdout); + printf("%%%%Creator: %s\n", progname); printf("%%%%Pages: %d\n", ncopies); - if (landscape = xmax > pixaspect*ymax) + if ( (landscape = xmax > pixaspect*ymax) ) puts("%%Orientation: Landscape"); else puts("%%Orientation: Portrait"); - if (rotate = PWIDTH > PHEIGHT ^ landscape) { + if ( (rotate = (PWIDTH > PHEIGHT) ^ landscape) ) { pwidth = PHEIGHT; pheight = PWIDTH; } else { pwidth = PWIDTH; pheight = PHEIGHT; } - if (dpi > 100 && pixaspect >= 0.99 & pixaspect <= 1.01) + if (dpi > 100 && (pixaspect >= 0.99) & (pixaspect <= 1.01)) if (pheight/pwidth > ymax/xmax) { n = pwidth*dpi/xmax; /* floor */ iwidth = n > 0 ? (double)(n*xmax)/dpi : pwidth; @@ -468,7 +473,7 @@ ra2ps() /* convert Radiance scanlines to 6-bit */ } putchar('\n'); /* free scanline */ - free((char *)scanin); + free((void *)scanin); }