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.4 by greg, Tue Sep 12 13:04:24 1989 UTC vs.
Revision 2.18 by greg, Sun Feb 27 10:17:04 1994 UTC

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