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