From Bryce Eldridge, "Here is an update for the TIFF plugin that includes the following features when writing out TIFF files:
- Support for writing unsigned 16-bit images (GL_UNSIGNED_SHORT) - Code to parse the options string for the following options: -- Flag to turn off the compression. The PACKBITS compression type causes issues for me with some programs on Windows (Picasa for example). -- Options to set the XRESOLUTION and YRESOLUTION tags (DPI) in the TIFF file. Existing behavior (PACKBITS compression, DPI tags left at default) is preserved if the options string is not set. "
This commit is contained in:
parent
909a4d1603
commit
b8b368dc7c
@ -829,7 +829,7 @@ class ReaderWriterTIFF : public osgDB::ReaderWriter
|
||||
return pOsgImage;
|
||||
}
|
||||
|
||||
WriteResult::WriteStatus writeTIFStream(std::ostream& fout, const osg::Image& img) const
|
||||
WriteResult::WriteStatus writeTIFStream(std::ostream& fout, const osg::Image& img, bool noCompression, float xResDPI, float yResDPI) const
|
||||
{
|
||||
//Code is based from the following article on CodeProject.com
|
||||
//http://www.codeproject.com/bitmap/BitmapsToTiffs.asp
|
||||
@ -887,6 +887,10 @@ class ReaderWriterTIFF : public osgDB::ReaderWriter
|
||||
TIFFSetField(image, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_INT);
|
||||
bitsPerSample = 16;
|
||||
break;
|
||||
case GL_UNSIGNED_SHORT:
|
||||
TIFFSetField(image, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT);
|
||||
bitsPerSample = 16;
|
||||
break;
|
||||
default:
|
||||
bitsPerSample = 8;
|
||||
break;
|
||||
@ -897,10 +901,17 @@ class ReaderWriterTIFF : public osgDB::ReaderWriter
|
||||
TIFFSetField(image, TIFFTAG_BITSPERSAMPLE,bitsPerSample);
|
||||
TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL,samplesPerPixel);
|
||||
TIFFSetField(image, TIFFTAG_PHOTOMETRIC, photometric);
|
||||
TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_PACKBITS);
|
||||
TIFFSetField(image, TIFFTAG_COMPRESSION, noCompression ? COMPRESSION_NONE : COMPRESSION_PACKBITS);
|
||||
TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
|
||||
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
|
||||
|
||||
if(xResDPI > 0 && yResDPI > 0)
|
||||
{
|
||||
TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
|
||||
TIFFSetField(image, TIFFTAG_XRESOLUTION, xResDPI);
|
||||
TIFFSetField(image, TIFFTAG_YRESOLUTION, yResDPI);
|
||||
}
|
||||
|
||||
//uint32 rowsperstrip = TIFFDefaultStripSize(image, -1);
|
||||
//TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
|
||||
|
||||
@ -945,9 +956,36 @@ class ReaderWriterTIFF : public osgDB::ReaderWriter
|
||||
return rr;
|
||||
}
|
||||
|
||||
virtual WriteResult writeImage(const osg::Image& img,std::ostream& fout,const osgDB::ReaderWriter::Options* /*options*/) const
|
||||
virtual WriteResult writeImage(const osg::Image& img,std::ostream& fout,const osgDB::ReaderWriter::Options* options) const
|
||||
{
|
||||
WriteResult::WriteStatus ws = writeTIFStream(fout,img);
|
||||
bool noCompression = false;
|
||||
float xResDPI = 0;
|
||||
float yResDPI = 0;
|
||||
|
||||
if(options)
|
||||
{
|
||||
std::istringstream iss(options->getOptionString());
|
||||
std::string opt;
|
||||
|
||||
while( iss >> opt)
|
||||
{
|
||||
if(opt == "no_compression")
|
||||
{
|
||||
noCompression = true;
|
||||
}
|
||||
else if(opt == "x_resolution")
|
||||
{
|
||||
iss >> xResDPI;
|
||||
}
|
||||
else if(opt == "y_resolution")
|
||||
{
|
||||
iss >> yResDPI;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
WriteResult::WriteStatus ws = writeTIFStream(fout,img,noCompression,xResDPI,yResDPI);
|
||||
return ws;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user