Added saving of inline Images without having the physical image file.

The can be read from and inlined image file
This commit is contained in:
Mathieu MARACHE 2018-09-07 14:04:41 +02:00 committed by Mathieu MARACHE
parent dfdb946d60
commit 2e38e4751c
No known key found for this signature in database
GPG Key ID: B9FCC2E99545A9A3

View File

@ -17,6 +17,7 @@
#include <osgDB/ConvertBase64> #include <osgDB/ConvertBase64>
#include <osgDB/FileUtils> #include <osgDB/FileUtils>
#include <osgDB/WriteFile> #include <osgDB/WriteFile>
#include <osgDB/FileNameUtils>
#include <osgDB/ObjectWrapper> #include <osgDB/ObjectWrapper>
#include <osgDB/fstream> #include <osgDB/fstream>
#include <sstream> #include <sstream>
@ -581,7 +582,10 @@ void OutputStream::writeImage( const osg::Image* img )
if ( isBinary() ) if ( isBinary() )
{ {
std::string fullPath = osgDB::findDataFile( img->getFileName(), _options.get() ); std::string fullPath = osgDB::findDataFile( img->getFileName(), _options.get() );
if (fullPath.empty()==false)
{
osgDB::ifstream infile( fullPath.c_str(), std::ios::in|std::ios::binary ); osgDB::ifstream infile( fullPath.c_str(), std::ios::in|std::ios::binary );
if ( infile ) if ( infile )
{ {
infile.seekg( 0, std::ios::end ); infile.seekg( 0, std::ios::end );
@ -611,6 +615,29 @@ void OutputStream::writeImage( const osg::Image* img )
*this << (unsigned int)0; *this << (unsigned int)0;
} }
} }
else
{
std::string ext = osgDB::getFileExtension( img->getFileName() );
osgDB::ReaderWriter* writer =
osgDB::Registry::instance()->getReaderWriterForExtension( ext );
if ( writer )
{
std::stringstream outputStream;
writer->writeImage(*img, outputStream, getOptions());
std::string data (outputStream.str());
unsigned int size = data.size();
writeSize(size);
writeCharArray( data.c_str(), size );
}
else
{
OSG_WARN << "OutputStream::writeImage(): Failed to find a plugin to write the image file "
<< img->getFileName() << std::endl;
*this << (unsigned int)0;
}
}
}
break; break;
case IMAGE_EXTERNAL: case IMAGE_EXTERNAL:
break; break;