A class to help run-length encoding (RLE) streams. More...
#include <rle_encoder.hpp>
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_type > | raw_buffer_type |
The type of the buffer on which we store the raw data. |
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 :
Definition at line 58 of file rle_encoder.hpp.
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.
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.
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.
void claw::rle_encoder< OutputBuffer >::encode | ( | Iterator | first, | |
Iterator | last, | |||
output_buffer_type & | output | |||
) | const [inline] |
Encode a range of datas.
first | Iterator on the first data. | |
last | Iterator past the last data. | |
output | The buffer on which we write the compressed data. |
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()