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.10 by greg, Thu Sep 13 09:46:00 1990 UTC vs.
Revision 2.1 by greg, Tue Nov 12 16:04:27 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 + #include  "resolu.h"
20 +
21   extern char  *malloc();
22 + extern float  *matchlamp();
23  
24 + #define  FEQ(a,b)       ((a) >= .98*(b) && (a) <= 1.02*(b))
25 +
26   #define  CHECKRAD       1.5     /* radius to check for filtering */
27  
28   COLOR  exposure = WHTCOLOR;     /* exposure for the frame */
# Line 44 | Line 49 | double  spread = 1e-4;         /* spread for star points */
49  
50   char  *tfname = NULL;
51  
52 + char  *lampdat = "lamp.tab";    /* lamp data file */
53 +
54 + int  order;                     /* scanline ordering of input */
55   int  xres, yres;                /* resolution of input */
56   double  inpaspect = 1.0;        /* pixel aspect ratio of input */
57 + int  correctaspect = 0;         /* aspect ratio correction? */
58  
59 + int  wrongformat = 0;
60 +
61   int  xrad;                      /* x window size */
62   int  yrad;                      /* y window size */
63  
# Line 66 | Line 77 | char  **argv;
77          extern long  ftell();
78          extern int  quit(), headline();
79          FILE  *fin;
80 +        float  *lampcolor;
81 +        char  *lamptype = NULL;
82          long  fpos;
83          double  outaspect = 0.0;
84          double  d;
85 <        int  i;
85 >        int  i, j;
86  
87          if (signal(SIGINT, quit) == SIG_IGN)
88                  signal(SIGINT, SIG_IGN);
# Line 103 | Line 116 | char  **argv;
116                                  } else
117                                          nrows = atoi(argv[i]);
118                                  break;
119 +                        case 'c':
120 +                                correctaspect = !correctaspect;
121 +                                break;
122                          case 'p':
123                                  i++;
124                                  outaspect = atof(argv[i]);
# Line 112 | Line 128 | char  **argv;
128                                          d = pow(2.0, atof(argv[i+1]));
129                                  else
130                                          d = atof(argv[i+1]);
131 +                                if (d < 1e-20 || d > 1e20) {
132 +                                        fprintf(stderr,
133 +                                                "%s: exposure out of range\n",
134 +                                                        argv[0]);
135 +                                        exit(1);
136 +                                }
137                                  switch (argv[i][2]) {
138                                  case '\0':
139                                          scalecolor(exposure, d);
# Line 130 | Line 152 | char  **argv;
152                                  }
153                                  i++;
154                                  break;
155 +                        case 'f':
156 +                                lampdat = argv[++i];
157 +                                break;
158 +                        case 't':
159 +                                lamptype = argv[++i];
160 +                                break;
161                          case '1':
162                                  singlepass = 1;
163                                  break;
# Line 163 | Line 191 | char  **argv;
191                          }
192                  else
193                          break;
194 <                        
194 >                                        /* get lamp data (if necessary) */
195 >        if (lamptype != NULL) {
196 >                if (loadlamps(lampdat) < 0)
197 >                        quit(1);
198 >                if ((lampcolor = matchlamp(lamptype)) == NULL) {
199 >                        fprintf(stderr, "%s: unknown lamp type\n", lamptype);
200 >                        quit(1);
201 >                }
202 >                for (i = 0; i < 3; i++)
203 >                        if (lampcolor[i] > 1e-4)
204 >                                colval(exposure,i) /= lampcolor[i];
205 >                freelamps();
206 >        }
207 >                                        /* open input file */
208          if (i == argc) {
209                  if (singlepass)
210                          fin = stdin;
# Line 191 | Line 232 | char  **argv;
232                  quit(1);
233          }
234                                          /* get header */
235 <        getheader(fin, headline);
235 >        getheader(fin, headline, NULL);
236 >        if (wrongformat) {
237 >                fprintf(stderr, "%s: input must be a Radiance picture\n",
238 >                                progname);
239 >                quit(1);
240 >        }
241                                          /* add new header info. */
242          printargs(i, argv, stdout);
243                                          /* get picture size */
244 <        if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) {
244 >        if ((order = fgetresolu(&xres, &yres, fin)) < 0) {
245                  fprintf(stderr, "%s: bad picture size\n", progname);
246                  quit(1);
247          }
248 +        if (!(order & YMAJOR))
249 +                inpaspect = 1.0/inpaspect;
250                                          /* compute output resolution */
251          if (ncols <= 0)
252                  ncols = x_c*xres + .5;
# Line 237 | Line 285 | char  **argv;
285   headline(s)                             /* process line from header */
286   char  *s;
287   {
288 +        char  fmt[32];
289 +
290          fputs(s, stdout);               /* copy to output */
291          if (isaspect(s))                /* get aspect ratio */
292                  inpaspect *= aspectval(s);
293 +        else if (isformat(s)) {
294 +                formatval(fmt, s);
295 +                wrongformat = strcmp(fmt, COLRFMT);
296 +        }
297   }
298  
299  
# Line 281 | Line 335 | FILE  *in;
335                          fprintf(stderr, "%s: warning - partial frame (%d%%)\n",
336                                          progname, 100*i/yres);
337                          yres = i;
338 +                        y_r = (double)nrows/yres;
339                          break;
340                  }
341                  pass1scan(scan, i);
# Line 337 | Line 392 | FILE  *in;
392  
393   scan2init()                     /* prepare scanline arrays */
394   {
395 +        COLOR   ctmp;
396          double  d;
397          register int  i;
398  
# Line 352 | Line 408 | scan2init()                    /* prepare scanline arrays */
408  
409                  initmask();             /* initialize filter table */
410          }
411 <        barsize = 2 * yrad;
411 >        barsize = 2*yrad + 1;
412          scanin = (COLOR **)malloc(barsize*sizeof(COLOR *));
413          for (i = 0; i < barsize; i++) {
414                  scanin[i] = (COLOR *)malloc(xres*sizeof(COLOR));
# Line 366 | Line 422 | scan2init()                    /* prepare scanline arrays */
422                  fprintf(stderr, "%s: out of memory\n", progname);
423                  quit(1);
424          }
425 <                                        /* record pixel aspect and exposure */
426 <        d = x_c / y_r;
427 <        if (d < .99 || d > 1.01)
428 <                fputaspect(d, stdout);
425 >                                        /* record pixel aspect ratio */
426 >        if (!correctaspect) {
427 >                d = order & YMAJOR ? x_c/y_r : y_r/x_c ;
428 >                if (!FEQ(d,1.0))
429 >                        fputaspect(d, stdout);
430 >        }
431 >                                        /* record exposure */
432          d = bright(exposure);
433 <        if (d < .995 || d > 1.005)
433 >        if (!FEQ(d,1.0))
434                  fputexpos(d, stdout);
435 +                                        /* record color correction */
436 +        copycolor(ctmp, exposure);
437 +        scalecolor(ctmp, 1.0/d);
438 +        if (!FEQ(colval(ctmp,RED),colval(ctmp,GRN)) ||
439 +                        !FEQ(colval(ctmp,GRN),colval(ctmp,BLU)))
440 +                fputcolcor(ctmp, stdout);
441          printf("\n");
442 <        fputresolu(YMAJOR|YDECR, ncols, nrows, stdout); /* resolution */
442 >                                        /* write out resolution */
443 >        fputresolu(order, ncols, nrows, stdout);
444   }
445  
446  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines