|
degate 0.1.1
|
The TIFFWriter parses tiff images. More...
#include <TIFFWriter.h>

Public Member Functions | |
| TIFFWriter (unsigned int width, unsigned int height, std::string const &filename) | |
| virtual | ~TIFFWriter () |
| bool | write_image (std::tr1::shared_ptr< ImageType > img) |
| exception FileSystemException | |
The TIFFWriter parses tiff images.
Definition at line 47 of file TIFFWriter.h.
| degate::TIFFWriter< ImageType >::TIFFWriter | ( | unsigned int | width, |
| unsigned int | height, | ||
| std::string const & | filename | ||
| ) | [inline] |
Definition at line 56 of file TIFFWriter.h.
| virtual degate::TIFFWriter< ImageType >::~TIFFWriter | ( | ) | [inline, virtual] |
Definition at line 60 of file TIFFWriter.h.
{ }
| bool degate::TIFFWriter< ImageType >::write_image | ( | std::tr1::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->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;
}
1.7.4