1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     cx_StreamingUncompression.h
4 
5   Copyright (C)2009-2012 Nintendo Co., Ltd./HAL Laboratory, Inc.  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   $Revision: 47717 $
14  *---------------------------------------------------------------------------*/
15 
16 /* Please see man pages for details
17 
18 
19 
20 */
21 
22 #ifndef NN_CX_CX_STREAMING_UNCOMPRESSION_H_
23 #define NN_CX_CX_STREAMING_UNCOMPRESSION_H_
24 
25 #include <nn/types.h>
26 #include <nn/assert.h>
27 
28 namespace nn {
29 namespace cx {
30 
31 /* Please see man pages for details
32 
33  */
34 struct UncompContextRL
35 {
36     u8 *destp;                         //
37     s32 destCount;                     //
38     s32 forceDestCount;                //
39     u16 length;                        //
40     u8  flags;                         //
41     u8  headerSize;                    //
42 };
43 
44 
45 /* Please see man pages for details
46 
47  */
48 struct UncompContextLZ
49 {
50     u8 *destp;                         //
51     s32 destCount;                     //
52     s32 forceDestCount;                //
53     s32 length;                        //
54     u8  lengthFlg;                     //
55     u8  flags;                         //
56     u8  flagIndex;                     //
57     u8  headerSize;                    //
58     u8  exFormat;                      //
59     NN_PADDING3;
60 };
61 
62 
63 /* Please see man pages for details
64 
65  */
66 struct UncompContextHuffman
67 {
68     u8 *destp;                         //
69     s32 destCount;                     //
70     s32 forceDestCount;                //
71     u8 *treep;                         //
72     u32 srcTmp;                        //
73     u32 destTmp;                       //
74     s16 treeSize;                      //
75     u8  srcTmpCnt;                     //
76     u8  destTmpCnt;                    //
77     u8  bitSize;                       //
78     u8  headerSize;                    //
79     NN_PADDING2;
80     u8  tree[0x200];                   //
81 };
82 
83 
84 /* Please see man pages for details
85 
86  */
87 struct UncompContextLH
88 {
89     u8   *destp;                         //
90     s32  destCount;                      //
91     s32  forceDestCount;                 //
92     u16  huffTable9 [ 1 << (9 + 1) ];    //
93     u16  huffTable12[ 1 << (5 + 1) ];    //
94     u16  *nodep;                         //
95     s32  tableSize9;                     //
96     s32  tableSize12;                    //
97     u32  tableIdx;                       //
98     u32  stream;                         //
99     u32  stream_len;                     //
100     u16  length;                         //
101     s8   offset_bits;                    //
102     u8   headerSize;                     //
103 };
104 
105 
106 /* Please see man pages for details
107 
108  */
109 struct UncompContextLRC
110 {
111     u8   *destp;                         //
112     s32  destCount;                      //
113     s32  forceDestCount;                 //
114     u32  freq9    [ 1 << 9  ];           //
115     u32  low_cnt9 [ 1 << 9  ];           //
116     u32  freq12   [ 1 << 12 ];           //
117     u32  low_cnt12[ 1 << 12 ];           //
118     u32  total9;                         //
119     u32  total12;                        //
120     u32  range;                          //
121     u32  code;                           //
122     u32  low;                            //
123     u32  carry_cnt;                      //
124     u8   carry;                          //
125     u8   codeLen;                        //
126     u16  length;                         //
127     u8   headerSize;                     //
128     NN_PADDING3;
129 };
130 
131 //----------------------------------------------------------------------
132 /* Please see man pages for details
133 
134  *///-------------------------------------------------------------------
135 struct UncompContextDeflate
136 {
137     bit8 dummy[39956] NN_ATTRIBUTE_ALIGN(4);
138 };
139 
140 //----------------------------------------------------------------------
141 /* Please see man pages for details
142  *///-------------------------------------------------------------------
143 typedef UncompContextDeflate UncompContextGzip;
144 
145 //----------------------------------------------------------------------
146 /* Please see man pages for details
147  *///-------------------------------------------------------------------
148 typedef UncompContextDeflate UncompContextZlib;
149 
150 
151 /* Please see man pages for details
152 
153 
154 */
155 
156 /* Please see man pages for details
157 
158 
159 
160  */
161 void InitUncompContextRL( UncompContextRL *context, void *dest );
162 
163 
164 /* Please see man pages for details
165 
166 
167 
168 
169 
170 
171  */
172 void InitUncompContextLZ( UncompContextLZ *context, void *dest );
173 
174 
175 /* Please see man pages for details
176 
177 
178 
179  */
180 void InitUncompContextHuffman( UncompContextHuffman    *context,
181                                  void                      *dest );
182 
183 /* Please see man pages for details
184 
185 
186 
187  */
188 void InitUncompContextLH( UncompContextLH * context, void* dest );
189 
190 
191 /* Please see man pages for details
192 
193 
194 
195  */
196 void InitUncompContextLRC( UncompContextLRC * context, void* dest );
197 
198 
199 //----------------------------------------------------------------------
200 /* Please see man pages for details
201 
202 
203 
204 
205 
206  *///-------------------------------------------------------------------
207 void InitUncompContextDeflate( UncompContextDeflate* pContext, void* pDst, size_t dstSize );
208 
209 //----------------------------------------------------------------------
210 /* Please see man pages for details
211 
212 
213 
214 
215 
216  *///-------------------------------------------------------------------
217 void InitUncompContextGzip   ( UncompContextGzip* pContext, void* pDst, size_t dstSize );
218 
219 //----------------------------------------------------------------------
220 /* Please see man pages for details
221 
222 
223 
224 
225 
226  *///-------------------------------------------------------------------
227 void InitUncompContextZlib   ( UncompContextZlib* pContext, void* pDst, size_t dstSize );
228 
229 
230 
231 /* Please see man pages for details
232 
233 
234 
235 
236 
237  */
238 s32 ReadUncompRL( UncompContextRL *context, const void *data, u32 len );
239 
240 
241 /* Please see man pages for details
242 
243 
244 
245 
246 
247 
248 
249 
250  */
251 s32 ReadUncompLZ( UncompContextLZ *context, const void *data, u32 len );
252 
253 
254 /* Please see man pages for details
255 
256 
257 
258 
259 
260  */
261 s32 ReadUncompHuffman( UncompContextHuffman *context, const void *data, u32 len );
262 
263 
264 /* Please see man pages for details
265 
266 
267 
268 
269 
270  */
271 s32 ReadUncompLH( UncompContextLH *context, const void* data, u32 len );
272 
273 
274 /* Please see man pages for details
275 
276 
277 
278 
279 
280  */
281 s32 ReadUncompLRC( UncompContextLRC *context, const void* data, u32 len );
282 
283 //----------------------------------------------------------------------
284 /* Please see man pages for details
285 
286 
287 
288 
289 
290 
291 
292  *///-------------------------------------------------------------------
293 s32 ReadUncompDeflate( UncompContextDeflate* pContext, const void* pData, size_t dataSize );
294 
295 //----------------------------------------------------------------------
296 /* Please see man pages for details
297 
298 
299 
300 
301 
302 
303 
304 
305 
306  *///-------------------------------------------------------------------
307 s32 ReadUncompGzip   ( UncompContextGzip*    pContext, const void* pData, size_t dataSize );
308 
309 //----------------------------------------------------------------------
310 /* Please see man pages for details
311 
312 
313 
314 
315 
316 
317 
318 
319 
320  *///-------------------------------------------------------------------
321 s32 ReadUncompZlib   ( UncompContextZlib*    pContext, const void* pData, size_t dataSize );
322 
323 
324 
325 /* Please see man pages for details
326 
327 
328 
329 
330  */
331 template <typename UncompContext>
IsFinishedUncomp(const UncompContext * context)332 inline bool IsFinishedUncomp( const UncompContext *context )
333 {
334     NN_NULL_TASSERT_(context);
335     return (context->destCount > 0 || context->headerSize > 0)? false : true;
336 }
337 
338 /* Please see man pages for details
339 
340 
341 */
342 template <typename UncompContext>
IsFinishedUncompRL(const UncompContext * context)343 inline bool IsFinishedUncompRL( const UncompContext *context ) NN_ATTRIBUTE_DEPRECATED
344 {
345     NN_NULL_TASSERT_(context);
346     return (context->destCount > 0 || context->headerSize > 0)? false : true;
347 }
348 
349 
350 /* Please see man pages for details
351 
352 
353 
354 
355 
356  */
InitUncompContextRLFront(UncompContextRL * context,void * dest,s32 destSize)357 inline void InitUncompContextRLFront( UncompContextRL *context, void *dest, s32 destSize )
358 {
359     NN_ASSERT( destSize > 0 );
360     InitUncompContextRL( context, dest );
361     context->forceDestCount = destSize;
362 }
363 
364 
365 /* Please see man pages for details
366 
367 
368 
369 
370 
371 
372 
373 
374  */
InitUncompContextLZFront(UncompContextLZ * context,void * dest,s32 destSize)375 inline void InitUncompContextLZFront( UncompContextLZ *context, void *dest, s32 destSize )
376 {
377     NN_ASSERT( destSize > 0 );
378     InitUncompContextLZ( context, dest );
379     context->forceDestCount = destSize;
380 }
381 
382 
383 /* Please see man pages for details
384 
385 
386 
387 
388 
389  */
InitUncompContextHuffmanFront(UncompContextHuffman * context,void * dest,s32 destSize)390 inline void InitUncompContextHuffmanFront( UncompContextHuffman *context, void *dest, s32 destSize )
391 {
392     NN_ASSERT( destSize > 0 );
393     InitUncompContextHuffman( context, dest );
394     context->forceDestCount = destSize;
395 }
396 
397 
398 /* Please see man pages for details
399 
400 
401 
402 
403 
404  */
InitUncompContextLHFront(UncompContextLH * context,void * dest,s32 destSize)405 inline void InitUncompContextLHFront( UncompContextLH *context, void *dest, s32 destSize )
406 {
407     NN_ASSERT( destSize > 0 );
408     InitUncompContextLH( context, dest );
409     context->forceDestCount = destSize;
410 }
411 
412 
413 /* Please see man pages for details
414 
415 
416 
417 
418 
419  */
InitUncompContextLRCFront(UncompContextLRC * context,void * dest,s32 destSize)420 inline void InitUncompContextLRCFront( UncompContextLRC *context, void *dest, s32 destSize )
421 {
422     NN_ASSERT( destSize > 0 );
423     InitUncompContextLRC( context, dest );
424     context->forceDestCount = destSize;
425 }
426 
427 /*
428 
429 */
430 
431 }   // namespace cx
432 }   // namespace nn
433 
434 /* NN_CX_CX_STREAMING_UNCOMPRESSION_H_ */
435 #endif
436