1 /*---------------------------------------------------------------------------*
2 Project: Compress/uncompress library
3 File: CXStreamingUncompression.h
4
5 Copyright 2005 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Log: CXStreamingUncompression.h,v $
14 Revision 1.15 2007/05/30 04:19:52 takano_makoto
15 Added CXiInitUncompContextXXFront()
16
17 Revision 1.14 2007/05/18 10:50:39 yasuh-to
18 Rolled back to SYSTEMMENU2_DEV_BRANCH(HEAD)
19
20 Revision 1.11 2006/07/27 07:40:19 takano_makoto
21 Added const modifier to CXIsFinishedUncompXXX parameter.
22
23 Revision 1.10 2006/07/27 04:25:12 takano_makoto
24 Changed Condition of CXIsFinishedUncompXXX()
25
26 Revision 1.9 2006/07/27 04:12:14 takano_makoto
27 Changed Interface of CXInitUncompContextXXX()
28 Changed Parameter type u8* to void*
29
30 Revision 1.8 2006/07/12 01:11:41 takano_makoto
31 Fixed comment
32
33 Revision 1.7 2006/07/10 08:38:17 takano_makoto
34 Added CXIsFinishedUncompXXX() to determine when streaming decompression is complete
35 Changed the spec for CXReadUncompXXX() to include header in passed data
36 (for a simplified interface)
37
38 Revision 1.6 2006/07/06 09:19:14 takano_makoto
39 Changed the include guard to the REVOLUTION_SDK format
40
41 Revision 1.5 2006/07/06 04:40:14 takano_makoto
42 Changed RL8 and LZ8 to RL and LZ
43
44 Revision 1.4 2006/07/05 11:14:43 takano_makoto
45 Revised the include guard
46
47 Revision 1.3 2006/07/05 08:13:36 takano_makoto
48 Revised comments
49 Deleted context members only needed for 16 bit access functions
50
51 Revision 1.2 2006/07/04 08:26:20 takano_makoto
52 Changed the prefix from the DS version
53
54 $NoKeywords: $
55 *---------------------------------------------------------------------------*/
56
57
58 #ifndef __CX_STREAMING_UNCOMPRESSION_STREAM_H__
59 #define __CX_STREAMING_UNCOMPRESSION_STREAM_H__
60
61 #include <dolphin/types.h>
62 #include <revolution/os.h> // For ASSERT use.
63
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67
68
69 typedef struct
70 {
71 u8 *destp; // Write-destination pointer 4B
72 s32 destCount; // Remaining size to write 4B
73 s32 forceDestCount; // Forcibly set the decompression size 4B
74 u16 length; // Remaining size of continuous write 2B
75 u8 flags; // Compression flag 1B
76 u8 headerSize; // Size of header being read 1B
77 // Total is 16B
78 }
79 CXUncompContextRL;
80
81
82 typedef struct
83 {
84 u8 *destp; // Write-destination pointer 4B
85 s32 destCount; // Remaining size to write 4B
86 s32 forceDestCount; // Forcibly set the decompression size 4B
87 s32 length; // Remaining length of continuous write 4B
88 u8 lengthFlg; // Length-acquired flag 1B
89 u8 flags; // Compression flag 1B
90 u8 flagIndex; // Current compression flag index 1B
91 u8 headerSize; // Size of header being read 1B
92 u8 exFormat; // LZ77 compression extension option 1B
93 u8 padding_[3]; // 3B
94 // Total is 24B
95 }
96 CXUncompContextLZ;
97
98
99 typedef struct
100 {
101 u8 *destp; // Write-destination pointer 4B
102 s32 destCount; // Remaining size to write 4B
103 s32 forceDestCount; // Forcibly set the decompression size 4B
104 u8 *treep; // Huffman encoding table, current pointer 4B
105 u32 srcTmp; // Data being read 4B
106 u32 destTmp; // Data being decoded 4B
107 s16 treeSize; // Size of Huffman encoding table 2B
108 u8 srcTmpCnt; // Size of data being read 1B
109 u8 destTmpCnt; // Number of bits that have been decoded 1B
110 u8 bitSize; // Size of encoded bits 1B
111 u8 headerSize; // Size of header being read 1B
112 u8 padding_[2]; // 2B
113 u8 tree[0x200]; // Huffman encoding table 512B (32B is enough for 4bit encoding, but allocated enough for 8bit encoding)
114 // Total = 544B (60B sufficient if 4bit encoding)
115 }
116 CXUncompContextHuffman;
117
118 /*---------------------------------------------------------------------------*
119 Name : CXInitUncompContextRL
120
121 Description : Initializes the streaming decompression context for run-length compressed data.
122
123
124 Arguments : context Pointer to the run-length uncompressed context
125 dest Destination address for uncompressed data
126
127 Returns : Can get the data size after decompression.
128
129 *---------------------------------------------------------------------------*/
130 void CXInitUncompContextRL( CXUncompContextRL *context,
131 void *dest );
132
133
134 /*---------------------------------------------------------------------------*
135 Name : CXInitUncompContextLZ
136
137 Description : Initializes the streaming decompression context for LZ compressed data.
138
139 Arguments : context Pointer to the LZ uncompressed context
140 dest Destination address for uncompressed data
141
142 *---------------------------------------------------------------------------*/
143 void CXInitUncompContextLZ( CXUncompContextLZ *context,
144 void *dest );
145
146 /*---------------------------------------------------------------------------*
147 Name : CXInitUncompContextHuffman
148
149 Description : Initializes the streaming decompression context for Huffman compressed data.
150
151 Arguments : context Pointer to the Huffman uncompressed context
152 dest Destination address for uncompressed data
153
154 *---------------------------------------------------------------------------*/
155 void CXInitUncompContextHuffman( CXUncompContextHuffman *context,
156 void *dest );
157
158
159 /*---------------------------------------------------------------------------*
160 Name : CXReadUncompRL
161
162 Description : This function performs streaming decompression of run-length compressed data.
163
164 Arguments : context Pointer to the run-length uncompressed context
165 data Pointer to the next data
166 len Data size
167
168 Returns : Size of remaining uncompressed data.
169
170 *---------------------------------------------------------------------------*/
171 s32 CXReadUncompRL( CXUncompContextRL *context, const void *data, u32 len );
172
173 /*---------------------------------------------------------------------------*
174 Name : CXReadUncompLZ
175
176 Description : This function performs streaming decompression of LZ compressed data.
177
178 Arguments : context Pointer to the LZ uncompressed context
179 data Pointer to the next data
180 len Data size
181
182 Returns : Size of remaining uncompressed data.
183
184 *---------------------------------------------------------------------------*/
185 s32 CXReadUncompLZ( CXUncompContextLZ *context, const void *data, u32 len );
186
187 /*---------------------------------------------------------------------------*
188 Name : CXReadUncompHuffman
189
190 Description : This function performs streaming decompression of Huffman compressed data.
191
192 Arguments : context Pointer to the Huffman uncompressed context
193 data Pointer to the next data
194 len Data size
195
196 Returns : Size of remaining uncompressed data.
197
198 *---------------------------------------------------------------------------*/
199 s32 CXReadUncompHuffman( CXUncompContextHuffman *context, const void *data, u32 len );
200
201
202 /*---------------------------------------------------------------------------*
203 Name: CXIsFinishedUncompRL
204
205 Description: This function determines whether streaming decompression for run-length compression has completed or not.
206
207 Arguments: *context Pointer to the run-length decompressed context
208
209 Returns: TRUE when decompression is complete
210 FALSE when data needing to be read still remains
211 *---------------------------------------------------------------------------*/
CXIsFinishedUncompRL(const CXUncompContextRL * context)212 static inline BOOL CXIsFinishedUncompRL( const CXUncompContextRL *context )
213 {
214 return (context->destCount > 0 || context->headerSize > 0)? FALSE : TRUE;
215 }
216
217
218 /*---------------------------------------------------------------------------*
219 Name: CXIsFinishedUncompLZ
220
221 Description: This function determines whether streaming decompression for LZ compression has completed or not.
222
223 Arguments: *context Pointer to the LZ decompressed context
224
225 Returns: TRUE when decompression is complete
226 FALSE when data needing to be read still remains
227 *---------------------------------------------------------------------------*/
CXIsFinishedUncompLZ(const CXUncompContextLZ * context)228 static inline BOOL CXIsFinishedUncompLZ( const CXUncompContextLZ *context )
229 {
230 return (context->destCount > 0 || context->headerSize > 0)? FALSE : TRUE;
231 }
232
233
234 /*---------------------------------------------------------------------------*
235 Name: CXIsFinishedUncompHuffman
236
237 Description: This function determines whether streaming decompression for Huffman compression has completed or not.
238
239 Arguments: *context pointer to the Huffman decompressed context
240
241 Returns: TRUE when decompression is complete
242 FALSE when data needing to be read still remains
243 *---------------------------------------------------------------------------*/
CXIsFinishedUncompHuffman(const CXUncompContextHuffman * context)244 static inline BOOL CXIsFinishedUncompHuffman( const CXUncompContextHuffman *context )
245 {
246 return (context->destCount > 0 || context->headerSize > 0)? FALSE : TRUE;
247 }
248
249
250
251 /*---------------------------------------------------------------------------*
252 Name: CXInitUncompContextXXFront
253
254 Description: Initializes the streaming decompression context for compressed data. (Includes specification for decompression size)
255
256 Arguments: *context Pointer to the run-length decompressed context
257 *dest Destination address for decompressed data
258 destSize Decompressed size setting
259
260 Returns: None.
261 *---------------------------------------------------------------------------*/
CXiInitUncompContextRLFront(CXUncompContextRL * context,void * dest,s32 destSize)262 static inline void CXiInitUncompContextRLFront( CXUncompContextRL *context, void *dest, s32 destSize )
263 {
264 ASSERT( destSize > 0 );
265 CXInitUncompContextRL( context, dest );
266 context->forceDestCount = destSize;
267 }
268
CXiInitUncompContextLZFront(CXUncompContextLZ * context,void * dest,s32 destSize)269 static inline void CXiInitUncompContextLZFront( CXUncompContextLZ *context, void *dest, s32 destSize )
270 {
271 ASSERT( destSize > 0 );
272 CXInitUncompContextLZ( context, dest );
273 context->forceDestCount = destSize;
274 }
275
CXiInitUncompContextHuffmanFront(CXUncompContextHuffman * context,void * dest,s32 destSize)276 static inline void CXiInitUncompContextHuffmanFront( CXUncompContextHuffman *context, void *dest, s32 destSize )
277 {
278 ASSERT( destSize > 0 );
279 CXInitUncompContextHuffman( context, dest );
280 context->forceDestCount = destSize;
281 }
282
283
284
285
286 #ifdef __cplusplus
287 } /* extern "C" */
288 #endif
289
290 /* __CX_STREAMING_UNCOMPRESSION_STREAM_H__ */
291 #endif
292