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 |
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().
{
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()
1.7.1