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

📄 lzwfile.h

📁 用VC++实现LZW算法
💻 H
字号:
#ifndef ___LZWFILE_H
#define ___LZWFILE_H

#include "lzwtable.h"   
#include "lzwcode.h"

/*
HGLZ file:
	lzw file head
	{
		for(i)
		{
			node head
			for(j)
			{
				single file head
				compressed file data
				.
				.
				.
				single file head
				compressed file data
			}
		}
	}

compress file data:
	lzw clear code
	data
	lzw end data
*/
#define LZW_FILE_TAG	((DWORD)'H'|(DWORD)'G'<<8|(DWORD)'L'<<16|(DWORD)'Z'<<24)
/*HGLZ*/
#define LZW_NODE_CHANGE_DIRECTORY		0X00
#define LZW_NODE_GOTO_BEGIN				0X80
#define LZW_NODE_BEGIN_COMPRESS			0X90
#define LZW_NODE_TAG					0XEE
#define LZW_SINGLE_FILE_TAG				0XFF
#define LZW_MIN_FILE_LENGTH	(sizeof(LZWFILEHEAD)+sizeof(LZWSINGLEFILEHEAD)+sizeof(LZWNODEHEAD))

typedef struct LZWEncodeSingleFileInfo
{
	DWORD dwOldLength;
	DWORD dwCompressedLength;
}LZWENCODESINGLEFILEINFO,*PLZWENCODESINGLEFILEINFO;
typedef struct LZWFileHead
{
	DWORD dwFileTag;//must be "HGLZ" LZW_FILE_TAG
	WORD wVersion;//high byte is primary version
	DWORD dwFileCount;
}LZWFILEHEAD,*PLZWFILEHEAD;
typedef struct LZWSingleFileHead
{
	WORD wSingleFileTag;// must be 0XFF lzw_single_file_tag
	DWORD dwAttribute;
	DWORD dwFileOldLength;// to caculate the compress ratio
	DWORD dwFileCompressedLength;// to find the next file head
	WORD wFileNameLength;
	// BYTE[] for file name
}LZWSINGLEFILEHEAD,*PZWSINGLEFILEHEAD;
typedef struct LZWNodeHead
{
	WORD wNodeTag;// must be 0XEE lzw_node_tag
	WORD wDirectoryType;
	// 0x00 : change 
	// 0x80 : goto begin directory
	// 0x90 : begin to compress
	WORD wDirectoryNameLength;
	//BYTE[] for directory name
}LZWNODEHEAD,*PLZWNODEHEAD;

// compress single file
BOOL LZWEncodeFile(LPCSTR pszInFile,// file to compress
					LPCSTR pszOutFile,// compressed file
					FUN_LZWENCODEDBYTES pfunEncodedBytes=NULL);
// decompress the specified file to some file
BOOL LZWDecodeFileToFile(LPCSTR pszInFile,// compressed file
						LPCSTR pszOutFile,// file be decompressed
						DWORD dwPos=0,//the decompressed file position
						FUN_LZWDECODEDBYTES pfunDecodedBytes=NULL);
// decompress the specified file to the directory 
// for batch decompress
BOOL LZWDecodeFileOnPosition(LPCSTR pszInFile,// compressed file
							LPCSTR pszOutPath,// file be decompressed
							DWORD dwPos=0,//the decompressed file position
							FUN_LZWDECODEDBYTES pfunDecodedBytes=NULL);
BOOL LZWParseFileHead(LPCSTR pszInFile,CString *pszOut=NULL);
BOOL LZWParseFileHead(LPCSTR pszInFile,CStringArray &szNameArray);
// add a file to a compressed file
BOOL LZWAddEncodeFile(LPCSTR pszInFile,// file to be added
						LPCSTR pszOutFile,// compressed file
						FUN_LZWENCODEDBYTES pfunEncodedBytes=NULL);
BOOL LZWCheckFile(LPCSTR pszCheck);// is the file a HGLZ
BOOL LZWCheckFile(CFile* pfileCheck);// is the file a HGLZ
#endif

⌨️ 快捷键说明

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