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.43 by greg, Wed Sep 11 18:56:12 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 (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);
# Line 370 | 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 377 | 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) {
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 >                        printf("%s%c\n", NCOMPSTR, "13"[putprim==ALL]);
417 >                        if (dataonly && !resolution & !uniq)
418                                  printf("NCOLS=%d\nNROWS=%d\n", scanlen(&picres),
419                                                  numscans(&picres));
420 <                        if (expval < .99 || expval > 1.01)
420 >                        if ((expval < .99) | (expval > 1.01))
421                                  fputexpos(expval, stdout);
422                          if (swapbytes) {
423                                  if (nativebigendian())
# Line 415 | Line 441 | unkopt:
441  
442  
443   static int
444 + IDformat(const char *s)
445 + {
446 +        if (!s || !*s) return(0);
447 +        if (!strcmp(s, "ascii")) return('a');
448 +        if (!strcmp(s, "float")) return('f');
449 +        if (!strcmp(s, "double")) return('d');
450 +        if (!strcmp(s, "byte")) return('b');
451 +        if (!strcmp(s, "16-bit")) return('w');
452 +        return(0);
453 + }
454 +
455 +
456 + static int
457   checkhead(                              /* deal with line from header */
458          char    *line,
459          void    *p
460   )
461   {
462 +        static char     fmt[MAXFMTLEN];
463          FILE    *fout = (FILE *)p;
424        char    fmt[MAXFMTLEN];
464          double  d;
465          COLOR   ctmp;
466          int     rv;
467  
468          if (formatval(fmt, line)) {
469 <                if (reverse)
470 <                        wrongformat = strcmp(fmt, fmtid);
471 <                else if (!strcmp(fmt, CIEFMT))
469 >                if (reverse) {
470 >                        if (format == 'a') {
471 >                                format = IDformat(fmt);
472 >                                if (format)
473 >                                        fmtid = fmt;
474 >                                else
475 >                                        wrongformat = 1;
476 >                        } else
477 >                                wrongformat = strcmp(fmt, fmtid);
478 >                } else if (!strcmp(fmt, CIEFMT))
479                          mybright = &xyz_bright;
480 <                else if (!strcmp(fmt, COLRFMT))
480 >                else if (!strcmp(fmt, COLRFMT) || !strcmp(fmt, SPECFMT))
481                          mybright = &rgb_bright;
482                  else
483 <                        wrongformat++;
483 >                        wrongformat = 1;
484                  return(1);
485          }
486 <        if (!strncmp(line,"NROWS=",6) ||
487 <                        !strncmp(line,"NCOLS=",6) ||
442 <                        !strncmp(line,"NCOMP=",6))
486 >        if (!strncmp(line,"NROWS=",6)) {
487 >                picres.yr = atoi(line+6);
488                  return(1);
489 <
489 >        }
490 >        if (!strncmp(line,"NCOLS=",6)) {
491 >                picres.xr = atoi(line+6);
492 >                return(1);
493 >        }
494 >        if (isncomp(line)) {
495 >                NCSAMP = ncompval(line);
496 >                dataonly |= reverse;    /* pretty safe assumption */
497 >                return(1);
498 >        }
499 >        if (iswlsplit(line)) {
500 >                wlsplitval(WLPART, line);
501 >                return(1);
502 >        }
503          if (original && isexpos(line)) {
504                  d = 1.0/exposval(line);
505                  scalecolor(exposure, d);
# Line 499 | Line 557 | pixtoval(void)                         /* convert picture to values */
557                  set_io();
558                  setcolor(lastc, 0.0, 0.0, 0.0);
559                  for (y = 0; y < numscans(&picres); y++) {
560 <                        if (freadscan(scanln, scanlen(&picres), fin) < 0) {
560 >                        if (fread2scan(scanln, scanlen(&picres), fin,
561 >                                                NCSAMP, WLPART) < 0) {
562                                  fprintf(stderr, "%s: read error\n", progname);
563                                  quit(1);
564                          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines