degate  0.1.2
Public Member Functions | Private Attributes
degate::TIFFReader< ImageType > Class Template Reference

The TIFFReader parses tiff images. More...

#include <TIFFReader.h>

Inheritance diagram for degate::TIFFReader< ImageType >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 TIFFReader (std::string const &filename)
 ~TIFFReader ()
bool read ()
 Read the image ot at least its meta data.
bool get_image (std::shared_ptr< ImageType >)
 Read the file content into image.

Private Attributes

TIFF * tif

Detailed Description

template<class ImageType>
class degate::TIFFReader< ImageType >

The TIFFReader parses tiff images.

Definition at line 41 of file TIFFReader.h.


Constructor & Destructor Documentation

template<class ImageType >
degate::TIFFReader< ImageType >::TIFFReader ( std::string const &  filename) [inline]

Definition at line 56 of file TIFFReader.h.

                                          :
      ImageReaderBase<ImageType>(filename),
      tif(NULL) {}
template<class ImageType >
degate::TIFFReader< ImageType >::~TIFFReader ( ) [inline]

Definition at line 60 of file TIFFReader.h.

References degate::TIFFReader< ImageType >::tif.

                  {
      if(tif != NULL) TIFFClose(tif);
    }

Member Function Documentation

template<class ImageType >
bool degate::TIFFReader< ImageType >::get_image ( std::shared_ptr< ImageType >  img) [virtual]

Read the file content into image.

Implements degate::ImageReaderBase< ImageType >.

Definition at line 87 of file TIFFReader.h.

                                                                    {

    size_t npixels = get_width() * get_height();
    uint32 * raster = (uint32*) _TIFFmalloc(npixels * sizeof (uint32));
    if(raster == NULL) return false;

    if(TIFFReadRGBAImage(tif, get_width(), get_height(), raster, 0)) {
      for(unsigned int y = 0; y < get_height(); y++) {
        for(unsigned int x = 0; x < get_width(); x++) {

          uint32 v = raster[y * get_width() + x];

          img->set_pixel(x, get_height() - y -1, v);

        }
      }

    }
    _TIFFfree(raster);
    return true;
  }
template<class ImageType >
bool degate::TIFFReader< ImageType >::read ( ) [virtual]

Read the image ot at least its meta data.

If you derive from class ImageReaderBase, you can implement a full image read operation here. But it is also possible to implement just the read of meta data, such as width and height.

Returns:
The function returns true, if the image file was read. Else false is returned. If read() was successful you can

Implements degate::ImageReaderBase< ImageType >.

Definition at line 72 of file TIFFReader.h.

                                   {
    tif = TIFFOpen(get_filename().c_str(), "r");
    if(tif == NULL) return false;

    uint32 w, h;
    TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
    TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);

    set_width(w);
    set_height(h);

    return true;
  }

Member Data Documentation

template<class ImageType >
TIFF* degate::TIFFReader< ImageType >::tif [private]

Definition at line 45 of file TIFFReader.h.

Referenced by degate::TIFFReader< ImageType >::~TIFFReader().


The documentation for this class was generated from the following file: