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.33 by greg, Thu Aug 18 00:52:48 2016 UTC vs.
Revision 2.37 by greg, Wed Aug 14 18:20:02 2019 UTC

# 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 251 | Line 252 | unkopt:
252                  else
253                          fmtid = "16-bit_grey";
254          }
255 +        if (!reverse || (format != 'a') & (format != 'i'))
256 +                inpmode = "rb";
257                                          /* assign reverse ordering */
258          rord[ord[0]] = 0;
259          rord[ord[1]] = 1;
260          rord[ord[2]] = 2;
261                                          /* get input */
262          if (i == argc) {
263 +                long    n = skipbytes;
264 +                if (inpmode[1] == 'b')
265 +                        SET_FILE_BINARY(stdin);
266 +                while (n-- > 0)
267 +                        if (getchar() == EOF) {
268 +                                fprintf(stderr,
269 +                                "%s: cannot skip %ld bytes on standard input\n",
270 +                                                progname, skipbytes);
271 +                                quit(1);
272 +                        }
273                  fin = stdin;
274          } else if (i < argc) {
275 <                if ((fin = fopen(argv[i], "r")) == NULL) {
275 >                if ((fin = fopen(argv[i], inpmode)) == NULL) {
276                          fprintf(stderr, "%s: can't open file \"%s\"\n",
277                                                  progname, argv[i]);
278                          quit(1);
279                  }
280                  if (reverse && putprim != BRIGHT && i == argc-3) {
281 <                        if ((fin2 = fopen(argv[i+1], "r")) == NULL) {
281 >                        if ((fin2 = fopen(argv[i+1], inpmode)) == NULL) {
282                                  fprintf(stderr, "%s: can't open file \"%s\"\n",
283                                                  progname, argv[i+1]);
284                                  quit(1);
285                          }
286 <                        if ((fin3 = fopen(argv[i+2], "r")) == NULL) {
286 >                        if ((fin3 = fopen(argv[i+2], inpmode)) == NULL) {
287                                  fprintf(stderr, "%s: can't open file \"%s\"\n",
288                                                  progname, argv[i+2]);
289                                  quit(1);
# Line 279 | Line 292 | unkopt:
292                  } else if (i != argc-1)
293                          fin = NULL;
294                  if (reverse && putprim != BRIGHT && !interleave) {
295 <                        fin2 = fopen(argv[i], "r");
296 <                        fin3 = fopen(argv[i], "r");
295 >                        fin2 = fopen(argv[i], inpmode);
296 >                        fin3 = fopen(argv[i], inpmode);
297                  }
298 <                if (skipbytes && (fseek(fin, skipbytes, 0) || (fin2 != NULL &&
299 <                                (fseek(fin2, skipbytes, 0) ||
300 <                                fseek(fin3, skipbytes, 0))))) {
298 >                if (skipbytes && (fseek(fin, skipbytes, SEEK_SET) || (fin2 != NULL &&
299 >                                fseek(fin2, skipbytes, SEEK_SET) |
300 >                                fseek(fin3, skipbytes, SEEK_SET)))) {
301                          fprintf(stderr, "%s: cannot skip %ld bytes on input\n",
302                                          progname, skipbytes);
303                          quit(1);
# Line 296 | Line 309 | unkopt:
309          }
310  
311          if (reverse) {
299 #if defined(_WIN32) || defined(_WIN64)
312                  SET_FILE_BINARY(stdout);
301                if (format != 'a' && format != 'i')
302                        SET_FILE_BINARY(fin);
303 #endif
313                                          /* get header */
314                  if (header) {
315                          if (checkheader(fin, fmtid, stdout) < 0) {
# Line 349 | Line 358 | unkopt:
358                  fputsresolu(&picres, stdout);   /* always put resolution */
359                  valtopix();
360          } else {
361 < #if defined(_WIN32) || defined(_WIN64)
353 <                SET_FILE_BINARY(fin);
354 <                if (format != 'a' && format != 'i')
361 >                if ((format != 'a') & (format != 'i'))
362                          SET_FILE_BINARY(stdout);
356 #endif
363                                                  /* get header */
364                  getheader(fin, checkhead, NULL);
365                  if (wrongformat) {
# Line 370 | Line 376 | unkopt:
376                          printargs(i, argv, stdout);
377                          if (expval < .99 || expval > 1.01)
378                                  fputexpos(expval, stdout);
379 +                        if (swapbytes) {
380 +                                if (nativebigendian())
381 +                                        puts("BigEndian=0");
382 +                                else
383 +                                        puts("BigEndian=1");
384 +                        } else if ((format != 'a') & (format != 'i'))
385 +                                fputendian(stdout);
386                          fputformat(fmtid, stdout);
387                          putchar('\n');
388                  }
# Line 389 | Line 402 | checkhead(                             /* deal with line from header */
402          void    *p
403   )
404   {
405 <        char    fmt[32];
405 >        char    fmt[MAXFMTLEN];
406          double  d;
407          COLOR   ctmp;
408 +        int     rv;
409  
410          if (formatval(fmt, line)) {
411                  if (!strcmp(fmt, CIEFMT))
# Line 410 | Line 424 | checkhead(                             /* deal with line from header */
424                                  colval(exposure,GRN)/colval(ctmp,GRN),
425                                  colval(exposure,BLU)/colval(ctmp,BLU));
426                  doexposure++;
427 +        } else if (reverse && (rv = isbigendian(line)) >= 0) {
428 +                swapbytes = (nativebigendian() != rv);
429          } else if (header)
430                  fputs(line, stdout);
431          return(0);
# Line 419 | Line 435 | checkhead(                             /* deal with line from header */
435   static void
436   pixtoval(void)                          /* convert picture to values */
437   {
438 <        register COLOR  *scanln;
438 >        COLOR   *scanln;
439          int  dogamma;
440          COLOR  lastc;
441          RREAL  hv[2];
442          int  startprim, endprim;
443          long  startpos;
444 <        int  y;
429 <        register int  x;
444 >        int  x, y;
445  
446          scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
447          if (scanln == NULL) {
# Line 434 | Line 449 | pixtoval(void)                         /* convert picture to values */
449                  quit(1);
450          }
451          dogamma = gamcor < .95 || gamcor > 1.05;
452 <        if (putprim == ALL && !interleave) {
452 >        if ((putprim == ALL) & !interleave) {
453                  startprim = RED; endprim = BLU;
454                  startpos = ftell(fin);
455          } else {
456                  startprim = putprim; endprim = putprim;
457          }
458          for (putprim = startprim; putprim <= endprim; putprim++) {
459 <                if (putprim != startprim && fseek(fin, startpos, 0)) {
459 >                if (putprim != startprim && fseek(fin, startpos, SEEK_SET)) {
460                          fprintf(stderr, "%s: seek error on input file\n",
461                                          progname);
462                          quit(1);
# Line 493 | Line 508 | pixtoval(void)                         /* convert picture to values */
508   static void
509   valtopix(void)                  /* convert values to a pixel file */
510   {
511 <        int  dogamma;
512 <        register COLOR  *scanln;
513 <        int  y;
514 <        register int  x;
511 >        int     dogamma;
512 >        COLOR   *scanln;
513 >        COLR    rgbe;
514 >        int     x, y;
515  
516          scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
517          if (scanln == NULL) {
# Line 525 | Line 540 | valtopix(void)                 /* convert values to a pixel file */
540                                          pow(colval(scanln[x],BLU), gamcor));
541                          if (doexposure)
542                                  multcolor(scanln[x], exposure);
543 +                        if (uniq) {             /* uncompressed? */
544 +                                setcolr(rgbe,   scanln[x][RED],
545 +                                                scanln[x][GRN],
546 +                                                scanln[x][BLU]);
547 +                                if (putbinary(rgbe, sizeof(COLR), 1, stdout) != 1)
548 +                                        goto writerr;
549 +                        }
550                  }
551 <                if (fwritescan(scanln, scanlen(&picres), stdout) < 0) {
552 <                        fprintf(stderr, "%s: write error\n", progname);
553 <                        quit(1);
532 <                }
551 >                                                /* write scan if compressed */
552 >                if (!uniq && fwritescan(scanln, scanlen(&picres), stdout) < 0)
553 >                        goto writerr;
554          }
555          free((void *)scanln);
556 +        return;
557 + writerr:
558 +        fprintf(stderr, "%s: write error\n", progname);
559 +        quit(1);
560   }
561  
562  
# Line 939 | Line 964 | putbbyte(                      /* put a byte brightness to stdout */
964          COLOR  col
965   )
966   {
967 <        register int  i;
967 >        int  i;
968          uby8  vb;
969  
970          i = (*mybright)(col)*256.;
# Line 1092 | Line 1117 | set_io(void)                   /* set put and get functions */
1117                                  if (fin2 == NULL)
1118                                          goto namerr;
1119                                  if (fseek(fin2,
1120 <                                (long)sizeof(float)*picres.xr*picres.yr, 1))
1120 >                                (long)sizeof(float)*picres.xr*picres.yr, SEEK_CUR))
1121                                          goto seekerr;
1122                                  if (fseek(fin3,
1123 <                                (long)sizeof(float)*2*picres.xr*picres.yr, 1))
1123 >                                (long)sizeof(float)*2*picres.xr*picres.yr, SEEK_CUR))
1124                                          goto seekerr;
1125                          }
1126                  }
# Line 1114 | Line 1139 | set_io(void)                   /* set put and get functions */
1139                                  if (fin2 == NULL)
1140                                          goto namerr;
1141                                  if (fseek(fin2,
1142 <                                (long)sizeof(double)*picres.xr*picres.yr, 1))
1142 >                                (long)sizeof(double)*picres.xr*picres.yr, SEEK_CUR))
1143                                          goto seekerr;
1144                                  if (fseek(fin3,
1145 <                                (long)sizeof(double)*2*picres.xr*picres.yr, 1))
1145 >                                (long)sizeof(double)*2*picres.xr*picres.yr, SEEK_CUR))
1146                                          goto seekerr;
1147                          }
1148                  }
# Line 1154 | Line 1179 | set_io(void)                   /* set put and get functions */
1179                                  if (fin2 == NULL)
1180                                          goto namerr;
1181                                  if (fseek(fin2,
1182 <                                (long)sizeof(uby8)*picres.xr*picres.yr, 1))
1182 >                                (long)sizeof(uby8)*picres.xr*picres.yr, SEEK_CUR))
1183                                          goto seekerr;
1184                                  if (fseek(fin3,
1185 <                                (long)sizeof(uby8)*2*picres.xr*picres.yr, 1))
1185 >                                (long)sizeof(uby8)*2*picres.xr*picres.yr, SEEK_CUR))
1186                                          goto seekerr;
1187                          }
1188                  }
# Line 1176 | Line 1201 | set_io(void)                   /* set put and get functions */
1201                                  if (fin2 == NULL)
1202                                          goto namerr;
1203                                  if (fseek(fin2,
1204 <                                (long)sizeof(uint16)*picres.xr*picres.yr, 1))
1204 >                                (long)sizeof(uint16)*picres.xr*picres.yr, SEEK_CUR))
1205                                          goto seekerr;
1206                                  if (fseek(fin3,
1207 <                                (long)sizeof(uint16)*2*picres.xr*picres.yr, 1))
1207 >                                (long)sizeof(uint16)*2*picres.xr*picres.yr, SEEK_CUR))
1208                                          goto seekerr;
1209                          }
1210                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines