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.32 by schorsch, Sun Mar 6 01:13:17 2016 UTC vs.
Revision 2.43 by greg, Wed Sep 11 18:56:12 2024 UTC

# Line 26 | Line 26 | int  dataonly = 0;             /* data only format? */
26   int  putprim = ALL;             /* what to put out */
27   int  reverse = 0;               /* reverse conversion? */
28   int  format = 'a';              /* input/output format */
29 < char  *fmtid = "ascii";         /* format identifier for header */
29 > const char  *fmtid = "ascii";   /* format identifier for header */
30   int  header = 1;                /* do header? */
31   long  skipbytes = 0;            /* skip bytes in input? */
32   int  swapbytes = 0;             /* swap bytes? */
# Line 66 | Line 66 | static putfunc_t putbascii, putbint, putbdouble, putbf
66   static putfunc_t putcascii, putcint, putcdouble, putcfloat, putcbyte, putcword;
67   static putfunc_t putpascii, putpint, putpdouble, putpfloat, putpbyte, putpword;
68  
69 + static int IDformat(const char *s);
70   static void set_io(void);
71   static void pixtoval(void);
72   static void valtopix(void);
# Line 93 | Line 94 | main(
94          char  **argv
95   )
96   {
97 <        double  d, expval = 1.0;
98 <        int  i;
97 >        const char      *inpmode = "r";
98 >        double          d, expval = 1.0;
99 >        int             i;
100  
101          progname = argv[0];
102          mybright = &rgb_bright; /* default */
103 +        picres.rt = PIXSTANDARD;
104  
105          for (i = 1; i < argc; i++)
106                  if (argv[i][0] == '-' || argv[i][0] == '+')
# Line 117 | Line 120 | main(
120                          case 'o':               /* original values */
121                                  original = argv[i][0] == '-';
122                                  break;
123 +                        case 'O':               /* original watts/sr/m^2 */
124 +                                original = -(argv[i][0] == '-');
125 +                                break;
126                          case 'g':               /* gamma correction */
127                                  gamcor = atof(argv[i+1]);
128                                  if (argv[i][0] == '+')
# Line 172 | Line 178 | main(
178                                  }
179                                  break;
180                          case 'd':               /* data only (no indices) */
181 <                                dataonly = argv[i][0] == '-';
181 >                                dataonly = (argv[i][0] == '-');
182                                  switch (argv[i][2]) {
183                                  case '\0':
184                                  case 'a':               /* ascii */
# Line 214 | Line 220 | main(
220                                  }
221                                  break;
222                          case 'x':               /* x resolution */
223 <                        case 'X':               /* x resolution */
223 >                        case 'X':
224                                  resolution = 0;
225                                  if (argv[i][0] == '-')
226                                          picres.rt |= XDECR;
227 +                                else
228 +                                        picres.rt &= ~XDECR;
229 +                                if (picres.yr == 0)
230 +                                        picres.rt &= ~YMAJOR;
231                                  picres.xr = atoi(argv[++i]);
232                                  break;
233                          case 'y':               /* y resolution */
234 <                        case 'Y':               /* y resolution */
234 >                        case 'Y':
235                                  resolution = 0;
236                                  if (argv[i][0] == '-')
237                                          picres.rt |= YDECR;
238 +                                else
239 +                                        picres.rt &= ~YDECR;
240                                  if (picres.xr == 0)
241                                          picres.rt |= YMAJOR;
242                                  picres.yr = atoi(argv[++i]);
# Line 239 | Line 251 | unkopt:
251                  else
252                          break;
253                                          /* recognize special formats */
254 <        if (dataonly && format == 'b') {
254 >        if (dataonly & (format == 'b')) {
255                  if (putprim == ALL)
256                          fmtid = "24-bit_rgb";
257                  else
258                          fmtid = "8-bit_grey";
259          }
260 <        if (dataonly && format == 'w') {
260 >        if (dataonly & (format == 'w')) {
261                  if (putprim == ALL)
262                          fmtid = "48-bit_rgb";
263                  else
264                          fmtid = "16-bit_grey";
265          }
266 +        if (!reverse | ((format != 'a') & (format != 'i')))
267 +                inpmode = "rb";
268                                          /* assign reverse ordering */
269          rord[ord[0]] = 0;
270          rord[ord[1]] = 1;
271          rord[ord[2]] = 2;
272                                          /* get input */
273          if (i == argc) {
274 +                long    n = skipbytes;
275 +                if (inpmode[1] == 'b')
276 +                        SET_FILE_BINARY(stdin);
277 +                while (n-- > 0)
278 +                        if (getchar() == EOF) {
279 +                                fprintf(stderr,
280 +                                "%s: cannot skip %ld bytes on standard input\n",
281 +                                                progname, skipbytes);
282 +                                quit(1);
283 +                        }
284                  fin = stdin;
285          } else if (i < argc) {
286 <                if ((fin = fopen(argv[i], "r")) == NULL) {
286 >                if ((fin = fopen(argv[i], inpmode)) == NULL) {
287                          fprintf(stderr, "%s: can't open file \"%s\"\n",
288                                                  progname, argv[i]);
289                          quit(1);
290                  }
291 <                if (reverse && putprim != BRIGHT && i == argc-3) {
292 <                        if ((fin2 = fopen(argv[i+1], "r")) == NULL) {
291 >                if (reverse & (putprim != BRIGHT ) & (i == argc-3)) {
292 >                        if ((fin2 = fopen(argv[i+1], inpmode)) == NULL) {
293                                  fprintf(stderr, "%s: can't open file \"%s\"\n",
294                                                  progname, argv[i+1]);
295                                  quit(1);
296                          }
297 <                        if ((fin3 = fopen(argv[i+2], "r")) == NULL) {
297 >                        if ((fin3 = fopen(argv[i+2], inpmode)) == NULL) {
298                                  fprintf(stderr, "%s: can't open file \"%s\"\n",
299                                                  progname, argv[i+2]);
300                                  quit(1);
# Line 278 | Line 302 | unkopt:
302                          interleave = -1;
303                  } else if (i != argc-1)
304                          fin = NULL;
305 <                if (reverse && putprim != BRIGHT && !interleave) {
306 <                        fin2 = fopen(argv[i], "r");
307 <                        fin3 = fopen(argv[i], "r");
305 >                if (reverse & (putprim != BRIGHT) & !interleave) {
306 >                        fin2 = fopen(argv[i], inpmode);
307 >                        fin3 = fopen(argv[i], inpmode);
308                  }
309 <                if (skipbytes && (fseek(fin, skipbytes, 0) || (fin2 != NULL &&
310 <                                (fseek(fin2, skipbytes, 0) ||
311 <                                fseek(fin3, skipbytes, 0))))) {
309 >                if (skipbytes && (fseek(fin, skipbytes, SEEK_SET) || (fin2 != NULL &&
310 >                                fseek(fin2, skipbytes, SEEK_SET) |
311 >                                fseek(fin3, skipbytes, SEEK_SET)))) {
312                          fprintf(stderr, "%s: cannot skip %ld bytes on input\n",
313                                          progname, skipbytes);
314                          quit(1);
# Line 294 | Line 318 | unkopt:
318                  fprintf(stderr, "%s: bad # file arguments\n", progname);
319                  quit(1);
320          }
297
321          if (reverse) {
299 #if defined(_WIN32) || defined(_WIN64)
322                  SET_FILE_BINARY(stdout);
301                if (format != 'a' && format != 'i')
302                        SET_FILE_BINARY(fin);
303 #endif
323                                          /* get header */
324                  if (header) {
325 <                        if (checkheader(fin, fmtid, stdout) < 0) {
326 <                                fprintf(stderr, "%s: wrong input format\n",
327 <                                                progname);
325 >                        getheader(fin, checkhead, stdout);
326 >                        if (wrongformat) {
327 >                                fprintf(stderr, "%s: wrong input format (expected %s)\n",
328 >                                                progname, fmtid);
329                                  quit(1);
330                          }
331                          if (fin2 != NULL) {
332                                  getheader(fin2, NULL, NULL);
333                                  getheader(fin3, NULL, NULL);
334                          }
335 <                } else
335 >                        resolution &= (picres.xr <= 0) | (picres.yr <= 0);
336 >                } else {
337                          newheader("RADIANCE", stdout);
338 +                }
339                                          /* get resolution */
340                  if ((resolution && !fgetsresolu(&picres, fin)) ||
341 <                                picres.xr <= 0 || picres.yr <= 0) {
341 >                                (picres.xr <= 0) | (picres.yr <= 0)) {
342                          fprintf(stderr, "%s: missing resolution\n", progname);
343                          quit(1);
344                  }
345                  if (resolution && fin2 != NULL) {
346                          RESOLU  pres2;
347                          if (!fgetsresolu(&pres2, fin2) ||
348 <                                        pres2.rt != picres.rt ||
349 <                                        pres2.xr != picres.xr ||
350 <                                        pres2.yr != picres.yr ||
348 >                                        (pres2.rt != picres.rt) |
349 >                                        (pres2.xr != picres.xr) |
350 >                                        (pres2.yr != picres.yr) ||
351                                          !fgetsresolu(&pres2, fin3) ||
352 <                                        pres2.rt != picres.rt ||
353 <                                        pres2.xr != picres.xr ||
354 <                                        pres2.yr != picres.yr) {
352 >                                        (pres2.rt != picres.rt) |
353 >                                        (pres2.xr != picres.xr) |
354 >                                        (pres2.yr != picres.yr)) {
355                                  fprintf(stderr, "%s: resolution mismatch\n",
356                                                  progname);
357                                  quit(1);
# Line 337 | Line 359 | unkopt:
359                  }
360                                                  /* add to header */
361                  printargs(i, argv, stdout);
362 <                if (expval < .99 || expval > 1.01)
362 >                if ((expval < .99) | (expval > 1.01))
363                          fputexpos(expval, stdout);
364 +                if (NCSAMP == 1) {
365 +                        if (putprim == ALL)
366 +                                putprim = BRIGHT;
367 +                } else {
368 +                        if (NCSAMP != 3) {
369 +                                fprintf(stderr, "%s: input NCOMP must be 1 or 3\n",
370 +                                                progname);
371 +                                quit(1);
372 +                        }
373 +                        if (putprim != ALL) {
374 +                                fprintf(stderr, "%s: NCOMP mismatch\n", progname);
375 +                                quit(1);
376 +                        }
377 +                }
378                  if (outprims != NULL) {
379                          if (outprims != stdprims)
380                                  fputprims(outprims, stdout);
381                          fputformat(COLRFMT, stdout);
382 <                } else                          /* XYZ data */
382 >                } else {                        /* XYZ data */
383 >                        if (original < 0) {
384 >                                scalecolor(exposure, WHTEFFICACY);
385 >                                doexposure++;
386 >                        }
387                          fputformat(CIEFMT, stdout);
388 +                }
389                  putchar('\n');
390                  fputsresolu(&picres, stdout);   /* always put resolution */
391                  valtopix();
392          } else {
393 < #if defined(_WIN32) || defined(_WIN64)
353 <                SET_FILE_BINARY(fin);
354 <                if (format != 'a' && format != 'i')
393 >                if ((format != 'a') & (format != 'i'))
394                          SET_FILE_BINARY(stdout);
356 #endif
395                                                  /* get header */
396 <                getheader(fin, checkhead, NULL);
396 >                picres.rt = PIXSTANDARD;
397 >                picres.xr = picres.yr = 0;
398 >                getheader(fin, checkhead, header ? stdout : (FILE *)NULL);
399                  if (wrongformat) {
400                          fprintf(stderr,
401                                  "%s: input not a Radiance RGBE picture\n",
402                                          progname);
403                          quit(1);
404                  }
405 <                if (!fgetsresolu(&picres, fin)) {
405 >                if ((picres.xr <= 0) | (picres.yr <= 0) &&
406 >                                !fgetsresolu(&picres, fin)) {
407                          fprintf(stderr, "%s: missing resolution\n", progname);
408                          quit(1);
409                  }
410 +                if ((original < 0) & (mybright == &xyz_bright)) {
411 +                        scalecolor(exposure, 1./WHTEFFICACY);
412 +                        doexposure++;
413 +                }
414                  if (header) {
415                          printargs(i, argv, stdout);
416 <                        if (expval < .99 || expval > 1.01)
416 >                        printf("%s%c\n", NCOMPSTR, "13"[putprim==ALL]);
417 >                        if (dataonly && !resolution & !uniq)
418 >                                printf("NCOLS=%d\nNROWS=%d\n", scanlen(&picres),
419 >                                                numscans(&picres));
420 >                        if ((expval < .99) | (expval > 1.01))
421                                  fputexpos(expval, stdout);
422 +                        if (swapbytes) {
423 +                                if (nativebigendian())
424 +                                        puts("BigEndian=0");
425 +                                else
426 +                                        puts("BigEndian=1");
427 +                        } else if ((format != 'a') & (format != 'i') &
428 +                                                (format != 'b'))
429 +                                fputendian(stdout);
430                          fputformat(fmtid, stdout);
431                          putchar('\n');
432                  }
# Line 384 | Line 441 | unkopt:
441  
442  
443   static int
444 + IDformat(const char *s)
445 + {
446 +        if (!s || !*s) return(0);
447 +        if (!strcmp(s, "ascii")) return('a');
448 +        if (!strcmp(s, "float")) return('f');
449 +        if (!strcmp(s, "double")) return('d');
450 +        if (!strcmp(s, "byte")) return('b');
451 +        if (!strcmp(s, "16-bit")) return('w');
452 +        return(0);
453 + }
454 +
455 +
456 + static int
457   checkhead(                              /* deal with line from header */
458          char    *line,
459          void    *p
460   )
461   {
462 <        char    fmt[32];
462 >        static char     fmt[MAXFMTLEN];
463 >        FILE    *fout = (FILE *)p;
464          double  d;
465          COLOR   ctmp;
466 +        int     rv;
467  
468          if (formatval(fmt, line)) {
469 <                if (!strcmp(fmt, CIEFMT))
469 >                if (reverse) {
470 >                        if (format == 'a') {
471 >                                format = IDformat(fmt);
472 >                                if (format)
473 >                                        fmtid = fmt;
474 >                                else
475 >                                        wrongformat = 1;
476 >                        } else
477 >                                wrongformat = strcmp(fmt, fmtid);
478 >                } else if (!strcmp(fmt, CIEFMT))
479                          mybright = &xyz_bright;
480 <                else if (!strcmp(fmt, COLRFMT))
480 >                else if (!strcmp(fmt, COLRFMT) || !strcmp(fmt, SPECFMT))
481                          mybright = &rgb_bright;
482                  else
483 <                        wrongformat++;
484 <        } else if (original && isexpos(line)) {
483 >                        wrongformat = 1;
484 >                return(1);
485 >        }
486 >        if (!strncmp(line,"NROWS=",6)) {
487 >                picres.yr = atoi(line+6);
488 >                return(1);
489 >        }
490 >        if (!strncmp(line,"NCOLS=",6)) {
491 >                picres.xr = atoi(line+6);
492 >                return(1);
493 >        }
494 >        if (isncomp(line)) {
495 >                NCSAMP = ncompval(line);
496 >                dataonly |= reverse;    /* pretty safe assumption */
497 >                return(1);
498 >        }
499 >        if (iswlsplit(line)) {
500 >                wlsplitval(WLPART, line);
501 >                return(1);
502 >        }
503 >        if (original && isexpos(line)) {
504                  d = 1.0/exposval(line);
505                  scalecolor(exposure, d);
506                  doexposure++;
507 <        } else if (original && iscolcor(line)) {
507 >                return(1);
508 >        }
509 >        if (original && iscolcor(line)) {
510                  colcorval(ctmp, line);
511                  setcolor(exposure, colval(exposure,RED)/colval(ctmp,RED),
512                                  colval(exposure,GRN)/colval(ctmp,GRN),
513                                  colval(exposure,BLU)/colval(ctmp,BLU));
514                  doexposure++;
515 <        } else if (header)
516 <                fputs(line, stdout);
515 >                return(1);
516 >        }
517 >        if ((rv = isbigendian(line)) >= 0) {
518 >                if (reverse)
519 >                        swapbytes = (nativebigendian() != rv);
520 >                return(1);
521 >        }
522 >        if (fout != NULL)
523 >                fputs(line, fout);
524          return(0);
525   }
526  
# Line 419 | Line 528 | checkhead(                             /* deal with line from header */
528   static void
529   pixtoval(void)                          /* convert picture to values */
530   {
531 <        register COLOR  *scanln;
531 >        COLOR   *scanln;
532          int  dogamma;
533          COLOR  lastc;
534          RREAL  hv[2];
535          int  startprim, endprim;
536          long  startpos;
537 <        int  y;
429 <        register int  x;
537 >        int  x, y;
538  
539          scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
540          if (scanln == NULL) {
# Line 434 | Line 542 | pixtoval(void)                         /* convert picture to values */
542                  quit(1);
543          }
544          dogamma = gamcor < .95 || gamcor > 1.05;
545 <        if (putprim == ALL && !interleave) {
545 >        if ((putprim == ALL) & !interleave) {
546                  startprim = RED; endprim = BLU;
547                  startpos = ftell(fin);
548          } else {
549                  startprim = putprim; endprim = putprim;
550          }
551          for (putprim = startprim; putprim <= endprim; putprim++) {
552 <                if (putprim != startprim && fseek(fin, startpos, 0)) {
552 >                if (putprim != startprim && fseek(fin, startpos, SEEK_SET)) {
553                          fprintf(stderr, "%s: seek error on input file\n",
554                                          progname);
555                          quit(1);
# Line 449 | Line 557 | pixtoval(void)                         /* convert picture to values */
557                  set_io();
558                  setcolor(lastc, 0.0, 0.0, 0.0);
559                  for (y = 0; y < numscans(&picres); y++) {
560 <                        if (freadscan(scanln, scanlen(&picres), fin) < 0) {
560 >                        if (fread2scan(scanln, scanlen(&picres), fin,
561 >                                                NCSAMP, WLPART) < 0) {
562                                  fprintf(stderr, "%s: read error\n", progname);
563                                  quit(1);
564                          }
# Line 493 | Line 602 | pixtoval(void)                         /* convert picture to values */
602   static void
603   valtopix(void)                  /* convert values to a pixel file */
604   {
605 <        int  dogamma;
606 <        register COLOR  *scanln;
607 <        int  y;
608 <        register int  x;
605 >        int     dogamma;
606 >        COLOR   *scanln;
607 >        COLR    rgbe;
608 >        int     x, y;
609  
610          scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
611          if (scanln == NULL) {
# Line 525 | Line 634 | valtopix(void)                 /* convert values to a pixel file */
634                                          pow(colval(scanln[x],BLU), gamcor));
635                          if (doexposure)
636                                  multcolor(scanln[x], exposure);
637 +                        if (uniq) {             /* uncompressed? */
638 +                                setcolr(rgbe,   scanln[x][RED],
639 +                                                scanln[x][GRN],
640 +                                                scanln[x][BLU]);
641 +                                if (putbinary(rgbe, sizeof(COLR), 1, stdout) != 1)
642 +                                        goto writerr;
643 +                        }
644                  }
645 <                if (fwritescan(scanln, scanlen(&picres), stdout) < 0) {
646 <                        fprintf(stderr, "%s: write error\n", progname);
647 <                        quit(1);
532 <                }
645 >                                                /* write scan if compressed */
646 >                if (!uniq && fwritescan(scanln, scanlen(&picres), stdout) < 0)
647 >                        goto writerr;
648          }
649          free((void *)scanln);
650 +        return;
651 + writerr:
652 +        fprintf(stderr, "%s: write error\n", progname);
653 +        quit(1);
654   }
655  
656  
# Line 572 | Line 691 | getcdouble(            /* get a double color value from stream(s
691          double  vd[3];
692  
693          if (fin2 == NULL) {
694 <                if (fread((char *)vd, sizeof(double), 3, fin) != 3)
694 >                if (getbinary(vd, sizeof(double), 3, fin) != 3)
695                          return(-1);
696          } else {
697 <                if (fread((char *)vd, sizeof(double), 1, fin) != 1 ||
698 <                        fread((char *)(vd+1), sizeof(double), 1, fin2) != 1 ||
699 <                        fread((char *)(vd+2), sizeof(double), 1, fin3) != 1)
697 >                if (getbinary(vd, sizeof(double), 1, fin) != 1 ||
698 >                        getbinary(vd+1, sizeof(double), 1, fin2) != 1 ||
699 >                        getbinary(vd+2, sizeof(double), 1, fin3) != 1)
700                          return(-1);
701          }
702          if (swapbytes)
# Line 595 | Line 714 | getcfloat(             /* get a float color value from stream(s)
714          float  vf[3];
715  
716          if (fin2 == NULL) {
717 <                if (fread((char *)vf, sizeof(float), 3, fin) != 3)
717 >                if (getbinary(vf, sizeof(float), 3, fin) != 3)
718                          return(-1);
719          } else {
720 <                if (fread((char *)vf, sizeof(float), 1, fin) != 1 ||
721 <                        fread((char *)(vf+1), sizeof(float), 1, fin2) != 1 ||
722 <                        fread((char *)(vf+2), sizeof(float), 1, fin3) != 1)
720 >                if (getbinary(vf, sizeof(float), 1, fin) != 1 ||
721 >                        getbinary(vf+1, sizeof(float), 1, fin2) != 1 ||
722 >                        getbinary(vf+2, sizeof(float), 1, fin3) != 1)
723                          return(-1);
724          }
725          if (swapbytes)
# Line 640 | Line 759 | getcbyte(              /* get a byte color value from stream(s) */
759          uby8  vb[3];
760  
761          if (fin2 == NULL) {
762 <                if (fread((char *)vb, sizeof(uby8), 3, fin) != 3)
762 >                if (getbinary(vb, sizeof(uby8), 3, fin) != 3)
763                          return(-1);
764          } else {
765 <                if (fread((char *)vb, sizeof(uby8), 1, fin) != 1 ||
766 <                        fread((char *)(vb+1), sizeof(uby8), 1, fin2) != 1 ||
767 <                        fread((char *)(vb+2), sizeof(uby8), 1, fin3) != 1)
765 >                if (getbinary(vb, sizeof(uby8), 1, fin) != 1 ||
766 >                        getbinary(vb+1, sizeof(uby8), 1, fin2) != 1 ||
767 >                        getbinary(vb+2, sizeof(uby8), 1, fin3) != 1)
768                          return(-1);
769          }
770          setcolor(col, (vb[rord[RED]]+.5)/256.,
# Line 662 | Line 781 | getcword(              /* get a 16-bit color value from stream(s)
781          uint16  vw[3];
782  
783          if (fin2 == NULL) {
784 <                if (fread((char *)vw, sizeof(uint16), 3, fin) != 3)
784 >                if (getbinary(vw, sizeof(uint16), 3, fin) != 3)
785                          return(-1);
786          } else {
787 <                if (fread((char *)vw, sizeof(uint16), 1, fin) != 1 ||
788 <                        fread((char *)(vw+1), sizeof(uint16), 1, fin2) != 1 ||
789 <                        fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1)
787 >                if (getbinary(vw, sizeof(uint16), 1, fin) != 1 ||
788 >                        getbinary(vw+1, sizeof(uint16), 1, fin2) != 1 ||
789 >                        getbinary(vw+2, sizeof(uint16), 1, fin3) != 1)
790                          return(-1);
791          }
792          if (swapbytes)
# Line 699 | Line 818 | getbdouble(            /* get a double brightness value from fin
818   {
819          double  vd;
820  
821 <        if (fread((char *)&vd, sizeof(double), 1, fin) != 1)
821 >        if (getbinary(&vd, sizeof(double), 1, fin) != 1)
822                  return(-1);
823          if (swapbytes)
824                  swap64((char *)&vd, 1);
# Line 715 | Line 834 | getbfloat(             /* get a float brightness value from fin *
834   {
835          float  vf;
836  
837 <        if (fread((char *)&vf, sizeof(float), 1, fin) != 1)
837 >        if (getbinary(&vf, sizeof(float), 1, fin) != 1)
838                  return(-1);
839          if (swapbytes)
840                  swap32((char *)&vf, 1);
# Line 748 | Line 867 | getbbyte(              /* get a byte brightness value from fin */
867          uby8  vb;
868          double  d;
869  
870 <        if (fread((char *)&vb, sizeof(uby8), 1, fin) != 1)
870 >        if (getbinary(&vb, sizeof(uby8), 1, fin) != 1)
871                  return(-1);
872          d = (vb+.5)/256.;
873          setcolor(col, d, d, d);
# Line 764 | Line 883 | getbword(              /* get a 16-bit brightness value from fin *
883          uint16  vw;
884          double  d;
885  
886 <        if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1)
886 >        if (getbinary(&vw, sizeof(uint16), 1, fin) != 1)
887                  return(-1);
888          if (swapbytes)
889                  swap16((char *)&vw, 1);
# Line 800 | Line 919 | putcfloat(                     /* put a float color to stdout */
919          vf[2] = colval(col,ord[2]);
920          if (swapbytes)
921                  swap32((char *)vf, 3);
922 <        fwrite((char *)vf, sizeof(float), 3, stdout);
922 >        putbinary(vf, sizeof(float), 3, stdout);
923  
924          return(ferror(stdout) ? -1 : 0);
925   }
# Line 818 | Line 937 | putcdouble(                    /* put a double color to stdout */
937          vd[2] = colval(col,ord[2]);
938          if (swapbytes)
939                  swap64((char *)vd, 3);
940 <        fwrite((char *)vd, sizeof(double), 3, stdout);
940 >        putbinary(vd, sizeof(double), 3, stdout);
941  
942          return(ferror(stdout) ? -1 : 0);
943   }
# Line 852 | Line 971 | putcbyte(                      /* put a byte color to stdout */
971          vb[1] = min(i,255);
972          i = colval(col,ord[2])*256.;
973          vb[2] = min(i,255);
974 <        fwrite((char *)vb, sizeof(uby8), 3, stdout);
974 >        putbinary(vb, sizeof(uby8), 3, stdout);
975  
976          return(ferror(stdout) ? -1 : 0);
977   }
# Line 874 | Line 993 | putcword(                      /* put a 16-bit color to stdout */
993          vw[2] = min(i,65535);
994          if (swapbytes)
995                  swap16((char *)vw, 3);
996 <        fwrite((char *)vw, sizeof(uint16), 3, stdout);
996 >        putbinary(vw, sizeof(uint16), 3, stdout);
997  
998          return(ferror(stdout) ? -1 : 0);
999   }
# Line 901 | Line 1020 | putbfloat(                     /* put a float brightness to stdout */
1020          vf = (*mybright)(col);
1021          if (swapbytes)
1022                  swap32((char *)&vf, 1);
1023 <        fwrite((char *)&vf, sizeof(float), 1, stdout);
1023 >        putbinary(&vf, sizeof(float), 1, stdout);
1024  
1025          return(ferror(stdout) ? -1 : 0);
1026   }
# Line 917 | Line 1036 | putbdouble(                    /* put a double brightness to stdout */
1036          vd = (*mybright)(col);
1037          if (swapbytes)
1038                  swap64((char *)&vd, 1);
1039 <        fwrite((char *)&vd, sizeof(double), 1, stdout);
1039 >        putbinary(&vd, sizeof(double), 1, stdout);
1040  
1041          return(ferror(stdout) ? -1 : 0);
1042   }
# Line 939 | Line 1058 | putbbyte(                      /* put a byte brightness to stdout */
1058          COLOR  col
1059   )
1060   {
1061 <        register int  i;
1061 >        int  i;
1062          uby8  vb;
1063  
1064          i = (*mybright)(col)*256.;
1065          vb = min(i,255);
1066 <        fwrite((char *)&vb, sizeof(uby8), 1, stdout);
1066 >        putbinary(&vb, sizeof(uby8), 1, stdout);
1067  
1068          return(ferror(stdout) ? -1 : 0);
1069   }
# Line 962 | Line 1081 | putbword(                      /* put a 16-bit brightness to stdout */
1081          vw = min(i,65535);
1082          if (swapbytes)
1083                  swap16((char *)&vw, 1);
1084 <        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
1084 >        putbinary(&vw, sizeof(uint16), 1, stdout);
1085  
1086          return(ferror(stdout) ? -1 : 0);
1087   }
# Line 989 | Line 1108 | putpfloat(                     /* put a float primary to stdout */
1108          vf = colval(col,putprim);
1109          if (swapbytes)
1110                  swap32((char *)&vf, 1);
1111 <        fwrite((char *)&vf, sizeof(float), 1, stdout);
1111 >        putbinary(&vf, sizeof(float), 1, stdout);
1112  
1113          return(ferror(stdout) ? -1 : 0);
1114   }
# Line 1005 | Line 1124 | putpdouble(                    /* put a double primary to stdout */
1124          vd = colval(col,putprim);
1125          if (swapbytes)
1126                  swap64((char *)&vd, 1);
1127 <        fwrite((char *)&vd, sizeof(double), 1, stdout);
1127 >        putbinary(&vd, sizeof(double), 1, stdout);
1128  
1129          return(ferror(stdout) ? -1 : 0);
1130   }
# Line 1032 | Line 1151 | putpbyte(                      /* put a byte primary to stdout */
1151  
1152          i = colval(col,putprim)*256.;
1153          vb = min(i,255);
1154 <        fwrite((char *)&vb, sizeof(uby8), 1, stdout);
1154 >        putbinary(&vb, sizeof(uby8), 1, stdout);
1155  
1156          return(ferror(stdout) ? -1 : 0);
1157   }
# Line 1050 | Line 1169 | putpword(                      /* put a 16-bit primary to stdout */
1169          vw = min(i,65535);
1170          if (swapbytes)
1171                  swap16((char *)&vw, 1);
1172 <        fwrite((char *)&vw, sizeof(uint16), 1, stdout);
1172 >        putbinary(&vw, sizeof(uint16), 1, stdout);
1173  
1174          return(ferror(stdout) ? -1 : 0);
1175   }
# Line 1092 | Line 1211 | set_io(void)                   /* set put and get functions */
1211                                  if (fin2 == NULL)
1212                                          goto namerr;
1213                                  if (fseek(fin2,
1214 <                                (long)sizeof(float)*picres.xr*picres.yr, 1))
1214 >                                (long)sizeof(float)*picres.xr*picres.yr, SEEK_CUR))
1215                                          goto seekerr;
1216                                  if (fseek(fin3,
1217 <                                (long)sizeof(float)*2*picres.xr*picres.yr, 1))
1217 >                                (long)sizeof(float)*2*picres.xr*picres.yr, SEEK_CUR))
1218                                          goto seekerr;
1219                          }
1220                  }
# Line 1114 | Line 1233 | set_io(void)                   /* set put and get functions */
1233                                  if (fin2 == NULL)
1234                                          goto namerr;
1235                                  if (fseek(fin2,
1236 <                                (long)sizeof(double)*picres.xr*picres.yr, 1))
1236 >                                (long)sizeof(double)*picres.xr*picres.yr, SEEK_CUR))
1237                                          goto seekerr;
1238                                  if (fseek(fin3,
1239 <                                (long)sizeof(double)*2*picres.xr*picres.yr, 1))
1239 >                                (long)sizeof(double)*2*picres.xr*picres.yr, SEEK_CUR))
1240                                          goto seekerr;
1241                          }
1242                  }
# Line 1154 | Line 1273 | set_io(void)                   /* set put and get functions */
1273                                  if (fin2 == NULL)
1274                                          goto namerr;
1275                                  if (fseek(fin2,
1276 <                                (long)sizeof(uby8)*picres.xr*picres.yr, 1))
1276 >                                (long)sizeof(uby8)*picres.xr*picres.yr, SEEK_CUR))
1277                                          goto seekerr;
1278                                  if (fseek(fin3,
1279 <                                (long)sizeof(uby8)*2*picres.xr*picres.yr, 1))
1279 >                                (long)sizeof(uby8)*2*picres.xr*picres.yr, SEEK_CUR))
1280                                          goto seekerr;
1281                          }
1282                  }
# Line 1176 | Line 1295 | set_io(void)                   /* set put and get functions */
1295                                  if (fin2 == NULL)
1296                                          goto namerr;
1297                                  if (fseek(fin2,
1298 <                                (long)sizeof(uint16)*picres.xr*picres.yr, 1))
1298 >                                (long)sizeof(uint16)*picres.xr*picres.yr, SEEK_CUR))
1299                                          goto seekerr;
1300                                  if (fseek(fin3,
1301 <                                (long)sizeof(uint16)*2*picres.xr*picres.yr, 1))
1301 >                                (long)sizeof(uint16)*2*picres.xr*picres.yr, SEEK_CUR))
1302                                          goto seekerr;
1303                          }
1304                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines