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.23 by gwlarson, Mon Jul 19 09:53:06 1999 UTC vs.
Revision 2.28 by schorsch, Sun Mar 28 20:33:14 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  
# Line 53 | Line 51 | int  docolor = 1;                      /* produce color image? */
51   int  bradj = 0;                         /* brightness adjustment */
52   int  ncopies = 1;                       /* number of copies */
53  
54 < extern int      Aputprim(), Bputprim(), Cputprim();
54 > char  *progname;
55 > int  xmax, ymax;                        /* input image dimensions */
56  
57 < int  (*putprim)() = Aputprim;           /* function for writing scanline */
57 > typedef void putprimf_t(COLR *scn, int pri);
58  
59 < char  *progname;
59 > static gethfunc headline;
60 > static putprimf_t Aputprim, Bputprim, Cputprim;
61  
62 < int  xmax, ymax;                        /* input image dimensions */
62 > static double unit2inch(register char *s);
63 > static int matchid(char *name, char *id);
64 > static void parsepaper(char *ps);
65 > static void quiterr(char *err);
66 > static void PSheader(int ac, char **av);
67 > static void PStrailer(void);
68 > static void PSprocdef(char *nam);
69 > static void ra2ps(void);
70 > static void putrle(int cnt, int cod);
71  
64 extern char  *malloc();
65 extern double   unit2inch();
72  
73 + putprimf_t *putprim = Aputprim;         /* function for writing scanline */
74  
75 < int
76 < headline(s)             /* check header line */
77 < char  *s;
75 >
76 > static int
77 > headline(               /* check header line */
78 >        char    *s,
79 >        void    *p
80 > )
81   {
82          char  fmt[32];
83  
# Line 79 | Line 89 | char  *s;
89          return(0);
90   }
91  
92 <
93 < main(argc, argv)
84 < int  argc;
85 < char  *argv[];
92 > int
93 > main(int  argc, char  *argv[])
94   {
95          int  i;
96          double  d;
# Line 160 | Line 168 | char  *argv[];
168                                  progname, argv[i+1]);
169                  exit(1);
170          }
171 < #ifdef MSDOS
164 <        setmode(fileno(stdin), O_BINARY);
165 < #endif
171 >        SET_FILE_BINARY(stdin);
172                                  /* get our header */
173          getheader(stdin, headline, NULL);
174          if (wrongformat || fgetresolu(&xmax, &ymax, stdin) < 0)
# Line 189 | Line 195 | userr:
195   }
196  
197  
198 < double
199 < unit2inch(s)            /* determine unit */
200 < register char   *s;
198 > static double
199 > unit2inch(              /* determine unit */
200 >        register char   *s
201 > )
202   {
203          static struct unit {char n; float f;} u[] = {
204 <                'i', 1.,
205 <                'm', 1./25.4,
206 <                'c', 1./2.54,
207 <                '\0' };
204 >                {'i', 1.},
205 >                {'m', 1./25.4},
206 >                {'c', 1./2.54},
207 >                {'\0',0} };
208          register struct unit    *up;
209  
210          while (*s && !isalpha(*s))
# Line 209 | Line 216 | register char  *s;
216   }
217  
218  
219 < int
220 < matchid(name, id)       /* see if name matches id (case insensitive) */
221 < char    *name;
222 < register char   *id;
219 > static int
220 > matchid(        /* see if name matches id (case insensitive) */
221 >        char    *name,
222 >        register char   *id
223 > )
224   {
225          register char   *s = name;
226  
# Line 228 | Line 236 | register char  *id;
236   }
237  
238  
239 < parsepaper(ps)          /* determine paper size from name */
240 < char    *ps;
239 > static void
240 > parsepaper(             /* determine paper size from name */
241 >        char    *ps
242 > )
243   {
244          static struct psize {char n[12]; float w,h;} p[] = {
245 <                "envelope", 4.12, 9.5,
246 <                "executive", 7.25, 10.5,
247 <                "letter", 8.5, 11.,
248 <                "lettersmall", 7.68, 10.16,
249 <                "legal", 8.5, 14.,
250 <                "monarch", 3.87, 7.5,
251 <                "statement", 5.5, 8.5,
252 <                "tabloid", 11., 17.,
253 <                "A3", 11.69, 16.54,
254 <                "A4", 8.27, 11.69,
255 <                "A4small", 7.47, 10.85,
256 <                "A5", 6.00, 8.27,
257 <                "A6", 4.13, 6.00,
258 <                "B4", 10.12, 14.33,
259 <                "B5", 7.17, 10.12,
260 <                "C5", 6.38, 9.01,
261 <                "C6", 4.49, 6.38,
262 <                "DL", 4.33, 8.66,
263 <                "hagaki", 3.94, 5.83,
264 <                "" };
245 >                {"envelope", 4.12, 9.5},
246 >                {"executive", 7.25, 10.5},
247 >                {"letter", 8.5, 11.},
248 >                {"lettersmall", 7.68, 10.16},
249 >                {"legal", 8.5, 14.},
250 >                {"monarch", 3.87, 7.5},
251 >                {"statement", 5.5, 8.5},
252 >                {"tabloid", 11., 17.},
253 >                {"A3", 11.69, 16.54},
254 >                {"A4", 8.27, 11.69},
255 >                {"A4small", 7.47, 10.85},
256 >                {"A5", 6.00, 8.27},
257 >                {"A6", 4.13, 6.00},
258 >                {"B4", 10.12, 14.33},
259 >                {"B5", 7.17, 10.12},
260 >                {"C5", 6.38, 9.01},
261 >                {"C6", 4.49, 6.38},
262 >                {"DL", 4.33, 8.66},
263 >                {"hagaki", 3.94, 5.83},
264 >                {"",0.0,0.0} };
265          register struct psize   *pp;
266          register char   *s = ps;
267          double  d;
# Line 264 | Line 274 | char   *ps;
274                  height = atof(++s);
275                  width *= d;
276                  height *= d;
277 <                if (width >= 1. & height >= 1.)
277 >                if ((width >= 1.) & (height >= 1.))
278                          return;
279          } else                          /* check for match to standard size */
280                  for (pp = p; pp->n[0]; pp++)
# Line 283 | Line 293 | char   *ps;
293   }
294  
295  
296 < quiterr(err)            /* print message and exit */
297 < char  *err;
296 > static void
297 > quiterr(                /* print message and exit */
298 >        char  *err
299 > )
300   {
301          if (err != NULL) {
302                  fprintf(stderr, "%s: %s\n", progname, err);
# Line 294 | Line 306 | char  *err;
306   }
307  
308  
309 < PSheader(ac, av)                /* print PostScript header */
310 < int  ac;
311 < char  **av;
309 > static void
310 > PSheader(               /* print PostScript header */
311 >        int  ac,
312 >        char  **av
313 > )
314   {
315          char  *rstr;
316          int  landscape, rotate, n;
# Line 305 | Line 319 | char  **av;
319                                          /* EPS comments */
320          puts("%!PS-Adobe-2.0 EPSF-2.0");
321          printf("%%%%Title: "); printargs(ac, av, stdout);
322 <        printf("%%%%Creator: %s\n", SCCSid);
322 >        printf("%%%%Creator: %s\n", progname);
323          printf("%%%%Pages: %d\n", ncopies);
324 <        if (landscape = xmax > pixaspect*ymax)
324 >        if ( (landscape = xmax > pixaspect*ymax) )
325                  puts("%%Orientation: Landscape");
326          else
327                  puts("%%Orientation: Portrait");
328 <        if (rotate = PWIDTH > PHEIGHT ^ landscape) {
328 >        if ( (rotate = (PWIDTH > PHEIGHT) ^ landscape) ) {
329                  pwidth = PHEIGHT;
330                  pheight = PWIDTH;
331          } else {
332                  pwidth = PWIDTH;
333                  pheight = PHEIGHT;
334          }
335 <        if (dpi > 100 && pixaspect >= 0.99 & pixaspect <= 1.01)
335 >        if (dpi > 100 && (pixaspect >= 0.99) & (pixaspect <= 1.01))
336                  if (pheight/pwidth > ymax/xmax) {
337                          n = pwidth*dpi/xmax;    /* floor */
338                          iwidth = n > 0 ? (double)(n*xmax)/dpi : pwidth;
# Line 393 | Line 407 | char  **av;
407   }
408  
409  
410 < PStrailer()                     /* print PostScript trailer */
410 > static void
411 > PStrailer(void)                 /* print PostScript trailer */
412   {
413          puts("%%Trailer");
414          if (ncopies > 1)
# Line 405 | Line 420 | PStrailer()                    /* print PostScript trailer */
420   }
421  
422  
423 < PSprocdef(nam)                  /* define PS procedure to read image */
424 < char  *nam;
423 > static void
424 > PSprocdef(                      /* define PS procedure to read image */
425 >        char  *nam
426 > )
427   {
428          short  itab[128];
429          register int  i;
# Line 414 | Line 431 | char  *nam;
431          for (i = 0; i < 128; i++)       /* clear */
432                  itab[i] = -1;
433          for (i = 1; i < 63; i++)        /* assign greys */
434 <                itab[code[i]] = 256.0*pow((i+.5)/64.0, CODE6GAM/devgam);
435 <        itab[code[0]] = 0;              /* black is black */
436 <        itab[code[63]] = 255;           /* and white is white */
434 >                itab[(int)code[i]] = 256.0*pow((i+.5)/64.0, CODE6GAM/devgam);
435 >        itab[(int)code[0]] = 0;         /* black is black */
436 >        itab[(int)code[63]] = 255;              /* and white is white */
437          printf("/codetab [");
438          for (i = 0; i < 128; i++) {
439                  if (!(i & 0xf))
# Line 445 | Line 462 | char  *nam;
462   }
463  
464  
465 < ra2ps()                         /* convert Radiance scanlines to 6-bit */
465 > static void
466 > ra2ps(void)                             /* convert Radiance scanlines to 6-bit */
467   {
468          register COLR   *scanin;
469          int     y;
# Line 474 | Line 492 | ra2ps()                                /* convert Radiance scanlines to 6-bit */
492          }
493          putchar('\n');
494                                                  /* free scanline */
495 <        free((char *)scanin);
495 >        free((void *)scanin);
496   }
497  
498  
499 < int
500 < Aputprim(scn, pri)              /* put out hex ASCII primary from scanline */
501 < COLR    *scn;
502 < int     pri;
499 > static void
500 > Aputprim(               /* put out hex ASCII primary from scanline */
501 >        COLR    *scn,
502 >        int     pri
503 > )
504   {
505          static char     hexdigit[] = "0123456789ABCDEF";
506          static int      col = 0;
# Line 503 | Line 522 | int    pri;
522   }
523  
524  
525 < int
526 < Bputprim(scn, pri)              /* put out binary primary from scanline */
527 < COLR    *scn;
528 < int     pri;
525 > static void
526 > Bputprim(               /* put out binary primary from scanline */
527 >        COLR    *scn,
528 >        int     pri
529 > )
530   {
531          register int    x, c;
532  
# Line 521 | Line 541 | int    pri;
541   }
542  
543  
544 < int
545 < Cputprim(scn, pri)              /* put out compressed primary from scanline */
546 < COLR    *scn;
547 < int     pri;
544 > static void
545 > Cputprim(               /* put out compressed primary from scanline */
546 >        COLR    *scn,
547 >        int     pri
548 > )
549   {
550          register int    c;
551          register int    x;
# Line 550 | Line 571 | int    pri;
571   }
572  
573  
574 < putrle(cnt, cod)                /* put out cnt of cod */
575 < register int    cnt, cod;
574 > static void
575 > putrle(         /* put out cnt of cod */
576 >        register int    cnt,
577 >        register int    cod
578 > )
579   {
580          static int      col = 0;
581  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines