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