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

Comparing ray/src/px/pcomb.c (file contents):
Revision 2.56 by greg, Mon Nov 20 21:44:29 2023 UTC vs.
Revision 2.58 by greg, Mon Dec 11 15:13:39 2023 UTC

# Line 23 | Line 23 | struct {
23          FILE    *fp;            /* stream pointer */
24          VIEW    vw;             /* view for picture */
25          RESOLU  rs;             /* image resolution and orientation */
26 +        int     infloat;        /* input is floating point (#comp)? */
27          float   pa;             /* pixel aspect ratio */
28          COLOR   *scan[WINSIZ];  /* input scanline window */
29          COLOR   coef;           /* coefficient */
# Line 34 | Line 35 | int    nfiles;                         /* number of input files */
35   VIEW    *commvp = NULL;                 /* common view parameters */
36  
37   char    ourfmt[MAXFMTLEN] = PICFMT;     /* input picture format */
38 + int     outfloat = 0;                   /* #component float output? */
39  
40   char    StandardInput[] = "<stdin>";
41   char    Command[] = "<Command>";
# Line 120 | Line 122 | main(
122                                  echoheader = !echoheader;
123                                  continue;
124                          case 'f':
125 +                                if (argv[a][2]) {
126 +                                        outfloat = (argv[a][2] == 'f');
127 +                                        continue;
128 +                                }
129 +                                /* fall through */
130                          case 'e':
131                                  a++;
132                                  continue;
# Line 198 | Line 205 | main(
205                          case 'h':
206                                  continue;
207                          case 'f':
208 +                                if (argv[a][2])
209 +                                        continue;
210                                  fpath = getpath(argv[++a], getrlibpath(), 0);
211                                  if (fpath == NULL) {
212                                          eputs(argv[0]);
# Line 222 | Line 231 | main(
231                  eputs(": illegal output resolution\n");
232                  quit(1);
233          }
234 <                                                /* complete header */
235 <        printargs(argc, argv, stdout);
234 >        if (!vardefined(vbrtout))               /* single or 3-channel? */
235 >                outfloat *= 3;
236 >
237 >        printargs(argc, argv, stdout);          /* complete header */
238          if (commvp != NULL) {
239                  fputs(VIEWSTR, stdout);
240                  fprintview(commvp, stdout);
241                  fputc('\n', stdout);
242          }
243 <        if (strcmp(ourfmt, PICFMT))
244 <                fputformat(ourfmt, stdout);     /* print format if known */
245 <        putchar('\n');
246 <        fprtresolu(xres, yres, stdout);
247 <                                                /* combine pictures */
248 <        combine();
243 >        if (outfloat) {                         /* print format if known */
244 >                printf("NROWS=%d\nNCOLS=%d\n", yres, xres);
245 >                fputncomp(outfloat, stdout);
246 >                fputendian(stdout);
247 >                fputformat("float", stdout);
248 >        } else if (strcmp(ourfmt, PICFMT))
249 >                fputformat(ourfmt, stdout);
250 >        fputc('\n', stdout);                    /* end header */
251 >        if (!outfloat)
252 >                fprtresolu(xres, yres, stdout);
253 >
254 >        combine();                              /* combine pictures */
255          quit(0);
256   usage:
257          eputs("Usage: ");
258          eputs(argv[0]);
259          eputs(
260 < " [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] hdr ..]\n");
260 > " [-w][-h][-ff][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] hdr ..]\n");
261          quit(1);
262          return 1; /* pro forma return */
263   }
# Line 255 | Line 272 | headline(                      /* check header line & echo if requested *
272          int     orig = *(int *)p;
273          char    fmt[MAXFMTLEN];
274          double  d;
275 +        int     bigend;
276          COLOR   ctmp;
277  
278          if (isheadid(s))                        /* header id */
# Line 263 | Line 281 | headline(                      /* check header line & echo if requested *
281                  if (globmatch(ourfmt, fmt)) {
282                          wrongformat = 0;
283                          strcpy(ourfmt, fmt);
284 <                } else
284 >                } else if (!strcmp("float", fmt))
285 >                        input[nfiles].infloat *= -1;
286 >                else
287                          wrongformat = globmatch(PICFMT, fmt) ? 1 : -1;
288                  return(0);      /* don't echo */
289          }
290 +        if ((bigend = isbigendian(s)) >= 0) {
291 +                if (bigend != nativebigendian()) {
292 +                        eputs(input[nfiles].name);
293 +                        eputs(": unsupported input byte ordering\n");
294 +                        quit(1);
295 +                }
296 +                return(0);      /* don't echo */
297 +        }
298 +        if (!strncmp("NROWS=", s, 6)) {         /* X-resolution */
299 +                input[nfiles].rs.yr = atoi(s+6);
300 +                return(0);      /* don't echo */
301 +        }
302 +        if (!strncmp("NCOLS=", s, 6)) {         /* Y-resolution */
303 +                input[nfiles].rs.xr = atoi(s+6);
304 +                return(0);      /* don't echo */
305 +        }
306 +        if (isncomp(s))                         /* # components */
307 +                input[nfiles].infloat *= ncompval(s);
308 +
309          if (orig) {                             /* undo exposure? */
310                  if (isexpos(s)) {
311                          d = 1./exposval(s);
# Line 306 | Line 345 | checkfile(int orig)                    /* ready a file */
345          int     i;
346                                          /* process header */
347          gotview = 0;
348 +        input[nfiles].infloat = -1;
349 +        input[nfiles].rs.rt = PIXSTANDARD;
350 +        input[nfiles].rs.xr = input[nfiles].rs.yr = 0;
351          if (echoheader) {
352                  fputs(input[nfiles].name, stdout);
353                  fputs(":\n", stdout);
354          }
355          getheader(input[nfiles].fp, headline, &orig);
356 +
357 +        if (input[nfiles].infloat <= 0)
358 +                input[nfiles].infloat = 0;
359 +        else if ((input[nfiles].infloat != 3) &
360 +                                (input[nfiles].infloat != 1)) {
361 +                eputs(input[nfiles].name);
362 +                eputs(": unsupported number of components\n");
363 +                quit(1);
364 +        }
365          if (wrongformat < 0) {
366                  eputs(input[nfiles].name);
367 <                eputs(": not a Radiance picture\n");
367 >                eputs(": not a Radiance picture or float matrix\n");
368                  quit(1);
369          }
370          if (wrongformat > 0) {
# Line 324 | Line 375 | checkfile(int orig)                    /* ready a file */
375                  input[nfiles].vw.type = 0;
376          else if (commvp == NULL)
377                  commvp = &input[nfiles].vw;
378 <        if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) {
378 >        if ((input[nfiles].rs.xr <= 0) | (input[nfiles].rs.yr <= 0) &&
379 >                        !fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) {
380                  eputs(input[nfiles].name);
381                  eputs(": bad picture size\n");
382                  quit(1);
# Line 401 | Line 453 | static void
453   combine(void)                   /* combine pictures */
454   {
455          EPNODE  *coldef[3], *brtdef;
456 +        int     set_x, set_y;
457          COLOR   *scanout;
458          double  d;
459          int     i, j;
# Line 415 | Line 468 | combine(void)                  /* combine pictures */
468                  brtdef = eparse(vbrtout);
469          else
470                  brtdef = NULL;
471 +                                                /* what to set */
472 +        set_x = varlookup(vxpos) != NULL && !vardefined(vxpos);
473 +        set_y = varlookup(vypos) != NULL && !vardefined(vypos);
474                                                  /* allocate scanline */
475          scanout = (COLOR *)emalloc(xres*sizeof(COLOR));
476                                                  /* set input position */
# Line 422 | Line 478 | combine(void)                  /* combine pictures */
478                                                  /* combine files */
479          for (ypos = yres-1; ypos >= 0; ypos--) {
480              advance();
481 <            varset(vypos, '=', (double)ypos);
481 >            if (set_y) varset(vypos, '=', (double)ypos);
482              for (xpos = 0; xpos < xres; xpos++) {
483                  xscan = (xpos+.5)*xmax/xres;
484 <                varset(vxpos, '=', (double)xpos);
484 >                if (set_x) varset(vxpos, '=', (double)xpos);
485                  eclock++;
486                  if (brtdef != NULL) {
487                      d = evalue(brtdef);
488 <                    if (d < 0.0)
433 <                        d = 0.0;
488 >                    d *= (outfloat > 0) | (d >= 0);
489                      setcolor(scanout[xpos], d, d, d);
490                  } else {
491                      for (j = 0; j < 3; j++) {
# Line 441 | Line 496 | combine(void)                  /* combine pictures */
496                              for (i = 0; i < nfiles; i++)
497                                  d += colval(input[i].scan[MIDSCN][xscan],j);
498                          }
499 <                        if (d < 0.0)
445 <                            d = 0.0;
499 >                        d *= (outfloat > 0) | (d >= 0);
500                          colval(scanout[xpos],j) = d;
501                      }
502                  }
503              }
504 <            if (fwritescan(scanout, xres, stdout) < 0) {
505 <                    perror("write error");
506 <                    quit(1);
504 >            switch (outfloat) {
505 >            case 3:                     /* writing out float triplets */
506 >                if (fwrite(scanout, sizeof(float)*3, xres, stdout) != xres)
507 >                    goto writerr;
508 >                break;
509 >            case 1:                     /* writing out gray float values */
510 >                for (xpos = 0; xpos < xres; xpos++)
511 >                    if (putbinary(&scanout[xpos][CIEY],
512 >                                sizeof(float), 1, stdout) != 1)
513 >                        goto writerr;
514 >                break;
515 >            default:                    /* writing out Radiance picture */
516 >                if (fwritescan(scanout, xres, stdout) < 0)
517 >                    goto writerr;
518 >                break;
519              }
520          }
521          efree((char *)scanout);
522 +        return;
523 + writerr:
524 +    perror("write error");
525 +    quit(1);
526   }
527  
528  
# Line 471 | Line 541 | advance(void)                  /* read in data for next scanline */
541                          input[i].scan[0] = st;
542                          if (yscan <= MIDSCN)            /* hit bottom? */
543                                  continue;
544 <                        if (freadscan(st, xmax, input[i].fp) < 0) {  /* read */
545 <                                eputs(input[i].name);
546 <                                eputs(": read error\n");
547 <                                quit(1);
548 <                        }
544 >                                                         /* read scanline */
545 >                        if (input[i].infloat) {
546 >                                if (fread(st, sizeof(float)*input[i].infloat,
547 >                                                xmax, input[i].fp) != xmax)
548 >                                        goto readerr;
549 >                                if (input[i].infloat == 1) {
550 >                                        const COLORV    *f = st[0] + xmax;
551 >                                        int             x = xmax;
552 >                                        while (x-- > 0)
553 >                                                st[x][BLU] = st[x][GRN] =
554 >                                                        st[x][RED] = *--f;
555 >                                }
556 >                        } else if (freadscan(st, xmax, input[i].fp) < 0)
557 >                                goto readerr;
558                          for (j = 0; j < xmax; j++)      /* adjust color */
559                                  multcolor(st[j], input[i].coef);
560                  }
561 +        return;
562 + readerr:
563 +        eputs(input[i].name);
564 +        eputs(": read error\n");
565 +        quit(1);
566   }
567  
568  
# Line 609 | Line 693 | l_ray(         /* return ray origin or direction */
693                  return((double)nfiles);
694          fn = d - 0.5;
695          if (ltick[fn] != eclock) {              /* need to compute? */
696 <                lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0;
697 <                ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0;
698 <                ldist[fn] = -1.0;
699 <                if (input[fn].vw.type == 0)
696 >                if (input[fn].vw.type == 0) {
697 >                        lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0;
698 >                        ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0;
699 >                        ldist[fn] = -1.0;
700                          errno = EDOM;
701 <                else {
701 >                } else {
702                          pix2loc(loc, &input[fn].rs, xscan, ymax-1-yscan);
703                          ldist[fn] = viewray(lorg[fn], ldir[fn],
704                                          &input[fn].vw, loc[0], loc[1]);
705 +                        if (ldist[fn] < -FTINY)
706 +                                errno = EDOM;
707                  }
708                  ltick[fn] = eclock;
709          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines