Subversion Repositories spk

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 cycrow 1
/*****************************************************************************
2
 
3
  HipPack
4
  -------
5
 
6
  This is the root class for the implementation of my hybrid compression
7
  algorithm which combines Huffman compression and LZ77.
8
 
9
  by yoda
10
 
11
  WWW:      y0da.cjb.net
12
  E-mail:   LordPE@gmx.net
13
 
14
  You are allowed to use this class in your own projects if you keep this
15
  trademark.
16
 
17
*****************************************************************************/
18
 
19
#pragma once
20
 
21
#include <windows.h>
22
#include "ByteReader.h"
23
#include "macros.h"
24
 
25
//
26
// constants
27
//
28
#define HIP_MAJOR_VERSION              0
29
#define HIP_MINOR_VERSION              2
30
 
31
#define HP_MIN_MATCH_LEN               2
32
#define HP_LITERAL_PREFIX              0
33
#define HP_PTRSIZE_PREFIX              1
34
/*
35
#define HP_PTRSIZE_SHORTREF            10    - bits
36
#define HP_PTRSIZE_NORMALREF           11    /
37
*/
38
#define HP_SHORTREF_BASE               2 // affects ptr !
39
#define HP_NORMALREF_BASE              3 // affects ptr and size !
40
#define HP_SHORTREF_MAX_SIZE           5
41
#define HP_SHORTREF_PTR_BIT_COUNT      7
42
//#define HP_MAX_MATCH_SIZE_BITS         6
43
 
44
#define HP_MIN_LITERALS_IN_BLOCK       14
45
 
46
#define HP_INITAL_BASE                 8
47
#define HP_BASE1_WIN                   48  * 1024
48
#define HP_BASE1                       9
49
#define HP_BASE2_WIN                   64  * 1024
50
#define HP_BASE2                       10
51
#define HP_BASE3_WIN                   96 * 1024
52
#define HP_BASE3                       11
53
 
54
#define HP_NREF_SIZE_DEC_INDEX4        0x18000
55
#define HP_NREF_SIZE_DEC_INDEX3        0x10000
56
#define HP_NREF_SIZE_DEC_INDEX2        0x37FF
57
#define HP_NREF_SIZE_DEC_INDEX1        0x27F
58
 
59
#define HIP_HDR_SIGNATURE              0x21506948 // "HiP!"
60
#define HIP_ITERATION_FOR_CALLBACK     98
61
 
62
#define HP_HUFF_ADAPT_ITERATION        512
63
 
64
//
65
// types
66
//
67
 
68
// the user should return TRUE to continue the compression
69
// process and FALSE to abort it
70
typedef BOOL (__stdcall* hpCompressCallback)( DWORD cbDone, DWORD cbTotal );
71
 
72
//
73
// structures
74
//
75
#include <PshPack1.h> // turn on struct 1-byte-alignment
76
typedef struct _HP_MATCH
77
{
78
	DWORD                    dwRelOff;
79
	WORD                     wSize;
80
} HP_MATCH, *PHP_MATCH;
81
 
82
typedef struct _HIP_HEADER
83
{
84
	DWORD                    Signature;                    // == HIP_HDR_SIGNATURE if valid
85
	DWORD                    cbUncompressed;
86
	DWORD                    CRC;                          // 0 if unused
87
	WORD                     MajorVersion;
88
	WORD                     MinorVersion;
89
} HIP_HEADER, *PHIP_HEADER;
90
 
91
typedef HP_MATCH    HIP_MATCH_HISTORY;
92
typedef HP_MATCH  *PHIP_MATCH_HISTORY;
93
#include <PopPack.h>
94
 
95
//
96
// HipPack class
97
//
98
class HipPack
99
{
100
public:
101
	HipPack( void* pInBuff, DWORD cbInBuff );
102
	~HipPack(void);
103
 
104
	void                Dispose();
105
	BOOL                PerformDecompression( OUT void** ppCompBlock, OUT DWORD* pdwcbBlock );
106
	hpCompressCallback  SetCallback( hpCompressCallback proc );
107
//	void                InterruptCompression();
108
 
109
private:
110
    void*                    m_pBuff;
111
	DWORD                    m_cbBuff;
112
	void*                    m_pOut;
113
	PBYTE                    m_pbyValidHEntries;
114
	PHIP_MATCH_HISTORY       m_pHistory;
115
	hpCompressCallback       m_Callback;
116
	BOOL                     m_bStopRun;
117
 
118
	void  FreeOutBuff();
119
	DWORD GammaDecodeDistance( PByteReader reader, DWORD dwcBaseBits );
120
	DWORD GammaDecodeLength( PByteReader reader );
121
	void  MyMemCpy( void* pDest, const void* pSrc, DWORD cb );
122
};
123
 
124
typedef HipPack *PHipPack;