<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > LZW壓縮類定義和構(gòu)思

          LZW壓縮類定義和構(gòu)思

          作者: 時(shí)間:2016-12-01 來源:網(wǎng)絡(luò) 收藏
          //定義CLZW

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

          本文引用地址:http://www.ex-cimer.com/article/201612/324260.htm

          #define MAX_LZW_BITS 12 //最大LZW代碼大小
          #define LZW_TABLE_SIZE (1<#define HSIZE 5003 //hash表80%占有率大小

          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<<(n_bits))-1)

          class CLZW
          {
          public:
          CLZW();//構(gòu)造函數(shù)
          ~CLZW();//析構(gòu)函數(shù)

          FILE* outfile;
          FILE* infile;

          int GetDataBlock(char *buf);//一個(gè)零長(zhǎng)度的塊標(biāo)志數(shù)據(jù)塊序列的結(jié)束
          void SkipDataBlocks();//找到數(shù)據(jù)塊結(jié)尾
          void ReInitLZW();//初始化LZW狀態(tài)
          void InitLZWCode (FILE* file,int in_size);//初始化文件對(duì)象
          int GetCode();//從壓縮數(shù)據(jù)提取以后的code_size個(gè)比特
          int LzwReadByte();//讀取一個(gè)LZW壓縮的字節(jié)

          void CHAR_OUT(int c);//向現(xiàn)有緩沖區(qū)增加一個(gè)字節(jié)
          void flush_packet();//清空緩沖區(qū)中的積累數(shù)據(jù)
          void clear_hash();//清空hash表
          void clear_block();//重置壓縮并發(fā)送一個(gè)清除碼
          void output(code_int code);//發(fā)送一個(gè)n_bits比特的代碼并用cur_accum和cur_bits重組一個(gè)8位的字節(jié)
          void compress_init(FILE* file,int ibits);//初始化LZW壓縮
          void compress_byte(int c);//壓縮一個(gè)8位字節(jié)
          void compress_term();//保存結(jié)尾

          protected:
          INT32 cur_accum;//用于保存還未輸出的bits
          int cur_bits;//cur_accum中的bits
          int n_bits;//當(dāng)前bits/code數(shù)目
          code_int maxcode;//n_bits數(shù)目中的最大的代碼
          int code_counter;//輸出符號(hào)計(jì)數(shù)器
          int init_bits;//初始n_bit..清除后重新恢復(fù)
          code_int ClearCode;//清除代碼(保持不變)
          code_int EOFCode;//EOF代碼(結(jié)束代碼)
          bool first_byte;//判斷是否為第一個(gè)字節(jié)

          //壓縮
          code_int free_code;//備用代碼
          code_int *hash_code;//符號(hào)代碼Hash表
          code_int *hash_prefix;//前綴符號(hào)Hash表
          UINT8 *hash_suffix;//后綴字節(jié)Hash表
          code_int waiting_code;//還沒有輸出的代碼
          int bytesinpkt;//在當(dāng)前緩沖區(qū)中的bytes數(shù)目
          char packetbuf[256];//用于壓縮的積累緩沖區(qū)

          //解壓
          char code_buf[256+4];//當(dāng)前輸入數(shù)據(jù)塊
          int last_byte;//code_buf中的bytes
          int last_bit;//code_buf中的bits
          bool out_of_blocks;//遇到結(jié)尾為真值
          code_int *symbol_head;//前綴符號(hào)表
          UINT8 *symbol_tail;//后綴字節(jié)表
          UINT8 *symbol_stack;//用于符號(hào)展開的棧
          UINT8 *sp;//棧指針

          };

          #endif



          關(guān)鍵詞: LZW壓縮類定義構(gòu)

          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();