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.20 by greg, Sat Feb 22 02:07:28 2003 UTC vs.
Revision 2.21 by greg, Tue Jul 1 19:04:08 2003 UTC

# Line 53 | Line 53 | struct {
53                  float   *fp;            /* float pointer */
54                  char    *p;             /* generic pointer */
55          } t;                    /* TIFF scanline */
56 <        int     (*tf)();        /* translation procedure */
56 >        void    (*tf)();        /* translation procedure */
57   }       cvts = {        /* conversion structure */
58          0, COMPRESSION_NONE, PHOTOMETRIC_RGB,
59          PLANARCONFIG_CONTIG, GAMCOR, 0, 1, 1., 1.,
# Line 64 | Line 64 | struct {
64   #define CLR(f)          (cvts.flags &= ~(f))
65   #define TGL(f)          (cvts.flags ^= (f))
66  
67 < int     Luv2Color(), L2Color(), RGB2Colr(), Gry2Colr();
68 < int     Color2Luv(), Color2L(), Colr2RGB(), Colr2Gry();
69 < int     RRGGBB2Color(), GGry2Color();
67 > void    Luv2Color(), L2Color(), RGB2Colr(), Gry2Colr();
68 > void    Color2Luv(), Color2L(), Colr2RGB(), Colr2Gry();
69 > void    RRGGBB2Color(), GGry2Color(), Color2RRGGBB(), Color2GGry();
70  
71 + #define RfGfBf2Color    Luv2Color
72 + #define Gryf2Color      L2Color
73 + #define Color2Gryf      Color2L
74 + #define Color2RfGfBf    Color2Luv
75 +
76   short   ortab[8] = {            /* orientation conversion table */
77          YMAJOR|YDECR,
78          YMAJOR|YDECR|XDECR,
# Line 113 | Line 118 | char  *argv[];
118                                  cvts.comp = COMPRESSION_SGILOG24;
119                                  cvts.phot = PHOTOMETRIC_LOGLUV;
120                                  break;
121 +                        case 'w':               /* 16-bit/primary output? */
122 +                                TGL(C_TWRD);
123 +                                break;
124 +                        case 'f':               /* IEEE float output? */
125 +                                TGL(C_TFLT);
126 +                                break;
127                          case 'b':               /* greyscale output? */
128                                  TGL(C_GRY);
129                                  break;
# Line 143 | Line 154 | doneopts:
154  
155                  if (i != argc-2)
156                          goto userr;
157 <
158 <                if (CHK(C_GRY))         /* consistency corrections */
157 >                                                /* consistency checks */
158 >                if (CHK(C_GRY))
159                          if (cvts.phot == PHOTOMETRIC_RGB)
160                                  cvts.phot = PHOTOMETRIC_MINISBLACK;
161                          else {
162                                  cvts.phot = PHOTOMETRIC_LOGL;
163                                  cvts.comp = COMPRESSION_SGILOG;
164                          }
165 +                if (CHK(C_TWRD|C_TFLT) == (C_TWRD|C_TFLT))
166 +                        goto userr;
167  
168                  ra2tiff(i, argv);
169          }
# Line 158 | Line 171 | doneopts:
171          exit(0);
172   userr:
173          fprintf(stderr,
174 <        "Usage: %s [-z|-L|-l][-b][-e +/-stops][-g gamma] {in.pic|-} out.tif\n",
174 >        "Usage: %s [-z|-L|-l|-f|-w][-b][-e +/-stops][-g gamma] {in.pic|-} out.tif\n",
175                          progname);
176          fprintf(stderr,
177          "   Or: %s -r [-x][-e +/-stops][-g gamma] in.tif [out.pic|-]\n",
# Line 198 | Line 211 | initfromtif()          /* initialize conversion from TIFF inpu
211          uint16  hi;
212          float   *fa, f1, f2;
213  
214 <        CLR(C_GRY|C_GAMMA|C_PRIM|C_RFLT|C_TFLT|C_CXFM);
214 >        CLR(C_GRY|C_GAMMA|C_PRIM|C_RFLT|C_TFLT|C_TWRD|C_CXFM);
215  
216          TIFFGetFieldDefaulted(cvts.tif, TIFFTAG_PLANARCONFIG, &cvts.pconf);
217  
# Line 271 | Line 284 | initfromtif()          /* initialize conversion from TIFF inpu
284                  if (!TIFFGetField(cvts.tif, TIFFTAG_SAMPLESPERPIXEL, &hi) ||
285                                  hi != 3)
286                          quiterr("unsupported samples per pixel for RGB");
287 <                if (!TIFFGetField(cvts.tif, TIFFTAG_BITSPERSAMPLE, &hi) ||
288 <                                hi != 8 & hi != 16)
289 <                        quiterr("unsupported bits per sample for RGB");
290 <                if (hi == 8)
287 >                if (!TIFFGetField(cvts.tif, TIFFTAG_BITSPERSAMPLE, &hi))
288 >                        hi = -1;
289 >                switch (hi) {
290 >                case 8:
291                          cvts.tf = RGB2Colr;
292 <                else {
292 >                        break;
293 >                case 16:
294                          cvts.tf = RRGGBB2Color;
295                          SET(C_RFLT|C_TWRD);
296 +                        break;
297 +                case 32:
298 +                        cvts.tf = RfGfBf2Color;
299 +                        SET(C_RFLT|C_TFLT);
300 +                        break;
301 +                default:
302 +                        quiterr("unsupported bits per sample for RGB");
303                  }
304                  break;
305          case PHOTOMETRIC_MINISBLACK:
# Line 288 | Line 309 | initfromtif()          /* initialize conversion from TIFF inpu
309                  if (!TIFFGetField(cvts.tif, TIFFTAG_SAMPLESPERPIXEL, &hi) ||
310                                  hi != 1)
311                          quiterr("unsupported samples per pixel for greyscale");
312 <                if (!TIFFGetField(cvts.tif, TIFFTAG_BITSPERSAMPLE, &hi) ||
313 <                                hi != 8 & hi != 16)
314 <                        quiterr("unsupported bits per sample for greyscale");
315 <                if (hi == 8)
312 >                if (!TIFFGetField(cvts.tif, TIFFTAG_BITSPERSAMPLE, &hi))
313 >                        hi = -1;
314 >                switch (hi) {
315 >                case 8:
316                          cvts.tf = Gry2Colr;
317 <                else {
317 >                        break;
318 >                case 16:
319                          cvts.tf = GGry2Color;
320                          SET(C_RFLT|C_TWRD);
321 +                        break;
322 +                case 32:
323 +                        cvts.tf = Gryf2Color;
324 +                        SET(C_RFLT|C_TFLT);
325 +                        break;
326 +                default:
327 +                        quiterr("unsupported bits per sample for Gray");
328                  }
329                  break;
330          default:
# Line 393 | Line 422 | initfromrad()                  /* initialize input from a Radiance pi
422   {
423          int     i1, i2, po;
424                                                  /* read Radiance header */
425 <        CLR(C_RFLT|C_TFLT|C_XYZE|C_PRIM|C_GAMMA|C_CXFM);
425 >        CLR(C_RFLT|C_XYZE|C_PRIM|C_GAMMA|C_CXFM);
426          cvts.stonits = 1.;
427          cvts.pixrat = 1.;
428          cvts.pconf = PLANARCONFIG_CONTIG;
# Line 419 | Line 448 | initfromrad()                  /* initialize input from a Radiance pi
448          switch (cvts.phot) {
449          case PHOTOMETRIC_LOGLUV:
450                  SET(C_RFLT|C_TFLT);
451 <                CLR(C_GRY);
451 >                CLR(C_GRY|C_TWRD);
452                  if (!CHK(C_XYZE)) {
453                          comprgb2xyzWBmat(cvts.cmat,
454                                          CHK(C_PRIM) ? cvts.prims : stdprims);
# Line 434 | Line 463 | initfromrad()                  /* initialize input from a Radiance pi
463                  break;
464          case PHOTOMETRIC_LOGL:
465                  SET(C_GRY|C_RFLT|C_TFLT);
466 +                CLR(C_TWRD);
467                  if (cvts.comp != COMPRESSION_SGILOG)    
468                          quiterr("internal error 3 in initfromrad");
469                  TIFFSetField(cvts.tif, TIFFTAG_SGILOGDATAFMT,
# Line 455 | Line 485 | initfromrad()                  /* initialize input from a Radiance pi
485                          TIFFSetField(cvts.tif, TIFFTAG_WHITEPOINT,
486                                          (float *)cvts.prims[WHT]);
487                  }
488 <                cvts.tf = Colr2RGB;
488 >                if (CHK(C_TWRD)) {
489 >                        cvts.tf = Color2RRGGBB;
490 >                        SET(C_RFLT);
491 >                } else if (CHK(C_TFLT)) {
492 >                        cvts.tf = Color2RfGfBf;
493 >                        SET(C_RFLT);
494 >                } else
495 >                        cvts.tf = Colr2RGB;
496                  break;
497          case PHOTOMETRIC_MINISBLACK:
498                  SET(C_GRY|C_GAMMA|C_GAMUT);
499                  setcolrgam(cvts.gamcor);
500 <                cvts.tf = Colr2Gry;
500 >                if (CHK(C_TWRD)) {
501 >                        cvts.tf = Color2GGry;
502 >                        SET(C_RFLT);
503 >                } else if (CHK(C_TFLT)) {
504 >                        cvts.tf = Color2Gryf;
505 >                        SET(C_RFLT);
506 >                } else
507 >                        cvts.tf = Colr2Gry;
508                  break;
509          default:
510                  quiterr("internal error 4 in initfromrad");
# Line 470 | Line 514 | initfromrad()                  /* initialize input from a Radiance pi
514          TIFFSetField(cvts.tif, TIFFTAG_IMAGEWIDTH, cvts.xmax);
515          TIFFSetField(cvts.tif, TIFFTAG_IMAGELENGTH, cvts.ymax);
516          TIFFSetField(cvts.tif, TIFFTAG_SAMPLESPERPIXEL, CHK(C_GRY) ? 1 : 3);
517 <        TIFFSetField(cvts.tif, TIFFTAG_BITSPERSAMPLE, CHK(C_TFLT) ? 32 : 8);
517 >        TIFFSetField(cvts.tif, TIFFTAG_BITSPERSAMPLE,
518 >                        CHK(C_TFLT) ? 32 : CHK(C_TWRD) ? 16 : 8);
519          TIFFSetField(cvts.tif, TIFFTAG_XRESOLUTION, 72.);
520          TIFFSetField(cvts.tif, TIFFTAG_YRESOLUTION, 72./cvts.pixrat);
521          TIFFSetField(cvts.tif, TIFFTAG_ORIENTATION, cvts.orient);
# Line 514 | Line 559 | char  *av[];
559   }
560  
561  
562 < int
562 > void
563   Luv2Color(y)                    /* read/convert/write Luv->COLOR scanline */
564   uint32  y;
565   {
# Line 525 | Line 570 | uint32 y;
570  
571          if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0)
572                  quiterr("error reading TIFF input");
573 <        
573 >                                        /* also works for float RGB */
574          for (x = cvts.xmax; x--; ) {
575 <                colval(cvts.r.colors[x],CIEX) = cvts.t.fp[3*x];
576 <                colval(cvts.r.colors[x],CIEY) = cvts.t.fp[3*x + 1];
577 <                colval(cvts.r.colors[x],CIEZ) = cvts.t.fp[3*x + 2];
575 >                setcolor(cvts.r.colors[x],
576 >                                cvts.t.fp[3*x],
577 >                                cvts.t.fp[3*x + 1],
578 >                                cvts.t.fp[3*x + 2]);
579                  if (CHK(C_CXFM))
580                          colortrans(cvts.r.colors[x], cvts.cmat,
581                                          cvts.r.colors[x]);
# Line 548 | Line 594 | uint32 y;
594   }
595  
596  
597 < int
597 > void
598   RRGGBB2Color(y)                 /* read/convert/write RGB16->COLOR scanline */
599   uint32  y;
600   {
# Line 590 | Line 636 | uint32 y;
636   }
637  
638  
639 < int
640 < L2Color(y)                      /* read/convert/write L16->COLOR scanline */
639 > void
640 > L2Color(y)                      /* read/convert/write Lfloat->COLOR scanline */
641   uint32  y;
642   {
643 +        float   m = pow(2., (double)cvts.bradj);
644          register int    x;
645  
646          if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT|C_GRY))
# Line 601 | Line 648 | uint32 y;
648  
649          if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0)
650                  quiterr("error reading TIFF input");
651 <        
652 <        for (x = cvts.xmax; x--; )
653 <                colval(cvts.r.colors[x],RED) =
654 <                colval(cvts.r.colors[x],GRN) =
655 <                colval(cvts.r.colors[x],BLU) =
656 <                                cvts.t.fp[x] > 0. ? cvts.t.fp[x] : 0.;
610 <
651 >                                        /* also works for float greyscale */
652 >        for (x = cvts.xmax; x--; ) {
653 >                register float  f = cvts.t.fp[x];
654 >                if (cvts.bradj) f *= m;
655 >                setcolor(cvts.r.colors[x], f, f, f);
656 >        }
657          if (fwritescan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0)
658                  quiterr("error writing Radiance picture");
659   }
660  
661  
662 < int
662 > void
663   RGB2Colr(y)                     /* read/convert/write RGB->COLR scanline */
664   uint32  y;
665   {
# Line 669 | Line 715 | readerr:
715   }
716  
717  
718 < int
718 > void
719   Gry2Colr(y)                     /* read/convert/write G8->COLR scanline */
720   uint32  y;
721   {
# Line 695 | Line 741 | uint32 y;
741   }
742  
743  
744 < int
744 > void
745   GGry2Color(y)                   /* read/convert/write G16->COLOR scanline */
746   uint32  y;
747   {
# Line 725 | Line 771 | uint32 y;
771   }
772  
773  
774 < int
775 < Color2L(y)                      /* read/convert/write COLOR->L16 scanline */
774 > void
775 > Color2GGry(y)                   /* read/convert/write COLOR->G16 scanline */
776   uint32  y;
777   {
778 <        double  m = pow(2.,(double)cvts.bradj);
778 >        int     dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01;
779 >        float   m = pow(2.,(double)cvts.bradj);
780          register int    x;
781  
782 +        if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY) != (C_RFLT|C_TWRD|C_GRY))
783 +                quiterr("internal error 1 in Color2GGry");
784 +
785 +        if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0)
786 +                quiterr("error reading Radiance picture");
787 +
788 +        for (x = cvts.xmax; x--; ) {
789 +                register float  f = m*( CHK(C_XYZE) ?
790 +                                                colval(cvts.r.colors[x],CIEY)
791 +                                                : bright(cvts.r.colors[x]) );
792 +                if (f <= 0)
793 +                        cvts.t.wp[x] = 0;
794 +                else if (f >= 1)
795 +                        cvts.t.wp[x] = 0xffff;
796 +                else if (dogamma)
797 +                        cvts.t.wp[x] = (int)((float)(1L<<16) *
798 +                                                pow(f, 1./cvts.gamcor));
799 +                else
800 +                        cvts.t.wp[x] = (int)((float)(1L<<16) * f);
801 +        }
802 +
803 +        if (TIFFWriteScanline(cvts.tif, cvts.t.p, y, 0) < 0)
804 +                quiterr("error writing TIFF output");
805 + }
806 +
807 +
808 + void
809 + Color2L(y)                      /* read/convert/write COLOR->Lfloat scanline */
810 + uint32  y;
811 + {
812 +        float   m = pow(2.,(double)cvts.bradj);
813 +        register int    x;
814 +
815          if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY) != (C_RFLT|C_TFLT|C_GRY))
816                  quiterr("internal error 1 in Color2L");
817  
# Line 747 | Line 827 | uint32 y;
827   }
828  
829  
830 < int
830 > void
831   Color2Luv(y)                    /* read/convert/write COLOR->Luv scanline */
832   uint32  y;
833   {
# Line 768 | Line 848 | uint32 y;
848                  for (x = cvts.xmax; x--; )
849                          scalecolor(cvts.r.colors[x], m);
850          }
851 <
851 >                                        /* also works for float RGB */
852          for (x = cvts.xmax; x--; ) {
853                  cvts.t.fp[3*x] = colval(cvts.r.colors[x],CIEX);
854                  cvts.t.fp[3*x+1] = colval(cvts.r.colors[x],CIEY);
# Line 780 | Line 860 | uint32 y;
860   }
861  
862  
863 < int
863 > void
864 > Color2RRGGBB(y)                 /* read/convert/write COLOR->RGB16 scanline */
865 > uint32  y;
866 > {
867 >        int     dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01;
868 >        float   m = pow(2.,(double)cvts.bradj);
869 >        register int    x, i;
870 >
871 >        if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY) != (C_RFLT|C_TWRD))
872 >                quiterr("internal error 1 in Color2RRGGBB");
873 >
874 >        if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0)
875 >                quiterr("error reading Radiance picture");
876 >
877 >        for (x = cvts.xmax; x--; )
878 >            for (i = 3; i--; ) {
879 >                register float  f = m*colval(cvts.r.colors[x],i);
880 >                if (f <= 0)
881 >                        cvts.t.wp[3*x + i] = 0;
882 >                else if (f >= 1)
883 >                        cvts.t.wp[3*x + i] = 0xffff;
884 >                else if (dogamma)
885 >                        cvts.t.wp[3*x + i] = (int)((float)(1L<<16) *
886 >                                                pow(f, 1./cvts.gamcor));
887 >                else
888 >                        cvts.t.wp[3*x + i] = (int)((float)(1L<<16)*f);
889 >            }
890 >
891 >        if (TIFFWriteScanline(cvts.tif, cvts.t.p, y, 0) < 0)
892 >                quiterr("error writing TIFF output");
893 > }
894 >
895 >
896 > void
897   Colr2Gry(y)                     /* read/convert/write COLR->RGB scanline */
898   uint32  y;
899   {
# Line 806 | Line 919 | uint32 y;
919   }
920  
921  
922 < int
922 > void
923   Colr2RGB(y)                     /* read/convert/write COLR->RGB scanline */
924   uint32  y;
925   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines