--- ray/src/px/ra_ps.c 1997/09/23 16:52:23 2.19 +++ ray/src/px/ra_ps.c 2003/02/22 02:07:28 2.24 @@ -1,9 +1,6 @@ -/* Copyright (c) 1997 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: ra_ps.c,v 2.24 2003/02/22 02:07:28 greg Exp $"; #endif - /* * Radiance picture to PostScript file translator -- one way! */ @@ -19,7 +16,8 @@ static char SCCSid[] = "$SunId$ SGI"; #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,12 +40,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 */ -int docolor = 0; /* produce color image? */ +double dpi = 0; /* print density (0 if unknown) */ +int docolor = 1; /* produce color image? */ int bradj = 0; /* brightness adjustment */ int ncopies = 1; /* number of copies */ @@ -57,12 +56,12 @@ int (*putprim)() = Aputprim; /* function for writing char *progname; -int xmax, ymax; +int xmax, ymax; /* input image dimensions */ -extern char *malloc(); extern double unit2inch(); +int headline(s) /* check header line */ char *s; { @@ -73,6 +72,7 @@ char *s; wrongformat = strcmp(fmt, COLRFMT); } else if (isaspect(s)) pixaspect *= aspectval(s); + return(0); } @@ -103,6 +103,9 @@ char *argv[]; case 'C': /* compressed ASCII encoding */ putprim = Cputprim; break; + case 'd': /* print density */ + dpi = atof(argv[++i]); + break; case 'g': /* device gamma adjustment */ devgam = atof(argv[++i]); break; @@ -161,12 +164,14 @@ char *argv[]; 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 */ @@ -174,7 +179,7 @@ char *argv[]; exit(0); userr: fprintf(stderr, -"Usage: %s [-b|c][-A|B|C][-e +/-stops][-p paper][-m[h|v] margin][-g gamma] [input [output]]\n", +"Usage: %s [-b|c][-A|B|C][-e +/-stops][-p paper][-m[h|v] margin][-d dpi][-g gamma] [input [output]]\n", progname); exit(1); } @@ -184,7 +189,7 @@ double unit2inch(s) /* determine unit */ register char *s; { - static struct unit {char n; float f} u[] = { + static struct unit {char n; float f;} u[] = { 'i', 1., 'm', 1./25.4, 'c', 1./2.54, @@ -285,37 +290,49 @@ char *err; } -PSheader(name) /* print PostScript header */ -char *name; +PSheader(ac, av) /* print PostScript header */ +int ac; +char **av; { char *rstr; - int landscape = 0; + int landscape, rotate, n; double pwidth, pheight; 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) puts("%%Orientation: Landscape"); else puts("%%Orientation: Portrait"); - if (PWIDTH > PHEIGHT ^ landscape) { + if (rotate = PWIDTH > PHEIGHT ^ landscape) { pwidth = PHEIGHT; pheight = PWIDTH; } else { pwidth = PWIDTH; pheight = PHEIGHT; } - if (pheight/pwidth > pixaspect*ymax/xmax) { - iwidth = pwidth; - iheight = pwidth*pixaspect*ymax/xmax; - } else { - iheight = pheight; - iwidth = pheight*xmax/(pixaspect*ymax); - } - if (pwidth == PHEIGHT) + 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; + iheight = iwidth*ymax/xmax; + } else { + n = pheight*dpi/ymax; /* floor */ + iheight = n > 0 ? (double)(n*ymax)/dpi : pheight; + iwidth = iheight*xmax/ymax; + } + else + if (pheight/pwidth > pixaspect*ymax/xmax) { + iwidth = pwidth; + iheight = iwidth*pixaspect*ymax/xmax; + } else { + iheight = pheight; + iwidth = iheight*xmax/(pixaspect*ymax); + } + if (rotate) printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n", HMARGIN+(pheight-iheight)*.5, VMARGIN+(pwidth-iwidth)*.5, @@ -342,7 +359,7 @@ char *name; PSprocdef("read6bitRLE"); /* set up transformation matrix */ printf("%f %f translate\n", HMARGIN, VMARGIN); - if (pwidth == PHEIGHT) { + if (rotate) { printf("%f 0 translate\n", PWIDTH); puts("90 rotate"); } @@ -453,7 +470,7 @@ ra2ps() /* convert Radiance scanlines to 6-bit */ } putchar('\n'); /* free scanline */ - free((char *)scanin); + free((void *)scanin); }