ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ra_ps.c
(Generate patch)

Comparing ray/src/px/ra_ps.c (file contents):
Revision 2.19 by gregl, Tue Sep 23 16:52:23 1997 UTC vs.
Revision 2.21 by gwlarson, Fri Aug 28 10:03:46 1998 UTC

# Line 19 | Line 19 | static char SCCSid[] = "$SunId$ SGI";
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  
# Line 42 | Line 43 | char  code[] =                 /* 6-bit code lookup table */
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  
# Line 57 | Line 59 | int  (*putprim)() = Aputprim;          /* function for writing
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();
# Line 103 | Line 105 | char  *argv[];
105                          case 'C':               /* compressed ASCII encoding */
106                                  putprim = Cputprim;
107                                  break;
108 +                        case 'd':               /* print density */
109 +                                dpi = atof(argv[++i]);
110 +                                break;
111                          case 'g':               /* device gamma adjustment */
112                                  devgam = atof(argv[++i]);
113                                  break;
# Line 161 | Line 166 | char  *argv[];
166          if (wrongformat || fgetresolu(&xmax, &ymax, stdin) < 0)
167                  quiterr("bad picture format");
168                                  /* gamma compression */
169 +        if (devgam <= 0.05)
170 +                devgam = docolor ? DEFCGAM : DEFGGAM;
171          if (putprim == Cputprim)
172                  setcolrgam(CODE6GAM);
173          else if (devgam != 1.)
174                  setcolrgam(devgam);
175                                  /* write header */
176 <        PSheader(i <= argc-1 ? argv[i] : "<stdin>");
176 >        PSheader(argc, argv);
177                                  /* convert file */
178          ra2ps();
179                                  /* write trailer */
# Line 174 | Line 181 | char  *argv[];
181          exit(0);
182   userr:
183          fprintf(stderr,
184 < "Usage: %s [-b|c][-A|B|C][-e +/-stops][-p paper][-m[h|v] margin][-g gamma] [input [output]]\n",
184 > "Usage: %s [-b|c][-A|B|C][-e +/-stops][-p paper][-m[h|v] margin][-d dpi][-g gamma] [input [output]]\n",
185                          progname);
186          exit(1);
187   }
# Line 285 | Line 292 | char  *err;
292   }
293  
294  
295 < PSheader(name)                  /* print PostScript header */
296 < char  *name;
295 > PSheader(ac, av)                /* print PostScript header */
296 > int  ac;
297 > char  **av;
298   {
299          char  *rstr;
300 <        int  landscape = 0;
300 >        int  landscape, rotate, n;
301          double  pwidth, pheight;
302          double  iwidth, iheight;
303                                          /* EPS comments */
304          puts("%!PS-Adobe-2.0 EPSF-2.0");
305 <        printf("%%%%Title: %s\n", name);
306 <        printf("%%%%Creator: %s = %s\n", progname, SCCSid);
305 >        printf("%%%%Title: "); printargs(ac, av, stdout);
306 >        printf("%%%%Creator: %s\n", SCCSid);
307          printf("%%%%Pages: %d\n", ncopies);
308          if (landscape = xmax > pixaspect*ymax)
309                  puts("%%Orientation: Landscape");
310          else
311                  puts("%%Orientation: Portrait");
312 <        if (PWIDTH > PHEIGHT ^ landscape) {
312 >        if (rotate = PWIDTH > PHEIGHT ^ landscape) {
313                  pwidth = PHEIGHT;
314                  pheight = PWIDTH;
315          } else {
316                  pwidth = PWIDTH;
317                  pheight = PHEIGHT;
318          }
319 <        if (pheight/pwidth > pixaspect*ymax/xmax) {
320 <                iwidth = pwidth;
321 <                iheight = pwidth*pixaspect*ymax/xmax;
322 <        } else {
323 <                iheight = pheight;
324 <                iwidth = pheight*xmax/(pixaspect*ymax);
325 <        }
326 <        if (pwidth == PHEIGHT)
319 >        if (dpi > 100 && pixaspect >= 0.99 & pixaspect <= 1.01)
320 >                if (pheight/pwidth > ymax/xmax) {
321 >                        n = pwidth*dpi/xmax;    /* floor */
322 >                        iwidth = n > 0 ? (double)(n*xmax)/dpi : pwidth;
323 >                        iheight = iwidth*ymax/xmax;
324 >                } else {
325 >                        n = pheight*dpi/ymax;   /* floor */
326 >                        iheight = n > 0 ? (double)(n*ymax)/dpi : pheight;
327 >                        iwidth = iheight*xmax/ymax;
328 >                }
329 >        else
330 >                if (pheight/pwidth > pixaspect*ymax/xmax) {
331 >                        iwidth = pwidth;
332 >                        iheight = iwidth*pixaspect*ymax/xmax;
333 >                } else {
334 >                        iheight = pheight;
335 >                        iwidth = iheight*xmax/(pixaspect*ymax);
336 >                }
337 >        if (rotate)
338                  printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n",
339                                  HMARGIN+(pheight-iheight)*.5,
340                                  VMARGIN+(pwidth-iwidth)*.5,
# Line 342 | Line 361 | char  *name;
361                  PSprocdef("read6bitRLE");
362                                          /* set up transformation matrix */
363          printf("%f %f translate\n", HMARGIN, VMARGIN);
364 <        if (pwidth == PHEIGHT) {
364 >        if (rotate) {
365                  printf("%f 0 translate\n", PWIDTH);
366                  puts("90 rotate");
367          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines