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.40 by greg, Tue Jun 30 22:30:29 2020 UTC vs.
Revision 2.44 by greg, Wed Sep 11 23:21:01 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 99 | Line 100 | main(
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 118 | 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 215 | 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 240 | 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'))
266 >        if (!reverse | ((format != 'a') & (format != 'i')))
267                  inpmode = "rb";
268                                          /* assign reverse ordering */
269          rord[ord[0]] = 0;
# Line 277 | Line 288 | unkopt:
288                                                  progname, argv[i]);
289                          quit(1);
290                  }
291 <                if (reverse && putprim != BRIGHT && i == argc-3) {
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]);
# Line 291 | Line 302 | unkopt:
302                          interleave = -1;
303                  } else if (i != argc-1)
304                          fin = NULL;
305 <                if (reverse && putprim != BRIGHT && !interleave) {
305 >                if (reverse & (putprim != BRIGHT) & !interleave) {
306                          fin2 = fopen(argv[i], inpmode);
307                          fin3 = fopen(argv[i], inpmode);
308                  }
# Line 307 | Line 318 | unkopt:
318                  fprintf(stderr, "%s: bad # file arguments\n", progname);
319                  quit(1);
320          }
310
321          if (reverse) {
322                  SET_FILE_BINARY(stdout);
323                                          /* get header */
# Line 322 | Line 332 | unkopt:
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 347 | 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();
# Line 362 | Line 393 | unkopt:
393                  if ((format != 'a') & (format != 'i'))
394                          SET_FILE_BINARY(stdout);
395                                                  /* get header */
396 +                picres.rt = PIXSTANDARD;
397 +                picres.xr = picres.yr = 0;
398                  getheader(fin, checkhead, header ? stdout : (FILE *)NULL);
399                  if (wrongformat) {
400                          fprintf(stderr,
# Line 369 | Line 402 | unkopt:
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 <                        printf("NCOMP=%d\n", putprim==ALL ? 3 : 1);
417 <                        if (!resolution && dataonly && !uniq)
416 >                        if (dataonly)
417 >                                printf("%s%c\n", NCOMPSTR, "13"[putprim==ALL]);
418 >                        if (dataonly && !resolution & !uniq)
419                                  printf("NCOLS=%d\nNROWS=%d\n", scanlen(&picres),
420                                                  numscans(&picres));
421 <                        if (expval < .99 || expval > 1.01)
421 >                        if ((expval < .99) | (expval > 1.01))
422                                  fputexpos(expval, stdout);
423                          if (swapbytes) {
424                                  if (nativebigendian())
# Line 403 | Line 442 | unkopt:
442  
443  
444   static int
445 + IDformat(const char *s)
446 + {
447 +        if (!s || !*s) return(0);
448 +        if (!strcmp(s, "ascii")) return('a');
449 +        if (!strcmp(s, "float")) return('f');
450 +        if (!strcmp(s, "double")) return('d');
451 +        if (!strcmp(s, "byte")) return('b');
452 +        if (!strcmp(s, "16-bit")) return('w');
453 +        return(0);
454 + }
455 +
456 +
457 + static int
458   checkhead(                              /* deal with line from header */
459          char    *line,
460          void    *p
461   )
462   {
463 +        static char     fmt[MAXFMTLEN];
464          FILE    *fout = (FILE *)p;
412        char    fmt[MAXFMTLEN];
465          double  d;
466          COLOR   ctmp;
467          int     rv;
468  
469          if (formatval(fmt, line)) {
470 <                if (reverse)
471 <                        wrongformat = strcmp(fmt, fmtid);
472 <                else if (!strcmp(fmt, CIEFMT))
470 >                if (reverse) {
471 >                        if (format == 'a') {
472 >                                format = IDformat(fmt);
473 >                                if (format)
474 >                                        fmtid = fmt;
475 >                                else
476 >                                        wrongformat = 1;
477 >                        } else
478 >                                wrongformat = strcmp(fmt, fmtid);
479 >                } else if (!strcmp(fmt, CIEFMT))
480                          mybright = &xyz_bright;
481 <                else if (!strcmp(fmt, COLRFMT))
481 >                else if (!strcmp(fmt, COLRFMT) || !strcmp(fmt, SPECFMT))
482                          mybright = &rgb_bright;
483                  else
484 <                        wrongformat++;
484 >                        wrongformat = 1;
485                  return(1);
486          }
487 +        if (!strncmp(line,"NROWS=",6)) {
488 +                picres.yr = atoi(line+6);
489 +                return(1);
490 +        }
491 +        if (!strncmp(line,"NCOLS=",6)) {
492 +                picres.xr = atoi(line+6);
493 +                return(1);
494 +        }
495 +        if (isncomp(line)) {
496 +                NCSAMP = ncompval(line);
497 +                dataonly |= reverse;    /* pretty safe assumption */
498 +                return(1);
499 +        }
500 +        if (iswlsplit(line)) {
501 +                wlsplitval(WLPART, line);
502 +                return(1);
503 +        }
504          if (original && isexpos(line)) {
505                  d = 1.0/exposval(line);
506                  scalecolor(exposure, d);
# Line 482 | Line 558 | pixtoval(void)                         /* convert picture to values */
558                  set_io();
559                  setcolor(lastc, 0.0, 0.0, 0.0);
560                  for (y = 0; y < numscans(&picres); y++) {
561 <                        if (freadscan(scanln, scanlen(&picres), fin) < 0) {
561 >                        if (fread2scan(scanln, scanlen(&picres), fin,
562 >                                                NCSAMP, WLPART) < 0) {
563                                  fprintf(stderr, "%s: read error\n", progname);
564                                  quit(1);
565                          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines