📄 lzw.h
字号:
// LZW.h: CLZW类定义.
//
#ifndef _LZW_H__INCLUDED
#define _LZW_H__INCLUDED
#include <stdio.h> // 用于_vsnprintf, _vsnwprintf, getc, getwc.
#include <string.h> // 用于 memset.
#include <stdlib.h> // 用于 malloc,free.
#define MAX_LZW_BITS 12 // 最大 LZW 代码大小.
#define LZW_TABLE_SIZE (1<<MAX_LZW_BITS) // 可能的 LZW 符号数量.
#define HSIZE 5003 // hash表80%占有率大小.
typedef int INT32;
typedef short UINT8;
typedef short code_int; // 必须为 -1 .. 2**MAX_LZW_BITS.
typedef short hash_int; // 必须为-2*HSIZE..2*HSIZE.
#define MAXCODE(n_bits) (((code_int) 1 << (n_bits)) - 1)
class CLZW
{
public:
CLZW();
virtual ~CLZW();
FILE* outfile;
FILE* infile;
int GetDataBlock (char *buf);
void SkipDataBlocks ();
void ReInitLZW ();
void InitLZWCode (FILE* file,int in_size);
int GetCode ();
int LZWReadByte ();
void CHAR_OUT(int c);
void flush_packet ();
void clear_hash ();
void clear_block ();
void output (code_int code);
void compress_init (FILE* file, int ibits);
void compress_byte (int c);
void compress_term ();
protected:
INT32 cur_accum; // 用于保存还未输出的bits.
int cur_bits; // cur_accum中的bits.
int n_bits; // 当前bits/code 数目.
code_int maxcode; // n_bits数目中最大的代码.
int code_counter; // 输出符号计数器.
int init_bits; // 初始n_bits ... 清除后重新恢复.
code_int ClearCode; // 清除代码(保持不变).
code_int EOFCode; // EOF代码(结束代码).
bool first_byte; // 判别是否为第一个字节.
// 编码.
code_int free_code; // 备用代码.
code_int *hash_code; // 符号代码hash表.
code_int *hash_prefix; // 前缀符号hash表.
UINT8 *hash_suffix; // 后缀字节hash表.
code_int waiting_code; // 还没有输出的代码.
int bytesinpkt; // 在当前缓冲区中的 bytes 数目.
char packetbuf[256]; // 用于压缩的积累缓冲区.
// 解码.
char code_buf[256+4]; // 当前输入数据块.
int last_byte; // code_buf中的bytes.
int last_bit; // code_buf中的bits.
bool out_of_blocks; // 如果遇到结尾为真值.
code_int *symbol_head; // 前缀符号表.
UINT8 *symbol_tail; // 后缀字节表.
UINT8 *symbol_stack; // 用于符号展开的堆栈.
UINT8 *sp; // 堆栈指针.
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -