From Farshid Lashkari, "I've attached another modified version of the IVE loader which

supports compressing the image data. The option to compress the data
is "compressImageData". Currently it uses the jpeg plugin to write the
image. Maybe we could add an option that allows the user to specify
which image format to use. The jpeg writer supports specifying the
quality of the jpeg, so you could use the following command line to
convert the skydome.osg model to IVE using 50% jpeg quality:

osgconv -O "compressImageData JPEG_QUALITY 50" skydome.osg skydome.ive"
This commit is contained in:
Robert Osfield 2006-03-01 10:17:53 +00:00
parent 58bdc6f92f
commit 74f073c2a8
3 changed files with 41 additions and 1 deletions

View File

@ -837,6 +837,7 @@ osg::Image* DataInputStream::readImage(IncludeImageMode mode)
}
break;
case IMAGE_INCLUDE_FILE:
case IMAGE_COMPRESS_DATA:
// Read image file from stream
{
std::string filename = readString();

View File

@ -89,6 +89,7 @@
#include <osgDB/FileUtils>
#include <fstream>
#include <sstream>
using namespace ive;
@ -103,6 +104,8 @@ void DataOutputStream::setOptions(const osgDB::ReaderWriter::Options* options)
setIncludeImageMode(IMAGE_REFERENCE_FILE);
} else if(_options->getOptionString().find("includeImageFileInIVEFile")!=std::string::npos) {
setIncludeImageMode(IMAGE_INCLUDE_FILE);
} else if(_options->getOptionString().find("compressImageData")!=std::string::npos) {
setIncludeImageMode(IMAGE_COMPRESS_DATA);
}
osg::notify(osg::DEBUG_INFO) << "ive::DataOutpouStream.setIncludeImageMode()=" << getIncludeImageMode() << std::endl;
@ -1057,6 +1060,42 @@ void DataOutputStream::writeImage(IncludeImageMode mode, osg::Image *image)
writeInt(0);
}
break;
case IMAGE_COMPRESS_DATA:
if(image) {
//Get ReaderWriter for jpeg images
osgDB::ReaderWriter *writer = osgDB::Registry::instance()->getReaderWriterForExtension("jpeg");
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
//corrupt the output stream.
std::stringstream outputStream;
osgDB::ReaderWriter::WriteResult wr;
wr = writer->writeImage(*image,outputStream,_options.get());
if(wr.success()) {
//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
//Write size of stream
int size = outputStream.tellp();
writeInt(size);
//Write stream
writeCharArray(outputStream.str().c_str(),size);
return;
}
}
}
//Image compression failed, write blank data
writeString("");
writeInt(0);
break;
default:
throw Exception("DataOutputStream::writeImage(): Invalid IncludeImageMode value.");
break;

View File

@ -12,7 +12,7 @@
//Don't know where else to put this
namespace ive{
typedef enum IncludeImageMode { IMAGE_REFERENCE_FILE=0,IMAGE_INCLUDE_DATA,IMAGE_INCLUDE_FILE };
typedef enum IncludeImageMode { IMAGE_REFERENCE_FILE=0,IMAGE_INCLUDE_DATA,IMAGE_INCLUDE_FILE,IMAGE_COMPRESS_DATA };
}
#endif