diff --git a/src/osg/PagedLOD.cpp b/src/osg/PagedLOD.cpp index 18c724647..73d097074 100644 --- a/src/osg/PagedLOD.cpp +++ b/src/osg/PagedLOD.cpp @@ -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 +*/ } } diff --git a/src/osgDB/Input.cpp b/src/osgDB/Input.cpp index 7021226c6..be0594b71 100644 --- a/src/osgDB/Input.cpp +++ b/src/osgDB/Input.cpp @@ -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); } diff --git a/src/osgPlugins/jp2/ReaderWriterJP2.cpp b/src/osgPlugins/jp2/ReaderWriterJP2.cpp index 31f2a0704..d40e7499d 100644 --- a/src/osgPlugins/jp2/ReaderWriterJP2.cpp +++ b/src/osgPlugins/jp2/ReaderWriterJP2.cpp @@ -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(&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(&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); diff --git a/src/osgPlugins/osga/ReaderWriterOSGA.cpp b/src/osgPlugins/osga/ReaderWriterOSGA.cpp index a9b928519..8859777b2 100644 --- a/src/osgPlugins/osga/ReaderWriterOSGA.cpp +++ b/src/osgPlugins/osga/ReaderWriterOSGA.cpp @@ -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 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: diff --git a/src/osgTerrain/DataSet.cpp b/src/osgTerrain/DataSet.cpp index 5e1cdcb71..5483abad4 100644 --- a/src/osgTerrain/DataSet.cpp +++ b/src/osgTerrain/DataSet.cpp @@ -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())