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

Comparing ray/src/px/pvalue.c (file contents):
Revision 2.10 by greg, Wed Jan 8 07:43:49 1997 UTC vs.
Revision 2.13 by gwlarson, Tue Oct 27 09:08:27 1998 UTC

# Line 43 | Line 43 | int  header = 1;               /* do header? */
43  
44   long  skipbytes = 0;            /* skip bytes in input? */
45  
46 + int  interleave = 1;            /* file is interleaved? */
47 +
48   int  resolution = 1;            /* put/get resolution string? */
49  
50   int  original = 0;              /* convert to original values? */
# Line 119 | Line 121 | char  **argv;
121                          case 'r':               /* reverse conversion */
122                                  reverse = argv[i][0] == '-';
123                                  break;
124 +                        case 'n':               /* non-interleaved RGB */
125 +                                interleave = argv[i][0] == '+';
126 +                                break;
127                          case 'b':               /* brightness values */
128                                  putprim = argv[i][0] == '-' ? BRIGHT : ALL;
129                                  break;
# Line 205 | Line 210 | unkopt:
210                                                  progname, argv[i]);
211                          quit(1);
212                  }
208                if (skipbytes && fseek(fin, skipbytes, 0))
209                        goto seekerr;
213                  if (reverse && !brightonly && i == argc-3) {
214                          if ((fin2 = fopen(argv[i+1], "r")) == NULL) {
215                                  fprintf(stderr, "%s: can't open file \"%s\"\n",
# Line 218 | Line 221 | unkopt:
221                                                  progname, argv[i+2]);
222                                  quit(1);
223                          }
224 <                        if (skipbytes && (fseek(fin2, skipbytes, 0) ||
222 <                                        fseek(fin3, skipbytes, 0)))
223 <                                goto seekerr;
224 >                        interleave = -1;
225                  } else if (i != argc-1)
226                          fin = NULL;
227 +                if (reverse && !brightonly && !interleave) {
228 +                        fin2 = fopen(argv[i], "r");
229 +                        fin3 = fopen(argv[i], "r");
230 +                }
231 +                if (skipbytes && (fseek(fin, skipbytes, 0) || (fin2 != NULL &&
232 +                                (fseek(fin2, skipbytes, 0) ||
233 +                                fseek(fin3, skipbytes, 0))))) {
234 +                        fprintf(stderr, "%s: cannot skip %ld bytes on input\n",
235 +                                        progname, skipbytes);
236 +                        quit(1);
237 +                }
238          }
239          if (fin == NULL) {
240                  fprintf(stderr, "%s: bad # file arguments\n", progname);
241                  quit(1);
242          }
243  
232        set_io();
233
244          if (reverse) {
245   #ifdef MSDOS
246                  setmode(fileno(stdout), O_BINARY);
# Line 309 | Line 319 | unkopt:
319          }
320  
321          quit(0);
312 seekerr:
313        fprintf(stderr, "%s: cannot skip %ld bytes on input\n",
314                        progname, skipbytes);
315        quit(1);
322   }
323  
324  
325 + int
326   checkhead(line)                         /* deal with line from header */
327   char  *line;
328   {
# Line 337 | Line 344 | char  *line;
344                  doexposure++;
345          } else if (header)
346                  fputs(line, stdout);
347 +        return(0);
348   }
349  
350  
# Line 346 | Line 354 | pixtoval()                             /* convert picture to values */
354          int  dogamma;
355          COLOR  lastc;
356          FLOAT  hv[2];
357 +        int  startprim, endprim;
358 +        long  startpos;
359          int  y;
360          register int  x;
361  
# Line 355 | Line 365 | pixtoval()                             /* convert picture to values */
365                  quit(1);
366          }
367          dogamma = gamcor < .95 || gamcor > 1.05;
368 <        setcolor(lastc, 0.0, 0.0, 0.0);
369 <        for (y = 0; y < numscans(&picres); y++) {
370 <                if (freadscan(scanln, scanlen(&picres), fin) < 0) {
371 <                        fprintf(stderr, "%s: read error\n", progname);
368 >        if (putprim == ALL && !interleave) {
369 >                startprim = RED; endprim = BLU;
370 >                startpos = ftell(fin);
371 >        } else {
372 >                startprim = putprim; endprim = putprim;
373 >        }
374 >        for (putprim = startprim; putprim <= endprim; putprim++) {
375 >                if (putprim != startprim && fseek(fin, startpos, 0)) {
376 >                        fprintf(stderr, "%s: seek error on input file\n",
377 >                                        progname);
378                          quit(1);
379                  }
380 <                for (x = 0; x < scanlen(&picres); x++) {
381 <                        if (uniq)
382 <                                if (    colval(scanln[x],RED) ==
383 <                                                colval(lastc,RED) &&
384 <                                        colval(scanln[x],GRN) ==
369 <                                                colval(lastc,GRN) &&
370 <                                        colval(scanln[x],BLU) ==
371 <                                                colval(lastc,BLU)       )
372 <                                        continue;
373 <                                else
374 <                                        copycolor(lastc, scanln[x]);
375 <                        if (doexposure)
376 <                                multcolor(scanln[x], exposure);
377 <                        if (dogamma)
378 <                                setcolor(scanln[x],
379 <                                pow(colval(scanln[x],RED), 1.0/gamcor),
380 <                                pow(colval(scanln[x],GRN), 1.0/gamcor),
381 <                                pow(colval(scanln[x],BLU), 1.0/gamcor));
382 <                        if (!dataonly) {
383 <                                pix2loc(hv, &picres, x, y);
384 <                                printf("%7d %7d ", (int)(hv[0]*picres.xr),
385 <                                                (int)(hv[1]*picres.yr));
386 <                        }
387 <                        if ((*putval)(scanln[x], stdout) < 0) {
388 <                                fprintf(stderr, "%s: write error\n", progname);
380 >                set_io();
381 >                setcolor(lastc, 0.0, 0.0, 0.0);
382 >                for (y = 0; y < numscans(&picres); y++) {
383 >                        if (freadscan(scanln, scanlen(&picres), fin) < 0) {
384 >                                fprintf(stderr, "%s: read error\n", progname);
385                                  quit(1);
386                          }
387 +                        for (x = 0; x < scanlen(&picres); x++) {
388 +                                if (uniq)
389 +                                        if (    colval(scanln[x],RED) ==
390 +                                                        colval(lastc,RED) &&
391 +                                                colval(scanln[x],GRN) ==
392 +                                                        colval(lastc,GRN) &&
393 +                                                colval(scanln[x],BLU) ==
394 +                                                        colval(lastc,BLU)       )
395 +                                                continue;
396 +                                        else
397 +                                                copycolor(lastc, scanln[x]);
398 +                                if (doexposure)
399 +                                        multcolor(scanln[x], exposure);
400 +                                if (dogamma)
401 +                                        setcolor(scanln[x],
402 +                                        pow(colval(scanln[x],RED), 1.0/gamcor),
403 +                                        pow(colval(scanln[x],GRN), 1.0/gamcor),
404 +                                        pow(colval(scanln[x],BLU), 1.0/gamcor));
405 +                                if (!dataonly) {
406 +                                        pix2loc(hv, &picres, x, y);
407 +                                        printf("%7d %7d ",
408 +                                                        (int)(hv[0]*picres.xr),
409 +                                                        (int)(hv[1]*picres.yr));
410 +                                }
411 +                                if ((*putval)(scanln[x]) < 0) {
412 +                                        fprintf(stderr, "%s: write error\n",
413 +                                                        progname);
414 +                                        quit(1);
415 +                                }
416 +                        }
417                  }
418          }
419          free((char *)scanln);
# Line 407 | Line 433 | valtopix()                     /* convert values to a pixel file */
433                  quit(1);
434          }
435          dogamma = gamcor < .95 || gamcor > 1.05;
436 +        set_io();
437          for (y = 0; y < numscans(&picres); y++) {
438                  for (x = 0; x < scanlen(&picres); x++) {
439                          if (!dataonly) {
# Line 416 | Line 443 | valtopix()                     /* convert values to a pixel file */
443                                          fscanf(fin3, "%*d %*d");
444                                  }
445                          }
446 <                        if ((*getval)(scanln[x], fin, fin2, fin3) < 0) {
446 >                        if ((*getval)(scanln[x]) < 0) {
447                                  fprintf(stderr, "%s: read error\n", progname);
448                                  quit(1);
449                          }
# Line 444 | Line 471 | int  code;
471   }
472  
473  
474 < getcascii(col, f1, f2, f3)      /* get an ascii color value from stream(s) */
474 > getcascii(col)          /* get an ascii color value from stream(s) */
475   COLOR  col;
449 FILE  *f1, *f2, *f3;
476   {
477          double  vd[3];
478  
479 <        if (f2 == NULL) {
480 <                if (fscanf(f1, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3)
479 >        if (fin2 == NULL) {
480 >                if (fscanf(fin, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3)
481                          return(-1);
482          } else {
483 <                if (fscanf(f1, "%lf", &vd[0]) != 1 ||
484 <                                fscanf(f2, "%lf", &vd[1]) != 1 ||
485 <                                fscanf(f3, "%lf", &vd[2]) != 1)
483 >                if (fscanf(fin, "%lf", &vd[0]) != 1 ||
484 >                                fscanf(fin2, "%lf", &vd[1]) != 1 ||
485 >                                fscanf(fin3, "%lf", &vd[2]) != 1)
486                          return(-1);
487          }
488          setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]);
# Line 464 | Line 490 | FILE  *f1, *f2, *f3;
490   }
491  
492  
493 < getcdouble(col, f1, f2, f3)     /* get a double color value from stream(s) */
493 > getcdouble(col)         /* get a double color value from stream(s) */
494   COLOR  col;
469 FILE  *f1, *f2, *f3;
495   {
496          double  vd[3];
497  
498 <        if (f2 == NULL) {
499 <                if (fread((char *)vd, sizeof(double), 3, f1) != 3)
498 >        if (fin2 == NULL) {
499 >                if (fread((char *)vd, sizeof(double), 3, fin) != 3)
500                          return(-1);
501          } else {
502 <                if (fread((char *)vd, sizeof(double), 1, f1) != 1 ||
503 <                        fread((char *)(vd+1), sizeof(double), 1, f2) != 1 ||
504 <                        fread((char *)(vd+2), sizeof(double), 1, f3) != 1)
502 >                if (fread((char *)vd, sizeof(double), 1, fin) != 1 ||
503 >                        fread((char *)(vd+1), sizeof(double), 1, fin2) != 1 ||
504 >                        fread((char *)(vd+2), sizeof(double), 1, fin3) != 1)
505                          return(-1);
506          }
507          setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]);
# Line 484 | Line 509 | FILE  *f1, *f2, *f3;
509   }
510  
511  
512 < getcfloat(col, f1, f2, f3)      /* get a float color value from stream(s) */
512 > getcfloat(col)          /* get a float color value from stream(s) */
513   COLOR  col;
489 FILE  *f1, *f2, *f3;
514   {
515          float  vf[3];
516  
517 <        if (f2 == NULL) {
518 <                if (fread((char *)vf, sizeof(float), 3, f1) != 3)
517 >        if (fin2 == NULL) {
518 >                if (fread((char *)vf, sizeof(float), 3, fin) != 3)
519                          return(-1);
520          } else {
521 <                if (fread((char *)vf, sizeof(float), 1, f1) != 1 ||
522 <                        fread((char *)(vf+1), sizeof(float), 1, f2) != 1 ||
523 <                        fread((char *)(vf+2), sizeof(float), 1, f3) != 1)
521 >                if (fread((char *)vf, sizeof(float), 1, fin) != 1 ||
522 >                        fread((char *)(vf+1), sizeof(float), 1, fin2) != 1 ||
523 >                        fread((char *)(vf+2), sizeof(float), 1, fin3) != 1)
524                          return(-1);
525          }
526          setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]);
# Line 504 | Line 528 | FILE  *f1, *f2, *f3;
528   }
529  
530  
531 < getcint(col, f1, f2, f3)        /* get an int color value from stream(s) */
531 > getcint(col)            /* get an int color value from stream(s) */
532   COLOR  col;
509 FILE  *f1, *f2, *f3;
533   {
534          int  vi[3];
535  
536 <        if (f2 == NULL) {
537 <                if (fscanf(f1, "%d %d %d", &vi[0], &vi[1], &vi[2]) != 3)
536 >        if (fin2 == NULL) {
537 >                if (fscanf(fin, "%d %d %d", &vi[0], &vi[1], &vi[2]) != 3)
538                          return(-1);
539          } else {
540 <                if (fscanf(f1, "%d", &vi[0]) != 1 ||
541 <                                fscanf(f2, "%d", &vi[1]) != 1 ||
542 <                                fscanf(f3, "%d", &vi[2]) != 1)
540 >                if (fscanf(fin, "%d", &vi[0]) != 1 ||
541 >                                fscanf(fin2, "%d", &vi[1]) != 1 ||
542 >                                fscanf(fin3, "%d", &vi[2]) != 1)
543                          return(-1);
544          }
545          setcolor(col, (vi[rord[RED]]+.5)/256.,
# Line 525 | Line 548 | FILE  *f1, *f2, *f3;
548   }
549  
550  
551 < getcbyte(col, f1, f2, f3)       /* get a byte color value from stream(s) */
551 > getcbyte(col)           /* get a byte color value from stream(s) */
552   COLOR  col;
530 FILE  *f1, *f2, *f3;
553   {
554          BYTE  vb[3];
555  
556 <        if (f2 == NULL) {
557 <                if (fread((char *)vb, sizeof(BYTE), 3, f1) != 3)
556 >        if (fin2 == NULL) {
557 >                if (fread((char *)vb, sizeof(BYTE), 3, fin) != 3)
558                          return(-1);
559          } else {
560 <                if (fread((char *)vb, sizeof(BYTE), 1, f1) != 1 ||
561 <                        fread((char *)(vb+1), sizeof(BYTE), 1, f2) != 1 ||
562 <                        fread((char *)(vb+2), sizeof(BYTE), 1, f3) != 1)
560 >                if (fread((char *)vb, sizeof(BYTE), 1, fin) != 1 ||
561 >                        fread((char *)(vb+1), sizeof(BYTE), 1, fin2) != 1 ||
562 >                        fread((char *)(vb+2), sizeof(BYTE), 1, fin3) != 1)
563                          return(-1);
564          }
565          setcolor(col, (vb[rord[RED]]+.5)/256.,
# Line 546 | Line 568 | FILE  *f1, *f2, *f3;
568   }
569  
570  
571 < getbascii(col, fp)              /* get an ascii brightness value from fp */
571 > getbascii(col)          /* get an ascii brightness value from fin */
572   COLOR  col;
551 FILE  *fp;
573   {
574          double  vd;
575  
576 <        if (fscanf(fp, "%lf", &vd) != 1)
576 >        if (fscanf(fin, "%lf", &vd) != 1)
577                  return(-1);
578          setcolor(col, vd, vd, vd);
579          return(0);
580   }
581  
582  
583 < getbdouble(col, fp)             /* get a double brightness value from fp */
583 > getbdouble(col)         /* get a double brightness value from fin */
584   COLOR  col;
564 FILE  *fp;
585   {
586          double  vd;
587  
588 <        if (fread((char *)&vd, sizeof(double), 1, fp) != 1)
588 >        if (fread((char *)&vd, sizeof(double), 1, fin) != 1)
589                  return(-1);
590          setcolor(col, vd, vd, vd);
591          return(0);
592   }
593  
594  
595 < getbfloat(col, fp)              /* get a float brightness value from fp */
595 > getbfloat(col)          /* get a float brightness value from fin */
596   COLOR  col;
577 FILE  *fp;
597   {
598          float  vf;
599  
600 <        if (fread((char *)&vf, sizeof(float), 1, fp) != 1)
600 >        if (fread((char *)&vf, sizeof(float), 1, fin) != 1)
601                  return(-1);
602          setcolor(col, vf, vf, vf);
603          return(0);
604   }
605  
606  
607 < getbint(col, fp)                /* get an int brightness value from fp */
607 > getbint(col)            /* get an int brightness value from fin */
608   COLOR  col;
590 FILE  *fp;
609   {
610          int  vi;
611          double  d;
612  
613 <        if (fscanf(fp, "%d", &vi) != 1)
613 >        if (fscanf(fin, "%d", &vi) != 1)
614                  return(-1);
615          d = (vi+.5)/256.;
616          setcolor(col, d, d, d);
# Line 600 | Line 618 | FILE  *fp;
618   }
619  
620  
621 < getbbyte(col, fp)               /* get a byte brightness value from fp */
621 > getbbyte(col)           /* get a byte brightness value from fin */
622   COLOR  col;
605 FILE  *fp;
623   {
624          BYTE  vb;
625          double  d;
626  
627 <        if (fread((char *)&vb, sizeof(BYTE), 1, fp) != 1)
627 >        if (fread((char *)&vb, sizeof(BYTE), 1, fin) != 1)
628                  return(-1);
629          d = (vb+.5)/256.;
630          setcolor(col, d, d, d);
# Line 615 | Line 632 | FILE  *fp;
632   }
633  
634  
635 < putcascii(col, fp)                      /* put an ascii color to fp */
635 > putcascii(col)                  /* put an ascii color to stdout */
636   COLOR  col;
620 FILE  *fp;
637   {
638 <        fprintf(fp, "%15.3e %15.3e %15.3e\n",
638 >        fprintf(stdout, "%15.3e %15.3e %15.3e\n",
639                          colval(col,ord[0]),
640                          colval(col,ord[1]),
641                          colval(col,ord[2]));
642  
643 <        return(ferror(fp) ? -1 : 0);
643 >        return(ferror(stdout) ? -1 : 0);
644   }
645  
646  
647 < putcfloat(col, fp)                      /* put a float color to fp */
647 > putcfloat(col)                  /* put a float color to stdout */
648   COLOR  col;
633 FILE  *fp;
649   {
650          float  vf[3];
651  
652          vf[0] = colval(col,ord[0]);
653          vf[1] = colval(col,ord[1]);
654          vf[2] = colval(col,ord[2]);
655 <        fwrite((char *)vf, sizeof(float), 3, fp);
655 >        fwrite((char *)vf, sizeof(float), 3, stdout);
656  
657 <        return(ferror(fp) ? -1 : 0);
657 >        return(ferror(stdout) ? -1 : 0);
658   }
659  
660  
661 < putcdouble(col, fp)                     /* put a double color to fp */
661 > putcdouble(col)                 /* put a double color to stdout */
662   COLOR  col;
648 FILE  *fp;
663   {
664          double  vd[3];
665  
666          vd[0] = colval(col,ord[0]);
667          vd[1] = colval(col,ord[1]);
668          vd[2] = colval(col,ord[2]);
669 <        fwrite((char *)vd, sizeof(double), 3, fp);
669 >        fwrite((char *)vd, sizeof(double), 3, stdout);
670  
671 <        return(ferror(fp) ? -1 : 0);
671 >        return(ferror(stdout) ? -1 : 0);
672   }
673  
674  
675 < putcint(col, fp)                        /* put an int color to fp */
675 > putcint(col)                    /* put an int color to stdout */
676   COLOR  col;
663 FILE  *fp;
677   {
678 <        fprintf(fp, "%d %d %d\n",
678 >        fprintf(stdout, "%d %d %d\n",
679                          (int)(colval(col,ord[0])*256.),
680                          (int)(colval(col,ord[1])*256.),
681                          (int)(colval(col,ord[2])*256.));
682  
683 <        return(ferror(fp) ? -1 : 0);
683 >        return(ferror(stdout) ? -1 : 0);
684   }
685  
686  
687 < putcbyte(col, fp)                       /* put a byte color to fp */
687 > putcbyte(col)                   /* put a byte color to stdout */
688   COLOR  col;
676 FILE  *fp;
689   {
690          register int  i;
691          BYTE  vb[3];
# Line 684 | Line 696 | FILE  *fp;
696          vb[1] = min(i,255);
697          i = colval(col,ord[2])*256.;
698          vb[2] = min(i,255);
699 <        fwrite((char *)vb, sizeof(BYTE), 3, fp);
699 >        fwrite((char *)vb, sizeof(BYTE), 3, stdout);
700  
701 <        return(ferror(fp) ? -1 : 0);
701 >        return(ferror(stdout) ? -1 : 0);
702   }
703  
704  
705 < putbascii(col, fp)                      /* put an ascii brightness to fp */
705 > putbascii(col)                  /* put an ascii brightness to stdout */
706   COLOR  col;
695 FILE  *fp;
707   {
708 <        fprintf(fp, "%15.3e\n", bright(col));
708 >        fprintf(stdout, "%15.3e\n", bright(col));
709  
710 <        return(ferror(fp) ? -1 : 0);
710 >        return(ferror(stdout) ? -1 : 0);
711   }
712  
713  
714 < putbfloat(col, fp)                      /* put a float brightness to fp */
714 > putbfloat(col)                  /* put a float brightness to stdout */
715   COLOR  col;
705 FILE  *fp;
716   {
717          float  vf;
718  
719          vf = bright(col);
720 <        fwrite((char *)&vf, sizeof(float), 1, fp);
720 >        fwrite((char *)&vf, sizeof(float), 1, stdout);
721  
722 <        return(ferror(fp) ? -1 : 0);
722 >        return(ferror(stdout) ? -1 : 0);
723   }
724  
725  
726 < putbdouble(col, fp)                     /* put a double brightness to fp */
726 > putbdouble(col)                 /* put a double brightness to stdout */
727   COLOR  col;
718 FILE  *fp;
728   {
729          double  vd;
730  
731          vd = bright(col);
732 <        fwrite((char *)&vd, sizeof(double), 1, fp);
732 >        fwrite((char *)&vd, sizeof(double), 1, stdout);
733  
734 <        return(ferror(fp) ? -1 : 0);
734 >        return(ferror(stdout) ? -1 : 0);
735   }
736  
737  
738 < putbint(col, fp)                        /* put an int brightness to fp */
738 > putbint(col)                    /* put an int brightness to stdout */
739   COLOR  col;
731 FILE  *fp;
740   {
741 <        fprintf(fp, "%d\n", (int)(bright(col)*256.));
741 >        fprintf(stdout, "%d\n", (int)(bright(col)*256.));
742  
743 <        return(ferror(fp) ? -1 : 0);
743 >        return(ferror(stdout) ? -1 : 0);
744   }
745  
746  
747 < putbbyte(col, fp)                       /* put a byte brightness to fp */
747 > putbbyte(col)                   /* put a byte brightness to stdout */
748   COLOR  col;
741 FILE  *fp;
749   {
750          register int  i;
751          BYTE  vb;
752  
753          i = bright(col)*256.;
754          vb = min(i,255);
755 <        fwrite((char *)&vb, sizeof(BYTE), 1, fp);
755 >        fwrite((char *)&vb, sizeof(BYTE), 1, stdout);
756  
757 <        return(ferror(fp) ? -1 : 0);
757 >        return(ferror(stdout) ? -1 : 0);
758   }
759  
760  
761 < putpascii(col, fp)                      /* put an ascii primary to fp */
761 > putpascii(col)                  /* put an ascii primary to stdout */
762   COLOR  col;
756 FILE  *fp;
763   {
764 <        fprintf(fp, "%15.3e\n", colval(col,putprim));
764 >        fprintf(stdout, "%15.3e\n", colval(col,putprim));
765  
766 <        return(ferror(fp) ? -1 : 0);
766 >        return(ferror(stdout) ? -1 : 0);
767   }
768  
769  
770 < putpfloat(col, fp)                      /* put a float primary to fp */
770 > putpfloat(col)                  /* put a float primary to stdout */
771   COLOR  col;
766 FILE  *fp;
772   {
773          float  vf;
774  
775          vf = colval(col,putprim);
776 <        fwrite((char *)&vf, sizeof(float), 1, fp);
776 >        fwrite((char *)&vf, sizeof(float), 1, stdout);
777  
778 <        return(ferror(fp) ? -1 : 0);
778 >        return(ferror(stdout) ? -1 : 0);
779   }
780  
781  
782 < putpdouble(col, fp)                     /* put a double primary to fp */
782 > putpdouble(col)                 /* put a double primary to stdout */
783   COLOR  col;
779 FILE  *fp;
784   {
785          double  vd;
786  
787          vd = colval(col,putprim);
788 <        fwrite((char *)&vd, sizeof(double), 1, fp);
788 >        fwrite((char *)&vd, sizeof(double), 1, stdout);
789  
790 <        return(ferror(fp) ? -1 : 0);
790 >        return(ferror(stdout) ? -1 : 0);
791   }
792  
793  
794 < putpint(col, fp)                        /* put an int primary to fp */
794 > putpint(col)                    /* put an int primary to stdout */
795   COLOR  col;
792 FILE  *fp;
796   {
797 <        fprintf(fp, "%d\n", (int)(colval(col,putprim)*256.));
797 >        fprintf(stdout, "%d\n", (int)(colval(col,putprim)*256.));
798  
799 <        return(ferror(fp) ? -1 : 0);
799 >        return(ferror(stdout) ? -1 : 0);
800   }
801  
802  
803 < putpbyte(col, fp)                       /* put a byte primary to fp */
803 > putpbyte(col)                   /* put a byte primary to stdout */
804   COLOR  col;
802 FILE  *fp;
805   {
806          register int  i;
807          BYTE  vb;
808  
809          i = colval(col,putprim)*256.;
810          vb = min(i,255);
811 <        fwrite((char *)&vb, sizeof(BYTE), 1, fp);
811 >        fwrite((char *)&vb, sizeof(BYTE), 1, stdout);
812  
813 <        return(ferror(fp) ? -1 : 0);
813 >        return(ferror(stdout) ? -1 : 0);
814   }
815  
816  
# Line 825 | Line 827 | set_io()                       /* set put and get functions */
827                  } else {
828                          getval = getcascii;
829                          putval = putcascii;
830 +                        if (reverse && !interleave) {
831 +                                fprintf(stderr,
832 +                                "%s: ASCII input files must be interleaved\n",
833 +                                                progname);
834 +                                quit(1);
835 +                        }
836                  }
837                  return;
838          case 'f':                                       /* binary float */
# Line 837 | Line 845 | set_io()                       /* set put and get functions */
845                  } else {
846                          getval = getcfloat;
847                          putval = putcfloat;
848 +                        if (reverse && !interleave) {
849 +                                if (fin2 == NULL)
850 +                                        goto namerr;
851 +                                if (fseek(fin2,
852 +                                (long)sizeof(float)*picres.xr*picres.yr, 1))
853 +                                        goto seekerr;
854 +                                if (fseek(fin3,
855 +                                (long)sizeof(float)*2*picres.xr*picres.yr, 1))
856 +                                        goto seekerr;
857 +                        }
858                  }
859                  return;
860          case 'd':                                       /* binary double */
# Line 849 | Line 867 | set_io()                       /* set put and get functions */
867                  } else {
868                          getval = getcdouble;
869                          putval = putcdouble;
870 +                        if (reverse && !interleave) {
871 +                                if (fin2 == NULL)
872 +                                        goto namerr;
873 +                                if (fseek(fin2,
874 +                                (long)sizeof(double)*picres.xr*picres.yr, 1))
875 +                                        goto seekerr;
876 +                                if (fseek(fin3,
877 +                                (long)sizeof(double)*2*picres.xr*picres.yr, 1))
878 +                                        goto seekerr;
879 +                        }
880                  }
881                  return;
882          case 'i':                                       /* integer */
# Line 861 | Line 889 | set_io()                       /* set put and get functions */
889                  } else {
890                          getval = getcint;
891                          putval = putcint;
892 +                        if (reverse && !interleave) {
893 +                                fprintf(stderr,
894 +                                "%s: integer input files must be interleaved\n",
895 +                                                progname);
896 +                                quit(1);
897 +                        }
898                  }
899                  return;
900          case 'b':                                       /* byte */
# Line 873 | Line 907 | set_io()                       /* set put and get functions */
907                  } else {
908                          getval = getcbyte;
909                          putval = putcbyte;
910 +                        if (reverse && !interleave) {
911 +                                if (fin2 == NULL)
912 +                                        goto namerr;
913 +                                if (fseek(fin2,
914 +                                (long)sizeof(BYTE)*picres.xr*picres.yr, 1))
915 +                                        goto seekerr;
916 +                                if (fseek(fin3,
917 +                                (long)sizeof(BYTE)*2*picres.xr*picres.yr, 1))
918 +                                        goto seekerr;
919 +                        }
920                  }
921                  return;
922          }
923 + badopt:
924 +        fprintf(stderr, "%s: botched file type\n", progname);
925 +        quit(1);
926 + namerr:
927 +        fprintf(stderr, "%s: non-interleaved file(s) must be named\n",
928 +                        progname);
929 +        quit(1);
930 + seekerr:
931 +        fprintf(stderr, "%s: cannot seek on interleaved input file\n",
932 +                        progname);
933 +        quit(1);
934   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines