×
嵌入式 > 技术百科 > 详情

LZW压缩类定义和构思

发布时间:2020-06-15 发布时间:
|
//定义CLZW类

#ifndef _LZW_H_INCLUDED
#define _LZW_H_INCLUDED
#include stdio.h//用于getc,getwc
#include string.h//用于memset
#include stdlib.h //用于malloc,free

#define MAX_LZW_BITS 12 //最大LZW代码大小
#define LZW_TABLE_SIZE (1

typedef int INT32;
typedef short UINT8;
typedef short code_int; //取值范围为-1到2*MAX_LZE_BITS
typedef short hash_int; //取值范围为-2到2*HSIZE

#define MAXCODE(n_bits) (((code_int)1<

class CLZW
{
public:
CLZW();//构造函数
~CLZW();//析构函数

FILE* outfile;
FILE* infile;

int GetDataBlock(char *buf);//一个零长度的块标志数据块序列的结束
void SkipDataBlocks();//找到数据块结尾
void ReInitLZW();//初始化LZW状态
void InitLZWCode (FILE* file,int in_size);//初始化文件对象
int GetCode();//从压缩数据提取以后的code_size个比特
int LzwReadByte();//读取一个LZW压缩的字节

void CHAR_OUT(int c);//向现有缓冲区增加一个字节
void flush_packet();//清空缓冲区中的积累数据
void clear_hash();//清空hash表
void clear_block();//重置压缩并发送一个清除码
void output(code_int code);//发送一个n_bits比特的代码并用cur_accum和cur_bits重组一个8位的字节
void compress_init(FILE* file,int ibits);//初始化LZW压缩
void compress_byte(int c);//压缩一个8位字节
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_bit..清除后重新恢复
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

 

『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
分布式光纤温度传感器(DTS)系统的应用