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.20 by gwlarson, Tue Oct 27 09:08:25 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 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        32
25 > #define  MAXFILE        64
26  
27 < #define  SIGNHT         24
28 < #define  setpscom(b,n)  sprintf(b, "psign -h %d '%.30s'|pfilt -1 -x /2 -y /2",\
22 <                                2*SIGNHT, n)
27 > #define  HASMIN         1
28 > #define  HASMAX         2
29  
30                                          /* output picture size */
31   int  xsiz = 0;
# Line 32 | 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 {
# Line 41 | Line 52 | struct {
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 + char  ourfmt[LPICFMT+1] = PICFMT;
62   int  wrongformat = 0;
63  
64 < char  tmpbuf[128];
64 > FILE  *popen(), *lblopen();
65  
66 < FILE  *popen();
66 > extern char  *malloc();
67  
68  
69   tabputs(s)                      /* print line preceded by a tab */
# Line 59 | Line 71 | char  *s;
71   {
72          char  fmt[32];
73  
74 <        if (isformat(s)) {
75 <                formatval(fmt, s);
76 <                wrongformat = strcmp(fmt, COLRFMT);
74 >        if (isheadid(s))
75 >                return(0);
76 >        if (formatval(fmt, s)) {
77 >                if (globmatch(ourfmt, fmt)) {
78 >                        wrongformat = 0;
79 >                        strcpy(ourfmt, fmt);
80 >                } else
81 >                        wrongformat = 1;
82          } else {
83                  putc('\t', stdout);
84                  fputs(s, stdout);
85          }
86 +        return(0);
87   }
88  
89  
# Line 73 | Line 91 | main(argc, argv)
91   int  argc;
92   char  *argv[];
93   {
76        double  atof();
94          int  ncolumns = 0;
95 <        int  dolabels = 0;
96 <        int  curcol = 0, curx = 0, cury = 0;
95 >        int  autolabel = 0;
96 >        int  curcol = 0, x0 = 0, curx = 0, cury = 0, spacing = 0;
97 >        int  xsgn, ysgn;
98 >        char  *thislabel;
99          int  an;
100 <
100 > #ifdef MSDOS
101 >        extern int  _fmode;
102 >        _fmode = O_BINARY;
103 >        setmode(fileno(stdin), O_BINARY);
104 >        setmode(fileno(stdout), O_BINARY);
105 > #endif
106          progname = argv[0];
107  
108          for (an = 1; an < argc && argv[an][0] == '-'; an++)
109                  switch (argv[an][1]) {
110                  case 'x':
111 <                        xmax = xsiz = atoi(argv[++an]);
111 >                        xsiz = atoi(argv[++an]);
112                          break;
113                  case 'y':
114 <                        ymax = ysiz = atoi(argv[++an]);
114 >                        ysiz = atoi(argv[++an]);
115                          break;
116                  case 'b':
117                          setcolr(bgcolr, atof(argv[an+1]),
# Line 98 | Line 122 | char  *argv[];
122                  case 'a':
123                          ncolumns = atoi(argv[++an]);
124                          break;
125 +                case 's':
126 +                        spacing = atoi(argv[++an]);
127 +                        break;
128 +                case 'o':
129 +                        curx = x0 = atoi(argv[++an]);
130 +                        cury = atoi(argv[++an]);
131 +                        break;
132                  case 'l':
133 <                        dolabels++;
133 >                        switch (argv[an][2]) {
134 >                        case 'a':
135 >                                autolabel++;
136 >                                break;
137 >                        case 'h':
138 >                                labelht = atoi(argv[++an]);
139 >                                break;
140 >                        case '\0':
141 >                                goto dofiles;
142 >                        default:
143 >                                goto userr;
144 >                        }
145                          break;
146                  case '\0':
147                  case 't':
# Line 108 | Line 150 | char  *argv[];
150                          goto userr;
151                  }
152   dofiles:
153 +        newheader("RADIANCE", stdout);
154          for (nfile = 0; an < argc; nfile++) {
155 <                if (dolabels) {
156 <                        if (nfile >= MAXFILE-1) {
157 <                                fprintf(stderr,
158 <                                "%s: only %d files allowed with labels\n",
159 <                                        progname, MAXFILE/2);
160 <                        }
161 <                } 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] == '+'))
155 >                if (nfile >= MAXFILE)
156 >                        goto toomany;
157 >                thislabel = NULL;
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];
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;
199 <                        /* fall through */
199 >                                goto userr;
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>";
212                          input[nfile].fp = stdin;
213                  } else {
214 <                        input[nfile].name = argv[an];
215 <                        if ((input[nfile].fp = argv[an][0] == '!' ?
216 <                                        popen(argv[an]+1, "r") :
217 <                                        fopen(argv[an], "r")) == NULL) {
214 >                        if (argv[an][0] == '!') {
215 >                                input[nfile].name = Command;
216 >                                input[nfile].fp = popen(argv[an]+1, "r");
217 >                        } else {
218 >                                input[nfile].name = argv[an];
219 >                                input[nfile].fp = fopen(argv[an], "r");
220 >                        }
221 >                        if (input[nfile].fp == NULL) {
222                                  perror(argv[an]);
223                                  quit(1);
224                          }
# Line 173 | 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: bad Radiance input file\n",
232                                          input[nfile].name);
233                          quit(1);
234                  }
235                                                  /* get picture size */
236                  if (fgetresolu(&input[nfile].xres, &input[nfile].yres,
237 <                                input[nfile].fp) != (YMAJOR|YDECR)) {
237 >                                input[nfile].fp) < 0) {
238                          fprintf(stderr, "%s: bad picture size\n",
239                                          input[nfile].name);
240                          quit(1);
241                  }
242                  if (ncolumns > 0) {
243                          if (curcol >= ncolumns) {
244 <                                cury = ymax;
245 <                                curx = 0;
244 >                                cury = ymax + spacing;
245 >                                curx = x0;
246                                  curcol = 0;
247                          }
248                          input[nfile].xloc = curx;
249                          input[nfile].yloc = cury;
250 <                        curx += input[nfile].xres;
250 >                        curx += input[nfile].xres + spacing;
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 206 | Line 269 | getfile:
269                          xmax = input[nfile].xloc+input[nfile].xres;
270                  if (input[nfile].yloc+input[nfile].yres > ymax)
271                          ymax = input[nfile].yloc+input[nfile].yres;
272 <                if (dolabels) {
273 <                        input[++nfile].name = "<Label>";
274 <                        setpscom(tmpbuf, input[nfile-1].name);
275 <                        if ((input[nfile].fp = popen(tmpbuf, "r")) == NULL)
272 >                if (thislabel != NULL) {
273 >                        if (++nfile >= MAXFILE)
274 >                                goto toomany;
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,
280 >                                        &input[nfile].xres,
281 >                                        &input[nfile].yres)) == NULL)
282                                  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;
283                          input[nfile].xloc = input[nfile-1].xloc;
284                          input[nfile].yloc = input[nfile-1].yloc +
285 <                                        input[nfile-1].yres - SIGNHT;
222 <                        input[nfile].hasmin = input[nfile].hasmax = 0;
285 >                                        input[nfile-1].yres-input[nfile].yres;
286                  }
287          }
288          if (xsiz <= 0)
289                  xsiz = xmax;
290 +        else if (xsiz > xmax)
291 +                xmax = xsiz;
292          if (ysiz <= 0)
293                  ysiz = ymax;
294 +        else if (ysiz > ymax)
295 +                ymax = ysiz;
296                                          /* add new header info. */
297          printargs(argc, argv, stdout);
298 <        fputformat(COLRFMT, stdout);
299 <        printf("\n-Y %d +X %d\n", ysiz, xsiz);
298 >        if (strcmp(ourfmt, PICFMT))
299 >                fputformat(ourfmt, stdout);     /* print format if known */
300 >        putchar('\n');
301 >        fprtresolu(xsiz, ysiz, stdout);
302  
303          compos();
304          
305          quit(0);
306   userr:
307 <        fprintf(stderr, "Usage: %s [-x xres][-y yres][-b r g b] ", progname);
308 <        fprintf(stderr, "[-t min1][+t max1] file1 x1 y1 ..\n");
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][=SS] pic1 x1 y1 ..\n");
311          quit(1);
312 + toomany:
313 +        fprintf(stderr, "%s: only %d files and labels allowed\n",
314 +                        progname, MAXFILE);
315 +        quit(1);
316   labelerr:
317          fprintf(stderr, "%s: error opening label\n", progname);
318          quit(1);
# Line 281 | 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 319 | Line 394 | register COLR  c1, c2;
394   }
395  
396  
397 + FILE *
398 + lblopen(s, xp, yp)              /* open pipe to label generator */
399 + char  *s;
400 + int  *xp, *yp;
401 + {
402 +        char  com[128];
403 +        FILE  *fp;
404 +
405 +        sprintf(com, "psign -s -.15 -a 2 -x %d -y %d '%.90s'", *xp, *yp, s);
406 +        if ((fp = popen(com, "r")) == NULL)
407 +                return(NULL);
408 +        if (checkheader(fp, COLRFMT, NULL) < 0)
409 +                goto err;
410 +        if (fgetresolu(xp, yp, fp) < 0)
411 +                goto err;
412 +        return(fp);
413 + err:
414 +        pclose(fp);
415 +        return(NULL);
416 + }
417 +
418 +
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