A class to help encoding a stream with Lempel-Ziv-Welch (LZW) compression algorithm. More...
#include <lzw_encoder.hpp>
Public Types | |
typedef InputBuffer | input_buffer_type |
The type of the input buffer. | |
typedef OutputBuffer | output_buffer_type |
The type of the output buffer. | |
Public Member Functions | |
void | encode (input_buffer_type &input, output_buffer_type &output) const |
Encode a sequence of datas. |
A class to help encoding a stream with Lempel-Ziv-Welch (LZW) compression algorithm.
Template parameters:
The InputBuffer type must have the following methods:
The OutputBuffer type must have the following methods:
Definition at line 60 of file lzw_encoder.hpp.
typedef InputBuffer claw::lzw_encoder< InputBuffer, OutputBuffer >::input_buffer_type |
The type of the input buffer.
Definition at line 64 of file lzw_encoder.hpp.
typedef OutputBuffer claw::lzw_encoder< InputBuffer, OutputBuffer >::output_buffer_type |
The type of the output buffer.
Definition at line 67 of file lzw_encoder.hpp.
void claw::lzw_encoder< InputBuffer, OutputBuffer >::encode | ( | input_buffer_type & | input, | |
output_buffer_type & | output | |||
) | const [inline] |
Encode a sequence of datas.
input | Where we read the uncompressed data. | |
output | Where we write compressed data. |
Definition at line 16 of file lzw_encoder.tpp.
00017 { 00018 typedef std::pair<unsigned int, unsigned int> word; 00019 00020 if ( !input.end_of_data() ) 00021 { 00022 std::map<word, unsigned int> table; 00023 00024 unsigned int symbol = input.get_next(); 00025 unsigned int prefix_code = symbol; 00026 unsigned int next_code = input.symbols_count(); 00027 00028 while ( !input.end_of_data() && (next_code != output.max_code()) ) 00029 { 00030 symbol = input.get_next(); 00031 00032 word new_word(prefix_code, symbol); 00033 00034 if ( table.find(new_word) != table.end() ) 00035 prefix_code = table[new_word]; 00036 else 00037 { 00038 output.write(prefix_code); 00039 output.new_code(next_code); 00040 table[new_word] = next_code; 00041 prefix_code = symbol; 00042 00043 ++next_code; 00044 } 00045 } 00046 00047 output.write(prefix_code); 00048 } 00049 } // lzw_encoder::encode()