degate  0.1.2
Public Member Functions
degate::TIFFWriter< ImageType > Class Template Reference

The TIFFWriter parses tiff images. More...

#include <TIFFWriter.h>

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

List of all members.

Public Member Functions

 TIFFWriter (unsigned int width, unsigned int height, std::string const &filename)
virtual ~TIFFWriter ()
bool write_image (std::shared_ptr< ImageType > img)
 exception FileSystemException

Detailed Description

template<class ImageType>
class degate::TIFFWriter< ImageType >

The TIFFWriter parses tiff images.

Definition at line 47 of file TIFFWriter.h.


Constructor & Destructor Documentation

template<class ImageType >
degate::TIFFWriter< ImageType >::TIFFWriter ( unsigned int  width,
unsigned int  height,
std::string const &  filename 
) [inline]

Definition at line 56 of file TIFFWriter.h.

                                          :
      ImageWriterBase<ImageType>(width, height, filename) {}
template<class ImageType >
virtual degate::TIFFWriter< ImageType >::~TIFFWriter ( ) [inline, virtual]

Definition at line 60 of file TIFFWriter.h.

{ }

Member Function Documentation

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

exception FileSystemException

Implements degate::ImageWriterBase< ImageType >.

Definition at line 70 of file TIFFWriter.h.

References MASK_B, MASK_G, and MASK_R.

                                                                      {

    TIFF * tif = TIFFOpen(get_filename().c_str(), "w");
    if(tif == NULL) {
      throw FileSystemException(strerror(errno));
    }

    size_t npixels = get_width() * get_height();

    char * raster = (char*) _TIFFmalloc(npixels * 3);
    if(raster == NULL) return false;

    for(unsigned int y = 0; y < get_height(); y++) {
      for(unsigned int x = 0; x < get_width(); x++) {

        rgba_pixel_t p =
          img->template get_pixel_as<rgba_pixel_t>(x, y);

        raster[3*(y * get_width() + x)] = MASK_R(p);
        raster[3*(y * get_width() + x)+1] = MASK_G(p);
        raster[3*(y * get_width() + x)+2] = MASK_B(p);
      }
    }


    // Write the tiff tags to the file
    TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, get_width());
    TIFFSetField(tif, TIFFTAG_IMAGELENGTH, get_height());
    TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
    TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
    TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
    TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
    TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);

    bool ret = true;

    // Actually write the image
    if(TIFFWriteEncodedStrip(tif, 0, raster, npixels * 3) == 0) {
      ret = false;
    }

    if(tif != NULL) TIFFClose(tif);
    _TIFFfree(raster);

    return ret;
  }

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