ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pcomb.c
(Generate patch)

Comparing ray/src/px/pcomb.c (file contents):
Revision 1.19 by greg, Thu May 30 09:47:14 1991 UTC vs.
Revision 2.7 by greg, Mon Sep 21 12:13:48 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 12 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12  
13   #include <stdio.h>
14  
15 + #ifdef MSDOS
16 + #include <fcntl.h>
17 + #endif
18 +
19   #include <errno.h>
20  
21   #include "color.h"
22  
23 + #include  "resolu.h"
24 +
25   #include "calcomp.h"
26  
27   #define MAXINP          32              /* maximum number of input files */
28   #define WINSIZ          9               /* scanline window size */
29   #define MIDSCN          4               /* current scan position */
30  
25 #define BRT             (-1)            /* special index for brightness */
26
31   struct {
32          char    *name;          /* file or command name */
33          FILE    *fp;            /* stream pointer */
# Line 34 | Line 38 | struct {
38  
39   int     nfiles;                         /* number of input files */
40  
41 < char    *vcolin[3] = {"ri", "gi", "bi"};
42 < char    *vcolout[3] = {"ro", "go", "bo"};
41 > char    Command[] = "<Command>";
42 > char    vcolin[3][4] = {"ri", "gi", "bi"};
43 > char    vcolout[3][4] = {"ro", "go", "bo"};
44   char    vbrtin[] = "li";
45   char    vbrtout[] = "lo";
46 < char    *vcolexp[3] = {"re", "ge", "be"};
46 > char    vcolexp[3][4] = {"re", "ge", "be"};
47   char    vbrtexp[] = "le";
48  
49   char    vnfiles[] = "nfiles";
# Line 63 | Line 68 | int    wrongformat = 0;
68  
69   FILE    *popen();
70  
71 + extern char     *emalloc();
72  
73 +
74   main(argc, argv)
75   int     argc;
76   char    *argv[];
77   {
71        char    buf[128];
78          int     original;
79          double  f;
80          int     a, i;
81 + #ifdef MSDOS
82 +        extern int  _fmode;
83 +        _fmode = O_BINARY;
84 +        setmode(fileno(stdin), O_BINARY);
85 +        setmode(fileno(stdout), O_BINARY);
86 + #endif
87                                                  /* scan options */
88          for (a = 1; a < argc; a++) {
89                  if (argv[a][0] == '-')
# Line 111 | Line 123 | char   *argv[];
123                                  break;
124                          case 'o':
125                                  original++;
126 <                                break;
126 >                                continue;
127                          case 's':
128                                  f = atof(argv[++a]);
129                                  scalecolor(input[nfiles].coef, f);
# Line 125 | Line 137 | char   *argv[];
137                                  goto usage;
138                          }
139                  else {
140 <                        input[nfiles].name = argv[a];
141 <                        input[nfiles].fp = argv[a][0]=='!' ?
142 <                                        popen(argv[a]+1, "r") :
143 <                                        fopen(argv[a], "r");
140 >                        if (argv[a][0] == '!') {
141 >                                input[nfiles].name = Command;
142 >                                input[nfiles].fp = popen(argv[a]+1, "r");
143 >                        } else {
144 >                                input[nfiles].name = argv[a];
145 >                                input[nfiles].fp = fopen(argv[a], "r");
146 >                        }
147                          if (input[nfiles].fp == NULL) {
148                                  perror(argv[a]);
149                                  quit(1);
# Line 152 | Line 167 | char   *argv[];
167                  if (argv[a][0] == '-')
168                          switch (argv[a][1]) {
169                          case 'x':
170 <                                strcpy(buf, vxres);
156 <                                strcat(buf, ":");
157 <                                strcat(buf, argv[++a]);
158 <                                scompile(buf, NULL, 0);
170 >                                varset(vxres, ':', eval(argv[++a]));
171                                  continue;
172                          case 'y':
173 <                                strcpy(buf, vyres);
162 <                                strcat(buf, ":");
163 <                                strcat(buf, argv[++a]);
164 <                                scompile(buf, NULL, 0);
173 >                                varset(vyres, ':', eval(argv[++a]));
174                                  continue;
175                          case 'w':
176                                  continue;
# Line 190 | Line 199 | char   *argv[];
199          printargs(argc, argv, stdout);
200          fputformat(COLRFMT, stdout);
201          putchar('\n');
202 <        fputresolu(YMAJOR|YDECR, xres, yres, stdout);
202 >        fprtresolu(xres, yres, stdout);
203                                                  /* combine pictures */
204          combine();
205          quit(0);
# Line 198 | Line 207 | usage:
207          eputs("Usage: ");
208          eputs(argv[0]);
209          eputs(
210 < " [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n");
210 > " [-w][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n");
211          quit(1);
212   }
213  
# Line 241 | Line 250 | checkfile()                    /* ready a file */
250                  eputs(": not in Radiance picture format\n");
251                  quit(1);
252          }
253 <        if (fgetresolu(&xinp, &yinp, input[nfiles].fp) != (YMAJOR|YDECR)) {
253 >        if (fgetresolu(&xinp, &yinp, input[nfiles].fp) < 0) {
254                  eputs(input[nfiles].name);
255                  eputs(": bad picture size\n");
256                  quit(1);
# Line 338 | Line 347 | combine()                      /* combine pictures */
347  
348   advance()                       /* read in data for next scanline */
349   {
350 +        extern double  fabs();
351          int     ytarget;
352          register COLOR  *st;
353          register int    i, j;
# Line 350 | Line 360 | advance()                      /* read in data for next scanline */
360                          input[i].scan[0] = st;
361                          if (yscan <= MIDSCN)            /* hit bottom? */
362                                  continue;
363 <                        if (freadscan(st, xmax, input[i].fp) < 0) {     /* read */
363 >                        if (freadscan(st, xmax, input[i].fp) < 0) {  /* read */
364                                  eputs(input[i].name);
365                                  eputs(": read error\n");
366                                  quit(1);
367                          }
368 <                        for (j = 0; j < xmax; j++)      /* adjust color */
369 <                                multcolor(st[j], input[i].coef);
368 >                        if (fabs(colval(input[i].coef,RED)-1.0) > 1e-3 ||
369 >                                fabs(colval(input[i].coef,GRN)-1.0) > 1e-3 ||
370 >                                fabs(colval(input[i].coef,BLU)-1.0) > 1e-3)
371 >                                for (j = 0; j < xmax; j++)  /* adjust color */
372 >                                        multcolor(st[j], input[i].coef);
373                  }
374   }
375  
# Line 453 | Line 466 | char   *msg;
466   }
467  
468  
469 < quit(code)
470 < int     code;
469 > quit(code)              /* exit gracefully */
470 > int  code;
471   {
472 +        register int  i;
473 +                                /* close input files */
474 +        for (i = 0; i < nfiles; i++)
475 +                if (input[i].name == Command)
476 +                        pclose(input[i].fp);
477 +                else
478 +                        fclose(input[i].fp);
479          exit(code);
480   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines