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.33 by greg, Fri Oct 4 01:53:45 2024 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  
11 #include  <stdio.h>
8   #include  <math.h>
9   #include  <ctype.h>
10 < #ifdef MSDOS
11 < #include  <fcntl.h>
12 < #endif
10 >
11 > #include  "platform.h"
12 > #include  "paths.h"
13 > #include  "rtio.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(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];
82 >        char  fmt[MAXFMTLEN];
83  
84 <        if (isformat(s)) {
85 <                formatval(fmt, s);
86 <                wrongformat = strcmp(fmt, COLRFMT);
77 <        } else if (isaspect(s))
84 >        if (formatval(fmt, s))
85 >                wrongformat = strcmp(fmt, COLRFMT) && strcmp(fmt, SPECFMT);
86 >        else if (isaspect(s))
87                  pixaspect *= aspectval(s);
88 +        else if (isncomp(s))
89 +                NCSAMP = ncompval(s);
90 +        else if (iswlsplit(s))
91 +                wlsplitval(WLPART, s);
92          return(0);
93   }
94  
95 <
96 < main(argc, argv)
84 < int  argc;
85 < char  *argv[];
95 > int
96 > main(int  argc, char  *argv[])
97   {
98          int  i;
99          double  d;
# Line 160 | Line 171 | char  *argv[];
171                                  progname, argv[i+1]);
172                  exit(1);
173          }
174 < #ifdef MSDOS
164 <        setmode(fileno(stdin), O_BINARY);
165 < #endif
174 >        SET_FILE_BINARY(stdin);
175                                  /* get our header */
176          getheader(stdin, headline, NULL);
177          if (wrongformat || fgetresolu(&xmax, &ymax, stdin) < 0)
# Line 189 | Line 198 | userr:
198   }
199  
200  
201 < double
202 < unit2inch(s)            /* determine unit */
203 < register char   *s;
201 > static double
202 > unit2inch(              /* determine unit */
203 >        char    *s
204 > )
205   {
206          static struct unit {char n; float f;} u[] = {
207 <                'i', 1.,
208 <                'm', 1./25.4,
209 <                'c', 1./2.54,
210 <                '\0' };
211 <        register struct unit    *up;
207 >                {'i', 1.},
208 >                {'m', 1./25.4},
209 >                {'c', 1./2.54},
210 >                {'\0',0} };
211 >        struct unit     *up;
212  
213          while (*s && !isalpha(*s))
214                  s++;
# Line 209 | Line 219 | register char  *s;
219   }
220  
221  
222 < int
223 < matchid(name, id)       /* see if name matches id (case insensitive) */
224 < char    *name;
225 < register char   *id;
222 > static int
223 > matchid(        /* see if name matches id (case insensitive) */
224 >        char    *name,
225 >        char    *id
226 > )
227   {
228 <        register char   *s = name;
228 >        char    *s = name;
229  
230          while (*s) {
231                  if (isalpha(*s)) {
# Line 228 | Line 239 | register char  *id;
239   }
240  
241  
242 < parsepaper(ps)          /* determine paper size from name */
243 < char    *ps;
242 > static void
243 > parsepaper(             /* determine paper size from name */
244 >        char    *ps
245 > )
246   {
247          static struct psize {char n[12]; float w,h;} p[] = {
248 <                "envelope", 4.12, 9.5,
249 <                "executive", 7.25, 10.5,
250 <                "letter", 8.5, 11.,
251 <                "lettersmall", 7.68, 10.16,
252 <                "legal", 8.5, 14.,
253 <                "monarch", 3.87, 7.5,
254 <                "statement", 5.5, 8.5,
255 <                "tabloid", 11., 17.,
256 <                "A3", 11.69, 16.54,
257 <                "A4", 8.27, 11.69,
258 <                "A4small", 7.47, 10.85,
259 <                "A5", 6.00, 8.27,
260 <                "A6", 4.13, 6.00,
261 <                "B4", 10.12, 14.33,
262 <                "B5", 7.17, 10.12,
263 <                "C5", 6.38, 9.01,
264 <                "C6", 4.49, 6.38,
265 <                "DL", 4.33, 8.66,
266 <                "hagaki", 3.94, 5.83,
267 <                "" };
268 <        register struct psize   *pp;
269 <        register char   *s = ps;
248 >                {"envelope", 4.12, 9.5},
249 >                {"executive", 7.25, 10.5},
250 >                {"letter", 8.5, 11.},
251 >                {"lettersmall", 7.68, 10.16},
252 >                {"legal", 8.5, 14.},
253 >                {"monarch", 3.87, 7.5},
254 >                {"statement", 5.5, 8.5},
255 >                {"tabloid", 11., 17.},
256 >                {"A3", 11.69, 16.54},
257 >                {"A4", 8.27, 11.69},
258 >                {"A4small", 7.47, 10.85},
259 >                {"A5", 6.00, 8.27},
260 >                {"A6", 4.13, 6.00},
261 >                {"B4", 10.12, 14.33},
262 >                {"B5", 7.17, 10.12},
263 >                {"C5", 6.38, 9.01},
264 >                {"C6", 4.49, 6.38},
265 >                {"DL", 4.33, 8.66},
266 >                {"hagaki", 3.94, 5.83},
267 >                {"",0.0,0.0} };
268 >        struct psize    *pp;
269 >        char    *s = ps;
270          double  d;
271  
272          if (isdigit(*s)) {              /* check for WWxHH specification */
# Line 264 | Line 277 | char   *ps;
277                  height = atof(++s);
278                  width *= d;
279                  height *= d;
280 <                if (width >= 1. & height >= 1.)
280 >                if ((width >= 1.) & (height >= 1.))
281                          return;
282          } else                          /* check for match to standard size */
283                  for (pp = p; pp->n[0]; pp++)
# Line 283 | Line 296 | char   *ps;
296   }
297  
298  
299 < quiterr(err)            /* print message and exit */
300 < char  *err;
299 > static void
300 > quiterr(                /* print message and exit */
301 >        char  *err
302 > )
303   {
304          if (err != NULL) {
305                  fprintf(stderr, "%s: %s\n", progname, err);
# Line 294 | Line 309 | char  *err;
309   }
310  
311  
312 < PSheader(ac, av)                /* print PostScript header */
313 < int  ac;
314 < char  **av;
312 > static void
313 > PSheader(               /* print PostScript header */
314 >        int  ac,
315 >        char  **av
316 > )
317   {
318          char  *rstr;
319          int  landscape, rotate, n;
# Line 305 | Line 322 | char  **av;
322                                          /* EPS comments */
323          puts("%!PS-Adobe-2.0 EPSF-2.0");
324          printf("%%%%Title: "); printargs(ac, av, stdout);
325 <        printf("%%%%Creator: %s\n", SCCSid);
325 >        printf("%%%%Creator: %s\n", progname);
326          printf("%%%%Pages: %d\n", ncopies);
327 <        if (landscape = xmax > pixaspect*ymax)
327 >        if ( (landscape = xmax > pixaspect*ymax) )
328                  puts("%%Orientation: Landscape");
329          else
330                  puts("%%Orientation: Portrait");
331 <        if (rotate = PWIDTH > PHEIGHT ^ landscape) {
331 >        if ( (rotate = (PWIDTH > PHEIGHT) ^ landscape) ) {
332                  pwidth = PHEIGHT;
333                  pheight = PWIDTH;
334          } else {
335                  pwidth = PWIDTH;
336                  pheight = PHEIGHT;
337          }
338 <        if (dpi > 100 && pixaspect >= 0.99 & pixaspect <= 1.01)
338 >        if (dpi > 100 && (pixaspect >= 0.99) & (pixaspect <= 1.01))
339                  if (pheight/pwidth > ymax/xmax) {
340                          n = pwidth*dpi/xmax;    /* floor */
341                          iwidth = n > 0 ? (double)(n*xmax)/dpi : pwidth;
# Line 393 | Line 410 | char  **av;
410   }
411  
412  
413 < PStrailer()                     /* print PostScript trailer */
413 > static void
414 > PStrailer(void)                 /* print PostScript trailer */
415   {
416          puts("%%Trailer");
417          if (ncopies > 1)
# Line 405 | Line 423 | PStrailer()                    /* print PostScript trailer */
423   }
424  
425  
426 < PSprocdef(nam)                  /* define PS procedure to read image */
427 < char  *nam;
426 > static void
427 > PSprocdef(                      /* define PS procedure to read image */
428 >        char  *nam
429 > )
430   {
431          short  itab[128];
432 <        register int  i;
432 >        int  i;
433                                  /* assign code values */
434          for (i = 0; i < 128; i++)       /* clear */
435                  itab[i] = -1;
436          for (i = 1; i < 63; i++)        /* assign greys */
437 <                itab[code[i]] = 256.0*pow((i+.5)/64.0, CODE6GAM/devgam);
438 <        itab[code[0]] = 0;              /* black is black */
439 <        itab[code[63]] = 255;           /* and white is white */
437 >                itab[(int)code[i]] = 256.0*pow((i+.5)/64.0, CODE6GAM/devgam);
438 >        itab[(int)code[0]] = 0;         /* black is black */
439 >        itab[(int)code[63]] = 255;              /* and white is white */
440          printf("/codetab [");
441          for (i = 0; i < 128; i++) {
442                  if (!(i & 0xf))
# Line 445 | Line 465 | char  *nam;
465   }
466  
467  
468 < ra2ps()                         /* convert Radiance scanlines to 6-bit */
468 > static void
469 > ra2ps(void)                             /* convert Radiance scanlines to 6-bit */
470   {
471 <        register COLR   *scanin;
471 >        COLR    *scanin;
472          int     y;
473                                                  /* allocate scanline */
474          scanin = (COLR *)malloc(xmax*sizeof(COLR));
# Line 455 | Line 476 | ra2ps()                                /* convert Radiance scanlines to 6-bit */
476                  quiterr("out of memory in ra2ps");
477                                                  /* convert image */
478          for (y = ymax-1; y >= 0; y--) {
479 <                if (freadcolrs(scanin, xmax, stdin) < 0)
479 >                if (fread2colrs(scanin, xmax, stdin, NCSAMP, WLPART) < 0)
480                          quiterr("error reading Radiance picture");
481 <                if (putprim == Cputprim || devgam != 1.) {
481 >                if ((putprim == Cputprim) | (devgam != 1.)) {
482                          if (bradj)                      /* adjust exposure */
483                                  shiftcolrs(scanin, xmax, bradj);
484                          colrs_gambs(scanin, xmax);      /* gamma compression */
# Line 474 | Line 495 | ra2ps()                                /* convert Radiance scanlines to 6-bit */
495          }
496          putchar('\n');
497                                                  /* free scanline */
498 <        free((char *)scanin);
498 >        free((void *)scanin);
499   }
500  
501  
502 < int
503 < Aputprim(scn, pri)              /* put out hex ASCII primary from scanline */
504 < COLR    *scn;
505 < int     pri;
502 > static void
503 > Aputprim(               /* put out hex ASCII primary from scanline */
504 >        COLR    *scn,
505 >        int     pri
506 > )
507   {
508          static char     hexdigit[] = "0123456789ABCDEF";
509          static int      col = 0;
510 <        register int    x, c;
510 >        int     x, c;
511  
512          for (x = 0; x < xmax; x++) {
513                  if (pri == GRY)
# Line 503 | Line 525 | int    pri;
525   }
526  
527  
528 < int
529 < Bputprim(scn, pri)              /* put out binary primary from scanline */
530 < COLR    *scn;
531 < int     pri;
528 > static void
529 > Bputprim(               /* put out binary primary from scanline */
530 >        COLR    *scn,
531 >        int     pri
532 > )
533   {
534 <        register int    x, c;
534 >        int     x, c;
535  
536          for (x = 0; x < xmax; x++) {
537                  if (pri == GRY)
# Line 521 | Line 544 | int    pri;
544   }
545  
546  
547 < int
548 < Cputprim(scn, pri)              /* put out compressed primary from scanline */
549 < COLR    *scn;
550 < int     pri;
547 > static void
548 > Cputprim(               /* put out compressed primary from scanline */
549 >        COLR    *scn,
550 >        int     pri
551 > )
552   {
553 <        register int    c;
554 <        register int    x;
553 >        int     c;
554 >        int     x;
555          int     lastc, cnt;
556  
557          lastc = -1; cnt = 0;
# Line 550 | Line 574 | int    pri;
574   }
575  
576  
577 < putrle(cnt, cod)                /* put out cnt of cod */
578 < register int    cnt, cod;
577 > static void
578 > putrle(         /* put out cnt of cod */
579 >        int     cnt,
580 >        int     cod
581 > )
582   {
583          static int      col = 0;
584  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines