~ubuntu-branches/ubuntu/trusty/advancecomp/trusty

« back to all changes in this revision

Viewing changes to 7z/DeflateEncoder.h

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ozarowski
  • Date: 2006-05-13 21:15:49 UTC
  • Revision ID: james.westby@ubuntu.com-20060513211549-2vu7peis643ojcm5
Tags: upstream-1.15
ImportĀ upstreamĀ versionĀ 1.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __DEFLATE_ENCODER_H
 
2
#define __DEFLATE_ENCODER_H
 
3
 
 
4
#include "BinTree3Z.h"
 
5
#include "LSBFEncoder.h"
 
6
#include "HuffmanEncoder.h"
 
7
#include "Const.h"
 
8
 
 
9
namespace NDeflate {
 
10
namespace NEncoder {
 
11
 
 
12
struct CCodeValue
 
13
{
 
14
  BYTE Flag;
 
15
  union
 
16
  {
 
17
    BYTE Imm;
 
18
    BYTE Len;
 
19
  };
 
20
  UINT16 Pos;
 
21
};
 
22
 
 
23
class COnePosMatches
 
24
{
 
25
public:
 
26
  UINT16 *MatchDistances;
 
27
  UINT16 LongestMatchLength;    
 
28
  UINT16 LongestMatchDistance;
 
29
  void Init(UINT16 *aMatchDistances)
 
30
  {
 
31
    MatchDistances = aMatchDistances;
 
32
  };
 
33
};
 
34
 
 
35
struct COptimal
 
36
{
 
37
  UINT32 Price;
 
38
  UINT16 PosPrev;
 
39
  UINT16 BackPrev;
 
40
};
 
41
 
 
42
const int kNumOpts = 0x1000;
 
43
 
 
44
class CCoder
 
45
{
 
46
  UINT32 m_FinderPos;
 
47
  
 
48
  COptimal m_Optimum[kNumOpts];
 
49
  
 
50
  NBT3Z::CInTree m_MatchFinder;
 
51
 
 
52
  NStream::NLSBF::CEncoder m_OutStream;
 
53
  NStream::NLSBF::CReverseEncoder m_ReverseOutStream;
 
54
  
 
55
  NCompression::NHuffman::CEncoder m_MainCoder;
 
56
  NCompression::NHuffman::CEncoder m_DistCoder;
 
57
  NCompression::NHuffman::CEncoder m_LevelCoder;
 
58
 
 
59
  BYTE m_LastLevels[kMaxTableSize];
 
60
 
 
61
  UINT32 m_ValueIndex;
 
62
  CCodeValue *m_Values;
 
63
 
 
64
  UINT32 m_OptimumEndIndex;
 
65
  UINT32 m_OptimumCurrentIndex;
 
66
  UINT32 m_AdditionalOffset;
 
67
 
 
68
  UINT32 m_LongestMatchLength;    
 
69
  UINT32 m_LongestMatchDistance;
 
70
  UINT16 *m_MatchDistances;
 
71
 
 
72
  UINT32 m_NumFastBytes;
 
73
  UINT32 m_MatchLengthEdge;
 
74
 
 
75
  BYTE  m_LiteralPrices[256];
 
76
  
 
77
  BYTE  m_LenPrices[kNumLenCombinations];
 
78
  BYTE  m_PosPrices[kDistTableSize];
 
79
 
 
80
  UINT32 m_CurrentBlockUncompressedSize;
 
81
 
 
82
  COnePosMatches *m_OnePosMatchesArray;
 
83
  UINT16 *m_OnePosMatchesMemory;
 
84
 
 
85
  UINT64 m_BlockStartPostion;
 
86
  int m_NumPasses;
 
87
 
 
88
  bool m_Created;
 
89
 
 
90
  HRESULT Create();
 
91
  void Free();
 
92
 
 
93
  void GetBacks(UINT32 aPos);
 
94
 
 
95
  void ReadGoodBacks();
 
96
  void MovePos(UINT32 aNum);
 
97
  UINT32 Backward(UINT32 &aBackRes, UINT32 aCur);
 
98
  UINT32 GetOptimal(UINT32 &aBackRes);
 
99
 
 
100
  void InitStructures();
 
101
  void CodeLevelTable(BYTE *aNewLevels, int aNumLevels, bool aCodeMode);
 
102
  int WriteTables(bool aWriteMode, bool anFinalBlock);
 
103
  void CopyBackBlockOp(UINT32 aDistance, UINT32 aLength);
 
104
  void WriteBlockData(bool aWriteMode, bool anFinalBlock);
 
105
 
 
106
  HRESULT CodeReal(ISequentialInStream *anInStream, ISequentialOutStream *anOutStream, const UINT64 *anInSize);
 
107
 
 
108
public:
 
109
  CCoder();
 
110
  ~CCoder();
 
111
 
 
112
  HRESULT SetEncoderNumPasses(UINT32 A);
 
113
  HRESULT SetEncoderNumFastBytes(UINT32 A);
 
114
  HRESULT Code(ISequentialInStream *anInStream, ISequentialOutStream *anOutStream, const UINT64 *anInSize);
 
115
};
 
116
 
 
117
}}
 
118
 
 
119
#endif