Improvements to support for archives
This commit is contained in:
parent
f30146a9fe
commit
b60304f8ad
@ -48,6 +48,16 @@ void PagedLOD::setDatabasePath(const std::string& path)
|
||||
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
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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,7 +277,7 @@ 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());
|
||||
@ -274,6 +285,8 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter
|
||||
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_;
|
||||
|
||||
int s = jas_image_width(jimage);
|
||||
@ -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);
|
||||
|
@ -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:
|
||||
|
||||
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user