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.35 by greg, Thu Dec 7 21:15:54 2023 UTC vs.
Revision 2.36 by greg, Fri Dec 8 17:56:26 2023 UTC

# Line 69 | Line 69 | int  xbrad;                    /* x box size */
69   int  ybrad;                     /* y box size */
70  
71   int  barsize;                   /* size of input scan bar */
72 < COLOR  **scanin;                /* input scan bar */
73 < COLOR  *scanout;                /* output scan line */
74 < COLOR  **scoutbar;              /* output scan bar (if thresh > 0) */
72 > COLORV  **scanin;               /* input scan bar */
73 > COLORV  *scanout;               /* output scan line */
74 > COLORV  **scoutbar;             /* output scan bar (if thresh > 0) */
75   float  **greybar;               /* grey-averaged input values */
76   int  obarsize = 0;              /* size of output scan bar */
77   int  orad = 0;                  /* output window radius */
# Line 79 | Line 79 | int  orad = 0;                 /* output window radius */
79   char  *progname;
80  
81   static gethfunc headline;
82 static brightfunc_t rgb_bright;
83 static brightfunc_t xyz_bright;
82   static void copyfile(FILE  *in, FILE  *out);
83   static void pass1(FILE  *in);
84   static void pass2(FILE  *in);
# Line 268 | Line 266 | main(
266                                  progname);
267                  quit(1);
268          }
269 +        if (NCSAMP < 3) {
270 +                fprintf(stderr, "%s: bad number of components\n", progname);
271 +                quit(1);
272 +        }
273                                          /* add new header info. */
274          printargs(i, argv, stdout);
275                                          /* get picture size */
# Line 318 | Line 320 | main(
320  
321   static double
322   rgb_bright(
323 <        COLOR  clr
323 >        SCOLOR  clr
324   )
325   {
326          return(bright(clr));
# Line 327 | Line 329 | rgb_bright(
329  
330   static double
331   xyz_bright(
332 <        COLOR  clr
332 >        SCOLOR  clr
333   )
334   {
335 <        return(clr[CIEY]);
335 >        return(colval(clr,CIEY));
336   }
337  
338  
339 + static double
340 + spec_bright(
341 +        SCOLOR  clr
342 + )
343 + {
344 +        return(pbright(clr));
345 + }
346 +
347 +
348   brightfunc_t *ourbright = rgb_bright;
349  
350   static int
# Line 349 | Line 360 | headline(                              /* process line from header */
360                  inpaspect *= aspectval(s);
361          else if (isexpos(s))            /* get exposure */
362                  hotlvl *= exposval(s);
363 +        else if (isncomp(s))            /* get #components (spectral) */
364 +                NCSAMP = ncompval(s);
365 +        else if (iswlsplit(s))          /* get wavelength partitions */
366 +                wlsplitval(WLPART, s);
367          else if (formatval(fmt, s)) {   /* get format */
368                  wrongformat = 0;
369                  if (!strcmp(COLRFMT, fmt))
370                          ourbright = rgb_bright;
371                  else if (!strcmp(CIEFMT, fmt))
372                          ourbright = xyz_bright;
373 +                else if (!strcmp(SPECFMT, fmt))
374 +                        ourbright = spec_bright;
375                  else
376                          wrongformat = !globmatch(PICFMT, fmt);
377          } else if (isview(s) && sscanview(&ourview, s) > 0)
# Line 387 | Line 404 | pass1(                         /* first pass of picture file */
404   )
405   {
406          int  i;
407 <        COLOR  *scan;
407 >        COLORV  *scan;
408  
409          pass1init();
410  
411 <        scan = (COLOR *)malloc(xres*sizeof(COLOR));
411 >        scan = (COLORV *)malloc(xres*NCSAMP*sizeof(COLORV));
412          if (scan == NULL) {
413                  fprintf(stderr, "%s: out of memory\n", progname);
414                  quit(1);
415          }
416          for (i = 0; i < yres; i++) {
417 <                if (freadscan(scan, xres, in) < 0) {
417 >                if (freadsscan(scan, NCSAMP, xres, in) < 0) {
418                          nrows = (long)nrows * i / yres; /* adjust frame */
419                          if (nrows <= 0) {
420                                  fprintf(stderr, "%s: empty frame\n", progname);
# Line 412 | Line 429 | pass1(                         /* first pass of picture file */
429                  }
430                  pass1scan(scan, i);
431          }
432 <        free((void *)scan);
432 >        free(scan);
433   }
434  
435  
# Line 432 | Line 449 | pass2(                 /* last pass on file, write to stdout */
449                  ycent = (r+.5)*yres/nrows;
450                  while (yread <= ycent+yrad) {
451                          if (yread < yres) {
452 <                                if (freadscan(scanin[yread%barsize],
453 <                                                xres, in) < 0) {
452 >                                if (freadsscan(scanin[yread%barsize],
453 >                                                NCSAMP, xres, in) < 0) {
454                                          fprintf(stderr,
455                                                  "%s: truncated input (y=%d)\n",
456                                                  progname, yres-1-yread);
# Line 450 | Line 467 | pass2(                 /* last pass on file, write to stdout */
467                          if (thresh > FTINY)
468                                  dothresh(xcent, ycent, c, r);
469                          else if (rad > FTINY)
470 <                                dogauss(scanout[c], xcent, ycent, c, r);
470 >                                dogauss(scanout+c*NCSAMP, xcent, ycent, c, r);
471                          else
472 <                                dobox(scanout[c], xcent, ycent, c, r);
472 >                                dobox(scanout+c*NCSAMP, xcent, ycent, c, r);
473                  }
474 <                if (scanout != NULL && fwritescan(scanout, ncols, stdout) < 0) {
474 >                if (scanout != NULL && fwritesscan(scanout, NCSAMP, ncols, stdout) < 0) {
475                          fprintf(stderr, "%s: write error in pass2\n", progname);
476                          quit(1);
477                  }
478          }
479                                          /* skip leftover input */
480          while (yread < yres) {
481 <                if (freadscan(scanin[0], xres, in) < 0)
481 >                if (freadsscan(scanin[0], NCSAMP, xres, in) < 0)
482                          break;
483                  yread++;
484          }
# Line 497 | Line 514 | scan2init(void)                        /* prepare scanline arrays */
514                  yrad = ybrad;
515          }
516          barsize = 2*yrad + 1;
517 <        scanin = (COLOR **)malloc(barsize*sizeof(COLOR *));
517 >        scanin = (COLORV **)malloc(barsize*sizeof(COLORV *));
518          if (scanin == NULL)
519                  goto memerr;
520          for (i = 0; i < barsize; i++) {
521 <                scanin[i] = (COLOR *)malloc(xres*sizeof(COLOR));
521 >                scanin[i] = (COLORV *)malloc(xres*NCSAMP*sizeof(COLORV));
522                  if (scanin[i] == NULL)
523                          goto memerr;
524          }
525          if (obarsize > 0) {
526 <                scoutbar = (COLOR **)malloc(obarsize*sizeof(COLOR *));
526 >                scoutbar = (COLORV **)malloc(obarsize*sizeof(COLORV *));
527                  greybar = (float **)malloc(obarsize*sizeof(float *));
528                  if ((scoutbar == NULL) | (greybar == NULL))
529                          goto memerr;
530                  for (i = 0; i < obarsize; i++) {
531 <                        scoutbar[i] = (COLOR *)malloc(ncols*sizeof(COLOR));
531 >                        scoutbar[i] = (COLORV *)malloc(ncols*NCSAMP*sizeof(COLORV));
532                          greybar[i] = (float *)malloc(ncols*sizeof(float));
533                          if ((scoutbar[i] == NULL) | (greybar[i] == NULL))
534                                  goto memerr;
535                  }
536          } else {
537 <                scanout = (COLOR *)malloc(ncols*sizeof(COLOR));
537 >                scanout = (COLORV *)malloc(ncols*NCSAMP*sizeof(COLORV));
538                  if (scanout == NULL)
539                          goto memerr;
540          }
# Line 528 | Line 545 | scan2init(void)                        /* prepare scanline arrays */
545                          fputaspect(d, stdout);
546          }
547                                          /* record exposure */
548 <        d = (*ourbright)(exposure);
548 >        d = bright(exposure);
549          if (!FEQ(d,1.0))
550                  fputexpos(d, stdout);
551                                          /* record color correction */
# Line 553 | Line 570 | scan2sync(                     /* synchronize grey averages and output s
570   )
571   {
572          static int  nextrow = 0;
573 <        COLOR  ctmp;
573 >        SCOLOR  ctmp;
574          int  ybot;
575          int  c;
576                                          /* average input scanlines */
# Line 564 | Line 581 | scan2sync(                     /* synchronize grey averages and output s
581                          greybar[nextrow%obarsize][c] = (*ourbright)(ctmp);
582                  }
583                                          /* and zero output scanline */
584 <                memset((char *)scoutbar[nextrow%obarsize], '\0', ncols*sizeof(COLOR));
584 >                memset(scoutbar[nextrow%obarsize], 0, ncols*NCSAMP*sizeof(COLORV));
585                  nextrow++;
586          }
587                                          /* point to top scanline for output */
# Line 581 | Line 598 | scan2flush(void)                       /* flush output buffer */
598          int  r;
599  
600          for (r = nrows-orad; r < nrows; r++)
601 <                if (fwritescan(scoutbar[r%obarsize], ncols, stdout) < 0)
601 >                if (fwritesscan(scoutbar[r%obarsize], NCSAMP, ncols, stdout) < 0)
602                          break;
603          if (fflush(stdout) < 0) {
604                  fprintf(stderr, "%s: write error at end of pass2\n", progname);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines