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.14 by greg, Tue Sep 8 10:36:22 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 14 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14  
15   #include  "color.h"
16  
17 + #include  "resolu.h"
18  
19 < #define  MAXFILE        32
19 > #define  MAXFILE        64
20  
20 #define  SIGNHT         24
21 #define  setpscom(b,n)  sprintf(b, "psign -h %d '%.30s'|pfilt -1 -x /2 -y /2",\
22                                2*SIGNHT, n)
23
21                                          /* output picture size */
22   int  xsiz = 0;
23   int  ysiz = 0;
# Line 32 | Line 29 | int  ymax = 0;
29  
30   COLR  bgcolr = BLKCOLR;                 /* background color */
31  
32 + int  labelht = 24;                      /* label height */
33 +
34   int  checkthresh = 0;                   /* check threshold value */
35  
36 + char  Command[] = "<Command>";
37 + char  Label[] = "<Label>";
38 +
39   char  *progname;
40  
41   struct {
# Line 49 | Line 51 | int  nfile;                    /* number of files */
51  
52   int  wrongformat = 0;
53  
54 < char  tmpbuf[128];
54 > FILE  *popen(), *lblopen();
55  
54 FILE  *popen();
56  
56
57   tabputs(s)                      /* print line preceded by a tab */
58   char  *s;
59   {
# Line 73 | Line 73 | main(argc, argv)
73   int  argc;
74   char  *argv[];
75   {
76        double  atof();
76          int  ncolumns = 0;
77 <        int  dolabels = 0;
78 <        int  curcol = 0, curx = 0, cury = 0;
77 >        int  autolabel = 0;
78 >        int  curcol = 0, x0 = 0, curx = 0, cury = 0, spacing = 0;
79 >        char  *thislabel;
80          int  an;
81  
82          progname = argv[0];
# Line 84 | Line 84 | char  *argv[];
84          for (an = 1; an < argc && argv[an][0] == '-'; an++)
85                  switch (argv[an][1]) {
86                  case 'x':
87 <                        xmax = xsiz = atoi(argv[++an]);
87 >                        xsiz = atoi(argv[++an]);
88                          break;
89                  case 'y':
90 <                        ymax = ysiz = atoi(argv[++an]);
90 >                        ysiz = atoi(argv[++an]);
91                          break;
92                  case 'b':
93                          setcolr(bgcolr, atof(argv[an+1]),
# Line 98 | Line 98 | char  *argv[];
98                  case 'a':
99                          ncolumns = atoi(argv[++an]);
100                          break;
101 +                case 's':
102 +                        spacing = atoi(argv[++an]);
103 +                        break;
104 +                case 'o':
105 +                        curx = x0 = atoi(argv[++an]);
106 +                        cury = atoi(argv[++an]);
107 +                        break;
108                  case 'l':
109 <                        dolabels++;
109 >                        switch (argv[an][2]) {
110 >                        case 'a':
111 >                                autolabel++;
112 >                                break;
113 >                        case 'h':
114 >                                labelht = atoi(argv[++an]);
115 >                                break;
116 >                        case '\0':
117 >                                goto dofiles;
118 >                        default:
119 >                                goto userr;
120 >                        }
121                          break;
122                  case '\0':
123                  case 't':
# Line 109 | Line 127 | char  *argv[];
127                  }
128   dofiles:
129          for (nfile = 0; an < argc; nfile++) {
130 <                if (dolabels) {
131 <                        if (nfile >= MAXFILE-1) {
132 <                                fprintf(stderr,
115 <                                "%s: only %d files allowed with labels\n",
116 <                                        progname, MAXFILE/2);
117 <                        }
118 <                } 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 <                }
130 >                if (nfile >= MAXFILE)
131 >                        goto toomany;
132 >                thislabel = NULL;
133                  input[nfile].hasmin = input[nfile].hasmax = 0;
134                  while (an < argc && (argv[an][0] == '-' || argv[an][0] == '+'))
135                          switch (argv[an][1]) {
# Line 146 | Line 150 | dofiles:
150                                  }
151                                  an += 2;
152                                  break;
153 +                        case 'l':
154 +                                if (strcmp(argv[an], "-l"))
155 +                                        goto userr;
156 +                                thislabel = argv[an+1];
157 +                                an += 2;
158 +                                break;
159                          case '\0':
160                                  if (argv[an][0] == '-')
161                                          goto getfile;
162 <                        /* fall through */
162 >                                goto userr;
163                          default:
164                                  goto userr;
165                          }
166   getfile:
167                  if (argc-an < (ncolumns ? 1 : 3))
168                          goto userr;
169 +                if (autolabel && thislabel == NULL)
170 +                        thislabel = argv[an];
171                  if (!strcmp(argv[an], "-")) {
172                          input[nfile].name = "<stdin>";
173                          input[nfile].fp = stdin;
174                  } else {
175 <                        input[nfile].name = argv[an];
176 <                        if ((input[nfile].fp = argv[an][0] == '!' ?
177 <                                        popen(argv[an]+1, "r") :
178 <                                        fopen(argv[an], "r")) == NULL) {
175 >                        if (argv[an][0] == '!') {
176 >                                input[nfile].name = Command;
177 >                                input[nfile].fp = popen(argv[an]+1, "r");
178 >                        } else {
179 >                                input[nfile].name = argv[an];
180 >                                input[nfile].fp = fopen(argv[an], "r");
181 >                        }
182 >                        if (input[nfile].fp == NULL) {
183                                  perror(argv[an]);
184                                  quit(1);
185                          }
# Line 179 | Line 195 | getfile:
195                  }
196                                                  /* get picture size */
197                  if (fgetresolu(&input[nfile].xres, &input[nfile].yres,
198 <                                input[nfile].fp) != (YMAJOR|YDECR)) {
198 >                                input[nfile].fp) < 0) {
199                          fprintf(stderr, "%s: bad picture size\n",
200                                          input[nfile].name);
201                          quit(1);
202                  }
203                  if (ncolumns > 0) {
204                          if (curcol >= ncolumns) {
205 <                                cury = ymax;
206 <                                curx = 0;
205 >                                cury = ymax + spacing;
206 >                                curx = x0;
207                                  curcol = 0;
208                          }
209                          input[nfile].xloc = curx;
210                          input[nfile].yloc = cury;
211 <                        curx += input[nfile].xres;
211 >                        curx += input[nfile].xres + spacing;
212                          curcol++;
213                  } else {
214                          input[nfile].xloc = atoi(argv[an++]);
# Line 206 | Line 222 | getfile:
222                          xmax = input[nfile].xloc+input[nfile].xres;
223                  if (input[nfile].yloc+input[nfile].yres > ymax)
224                          ymax = input[nfile].yloc+input[nfile].yres;
225 <                if (dolabels) {
226 <                        input[++nfile].name = "<Label>";
227 <                        setpscom(tmpbuf, input[nfile-1].name);
228 <                        if ((input[nfile].fp = popen(tmpbuf, "r")) == NULL)
225 >                if (thislabel != NULL) {
226 >                        if (++nfile >= MAXFILE)
227 >                                goto toomany;
228 >                        input[nfile].name = Label;
229 >                        input[nfile].hasmin = input[nfile].hasmax = 0;
230 >                        input[nfile].xres = input[nfile-1].xres;
231 >                        input[nfile].yres = labelht;
232 >                        if ((input[nfile].fp = lblopen(thislabel,
233 >                                        &input[nfile].xres,
234 >                                        &input[nfile].yres)) == NULL)
235                                  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;
236                          input[nfile].xloc = input[nfile-1].xloc;
237                          input[nfile].yloc = input[nfile-1].yloc +
238 <                                        input[nfile-1].yres - SIGNHT;
222 <                        input[nfile].hasmin = input[nfile].hasmax = 0;
238 >                                        input[nfile-1].yres-input[nfile].yres;
239                  }
240          }
241          if (xsiz <= 0)
242                  xsiz = xmax;
243 +        else if (xsiz > xmax)
244 +                xmax = xsiz;
245          if (ysiz <= 0)
246                  ysiz = ymax;
247 +        else if (ysiz > ymax)
248 +                ymax = ysiz;
249                                          /* add new header info. */
250          printargs(argc, argv, stdout);
251          fputformat(COLRFMT, stdout);
252 <        printf("\n-Y %d +X %d\n", ysiz, xsiz);
252 >        putchar('\n');
253 >        fprtresolu(xsiz, ysiz, stdout);
254  
255          compos();
256          
257          quit(0);
258   userr:
259 <        fprintf(stderr, "Usage: %s [-x xres][-y yres][-b r g b] ", progname);
260 <        fprintf(stderr, "[-t min1][+t max1] file1 x1 y1 ..\n");
259 >        fprintf(stderr,
260 >        "Usage: %s [-x xr][-y yr][-b r g b][-a n][-s p][-o x0 y0][-la][-lh h] ",
261 >                        progname);
262 >        fprintf(stderr, "[-t min1][+t max1][-l lab] pic1 x1 y1 ..\n");
263          quit(1);
264 + toomany:
265 +        fprintf(stderr, "%s: only %d files and labels allowed\n",
266 +                        progname, MAXFILE);
267 +        quit(1);
268   labelerr:
269          fprintf(stderr, "%s: error opening label\n", progname);
270          quit(1);
# Line 319 | Line 346 | register COLR  c1, c2;
346   }
347  
348  
349 + FILE *
350 + lblopen(s, xp, yp)              /* open pipe to label generator */
351 + char  *s;
352 + int  *xp, *yp;
353 + {
354 +        char  com[128];
355 +        FILE  *fp;
356 +
357 +        sprintf(com, "psign -s -.15 -a 2 -x %d -y %d '%.90s'", *xp, *yp, s);
358 +        if ((fp = popen(com, "r")) == NULL)
359 +                return(NULL);
360 +        if (checkheader(fp, COLRFMT, NULL) < 0)
361 +                goto err;
362 +        if (fgetresolu(xp, yp, fp) < 0)
363 +                goto err;
364 +        return(fp);
365 + err:
366 +        pclose(fp);
367 +        return(NULL);
368 + }
369 +
370 +
371   quit(code)              /* exit gracefully */
372   int  code;
373   {
374 +        register int  i;
375 +                                /* close input files */
376 +        for (i = 0; i < nfile; i++)
377 +                if (input[i].name == Command || input[i].name == Label)
378 +                        pclose(input[i].fp);
379 +                else
380 +                        fclose(input[i].fp);
381          exit(code);
382   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines