Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libjni-mrsid / include / mrsid_readers / MrSIDImageReaderBase.h @ 3539

History | View | Annotate | Download (7.8 KB)

1
/* $Id: MrSIDImageReaderBase.h 3539 2006-01-09 12:23:20Z nacho $ */
2
/* //////////////////////////////////////////////////////////////////////////
3
//                                                                         //
4
// This code is Copyright (c) 2004 LizardTech, Inc, 1008 Western Avenue,   //
5
// Suite 200, Seattle, WA 98104.  Unauthorized use or distribution         //
6
// prohibited.  Access to and use of this code is permitted only under     //
7
// license from LizardTech, Inc.  Portions of the code are protected by    //
8
// US and foreign patents and other filings. All Rights Reserved.          //
9
//                                                                         //
10
////////////////////////////////////////////////////////////////////////// */
11
/* PUBLIC */
12

    
13
#ifndef MRSIDIMAGEREADERBASE_H
14
#define MRSIDIMAGEREADERBASE_H
15

    
16
// lt_lib_mrsid_core
17
#include "lti_imageReader.h"
18

    
19

    
20
LT_BEGIN_NAMESPACE(LizardTech)
21

    
22
#if defined(LT_COMPILER_MS)
23
   #pragma warning(push,4)
24
#endif
25

    
26
class LTFileSpec;
27
class LTIOStreamInf;
28
class MrSIDPasswordDelegate;
29
class MrSIDSimplePasswordDelegate;
30

    
31
/*
32
 * memory settings for creating MrSID decoders
33
 *
34
 * "Small", "medium", and "large" refer to how much memory the
35
 * decoder will use when opening the image and constructing certain
36
 * internal data structures and tables.  In general, decode
37
 * performance will increase if more memory can be used.
38
 */
39
enum MrSIDMemoryUsage
40
{
41
   MRSID_MEMORY_USAGE_INVALID    = 0,
42
   MRSID_MEMORY_USAGE_DEFAULT    = 1,
43
   MRSID_MEMORY_USAGE_SMALL      = 2,
44
   MRSID_MEMORY_USAGE_MEDIUM     = 3,
45
   MRSID_MEMORY_USAGE_LARGE      = 4
46
};
47

    
48
/*
49
 * stream settings for creating MrSID decoders
50
 *
51
 * Normally, the stream used by the decoder is
52
 * only opened when doing actual decode work, as resources like
53
 * file handles can be a scarce resource in some environments.  This
54
 * obviously incurs a performance penalty; the "KeepStreamOpen" modes
55
 * can be used to change the behaviour.
56
 */
57
enum MrSIDStreamUsage
58
{
59
   MRSID_STREAM_USAGE_INVALID    = 0,
60
   MRSID_STREAM_USAGE_KEEPOPEN   = 2,
61
   MRSID_STREAM_USAGE_KEEPCLOSED = 3,
62
   MRSID_STREAM_USAGE_DEFAULT    = MRSID_STREAM_USAGE_KEEPCLOSED
63
};
64

    
65

    
66
/**
67
 * base class for MrSID image readers
68
 *
69
 * All the MrSID image readers (MrSIDImageReader, MG3CompositeImageReader, etc)
70
 * inherit from this class.
71
 */
72
class MrSIDImageReaderBase : public LTIImageReader
73
{
74
public:
75
   /**
76
    * constructor
77
    *
78
    * Creates a MrSIDImageReaderBase object.
79
    *
80
    * @param  memoryUsage   the memory model to use
81
    * @param  streamUsage   the stream model to use
82
    * @param  useWorldFile  whether or not a world file is being used
83
    */
84
   MrSIDImageReaderBase(MrSIDMemoryUsage memoryUsage,
85
                        MrSIDStreamUsage streamUsage,
86
                        bool useWorldFile);
87
   virtual ~MrSIDImageReaderBase();
88
   virtual LT_STATUS initialize();
89

    
90
   /**
91
    * get number of resolution levels
92
    *
93
    * Returns the number of resolution levels supported by the image.
94
    * This value returned corresponds to the LTIImage::getMinMagnification()
95
    * function.
96
    *
97
    * @return the number of resolution levels in the MrSID image
98
    */
99
   virtual lt_uint8 getNumLevels() const =0;
100

    
101
   /**
102
    * image encryption query
103
    *
104
    * Returns true iff the image is password-protected.  If the image is
105
    * locked, the setPasswordDelegate() or setPassword() function must be
106
    * used to provide the decoder with information to decrypt the image
107
    * as decode requests are processed.
108
    *
109
    * @return true, if image is password-protected
110
    */
111
   virtual bool isLocked() const =0;
112

    
113
   /**
114
    * get MrSID image version
115
    *
116
    * Returns detailed version information for the MrSID image.  Typical
117
    * version numbers will be 1.0.1 for MG2 (the \a letter value is not
118
    * used) and 3.0.26.q for MG3.  Most developers need only consider the
119
    * \a major number, which will be either 2 or 3..
120
    *
121
    * See also getSidVersion().
122
    *
123
    * @param major  the major version number
124
    * @param minor  the minor version number
125
    * @param tweak  the revision number
126
    * @param letter  the revision build number (MG3 only)
127
    */
128
   virtual void getVersion(lt_uint8& major, lt_uint8& minor, lt_uint8& tweak, char& letter) const=0;
129

    
130
   /**
131
    * set password handler
132
    *
133
    * This function is used to set up a password delegate, which will be
134
    * automatically called form within the internal decoder logic to obtain
135
    * a text password, if one is needed for decoded the image.
136
    *
137
    * Alternatively, the more direct setPassword() function may be used.
138
    *
139
    * See the isLocked() function for more details.
140
    * 
141
    * @param  passwordDelegate  the delegate to be called
142
    */
143
   void setPasswordDelegate(MrSIDPasswordDelegate* passwordDelegate);
144

    
145
   /**
146
    * set password handler
147
    *
148
    * This function is set the password used by the decoder logic
149
    * to decode the image, if one is needed.
150
    *
151
    * The password must be set prior to performing any decode (read)
152
    * requests; for more flexibility, the setPasswordDelegate() function
153
    * may be used.
154
    *
155
    * See the isLocked() function for more details.
156
    * 
157
    * @param  password  the password for the image
158
    */
159
   void setPassword(const lt_utf8* password);
160

    
161
public:
162
   /**
163
    * get MrSID version information
164
    *
165
    * Returns version information for a specific MrSID image.  This is
166
    * a static function, which is passed a filename; the getVersion()
167
    * function operates on the image represented by this MrSIDImageReaderBase
168
    * image and returns more detailed information.
169
    *
170
    * The \a ver value returned will be 2 (for MrSID/MG2), 3 (for MrSID/MG3),
171
    * or 0 (if error).
172
    *
173
    * @param fileSpec  the file to get the version of
174
    * @param ver       the major version number
175
    * @return status code indicating success or failure
176
    */
177
   static LT_STATUS getSidVersion(const LTFileSpec& fileSpec, lt_uint8& ver);
178

    
179
   /**
180
    * MrSID version information
181
    *
182
    * Returns version information for a specific MrSID image.  This is
183
    * a static function, which is passed a stream; the getVersion()
184
    * function operates on the image represented by this MrSIDImageReaderBase
185
    * image and returns more detailed information.
186
    *
187
    * The \a ver value returned will be 2 (for MrSID/MG2), 3 (for MrSID/MG3),
188
    * or 0 (if error).
189
    *
190
    * @param stream  the file to get the version of
191
    * @param ver       the major version number
192
    * @return status code indicating success or failure
193
    */
194
   static LT_STATUS getSidVersion(LTIOStreamInf& stream, lt_uint8& ver);
195

    
196
protected:
197

    
198
   LT_STATUS setupDynamicRangeFromMetadata(bool& gotThem,
199
                                           double& min,
200
                                           double& max);
201

    
202
   static LT_STATUS setupClutFromMetadata(const LTIMetadataDatabase& metadata,
203
                                          LTIPixelLookupTable*& clut);
204

    
205
   static LT_STATUS setupDefaultPixelFromMetadata(LTIMetadataDatabase& metadata,
206
                                                  const LTIPixel& pixelProps,
207
                                                  LTIPixel*& backgroundPixel,
208
                                                  LTIPixel*& nodataPixel);
209

    
210
   LT_STATUS setupGeoInfoFromMetadata(bool &didSet);
211

    
212
   LT_STATUS setupGeoInfoFromWorldFile(const LTFileSpec *file,
213
                                       LTIOStreamInf *stream,
214
                                       bool &didSet);
215
   LT_STATUS updateGeoMetadata();
216

    
217
   MrSIDMemoryUsage m_memoryUsage;
218
   MrSIDStreamUsage m_streamUsage;
219
   bool m_useWorldFile;
220

    
221
private:
222
   typedef LTIImageReader Super;
223

    
224
   MrSIDPasswordDelegate* m_pwdDelegate;
225
   MrSIDSimplePasswordDelegate* m_localPwdDelegate;
226

    
227
   // nope
228
   MrSIDImageReaderBase(const MrSIDImageReaderBase&);
229
   MrSIDImageReaderBase& operator=(const MrSIDImageReaderBase&);
230
};
231

    
232

    
233
LT_END_NAMESPACE(LizardTech)
234

    
235
#if defined(LT_COMPILER_MS)
236
        #pragma warning(pop)
237
#endif
238

    
239
#endif // MRSIDIMAGEREADERBASE_H