![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Base/Huffman.h>
Huffman code for data compression. More...
Huffman code for data compression.
Public Member Functions | |
unsigned long long | compute (unsigned int *occurrences, unsigned int size) |
Compute code from a raw buffer of occurrences and return resulting byte size. | |
int | storeTree (unsigned char *buffer) const |
Stores the huffman tree in the buffer and returns the number of bytes used. | |
bool | loadTree (const unsigned char *buffer) |
Loads the huffman tree from the buffer. | |
void | clear () |
Clear everything. | |
unsigned char | bits (unsigned short symbol) const |
Return the number of bits for a given symbol. | |
unsigned long long | code (unsigned short symbol) const |
Return the code for a given symbol. | |
template<typename T> | |
int | encode (const T *bufIn, unsigned int size, unsigned char *bufOut, unsigned int bufOutSize, unsigned int &bitPos) |
Encode data, sizes of both input and output buffer are given, along with the latter's bit position. | |
template<typename T> | |
int | decode (const unsigned char *bufIn, int size, T *bufOut) const |
Decode data. | |
void | debugTree (std::ostream &osObject, bool leavesOnly=false, bool charSymbols=false) const |
Output a tabular representation of the huffman tree for debugging purposes. | |
unsigned long long | numBytesForBits (const unsigned long long bitSize) const |
Computes the number of bytes that are needed to store n bits. | |
int storeTree | ( | unsigned char * | buffer | ) | const |
Stores the huffman tree in the buffer and returns the number of bytes used.
Returns 0 in case of too small buffer
bool loadTree | ( | const unsigned char * | buffer | ) |
Loads the huffman tree from the buffer.
Returns true if successful
unsigned char bits | ( | unsigned short | symbol | ) | const |
Return the number of bits for a given symbol.
This method is written for speed, no checking whatsoever is performed.
int encode | ( | const T * | bufIn, |
unsigned int | size, | ||
unsigned char * | bufOut, | ||
unsigned int | bufOutSize, | ||
unsigned int & | bitPos ) |
Encode data, sizes of both input and output buffer are given, along with the latter's bit position.
The bit position will be updated by this method. The number of encoded bytes is returned, if it is smaller than the specified size, the encoded data did not fit into the output buffer, hence this method has to be called again with an increased output buffer size.
int decode | ( | const unsigned char * | bufIn, |
int | size, | ||
T * | bufOut ) const |
Decode data.
Both input and output buffers need to contain sufficient memory to accomodate the size of the data.