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.13 by greg, Fri Aug 28 16:29:20 1992 UTC vs.
Revision 2.28 by greg, Mon Mar 15 21:16:54 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 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>
11 + #include  <math.h>
12 + #include  <time.h>
13 + #include  <string.h>
14  
15 < #include  "color.h"
15 > #include "copyright.h"
16  
17 + #include  "platform.h"
18 + #include  "rtprocess.h"
19 + #include  "color.h"
20   #include  "resolu.h"
21  
22 < #define  MAXFILE        64
22 > #define  MAXFILE        64
23  
24 + #define  HASMIN         1
25 + #define  HASMAX         2
26 +
27                                          /* output picture size */
28   int  xsiz = 0;
29   int  ysiz = 0;
# Line 33 | Line 39 | int  labelht = 24;                     /* label height */
39  
40   int  checkthresh = 0;                   /* check threshold value */
41  
42 + char  StandardInput[] = "<stdin>";
43 + char  Command[] = "<Command>";
44 + char  Label[] = "<Label>";
45 +
46   char  *progname;
47  
48   struct {
# Line 40 | Line 50 | struct {
50          FILE  *fp;                      /* stream pointer */
51          int  xres, yres;                /* picture size */
52          int  xloc, yloc;                /* anchor point */
53 <        int  hasmin, hasmax;            /* has threshold values */
53 >        int  flags;                     /* HASMIN, HASMAX */
54          COLR  thmin, thmax;             /* thresholds */
55   } input[MAXFILE];               /* our input files */
56  
57   int  nfile;                     /* number of files */
58  
59 + char  ourfmt[LPICFMT+1] = PICFMT;
60   int  wrongformat = 0;
61  
62 < FILE  *popen(), *lblopen();
62 > FILE  *lblopen();
63 > void  quit();
64  
65 + static gethfunc tabputs;
66  
67 < tabputs(s)                      /* print line preceded by a tab */
68 < char  *s;
67 >
68 > static int
69 > tabputs(                        /* print line preceded by a tab */
70 >        char    *s,
71 >        void    *p
72 > )
73   {
74          char  fmt[32];
75  
76 <        if (isformat(s)) {
77 <                formatval(fmt, s);
78 <                wrongformat = strcmp(fmt, COLRFMT);
76 >        if (isheadid(s))
77 >                return(0);
78 >        if (formatval(fmt, s)) {
79 >                if (globmatch(ourfmt, fmt)) {
80 >                        wrongformat = 0;
81 >                        strcpy(ourfmt, fmt);
82 >                } else
83 >                        wrongformat = 1;
84          } else {
85                  putc('\t', stdout);
86                  fputs(s, stdout);
87          }
88 +        return(0);
89   }
90  
91  
# Line 73 | Line 96 | char  *argv[];
96          int  ncolumns = 0;
97          int  autolabel = 0;
98          int  curcol = 0, x0 = 0, curx = 0, cury = 0, spacing = 0;
99 +        int  xsgn, ysgn;
100          char  *thislabel;
101          int  an;
102 <
102 >        SET_DEFAULT_BINARY();
103 >        SET_FILE_BINARY(stdin);
104 >        SET_FILE_BINARY(stdout);
105          progname = argv[0];
106  
107          for (an = 1; an < argc && argv[an][0] == '-'; an++)
# Line 123 | Line 149 | char  *argv[];
149                          goto userr;
150                  }
151   dofiles:
152 +        newheader("RADIANCE", stdout);
153 +        fputnow(stdout);
154          for (nfile = 0; an < argc; nfile++) {
155                  if (nfile >= MAXFILE)
156                          goto toomany;
157                  thislabel = NULL;
158 <                input[nfile].hasmin = input[nfile].hasmax = 0;
159 <                while (an < argc && (argv[an][0] == '-' || argv[an][0] == '+'))
158 >                input[nfile].flags = 0;
159 >                xsgn = ysgn = '-';
160 >                while (an < argc && (argv[an][0] == '-' || argv[an][0] == '+'
161 >                                || argv[an][0] == '=')) {
162                          switch (argv[an][1]) {
163                          case 't':
164                                  checkthresh = 1;
165                                  if (argv[an][0] == '-') {
166 <                                        input[nfile].hasmin = 1;
166 >                                        input[nfile].flags |= HASMIN;
167                                          setcolr(input[nfile].thmin,
168                                                          atof(argv[an+1]),
169                                                          atof(argv[an+1]),
170                                                          atof(argv[an+1]));
171 <                                } else {
172 <                                        input[nfile].hasmax = 1;
171 >                                } else if (argv[an][0] == '+') {
172 >                                        input[nfile].flags |= HASMAX;
173                                          setcolr(input[nfile].thmax,
174                                                          atof(argv[an+1]),
175                                                          atof(argv[an+1]),
176                                                          atof(argv[an+1]));
177 <                                }
178 <                                an += 2;
177 >                                } else
178 >                                        goto userr;
179 >                                an++;
180                                  break;
181                          case 'l':
182                                  if (strcmp(argv[an], "-l"))
183                                          goto userr;
184 <                                thislabel = argv[an+1];
154 <                                an += 2;
184 >                                thislabel = argv[++an];
185                                  break;
186 +                        case '+':
187 +                        case '-':
188 +                        case '0':
189 +                                if (argv[an][0] != '=')
190 +                                        goto userr;
191 +                                xsgn = argv[an][1];
192 +                                ysgn = argv[an][2];
193 +                                if (ysgn != '+' && ysgn != '-' && ysgn != '0')
194 +                                        goto userr;
195 +                                break;
196                          case '\0':
197                                  if (argv[an][0] == '-')
198                                          goto getfile;
# Line 160 | Line 200 | dofiles:
200                          default:
201                                  goto userr;
202                          }
203 +                        an++;
204 +                }
205   getfile:
206                  if (argc-an < (ncolumns ? 1 : 3))
207                          goto userr;
208                  if (autolabel && thislabel == NULL)
209                          thislabel = argv[an];
210                  if (!strcmp(argv[an], "-")) {
211 <                        input[nfile].name = "<stdin>";
211 >                        input[nfile].name = StandardInput;
212                          input[nfile].fp = stdin;
213                  } else {
214                          if (argv[an][0] == '!') {
215 <                                input[nfile].name = "<Command>";
215 >                                input[nfile].name = Command;
216                                  input[nfile].fp = popen(argv[an]+1, "r");
217                          } else {
218                                  input[nfile].name = argv[an];
# Line 186 | Line 228 | getfile:
228                  printf("%s:\n", input[nfile].name);
229                  getheader(input[nfile].fp, tabputs, NULL);
230                  if (wrongformat) {
231 <                        fprintf(stderr, "%s: not a Radiance picture\n",
231 >                        fprintf(stderr, "%s: incompatible input format\n",
232                                          input[nfile].name);
233                          quit(1);
234                  }
# Line 209 | Line 251 | getfile:
251                          curcol++;
252                  } else {
253                          input[nfile].xloc = atoi(argv[an++]);
254 +                        if (xsgn == '+')
255 +                                input[nfile].xloc -= input[nfile].xres;
256 +                        else if (xsgn == '0')
257 +                                input[nfile].xloc -= input[nfile].xres/2;
258                          input[nfile].yloc = atoi(argv[an++]);
259 +                        if (ysgn == '+')
260 +                                input[nfile].yloc -= input[nfile].yres;
261 +                        else if (ysgn == '0')
262 +                                input[nfile].yloc -= input[nfile].yres/2;
263                  }
264                  if (input[nfile].xloc < xmin)
265                          xmin = input[nfile].xloc;
# Line 222 | Line 272 | getfile:
272                  if (thislabel != NULL) {
273                          if (++nfile >= MAXFILE)
274                                  goto toomany;
275 <                        input[nfile].name = "<Label>";
276 <                        input[nfile].hasmin = input[nfile].hasmax = 0;
275 >                        input[nfile].name = Label;
276 >                        input[nfile].flags = 0;
277                          input[nfile].xres = input[nfile-1].xres;
278                          input[nfile].yres = labelht;
279                          if ((input[nfile].fp = lblopen(thislabel,
# Line 245 | Line 295 | getfile:
295                  ymax = ysiz;
296                                          /* add new header info. */
297          printargs(argc, argv, stdout);
298 <        fputformat(COLRFMT, stdout);
298 >        if (strcmp(ourfmt, PICFMT))
299 >                fputformat(ourfmt, stdout);     /* print format if known */
300          putchar('\n');
301          fprtresolu(xsiz, ysiz, stdout);
302  
# Line 256 | Line 307 | userr:
307          fprintf(stderr,
308          "Usage: %s [-x xr][-y yr][-b r g b][-a n][-s p][-o x0 y0][-la][-lh h] ",
309                          progname);
310 <        fprintf(stderr, "[-t min1][+t max1][-l lab] pic1 x1 y1 ..\n");
310 >        fprintf(stderr, "[-t min1][+t max1][-l lab][=SS] pic1 x1 y1 ..\n");
311          quit(1);
312   toomany:
313          fprintf(stderr, "%s: only %d files and labels allowed\n",
# Line 305 | Line 356 | compos()                               /* composite pictures */
356                                  if (x > xsiz)
357                                          x = xsiz;
358                                  for (x--; x >= 0 && x >= input[i].xloc; x--) {
359 <                                        if (input[i].hasmin &&
359 >                                        if (input[i].flags & HASMIN &&
360                                          cmpcolr(scanin[x], input[i].thmin) <= 0)
361                                                  continue;
362 <                                        if (input[i].hasmax &&
362 >                                        if (input[i].flags & HASMAX &&
363                                          cmpcolr(scanin[x], input[i].thmax) >= 0)
364                                                  continue;
365                                          copycolr(scanout[x], scanin[x]);
# Line 322 | Line 373 | compos()                               /* composite pictures */
373                          quit(1);
374                  }
375          }
376 +                                        /* read remainders from streams */
377 +        for (i = 0; i < nfile; i++)
378 +                if (input[i].name[0] == '<')
379 +                        while (getc(input[i].fp) != EOF)
380 +                                ;
381          return;
382   memerr:
383          perror(progname);
# Line 337 | Line 393 | register COLR  c1, c2;
393  
394          j = 4;                          /* check exponents first! */
395          while (j--)
396 <                if (i = c1[j] - c2[j])
396 >                if ( (i = c1[j] - c2[j]) )
397                          return(i);
398          return(0);
399   }
# Line 348 | Line 404 | lblopen(s, xp, yp)             /* open pipe to label generator */
404   char  *s;
405   int  *xp, *yp;
406   {
407 <        char  com[128];
407 >        char  com[PATH_MAX];
408          FILE  *fp;
409  
410          sprintf(com, "psign -s -.15 -a 2 -x %d -y %d '%.90s'", *xp, *yp, s);
# Line 365 | Line 421 | err:
421   }
422  
423  
424 < #ifdef  NIX
369 <
370 < quit(code)
371 < int  code;
372 < {
373 <        exit(code);
374 < }
375 <
376 < #else
377 <
424 > void
425   quit(code)              /* exit gracefully */
426   int  code;
427   {
428          register int  i;
429                                  /* close input files */
430          for (i = 0; i < nfile; i++)
431 <                fclose(input[i].fp);
432 <                                /* reap any children */
433 <        while (wait(0) != -1)
434 <                ;
431 >                if (input[i].name == Command || input[i].name == Label)
432 >                        pclose(input[i].fp);
433 >                else
434 >                        fclose(input[i].fp);
435          exit(code);
436   }
390
391 #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines