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 2.9 by greg, Fri Jun 25 15:01:17 1993 UTC vs.
Revision 2.20 by gwlarson, Tue Oct 27 09:08:26 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1992 Regents of the University of California */
1 > /* Copyright (c) 1996 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 17 | Line 17 | static char SCCSid[] = "$SunId$ LBL";
17  
18   #include  "color.h"
19  
20 + #include  "view.h"
21 +
22   #include  "resolu.h"
23  
24   #include  "paths.h"
# Line 53 | Line 55 | double spread = 1e-4;          /* spread for star points */
55  
56   char  *tfname = NULL;
57  
58 + char  template[] = TEMPLATE;
59 +
60   char  *lampdat = "lamp.tab";    /* lamp data file */
61  
62   int  order;                     /* scanline ordering of input */
# Line 62 | Line 66 | int  correctaspect = 0;                /* aspect ratio correction? *
66  
67   int  wrongformat = 0;
68  
69 + VIEW  ourview = STDVIEW;
70 + int  gotview = 0;
71 + int  wrapfilt = 0;              /* wrap filter horizontally? */
72 +
73 + int  estatus = 0;               /* exit status (for non-fatal errors) */
74 +
75   int  xrad;                      /* x search radius */
76   int  yrad;                      /* y search radius */
77   int  xbrad;                     /* x box size */
# Line 100 | Line 110 | char  **argv;
110          if (signal(SIGINT, quit) == SIG_IGN)
111                  signal(SIGINT, SIG_IGN);
112          if (signal(SIGHUP, quit) == SIG_IGN)
113 <                signal(SIGINT, SIG_IGN);
113 >                signal(SIGHUP, SIG_IGN);
114          signal(SIGTERM, quit);
115          signal(SIGPIPE, quit);
116   #ifdef  SIGXCPU
# Line 145 | Line 155 | char  **argv;
155                                          fprintf(stderr,
156                                                  "%s: exposure out of range\n",
157                                                          argv[0]);
158 <                                        exit(1);
158 >                                        quit(1);
159                                  }
160                                  switch (argv[i][2]) {
161                                  case '\0':
# Line 217 | Line 227 | char  **argv;
227                          fprintf(stderr, "%s: unknown lamp type\n", lamptype);
228                          quit(1);
229                  }
230 <                for (i = 0; i < 3; i++)
231 <                        if (lampcolor[i] > 1e-4)
232 <                                colval(exposure,i) /= lampcolor[i];
230 >                for (j = 0; j < 3; j++)
231 >                        if (lampcolor[j] > 1e-4)
232 >                                colval(exposure,j) /= lampcolor[j];
233                  freelamps();
234          }
235                                          /* open input file */
# Line 227 | Line 237 | char  **argv;
237                  if (singlepass)
238                          fin = stdin;
239                  else {
240 <                        tfname = mktemp(TEMPLATE);
240 >                        tfname = mktemp(template);
241                          if ((fin = fopen(tfname, "w+")) == NULL) {
242                                  fprintf(stderr, "%s: can't create ", progname);
243                                  fprintf(stderr, "temp file \"%s\"\n", tfname);
# Line 265 | Line 275 | char  **argv;
275          }
276          if (!(order & YMAJOR))
277                  inpaspect = 1.0/inpaspect;
278 +                                        /* wrap around for cylindrical view? */
279 +        wrapfilt = gotview && ourview.type == VT_CYL &&
280 +                        ourview.horiz >= 360.-FTINY && order & YMAJOR;
281                                          /* compute output resolution */
282          if (ncols <= 0)
283                  ncols = x_c*xres + .5;
# Line 296 | Line 309 | char  **argv;
309          }
310          pass2(fin);
311  
312 <        quit(0);
312 >        quit(estatus);
313   }
314  
315  
316 + double
317 + rgb_bright(clr)
318 + COLOR  clr;
319 + {
320 +        return(bright(clr));
321 + }
322 +
323 +
324 + double
325 + xyz_bright(clr)
326 + COLOR  clr;
327 + {
328 +        return(clr[CIEY]);
329 + }
330 +
331 +
332 + double  (*ourbright)() = rgb_bright;
333 +
334 +
335 + int
336   headline(s)                             /* process line from header */
337   char  *s;
338   {
# Line 308 | Line 341 | char  *s;
341          fputs(s, stdout);               /* copy to output */
342          if (isaspect(s))                /* get aspect ratio */
343                  inpaspect *= aspectval(s);
344 <        else if (isexpos(s))
344 >        else if (isexpos(s))            /* get exposure */
345                  hotlvl *= exposval(s);
346 <        else if (isformat(s)) {
347 <                formatval(fmt, s);
348 <                wrongformat = strcmp(fmt, COLRFMT);
349 <        }
346 >        else if (formatval(fmt, s)) {   /* get format */
347 >                wrongformat = 0;
348 >                if (!strcmp(COLRFMT, fmt))
349 >                        ourbright = rgb_bright;
350 >                else if (!strcmp(CIEFMT, fmt))
351 >                        ourbright = xyz_bright;
352 >                else
353 >                        wrongformat = !globmatch(PICFMT, fmt);
354 >        } else if (isview(s) && sscanview(&ourview, s) > 0)
355 >                gotview++;
356 >        return(0);
357   }
358  
359  
# Line 356 | Line 396 | FILE  *in;
396                                          progname, (int)(100L*i/yres));
397                          yres = i;
398                          y_r = (double)nrows/yres;
399 +                        estatus++;
400                          break;
401                  }
402                  pass1scan(scan, i);
# Line 375 | Line 416 | FILE  *in;
416          scan2init();
417          yread = 0;
418          for (r = 0; r < nrows; r++) {
419 <                ycent = (long)r*yres/nrows;
419 >                ycent = (r+.5)*yres/nrows;
420                  while (yread <= ycent+yrad) {
421                          if (yread < yres) {
422                                  if (freadscan(scanin[yread%barsize],
423                                                  xres, in) < 0) {
424                                          fprintf(stderr,
425 <                                                "%s: bad read (y=%d)\n",
425 >                                                "%s: truncated input (y=%d)\n",
426                                                  progname, yres-1-yread);
427                                          quit(1);
428                                  }
# Line 392 | Line 433 | FILE  *in;
433                  if (obarsize > 0)
434                          scan2sync(r);
435                  for (c = 0; c < ncols; c++) {
436 <                        xcent = (long)c*xres/ncols;
436 >                        xcent = (c+.5)*xres/ncols;
437                          if (thresh > FTINY)
438                                  dothresh(xcent, ycent, c, r);
439                          else if (rad > FTINY)
# Line 428 | Line 469 | scan2init()                    /* prepare scanline arrays */
469                          rad *= (y_r + x_c)/2.0;
470  
471                  if (thresh > FTINY) {
431                        xrad = CHECKRAD*THRESHRAD*rad/x_c + xbrad;
432                        yrad = CHECKRAD*THRESHRAD*rad/y_r + ybrad;
472                          orad = CHECKRAD*THRESHRAD*rad + 1;
473 +                        xrad = orad/x_c + xbrad;
474 +                        yrad = orad/y_r + ybrad;
475                          obarsize = 2*orad + 1;
476                  } else {
477                          xrad = CHECKRAD*rad/x_c + 1;
# Line 443 | Line 484 | scan2init()                    /* prepare scanline arrays */
484          }
485          barsize = 2*yrad + 1;
486          scanin = (COLOR **)malloc(barsize*sizeof(COLOR *));
487 +        if (scanin == NULL)
488 +                goto memerr;
489          for (i = 0; i < barsize; i++) {
490                  scanin[i] = (COLOR *)malloc(xres*sizeof(COLOR));
491 <                if (scanin[i] == NULL) {
492 <                        fprintf(stderr, "%s: out of memory\n", progname);
450 <                        quit(1);
451 <                }
491 >                if (scanin[i] == NULL)
492 >                        goto memerr;
493          }
494          if (obarsize > 0) {
495                  scoutbar = (COLOR **)malloc(obarsize*sizeof(COLOR *));
496                  greybar = (float **)malloc(obarsize*sizeof(float *));
497 +                if (scoutbar == NULL | greybar == NULL)
498 +                        goto memerr;
499                  for (i = 0; i < obarsize; i++) {
500                          scoutbar[i] = (COLOR *)malloc(ncols*sizeof(COLOR));
501                          greybar[i] = (float *)malloc(ncols*sizeof(float));
502 <                        if (scoutbar[i] == NULL | greybar[i] == NULL) {
503 <                                fprintf(stderr, "%s: out of memory\n",
461 <                                                progname);
462 <                                quit(1);
463 <                        }
502 >                        if (scoutbar[i] == NULL | greybar[i] == NULL)
503 >                                goto memerr;
504                  }
505          } else {
506                  scanout = (COLOR *)malloc(ncols*sizeof(COLOR));
507 <                if (scanout == NULL) {
508 <                        fprintf(stderr, "%s: out of memory\n", progname);
469 <                        quit(1);
470 <                }
507 >                if (scanout == NULL)
508 >                        goto memerr;
509          }
510                                          /* record pixel aspect ratio */
511          if (!correctaspect) {
# Line 476 | Line 514 | scan2init()                    /* prepare scanline arrays */
514                          fputaspect(d, stdout);
515          }
516                                          /* record exposure */
517 <        d = bright(exposure);
517 >        d = (*ourbright)(exposure);
518          if (!FEQ(d,1.0))
519                  fputexpos(d, stdout);
520                                          /* record color correction */
# Line 488 | Line 526 | scan2init()                    /* prepare scanline arrays */
526          printf("\n");
527                                          /* write out resolution */
528          fputresolu(order, ncols, nrows, stdout);
529 +        return;
530 + memerr:
531 +        fprintf(stderr, "%s: out of memory\n", progname);
532 +        quit(1);
533   }
534  
535  
# Line 499 | Line 541 | int  r;
541          int  ybot;
542          register int  c;
543                                          /* average input scanlines */
544 <        while (nextrow < r+orad && nextrow < nrows) {
545 <                ybot = (long)nextrow*yres/nrows;
544 >        while (nextrow <= r+orad && nextrow < nrows) {
545 >                ybot = (nextrow+.5)*yres/nrows;
546                  for (c = 0; c < ncols; c++) {
547 <                        dobox(ctmp, (int)((long)c*xres/ncols),ybot, c,nextrow);
548 <                        greybar[nextrow%obarsize][c] = bright(ctmp);
547 >                        dobox(ctmp, (int)((c+.5)*xres/ncols),ybot, c,nextrow);
548 >                        greybar[nextrow%obarsize][c] = (*ourbright)(ctmp);
549                  }
550                                          /* and zero output scanline */
551                  bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR));
# Line 526 | Line 568 | scan2flush()                   /* flush output buffer */
568                          break;
569          if (fflush(stdout) < 0) {
570                  fprintf(stderr, "%s: write error at end of pass2\n", progname);
571 <                exit(1);
571 >                quit(1);
572          }
573   }
574  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines