xref: /third_party/lzma/CPP/7zip/Compress/Bcj2Coder.h (revision 370b324c)
1// Bcj2Coder.h
2
3#ifndef ZIP7_INC_COMPRESS_BCJ2_CODER_H
4#define ZIP7_INC_COMPRESS_BCJ2_CODER_H
5
6#include "../../../C/Bcj2.h"
7
8#include "../../Common/MyCom.h"
9
10#include "../ICoder.h"
11
12namespace NCompress {
13namespace NBcj2 {
14
15class CBaseCoder
16{
17protected:
18  Byte *_bufs[BCJ2_NUM_STREAMS + 1];
19  UInt32 _bufsSizes[BCJ2_NUM_STREAMS + 1];
20  UInt32 _bufsSizes_New[BCJ2_NUM_STREAMS + 1];
21
22  HRESULT Alloc(bool allocForOrig = true);
23public:
24  CBaseCoder();
25  ~CBaseCoder();
26};
27
28
29#ifndef Z7_EXTRACT_ONLY
30
31class CEncoder Z7_final:
32  public ICompressCoder2,
33  public ICompressSetCoderProperties,
34  public ICompressSetBufSize,
35  public CMyUnknownImp,
36  public CBaseCoder
37{
38  Z7_IFACES_IMP_UNK_3(
39      ICompressCoder2,
40      ICompressSetCoderProperties,
41      ICompressSetBufSize)
42
43  UInt32 _relatLim;
44  // UInt32 _excludeRangeBits;
45
46  HRESULT CodeReal(
47      ISequentialInStream * const *inStreams, const UInt64 * const *inSizes, UInt32 numInStreams,
48      ISequentialOutStream * const *outStreams, const UInt64 * const *outSizes, UInt32 numOutStreams,
49      ICompressProgressInfo *progress);
50public:
51  CEncoder();
52  ~CEncoder();
53};
54
55#endif
56
57
58
59class CBaseDecoder: public CBaseCoder
60{
61protected:
62  HRESULT _readRes[BCJ2_NUM_STREAMS];
63  unsigned _extraSizes[BCJ2_NUM_STREAMS];
64  UInt64 _readSizes[BCJ2_NUM_STREAMS];
65
66  CBcj2Dec dec;
67
68  UInt64 GetProcessedSize_ForInStream(unsigned i) const
69  {
70    return _readSizes[i] - ((size_t)(dec.lims[i] - dec.bufs[i]) + _extraSizes[i]);
71  }
72  void InitCommon();
73  void ReadInStream(ISequentialInStream *inStream);
74};
75
76
77class CDecoder Z7_final:
78  public ICompressCoder2,
79  public ICompressSetFinishMode,
80  public ICompressGetInStreamProcessedSize2,
81  public ICompressSetBufSize,
82#ifndef Z7_NO_READ_FROM_CODER
83  public ICompressSetInStream2,
84  public ICompressSetOutStreamSize,
85  public ISequentialInStream,
86#endif
87  public CMyUnknownImp,
88  public CBaseDecoder
89{
90  Z7_COM_QI_BEGIN2(ICompressCoder2)
91    Z7_COM_QI_ENTRY(ICompressSetFinishMode)
92    Z7_COM_QI_ENTRY(ICompressGetInStreamProcessedSize2)
93    Z7_COM_QI_ENTRY(ICompressSetBufSize)
94  #ifndef Z7_NO_READ_FROM_CODER
95    Z7_COM_QI_ENTRY(ICompressSetInStream2)
96    Z7_COM_QI_ENTRY(ICompressSetOutStreamSize)
97    Z7_COM_QI_ENTRY(ISequentialInStream)
98  #endif
99  Z7_COM_QI_END
100  Z7_COM_ADDREF_RELEASE
101
102  Z7_IFACE_COM7_IMP(ICompressCoder2)
103  Z7_IFACE_COM7_IMP(ICompressSetFinishMode)
104  Z7_IFACE_COM7_IMP(ICompressGetInStreamProcessedSize2)
105  Z7_IFACE_COM7_IMP(ICompressSetBufSize)
106#ifndef Z7_NO_READ_FROM_CODER
107  Z7_IFACE_COM7_IMP(ICompressSetInStream2)
108  Z7_IFACE_COM7_IMP(ICompressSetOutStreamSize)
109  Z7_IFACE_COM7_IMP(ISequentialInStream)
110#endif
111
112  bool _finishMode;
113
114#ifndef Z7_NO_READ_FROM_CODER
115  bool _outSizeDefined;
116  UInt64 _outSize;
117  UInt64 _outSize_Processed;
118  CMyComPtr<ISequentialInStream> _inStreams[BCJ2_NUM_STREAMS];
119#endif
120
121public:
122  CDecoder();
123};
124
125}}
126
127#endif
128