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 [inline]

Encode a range of datas.

Parameters:
first Iterator on the first data.
last Iterator past the last data.
output The 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().

00045 {
00046   const unsigned int max_encodable = output.max_encodable();
00047   const unsigned int min_interesting = output.min_interesting();
00048   raw_buffer_type raw_buffer;
00049 
00050   assert( max_encodable > 0 );
00051 
00052   while (first != last)
00053     {
00054       unsigned int count = 1;
00055       pattern_type pattern = *first;
00056       Iterator saved_it = first;
00057       ++first;
00058       bool ok = true;
00059 
00060       // try to find enough similar data
00061       while ( ok && (first != last) && (count < max_encodable) )
00062         if (*first == pattern)
00063           {
00064             ++count;
00065             ++first;
00066           }
00067         else
00068           ok = false;
00069 
00070       // if we have enough data
00071       if ( count >= min_interesting )
00072         {
00073           if ( !raw_buffer.empty() )
00074             {
00075               output.raw( raw_buffer.begin(), raw_buffer.end() );
00076               raw_buffer.clear();
00077             }
00078 
00079           output.encode( count, pattern );
00080         }
00081       else
00082         raw_buffer.insert( raw_buffer.end(), saved_it, first );
00083     }
00084 
00085   
00086   if ( !raw_buffer.empty() )
00087     output.raw( raw_buffer.begin(), raw_buffer.end() );
00088 } // rle_encoder::encode()


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