GIF style LZW compressor.
More...
GIF style LZW compressor.
This class will compress pixel data into using GIF LZW format
- See also
- FileGIF or GIFDecoder
◆ eEncodingState
Enumerator |
---|
ENCODE_INPROGRESS | Encoding is in progress.
|
ENCODE_FINAL | Encoding is complete, don't output to the stream anymore.
|
◆ GIFEncoder()
Burger::GIFEncoder::GIFEncoder |
( |
| ) |
|
Init the encoder to an inert state.
◆ AddHashEntry()
void Burger::GIFEncoder::AddHashEntry |
( |
uint_t | uKey, |
|
|
uint_t | uCode ) |
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.
- Parameters
-
uKey | Hash key (Index into the hash) |
uCode | LZW code |
◆ ClearHash()
void Burger::GIFEncoder::ClearHash |
( |
void | | ) |
|
◆ Flush()
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
◆ GetClearCode()
uint_t Burger::GIFEncoder::GetClearCode |
( |
void | | ) |
const |
|
inline |
Return the LZW Clear code.
Based on the bit depth, return the code to clear the LZW cache
- Returns
- LZW clear code
◆ GetCode()
Return the LZW code from a hash.
- Parameters
-
- Returns
- LZW code
◆ GetEOFCode()
uint_t Burger::GIFEncoder::GetEOFCode |
( |
void | | ) |
const |
|
inline |
Return the LZW End of File code.
Based on the bit depth, return the code to end decompression of LZW data
- Returns
- LZW EOF code
◆ GetHashKey()
static uint_t Burger::GIFEncoder::GetHashKey |
( |
uint_t | uInput | ) |
|
|
inlinestatic |
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
- Parameters
-
uInput | Value with LZW code shifted left by 8 bits and the pixel in the lower 8 bits |
- Returns
- Hash of the key
◆ GetKey()
Return the LZW key from a hash.
- Parameters
-
- Returns
- LZW Key
◆ Init()
Given a palette depth, create a GIF LZW encoder.
Call this function before any encoding is performed.
- Parameters
-
pOutput | Pointer to a valid OutputMemoryStream to store the compressed data |
uDepth | Depth of the pixel data in bits (2-8) |
◆ LookupHash()
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.
- Parameters
-
uInput | Encoded pixel and previous pixel |
- Returns
- BURGER_MAXUINT on error or a valid 12 bit hash index
◆ New()
◆ PutCode()
Prepare a LZW code to form a key.
- Parameters
-
- Returns
- Code shifted to a position for a key
◆ PutKey()
Prepare a LZW key to form a key.
- Parameters
-
- Returns
- Token shifted to a position for a key
◆ WriteByte()
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
- Parameters
-
uInput | 8 bit data to write to the byte stream |
◆ WriteCode()
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.
- Parameters
-
uCode | Bit pattern for LZW code |
◆ WritePixels()
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.
- Parameters
-
pInput | Pointer to an array of pixels for a single scan line |
uInputLength | Number of pixels to encode |
◆ cHashKeyMask
◆ cHashSize
const uint_t Burger::GIFEncoder::cHashSize = 1U<<13U |
|
staticprivate |
8192 entry (13 bit) hash table
◆ cLZBits
const uint_t Burger::GIFEncoder::cLZBits = 12U |
|
staticprivate |
Number of bits for an LZW token.
◆ cLZLastCode
Largest allowable LZW token.
◆ cStartingCode
Impossible LZW token for alerting encoding hasn't started.
◆ m_Buffer
uint8_t Burger::GIFEncoder::m_Buffer[256] |
|
private |
Buffer of encoded LZW bytes.
◆ m_eEncodingState
Flag for determining if a flush is needed on destruction.
◆ m_HashTable
Hash for quick match in the LZW buffer for encoding strings.
◆ m_pOutput
Pointer to the stream to store the compressed data.
◆ m_uBytesInBuffer
uint_t Burger::GIFEncoder::m_uBytesInBuffer |
|
private |
Number of LZW bytes cached before a data flush.
◆ m_uCode
uint_t Burger::GIFEncoder::m_uCode |
|
private |
◆ m_uColorDepth
uint_t Burger::GIFEncoder::m_uColorDepth |
|
private |
Number of bits of color data (8 is the default)
◆ m_uMaximumRunningCode
uint_t Burger::GIFEncoder::m_uMaximumRunningCode |
|
private |
If the current LZW matches this valid, increase bit size.
◆ m_uRunningBits
uint_t Burger::GIFEncoder::m_uRunningBits |
|
private |
Number of valid bits in the current LZW code.
◆ m_uRunningCode
uint_t Burger::GIFEncoder::m_uRunningCode |
|
private |
◆ m_uShiftData
uint_t Burger::GIFEncoder::m_uShiftData |
|
private |
◆ m_uShiftState
uint_t Burger::GIFEncoder::m_uShiftState |
|
private |
Number of bits in the bit bucket.