1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - MI - include
3   File:     compress.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-17#$
14   $Rev: 8556 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef NITRO_MI_COMPRESS_H_
19 #define NITRO_MI_COMPRESS_H_
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #include <nitro/misc.h>
26 #include <nitro/types.h>
27 
28 
29 /*---------------------------------------------------------------------------*
30   Name:         MI_CompressLZ
31                 MI_CompressLZFast
32 
33   Description:  Function that performs LZ77 compression
34                 In the high-speed version of MI_CompressLZFast, a work buffer the size in bytes of MI_LZ_FAST_COMPRESS_WORK_SIZE is necessary.
35 
36 
37   Arguments:    srcp:            Pointer to compression source data
38                 size:            Size of compression source data
39                 dstp:            Pointer to compressed data
40                                 The buffer must be larger than the size of the compression source data.
41 
42   Returns:      The data size after compression.
43                 If compressed data is larger than original data, compression is terminated and 0 is returned.
44  *---------------------------------------------------------------------------*/
45 u32     MI_CompressLZImpl(const u8 *srcp, u32 size, u8 *dstp, BOOL exFormat);
46 u32     MI_CompressLZFastImpl(const u8 *srcp, u32 size, u8 *dstp, u8 *work, BOOL exFormat);
47 
MI_CompressLZ(const u8 * srcp,u32 size,u8 * dstp)48 static inline u32 MI_CompressLZ(const u8 *srcp, u32 size, u8 *dstp)
49 {
50     return MI_CompressLZImpl( srcp, size, dstp, FALSE );
51 }
MI_CompressLZEx(const u8 * srcp,u32 size,u8 * dstp)52 static inline u32 MI_CompressLZEx(const u8 *srcp, u32 size, u8 *dstp)
53 {
54     return MI_CompressLZImpl( srcp, size, dstp, TRUE );
55 }
MI_CompressLZFast(const u8 * srcp,u32 size,u8 * dstp,u8 * work)56 static inline u32 MI_CompressLZFast(const u8 *srcp, u32 size, u8 *dstp, u8 *work)
57 {
58     return MI_CompressLZFastImpl( srcp, size, dstp, work, FALSE );
59 }
MI_CompressLZExFast(const u8 * srcp,u32 size,u8 * dstp,u8 * work)60 static inline u32 MI_CompressLZExFast(const u8 *srcp, u32 size, u8 *dstp, u8 *work)
61 {
62     return MI_CompressLZFastImpl( srcp, size, dstp, work, TRUE );
63 }
64 
65 
66 #define MI_LZ_FAST_COMPRESS_WORK_SIZE   ( (4096 + 256 + 256) * sizeof(s16) )
67 
68 
69 
70 /*---------------------------------------------------------------------------*
71   Name:         MI_CompressRL
72 
73   Description:  Function that performs run-length compression
74 
75   Arguments:    srcp:            Pointer to compression source data
76                 size:            Size of compression source data
77                 dstp:            Pointer to compressed data
78                                 The buffer must be larger than the size of the compression source data.
79 
80   Returns:      The data size after compression.
81                 If compressed data is larger than original data, compression is terminated and 0 is returned.
82  *---------------------------------------------------------------------------*/
83 u32     MI_CompressRL(const u8 *srcp, u32 size, u8 *dstp);
84 
85 
86 #define MI_HUFFMAN_COMPRESS_WORK_SIZE   ( 12288 + 512 + 1536 )
87 
88 /*---------------------------------------------------------------------------*
89   Name:         MI_CompressHuffman
90 
91   Description:  Function that performs Huffman compression
92 
93   Arguments:    srcp:            Pointer to compression source data
94                 size:            Size of compression source data
95                 dstp:            Pointer to compressed data
96                                 The buffer must be larger than the size of the compression source data.
97                 huffBitSize     The number of bits to encode
98                 work:           The work buffer for compression; requires the size of MI_HUFFMAN_COMPRESS_WORK_SIZE.
99 
100   Returns:      The data size after compression.
101                 If compressed data is larger than original data, compression is terminated and 0 is returned.
102  *---------------------------------------------------------------------------*/
103 u32     MI_CompressHuffman(const u8 *srcp, u32 size, u8 *dstp, u8 huffBitSize, u8 *work);
104 
105 
106 #ifdef __cplusplus
107 } /* extern "C" */
108 #endif
109 
110 /* NITRO_MI_COMPRESS_H_ */
111 #endif
112