⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hippack.h

📁 My (so called) HiP compression algorithm as console mode utility. It s a hybrid of Lempel-Ziv 77 a
💻 H
字号:
/*****************************************************************************

  HipPack
  -------

  This is the root class for the implementation of my hybrid compression
  algorithm which combines Huffman compression and LZ77.

  by yoda

  WWW:      y0da.cjb.net
  E-mail:   LordPE@gmx.net

  You are allowed to use this class in your own projects if you keep this
  trademark.

*****************************************************************************/

#pragma once

#include <windows.h>
#include "ByteReader.h"
#include "ByteWriter.h"
#include "macros.h"

//
// constants
//
#define HIP_MAJOR_VERSION              0
#define HIP_MINOR_VERSION              2

#define HP_MIN_MATCH_LEN               2
#define HP_LITERAL_PREFIX              0
#define HP_PTRSIZE_PREFIX              1
/*
#define HP_PTRSIZE_SHORTREF            10    - bits
#define HP_PTRSIZE_NORMALREF           11    /
*/
#define HP_SHORTREF_BASE               2 // affects ptr !
#define HP_NORMALREF_BASE              3 // affects ptr and size !
#define HP_SHORTREF_MAX_SIZE           5
#define HP_SHORTREF_PTR_BIT_COUNT      7
//#define HP_MAX_MATCH_SIZE_BITS         6

#define HP_MIN_LITERALS_IN_BLOCK       14

#define HP_INITAL_BASE                 8
#define HP_BASE1_WIN                   48  * 1024
#define HP_BASE1                       9
#define HP_BASE2_WIN                   64  * 1024
#define HP_BASE2                       10
#define HP_BASE3_WIN                   96 * 1024
#define HP_BASE3                       11

#define HP_NREF_SIZE_DEC_INDEX4        0x18000
#define HP_NREF_SIZE_DEC_INDEX3        0x10000
#define HP_NREF_SIZE_DEC_INDEX2        0x37FF
#define HP_NREF_SIZE_DEC_INDEX1        0x27F

#define HIP_HDR_SIGNATURE              0x21506948 // "HiP!"
#define HIP_ITERATION_FOR_CALLBACK     98

#define HP_HUFF_ADAPT_ITERATION        512

//
// types
//

// the user should return TRUE to continue the compression
// process and FALSE to abort it
typedef BOOL (__stdcall* hpCompressCallback)( DWORD cbDone, DWORD cbTotal );

//
// structures
//
#include <PshPack1.h> // turn on struct 1-byte-alignment
typedef struct _HP_MATCH
{
	DWORD                    dwRelOff;
	WORD                     wSize;
} HP_MATCH, *PHP_MATCH;

typedef struct _HIP_HEADER
{
	DWORD                    Signature;                    // == HIP_HDR_SIGNATURE if valid
	DWORD                    cbUncompressed;
	DWORD                    CRC;                          // 0 if unused
	WORD                     MajorVersion;
	WORD                     MinorVersion;
} HIP_HEADER, *PHIP_HEADER;

typedef HP_MATCH    HIP_MATCH_HISTORY;
typedef HP_MATCH  *PHIP_MATCH_HISTORY;
#include <PopPack.h>

//
// HipPack class
//
class HipPack
{
public:
	HipPack( void* pInBuff, DWORD cbInBuff );
	~HipPack(void);

	void                Dispose();
	BOOL                PerformCompression( BYTE byLevel, OUT void** ppCompBlock, OUT DWORD* pdwcbBlock );
	BOOL                PerformDecompression( OUT void** ppCompBlock, OUT DWORD* pdwcbBlock );
	hpCompressCallback  SetCallback( hpCompressCallback proc );
	void                InterruptCompression();

private:
    void*                    m_pBuff;
	DWORD                    m_cbBuff;
	void*                    m_pOut;
	PBYTE                    m_pbyValidHEntries;
	PHIP_MATCH_HISTORY       m_pHistory;
	hpCompressCallback       m_Callback;
	BOOL                     m_bStopRun;

	void  FreeOutBuff();
	DWORD GetBitCount( DWORD value );
	BOOL  GammaEncodeDistance( PByteWriter writer, DWORD dwDistance, DWORD dwcBaseBits );
	BOOL  GammaEncodeLength( PByteWriter writer, DWORD dwLength );
//	void  GammaEncodeDistanceHigh( PByteWriter writer, DWORD dwDistance );
	DWORD GammaDecodeDistance( PByteReader reader, DWORD dwcBaseBits );
	DWORD GammaDecodeLength( PByteReader reader );
//	DWORD GammaDecodeDistanceHigh( PByteReader reader );
//	BOOL  PrepareCompression();
	DWORD GetByteChainLength( PBYTE pby, DWORD cbMaxData );
	void  MyMemCpy( void* pDest, const void* pSrc, DWORD cb );
};

typedef HipPack *PHipPack;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -