claw::lzw_decoder< InputBuffer, OutputBuffer > Class Template Reference

A class to help decoding a stream encoded with Lempel-Ziv-Welch (LZW) compression algorithm. More...

#include <lzw_decoder.hpp>

List of all members.

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_typetable_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.

Detailed Description

template<typename InputBuffer, typename OutputBuffer>
class claw::lzw_decoder< InputBuffer, OutputBuffer >

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:

Author:
Julien Jorge

Definition at line 61 of file lzw_decoder.hpp.


Member Typedef Documentation

template<typename InputBuffer , typename OutputBuffer >
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.

template<typename InputBuffer , typename OutputBuffer >
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.

template<typename InputBuffer , typename OutputBuffer >
typedef std::vector<word_type> claw::lzw_decoder< InputBuffer, OutputBuffer >::table_type [private]

Definition at line 72 of file lzw_decoder.hpp.

template<typename InputBuffer , typename OutputBuffer >
typedef std::pair<unsigned int, unsigned int> claw::lzw_decoder< InputBuffer, OutputBuffer >::word_type [private]

Definition at line 71 of file lzw_decoder.hpp.


Member Function Documentation

template<typename InputBuffer , typename OutputBuffer >
void claw::lzw_decoder< InputBuffer, OutputBuffer >::decode ( input_buffer_type input,
output_buffer_type output 
) [inline]

Decode a sequence of LZW compressed datas.

Parameters:
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()

template<typename InputBuffer , typename OutputBuffer >
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.

Parameters:
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()

template<typename InputBuffer , typename OutputBuffer >
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.

Parameters:
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.

00088 {
00089   unsigned int result = code;
00090 
00091   while ( result >= symbols_count )
00092     result = table[result - symbols_count].first;
00093 
00094   return result;
00095 } // lzw_decoder::get_first_symbol()


The documentation for this class was generated from the following files:

Generated on 9 Nov 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.6.1