2 * Run-length encoding (RLE) is a very simple form of data compression
3 * in which runs of data (that is, sequences in which the same data value
4 * occurs in many consecutive data elements) are stored as a single data
5 * value and count, rather than as the original run. This is most useful
6 * on data that contains many such runs: for example, simple graphic
7 * images such as icons, line drawings, and animations. It is not useful
8 * with files that don't have many runs as it could slightly increase the
10 * ALGORITHM: This algorithm is an optimized version of the traditional
11 * RLE algorithm in that it behaves better with very few runs.
13 * With a run of a character where that run is >= 3 this is
14 * replaced with the repeat indicator 0X80 and then the repeat count OR'd
15 * over this ident. This repeat count therefore has a maximum value
16 * of 127 (0x7F) which is to be interpreted as the next character repeated
17 * another 'repeat count' times (i.e. a maximum of 128 characters can be
18 * represented in any single dupal). if the repeat ident is not present
19 * then the count is to be interpreted as a copy of the next repeat count
22 * EXAMPLE: the following arbitary string of 67 bytes:-
23 * WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW
24 * will produce (as a HEXDUMP) of 14 bytes
25 * 8B 57 00 42 8B 57 82 42 97 57 00 42 8D 57 .W.B.W.B.W.B.W
28 #include "RLECompressor.h"
29 #include "ace/Compression/rle/RLECompressor.h"
31 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
35 RLECompressor::RLECompressor(::Compression::CompressorFactory_ptr compressor_factory
)
36 : BaseCompressor (compressor_factory
, 0)
41 RLECompressor::compress(const ::Compression::Buffer
&source
, ::Compression::Buffer
&target
)
43 // Ensure maximum is at least X 1.1 input length.
44 target
.length(static_cast<CORBA::ULong
>((source
.length() * 1.1) + 32U));
46 ACE_UINT64 out_len
= ACE_RLECompression::instance()->compress( source
.get_buffer(),
50 if (ACE_UINT64(-1) == out_len
) { // Overrun
51 throw ::Compression::CompressionException();
54 target
.length(static_cast< CORBA::ULong
>(out_len
)); // Set Output Buffer to the right size now.
56 // Update statistics for this compressor
57 this->update_stats(source
.length(), target
.length());
61 RLECompressor::decompress(const ::Compression::Buffer
&source
, ::Compression::Buffer
&target
)
63 ACE_UINT64 out_len
= ACE_RLECompression::instance()->decompress(source
.get_buffer(),
67 if (ACE_UINT64(-1) == out_len
) { // Overrun
68 throw ::Compression::CompressionException();
71 target
.length(static_cast<CORBA::ULong
>(out_len
));
76 TAO_END_VERSIONED_NAMESPACE_DECL