-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLZWCodec.h
80 lines (61 loc) · 1.5 KB
/
LZWCodec.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#if !defined(APP_LZWCodec_h)
#define APP_LZWCodec_h
#include <windows.h>
enum LZWError {
LZW_Success,
LZW_DecoderAlreadyRunning,
LZW_EncoderAlreadyRunning,
LZW_DecoderNotStarted,
LZW_EncoderNotStarted,
LZW_NoOutputInterface,
LZW_NextCodeOutOfRange,
LZW_FirstCodeOutOfRange,
LZW_SuffixCodeOutOfRange,
LZW_OutputError
};
class CLZWOutput {
public:
virtual ~CLZWOutput(void);
virtual LZWError Initialize(void) = 0;
virtual LZWError WriteBuffer(const BYTE *buffer, const DWORD byteCount) = 0;
virtual LZWError CleanUp(void) = 0;
};
class CLZWCodec
{
public:
CLZWCodec(void);
~CLZWCodec(void);
LZWError SetOutput(CLZWOutput *pInterface);
LZWError StartEncoder(DWORD bitCount);
LZWError StopEncoder(void);
LZWError EncodeStream(BYTE *streamPtr, DWORD streamLen);
LZWError EncodeByte(BYTE code);
LZWError StartDecoder(DWORD bitCount);
LZWError StopDecoder(void);
LZWError DecodeStream(BYTE *streamPtr, DWORD streamLen);
private:
LZWError writeCode(DWORD code);
CLZWOutput* m_pOutputInterface;
BYTE m_Buffer[8192];
DWORD m_BufferSize;
DWORD m_BytesInBuffer;
bool m_IsEncoding;
bool m_IsDecoding;
DWORD m_InitialBitCount;
DWORD m_CurrentBitCount;
DWORD m_ClearCode;
DWORD m_EndCode;
DWORD m_NextFreeCode;
DWORD m_NextBitShift;
DWORD m_BitData;
DWORD m_BitsLoaded;
DWORD m_PrefixCode;
DWORD m_OldCode;
DWORD m_FirstCode;
DWORD m_PrefixList[4096];
DWORD m_SuffixList[4096];
DWORD* m_PrefixFirst;
DWORD* m_PrefixNext;
BYTE* m_CodeList;
};
#endif // APP_LZWCodec_h