"L. Spiro Engine"
|
A dictionary for the encoding of a bytestream using the LZW algorithm. More...
#include <LSCLzwEncodingDict.h>
Classes | |
struct | LSN_LZW_DICT_ENTRY |
Public Types | |
enum | LSN_LZW_INVALID_CODE { LSN_LZW_INVALID_CODE = ~0UL, LSN_LZW_FORCE_DWORD = 0x7FFFFFFFUL } |
typedef struct lsc::CLzwEncodingDict::LSN_LZW_DICT_ENTRY * | LPLSN_LZW_DICT_ENTRY |
typedef struct lsc::CLzwEncodingDict::LSN_LZW_DICT_ENTRY | LPCLSN_LZW_DICT_ENTRY |
Public Member Functions | |
LSVOID LSE_CALL | Reset () |
LSVOID LSE_CALL | SetAllocator (CStdAllocator *_psaAllocator) |
LSBOOL LSE_CALL | InitDict (LSUINT32 _ui32RootCodes, LSUINT32 _ui32MaxBits) |
LSUINT32 LSE_CALL | GetEntryIndex (LSUINT32 _ui32Code, LSUINT32 _ui32Char) const |
const LSN_LZW_DICT_ENTRY &LSE_CALL | GetEntry (LSUINT32 _ui32Index) const |
LSVOID LSE_CALL | AddEntry (LSUINT32 _ui32Index, LSUINT32 _ui32BaseCode, LSUINT32 _ui32Char) |
LSUINT32 LSE_CALL | TotalEntries () const |
LSUINT32 LSE_CALL | GetMaxDictionarySize () const |
LSUINT32 LSE_CALL | GetStartingBits () const |
LSUINT32 LSE_CALL | GetResetCode () const |
LSUINT32 LSE_CALL | GetEndStreamCode () const |
LSUINT32 LSE_CALL | GetBits () const |
Protected Attributes | |
CAllocator | m_caAllocator |
LSUINT32 | m_ui32AllocatedDictSize |
LSUINT32 | m_ui32MaxBits |
LSUINT32 | m_ui32DictSize |
LSUINT16 | m_ui16MinBits |
LSUINT16 | m_ui16StartingBits |
LSUINT32 | m_ui32RootCodes |
LPLSN_LZW_DICT_ENTRY | m_lpldeDictionary |
A dictionary for the encoding of a bytestream using the LZW algorithm.
Class CLzwEncodingDict Description: When encoding bytes, the dictionary for the LZW algorithm is stored differently from when the bytes are being decoded. During encryption, codes are referenced via (code+char) combination which requires a hash look-up. For this reason, we cannot store the codes in such a way that index = code. During decoding, however, codes are referenced only by code, so we are able to store the codes linearly such that index = code. This saves space over the encoding algorithm and gives us cause to keep the two dictionaries separate. The dictionary is created with a maximum size at the beginning, which depends on the maximum number of bits a code may have. This class can output variable-sized codes or predefined-sized codes as per the desires of the user. Variable-sized codes simply means that the smallest number of bits needed to access any code in the dictionary are output instead of using a fixed size such as 15 bits for every code. This is the typical method for encoding.
typedef struct lsc::CLzwEncodingDict::LSN_LZW_DICT_ENTRY * lsc::CLzwEncodingDict::LPLSN_LZW_DICT_ENTRY |
A dictionary entry.
Flags we use.
LSVOID LSE_CALL lsc::CLzwEncodingDict::AddEntry | ( | LSUINT32 | _ui32Index, |
LSUINT32 | _ui32BaseCode, | ||
LSUINT32 | _ui32Char | ||
) |
Add an entry at a given index. The index must have been returned by a previous call to GetEntryIndex() and must be unused.
_ui32Index | Index, returned by a previous call to GetEntryIndex(), where the code is to be added. |
_ui32BaseCode | The base code of the new code to be added. The base code is the code of an existing entry off which this entry is based. This entry extends the base code by one character, given in _ui32Char. |
_ui32Char | The character by which the new code extends the base code. |
LSUINT32 LSE_CALL lsc::CLzwEncodingDict::GetBits | ( | ) | const |
Get the bits needed to read any code in the dictionary.
LSUINT32 LSE_CALL lsc::CLzwEncodingDict::GetEndStreamCode | ( | ) | const |
Get the end-stream code.
const LSN_LZW_DICT_ENTRY& LSE_CALL lsc::CLzwEncodingDict::GetEntry | ( | LSUINT32 | _ui32Index | ) | const |
Get an entry by index for read only. The entry is not guaranteed to contain a valid code.
_ui32Index | Index of the entry to retrieve. |
LSUINT32 LSE_CALL lsc::CLzwEncodingDict::GetEntryIndex | ( | LSUINT32 | _ui32Code, |
LSUINT32 | _ui32Char | ||
) | const |
Get the index of an entry in the dictionary. If the entry does not exist, the returned index is where it should be added to the dictionary.
_ui32Code | The code of the entry to find. |
_ui32Char | The allocator to use by this class. |
LSUINT32 LSE_CALL lsc::CLzwEncodingDict::GetMaxDictionarySize | ( | ) | const |
Get the maximum dictionary size.
LSUINT32 LSE_CALL lsc::CLzwEncodingDict::GetResetCode | ( | ) | const |
Get the reset-dictionary code.
LSUINT32 LSE_CALL lsc::CLzwEncodingDict::GetStartingBits | ( | ) | const |
Get the number of bits needed at the beginning of the dictionary (when the dictionary is set to its root size).
LSBOOL LSE_CALL lsc::CLzwEncodingDict::InitDict | ( | LSUINT32 | _ui32RootCodes, |
LSUINT32 | _ui32MaxBits | ||
) |
Begin a compression. We need to know the maximum number of bits to create the dictionary. The dictionary can be cleared and recreated many times during compression.
_ui32RootCodes | The default dictionary is composed of this number of root codes. |
_psaAllocator | The allocator to use by this class. |
LSVOID LSE_CALL lsc::CLzwEncodingDict::Reset | ( | ) |
Reset everything. Deallocates all resources.
LSVOID LSE_CALL lsc::CLzwEncodingDict::SetAllocator | ( | CStdAllocator * | _psaAllocator | ) |
Set the allocator. If different from the current allocator, the dictionary is reset.
_psaAllocator | The allocator to use by this class. |
LSUINT32 LSE_CALL lsc::CLzwEncodingDict::TotalEntries | ( | ) | const |
Get the size of the dictionary.
CAllocator lsc::CLzwEncodingDict::m_caAllocator [protected] |
Our allocator.
The dictionary.
LSUINT16 lsc::CLzwEncodingDict::m_ui16MinBits [protected] |
The minimum number of bits needed to access every entry in the dictionary.
LSUINT16 lsc::CLzwEncodingDict::m_ui16StartingBits [protected] |
The starting size of each entry in bits.
LSUINT32 lsc::CLzwEncodingDict::m_ui32AllocatedDictSize [protected] |
Allocated size of the dictionary.
LSUINT32 lsc::CLzwEncodingDict::m_ui32DictSize [protected] |
Actual number of entries in the dictionary.
LSUINT32 lsc::CLzwEncodingDict::m_ui32MaxBits [protected] |
Maximum bits in the dictionary entries.
LSUINT32 lsc::CLzwEncodingDict::m_ui32RootCodes [protected] |
Root codes.