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.1 by greg, Thu Feb 2 10:49:23 1989 UTC vs.
Revision 1.10 by greg, Mon Nov 11 14:01:42 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 57 | Line 71 | int  argc;
71   char  *argv[];
72   {
73          double  atof();
74 +        int  ncolumns = 0;
75 +        int  autolabel = 0;
76 +        int  curcol = 0, curx = 0, cury = 0;
77 +        char  *thislabel;
78          int  an;
79  
80          progname = argv[0];
# Line 75 | Line 93 | char  *argv[];
93                                          atof(argv[an+3]));
94                          an += 3;
95                          break;
96 +                case 'a':
97 +                        ncolumns = atoi(argv[++an]);
98 +                        break;
99 +                case 'l':
100 +                        switch (argv[an][2]) {
101 +                        case 'a':
102 +                                autolabel++;
103 +                                break;
104 +                        case 'h':
105 +                                labelht = atoi(argv[++an]);
106 +                                break;
107 +                        case '\0':
108 +                                goto dofiles;
109 +                        default:
110 +                                goto userr;
111 +                        }
112 +                        break;
113                  case '\0':
114                  case 't':
115                          goto dofiles;
# Line 83 | Line 118 | char  *argv[];
118                  }
119   dofiles:
120          for (nfile = 0; an < argc; nfile++) {
121 <                if (nfile >= MAXFILE) {
122 <                        fprintf(stderr, "%s: too many files\n", progname);
123 <                        quit(1);
124 <                }
121 >                if (nfile >= MAXFILE)
122 >                        goto toomany;
123 >                if (autolabel)
124 >                        thislabel = argv[an];
125 >                else
126 >                        thislabel = NULL;
127                  input[nfile].hasmin = input[nfile].hasmax = 0;
128                  while (an < argc && (argv[an][0] == '-' || argv[an][0] == '+'))
129                          switch (argv[an][1]) {
# Line 107 | Line 144 | dofiles:
144                                  }
145                                  an += 2;
146                                  break;
147 +                        case 'l':
148 +                                if (strcmp(argv[an], "-l"))
149 +                                        goto userr;
150 +                                thislabel = argv[++an];
151 +                                break;
152                          case '\0':
153                                  if (argv[an][0] == '-')
154                                          goto getfile;
155 <                        /* fall through */
155 >                                goto userr;
156                          default:
157                                  goto userr;
158                          }
159   getfile:
160 <                if (argc-an < 3)
160 >                if (argc-an < (ncolumns ? 1 : 3))
161                          goto userr;
162                  if (!strcmp(argv[an], "-")) {
163                          input[nfile].name = "<stdin>";
164                          input[nfile].fp = stdin;
165                  } else {
166                          input[nfile].name = argv[an];
167 <                        if ((input[nfile].fp = fopen(argv[an], "r")) == NULL) {
168 <                                fprintf(stderr, "%s: cannot open\n", argv[an]);
167 >                        if ((input[nfile].fp = argv[an][0] == '!' ?
168 >                                        popen(argv[an]+1, "r") :
169 >                                        fopen(argv[an], "r")) == NULL) {
170 >                                perror(argv[an]);
171                                  quit(1);
172                          }
173                  }
174                  an++;
175                                                  /* get header */
176                  printf("%s:\n", input[nfile].name);
177 <                getheader(input[nfile].fp, tabputs);
177 >                getheader(input[nfile].fp, tabputs, NULL);
178 >                if (wrongformat) {
179 >                        fprintf(stderr, "%s: not a Radiance picture\n",
180 >                                        input[nfile].name);
181 >                        quit(1);
182 >                }
183                                                  /* get picture size */
184 <                if (fscanf(input[nfile].fp, "-Y %d +X %d\n",
185 <                                &input[nfile].yres, &input[nfile].xres) != 2) {
184 >                if (fgetresolu(&input[nfile].xres, &input[nfile].yres,
185 >                                input[nfile].fp) < 0) {
186                          fprintf(stderr, "%s: bad picture size\n",
187                                          input[nfile].name);
188                          quit(1);
189                  }
190 <                input[nfile].xloc = atoi(argv[an++]);
191 <                input[nfile].yloc = atoi(argv[an++]);
190 >                if (ncolumns > 0) {
191 >                        if (curcol >= ncolumns) {
192 >                                cury = ymax;
193 >                                curx = 0;
194 >                                curcol = 0;
195 >                        }
196 >                        input[nfile].xloc = curx;
197 >                        input[nfile].yloc = cury;
198 >                        curx += input[nfile].xres;
199 >                        curcol++;
200 >                } else {
201 >                        input[nfile].xloc = atoi(argv[an++]);
202 >                        input[nfile].yloc = atoi(argv[an++]);
203 >                }
204                  if (input[nfile].xloc < xmin)
205                          xmin = input[nfile].xloc;
206                  if (input[nfile].yloc < ymin)
# Line 148 | Line 209 | getfile:
209                          xmax = input[nfile].xloc+input[nfile].xres;
210                  if (input[nfile].yloc+input[nfile].yres > ymax)
211                          ymax = input[nfile].yloc+input[nfile].yres;
212 +                if (thislabel != NULL) {
213 +                        if (++nfile >= MAXFILE)
214 +                                goto toomany;
215 +                        input[nfile].name = "<Label>";
216 +                        input[nfile].hasmin = input[nfile].hasmax = 0;
217 +                        if ((input[nfile].fp = lblopen(thislabel,
218 +                                        &input[nfile].xres,
219 +                                        &input[nfile].yres)) == NULL)
220 +                                goto labelerr;
221 +                        input[nfile].xloc = input[nfile-1].xloc;
222 +                        input[nfile].yloc = input[nfile-1].yloc +
223 +                                        input[nfile-1].yres-input[nfile].yres;
224 +                }
225          }
226          if (xsiz <= 0)
227                  xsiz = xmax;
# Line 155 | Line 229 | getfile:
229                  ysiz = ymax;
230                                          /* add new header info. */
231          printargs(argc, argv, stdout);
232 <        printf("\n-Y %d +X %d\n", ysiz, xsiz);
232 >        fputformat(COLRFMT, stdout);
233 >        putchar('\n');
234 >        fprtresolu(xsiz, ysiz, stdout);
235  
236          compos();
237          
238          quit(0);
239   userr:
240 <        fprintf(stderr, "Usage: %s [-x xres][-y yres][-b r g b] ", progname);
241 <        fprintf(stderr, "[-t min1][+t max1] file1 x1 y1 ..\n");
240 >        fprintf(stderr, "Usage: %s [-x xr][-y yr][-b r g b][-a n][-la][-lh h] ",
241 >                        progname);
242 >        fprintf(stderr, "[-t min1][+t max1][-l lab] pic1 x1 y1 ..\n");
243          quit(1);
244 + toomany:
245 +        fprintf(stderr, "%s: only %d files and labels allowed\n",
246 +                        progname, MAXFILE);
247 +        quit(1);
248 + labelerr:
249 +        fprintf(stderr, "%s: error opening label\n", progname);
250 +        quit(1);
251   }
252  
253  
# Line 173 | Line 257 | compos()                               /* composite pictures */
257          int  y;
258          register int  x, i;
259  
260 <        scanin = (COLR *)malloc((xmax-xmin)*sizeof(COLR)) - xmin;
177 <        scanin = (COLR *)malloc((xmax-xmin)*sizeof(COLR)) - xmin;
260 >        scanin = (COLR *)malloc((xmax-xmin)*sizeof(COLR));
261          if (scanin == NULL)
262                  goto memerr;
263          scanin -= xmin;
# Line 193 | Line 276 | compos()                               /* composite pictures */
276                                  continue;
277                          if (freadcolrs(scanin+input[i].xloc,
278                                          input[i].xres, input[i].fp) < 0) {
279 <                                fprintf(stderr, "%s: read error\n",
280 <                                                input[i].name);
279 >                                fprintf(stderr, "%s: read error (y==%d)\n",
280 >                                                input[i].name,
281 >                                                y-input[i].yloc);
282                                  quit(1);
283                          }
284                          if (y >= ysiz)
# Line 217 | Line 301 | compos()                               /* composite pictures */
301                  if (y >= ysiz)
302                          continue;
303                  if (fwritecolrs(scanout, xsiz, stdout) < 0) {
304 <                        fprintf(stderr, "%s: write error\n", progname);
304 >                        perror(progname);
305                          quit(1);
306                  }
307          }
308          return;
309   memerr:
310 <        fprintf(stderr, "%s: out of memory\n", progname);
310 >        perror(progname);
311          quit(1);
312   }
313  
# Line 239 | Line 323 | register COLR  c1, c2;
323                  if (i = c1[j] - c2[j])
324                          return(i);
325          return(0);
326 + }
327 +
328 +
329 + FILE *
330 + lblopen(s, xp, yp)              /* open pipe to label generator */
331 + char  *s;
332 + int  *xp, *yp;
333 + {
334 +        char  com[128];
335 +        FILE  *fp;
336 +
337 +        sprintf(com, "psign -h %d '%.30s' | pfilt -1 -x /2 -y /2",
338 +                        2*labelht, s);
339 +        if ((fp = popen(com, "r")) == NULL)
340 +                return(NULL);
341 +        if (checkheader(fp, COLRFMT, NULL) < 0)
342 +                goto err;
343 +        if (fgetresolu(xp, yp, fp) < 0)
344 +                goto err;
345 +        return(fp);
346 + err:
347 +        pclose(fp);
348 +        return(NULL);
349   }
350  
351  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines