3
#ifndef __DEFLATE_ENCODER_H
4
#define __DEFLATE_ENCODER_H
8
#include "../../../C/LzFind.h"
11
#include "Common/MyCom.h"
13
#include "../ICoder.h"
15
#include "BitlEncoder.h"
16
#include "DeflateConst.h"
26
void SetAsLiteral() { Len = (1 << 15); }
27
bool IsLiteral() const { return (Len >= (1 << 15)); }
37
const UInt32 kNumOptsBase = 1 << 12;
38
const UInt32 kNumOpts = kNumOptsBase + kMatchMaxLen;
42
struct CTables: public CLevels
49
void InitStructures();
52
typedef struct _CSeqInStream
54
ISeqInStream SeqInStream;
55
CMyComPtr<ISequentialInStream> RealStream;
60
CMatchFinder _lzInWindow;
61
CBitlEncoder m_OutStream;
63
CSeqInStream _seqInStream;
68
UInt16 *m_MatchDistances;
69
UInt32 m_NumFastBytes;
73
UInt16 *m_OnePosMatchesMemory;
74
UInt16 *m_DistanceMemory;
82
UInt32 m_ValueBlockSize;
84
UInt32 m_NumLenCombinations;
86
const Byte *m_LenStart;
87
const Byte *m_LenDirectBits;
92
Byte m_LevelLevels[kLevelTableSize];
93
int m_NumLitLenLevels;
95
UInt32 m_NumLevelCodes;
99
UInt32 m_AdditionalOffset;
101
UInt32 m_OptimumEndIndex;
102
UInt32 m_OptimumCurrentIndex;
104
Byte m_LiteralPrices[256];
105
Byte m_LenPrices[kNumLenSymbolsMax];
106
Byte m_PosPrices[kDistTableSize64];
109
UInt32 mainFreqs[kFixedMainTableSize];
110
UInt32 distFreqs[kDistTableSize64];
111
UInt32 mainCodes[kFixedMainTableSize];
112
UInt32 distCodes[kDistTableSize64];
113
UInt32 levelCodes[kLevelTableSize];
114
Byte levelLens[kLevelTableSize];
119
COptimal m_Optimum[kNumOpts];
121
UInt32 m_MatchFinderCycles;
122
// IMatchFinderSetNumPasses *m_SetMfPasses;
125
void MovePos(UInt32 num);
126
UInt32 Backward(UInt32 &backRes, UInt32 cur);
127
UInt32 GetOptimal(UInt32 &backRes);
128
UInt32 GetOptimalFast(UInt32 &backRes);
130
void LevelTableDummy(const Byte *levels, int numLevels, UInt32 *freqs);
132
void WriteBits(UInt32 value, int numBits);
133
void LevelTableCode(const Byte *levels, int numLevels, const Byte *lens, const UInt32 *codes);
135
void MakeTables(unsigned maxHuffLen);
136
UInt32 GetLzBlockPrice() const;
138
UInt32 TryDynBlock(int tableIndex, UInt32 numPasses);
140
UInt32 TryFixedBlock(int tableIndex);
142
void SetPrices(const CLevels &levels);
148
void WriteStoreBlock(UInt32 blockSize, UInt32 additionalOffset, bool finalBlock);
149
void WriteTables(bool writeMode, bool finalBlock);
151
void WriteBlockData(bool writeMode, bool finalBlock);
153
void ReleaseStreams()
155
_seqInStream.RealStream.Release();
156
m_OutStream.ReleaseStream();
162
CCoderReleaser(CCoder *coder): m_Coder(coder) {}
163
~CCoderReleaser() { m_Coder->ReleaseStreams(); }
165
friend class CCoderReleaser;
167
UInt32 GetBlockPrice(int tableIndex, int numDivPasses);
168
void CodeBlock(int tableIndex, bool finalBlock);
171
CCoder(bool deflate64Mode = false);
174
HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
175
const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
177
HRESULT BaseCode(ISequentialInStream *inStream, ISequentialOutStream *outStream,
178
const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
180
HRESULT BaseSetEncoderProperties2(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);
185
public ICompressCoder,
186
public ICompressSetCoderProperties,
187
public CMyUnknownImp,
191
MY_UNKNOWN_IMP1(ICompressSetCoderProperties)
192
CCOMCoder(): CCoder(false) {};
193
STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
194
const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
195
STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);
199
public ICompressCoder,
200
public ICompressSetCoderProperties,
201
public CMyUnknownImp,
205
MY_UNKNOWN_IMP1(ICompressSetCoderProperties)
206
CCOMCoder64(): CCoder(true) {};
207
STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
208
const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
209
STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);