• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Bcj2Coder.h
2 
3 #ifndef __COMPRESS_BCJ2_CODER_H
4 #define __COMPRESS_BCJ2_CODER_H
5 
6 #include "../../Common/MyCom.h"
7 
8 #include "../ICoder.h"
9 
10 #include "RangeCoderBit.h"
11 
12 namespace NCompress {
13 namespace NBcj2 {
14 
15 const int kNumMoveBits = 5;
16 
17 #ifndef EXTRACT_ONLY
18 
19 class CEncoder:
20   public ICompressCoder2,
21   public CMyUnknownImp
22 {
23   Byte *_buffer;
24   bool Create();
25 
26   COutBuffer _mainStream;
27   COutBuffer _callStream;
28   COutBuffer _jumpStream;
29   NCompress::NRangeCoder::CEncoder _rangeEncoder;
30   NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusEncoder[256 + 2];
31 
32   HRESULT Flush();
33 public:
ReleaseStreams()34   void ReleaseStreams()
35   {
36     _mainStream.ReleaseStream();
37     _callStream.ReleaseStream();
38     _jumpStream.ReleaseStream();
39     _rangeEncoder.ReleaseStream();
40   }
41 
42   class CCoderReleaser
43   {
44     CEncoder *_coder;
45   public:
CCoderReleaser(CEncoder * coder)46     CCoderReleaser(CEncoder *coder): _coder(coder) {}
~CCoderReleaser()47     ~CCoderReleaser() {  _coder->ReleaseStreams(); }
48   };
49 
50 public:
51   MY_UNKNOWN_IMP
52 
53   HRESULT CodeReal(ISequentialInStream **inStreams, const UInt64 **inSizes, UInt32 numInStreams,
54       ISequentialOutStream **outStreams, const UInt64 **outSizes, UInt32 numOutStreams,
55       ICompressProgressInfo *progress);
56   STDMETHOD(Code)(ISequentialInStream **inStreams, const UInt64 **inSizes, UInt32 numInStreams,
57       ISequentialOutStream **outStreams, const UInt64 **outSizes, UInt32 numOutStreams,
58       ICompressProgressInfo *progress);
CEncoder()59   CEncoder(): _buffer(0) {};
60   ~CEncoder();
61 };
62 
63 #endif
64 
65 class CDecoder:
66   public ICompressCoder2,
67   public ICompressSetBufSize,
68   public CMyUnknownImp
69 {
70   CInBuffer _mainInStream;
71   CInBuffer _callStream;
72   CInBuffer _jumpStream;
73   NCompress::NRangeCoder::CDecoder _rangeDecoder;
74   NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusDecoder[256 + 2];
75 
76   COutBuffer _outStream;
77   UInt32 _inBufSizes[4];
78   UInt32 _outBufSize;
79 
80 public:
ReleaseStreams()81   void ReleaseStreams()
82   {
83     _mainInStream.ReleaseStream();
84     _callStream.ReleaseStream();
85     _jumpStream.ReleaseStream();
86     _rangeDecoder.ReleaseStream();
87     _outStream.ReleaseStream();
88   }
89 
Flush()90   HRESULT Flush() { return _outStream.Flush(); }
91   class CCoderReleaser
92   {
93     CDecoder *_coder;
94   public:
CCoderReleaser(CDecoder * coder)95     CCoderReleaser(CDecoder *coder): _coder(coder) {}
~CCoderReleaser()96     ~CCoderReleaser()  { _coder->ReleaseStreams(); }
97   };
98 
99 public:
100   MY_UNKNOWN_IMP1(ICompressSetBufSize);
101   HRESULT CodeReal(ISequentialInStream **inStreams, const UInt64 **inSizes, UInt32 numInStreams,
102       ISequentialOutStream **outStreams, const UInt64 **outSizes, UInt32 numOutStreams,
103       ICompressProgressInfo *progress);
104   STDMETHOD(Code)(ISequentialInStream **inStreams, const UInt64 **inSizes, UInt32 numInStreams,
105       ISequentialOutStream **outStreams, const UInt64 **outSizes, UInt32 numOutStreams,
106       ICompressProgressInfo *progress);
107 
108   STDMETHOD(SetInBufSize)(UInt32 streamIndex, UInt32 size);
109   STDMETHOD(SetOutBufSize)(UInt32 streamIndex, UInt32 size);
110   CDecoder();
111 };
112 
113 }}
114 
115 #endif
116