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.31 by greg, Fri May 20 02:06:39 2011 UTC vs.
Revision 2.35 by greg, Mon Jul 15 22:39:50 2019 UTC

# Line 296 | Line 296 | unkopt:
296          }
297  
298          if (reverse) {
299 < #ifdef _WIN32
299 > #if defined(_WIN32) || defined(_WIN64)
300                  SET_FILE_BINARY(stdout);
301                  if (format != 'a' && format != 'i')
302                          SET_FILE_BINARY(fin);
# Line 349 | Line 349 | unkopt:
349                  fputsresolu(&picres, stdout);   /* always put resolution */
350                  valtopix();
351          } else {
352 < #ifdef _WIN32
352 > #if defined(_WIN32) || defined(_WIN64)
353                  SET_FILE_BINARY(fin);
354                  if (format != 'a' && format != 'i')
355                          SET_FILE_BINARY(stdout);
# Line 389 | Line 389 | checkhead(                             /* deal with line from header */
389          void    *p
390   )
391   {
392 <        char    fmt[32];
392 >        char    fmt[MAXFMTLEN];
393          double  d;
394          COLOR   ctmp;
395  
# Line 419 | Line 419 | checkhead(                             /* deal with line from header */
419   static void
420   pixtoval(void)                          /* convert picture to values */
421   {
422 <        register COLOR  *scanln;
422 >        COLOR   *scanln;
423          int  dogamma;
424          COLOR  lastc;
425          RREAL  hv[2];
426          int  startprim, endprim;
427          long  startpos;
428 <        int  y;
429 <        register int  x;
428 >        int  x, y;
429  
430          scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
431          if (scanln == NULL) {
# Line 493 | Line 492 | pixtoval(void)                         /* convert picture to values */
492   static void
493   valtopix(void)                  /* convert values to a pixel file */
494   {
495 <        int  dogamma;
496 <        register COLOR  *scanln;
497 <        int  y;
498 <        register int  x;
495 >        int     dogamma;
496 >        COLOR   *scanln;
497 >        COLR    rgbe;
498 >        int     x, y;
499  
500          scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
501          if (scanln == NULL) {
# Line 525 | Line 524 | valtopix(void)                 /* convert values to a pixel file */
524                                          pow(colval(scanln[x],BLU), gamcor));
525                          if (doexposure)
526                                  multcolor(scanln[x], exposure);
527 +                        if (uniq) {             /* uncompressed? */
528 +                                setcolr(rgbe,   scanln[x][RED],
529 +                                                scanln[x][GRN],
530 +                                                scanln[x][BLU]);
531 +                                if (putbinary(rgbe, sizeof(COLR), 1, stdout) != 1)
532 +                                        goto writerr;
533 +                        }
534                  }
535 <                if (fwritescan(scanln, scanlen(&picres), stdout) < 0) {
536 <                        fprintf(stderr, "%s: write error\n", progname);
537 <                        quit(1);
532 <                }
535 >                                                /* write scan if compressed */
536 >                if (!uniq && fwritescan(scanln, scanlen(&picres), stdout) < 0)
537 >                        goto writerr;
538          }
539          free((void *)scanln);
540 +        return;
541 + writerr:
542 +        fprintf(stderr, "%s: write error\n", progname);
543 +        quit(1);
544   }
545  
546  
# Line 572 | Line 581 | getcdouble(            /* get a double color value from stream(s
581          double  vd[3];
582  
583          if (fin2 == NULL) {
584 <                if (fread((char *)vd, sizeof(double), 3, fin) != 3)
584 >                if (getbinary(vd, sizeof(double), 3, fin) != 3)
585                          return(-1);
586          } else {
587 <                if (fread((char *)vd, sizeof(double), 1, fin) != 1 ||
588 <                        fread((char *)(vd+1), sizeof(double), 1, fin2) != 1 ||
589 <                        fread((char *)(vd+2), sizeof(double), 1, fin3) != 1)
587 >                if (getbinary(vd, sizeof(double), 1, fin) != 1 ||
588 >                        getbinary(vd+1, sizeof(double), 1, fin2) != 1 ||
589 >                        getbinary(vd+2, sizeof(double), 1, fin3) != 1)
590                          return(-1);
591          }
592          if (swapbytes)
# Line 595 | Line 604 | getcfloat(             /* get a float color value from stream(s)
604          float  vf[3];
605  
606          if (fin2 == NULL) {
607 <                if (fread((char *)vf, sizeof(float), 3, fin) != 3)
607 >                if (getbinary(vf, sizeof(float), 3, fin) != 3)
608                          return(-1);
609          } else {
610 <                if (fread((char *)vf, sizeof(float), 1, fin) != 1 ||
611 <                        fread((char *)(vf+1), sizeof(float), 1, fin2) != 1 ||
612 <                        fread((char *)(vf+2), sizeof(float), 1, fin3) != 1)
610 >                if (getbinary(vf, sizeof(float), 1, fin) != 1 ||
611 >                        getbinary(vf+1, sizeof(float), 1, fin2) != 1 ||
612 >                        getbinary(vf+2, sizeof(float), 1, fin3) != 1)
613                          return(-1);
614          }
615          if (swapbytes)
# Line 640 | Line 649 | getcbyte(              /* get a byte color value from stream(s) */
649          uby8  vb[3];
650  
651          if (fin2 == NULL) {
652 <                if (fread((char *)vb, sizeof(uby8), 3, fin) != 3)
652 >                if (getbinary(vb, sizeof(uby8), 3, fin) != 3)
653                          return(-1);
654          } else {
655 <                if (fread((char *)vb, sizeof(uby8), 1, fin) != 1 ||
656 <                        fread((char *)(vb+1), sizeof(uby8), 1, fin2) != 1 ||
657 <                        fread((char *)(vb+2), sizeof(uby8), 1, fin3) != 1)
655 >                if (getbinary(vb, sizeof(uby8), 1, fin) != 1 ||
656 >                        getbinary(vb+1, sizeof(uby8), 1, fin2) != 1 ||
657 >                        getbinary(vb+2, sizeof(uby8), 1, fin3) != 1)
658                          return(-1);
659          }
660          setcolor(col, (vb[rord[RED]]+.5)/256.,
# Line 662 | Line 671 | getcword(              /* get a 16-bit color value from stream(s)
671          uint16  vw[3];
672  
673          if (fin2 == NULL) {
674 <                if (fread((char *)vw, sizeof(uint16), 3, fin) != 3)
674 >                if (getbinary(vw, sizeof(uint16), 3, fin) != 3)
675                          return(-1);
676          } else {
677 <                if (fread((char *)vw, sizeof(uint16), 1, fin) != 1 ||
678 <                        fread((char *)(vw+1), sizeof(uint16), 1, fin2) != 1 ||
679 <                        fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1)
677 >                if (getbinary(vw, sizeof(uint16), 1, fin) != 1 ||
678 >                        getbinary(vw+1, sizeof(uint16), 1, fin2) != 1 ||
679 >                        getbinary(vw+2, sizeof(uint16), 1, fin3) != 1)
680                          return(-1);
681          }
682          if (swapbytes)
# Line 699 | Line 708 | getbdouble(            /* get a double brightness value from fin
708   {
709          double  vd;
710  
711 <        if (fread((char *)&vd, sizeof(double), 1, fin) != 1)
711 >        if (getbinary(&vd, sizeof(double), 1, fin) != 1)
712                  return(-1);
713          if (swapbytes)
714                  swap64((char *)&vd, 1);
# Line 715 | Line 724 | getbfloat(             /* get a float brightness value from fin *
724   {
725          float  vf;
726  
727 <        if (fread((char *)&vf, sizeof(float), 1, fin) != 1)
727 >        if (getbinary(&vf, sizeof(float), 1, fin) != 1)
728                  return(-1);
729          if (swapbytes)
730                  swap32((char *)&vf, 1);
# Line 748 | Line 757 | getbbyte(              /* get a byte brightness value from fin */
757          uby8  vb;
758          double  d;
759  
760 <        if (fread((char *)&vb, sizeof(uby8), 1, fin) != 1)
760 >        if (getbinary(&vb, sizeof(uby8), 1, fin) != 1)
761                  return(-1);
762          d = (vb+.5)/256.;
763          setcolor(col, d, d, d);
# Line 764 | Line 773 | getbword(              /* get a 16-bit brightness value from fin *
773          uint16  vw;
774          double  d;
775  
776 <        if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1)
776 >        if (getbinary(&vw, sizeof(uint16), 1, fin) != 1)
777                  return(-1);
778          if (swapbytes)
779                  swap16((char *)&vw, 1);
# Line 800 | Line 809 | putcfloat(                     /* put a float color to stdout */
809          vf[2] = colval(col,ord[2]);
810          if (swapbytes)
811                  swap32((char *)vf, 3);
812 <        fwrite((char *)vf, sizeof(float), 3, stdout);
812 >        putbinary(vf, sizeof(float), 3, stdout);
813  
814          return(ferror(stdout) ? -1 : 0);
815   }
# Line 818 | Line 827 | putcdouble(                    /* put a double color to stdout */
827          vd[2] = colval(col,ord[2]);
828          if (swapbytes)
829                  swap64((char *)vd, 3);
830 <        fwrite((char *)vd, sizeof(double), 3, stdout);
830 >        putbinary(vd, sizeof(double), 3, stdout);
831  
832          return(ferror(stdout) ? -1 : 0);
833   }
# Line 852 | Line 861 | putcbyte(                      /* put a byte color to stdout */
861          vb[1] = min(i,255);
862          i = colval(col,ord[2])*256.;
863          vb[2] = min(i,255);
864 <        fwrite((char *)vb, sizeof(uby8), 3, stdout);
864 >        putbinary(vb, sizeof(uby8), 3, stdout);
865  
866          return(ferror(stdout) ? -1 : 0);
867   }
# Line 874 | Line 883 | putcword(                      /* put a 16-bit color to stdout */
883          vw[2] = min(i,65535);
884          if (swapbytes)
885                  swap16((char *)vw, 3);
886 <        fwrite((char *)vw, sizeof(uint16), 3, stdout);
886 >        putbinary(vw, sizeof(uint16), 3, stdout);
887  
888          return(ferror(stdout) ? -1 : 0);
889   }
# Line 901 | Line 910 | putbfloat(                     /* put a float brightness to stdout */
910          vf = (*mybright)(col);
911          if (swapbytes)
912                  swap32((char *)&vf, 1);
913 <        fwrite((char *)&vf, sizeof(float), 1, stdout);
913 >        putbinary(&vf, sizeof(float), 1, stdout);
914  
915          return(ferror(stdout) ? -1 : 0);
916   }
# Line 917 | Line 926 | putbdouble(                    /* put a double brightness to stdout */
926          vd = (*mybright)(col);
927          if (swapbytes)
928                  swap64((char *)&vd, 1);
929 <        fwrite((char *)&vd, sizeof(double), 1, stdout);
929 >        putbinary(&vd, sizeof(double), 1, stdout);
930  
931          return(ferror(stdout) ? -1 : 0);
932   }
# Line 939 | Line 948 | putbbyte(                      /* put a byte brightness to stdout */
948          COLOR  col
949   )
950   {
951 <        register int  i;
951 >        int  i;
952          uby8  vb;
953  
954          i = (*mybright)(col)*256.;
955          vb = min(i,255);
956 <        fwrite((char *)&vb, sizeof(uby8), 1, stdout);
956 >        putbinary(&vb, sizeof(uby8), 1, stdout);
957  
958          return(ferror(stdout) ? -1 : 0);
959   }
# Line 962 | Line 971 | putbword(                      /* put a 16-bit brightness to stdout */
971          vw = min(i,65535);
972          if (swapbytes)
973                  swap16((char *)&vw, 1);
974 <        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
974 >        putbinary(&vw, sizeof(uint16), 1, stdout);
975  
976          return(ferror(stdout) ? -1 : 0);
977   }
# Line 989 | Line 998 | putpfloat(                     /* put a float primary to stdout */
998          vf = colval(col,putprim);
999          if (swapbytes)
1000                  swap32((char *)&vf, 1);
1001 <        fwrite((char *)&vf, sizeof(float), 1, stdout);
1001 >        putbinary(&vf, sizeof(float), 1, stdout);
1002  
1003          return(ferror(stdout) ? -1 : 0);
1004   }
# Line 1005 | Line 1014 | putpdouble(                    /* put a double primary to stdout */
1014          vd = colval(col,putprim);
1015          if (swapbytes)
1016                  swap64((char *)&vd, 1);
1017 <        fwrite((char *)&vd, sizeof(double), 1, stdout);
1017 >        putbinary(&vd, sizeof(double), 1, stdout);
1018  
1019          return(ferror(stdout) ? -1 : 0);
1020   }
# Line 1032 | Line 1041 | putpbyte(                      /* put a byte primary to stdout */
1041  
1042          i = colval(col,putprim)*256.;
1043          vb = min(i,255);
1044 <        fwrite((char *)&vb, sizeof(uby8), 1, stdout);
1044 >        putbinary(&vb, sizeof(uby8), 1, stdout);
1045  
1046          return(ferror(stdout) ? -1 : 0);
1047   }
# Line 1050 | Line 1059 | putpword(                      /* put a 16-bit primary to stdout */
1059          vw = min(i,65535);
1060          if (swapbytes)
1061                  swap16((char *)&vw, 1);
1062 <        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
1062 >        putbinary(&vw, sizeof(uint16), 1, stdout);
1063  
1064          return(ferror(stdout) ? -1 : 0);
1065   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines