1 /*---------------------------------------------------------------------------*
2   Project:     Compress/uncompress library
3   File:        CXCompression.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: CXCompression.h,v $
14   Revision 1.9  2007/05/30 04:20:56  takano_makoto
15   Added CXCompressLZEx.
16 
17   Revision 1.8  2007/05/18 10:50:39  yasuh-to
18   Rolled back to SYSTEMMENU2_DEV_BRANCH(HEAD)
19 
20   Revision 1.5  2006/07/06 09:19:14  takano_makoto
21   Changed the include guard to the REVOLUTION_SDK format
22 
23   Revision 1.4  2006/07/05 11:14:34  takano_makoto
24   Changed MI_LZ_COMPRESS_WORK_SIZE to CX_LZ_COMPRESS_WORK_SIZE
25   Revised the include guard
26 
27   Revision 1.3  2006/07/04 13:19:40  takano_makoto
28   Changed LZ compression to the high-speed version using work buffer
29 
30   Revision 1.2  2006/07/04 08:25:25  takano_makoto
31   Changed the prefix from the DS version
32 
33   $NoKeywords: $
34  *---------------------------------------------------------------------------*/
35 
36 
37 #ifndef __CX_COMPRESS_H__
38 #define __CX_COMPRESS_H__
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 #include <dolphin/types.h>
45 
46 
47 #define CX_LZ_COMPRESS_WORK_SIZE   ( (4096 + 256 + 256) * sizeof(s16) )
48 
49 /*---------------------------------------------------------------------------*
50   Name:         CXCompressLZ
51 
52   Description:  Function that performs LZ77 compression
53 
54   Arguments:    srcp            Pointer to compression source data
55                 size            Size of compression source data
56                 dstp            Pointer to compressed data
57                                 Buffer must be larger than size of compression source data.
58                 work            Temporary buffer for compression
59                                 A region for the size of CX_LZ_COMPRESS_WORK_SIZE is necessary.
60 
61   Returns:      The data size after compression.
62                 If compressed data is larger than original data, compression is terminated and 0 is returned.
63  *---------------------------------------------------------------------------*/
64 u32 CXCompressLZImpl(const u8 *srcp, u32 size, u8 *dstp, void *work, BOOL exFormat);
65 
CXCompressLZEx(const u8 * srcp,u32 size,u8 * dstp,void * work)66 inline u32 CXCompressLZEx(const u8 *srcp, u32 size, u8 *dstp, void* work)
67 {
68     return CXCompressLZImpl( srcp, size, dstp, work, TRUE );
69 }
CXCompressLZ(const u8 * srcp,u32 size,u8 * dstp,void * work)70 inline u32 CXCompressLZ(const u8 *srcp, u32 size, u8 *dstp, void *work)
71 {
72     return CXCompressLZImpl( srcp, size, dstp, work, FALSE );
73 }
74 
75 
76 /*---------------------------------------------------------------------------*
77   Name:         CXCompressRL
78 
79   Description:  Function that performs run-length compression
80 
81   Arguments:    srcp            Pointer to compression source data
82                 size            Size of compression source data
83                 dstp            Pointer to compressed data
84                                 Buffer must be larger than size of compression source data.
85 
86   Returns:      The data size after compression.
87                 If compressed data is larger than original data, compression is terminated and 0 is returned.
88  *---------------------------------------------------------------------------*/
89 u32 CXCompressRL( const u8 *srcp, u32 size, u8 *dstp );
90 
91 
92 #define CX_HUFFMAN_COMPRESS_WORK_SIZE   ( 12288 + 512 + 1536 )
93 
94 
95 /*---------------------------------------------------------------------------*
96   Name:         CXCompressHuffman
97 
98   Description:  Function that performs Huffman compression
99 
100   Arguments:    srcp            Pointer to compression source data
101                 size            Size of compression source data
102                 dstp            Pointer to compressed data
103                                 Buffer must be larger than size of compression source data.
104                 huffBitSize     The number of bits to encode
105                 work            The work buffer for compression that requires a size of CX_HUFFMAN_COMPRESS_WORK_SIZE.
106 
107   Returns:      The data size after compression.
108                 If compressed data is larger than original data, compression is terminated and 0 is returned.
109  *---------------------------------------------------------------------------*/
110 u32 CXCompressHuffman( const u8 *srcp, u32 size, u8 *dstp, u8 huffBitSize, void *work );
111 
112 
113 #ifdef __cplusplus
114 } /* extern "C" */
115 #endif
116 
117 /* __CX_COMPRESS_H__ */
118 #endif
119