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

Comparing ray/src/px/pfilt.c (file contents):
Revision 1.4 by greg, Tue Apr 11 21:50:05 1989 UTC vs.
Revision 1.15 by greg, Fri Dec 14 16:33:16 1990 UTC

# Line 16 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16  
17   #include  "color.h"
18  
19
19   extern char  *malloc();
20 + extern float  *matchlamp();
21  
22 + #define  FEQ(a,b)       ((a) >= .98*(b) && (a) <= 1.02*(b))
23 +
24   #define  CHECKRAD       1.5     /* radius to check for filtering */
25  
26   COLOR  exposure = WHTCOLOR;     /* exposure for the frame */
# Line 45 | Line 47 | double  spread = 1e-4;         /* spread for star points */
47  
48   char  *tfname = NULL;
49  
50 + char  *lampdat = "lamp.tab";    /* lamp data file */
51 +
52   int  xres, yres;                /* resolution of input */
53 + double  inpaspect = 1.0;        /* pixel aspect ratio of input */
54 + int  correctaspect = 0;         /* aspect ratio correction? */
55  
56   int  xrad;                      /* x window size */
57   int  yrad;                      /* y window size */
# Line 64 | Line 70 | char  **argv;
70          extern char  *mktemp();
71          extern double  atof(), pow();
72          extern long  ftell();
73 <        extern int  quit();
73 >        extern int  quit(), headline();
74          FILE  *fin;
75 +        float  *lampcolor;
76 +        char  *lamptype = NULL;
77          long  fpos;
78 +        double  outaspect = 0.0;
79          double  d;
80          int  i;
81  
# Line 88 | Line 97 | char  **argv;
97                          switch (argv[i][1]) {
98                          case 'x':
99                                  i++;
100 <                                if (argv[i][0] == '/')
100 >                                if (argv[i][0] == '/') {
101                                          x_c = 1.0/atof(argv[i]+1);
102 <                                else
102 >                                        ncols = 0;
103 >                                } else
104                                          ncols = atoi(argv[i]);
105                                  break;
106                          case 'y':
107                                  i++;
108 <                                if (argv[i][0] == '/')
108 >                                if (argv[i][0] == '/') {
109                                          y_r = 1.0/atof(argv[i]+1);
110 <                                else
110 >                                        nrows = 0;
111 >                                } else
112                                          nrows = atoi(argv[i]);
113                                  break;
114 +                        case 'c':
115 +                                correctaspect = !correctaspect;
116 +                                break;
117 +                        case 'p':
118 +                                i++;
119 +                                outaspect = atof(argv[i]);
120 +                                break;
121                          case 'e':
122                                  if (argv[i+1][0] == '+' || argv[i+1][0] == '-')
123                                          d = pow(2.0, atof(argv[i+1]));
124                                  else
125                                          d = atof(argv[i+1]);
126 +                                if (d < 1e-20 || d > 1e20) {
127 +                                        fprintf(stderr,
128 +                                                "%s: exposure out of range\n",
129 +                                                        argv[0]);
130 +                                        exit(1);
131 +                                }
132                                  switch (argv[i][2]) {
133                                  case '\0':
134                                          scalecolor(exposure, d);
# Line 123 | Line 147 | char  **argv;
147                                  }
148                                  i++;
149                                  break;
150 +                        case 'f':
151 +                                lampdat = argv[++i];
152 +                                break;
153 +                        case 't':
154 +                                lamptype = argv[++i];
155 +                                break;
156                          case '1':
157                                  singlepass = 1;
158                                  break;
159 <                        case 'p':
159 >                        case '2':
160 >                                singlepass = 0;
161 >                                break;
162 >                        case 'n':
163                                  npts = atoi(argv[++i]) / 2;
164                                  break;
165                          case 's':
# Line 153 | Line 186 | char  **argv;
186                          }
187                  else
188                          break;
189 <                        
189 >                                        /* get lamp data (if necessary) */
190 >        if (lamptype != NULL) {
191 >                if (loadlamps(lampdat) < 0)
192 >                        quit(1);
193 >                if ((lampcolor = matchlamp(lamptype)) == NULL) {
194 >                        fprintf(stderr, "%s: unknown lamp type\n", lamptype);
195 >                        quit(1);
196 >                }
197 >                colval(exposure,RED) /= lampcolor[0];
198 >                colval(exposure,GRN) /= lampcolor[1];
199 >                colval(exposure,BLU) /= lampcolor[2];
200 >                freelamps();
201 >        }
202 >                                        /* open input file */
203          if (i == argc) {
204                  if (singlepass)
205                          fin = stdin;
# Line 180 | Line 226 | char  **argv;
226                  fprintf(stderr, "%s: bad # file arguments\n", progname);
227                  quit(1);
228          }
229 <                                        /* copy header */
230 <        copyheader(fin, stdout);
229 >                                        /* get header */
230 >        getheader(fin, headline);
231                                          /* add new header info. */
232          printargs(i, argv, stdout);
233                                          /* get picture size */
234 <        if (fscanf(fin, "-Y %d +X %d\n", &yres, &xres) != 2) {
234 >        if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) {
235                  fprintf(stderr, "%s: bad picture size\n", progname);
236                  quit(1);
237          }
238 <        if (ncols > 0)
239 <                x_c = (double)ncols/xres;
194 <        else
238 >                                        /* compute output resolution */
239 >        if (ncols <= 0)
240                  ncols = x_c*xres + .5;
241 <        if (nrows > 0)
197 <                y_r = (double)nrows/yres;
198 <        else
241 >        if (nrows <= 0)
242                  nrows = y_r*yres + .5;
243 +        if (outaspect > .01) {
244 +                d = inpaspect * yres/xres / outaspect;
245 +                if (d * ncols > nrows)
246 +                        ncols = nrows / d;
247 +                else
248 +                        nrows = ncols * d;
249 +        }
250 +        x_c = (double)ncols/xres;
251 +        y_r = (double)nrows/yres;
252  
253 <        if (singlepass) {
202 <                                        /* skip exposure, etc. */
253 >        if (singlepass) {               /* skip exposure, etc. */
254                  pass1default();
255                  pass2(fin);
256                  quit(0);
# Line 219 | Line 270 | char  **argv;
270   }
271  
272  
273 + headline(s)                             /* process line from header */
274 + char  *s;
275 + {
276 +        fputs(s, stdout);               /* copy to output */
277 +        if (isaspect(s))                /* get aspect ratio */
278 +                inpaspect *= aspectval(s);
279 + }
280 +
281 +
282   copyfile(in, out)                       /* copy a file */
283   register FILE  *in, *out;
284   {
# Line 257 | Line 317 | FILE  *in;
317                          fprintf(stderr, "%s: warning - partial frame (%d%%)\n",
318                                          progname, 100*i/yres);
319                          yres = i;
320 +                        y_r = (double)nrows/yres;
321                          break;
322                  }
323                  pass1scan(scan, i);
# Line 302 | Line 363 | FILE  *in;
363                          quit(1);
364                  }
365          }
366 +                                        /* skip leftovers */
367 +        while (yread < yres) {
368 +                if (freadscan(scanin[0], xres, in) < 0)
369 +                        break;
370 +                yread++;
371 +        }
372   }
373  
374  
375   scan2init()                     /* prepare scanline arrays */
376   {
377 <        double  e;
377 >        COLOR   ctmp;
378 >        double  d;
379          register int  i;
380  
381          if (rad <= 0.0) {
# Line 336 | Line 404 | scan2init()                    /* prepare scanline arrays */
404                  fprintf(stderr, "%s: out of memory\n", progname);
405                  quit(1);
406          }
407 <        e = bright(exposure);
408 <        if (e < 1-1e-7 || e > 1+1e-7)           /* record exposure */
409 <                printf("EXPOSURE=%e\n", e);
407 >                                        /* record pixel aspect ratio */
408 >        if (!correctaspect) {
409 >                d = x_c / y_r;
410 >                if (!FEQ(d,1.0))
411 >                        fputaspect(d, stdout);
412 >        }
413 >                                        /* record exposure */
414 >        d = bright(exposure);
415 >        if (!FEQ(d,1.0))
416 >                fputexpos(d, stdout);
417 >                                        /* record color correction */
418 >        copycolor(ctmp, exposure);
419 >        scalecolor(ctmp, 1.0/d);
420 >        if (!FEQ(colval(ctmp,RED),colval(ctmp,GRN)) ||
421 >                        !FEQ(colval(ctmp,GRN),colval(ctmp,BLU)))
422 >                fputcolcor(ctmp, stdout);
423          printf("\n");
424 <        printf("-Y %d +X %d\n", nrows, ncols);  /* write picture size */
424 >                                        /* write out resolution */
425 >        fputresolu(YMAJOR|YDECR, ncols, nrows, stdout);
426   }
427  
428  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines