ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pcompos.c
(Generate patch)

Comparing ray/src/px/pcompos.c (file contents):
Revision 2.18 by greg, Sun Feb 27 10:17:04 1994 UTC vs.
Revision 2.35 by greg, Tue Feb 2 18:02:32 2016 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1993 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  pcompos.c - program to composite pictures.
6   *
# Line 11 | Line 8 | static char SCCSid[] = "$SunId$ LBL";
8   */
9  
10   #include  <stdio.h>
14
11   #include  <math.h>
12 + #include  <time.h>
13 + #include  <string.h>
14  
15 < #ifdef MSDOS
18 < #include  <fcntl.h>
19 < #endif
15 > #include "copyright.h"
16  
17 + #include  "platform.h"
18 + #include  "paths.h"
19 + #include  "rterror.h"
20   #include  "color.h"
22
21   #include  "resolu.h"
22  
23 < #define  MAXFILE        64
23 > #define  MAXFILE        1024
24  
25   #define  HASMIN         1
26   #define  HASMAX         2
# Line 42 | Line 40 | int  labelht = 24;                     /* label height */
40  
41   int  checkthresh = 0;                   /* check threshold value */
42  
43 + char  StandardInput[] = "<stdin>";
44   char  Command[] = "<Command>";
45   char  Label[] = "<Label>";
46  
# Line 53 | Line 52 | struct {
52          int  xres, yres;                /* picture size */
53          int  xloc, yloc;                /* anchor point */
54          int  flags;                     /* HASMIN, HASMAX */
55 <        COLR  thmin, thmax;             /* thresholds */
55 >        double  thmin, thmax;           /* thresholds */
56   } input[MAXFILE];               /* our input files */
57  
58   int  nfile;                     /* number of files */
59  
60 + int  echoheader = 1;
61 + char  ourfmt[LPICFMT+1] = PICFMT;
62   int  wrongformat = 0;
63  
63 FILE  *popen(), *lblopen();
64  
65 < extern char  *malloc();
65 > static gethfunc headline;
66 > static void compos(void);
67 > static int cmpcolr(COLR  c1, double lv2);
68 > static FILE * lblopen(char  *s, int  *xp, int  *yp);
69  
70  
71 < tabputs(s)                      /* print line preceded by a tab */
72 < char  *s;
71 >
72 > static int
73 > headline(                       /* print line preceded by a tab */
74 >        char    *s,
75 >        void    *p
76 > )
77   {
78          char  fmt[32];
79  
80          if (isheadid(s))
81 <                return;
82 <        if (formatval(fmt, s))
83 <                wrongformat = strcmp(fmt, COLRFMT);
84 <        else {
81 >                return(0);
82 >        if (formatval(fmt, s)) {
83 >                if (globmatch(ourfmt, fmt)) {
84 >                        wrongformat = 0;
85 >                        strcpy(ourfmt, fmt);
86 >                } else
87 >                        wrongformat = 1;
88 >        } else if (echoheader) {
89                  putc('\t', stdout);
90                  fputs(s, stdout);
91          }
92 +        return(0);
93   }
94  
95  
96 < main(argc, argv)
97 < int  argc;
98 < char  *argv[];
96 > int
97 > main(
98 >        int  argc,
99 >        char  *argv[]
100 > )
101   {
102          int  ncolumns = 0;
103          int  autolabel = 0;
# Line 91 | Line 105 | char  *argv[];
105          int  xsgn, ysgn;
106          char  *thislabel;
107          int  an;
108 < #ifdef MSDOS
109 <        extern int  _fmode;
110 <        _fmode = O_BINARY;
97 <        setmode(fileno(stdin), O_BINARY);
98 <        setmode(fileno(stdout), O_BINARY);
99 < #endif
108 >        SET_DEFAULT_BINARY();
109 >        SET_FILE_BINARY(stdin);
110 >        SET_FILE_BINARY(stdout);
111          progname = argv[0];
112  
113          for (an = 1; an < argc && argv[an][0] == '-'; an++)
114                  switch (argv[an][1]) {
115 +                case 'h':
116 +                        echoheader = !echoheader;
117 +                        break;
118                  case 'x':
119                          xsiz = atoi(argv[++an]);
120                          break;
# Line 145 | Line 159 | char  *argv[];
159                  }
160   dofiles:
161          newheader("RADIANCE", stdout);
162 +        fputnow(stdout);
163          for (nfile = 0; an < argc; nfile++) {
164                  if (nfile >= MAXFILE)
165                          goto toomany;
# Line 158 | Line 173 | dofiles:
173                                  checkthresh = 1;
174                                  if (argv[an][0] == '-') {
175                                          input[nfile].flags |= HASMIN;
176 <                                        setcolr(input[nfile].thmin,
162 <                                                        atof(argv[an+1]),
163 <                                                        atof(argv[an+1]),
164 <                                                        atof(argv[an+1]));
176 >                                        input[nfile].thmin = atof(argv[an+1]);
177                                  } else if (argv[an][0] == '+') {
178                                          input[nfile].flags |= HASMAX;
179 <                                        setcolr(input[nfile].thmax,
168 <                                                        atof(argv[an+1]),
169 <                                                        atof(argv[an+1]),
170 <                                                        atof(argv[an+1]));
179 >                                        input[nfile].thmax = atof(argv[an+1]);
180                                  } else
181                                          goto userr;
182                                  an++;
# Line 202 | Line 211 | getfile:
211                  if (autolabel && thislabel == NULL)
212                          thislabel = argv[an];
213                  if (!strcmp(argv[an], "-")) {
214 <                        input[nfile].name = "<stdin>";
214 >                        input[nfile].name = StandardInput;
215                          input[nfile].fp = stdin;
216                  } else {
217                          if (argv[an][0] == '!') {
# Line 219 | Line 228 | getfile:
228                  }
229                  an++;
230                                                  /* get header */
231 <                printf("%s:\n", input[nfile].name);
232 <                getheader(input[nfile].fp, tabputs, NULL);
231 >                if (echoheader)
232 >                        printf("%s:\n", input[nfile].name);
233 >                getheader(input[nfile].fp, headline, NULL);
234                  if (wrongformat) {
235 <                        fprintf(stderr, "%s: not a Radiance picture\n",
235 >                        fprintf(stderr, "%s: incompatible input format\n",
236                                          input[nfile].name);
237                          quit(1);
238                  }
# Line 233 | Line 243 | getfile:
243                                          input[nfile].name);
244                          quit(1);
245                  }
246 <                if (ncolumns > 0) {
247 <                        if (curcol >= ncolumns) {
246 >                if (ncolumns) {
247 >                        if (curcol >= abs(ncolumns)) {
248                                  cury = ymax + spacing;
249                                  curx = x0;
250                                  curcol = 0;
# Line 287 | Line 297 | getfile:
297                  ysiz = ymax;
298          else if (ysiz > ymax)
299                  ymax = ysiz;
300 +        if (ncolumns < 0) {             /* reverse rows if requested */
301 +                int     i = nfile;
302 +                while (i--)
303 +                        input[i].yloc = ymax - input[i].yres - input[i].yloc;
304 +        }
305                                          /* add new header info. */
306          printargs(argc, argv, stdout);
307 <        fputformat(COLRFMT, stdout);
307 >        if (strcmp(ourfmt, PICFMT))
308 >                fputformat(ourfmt, stdout);     /* print format if known */
309          putchar('\n');
310          fprtresolu(xsiz, ysiz, stdout);
311  
# Line 298 | Line 314 | getfile:
314          quit(0);
315   userr:
316          fprintf(stderr,
317 <        "Usage: %s [-x xr][-y yr][-b r g b][-a n][-s p][-o x0 y0][-la][-lh h] ",
317 >        "Usage: %s [-h][-x xr][-y yr][-b r g b][-a n][-s p][-o x0 y0][-la][-lh h] ",
318                          progname);
319          fprintf(stderr, "[-t min1][+t max1][-l lab][=SS] pic1 x1 y1 ..\n");
320          quit(1);
# Line 309 | Line 325 | toomany:
325   labelerr:
326          fprintf(stderr, "%s: error opening label\n", progname);
327          quit(1);
328 +        return 1; /* pro forma return */
329   }
330  
331  
332 < compos()                                /* composite pictures */
332 > static void
333 > compos(void)                            /* composite pictures */
334   {
335          COLR  *scanin, *scanout;
336          int  y;
# Line 366 | Line 384 | compos()                               /* composite pictures */
384                          quit(1);
385                  }
386          }
387 +                                        /* read remainders from streams */
388 +        for (i = 0; i < nfile; i++)
389 +                if (input[i].name[0] == '<')
390 +                        while (getc(input[i].fp) != EOF)
391 +                                ;
392          return;
393   memerr:
394          perror(progname);
# Line 373 | Line 396 | memerr:
396   }
397  
398  
399 < int
400 < cmpcolr(c1, c2)                 /* compare two colr's (improvisation) */
401 < register COLR  c1, c2;
399 > static int
400 > cmpcolr(                        /* compare COLR to luminance */
401 >        register COLR  c1,
402 >        double lv2
403 > )
404   {
405 <        register int  i, j;
406 <
407 <        j = 4;                          /* check exponents first! */
408 <        while (j--)
409 <                if (i = c1[j] - c2[j])
410 <                        return(i);
405 >        double  lv1 = .0;
406 >        
407 >        if (c1[EXP])
408 >                lv1 = ldexp((double)normbright(c1), (int)c1[EXP]-(COLXS+8));
409 >        if (lv1 < lv2) return(-1);
410 >        if (lv1 > lv2) return(1);
411          return(0);
412   }
413  
414  
415 < FILE *
416 < lblopen(s, xp, yp)              /* open pipe to label generator */
417 < char  *s;
418 < int  *xp, *yp;
415 > static FILE *
416 > lblopen(                /* open pipe to label generator */
417 >        char  *s,
418 >        int  *xp,
419 >        int  *yp
420 > )
421   {
422 <        char  com[128];
422 >        char  com[PATH_MAX];
423          FILE  *fp;
424  
425          sprintf(com, "psign -s -.15 -a 2 -x %d -y %d '%.90s'", *xp, *yp, s);
# Line 409 | Line 436 | err:
436   }
437  
438  
439 + void
440   quit(code)              /* exit gracefully */
441   int  code;
442   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines