Logo Search packages:      
Sourcecode: pfstools version File versions  Download package

HDRTiffReader::HDRTiffReader ( const char *  filename  ) 

for verbose output

! TODO: verify if 8bit is always gamma corrected

! TODO: verify this case!!

Definition at line 46 of file hdrtiffio.cpp.

References exponential_mode, format_string, nSamples, phot, relative_values, stonits, TypeOfData, and xyz_colorspace.

{
  // default values for constants
  exponential_mode = false;
  relative_values = false;
  xyz_colorspace = false;

  // read header containing width and height from file
  tif = TIFFOpen(filename, "r");
  if( !tif )
    throw pfs::Exception("TIFF: could not open file for reading.");

  //--- image size
  TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
  TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);

  if( width*height<=0 )
  {
    TIFFClose(tif);
    throw pfs::Exception("TIFF: illegal image size");
  }

  DEBUG_STR << "TIFF file \"" << filename << "\" ("
          << width << "x" << height << ")" << endl;

      //--- image parameters
  if(!TIFFGetField(tif, TIFFTAG_COMPRESSION, &comp)) // compression type
    comp = COMPRESSION_NONE;

      // type of photometric data
  if(!TIFFGetFieldDefaulted(tif, TIFFTAG_PHOTOMETRIC, &phot))
    throw pfs::Exception("TIFF: unspecified photometric type");

  uint16 * extra_sample_types=0;
  uint16 extra_samples_per_pixel=0;
  switch(phot)
  {
    case PHOTOMETRIC_LOGLUV:
      DEBUG_STR << "Photometric data: LogLuv" << endl;
      if (comp != COMPRESSION_SGILOG && comp != COMPRESSION_SGILOG24)
      {
      TIFFClose(tif);
      throw pfs::Exception("TIFF: only support SGILOG compressed LogLuv data");
      }
      TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &nSamples);
      // set decoder to output in float XYZ
      TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_FLOAT);
      xyz_colorspace = true;
      TypeOfData = FLOAT;      
      strcpy(format_string,"linear LogLuv XYZ");
      relative_values=true;
      break;
    case PHOTOMETRIC_RGB:
      DEBUG_STR << "Photometric data: RGB" << endl;
     // read extra samples (# of alpha channels)
      if (TIFFGetField( tif, TIFFTAG_EXTRASAMPLES,
                        &extra_samples_per_pixel, &extra_sample_types )!=1)
      {
          extra_samples_per_pixel=0;
      }


      TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &nSamples);
      bps = nSamples - extra_samples_per_pixel;
      if (bps!=3)
      {
      TIFFClose(tif);
      throw pfs::Exception("TIFF: unsupported samples per pixel for RGB");
      }
      if (!TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bps) || (bps!=8 && bps!=16 && bps!=32))
      {
      TIFFClose(tif);
      throw pfs::Exception("TIFF: unsupported bits per sample for RGB");
      }

      if( bps==8 )
      {
      TypeOfData = BYTE;
      DEBUG_STR << "8bit per channel" << endl;
        strcpy(format_string,"linear 8bit RGB");
        relative_values=false; //!! TODO: verify if 8bit is always gamma corrected
      }
      else if( bps==16 )
      {
      TypeOfData = WORD;
      DEBUG_STR << "16bit per channel" << endl;
        strcpy(format_string,"linear 16bit RGB");
        relative_values=true;   //!! TODO: verify this case!!
      }
      else
      {
      TypeOfData = FLOAT;
      DEBUG_STR << "32bit float per channel" << endl;
        strcpy(format_string,"linear 32bit float RGB");
        relative_values=true; 
      }
      break;
    case PHOTOMETRIC_MINISBLACK: // HDR video camera format (grayscale)
      DEBUG_STR << "Photometric data: MINISBLACK (hdrv camera)" << endl;
      if (!TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &bps) || !bps==1)
      {
      TIFFClose(tif);
      throw pfs::Exception("TIFF: Unsupported samples per pixel for "
                       "grayscale image");
      }
      if (!TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bps) || !bps==16)
      {
      DEBUG_STR << "Detected bits per sample: " << bps << endl;
      TIFFClose(tif);
      throw pfs::Exception("TIFF: unsupported bits per sample for "
                       "grayscale image.");
      }
      TypeOfData = GRAYSCALE16;
      strcpy(format_string,"linear 16bit");
      relative_values=true;
      break;
    default:
      DEBUG_STR << "Unsupported photometric type: " << phot << endl;
      TIFFClose(tif);
      strcpy(format_string,"unknown");
      relative_values=false;
      throw pfs::Exception("TIFF: unsupported photometric type");
  }

  if (!TIFFGetField(tif, TIFFTAG_STONITS, &stonits))
    stonits = 1.;
}


Generated by  Doxygen 1.6.0   Back to index