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.26 by schorsch, Sun Mar 28 20:33:14 2004 UTC vs.
Revision 2.42 by greg, Thu Mar 10 03:25:54 2022 UTC

# Line 36 | Line 36 | int  original = 0;             /* convert to original values? */
36   int  wrongformat = 0;           /* wrong input format? */
37   double  gamcor = 1.0;           /* gamma correction */
38  
39 + RGBPRIMP  outprims = stdprims;  /* output primaries for reverse conversion */
40 + RGBPRIMS  myprims;
41 +
42   int  ord[3] = {RED, GRN, BLU};  /* RGB ordering */
43   int  rord[4];                   /* reverse ordering */
44  
# Line 66 | Line 69 | static putfunc_t putpascii, putpint, putpdouble, putpf
69   static void set_io(void);
70   static void pixtoval(void);
71   static void valtopix(void);
69 static void swap16(uint16  *wp, int  n);
70 static void swap32(uint32  *wp, int  n);
71 static void swap64(char  *wp, int  n);
72  
73  
74   static double
# Line 93 | Line 93 | main(
93          char  **argv
94   )
95   {
96 <        double  d, expval = 1.0;
97 <        int  i;
96 >        const char      *inpmode = "r";
97 >        double          d, expval = 1.0;
98 >        int             i;
99  
100          progname = argv[0];
101          mybright = &rgb_bright; /* default */
# Line 117 | Line 118 | main(
118                          case 'o':               /* original values */
119                                  original = argv[i][0] == '-';
120                                  break;
121 +                        case 'O':               /* original watts/sr/m^2 */
122 +                                original = -(argv[i][0] == '-');
123 +                                break;
124                          case 'g':               /* gamma correction */
125                                  gamcor = atof(argv[i+1]);
126                                  if (argv[i][0] == '+')
# Line 149 | Line 153 | main(
153                          case 'b':               /* brightness values */
154                                  putprim = argv[i][0] == '-' ? BRIGHT : ALL;
155                                  break;
156 <                        case 'p':               /* put primary */
156 >                        case 'p':               /* primary controls */
157                                  switch (argv[i][2]) {
158 +                                /* these two options affect -r conversion */
159 +                                case '\0':
160 +                                        myprims[RED][CIEX] = atof(argv[++i]);
161 +                                        myprims[RED][CIEY] = atof(argv[++i]);
162 +                                        myprims[GRN][CIEX] = atof(argv[++i]);
163 +                                        myprims[GRN][CIEY] = atof(argv[++i]);
164 +                                        myprims[BLU][CIEX] = atof(argv[++i]);
165 +                                        myprims[BLU][CIEY] = atof(argv[++i]);
166 +                                        myprims[WHT][CIEX] = atof(argv[++i]);
167 +                                        myprims[WHT][CIEY] = atof(argv[++i]);
168 +                                        outprims = myprims;
169 +                                        break;
170 +                                case 'x': case 'X': outprims = NULL; break;
171 +                                /* the following options affect +r only */
172                                  case 'r': case 'R': putprim = RED; break;
173                                  case 'g': case 'G': putprim = GRN; break;
174                                  case 'b': case 'B': putprim = BLU; break;
# Line 158 | Line 176 | main(
176                                  }
177                                  break;
178                          case 'd':               /* data only (no indices) */
179 <                                dataonly = argv[i][0] == '-';
179 >                                dataonly = (argv[i][0] == '-');
180                                  switch (argv[i][2]) {
181                                  case '\0':
182                                  case 'a':               /* ascii */
# Line 237 | Line 255 | unkopt:
255                  else
256                          fmtid = "16-bit_grey";
257          }
258 +        if (!reverse || (format != 'a') & (format != 'i'))
259 +                inpmode = "rb";
260                                          /* assign reverse ordering */
261          rord[ord[0]] = 0;
262          rord[ord[1]] = 1;
263          rord[ord[2]] = 2;
264                                          /* get input */
265          if (i == argc) {
266 +                long    n = skipbytes;
267 +                if (inpmode[1] == 'b')
268 +                        SET_FILE_BINARY(stdin);
269 +                while (n-- > 0)
270 +                        if (getchar() == EOF) {
271 +                                fprintf(stderr,
272 +                                "%s: cannot skip %ld bytes on standard input\n",
273 +                                                progname, skipbytes);
274 +                                quit(1);
275 +                        }
276                  fin = stdin;
277          } else if (i < argc) {
278 <                if ((fin = fopen(argv[i], "r")) == NULL) {
278 >                if ((fin = fopen(argv[i], inpmode)) == NULL) {
279                          fprintf(stderr, "%s: can't open file \"%s\"\n",
280                                                  progname, argv[i]);
281                          quit(1);
282                  }
283                  if (reverse && putprim != BRIGHT && i == argc-3) {
284 <                        if ((fin2 = fopen(argv[i+1], "r")) == NULL) {
284 >                        if ((fin2 = fopen(argv[i+1], inpmode)) == NULL) {
285                                  fprintf(stderr, "%s: can't open file \"%s\"\n",
286                                                  progname, argv[i+1]);
287                                  quit(1);
288                          }
289 <                        if ((fin3 = fopen(argv[i+2], "r")) == NULL) {
289 >                        if ((fin3 = fopen(argv[i+2], inpmode)) == NULL) {
290                                  fprintf(stderr, "%s: can't open file \"%s\"\n",
291                                                  progname, argv[i+2]);
292                                  quit(1);
# Line 265 | Line 295 | unkopt:
295                  } else if (i != argc-1)
296                          fin = NULL;
297                  if (reverse && putprim != BRIGHT && !interleave) {
298 <                        fin2 = fopen(argv[i], "r");
299 <                        fin3 = fopen(argv[i], "r");
298 >                        fin2 = fopen(argv[i], inpmode);
299 >                        fin3 = fopen(argv[i], inpmode);
300                  }
301 <                if (skipbytes && (fseek(fin, skipbytes, 0) || (fin2 != NULL &&
302 <                                (fseek(fin2, skipbytes, 0) ||
303 <                                fseek(fin3, skipbytes, 0))))) {
301 >                if (skipbytes && (fseek(fin, skipbytes, SEEK_SET) || (fin2 != NULL &&
302 >                                fseek(fin2, skipbytes, SEEK_SET) |
303 >                                fseek(fin3, skipbytes, SEEK_SET)))) {
304                          fprintf(stderr, "%s: cannot skip %ld bytes on input\n",
305                                          progname, skipbytes);
306                          quit(1);
# Line 282 | Line 312 | unkopt:
312          }
313  
314          if (reverse) {
285 #ifdef _WIN32
315                  SET_FILE_BINARY(stdout);
287                if (format != 'a' && format != 'i')
288                        SET_FILE_BINARY(fin);
289 #endif
316                                          /* get header */
317                  if (header) {
318 <                        if (checkheader(fin, fmtid, stdout) < 0) {
319 <                                fprintf(stderr, "%s: wrong input format\n",
320 <                                                progname);
318 >                        getheader(fin, checkhead, stdout);
319 >                        if (wrongformat) {
320 >                                fprintf(stderr, "%s: wrong input format (expected %s)\n",
321 >                                                progname, fmtid);
322                                  quit(1);
323                          }
324                          if (fin2 != NULL) {
# Line 325 | Line 352 | unkopt:
352                  printargs(i, argv, stdout);
353                  if (expval < .99 || expval > 1.01)
354                          fputexpos(expval, stdout);
355 <                fputformat(COLRFMT, stdout);
355 >                if (outprims != NULL) {
356 >                        if (outprims != stdprims)
357 >                                fputprims(outprims, stdout);
358 >                        fputformat(COLRFMT, stdout);
359 >                } else {                        /* XYZ data */
360 >                        if (original < 0) {
361 >                                scalecolor(exposure, WHTEFFICACY);
362 >                                doexposure++;
363 >                        }
364 >                        fputformat(CIEFMT, stdout);
365 >                }
366                  putchar('\n');
367                  fputsresolu(&picres, stdout);   /* always put resolution */
368                  valtopix();
369          } else {
370 < #ifdef _WIN32
334 <                SET_FILE_BINARY(fin);
335 <                if (format != 'a' && format != 'i')
370 >                if ((format != 'a') & (format != 'i'))
371                          SET_FILE_BINARY(stdout);
337 #endif
372                                                  /* get header */
373 <                getheader(fin, checkhead, NULL);
373 >                getheader(fin, checkhead, header ? stdout : (FILE *)NULL);
374                  if (wrongformat) {
375                          fprintf(stderr,
376                                  "%s: input not a Radiance RGBE picture\n",
# Line 347 | Line 381 | unkopt:
381                          fprintf(stderr, "%s: missing resolution\n", progname);
382                          quit(1);
383                  }
384 +                if (original < 0 && mybright == &xyz_bright) {
385 +                        scalecolor(exposure, 1./WHTEFFICACY);
386 +                        doexposure++;
387 +                }
388                  if (header) {
389                          printargs(i, argv, stdout);
390 +                        printf("NCOMP=%d\n", putprim==ALL ? 3 : 1);
391 +                        if (!resolution && dataonly && !uniq)
392 +                                printf("NCOLS=%d\nNROWS=%d\n", scanlen(&picres),
393 +                                                numscans(&picres));
394                          if (expval < .99 || expval > 1.01)
395                                  fputexpos(expval, stdout);
396 +                        if (swapbytes) {
397 +                                if (nativebigendian())
398 +                                        puts("BigEndian=0");
399 +                                else
400 +                                        puts("BigEndian=1");
401 +                        } else if ((format != 'a') & (format != 'i') &
402 +                                                (format != 'b'))
403 +                                fputendian(stdout);
404                          fputformat(fmtid, stdout);
405                          putchar('\n');
406                  }
# Line 370 | Line 420 | checkhead(                             /* deal with line from header */
420          void    *p
421   )
422   {
423 <        char    fmt[32];
423 >        FILE    *fout = (FILE *)p;
424 >        char    fmt[MAXFMTLEN];
425          double  d;
426          COLOR   ctmp;
427 +        int     rv;
428  
429          if (formatval(fmt, line)) {
430 <                if (!strcmp(fmt, CIEFMT)) {
430 >                if (reverse)
431 >                        wrongformat = strcmp(fmt, fmtid);
432 >                else if (!strcmp(fmt, CIEFMT))
433                          mybright = &xyz_bright;
434 <                        if (original) {
381 <                                scalecolor(exposure, 1./WHTEFFICACY);
382 <                                doexposure++;
383 <                        }
384 <                } else if (!strcmp(fmt, COLRFMT))
434 >                else if (!strcmp(fmt, COLRFMT))
435                          mybright = &rgb_bright;
436                  else
437                          wrongformat++;
438 <        } else if (original && isexpos(line)) {
438 >                return(1);
439 >        }
440 >        if (!strncmp(line,"NROWS=",6) ||
441 >                        !strncmp(line,"NCOLS=",6) ||
442 >                        !strncmp(line,"NCOMP=",6))
443 >                return(1);
444 >
445 >        if (original && isexpos(line)) {
446                  d = 1.0/exposval(line);
447                  scalecolor(exposure, d);
448                  doexposure++;
449 <        } else if (original && iscolcor(line)) {
449 >                return(1);
450 >        }
451 >        if (original && iscolcor(line)) {
452                  colcorval(ctmp, line);
453                  setcolor(exposure, colval(exposure,RED)/colval(ctmp,RED),
454                                  colval(exposure,GRN)/colval(ctmp,GRN),
455                                  colval(exposure,BLU)/colval(ctmp,BLU));
456                  doexposure++;
457 <        } else if (header)
458 <                fputs(line, stdout);
457 >                return(1);
458 >        }
459 >        if ((rv = isbigendian(line)) >= 0) {
460 >                if (reverse)
461 >                        swapbytes = (nativebigendian() != rv);
462 >                return(1);
463 >        }
464 >        if (fout != NULL)
465 >                fputs(line, fout);
466          return(0);
467   }
468  
# Line 404 | Line 470 | checkhead(                             /* deal with line from header */
470   static void
471   pixtoval(void)                          /* convert picture to values */
472   {
473 <        register COLOR  *scanln;
473 >        COLOR   *scanln;
474          int  dogamma;
475          COLOR  lastc;
476          RREAL  hv[2];
477          int  startprim, endprim;
478          long  startpos;
479 <        int  y;
414 <        register int  x;
479 >        int  x, y;
480  
481          scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
482          if (scanln == NULL) {
# Line 419 | Line 484 | pixtoval(void)                         /* convert picture to values */
484                  quit(1);
485          }
486          dogamma = gamcor < .95 || gamcor > 1.05;
487 <        if (putprim == ALL && !interleave) {
487 >        if ((putprim == ALL) & !interleave) {
488                  startprim = RED; endprim = BLU;
489                  startpos = ftell(fin);
490          } else {
491                  startprim = putprim; endprim = putprim;
492          }
493          for (putprim = startprim; putprim <= endprim; putprim++) {
494 <                if (putprim != startprim && fseek(fin, startpos, 0)) {
494 >                if (putprim != startprim && fseek(fin, startpos, SEEK_SET)) {
495                          fprintf(stderr, "%s: seek error on input file\n",
496                                          progname);
497                          quit(1);
# Line 478 | Line 543 | pixtoval(void)                         /* convert picture to values */
543   static void
544   valtopix(void)                  /* convert values to a pixel file */
545   {
546 <        int  dogamma;
547 <        register COLOR  *scanln;
548 <        int  y;
549 <        register int  x;
546 >        int     dogamma;
547 >        COLOR   *scanln;
548 >        COLR    rgbe;
549 >        int     x, y;
550  
551          scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
552          if (scanln == NULL) {
# Line 510 | Line 575 | valtopix(void)                 /* convert values to a pixel file */
575                                          pow(colval(scanln[x],BLU), gamcor));
576                          if (doexposure)
577                                  multcolor(scanln[x], exposure);
578 +                        if (uniq) {             /* uncompressed? */
579 +                                setcolr(rgbe,   scanln[x][RED],
580 +                                                scanln[x][GRN],
581 +                                                scanln[x][BLU]);
582 +                                if (putbinary(rgbe, sizeof(COLR), 1, stdout) != 1)
583 +                                        goto writerr;
584 +                        }
585                  }
586 <                if (fwritescan(scanln, scanlen(&picres), stdout) < 0) {
587 <                        fprintf(stderr, "%s: write error\n", progname);
588 <                        quit(1);
517 <                }
586 >                                                /* write scan if compressed */
587 >                if (!uniq && fwritescan(scanln, scanlen(&picres), stdout) < 0)
588 >                        goto writerr;
589          }
590          free((void *)scanln);
591 +        return;
592 + writerr:
593 +        fprintf(stderr, "%s: write error\n", progname);
594 +        quit(1);
595   }
596  
597  
# Line 528 | Line 603 | int  code;
603   }
604  
605  
531 static void
532 swap16(         /* swap n 16-bit words */
533        register uint16  *wp,
534        int  n
535 )
536 {
537        while (n-- > 0) {
538                *wp = *wp << 8 | ((*wp >> 8) & 0xff);
539                wp++;
540        }
541 }
542
543
544 static void
545 swap32(         /* swap n 32-bit words */
546        register uint32  *wp,
547        int  n
548 )
549 {
550        while (n-- > 0) {
551                *wp = *wp << 24 | ((*wp >> 24) & 0xff) |
552                        (*wp & 0xff00) << 8 | (*wp & 0xff0000) >> 8;
553                wp++;
554        }
555 }
556
557
558 static void
559 swap64(         /* swap n 64-bit words */
560        register char  *wp,
561        int  n
562 )
563 {
564        register int    t;
565
566        while (n-- > 0) {
567                t = wp[0]; wp[0] = wp[7]; wp[7] = t;
568                t = wp[1]; wp[1] = wp[6]; wp[6] = t;
569                t = wp[2]; wp[2] = wp[5]; wp[5] = t;
570                t = wp[3]; wp[3] = wp[4]; wp[4] = t;
571                wp += 8;
572        }
573 }
574
575
606   static int
607   getcascii(              /* get an ascii color value from stream(s) */
608          COLOR  col
# Line 602 | Line 632 | getcdouble(            /* get a double color value from stream(s
632          double  vd[3];
633  
634          if (fin2 == NULL) {
635 <                if (fread((char *)vd, sizeof(double), 3, fin) != 3)
635 >                if (getbinary(vd, sizeof(double), 3, fin) != 3)
636                          return(-1);
637          } else {
638 <                if (fread((char *)vd, sizeof(double), 1, fin) != 1 ||
639 <                        fread((char *)(vd+1), sizeof(double), 1, fin2) != 1 ||
640 <                        fread((char *)(vd+2), sizeof(double), 1, fin3) != 1)
638 >                if (getbinary(vd, sizeof(double), 1, fin) != 1 ||
639 >                        getbinary(vd+1, sizeof(double), 1, fin2) != 1 ||
640 >                        getbinary(vd+2, sizeof(double), 1, fin3) != 1)
641                          return(-1);
642          }
643          if (swapbytes)
# Line 625 | Line 655 | getcfloat(             /* get a float color value from stream(s)
655          float  vf[3];
656  
657          if (fin2 == NULL) {
658 <                if (fread((char *)vf, sizeof(float), 3, fin) != 3)
658 >                if (getbinary(vf, sizeof(float), 3, fin) != 3)
659                          return(-1);
660          } else {
661 <                if (fread((char *)vf, sizeof(float), 1, fin) != 1 ||
662 <                        fread((char *)(vf+1), sizeof(float), 1, fin2) != 1 ||
663 <                        fread((char *)(vf+2), sizeof(float), 1, fin3) != 1)
661 >                if (getbinary(vf, sizeof(float), 1, fin) != 1 ||
662 >                        getbinary(vf+1, sizeof(float), 1, fin2) != 1 ||
663 >                        getbinary(vf+2, sizeof(float), 1, fin3) != 1)
664                          return(-1);
665          }
666          if (swapbytes)
667 <                swap32((uint32 *)vf, 3);
667 >                swap32((char *)vf, 3);
668          setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]);
669          return(0);
670   }
# Line 667 | Line 697 | getcbyte(              /* get a byte color value from stream(s) */
697          COLOR  col
698   )
699   {
700 <        BYTE  vb[3];
700 >        uby8  vb[3];
701  
702          if (fin2 == NULL) {
703 <                if (fread((char *)vb, sizeof(BYTE), 3, fin) != 3)
703 >                if (getbinary(vb, sizeof(uby8), 3, fin) != 3)
704                          return(-1);
705          } else {
706 <                if (fread((char *)vb, sizeof(BYTE), 1, fin) != 1 ||
707 <                        fread((char *)(vb+1), sizeof(BYTE), 1, fin2) != 1 ||
708 <                        fread((char *)(vb+2), sizeof(BYTE), 1, fin3) != 1)
706 >                if (getbinary(vb, sizeof(uby8), 1, fin) != 1 ||
707 >                        getbinary(vb+1, sizeof(uby8), 1, fin2) != 1 ||
708 >                        getbinary(vb+2, sizeof(uby8), 1, fin3) != 1)
709                          return(-1);
710          }
711          setcolor(col, (vb[rord[RED]]+.5)/256.,
# Line 692 | Line 722 | getcword(              /* get a 16-bit color value from stream(s)
722          uint16  vw[3];
723  
724          if (fin2 == NULL) {
725 <                if (fread((char *)vw, sizeof(uint16), 3, fin) != 3)
725 >                if (getbinary(vw, sizeof(uint16), 3, fin) != 3)
726                          return(-1);
727          } else {
728 <                if (fread((char *)vw, sizeof(uint16), 1, fin) != 1 ||
729 <                        fread((char *)(vw+1), sizeof(uint16), 1, fin2) != 1 ||
730 <                        fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1)
728 >                if (getbinary(vw, sizeof(uint16), 1, fin) != 1 ||
729 >                        getbinary(vw+1, sizeof(uint16), 1, fin2) != 1 ||
730 >                        getbinary(vw+2, sizeof(uint16), 1, fin3) != 1)
731                          return(-1);
732          }
733          if (swapbytes)
734 <                swap16(vw, 3);
734 >                swap16((char *)vw, 3);
735          setcolor(col, (vw[rord[RED]]+.5)/65536.,
736                          (vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.);
737          return(0);
# Line 729 | Line 759 | getbdouble(            /* get a double brightness value from fin
759   {
760          double  vd;
761  
762 <        if (fread((char *)&vd, sizeof(double), 1, fin) != 1)
762 >        if (getbinary(&vd, sizeof(double), 1, fin) != 1)
763                  return(-1);
764          if (swapbytes)
765                  swap64((char *)&vd, 1);
# Line 745 | Line 775 | getbfloat(             /* get a float brightness value from fin *
775   {
776          float  vf;
777  
778 <        if (fread((char *)&vf, sizeof(float), 1, fin) != 1)
778 >        if (getbinary(&vf, sizeof(float), 1, fin) != 1)
779                  return(-1);
780          if (swapbytes)
781 <                swap32((uint32 *)&vf, 1);
781 >                swap32((char *)&vf, 1);
782          setcolor(col, vf, vf, vf);
783          return(0);
784   }
# Line 775 | Line 805 | getbbyte(              /* get a byte brightness value from fin */
805          COLOR  col
806   )
807   {
808 <        BYTE  vb;
808 >        uby8  vb;
809          double  d;
810  
811 <        if (fread((char *)&vb, sizeof(BYTE), 1, fin) != 1)
811 >        if (getbinary(&vb, sizeof(uby8), 1, fin) != 1)
812                  return(-1);
813          d = (vb+.5)/256.;
814          setcolor(col, d, d, d);
# Line 794 | Line 824 | getbword(              /* get a 16-bit brightness value from fin *
824          uint16  vw;
825          double  d;
826  
827 <        if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1)
827 >        if (getbinary(&vw, sizeof(uint16), 1, fin) != 1)
828                  return(-1);
829          if (swapbytes)
830 <                swap16(&vw, 1);
830 >                swap16((char *)&vw, 1);
831          d = (vw+.5)/65536.;
832          setcolor(col, d, d, d);
833          return(0);
# Line 829 | Line 859 | putcfloat(                     /* put a float color to stdout */
859          vf[1] = colval(col,ord[1]);
860          vf[2] = colval(col,ord[2]);
861          if (swapbytes)
862 <                swap32((uint32 *)vf, 3);
863 <        fwrite((char *)vf, sizeof(float), 3, stdout);
862 >                swap32((char *)vf, 3);
863 >        putbinary(vf, sizeof(float), 3, stdout);
864  
865          return(ferror(stdout) ? -1 : 0);
866   }
# Line 848 | Line 878 | putcdouble(                    /* put a double color to stdout */
878          vd[2] = colval(col,ord[2]);
879          if (swapbytes)
880                  swap64((char *)vd, 3);
881 <        fwrite((char *)vd, sizeof(double), 3, stdout);
881 >        putbinary(vd, sizeof(double), 3, stdout);
882  
883          return(ferror(stdout) ? -1 : 0);
884   }
# Line 874 | Line 904 | putcbyte(                      /* put a byte color to stdout */
904   )
905   {
906          long  i;
907 <        BYTE  vb[3];
907 >        uby8  vb[3];
908  
909          i = colval(col,ord[0])*256.;
910          vb[0] = min(i,255);
# Line 882 | Line 912 | putcbyte(                      /* put a byte color to stdout */
912          vb[1] = min(i,255);
913          i = colval(col,ord[2])*256.;
914          vb[2] = min(i,255);
915 <        fwrite((char *)vb, sizeof(BYTE), 3, stdout);
915 >        putbinary(vb, sizeof(uby8), 3, stdout);
916  
917          return(ferror(stdout) ? -1 : 0);
918   }
# Line 903 | Line 933 | putcword(                      /* put a 16-bit color to stdout */
933          i = colval(col,ord[2])*65536.;
934          vw[2] = min(i,65535);
935          if (swapbytes)
936 <                swap16(vw, 3);
937 <        fwrite((char *)vw, sizeof(uint16), 3, stdout);
936 >                swap16((char *)vw, 3);
937 >        putbinary(vw, sizeof(uint16), 3, stdout);
938  
939          return(ferror(stdout) ? -1 : 0);
940   }
# Line 930 | Line 960 | putbfloat(                     /* put a float brightness to stdout */
960  
961          vf = (*mybright)(col);
962          if (swapbytes)
963 <                swap32((uint32 *)&vf, 1);
964 <        fwrite((char *)&vf, sizeof(float), 1, stdout);
963 >                swap32((char *)&vf, 1);
964 >        putbinary(&vf, sizeof(float), 1, stdout);
965  
966          return(ferror(stdout) ? -1 : 0);
967   }
# Line 947 | Line 977 | putbdouble(                    /* put a double brightness to stdout */
977          vd = (*mybright)(col);
978          if (swapbytes)
979                  swap64((char *)&vd, 1);
980 <        fwrite((char *)&vd, sizeof(double), 1, stdout);
980 >        putbinary(&vd, sizeof(double), 1, stdout);
981  
982          return(ferror(stdout) ? -1 : 0);
983   }
# Line 969 | Line 999 | putbbyte(                      /* put a byte brightness to stdout */
999          COLOR  col
1000   )
1001   {
1002 <        register int  i;
1003 <        BYTE  vb;
1002 >        int  i;
1003 >        uby8  vb;
1004  
1005          i = (*mybright)(col)*256.;
1006          vb = min(i,255);
1007 <        fwrite((char *)&vb, sizeof(BYTE), 1, stdout);
1007 >        putbinary(&vb, sizeof(uby8), 1, stdout);
1008  
1009          return(ferror(stdout) ? -1 : 0);
1010   }
# Line 991 | Line 1021 | putbword(                      /* put a 16-bit brightness to stdout */
1021          i = (*mybright)(col)*65536.;
1022          vw = min(i,65535);
1023          if (swapbytes)
1024 <                swap16(&vw, 1);
1025 <        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
1024 >                swap16((char *)&vw, 1);
1025 >        putbinary(&vw, sizeof(uint16), 1, stdout);
1026  
1027          return(ferror(stdout) ? -1 : 0);
1028   }
# Line 1018 | Line 1048 | putpfloat(                     /* put a float primary to stdout */
1048  
1049          vf = colval(col,putprim);
1050          if (swapbytes)
1051 <                swap32((uint32 *)&vf, 1);
1052 <        fwrite((char *)&vf, sizeof(float), 1, stdout);
1051 >                swap32((char *)&vf, 1);
1052 >        putbinary(&vf, sizeof(float), 1, stdout);
1053  
1054          return(ferror(stdout) ? -1 : 0);
1055   }
# Line 1035 | Line 1065 | putpdouble(                    /* put a double primary to stdout */
1065          vd = colval(col,putprim);
1066          if (swapbytes)
1067                  swap64((char *)&vd, 1);
1068 <        fwrite((char *)&vd, sizeof(double), 1, stdout);
1068 >        putbinary(&vd, sizeof(double), 1, stdout);
1069  
1070          return(ferror(stdout) ? -1 : 0);
1071   }
# Line 1058 | Line 1088 | putpbyte(                      /* put a byte primary to stdout */
1088   )
1089   {
1090          long  i;
1091 <        BYTE  vb;
1091 >        uby8  vb;
1092  
1093          i = colval(col,putprim)*256.;
1094          vb = min(i,255);
1095 <        fwrite((char *)&vb, sizeof(BYTE), 1, stdout);
1095 >        putbinary(&vb, sizeof(uby8), 1, stdout);
1096  
1097          return(ferror(stdout) ? -1 : 0);
1098   }
# Line 1079 | Line 1109 | putpword(                      /* put a 16-bit primary to stdout */
1109          i = colval(col,putprim)*65536.;
1110          vw = min(i,65535);
1111          if (swapbytes)
1112 <                swap16(&vw, 1);
1113 <        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
1112 >                swap16((char *)&vw, 1);
1113 >        putbinary(&vw, sizeof(uint16), 1, stdout);
1114  
1115          return(ferror(stdout) ? -1 : 0);
1116   }
# Line 1122 | Line 1152 | set_io(void)                   /* set put and get functions */
1152                                  if (fin2 == NULL)
1153                                          goto namerr;
1154                                  if (fseek(fin2,
1155 <                                (long)sizeof(float)*picres.xr*picres.yr, 1))
1155 >                                (long)sizeof(float)*picres.xr*picres.yr, SEEK_CUR))
1156                                          goto seekerr;
1157                                  if (fseek(fin3,
1158 <                                (long)sizeof(float)*2*picres.xr*picres.yr, 1))
1158 >                                (long)sizeof(float)*2*picres.xr*picres.yr, SEEK_CUR))
1159                                          goto seekerr;
1160                          }
1161                  }
# Line 1144 | Line 1174 | set_io(void)                   /* set put and get functions */
1174                                  if (fin2 == NULL)
1175                                          goto namerr;
1176                                  if (fseek(fin2,
1177 <                                (long)sizeof(double)*picres.xr*picres.yr, 1))
1177 >                                (long)sizeof(double)*picres.xr*picres.yr, SEEK_CUR))
1178                                          goto seekerr;
1179                                  if (fseek(fin3,
1180 <                                (long)sizeof(double)*2*picres.xr*picres.yr, 1))
1180 >                                (long)sizeof(double)*2*picres.xr*picres.yr, SEEK_CUR))
1181                                          goto seekerr;
1182                          }
1183                  }
# Line 1184 | Line 1214 | set_io(void)                   /* set put and get functions */
1214                                  if (fin2 == NULL)
1215                                          goto namerr;
1216                                  if (fseek(fin2,
1217 <                                (long)sizeof(BYTE)*picres.xr*picres.yr, 1))
1217 >                                (long)sizeof(uby8)*picres.xr*picres.yr, SEEK_CUR))
1218                                          goto seekerr;
1219                                  if (fseek(fin3,
1220 <                                (long)sizeof(BYTE)*2*picres.xr*picres.yr, 1))
1220 >                                (long)sizeof(uby8)*2*picres.xr*picres.yr, SEEK_CUR))
1221                                          goto seekerr;
1222                          }
1223                  }
# Line 1206 | Line 1236 | set_io(void)                   /* set put and get functions */
1236                                  if (fin2 == NULL)
1237                                          goto namerr;
1238                                  if (fseek(fin2,
1239 <                                (long)sizeof(uint16)*picres.xr*picres.yr, 1))
1239 >                                (long)sizeof(uint16)*picres.xr*picres.yr, SEEK_CUR))
1240                                          goto seekerr;
1241                                  if (fseek(fin3,
1242 <                                (long)sizeof(uint16)*2*picres.xr*picres.yr, 1))
1242 >                                (long)sizeof(uint16)*2*picres.xr*picres.yr, SEEK_CUR))
1243                                          goto seekerr;
1244                          }
1245                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines