--- ray/src/px/ra_ps.c 1992/07/13 09:28:01 2.1 +++ ray/src/px/ra_ps.c 1994/02/10 15:40:12 2.8 @@ -4,17 +4,14 @@ static char SCCSid[] = "$SunId$ LBL"; #endif -/* Copyright (c) 1992 Regents of the University of California */ - -#ifndef lint -static char SCCSid[] = "$SunId$ LBL"; -#endif - /* * Radiance picture to PostScript file translator -- one way! */ #include +#ifdef MSDOS +#include +#endif #include "color.h" #include "random.h" @@ -27,15 +24,18 @@ char code[] = /* 6-bit code lookup table */ "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@+"; int wrongformat = 0; /* input in wrong format? */ -double pixaspect = 1.0; /* pixel aspect ratio */ +double pixaspect = 1.0; /* pixel aspect ratio */ int bradj = 0; /* brightness adjustment */ +int ncopies = 1; /* number of copies */ char *progname; int xmax, ymax; +extern char *malloc(); + headline(s) /* check header line */ char *s; { @@ -65,6 +65,9 @@ char *argv[]; goto userr; bradj = atoi(argv[++i]); break; + case 'n': /* number of copies */ + ncopies = atoi(argv[++i]); + break; default: goto userr; } @@ -79,10 +82,13 @@ char *argv[]; exit(1); } if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) { - fprintf(stderr, "can't open output \"%s\"\n", + fprintf(stderr, "%s: can't open output \"%s\"\n", progname, argv[i+1]); exit(1); } +#ifdef MSDOS + setmode(fileno(stdin), O_BINARY); +#endif /* get our header */ getheader(stdin, headline, NULL); if (wrongformat || fgetresolu(&xmax, &ymax, stdin) < 0) @@ -115,24 +121,26 @@ PSheader(name) /* print PostScript header */ char *name; { int landscape = 0; - double pwidth, pheight; + double pwidth, pheight; + double iwidth, iheight; printf("%%!\n"); printf("%%%%Title: %s\n", name); printf("%%%%Creator: %s\n", progname); - printf("%%%%Pages: 1\n"); + printf("%%%%Pages: %d\n", ncopies); if (landscape = xmax > pixaspect*ymax) printf("%%%%Landscape\n"); else printf("%%%%Portrait\n"); printf("%%%%EndComments\n"); - printf("gsave\n"); printf("64 dict begin\n"); + /* define image reader */ + PSprocdef("read6bit"); /* set up transformation matrix */ - printf("%f %f translate 1 -1 scale\n", HMARGIN, VMARGIN+PHEIGHT); + printf("%f %f translate\n", HMARGIN, VMARGIN); if (PWIDTH > PHEIGHT ^ landscape) { printf("0 %f translate\n", PHEIGHT); - printf("90 rotate\n"); + printf("-90 rotate\n"); pwidth = PHEIGHT; pheight = PWIDTH; } else { @@ -140,29 +148,28 @@ char *name; pheight = PHEIGHT; } if (pheight/pwidth > pixaspect*ymax/xmax) { - printf("%f %f matrix scale\n", pwidth/xmax, - pixaspect*pwidth/xmax); - printf("0 %f matrix translate\n", - .5*(pheight-pwidth*pixaspect*ymax/xmax)); + iwidth = pwidth; + iheight = pwidth*pixaspect*ymax/xmax; } else { - printf("%f %f matrix scale\n", pheight/(ymax*pixaspect), - pheight/ymax); - printf("%f 0 matrix translate\n", - .5*(pwidth-pheight*xmax/(ymax*pixaspect))); + iheight = pheight; + iwidth = pheight*xmax/(pixaspect*ymax); } - printf("matrix concatmatrix /imat exch def\n"); - PSprocdef("read6bit"); + printf("%f %f translate\n", (pwidth-iwidth)*.5, (pheight-iheight)*.5); + printf("%f %f scale\n", iwidth, iheight); printf("%%%%EndProlog\n"); - printf("%d %d 8 imat {read6bit} image", xmax, ymax); + /* start image procedure */ + printf("%d %d 8 [%d 0 0 %d 0 %d] {read6bit} image", xmax, ymax, + xmax, -ymax, ymax); } PStrailer() /* print PostScript trailer */ { puts("%%Trailer"); - puts("end"); + if (ncopies > 1) + printf("/#copies %d def\n", ncopies); puts("showpage"); - puts("grestore"); + puts("end"); puts("%%EOF"); } @@ -172,11 +179,13 @@ char *nam; { short itab[128]; register int i; - - for (i = 0; i < 128; i++) + /* assign code values */ + for (i = 0; i < 128; i++) /* clear */ itab[i] = -1; - for (i = 0; i < 64; i++) + for (i = 1; i < 63; i++) /* assign greys */ itab[code[i]] = i<<2 | 2; + itab[code[0]] = 0; /* black is black */ + itab[code[63]] = 255; /* and white is white */ printf("/decode ["); for (i = 0; i < 128; i++) { if (!(i & 0xf)) @@ -189,7 +198,8 @@ char *nam; printf("\t{ 0 1 %d { scanline exch\n", xmax-1); printf("\t\t{ decode currentfile read not {stop} if get\n"); printf("\tdup 0 lt {pop} {exit} ifelse } loop put } for\n"); - printf("} stopped {pop pop pop 0 string} {scanline} ifelse } def\n"); + printf("\t} stopped {pop pop pop 0 string} {scanline} ifelse\n"); + printf("} bind def\n"); } @@ -208,7 +218,7 @@ ra2ps() /* convert Radiance scanlines to 6-bit */ for (y = ymax-1; y >= 0; y--) { if (freadcolrs(scanin, xmax, stdin) < 0) quiterr("error reading Radiance picture"); - normcolrs(scanin, xmax, bradj); /* normalize */ + normcolrs(scanin, xmax, bradj); /* normalize */ for (x = 0; x < xmax; x++) { if (!(col++ & 0x3f)) putchar('\n');