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.42 by greg, Thu Mar 10 03:25:54 2022 UTC vs.
Revision 2.45 by greg, Mon Sep 16 23:02:53 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 218 | 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 243 | 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 280 | 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 294 | 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 310 | Line 318 | unkopt:
318                  fprintf(stderr, "%s: bad # file arguments\n", progname);
319                  quit(1);
320          }
313
321          if (reverse) {
322                  SET_FILE_BINARY(stdout);
323                                          /* get header */
# Line 325 | 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 350 | 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 (!header & (putprim != ALL)) {
365 +                        NCSAMP = 1;             /* no header, so trust user */
366 +                } else if (NCSAMP == 1) {
367 +                        if (putprim == ALL)
368 +                                putprim = BRIGHT;
369 +                } else {
370 +                        if (NCSAMP != 3) {
371 +                                fprintf(stderr, "%s: input NCOMP must be 1 or 3\n",
372 +                                                progname);
373 +                                quit(1);
374 +                        }
375 +                        if (putprim != ALL) {
376 +                                fprintf(stderr, "%s: NCOMP mismatch\n", progname);
377 +                                quit(1);
378 +                        }
379 +                }
380                  if (outprims != NULL) {
381                          if (outprims != stdprims)
382                                  fputprims(outprims, stdout);
# Line 370 | Line 395 | unkopt:
395                  if ((format != 'a') & (format != 'i'))
396                          SET_FILE_BINARY(stdout);
397                                                  /* get header */
398 +                picres.rt = PIXSTANDARD;
399 +                picres.xr = picres.yr = 0;
400                  getheader(fin, checkhead, header ? stdout : (FILE *)NULL);
401                  if (wrongformat) {
402                          fprintf(stderr,
# Line 377 | Line 404 | unkopt:
404                                          progname);
405                          quit(1);
406                  }
407 <                if (!fgetsresolu(&picres, fin)) {
407 >                if ((picres.xr <= 0) | (picres.yr <= 0) &&
408 >                                !fgetsresolu(&picres, fin)) {
409                          fprintf(stderr, "%s: missing resolution\n", progname);
410                          quit(1);
411                  }
412 <                if (original < 0 && mybright == &xyz_bright) {
412 >                if ((original < 0) & (mybright == &xyz_bright)) {
413                          scalecolor(exposure, 1./WHTEFFICACY);
414                          doexposure++;
415                  }
416                  if (header) {
417                          printargs(i, argv, stdout);
418 <                        printf("NCOMP=%d\n", putprim==ALL ? 3 : 1);
419 <                        if (!resolution && dataonly && !uniq)
418 >                        if (dataonly)
419 >                                printf("%s%c\n", NCOMPSTR, "13"[putprim==ALL]);
420 >                        if (dataonly && !resolution & !uniq)
421                                  printf("NCOLS=%d\nNROWS=%d\n", scanlen(&picres),
422                                                  numscans(&picres));
423 <                        if (expval < .99 || expval > 1.01)
423 >                        if ((expval < .99) | (expval > 1.01))
424                                  fputexpos(expval, stdout);
425                          if (swapbytes) {
426                                  if (nativebigendian())
# Line 415 | Line 444 | unkopt:
444  
445  
446   static int
447 + IDformat(const char *s)
448 + {
449 +        if (!s || !*s) return(0);
450 +        if (!strcmp(s, "ascii")) return('a');
451 +        if (!strcmp(s, "float")) return('f');
452 +        if (!strcmp(s, "double")) return('d');
453 +        if (!strcmp(s, "byte")) return('b');
454 +        if (!strcmp(s, "16-bit")) return('w');
455 +        return(0);
456 + }
457 +
458 +
459 + static int
460   checkhead(                              /* deal with line from header */
461          char    *line,
462          void    *p
463   )
464   {
465 +        static char     fmt[MAXFMTLEN];
466          FILE    *fout = (FILE *)p;
424        char    fmt[MAXFMTLEN];
467          double  d;
468          COLOR   ctmp;
469          int     rv;
470  
471          if (formatval(fmt, line)) {
472 <                if (reverse)
473 <                        wrongformat = strcmp(fmt, fmtid);
474 <                else if (!strcmp(fmt, CIEFMT))
472 >                if (reverse) {
473 >                        if (format == 'a') {
474 >                                format = IDformat(fmt);
475 >                                if (format)
476 >                                        fmtid = fmt;
477 >                                else
478 >                                        wrongformat = 1;
479 >                        } else
480 >                                wrongformat = strcmp(fmt, fmtid);
481 >                } else if (!strcmp(fmt, CIEFMT))
482                          mybright = &xyz_bright;
483 <                else if (!strcmp(fmt, COLRFMT))
483 >                else if (!strcmp(fmt, COLRFMT) || !strcmp(fmt, SPECFMT))
484                          mybright = &rgb_bright;
485                  else
486 <                        wrongformat++;
486 >                        wrongformat = 1;
487                  return(1);
488          }
489 <        if (!strncmp(line,"NROWS=",6) ||
490 <                        !strncmp(line,"NCOLS=",6) ||
442 <                        !strncmp(line,"NCOMP=",6))
489 >        if (!strncmp(line,"NROWS=",6)) {
490 >                picres.yr = atoi(line+6);
491                  return(1);
492 <
492 >        }
493 >        if (!strncmp(line,"NCOLS=",6)) {
494 >                picres.xr = atoi(line+6);
495 >                return(1);
496 >        }
497 >        if (isncomp(line)) {
498 >                NCSAMP = ncompval(line);
499 >                dataonly |= reverse;    /* pretty safe assumption */
500 >                return(1);
501 >        }
502 >        if (iswlsplit(line)) {
503 >                wlsplitval(WLPART, line);
504 >                return(1);
505 >        }
506          if (original && isexpos(line)) {
507                  d = 1.0/exposval(line);
508                  scalecolor(exposure, d);
# Line 499 | Line 560 | pixtoval(void)                         /* convert picture to values */
560                  set_io();
561                  setcolor(lastc, 0.0, 0.0, 0.0);
562                  for (y = 0; y < numscans(&picres); y++) {
563 <                        if (freadscan(scanln, scanlen(&picres), fin) < 0) {
563 >                        if (fread2scan(scanln, scanlen(&picres), fin,
564 >                                                NCSAMP, WLPART) < 0) {
565                                  fprintf(stderr, "%s: read error\n", progname);
566                                  quit(1);
567                          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines