From 8796f37acb7296d754a6d9914e6ca898c9977ba1 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 2 Mar 2006 20:31:40 +0000 Subject: [PATCH] Added automatic toggling between png and jpeg when compressImageData option is used. Jpeg is used to compress RGB data only, the just of the formats are passed on to the png plugin. --- src/osgPlugins/ive/DataOutputStream.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index eed1cb3f7..bfd92346f 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -1061,11 +1061,17 @@ void DataOutputStream::writeImage(IncludeImageMode mode, osg::Image *image) } break; case IMAGE_COMPRESS_DATA: - if(image) { + if(image) + { //Get ReaderWriter for jpeg images - osgDB::ReaderWriter *writer = osgDB::Registry::instance()->getReaderWriterForExtension("jpeg"); + + std::string extension = "png"; + if (image->getPixelFormat()==GL_RGB) extension = "jpg"; + + osgDB::ReaderWriter* writer = osgDB::Registry::instance()->getReaderWriterForExtension(extension); - if(writer) { + if(writer) + { //Attempt to write the image to an output stream. //The reason this isn't performed directly on the internal _ostream //is because the writer might perform seek operations which could @@ -1079,7 +1085,7 @@ void DataOutputStream::writeImage(IncludeImageMode mode, osg::Image *image) //Write file format. Do this for two reasons: // 1 - Same code can be used to read in as with IMAGE_INCLUDE_FILE mode // 2 - Maybe in future version user can specify which format to use - writeString(".jpeg"); //Need to add dot so osgDB::getFileExtension will work + writeString(std::string(".")+extension); //Need to add dot so osgDB::getFileExtension will work //Write size of stream int size = outputStream.tellp();