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.40 by greg, Tue Jun 30 22:30:29 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 172 | Line 173 | main(
173                                  }
174                                  break;
175                          case 'd':               /* data only (no indices) */
176 <                                dataonly = argv[i][0] == '-';
176 >                                dataonly = (argv[i][0] == '-');
177                                  switch (argv[i][2]) {
178                                  case '\0':
179                                  case 'a':               /* ascii */
# 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 368 | Line 375 | unkopt:
375                  }
376                  if (header) {
377                          printargs(i, argv, stdout);
378 +                        printf("NCOMP=%d\n", putprim==ALL ? 3 : 1);
379 +                        if (!resolution && dataonly && !uniq)
380 +                                printf("NCOLS=%d\nNROWS=%d\n", scanlen(&picres),
381 +                                                numscans(&picres));
382                          if (expval < .99 || expval > 1.01)
383                                  fputexpos(expval, stdout);
384 +                        if (swapbytes) {
385 +                                if (nativebigendian())
386 +                                        puts("BigEndian=0");
387 +                                else
388 +                                        puts("BigEndian=1");
389 +                        } else if ((format != 'a') & (format != 'i') &
390 +                                                (format != 'b'))
391 +                                fputendian(stdout);
392                          fputformat(fmtid, stdout);
393                          putchar('\n');
394                  }
# Line 389 | Line 408 | checkhead(                             /* deal with line from header */
408          void    *p
409   )
410   {
411 <        char    fmt[32];
411 >        FILE    *fout = (FILE *)p;
412 >        char    fmt[MAXFMTLEN];
413          double  d;
414          COLOR   ctmp;
415 +        int     rv;
416  
417          if (formatval(fmt, line)) {
418 <                if (!strcmp(fmt, CIEFMT))
418 >                if (reverse)
419 >                        wrongformat = strcmp(fmt, fmtid);
420 >                else if (!strcmp(fmt, CIEFMT))
421                          mybright = &xyz_bright;
422                  else if (!strcmp(fmt, COLRFMT))
423                          mybright = &rgb_bright;
424                  else
425                          wrongformat++;
426 <        } else if (original && isexpos(line)) {
426 >                return(1);
427 >        }
428 >        if (original && isexpos(line)) {
429                  d = 1.0/exposval(line);
430                  scalecolor(exposure, d);
431                  doexposure++;
432 <        } else if (original && iscolcor(line)) {
432 >                return(1);
433 >        }
434 >        if (original && iscolcor(line)) {
435                  colcorval(ctmp, line);
436                  setcolor(exposure, colval(exposure,RED)/colval(ctmp,RED),
437                                  colval(exposure,GRN)/colval(ctmp,GRN),
438                                  colval(exposure,BLU)/colval(ctmp,BLU));
439                  doexposure++;
440 <        } else if (header)
441 <                fputs(line, stdout);
440 >                return(1);
441 >        }
442 >        if ((rv = isbigendian(line)) >= 0) {
443 >                if (reverse)
444 >                        swapbytes = (nativebigendian() != rv);
445 >                return(1);
446 >        }
447 >        if (fout != NULL)
448 >                fputs(line, fout);
449          return(0);
450   }
451  
# Line 419 | Line 453 | checkhead(                             /* deal with line from header */
453   static void
454   pixtoval(void)                          /* convert picture to values */
455   {
456 <        register COLOR  *scanln;
456 >        COLOR   *scanln;
457          int  dogamma;
458          COLOR  lastc;
459          RREAL  hv[2];
460          int  startprim, endprim;
461          long  startpos;
462 <        int  y;
429 <        register int  x;
462 >        int  x, y;
463  
464          scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
465          if (scanln == NULL) {
# Line 434 | Line 467 | pixtoval(void)                         /* convert picture to values */
467                  quit(1);
468          }
469          dogamma = gamcor < .95 || gamcor > 1.05;
470 <        if (putprim == ALL && !interleave) {
470 >        if ((putprim == ALL) & !interleave) {
471                  startprim = RED; endprim = BLU;
472                  startpos = ftell(fin);
473          } else {
474                  startprim = putprim; endprim = putprim;
475          }
476          for (putprim = startprim; putprim <= endprim; putprim++) {
477 <                if (putprim != startprim && fseek(fin, startpos, 0)) {
477 >                if (putprim != startprim && fseek(fin, startpos, SEEK_SET)) {
478                          fprintf(stderr, "%s: seek error on input file\n",
479                                          progname);
480                          quit(1);
# Line 493 | Line 526 | pixtoval(void)                         /* convert picture to values */
526   static void
527   valtopix(void)                  /* convert values to a pixel file */
528   {
529 <        int  dogamma;
530 <        register COLOR  *scanln;
531 <        int  y;
532 <        register int  x;
529 >        int     dogamma;
530 >        COLOR   *scanln;
531 >        COLR    rgbe;
532 >        int     x, y;
533  
534          scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
535          if (scanln == NULL) {
# Line 525 | Line 558 | valtopix(void)                 /* convert values to a pixel file */
558                                          pow(colval(scanln[x],BLU), gamcor));
559                          if (doexposure)
560                                  multcolor(scanln[x], exposure);
561 +                        if (uniq) {             /* uncompressed? */
562 +                                setcolr(rgbe,   scanln[x][RED],
563 +                                                scanln[x][GRN],
564 +                                                scanln[x][BLU]);
565 +                                if (putbinary(rgbe, sizeof(COLR), 1, stdout) != 1)
566 +                                        goto writerr;
567 +                        }
568                  }
569 <                if (fwritescan(scanln, scanlen(&picres), stdout) < 0) {
570 <                        fprintf(stderr, "%s: write error\n", progname);
571 <                        quit(1);
532 <                }
569 >                                                /* write scan if compressed */
570 >                if (!uniq && fwritescan(scanln, scanlen(&picres), stdout) < 0)
571 >                        goto writerr;
572          }
573          free((void *)scanln);
574 +        return;
575 + writerr:
576 +        fprintf(stderr, "%s: write error\n", progname);
577 +        quit(1);
578   }
579  
580  
# Line 939 | Line 982 | putbbyte(                      /* put a byte brightness to stdout */
982          COLOR  col
983   )
984   {
985 <        register int  i;
985 >        int  i;
986          uby8  vb;
987  
988          i = (*mybright)(col)*256.;
# Line 1092 | Line 1135 | set_io(void)                   /* set put and get functions */
1135                                  if (fin2 == NULL)
1136                                          goto namerr;
1137                                  if (fseek(fin2,
1138 <                                (long)sizeof(float)*picres.xr*picres.yr, 1))
1138 >                                (long)sizeof(float)*picres.xr*picres.yr, SEEK_CUR))
1139                                          goto seekerr;
1140                                  if (fseek(fin3,
1141 <                                (long)sizeof(float)*2*picres.xr*picres.yr, 1))
1141 >                                (long)sizeof(float)*2*picres.xr*picres.yr, SEEK_CUR))
1142                                          goto seekerr;
1143                          }
1144                  }
# Line 1114 | Line 1157 | set_io(void)                   /* set put and get functions */
1157                                  if (fin2 == NULL)
1158                                          goto namerr;
1159                                  if (fseek(fin2,
1160 <                                (long)sizeof(double)*picres.xr*picres.yr, 1))
1160 >                                (long)sizeof(double)*picres.xr*picres.yr, SEEK_CUR))
1161                                          goto seekerr;
1162                                  if (fseek(fin3,
1163 <                                (long)sizeof(double)*2*picres.xr*picres.yr, 1))
1163 >                                (long)sizeof(double)*2*picres.xr*picres.yr, SEEK_CUR))
1164                                          goto seekerr;
1165                          }
1166                  }
# Line 1154 | Line 1197 | set_io(void)                   /* set put and get functions */
1197                                  if (fin2 == NULL)
1198                                          goto namerr;
1199                                  if (fseek(fin2,
1200 <                                (long)sizeof(uby8)*picres.xr*picres.yr, 1))
1200 >                                (long)sizeof(uby8)*picres.xr*picres.yr, SEEK_CUR))
1201                                          goto seekerr;
1202                                  if (fseek(fin3,
1203 <                                (long)sizeof(uby8)*2*picres.xr*picres.yr, 1))
1203 >                                (long)sizeof(uby8)*2*picres.xr*picres.yr, SEEK_CUR))
1204                                          goto seekerr;
1205                          }
1206                  }
# Line 1176 | Line 1219 | set_io(void)                   /* set put and get functions */
1219                                  if (fin2 == NULL)
1220                                          goto namerr;
1221                                  if (fseek(fin2,
1222 <                                (long)sizeof(uint16)*picres.xr*picres.yr, 1))
1222 >                                (long)sizeof(uint16)*picres.xr*picres.yr, SEEK_CUR))
1223                                          goto seekerr;
1224                                  if (fseek(fin3,
1225 <                                (long)sizeof(uint16)*2*picres.xr*picres.yr, 1))
1225 >                                (long)sizeof(uint16)*2*picres.xr*picres.yr, SEEK_CUR))
1226                                          goto seekerr;
1227                          }
1228                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines