| 1 | #include <osg/ImageSequence> |
|---|
| 2 | #include <osgDB/ObjectWrapper> |
|---|
| 3 | #include <osgDB/InputStream> |
|---|
| 4 | #include <osgDB/OutputStream> |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | static bool checkFileNames( const osg::ImageSequence& image ) |
|---|
| 8 | { |
|---|
| 9 | return image.getNumImageFiles()>0; |
|---|
| 10 | } |
|---|
| 11 | |
|---|
| 12 | static bool readFileNames( osgDB::InputStream& is, osg::ImageSequence& image ) |
|---|
| 13 | { |
|---|
| 14 | unsigned int files = 0; is >> files >> is.BEGIN_BRACKET; |
|---|
| 15 | for ( unsigned int i=0; i<files; ++i ) |
|---|
| 16 | { |
|---|
| 17 | std::string filename; is.readWrappedString( filename ); |
|---|
| 18 | image.addImageFile( filename ); |
|---|
| 19 | } |
|---|
| 20 | is >> is.END_BRACKET; |
|---|
| 21 | return true; |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | static bool writeFileNames( osgDB::OutputStream& os, const osg::ImageSequence& image ) |
|---|
| 25 | { |
|---|
| 26 | const osg::ImageSequence::FileNames& files = image.getFileNames(); |
|---|
| 27 | os.writeSize(files.size()); os << os.BEGIN_BRACKET << std::endl; |
|---|
| 28 | for ( osg::ImageSequence::FileNames::const_iterator itr=files.begin(); |
|---|
| 29 | itr!=files.end(); ++itr ) |
|---|
| 30 | { |
|---|
| 31 | os.writeWrappedString( *itr ); |
|---|
| 32 | os << std::endl; |
|---|
| 33 | } |
|---|
| 34 | os << os.END_BRACKET << std::endl; |
|---|
| 35 | return true; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | static bool checkImages( const osg::ImageSequence& image ) |
|---|
| 40 | { |
|---|
| 41 | return image.getNumImages()>0; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | static bool readImages( osgDB::InputStream& is, osg::ImageSequence& image ) |
|---|
| 45 | { |
|---|
| 46 | unsigned int images = is.readSize(); is >> is.BEGIN_BRACKET; |
|---|
| 47 | for ( unsigned int i=0; i<images; ++i ) |
|---|
| 48 | { |
|---|
| 49 | osg::Image* img = dynamic_cast<osg::Image*>( is.readObject() ); |
|---|
| 50 | if ( img ) image.addImage( img ); |
|---|
| 51 | } |
|---|
| 52 | is >> is.END_BRACKET; |
|---|
| 53 | return true; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | static bool writeImages( osgDB::OutputStream& os, const osg::ImageSequence& image ) |
|---|
| 57 | { |
|---|
| 58 | const osg::ImageSequence::Images& images = image.getImages(); |
|---|
| 59 | os.writeSize(images.size()); os << os.BEGIN_BRACKET << std::endl; |
|---|
| 60 | for ( osg::ImageSequence::Images::const_iterator itr=images.begin(); |
|---|
| 61 | itr!=images.end(); ++itr ) |
|---|
| 62 | { |
|---|
| 63 | os.writeObject( (*itr).get() ); |
|---|
| 64 | } |
|---|
| 65 | os << os.END_BRACKET << std::endl; |
|---|
| 66 | return true; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | REGISTER_OBJECT_WRAPPER( ImageSequence, |
|---|
| 70 | new osg::ImageSequence, |
|---|
| 71 | osg::ImageSequence, |
|---|
| 72 | "osg::Object osg::Image osg::ImageStream osg::ImageSequence" ) |
|---|
| 73 | { |
|---|
| 74 | ADD_DOUBLE_SERIALIZER( ReferenceTime, DBL_MAX ); |
|---|
| 75 | ADD_DOUBLE_SERIALIZER( TimeMultiplier, 1.0 ); |
|---|
| 76 | |
|---|
| 77 | BEGIN_ENUM_SERIALIZER( Mode, PRE_LOAD_ALL_IMAGES ); |
|---|
| 78 | ADD_ENUM_VALUE( PRE_LOAD_ALL_IMAGES ); |
|---|
| 79 | ADD_ENUM_VALUE( PAGE_AND_RETAIN_IMAGES ); |
|---|
| 80 | ADD_ENUM_VALUE( PAGE_AND_DISCARD_USED_IMAGES ); |
|---|
| 81 | END_ENUM_SERIALIZER(); |
|---|
| 82 | |
|---|
| 83 | ADD_DOUBLE_SERIALIZER( Length, 1.0 ); |
|---|
| 84 | ADD_USER_SERIALIZER( FileNames ); |
|---|
| 85 | ADD_USER_SERIALIZER( Images ); |
|---|
| 86 | } |
|---|