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.18 by greg, Mon Oct 28 08:10:18 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 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 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  wrongformat = 0;
57 +
58   int  xrad;                      /* x window size */
59   int  yrad;                      /* y window size */
60  
# Line 64 | Line 72 | char  **argv;
72          extern char  *mktemp();
73          extern double  atof(), pow();
74          extern long  ftell();
75 <        extern int  quit();
75 >        extern int  quit(), headline();
76          FILE  *fin;
77 +        float  *lampcolor;
78 +        char  *lamptype = NULL;
79          long  fpos;
80 +        double  outaspect = 0.0;
81          double  d;
82 <        int  i;
82 >        int  i, j;
83  
84          if (signal(SIGINT, quit) == SIG_IGN)
85                  signal(SIGINT, SIG_IGN);
# Line 88 | Line 99 | char  **argv;
99                          switch (argv[i][1]) {
100                          case 'x':
101                                  i++;
102 <                                if (argv[i][0] == '/')
102 >                                if (argv[i][0] == '/') {
103                                          x_c = 1.0/atof(argv[i]+1);
104 <                                else
104 >                                        ncols = 0;
105 >                                } else
106                                          ncols = atoi(argv[i]);
107                                  break;
108                          case 'y':
109                                  i++;
110 <                                if (argv[i][0] == '/')
110 >                                if (argv[i][0] == '/') {
111                                          y_r = 1.0/atof(argv[i]+1);
112 <                                else
112 >                                        nrows = 0;
113 >                                } else
114                                          nrows = atoi(argv[i]);
115                                  break;
116 +                        case 'c':
117 +                                correctaspect = !correctaspect;
118 +                                break;
119 +                        case 'p':
120 +                                i++;
121 +                                outaspect = atof(argv[i]);
122 +                                break;
123                          case 'e':
124                                  if (argv[i+1][0] == '+' || argv[i+1][0] == '-')
125                                          d = pow(2.0, atof(argv[i+1]));
126                                  else
127                                          d = atof(argv[i+1]);
128 +                                if (d < 1e-20 || d > 1e20) {
129 +                                        fprintf(stderr,
130 +                                                "%s: exposure out of range\n",
131 +                                                        argv[0]);
132 +                                        exit(1);
133 +                                }
134                                  switch (argv[i][2]) {
135                                  case '\0':
136                                          scalecolor(exposure, d);
# Line 123 | Line 149 | char  **argv;
149                                  }
150                                  i++;
151                                  break;
152 +                        case 'f':
153 +                                lampdat = argv[++i];
154 +                                break;
155 +                        case 't':
156 +                                lamptype = argv[++i];
157 +                                break;
158                          case '1':
159                                  singlepass = 1;
160                                  break;
161 <                        case 'p':
161 >                        case '2':
162 >                                singlepass = 0;
163 >                                break;
164 >                        case 'n':
165                                  npts = atoi(argv[++i]) / 2;
166                                  break;
167                          case 's':
# Line 153 | Line 188 | char  **argv;
188                          }
189                  else
190                          break;
191 <                        
191 >                                        /* get lamp data (if necessary) */
192 >        if (lamptype != NULL) {
193 >                if (loadlamps(lampdat) < 0)
194 >                        quit(1);
195 >                if ((lampcolor = matchlamp(lamptype)) == NULL) {
196 >                        fprintf(stderr, "%s: unknown lamp type\n", lamptype);
197 >                        quit(1);
198 >                }
199 >                for (i = 0; i < 3; i++)
200 >                        if (lampcolor[i] > 1e-4)
201 >                                colval(exposure,i) /= lampcolor[i];
202 >                freelamps();
203 >        }
204 >                                        /* open input file */
205          if (i == argc) {
206                  if (singlepass)
207                          fin = stdin;
# Line 180 | Line 228 | char  **argv;
228                  fprintf(stderr, "%s: bad # file arguments\n", progname);
229                  quit(1);
230          }
231 <                                        /* copy header */
232 <        copyheader(fin, stdout);
231 >                                        /* get header */
232 >        getheader(fin, headline, NULL);
233 >        if (wrongformat) {
234 >                fprintf(stderr, "%s: input must be a Radiance picture\n",
235 >                                progname);
236 >                quit(1);
237 >        }
238                                          /* add new header info. */
239          printargs(i, argv, stdout);
240                                          /* get picture size */
241 <        if (fscanf(fin, "-Y %d +X %d\n", &yres, &xres) != 2) {
241 >        if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) {
242                  fprintf(stderr, "%s: bad picture size\n", progname);
243                  quit(1);
244          }
245 <        if (ncols > 0)
246 <                x_c = (double)ncols/xres;
194 <        else
245 >                                        /* compute output resolution */
246 >        if (ncols <= 0)
247                  ncols = x_c*xres + .5;
248 <        if (nrows > 0)
197 <                y_r = (double)nrows/yres;
198 <        else
248 >        if (nrows <= 0)
249                  nrows = y_r*yres + .5;
250 +        if (outaspect > .01) {
251 +                d = inpaspect * yres/xres / outaspect;
252 +                if (d * ncols > nrows)
253 +                        ncols = nrows / d;
254 +                else
255 +                        nrows = ncols * d;
256 +        }
257 +        x_c = (double)ncols/xres;
258 +        y_r = (double)nrows/yres;
259  
260 <        if (singlepass) {
202 <                                        /* skip exposure, etc. */
260 >        if (singlepass) {               /* skip exposure, etc. */
261                  pass1default();
262                  pass2(fin);
263                  quit(0);
# Line 219 | Line 277 | char  **argv;
277   }
278  
279  
280 + headline(s)                             /* process line from header */
281 + char  *s;
282 + {
283 +        char  fmt[32];
284 +
285 +        fputs(s, stdout);               /* copy to output */
286 +        if (isaspect(s))                /* get aspect ratio */
287 +                inpaspect *= aspectval(s);
288 +        else if (isformat(s)) {
289 +                formatval(fmt, s);
290 +                wrongformat = strcmp(fmt, COLRFMT);
291 +        }
292 + }
293 +
294 +
295   copyfile(in, out)                       /* copy a file */
296   register FILE  *in, *out;
297   {
# Line 257 | Line 330 | FILE  *in;
330                          fprintf(stderr, "%s: warning - partial frame (%d%%)\n",
331                                          progname, 100*i/yres);
332                          yres = i;
333 +                        y_r = (double)nrows/yres;
334                          break;
335                  }
336                  pass1scan(scan, i);
# Line 302 | Line 376 | FILE  *in;
376                          quit(1);
377                  }
378          }
379 +                                        /* skip leftovers */
380 +        while (yread < yres) {
381 +                if (freadscan(scanin[0], xres, in) < 0)
382 +                        break;
383 +                yread++;
384 +        }
385   }
386  
387  
388   scan2init()                     /* prepare scanline arrays */
389   {
390 <        double  e;
390 >        COLOR   ctmp;
391 >        double  d;
392          register int  i;
393  
394          if (rad <= 0.0) {
# Line 322 | Line 403 | scan2init()                    /* prepare scanline arrays */
403  
404                  initmask();             /* initialize filter table */
405          }
406 <        barsize = 2 * yrad;
406 >        barsize = 2*yrad + 1;
407          scanin = (COLOR **)malloc(barsize*sizeof(COLOR *));
408          for (i = 0; i < barsize; i++) {
409                  scanin[i] = (COLOR *)malloc(xres*sizeof(COLOR));
# Line 336 | Line 417 | scan2init()                    /* prepare scanline arrays */
417                  fprintf(stderr, "%s: out of memory\n", progname);
418                  quit(1);
419          }
420 <        e = bright(exposure);
421 <        if (e < 1-1e-7 || e > 1+1e-7)           /* record exposure */
422 <                printf("EXPOSURE=%e\n", e);
420 >                                        /* record pixel aspect ratio */
421 >        if (!correctaspect) {
422 >                d = x_c / y_r;
423 >                if (!FEQ(d,1.0))
424 >                        fputaspect(d, stdout);
425 >        }
426 >                                        /* record exposure */
427 >        d = bright(exposure);
428 >        if (!FEQ(d,1.0))
429 >                fputexpos(d, stdout);
430 >                                        /* record color correction */
431 >        copycolor(ctmp, exposure);
432 >        scalecolor(ctmp, 1.0/d);
433 >        if (!FEQ(colval(ctmp,RED),colval(ctmp,GRN)) ||
434 >                        !FEQ(colval(ctmp,GRN),colval(ctmp,BLU)))
435 >                fputcolcor(ctmp, stdout);
436          printf("\n");
437 <        printf("-Y %d +X %d\n", nrows, ncols);  /* write picture size */
437 >                                        /* write out resolution */
438 >        fputresolu(YMAJOR|YDECR, ncols, nrows, stdout);
439   }
440  
441  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines