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.11 07/27/2006 07:40:19 takano_makoto
15 Add const modifier to CXIsFinishedUncompXXX parameter.
16
17 Revision 1.10 07/27/2006 04:25:12 takano_makoto
18 Change Condition of CXIsFinishedUncompXXX()
19
20 Revision 1.9 07/27/2006 04:12:14 takano_makoto
21 Change Interface of CXInitUncompContextXXX()
22 Change Parameter type u8* to void*
23
24 Revision 1.8 07/12/2006 01:11:41 takano_makoto
25 fix comment
26
27 Revision 1.7 07/10/2006 08:38:17 takano_makoto
28 Added CXIsFinishedUncompXXX() to determine when streaming decompression is complete
29 Changed the spec for CXReadUncompXXX() to include header in passed data
30 (for a simplified interface)
31
32 Revision 1.6 07/06/2006 09:19:14 takano_makoto
33 Changed the include guard to the REVOLUTION_SDK format
34
35 Revision 1.5 07/06/2006 04:40:14 takano_makoto
36 changed RL8 and LZ8 to RL and ZL
37
38 Revision 1.4 07/05/2006 11:14:43 takano_makoto
39 revised the include guard
40
41 Revision 1.3 07/05/2006 08:13:36 takano_makoto
42 revised comments
43 deleted context members only needed for 16 bit access functions
44
45 Revision 1.2 07/04/2006 08:26:20 takano_makoto
46 changed the prefix from the DS version
47
48 $NoKeywords: $
49 *---------------------------------------------------------------------------*/
50
51
52 #ifndef __CX_STREAMING_UNCOMPRESSION_STREAM_H__
53 #define __CX_STREAMING_UNCOMPRESSION_STREAM_H__
54
55 #include <dolphin/types.h>
56
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60
61
62 typedef struct
63 {
64 u8 *destp; // Write-destination pointer 4B
65 s32 destCount; // Remaining size to write 4B
66 u16 length; // Remaining size of continuous write 2B
67 u8 flags; // Compression flag 1B
68 u8 headerSize; // Size of header being read 1B
69 // Total is 12B
70 }
71 CXUncompContextRL;
72
73
74 typedef struct
75 {
76 u8 *destp; // Write-destination pointer 4B
77 s32 destCount; // Remaining size to write 4B
78 u8 flags; // Compression flag 1B
79 u8 flagIndex; // Current compression flag index 1B
80 u8 length; // Remaining length of continuous write 1B
81 u8 lengthFlg; // Length-acquired flag 1B
82 u8 headerSize; // Size of header being read 1B
83 u8 padding_[1]; // 3B
84 // Total is 16B
85 }
86 CXUncompContextLZ;
87
88
89 typedef struct
90 {
91 u8 *destp; // Write-destination pointer 4B
92 s32 destCount; // Remaining size to write 4B
93 u8 *treep; // Huffman encoding table, current pointer 4B
94 u32 srcTmp; // Data being read 4B
95 u32 destTmp; // Data being decoded 4B
96 s16 treeSize; // Size of Huffman encoding table 2B
97 u8 srcTmpCnt; // Size of data being read 1B
98 u8 destTmpCnt; // Number of bits that have been decoded 1B
99 u8 bitSize; // Size of encoded bits 1B
100 u8 headerSize; // Size of header being read 1B
101 u8 padding_[2]; // 2B
102 u8 tree[0x200]; // Huffman encoding table 512B (32B is OK if 4bit encoding, but allocated enough for 8bit encoding)
103 // Total = 540B (60B sufficient if 4bit encoding)
104 }
105 CXUncompContextHuffman;
106
107 /*---------------------------------------------------------------------------*
108 Name: CXInitUncompContextRL
109
110 Description: Initializes the streaming uncompression context for run-length
111 compressed data
112
113 Arguments: context Pointer to the run-length uncompressed context
114 dest Destination address for uncompressed data
115 header a pointer to the leading data for the compressed data
116
117 Returns: Can get the data size after decompression.
118
119 *---------------------------------------------------------------------------*/
120 void CXInitUncompContextRL( CXUncompContextRL *context,
121 void *dest );
122
123 /*---------------------------------------------------------------------------*
124 Name: CXInitUncompContextLZ
125
126 Description: Initializes the streaming uncompression context for LZ compressed data.
127
128 Arguments: context Pointer to the LZ uncompressed context
129 dest Destination address for uncompressed data
130 header a pointer to the leading data for the compressed data
131
132 *---------------------------------------------------------------------------*/
133 void CXInitUncompContextLZ( CXUncompContextLZ *context,
134 void *dest );
135
136 /*---------------------------------------------------------------------------*
137 Name: CXInitUncompContextHuffman
138
139 Description: Initializes the streaming uncompression context for Huffman compressed data.
140
141 Arguments: context Pointer to the Huffman uncompressed context
142 dest Destination address for uncompressed data
143 header a pointer to the leading data for the compressed data
144
145 *---------------------------------------------------------------------------*/
146 void CXInitUncompContextHuffman( CXUncompContextHuffman *context,
147 void *dest );
148
149 /*---------------------------------------------------------------------------*
150 Name: CXReadUncompRL
151
152 Description: This function performs streaming uncompression of run-length compressed data.
153
154 Arguments: context Pointer to the run-length uncompressed context
155 data Pointer to the next data
156 len Data size
157
158 Returns: Size of remaining uncompressed data.
159
160 *---------------------------------------------------------------------------*/
161 s32 CXReadUncompRL( CXUncompContextRL *context, const void *data, u32 len );
162
163 /*---------------------------------------------------------------------------*
164 Name: CXReadUncompLZ
165
166 Description: This function performs streaming uncompression of LZ compressed data.
167
168 Arguments: context Pointer to the LZ uncompressed context
169 data Pointer to the next data
170 len Data size
171
172 Returns: Size of remaining uncompressed data.
173
174 *---------------------------------------------------------------------------*/
175 s32 CXReadUncompLZ( CXUncompContextLZ *context, const void *data, u32 len );
176
177 /*---------------------------------------------------------------------------*
178 Name: CXReadUncompHuffman
179
180 Description: This function performs streaming uncompression of Huffman compressed data.
181
182 Arguments: context Pointer to the Huffman uncompressed context
183 data Pointer to the next data
184 len Data size
185
186 Returns: Size of remaining uncompressed data.
187
188 *---------------------------------------------------------------------------*/
189 s32 CXReadUncompHuffman( CXUncompContextHuffman *context, const void *data, u32 len );
190
191
192 /*---------------------------------------------------------------------------*
193 Name: CXIsFinishedUncompRL
194
195 Description: This function determines whether streaming decompression for runlength compression has completed or not.
196
197 Arguments: *context Pointer to the run-length decompressed context
198
199 Returns: TRUE when decompression is complete
200 FALSE when data needing to be read still remains
201 *---------------------------------------------------------------------------*/
CXIsFinishedUncompRL(const CXUncompContextRL * context)202 static inline BOOL CXIsFinishedUncompRL( const CXUncompContextRL *context )
203 {
204 return (context->destCount > 0 || context->headerSize > 0)? FALSE : TRUE;
205 }
206
207
208 /*---------------------------------------------------------------------------*
209 Name: CXIsFinishedUncompLZ
210
211 Description: This function determines whether streaming decompression for LZ compression has completed or not.
212
213 Arguments: *context Pointer to the LZ decompressed context
214
215 Returns: TRUE when decompression is complete
216 FALSE when data needing to be read still remains
217 *---------------------------------------------------------------------------*/
CXIsFinishedUncompLZ(const CXUncompContextLZ * context)218 static inline BOOL CXIsFinishedUncompLZ( const CXUncompContextLZ *context )
219 {
220 return (context->destCount > 0 || context->headerSize > 0)? FALSE : TRUE;
221 }
222
223
224 /*---------------------------------------------------------------------------*
225 Name: CXIsFinishedUncompHuffman
226
227 Description: This function determines whether streaming decompression for Huffman compression has completed or not.
228
229 Arguments: *context pointer to the Huffman decompressed context
230
231 Returns: TRUE when decompression is complete
232 FALSE when data needing to be read still remains
233 *---------------------------------------------------------------------------*/
CXIsFinishedUncompHuffman(const CXUncompContextHuffman * context)234 static inline BOOL CXIsFinishedUncompHuffman( const CXUncompContextHuffman *context )
235 {
236 return (context->destCount > 0 || context->headerSize > 0)? FALSE : TRUE;
237 }
238
239
240 #ifdef __cplusplus
241 } /* extern "C"*/
242 #endif
243
244 /* __CX_STREAMING_UNCOMPRESSION_STREAM_H__*/
245 #endif
246