A class to help decoding a stream encoded with Lempel-Ziv-Welch (LZW) compression algorithm. More...
#include <lzw_decoder.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 | decode (input_buffer_type &input, output_buffer_type &output) |
Decode a sequence of LZW compressed datas. | |
Private Types | |
typedef std::pair< unsigned int, unsigned int > | word_type |
typedef std::vector< word_type > | table_type |
Private Member Functions | |
unsigned int | get_first_symbol (const table_type &table, const unsigned int code, const unsigned int symbols_count) const |
Get the first symbol of a string, represented by a code. | |
void | decompose (const table_type &table, unsigned int code, const unsigned int symbols_count, output_buffer_type &output) const |
Write a string, represented by a code, in the ouput buffer. |
A class to help decoding a stream encoded 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 61 of file lzw_decoder.hpp.
typedef InputBuffer claw::lzw_decoder< InputBuffer, OutputBuffer >::input_buffer_type |
The type of the input buffer.
Definition at line 65 of file lzw_decoder.hpp.
typedef OutputBuffer claw::lzw_decoder< InputBuffer, OutputBuffer >::output_buffer_type |
The type of the output buffer.
Definition at line 68 of file lzw_decoder.hpp.
typedef std::vector<word_type> claw::lzw_decoder< InputBuffer, OutputBuffer >::table_type [private] |
Definition at line 72 of file lzw_decoder.hpp.
typedef std::pair<unsigned int, unsigned int> claw::lzw_decoder< InputBuffer, OutputBuffer >::word_type [private] |
Definition at line 71 of file lzw_decoder.hpp.
void claw::lzw_decoder< InputBuffer, OutputBuffer >::decode | ( | input_buffer_type & | input, | |
output_buffer_type & | output | |||
) | [inline] |
Decode a sequence of LZW compressed datas.
input | Where we read the compressed datas. | |
output | Where we write uncompressed datas. |
Definition at line 40 of file lzw_decoder.tpp.
00041 { 00042 const unsigned int symbols_count = input.symbols_count(); 00043 00044 table_type table; 00045 unsigned int table_size = 0; 00046 00047 unsigned int prefix = input.get_next(); 00048 00049 if ( !input.end_of_data() ) 00050 { 00051 while ( !input.end_of_data() ) 00052 { 00053 unsigned int suffix = input.get_next(); 00054 00055 if (!input.end_of_data() ) 00056 { 00057 unsigned int new_suffix; 00058 00059 if ( suffix < table_size + symbols_count ) 00060 new_suffix = get_first_symbol(table, suffix, symbols_count); 00061 else 00062 new_suffix = get_first_symbol(table, prefix, symbols_count); 00063 00064 table.push_back( word_type(prefix, new_suffix) ); 00065 ++table_size; 00066 input.new_code(table_size + symbols_count); 00067 00068 decompose( table, prefix, symbols_count, output ); 00069 prefix = suffix; 00070 } 00071 } 00072 00073 decompose( table, prefix, symbols_count, output ); 00074 } 00075 } // lzw_decoder::decode()
void claw::lzw_decoder< InputBuffer, OutputBuffer >::decompose | ( | const table_type & | table, | |
unsigned int | code, | |||
const unsigned int | symbols_count, | |||
output_buffer_type & | output | |||
) | const [inline, private] |
Write a string, represented by a code, in the ouput buffer.
table | The table of codes. | |
code | The code of the string to write. | |
symbols_count | The count of atomic codes. | |
output | Where we write the uncompressed datas. |
Definition at line 107 of file lzw_decoder.tpp.
00109 { 00110 std::list<unsigned int> result; 00111 00112 while ( code >= symbols_count ) 00113 { 00114 result.push_front( table[code - symbols_count].second ); 00115 code = table[code - symbols_count].first; 00116 } 00117 00118 result.push_front(code); 00119 00120 std::list<unsigned int>::const_iterator it; 00121 00122 for (it=result.begin(); it!=result.end(); ++it) 00123 output.write( *it ); 00124 00125 } // lzw_decoder::decompose()
unsigned int claw::lzw_decoder< InputBuffer, OutputBuffer >::get_first_symbol | ( | const table_type & | table, | |
const unsigned int | code, | |||
const unsigned int | symbols_count | |||
) | const [inline, private] |
Get the first symbol of a string, represented by a code.
table | The table of codes. | |
code | The code of the string from which we want the first symbol. | |
symbols_count | The count of atomic codes. |
Definition at line 86 of file lzw_decoder.tpp.