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.35 by greg, Mon Jul 15 22:39:50 2019 UTC vs.
Revision 2.38 by greg, Thu Feb 6 19:33:32 2020 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) {
316 <                                fprintf(stderr, "%s: wrong input format\n",
317 <                                                progname);
315 >                        getheader(fin, checkhead, stdout);
316 >                        if (wrongformat) {
317 >                                fprintf(stderr, "%s: wrong input format (expected %s)\n",
318 >                                                progname, fmtid);
319                                  quit(1);
320                          }
321                          if (fin2 != NULL) {
# Line 349 | Line 359 | unkopt:
359                  fputsresolu(&picres, stdout);   /* always put resolution */
360                  valtopix();
361          } else {
362 < #if defined(_WIN32) || defined(_WIN64)
353 <                SET_FILE_BINARY(fin);
354 <                if (format != 'a' && format != 'i')
362 >                if ((format != 'a') & (format != 'i'))
363                          SET_FILE_BINARY(stdout);
356 #endif
364                                                  /* get header */
365 <                getheader(fin, checkhead, NULL);
365 >                getheader(fin, checkhead, header ? stdout : (FILE *)NULL);
366                  if (wrongformat) {
367                          fprintf(stderr,
368                                  "%s: input not a Radiance RGBE picture\n",
# Line 370 | Line 377 | unkopt:
377                          printargs(i, argv, stdout);
378                          if (expval < .99 || expval > 1.01)
379                                  fputexpos(expval, stdout);
380 +                        if (swapbytes) {
381 +                                if (nativebigendian())
382 +                                        puts("BigEndian=0");
383 +                                else
384 +                                        puts("BigEndian=1");
385 +                        } else if ((format != 'a') & (format != 'i'))
386 +                                fputendian(stdout);
387                          fputformat(fmtid, stdout);
388                          putchar('\n');
389                  }
# Line 389 | Line 403 | checkhead(                             /* deal with line from header */
403          void    *p
404   )
405   {
406 +        FILE    *fout = (FILE *)p;
407          char    fmt[MAXFMTLEN];
408          double  d;
409          COLOR   ctmp;
410 +        int     rv;
411  
412          if (formatval(fmt, line)) {
413 <                if (!strcmp(fmt, CIEFMT))
413 >                if (reverse)
414 >                        wrongformat = strcmp(fmt, fmtid);
415 >                else if (!strcmp(fmt, CIEFMT))
416                          mybright = &xyz_bright;
417                  else if (!strcmp(fmt, COLRFMT))
418                          mybright = &rgb_bright;
# Line 410 | Line 428 | checkhead(                             /* deal with line from header */
428                                  colval(exposure,GRN)/colval(ctmp,GRN),
429                                  colval(exposure,BLU)/colval(ctmp,BLU));
430                  doexposure++;
431 <        } else if (header)
432 <                fputs(line, stdout);
431 >        } else if ((rv = isbigendian(line)) >= 0) {
432 >                if (reverse)
433 >                        swapbytes = (nativebigendian() != rv);
434 >        } else if (fout != NULL)
435 >                fputs(line, fout);
436          return(0);
437   }
438  
# Line 433 | Line 454 | pixtoval(void)                         /* convert picture to values */
454                  quit(1);
455          }
456          dogamma = gamcor < .95 || gamcor > 1.05;
457 <        if (putprim == ALL && !interleave) {
457 >        if ((putprim == ALL) & !interleave) {
458                  startprim = RED; endprim = BLU;
459                  startpos = ftell(fin);
460          } else {
461                  startprim = putprim; endprim = putprim;
462          }
463          for (putprim = startprim; putprim <= endprim; putprim++) {
464 <                if (putprim != startprim && fseek(fin, startpos, 0)) {
464 >                if (putprim != startprim && fseek(fin, startpos, SEEK_SET)) {
465                          fprintf(stderr, "%s: seek error on input file\n",
466                                          progname);
467                          quit(1);
# Line 1101 | Line 1122 | set_io(void)                   /* set put and get functions */
1122                                  if (fin2 == NULL)
1123                                          goto namerr;
1124                                  if (fseek(fin2,
1125 <                                (long)sizeof(float)*picres.xr*picres.yr, 1))
1125 >                                (long)sizeof(float)*picres.xr*picres.yr, SEEK_CUR))
1126                                          goto seekerr;
1127                                  if (fseek(fin3,
1128 <                                (long)sizeof(float)*2*picres.xr*picres.yr, 1))
1128 >                                (long)sizeof(float)*2*picres.xr*picres.yr, SEEK_CUR))
1129                                          goto seekerr;
1130                          }
1131                  }
# Line 1123 | Line 1144 | set_io(void)                   /* set put and get functions */
1144                                  if (fin2 == NULL)
1145                                          goto namerr;
1146                                  if (fseek(fin2,
1147 <                                (long)sizeof(double)*picres.xr*picres.yr, 1))
1147 >                                (long)sizeof(double)*picres.xr*picres.yr, SEEK_CUR))
1148                                          goto seekerr;
1149                                  if (fseek(fin3,
1150 <                                (long)sizeof(double)*2*picres.xr*picres.yr, 1))
1150 >                                (long)sizeof(double)*2*picres.xr*picres.yr, SEEK_CUR))
1151                                          goto seekerr;
1152                          }
1153                  }
# Line 1163 | Line 1184 | set_io(void)                   /* set put and get functions */
1184                                  if (fin2 == NULL)
1185                                          goto namerr;
1186                                  if (fseek(fin2,
1187 <                                (long)sizeof(uby8)*picres.xr*picres.yr, 1))
1187 >                                (long)sizeof(uby8)*picres.xr*picres.yr, SEEK_CUR))
1188                                          goto seekerr;
1189                                  if (fseek(fin3,
1190 <                                (long)sizeof(uby8)*2*picres.xr*picres.yr, 1))
1190 >                                (long)sizeof(uby8)*2*picres.xr*picres.yr, SEEK_CUR))
1191                                          goto seekerr;
1192                          }
1193                  }
# Line 1185 | Line 1206 | set_io(void)                   /* set put and get functions */
1206                                  if (fin2 == NULL)
1207                                          goto namerr;
1208                                  if (fseek(fin2,
1209 <                                (long)sizeof(uint16)*picres.xr*picres.yr, 1))
1209 >                                (long)sizeof(uint16)*picres.xr*picres.yr, SEEK_CUR))
1210                                          goto seekerr;
1211                                  if (fseek(fin3,
1212 <                                (long)sizeof(uint16)*2*picres.xr*picres.yr, 1))
1212 >                                (long)sizeof(uint16)*2*picres.xr*picres.yr, SEEK_CUR))
1213                                          goto seekerr;
1214                          }
1215                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines