📄 lzw.h
字号:
// LZW.h: interface for the CLZW class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_LZW_H__0BC8178C_3AB9_4B75_97D8_8B36939F1A28__INCLUDED_)
#define AFX_LZW_H__0BC8178C_3AB9_4B75_97D8_8B36939F1A28__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VALUE
#define FUNCTION
#define INIT_BITS 9
#define MAX_BITS 14 /* Do not exceed 14 with this program */
#define HASHING_SHIFT MAX_BITS - 8
#if MAX_BITS == 14 /* Set the table size. Must be a prime */
#define TABLE_SIZE 18041 /* number somewhat larger than 2^MAX_BITS.*/
#elif MAX_BITS == 13
#define TABLE_SIZE 9029
#else
#define TABLE_SIZE 5021
#endif
#define CLEAR_TABLE 256 /* Code to flush the string table */
#define TERMINATOR 257 /* To mark EOF Condition, instead of MAX_VALUE */
#define FIRST_CODE 258 /* First available code for code_value table */
#define CHECK_TIME 100 /* Check comp ratio every CHECK_TIME chars input */
#define MAXVAL(n) (( 1 <<( n )) -1) /* max_value formula macro */
class CLZW
{
public:
CLZW();
virtual ~CLZW();
public FUNCTION:
bool compress(const char *input, const char *output);
bool expand(const char *input, const char *output);
private VALUE:
int *code_value; /* This is the code value array */
unsigned int *prefix_code; /* This array holds the prefix codes */
unsigned char *append_character; /* This array holds the appended chars */
unsigned char decode_stack[4000]; /* This array holds the decoded string */
int num_bits; /* Starting with 9 bit codes */
unsigned long bytes_in,bytes_out; /* Used to monitor compression ratio */
unsigned int max_code; /* old MAX_CODE */
unsigned long checkpoint; /* For compression ratio monitoring */
int output_bit_count;
unsigned long output_bit_buffer;
int input_bit_count;
unsigned long input_bit_buffer;
private FUNCTION:
unsigned int find_match(unsigned int hash_prefix, unsigned int hash_character);
unsigned char *decode_string(unsigned char *buffer, unsigned int code);
unsigned int input_code(FILE *input);
void output_code(FILE *output, unsigned int code);
void compress(FILE *input, FILE *output);
void expand(FILE *input, FILE *output);
void InitGlobalVar();
};
#endif // !defined(AFX_LZW_H__0BC8178C_3AB9_4B75_97D8_8B36939F1A28__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -