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.2 by greg, Mon Jun 12 10:07:29 1989 UTC vs.
Revision 2.2 by greg, Thu Dec 19 14:51:50 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1987 Regents of the University of California */
1 > /* Copyright (c) 1991 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        16
19 > #define  MAXFILE        32
20  
21                                          /* output picture size */
22   int  xsiz = 0;
# Line 28 | 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  *progname;
37  
38   struct {
39 <        char  *name;                    /* file name */
39 >        char  *name;                    /* file or command name */
40          FILE  *fp;                      /* stream pointer */
41          int  xres, yres;                /* picture size */
42          int  xloc, yloc;                /* anchor point */
# Line 43 | Line 46 | struct {
46  
47   int  nfile;                     /* number of files */
48  
49 + int  wrongformat = 0;
50  
51 + FILE  *popen(), *lblopen();
52 +
53 +
54   tabputs(s)                      /* print line preceded by a tab */
55   char  *s;
56   {
57 <        putc('\t', stdout);
58 <        fputs(s, stdout);
57 >        char  fmt[32];
58 >
59 >        if (isformat(s)) {
60 >                formatval(fmt, s);
61 >                wrongformat = strcmp(fmt, COLRFMT);
62 >        } else {
63 >                putc('\t', stdout);
64 >                fputs(s, stdout);
65 >        }
66   }
67  
68  
# Line 56 | Line 70 | main(argc, argv)
70   int  argc;
71   char  *argv[];
72   {
73 <        double  atof();
73 >        int  ncolumns = 0;
74 >        int  autolabel = 0;
75 >        int  curcol = 0, curx = 0, cury = 0;
76 >        char  *thislabel;
77          int  an;
78  
79          progname = argv[0];
# Line 75 | Line 92 | char  *argv[];
92                                          atof(argv[an+3]));
93                          an += 3;
94                          break;
95 +                case 'a':
96 +                        ncolumns = atoi(argv[++an]);
97 +                        break;
98 +                case 'l':
99 +                        switch (argv[an][2]) {
100 +                        case 'a':
101 +                                autolabel++;
102 +                                break;
103 +                        case 'h':
104 +                                labelht = atoi(argv[++an]);
105 +                                break;
106 +                        case '\0':
107 +                                goto dofiles;
108 +                        default:
109 +                                goto userr;
110 +                        }
111 +                        break;
112                  case '\0':
113                  case 't':
114                          goto dofiles;
# Line 83 | Line 117 | char  *argv[];
117                  }
118   dofiles:
119          for (nfile = 0; an < argc; nfile++) {
120 <                if (nfile >= MAXFILE) {
121 <                        fprintf(stderr, "%s: too many files\n", progname);
122 <                        quit(1);
123 <                }
120 >                if (nfile >= MAXFILE)
121 >                        goto toomany;
122 >                if (autolabel)
123 >                        thislabel = argv[an];
124 >                else
125 >                        thislabel = NULL;
126                  input[nfile].hasmin = input[nfile].hasmax = 0;
127                  while (an < argc && (argv[an][0] == '-' || argv[an][0] == '+'))
128                          switch (argv[an][1]) {
# Line 107 | Line 143 | dofiles:
143                                  }
144                                  an += 2;
145                                  break;
146 +                        case 'l':
147 +                                if (strcmp(argv[an], "-l"))
148 +                                        goto userr;
149 +                                thislabel = argv[++an];
150 +                                break;
151                          case '\0':
152                                  if (argv[an][0] == '-')
153                                          goto getfile;
154 <                        /* fall through */
154 >                                goto userr;
155                          default:
156                                  goto userr;
157                          }
158   getfile:
159 <                if (argc-an < 3)
159 >                if (argc-an < (ncolumns ? 1 : 3))
160                          goto userr;
161                  if (!strcmp(argv[an], "-")) {
162                          input[nfile].name = "<stdin>";
163                          input[nfile].fp = stdin;
164                  } else {
165                          input[nfile].name = argv[an];
166 <                        if ((input[nfile].fp = fopen(argv[an], "r")) == NULL) {
167 <                                fprintf(stderr, "%s: cannot open\n", argv[an]);
166 >                        if ((input[nfile].fp = argv[an][0] == '!' ?
167 >                                        popen(argv[an]+1, "r") :
168 >                                        fopen(argv[an], "r")) == NULL) {
169 >                                perror(argv[an]);
170                                  quit(1);
171                          }
172                  }
173                  an++;
174                                                  /* get header */
175                  printf("%s:\n", input[nfile].name);
176 <                getheader(input[nfile].fp, tabputs);
176 >                getheader(input[nfile].fp, tabputs, NULL);
177 >                if (wrongformat) {
178 >                        fprintf(stderr, "%s: not a Radiance picture\n",
179 >                                        input[nfile].name);
180 >                        quit(1);
181 >                }
182                                                  /* get picture size */
183 <                if (fscanf(input[nfile].fp, "-Y %d +X %d\n",
184 <                                &input[nfile].yres, &input[nfile].xres) != 2) {
183 >                if (fgetresolu(&input[nfile].xres, &input[nfile].yres,
184 >                                input[nfile].fp) < 0) {
185                          fprintf(stderr, "%s: bad picture size\n",
186                                          input[nfile].name);
187                          quit(1);
188                  }
189 <                input[nfile].xloc = atoi(argv[an++]);
190 <                input[nfile].yloc = atoi(argv[an++]);
189 >                if (ncolumns > 0) {
190 >                        if (curcol >= ncolumns) {
191 >                                cury = ymax;
192 >                                curx = 0;
193 >                                curcol = 0;
194 >                        }
195 >                        input[nfile].xloc = curx;
196 >                        input[nfile].yloc = cury;
197 >                        curx += input[nfile].xres;
198 >                        curcol++;
199 >                } else {
200 >                        input[nfile].xloc = atoi(argv[an++]);
201 >                        input[nfile].yloc = atoi(argv[an++]);
202 >                }
203                  if (input[nfile].xloc < xmin)
204                          xmin = input[nfile].xloc;
205                  if (input[nfile].yloc < ymin)
# Line 148 | Line 208 | getfile:
208                          xmax = input[nfile].xloc+input[nfile].xres;
209                  if (input[nfile].yloc+input[nfile].yres > ymax)
210                          ymax = input[nfile].yloc+input[nfile].yres;
211 +                if (thislabel != NULL) {
212 +                        if (++nfile >= MAXFILE)
213 +                                goto toomany;
214 +                        input[nfile].name = "<Label>";
215 +                        input[nfile].hasmin = input[nfile].hasmax = 0;
216 +                        if ((input[nfile].fp = lblopen(thislabel,
217 +                                        &input[nfile].xres,
218 +                                        &input[nfile].yres)) == NULL)
219 +                                goto labelerr;
220 +                        input[nfile].xloc = input[nfile-1].xloc;
221 +                        input[nfile].yloc = input[nfile-1].yloc +
222 +                                        input[nfile-1].yres-input[nfile].yres;
223 +                }
224          }
225          if (xsiz <= 0)
226                  xsiz = xmax;
# Line 155 | Line 228 | getfile:
228                  ysiz = ymax;
229                                          /* add new header info. */
230          printargs(argc, argv, stdout);
231 <        printf("\n-Y %d +X %d\n", ysiz, xsiz);
231 >        fputformat(COLRFMT, stdout);
232 >        putchar('\n');
233 >        fprtresolu(xsiz, ysiz, stdout);
234  
235          compos();
236          
237          quit(0);
238   userr:
239 <        fprintf(stderr, "Usage: %s [-x xres][-y yres][-b r g b] ", progname);
240 <        fprintf(stderr, "[-t min1][+t max1] file1 x1 y1 ..\n");
239 >        fprintf(stderr, "Usage: %s [-x xr][-y yr][-b r g b][-a n][-la][-lh h] ",
240 >                        progname);
241 >        fprintf(stderr, "[-t min1][+t max1][-l lab] pic1 x1 y1 ..\n");
242          quit(1);
243 + toomany:
244 +        fprintf(stderr, "%s: only %d files and labels allowed\n",
245 +                        progname, MAXFILE);
246 +        quit(1);
247 + labelerr:
248 +        fprintf(stderr, "%s: error opening label\n", progname);
249 +        quit(1);
250   }
251  
252  
# Line 173 | Line 256 | compos()                               /* composite pictures */
256          int  y;
257          register int  x, i;
258  
259 <        scanin = (COLR *)malloc((xmax-xmin)*sizeof(COLR)) - xmin;
177 <        scanin = (COLR *)malloc((xmax-xmin)*sizeof(COLR)) - xmin;
259 >        scanin = (COLR *)malloc((xmax-xmin)*sizeof(COLR));
260          if (scanin == NULL)
261                  goto memerr;
262          scanin -= xmin;
# Line 218 | Line 300 | compos()                               /* composite pictures */
300                  if (y >= ysiz)
301                          continue;
302                  if (fwritecolrs(scanout, xsiz, stdout) < 0) {
303 <                        fprintf(stderr, "%s: write error\n", progname);
303 >                        perror(progname);
304                          quit(1);
305                  }
306          }
307          return;
308   memerr:
309 <        fprintf(stderr, "%s: out of memory\n", progname);
309 >        perror(progname);
310          quit(1);
311   }
312  
# Line 240 | Line 322 | register COLR  c1, c2;
322                  if (i = c1[j] - c2[j])
323                          return(i);
324          return(0);
325 + }
326 +
327 +
328 + FILE *
329 + lblopen(s, xp, yp)              /* open pipe to label generator */
330 + char  *s;
331 + int  *xp, *yp;
332 + {
333 +        char  com[128];
334 +        FILE  *fp;
335 +
336 +        sprintf(com, "psign -h %d '%.30s' | pfilt -1 -x /2 -y /2",
337 +                        2*labelht, s);
338 +        if ((fp = popen(com, "r")) == NULL)
339 +                return(NULL);
340 +        if (checkheader(fp, COLRFMT, NULL) < 0)
341 +                goto err;
342 +        if (fgetresolu(xp, yp, fp) < 0)
343 +                goto err;
344 +        return(fp);
345 + err:
346 +        pclose(fp);
347 +        return(NULL);
348   }
349  
350  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines