GIF style LZW compressor. More...
Public Member Functions | |
GIFEncoder () | |
Init the encoder to an inert state. | |
uint_t | GetClearCode (void) const |
Return the LZW Clear code. | |
uint_t | GetEOFCode (void) const |
Return the LZW End of File code. | |
void | Init (OutputMemoryStream *pOutput, uint_t uDepth) |
Given a palette depth, create a GIF LZW encoder. | |
void | ClearHash (void) |
Erase the GIF LZW hash. | |
uint_t | LookupHash (uint_t uInput) |
Given a code, create a hash index. | |
void | AddHashEntry (uint_t uKey, uint_t uCode) |
Insert a new code into the hash. | |
void | WriteByte (uint_t uInput) |
Write a byte of data to the GIF byte stream. | |
void | WriteCode (uint_t uCode) |
Given an LZW code, encode it into the bit stream. | |
void | WritePixels (const uint8_t *pInput, uintptr_t uInputLength) |
Encode a scan line of pixels. | |
void | Flush (void) |
Encoding is complete, flush the buffer. | |
Static Public Member Functions | |
static GIFEncoder * | New (void) |
Allocate and initialize a GIFEncoder. | |
static uint_t | GetHashKey (uint_t uInput) |
Create a hash key. | |
static uint_t | GetKey (uint_t uInput) |
Return the LZW key from a hash. | |
static uint_t | PutKey (uint_t uInput) |
Prepare a LZW key to form a key. | |
static uint_t | GetCode (uint_t uInput) |
Return the LZW code from a hash. | |
static uint_t | PutCode (uint_t uInput) |
Prepare a LZW code to form a key. | |
Private Types | |
enum | eEncodingState { ENCODE_INPROGRESS , ENCODE_FINAL } |
Private Attributes | |
OutputMemoryStream * | m_pOutput |
Pointer to the stream to store the compressed data. | |
uint_t | m_uColorDepth |
Number of bits of color data (8 is the default) | |
uint_t | m_uRunningCode |
Current LZW code. | |
uint_t | m_uRunningBits |
Number of valid bits in the current LZW code. | |
uint_t | m_uMaximumRunningCode |
If the current LZW matches this valid, increase bit size. | |
uint_t | m_uCode |
Value being encoded. | |
uint_t | m_uShiftState |
Number of bits in the bit bucket. | |
uint_t | m_uShiftData |
Bit bucket. | |
eEncodingState | m_eEncodingState |
Flag for determining if a flush is needed on destruction. | |
uint_t | m_uBytesInBuffer |
Number of LZW bytes cached before a data flush. | |
uint8_t | m_Buffer [256] |
Buffer of encoded LZW bytes. | |
uint_t | m_HashTable [cHashSize] |
Hash for quick match in the LZW buffer for encoding strings. | |
Static Private Attributes | |
static const uint_t | cHashSize = 1U<<13U |
8192 entry (13 bit) hash table | |
static const uint_t | cHashKeyMask = cHashSize-1U |
Mask for the hash size. | |
static const uint_t | cLZBits = 12U |
Number of bits for an LZW token. | |
static const uint_t | cLZLastCode = (1U<<cLZBits)-1U |
Largest allowable LZW token. | |
static const uint_t | cStartingCode = (1U<<cLZBits) |
Impossible LZW token for alerting encoding hasn't started. | |
GIF style LZW compressor.
This class will compress pixel data into using GIF LZW format
|
private |
Burger::GIFEncoder::GIFEncoder | ( | ) |
Init the encoder to an inert state.
Insert a new code into the hash.
Given a hash key, look for an empty entry in the hash and insert the LZW token into it.
uKey | Hash key (Index into the hash) |
uCode | LZW code |
void Burger::GIFEncoder::ClearHash | ( | void | ) |
Erase the GIF LZW hash.
void Burger::GIFEncoder::Flush | ( | void | ) |
Encoding is complete, flush the buffer.
At the conclusion of compression, call this function to perform cleanup and flush out any cached data
|
inline |
Return the LZW Clear code.
Based on the bit depth, return the code to clear the LZW cache
Return the LZW code from a hash.
uInput | Hash value |
|
inline |
Return the LZW End of File code.
Based on the bit depth, return the code to end decompression of LZW data
Create a hash key.
Given a 16 bit value of the current and previous pixel, return a hash value to index into the hash table
uInput | Value with LZW code shifted left by 8 bits and the pixel in the lower 8 bits |
Return the LZW key from a hash.
uInput | Hash value |
void Burger::GIFEncoder::Init | ( | Burger::OutputMemoryStream * | pOutput, |
uint_t | uDepth ) |
Given a palette depth, create a GIF LZW encoder.
Call this function before any encoding is performed.
pOutput | Pointer to a valid OutputMemoryStream to store the compressed data |
uDepth | Depth of the pixel data in bits (2-8) |
Given a code, create a hash index.
Scan the hash table for a LZW token or return BURGER_MAXUINT if there is no matching entry.
uInput | Encoded pixel and previous pixel |
|
static |
Allocate and initialize a GIFEncoder.
Prepare a LZW code to form a key.
uInput | LZW code |
Prepare a LZW key to form a key.
uInput | LZW token |
void Burger::GIFEncoder::WriteByte | ( | uint_t | uInput | ) |
Write a byte of data to the GIF byte stream.
Cache a byte of output data and send it out as a "pascal" string with a length followed by a stream of data. Only write to the stream when 255 bytes have been accumulated
uInput | 8 bit data to write to the byte stream |
void Burger::GIFEncoder::WriteCode | ( | uint_t | uCode | ) |
Given an LZW code, encode it into the bit stream.
Write out an LZW code using bit packing.
uCode | Bit pattern for LZW code |
void Burger::GIFEncoder::WritePixels | ( | const uint8_t * | pInput, |
uintptr_t | uInputLength ) |
Encode a scan line of pixels.
Given a scan line of pixels, compress using LZW. Assume the pixels are bytes.
pInput | Pointer to an array of pixels for a single scan line |
uInputLength | Number of pixels to encode |
|
staticprivate |
8192 entry (13 bit) hash table
|
staticprivate |
Number of bits for an LZW token.
Largest allowable LZW token.
Impossible LZW token for alerting encoding hasn't started.
|
private |
Buffer of encoded LZW bytes.
|
private |
Flag for determining if a flush is needed on destruction.
Hash for quick match in the LZW buffer for encoding strings.
|
private |
Pointer to the stream to store the compressed data.
|
private |
Number of LZW bytes cached before a data flush.
|
private |
Value being encoded.
|
private |
Number of bits of color data (8 is the default)
|
private |
If the current LZW matches this valid, increase bit size.
|
private |
Number of valid bits in the current LZW code.
|
private |
Current LZW code.
|
private |
Bit bucket.
|
private |
Number of bits in the bit bucket.