/*---------------------------------------------------------------------------* Project: Compress/uncompress library File: CXStreamingUncompression.h Copyright 2005 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Log: CXStreamingUncompression.h,v $ Revision 1.16.4.1 2008/09/25 06:01:22 takano_makoto Changed CXiInitXXXFront to CXInitXXXFront. Revision 1.16 2007/10/31 12:52:11 takano_makoto Appended the LH and LRC formats. Revision 1.15 2007/05/30 04:19:52 takano_makoto Added CXiInitUncompContextXXFront() Revision 1.14 2007/05/18 10:50:39 yasuh-to Rollback to SYSTEMMENU2_DEV_BRANCH(HEAD) Revision 1.11 2006/07/27 07:40:19 takano_makoto Added const modifier to CXIsFinishedUncompXXX parameter. Revision 1.10 2006/07/27 04:25:12 takano_makoto Changed Condition of CXIsFinishedUncompXXX() Revision 1.9 2006/07/27 04:12:14 takano_makoto Changed Interface of CXInitUncompContextXXX() Changed Parameter type u8* to void* Revision 1.8 2006/07/12 01:11:41 takano_makoto Fixed comment Revision 1.7 2006/07/10 08:38:17 takano_makoto Added CXIsFinishedUncompXXX() to determine when streaming decompression is complete Changed the spec for CXReadUncompXXX() to include header in passed data (for a simplified interface) Revision 1.6 2006/07/06 09:19:14 takano_makoto Changed the include guard to the REVOLUTION_SDK format Revision 1.5 2006/07/06 04:40:14 takano_makoto Changed RL8 and LZ8 to RL and LZ Revision 1.4 2006/07/05 11:14:43 takano_makoto Revised the include guard Revision 1.3 2006/07/05 08:13:36 takano_makoto Revised comments Deleted context members only needed for 16 bit access functions Revision 1.2 2006/07/04 08:26:20 takano_makoto Changed the prefix from the DS version $NoKeywords: $ *---------------------------------------------------------------------------*/ #ifndef __CX_STREAMING_UNCOMPRESSION_STREAM_H__ #define __CX_STREAMING_UNCOMPRESSION_STREAM_H__ #include #include // For ASSERT use. #ifdef __cplusplus extern "C" { #endif typedef struct { u8 *destp; // Write-destination pointer: 4B s32 destCount; // Remaining size to write: 4B s32 forceDestCount; // Forcibly set the decompression size 4B u16 length; // Remaining size of continuous write: 2B u8 flags; // Compression flag: 1B u8 headerSize; // Size of header being read 1B // Total is 16B } CXUncompContextRL; typedef struct { u8 *destp; // Write-destination pointer: 4B s32 destCount; // Remaining size to write: 4B s32 forceDestCount; // Forcibly set the decompression size 4B s32 length; // Remaining length of continuous write: 4B u8 lengthFlg; // 'length' obtained flag: 1B u8 flags; // Compression flag: 1B u8 flagIndex; // Current compression flag index: 1B u8 headerSize; // Size of header being read: 1B u8 exFormat; // LZ77 compression extension option: 1B u8 padding_[3]; // 3B // Total is 24B } CXUncompContextLZ; typedef struct { u8 *destp; // Write-destination pointer: 4B s32 destCount; // Remaining size to write: 4B s32 forceDestCount; // Forcibly set the decompression size: 4B u8 *treep; // Huffman encoding table, current pointer: 4B u32 srcTmp; // Data being read: 4B u32 destTmp; // Data being decoded: 4B s16 treeSize; // Size of Huffman encoding table: 2B u8 srcTmpCnt; // Size of data being read: 1B u8 destTmpCnt; // Number of bits that have been decoded: 1B u8 bitSize; // Size of encoded bits: 1B u8 headerSize; // Size of header being read: 1B u8 padding_[2]; // 2B u8 tree[0x200]; // Huffman encoding table: 512B (32B is enough for 4-bit encoding, but allocated enough for 8-bit encoding) // Total = 544B (60B sufficient if 4-bit encoding) } CXUncompContextHuffman; typedef struct { u8 *destp; // Write-destination pointer: 4B s32 destCount; // Remaining size to write: 4B s32 forceDestCount; // Forcibly set the decompression size 4B u16 huffTable9 [ 1 << (9 + 1) ]; // Huffman encoding table: 2048B u16 huffTable12[ 1 << (5 + 1) ]; // Huffman encoding table: 128B u16 *nodep; // Node during a Huffman table search: 4B s32 tableSize9; // Table size during a load: 4B s32 tableSize12; // Table size during a load: 4B u32 tableIdx; // Index for the table load position: 4B u32 stream; // Bit stream for loading: 4B u32 stream_len; // Number of valid stream bits for loading: 4B u16 length; // Read length for LZ compression: 2B s8 offset_bits; // Bit length for offset information: 1B u8 headerSize; // Size of header being read: 1B } // Total is 2216B CXUncompContextLH; typedef struct { u8 *destp; // Write-destination pointer: 4B s32 destCount; // Remaining size to write: 4B s32 forceDestCount; // Forcibly set the decompression size 4B u32 freq9 [ 1 << 9 ]; // Frequency table for code data (2048 bytes) u32 low_cnt9 [ 1 << 9 ]; // low_cnt table for code data: 2048B u32 freq12 [ 1 << 12 ]; // Frequency table for offset data: 16384B u32 low_cnt12[ 1 << 12 ]; // low_cnt table for offset data: 16384B u32 total9; // Total value for code data: 4B u32 total12; // Total value for offset data: 4B u32 range; // Range state of a range coder: 4B u32 code; // Code state of a range coder: 4B u32 low; // Low state of a range coder: 4B u32 carry_cnt; // Number of carry digits for a range coder: 4B u8 carry; // Carry state for a range coder: 1B u8 codeLen; // Code length required for a range coder: 1B u16 length; // Read length for LZ compression: 2B u8 headerSize; // Size of header being read: 1B u8 padding_[3]; // 3B } // Total is 36908B CXUncompContextLRC; /*---------------------------------------------------------------------------* Name : CXInitUncompContextRL Description : Initializes the streaming decompression context for run-length compressed data. Arguments : context Pointer to the run-length uncompressed context dest Destination address for uncompressed data Returns : Can get the data size after decompression. *---------------------------------------------------------------------------*/ void CXInitUncompContextRL( CXUncompContextRL *context, void *dest ); /*---------------------------------------------------------------------------* Name : CXInitUncompContextLZ Description : Initializes the streaming decompression context for LZ-compressed data. Arguments : context Pointer to the LZ uncompressed context dest Destination address for uncompressed data *---------------------------------------------------------------------------*/ void CXInitUncompContextLZ( CXUncompContextLZ *context, void *dest ); /*---------------------------------------------------------------------------* Name : CXInitUncompContextHuffman Description : Initializes the streaming decompression context for Huffman-compressed data. Arguments : context Pointer to the Huffman uncompressed context dest Destination address for uncompressed data *---------------------------------------------------------------------------*/ void CXInitUncompContextHuffman( CXUncompContextHuffman *context, void *dest ); /*---------------------------------------------------------------------------* Name: CXInitUncompContextLH Description: Initializes the streaming decompression context for LZ-Huffman (combined) compressed data. Arguments: context: Pointer to the decompressed context dest Destination address for uncompressed data Returns: None. *---------------------------------------------------------------------------*/ void CXInitUncompContextLH( CXUncompContextLH * context, void* dest ); /*---------------------------------------------------------------------------* Name: CXInitUncompContextLRC Description: Initializes the streaming decompression context for LZ/Range Coder (combined) compressed data. Arguments: context: Pointer to the decompressed context dest Destination address for uncompressed data Returns: None. *---------------------------------------------------------------------------*/ void CXInitUncompContextLRC( CXUncompContextLRC * context, void* dest ); /*---------------------------------------------------------------------------* Name : CXReadUncompRL Description : This function performs streaming decompression of run-length compressed data. Arguments : context Pointer to the run-length uncompressed context data Pointer to the next data len Data size Returns : Size of remaining uncompressed data. *---------------------------------------------------------------------------*/ s32 CXReadUncompRL( CXUncompContextRL *context, const void *data, u32 len ); /*---------------------------------------------------------------------------* Name : CXReadUncompLZ Description : This function performs streaming decompression of LZ-compressed data. Arguments : context Pointer to the LZ uncompressed context data Pointer to the next data len Data size Returns : Size of remaining uncompressed data. *---------------------------------------------------------------------------*/ s32 CXReadUncompLZ( CXUncompContextLZ *context, const void *data, u32 len ); /*---------------------------------------------------------------------------* Name : CXReadUncompHuffman Description : This function performs streaming decompression of Huffman-compressed data. Arguments : context Pointer to the Huffman uncompressed context data Pointer to the next data len Data size Returns : Size of remaining uncompressed data. *---------------------------------------------------------------------------*/ s32 CXReadUncompHuffman( CXUncompContextHuffman *context, const void *data, u32 len ); /*---------------------------------------------------------------------------* Name: CXReadUncompLH Description: This function performs streaming decompression of LZ-Huffman (combined) compressed data. Arguments: *context: Pointer to the decompressed context data: Data pointer len Data size Returns: Size of remaining uncompressed data *---------------------------------------------------------------------------*/ s32 CXReadUncompLH( CXUncompContextLH *context, const void* data, u32 len ); /*---------------------------------------------------------------------------* Name: CXReadUncompLRC Description: This function performs streaming decompression of LZ/Range Coder (combined) compressed data. Arguments: *context: Pointer to the decompressed context data: Data pointer len: Data size Returns: Size of remaining uncompressed data *---------------------------------------------------------------------------*/ s32 CXReadUncompLRC( CXUncompContextLRC *context, const void* data, u32 len ); /*---------------------------------------------------------------------------* Name: CXIsFinishedUncompRL Description: This function determines whether streaming decompression for run-length compression has completed or not. Arguments: *context Pointer to the run-length decompressed context Returns: TRUE when decompression is complete FALSE when data needing to be read still remains *---------------------------------------------------------------------------*/ static inline BOOL CXIsFinishedUncompRL( const CXUncompContextRL *context ) { return (context->destCount > 0 || context->headerSize > 0)? FALSE : TRUE; } /*---------------------------------------------------------------------------* Name: CXIsFinishedUncompLZ Description: This function determines whether streaming decompression for LZ compression has completed or not. Arguments: *context Pointer to the LZ decompressed context Returns: TRUE when decompression is complete FALSE when data needing to be read still remains *---------------------------------------------------------------------------*/ static inline BOOL CXIsFinishedUncompLZ( const CXUncompContextLZ *context ) { return (context->destCount > 0 || context->headerSize > 0)? FALSE : TRUE; } /*---------------------------------------------------------------------------* Name: CXIsFinishedUncompHuffman Description: This function determines whether streaming decompression for Huffman compression has completed or not. Arguments: *context pointer to the Huffman decompressed context Returns: TRUE when decompression is complete FALSE when data needing to be read still remains *---------------------------------------------------------------------------*/ static inline BOOL CXIsFinishedUncompHuffman( const CXUncompContextHuffman *context ) { return (context->destCount > 0 || context->headerSize > 0)? FALSE : TRUE; } /*---------------------------------------------------------------------------* Name: CXIsFinishedUncompLH Description: This function determines if streaming decompression has completed for LZ-Huffman (combined) compression. Arguments: *context: Pointer to the decompressed context Returns: TRUE when decompression is complete FALSE when data needing to be read still remains *---------------------------------------------------------------------------*/ static inline BOOL CXIsFinishedUncompLH( const CXUncompContextLH *context ) { return (context->destCount > 0 || context->headerSize > 0)? FALSE : TRUE; } /*---------------------------------------------------------------------------* Name: CXIsFinishedUncompLRC Description: This function determines if streaming decompression has completed for LZ/Range Coder (combined) compression. Arguments: *context: Pointer to the decompressed context Returns: TRUE when decompression is complete FALSE when data needing to be read still remains *---------------------------------------------------------------------------*/ static inline BOOL CXIsFinishedUncompLRC( const CXUncompContextLRC *context ) { return (context->destCount > 0 || context->headerSize > 0)? FALSE : TRUE; } /*---------------------------------------------------------------------------* Name: CXInitUncompContextXXFront Description: Initializes the streaming decompression context for compressed data. (Includes specification for decompression size) Arguments: *context Pointer to the run-length decompressed context *dest Destination address for decompressed data destSize Decompressed size setting Returns: None. *---------------------------------------------------------------------------*/ static inline void CXInitUncompContextRLFront( CXUncompContextRL *context, void *dest, s32 destSize ) { ASSERT( destSize > 0 ); CXInitUncompContextRL( context, dest ); context->forceDestCount = destSize; } static inline void CXInitUncompContextLZFront( CXUncompContextLZ *context, void *dest, s32 destSize ) { ASSERT( destSize > 0 ); CXInitUncompContextLZ( context, dest ); context->forceDestCount = destSize; } static inline void CXInitUncompContextHuffmanFront( CXUncompContextHuffman *context, void *dest, s32 destSize ) { ASSERT( destSize > 0 ); ASSERT( (destSize % 4) == 0 ); CXInitUncompContextHuffman( context, dest ); context->forceDestCount = destSize; } static inline void CXInitUncompContextLHFront( CXUncompContextLH *context, void *dest, s32 destSize ) { ASSERT( destSize > 0 ); CXInitUncompContextLH( context, dest ); context->forceDestCount = destSize; } static inline void CXInitUncompContextLRCFront( CXUncompContextLRC *context, void *dest, s32 destSize ) { ASSERT( destSize > 0 ); CXInitUncompContextLRC( context, dest ); context->forceDestCount = destSize; } //===================================================================== // These aliases are defined for compatibility with older versions of the function names. // These may be deleted in the future. //===================================================================== #define CXiInitUncompContextRLFront CXInitUncompContextRLFront #define CXiInitUncompContextLZFront CXInitUncompContextLZFront #define CXiInitUncompContextHuffmanFront CXInitUncompContextHuffmanFront #define CXiInitUncompContextLHFront CXInitUncompContextLHFront #define CXiInitUncompContextLRCFront CXInitUncompContextLRCFront #ifdef __cplusplus } /* extern "C" */ #endif /* __CX_STREAMING_UNCOMPRESSION_STREAM_H__ */ #endif