ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ra_tiff.c
(Generate patch)

Comparing ray/src/px/ra_tiff.c (file contents):
Revision 2.28 by schorsch, Sun Mar 28 20:33:14 2004 UTC vs.
Revision 2.36 by greg, Fri Jul 19 17:37:56 2019 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7   *  Added white-balance adjustment 10/01 (GW).
8   */
9  
10 #include  <stdio.h>
10   #include  <math.h>
11   #include  <ctype.h>
13 #include  <time.h>
14 #include  <string.h>
12  
13 + #include  "rtio.h"
14 + #include  "platform.h"
15   #include  "tiffio.h"
16   #include  "color.h"
17   #include  "resolu.h"
# Line 191 | Line 190 | doneopts:
190          exit(0);
191   userr:
192          fprintf(stderr,
193 <        "Usage: %s [-z|-L|-l|-f|-w][-b][-e +/-stops][-g gamma] {in.pic|-} out.tif\n",
193 >        "Usage: %s [-z|-L|-l|-f|-w][-b][-e +/-stops][-g gamma] {in.hdr|-} out.tif\n",
194                          progname);
195          fprintf(stderr,
196 <        "   Or: %s -r [-x][-e +/-stops][-g gamma] in.tif [out.pic|-]\n",
196 >        "   Or: %s -r [-x][-e +/-stops][-g gamma] in.tif [out.hdr|-]\n",
197                          progname);
198          exit(1);
199   }
# Line 275 | Line 274 | initfromtif(void)              /* initialize conversion from TIFF
274                          cpcolormat(cvts.cmat, xyz2rgbmat);
275                          SET(C_CXFM|C_GAMUT);
276                  } else if (cvts.comp == COMPRESSION_SGILOG)
277 <                        SET(C_GAMUT);
277 >                        SET(C_GAMUT);           /* may be outside XYZ gamut */
278                  if (cvts.pconf != PLANARCONFIG_CONTIG)
279                          quiterr("cannot handle separate Luv planes");
280                  TIFFSetField(cvts.tif, TIFFTAG_SGILOGDATAFMT,
# Line 362 | Line 361 | initfromtif(void)              /* initialize conversion from TIFF
361                  quiterr("unknown input image resolution");
362  
363          if (!TIFFGetField(cvts.tif, TIFFTAG_STONITS, &cvts.stonits))
364 <                cvts.stonits = 1.;
364 >                cvts.stonits = -1.;
365  
366          if (!TIFFGetField(cvts.tif, TIFFTAG_DATETIME, &cp))
367                  cvts.capdate[0] = '\0';
# Line 380 | Line 379 | initfromtif(void)              /* initialize conversion from TIFF
379          if (cvts.pixrat < .99 || cvts.pixrat > 1.01)
380                  fputaspect(cvts.pixrat, cvts.rfp);
381          if (CHK(C_XYZE)) {
382 <                fputexpos(pow(2.,(double)cvts.bradj)/cvts.stonits, cvts.rfp);
382 >                if (cvts.stonits > .0)
383 >                        fputexpos(pow(2.,(double)cvts.bradj)/cvts.stonits, cvts.rfp);
384                  fputformat(CIEFMT, cvts.rfp);
385          } else {
386                  if (CHK(C_PRIM))
387                          fputprims(cvts.prims, cvts.rfp);
388 <                fputexpos(WHTEFFICACY*pow(2.,(double)cvts.bradj)/cvts.stonits,
389 <                                cvts.rfp);
388 >                if (cvts.stonits > .0)
389 >                        fputexpos(WHTEFFICACY*pow(2.,(double)cvts.bradj)/cvts.stonits,
390 >                                        cvts.rfp);
391                  fputformat(COLRFMT, cvts.rfp);
392          }
393          if (cvts.capdate[0])
# Line 413 | Line 414 | tiff2ra(               /* convert TIFF image to Radiance picture */
414                  cvts.rfp = stdout;
415          else if ((cvts.rfp = fopen(av[ac+1], "w")) == NULL)
416                  quiterr("cannot open Radiance output picture");
417 +        SET_FILE_BINARY(cvts.rfp);
418                                          /* start output header */
419          newheader("RADIANCE", cvts.rfp);
420          printargs(ac, av, cvts.rfp);
# Line 438 | Line 440 | headline(                      /* process Radiance input header line */
440   {
441          static int      tmstrlen = 0;
442          static int      ownstrlen = 0;
443 <        char    fmt[32];
443 >        char    fmt[MAXFMTLEN];
444  
445          if (!tmstrlen)
446                  tmstrlen = strlen(TMSTR);
# Line 569 | Line 571 | initfromrad(void)                      /* initialize input from a Radianc
571                                          SAMPLEFORMAT_IEEEFP);
572                          cvts.tf = Color2RfGfBf;
573                          SET(C_RFLT);
574 +                        CLR(C_GAMUT);
575                  } else
576                          cvts.tf = Colr2RGB;
577                  break;
# Line 631 | Line 634 | ra2tiff(               /* convert Radiance picture to TIFF image */
634                  cvts.rfp = stdin;
635          else if ((cvts.rfp = fopen(av[ac], "r")) == NULL)
636                  quiterr("cannot open Radiance input picture");
637 +        SET_FILE_BINARY(cvts.rfp);
638                                                  /* open TIFF file */
639          if ((cvts.tif = TIFFOpen(av[ac+1], "w")) == NULL)
640                  quiterr("cannot open TIFF output");
# Line 655 | Line 659 | Luv2Color(                     /* read/convert/write Luv->COLOR scanline
659          if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT))
660                  quiterr("internal error 1 in Luv2Color");
661  
662 +        if (cvts.pconf != PLANARCONFIG_CONTIG)
663 +                quiterr("cannot handle separate 32-bit color planes");
664 +
665          if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0)
666                  quiterr("error reading TIFF input");
667                                          /* also works for float RGB */
# Line 693 | Line 700 | RRGGBB2Color(                  /* read/convert/write RGB16->COLOR sca
700          if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_TWRD|C_RFLT))
701                  quiterr("internal error 1 in RRGGBB2Color");
702  
703 +        if (cvts.pconf != PLANARCONFIG_CONTIG)
704 +                quiterr("cannot handle separate 16-bit color planes");
705 +
706          if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0)
707                  quiterr("error reading TIFF input");
708          
# Line 709 | Line 719 | RRGGBB2Color(                  /* read/convert/write RGB16->COLOR sca
719                  if (CHK(C_CXFM))
720                          colortrans(cvts.r.colors[x], cvts.cmat,
721                                          cvts.r.colors[x]);
712                if (CHK(C_GAMUT))
713                        clipgamut(cvts.r.colors[x], cvts.t.fp[3*x + 1],
714                                        CGAMUT_LOWER, cblack, cwhite);
722          }
723          if (cvts.bradj) {
724                  d = pow(2.,(double)cvts.bradj);
# Line 970 | Line 977 | Color2RRGGBB(                  /* read/convert/write COLOR->RGB16 sca
977          if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0)
978                  quiterr("error reading Radiance picture");
979  
980 <        for (x = cvts.xmax; x--; )
980 >        for (x = cvts.xmax; x--; ) {
981 >            if (CHK(C_CXFM)) {
982 >                        colortrans(cvts.r.colors[x], cvts.cmat,
983 >                                        cvts.r.colors[x]);
984 >                if (CHK(C_GAMUT))
985 >                        clipgamut(cvts.r.colors[x], bright(cvts.r.colors[x]),
986 >                                        CGAMUT_LOWER, cblack, cwhite);
987 >            }
988              for (i = 3; i--; ) {
989                  register float  f = m*colval(cvts.r.colors[x],i);
990                  if (f <= 0)
# Line 983 | Line 997 | Color2RRGGBB(                  /* read/convert/write COLOR->RGB16 sca
997                  else
998                          cvts.t.wp[3*x + i] = (int)((float)(1L<<16)*f);
999              }
1000 +        }
1001  
1002          if (TIFFWriteScanline(cvts.tif, cvts.t.p, y, 0) < 0)
1003                  quiterr("error writing TIFF output");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines