svn-gvsig-desktop / tags / v1_0_1_RELEASE / libraries / libjni-ecwcompress / include / NCSJPCIOStream.h @ 43874
History | View | Annotate | Download (14.5 KB)
1 |
/********************************************************
|
---|---|
2 |
** Copyright 2002 Earth Resource Mapping Pty Ltd.
|
3 |
** This document contains unpublished source code of
|
4 |
** Earth Resource Mapping Pty Ltd. This notice does
|
5 |
** not indicate any intention to publish the source
|
6 |
** code contained herein.
|
7 |
**
|
8 |
** FILE: $Archive: /NCS/Source/include/NCSJPCIOStream.h $
|
9 |
** CREATED: 28/11/2002 3:27:34 PM
|
10 |
** AUTHOR: Simon Cope
|
11 |
** PURPOSE: CNCSJPCIOStream class header
|
12 |
** EDITS: [xx] ddMmmyy NAME COMMENTS
|
13 |
*******************************************************/
|
14 |
|
15 |
#ifndef NCSJPCIOSTREAM_H
|
16 |
#define NCSJPCIOSTREAM_H
|
17 |
|
18 |
#ifndef NCSJPCTYPES_H
|
19 |
#include "NCSJPCTypes.h" |
20 |
#endif // !NCSJPCTYPES_H |
21 |
|
22 |
// NCS 64bit FileIO routines
|
23 |
#ifndef NCSFILEIO_H
|
24 |
#include "NCSFileIO.h" |
25 |
#endif // !NCSFILEIO_H |
26 |
|
27 |
// UNICODE support
|
28 |
#ifdef WIN32
|
29 |
#include "TCHAR.h" |
30 |
#endif
|
31 |
|
32 |
// Various NCS Headers
|
33 |
#include "NCSDefs.h" |
34 |
#include "NCSError.h" |
35 |
//#include "NCSUtil.h"
|
36 |
|
37 |
// STD vector template
|
38 |
#include <vector> |
39 |
|
40 |
/**
|
41 |
* Some time-saving CHECKIO Macros.
|
42 |
* Ideally we'd use exceptions instead, but they aren't portable to all compilers/platforms,
|
43 |
* so revert to a low-tech solution.
|
44 |
*
|
45 |
* @param Error Reference to error to construct from
|
46 |
*/
|
47 |
#define NCSJP2_CHECKIO_BEGIN(e, s) while(e == NCS_SUCCESS) { \ |
48 |
CNCSError *pErrorNCSJP2_CHECKIO = &e;\ |
49 |
CNCSJPCIOStream *pStreamNCSJP2_CHECKIO = &s |
50 |
#define NCSJP2_CHECKIO(a) if(pStreamNCSJP2_CHECKIO->a == false) { *pErrorNCSJP2_CHECKIO = *pStreamNCSJP2_CHECKIO; break; } |
51 |
#define NCSJP2_CHECKIO_ERROR(a) *pErrorNCSJP2_CHECKIO = a; if(*pErrorNCSJP2_CHECKIO != NCS_SUCCESS) break |
52 |
#define NCSJP2_CHECKIO_END() break; } |
53 |
|
54 |
/**
|
55 |
* CNCSJPCIOStream class - 64bit IO "Stream" class.
|
56 |
* This class is the IO mechanism used to access JP2 files.
|
57 |
* << and >> Operators are not implemented as we can't use exception handling for portability reasons.
|
58 |
*
|
59 |
* @author Simon Cope
|
60 |
* @version $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $
|
61 |
*/
|
62 |
class NCSJPC_EXPORT_ALL CNCSJPCIOStream: public CNCSError { |
63 |
public:
|
64 |
/** Anonymous enum for Seek() origin. */
|
65 |
typedef enum { |
66 |
/** Origin is start of file */
|
67 |
START = NCS_FILE_SEEK_START, |
68 |
/** Origin is from current position in file */
|
69 |
CURRENT = NCS_FILE_SEEK_CURRENT, |
70 |
/** Origin is from the end of the file */
|
71 |
END = NCS_FILE_SEEK_END |
72 |
} Origin; |
73 |
|
74 |
/** Default constructor, initialises members */
|
75 |
CNCSJPCIOStream(); |
76 |
/** Virtual destructor, releases members */
|
77 |
virtual ~CNCSJPCIOStream(); |
78 |
|
79 |
/**
|
80 |
* Get the current CNCSError.
|
81 |
* @return CNCSError CNCSError object representing current error status of the Stream.
|
82 |
*/
|
83 |
virtual CNCSError GetError() { return((CNCSError)*this); };
|
84 |
#ifdef _WCHAR_T_DEFINED
|
85 |
/**
|
86 |
* Get the current filename for the stream.
|
87 |
* @return _TCHAR * const pointer to filename for the stream if available, else NULL.
|
88 |
*/
|
89 |
virtual const wchar_t *GetName() {
|
90 |
return((const wchar_t*)m_pName); |
91 |
}; |
92 |
/**
|
93 |
* Open the stream on the specified file.
|
94 |
* @param pName Full Name of JP2 stream being parsed
|
95 |
* @param bWrite Open for writing flag.
|
96 |
* @return CNCSError NCS_SUCCESS, or error code on failure.
|
97 |
*/
|
98 |
virtual CNCSError Open(wchar_t *pName, bool bWrite = false); |
99 |
#else
|
100 |
/**
|
101 |
* Get the current filename for the stream.
|
102 |
* @return _TCHAR * const pointer to filename for the stream if available, else NULL.
|
103 |
*/
|
104 |
virtual const char *GetName() { return(m_pName); }; |
105 |
#endif
|
106 |
/**
|
107 |
* Open the stream on the specified file.
|
108 |
* @param pName Full Name of JP2 stream being parsed
|
109 |
* @param bWrite Open for writing flag.
|
110 |
* @return CNCSError NCS_SUCCESS, or error code on failure.
|
111 |
*/
|
112 |
virtual CNCSError Open(char *pName, bool bWrite = false); |
113 |
/**
|
114 |
* Close the stream.
|
115 |
* @return CNCSError NCS_SUCCESS, or error code on failure.
|
116 |
*/
|
117 |
virtual CNCSError Close(); |
118 |
|
119 |
/**
|
120 |
* Seek on the file to the specified location.
|
121 |
* @param offset Signed 64bit offset to seek by
|
122 |
* @param origin Origin to calculate new position from.
|
123 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
124 |
*/
|
125 |
virtual bool NCS_FASTCALL Seek(INT64 offset, Origin origin = CURRENT);
|
126 |
/**
|
127 |
* Is stream seekable.
|
128 |
* @return bool true if seekable, or false if not.
|
129 |
*/
|
130 |
virtual bool NCS_FASTCALL Seek();
|
131 |
/**
|
132 |
* Get the current file pointer position.
|
133 |
* @return INT64 Current file pointer position, or -1 on error.
|
134 |
*/
|
135 |
virtual INT64 NCS_FASTCALL Tell(); |
136 |
/**
|
137 |
* Get the total current size of the file, in bytes.
|
138 |
* @return INT64 Size of the file, or -1 on error.
|
139 |
*/
|
140 |
virtual INT64 NCS_FASTCALL Size(); |
141 |
|
142 |
/**
|
143 |
* Mark the current position in the file, so we can rewind it if required.
|
144 |
* Note: maintains a stack of marked positions.
|
145 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
146 |
*/
|
147 |
virtual bool NCS_FASTCALL Mark();
|
148 |
/**
|
149 |
* Rewind the file to the previously marked position.
|
150 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
151 |
*/
|
152 |
virtual bool NCS_FASTCALL Rewind();
|
153 |
/**
|
154 |
* UnMark the previously marked file position.
|
155 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
156 |
*/
|
157 |
virtual bool NCS_FASTCALL UnMark();
|
158 |
|
159 |
/** Is file open for writing
|
160 |
* @return bool true is file os open for writing, otherwise false
|
161 |
*/
|
162 |
virtual bool NCS_FASTCALL IsWrite();
|
163 |
|
164 |
/** Is the stream a packet stream? This means the SOD segment will be missing from
|
165 |
* the stream as parsed, and must be requested separately (ie, ECWP, JPIP)
|
166 |
* @return bool true this is a packet stream, otherwise false
|
167 |
*/
|
168 |
virtual bool NCS_FASTCALL IsPacketStream() { return(false); } |
169 |
|
170 |
/** Packet stream subclasses overload this to process received packets on a
|
171 |
* regular basis
|
172 |
*/
|
173 |
virtual void ProcessReceivedPackets() {};
|
174 |
/**
|
175 |
* Read some data from the stream into the supplied buffer.
|
176 |
* @param buffer Buffer to read the data into
|
177 |
* @param count How many bytes of data to read.
|
178 |
* @param pRead How many bytes of data were actually read.
|
179 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
180 |
*/
|
181 |
virtual bool NCS_FASTCALL Read(void* buffer, UINT32 count); |
182 |
/**
|
183 |
* Write some data to the stream.
|
184 |
* @param buffer Buffer of data to write to the stream
|
185 |
* @param count How many bytes of data to write to the stream.
|
186 |
* @param pWrote How many bytes of data were actually written to the stream.
|
187 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
188 |
*/
|
189 |
virtual bool NCS_FASTCALL Write(void* buffer, UINT32 count); |
190 |
|
191 |
/**
|
192 |
* Read a UINT8 from the stream.
|
193 |
* @param buffer Buffer to receive the data
|
194 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
195 |
*/
|
196 |
virtual NCS_INLINE bool NCS_FASTCALL ReadUINT8(UINT8 &Buffer) {
|
197 |
return(Read(&Buffer, sizeof(Buffer))); |
198 |
}; |
199 |
/**
|
200 |
* Read a UINT16 from the stream.
|
201 |
* @param buffer Buffer to receive the data
|
202 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
203 |
*/
|
204 |
virtual bool NCS_FASTCALL ReadUINT16(UINT16 &Buffer);
|
205 |
/**
|
206 |
* Read a UINT32 from the stream, byteswapped if necessary.
|
207 |
* @param buffer Buffer to receive the data
|
208 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
209 |
*/
|
210 |
virtual bool NCS_FASTCALL ReadUINT32(UINT32 &Buffer);
|
211 |
/**
|
212 |
* Read a UINT64 from the stream, byteswapped if necessary.
|
213 |
* @param buffer Buffer to receive the data
|
214 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
215 |
*/
|
216 |
virtual bool NCS_FASTCALL ReadUINT64(UINT64 &Buffer);
|
217 |
/**
|
218 |
* Read a INT8 from the stream.
|
219 |
* @param buffer Buffer to receive the data
|
220 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
221 |
*/
|
222 |
virtual NCS_INLINE bool NCS_FASTCALL ReadINT8(INT8 &Buffer) {
|
223 |
return(Read(&Buffer, sizeof(Buffer))); |
224 |
}; |
225 |
/**
|
226 |
* Read a INT16 from the stream.
|
227 |
* @param buffer Buffer to receive the data
|
228 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
229 |
*/
|
230 |
virtual bool NCS_FASTCALL ReadINT16(INT16 &Buffer);
|
231 |
/**
|
232 |
* Read a INT32 from the stream, byteswapped if necessary.
|
233 |
* @param buffer Buffer to receive the data
|
234 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
235 |
*/
|
236 |
virtual bool NCS_FASTCALL ReadINT32(INT32 &Buffer);
|
237 |
/**
|
238 |
* Read a INT64 from the stream, byteswapped if necessary.
|
239 |
* @param buffer Buffer to receive the data
|
240 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
241 |
*/
|
242 |
virtual bool NCS_FASTCALL ReadINT64(INT64 &Buffer);
|
243 |
/**
|
244 |
* Read a IEEE4 float from the stream, byteswapped if necessary.
|
245 |
* @param buffer Buffer to receive the data
|
246 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
247 |
*/
|
248 |
virtual bool NCS_FASTCALL ReadIEEE4(IEEE4 &Buffer);
|
249 |
/**
|
250 |
* Read a IEEE8 double from the stream, byteswapped if necessary.
|
251 |
* @param buffer Buffer to receive the data
|
252 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
253 |
*/
|
254 |
virtual bool NCS_FASTCALL ReadIEEE8(IEEE8 &Buffer);
|
255 |
/**
|
256 |
* Write a UINT8 to the stream.
|
257 |
* @param buffer Buffer to write to the stream
|
258 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
259 |
*/
|
260 |
virtual bool NCS_FASTCALL WriteUINT8(UINT8 nValue);
|
261 |
/**
|
262 |
* Write a UINT16 to the stream, byteswapped if necessary.
|
263 |
* @param buffer Buffer to write to the stream
|
264 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
265 |
*/
|
266 |
virtual bool NCS_FASTCALL WriteUINT16(UINT16 nValue);
|
267 |
/**
|
268 |
* Write a UINT32 to the stream, byteswapped if necessary.
|
269 |
* @param buffer Buffer to write to the stream
|
270 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
271 |
*/
|
272 |
virtual bool NCS_FASTCALL WriteUINT32(UINT32 nValue);
|
273 |
/**
|
274 |
* Write a UINT64 to the stream, byteswapped if necessary.
|
275 |
* @param buffer Buffer to write to the stream
|
276 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
277 |
*/
|
278 |
virtual bool NCS_FASTCALL WriteUINT64(UINT64 nValue);
|
279 |
/**
|
280 |
* Write a INT8 to the stream.
|
281 |
* @param buffer Buffer to write to the stream
|
282 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
283 |
*/
|
284 |
virtual bool NCS_FASTCALL WriteINT8(INT8 nValue);
|
285 |
/**
|
286 |
* Write a INT16 to the stream, byteswapped if necessary.
|
287 |
* @param buffer Buffer to write to the stream
|
288 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
289 |
*/
|
290 |
virtual bool NCS_FASTCALL WriteINT16(INT16 nValue);
|
291 |
/**
|
292 |
* Write a INT32 to the stream, byteswapped if necessary.
|
293 |
* @param buffer Buffer to write to the stream
|
294 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
295 |
*/
|
296 |
virtual bool NCS_FASTCALL WriteINT32(INT32 nValue);
|
297 |
/**
|
298 |
* Write a INT64 to the stream, byteswapped if necessary.
|
299 |
* @param buffer Buffer to write to the stream
|
300 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
301 |
*/
|
302 |
virtual bool NCS_FASTCALL WriteINT64(INT64 nValue);
|
303 |
/**
|
304 |
* Write a IEEE4 float to the stream, byteswapped if necessary.
|
305 |
* @param buffer Buffer to write to the stream
|
306 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
307 |
*/
|
308 |
virtual bool NCS_FASTCALL WriteIEEE4(IEEE4 fValue);
|
309 |
/**
|
310 |
* Write a IEEE8 double to the stream, byteswapped if necessary.
|
311 |
* @param buffer Buffer to write to the stream
|
312 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
313 |
*/
|
314 |
virtual bool NCS_FASTCALL WriteIEEE8(IEEE8 dValue);
|
315 |
|
316 |
/**
|
317 |
* Reset values for bit (Un)stuffing.
|
318 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
319 |
*/
|
320 |
virtual bool NCS_FASTCALL ResetBitStuff();
|
321 |
/**
|
322 |
* Flush values for bit (Un)stuffing.
|
323 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
324 |
*/
|
325 |
virtual bool NCS_FASTCALL FlushBitStuff();
|
326 |
/**
|
327 |
* Stuff a bit to the JPC bitdata stream.
|
328 |
* @param bool Buffer to write bit value to stream from.
|
329 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
330 |
*/
|
331 |
virtual bool NCS_FASTCALL Stuff(bool bBit); |
332 |
/**
|
333 |
* UnStuff a bit from the JPC bitdata stream.
|
334 |
* @param bool Buffer to read bit from stream to.
|
335 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
336 |
*/
|
337 |
virtual bool NCS_FASTCALL UnStuff(bool &bBit); |
338 |
/**
|
339 |
* Read a packed LengthType from the stream.
|
340 |
* @param nLength Read length in bytes
|
341 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
342 |
*/
|
343 |
virtual NCS_INLINE bool NCS_FASTCALL ReadLengthType(UINT32 &nLength) {
|
344 |
UINT32 nTmp = 0;
|
345 |
bool bRet = false; |
346 |
UINT8 t8; |
347 |
|
348 |
while(bRet = ReadUINT8(t8)) {
|
349 |
nTmp = (nTmp << 7) | (t8 & 0x7f); |
350 |
if((t8 & 0x80) == 0) { |
351 |
break;
|
352 |
} |
353 |
} |
354 |
nLength = nTmp; |
355 |
return(bRet);
|
356 |
}; |
357 |
/**
|
358 |
* Write a packed LengthType to the stream.
|
359 |
* @param nLength Length to write to stream
|
360 |
* @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
361 |
*/
|
362 |
virtual bool NCS_FASTCALL WriteLengthType(UINT32 nLength);
|
363 |
protected:
|
364 |
/** name stream is open on */
|
365 |
#ifdef _WCHAR_T_DEFINED
|
366 |
wchar_t *m_pName; |
367 |
#else
|
368 |
char *m_pName;
|
369 |
#endif
|
370 |
/** Stream is open for writing */
|
371 |
bool m_bWrite;
|
372 |
/** Stack of marks in the stream */
|
373 |
std::vector<INT64> m_Marks; |
374 |
/** File pointer */
|
375 |
INT64 m_nOffset; |
376 |
|
377 |
/** Current byte(s) when bit stuffing/unstuffing */
|
378 |
UINT16 m_nThisBytes; |
379 |
/** # of bits left */
|
380 |
UINT8 m_nBitsLeft; |
381 |
}; |
382 |
|
383 |
typedef std::vector<CNCSJPCIOStream *> CNCSJPCIOStreamVector;
|
384 |
|
385 |
#endif // !NCSJPCIOSTREAM_H |