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

void HDRTiffReader::readImage ( pfs::Array2D X,
pfs::Array2D Y,
pfs::Array2D Z 
)

! this is for exponential tiffs

Definition at line 174 of file hdrtiffio.cpp.

References exponential_mode, pfs::Array2D::getCols(), nSamples, and TypeOfData.

{
  //--- scanline buffer with pointers to different data types
  union {
    float* fp;
    uint16* wp;
    uint8* bp;
    void* vp;
  } buf;

  //--- image length
  uint32 imagelength;
  TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &imagelength);
  DEBUG_STR << "Image length: " << imagelength << endl;

  //--- image scanline size
  uint32 scanlinesize = TIFFScanlineSize(tif);
  buf.vp = _TIFFmalloc(scanlinesize);
//    DEBUG_STR << "Scanline size: " << scanlinesize << endl;


  //--- read scan lines
  const int image_width = X->getCols();
  for(uint32 row = 0; row < imagelength; row++)
  {
    switch(TypeOfData)
    {
      case FLOAT:
      TIFFReadScanline(tif, buf.fp, row);
      for( int i=0; i < image_width; i++ )
      {
        (*X)(i,row) = buf.fp[i*nSamples];
        (*Y)(i,row) = buf.fp[i*nSamples+1];
        (*Z)(i,row) = buf.fp[i*nSamples+2];
      }
      break;
      case WORD:
      TIFFReadScanline(tif, buf.wp, row);
      for( int i=0; i<image_width; i++ )
      {
        (*X)(i,row) = buf.wp[i*nSamples];
        (*Y)(i,row) = buf.wp[i*nSamples+1];
        (*Z)(i,row) = buf.wp[i*nSamples+2];
      }
      break;
      case BYTE:
      TIFFReadScanline(tif, buf.bp, row);
      for( int i=0; i<image_width; i++ )
      {
        (*X)(i,row) = buf.bp[i*nSamples]/255.0;
        (*Y)(i,row) = buf.bp[i*nSamples+1]/255.0;
        (*Z)(i,row) = buf.bp[i*nSamples+2]/255.0;
//      (*X)(i,row) = pow( buf.bp[i*nSamples]/255.0, 2.2 );
//      (*Y)(i,row) = pow( buf.bp[i*nSamples+1]/255.0, 2.2 );
//      (*Z)(i,row) = pow( buf.bp[i*nSamples+2]/255.0, 2.2 );
//                      (*X)(i,row) = buf.bp[i*3];
//                      (*Y)(i,row) = buf.bp[i*3+1];
//                      (*Z)(i,row) = buf.bp[i*3+2];
      }
      break;
      case GRAYSCALE16:
      TIFFReadScanline(tif, buf.wp, row);

        if( !exponential_mode )
        {
          for( int i=0; i<image_width ; i++ )
          {
            float lum = buf.wp[i];
            // D65 observer XYZ = (95.047,100,108.883);
            (*X)(i,row) = 0.95047f * lum;
            (*Y)(i,row) = lum;
            (*Z)(i,row) = 1.08883f * lum;
          }
        }
        else
        {
          //!! this is for exponential tiffs
          for( int i=0; i<image_width ; i++ )
          {
            static float pow2[] = {1,2,4,8,16,32,64,128,256,
                                   512,1024,2048,4096,8192,16384,32768};
            //--- 16bit value = a:4bit..b:12bit, lum = b*2^a
            float value = buf.wp[i] & 0x0fff;
            unsigned char expo = ( buf.wp[i] & 0xf000 ) >> 12;
            float lum = value*pow2[expo];
            (*X)(i,imagelength-row-1) = lum;
            (*Y)(i,imagelength-row-1) = lum;
            (*Z)(i,imagelength-row-1) = lum;
          }
        }
      break;
    }
  }

  //--- free buffers and close files
  _TIFFfree(buf.vp);
  TIFFClose(tif);
}


Generated by  Doxygen 1.6.0   Back to index