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 | ||
) |
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.
Referenced by claw::graphic::gif::reader::decode_data().
{ const unsigned int symbols_count = input.symbols_count(); table_type table; unsigned int table_size = 0; unsigned int prefix = input.get_next(); if ( !input.end_of_data() ) { while ( !input.end_of_data() ) { unsigned int suffix = input.get_next(); if (!input.end_of_data() ) { unsigned int new_suffix; if ( suffix < table_size + symbols_count ) new_suffix = get_first_symbol(table, suffix, symbols_count); else new_suffix = get_first_symbol(table, prefix, symbols_count); table.push_back( word_type(prefix, new_suffix) ); ++table_size; input.new_code(table_size + symbols_count); decompose( table, prefix, symbols_count, output ); prefix = suffix; } } decompose( table, prefix, symbols_count, output ); } } // 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 [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.
{ std::list<unsigned int> result; while ( code >= symbols_count ) { result.push_front( table[code - symbols_count].second ); code = table[code - symbols_count].first; } result.push_front(code); std::list<unsigned int>::const_iterator it; for (it=result.begin(); it!=result.end(); ++it) output.write( *it ); } // 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 [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.
{ unsigned int result = code; while ( result >= symbols_count ) result = table[result - symbols_count].first; return result; } // lzw_decoder::get_first_symbol()