svn-gvsig-desktop / trunk / libraries / libjni-readecw-linux / include / NCSJPCPacketLengthType.h @ 1458
History | View | Annotate | Download (3.03 KB)
1 |
/********************************************************
|
---|---|
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/NCSJPCPacketLengthType.h $
|
15 |
** CREATED: 18/12/2002 3:27:34 PM
|
16 |
** AUTHOR: Simon Cope
|
17 |
** PURPOSE: CNCSJPCPacketLengthType class header
|
18 |
** EDITS: [xx] ddMmmyy NAME COMMENTS
|
19 |
*******************************************************/
|
20 |
|
21 |
#ifndef NCSJPCPACKETLENGTHTYPE_H
|
22 |
#define NCSJPCPACKETLENGTHTYPE_H
|
23 |
|
24 |
#include "NCSJPCMarker.h" |
25 |
|
26 |
/**
|
27 |
* CNCSJPCPacketLengthType class - the JPC Packet Length Type.
|
28 |
*
|
29 |
* @author Simon Cope
|
30 |
* @version $Revision: 1458 $ $Author: igbrotru $ $Date: 2005-02-15 08:52:16 +0100 (Tue, 15 Feb 2005) $
|
31 |
*/
|
32 |
class NCSJPC_EXPORT_ALL CNCSJPCPacketLengthType { |
33 |
public:
|
34 |
/** Packet length - Header usually includes Data, except when using PPM or PPT markers */
|
35 |
UINT32 m_nHeaderLength; |
36 |
/** Packet data length - Only when using PPM or PPT markers */
|
37 |
UINT32 m_nDataLength; |
38 |
|
39 |
/** Default constructor, initialises members */
|
40 |
CNCSJPCPacketLengthType(); |
41 |
|
42 |
/**
|
43 |
* Parse the fields from the JPC codestream.
|
44 |
* @param Stream IOStream to use to parse file.
|
45 |
* @return bool true on success.
|
46 |
*/
|
47 |
NCS_INLINE bool Parse(CNCSJPCIOStream &Stream) {
|
48 |
UINT32 nTmp = 0;
|
49 |
bool bRet = false; |
50 |
UINT8 t8; |
51 |
|
52 |
while(bRet = Stream.ReadUINT8(t8)) {
|
53 |
nTmp = (nTmp << 7) | (t8 & 0x7f); |
54 |
if((t8 & 0x80) == 0) { |
55 |
break;
|
56 |
} |
57 |
} |
58 |
m_nHeaderLength = nTmp; |
59 |
return(bRet);
|
60 |
}; |
61 |
/**
|
62 |
* Parse the fields from a chunk of memory.
|
63 |
* @param UINT8* Memory buffer to parse length from.
|
64 |
* @param &i Index into memory buffer, incremented before return
|
65 |
* @return bool true on success.
|
66 |
*/
|
67 |
NCS_INLINE bool Parse(UINT8 *pBuf, INT32 &i) {
|
68 |
UINT32 nTmp = 0;
|
69 |
|
70 |
while(true) { |
71 |
UINT8 t8 = pBuf[i++]; |
72 |
nTmp = (nTmp << 7) | (t8 & 0x7f); |
73 |
if((t8 & 0x80) == 0) { |
74 |
break;
|
75 |
} |
76 |
} |
77 |
m_nHeaderLength = nTmp; |
78 |
return(true); |
79 |
}; |
80 |
/**
|
81 |
* UnParse the fields to the JPC codestream.
|
82 |
* @param Stream IOStream to use to parse file.
|
83 |
* @return bool true on success.
|
84 |
*/
|
85 |
NCS_INLINE bool UnParse(CNCSJPCIOStream &Stream) {
|
86 |
UINT32 nMask = 0xffffffff;
|
87 |
INT8 nShift = 0;
|
88 |
bool bRet = true; |
89 |
|
90 |
while(nMask & m_nHeaderLength) {
|
91 |
nMask <<= 7;
|
92 |
nShift++; |
93 |
} |
94 |
if(nShift > 0) { |
95 |
nShift--; |
96 |
nMask >>= 7;
|
97 |
nMask = 0x7f << (nShift * 7); |
98 |
while(nShift >= 0 && bRet) { |
99 |
bRet &= Stream.WriteUINT8((UINT8)(((m_nHeaderLength & nMask) >> (nShift * 7)) | ((nShift > 0) ? 0x80 : 0x00))); |
100 |
nShift--; |
101 |
nMask >>= 7;
|
102 |
} |
103 |
} else {
|
104 |
// Zero length
|
105 |
bRet &= Stream.WriteUINT8((UINT8)0x00);
|
106 |
} |
107 |
return(bRet);
|
108 |
|
109 |
}; |
110 |
}; |
111 |
|
112 |
|
113 |
#endif // !NCSJPCPACKETLENGTHTYPE_H |