资源简介
LZW压缩算法的C++源码,已经封装成class

代码片段和文件信息
// LZW.cpp: implementation of the CLZW class.
//
//////////////////////////////////////////////////////////////////////
#include “stdafx.h“
#include “LZW.h“
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
void CLZW::InitGlobalVar()
{
num_bits = INIT_BITS;
bytes_in = 0;
bytes_out = 0;
checkpoint = CHECK_TIME;
max_code = MAXVAL(num_bits);
}
CLZW::CLZW()
{
InitGlobalVar();
code_value = NULL;
prefix_code = NULL;
append_character = NULL;
code_value=(int *)malloc(TABLE_SIZE*sizeof(unsigned int));
prefix_code=(unsigned int *)malloc(TABLE_SIZE*sizeof(unsigned int));
append_character=(unsigned char *)malloc(TABLE_SIZE*sizeof(unsigned char));
}
CLZW::~CLZW()
{
if(code_value)
free(code_value);
if(prefix_code)
free(prefix_code);
if(append_character)
free(append_character);
}
/* UNCHANGED from original
* This is the hashing routine.
*/
unsigned int CLZW::find_match(unsigned int hash_prefix unsigned int hash_character)
{
int index offset;
index = (hash_character << HASHING_SHIFT ) ^ hash_prefix;
if (index == 0 )
offset=1;
else
offset = TABLE_SIZE - index;
while(1)
{
if(code_value[index] == -1)
return(index);
if( prefix_code[index] == hash_prefix &&
append_character[index] == hash_character)
return(index);
index -= offset;
if (index < 0)
index += TABLE_SIZE;
}
}
/* UNCHANGED from original
* Decode a string from the string table storing it in a buffer.
* The buffer can then be output in reverse order by the expansion
* program.
*/
unsigned char *CLZW::decode_string(unsigned char *buffer unsigned int code)
{
int i=0;
while(code > 255 )
{
*buffer++ = append_character[code];
code=prefix_code[code];
if (i++ >= 4000 )
{
// printf(“Error during code expansion\n“);
exit(1);
}
}
*buffer=code;
return(buffer);
}
/* UNCHANGED from original
* Input a variable length code.
*/
unsigned int CLZW::input_code(FILE *input)
{
unsigned int return_value;
while (input_bit_count <= 24 ) {
input_bit_buffer |= (unsigned long) getc(input) << (24 - input_bit_count);
input_bit_count += 8;
}
return_value=input_bit_buffer >> (32-num_bits);
input_bit_buffer <<= num_bits;
input_bit_count -= num_bits;
return(return_value);
}
/* MODIFIED Output a variable length code.
*/
void CLZW::output_code(FILE *output unsigned int code)
{
output_bit_buffer |= (unsigned long) code << (32 - num_bits -
output_bit_count);
output_bit_count += num_bits;
while (output_bit_count >= 8) {
putc(output_bit_buffer >> 24 output);
output_bit_buffer <<= 8;
output_bit_count -= 8;
bytes_out++
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 9266 2008-11-08 20:02 LZW\LZW.cpp
文件 2431 2008-11-08 11:50 LZW\LZW.h
目录 0 2009-01-03 14:01 LZW
----------- --------- ---------- ----- ----
11697 3
- 上一篇:MFC下获取字符的点阵字模数据并显示
- 下一篇:C++简单的飞行射击游戏源码
相关资源
- 基于mfc的多线程文件传输
- MFC数字钟(基于VC6.0)
- VC++MFC小游戏实例教程(实例)+MFC类库
- ChartCtrl控件库(可在VS2019中使用)
- 商品库存管理系统 C++ MFC
- mfc 调用redis
- MFC视频播放器源码(支持avi/wma/mp3等格
- mfc绘图大全(画直线、矩形、椭圆)
- MFC控件重绘
- hook,捕获所有案件,查找所有窗口,
- (学习)VS2010之MFC入门到精通教程
- MFC文档_视图_框架_模板结构体系深入
- 简单员工管理系统(适合初学MFC)
- XUnZip Zip解压缩.rar
- MFC五子棋游戏
- MFC UDP编程
- MFC的异步网络通讯应用程序
- C++MFC模块讲解,黑发程序员课程整理
- 一个简单而强大的基于MFC的web server源
- 基于MFC的VC++仿QQ浏览器源码(雏形)
- MFCaccess.rar
- VC++MFC课程设计的学生成绩管理系统
- MFC 日历控件 万年历 Calendar自绘
- CrystalDiskInfo-HDD/SSD硬盘信息,SMART信息
- MFC自定义界面HUI,高效简单,含详细
- 仿射密码-Affine cipher
- c++MFC车牌自动识别定位,只能定位和
- mfc+sql 酒店客房管理系统
- 基于图割的图像分割OpenCV+MFC实现
- MFC绘制Bezier曲线B样条曲线曲线拟合
评论
共有 条评论