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.27 by schorsch, Fri Jan 2 12:47:01 2004 UTC vs.
Revision 2.35 by greg, Sat Jun 7 05:09:46 2025 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   *  Radiance picture to PostScript file translator -- one way!
6   */
7  
8 #include  <stdio.h>
9 #include  <string.h>
8   #include  <math.h>
9   #include  <ctype.h>
10  
11   #include  "platform.h"
12 + #include  "rtio.h"
13   #include  "color.h"
14   #include  "resolu.h"
15  
# Line 51 | Line 50 | int  docolor = 1;                      /* produce color image? */
50   int  bradj = 0;                         /* brightness adjustment */
51   int  ncopies = 1;                       /* number of copies */
52  
53 < extern int      Aputprim(), Bputprim(), Cputprim();
53 > int  xmax, ymax;                        /* input image dimensions */
54  
55 < int  (*putprim)() = Aputprim;           /* function for writing scanline */
55 > typedef void putprimf_t(COLR *scn, int pri);
56  
57 < char  *progname;
57 > static gethfunc headline;
58 > static putprimf_t Aputprim, Bputprim, Cputprim;
59  
60 < int  xmax, ymax;                        /* input image dimensions */
60 > static double unit2inch(char *s);
61 > static int matchid(char *name, char *id);
62 > static void parsepaper(char *ps);
63 > static void quiterr(char *err);
64 > static void PSheader(int ac, char **av);
65 > static void PStrailer(void);
66 > static void PSprocdef(char *nam);
67 > static void ra2ps(void);
68 > static void putrle(int cnt, int cod);
69  
62 extern double   unit2inch();
70  
71 < static gethfunc headline;
71 > putprimf_t *putprim = Aputprim;         /* function for writing scanline */
72  
73  
74   static int
# Line 70 | Line 77 | headline(              /* check header line */
77          void    *p
78   )
79   {
80 <        char  fmt[32];
80 >        char  fmt[MAXFMTLEN];
81  
82 <        if (isformat(s)) {
83 <                formatval(fmt, s);
84 <                wrongformat = strcmp(fmt, COLRFMT);
78 <        } else if (isaspect(s))
82 >        if (formatval(fmt, s))
83 >                wrongformat = strcmp(fmt, COLRFMT) && strcmp(fmt, SPECFMT);
84 >        else if (isaspect(s))
85                  pixaspect *= aspectval(s);
86 +        else if (isncomp(s))
87 +                NCSAMP = ncompval(s);
88 +        else if (iswlsplit(s))
89 +                wlsplitval(WLPART, s);
90          return(0);
91   }
92  
93 <
94 < main(argc, argv)
85 < int  argc;
86 < char  *argv[];
93 > int
94 > main(int  argc, char  *argv[])
95   {
96          int  i;
97          double  d;
98          
99 <        progname = argv[0];
99 >        fixargv0(argv[0]);              /* assigns progname */
100  
101          for (i = 1; i < argc; i++)
102                  if (argv[i][0] == '-')
# Line 188 | Line 196 | userr:
196   }
197  
198  
199 < double
200 < unit2inch(s)            /* determine unit */
201 < register char   *s;
199 > static double
200 > unit2inch(              /* determine unit */
201 >        char    *s
202 > )
203   {
204          static struct unit {char n; float f;} u[] = {
205                  {'i', 1.},
206                  {'m', 1./25.4},
207                  {'c', 1./2.54},
208                  {'\0',0} };
209 <        register struct unit    *up;
209 >        struct unit     *up;
210  
211          while (*s && !isalpha(*s))
212                  s++;
# Line 208 | Line 217 | register char  *s;
217   }
218  
219  
220 < int
221 < matchid(name, id)       /* see if name matches id (case insensitive) */
222 < char    *name;
223 < register char   *id;
220 > static int
221 > matchid(        /* see if name matches id (case insensitive) */
222 >        char    *name,
223 >        char    *id
224 > )
225   {
226 <        register char   *s = name;
226 >        char    *s = name;
227  
228          while (*s) {
229                  if (isalpha(*s)) {
# Line 227 | Line 237 | register char  *id;
237   }
238  
239  
240 < parsepaper(ps)          /* determine paper size from name */
241 < char    *ps;
240 > static void
241 > parsepaper(             /* determine paper size from name */
242 >        char    *ps
243 > )
244   {
245          static struct psize {char n[12]; float w,h;} p[] = {
246                  {"envelope", 4.12, 9.5},
# Line 251 | Line 263 | char   *ps;
263                  {"DL", 4.33, 8.66},
264                  {"hagaki", 3.94, 5.83},
265                  {"",0.0,0.0} };
266 <        register struct psize   *pp;
267 <        register char   *s = ps;
266 >        struct psize    *pp;
267 >        char    *s = ps;
268          double  d;
269  
270          if (isdigit(*s)) {              /* check for WWxHH specification */
# Line 282 | Line 294 | char   *ps;
294   }
295  
296  
297 < quiterr(err)            /* print message and exit */
298 < char  *err;
297 > static void
298 > quiterr(                /* print message and exit */
299 >        char  *err
300 > )
301   {
302          if (err != NULL) {
303                  fprintf(stderr, "%s: %s\n", progname, err);
# Line 293 | Line 307 | char  *err;
307   }
308  
309  
310 < PSheader(ac, av)                /* print PostScript header */
311 < int  ac;
312 < char  **av;
310 > static void
311 > PSheader(               /* print PostScript header */
312 >        int  ac,
313 >        char  **av
314 > )
315   {
316          char  *rstr;
317          int  landscape, rotate, n;
# Line 392 | Line 408 | char  **av;
408   }
409  
410  
411 < PStrailer()                     /* print PostScript trailer */
411 > static void
412 > PStrailer(void)                 /* print PostScript trailer */
413   {
414          puts("%%Trailer");
415          if (ncopies > 1)
# Line 404 | Line 421 | PStrailer()                    /* print PostScript trailer */
421   }
422  
423  
424 < PSprocdef(nam)                  /* define PS procedure to read image */
425 < char  *nam;
424 > static void
425 > PSprocdef(                      /* define PS procedure to read image */
426 >        char  *nam
427 > )
428   {
429          short  itab[128];
430 <        register int  i;
430 >        int  i;
431                                  /* assign code values */
432          for (i = 0; i < 128; i++)       /* clear */
433                  itab[i] = -1;
434          for (i = 1; i < 63; i++)        /* assign greys */
435 <                itab[code[i]] = 256.0*pow((i+.5)/64.0, CODE6GAM/devgam);
436 <        itab[code[0]] = 0;              /* black is black */
437 <        itab[code[63]] = 255;           /* and white is white */
435 >                itab[(int)code[i]] = 256.0*pow((i+.5)/64.0, CODE6GAM/devgam);
436 >        itab[(int)code[0]] = 0;         /* black is black */
437 >        itab[(int)code[63]] = 255;              /* and white is white */
438          printf("/codetab [");
439          for (i = 0; i < 128; i++) {
440                  if (!(i & 0xf))
# Line 444 | Line 463 | char  *nam;
463   }
464  
465  
466 < ra2ps()                         /* convert Radiance scanlines to 6-bit */
466 > static void
467 > ra2ps(void)                             /* convert Radiance scanlines to 6-bit */
468   {
469 <        register COLR   *scanin;
469 >        COLR    *scanin;
470          int     y;
471                                                  /* allocate scanline */
472          scanin = (COLR *)malloc(xmax*sizeof(COLR));
# Line 454 | Line 474 | ra2ps()                                /* convert Radiance scanlines to 6-bit */
474                  quiterr("out of memory in ra2ps");
475                                                  /* convert image */
476          for (y = ymax-1; y >= 0; y--) {
477 <                if (freadcolrs(scanin, xmax, stdin) < 0)
477 >                if (fread2colrs(scanin, xmax, stdin, NCSAMP, WLPART) < 0)
478                          quiterr("error reading Radiance picture");
479 <                if (putprim == Cputprim || devgam != 1.) {
479 >                if ((putprim == Cputprim) | (devgam != 1.)) {
480                          if (bradj)                      /* adjust exposure */
481                                  shiftcolrs(scanin, xmax, bradj);
482                          colrs_gambs(scanin, xmax);      /* gamma compression */
# Line 477 | Line 497 | ra2ps()                                /* convert Radiance scanlines to 6-bit */
497   }
498  
499  
500 < int
501 < Aputprim(scn, pri)              /* put out hex ASCII primary from scanline */
502 < COLR    *scn;
503 < int     pri;
500 > static void
501 > Aputprim(               /* put out hex ASCII primary from scanline */
502 >        COLR    *scn,
503 >        int     pri
504 > )
505   {
506          static char     hexdigit[] = "0123456789ABCDEF";
507          static int      col = 0;
508 <        register int    x, c;
508 >        int     x, c;
509  
510          for (x = 0; x < xmax; x++) {
511                  if (pri == GRY)
# Line 502 | Line 523 | int    pri;
523   }
524  
525  
526 < int
527 < Bputprim(scn, pri)              /* put out binary primary from scanline */
528 < COLR    *scn;
529 < int     pri;
526 > static void
527 > Bputprim(               /* put out binary primary from scanline */
528 >        COLR    *scn,
529 >        int     pri
530 > )
531   {
532 <        register int    x, c;
532 >        int     x, c;
533  
534          for (x = 0; x < xmax; x++) {
535                  if (pri == GRY)
# Line 520 | Line 542 | int    pri;
542   }
543  
544  
545 < int
546 < Cputprim(scn, pri)              /* put out compressed primary from scanline */
547 < COLR    *scn;
548 < int     pri;
545 > static void
546 > Cputprim(               /* put out compressed primary from scanline */
547 >        COLR    *scn,
548 >        int     pri
549 > )
550   {
551 <        register int    c;
552 <        register int    x;
551 >        int     c;
552 >        int     x;
553          int     lastc, cnt;
554  
555          lastc = -1; cnt = 0;
# Line 549 | Line 572 | int    pri;
572   }
573  
574  
575 < putrle(cnt, cod)                /* put out cnt of cod */
576 < register int    cnt, cod;
575 > static void
576 > putrle(         /* put out cnt of cod */
577 >        int     cnt,
578 >        int     cod
579 > )
580   {
581          static int      col = 0;
582  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines