Improvements to support for archives

This commit is contained in:
Robert Osfield 2004-11-12 08:55:11 +00:00
parent f30146a9fe
commit b60304f8ad
5 changed files with 70 additions and 11 deletions

View File

@ -47,7 +47,17 @@ void PagedLOD::setDatabasePath(const std::string& path)
char& lastCharacter = _databasePath[_databasePath.size()-1];
const char unixSlash = '/';
const char winSlash = '\\';
if (lastCharacter==winSlash)
{
lastCharacter = unixSlash;
}
else if (lastCharacter!=unixSlash)
{
_databasePath += unixSlash;
}
/*
// make sure the last character is the appropriate slash
#ifdef WIN32
if (lastCharacter==unixSlash)
@ -68,6 +78,7 @@ void PagedLOD::setDatabasePath(const std::string& path)
_databasePath += unixSlash;
}
#endif
*/
}
}

View File

@ -85,6 +85,13 @@ osg::Object* Input::readObject(const std::string& fileName)
osg::Image* Input::readImage(const std::string& fileName)
{
if (_options.valid() && !_options->getDatabasePath().empty())
{
osg::Image* image = readImageFile(_options->getDatabasePath()+'/'+fileName);
if (image) return image;
}
return readImageFile(fileName);
}

View File

@ -178,6 +178,17 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter
osgDB::equalCaseInsensitive(extension,"jpc");
}
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options)
{
return readImage(file,options);
}
virtual ReadResult readObject(std::istream& fin, const Options* options)
{
return readImage(fin,options);
}
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options)
{
std::string ext = osgDB::getFileExtension(file);
@ -266,13 +277,15 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter
jas_stream_t* in = jas_stream_memopen((char*)sdata, ssize);
char* opt = 0;
if(options)
if(options && !options->getOptionString().empty())
{
opt = new char[options->getOptionString().size() + 1];
strcpy(opt, options->getOptionString().c_str());
}
jas_image_t* jimage = jas_image_decode(in, -1, opt); // last is the option string whatto put there?
if(opt) delete[] opt;
if (!jimage) return ReadResult::FILE_NOT_HANDLED;
int internalFormat = jimage->numcmpts_;
@ -312,6 +325,22 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter
return image;
}
virtual WriteResult writeObject(const osg::Object& object,const std::string& file, const osgDB::ReaderWriter::Options* options)
{
const osg::Image* image = dynamic_cast<const osg::Image*>(&object);
if (!image) return WriteResult::FILE_NOT_HANDLED;
return writeImage(*image,file,options);
}
virtual WriteResult writeObject(const osg::Object& object,std::ostream& fout,const Options* options)
{
const osg::Image* image = dynamic_cast<const osg::Image*>(&object);
if (!image) return WriteResult::FILE_NOT_HANDLED;
return writeImage(*image,fout,options);
}
virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options* options)
{
std::string ext = osgDB::getFileExtension(fileName);

View File

@ -34,9 +34,25 @@ public:
return archive.get();
}
virtual ReadResult readObject(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readHeightField(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readImage(const std::string& file,const Options* options)
{
ReadResult result = openArchive(file,osgDB::Archive::READ);
if (!result.validArchive()) return result;
osg::ref_ptr<ReaderWriter::Options> local_options = new ReaderWriter::Options;
local_options->setDatabasePath(file);
ReadResult result_2 = result.getArchive()->readImage(result.getArchive()->getMasterFileName(),local_options.get());
// register the archive so that it is cached for future use.
osgDB::Registry::instance()->addToArchiveCache(file, result.getArchive());
return result_2;
}
virtual ReadResult readNode(const std::string& file,const Options* options)
{
@ -58,11 +74,6 @@ public:
return result_2;
}
virtual WriteResult writeObject(const osg::Object& /*obj*/,const std::string& /*fileName*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,const std::string& /*fileName*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options* =NULL) { return WriteResult(WriteResult::FILE_NOT_HANDLED); }
protected:

View File

@ -1946,6 +1946,7 @@ osg::StateSet* DataSet::DestinationTile::createStateSet()
if (!_imagery.valid() || !_imagery->_image.valid()) return 0;
std::string imageExension(".dds"); // ".rgb"
//std::string imageExension(".jp2"); // ".rgb"
std::string imageName(_name+imageExension);
_imagery->_image->setFileName(imageName.c_str());
@ -3896,7 +3897,7 @@ void DataSet::_buildDestination(bool writeToDisk)
if (!_archive && !_archiveName.empty())
{
unsigned int indexBlockSizeHint=4096;
_archive = openArchive(_archiveName, osgDB::Archive::CREATE, indexBlockSizeHint);
_archive = osgDB::openArchive(_archiveName, osgDB::Archive::CREATE, indexBlockSizeHint);
}
if (_destinationGraph.valid())