已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验三 LZW编码一、实验目的1、加深对LZW编码的理解;2、掌握LZW编码的程序设计。二、原理与说明LZW编码的步骤:串表a1aab7b2bc8c3cb9aa4baa10ab5aaba11ba6abb12a a b aa b c ba aab ab bc1 1 2 4 2 3 6 7 5 8三、实验内容利用C、VB或VC语言实现LZW编码的算法,掌握LZW编码的程序设计并调试通过。四、实验设备计算机程序如下:#include#includeconio.h#includemalloc.h#includestring.h#includeprocess.h#define BIRS 12#define HASHING_SHIFT BITS-8#define MAX_VALUE(1BITS)-1#define MAX_CODE MAX_VALUE-1#if BITS=14#define TABLE_SIZE 18041#endif#if BITS=13#define TABLE_SIZE 9029#endif#if BITS=12#define TABLE_SIZE 5021int *code_value;unsigned int *prefix_code;unsigned char *append_character;unsigned char decode_stack4000;char ok;find match(int hash_perfix,unsigned int hash_character)int index;int offset;index=(hash_characterHASHING_SHIFT)hash_prefix;if(index=0)offset=1;elseoffset=TABLE_SIZE-index;while(1)if(code_valueindex=-1)return(index);if(prefix_codeindex=hash_prefix&append_characterindex=hash_character)return(index);index-=offset;if(index0)index+=TABLE_SIZE;input_code(FILE*input)unsigned int return_value;static int input_bit_count=0;static unsigned long input_bit_buffer=0L;while(input_bit_count=24)input_bit_buffer|=(unsigned long)getc(input)(32-BITS);input_bit_buffer=BITS;input_bit_count-=BITS;return(return_value);void output_code(FILE*output,unsigned int code)static int output_bit_count=0;static unsigned long output_bit_buffer=0L;output_bit_buffer|=(unsigned long)code=8)putc(output_bit_buffer24,output);output_bit_buffer=8;output_bit_count-=8;void compress(FILE *input,FILE *output)unsigned int next_code;unsigned int character; unsigned int string_code;unsigned int index;int i;next_code=256;for(i=0;iTABLE_SIZE;i+)code_valuei=-1;i=0;printf(nnCompressing.n);string_code=getc(input);while(character=getc(input)!=(unsigned)EOF)index=find_match(string_code,character);if(code_valueindex!=-1)string_code=code_valueindex;elseif(next_code=next_code)*decode_stack=character;string=(unsigned char*)decode_string(decode_stcak+1,old_code);elsestring=(unsigned char*)decode_string(decode_stck,nex_code);character=*string;while(string=decode_stack)putc(*string-,output);if(next_code255)*buffer+=append_charactercode;code=prefix_codecode;if(i+=4094)printf(Fatal error during code expansion.n);exit(0);*buffer=code;return(char*)buffer);int main(int argc,char*argv)FILE*input_file;FILE*output_file;FILE*lzw_file;char input_file_name81;int select;character=*string;while(string=decode_stack)putc(*string-,output);if(next_code1)strcpy(input_file_name,argv1);elseprintf(nInput file name?);scanf(%s,input_file_name);printf(nCompressed file name?);scanf(%s,compressed_file_name);input_file=fopen(input_file_name,rb);lzw_file=fopen(compressed_filename,wb);while(input_file=NULL|lzw_file=NULL)printf(Fatal error opening files!n);printf(nInput file names?); scanf(%s,input_file_name); printf(nCompressed file name?); scanf(%s,compressed_file_name);input_file=fopen(input_file_name,rb); lzw_file=fopen(compressed_filename,wb);compress(input_file,lzw_file);fclose(input_file);fclode(lzw_file);free(code_value);else if(select=2)printf(nOnput file names?); scanf(%s,onput_filename); printf(nExpanded file name?); scanf(%s,expanded_filename);input_file=fopen(onput_filename,rb); lzw_file=fopen(expanded_filename,wb);while(lzw_file=NULL|output_file=NULL)printf(Fatal error opening files!n); printf(nOnput file names?); scanf(%s,onput_filename); printf(nExpanded file name?); scanf(%s,expanded_filename);input_file=fopen(onput_filename,rb); lzw_file=fopen(expanded_filename,wb);expand(lzw_file,output_file);fclose(lzw_file);fclose(output_file);elseexit(0
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 46340-2025绿色产品评价光伏组件及逆变器
- 受众结构演变与媒体响应策略-洞察与解读
- (2025年)医院环境卫生学及消毒效果监测培训试题(附答案)
- 背阔肌训练动作
- 演讲训练思维活动
- 语文课堂教学方法设计
- 2025年药品管理法试题及答案
- 长方形的对边相等设计研究
- 2025年上海公务员考试真题及答案
- 2025年医疗器械法规单选试题附答案
- DLT 593-2016 高压开关设备和控制设备
- 备考期末-六选五-专项练习-2022-2023学年人教版英语八年级上册
- GB/T 20718-2006道路车辆牵引车和挂车之间的电连接器12V13芯型
- GB/T 18570.3-2005涂覆涂料前钢材表面处理表面清洁度的评定试验第3部分:涂覆涂料前钢材表面的灰尘评定(压敏粘带法)
- GA 576-2018防尾随联动互锁安全门通用技术条件
- 隧道工程施工风险源辨识与防控措施
- 霍金生平简介静态PPT
- 高速铁路路基堆载预压施工方案
- IATF16949:2016中文完整
- SHT3903-2017监理用表
- 2020年度希望之星英语大赛小低组看图说话(图文五篇
评论
0/150
提交评论