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.33 by greg, Fri Oct 4 01:53:45 2024 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  "paths.h"
13 + #include  "rtio.h"
14   #include  "color.h"
15   #include  "resolu.h"
16  
# Line 51 | 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();
55
56 int  (*putprim)() = Aputprim;           /* function for writing scanline */
57
54   char  *progname;
59
55   int  xmax, ymax;                        /* input image dimensions */
56  
57 < extern double   unit2inch();
57 > typedef void putprimf_t(COLR *scn, int pri);
58  
59   static gethfunc headline;
60 + static putprimf_t Aputprim, Bputprim, Cputprim;
61  
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  
72 +
73 + putprimf_t *putprim = Aputprim;         /* function for writing scanline */
74 +
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);
78 <        } 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)
85 < int  argc;
86 < char  *argv[];
95 > int
96 > main(int  argc, char  *argv[])
97   {
98          int  i;
99          double  d;
# Line 188 | 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',0} };
211 <        register struct unit    *up;
211 >        struct unit     *up;
212  
213          while (*s && !isalpha(*s))
214                  s++;
# Line 208 | 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 227 | 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},
# Line 251 | Line 265 | char   *ps;
265                  {"DL", 4.33, 8.66},
266                  {"hagaki", 3.94, 5.83},
267                  {"",0.0,0.0} };
268 <        register struct psize   *pp;
269 <        register char   *s = ps;
268 >        struct psize    *pp;
269 >        char    *s = ps;
270          double  d;
271  
272          if (isdigit(*s)) {              /* check for WWxHH specification */
# Line 282 | 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 293 | 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 392 | 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 404 | 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 444 | 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 454 | 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 477 | Line 499 | ra2ps()                                /* convert Radiance scanlines to 6-bit */
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 502 | 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 520 | 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 549 | 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