The SAGA_RLE1 compression format is used for SAGA Image resources.
The first byte in an SAGA_RLE1 encoded data stream is a guaranteed to be a RLE marker. (mark_byte). The end of one marker sequence is immediately followed by another RLE marker. A RLE marker of 0 ends the decoding stream.
The two most significant bits of the marker byte determine the marker type, one of which is a subgroup of 3 additional marker types.
Short Uncompressed Run [ Uncompressed run of <= 63 bytes ]
[ ( mark_byte & 0xC0 ) ==0xC0 ]
Type | Name | Description |
BYTE | mark_byte | The runcount is given by ( mark_byte & 0x3F ) |
BYTE | data[ mark_byte & 0x3F ] | Uncompressed data |
Short Compressed Run [ Compressed run of <= 63 bytes ]
[ ( mark_byte & 0xC0 ) == 0x80 ]
Type | Name | Description |
BYTE | mark_byte | The runcount is given by ( mark_byte & 0x3F ) + 3 |
BYTE | data_byte | Data byte to repeat [runcount] times. |
Short Repeat - Previously decoded data is repeated [ repeat run of <= 10 bytes ]
[ ( mark_byte & 0xC0 ) = 0x40 ]
Type | Name | Description |
BYTE | mark_byte | The runcount is given by ( ( mark_byte >> 3 ) & 0x07 ) + 3 |
BYTE | backtrack_amt | Data is repeated beginning at current decode position minus [backtrack_amt] for [runcount] times. |
RLE Marker Subgroup Indicator
[ ( mark_byte & 0xC0 ) == 0x00 ]
If the two highest-order bits of the mark byte are not set, then the next two highest-order bits determine the type of RLE marker from the following:
Bitfield Encoding
- Data is encoded by a bit pattern, with two colors associated to set or cleared bits.
[ ( mark_byte & 0x30 ) == 0x30 ]
Type | Name | Description |
BYTE | mark_byte | The runcount is given by ( mark_byte & 0x0F ) + 1 |
BYTE | data_byte1 | Data byte corresponding to cleared bit state |
BYTE | data_byte2 | Data byte corresponding to set bit state |
BYTE | bitfield_byte[ runcount ] | [runcount] number of bitfields encoding 8 compressed pixels each |
Long Uncompressed Run
[ ( mark_byte & 0x30 ) == 0x20 ]
Type | Name | Description |
BYTE | mark_byte | The runcount is given by ( ( mark_byte & 0x0F ) << 8 ) + run_addend |
BYTE | run_addend | See above |
BYTE | data[ runcount ] | Uncompressed data |
Long Repeat - Similar concept as Short Repeat above
[ ( mark_byte & 0x30 ) == 0x10 ]
Type | Name | Description |
BYTE | mark_byte | The backtrack amount is given by ( ( mark_byte & 0x0F ) << 8 ) + run_addend |
BYTE | run_addend | See above |
BYTE | runcount | Number of bytes to repeat from output stream |