Added osg::Image::set/getWriteHint() that allows images themselves to control how

they are written to disk, either inline or as an external file.  Added support for
this in the .ive plugin.  Default of WriteHint is NO_PREFERNCE, in which case it's
up to the reader/writer to decide.
This commit is contained in:
Robert Osfield 2008-09-10 11:26:30 +00:00
parent c478ad08fc
commit 45ccf11161
9 changed files with 56 additions and 10 deletions

View File

@ -79,6 +79,15 @@ class OSG_EXPORT Image : public Object
void setFileName(const std::string& fileName);
inline const std::string& getFileName() const { return _fileName; }
enum WriteHint {
NO_PREFERENCE,
STORE_INLINE,
EXTERNAL_FILE
};
void setWriteHint(WriteHint writeHint) { _writeHint = writeHint; }
WriteHint getWriteHint() const { return _writeHint; }
enum AllocationMode {
NO_DELETE,
USE_NEW_DELETE,
@ -307,6 +316,8 @@ class OSG_EXPORT Image : public Object
Image& operator = (const Image&) { return *this; }
std::string _fileName;
WriteHint _writeHint;
Origin _origin;

View File

@ -38,6 +38,7 @@ Image::Image()
setDataVariance(STATIC);
_fileName = "";
_writeHint = NO_PREFERENCE;
_origin = BOTTOM_LEFT;
_s = _t = _r = 0;
_internalTextureFormat = 0;
@ -54,6 +55,7 @@ Image::Image()
Image::Image(const Image& image,const CopyOp& copyop):
Object(image,copyop),
_fileName(image._fileName),
_writeHint(image._writeHint),
_origin(image._origin),
_s(image._s), _t(image._t), _r(image._r),
_internalTextureFormat(image._internalTextureFormat),

View File

@ -1125,8 +1125,27 @@ void DataOutputStream::writeNode(const osg::Node* node)
}
}
IncludeImageMode DataOutputStream::getIncludeImageMode(const osg::Image* image) const
{
if (image)
{
if (image->getWriteHint()==osg::Image::STORE_INLINE)
{
return IMAGE_INCLUDE_DATA;
}
else if (image->getWriteHint()==osg::Image::EXTERNAL_FILE)
{
return IMAGE_REFERENCE_FILE;
}
}
return getIncludeImageMode();
}
void DataOutputStream::writeImage(osg::Image *image)
{
IncludeImageMode mode = getIncludeImageMode(image);
if ( getVersion() >= VERSION_0029)
{
osg::ImageSequence* is = dynamic_cast<osg::ImageSequence*>(image);
@ -1137,19 +1156,20 @@ void DataOutputStream::writeImage(osg::Image *image)
else
{
writeInt(IVEIMAGE);
writeChar(getIncludeImageMode());
writeImage(getIncludeImageMode(),image);
writeChar(mode);
writeImage(mode,image);
}
}
else
{
writeChar(getIncludeImageMode());
writeImage(getIncludeImageMode(),image);
writeChar(mode);
writeImage(mode,image);
}
}
void DataOutputStream::writeImage(IncludeImageMode mode, osg::Image *image)
{
osg::notify(osg::NOTICE)<<"DataOutputStream::writeImage("<<mode<<" image->getFileName()="<<image->getFileName()<<std::endl;
switch(mode) {
case IMAGE_INCLUDE_DATA:
// Include image data in stream

View File

@ -107,6 +107,7 @@ public:
// Set and get include image data in stream
void setIncludeImageMode(IncludeImageMode mode) {_includeImageMode=mode;};
IncludeImageMode getIncludeImageMode() const {return _includeImageMode;};
IncludeImageMode getIncludeImageMode(const osg::Image* image) const;
// Set and get include external references in stream
void setIncludeExternalReferences(bool b) {_includeExternalReferences=b;};

View File

@ -36,6 +36,11 @@ void Image::write(DataOutputStream* out)
// Write name
out->writeString(getFileName());
if ( out->getVersion() >= VERSION_0031)
{
out->writeInt((int)getWriteHint());
}
// Write width, height, depth of image.
out->writeInt(s());
out->writeInt(t());
@ -91,6 +96,11 @@ void Image::read(DataInputStream* in)
// Read name
setFileName(in->readString());
if ( in->getVersion() >= VERSION_0031)
{
setWriteHint((osg::Image::WriteHint)in->readInt());
}
// Read width, height, depth of image.
int is=in->readInt();
int it=in->readInt();

View File

@ -32,7 +32,7 @@ void ImageLayer::write(DataOutputStream* out)
throw Exception("ImageLayer::write(): Could not cast this osgLayer::ImageLayer to an osgTerrain::Layer.");
IncludeImageMode imMode = out->getIncludeImageMode();
IncludeImageMode imMode = out->getIncludeImageMode(getImage());
if (getFileName().empty() && imMode==IMAGE_REFERENCE_FILE) imMode = IMAGE_INCLUDE_DATA;

View File

@ -40,8 +40,9 @@
#define VERSION_0029 29
#define VERSION_0030 30
#define VERSION_0031 31
#define VERSION_0032 32
#define VERSION VERSION_0031
#define VERSION VERSION_0032
/* The BYTE_SEX tag is used to check the endian
of the IVE file being read in. The IVE format

View File

@ -48,7 +48,8 @@ class ReaderWriterIVE : public ReaderWriter
// code for setting up the database path so that internally referenced files are searched for on relative paths.
osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options;
local_opt->setDatabasePath(osgDB::getFilePath(fileName));
local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName));
std::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary);
return readImage(istream, local_opt.get());
}
@ -63,7 +64,7 @@ class ReaderWriterIVE : public ReaderWriter
// code for setting up the database path so that internally referenced file are searched for on relative paths.
osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options;
local_opt->setDatabasePath(osgDB::getFilePath(fileName));
local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName));
std::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary);
return readNode(istream,local_opt.get());

View File

@ -50,7 +50,7 @@ void TextureCubeMap::write(DataOutputStream* out){
else
{
// Should we include images date in stream
IncludeImageMode includeImg = out->getIncludeImageMode();
IncludeImageMode includeImg = out->getIncludeImageMode(getImage(osg::TextureCubeMap::POSITIVE_X));
out->writeChar(includeImg);
out->writeImage(includeImg,getImage(osg::TextureCubeMap::POSITIVE_X));