# MI_CompressLZ*

## Syntax

  `#include <nitro/mi.h>`
  `u32 MI_CompressLZ( const u8 *srcp, u32 size, u8 *dstp );
  u32 MI_CompressLZFast( const u8 *srcp, u32 size, u8 *dstp, u8* work );
  u32 MI_CompressLZEx( const u8 *srcp, u32 size, u8 *dstp );
  u32 MI_CompressLZExFast( const u8 *srcp, u32 size, u8 *dstp, u8* work );
  `

## Arguments

srcp | Source address where the data to compress is stored.
size | Data size of the source to compress.
dstp | Needs a pointer to the compression destination buffer and a region greater than the source data size. Needs a 4-byte alignment.
work | Temporary work buffer used for data compression required by the `MI_CompressLZ*Fast()` line of functions. The number of bytes given by `MI_LZ_FAST_COMPRESS_WORK_SIZE` is required.

## Return Values

Returns the size of the compressed data. If the data after compression is larger than the source file, no compression will be performed and a 0 will be returned.

## Description

Performs LZ77 compression on the data, then writes it to a specified memory region. A region of the same size as the source data must be prepared in the compression destination buffer.

When using functions having "Fast" as a suffix, processing is performed several times faster than with standard functions through the use of a work buffer while searching the slide dictionary.
This process may take some time to complete, depending on the source data, because a simple search of the slide dictionary is carried out by an API that does not specify a work buffer.

Although you can expect a higher compression ratio when using LZ77 extended compression (`MI_CompressLZEx*` functions) than when using conventional LZ77 compression, more consistent compression times may be possible when using `MI_CompressLZFast` when one considers that the worst case compression time with LZ77 extended compression is several times longer than the worst case when using the conventional `MI_CompressLZFast` function. Decompression speed is about the same with either method.
Although the `MI_UncompressLZ*` functions or the `MI_ReadUncompLZ` function can be used to decompress data regardless of which compression method was used, note that files compressed using LZ77 extended compression cannot be decompressed by programs that use an SDK version before NITRO-SDK 4.2.

The function writes in 8-bit units, so for NITRO, an address in VRAM cannot be specified in dstp.
An address in VRAM can be specified in srcp for both NITRO and TWL.

## Internal Operation

Processing takes place only on the CPU, without the use of a system call or DMA.

## See Also

`MI_UncompressLZ*`
`MI_ReadUncompLZ`
`MI_CompressRL`
`MI_CompressHuffman`

## Revision History

2008/12/05 Added TWL-related description.
2007/11/01 Added LZ77 extended compression. Integrated `MI_CompressLZ*` series API reference.
2005/02/01 Initial version.

CONFIDENTIAL