Run dos2unix on bayou and remove white space at the end of lines.
Change-Id: If13d9a49ece2699885ae3e998173d3d44507b302 Signed-off-by: Stefan Reinauer <reinauer@google.com> Reviewed-on: http://review.coreboot.org/362 Tested-by: build bot (Jenkins) Reviewed-by: Peter Stuge <peter@stuge.se>
This commit is contained in:
parent
1861ff739c
commit
36c04e8a5c
|
@ -1,76 +1,76 @@
|
||||||
// InBuffer.h
|
// InBuffer.h
|
||||||
|
|
||||||
#ifndef __INBUFFER_H
|
#ifndef __INBUFFER_H
|
||||||
#define __INBUFFER_H
|
#define __INBUFFER_H
|
||||||
|
|
||||||
#include "../IStream.h"
|
#include "../IStream.h"
|
||||||
#include "../../Common/MyCom.h"
|
#include "../../Common/MyCom.h"
|
||||||
|
|
||||||
#ifndef _NO_EXCEPTIONS
|
#ifndef _NO_EXCEPTIONS
|
||||||
class CInBufferException
|
class CInBufferException
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HRESULT ErrorCode;
|
HRESULT ErrorCode;
|
||||||
CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
|
CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class CInBuffer
|
class CInBuffer
|
||||||
{
|
{
|
||||||
Byte *_buffer;
|
Byte *_buffer;
|
||||||
Byte *_bufferLimit;
|
Byte *_bufferLimit;
|
||||||
Byte *_bufferBase;
|
Byte *_bufferBase;
|
||||||
CMyComPtr<ISequentialInStream> _stream;
|
CMyComPtr<ISequentialInStream> _stream;
|
||||||
UInt64 _processedSize;
|
UInt64 _processedSize;
|
||||||
UInt32 _bufferSize;
|
UInt32 _bufferSize;
|
||||||
bool _wasFinished;
|
bool _wasFinished;
|
||||||
|
|
||||||
bool ReadBlock();
|
bool ReadBlock();
|
||||||
Byte ReadBlock2();
|
Byte ReadBlock2();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
#ifdef _NO_EXCEPTIONS
|
#ifdef _NO_EXCEPTIONS
|
||||||
HRESULT ErrorCode;
|
HRESULT ErrorCode;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CInBuffer();
|
CInBuffer();
|
||||||
~CInBuffer() { Free(); }
|
~CInBuffer() { Free(); }
|
||||||
|
|
||||||
bool Create(UInt32 bufferSize);
|
bool Create(UInt32 bufferSize);
|
||||||
void Free();
|
void Free();
|
||||||
|
|
||||||
void SetStream(ISequentialInStream *stream);
|
void SetStream(ISequentialInStream *stream);
|
||||||
void Init();
|
void Init();
|
||||||
void ReleaseStream() { _stream.Release(); }
|
void ReleaseStream() { _stream.Release(); }
|
||||||
|
|
||||||
bool ReadByte(Byte &b)
|
bool ReadByte(Byte &b)
|
||||||
{
|
{
|
||||||
if(_buffer >= _bufferLimit)
|
if(_buffer >= _bufferLimit)
|
||||||
if(!ReadBlock())
|
if(!ReadBlock())
|
||||||
return false;
|
return false;
|
||||||
b = *_buffer++;
|
b = *_buffer++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Byte ReadByte()
|
Byte ReadByte()
|
||||||
{
|
{
|
||||||
if(_buffer >= _bufferLimit)
|
if(_buffer >= _bufferLimit)
|
||||||
return ReadBlock2();
|
return ReadBlock2();
|
||||||
return *_buffer++;
|
return *_buffer++;
|
||||||
}
|
}
|
||||||
void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
|
void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
|
||||||
{
|
{
|
||||||
for(processedSize = 0; processedSize < size; processedSize++)
|
for(processedSize = 0; processedSize < size; processedSize++)
|
||||||
if (!ReadByte(((Byte *)data)[processedSize]))
|
if (!ReadByte(((Byte *)data)[processedSize]))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool ReadBytes(void *data, UInt32 size)
|
bool ReadBytes(void *data, UInt32 size)
|
||||||
{
|
{
|
||||||
UInt32 processedSize;
|
UInt32 processedSize;
|
||||||
ReadBytes(data, size, processedSize);
|
ReadBytes(data, size, processedSize);
|
||||||
return (processedSize == size);
|
return (processedSize == size);
|
||||||
}
|
}
|
||||||
UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }
|
UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }
|
||||||
bool WasFinished() const { return _wasFinished; }
|
bool WasFinished() const { return _wasFinished; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,64 +1,64 @@
|
||||||
// OutBuffer.h
|
// OutBuffer.h
|
||||||
|
|
||||||
#ifndef __OUTBUFFER_H
|
#ifndef __OUTBUFFER_H
|
||||||
#define __OUTBUFFER_H
|
#define __OUTBUFFER_H
|
||||||
|
|
||||||
#include "../IStream.h"
|
#include "../IStream.h"
|
||||||
#include "../../Common/MyCom.h"
|
#include "../../Common/MyCom.h"
|
||||||
|
|
||||||
#ifndef _NO_EXCEPTIONS
|
#ifndef _NO_EXCEPTIONS
|
||||||
struct COutBufferException
|
struct COutBufferException
|
||||||
{
|
{
|
||||||
HRESULT ErrorCode;
|
HRESULT ErrorCode;
|
||||||
COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
|
COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class COutBuffer
|
class COutBuffer
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
Byte *_buffer;
|
Byte *_buffer;
|
||||||
UInt32 _pos;
|
UInt32 _pos;
|
||||||
UInt32 _limitPos;
|
UInt32 _limitPos;
|
||||||
UInt32 _streamPos;
|
UInt32 _streamPos;
|
||||||
UInt32 _bufferSize;
|
UInt32 _bufferSize;
|
||||||
CMyComPtr<ISequentialOutStream> _stream;
|
CMyComPtr<ISequentialOutStream> _stream;
|
||||||
UInt64 _processedSize;
|
UInt64 _processedSize;
|
||||||
Byte *_buffer2;
|
Byte *_buffer2;
|
||||||
bool _overDict;
|
bool _overDict;
|
||||||
|
|
||||||
HRESULT FlushPart();
|
HRESULT FlushPart();
|
||||||
void FlushWithCheck();
|
void FlushWithCheck();
|
||||||
public:
|
public:
|
||||||
#ifdef _NO_EXCEPTIONS
|
#ifdef _NO_EXCEPTIONS
|
||||||
HRESULT ErrorCode;
|
HRESULT ErrorCode;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}
|
COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}
|
||||||
~COutBuffer() { Free(); }
|
~COutBuffer() { Free(); }
|
||||||
|
|
||||||
bool Create(UInt32 bufferSize);
|
bool Create(UInt32 bufferSize);
|
||||||
void Free();
|
void Free();
|
||||||
|
|
||||||
void SetMemStream(Byte *buffer) { _buffer2 = buffer; }
|
void SetMemStream(Byte *buffer) { _buffer2 = buffer; }
|
||||||
void SetStream(ISequentialOutStream *stream);
|
void SetStream(ISequentialOutStream *stream);
|
||||||
void Init();
|
void Init();
|
||||||
HRESULT Flush();
|
HRESULT Flush();
|
||||||
void ReleaseStream() { _stream.Release(); }
|
void ReleaseStream() { _stream.Release(); }
|
||||||
|
|
||||||
void WriteByte(Byte b)
|
void WriteByte(Byte b)
|
||||||
{
|
{
|
||||||
_buffer[_pos++] = b;
|
_buffer[_pos++] = b;
|
||||||
if(_pos == _limitPos)
|
if(_pos == _limitPos)
|
||||||
FlushWithCheck();
|
FlushWithCheck();
|
||||||
}
|
}
|
||||||
void WriteBytes(const void *data, size_t size)
|
void WriteBytes(const void *data, size_t size)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < size; i++)
|
for (size_t i = 0; i < size; i++)
|
||||||
WriteByte(((const Byte *)data)[i]);
|
WriteByte(((const Byte *)data)[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt64 GetProcessedSize() const;
|
UInt64 GetProcessedSize() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
// StdAfx.h
|
// StdAfx.h
|
||||||
|
|
||||||
#ifndef __STDAFX_H
|
#ifndef __STDAFX_H
|
||||||
#define __STDAFX_H
|
#define __STDAFX_H
|
||||||
|
|
||||||
#include "../../Common/MyWindows.h"
|
#include "../../Common/MyWindows.h"
|
||||||
#include "../../Common/NewHandler.h"
|
#include "../../Common/NewHandler.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
// StreamUtils.h
|
// StreamUtils.h
|
||||||
|
|
||||||
#ifndef __STREAMUTILS_H
|
#ifndef __STREAMUTILS_H
|
||||||
#define __STREAMUTILS_H
|
#define __STREAMUTILS_H
|
||||||
|
|
||||||
#include "../IStream.h"
|
#include "../IStream.h"
|
||||||
|
|
||||||
HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize);
|
HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize);
|
||||||
HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize);
|
HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,54 +1,54 @@
|
||||||
// BinTree.h
|
// BinTree.h
|
||||||
|
|
||||||
#include "../LZInWindow.h"
|
#include "../LZInWindow.h"
|
||||||
#include "../IMatchFinder.h"
|
#include "../IMatchFinder.h"
|
||||||
|
|
||||||
namespace BT_NAMESPACE {
|
namespace BT_NAMESPACE {
|
||||||
|
|
||||||
typedef UInt32 CIndex;
|
typedef UInt32 CIndex;
|
||||||
const UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1;
|
const UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1;
|
||||||
|
|
||||||
class CMatchFinder:
|
class CMatchFinder:
|
||||||
public IMatchFinder,
|
public IMatchFinder,
|
||||||
public CLZInWindow,
|
public CLZInWindow,
|
||||||
public CMyUnknownImp,
|
public CMyUnknownImp,
|
||||||
public IMatchFinderSetNumPasses
|
public IMatchFinderSetNumPasses
|
||||||
{
|
{
|
||||||
UInt32 _cyclicBufferPos;
|
UInt32 _cyclicBufferPos;
|
||||||
UInt32 _cyclicBufferSize; // it must be historySize + 1
|
UInt32 _cyclicBufferSize; // it must be historySize + 1
|
||||||
UInt32 _matchMaxLen;
|
UInt32 _matchMaxLen;
|
||||||
CIndex *_hash;
|
CIndex *_hash;
|
||||||
CIndex *_son;
|
CIndex *_son;
|
||||||
UInt32 _hashMask;
|
UInt32 _hashMask;
|
||||||
UInt32 _cutValue;
|
UInt32 _cutValue;
|
||||||
UInt32 _hashSizeSum;
|
UInt32 _hashSizeSum;
|
||||||
|
|
||||||
void Normalize();
|
void Normalize();
|
||||||
void FreeThisClassMemory();
|
void FreeThisClassMemory();
|
||||||
void FreeMemory();
|
void FreeMemory();
|
||||||
|
|
||||||
MY_UNKNOWN_IMP
|
MY_UNKNOWN_IMP
|
||||||
|
|
||||||
STDMETHOD(SetStream)(ISequentialInStream *inStream);
|
STDMETHOD(SetStream)(ISequentialInStream *inStream);
|
||||||
STDMETHOD_(void, ReleaseStream)();
|
STDMETHOD_(void, ReleaseStream)();
|
||||||
STDMETHOD(Init)();
|
STDMETHOD(Init)();
|
||||||
HRESULT MovePos();
|
HRESULT MovePos();
|
||||||
STDMETHOD_(Byte, GetIndexByte)(Int32 index);
|
STDMETHOD_(Byte, GetIndexByte)(Int32 index);
|
||||||
STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);
|
STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);
|
||||||
STDMETHOD_(UInt32, GetNumAvailableBytes)();
|
STDMETHOD_(UInt32, GetNumAvailableBytes)();
|
||||||
STDMETHOD_(const Byte *, GetPointerToCurrentPos)();
|
STDMETHOD_(const Byte *, GetPointerToCurrentPos)();
|
||||||
STDMETHOD_(Int32, NeedChangeBufferPos)(UInt32 numCheckBytes);
|
STDMETHOD_(Int32, NeedChangeBufferPos)(UInt32 numCheckBytes);
|
||||||
STDMETHOD_(void, ChangeBufferPos)();
|
STDMETHOD_(void, ChangeBufferPos)();
|
||||||
|
|
||||||
STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore,
|
STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore,
|
||||||
UInt32 matchMaxLen, UInt32 keepAddBufferAfter);
|
UInt32 matchMaxLen, UInt32 keepAddBufferAfter);
|
||||||
STDMETHOD(GetMatches)(UInt32 *distances);
|
STDMETHOD(GetMatches)(UInt32 *distances);
|
||||||
STDMETHOD(Skip)(UInt32 num);
|
STDMETHOD(Skip)(UInt32 num);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CMatchFinder();
|
CMatchFinder();
|
||||||
virtual ~CMatchFinder();
|
virtual ~CMatchFinder();
|
||||||
virtual void SetNumPasses(UInt32 numPasses) { _cutValue = numPasses; }
|
virtual void SetNumPasses(UInt32 numPasses) { _cutValue = numPasses; }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
// BinTree2.h
|
// BinTree2.h
|
||||||
|
|
||||||
#ifndef __BINTREE2_H
|
#ifndef __BINTREE2_H
|
||||||
#define __BINTREE2_H
|
#define __BINTREE2_H
|
||||||
|
|
||||||
#define BT_NAMESPACE NBT2
|
#define BT_NAMESPACE NBT2
|
||||||
|
|
||||||
#include "BinTreeMain.h"
|
#include "BinTreeMain.h"
|
||||||
|
|
||||||
#undef BT_NAMESPACE
|
#undef BT_NAMESPACE
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
// BinTree3.h
|
// BinTree3.h
|
||||||
|
|
||||||
#ifndef __BINTREE3_H
|
#ifndef __BINTREE3_H
|
||||||
#define __BINTREE3_H
|
#define __BINTREE3_H
|
||||||
|
|
||||||
#define BT_NAMESPACE NBT3
|
#define BT_NAMESPACE NBT3
|
||||||
|
|
||||||
#define HASH_ARRAY_2
|
#define HASH_ARRAY_2
|
||||||
|
|
||||||
#include "BinTreeMain.h"
|
#include "BinTreeMain.h"
|
||||||
|
|
||||||
#undef HASH_ARRAY_2
|
#undef HASH_ARRAY_2
|
||||||
|
|
||||||
#undef BT_NAMESPACE
|
#undef BT_NAMESPACE
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// BinTree4.h
|
// BinTree4.h
|
||||||
|
|
||||||
#ifndef __BINTREE4_H
|
#ifndef __BINTREE4_H
|
||||||
#define __BINTREE4_H
|
#define __BINTREE4_H
|
||||||
|
|
||||||
#define BT_NAMESPACE NBT4
|
#define BT_NAMESPACE NBT4
|
||||||
|
|
||||||
#define HASH_ARRAY_2
|
#define HASH_ARRAY_2
|
||||||
#define HASH_ARRAY_3
|
#define HASH_ARRAY_3
|
||||||
|
|
||||||
#include "BinTreeMain.h"
|
#include "BinTreeMain.h"
|
||||||
|
|
||||||
#undef HASH_ARRAY_2
|
#undef HASH_ARRAY_2
|
||||||
#undef HASH_ARRAY_3
|
#undef HASH_ARRAY_3
|
||||||
|
|
||||||
#undef BT_NAMESPACE
|
#undef BT_NAMESPACE
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,19 +1,19 @@
|
||||||
// HC4.h
|
// HC4.h
|
||||||
|
|
||||||
#ifndef __HC4_H
|
#ifndef __HC4_H
|
||||||
#define __HC4_H
|
#define __HC4_H
|
||||||
|
|
||||||
#define BT_NAMESPACE NHC4
|
#define BT_NAMESPACE NHC4
|
||||||
|
|
||||||
#define HASH_ARRAY_2
|
#define HASH_ARRAY_2
|
||||||
#define HASH_ARRAY_3
|
#define HASH_ARRAY_3
|
||||||
|
|
||||||
#include "HCMain.h"
|
#include "HCMain.h"
|
||||||
|
|
||||||
#undef HASH_ARRAY_2
|
#undef HASH_ARRAY_2
|
||||||
#undef HASH_ARRAY_3
|
#undef HASH_ARRAY_3
|
||||||
|
|
||||||
#undef BT_NAMESPACE
|
#undef BT_NAMESPACE
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// HCMain.h
|
// HCMain.h
|
||||||
|
|
||||||
#define _HASH_CHAIN
|
#define _HASH_CHAIN
|
||||||
#include "../BinTree/BinTreeMain.h"
|
#include "../BinTree/BinTreeMain.h"
|
||||||
#undef _HASH_CHAIN
|
#undef _HASH_CHAIN
|
||||||
|
|
||||||
|
|
|
@ -1,33 +1,33 @@
|
||||||
// MatchFinders/IMatchFinder.h
|
// MatchFinders/IMatchFinder.h
|
||||||
|
|
||||||
#ifndef __IMATCHFINDER_H
|
#ifndef __IMATCHFINDER_H
|
||||||
#define __IMATCHFINDER_H
|
#define __IMATCHFINDER_H
|
||||||
|
|
||||||
struct IInWindowStream: public IUnknown
|
struct IInWindowStream: public IUnknown
|
||||||
{
|
{
|
||||||
STDMETHOD(SetStream)(ISequentialInStream *inStream) PURE;
|
STDMETHOD(SetStream)(ISequentialInStream *inStream) PURE;
|
||||||
STDMETHOD_(void, ReleaseStream)() PURE;
|
STDMETHOD_(void, ReleaseStream)() PURE;
|
||||||
STDMETHOD(Init)() PURE;
|
STDMETHOD(Init)() PURE;
|
||||||
STDMETHOD_(Byte, GetIndexByte)(Int32 index) PURE;
|
STDMETHOD_(Byte, GetIndexByte)(Int32 index) PURE;
|
||||||
STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 distance, UInt32 limit) PURE;
|
STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 distance, UInt32 limit) PURE;
|
||||||
STDMETHOD_(UInt32, GetNumAvailableBytes)() PURE;
|
STDMETHOD_(UInt32, GetNumAvailableBytes)() PURE;
|
||||||
STDMETHOD_(const Byte *, GetPointerToCurrentPos)() PURE;
|
STDMETHOD_(const Byte *, GetPointerToCurrentPos)() PURE;
|
||||||
STDMETHOD_(Int32, NeedChangeBufferPos)(UInt32 numCheckBytes) PURE;
|
STDMETHOD_(Int32, NeedChangeBufferPos)(UInt32 numCheckBytes) PURE;
|
||||||
STDMETHOD_(void, ChangeBufferPos)() PURE;
|
STDMETHOD_(void, ChangeBufferPos)() PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IMatchFinder: public IInWindowStream
|
struct IMatchFinder: public IInWindowStream
|
||||||
{
|
{
|
||||||
STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore,
|
STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore,
|
||||||
UInt32 matchMaxLen, UInt32 keepAddBufferAfter) PURE;
|
UInt32 matchMaxLen, UInt32 keepAddBufferAfter) PURE;
|
||||||
STDMETHOD(GetMatches)(UInt32 *distances) PURE;
|
STDMETHOD(GetMatches)(UInt32 *distances) PURE;
|
||||||
STDMETHOD(Skip)(UInt32 num) PURE;
|
STDMETHOD(Skip)(UInt32 num) PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IMatchFinderSetNumPasses
|
struct IMatchFinderSetNumPasses
|
||||||
{
|
{
|
||||||
//virtual ~IMatchFinderSetNumPasses(){}
|
//virtual ~IMatchFinderSetNumPasses(){}
|
||||||
virtual void SetNumPasses(UInt32 numPasses) PURE;
|
virtual void SetNumPasses(UInt32 numPasses) PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,87 +1,87 @@
|
||||||
// LZInWindow.h
|
// LZInWindow.h
|
||||||
|
|
||||||
#ifndef __LZ_IN_WINDOW_H
|
#ifndef __LZ_IN_WINDOW_H
|
||||||
#define __LZ_IN_WINDOW_H
|
#define __LZ_IN_WINDOW_H
|
||||||
|
|
||||||
#include "../../IStream.h"
|
#include "../../IStream.h"
|
||||||
|
|
||||||
class CLZInWindow
|
class CLZInWindow
|
||||||
{
|
{
|
||||||
Byte *_bufferBase; // pointer to buffer with data
|
Byte *_bufferBase; // pointer to buffer with data
|
||||||
ISequentialInStream *_stream;
|
ISequentialInStream *_stream;
|
||||||
UInt32 _posLimit; // offset (from _buffer) when new block reading must be done
|
UInt32 _posLimit; // offset (from _buffer) when new block reading must be done
|
||||||
bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream
|
bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream
|
||||||
const Byte *_pointerToLastSafePosition;
|
const Byte *_pointerToLastSafePosition;
|
||||||
protected:
|
protected:
|
||||||
Byte *_buffer; // Pointer to virtual Buffer begin
|
Byte *_buffer; // Pointer to virtual Buffer begin
|
||||||
UInt32 _blockSize; // Size of Allocated memory block
|
UInt32 _blockSize; // Size of Allocated memory block
|
||||||
UInt32 _pos; // offset (from _buffer) of curent byte
|
UInt32 _pos; // offset (from _buffer) of curent byte
|
||||||
UInt32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos
|
UInt32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos
|
||||||
UInt32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos
|
UInt32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos
|
||||||
UInt32 _streamPos; // offset (from _buffer) of first not read byte from Stream
|
UInt32 _streamPos; // offset (from _buffer) of first not read byte from Stream
|
||||||
|
|
||||||
void MoveBlock();
|
void MoveBlock();
|
||||||
HRESULT ReadBlock();
|
HRESULT ReadBlock();
|
||||||
void Free();
|
void Free();
|
||||||
public:
|
public:
|
||||||
CLZInWindow(): _bufferBase(0) {}
|
CLZInWindow(): _bufferBase(0) {}
|
||||||
virtual ~CLZInWindow() { Free(); }
|
virtual ~CLZInWindow() { Free(); }
|
||||||
|
|
||||||
// keepSizeBefore + keepSizeAfter + keepSizeReserv < 4G)
|
// keepSizeBefore + keepSizeAfter + keepSizeReserv < 4G)
|
||||||
bool Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv = (1<<17));
|
bool Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv = (1<<17));
|
||||||
|
|
||||||
void SetStream(ISequentialInStream *stream);
|
void SetStream(ISequentialInStream *stream);
|
||||||
HRESULT Init();
|
HRESULT Init();
|
||||||
// void ReleaseStream();
|
// void ReleaseStream();
|
||||||
|
|
||||||
Byte *GetBuffer() const { return _buffer; }
|
Byte *GetBuffer() const { return _buffer; }
|
||||||
|
|
||||||
const Byte *GetPointerToCurrentPos() const { return _buffer + _pos; }
|
const Byte *GetPointerToCurrentPos() const { return _buffer + _pos; }
|
||||||
|
|
||||||
HRESULT MovePos()
|
HRESULT MovePos()
|
||||||
{
|
{
|
||||||
_pos++;
|
_pos++;
|
||||||
if (_pos > _posLimit)
|
if (_pos > _posLimit)
|
||||||
{
|
{
|
||||||
const Byte *pointerToPostion = _buffer + _pos;
|
const Byte *pointerToPostion = _buffer + _pos;
|
||||||
if(pointerToPostion > _pointerToLastSafePosition)
|
if(pointerToPostion > _pointerToLastSafePosition)
|
||||||
MoveBlock();
|
MoveBlock();
|
||||||
return ReadBlock();
|
return ReadBlock();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
Byte GetIndexByte(Int32 index) const { return _buffer[(size_t)_pos + index]; }
|
Byte GetIndexByte(Int32 index) const { return _buffer[(size_t)_pos + index]; }
|
||||||
|
|
||||||
// index + limit have not to exceed _keepSizeAfter;
|
// index + limit have not to exceed _keepSizeAfter;
|
||||||
// -2G <= index < 2G
|
// -2G <= index < 2G
|
||||||
UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) const
|
UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) const
|
||||||
{
|
{
|
||||||
if(_streamEndWasReached)
|
if(_streamEndWasReached)
|
||||||
if ((_pos + index) + limit > _streamPos)
|
if ((_pos + index) + limit > _streamPos)
|
||||||
limit = _streamPos - (_pos + index);
|
limit = _streamPos - (_pos + index);
|
||||||
distance++;
|
distance++;
|
||||||
const Byte *pby = _buffer + (size_t)_pos + index;
|
const Byte *pby = _buffer + (size_t)_pos + index;
|
||||||
UInt32 i;
|
UInt32 i;
|
||||||
for(i = 0; i < limit && pby[i] == pby[(size_t)i - distance]; i++);
|
for(i = 0; i < limit && pby[i] == pby[(size_t)i - distance]; i++);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 GetNumAvailableBytes() const { return _streamPos - _pos; }
|
UInt32 GetNumAvailableBytes() const { return _streamPos - _pos; }
|
||||||
|
|
||||||
void ReduceOffsets(Int32 subValue)
|
void ReduceOffsets(Int32 subValue)
|
||||||
{
|
{
|
||||||
_buffer += subValue;
|
_buffer += subValue;
|
||||||
_posLimit -= subValue;
|
_posLimit -= subValue;
|
||||||
_pos -= subValue;
|
_pos -= subValue;
|
||||||
_streamPos -= subValue;
|
_streamPos -= subValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NeedMove(UInt32 numCheckBytes)
|
bool NeedMove(UInt32 numCheckBytes)
|
||||||
{
|
{
|
||||||
UInt32 reserv = _pointerToLastSafePosition - (_buffer + _pos);
|
UInt32 reserv = _pointerToLastSafePosition - (_buffer + _pos);
|
||||||
return (reserv <= numCheckBytes);
|
return (reserv <= numCheckBytes);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// StdAfx.h
|
// StdAfx.h
|
||||||
|
|
||||||
#ifndef __STDAFX_H
|
#ifndef __STDAFX_H
|
||||||
#define __STDAFX_H
|
#define __STDAFX_H
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,82 +1,82 @@
|
||||||
// LZMA.h
|
// LZMA.h
|
||||||
|
|
||||||
#ifndef __LZMA_H
|
#ifndef __LZMA_H
|
||||||
#define __LZMA_H
|
#define __LZMA_H
|
||||||
|
|
||||||
namespace NCompress {
|
namespace NCompress {
|
||||||
namespace NLZMA {
|
namespace NLZMA {
|
||||||
|
|
||||||
const UInt32 kNumRepDistances = 4;
|
const UInt32 kNumRepDistances = 4;
|
||||||
|
|
||||||
const int kNumStates = 12;
|
const int kNumStates = 12;
|
||||||
|
|
||||||
const Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5};
|
const Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5};
|
||||||
const Byte kMatchNextStates[kNumStates] = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};
|
const Byte kMatchNextStates[kNumStates] = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};
|
||||||
const Byte kRepNextStates[kNumStates] = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
|
const Byte kRepNextStates[kNumStates] = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
|
||||||
const Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
|
const Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
|
||||||
|
|
||||||
class CState
|
class CState
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Byte Index;
|
Byte Index;
|
||||||
void Init() { Index = 0; }
|
void Init() { Index = 0; }
|
||||||
void UpdateChar() { Index = kLiteralNextStates[Index]; }
|
void UpdateChar() { Index = kLiteralNextStates[Index]; }
|
||||||
void UpdateMatch() { Index = kMatchNextStates[Index]; }
|
void UpdateMatch() { Index = kMatchNextStates[Index]; }
|
||||||
void UpdateRep() { Index = kRepNextStates[Index]; }
|
void UpdateRep() { Index = kRepNextStates[Index]; }
|
||||||
void UpdateShortRep() { Index = kShortRepNextStates[Index]; }
|
void UpdateShortRep() { Index = kShortRepNextStates[Index]; }
|
||||||
bool IsCharState() const { return Index < 7; }
|
bool IsCharState() const { return Index < 7; }
|
||||||
};
|
};
|
||||||
|
|
||||||
const int kNumPosSlotBits = 6;
|
const int kNumPosSlotBits = 6;
|
||||||
const int kDicLogSizeMin = 0;
|
const int kDicLogSizeMin = 0;
|
||||||
const int kDicLogSizeMax = 32;
|
const int kDicLogSizeMax = 32;
|
||||||
const int kDistTableSizeMax = kDicLogSizeMax * 2;
|
const int kDistTableSizeMax = kDicLogSizeMax * 2;
|
||||||
|
|
||||||
const UInt32 kNumLenToPosStates = 4;
|
const UInt32 kNumLenToPosStates = 4;
|
||||||
|
|
||||||
inline UInt32 GetLenToPosState(UInt32 len)
|
inline UInt32 GetLenToPosState(UInt32 len)
|
||||||
{
|
{
|
||||||
len -= 2;
|
len -= 2;
|
||||||
if (len < kNumLenToPosStates)
|
if (len < kNumLenToPosStates)
|
||||||
return len;
|
return len;
|
||||||
return kNumLenToPosStates - 1;
|
return kNumLenToPosStates - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace NLength {
|
namespace NLength {
|
||||||
|
|
||||||
const int kNumPosStatesBitsMax = 4;
|
const int kNumPosStatesBitsMax = 4;
|
||||||
const UInt32 kNumPosStatesMax = (1 << kNumPosStatesBitsMax);
|
const UInt32 kNumPosStatesMax = (1 << kNumPosStatesBitsMax);
|
||||||
|
|
||||||
const int kNumPosStatesBitsEncodingMax = 4;
|
const int kNumPosStatesBitsEncodingMax = 4;
|
||||||
const UInt32 kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);
|
const UInt32 kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);
|
||||||
|
|
||||||
const int kNumLowBits = 3;
|
const int kNumLowBits = 3;
|
||||||
const int kNumMidBits = 3;
|
const int kNumMidBits = 3;
|
||||||
const int kNumHighBits = 8;
|
const int kNumHighBits = 8;
|
||||||
const UInt32 kNumLowSymbols = 1 << kNumLowBits;
|
const UInt32 kNumLowSymbols = 1 << kNumLowBits;
|
||||||
const UInt32 kNumMidSymbols = 1 << kNumMidBits;
|
const UInt32 kNumMidSymbols = 1 << kNumMidBits;
|
||||||
const UInt32 kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits);
|
const UInt32 kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const UInt32 kMatchMinLen = 2;
|
const UInt32 kMatchMinLen = 2;
|
||||||
const UInt32 kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1;
|
const UInt32 kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1;
|
||||||
|
|
||||||
const int kNumAlignBits = 4;
|
const int kNumAlignBits = 4;
|
||||||
const UInt32 kAlignTableSize = 1 << kNumAlignBits;
|
const UInt32 kAlignTableSize = 1 << kNumAlignBits;
|
||||||
const UInt32 kAlignMask = (kAlignTableSize - 1);
|
const UInt32 kAlignMask = (kAlignTableSize - 1);
|
||||||
|
|
||||||
const UInt32 kStartPosModelIndex = 4;
|
const UInt32 kStartPosModelIndex = 4;
|
||||||
const UInt32 kEndPosModelIndex = 14;
|
const UInt32 kEndPosModelIndex = 14;
|
||||||
const UInt32 kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;
|
const UInt32 kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;
|
||||||
|
|
||||||
const UInt32 kNumFullDistances = 1 << (kEndPosModelIndex / 2);
|
const UInt32 kNumFullDistances = 1 << (kEndPosModelIndex / 2);
|
||||||
|
|
||||||
const int kNumLitPosStatesBitsEncodingMax = 4;
|
const int kNumLitPosStatesBitsEncodingMax = 4;
|
||||||
const int kNumLitContextBitsMax = 8;
|
const int kNumLitContextBitsMax = 8;
|
||||||
|
|
||||||
const int kNumMoveBits = 5;
|
const int kNumMoveBits = 5;
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,411 +1,411 @@
|
||||||
// LZMA/Encoder.h
|
// LZMA/Encoder.h
|
||||||
|
|
||||||
#ifndef __LZMA_ENCODER_H
|
#ifndef __LZMA_ENCODER_H
|
||||||
#define __LZMA_ENCODER_H
|
#define __LZMA_ENCODER_H
|
||||||
|
|
||||||
#include "../../../Common/MyCom.h"
|
#include "../../../Common/MyCom.h"
|
||||||
#include "../../../Common/Alloc.h"
|
#include "../../../Common/Alloc.h"
|
||||||
#include "../../ICoder.h"
|
#include "../../ICoder.h"
|
||||||
#include "../LZ/IMatchFinder.h"
|
#include "../LZ/IMatchFinder.h"
|
||||||
#include "../RangeCoder/RangeCoderBitTree.h"
|
#include "../RangeCoder/RangeCoderBitTree.h"
|
||||||
|
|
||||||
#include "LZMA.h"
|
#include "LZMA.h"
|
||||||
|
|
||||||
namespace NCompress {
|
namespace NCompress {
|
||||||
namespace NLZMA {
|
namespace NLZMA {
|
||||||
|
|
||||||
typedef NRangeCoder::CBitEncoder<kNumMoveBits> CMyBitEncoder;
|
typedef NRangeCoder::CBitEncoder<kNumMoveBits> CMyBitEncoder;
|
||||||
|
|
||||||
class CBaseState
|
class CBaseState
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
CState _state;
|
CState _state;
|
||||||
Byte _previousByte;
|
Byte _previousByte;
|
||||||
UInt32 _repDistances[kNumRepDistances];
|
UInt32 _repDistances[kNumRepDistances];
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
_state.Init();
|
_state.Init();
|
||||||
_previousByte = 0;
|
_previousByte = 0;
|
||||||
for(UInt32 i = 0 ; i < kNumRepDistances; i++)
|
for(UInt32 i = 0 ; i < kNumRepDistances; i++)
|
||||||
_repDistances[i] = 0;
|
_repDistances[i] = 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct COptimal
|
struct COptimal
|
||||||
{
|
{
|
||||||
CState State;
|
CState State;
|
||||||
|
|
||||||
bool Prev1IsChar;
|
bool Prev1IsChar;
|
||||||
bool Prev2;
|
bool Prev2;
|
||||||
|
|
||||||
UInt32 PosPrev2;
|
UInt32 PosPrev2;
|
||||||
UInt32 BackPrev2;
|
UInt32 BackPrev2;
|
||||||
|
|
||||||
UInt32 Price;
|
UInt32 Price;
|
||||||
UInt32 PosPrev; // posNext;
|
UInt32 PosPrev; // posNext;
|
||||||
UInt32 BackPrev;
|
UInt32 BackPrev;
|
||||||
UInt32 Backs[kNumRepDistances];
|
UInt32 Backs[kNumRepDistances];
|
||||||
void MakeAsChar() { BackPrev = UInt32(-1); Prev1IsChar = false; }
|
void MakeAsChar() { BackPrev = UInt32(-1); Prev1IsChar = false; }
|
||||||
void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }
|
void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }
|
||||||
bool IsShortRep() { return (BackPrev == 0); }
|
bool IsShortRep() { return (BackPrev == 0); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
extern Byte g_FastPos[1 << 11];
|
extern Byte g_FastPos[1 << 11];
|
||||||
inline UInt32 GetPosSlot(UInt32 pos)
|
inline UInt32 GetPosSlot(UInt32 pos)
|
||||||
{
|
{
|
||||||
if (pos < (1 << 11))
|
if (pos < (1 << 11))
|
||||||
return g_FastPos[pos];
|
return g_FastPos[pos];
|
||||||
if (pos < (1 << 21))
|
if (pos < (1 << 21))
|
||||||
return g_FastPos[pos >> 10] + 20;
|
return g_FastPos[pos >> 10] + 20;
|
||||||
return g_FastPos[pos >> 20] + 40;
|
return g_FastPos[pos >> 20] + 40;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline UInt32 GetPosSlot2(UInt32 pos)
|
inline UInt32 GetPosSlot2(UInt32 pos)
|
||||||
{
|
{
|
||||||
if (pos < (1 << 17))
|
if (pos < (1 << 17))
|
||||||
return g_FastPos[pos >> 6] + 12;
|
return g_FastPos[pos >> 6] + 12;
|
||||||
if (pos < (1 << 27))
|
if (pos < (1 << 27))
|
||||||
return g_FastPos[pos >> 16] + 32;
|
return g_FastPos[pos >> 16] + 32;
|
||||||
return g_FastPos[pos >> 26] + 52;
|
return g_FastPos[pos >> 26] + 52;
|
||||||
}
|
}
|
||||||
|
|
||||||
const UInt32 kIfinityPrice = 0xFFFFFFF;
|
const UInt32 kIfinityPrice = 0xFFFFFFF;
|
||||||
|
|
||||||
const UInt32 kNumOpts = 1 << 12;
|
const UInt32 kNumOpts = 1 << 12;
|
||||||
|
|
||||||
|
|
||||||
class CLiteralEncoder2
|
class CLiteralEncoder2
|
||||||
{
|
{
|
||||||
CMyBitEncoder _encoders[0x300];
|
CMyBitEncoder _encoders[0x300];
|
||||||
public:
|
public:
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 0x300; i++)
|
for (int i = 0; i < 0x300; i++)
|
||||||
_encoders[i].Init();
|
_encoders[i].Init();
|
||||||
}
|
}
|
||||||
void Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol);
|
void Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol);
|
||||||
void EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, Byte matchByte, Byte symbol);
|
void EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, Byte matchByte, Byte symbol);
|
||||||
UInt32 GetPrice(bool matchMode, Byte matchByte, Byte symbol) const;
|
UInt32 GetPrice(bool matchMode, Byte matchByte, Byte symbol) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CLiteralEncoder
|
class CLiteralEncoder
|
||||||
{
|
{
|
||||||
CLiteralEncoder2 *_coders;
|
CLiteralEncoder2 *_coders;
|
||||||
int _numPrevBits;
|
int _numPrevBits;
|
||||||
int _numPosBits;
|
int _numPosBits;
|
||||||
UInt32 _posMask;
|
UInt32 _posMask;
|
||||||
public:
|
public:
|
||||||
CLiteralEncoder(): _coders(0) {}
|
CLiteralEncoder(): _coders(0) {}
|
||||||
~CLiteralEncoder() { Free(); }
|
~CLiteralEncoder() { Free(); }
|
||||||
void Free()
|
void Free()
|
||||||
{
|
{
|
||||||
MyFree(_coders);
|
MyFree(_coders);
|
||||||
_coders = 0;
|
_coders = 0;
|
||||||
}
|
}
|
||||||
bool Create(int numPosBits, int numPrevBits)
|
bool Create(int numPosBits, int numPrevBits)
|
||||||
{
|
{
|
||||||
if (_coders == 0 || (numPosBits + numPrevBits) != (_numPrevBits + _numPosBits))
|
if (_coders == 0 || (numPosBits + numPrevBits) != (_numPrevBits + _numPosBits))
|
||||||
{
|
{
|
||||||
Free();
|
Free();
|
||||||
UInt32 numStates = 1 << (numPosBits + numPrevBits);
|
UInt32 numStates = 1 << (numPosBits + numPrevBits);
|
||||||
_coders = (CLiteralEncoder2 *)MyAlloc(numStates * sizeof(CLiteralEncoder2));
|
_coders = (CLiteralEncoder2 *)MyAlloc(numStates * sizeof(CLiteralEncoder2));
|
||||||
}
|
}
|
||||||
_numPosBits = numPosBits;
|
_numPosBits = numPosBits;
|
||||||
_posMask = (1 << numPosBits) - 1;
|
_posMask = (1 << numPosBits) - 1;
|
||||||
_numPrevBits = numPrevBits;
|
_numPrevBits = numPrevBits;
|
||||||
return (_coders != 0);
|
return (_coders != 0);
|
||||||
}
|
}
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
UInt32 numStates = 1 << (_numPrevBits + _numPosBits);
|
UInt32 numStates = 1 << (_numPrevBits + _numPosBits);
|
||||||
for (UInt32 i = 0; i < numStates; i++)
|
for (UInt32 i = 0; i < numStates; i++)
|
||||||
_coders[i].Init();
|
_coders[i].Init();
|
||||||
}
|
}
|
||||||
CLiteralEncoder2 *GetSubCoder(UInt32 pos, Byte prevByte)
|
CLiteralEncoder2 *GetSubCoder(UInt32 pos, Byte prevByte)
|
||||||
{ return &_coders[((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits))]; }
|
{ return &_coders[((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits))]; }
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace NLength {
|
namespace NLength {
|
||||||
|
|
||||||
class CEncoder
|
class CEncoder
|
||||||
{
|
{
|
||||||
CMyBitEncoder _choice;
|
CMyBitEncoder _choice;
|
||||||
CMyBitEncoder _choice2;
|
CMyBitEncoder _choice2;
|
||||||
NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumLowBits> _lowCoder[kNumPosStatesEncodingMax];
|
NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumLowBits> _lowCoder[kNumPosStatesEncodingMax];
|
||||||
NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumMidBits> _midCoder[kNumPosStatesEncodingMax];
|
NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumMidBits> _midCoder[kNumPosStatesEncodingMax];
|
||||||
NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumHighBits> _highCoder;
|
NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumHighBits> _highCoder;
|
||||||
public:
|
public:
|
||||||
void Init(UInt32 numPosStates);
|
void Init(UInt32 numPosStates);
|
||||||
void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState);
|
void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState);
|
||||||
void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32 *prices) const;
|
void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32 *prices) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
const UInt32 kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;
|
const UInt32 kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;
|
||||||
|
|
||||||
class CPriceTableEncoder: public CEncoder
|
class CPriceTableEncoder: public CEncoder
|
||||||
{
|
{
|
||||||
UInt32 _prices[kNumPosStatesEncodingMax][kNumSymbolsTotal];
|
UInt32 _prices[kNumPosStatesEncodingMax][kNumSymbolsTotal];
|
||||||
UInt32 _tableSize;
|
UInt32 _tableSize;
|
||||||
UInt32 _counters[kNumPosStatesEncodingMax];
|
UInt32 _counters[kNumPosStatesEncodingMax];
|
||||||
public:
|
public:
|
||||||
void SetTableSize(UInt32 tableSize) { _tableSize = tableSize; }
|
void SetTableSize(UInt32 tableSize) { _tableSize = tableSize; }
|
||||||
UInt32 GetPrice(UInt32 symbol, UInt32 posState) const { return _prices[posState][symbol]; }
|
UInt32 GetPrice(UInt32 symbol, UInt32 posState) const { return _prices[posState][symbol]; }
|
||||||
void UpdateTable(UInt32 posState)
|
void UpdateTable(UInt32 posState)
|
||||||
{
|
{
|
||||||
SetPrices(posState, _tableSize, _prices[posState]);
|
SetPrices(posState, _tableSize, _prices[posState]);
|
||||||
_counters[posState] = _tableSize;
|
_counters[posState] = _tableSize;
|
||||||
}
|
}
|
||||||
void UpdateTables(UInt32 numPosStates)
|
void UpdateTables(UInt32 numPosStates)
|
||||||
{
|
{
|
||||||
for (UInt32 posState = 0; posState < numPosStates; posState++)
|
for (UInt32 posState = 0; posState < numPosStates; posState++)
|
||||||
UpdateTable(posState);
|
UpdateTable(posState);
|
||||||
}
|
}
|
||||||
void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState, bool updatePrice)
|
void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState, bool updatePrice)
|
||||||
{
|
{
|
||||||
CEncoder::Encode(rangeEncoder, symbol, posState);
|
CEncoder::Encode(rangeEncoder, symbol, posState);
|
||||||
if (updatePrice)
|
if (updatePrice)
|
||||||
if (--_counters[posState] == 0)
|
if (--_counters[posState] == 0)
|
||||||
UpdateTable(posState);
|
UpdateTable(posState);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class CEncoder :
|
class CEncoder :
|
||||||
public ICompressCoder,
|
public ICompressCoder,
|
||||||
public ICompressSetOutStream,
|
public ICompressSetOutStream,
|
||||||
public ICompressSetCoderProperties,
|
public ICompressSetCoderProperties,
|
||||||
public ICompressWriteCoderProperties,
|
public ICompressWriteCoderProperties,
|
||||||
public CBaseState,
|
public CBaseState,
|
||||||
public CMyUnknownImp
|
public CMyUnknownImp
|
||||||
{
|
{
|
||||||
COptimal _optimum[kNumOpts];
|
COptimal _optimum[kNumOpts];
|
||||||
CMyComPtr<IMatchFinder> _matchFinder; // test it
|
CMyComPtr<IMatchFinder> _matchFinder; // test it
|
||||||
NRangeCoder::CEncoder _rangeEncoder;
|
NRangeCoder::CEncoder _rangeEncoder;
|
||||||
|
|
||||||
CMyBitEncoder _isMatch[kNumStates][NLength::kNumPosStatesEncodingMax];
|
CMyBitEncoder _isMatch[kNumStates][NLength::kNumPosStatesEncodingMax];
|
||||||
CMyBitEncoder _isRep[kNumStates];
|
CMyBitEncoder _isRep[kNumStates];
|
||||||
CMyBitEncoder _isRepG0[kNumStates];
|
CMyBitEncoder _isRepG0[kNumStates];
|
||||||
CMyBitEncoder _isRepG1[kNumStates];
|
CMyBitEncoder _isRepG1[kNumStates];
|
||||||
CMyBitEncoder _isRepG2[kNumStates];
|
CMyBitEncoder _isRepG2[kNumStates];
|
||||||
CMyBitEncoder _isRep0Long[kNumStates][NLength::kNumPosStatesEncodingMax];
|
CMyBitEncoder _isRep0Long[kNumStates][NLength::kNumPosStatesEncodingMax];
|
||||||
|
|
||||||
NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> _posSlotEncoder[kNumLenToPosStates];
|
NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> _posSlotEncoder[kNumLenToPosStates];
|
||||||
|
|
||||||
CMyBitEncoder _posEncoders[kNumFullDistances - kEndPosModelIndex];
|
CMyBitEncoder _posEncoders[kNumFullDistances - kEndPosModelIndex];
|
||||||
NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumAlignBits> _posAlignEncoder;
|
NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumAlignBits> _posAlignEncoder;
|
||||||
|
|
||||||
NLength::CPriceTableEncoder _lenEncoder;
|
NLength::CPriceTableEncoder _lenEncoder;
|
||||||
NLength::CPriceTableEncoder _repMatchLenEncoder;
|
NLength::CPriceTableEncoder _repMatchLenEncoder;
|
||||||
|
|
||||||
CLiteralEncoder _literalEncoder;
|
CLiteralEncoder _literalEncoder;
|
||||||
|
|
||||||
UInt32 _matchDistances[kMatchMaxLen * 2 + 2 + 1];
|
UInt32 _matchDistances[kMatchMaxLen * 2 + 2 + 1];
|
||||||
|
|
||||||
bool _fastMode;
|
bool _fastMode;
|
||||||
// bool _maxMode;
|
// bool _maxMode;
|
||||||
UInt32 _numFastBytes;
|
UInt32 _numFastBytes;
|
||||||
UInt32 _longestMatchLength;
|
UInt32 _longestMatchLength;
|
||||||
UInt32 _numDistancePairs;
|
UInt32 _numDistancePairs;
|
||||||
|
|
||||||
UInt32 _additionalOffset;
|
UInt32 _additionalOffset;
|
||||||
|
|
||||||
UInt32 _optimumEndIndex;
|
UInt32 _optimumEndIndex;
|
||||||
UInt32 _optimumCurrentIndex;
|
UInt32 _optimumCurrentIndex;
|
||||||
|
|
||||||
bool _longestMatchWasFound;
|
bool _longestMatchWasFound;
|
||||||
|
|
||||||
UInt32 _posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];
|
UInt32 _posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];
|
||||||
|
|
||||||
UInt32 _distancesPrices[kNumLenToPosStates][kNumFullDistances];
|
UInt32 _distancesPrices[kNumLenToPosStates][kNumFullDistances];
|
||||||
|
|
||||||
UInt32 _alignPrices[kAlignTableSize];
|
UInt32 _alignPrices[kAlignTableSize];
|
||||||
UInt32 _alignPriceCount;
|
UInt32 _alignPriceCount;
|
||||||
|
|
||||||
UInt32 _distTableSize;
|
UInt32 _distTableSize;
|
||||||
|
|
||||||
UInt32 _posStateBits;
|
UInt32 _posStateBits;
|
||||||
UInt32 _posStateMask;
|
UInt32 _posStateMask;
|
||||||
UInt32 _numLiteralPosStateBits;
|
UInt32 _numLiteralPosStateBits;
|
||||||
UInt32 _numLiteralContextBits;
|
UInt32 _numLiteralContextBits;
|
||||||
|
|
||||||
UInt32 _dictionarySize;
|
UInt32 _dictionarySize;
|
||||||
|
|
||||||
UInt32 _dictionarySizePrev;
|
UInt32 _dictionarySizePrev;
|
||||||
UInt32 _numFastBytesPrev;
|
UInt32 _numFastBytesPrev;
|
||||||
|
|
||||||
UInt32 _matchPriceCount;
|
UInt32 _matchPriceCount;
|
||||||
UInt64 nowPos64;
|
UInt64 nowPos64;
|
||||||
bool _finished;
|
bool _finished;
|
||||||
ISequentialInStream *_inStream;
|
ISequentialInStream *_inStream;
|
||||||
|
|
||||||
UInt32 _matchFinderCycles;
|
UInt32 _matchFinderCycles;
|
||||||
int _matchFinderIndex;
|
int _matchFinderIndex;
|
||||||
#ifdef COMPRESS_MF_MT
|
#ifdef COMPRESS_MF_MT
|
||||||
bool _multiThread;
|
bool _multiThread;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool _writeEndMark;
|
bool _writeEndMark;
|
||||||
|
|
||||||
bool _needReleaseMFStream;
|
bool _needReleaseMFStream;
|
||||||
|
|
||||||
IMatchFinderSetNumPasses *setMfPasses;
|
IMatchFinderSetNumPasses *setMfPasses;
|
||||||
|
|
||||||
void ReleaseMatchFinder()
|
void ReleaseMatchFinder()
|
||||||
{
|
{
|
||||||
setMfPasses = 0;
|
setMfPasses = 0;
|
||||||
_matchFinder.Release();
|
_matchFinder.Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT ReadMatchDistances(UInt32 &len, UInt32 &numDistancePairs);
|
HRESULT ReadMatchDistances(UInt32 &len, UInt32 &numDistancePairs);
|
||||||
|
|
||||||
HRESULT MovePos(UInt32 num);
|
HRESULT MovePos(UInt32 num);
|
||||||
UInt32 GetRepLen1Price(CState state, UInt32 posState) const
|
UInt32 GetRepLen1Price(CState state, UInt32 posState) const
|
||||||
{
|
{
|
||||||
return _isRepG0[state.Index].GetPrice0() +
|
return _isRepG0[state.Index].GetPrice0() +
|
||||||
_isRep0Long[state.Index][posState].GetPrice0();
|
_isRep0Long[state.Index][posState].GetPrice0();
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 GetPureRepPrice(UInt32 repIndex, CState state, UInt32 posState) const
|
UInt32 GetPureRepPrice(UInt32 repIndex, CState state, UInt32 posState) const
|
||||||
{
|
{
|
||||||
UInt32 price;
|
UInt32 price;
|
||||||
if(repIndex == 0)
|
if(repIndex == 0)
|
||||||
{
|
{
|
||||||
price = _isRepG0[state.Index].GetPrice0();
|
price = _isRepG0[state.Index].GetPrice0();
|
||||||
price += _isRep0Long[state.Index][posState].GetPrice1();
|
price += _isRep0Long[state.Index][posState].GetPrice1();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
price = _isRepG0[state.Index].GetPrice1();
|
price = _isRepG0[state.Index].GetPrice1();
|
||||||
if (repIndex == 1)
|
if (repIndex == 1)
|
||||||
price += _isRepG1[state.Index].GetPrice0();
|
price += _isRepG1[state.Index].GetPrice0();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
price += _isRepG1[state.Index].GetPrice1();
|
price += _isRepG1[state.Index].GetPrice1();
|
||||||
price += _isRepG2[state.Index].GetPrice(repIndex - 2);
|
price += _isRepG2[state.Index].GetPrice(repIndex - 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
UInt32 GetRepPrice(UInt32 repIndex, UInt32 len, CState state, UInt32 posState) const
|
UInt32 GetRepPrice(UInt32 repIndex, UInt32 len, CState state, UInt32 posState) const
|
||||||
{
|
{
|
||||||
return _repMatchLenEncoder.GetPrice(len - kMatchMinLen, posState) +
|
return _repMatchLenEncoder.GetPrice(len - kMatchMinLen, posState) +
|
||||||
GetPureRepPrice(repIndex, state, posState);
|
GetPureRepPrice(repIndex, state, posState);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
UInt32 GetPosLen2Price(UInt32 pos, UInt32 posState) const
|
UInt32 GetPosLen2Price(UInt32 pos, UInt32 posState) const
|
||||||
{
|
{
|
||||||
if (pos >= kNumFullDistances)
|
if (pos >= kNumFullDistances)
|
||||||
return kIfinityPrice;
|
return kIfinityPrice;
|
||||||
return _distancesPrices[0][pos] + _lenEncoder.GetPrice(0, posState);
|
return _distancesPrices[0][pos] + _lenEncoder.GetPrice(0, posState);
|
||||||
}
|
}
|
||||||
UInt32 GetPosLen3Price(UInt32 pos, UInt32 len, UInt32 posState) const
|
UInt32 GetPosLen3Price(UInt32 pos, UInt32 len, UInt32 posState) const
|
||||||
{
|
{
|
||||||
UInt32 price;
|
UInt32 price;
|
||||||
UInt32 lenToPosState = GetLenToPosState(len);
|
UInt32 lenToPosState = GetLenToPosState(len);
|
||||||
if (pos < kNumFullDistances)
|
if (pos < kNumFullDistances)
|
||||||
price = _distancesPrices[lenToPosState][pos];
|
price = _distancesPrices[lenToPosState][pos];
|
||||||
else
|
else
|
||||||
price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] +
|
price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] +
|
||||||
_alignPrices[pos & kAlignMask];
|
_alignPrices[pos & kAlignMask];
|
||||||
return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);
|
return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
UInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState) const
|
UInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState) const
|
||||||
{
|
{
|
||||||
UInt32 price;
|
UInt32 price;
|
||||||
UInt32 lenToPosState = GetLenToPosState(len);
|
UInt32 lenToPosState = GetLenToPosState(len);
|
||||||
if (pos < kNumFullDistances)
|
if (pos < kNumFullDistances)
|
||||||
price = _distancesPrices[lenToPosState][pos];
|
price = _distancesPrices[lenToPosState][pos];
|
||||||
else
|
else
|
||||||
price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] +
|
price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] +
|
||||||
_alignPrices[pos & kAlignMask];
|
_alignPrices[pos & kAlignMask];
|
||||||
return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);
|
return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 Backward(UInt32 &backRes, UInt32 cur);
|
UInt32 Backward(UInt32 &backRes, UInt32 cur);
|
||||||
HRESULT GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes);
|
HRESULT GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes);
|
||||||
HRESULT GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRes);
|
HRESULT GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRes);
|
||||||
|
|
||||||
void FillDistancesPrices();
|
void FillDistancesPrices();
|
||||||
void FillAlignPrices();
|
void FillAlignPrices();
|
||||||
|
|
||||||
void ReleaseMFStream()
|
void ReleaseMFStream()
|
||||||
{
|
{
|
||||||
if (_matchFinder && _needReleaseMFStream)
|
if (_matchFinder && _needReleaseMFStream)
|
||||||
{
|
{
|
||||||
_matchFinder->ReleaseStream();
|
_matchFinder->ReleaseStream();
|
||||||
_needReleaseMFStream = false;
|
_needReleaseMFStream = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReleaseStreams()
|
void ReleaseStreams()
|
||||||
{
|
{
|
||||||
ReleaseMFStream();
|
ReleaseMFStream();
|
||||||
ReleaseOutStream();
|
ReleaseOutStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT Flush(UInt32 nowPos);
|
HRESULT Flush(UInt32 nowPos);
|
||||||
class CCoderReleaser
|
class CCoderReleaser
|
||||||
{
|
{
|
||||||
CEncoder *_coder;
|
CEncoder *_coder;
|
||||||
public:
|
public:
|
||||||
CCoderReleaser(CEncoder *coder): _coder(coder) {}
|
CCoderReleaser(CEncoder *coder): _coder(coder) {}
|
||||||
~CCoderReleaser()
|
~CCoderReleaser()
|
||||||
{
|
{
|
||||||
_coder->ReleaseStreams();
|
_coder->ReleaseStreams();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
friend class CCoderReleaser;
|
friend class CCoderReleaser;
|
||||||
|
|
||||||
void WriteEndMarker(UInt32 posState);
|
void WriteEndMarker(UInt32 posState);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CEncoder();
|
CEncoder();
|
||||||
void SetWriteEndMarkerMode(bool writeEndMarker)
|
void SetWriteEndMarkerMode(bool writeEndMarker)
|
||||||
{ _writeEndMark= writeEndMarker; }
|
{ _writeEndMark= writeEndMarker; }
|
||||||
|
|
||||||
HRESULT Create();
|
HRESULT Create();
|
||||||
|
|
||||||
MY_UNKNOWN_IMP3(
|
MY_UNKNOWN_IMP3(
|
||||||
ICompressSetOutStream,
|
ICompressSetOutStream,
|
||||||
ICompressSetCoderProperties,
|
ICompressSetCoderProperties,
|
||||||
ICompressWriteCoderProperties
|
ICompressWriteCoderProperties
|
||||||
)
|
)
|
||||||
|
|
||||||
HRESULT Init();
|
HRESULT Init();
|
||||||
|
|
||||||
// ICompressCoder interface
|
// ICompressCoder interface
|
||||||
HRESULT SetStreams(ISequentialInStream *inStream,
|
HRESULT SetStreams(ISequentialInStream *inStream,
|
||||||
ISequentialOutStream *outStream,
|
ISequentialOutStream *outStream,
|
||||||
const UInt64 *inSize, const UInt64 *outSize);
|
const UInt64 *inSize, const UInt64 *outSize);
|
||||||
HRESULT CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished);
|
HRESULT CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished);
|
||||||
|
|
||||||
HRESULT CodeReal(ISequentialInStream *inStream,
|
HRESULT CodeReal(ISequentialInStream *inStream,
|
||||||
ISequentialOutStream *outStream,
|
ISequentialOutStream *outStream,
|
||||||
const UInt64 *inSize, const UInt64 *outSize,
|
const UInt64 *inSize, const UInt64 *outSize,
|
||||||
ICompressProgressInfo *progress);
|
ICompressProgressInfo *progress);
|
||||||
|
|
||||||
// ICompressCoder interface
|
// ICompressCoder interface
|
||||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||||
ISequentialOutStream *outStream,
|
ISequentialOutStream *outStream,
|
||||||
const UInt64 *inSize, const UInt64 *outSize,
|
const UInt64 *inSize, const UInt64 *outSize,
|
||||||
ICompressProgressInfo *progress);
|
ICompressProgressInfo *progress);
|
||||||
|
|
||||||
// ICompressSetCoderProperties2
|
// ICompressSetCoderProperties2
|
||||||
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
||||||
const PROPVARIANT *properties, UInt32 numProperties);
|
const PROPVARIANT *properties, UInt32 numProperties);
|
||||||
|
|
||||||
// ICompressWriteCoderProperties
|
// ICompressWriteCoderProperties
|
||||||
STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
|
STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
|
||||||
|
|
||||||
STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);
|
STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);
|
||||||
STDMETHOD(ReleaseOutStream)();
|
STDMETHOD(ReleaseOutStream)();
|
||||||
|
|
||||||
virtual ~CEncoder() {}
|
virtual ~CEncoder() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// StdAfx.h
|
// StdAfx.h
|
||||||
|
|
||||||
#ifndef __STDAFX_H
|
#ifndef __STDAFX_H
|
||||||
#define __STDAFX_H
|
#define __STDAFX_H
|
||||||
|
|
||||||
#include "../../../Common/MyWindows.h"
|
#include "../../../Common/MyWindows.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,205 +1,205 @@
|
||||||
// Compress/RangeCoder/RangeCoder.h
|
// Compress/RangeCoder/RangeCoder.h
|
||||||
|
|
||||||
#ifndef __COMPRESS_RANGECODER_H
|
#ifndef __COMPRESS_RANGECODER_H
|
||||||
#define __COMPRESS_RANGECODER_H
|
#define __COMPRESS_RANGECODER_H
|
||||||
|
|
||||||
#include "../../Common/InBuffer.h"
|
#include "../../Common/InBuffer.h"
|
||||||
#include "../../Common/OutBuffer.h"
|
#include "../../Common/OutBuffer.h"
|
||||||
|
|
||||||
namespace NCompress {
|
namespace NCompress {
|
||||||
namespace NRangeCoder {
|
namespace NRangeCoder {
|
||||||
|
|
||||||
const int kNumTopBits = 24;
|
const int kNumTopBits = 24;
|
||||||
const UInt32 kTopValue = (1 << kNumTopBits);
|
const UInt32 kTopValue = (1 << kNumTopBits);
|
||||||
|
|
||||||
class CEncoder
|
class CEncoder
|
||||||
{
|
{
|
||||||
UInt32 _cacheSize;
|
UInt32 _cacheSize;
|
||||||
Byte _cache;
|
Byte _cache;
|
||||||
public:
|
public:
|
||||||
UInt64 Low;
|
UInt64 Low;
|
||||||
UInt32 Range;
|
UInt32 Range;
|
||||||
COutBuffer Stream;
|
COutBuffer Stream;
|
||||||
bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }
|
bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }
|
||||||
|
|
||||||
void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }
|
void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
Stream.Init();
|
Stream.Init();
|
||||||
Low = 0;
|
Low = 0;
|
||||||
Range = 0xFFFFFFFF;
|
Range = 0xFFFFFFFF;
|
||||||
_cacheSize = 1;
|
_cacheSize = 1;
|
||||||
_cache = 0;
|
_cache = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlushData()
|
void FlushData()
|
||||||
{
|
{
|
||||||
// Low += 1;
|
// Low += 1;
|
||||||
for(int i = 0; i < 5; i++)
|
for(int i = 0; i < 5; i++)
|
||||||
ShiftLow();
|
ShiftLow();
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT FlushStream() { return Stream.Flush(); }
|
HRESULT FlushStream() { return Stream.Flush(); }
|
||||||
|
|
||||||
void ReleaseStream() { Stream.ReleaseStream(); }
|
void ReleaseStream() { Stream.ReleaseStream(); }
|
||||||
|
|
||||||
void Encode(UInt32 start, UInt32 size, UInt32 total)
|
void Encode(UInt32 start, UInt32 size, UInt32 total)
|
||||||
{
|
{
|
||||||
Low += start * (Range /= total);
|
Low += start * (Range /= total);
|
||||||
Range *= size;
|
Range *= size;
|
||||||
while (Range < kTopValue)
|
while (Range < kTopValue)
|
||||||
{
|
{
|
||||||
Range <<= 8;
|
Range <<= 8;
|
||||||
ShiftLow();
|
ShiftLow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShiftLow()
|
void ShiftLow()
|
||||||
{
|
{
|
||||||
if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0)
|
if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0)
|
||||||
{
|
{
|
||||||
Byte temp = _cache;
|
Byte temp = _cache;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));
|
Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));
|
||||||
temp = 0xFF;
|
temp = 0xFF;
|
||||||
}
|
}
|
||||||
while(--_cacheSize != 0);
|
while(--_cacheSize != 0);
|
||||||
_cache = (Byte)((UInt32)Low >> 24);
|
_cache = (Byte)((UInt32)Low >> 24);
|
||||||
}
|
}
|
||||||
_cacheSize++;
|
_cacheSize++;
|
||||||
Low = (UInt32)Low << 8;
|
Low = (UInt32)Low << 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EncodeDirectBits(UInt32 value, int numTotalBits)
|
void EncodeDirectBits(UInt32 value, int numTotalBits)
|
||||||
{
|
{
|
||||||
for (int i = numTotalBits - 1; i >= 0; i--)
|
for (int i = numTotalBits - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
Range >>= 1;
|
Range >>= 1;
|
||||||
if (((value >> i) & 1) == 1)
|
if (((value >> i) & 1) == 1)
|
||||||
Low += Range;
|
Low += Range;
|
||||||
if (Range < kTopValue)
|
if (Range < kTopValue)
|
||||||
{
|
{
|
||||||
Range <<= 8;
|
Range <<= 8;
|
||||||
ShiftLow();
|
ShiftLow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol)
|
void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol)
|
||||||
{
|
{
|
||||||
UInt32 newBound = (Range >> numTotalBits) * size0;
|
UInt32 newBound = (Range >> numTotalBits) * size0;
|
||||||
if (symbol == 0)
|
if (symbol == 0)
|
||||||
Range = newBound;
|
Range = newBound;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Low += newBound;
|
Low += newBound;
|
||||||
Range -= newBound;
|
Range -= newBound;
|
||||||
}
|
}
|
||||||
while (Range < kTopValue)
|
while (Range < kTopValue)
|
||||||
{
|
{
|
||||||
Range <<= 8;
|
Range <<= 8;
|
||||||
ShiftLow();
|
ShiftLow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt64 GetProcessedSize() { return Stream.GetProcessedSize() + _cacheSize + 4; }
|
UInt64 GetProcessedSize() { return Stream.GetProcessedSize() + _cacheSize + 4; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class CDecoder
|
class CDecoder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CInBuffer Stream;
|
CInBuffer Stream;
|
||||||
UInt32 Range;
|
UInt32 Range;
|
||||||
UInt32 Code;
|
UInt32 Code;
|
||||||
bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }
|
bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }
|
||||||
|
|
||||||
void Normalize()
|
void Normalize()
|
||||||
{
|
{
|
||||||
while (Range < kTopValue)
|
while (Range < kTopValue)
|
||||||
{
|
{
|
||||||
Code = (Code << 8) | Stream.ReadByte();
|
Code = (Code << 8) | Stream.ReadByte();
|
||||||
Range <<= 8;
|
Range <<= 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }
|
void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
Stream.Init();
|
Stream.Init();
|
||||||
Code = 0;
|
Code = 0;
|
||||||
Range = 0xFFFFFFFF;
|
Range = 0xFFFFFFFF;
|
||||||
for(int i = 0; i < 5; i++)
|
for(int i = 0; i < 5; i++)
|
||||||
Code = (Code << 8) | Stream.ReadByte();
|
Code = (Code << 8) | Stream.ReadByte();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReleaseStream() { Stream.ReleaseStream(); }
|
void ReleaseStream() { Stream.ReleaseStream(); }
|
||||||
|
|
||||||
UInt32 GetThreshold(UInt32 total)
|
UInt32 GetThreshold(UInt32 total)
|
||||||
{
|
{
|
||||||
return (Code) / ( Range /= total);
|
return (Code) / ( Range /= total);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Decode(UInt32 start, UInt32 size)
|
void Decode(UInt32 start, UInt32 size)
|
||||||
{
|
{
|
||||||
Code -= start * Range;
|
Code -= start * Range;
|
||||||
Range *= size;
|
Range *= size;
|
||||||
Normalize();
|
Normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 DecodeDirectBits(int numTotalBits)
|
UInt32 DecodeDirectBits(int numTotalBits)
|
||||||
{
|
{
|
||||||
UInt32 range = Range;
|
UInt32 range = Range;
|
||||||
UInt32 code = Code;
|
UInt32 code = Code;
|
||||||
UInt32 result = 0;
|
UInt32 result = 0;
|
||||||
for (int i = numTotalBits; i != 0; i--)
|
for (int i = numTotalBits; i != 0; i--)
|
||||||
{
|
{
|
||||||
range >>= 1;
|
range >>= 1;
|
||||||
/*
|
/*
|
||||||
result <<= 1;
|
result <<= 1;
|
||||||
if (code >= range)
|
if (code >= range)
|
||||||
{
|
{
|
||||||
code -= range;
|
code -= range;
|
||||||
result |= 1;
|
result |= 1;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
UInt32 t = (code - range) >> 31;
|
UInt32 t = (code - range) >> 31;
|
||||||
code -= range & (t - 1);
|
code -= range & (t - 1);
|
||||||
result = (result << 1) | (1 - t);
|
result = (result << 1) | (1 - t);
|
||||||
|
|
||||||
if (range < kTopValue)
|
if (range < kTopValue)
|
||||||
{
|
{
|
||||||
code = (code << 8) | Stream.ReadByte();
|
code = (code << 8) | Stream.ReadByte();
|
||||||
range <<= 8;
|
range <<= 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Range = range;
|
Range = range;
|
||||||
Code = code;
|
Code = code;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)
|
UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)
|
||||||
{
|
{
|
||||||
UInt32 newBound = (Range >> numTotalBits) * size0;
|
UInt32 newBound = (Range >> numTotalBits) * size0;
|
||||||
UInt32 symbol;
|
UInt32 symbol;
|
||||||
if (Code < newBound)
|
if (Code < newBound)
|
||||||
{
|
{
|
||||||
symbol = 0;
|
symbol = 0;
|
||||||
Range = newBound;
|
Range = newBound;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
symbol = 1;
|
symbol = 1;
|
||||||
Code -= newBound;
|
Code -= newBound;
|
||||||
Range -= newBound;
|
Range -= newBound;
|
||||||
}
|
}
|
||||||
Normalize();
|
Normalize();
|
||||||
return symbol;
|
return symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); }
|
UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,120 +1,120 @@
|
||||||
// Compress/RangeCoder/RangeCoderBit.h
|
// Compress/RangeCoder/RangeCoderBit.h
|
||||||
|
|
||||||
#ifndef __COMPRESS_RANGECODER_BIT_H
|
#ifndef __COMPRESS_RANGECODER_BIT_H
|
||||||
#define __COMPRESS_RANGECODER_BIT_H
|
#define __COMPRESS_RANGECODER_BIT_H
|
||||||
|
|
||||||
#include "RangeCoder.h"
|
#include "RangeCoder.h"
|
||||||
|
|
||||||
namespace NCompress {
|
namespace NCompress {
|
||||||
namespace NRangeCoder {
|
namespace NRangeCoder {
|
||||||
|
|
||||||
const int kNumBitModelTotalBits = 11;
|
const int kNumBitModelTotalBits = 11;
|
||||||
const UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);
|
const UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);
|
||||||
|
|
||||||
const int kNumMoveReducingBits = 2;
|
const int kNumMoveReducingBits = 2;
|
||||||
|
|
||||||
const int kNumBitPriceShiftBits = 6;
|
const int kNumBitPriceShiftBits = 6;
|
||||||
const UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;
|
const UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;
|
||||||
|
|
||||||
class CPriceTables
|
class CPriceTables
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
|
static UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
|
||||||
static void Init();
|
static void Init();
|
||||||
CPriceTables();
|
CPriceTables();
|
||||||
};
|
};
|
||||||
|
|
||||||
template <int numMoveBits>
|
template <int numMoveBits>
|
||||||
class CBitModel
|
class CBitModel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UInt32 Prob;
|
UInt32 Prob;
|
||||||
void UpdateModel(UInt32 symbol)
|
void UpdateModel(UInt32 symbol)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;
|
Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;
|
||||||
Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);
|
Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);
|
||||||
*/
|
*/
|
||||||
if (symbol == 0)
|
if (symbol == 0)
|
||||||
Prob += (kBitModelTotal - Prob) >> numMoveBits;
|
Prob += (kBitModelTotal - Prob) >> numMoveBits;
|
||||||
else
|
else
|
||||||
Prob -= (Prob) >> numMoveBits;
|
Prob -= (Prob) >> numMoveBits;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
void Init() { Prob = kBitModelTotal / 2; }
|
void Init() { Prob = kBitModelTotal / 2; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <int numMoveBits>
|
template <int numMoveBits>
|
||||||
class CBitEncoder: public CBitModel<numMoveBits>
|
class CBitEncoder: public CBitModel<numMoveBits>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void Encode(CEncoder *encoder, UInt32 symbol)
|
void Encode(CEncoder *encoder, UInt32 symbol)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);
|
encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);
|
||||||
this->UpdateModel(symbol);
|
this->UpdateModel(symbol);
|
||||||
*/
|
*/
|
||||||
UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;
|
UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;
|
||||||
if (symbol == 0)
|
if (symbol == 0)
|
||||||
{
|
{
|
||||||
encoder->Range = newBound;
|
encoder->Range = newBound;
|
||||||
this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;
|
this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
encoder->Low += newBound;
|
encoder->Low += newBound;
|
||||||
encoder->Range -= newBound;
|
encoder->Range -= newBound;
|
||||||
this->Prob -= (this->Prob) >> numMoveBits;
|
this->Prob -= (this->Prob) >> numMoveBits;
|
||||||
}
|
}
|
||||||
if (encoder->Range < kTopValue)
|
if (encoder->Range < kTopValue)
|
||||||
{
|
{
|
||||||
encoder->Range <<= 8;
|
encoder->Range <<= 8;
|
||||||
encoder->ShiftLow();
|
encoder->ShiftLow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UInt32 GetPrice(UInt32 symbol) const
|
UInt32 GetPrice(UInt32 symbol) const
|
||||||
{
|
{
|
||||||
return CPriceTables::ProbPrices[
|
return CPriceTables::ProbPrices[
|
||||||
(((this->Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];
|
(((this->Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];
|
||||||
}
|
}
|
||||||
UInt32 GetPrice0() const { return CPriceTables::ProbPrices[this->Prob >> kNumMoveReducingBits]; }
|
UInt32 GetPrice0() const { return CPriceTables::ProbPrices[this->Prob >> kNumMoveReducingBits]; }
|
||||||
UInt32 GetPrice1() const { return CPriceTables::ProbPrices[(kBitModelTotal - this->Prob) >> kNumMoveReducingBits]; }
|
UInt32 GetPrice1() const { return CPriceTables::ProbPrices[(kBitModelTotal - this->Prob) >> kNumMoveReducingBits]; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <int numMoveBits>
|
template <int numMoveBits>
|
||||||
class CBitDecoder: public CBitModel<numMoveBits>
|
class CBitDecoder: public CBitModel<numMoveBits>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UInt32 Decode(CDecoder *decoder)
|
UInt32 Decode(CDecoder *decoder)
|
||||||
{
|
{
|
||||||
UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob;
|
UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob;
|
||||||
if (decoder->Code < newBound)
|
if (decoder->Code < newBound)
|
||||||
{
|
{
|
||||||
decoder->Range = newBound;
|
decoder->Range = newBound;
|
||||||
this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;
|
this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;
|
||||||
if (decoder->Range < kTopValue)
|
if (decoder->Range < kTopValue)
|
||||||
{
|
{
|
||||||
decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();
|
decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();
|
||||||
decoder->Range <<= 8;
|
decoder->Range <<= 8;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
decoder->Range -= newBound;
|
decoder->Range -= newBound;
|
||||||
decoder->Code -= newBound;
|
decoder->Code -= newBound;
|
||||||
this->Prob -= (this->Prob) >> numMoveBits;
|
this->Prob -= (this->Prob) >> numMoveBits;
|
||||||
if (decoder->Range < kTopValue)
|
if (decoder->Range < kTopValue)
|
||||||
{
|
{
|
||||||
decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();
|
decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();
|
||||||
decoder->Range <<= 8;
|
decoder->Range <<= 8;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,161 +1,161 @@
|
||||||
// Compress/RangeCoder/RangeCoderBitTree.h
|
// Compress/RangeCoder/RangeCoderBitTree.h
|
||||||
|
|
||||||
#ifndef __COMPRESS_RANGECODER_BIT_TREE_H
|
#ifndef __COMPRESS_RANGECODER_BIT_TREE_H
|
||||||
#define __COMPRESS_RANGECODER_BIT_TREE_H
|
#define __COMPRESS_RANGECODER_BIT_TREE_H
|
||||||
|
|
||||||
#include "RangeCoderBit.h"
|
#include "RangeCoderBit.h"
|
||||||
#include "RangeCoderOpt.h"
|
#include "RangeCoderOpt.h"
|
||||||
|
|
||||||
namespace NCompress {
|
namespace NCompress {
|
||||||
namespace NRangeCoder {
|
namespace NRangeCoder {
|
||||||
|
|
||||||
template <int numMoveBits, int NumBitLevels>
|
template <int numMoveBits, int NumBitLevels>
|
||||||
class CBitTreeEncoder
|
class CBitTreeEncoder
|
||||||
{
|
{
|
||||||
CBitEncoder<numMoveBits> Models[1 << NumBitLevels];
|
CBitEncoder<numMoveBits> Models[1 << NumBitLevels];
|
||||||
public:
|
public:
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
for(UInt32 i = 1; i < (1 << NumBitLevels); i++)
|
for(UInt32 i = 1; i < (1 << NumBitLevels); i++)
|
||||||
Models[i].Init();
|
Models[i].Init();
|
||||||
}
|
}
|
||||||
void Encode(CEncoder *rangeEncoder, UInt32 symbol)
|
void Encode(CEncoder *rangeEncoder, UInt32 symbol)
|
||||||
{
|
{
|
||||||
UInt32 modelIndex = 1;
|
UInt32 modelIndex = 1;
|
||||||
for (int bitIndex = NumBitLevels; bitIndex != 0 ;)
|
for (int bitIndex = NumBitLevels; bitIndex != 0 ;)
|
||||||
{
|
{
|
||||||
bitIndex--;
|
bitIndex--;
|
||||||
UInt32 bit = (symbol >> bitIndex) & 1;
|
UInt32 bit = (symbol >> bitIndex) & 1;
|
||||||
Models[modelIndex].Encode(rangeEncoder, bit);
|
Models[modelIndex].Encode(rangeEncoder, bit);
|
||||||
modelIndex = (modelIndex << 1) | bit;
|
modelIndex = (modelIndex << 1) | bit;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
void ReverseEncode(CEncoder *rangeEncoder, UInt32 symbol)
|
void ReverseEncode(CEncoder *rangeEncoder, UInt32 symbol)
|
||||||
{
|
{
|
||||||
UInt32 modelIndex = 1;
|
UInt32 modelIndex = 1;
|
||||||
for (int i = 0; i < NumBitLevels; i++)
|
for (int i = 0; i < NumBitLevels; i++)
|
||||||
{
|
{
|
||||||
UInt32 bit = symbol & 1;
|
UInt32 bit = symbol & 1;
|
||||||
Models[modelIndex].Encode(rangeEncoder, bit);
|
Models[modelIndex].Encode(rangeEncoder, bit);
|
||||||
modelIndex = (modelIndex << 1) | bit;
|
modelIndex = (modelIndex << 1) | bit;
|
||||||
symbol >>= 1;
|
symbol >>= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UInt32 GetPrice(UInt32 symbol) const
|
UInt32 GetPrice(UInt32 symbol) const
|
||||||
{
|
{
|
||||||
symbol |= (1 << NumBitLevels);
|
symbol |= (1 << NumBitLevels);
|
||||||
UInt32 price = 0;
|
UInt32 price = 0;
|
||||||
while (symbol != 1)
|
while (symbol != 1)
|
||||||
{
|
{
|
||||||
price += Models[symbol >> 1].GetPrice(symbol & 1);
|
price += Models[symbol >> 1].GetPrice(symbol & 1);
|
||||||
symbol >>= 1;
|
symbol >>= 1;
|
||||||
}
|
}
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
UInt32 ReverseGetPrice(UInt32 symbol) const
|
UInt32 ReverseGetPrice(UInt32 symbol) const
|
||||||
{
|
{
|
||||||
UInt32 price = 0;
|
UInt32 price = 0;
|
||||||
UInt32 modelIndex = 1;
|
UInt32 modelIndex = 1;
|
||||||
for (int i = NumBitLevels; i != 0; i--)
|
for (int i = NumBitLevels; i != 0; i--)
|
||||||
{
|
{
|
||||||
UInt32 bit = symbol & 1;
|
UInt32 bit = symbol & 1;
|
||||||
symbol >>= 1;
|
symbol >>= 1;
|
||||||
price += Models[modelIndex].GetPrice(bit);
|
price += Models[modelIndex].GetPrice(bit);
|
||||||
modelIndex = (modelIndex << 1) | bit;
|
modelIndex = (modelIndex << 1) | bit;
|
||||||
}
|
}
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <int numMoveBits, int NumBitLevels>
|
template <int numMoveBits, int NumBitLevels>
|
||||||
class CBitTreeDecoder
|
class CBitTreeDecoder
|
||||||
{
|
{
|
||||||
CBitDecoder<numMoveBits> Models[1 << NumBitLevels];
|
CBitDecoder<numMoveBits> Models[1 << NumBitLevels];
|
||||||
public:
|
public:
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
for(UInt32 i = 1; i < (1 << NumBitLevels); i++)
|
for(UInt32 i = 1; i < (1 << NumBitLevels); i++)
|
||||||
Models[i].Init();
|
Models[i].Init();
|
||||||
}
|
}
|
||||||
UInt32 Decode(CDecoder *rangeDecoder)
|
UInt32 Decode(CDecoder *rangeDecoder)
|
||||||
{
|
{
|
||||||
UInt32 modelIndex = 1;
|
UInt32 modelIndex = 1;
|
||||||
RC_INIT_VAR
|
RC_INIT_VAR
|
||||||
for(int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)
|
for(int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)
|
||||||
{
|
{
|
||||||
// modelIndex = (modelIndex << 1) + Models[modelIndex].Decode(rangeDecoder);
|
// modelIndex = (modelIndex << 1) + Models[modelIndex].Decode(rangeDecoder);
|
||||||
RC_GETBIT(numMoveBits, Models[modelIndex].Prob, modelIndex)
|
RC_GETBIT(numMoveBits, Models[modelIndex].Prob, modelIndex)
|
||||||
}
|
}
|
||||||
RC_FLUSH_VAR
|
RC_FLUSH_VAR
|
||||||
return modelIndex - (1 << NumBitLevels);
|
return modelIndex - (1 << NumBitLevels);
|
||||||
};
|
};
|
||||||
UInt32 ReverseDecode(CDecoder *rangeDecoder)
|
UInt32 ReverseDecode(CDecoder *rangeDecoder)
|
||||||
{
|
{
|
||||||
UInt32 modelIndex = 1;
|
UInt32 modelIndex = 1;
|
||||||
UInt32 symbol = 0;
|
UInt32 symbol = 0;
|
||||||
RC_INIT_VAR
|
RC_INIT_VAR
|
||||||
for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)
|
for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)
|
||||||
{
|
{
|
||||||
// UInt32 bit = Models[modelIndex].Decode(rangeDecoder);
|
// UInt32 bit = Models[modelIndex].Decode(rangeDecoder);
|
||||||
// modelIndex <<= 1;
|
// modelIndex <<= 1;
|
||||||
// modelIndex += bit;
|
// modelIndex += bit;
|
||||||
// symbol |= (bit << bitIndex);
|
// symbol |= (bit << bitIndex);
|
||||||
RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))
|
RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))
|
||||||
}
|
}
|
||||||
RC_FLUSH_VAR
|
RC_FLUSH_VAR
|
||||||
return symbol;
|
return symbol;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <int numMoveBits>
|
template <int numMoveBits>
|
||||||
void ReverseBitTreeEncode(CBitEncoder<numMoveBits> *Models,
|
void ReverseBitTreeEncode(CBitEncoder<numMoveBits> *Models,
|
||||||
CEncoder *rangeEncoder, int NumBitLevels, UInt32 symbol)
|
CEncoder *rangeEncoder, int NumBitLevels, UInt32 symbol)
|
||||||
{
|
{
|
||||||
UInt32 modelIndex = 1;
|
UInt32 modelIndex = 1;
|
||||||
for (int i = 0; i < NumBitLevels; i++)
|
for (int i = 0; i < NumBitLevels; i++)
|
||||||
{
|
{
|
||||||
UInt32 bit = symbol & 1;
|
UInt32 bit = symbol & 1;
|
||||||
Models[modelIndex].Encode(rangeEncoder, bit);
|
Models[modelIndex].Encode(rangeEncoder, bit);
|
||||||
modelIndex = (modelIndex << 1) | bit;
|
modelIndex = (modelIndex << 1) | bit;
|
||||||
symbol >>= 1;
|
symbol >>= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <int numMoveBits>
|
template <int numMoveBits>
|
||||||
UInt32 ReverseBitTreeGetPrice(CBitEncoder<numMoveBits> *Models,
|
UInt32 ReverseBitTreeGetPrice(CBitEncoder<numMoveBits> *Models,
|
||||||
UInt32 NumBitLevels, UInt32 symbol)
|
UInt32 NumBitLevels, UInt32 symbol)
|
||||||
{
|
{
|
||||||
UInt32 price = 0;
|
UInt32 price = 0;
|
||||||
UInt32 modelIndex = 1;
|
UInt32 modelIndex = 1;
|
||||||
for (int i = NumBitLevels; i != 0; i--)
|
for (int i = NumBitLevels; i != 0; i--)
|
||||||
{
|
{
|
||||||
UInt32 bit = symbol & 1;
|
UInt32 bit = symbol & 1;
|
||||||
symbol >>= 1;
|
symbol >>= 1;
|
||||||
price += Models[modelIndex].GetPrice(bit);
|
price += Models[modelIndex].GetPrice(bit);
|
||||||
modelIndex = (modelIndex << 1) | bit;
|
modelIndex = (modelIndex << 1) | bit;
|
||||||
}
|
}
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <int numMoveBits>
|
template <int numMoveBits>
|
||||||
UInt32 ReverseBitTreeDecode(CBitDecoder<numMoveBits> *Models,
|
UInt32 ReverseBitTreeDecode(CBitDecoder<numMoveBits> *Models,
|
||||||
CDecoder *rangeDecoder, int NumBitLevels)
|
CDecoder *rangeDecoder, int NumBitLevels)
|
||||||
{
|
{
|
||||||
UInt32 modelIndex = 1;
|
UInt32 modelIndex = 1;
|
||||||
UInt32 symbol = 0;
|
UInt32 symbol = 0;
|
||||||
RC_INIT_VAR
|
RC_INIT_VAR
|
||||||
for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)
|
for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)
|
||||||
{
|
{
|
||||||
// UInt32 bit = Models[modelIndex].Decode(rangeDecoder);
|
// UInt32 bit = Models[modelIndex].Decode(rangeDecoder);
|
||||||
// modelIndex <<= 1;
|
// modelIndex <<= 1;
|
||||||
// modelIndex += bit;
|
// modelIndex += bit;
|
||||||
// symbol |= (bit << bitIndex);
|
// symbol |= (bit << bitIndex);
|
||||||
RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))
|
RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))
|
||||||
}
|
}
|
||||||
RC_FLUSH_VAR
|
RC_FLUSH_VAR
|
||||||
return symbol;
|
return symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,31 +1,31 @@
|
||||||
// Compress/RangeCoder/RangeCoderOpt.h
|
// Compress/RangeCoder/RangeCoderOpt.h
|
||||||
|
|
||||||
#ifndef __COMPRESS_RANGECODER_OPT_H
|
#ifndef __COMPRESS_RANGECODER_OPT_H
|
||||||
#define __COMPRESS_RANGECODER_OPT_H
|
#define __COMPRESS_RANGECODER_OPT_H
|
||||||
|
|
||||||
#define RC_INIT_VAR \
|
#define RC_INIT_VAR \
|
||||||
UInt32 range = rangeDecoder->Range; \
|
UInt32 range = rangeDecoder->Range; \
|
||||||
UInt32 code = rangeDecoder->Code;
|
UInt32 code = rangeDecoder->Code;
|
||||||
|
|
||||||
#define RC_FLUSH_VAR \
|
#define RC_FLUSH_VAR \
|
||||||
rangeDecoder->Range = range; \
|
rangeDecoder->Range = range; \
|
||||||
rangeDecoder->Code = code;
|
rangeDecoder->Code = code;
|
||||||
|
|
||||||
#define RC_NORMALIZE \
|
#define RC_NORMALIZE \
|
||||||
if (range < NCompress::NRangeCoder::kTopValue) \
|
if (range < NCompress::NRangeCoder::kTopValue) \
|
||||||
{ code = (code << 8) | rangeDecoder->Stream.ReadByte(); range <<= 8; }
|
{ code = (code << 8) | rangeDecoder->Stream.ReadByte(); range <<= 8; }
|
||||||
|
|
||||||
#define RC_GETBIT2(numMoveBits, prob, mi, A0, A1) \
|
#define RC_GETBIT2(numMoveBits, prob, mi, A0, A1) \
|
||||||
{ UInt32 bound = (range >> NCompress::NRangeCoder::kNumBitModelTotalBits) * prob; \
|
{ UInt32 bound = (range >> NCompress::NRangeCoder::kNumBitModelTotalBits) * prob; \
|
||||||
if (code < bound) \
|
if (code < bound) \
|
||||||
{ A0; range = bound; \
|
{ A0; range = bound; \
|
||||||
prob += (NCompress::NRangeCoder::kBitModelTotal - prob) >> numMoveBits; \
|
prob += (NCompress::NRangeCoder::kBitModelTotal - prob) >> numMoveBits; \
|
||||||
mi <<= 1; } \
|
mi <<= 1; } \
|
||||||
else \
|
else \
|
||||||
{ A1; range -= bound; code -= bound; prob -= (prob) >> numMoveBits; \
|
{ A1; range -= bound; code -= bound; prob -= (prob) >> numMoveBits; \
|
||||||
mi = (mi + mi) + 1; }} \
|
mi = (mi + mi) + 1; }} \
|
||||||
RC_NORMALIZE
|
RC_NORMALIZE
|
||||||
|
|
||||||
#define RC_GETBIT(numMoveBits, prob, mi) RC_GETBIT2(numMoveBits, prob, mi, ; , ;)
|
#define RC_GETBIT(numMoveBits, prob, mi) RC_GETBIT2(numMoveBits, prob, mi, ; , ;)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// StdAfx.h
|
// StdAfx.h
|
||||||
|
|
||||||
#ifndef __STDAFX_H
|
#ifndef __STDAFX_H
|
||||||
#define __STDAFX_H
|
#define __STDAFX_H
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,163 +1,163 @@
|
||||||
// ICoder.h
|
// ICoder.h
|
||||||
|
|
||||||
#ifndef __ICODER_H
|
#ifndef __ICODER_H
|
||||||
#define __ICODER_H
|
#define __ICODER_H
|
||||||
|
|
||||||
#include "IStream.h"
|
#include "IStream.h"
|
||||||
|
|
||||||
// "23170F69-40C1-278A-0000-000400xx0000"
|
// "23170F69-40C1-278A-0000-000400xx0000"
|
||||||
#define CODER_INTERFACE(i, x) \
|
#define CODER_INTERFACE(i, x) \
|
||||||
DEFINE_GUID(IID_ ## i, \
|
DEFINE_GUID(IID_ ## i, \
|
||||||
0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x04, 0x00, x, 0x00, 0x00); \
|
0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x04, 0x00, x, 0x00, 0x00); \
|
||||||
struct i: public IUnknown
|
struct i: public IUnknown
|
||||||
|
|
||||||
CODER_INTERFACE(ICompressProgressInfo, 0x04)
|
CODER_INTERFACE(ICompressProgressInfo, 0x04)
|
||||||
{
|
{
|
||||||
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) PURE;
|
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
CODER_INTERFACE(ICompressCoder, 0x05)
|
CODER_INTERFACE(ICompressCoder, 0x05)
|
||||||
{
|
{
|
||||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||||
ISequentialOutStream *outStream,
|
ISequentialOutStream *outStream,
|
||||||
const UInt64 *inSize,
|
const UInt64 *inSize,
|
||||||
const UInt64 *outSize,
|
const UInt64 *outSize,
|
||||||
ICompressProgressInfo *progress) PURE;
|
ICompressProgressInfo *progress) PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
CODER_INTERFACE(ICompressCoder2, 0x18)
|
CODER_INTERFACE(ICompressCoder2, 0x18)
|
||||||
{
|
{
|
||||||
STDMETHOD(Code)(ISequentialInStream **inStreams,
|
STDMETHOD(Code)(ISequentialInStream **inStreams,
|
||||||
const UInt64 **inSizes,
|
const UInt64 **inSizes,
|
||||||
UInt32 numInStreams,
|
UInt32 numInStreams,
|
||||||
ISequentialOutStream **outStreams,
|
ISequentialOutStream **outStreams,
|
||||||
const UInt64 **outSizes,
|
const UInt64 **outSizes,
|
||||||
UInt32 numOutStreams,
|
UInt32 numOutStreams,
|
||||||
ICompressProgressInfo *progress) PURE;
|
ICompressProgressInfo *progress) PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace NCoderPropID
|
namespace NCoderPropID
|
||||||
{
|
{
|
||||||
enum EEnum
|
enum EEnum
|
||||||
{
|
{
|
||||||
kDictionarySize = 0x400,
|
kDictionarySize = 0x400,
|
||||||
kUsedMemorySize,
|
kUsedMemorySize,
|
||||||
kOrder,
|
kOrder,
|
||||||
kPosStateBits = 0x440,
|
kPosStateBits = 0x440,
|
||||||
kLitContextBits,
|
kLitContextBits,
|
||||||
kLitPosBits,
|
kLitPosBits,
|
||||||
kNumFastBytes = 0x450,
|
kNumFastBytes = 0x450,
|
||||||
kMatchFinder,
|
kMatchFinder,
|
||||||
kMatchFinderCycles,
|
kMatchFinderCycles,
|
||||||
kNumPasses = 0x460,
|
kNumPasses = 0x460,
|
||||||
kAlgorithm = 0x470,
|
kAlgorithm = 0x470,
|
||||||
kMultiThread = 0x480,
|
kMultiThread = 0x480,
|
||||||
kNumThreads,
|
kNumThreads,
|
||||||
kEndMarker = 0x490
|
kEndMarker = 0x490
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
CODER_INTERFACE(ICompressSetCoderProperties, 0x20)
|
CODER_INTERFACE(ICompressSetCoderProperties, 0x20)
|
||||||
{
|
{
|
||||||
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
||||||
const PROPVARIANT *properties, UInt32 numProperties) PURE;
|
const PROPVARIANT *properties, UInt32 numProperties) PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
CODER_INTERFACE(ICompressSetCoderProperties, 0x21)
|
CODER_INTERFACE(ICompressSetCoderProperties, 0x21)
|
||||||
{
|
{
|
||||||
STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE;
|
STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE;
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CODER_INTERFACE(ICompressSetDecoderProperties2, 0x22)
|
CODER_INTERFACE(ICompressSetDecoderProperties2, 0x22)
|
||||||
{
|
{
|
||||||
STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size) PURE;
|
STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size) PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
CODER_INTERFACE(ICompressWriteCoderProperties, 0x23)
|
CODER_INTERFACE(ICompressWriteCoderProperties, 0x23)
|
||||||
{
|
{
|
||||||
STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStreams) PURE;
|
STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStreams) PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
CODER_INTERFACE(ICompressGetInStreamProcessedSize, 0x24)
|
CODER_INTERFACE(ICompressGetInStreamProcessedSize, 0x24)
|
||||||
{
|
{
|
||||||
STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE;
|
STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
CODER_INTERFACE(ICompressSetCoderMt, 0x25)
|
CODER_INTERFACE(ICompressSetCoderMt, 0x25)
|
||||||
{
|
{
|
||||||
STDMETHOD(SetNumberOfThreads)(UInt32 numThreads) PURE;
|
STDMETHOD(SetNumberOfThreads)(UInt32 numThreads) PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
CODER_INTERFACE(ICompressGetSubStreamSize, 0x30)
|
CODER_INTERFACE(ICompressGetSubStreamSize, 0x30)
|
||||||
{
|
{
|
||||||
STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE;
|
STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
CODER_INTERFACE(ICompressSetInStream, 0x31)
|
CODER_INTERFACE(ICompressSetInStream, 0x31)
|
||||||
{
|
{
|
||||||
STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE;
|
STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE;
|
||||||
STDMETHOD(ReleaseInStream)() PURE;
|
STDMETHOD(ReleaseInStream)() PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
CODER_INTERFACE(ICompressSetOutStream, 0x32)
|
CODER_INTERFACE(ICompressSetOutStream, 0x32)
|
||||||
{
|
{
|
||||||
STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE;
|
STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE;
|
||||||
STDMETHOD(ReleaseOutStream)() PURE;
|
STDMETHOD(ReleaseOutStream)() PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
CODER_INTERFACE(ICompressSetInStreamSize, 0x33)
|
CODER_INTERFACE(ICompressSetInStreamSize, 0x33)
|
||||||
{
|
{
|
||||||
STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE;
|
STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
CODER_INTERFACE(ICompressSetOutStreamSize, 0x34)
|
CODER_INTERFACE(ICompressSetOutStreamSize, 0x34)
|
||||||
{
|
{
|
||||||
STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE;
|
STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
CODER_INTERFACE(ICompressFilter, 0x40)
|
CODER_INTERFACE(ICompressFilter, 0x40)
|
||||||
{
|
{
|
||||||
STDMETHOD(Init)() PURE;
|
STDMETHOD(Init)() PURE;
|
||||||
STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;
|
STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;
|
||||||
// Filter return outSize (UInt32)
|
// Filter return outSize (UInt32)
|
||||||
// if (outSize <= size): Filter have converted outSize bytes
|
// if (outSize <= size): Filter have converted outSize bytes
|
||||||
// if (outSize > size): Filter have not converted anything.
|
// if (outSize > size): Filter have not converted anything.
|
||||||
// and it needs at least outSize bytes to convert one block
|
// and it needs at least outSize bytes to convert one block
|
||||||
// (it's for crypto block algorithms).
|
// (it's for crypto block algorithms).
|
||||||
};
|
};
|
||||||
|
|
||||||
CODER_INTERFACE(ICryptoProperties, 0x80)
|
CODER_INTERFACE(ICryptoProperties, 0x80)
|
||||||
{
|
{
|
||||||
STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;
|
STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;
|
||||||
STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE;
|
STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
CODER_INTERFACE(ICryptoSetPassword, 0x90)
|
CODER_INTERFACE(ICryptoSetPassword, 0x90)
|
||||||
{
|
{
|
||||||
STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE;
|
STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
CODER_INTERFACE(ICryptoSetCRC, 0xA0)
|
CODER_INTERFACE(ICryptoSetCRC, 0xA0)
|
||||||
{
|
{
|
||||||
STDMETHOD(CryptoSetCRC)(UInt32 crc) PURE;
|
STDMETHOD(CryptoSetCRC)(UInt32 crc) PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
//////////////////////
|
//////////////////////
|
||||||
// It's for DLL file
|
// It's for DLL file
|
||||||
namespace NMethodPropID
|
namespace NMethodPropID
|
||||||
{
|
{
|
||||||
enum EEnum
|
enum EEnum
|
||||||
{
|
{
|
||||||
kID,
|
kID,
|
||||||
kName,
|
kName,
|
||||||
kDecoder,
|
kDecoder,
|
||||||
kEncoder,
|
kEncoder,
|
||||||
kInStreams,
|
kInStreams,
|
||||||
kOutStreams,
|
kOutStreams,
|
||||||
kDescription
|
kDescription
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,62 +1,62 @@
|
||||||
// IStream.h
|
// IStream.h
|
||||||
|
|
||||||
#ifndef __ISTREAM_H
|
#ifndef __ISTREAM_H
|
||||||
#define __ISTREAM_H
|
#define __ISTREAM_H
|
||||||
|
|
||||||
#include "../Common/MyUnknown.h"
|
#include "../Common/MyUnknown.h"
|
||||||
#include "../Common/Types.h"
|
#include "../Common/Types.h"
|
||||||
|
|
||||||
// "23170F69-40C1-278A-0000-000300xx0000"
|
// "23170F69-40C1-278A-0000-000300xx0000"
|
||||||
|
|
||||||
#define STREAM_INTERFACE_SUB(i, b, x) \
|
#define STREAM_INTERFACE_SUB(i, b, x) \
|
||||||
DEFINE_GUID(IID_ ## i, \
|
DEFINE_GUID(IID_ ## i, \
|
||||||
0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, x, 0x00, 0x00); \
|
0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, x, 0x00, 0x00); \
|
||||||
struct i: public b
|
struct i: public b
|
||||||
|
|
||||||
#define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x)
|
#define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x)
|
||||||
|
|
||||||
STREAM_INTERFACE(ISequentialInStream, 0x01)
|
STREAM_INTERFACE(ISequentialInStream, 0x01)
|
||||||
{
|
{
|
||||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE;
|
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE;
|
||||||
/*
|
/*
|
||||||
Out: if size != 0, return_value = S_OK and (*processedSize == 0),
|
Out: if size != 0, return_value = S_OK and (*processedSize == 0),
|
||||||
then there are no more bytes in stream.
|
then there are no more bytes in stream.
|
||||||
if (size > 0) && there are bytes in stream,
|
if (size > 0) && there are bytes in stream,
|
||||||
this function must read at least 1 byte.
|
this function must read at least 1 byte.
|
||||||
This function is allowed to read less than number of remaining bytes in stream.
|
This function is allowed to read less than number of remaining bytes in stream.
|
||||||
You must call Read function in loop, if you need exact amount of data
|
You must call Read function in loop, if you need exact amount of data
|
||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
STREAM_INTERFACE(ISequentialOutStream, 0x02)
|
STREAM_INTERFACE(ISequentialOutStream, 0x02)
|
||||||
{
|
{
|
||||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE;
|
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE;
|
||||||
/*
|
/*
|
||||||
if (size > 0) this function must write at least 1 byte.
|
if (size > 0) this function must write at least 1 byte.
|
||||||
This function is allowed to write less than "size".
|
This function is allowed to write less than "size".
|
||||||
You must call Write function in loop, if you need to write exact amount of data
|
You must call Write function in loop, if you need to write exact amount of data
|
||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
STREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03)
|
STREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03)
|
||||||
{
|
{
|
||||||
STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;
|
STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
STREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04)
|
STREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04)
|
||||||
{
|
{
|
||||||
STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;
|
STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;
|
||||||
STDMETHOD(SetSize)(Int64 newSize) PURE;
|
STDMETHOD(SetSize)(Int64 newSize) PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
STREAM_INTERFACE(IStreamGetSize, 0x06)
|
STREAM_INTERFACE(IStreamGetSize, 0x06)
|
||||||
{
|
{
|
||||||
STDMETHOD(GetSize)(UInt64 *size) PURE;
|
STDMETHOD(GetSize)(UInt64 *size) PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
STREAM_INTERFACE(IOutStreamFlush, 0x07)
|
STREAM_INTERFACE(IOutStreamFlush, 0x07)
|
||||||
{
|
{
|
||||||
STDMETHOD(Flush)() PURE;
|
STDMETHOD(Flush)() PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,29 +1,29 @@
|
||||||
// Common/Alloc.h
|
// Common/Alloc.h
|
||||||
|
|
||||||
#ifndef __COMMON_ALLOC_H
|
#ifndef __COMMON_ALLOC_H
|
||||||
#define __COMMON_ALLOC_H
|
#define __COMMON_ALLOC_H
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
void *MyAlloc(size_t size) throw();
|
void *MyAlloc(size_t size) throw();
|
||||||
void MyFree(void *address) throw();
|
void MyFree(void *address) throw();
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
bool SetLargePageSize();
|
bool SetLargePageSize();
|
||||||
|
|
||||||
void *MidAlloc(size_t size) throw();
|
void *MidAlloc(size_t size) throw();
|
||||||
void MidFree(void *address) throw();
|
void MidFree(void *address) throw();
|
||||||
void *BigAlloc(size_t size) throw();
|
void *BigAlloc(size_t size) throw();
|
||||||
void BigFree(void *address) throw();
|
void BigFree(void *address) throw();
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define MidAlloc(size) MyAlloc(size)
|
#define MidAlloc(size) MyAlloc(size)
|
||||||
#define MidFree(address) MyFree(address)
|
#define MidFree(address) MyFree(address)
|
||||||
#define BigAlloc(size) MyAlloc(size)
|
#define BigAlloc(size) MyAlloc(size)
|
||||||
#define BigFree(address) MyFree(address)
|
#define BigFree(address) MyFree(address)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,36 +1,36 @@
|
||||||
// Common/CRC.h
|
// Common/CRC.h
|
||||||
|
|
||||||
#ifndef __COMMON_CRC_H
|
#ifndef __COMMON_CRC_H
|
||||||
#define __COMMON_CRC_H
|
#define __COMMON_CRC_H
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include "Types.h"
|
#include "Types.h"
|
||||||
|
|
||||||
class CCRC
|
class CCRC
|
||||||
{
|
{
|
||||||
UInt32 _value;
|
UInt32 _value;
|
||||||
public:
|
public:
|
||||||
static UInt32 Table[256];
|
static UInt32 Table[256];
|
||||||
static void InitTable();
|
static void InitTable();
|
||||||
|
|
||||||
CCRC(): _value(0xFFFFFFFF){};
|
CCRC(): _value(0xFFFFFFFF){};
|
||||||
void Init() { _value = 0xFFFFFFFF; }
|
void Init() { _value = 0xFFFFFFFF; }
|
||||||
void UpdateByte(Byte v);
|
void UpdateByte(Byte v);
|
||||||
void UpdateUInt16(UInt16 v);
|
void UpdateUInt16(UInt16 v);
|
||||||
void UpdateUInt32(UInt32 v);
|
void UpdateUInt32(UInt32 v);
|
||||||
void UpdateUInt64(UInt64 v);
|
void UpdateUInt64(UInt64 v);
|
||||||
void Update(const void *data, size_t size);
|
void Update(const void *data, size_t size);
|
||||||
UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; }
|
UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; }
|
||||||
static UInt32 CalculateDigest(const void *data, size_t size)
|
static UInt32 CalculateDigest(const void *data, size_t size)
|
||||||
{
|
{
|
||||||
CCRC crc;
|
CCRC crc;
|
||||||
crc.Update(data, size);
|
crc.Update(data, size);
|
||||||
return crc.GetDigest();
|
return crc.GetDigest();
|
||||||
}
|
}
|
||||||
static bool VerifyDigest(UInt32 digest, const void *data, size_t size)
|
static bool VerifyDigest(UInt32 digest, const void *data, size_t size)
|
||||||
{
|
{
|
||||||
return (CalculateDigest(data, size) == digest);
|
return (CalculateDigest(data, size) == digest);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
// Common/Defs.h
|
// Common/Defs.h
|
||||||
|
|
||||||
#ifndef __COMMON_DEFS_H
|
#ifndef __COMMON_DEFS_H
|
||||||
#define __COMMON_DEFS_H
|
#define __COMMON_DEFS_H
|
||||||
|
|
||||||
template <class T> inline T MyMin(T a, T b)
|
template <class T> inline T MyMin(T a, T b)
|
||||||
{ return a < b ? a : b; }
|
{ return a < b ? a : b; }
|
||||||
template <class T> inline T MyMax(T a, T b)
|
template <class T> inline T MyMax(T a, T b)
|
||||||
{ return a > b ? a : b; }
|
{ return a > b ? a : b; }
|
||||||
|
|
||||||
template <class T> inline int MyCompare(T a, T b)
|
template <class T> inline int MyCompare(T a, T b)
|
||||||
{ return a < b ? -1 : (a == b ? 0 : 1); }
|
{ return a < b ? -1 : (a == b ? 0 : 1); }
|
||||||
|
|
||||||
inline int BoolToInt(bool value)
|
inline int BoolToInt(bool value)
|
||||||
{ return (value ? 1: 0); }
|
{ return (value ? 1: 0); }
|
||||||
|
|
||||||
inline bool IntToBool(int value)
|
inline bool IntToBool(int value)
|
||||||
{ return (value != 0); }
|
{ return (value != 0); }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,203 +1,203 @@
|
||||||
// MyCom.h
|
// MyCom.h
|
||||||
|
|
||||||
#ifndef __MYCOM_H
|
#ifndef __MYCOM_H
|
||||||
#define __MYCOM_H
|
#define __MYCOM_H
|
||||||
|
|
||||||
#include "MyWindows.h"
|
#include "MyWindows.h"
|
||||||
|
|
||||||
#define RINOK(x) { HRESULT __result_ = (x); if(__result_ != S_OK) return __result_; }
|
#define RINOK(x) { HRESULT __result_ = (x); if(__result_ != S_OK) return __result_; }
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class CMyComPtr
|
class CMyComPtr
|
||||||
{
|
{
|
||||||
T* _p;
|
T* _p;
|
||||||
public:
|
public:
|
||||||
// typedef T _PtrClass;
|
// typedef T _PtrClass;
|
||||||
CMyComPtr() { _p = NULL;}
|
CMyComPtr() { _p = NULL;}
|
||||||
CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); }
|
CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); }
|
||||||
CMyComPtr(const CMyComPtr<T>& lp)
|
CMyComPtr(const CMyComPtr<T>& lp)
|
||||||
{
|
{
|
||||||
if ((_p = lp._p) != NULL)
|
if ((_p = lp._p) != NULL)
|
||||||
_p->AddRef();
|
_p->AddRef();
|
||||||
}
|
}
|
||||||
~CMyComPtr() { if (_p) _p->Release(); }
|
~CMyComPtr() { if (_p) _p->Release(); }
|
||||||
void Release() { if (_p) { _p->Release(); _p = NULL; } }
|
void Release() { if (_p) { _p->Release(); _p = NULL; } }
|
||||||
operator T*() const { return (T*)_p; }
|
operator T*() const { return (T*)_p; }
|
||||||
// T& operator*() const { return *_p; }
|
// T& operator*() const { return *_p; }
|
||||||
T** operator&() { return &_p; }
|
T** operator&() { return &_p; }
|
||||||
T* operator->() const { return _p; }
|
T* operator->() const { return _p; }
|
||||||
T* operator=(T* p)
|
T* operator=(T* p)
|
||||||
{
|
{
|
||||||
if (p != 0)
|
if (p != 0)
|
||||||
p->AddRef();
|
p->AddRef();
|
||||||
if (_p)
|
if (_p)
|
||||||
_p->Release();
|
_p->Release();
|
||||||
_p = p;
|
_p = p;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); }
|
T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); }
|
||||||
bool operator!() const { return (_p == NULL); }
|
bool operator!() const { return (_p == NULL); }
|
||||||
// bool operator==(T* pT) const { return _p == pT; }
|
// bool operator==(T* pT) const { return _p == pT; }
|
||||||
// Compare two objects for equivalence
|
// Compare two objects for equivalence
|
||||||
void Attach(T* p2)
|
void Attach(T* p2)
|
||||||
{
|
{
|
||||||
Release();
|
Release();
|
||||||
_p = p2;
|
_p = p2;
|
||||||
}
|
}
|
||||||
T* Detach()
|
T* Detach()
|
||||||
{
|
{
|
||||||
T* pt = _p;
|
T* pt = _p;
|
||||||
_p = NULL;
|
_p = NULL;
|
||||||
return pt;
|
return pt;
|
||||||
}
|
}
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
|
HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
|
||||||
{
|
{
|
||||||
return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);
|
return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
|
HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
|
||||||
{
|
{
|
||||||
CLSID clsid;
|
CLSID clsid;
|
||||||
HRESULT hr = CLSIDFromProgID(szProgID, &clsid);
|
HRESULT hr = CLSIDFromProgID(szProgID, &clsid);
|
||||||
ATLASSERT(_p == NULL);
|
ATLASSERT(_p == NULL);
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p);
|
hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p);
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
template <class Q>
|
template <class Q>
|
||||||
HRESULT QueryInterface(REFGUID iid, Q** pp) const
|
HRESULT QueryInterface(REFGUID iid, Q** pp) const
|
||||||
{
|
{
|
||||||
return _p->QueryInterface(iid, (void**)pp);
|
return _p->QueryInterface(iid, (void**)pp);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class CMyComBSTR
|
class CMyComBSTR
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BSTR m_str;
|
BSTR m_str;
|
||||||
CMyComBSTR() { m_str = NULL; }
|
CMyComBSTR() { m_str = NULL; }
|
||||||
CMyComBSTR(LPCOLESTR pSrc) { m_str = ::SysAllocString(pSrc); }
|
CMyComBSTR(LPCOLESTR pSrc) { m_str = ::SysAllocString(pSrc); }
|
||||||
// CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }
|
// CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }
|
||||||
// CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize); }
|
// CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize); }
|
||||||
CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }
|
CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }
|
||||||
/*
|
/*
|
||||||
CMyComBSTR(REFGUID src)
|
CMyComBSTR(REFGUID src)
|
||||||
{
|
{
|
||||||
LPOLESTR szGuid;
|
LPOLESTR szGuid;
|
||||||
StringFromCLSID(src, &szGuid);
|
StringFromCLSID(src, &szGuid);
|
||||||
m_str = ::SysAllocString(szGuid);
|
m_str = ::SysAllocString(szGuid);
|
||||||
CoTaskMemFree(szGuid);
|
CoTaskMemFree(szGuid);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
~CMyComBSTR() { ::SysFreeString(m_str); }
|
~CMyComBSTR() { ::SysFreeString(m_str); }
|
||||||
CMyComBSTR& operator=(const CMyComBSTR& src)
|
CMyComBSTR& operator=(const CMyComBSTR& src)
|
||||||
{
|
{
|
||||||
if (m_str != src.m_str)
|
if (m_str != src.m_str)
|
||||||
{
|
{
|
||||||
if (m_str)
|
if (m_str)
|
||||||
::SysFreeString(m_str);
|
::SysFreeString(m_str);
|
||||||
m_str = src.MyCopy();
|
m_str = src.MyCopy();
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
CMyComBSTR& operator=(LPCOLESTR pSrc)
|
CMyComBSTR& operator=(LPCOLESTR pSrc)
|
||||||
{
|
{
|
||||||
::SysFreeString(m_str);
|
::SysFreeString(m_str);
|
||||||
m_str = ::SysAllocString(pSrc);
|
m_str = ::SysAllocString(pSrc);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
unsigned int Length() const { return ::SysStringLen(m_str); }
|
unsigned int Length() const { return ::SysStringLen(m_str); }
|
||||||
operator BSTR() const { return m_str; }
|
operator BSTR() const { return m_str; }
|
||||||
BSTR* operator&() { return &m_str; }
|
BSTR* operator&() { return &m_str; }
|
||||||
BSTR MyCopy() const
|
BSTR MyCopy() const
|
||||||
{
|
{
|
||||||
int byteLen = ::SysStringByteLen(m_str);
|
int byteLen = ::SysStringByteLen(m_str);
|
||||||
BSTR res = ::SysAllocStringByteLen(NULL, byteLen);
|
BSTR res = ::SysAllocStringByteLen(NULL, byteLen);
|
||||||
memmove(res, m_str, byteLen);
|
memmove(res, m_str, byteLen);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
void Attach(BSTR src) { m_str = src; }
|
void Attach(BSTR src) { m_str = src; }
|
||||||
BSTR Detach()
|
BSTR Detach()
|
||||||
{
|
{
|
||||||
BSTR s = m_str;
|
BSTR s = m_str;
|
||||||
m_str = NULL;
|
m_str = NULL;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
void Empty()
|
void Empty()
|
||||||
{
|
{
|
||||||
::SysFreeString(m_str);
|
::SysFreeString(m_str);
|
||||||
m_str = NULL;
|
m_str = NULL;
|
||||||
}
|
}
|
||||||
bool operator!() const { return (m_str == NULL); }
|
bool operator!() const { return (m_str == NULL); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class CMyUnknownImp
|
class CMyUnknownImp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ULONG __m_RefCount;
|
ULONG __m_RefCount;
|
||||||
CMyUnknownImp(): __m_RefCount(0) {}
|
CMyUnknownImp(): __m_RefCount(0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \
|
#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \
|
||||||
(REFGUID iid, void **outObject) {
|
(REFGUID iid, void **outObject) {
|
||||||
|
|
||||||
#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \
|
#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \
|
||||||
{ *outObject = (void *)(i *)this; AddRef(); return S_OK; }
|
{ *outObject = (void *)(i *)this; AddRef(); return S_OK; }
|
||||||
|
|
||||||
#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }
|
#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }
|
||||||
|
|
||||||
#define MY_ADDREF_RELEASE \
|
#define MY_ADDREF_RELEASE \
|
||||||
STDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \
|
STDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \
|
||||||
STDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0) \
|
STDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0) \
|
||||||
return __m_RefCount; delete this; return 0; }
|
return __m_RefCount; delete this; return 0; }
|
||||||
|
|
||||||
#define MY_UNKNOWN_IMP_SPEC(i) \
|
#define MY_UNKNOWN_IMP_SPEC(i) \
|
||||||
MY_QUERYINTERFACE_BEGIN \
|
MY_QUERYINTERFACE_BEGIN \
|
||||||
i \
|
i \
|
||||||
MY_QUERYINTERFACE_END \
|
MY_QUERYINTERFACE_END \
|
||||||
MY_ADDREF_RELEASE
|
MY_ADDREF_RELEASE
|
||||||
|
|
||||||
|
|
||||||
#define MY_UNKNOWN_IMP STDMETHOD(QueryInterface)(REFGUID, void **) { \
|
#define MY_UNKNOWN_IMP STDMETHOD(QueryInterface)(REFGUID, void **) { \
|
||||||
MY_QUERYINTERFACE_END \
|
MY_QUERYINTERFACE_END \
|
||||||
MY_ADDREF_RELEASE
|
MY_ADDREF_RELEASE
|
||||||
|
|
||||||
#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \
|
#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \
|
||||||
MY_QUERYINTERFACE_ENTRY(i) \
|
MY_QUERYINTERFACE_ENTRY(i) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \
|
#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \
|
||||||
MY_QUERYINTERFACE_ENTRY(i1) \
|
MY_QUERYINTERFACE_ENTRY(i1) \
|
||||||
MY_QUERYINTERFACE_ENTRY(i2) \
|
MY_QUERYINTERFACE_ENTRY(i2) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \
|
#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \
|
||||||
MY_QUERYINTERFACE_ENTRY(i1) \
|
MY_QUERYINTERFACE_ENTRY(i1) \
|
||||||
MY_QUERYINTERFACE_ENTRY(i2) \
|
MY_QUERYINTERFACE_ENTRY(i2) \
|
||||||
MY_QUERYINTERFACE_ENTRY(i3) \
|
MY_QUERYINTERFACE_ENTRY(i3) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \
|
#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \
|
||||||
MY_QUERYINTERFACE_ENTRY(i1) \
|
MY_QUERYINTERFACE_ENTRY(i1) \
|
||||||
MY_QUERYINTERFACE_ENTRY(i2) \
|
MY_QUERYINTERFACE_ENTRY(i2) \
|
||||||
MY_QUERYINTERFACE_ENTRY(i3) \
|
MY_QUERYINTERFACE_ENTRY(i3) \
|
||||||
MY_QUERYINTERFACE_ENTRY(i4) \
|
MY_QUERYINTERFACE_ENTRY(i4) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \
|
#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \
|
||||||
MY_QUERYINTERFACE_ENTRY(i1) \
|
MY_QUERYINTERFACE_ENTRY(i1) \
|
||||||
MY_QUERYINTERFACE_ENTRY(i2) \
|
MY_QUERYINTERFACE_ENTRY(i2) \
|
||||||
MY_QUERYINTERFACE_ENTRY(i3) \
|
MY_QUERYINTERFACE_ENTRY(i3) \
|
||||||
MY_QUERYINTERFACE_ENTRY(i4) \
|
MY_QUERYINTERFACE_ENTRY(i4) \
|
||||||
MY_QUERYINTERFACE_ENTRY(i5) \
|
MY_QUERYINTERFACE_ENTRY(i5) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,54 +1,54 @@
|
||||||
// Common/MyGuidDef.h
|
// Common/MyGuidDef.h
|
||||||
|
|
||||||
#ifndef GUID_DEFINED
|
#ifndef GUID_DEFINED
|
||||||
#define GUID_DEFINED
|
#define GUID_DEFINED
|
||||||
|
|
||||||
#include "Types.h"
|
#include "Types.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
UInt32 Data1;
|
UInt32 Data1;
|
||||||
UInt16 Data2;
|
UInt16 Data2;
|
||||||
UInt16 Data3;
|
UInt16 Data3;
|
||||||
unsigned char Data4[8];
|
unsigned char Data4[8];
|
||||||
} GUID;
|
} GUID;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#define REFGUID const GUID &
|
#define REFGUID const GUID &
|
||||||
#else
|
#else
|
||||||
#define REFGUID const GUID *
|
#define REFGUID const GUID *
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define REFCLSID REFGUID
|
#define REFCLSID REFGUID
|
||||||
#define REFIID REFGUID
|
#define REFIID REFGUID
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
inline bool operator==(REFGUID g1, REFGUID g2)
|
inline bool operator==(REFGUID g1, REFGUID g2)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < (int)sizeof(g1); i++)
|
for (int i = 0; i < (int)sizeof(g1); i++)
|
||||||
if (((const unsigned char *)&g1)[i] != ((const unsigned char *)&g2)[i])
|
if (((const unsigned char *)&g1)[i] != ((const unsigned char *)&g2)[i])
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
inline bool operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }
|
inline bool operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#define MY_EXTERN_C extern "C"
|
#define MY_EXTERN_C extern "C"
|
||||||
#else
|
#else
|
||||||
#define MY_EXTERN_C extern
|
#define MY_EXTERN_C extern
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // GUID_DEFINED
|
#endif // GUID_DEFINED
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEFINE_GUID
|
#ifdef DEFINE_GUID
|
||||||
#undef DEFINE_GUID
|
#undef DEFINE_GUID
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INITGUID
|
#ifdef INITGUID
|
||||||
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
|
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
|
||||||
MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
|
MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
|
||||||
#else
|
#else
|
||||||
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
|
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
|
||||||
MY_EXTERN_C const GUID name
|
MY_EXTERN_C const GUID name
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
// Common/MyInitGuid.h
|
// Common/MyInitGuid.h
|
||||||
|
|
||||||
#ifndef __COMMON_MYINITGUID_H
|
#ifndef __COMMON_MYINITGUID_H
|
||||||
#define __COMMON_MYINITGUID_H
|
#define __COMMON_MYINITGUID_H
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <initguid.h>
|
#include <initguid.h>
|
||||||
#else
|
#else
|
||||||
#define INITGUID
|
#define INITGUID
|
||||||
#include "MyGuidDef.h"
|
#include "MyGuidDef.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
// MyUnknown.h
|
// MyUnknown.h
|
||||||
|
|
||||||
#ifndef __MYUNKNOWN_H
|
#ifndef __MYUNKNOWN_H
|
||||||
#define __MYUNKNOWN_H
|
#define __MYUNKNOWN_H
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
#ifdef _WIN32_WCE
|
#ifdef _WIN32_WCE
|
||||||
#if (_WIN32_WCE > 300)
|
#if (_WIN32_WCE > 300)
|
||||||
#include <basetyps.h>
|
#include <basetyps.h>
|
||||||
#else
|
#else
|
||||||
#define MIDL_INTERFACE(x) struct
|
#define MIDL_INTERFACE(x) struct
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#include <basetyps.h>
|
#include <basetyps.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <unknwn.h>
|
#include <unknwn.h>
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#include "MyWindows.h"
|
#include "MyWindows.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,201 +1,201 @@
|
||||||
// MyWindows.h
|
// MyWindows.h
|
||||||
|
|
||||||
#ifndef __MYWINDOWS_H
|
#ifndef __MYWINDOWS_H
|
||||||
#define __MYWINDOWS_H
|
#define __MYWINDOWS_H
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
#define CHAR_PATH_SEPARATOR '\\'
|
#define CHAR_PATH_SEPARATOR '\\'
|
||||||
#define WCHAR_PATH_SEPARATOR L'\\'
|
#define WCHAR_PATH_SEPARATOR L'\\'
|
||||||
#define STRING_PATH_SEPARATOR "\\"
|
#define STRING_PATH_SEPARATOR "\\"
|
||||||
#define WSTRING_PATH_SEPARATOR L"\\"
|
#define WSTRING_PATH_SEPARATOR L"\\"
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define CHAR_PATH_SEPARATOR '/'
|
#define CHAR_PATH_SEPARATOR '/'
|
||||||
#define WCHAR_PATH_SEPARATOR L'/'
|
#define WCHAR_PATH_SEPARATOR L'/'
|
||||||
#define STRING_PATH_SEPARATOR "/"
|
#define STRING_PATH_SEPARATOR "/"
|
||||||
#define WSTRING_PATH_SEPARATOR L"/"
|
#define WSTRING_PATH_SEPARATOR L"/"
|
||||||
|
|
||||||
#include <stddef.h> // for wchar_t
|
#include <stddef.h> // for wchar_t
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "MyGuidDef.h"
|
#include "MyGuidDef.h"
|
||||||
|
|
||||||
typedef char CHAR;
|
typedef char CHAR;
|
||||||
typedef unsigned char UCHAR;
|
typedef unsigned char UCHAR;
|
||||||
|
|
||||||
#undef BYTE
|
#undef BYTE
|
||||||
typedef unsigned char BYTE;
|
typedef unsigned char BYTE;
|
||||||
|
|
||||||
typedef short SHORT;
|
typedef short SHORT;
|
||||||
typedef unsigned short USHORT;
|
typedef unsigned short USHORT;
|
||||||
|
|
||||||
#undef WORD
|
#undef WORD
|
||||||
typedef unsigned short WORD;
|
typedef unsigned short WORD;
|
||||||
typedef short VARIANT_BOOL;
|
typedef short VARIANT_BOOL;
|
||||||
|
|
||||||
typedef int INT;
|
typedef int INT;
|
||||||
typedef Int32 INT32;
|
typedef Int32 INT32;
|
||||||
typedef unsigned int UINT;
|
typedef unsigned int UINT;
|
||||||
typedef UInt32 UINT32;
|
typedef UInt32 UINT32;
|
||||||
typedef INT32 LONG; // LONG, ULONG and DWORD must be 32-bit
|
typedef INT32 LONG; // LONG, ULONG and DWORD must be 32-bit
|
||||||
typedef UINT32 ULONG;
|
typedef UINT32 ULONG;
|
||||||
|
|
||||||
#undef DWORD
|
#undef DWORD
|
||||||
typedef UINT32 DWORD;
|
typedef UINT32 DWORD;
|
||||||
|
|
||||||
typedef Int64 LONGLONG;
|
typedef Int64 LONGLONG;
|
||||||
typedef UInt64 ULONGLONG;
|
typedef UInt64 ULONGLONG;
|
||||||
|
|
||||||
typedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;
|
typedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;
|
||||||
typedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;
|
typedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;
|
||||||
|
|
||||||
typedef const CHAR *LPCSTR;
|
typedef const CHAR *LPCSTR;
|
||||||
typedef CHAR TCHAR;
|
typedef CHAR TCHAR;
|
||||||
typedef const TCHAR *LPCTSTR;
|
typedef const TCHAR *LPCTSTR;
|
||||||
typedef wchar_t WCHAR;
|
typedef wchar_t WCHAR;
|
||||||
typedef WCHAR OLECHAR;
|
typedef WCHAR OLECHAR;
|
||||||
typedef const WCHAR *LPCWSTR;
|
typedef const WCHAR *LPCWSTR;
|
||||||
typedef OLECHAR *BSTR;
|
typedef OLECHAR *BSTR;
|
||||||
typedef const OLECHAR *LPCOLESTR;
|
typedef const OLECHAR *LPCOLESTR;
|
||||||
typedef OLECHAR *LPOLESTR;
|
typedef OLECHAR *LPOLESTR;
|
||||||
|
|
||||||
typedef struct _FILETIME
|
typedef struct _FILETIME
|
||||||
{
|
{
|
||||||
DWORD dwLowDateTime;
|
DWORD dwLowDateTime;
|
||||||
DWORD dwHighDateTime;
|
DWORD dwHighDateTime;
|
||||||
}FILETIME;
|
}FILETIME;
|
||||||
|
|
||||||
#define HRESULT LONG
|
#define HRESULT LONG
|
||||||
#define FAILED(Status) ((HRESULT)(Status)<0)
|
#define FAILED(Status) ((HRESULT)(Status)<0)
|
||||||
typedef ULONG PROPID;
|
typedef ULONG PROPID;
|
||||||
typedef LONG SCODE;
|
typedef LONG SCODE;
|
||||||
|
|
||||||
#define S_OK ((HRESULT)0x00000000L)
|
#define S_OK ((HRESULT)0x00000000L)
|
||||||
#define S_FALSE ((HRESULT)0x00000001L)
|
#define S_FALSE ((HRESULT)0x00000001L)
|
||||||
#define E_NOTIMPL ((HRESULT)0x80004001L)
|
#define E_NOTIMPL ((HRESULT)0x80004001L)
|
||||||
#define E_NOINTERFACE ((HRESULT)0x80004002L)
|
#define E_NOINTERFACE ((HRESULT)0x80004002L)
|
||||||
#define E_ABORT ((HRESULT)0x80004004L)
|
#define E_ABORT ((HRESULT)0x80004004L)
|
||||||
#define E_FAIL ((HRESULT)0x80004005L)
|
#define E_FAIL ((HRESULT)0x80004005L)
|
||||||
#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L)
|
#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L)
|
||||||
#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)
|
#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)
|
||||||
#define E_INVALIDARG ((HRESULT)0x80070057L)
|
#define E_INVALIDARG ((HRESULT)0x80070057L)
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define STDMETHODCALLTYPE __stdcall
|
#define STDMETHODCALLTYPE __stdcall
|
||||||
#else
|
#else
|
||||||
#define STDMETHODCALLTYPE
|
#define STDMETHODCALLTYPE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f
|
#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f
|
||||||
#define STDMETHOD(f) STDMETHOD_(HRESULT, f)
|
#define STDMETHOD(f) STDMETHOD_(HRESULT, f)
|
||||||
#define STDMETHODIMP_(type) type STDMETHODCALLTYPE
|
#define STDMETHODIMP_(type) type STDMETHODCALLTYPE
|
||||||
#define STDMETHODIMP STDMETHODIMP_(HRESULT)
|
#define STDMETHODIMP STDMETHODIMP_(HRESULT)
|
||||||
|
|
||||||
#define PURE = 0
|
#define PURE = 0
|
||||||
|
|
||||||
#define MIDL_INTERFACE(x) struct
|
#define MIDL_INTERFACE(x) struct
|
||||||
|
|
||||||
struct IUnknown
|
struct IUnknown
|
||||||
{
|
{
|
||||||
//virtual ~IUnknown() {}
|
//virtual ~IUnknown() {}
|
||||||
STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;
|
STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;
|
||||||
STDMETHOD_(ULONG, AddRef)() PURE;
|
STDMETHOD_(ULONG, AddRef)() PURE;
|
||||||
STDMETHOD_(ULONG, Release)() PURE;
|
STDMETHOD_(ULONG, Release)() PURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef IUnknown *LPUNKNOWN;
|
typedef IUnknown *LPUNKNOWN;
|
||||||
|
|
||||||
#define VARIANT_TRUE ((VARIANT_BOOL)-1)
|
#define VARIANT_TRUE ((VARIANT_BOOL)-1)
|
||||||
#define VARIANT_FALSE ((VARIANT_BOOL)0)
|
#define VARIANT_FALSE ((VARIANT_BOOL)0)
|
||||||
|
|
||||||
enum VARENUM
|
enum VARENUM
|
||||||
{
|
{
|
||||||
VT_EMPTY = 0,
|
VT_EMPTY = 0,
|
||||||
VT_NULL = 1,
|
VT_NULL = 1,
|
||||||
VT_I2 = 2,
|
VT_I2 = 2,
|
||||||
VT_I4 = 3,
|
VT_I4 = 3,
|
||||||
VT_R4 = 4,
|
VT_R4 = 4,
|
||||||
VT_R8 = 5,
|
VT_R8 = 5,
|
||||||
VT_CY = 6,
|
VT_CY = 6,
|
||||||
VT_DATE = 7,
|
VT_DATE = 7,
|
||||||
VT_BSTR = 8,
|
VT_BSTR = 8,
|
||||||
VT_DISPATCH = 9,
|
VT_DISPATCH = 9,
|
||||||
VT_ERROR = 10,
|
VT_ERROR = 10,
|
||||||
VT_BOOL = 11,
|
VT_BOOL = 11,
|
||||||
VT_VARIANT = 12,
|
VT_VARIANT = 12,
|
||||||
VT_UNKNOWN = 13,
|
VT_UNKNOWN = 13,
|
||||||
VT_DECIMAL = 14,
|
VT_DECIMAL = 14,
|
||||||
VT_I1 = 16,
|
VT_I1 = 16,
|
||||||
VT_UI1 = 17,
|
VT_UI1 = 17,
|
||||||
VT_UI2 = 18,
|
VT_UI2 = 18,
|
||||||
VT_UI4 = 19,
|
VT_UI4 = 19,
|
||||||
VT_I8 = 20,
|
VT_I8 = 20,
|
||||||
VT_UI8 = 21,
|
VT_UI8 = 21,
|
||||||
VT_INT = 22,
|
VT_INT = 22,
|
||||||
VT_UINT = 23,
|
VT_UINT = 23,
|
||||||
VT_VOID = 24,
|
VT_VOID = 24,
|
||||||
VT_HRESULT = 25,
|
VT_HRESULT = 25,
|
||||||
VT_FILETIME = 64
|
VT_FILETIME = 64
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef unsigned short VARTYPE;
|
typedef unsigned short VARTYPE;
|
||||||
typedef WORD PROPVAR_PAD1;
|
typedef WORD PROPVAR_PAD1;
|
||||||
typedef WORD PROPVAR_PAD2;
|
typedef WORD PROPVAR_PAD2;
|
||||||
typedef WORD PROPVAR_PAD3;
|
typedef WORD PROPVAR_PAD3;
|
||||||
|
|
||||||
typedef struct tagPROPVARIANT
|
typedef struct tagPROPVARIANT
|
||||||
{
|
{
|
||||||
VARTYPE vt;
|
VARTYPE vt;
|
||||||
PROPVAR_PAD1 wReserved1;
|
PROPVAR_PAD1 wReserved1;
|
||||||
PROPVAR_PAD2 wReserved2;
|
PROPVAR_PAD2 wReserved2;
|
||||||
PROPVAR_PAD3 wReserved3;
|
PROPVAR_PAD3 wReserved3;
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
CHAR cVal;
|
CHAR cVal;
|
||||||
UCHAR bVal;
|
UCHAR bVal;
|
||||||
SHORT iVal;
|
SHORT iVal;
|
||||||
USHORT uiVal;
|
USHORT uiVal;
|
||||||
LONG lVal;
|
LONG lVal;
|
||||||
ULONG ulVal;
|
ULONG ulVal;
|
||||||
INT intVal;
|
INT intVal;
|
||||||
UINT uintVal;
|
UINT uintVal;
|
||||||
LARGE_INTEGER hVal;
|
LARGE_INTEGER hVal;
|
||||||
ULARGE_INTEGER uhVal;
|
ULARGE_INTEGER uhVal;
|
||||||
VARIANT_BOOL boolVal;
|
VARIANT_BOOL boolVal;
|
||||||
SCODE scode;
|
SCODE scode;
|
||||||
FILETIME filetime;
|
FILETIME filetime;
|
||||||
BSTR bstrVal;
|
BSTR bstrVal;
|
||||||
};
|
};
|
||||||
} PROPVARIANT;
|
} PROPVARIANT;
|
||||||
|
|
||||||
typedef PROPVARIANT tagVARIANT;
|
typedef PROPVARIANT tagVARIANT;
|
||||||
typedef tagVARIANT VARIANT;
|
typedef tagVARIANT VARIANT;
|
||||||
typedef VARIANT VARIANTARG;
|
typedef VARIANT VARIANTARG;
|
||||||
|
|
||||||
MY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);
|
MY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);
|
||||||
MY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);
|
MY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);
|
||||||
MY_EXTERN_C void SysFreeString(BSTR bstr);
|
MY_EXTERN_C void SysFreeString(BSTR bstr);
|
||||||
MY_EXTERN_C UINT SysStringByteLen(BSTR bstr);
|
MY_EXTERN_C UINT SysStringByteLen(BSTR bstr);
|
||||||
MY_EXTERN_C UINT SysStringLen(BSTR bstr);
|
MY_EXTERN_C UINT SysStringLen(BSTR bstr);
|
||||||
|
|
||||||
MY_EXTERN_C DWORD GetLastError();
|
MY_EXTERN_C DWORD GetLastError();
|
||||||
MY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);
|
MY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);
|
||||||
MY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);
|
MY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);
|
||||||
MY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);
|
MY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);
|
||||||
|
|
||||||
#define CP_ACP 0
|
#define CP_ACP 0
|
||||||
#define CP_OEMCP 1
|
#define CP_OEMCP 1
|
||||||
|
|
||||||
typedef enum tagSTREAM_SEEK
|
typedef enum tagSTREAM_SEEK
|
||||||
{
|
{
|
||||||
STREAM_SEEK_SET = 0,
|
STREAM_SEEK_SET = 0,
|
||||||
STREAM_SEEK_CUR = 1,
|
STREAM_SEEK_CUR = 1,
|
||||||
STREAM_SEEK_END = 2
|
STREAM_SEEK_END = 2
|
||||||
} STREAM_SEEK;
|
} STREAM_SEEK;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
// Common/NewHandler.h
|
// Common/NewHandler.h
|
||||||
|
|
||||||
#ifndef __COMMON_NEWHANDLER_H
|
#ifndef __COMMON_NEWHANDLER_H
|
||||||
#define __COMMON_NEWHANDLER_H
|
#define __COMMON_NEWHANDLER_H
|
||||||
|
|
||||||
class CNewException {};
|
class CNewException {};
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
void
|
void
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
__cdecl
|
__cdecl
|
||||||
#endif
|
#endif
|
||||||
operator delete(void *p) throw();
|
operator delete(void *p) throw();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
// StdAfx.h
|
// StdAfx.h
|
||||||
|
|
||||||
#ifndef __STDAFX_H
|
#ifndef __STDAFX_H
|
||||||
#define __STDAFX_H
|
#define __STDAFX_H
|
||||||
|
|
||||||
// #include "MyWindows.h"
|
// #include "MyWindows.h"
|
||||||
#include "NewHandler.h"
|
#include "NewHandler.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
// Common/Types.h
|
// Common/Types.h
|
||||||
|
|
||||||
#ifndef __COMMON_TYPES_H
|
#ifndef __COMMON_TYPES_H
|
||||||
#define __COMMON_TYPES_H
|
#define __COMMON_TYPES_H
|
||||||
|
|
||||||
typedef unsigned char Byte;
|
typedef unsigned char Byte;
|
||||||
typedef short Int16;
|
typedef short Int16;
|
||||||
typedef unsigned short UInt16;
|
typedef unsigned short UInt16;
|
||||||
typedef int Int32;
|
typedef int Int32;
|
||||||
typedef unsigned int UInt32;
|
typedef unsigned int UInt32;
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
typedef __int64 Int64;
|
typedef __int64 Int64;
|
||||||
typedef unsigned __int64 UInt64;
|
typedef unsigned __int64 UInt64;
|
||||||
#else
|
#else
|
||||||
typedef long long int Int64;
|
typedef long long int Int64;
|
||||||
typedef unsigned long long int UInt64;
|
typedef unsigned long long int UInt64;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue