Difference between revisions of "YAZ0 (File Format)"
(→Header) |
m (→Data Groups) |
||
Line 31: | Line 31: | ||
=== Data Groups === | === Data Groups === | ||
+ | |||
+ | The complete compressed data is organized in '''data groups'''. Each data group consists of 1 sequence header byte an 8 '''data sequences''': | ||
+ | |||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | ! N !! Size !! Description | ||
+ | |- | ||
+ | | 1 || 1 || the sequence header byte | ||
+ | |- | ||
+ | | 8 || 1-3 || 8 data sequences | ||
+ | |} | ||
+ | |||
+ | Each bit of the sequence header corespondents to one sequence: | ||
+ | * The MSB (most significant bit, 0x80) corespondents to sequence 1 | ||
+ | * The LSB (lowest significant bit, 0x01) corespondents to sequence 8 | ||
+ | |||
+ | A set bit (=1) in the sequence header means, that the sequence is 1 exact 1 byte long. This byte must be copied to the output stream 1:1. A cleared bit (=0) defines, that the sequence is 2 or 3 bytes long interpreted as a back reference to already decompressed data that must be copied. | ||
+ | |||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | ! Size !! 1.B !! 2.B !! 3.B !! Comment | ||
+ | |- | ||
+ | | 2 || NR || RR || - || N=1..f, SIZE=N+2 | ||
+ | |- | ||
+ | | 3 || 0R || RR || NN || N=00..ff, SIZE=N+0x12 | ||
+ | |} | ||
+ | |||
+ | * RRR is a value between 0x000 and 0xfff. Go back RRR+1 bytes in the output stream to find the start of the data to be copied. | ||
+ | * SIZE is the number of bytes to be copied. | ||
+ | |||
+ | Decoding data groups and data sequences are done until the end of the destination data is reached. | ||
== Examples == | == Examples == |
Revision as of 20:47, 6 April 2011
Yaz0 is a run length encoding (RLE compression) method. In Mario Kart Wii most of the SZS files are Yaz0 compressed U8 files.
Data structure
Header
The header of a Yaz0 file is always 16 bytes long. All numeric values stored as big endian values.
Offset | Type | Description |
---|---|---|
0x00 | char[4] | always "Yaz0" |
0x04 | u32 | size of the umompressed data |
0x08 | char[16] | always zero (padding) |
- GNU C example
typedef struct yaz0_header_t { char magic[4]; // always "Yaz0" be32_t uncompressed_size; // total size of uncompressed data char padding[8]; // always 0? } __attribute__ ((packed)) yaz0_header_t;
Data Groups
The complete compressed data is organized in data groups. Each data group consists of 1 sequence header byte an 8 data sequences:
N | Size | Description |
---|---|---|
1 | 1 | the sequence header byte |
8 | 1-3 | 8 data sequences |
Each bit of the sequence header corespondents to one sequence:
- The MSB (most significant bit, 0x80) corespondents to sequence 1
- The LSB (lowest significant bit, 0x01) corespondents to sequence 8
A set bit (=1) in the sequence header means, that the sequence is 1 exact 1 byte long. This byte must be copied to the output stream 1:1. A cleared bit (=0) defines, that the sequence is 2 or 3 bytes long interpreted as a back reference to already decompressed data that must be copied.
Size | 1.B | 2.B | 3.B | Comment |
---|---|---|---|---|
2 | NR | RR | - | N=1..f, SIZE=N+2 |
3 | 0R | RR | NN | N=00..ff, SIZE=N+0x12 |
- RRR is a value between 0x000 and 0xfff. Go back RRR+1 bytes in the output stream to find the start of the data to be copied.
- SIZE is the number of bytes to be copied.
Decoding data groups and data sequences are done until the end of the destination data is reached.