1 /*---------------------------------------------------------------------------* 2 Project: TwlSDK - MI - include 3 File: uncomp_stream.h 4 5 Copyright 2003-2008 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 $Date:: 2008-09-18#$ 14 $Rev: 8573 $ 15 $Author: okubata_ryoma $ 16 *---------------------------------------------------------------------------*/ 17 18 #ifndef NITRO_MI_UNCOMP_STREAM_H_ 19 #define NITRO_MI_UNCOMP_STREAM_H_ 20 21 #include <nitro/types.h> 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 typedef struct 28 { 29 u8 *destp; // Write-destination pointer 4B 30 s32 destCount; // Remaining size to write 4B 31 u16 destTmp; // Data being written: 2B 32 u8 destTmpCnt; // Size of data being written: 1B 33 u8 flags; // Compression flag 1B 34 u16 length; // Remaining size of continuous write 2B 35 u8 _padding[2]; // 2 bytes 36 // Total: 16 Bytes 37 } 38 MIUncompContextRL; 39 40 41 typedef struct 42 { 43 u8 *destp; // Write-destination pointer 4B 44 s32 destCount; // Remaining size to write 4B 45 u32 length; // Remaining length of continuous write 4B 46 u16 destTmp; // Data being written: 2B 47 u8 destTmpCnt; // Size of data being written: 1B 48 u8 flags; // Compression flag 1B 49 u8 flagIndex; // Current compression flag index 1B 50 u8 lengthFlg; // Length-acquired flag 1B 51 u8 exFormat; // LZ77 compression extension option: 1B 52 u8 _padding[1]; // 1B 53 // Total: 20 Bytes 54 } 55 MIUncompContextLZ; 56 57 58 typedef struct 59 { 60 u8 *destp; // Write-destination pointer 4B 61 s32 destCount; // Remaining size to write 4B 62 u8 *treep; // Huffman encoding table, current pointer 4B 63 u32 srcTmp; // Data being read 4B 64 u32 destTmp; // Data being decoded 4B 65 s16 treeSize; // Size of Huffman encoding table 2B 66 u8 srcTmpCnt; // Size of data being read 1B 67 u8 destTmpCnt; // Number of bits that have been decoded 1B 68 u8 bitSize; // Size of encoded bits 1B 69 u8 _padding2[3]; // 3B 70 u8 tree[0x200]; // Huffman encoding table 512B (32B is enough for 4-bit encoding, but enough is allocated for 8-bit encoding) 71 // Total = 540 Bytes (60 Bytes is sufficient for a 4-bit encoding) 72 } 73 MIUncompContextHuffman; 74 75 76 void MI_InitUncompContextRL(MIUncompContextRL *context, u8 *dest, 77 const MICompressionHeader *header); 78 void MI_InitUncompContextLZ(MIUncompContextLZ *context, u8 *dest, 79 const MICompressionHeader *header); 80 void MI_InitUncompContextHuffman(MIUncompContextHuffman *context, u8 *dest, 81 const MICompressionHeader *header); 82 83 s32 MI_ReadUncompRL8(MIUncompContextRL *context, const u8 *data, u32 len); 84 s32 MI_ReadUncompRL16(MIUncompContextRL *context, const u8 *data, u32 len); 85 s32 MI_ReadUncompLZ8(MIUncompContextLZ *context, const u8 *data, u32 len); 86 s32 MI_ReadUncompLZ16(MIUncompContextLZ *context, const u8 *data, u32 len); 87 s32 MI_ReadUncompHuffman(MIUncompContextHuffman *context, const u8 *data, u32 len); 88 89 #ifdef __cplusplus 90 } /* extern "C" */ 91 #endif 92 93 /* NITRO_MI_UNCOMP_STREAM_H_ */ 94 #endif 95