Merge pull request #619 from mathieu/topic/SaveInlinedImages
Added saving of inline Images without having the physical image file.
This commit is contained in:
commit
960f4d1ef2
@ -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,35 +582,61 @@ 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() );
|
||||||
osgDB::ifstream infile( fullPath.c_str(), std::ios::in|std::ios::binary );
|
if (fullPath.empty()==false)
|
||||||
if ( infile )
|
|
||||||
{
|
{
|
||||||
infile.seekg( 0, std::ios::end );
|
osgDB::ifstream infile( fullPath.c_str(), std::ios::in|std::ios::binary );
|
||||||
unsigned int size = infile.tellg();
|
|
||||||
writeSize(size);
|
|
||||||
|
|
||||||
if ( size>0 )
|
if ( infile )
|
||||||
{
|
{
|
||||||
char* data = new char[size];
|
infile.seekg( 0, std::ios::end );
|
||||||
if ( !data )
|
unsigned int size = infile.tellg();
|
||||||
{
|
writeSize(size);
|
||||||
throwException( "OutputStream::writeImage(): Out of memory." );
|
|
||||||
if ( getException() ) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
infile.seekg( 0, std::ios::beg );
|
if ( size>0 )
|
||||||
infile.read( data, size );
|
{
|
||||||
writeCharArray( data, size );
|
char* data = new char[size];
|
||||||
delete[] data;
|
if ( !data )
|
||||||
|
{
|
||||||
|
throwException( "OutputStream::writeImage(): Out of memory." );
|
||||||
|
if ( getException() ) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
infile.seekg( 0, std::ios::beg );
|
||||||
|
infile.read( data, size );
|
||||||
|
writeCharArray( data, size );
|
||||||
|
delete[] data;
|
||||||
|
}
|
||||||
|
infile.close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OSG_WARN << "OutputStream::writeImage(): Failed to open image file "
|
||||||
|
<< img->getFileName() << std::endl;
|
||||||
|
*this << (unsigned int)0;
|
||||||
}
|
}
|
||||||
infile.close();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
OSG_WARN << "OutputStream::writeImage(): Failed to open image file "
|
std::string ext = osgDB::getFileExtension( img->getFileName() );
|
||||||
<< img->getFileName() << std::endl;
|
osgDB::ReaderWriter* writer =
|
||||||
*this << (unsigned int)0;
|
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:
|
||||||
|
Loading…
Reference in New Issue
Block a user