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.27 by schorsch, Fri Jan 2 12:47:01 2004 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   */
7  
8   #include  <stdio.h>
9 + #include  <string.h>
10   #include  <math.h>
11   #include  <ctype.h>
12 < #ifdef MSDOS
13 < #include  <fcntl.h>
16 < #endif
12 >
13 > #include  "platform.h"
14   #include  "color.h"
15 + #include  "resolu.h"
16  
17   #define UPPER(c)        ((c)&~0x20)             /* ASCII trick */
18  
19   #define CODE6GAM        1.47                    /* gamma for 6-bit codes */
20 < #define DEFDGAM         1.0                     /* default device gamma */
20 > #define DEFGGAM         1.0                     /* greyscale device gamma */
21 > #define DEFCGAM         1.8                     /* color device gamma */
22  
23   #define GRY             -1                      /* artificial index for grey */
24  
# Line 42 | Line 41 | char  code[] =                 /* 6-bit code lookup table */
41   int  wrongformat = 0;                   /* input in wrong format? */
42   double  pixaspect = 1.0;                /* pixel aspect ratio */
43  
44 < double  devgam = DEFDGAM;               /* device gamma response */
44 > double  devgam = 0.;                    /* device gamma response */
45   double  hmarg = DEFMARG,
46          vmarg = DEFMARG;                /* horizontal and vertical margins */
47   double  width = DEFWIDTH,
48          height = DEFHEIGHT;             /* default paper width and height */
49 < int  docolor = 0;                       /* produce color image? */
49 > double  dpi = 0;                        /* print density (0 if unknown) */
50 > int  docolor = 1;                       /* produce color image? */
51   int  bradj = 0;                         /* brightness adjustment */
52   int  ncopies = 1;                       /* number of copies */
53  
# Line 57 | Line 57 | int  (*putprim)() = Aputprim;          /* function for writing
57  
58   char  *progname;
59  
60 < int  xmax, ymax;
60 > int  xmax, ymax;                        /* input image dimensions */
61  
62 extern char  *malloc();
62   extern double   unit2inch();
63  
64 + static gethfunc headline;
65  
66 < headline(s)             /* check header line */
67 < char  *s;
66 >
67 > static int
68 > headline(               /* check header line */
69 >        char    *s,
70 >        void    *p
71 > )
72   {
73          char  fmt[32];
74  
# Line 73 | Line 77 | char  *s;
77                  wrongformat = strcmp(fmt, COLRFMT);
78          } else if (isaspect(s))
79                  pixaspect *= aspectval(s);
80 +        return(0);
81   }
82  
83  
# Line 103 | Line 108 | char  *argv[];
108                          case 'C':               /* compressed ASCII encoding */
109                                  putprim = Cputprim;
110                                  break;
111 +                        case 'd':               /* print density */
112 +                                dpi = atof(argv[++i]);
113 +                                break;
114                          case 'g':               /* device gamma adjustment */
115                                  devgam = atof(argv[++i]);
116                                  break;
# Line 153 | Line 161 | char  *argv[];
161                                  progname, argv[i+1]);
162                  exit(1);
163          }
164 < #ifdef MSDOS
157 <        setmode(fileno(stdin), O_BINARY);
158 < #endif
164 >        SET_FILE_BINARY(stdin);
165                                  /* get our header */
166          getheader(stdin, headline, NULL);
167          if (wrongformat || fgetresolu(&xmax, &ymax, stdin) < 0)
168                  quiterr("bad picture format");
169                                  /* gamma compression */
170 +        if (devgam <= 0.05)
171 +                devgam = docolor ? DEFCGAM : DEFGGAM;
172          if (putprim == Cputprim)
173 <                setcolrgam(CODE6GAM/devgam);
173 >                setcolrgam(CODE6GAM);
174          else if (devgam != 1.)
175 <                setcolrgam(1./devgam);
175 >                setcolrgam(devgam);
176                                  /* write header */
177 <        PSheader(i <= argc-1 ? argv[i] : "<stdin>");
177 >        PSheader(argc, argv);
178                                  /* convert file */
179          ra2ps();
180                                  /* write trailer */
# Line 174 | Line 182 | char  *argv[];
182          exit(0);
183   userr:
184          fprintf(stderr,
185 < "Usage: %s [-b|c][-A|B|C][-e +/-stops][-p paper][-m[h|v] margin][-g gamma] [input [output]]\n",
185 > "Usage: %s [-b|c][-A|B|C][-e +/-stops][-p paper][-m[h|v] margin][-d dpi][-g gamma] [input [output]]\n",
186                          progname);
187          exit(1);
188   }
# Line 184 | Line 192 | double
192   unit2inch(s)            /* determine unit */
193   register char   *s;
194   {
195 <        static struct unit {char n; float f} u[] = {
196 <                'i', 1.,
197 <                'm', 1./25.4,
198 <                'c', 1./2.54,
199 <                '\0' };
195 >        static struct unit {char n; float f;} u[] = {
196 >                {'i', 1.},
197 >                {'m', 1./25.4},
198 >                {'c', 1./2.54},
199 >                {'\0',0} };
200          register struct unit    *up;
201  
202          while (*s && !isalpha(*s))
# Line 223 | Line 231 | parsepaper(ps)         /* determine paper size from name */
231   char    *ps;
232   {
233          static struct psize {char n[12]; float w,h;} p[] = {
234 <                "letter", 8.5, 11.,
235 <                "legal", 8.5, 14.,
236 <                "executive", 7.25, 10.5,
237 <                "envelope", 4.12, 9.5,
238 <                "monarch", 3.87, 7.5,
239 <                "tabloid", 11., 17.,
240 <                "A3", 11.69, 16.54,
241 <                "A4", 8.27, 11.69,
242 <                "A5", 6.00, 8.27,
243 <                "A6", 4.13, 6.00,
244 <                "B4", 10.12, 14.33,
245 <                "B5", 7.17, 10.12,
246 <                "DL", 4.33, 8.66,
247 <                "C5", 6.38, 9.01,
248 <                "C6", 4.49, 6.38,
249 <                "hagaki", 3.94, 5.83,
250 <                "" };
234 >                {"envelope", 4.12, 9.5},
235 >                {"executive", 7.25, 10.5},
236 >                {"letter", 8.5, 11.},
237 >                {"lettersmall", 7.68, 10.16},
238 >                {"legal", 8.5, 14.},
239 >                {"monarch", 3.87, 7.5},
240 >                {"statement", 5.5, 8.5},
241 >                {"tabloid", 11., 17.},
242 >                {"A3", 11.69, 16.54},
243 >                {"A4", 8.27, 11.69},
244 >                {"A4small", 7.47, 10.85},
245 >                {"A5", 6.00, 8.27},
246 >                {"A6", 4.13, 6.00},
247 >                {"B4", 10.12, 14.33},
248 >                {"B5", 7.17, 10.12},
249 >                {"C5", 6.38, 9.01},
250 >                {"C6", 4.49, 6.38},
251 >                {"DL", 4.33, 8.66},
252 >                {"hagaki", 3.94, 5.83},
253 >                {"",0.0,0.0} };
254          register struct psize   *pp;
255          register char   *s = ps;
256          double  d;
# Line 252 | Line 263 | char   *ps;
263                  height = atof(++s);
264                  width *= d;
265                  height *= d;
266 <                if (width >= 1. & height >= 1.)
266 >                if ((width >= 1.) & (height >= 1.))
267                          return;
268          } else                          /* check for match to standard size */
269                  for (pp = p; pp->n[0]; pp++)
# Line 266 | Line 277 | char   *ps;
277          fprintf(stderr, "_Name________Width_Height_(inches)\n");
278          for (pp = p; pp->n[0]; pp++)
279                  fprintf(stderr, "%-11s  %5.2f  %5.2f\n", pp->n, pp->w, pp->h);
280 +        fprintf(stderr, "Or use WWxHH size specification\n");
281          exit(1);
282   }
283  
# Line 281 | Line 293 | char  *err;
293   }
294  
295  
296 < PSheader(name)                  /* print PostScript header */
297 < char  *name;
296 > PSheader(ac, av)                /* print PostScript header */
297 > int  ac;
298 > char  **av;
299   {
300          char  *rstr;
301 <        int  landscape = 0;
301 >        int  landscape, rotate, n;
302          double  pwidth, pheight;
303          double  iwidth, iheight;
304                                          /* EPS comments */
305          puts("%!PS-Adobe-2.0 EPSF-2.0");
306 <        printf("%%%%Title: %s\n", name);
307 <        printf("%%%%Creator: %s = %s\n", progname, SCCSid);
306 >        printf("%%%%Title: "); printargs(ac, av, stdout);
307 >        printf("%%%%Creator: %s\n", progname);
308          printf("%%%%Pages: %d\n", ncopies);
309 <        if (landscape = xmax > pixaspect*ymax)
309 >        if ( (landscape = xmax > pixaspect*ymax) )
310                  puts("%%Orientation: Landscape");
311          else
312                  puts("%%Orientation: Portrait");
313 <        if (PWIDTH > PHEIGHT ^ landscape) {
313 >        if ( (rotate = (PWIDTH > PHEIGHT) ^ landscape) ) {
314                  pwidth = PHEIGHT;
315                  pheight = PWIDTH;
316          } else {
317                  pwidth = PWIDTH;
318                  pheight = PHEIGHT;
319          }
320 <        if (pheight/pwidth > pixaspect*ymax/xmax) {
321 <                iwidth = pwidth;
322 <                iheight = pwidth*pixaspect*ymax/xmax;
323 <        } else {
324 <                iheight = pheight;
325 <                iwidth = pheight*xmax/(pixaspect*ymax);
326 <        }
327 <        if (pwidth == PHEIGHT)
320 >        if (dpi > 100 && (pixaspect >= 0.99) & (pixaspect <= 1.01))
321 >                if (pheight/pwidth > ymax/xmax) {
322 >                        n = pwidth*dpi/xmax;    /* floor */
323 >                        iwidth = n > 0 ? (double)(n*xmax)/dpi : pwidth;
324 >                        iheight = iwidth*ymax/xmax;
325 >                } else {
326 >                        n = pheight*dpi/ymax;   /* floor */
327 >                        iheight = n > 0 ? (double)(n*ymax)/dpi : pheight;
328 >                        iwidth = iheight*xmax/ymax;
329 >                }
330 >        else
331 >                if (pheight/pwidth > pixaspect*ymax/xmax) {
332 >                        iwidth = pwidth;
333 >                        iheight = iwidth*pixaspect*ymax/xmax;
334 >                } else {
335 >                        iheight = pheight;
336 >                        iwidth = iheight*xmax/(pixaspect*ymax);
337 >                }
338 >        if (rotate)
339                  printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n",
340                                  HMARGIN+(pheight-iheight)*.5,
341                                  VMARGIN+(pwidth-iwidth)*.5,
# Line 338 | Line 362 | char  *name;
362                  PSprocdef("read6bitRLE");
363                                          /* set up transformation matrix */
364          printf("%f %f translate\n", HMARGIN, VMARGIN);
365 <        if (pwidth == PHEIGHT) {
365 >        if (rotate) {
366                  printf("%f 0 translate\n", PWIDTH);
367                  puts("90 rotate");
368          }
# Line 389 | Line 413 | char  *nam;
413          for (i = 0; i < 128; i++)       /* clear */
414                  itab[i] = -1;
415          for (i = 1; i < 63; i++)        /* assign greys */
416 <                itab[code[i]] = 256.0*pow((i+.5)/64.0, CODE6GAM);
416 >                itab[code[i]] = 256.0*pow((i+.5)/64.0, CODE6GAM/devgam);
417          itab[code[0]] = 0;              /* black is black */
418          itab[code[63]] = 255;           /* and white is white */
419          printf("/codetab [");
# Line 449 | Line 473 | ra2ps()                                /* convert Radiance scanlines to 6-bit */
473          }
474          putchar('\n');
475                                                  /* free scanline */
476 <        free((char *)scanin);
476 >        free((void *)scanin);
477   }
478  
479  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines