From 3ca30736b473b922e199fb0c0173ccbaee4b531b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 24 Feb 2012 11:43:35 +0000 Subject: [PATCH] Added support for checking the possible endian reversal the OSG_HEADER_LOW and OSG_HEADER_HIGH when reading binary files written out from systems that have a different endian to the system reading it. --- src/osgPlugins/osg/BinaryStreamOperator.h | 4 ++-- src/osgPlugins/osg/ReaderWriterOSG2.cpp | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/osgPlugins/osg/BinaryStreamOperator.h b/src/osgPlugins/osg/BinaryStreamOperator.h index b8f140141..7cfa1ca09 100644 --- a/src/osgPlugins/osg/BinaryStreamOperator.h +++ b/src/osgPlugins/osg/BinaryStreamOperator.h @@ -73,7 +73,7 @@ public: class BinaryInputIterator : public osgDB::InputIterator { public: - BinaryInputIterator( std::istream* istream ) : _byteSwap(0) { _in = istream; } + BinaryInputIterator( std::istream* istream, bool byteSwap ) : _byteSwap(byteSwap) { _in = istream; } virtual ~BinaryInputIterator() {} virtual bool isBinary() const { return true; } @@ -188,7 +188,7 @@ public: { readString( str ); } protected: - int _byteSwap; + bool _byteSwap; }; #endif diff --git a/src/osgPlugins/osg/ReaderWriterOSG2.cpp b/src/osgPlugins/osg/ReaderWriterOSG2.cpp index 542265e3f..990e31bba 100644 --- a/src/osgPlugins/osg/ReaderWriterOSG2.cpp +++ b/src/osgPlugins/osg/ReaderWriterOSG2.cpp @@ -26,6 +26,8 @@ using namespace osgDB; #define CATCH_EXCEPTION(s) \ if (s.getException()) return (s.getException()->getError() + " At " + s.getException()->getField()); +#define OSG_REVERSE(value) ( ((value & 0x000000ff)<<24) | ((value & 0x0000ff00)<<8) | ((value & 0x00ff0000)>>8) | ((value & 0xff000000)>>24) ) + InputIterator* readInputIterator( std::istream& fin, const Options* options ) { bool extensionIsAscii = false, extensionIsXML = false; @@ -43,8 +45,15 @@ InputIterator* readInputIterator( std::istream& fin, const Options* options ) fin.read( (char*)&headerHigh, INT_SIZE ); if ( headerLow==OSG_HEADER_LOW && headerHigh==OSG_HEADER_HIGH ) { - return new BinaryInputIterator(&fin); + OSG_INFO<<"Reading OpenSceneGraph binary file with the same endian as this computer."<