libUTL++
LZencoder.h
1 #pragma once
2 
4 
5 #include <libutl/Encoder.h>
6 #include <libutl/HuffmanEncoder.h>
7 
9 
10 UTL_NS_BEGIN;
11 
13 
14 #define LZ_LEN_CODES 28
15 #define LZ_DIST_CODES 30
16 
18 
51 
53 class LZencoder : public Encoder
54 {
56 
57 public:
65  LZencoder(uint_t mode, Stream* stream, bool owner = true, uint_t level = 9)
66  {
67  init();
68  start(mode, stream, owner, level);
69  }
70 
71  virtual size_t decode(byte_t* block, size_t num);
72 
73  virtual size_t encode(const byte_t* block, size_t num);
74 
82  void start(uint_t mode, Stream* stream, bool owner = true, uint_t level = 9);
83 
84 protected:
85  virtual void clear();
86  virtual void finishEncoding();
87 
88 private:
89  void init();
90  void
91  deInit()
92  {
93  close();
94  }
95  void addString(uint_t pos);
96  uint_t matchString(uint_t pos);
97  void removeString(uint_t pos);
98 
99 private:
100  uint_t _lab, _repc, _pos;
101  // sliding window, look-ahead buffer
102  byte_t* _wind;
103  byte_t* _look;
104  // match information
105  uint_t _prevMatchLen, _prevMatchDist, _prevLiteral;
106  uint_t _matchLen, _matchDist, _literal;
107  bool _matchAvailable;
108  // compress configuration
109  uint_t _goodLen; // reduce lazy search above this length
110  uint_t _maxLazyLen; // do not perform lazy search above this match length
111  uint_t _niceLen; // quit search above this match length
112  uint_t _maxChain; // follow at most this many hash chains
113  // coding distances, lengths
114  uint_t* _baseLen;
115  uint_t* _lenCode;
116  uint_t* _baseDist;
117  uint_t* _distCode;
118  static const uint_t eob;
119  static const uint_t lenBits[LZ_LEN_CODES];
120  static const uint_t distBits[LZ_DIST_CODES];
121  // hashing
122  uint_t* _head;
123  uint_t* _tail;
124  uint_t* _pred;
125  uint_t* _succ;
126  // H-coders
127  HuffmanEncoder _lEnc;
128  HuffmanEncoder _dEnc;
129 };
130 
132 
133 UTL_NS_END;
LZencoder(uint_t mode, Stream *stream, bool owner=true, uint_t level=9)
Constructor.
Definition: LZencoder.h:65
void deInit()
De-initialize UTL++.
Encoder/decoder abstraction.
Definition: Encoder.h:39
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
unsigned char byte_t
Unsigned character.
Definition: types.h:31
Adaptive Huffman coder.
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
Stream I/O abstraction.
Definition: Stream.h:68
LZ77-based compressor.
Definition: LZencoder.h:53
void init()
Initialize UTL++.