資源簡介
實現(xiàn)lzw數(shù)據(jù)壓縮與解壓 壓縮比在2:1以上 實現(xiàn)無損壓縮

代碼片段和文件信息
/********************************************************************
**
**?Copyright?(c)?2005?曹道偉
**
**?LZW?數(shù)據(jù)壓縮/解壓縮算法程序
**
**?2005-5-20
**
*****************************************************************************/
#include?
#include?
#define?BITS?12???????????????????/*?設(shè)置每個常量的位數(shù) */
#define?HASHING_SHIFT?BITS-8??????/*?為12,13或者為14* ?*/
#define?MAX_VALUE?(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?5021
#endif
void?*malloc();
int?*code_value;??????????????????/*?代碼值數(shù)組???????? */
unsigned?int?*prefix_code;????????/*?用于保存壓縮前的數(shù)據(jù) */
unsigned?char?*append_character;??/*?用于保存壓縮后的數(shù)據(jù)??*/
unsigned?char?decode_stack[4000];?/*?用于保存解壓縮后的數(shù)據(jù)*/
char?ok;
/********************************************************************
**
**?本程序從命令行獲得文件名并壓縮該文件
**?在C盤根目錄下輸出壓縮后的文件
**?然后再解壓縮,解壓縮后的文件.
**
*************************************************************************/
main(int?argc?char?*argv[])
{
FILE?*input_file;
FILE?*output_file;
FILE?*lzw_file;
char?input_file_name[81];
int??select;
char?output_filename[81];
char?compressed_filename[81];
char?expanded_filename[81];
/*
**??申請三個系統(tǒng)緩存用讀取文件、壓縮、解壓縮時用.
*/
??code_value=malloc(TABLE_SIZE*sizeof(unsigned?int));
??prefix_code=malloc(TABLE_SIZE*sizeof(unsigned?int));
??append_character=malloc(TABLE_SIZE*sizeof(unsigned?char));
??if?(code_value==NULL?||?prefix_code==NULL?||?append_character==NULL)
??{
????printf(“Fatal?error?allocating?table?space!\n“);
????/*
**?exit();
*/
??}
/*
**?獲取文件名?打開文件?創(chuàng)建壓縮后的文件.
*/
loop:
// clrscr();
//????clreol();
??printf(“**************************************************************\n“);
??printf(“*????????????Welcome?to?cao?LZW?arithmetic?demo?program!?????*\n“);
??printf(“*????????????1.Compress?file.????????????????????????????????*\n“);
??printf(“*????????????2.Expand?file.??????????????????????????????????*\n“);?
??printf(“*????????????3.Exit.?????????????????????????????????????????*\n“);
??printf(“*????????????Please?select?a?opt.????????????????????????????*\n“);
??printf(“**************************************************************\n“);
??scanf(“%d“&select);
?/******************************************/
??if(select?==?1)
{
??if?(argc>1)
????strcpy(input_file_nameargv[1]);
??else
??{
????printf(“\nInput?file?name??“);
????scanf(“%s“input_file_name);
printf(“\nCompressed?file?name??“);
scanf(“%s“compressed_filename);
??}
??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?name??“);
????scanf(“%s“input_file_name);
printf(“\nCompressed?file?name?“);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2884??2009-06-04?10:21??lzw\1.txt
?????文件?????172081??2009-06-04?16:57??lzw\Debug\lzw算法.exe
?????文件?????191696??2009-06-04?16:57??lzw\Debug\lzw算法.ilk
?????文件??????17039??2009-06-04?16:57??lzw\Debug\lzw算法.obj
?????文件?????177496??2009-06-04?16:46??lzw\Debug\lzw算法.pch
?????文件?????443392??2009-06-04?16:57??lzw\Debug\lzw算法.pdb
?????文件??????33792??2009-06-04?17:00??lzw\Debug\vc60.idb
?????文件??????53248??2009-06-04?16:57??lzw\Debug\vc60.pdb
?????文件??????27136??2009-06-04?10:28??lzw\LZW.doc
?????文件???????9197??2009-06-04?16:56??lzw\lzw算法.c
?????文件???????3413??2009-06-04?10:14??lzw\lzw算法.dsp
?????文件????????539??2009-06-04?10:25??lzw\lzw算法.dsw
?????文件??????41984??2009-06-04?17:01??lzw\lzw算法.ncb
?????文件??????48640??2009-06-04?17:01??lzw\lzw算法.opt
?????文件????????248??2009-06-04?16:59??lzw\lzw算法.plg
?????目錄??????????0??2009-06-05?10:07??lzw\Debug
?????目錄??????????0??2009-06-05?10:07??lzw
-----------?---------??----------?-----??----
??????????????1222785????????????????????17
- 上一篇:黑點軟件漢化3.01版-視頻水印專家注冊碼
- 下一篇:三維模型樹
評論
共有 條評論