root/OpenSceneGraph/trunk/src/osgWrappers/deprecated-dotosg/osg/ImageSequence.cpp @ 13041

Revision 13041, 3.8 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1#include "osg/ImageSequence"
2
3#include "osgDB/Registry"
4#include "osgDB/Input"
5#include "osgDB/Output"
6
7using namespace osg;
8using namespace osgDB;
9
10// forward declare functions to use later.
11bool ImageSequence_readLocalData(Object& obj, Input& fr);
12bool ImageSequence_writeLocalData(const Object& obj, Output& fw);
13
14// register the read and write functions with the osgDB::Registry.
15REGISTER_DOTOSGWRAPPER(ImageSequence)
16(
17    new osg::ImageSequence,
18    "ImageSequence",
19    "Object ImageSequence",
20    &ImageSequence_readLocalData,
21    &ImageSequence_writeLocalData
22);
23
24bool ImageSequence_readLocalData(Object& obj, Input& fr)
25{
26    bool iteratorAdvanced = false;
27
28    ImageSequence& is = static_cast<ImageSequence&>(obj);
29
30    std::string modeStr;
31    if (fr.read("Mode",modeStr))
32    {
33        if (modeStr=="PRE_LOAD_ALL_IMAGES")
34        {
35            is.setMode(osg::ImageSequence::PRE_LOAD_ALL_IMAGES);
36        }
37        else if (modeStr=="PAGE_AND_RETAIN_IMAGES")
38        {
39            is.setMode(osg::ImageSequence::PAGE_AND_RETAIN_IMAGES);
40        }
41        else if (modeStr=="PAGE_AND_DISCARD_USED_IMAGES")
42        {
43            is.setMode(osg::ImageSequence::PAGE_AND_DISCARD_USED_IMAGES);
44        }
45    }
46
47    double length;
48    if (fr.read("Duration", length) || fr.read("Length", length) )
49    {
50        is.setLength(length);
51    }
52
53    if (fr.matchSequence("FileNames {"))
54    {
55        fr += 2;
56        iteratorAdvanced = true;
57        int entry = fr[0].getNoNestedBrackets();
58        while (!fr.eof() && fr[0].getNoNestedBrackets() >= entry)
59        {
60            if (fr[0].getStr())
61            {
62                is.addImageFile(fr[0].getStr());
63            }
64            ++fr;
65        }
66    }
67
68    if (fr.matchSequence("Images {"))
69    {
70        fr += 2;
71        iteratorAdvanced = true;
72        int entry = fr[0].getNoNestedBrackets();
73        while (!fr.eof() && fr[0].getNoNestedBrackets() >= entry)
74        {
75            if (fr[0].getStr())
76            {
77                osg::ref_ptr<osg::Image> image = fr.readImage(fr[0].getStr());
78                if (image.valid()) is.addImage(image.get());
79            }
80            ++fr;
81        }
82    }
83
84    return iteratorAdvanced;
85}
86
87
88bool ImageSequence_writeLocalData(const Object& obj, Output& fw)
89{
90    const ImageSequence& is = static_cast<const ImageSequence&>(obj);
91
92    // no current image writing code here
93    // as it is all handled by osg::Registry::writeImage() via plugins.
94
95    switch(is.getMode())
96    {
97        case(osg::ImageSequence::PRE_LOAD_ALL_IMAGES):
98            fw.indent()<<"Mode PRE_LOAD_ALL_IMAGES"<<std::endl;
99            break;
100        case(osg::ImageSequence::PAGE_AND_RETAIN_IMAGES):
101            fw.indent()<<"Mode PAGE_AND_RETAIN_IMAGES"<<std::endl;
102            break;
103        case(osg::ImageSequence::PAGE_AND_DISCARD_USED_IMAGES):
104            fw.indent()<<"Mode PAGE_AND_DISCARD_USED_IMAGES"<<std::endl;
105            break;
106    }
107
108    fw.indent()<<"Length "<<is.getLength()<<std::endl;
109
110    if (!is.getFileNames().empty())
111    {
112        fw.indent()<<"FileNames {"<<std::endl;
113        fw.moveIn();
114
115        const osg::ImageSequence::FileNames& names = is.getFileNames();
116        for(osg::ImageSequence::FileNames::const_iterator itr = names.begin();
117            itr != names.end();
118            ++itr)
119        {
120            fw.indent()<<fw.wrapString(*itr)<<std::endl;
121        }
122
123        fw.moveOut();
124        fw.indent()<<"}"<<std::endl;
125    }
126    else
127    {
128        fw.indent()<<"Images {"<<std::endl;
129        fw.moveIn();
130
131        const osg::ImageSequence::Images& images = is.getImages();
132        for(osg::ImageSequence::Images::const_iterator itr = images.begin();
133            itr != images.end();
134            ++itr)
135        {
136            if (!(*itr)->getFileName().empty()) fw.indent()<<fw.wrapString((*itr)->getFileName())<<std::endl;
137        }
138
139        fw.moveOut();
140        fw.indent()<<"}"<<std::endl;
141    }
142
143    return true;
144}
Note: See TracBrowser for help on using the browser.