svn-gvsig-desktop / tags / v1_9_Build_1250 / libraries / libjni-ecwcompress / include / include-sdk / NCSHuffmanCoder.h @ 44644
History | View | Annotate | Download (3.88 KB)
1 | 3538 | nacho | /**********************************************************
|
---|---|---|---|
2 | ** Copyright 1998 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: NCSHuffmanCoder.h
|
||
15 | ** CREATED: 30 Jun 2004
|
||
16 | ** AUTHOR: Simon Cope
|
||
17 | ** PURPOSE: CNCSHuffmanCoder class header
|
||
18 | ** EDITS:
|
||
19 | *******************************************************/
|
||
20 | |||
21 | #ifndef NCSHUFFMANCODER_H
|
||
22 | #define NCSHUFFMANCODER_H
|
||
23 | |||
24 | #ifdef _MSC_VER
|
||
25 | #pragma warning( disable : 4786 ) |
||
26 | #endif
|
||
27 | |||
28 | #include "NCSTypes.h" |
||
29 | |||
30 | #ifdef __cplusplus
|
||
31 | |||
32 | #include <map> |
||
33 | |||
34 | extern "C" { |
||
35 | #endif // __cplusplus |
||
36 | |||
37 | typedef struct _NCSHuffmanSymbol { |
||
38 | UINT16 nValue; |
||
39 | BOOLEAN bZeroRun; |
||
40 | } NCSHuffmanSymbol; |
||
41 | |||
42 | #ifdef __cplusplus
|
||
43 | |||
44 | #include "NCSError.h" |
||
45 | |||
46 | /**
|
||
47 | * CNCSHuffmanCoder class - ECW Huffman Coder/Decoder.
|
||
48 | *
|
||
49 | * @author Simon Cope
|
||
50 | * @version $Revision$ $Author$ $Date$
|
||
51 | */
|
||
52 | class CNCSHuffmanCoder { |
||
53 | public:
|
||
54 | const static UINT32 NUM_SYMBOL_VALUES; |
||
55 | const static UINT16 SIGN_MASK; |
||
56 | const static UINT16 RUN_MASK; |
||
57 | const static INT16 MAX_BIN_VALUE; |
||
58 | const static INT16 MIN_BIN_VALUE; |
||
59 | const static UINT16 VALUE_MASK; |
||
60 | const static UINT16 MAX_RUN_LENGTH; |
||
61 | const static UINT8 SMALL_SYMBOL; |
||
62 | const static UINT8 SMALL_SHIFT; |
||
63 | |||
64 | /*
|
||
65 | ** Huffman structures and definitions
|
||
66 | */
|
||
67 | class CTree; |
||
68 | |||
69 | class CCodeNode { |
||
70 | public:
|
||
71 | typedef struct { |
||
72 | class CCodeNode *m_p0Child; |
||
73 | class CCodeNode *m_p1Child; |
||
74 | } A; |
||
75 | typedef union { |
||
76 | A m_P; |
||
77 | class CCodeNode *m_Children[2];
|
||
78 | } U; |
||
79 | U m_Children; |
||
80 | |||
81 | NCSHuffmanSymbol m_Symbol; |
||
82 | UINT32 m_nFrequency; |
||
83 | class CCodeNode *m_pNext; |
||
84 | UINT32 m_nCode; |
||
85 | UINT8 m_nCodeBits; |
||
86 | bool m_bInHistogram;
|
||
87 | |||
88 | CCodeNode(); |
||
89 | CCodeNode(UINT8 **ppPacked, UINT32 &nNodes); |
||
90 | virtual ~CCodeNode(); |
||
91 | |||
92 | void Pack(UINT8 **ppPacked, UINT32 &nNodes);
|
||
93 | CCodeNode *Unpack(UINT8 **ppPacked, UINT32 &nNodes); |
||
94 | void SetCode(UINT32 nCode, UINT8 nCodeBits);
|
||
95 | }; |
||
96 | class CTree: public CCodeNode { |
||
97 | public:
|
||
98 | CCodeNode *m_pRoot; |
||
99 | std::map<INT16, CCodeNode*> m_Histogram; |
||
100 | |||
101 | CTree(); |
||
102 | CTree(UINT8 **ppPacked); |
||
103 | virtual ~CTree(); |
||
104 | |||
105 | CNCSError Pack(UINT8 **ppPacked, INT16 *pUnPacked, UINT32 nSymbols); |
||
106 | CNCSError Unpack(UINT8 **ppPacked); |
||
107 | protected:
|
||
108 | CCodeNode *UnpackNode(UINT8 **ppPacked, UINT32 &nNodes); |
||
109 | }; |
||
110 | |||
111 | /** Default constructor. */
|
||
112 | CNCSHuffmanCoder(); |
||
113 | /** virtual default destructor. */
|
||
114 | virtual ~CNCSHuffmanCoder(); |
||
115 | |||
116 | CNCSError Pack(UINT8 *pPacked, UINT32 *pPackedLength, INT16 *pUnPacked, UINT32 nRawLength); |
||
117 | CNCSError UnPack(UINT8 *pPacked, INT16 *pUnPacked, UINT32 nRawLength); |
||
118 | private:
|
||
119 | CTree *m_pTree; |
||
120 | }; |
||
121 | |||
122 | }; |
||
123 | #endif
|
||
124 | |||
125 | #ifdef __cplusplus
|
||
126 | extern "C" { |
||
127 | #endif
|
||
128 | |||
129 | #define NCS_HUFFMAN_MAX_RUN_LENGTH 0x7fff |
||
130 | #define NCS_HUFFMAN_SIGN_MASK 0x4000 |
||
131 | #define NCS_HUFFMAN_VALUE_MASK 0x3fff |
||
132 | #define NCS_HUFFMAN_RUN_MASK 0x8000 |
||
133 | |||
134 | typedef struct { |
||
135 | void *pTree;
|
||
136 | UINT32 nBitsUsed; |
||
137 | } NCSHuffmanState; |
||
138 | |||
139 | NCSError unpack_huffman(UINT8 *pPacked, INT16 *pUnPacked, UINT32 nRawLength); |
||
140 | void unpack_huffman_init_state(NCSHuffmanState *pState, UINT8 **ppPacked);
|
||
141 | void unpack_huffman_fini_state(NCSHuffmanState *pState);
|
||
142 | NCSHuffmanSymbol *unpack_huffman_symbol(UINT8 **ppPacked, NCSHuffmanState *pState); |
||
143 | static NCS_INLINE BOOLEAN unpack_huffman_symbol_zero_run(NCSHuffmanSymbol *pSymbol) {
|
||
144 | return(pSymbol->bZeroRun);
|
||
145 | } |
||
146 | static NCS_INLINE UINT16 unpack_huffman_symbol_zero_length(NCSHuffmanSymbol *pSymbol) {
|
||
147 | return(pSymbol->nValue);
|
||
148 | }; |
||
149 | static NCS_INLINE INT16 unpack_huffman_symbol_value(NCSHuffmanSymbol *pSymbol) {
|
||
150 | return(pSymbol->nValue);
|
||
151 | }; |
||
152 | |||
153 | UINT32 pack_huffman(UINT8 *pPacked, INT16 *pUnPacked, UINT32 symbol_stream_length); |
||
154 | #ifdef __cplusplus
|
||
155 | }; |
||
156 | #endif
|
||
157 | |||
158 | #endif /* NCSHUFFMANCODER_H */ |