diff options
| author | Johnny Willemsen <jwillemsen@remedy.nl> | 2012-02-23 07:57:08 +0000 |
|---|---|---|
| committer | Johnny Willemsen <jwillemsen@remedy.nl> | 2012-02-23 07:57:08 +0000 |
| commit | a12c723006a4be82d2aa29489b677e9c804acd0d (patch) | |
| tree | 1c7b19615a7a4c79126da6fc92258e2056b156ad /ACE/ace/Compression/rle | |
| parent | 464e54600a8025bd4c5698e47cc8e007e3df06bf (diff) | |
| download | ATCD-a12c723006a4be82d2aa29489b677e9c804acd0d.tar.gz | |
Thu Feb 23 07:52:58 UTC 2012 Johnny Willemsen <jwillemsen@remedy.nl>
* ace/Compression:
* ace/Compression/ACE_Compression.mpc:
* ace/Compression/ACE_Compression_export.h:
* ace/Compression/Compressor.h:
* ace/Compression/Compressor.inl:
* ace/Compression/Compressor.cpp:
* ace/Compression/rle:
* ace/Compression/rle/ACE_RLECompression.mpc:
* ace/Compression/rle/ACE_RLECompression_export.h:
* ace/Compression/rle/RLECompressor.h:
* ace/Compression/rle/RLECompressor.cpp:
* bin/MakeProjectCreator/config/ace_compressionlib.mpb:
* bin/MakeProjectCreator/config/ace_rlecompressionlib.mpb:
Added new ACE compression and rle compressor libraries. This code
was first part of TAO, but now moved to ACE because it provides
a basic run length encoding compressor that makes it possible to
compress data without depending on any external library
* docs/bczar/bczar.html:
Added package
Diffstat (limited to 'ACE/ace/Compression/rle')
| -rw-r--r-- | ACE/ace/Compression/rle/ACE_RLECompression.mpc | 20 | ||||
| -rw-r--r-- | ACE/ace/Compression/rle/ACE_RLECompression_export.h | 57 | ||||
| -rw-r--r-- | ACE/ace/Compression/rle/RLECompressor.cpp | 154 | ||||
| -rw-r--r-- | ACE/ace/Compression/rle/RLECompressor.h | 111 |
4 files changed, 342 insertions, 0 deletions
diff --git a/ACE/ace/Compression/rle/ACE_RLECompression.mpc b/ACE/ace/Compression/rle/ACE_RLECompression.mpc new file mode 100644 index 00000000000..31316ea0740 --- /dev/null +++ b/ACE/ace/Compression/rle/ACE_RLECompression.mpc @@ -0,0 +1,20 @@ +// -*- MPC -*- +// $Id: + +project(ACE_RLECompression) : ace_compressionlib, install, ace_output { + sharedname = * + dynamicflags += ACE_RLECOMPRESSION_BUILD_DLL + + Source_Files { + RLECompressor.cpp + } + + Header_Files { + RLECompressor.h + ACE_RLECompression_export.h + } + + specific { + install_dir = ace/lib + } +} diff --git a/ACE/ace/Compression/rle/ACE_RLECompression_export.h b/ACE/ace/Compression/rle/ACE_RLECompression_export.h new file mode 100644 index 00000000000..85b20f0cbca --- /dev/null +++ b/ACE/ace/Compression/rle/ACE_RLECompression_export.h @@ -0,0 +1,57 @@ +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl ACE_RLECompression +// ------------------------------ +#ifndef ACE_RLECOMPRESSION_EXPORT_H +#define ACE_RLECOMPRESSION_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (ACE_RLECOMPRESSION_HAS_DLL) +# define ACE_RLECOMPRESSION_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && ACE_RLECOMPRESSION_HAS_DLL */ + +#if !defined (ACE_RLECOMPRESSION_HAS_DLL) +# define ACE_RLECOMPRESSION_HAS_DLL 1 +#endif /* ! ACE_RLECOMPRESSION_HAS_DLL */ + +#if defined (ACE_RLECOMPRESSION_HAS_DLL) && (ACE_RLECOMPRESSION_HAS_DLL == 1) +# if defined (ACE_RLECOMPRESSION_BUILD_DLL) +# define ACE_RLECompression_Export ACE_Proper_Export_Flag +# define ACE_RLECOMPRESSION_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define ACE_RLECOMPRESSION_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* ACE_RLECOMPRESSION_BUILD_DLL */ +# define ACE_RLECompression_Export ACE_Proper_Import_Flag +# define ACE_RLECOMPRESSION_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define ACE_RLECOMPRESSION_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* ACE_RLECOMPRESSION_BUILD_DLL */ +#else /* ACE_RLECOMPRESSION_HAS_DLL == 1 */ +# define ACE_RLECompression_Export +# define ACE_RLECOMPRESSION_SINGLETON_DECLARATION(T) +# define ACE_RLECOMPRESSION_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* ACE_RLECOMPRESSION_HAS_DLL == 1 */ + +// Set ACE_RLECOMPRESSION_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (ACE_RLECOMPRESSION_NTRACE) +# if (ACE_NTRACE == 1) +# define ACE_RLECOMPRESSION_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define ACE_RLECOMPRESSION_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !ACE_RLECOMPRESSION_NTRACE */ + +#if (ACE_RLECOMPRESSION_NTRACE == 1) +# define ACE_RLECOMPRESSION_TRACE(X) +#else /* (ACE_RLECOMPRESSION_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define ACE_RLECOMPRESSION_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (ACE_RLECOMPRESSION_NTRACE == 1) */ + +#endif /* ACE_RLECOMPRESSION_EXPORT_H */ + +// End of auto generated file. diff --git a/ACE/ace/Compression/rle/RLECompressor.cpp b/ACE/ace/Compression/rle/RLECompressor.cpp new file mode 100644 index 00000000000..1d924aa0a05 --- /dev/null +++ b/ACE/ace/Compression/rle/RLECompressor.cpp @@ -0,0 +1,154 @@ +// $Id$ + +#include "RLECompressor.h" +#include "ace/OS_NS_string.h" + +ACE_BEGIN_VERSIONED_NAMESPACE_DECL + +ACE_RLECompressor::ACE_RLECompressor(void) + : ACE_Compressor(ACE_COMPRESSORID_RLE) +{ +} + +ACE_UINT64 +ACE_RLECompressor::compress( const void *in_ptr, + ACE_UINT64 in_len, + void *out_ptr, + ACE_UINT64 max_out_len ) +{ + const ACE_UINT8 *in_p = static_cast<const ACE_UINT8*>(in_ptr); + ACE_UINT8 *out_p = static_cast<ACE_UINT8*>(out_ptr); + + ACE_UINT64 src_len = in_len; // Save for stats + ACE_UINT64 out_len = 0; + ACE_UINT64 out_index = 0; + ACE_UINT64 out_base = 0; + + ACE_UINT32 run_count = 0; + ACE_UINT32 dup_count = 0; + + bool run_code = false; + + ACE_UINT8 nxt_byte, cur_byte; + + if (in_p && out_p) while (in_len-- > 0) { + + if (run_code) switch (run_count) { + + default: + + out_p[out_index = out_base] = ACE_UINT8(run_count++ | 0x80); + out_p[++out_index] = cur_byte = *in_p++; + + if (in_len ? cur_byte == (nxt_byte = *in_p) : true) { + continue; + } + + // Fall Through + + case 128: + + if (++out_index >= max_out_len) { + return ACE_UINT64(-1); // Output Exhausted + } else if (in_len == 0) { + continue; + } + + run_code = false; + out_p[out_base = out_index] = 0; + dup_count = run_count = 0; + continue; + } + + switch (run_count) { + + case 128: + + if (++out_index >= max_out_len) { + return -1; // Output Exhausted + } + out_p[out_base = out_index] = 0; + dup_count = run_count = 0; + + // Fall Through + + default : + + cur_byte = *in_p++; + + if (in_len > 0) { + if (cur_byte == (nxt_byte = *in_p)) { + if (dup_count++ == 1) { + if (run_count >= dup_count) { + out_p[out_base] = static_cast<ACE_UINT8>(run_count - dup_count); + out_base += run_count; + } + run_code = true; + run_count = dup_count - 1; + dup_count = 0; + out_p[out_index = out_base] = static_cast<ACE_UINT8>(run_count++ | 0x80); + break; + } + } else dup_count = 0; + } + out_p[out_base] = char(run_count++); + break; + } + + if (++out_index >= max_out_len) { + return ACE_UINT64(-1); // Output Exhausted + } + + out_p[out_index] = cur_byte; + } + + out_len = ++out_index; // Update our output length + + this->update_stats(src_len, out_len); + + return out_len; +} + +// Decompress using Run Length Encoding (RLE) +ACE_UINT64 +ACE_RLECompressor::decompress( const void *in_ptr, + ACE_UINT64 in_len, + void *out_ptr, + ACE_UINT64 max_out_len ) +{ + ACE_UINT64 out_len = 0; + + const ACE_UINT8 *in_p = static_cast<const ACE_UINT8*>(in_ptr); + ACE_UINT8 *out_p = static_cast<ACE_UINT8*>(out_ptr); + + if (in_p && out_p) while(in_len-- > 0) { + + ACE_UINT8 cur_byte = *in_p++; + ACE_UINT32 cpy_len = ACE_UINT32((cur_byte & 0x7F) + 1); + + if (cpy_len > max_out_len) { + return ACE_UINT64(-1); // Output Exhausted + } else if ((cur_byte & 0x80) != 0) { // compressed + if (in_len-- > 0) { + ACE_OS::memset(out_p, *in_p++, cpy_len); + } else { + return ACE_UINT64(-1); // Output Exhausted + } + } else if (in_len >= cpy_len) { + ACE_OS::memcpy(out_p, in_p, cpy_len); + in_p += cpy_len; + in_len -= cpy_len; + } else { + return ACE_UINT64(-1); // Output Exhausted + } + + out_p += cpy_len; + max_out_len -= cpy_len; + out_len += cpy_len; + } + + return out_len; +} + +// Close versioned namespace, if enabled by the user. +ACE_END_VERSIONED_NAMESPACE_DECL diff --git a/ACE/ace/Compression/rle/RLECompressor.h b/ACE/ace/Compression/rle/RLECompressor.h new file mode 100644 index 00000000000..db00eb12ee1 --- /dev/null +++ b/ACE/ace/Compression/rle/RLECompressor.h @@ -0,0 +1,111 @@ +// -*- C++ -*- +//============================================================================= +/** + * @file RLECompressor.h + * + * $Id: RLECompressor.h + * + * @author TAO version by + * @author Derek Dominish <derek.dominish@dsto.defence.gov.au> + * @author ACE version by + * @author Derek Dominish <derek.dominish@dsto.defence.gov.au> + * + * Run-length encoding (RLE) is a very simple form of data compression + * in which runs of data (that is, sequences in which the same data value + * occurs in many consecutive data elements) are stored as a single data + * value and count, rather than as the original run. This is most useful + * on data that contains many such runs: for example, simple graphic + * images such as icons, line drawings, and animations. It is not useful + * with files that don't have many runs as it could slightly increase the + * output size. + * ALGORITHM: This algorithm is an optimised version of the traditional + * RLE algorithm in that it behaves better with very few runs. + * + * With a run of a character where that run is >= 3 this is + * replaced with the repeat indicator 0X80 and then the repeat count OR'd + * over this ident. This repeat count is therefore has a maximum value + * of 127 (0x7F) which is to be interpreted as the next charater repeated + * another 'repeat count' times (i.e. a maximum of 128 characters can be + * represented in any single dupal). if the repeat ident is not present + * then the count is to be interpreted as a copy of the next repeat count + * charaters + 1. + * + * EXAMPLE: the following arbitary string of 67 bytes:- + * WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW + * will produce (as a HEXDUMP) of 14 bytes + * 8B 57 00 42 8B 57 82 42 97 57 00 42 8D 57 .W.B.W.B.W.B.W + */ +//============================================================================= + +#ifndef ACE_RLECOMPRESSOR_H +#define ACE_RLECOMPRESSOR_H + +#include /**/ "ace/pre.h" + +#include "ACE_RLECompression_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Compression/Compressor.h" +#include "ace/Singleton.h" + +ACE_BEGIN_VERSIONED_NAMESPACE_DECL + +class ACE_RLECompression_Export ACE_RLECompressor : public ACE_Compressor +{ +public: + /** + * Default constructor. Should use instance() to get global instance. + */ + ACE_RLECompressor(void); + + /** + * Compress the @a in_ptr buffer for @a in_len into the + * @a dest_ptr buffer with a maximum @a max_out_len using + * the Run Length Ecoding (RLE) algorithm. If the + * @a max_out_len is exhausted through the compress process + * then a value of -1 will be returned from the function, + * otherwise the return value will indicate the resultant + * @a out_ptr compressed buffer length. + * + * @note It is advisable that the @max_out_len be slightly + * larger of the input @a in_len (i.e. x 1.1F) to cater + * for the possibility that a reduced compressed length + * is not possible. + */ + virtual ACE_UINT64 compress( const void *in_ptr, + ACE_UINT64 in_len, + void *out_ptr, + ACE_UINT64 max_out_len ); + + /** + * DeCompress the @a in_ptr buffer for @a in_len into the + * @a out_ptr buffer with a maximum @a max_out_len using + * the Run Length Ecoding (RLE) algorithm. If the + * @a max_out_len is exhausted during decompression + * then a value of -1 will be returned from the function, + * otherwise the return value will indicate the resultant + * @a out_ptr decompressed buffer length. + */ + virtual ACE_UINT64 decompress( const void *in_ptr, + ACE_UINT64 in_len, + void *out_ptr, + ACE_UINT64 max_out_len ); +}; + +typedef class ACE_Singleton<ACE_RLECompressor, ACE_SYNCH_MUTEX> ACE_RLECompression; + +// This is needed to get only one of these defined across a set of DLLs and EXE +#if defined(ACE_RLECOMPRESSION_BUILD_DLL) + ACE_EXPORT_SINGLETON_DECLARE(ACE_Singleton, ACE_RLECompressor, ACE_SYNCH_MUTEX); +#else + ACE_IMPORT_SINGLETON_DECLARE(ACE_Singleton, ACE_RLECompressor, ACE_SYNCH_MUTEX); +#endif + +ACE_END_VERSIONED_NAMESPACE_DECL + +#include /**/ "ace/post.h" + +#endif // ACE_RLECOMPRESSOR_H
\ No newline at end of file |
