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 1.7 by greg, Thu May 30 09:44:36 1991 UTC vs.
Revision 2.21 by greg, Sat Feb 22 02:07:27 2003 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 12 | Line 9 | static char SCCSid[] = "$SunId$ LBL";
9  
10   #include  <stdio.h>
11  
12 + #include  <math.h>
13 +
14 + #ifdef MSDOS
15 + #include  <fcntl.h>
16 + #endif
17 +
18 + #include  <time.h>
19 +
20   #include  "color.h"
21  
22 + #include  "resolu.h"
23  
24 < #define  MAXFILE        32
24 > #define  MAXFILE        64
25  
26 < #define  SIGNHT         24
27 < #define  setpscom(b,n)  sprintf(b, "psign -h %d '%.30s'|pfilt -1 -x /2 -y /2",\
22 <                                2*SIGNHT, n)
26 > #define  HASMIN         1
27 > #define  HASMAX         2
28  
29                                          /* output picture size */
30   int  xsiz = 0;
# Line 32 | Line 37 | int  ymax = 0;
37  
38   COLR  bgcolr = BLKCOLR;                 /* background color */
39  
40 + int  labelht = 24;                      /* label height */
41 +
42   int  checkthresh = 0;                   /* check threshold value */
43  
44 + char  Command[] = "<Command>";
45 + char  Label[] = "<Label>";
46 +
47   char  *progname;
48  
49   struct {
# Line 41 | Line 51 | struct {
51          FILE  *fp;                      /* stream pointer */
52          int  xres, yres;                /* picture size */
53          int  xloc, yloc;                /* anchor point */
54 <        int  hasmin, hasmax;            /* has threshold values */
54 >        int  flags;                     /* HASMIN, HASMAX */
55          COLR  thmin, thmax;             /* thresholds */
56   } input[MAXFILE];               /* our input files */
57  
58   int  nfile;                     /* number of files */
59  
60 + char  ourfmt[LPICFMT+1] = PICFMT;
61   int  wrongformat = 0;
62  
63 < char  tmpbuf[128];
63 > FILE  *lblopen();
64 > void  quit();
65  
54 FILE  *popen();
66  
56
67   tabputs(s)                      /* print line preceded by a tab */
68   char  *s;
69   {
70          char  fmt[32];
71  
72 <        if (isformat(s)) {
73 <                formatval(fmt, s);
74 <                wrongformat = strcmp(fmt, COLRFMT);
72 >        if (isheadid(s))
73 >                return(0);
74 >        if (formatval(fmt, s)) {
75 >                if (globmatch(ourfmt, fmt)) {
76 >                        wrongformat = 0;
77 >                        strcpy(ourfmt, fmt);
78 >                } else
79 >                        wrongformat = 1;
80          } else {
81                  putc('\t', stdout);
82                  fputs(s, stdout);
83          }
84 +        return(0);
85   }
86  
87  
# Line 73 | Line 89 | main(argc, argv)
89   int  argc;
90   char  *argv[];
91   {
76        double  atof();
92          int  ncolumns = 0;
93 <        int  dolabels = 0;
94 <        int  curcol = 0, curx = 0, cury = 0;
93 >        int  autolabel = 0;
94 >        int  curcol = 0, x0 = 0, curx = 0, cury = 0, spacing = 0;
95 >        int  xsgn, ysgn;
96 >        char  *thislabel;
97          int  an;
98 <
98 > #ifdef MSDOS
99 >        extern int  _fmode;
100 >        _fmode = O_BINARY;
101 >        setmode(fileno(stdin), O_BINARY);
102 >        setmode(fileno(stdout), O_BINARY);
103 > #endif
104          progname = argv[0];
105  
106          for (an = 1; an < argc && argv[an][0] == '-'; an++)
107                  switch (argv[an][1]) {
108                  case 'x':
109 <                        xmax = xsiz = atoi(argv[++an]);
109 >                        xsiz = atoi(argv[++an]);
110                          break;
111                  case 'y':
112 <                        ymax = ysiz = atoi(argv[++an]);
112 >                        ysiz = atoi(argv[++an]);
113                          break;
114                  case 'b':
115                          setcolr(bgcolr, atof(argv[an+1]),
# Line 98 | Line 120 | char  *argv[];
120                  case 'a':
121                          ncolumns = atoi(argv[++an]);
122                          break;
123 +                case 's':
124 +                        spacing = atoi(argv[++an]);
125 +                        break;
126 +                case 'o':
127 +                        curx = x0 = atoi(argv[++an]);
128 +                        cury = atoi(argv[++an]);
129 +                        break;
130                  case 'l':
131 <                        dolabels++;
131 >                        switch (argv[an][2]) {
132 >                        case 'a':
133 >                                autolabel++;
134 >                                break;
135 >                        case 'h':
136 >                                labelht = atoi(argv[++an]);
137 >                                break;
138 >                        case '\0':
139 >                                goto dofiles;
140 >                        default:
141 >                                goto userr;
142 >                        }
143                          break;
144                  case '\0':
145                  case 't':
# Line 108 | Line 148 | char  *argv[];
148                          goto userr;
149                  }
150   dofiles:
151 +        newheader("RADIANCE", stdout);
152 +        fputnow(stdout);
153          for (nfile = 0; an < argc; nfile++) {
154 <                if (dolabels) {
155 <                        if (nfile >= MAXFILE-1) {
156 <                                fprintf(stderr,
157 <                                "%s: only %d files allowed with labels\n",
158 <                                        progname, MAXFILE/2);
159 <                        }
160 <                } else {
119 <                        if (nfile >= MAXFILE) {
120 <                                fprintf(stderr, "%s: only %d files allowed\n",
121 <                                                progname, MAXFILE);
122 <                                quit(1);
123 <                        }
124 <                }
125 <                if (nfile >= (dolabels ? MAXFILE-1 : MAXFILE)) {
126 <                        fprintf(stderr, "%s: too many files\n", progname);
127 <                        quit(1);
128 <                }
129 <                input[nfile].hasmin = input[nfile].hasmax = 0;
130 <                while (an < argc && (argv[an][0] == '-' || argv[an][0] == '+'))
154 >                if (nfile >= MAXFILE)
155 >                        goto toomany;
156 >                thislabel = NULL;
157 >                input[nfile].flags = 0;
158 >                xsgn = ysgn = '-';
159 >                while (an < argc && (argv[an][0] == '-' || argv[an][0] == '+'
160 >                                || argv[an][0] == '=')) {
161                          switch (argv[an][1]) {
162                          case 't':
163                                  checkthresh = 1;
164                                  if (argv[an][0] == '-') {
165 <                                        input[nfile].hasmin = 1;
165 >                                        input[nfile].flags |= HASMIN;
166                                          setcolr(input[nfile].thmin,
167                                                          atof(argv[an+1]),
168                                                          atof(argv[an+1]),
169                                                          atof(argv[an+1]));
170 <                                } else {
171 <                                        input[nfile].hasmax = 1;
170 >                                } else if (argv[an][0] == '+') {
171 >                                        input[nfile].flags |= HASMAX;
172                                          setcolr(input[nfile].thmax,
173                                                          atof(argv[an+1]),
174                                                          atof(argv[an+1]),
175                                                          atof(argv[an+1]));
176 <                                }
177 <                                an += 2;
176 >                                } else
177 >                                        goto userr;
178 >                                an++;
179                                  break;
180 +                        case 'l':
181 +                                if (strcmp(argv[an], "-l"))
182 +                                        goto userr;
183 +                                thislabel = argv[++an];
184 +                                break;
185 +                        case '+':
186 +                        case '-':
187 +                        case '0':
188 +                                if (argv[an][0] != '=')
189 +                                        goto userr;
190 +                                xsgn = argv[an][1];
191 +                                ysgn = argv[an][2];
192 +                                if (ysgn != '+' && ysgn != '-' && ysgn != '0')
193 +                                        goto userr;
194 +                                break;
195                          case '\0':
196                                  if (argv[an][0] == '-')
197                                          goto getfile;
198 <                        /* fall through */
198 >                                goto userr;
199                          default:
200                                  goto userr;
201                          }
202 +                        an++;
203 +                }
204   getfile:
205                  if (argc-an < (ncolumns ? 1 : 3))
206                          goto userr;
207 +                if (autolabel && thislabel == NULL)
208 +                        thislabel = argv[an];
209                  if (!strcmp(argv[an], "-")) {
210                          input[nfile].name = "<stdin>";
211                          input[nfile].fp = stdin;
212                  } else {
213 <                        input[nfile].name = argv[an];
214 <                        if ((input[nfile].fp = argv[an][0] == '!' ?
215 <                                        popen(argv[an]+1, "r") :
216 <                                        fopen(argv[an], "r")) == NULL) {
213 >                        if (argv[an][0] == '!') {
214 >                                input[nfile].name = Command;
215 >                                input[nfile].fp = popen(argv[an]+1, "r");
216 >                        } else {
217 >                                input[nfile].name = argv[an];
218 >                                input[nfile].fp = fopen(argv[an], "r");
219 >                        }
220 >                        if (input[nfile].fp == NULL) {
221                                  perror(argv[an]);
222                                  quit(1);
223                          }
# Line 173 | Line 227 | getfile:
227                  printf("%s:\n", input[nfile].name);
228                  getheader(input[nfile].fp, tabputs, NULL);
229                  if (wrongformat) {
230 <                        fprintf(stderr, "%s: not a Radiance picture\n",
230 >                        fprintf(stderr, "%s: incompatible input format\n",
231                                          input[nfile].name);
232                          quit(1);
233                  }
234                                                  /* get picture size */
235                  if (fgetresolu(&input[nfile].xres, &input[nfile].yres,
236 <                                input[nfile].fp) != (YMAJOR|YDECR)) {
236 >                                input[nfile].fp) < 0) {
237                          fprintf(stderr, "%s: bad picture size\n",
238                                          input[nfile].name);
239                          quit(1);
240                  }
241                  if (ncolumns > 0) {
242                          if (curcol >= ncolumns) {
243 <                                cury = ymax;
244 <                                curx = 0;
243 >                                cury = ymax + spacing;
244 >                                curx = x0;
245                                  curcol = 0;
246                          }
247                          input[nfile].xloc = curx;
248                          input[nfile].yloc = cury;
249 <                        curx += input[nfile].xres;
249 >                        curx += input[nfile].xres + spacing;
250                          curcol++;
251                  } else {
252                          input[nfile].xloc = atoi(argv[an++]);
253 +                        if (xsgn == '+')
254 +                                input[nfile].xloc -= input[nfile].xres;
255 +                        else if (xsgn == '0')
256 +                                input[nfile].xloc -= input[nfile].xres/2;
257                          input[nfile].yloc = atoi(argv[an++]);
258 +                        if (ysgn == '+')
259 +                                input[nfile].yloc -= input[nfile].yres;
260 +                        else if (ysgn == '0')
261 +                                input[nfile].yloc -= input[nfile].yres/2;
262                  }
263                  if (input[nfile].xloc < xmin)
264                          xmin = input[nfile].xloc;
# Line 206 | Line 268 | getfile:
268                          xmax = input[nfile].xloc+input[nfile].xres;
269                  if (input[nfile].yloc+input[nfile].yres > ymax)
270                          ymax = input[nfile].yloc+input[nfile].yres;
271 <                if (dolabels) {
272 <                        input[++nfile].name = "<Label>";
273 <                        setpscom(tmpbuf, input[nfile-1].name);
274 <                        if ((input[nfile].fp = popen(tmpbuf, "r")) == NULL)
271 >                if (thislabel != NULL) {
272 >                        if (++nfile >= MAXFILE)
273 >                                goto toomany;
274 >                        input[nfile].name = Label;
275 >                        input[nfile].flags = 0;
276 >                        input[nfile].xres = input[nfile-1].xres;
277 >                        input[nfile].yres = labelht;
278 >                        if ((input[nfile].fp = lblopen(thislabel,
279 >                                        &input[nfile].xres,
280 >                                        &input[nfile].yres)) == NULL)
281                                  goto labelerr;
214                        if (checkheader(input[nfile].fp, COLRFMT, NULL) < 0)
215                                goto labelerr;
216                        if (fgetresolu(&input[nfile].xres, &input[nfile].yres,
217                                        input[nfile].fp) != (YMAJOR|YDECR))
218                                goto labelerr;
282                          input[nfile].xloc = input[nfile-1].xloc;
283                          input[nfile].yloc = input[nfile-1].yloc +
284 <                                        input[nfile-1].yres - SIGNHT;
222 <                        input[nfile].hasmin = input[nfile].hasmax = 0;
284 >                                        input[nfile-1].yres-input[nfile].yres;
285                  }
286          }
287          if (xsiz <= 0)
288                  xsiz = xmax;
289 +        else if (xsiz > xmax)
290 +                xmax = xsiz;
291          if (ysiz <= 0)
292                  ysiz = ymax;
293 +        else if (ysiz > ymax)
294 +                ymax = ysiz;
295                                          /* add new header info. */
296          printargs(argc, argv, stdout);
297 <        fputformat(COLRFMT, stdout);
298 <        printf("\n-Y %d +X %d\n", ysiz, xsiz);
297 >        if (strcmp(ourfmt, PICFMT))
298 >                fputformat(ourfmt, stdout);     /* print format if known */
299 >        putchar('\n');
300 >        fprtresolu(xsiz, ysiz, stdout);
301  
302          compos();
303          
304          quit(0);
305   userr:
306 <        fprintf(stderr, "Usage: %s [-x xres][-y yres][-b r g b] ", progname);
307 <        fprintf(stderr, "[-t min1][+t max1] file1 x1 y1 ..\n");
306 >        fprintf(stderr,
307 >        "Usage: %s [-x xr][-y yr][-b r g b][-a n][-s p][-o x0 y0][-la][-lh h] ",
308 >                        progname);
309 >        fprintf(stderr, "[-t min1][+t max1][-l lab][=SS] pic1 x1 y1 ..\n");
310          quit(1);
311 + toomany:
312 +        fprintf(stderr, "%s: only %d files and labels allowed\n",
313 +                        progname, MAXFILE);
314 +        quit(1);
315   labelerr:
316          fprintf(stderr, "%s: error opening label\n", progname);
317          quit(1);
# Line 281 | Line 355 | compos()                               /* composite pictures */
355                                  if (x > xsiz)
356                                          x = xsiz;
357                                  for (x--; x >= 0 && x >= input[i].xloc; x--) {
358 <                                        if (input[i].hasmin &&
358 >                                        if (input[i].flags & HASMIN &&
359                                          cmpcolr(scanin[x], input[i].thmin) <= 0)
360                                                  continue;
361 <                                        if (input[i].hasmax &&
361 >                                        if (input[i].flags & HASMAX &&
362                                          cmpcolr(scanin[x], input[i].thmax) >= 0)
363                                                  continue;
364                                          copycolr(scanout[x], scanin[x]);
# Line 319 | Line 393 | register COLR  c1, c2;
393   }
394  
395  
396 + FILE *
397 + lblopen(s, xp, yp)              /* open pipe to label generator */
398 + char  *s;
399 + int  *xp, *yp;
400 + {
401 +        char  com[128];
402 +        FILE  *fp;
403 +
404 +        sprintf(com, "psign -s -.15 -a 2 -x %d -y %d '%.90s'", *xp, *yp, s);
405 +        if ((fp = popen(com, "r")) == NULL)
406 +                return(NULL);
407 +        if (checkheader(fp, COLRFMT, NULL) < 0)
408 +                goto err;
409 +        if (fgetresolu(xp, yp, fp) < 0)
410 +                goto err;
411 +        return(fp);
412 + err:
413 +        pclose(fp);
414 +        return(NULL);
415 + }
416 +
417 +
418 + void
419   quit(code)              /* exit gracefully */
420   int  code;
421   {
422 +        register int  i;
423 +                                /* close input files */
424 +        for (i = 0; i < nfile; i++)
425 +                if (input[i].name == Command || input[i].name == Label)
426 +                        pclose(input[i].fp);
427 +                else
428 +                        fclose(input[i].fp);
429          exit(code);
430   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines