root/OpenSceneGraph/trunk/examples/osgphotoalbum/PhotoArchive.h @ 6941

Revision 6941, 3.2 kB (checked in by robert, 7 years ago)

From Martin Lavery and Robert Osfield, Updated examples to use a variation of the MIT License

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*-
2*
3*  OpenSceneGraph example, osgphotoalbum.
4*
5*  Permission is hereby granted, free of charge, to any person obtaining a copy
6*  of this software and associated documentation files (the "Software"), to deal
7*  in the Software without restriction, including without limitation the rights
8*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9*  copies of the Software, and to permit persons to whom the Software is
10*  furnished to do so, subject to the following conditions:
11*
12*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13*  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14*  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15*  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16*  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18*  THE SOFTWARE.
19*/
20
21#ifndef PHOTOARCHIVE_H
22#define PHOTOARCHIVE_H
23
24#include <osg/Image>
25
26class PhotoArchive : public osg::Referenced
27{
28public:
29
30    static PhotoArchive* open(const std::string& filename)
31    {
32        osg::ref_ptr<PhotoArchive> archive = new PhotoArchive(filename);
33        if (!archive->empty()) return archive.release();
34        else return 0;
35    }
36
37    typedef std::vector<std::string> FileNameList;
38   
39    bool empty() { return _photoIndex.empty(); }
40
41    void getImageFileNameList(FileNameList& filenameList);
42   
43    static void buildArchive(const std::string& filename, const FileNameList& imageList, unsigned int thumbnailSize=256, unsigned int maximumSize=1024, bool compressed=true);
44
45    osg::Image* readImage(const std::string& filename,
46                          unsigned int target_s, unsigned target_t,
47                          float& original_s, float& original_t);
48                         
49   
50   
51protected:
52
53    PhotoArchive(const std::string& filename);
54
55    virtual ~PhotoArchive() {}
56
57    bool readPhotoIndex(const std::string& filename);
58   
59    struct PhotoHeader
60    {
61        PhotoHeader():
62            original_s(0),
63            original_t(0),
64            thumbnail_s(0),
65            thumbnail_t(0),
66            thumbnail_position(0),
67            fullsize_s(0),
68            fullsize_t(0),
69            fullsize_position(0)
70        {
71            filename[0]='\0';
72        }
73   
74        char filename[256];
75        unsigned int original_s;
76        unsigned int original_t;
77
78        unsigned int thumbnail_s;
79        unsigned int thumbnail_t;
80        unsigned int thumbnail_position;
81
82        unsigned int fullsize_s;
83        unsigned int fullsize_t;
84        unsigned int fullsize_position;
85    };
86
87   
88    struct ImageHeader
89    {
90        ImageHeader():
91            s(0),
92            t(0),
93            internalTextureformat(0),
94            pixelFormat(0),
95            type(0),
96            size(0) {}
97   
98        unsigned int s;
99        unsigned int t;
100        GLint internalTextureformat;
101        GLenum pixelFormat;
102        GLenum type;
103        unsigned int size;
104    };
105
106
107    typedef std::vector<PhotoHeader> PhotoIndexList;
108
109    std::string     _archiveFileName;
110    PhotoIndexList  _photoIndex;   
111
112};
113
114#endif
Note: See TracBrowser for help on using the browser.