CLAW Library (a C++ Library Absolutely Wonderful) 1.5.5
Public Types | Public Member Functions | Private Types

claw::rle_encoder< OutputBuffer > Class Template Reference

A class to help run-length encoding (RLE) streams. More...

#include <rle_encoder.hpp>

List of all members.

Public Types

typedef OutputBuffer output_buffer_type
 The type of the output buffer.
typedef
output_buffer_type::pattern_type 
pattern_type
 The type of the stored data.

Public Member Functions

template<typename Iterator >
void encode (Iterator first, Iterator last, output_buffer_type &output) const
 Encode a range of datas.

Private Types

typedef std::list< pattern_typeraw_buffer_type
 The type of the buffer on which we store the raw data.

Detailed Description

template<typename OutputBuffer>
class claw::rle_encoder< OutputBuffer >

A class to help run-length encoding (RLE) streams.

Template parameters :

The OutputBuffer type must have the following typedefs :

The OutputBuffer type must have the following methods :

Author:
Julien Jorge

Definition at line 58 of file rle_encoder.hpp.


Member Typedef Documentation

template<typename OutputBuffer>
typedef OutputBuffer claw::rle_encoder< OutputBuffer >::output_buffer_type

The type of the output buffer.

Reimplemented in claw::graphic::targa::writer::rle_targa_encoder< Pixel >.

Definition at line 62 of file rle_encoder.hpp.

template<typename OutputBuffer>
typedef output_buffer_type::pattern_type claw::rle_encoder< OutputBuffer >::pattern_type

The type of the stored data.

Definition at line 65 of file rle_encoder.hpp.

template<typename OutputBuffer>
typedef std::list<pattern_type> claw::rle_encoder< OutputBuffer >::raw_buffer_type [private]

The type of the buffer on which we store the raw data.

Definition at line 69 of file rle_encoder.hpp.


Member Function Documentation

template<typename OutputBuffer >
template<typename Iterator >
void claw::rle_encoder< OutputBuffer >::encode ( Iterator  first,
Iterator  last,
output_buffer_type output 
) const

Encode a range of datas.

Parameters:
firstIterator on the first data.
lastIterator past the last data.
outputThe buffer on which we write the compressed data.
Precondition:
Iterator::value_type must be castable to pattern_type.

Definition at line 43 of file rle_encoder.tpp.

Referenced by claw::graphic::targa::writer::save_rle_true_color(), and claw::graphic::pcx::writer::save_rle_true_color().

{
  const unsigned int max_encodable = output.max_encodable();
  const unsigned int min_interesting = output.min_interesting();
  raw_buffer_type raw_buffer;

  assert( max_encodable > 0 );

  while (first != last)
    {
      unsigned int count = 1;
      pattern_type pattern = *first;
      Iterator saved_it = first;
      ++first;
      bool ok = true;

      // try to find enough similar data
      while ( ok && (first != last) && (count < max_encodable) )
        if (*first == pattern)
          {
            ++count;
            ++first;
          }
        else
          ok = false;

      // if we have enough data
      if ( count >= min_interesting )
        {
          if ( !raw_buffer.empty() )
            {
              output.raw( raw_buffer.begin(), raw_buffer.end() );
              raw_buffer.clear();
            }

          output.encode( count, pattern );
        }
      else
        raw_buffer.insert( raw_buffer.end(), saved_it, first );
    }

  
  if ( !raw_buffer.empty() )
    output.raw( raw_buffer.begin(), raw_buffer.end() );
} // rle_encoder::encode()

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