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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines