91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 4KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2021-05-09
  • 語(yǔ)言: C/C++
  • 標(biāo)簽: LZW??壓縮??mfc??封裝??

資源簡(jiǎn)介

LZW壓縮算法的C++源碼,已經(jīng)封裝成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?< 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? 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)?< 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?<?????????????????????????????????????????????????????????????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++

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----

?????文件???????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


評(píng)論

共有 條評(píng)論