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.18 by gregl, Thu Sep 18 18:01:24 1997 UTC vs.
Revision 2.24 by greg, Sat Feb 22 02:07:28 2003 UTC

# Line 1 | Line 1
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   */
# Line 19 | Line 16 | static char SCCSid[] = "$SunId$ SGI";
16   #define UPPER(c)        ((c)&~0x20)             /* ASCII trick */
17  
18   #define CODE6GAM        1.47                    /* gamma for 6-bit codes */
19 < #define DEFDGAM         1.0                     /* default device gamma */
19 > #define DEFGGAM         1.0                     /* greyscale device gamma */
20 > #define DEFCGAM         1.8                     /* color device gamma */
21  
22   #define GRY             -1                      /* artificial index for grey */
23  
# Line 42 | Line 40 | char  code[] =                 /* 6-bit code lookup table */
40   int  wrongformat = 0;                   /* input in wrong format? */
41   double  pixaspect = 1.0;                /* pixel aspect ratio */
42  
43 < double  devgam = DEFDGAM;               /* device gamma response */
43 > double  devgam = 0.;                    /* device gamma response */
44   double  hmarg = DEFMARG,
45          vmarg = DEFMARG;                /* horizontal and vertical margins */
46   double  width = DEFWIDTH,
47          height = DEFHEIGHT;             /* default paper width and height */
48 < int  docolor = 0;                       /* produce color image? */
48 > double  dpi = 0;                        /* print density (0 if unknown) */
49 > int  docolor = 1;                       /* produce color image? */
50   int  bradj = 0;                         /* brightness adjustment */
51   int  ncopies = 1;                       /* number of copies */
52  
# Line 57 | Line 56 | int  (*putprim)() = Aputprim;          /* function for writing
56  
57   char  *progname;
58  
59 < int  xmax, ymax;
59 > int  xmax, ymax;                        /* input image dimensions */
60  
62 extern char  *malloc();
61   extern double   unit2inch();
62  
63  
64 + int
65   headline(s)             /* check header line */
66   char  *s;
67   {
# Line 73 | Line 72 | char  *s;
72                  wrongformat = strcmp(fmt, COLRFMT);
73          } else if (isaspect(s))
74                  pixaspect *= aspectval(s);
75 +        return(0);
76   }
77  
78  
# Line 103 | Line 103 | char  *argv[];
103                          case 'C':               /* compressed ASCII encoding */
104                                  putprim = Cputprim;
105                                  break;
106 +                        case 'd':               /* print density */
107 +                                dpi = atof(argv[++i]);
108 +                                break;
109                          case 'g':               /* device gamma adjustment */
110                                  devgam = atof(argv[++i]);
111                                  break;
# Line 161 | Line 164 | char  *argv[];
164          if (wrongformat || fgetresolu(&xmax, &ymax, stdin) < 0)
165                  quiterr("bad picture format");
166                                  /* gamma compression */
167 +        if (devgam <= 0.05)
168 +                devgam = docolor ? DEFCGAM : DEFGGAM;
169          if (putprim == Cputprim)
170 <                setcolrgam(CODE6GAM/devgam);
170 >                setcolrgam(CODE6GAM);
171          else if (devgam != 1.)
172 <                setcolrgam(1./devgam);
172 >                setcolrgam(devgam);
173                                  /* write header */
174 <        PSheader(i <= argc-1 ? argv[i] : "<stdin>");
174 >        PSheader(argc, argv);
175                                  /* convert file */
176          ra2ps();
177                                  /* write trailer */
# Line 174 | Line 179 | char  *argv[];
179          exit(0);
180   userr:
181          fprintf(stderr,
182 < "Usage: %s [-b|c][-A|B|C][-e +/-stops][-p paper][-m[h|v] margin][-g gamma] [input [output]]\n",
182 > "Usage: %s [-b|c][-A|B|C][-e +/-stops][-p paper][-m[h|v] margin][-d dpi][-g gamma] [input [output]]\n",
183                          progname);
184          exit(1);
185   }
# Line 184 | Line 189 | double
189   unit2inch(s)            /* determine unit */
190   register char   *s;
191   {
192 <        static struct unit {char n; float f} u[] = {
192 >        static struct unit {char n; float f;} u[] = {
193                  'i', 1.,
194                  'm', 1./25.4,
195                  'c', 1./2.54,
# Line 223 | Line 228 | parsepaper(ps)         /* determine paper size from name */
228   char    *ps;
229   {
230          static struct psize {char n[12]; float w,h;} p[] = {
231 +                "envelope", 4.12, 9.5,
232 +                "executive", 7.25, 10.5,
233                  "letter", 8.5, 11.,
234 +                "lettersmall", 7.68, 10.16,
235                  "legal", 8.5, 14.,
228                "executive", 7.25, 10.5,
229                "envelope", 4.12, 9.5,
236                  "monarch", 3.87, 7.5,
237 +                "statement", 5.5, 8.5,
238                  "tabloid", 11., 17.,
239                  "A3", 11.69, 16.54,
240                  "A4", 8.27, 11.69,
241 +                "A4small", 7.47, 10.85,
242                  "A5", 6.00, 8.27,
243                  "A6", 4.13, 6.00,
244                  "B4", 10.12, 14.33,
245                  "B5", 7.17, 10.12,
238                "DL", 4.33, 8.66,
246                  "C5", 6.38, 9.01,
247                  "C6", 4.49, 6.38,
248 +                "DL", 4.33, 8.66,
249                  "hagaki", 3.94, 5.83,
250                  "" };
251          register struct psize   *pp;
# Line 266 | Line 274 | char   *ps;
274          fprintf(stderr, "_Name________Width_Height_(inches)\n");
275          for (pp = p; pp->n[0]; pp++)
276                  fprintf(stderr, "%-11s  %5.2f  %5.2f\n", pp->n, pp->w, pp->h);
277 +        fprintf(stderr, "Or use WWxHH size specification\n");
278          exit(1);
279   }
280  
# Line 281 | Line 290 | char  *err;
290   }
291  
292  
293 < PSheader(name)                  /* print PostScript header */
294 < char  *name;
293 > PSheader(ac, av)                /* print PostScript header */
294 > int  ac;
295 > char  **av;
296   {
297          char  *rstr;
298 <        int  landscape = 0;
298 >        int  landscape, rotate, n;
299          double  pwidth, pheight;
300          double  iwidth, iheight;
301                                          /* EPS comments */
302          puts("%!PS-Adobe-2.0 EPSF-2.0");
303 <        printf("%%%%Title: %s\n", name);
304 <        printf("%%%%Creator: %s = %s\n", progname, SCCSid);
303 >        printf("%%%%Title: "); printargs(ac, av, stdout);
304 >        printf("%%%%Creator: %s\n", progname);
305          printf("%%%%Pages: %d\n", ncopies);
306          if (landscape = xmax > pixaspect*ymax)
307                  puts("%%Orientation: Landscape");
308          else
309                  puts("%%Orientation: Portrait");
310 <        if (PWIDTH > PHEIGHT ^ landscape) {
310 >        if (rotate = PWIDTH > PHEIGHT ^ landscape) {
311                  pwidth = PHEIGHT;
312                  pheight = PWIDTH;
313          } else {
314                  pwidth = PWIDTH;
315                  pheight = PHEIGHT;
316          }
317 <        if (pheight/pwidth > pixaspect*ymax/xmax) {
318 <                iwidth = pwidth;
319 <                iheight = pwidth*pixaspect*ymax/xmax;
320 <        } else {
321 <                iheight = pheight;
322 <                iwidth = pheight*xmax/(pixaspect*ymax);
323 <        }
324 <        if (pwidth == PHEIGHT)
317 >        if (dpi > 100 && pixaspect >= 0.99 & pixaspect <= 1.01)
318 >                if (pheight/pwidth > ymax/xmax) {
319 >                        n = pwidth*dpi/xmax;    /* floor */
320 >                        iwidth = n > 0 ? (double)(n*xmax)/dpi : pwidth;
321 >                        iheight = iwidth*ymax/xmax;
322 >                } else {
323 >                        n = pheight*dpi/ymax;   /* floor */
324 >                        iheight = n > 0 ? (double)(n*ymax)/dpi : pheight;
325 >                        iwidth = iheight*xmax/ymax;
326 >                }
327 >        else
328 >                if (pheight/pwidth > pixaspect*ymax/xmax) {
329 >                        iwidth = pwidth;
330 >                        iheight = iwidth*pixaspect*ymax/xmax;
331 >                } else {
332 >                        iheight = pheight;
333 >                        iwidth = iheight*xmax/(pixaspect*ymax);
334 >                }
335 >        if (rotate)
336                  printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n",
337                                  HMARGIN+(pheight-iheight)*.5,
338                                  VMARGIN+(pwidth-iwidth)*.5,
# Line 338 | Line 359 | char  *name;
359                  PSprocdef("read6bitRLE");
360                                          /* set up transformation matrix */
361          printf("%f %f translate\n", HMARGIN, VMARGIN);
362 <        if (pwidth == PHEIGHT) {
362 >        if (rotate) {
363                  printf("%f 0 translate\n", PWIDTH);
364                  puts("90 rotate");
365          }
# Line 389 | Line 410 | char  *nam;
410          for (i = 0; i < 128; i++)       /* clear */
411                  itab[i] = -1;
412          for (i = 1; i < 63; i++)        /* assign greys */
413 <                itab[code[i]] = 256.0*pow((i+.5)/64.0, CODE6GAM);
413 >                itab[code[i]] = 256.0*pow((i+.5)/64.0, CODE6GAM/devgam);
414          itab[code[0]] = 0;              /* black is black */
415          itab[code[63]] = 255;           /* and white is white */
416          printf("/codetab [");
# Line 449 | Line 470 | ra2ps()                                /* convert Radiance scanlines to 6-bit */
470          }
471          putchar('\n');
472                                                  /* free scanline */
473 <        free((char *)scanin);
473 >        free((void *)scanin);
474   }
475  
476  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines