Logo Search packages:      
Sourcecode: qtpfsgui version File versions

TiffReader::TiffReader ( const char *  filename  ) 

scale factor to get nit values

Tiff facilities.

This file is a part of Qtpfsgui package. ---------------------------------------------------------------------- Copyright (C) 2003,2004 Rafal Mantiuk and Grzegorz Krawczyk Copyright (C) 2006 Giuseppe Rota

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ----------------------------------------------------------------------

Author:
Grzegorz Krawczyk, <krawczyk@mpi-sb.mpg.de> slightly modified by Giuseppe Rota <grota@sourceforge.net> for qtpfsgui

Definition at line 33 of file pfstiff.cpp.

References nSamples, phot, stonits, and TypeOfData.

                                             {
  // 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");
  }

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

  // 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:
      qDebug("Photometric data: LogLuv");
      if (comp != COMPRESSION_SGILOG && comp != COMPRESSION_SGILOG24) {
      TIFFClose(tif);
      throw pfs::Exception("TIFF: only support SGILOG compressed LogLuv data");
      }
      TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &nSamples);
      TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_FLOAT);
      TypeOfData = FLOATLOGLUV;
      break;
    case PHOTOMETRIC_RGB:
      qDebug("Photometric data: RGB");
     // 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;
      qDebug("8bit per channel");
      }
      else if( bps==16 )
      {
      TypeOfData = WORD;
      qDebug("16bit per channel");
      }
      else
      {
      TypeOfData = FLOAT;
      qDebug("32bit float per channel");
      }
      break;
    default:
      qFatal("Unsupported photometric type: %d",phot);
      TIFFClose(tif);
      throw pfs::Exception("TIFF: unsupported photometric type");
  }

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


Generated by  Doxygen 1.6.0   Back to index