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.6 by greg, Thu Apr 18 14:35:19 1991 UTC vs.
Revision 2.22 by schorsch, Thu Jun 5 19:29:34 2003 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines