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.5 by greg, Tue Jun 16 16:48:41 1992 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+1];
150 +                                an += 2;
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]);
166 >                        if (argv[an][0] == '!') {
167 >                                input[nfile].name = "<Command>";
168 >                                input[nfile].fp = popen(argv[an]+1, "r");
169 >                        } else {
170 >                                input[nfile].name = argv[an];
171 >                                input[nfile].fp = fopen(argv[an], "r");
172 >                        }
173 >                        if (input[nfile].fp == NULL) {
174 >                                perror(argv[an]);
175                                  quit(1);
176                          }
177                  }
178                  an++;
179                                                  /* get header */
180                  printf("%s:\n", input[nfile].name);
181 <                getheader(input[nfile].fp, tabputs);
181 >                getheader(input[nfile].fp, tabputs, NULL);
182 >                if (wrongformat) {
183 >                        fprintf(stderr, "%s: not a Radiance picture\n",
184 >                                        input[nfile].name);
185 >                        quit(1);
186 >                }
187                                                  /* get picture size */
188 <                if (fscanf(input[nfile].fp, "-Y %d +X %d\n",
189 <                                &input[nfile].yres, &input[nfile].xres) != 2) {
188 >                if (fgetresolu(&input[nfile].xres, &input[nfile].yres,
189 >                                input[nfile].fp) < 0) {
190                          fprintf(stderr, "%s: bad picture size\n",
191                                          input[nfile].name);
192                          quit(1);
193                  }
194 <                input[nfile].xloc = atoi(argv[an++]);
195 <                input[nfile].yloc = atoi(argv[an++]);
194 >                if (ncolumns > 0) {
195 >                        if (curcol >= ncolumns) {
196 >                                cury = ymax;
197 >                                curx = 0;
198 >                                curcol = 0;
199 >                        }
200 >                        input[nfile].xloc = curx;
201 >                        input[nfile].yloc = cury;
202 >                        curx += input[nfile].xres;
203 >                        curcol++;
204 >                } else {
205 >                        input[nfile].xloc = atoi(argv[an++]);
206 >                        input[nfile].yloc = atoi(argv[an++]);
207 >                }
208                  if (input[nfile].xloc < xmin)
209                          xmin = input[nfile].xloc;
210                  if (input[nfile].yloc < ymin)
# Line 148 | Line 213 | getfile:
213                          xmax = input[nfile].xloc+input[nfile].xres;
214                  if (input[nfile].yloc+input[nfile].yres > ymax)
215                          ymax = input[nfile].yloc+input[nfile].yres;
216 +                if (thislabel != NULL) {
217 +                        if (++nfile >= MAXFILE)
218 +                                goto toomany;
219 +                        input[nfile].name = "<Label>";
220 +                        input[nfile].hasmin = input[nfile].hasmax = 0;
221 +                        if ((input[nfile].fp = lblopen(thislabel,
222 +                                        &input[nfile].xres,
223 +                                        &input[nfile].yres)) == NULL)
224 +                                goto labelerr;
225 +                        input[nfile].xloc = input[nfile-1].xloc;
226 +                        input[nfile].yloc = input[nfile-1].yloc +
227 +                                        input[nfile-1].yres-input[nfile].yres;
228 +                }
229          }
230          if (xsiz <= 0)
231                  xsiz = xmax;
# Line 155 | Line 233 | getfile:
233                  ysiz = ymax;
234                                          /* add new header info. */
235          printargs(argc, argv, stdout);
236 <        printf("\n-Y %d +X %d\n", ysiz, xsiz);
236 >        fputformat(COLRFMT, stdout);
237 >        putchar('\n');
238 >        fprtresolu(xsiz, ysiz, stdout);
239  
240          compos();
241          
242          quit(0);
243   userr:
244 <        fprintf(stderr, "Usage: %s [-x xres][-y yres][-b r g b] ", progname);
245 <        fprintf(stderr, "[-t min1][+t max1] file1 x1 y1 ..\n");
244 >        fprintf(stderr, "Usage: %s [-x xr][-y yr][-b r g b][-a n][-la][-lh h] ",
245 >                        progname);
246 >        fprintf(stderr, "[-t min1][+t max1][-l lab] pic1 x1 y1 ..\n");
247          quit(1);
248 + toomany:
249 +        fprintf(stderr, "%s: only %d files and labels allowed\n",
250 +                        progname, MAXFILE);
251 +        quit(1);
252 + labelerr:
253 +        fprintf(stderr, "%s: error opening label\n", progname);
254 +        quit(1);
255   }
256  
257  
# Line 173 | Line 261 | compos()                               /* composite pictures */
261          int  y;
262          register int  x, i;
263  
264 <        scanin = (COLR *)malloc((xmax-xmin)*sizeof(COLR)) - xmin;
177 <        scanin = (COLR *)malloc((xmax-xmin)*sizeof(COLR)) - xmin;
264 >        scanin = (COLR *)malloc((xmax-xmin)*sizeof(COLR));
265          if (scanin == NULL)
266                  goto memerr;
267          scanin -= xmin;
# Line 218 | Line 305 | compos()                               /* composite pictures */
305                  if (y >= ysiz)
306                          continue;
307                  if (fwritecolrs(scanout, xsiz, stdout) < 0) {
308 <                        fprintf(stderr, "%s: write error\n", progname);
308 >                        perror(progname);
309                          quit(1);
310                  }
311          }
312          return;
313   memerr:
314 <        fprintf(stderr, "%s: out of memory\n", progname);
314 >        perror(progname);
315          quit(1);
316   }
317  
# Line 240 | Line 327 | register COLR  c1, c2;
327                  if (i = c1[j] - c2[j])
328                          return(i);
329          return(0);
330 + }
331 +
332 +
333 + FILE *
334 + lblopen(s, xp, yp)              /* open pipe to label generator */
335 + char  *s;
336 + int  *xp, *yp;
337 + {
338 +        char  com[128];
339 +        FILE  *fp;
340 +
341 +        sprintf(com, "psign -s -.2 -h %d '%.30s'", labelht, s);
342 +        if ((fp = popen(com, "r")) == NULL)
343 +                return(NULL);
344 +        if (checkheader(fp, COLRFMT, NULL) < 0)
345 +                goto err;
346 +        if (fgetresolu(xp, yp, fp) < 0)
347 +                goto err;
348 +        return(fp);
349 + err:
350 +        pclose(fp);
351 +        return(NULL);
352   }
353  
354  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines