| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | #ifndef PHOTOARCHIVE_H |
|---|
| 22 | #define PHOTOARCHIVE_H |
|---|
| 23 | |
|---|
| 24 | #include <osg/Image> |
|---|
| 25 | |
|---|
| 26 | class PhotoArchive : public osg::Referenced |
|---|
| 27 | { |
|---|
| 28 | public: |
|---|
| 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 | |
|---|
| 51 | protected: |
|---|
| 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 |
|---|