Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ImplodeDecoder.h « Compress « 7zip « CPP - github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a73c143c98c214e68460a9d5186676997b0b1bd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// ImplodeDecoder.h

#ifndef __COMPRESS_IMPLODE_DECODER_H
#define __COMPRESS_IMPLODE_DECODER_H

#include "../../Common/MyCom.h"

#include "../ICoder.h"

#include "../Common/InBuffer.h"

#include "BitlDecoder.h"
#include "LzOutWindow.h"

namespace NCompress {
namespace NImplode {
namespace NDecoder {

typedef NBitl::CDecoder<CInBuffer> CInBit;

const unsigned kNumHuffmanBits = 16;
const unsigned kMaxHuffTableSize = 1 << 8;

class CHuffmanDecoder
{
  UInt32 _limits[kNumHuffmanBits + 1];
  UInt32 _poses[kNumHuffmanBits + 1];
  Byte _symbols[kMaxHuffTableSize];
public:
  bool Build(const Byte *lens, unsigned numSymbols) throw();
  UInt32 Decode(CInBit *inStream) const throw();
};


class CCoder:
  public ICompressCoder,
  public ICompressSetDecoderProperties2,
  public ICompressSetFinishMode,
  public ICompressGetInStreamProcessedSize,
  public CMyUnknownImp
{
  CLzOutWindow _outWindowStream;
  CInBit _inBitStream;
  
  CHuffmanDecoder _litDecoder;
  CHuffmanDecoder _lenDecoder;
  CHuffmanDecoder _distDecoder;

  Byte _flags;
  bool _fullStreamMode;

  bool BuildHuff(CHuffmanDecoder &table, unsigned numSymbols);
  HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);

public:
  MY_UNKNOWN_IMP3(
      ICompressSetDecoderProperties2,
      ICompressSetFinishMode,
      ICompressGetInStreamProcessedSize)

  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
  STDMETHOD(SetFinishMode)(UInt32 finishMode);
  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);

  CCoder();
};

}}}

#endif