亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? codhuff.c

?? 著名壓縮算法的實現
?? C
字號:
/* File: codhuff.c   Author: David Bourgin (David.Bourgin@ufrima.imag.fr)   Creation date: 7/2/94   Last update: 24/7/95   Purpose: Example of Huffman encoding with a file source to compress.   Attention: The compiler must have been configured for a stack of at least   20 kb.*/#include <stdio.h>/* For routines fgetc,fputc,fwrite and rewind */#include <memory.h>/* For routines memset,memcpy */#include <malloc.h>/* For routines malloc and free */#include <stdlib.h>/* For routines qsort et exit *//* Error codes returned to the caller */#define NO_ERROR      0#define BAD_FILE_NAME 1#define BAD_ARGUMENT  2#define BAD_MEM_ALLOC 3/* Useful constants */#define FALSE 0#define TRUE  1/* Global variables */FILE *source_file,*dest_file;typedef struct s_tree { unsigned int byte;                             /* A byte has to be coded as an unsigned integer to allow a node to have a value over 255 */                        unsigned long int weight;                        struct s_tree *left_ptr,                                      *right_ptr;                      } t_tree,*p_tree;#define BYTE_OF_TREE(ptr_tree)  ((*(ptr_tree)).byte)#define WEIGHT_OF_TREE(ptr_tree)  ((*(ptr_tree)).weight)#define LEFTPTR_OF_TREE(ptr_tree)  ((*(ptr_tree)).left_ptr)#define RIGHTPTR_OF_TREE(ptr_tree)  ((*(ptr_tree)).right_ptr)typedef struct { unsigned char bits[32];                 unsigned int bits_nb;               } t_bin_val;#define BITS_BIN_VAL(bin_val)  ((bin_val).bits)#define BITS_NB_BIN_VAL(bin_val)  ((bin_val).bits_nb)                             /* Being that fgetc=EOF only after any access                                then 'stored_byte_status' is 'TRUE' if a byte has been stored with 'fgetc'                                or 'FALSE' if there's no valid byte not already read and not handled in 'stored_byte_val' */int stored_byte_status=FALSE;int stored_byte_val;/* Pseudo procedures */#define beginning_of_data()  { (void)rewind(source_file); stored_byte_status=FALSE; }#define end_of_data()  (stored_byte_status?FALSE:!(stored_byte_status=((stored_byte_val=fgetc(source_file))!=EOF)))#define read_byte()  (stored_byte_status?stored_byte_status=FALSE,(unsigned char)stored_byte_val:(unsigned char)fgetc(source_file))#define write_byte(byte)  ((void)fputc((byte),dest_file))unsigned char bit_counter_to_write=0;unsigned int val_to_write=0;void write_bin_val(bin_val)/* Returned parameters: None   Action: Writes in the output stream the value binary-coded into 'bin_val'   Errors: An input/output error could disturb the running of the program*/t_bin_val bin_val;{ unsigned char bin_pos,                byte_pos;  byte_pos=(BITS_NB_BIN_VAL(bin_val)+7) >> 3;  bin_pos=BITS_NB_BIN_VAL(bin_val) & 7;  if (bin_pos)     { byte_pos--;       val_to_write=(val_to_write<<bin_pos)|BITS_BIN_VAL(bin_val)[byte_pos];       bit_counter_to_write += bin_pos;       if (bit_counter_to_write>=8)          { bit_counter_to_write -= 8;            write_byte((unsigned char)(val_to_write>>bit_counter_to_write));            val_to_write &= ((1<<bit_counter_to_write)-1);          }     }  while (byte_pos)        { byte_pos--;          val_to_write=(val_to_write<<8)|BITS_BIN_VAL(bin_val)[byte_pos];          write_byte((unsigned char)(val_to_write>>bit_counter_to_write));          val_to_write &= ((1<<bit_counter_to_write)-1);        }}void fill_encoding()/* Returned parameters: None   Action: Fills the last byte to write in the output stream with zero values   Errors: An input/output error could disturb the running of the program*/{ if (bit_counter_to_write)     write_byte(val_to_write << (8-bit_counter_to_write));}void write_header(codes_table)/* Returned parameters: None   Action: Writes the header in the stream of codes   Errors: An input/output error could disturb the running of the program*/t_bin_val codes_table[257];{ register unsigned int i,j;  t_bin_val bin_val_to_0,            bin_val_to_1,            bin_val;         /* Is used to send in binary mode via write_bin_val */  *BITS_BIN_VAL(bin_val_to_0)=0;  BITS_NB_BIN_VAL(bin_val_to_0)=1;  *BITS_BIN_VAL(bin_val_to_1)=1;  BITS_NB_BIN_VAL(bin_val_to_1)=1;  for (i=0,j=0;j<=255;j++)      if BITS_NB_BIN_VAL(codes_table[j])         i++;                             /* From there, i contains the number of bytes of the several non null occurrences to encode */                              /* First part of the header: Specifies the bytes that appear in the source of encoding */  if (i<32)     {                       /* Encoding of the appeared bytes with a block of bytes */       write_bin_val(bin_val_to_0);       BITS_NB_BIN_VAL(bin_val)=5;       *BITS_BIN_VAL(bin_val)=(unsigned char)(i-1);       write_bin_val(bin_val);       BITS_NB_BIN_VAL(bin_val)=8;       for (j=0;j<=255;j++)           if BITS_NB_BIN_VAL(codes_table[j])              { *BITS_BIN_VAL(bin_val)=(unsigned char)j;                write_bin_val(bin_val);              }     }  else {                     /* Encoding of the appeared bytes with a block of bits */         write_bin_val(bin_val_to_1);         for (j=0;j<=255;j++)             if BITS_NB_BIN_VAL(codes_table[j])                write_bin_val(bin_val_to_1);             else write_bin_val(bin_val_to_0);     };                             /* Second part of the header: Specifies the encoding of the bytes (fictive or not) that appear in the source of encoding */  for (i=0;i<=256;i++)      if (j=BITS_NB_BIN_VAL(codes_table[i]))         { if (j<33)              { write_bin_val(bin_val_to_0);                BITS_NB_BIN_VAL(bin_val)=5;              }           else { write_bin_val(bin_val_to_1);                  BITS_NB_BIN_VAL(bin_val)=8;                }           *BITS_BIN_VAL(bin_val)=(unsigned char)(j-1);           write_bin_val(bin_val);           write_bin_val(codes_table[i]);         }}int weight_tree_comp(tree1,tree2)/* Returned parameters: Returns a comparison status   Action: Returns a negative, zero or positive integer depending on the weight   of 'tree2' is less than, equal to, or greater than the weight of 'tree1'   Errors: None*/p_tree *tree1,*tree2;{ return (WEIGHT_OF_TREE(*tree2) ^ WEIGHT_OF_TREE(*tree1))?((WEIGHT_OF_TREE(*tree2)<WEIGHT_OF_TREE(*tree1))?-1:1):0;}void suppress_tree(tree)/* Returned parameters: None   Action: Suppresses the allocated memory for the 'tree'   Errors: None if the tree has been build with dynamical allocations!*/p_tree tree;{ if (tree!=NULL)     { suppress_tree(LEFTPTR_OF_TREE(tree));       suppress_tree(RIGHTPTR_OF_TREE(tree));       free(tree);     }}p_tree build_tree_encoding()/* Returned parameters: Returns a tree of encoding   Action: Generates an Huffman encoding tree based on the data from the stream to compress   Errors: If no memory is available for the allocations then a 'BAD_MEM_ALLOC' exception is raised*/{ register unsigned int i;  p_tree occurrences_table[257],         ptr_fictive_tree;                             /* Sets up the occurrences number of all bytes to 0 */  for (i=0;i<=256;i++)      { if ((occurrences_table[i]=(p_tree)malloc(sizeof(t_tree)))==NULL)           { for (;i;i--)                 free(occurrences_table[i-1]);             exit(BAD_MEM_ALLOC);           }        BYTE_OF_TREE(occurrences_table[i])=i;        WEIGHT_OF_TREE(occurrences_table[i])=0;        LEFTPTR_OF_TREE(occurrences_table[i])=NULL;        RIGHTPTR_OF_TREE(occurrences_table[i])=NULL;      }                             /* Valids the occurrences of 'occurrences_table' with regard to the data to compressr */  if (!end_of_data())     { while (!end_of_data())             { i=read_byte();               WEIGHT_OF_TREE(occurrences_table[i])++;             }       WEIGHT_OF_TREE(occurrences_table[256])=1;                             /* Sorts the occurrences table depending on the weight of each character */       (void)qsort(occurrences_table,257,sizeof(p_tree),weight_tree_comp);       for (i=256;(i!=0)&&(!WEIGHT_OF_TREE(occurrences_table[i]));i--)           free(occurrences_table[i]);       i++;                             /* From there, 'i' gives the number of different bytes with a null occurrence in the stream to compress */       while (i>0)           /* Looks up (i+1)/2 times the occurrence table to link the nodes in an uniq tree */             { if ((ptr_fictive_tree=(p_tree)malloc(sizeof(t_tree)))==NULL)                  { for (i=0;i<=256;i++)                        suppress_tree(occurrences_table[i]);                    exit(BAD_MEM_ALLOC);                  }               BYTE_OF_TREE(ptr_fictive_tree)=257;               WEIGHT_OF_TREE(ptr_fictive_tree)=WEIGHT_OF_TREE(occurrences_table[--i]);               LEFTPTR_OF_TREE(ptr_fictive_tree)=occurrences_table[i];               if (i)                  { i--;                    WEIGHT_OF_TREE(ptr_fictive_tree) += WEIGHT_OF_TREE(occurrences_table[i]);                    RIGHTPTR_OF_TREE(ptr_fictive_tree)=occurrences_table[i];                  }               else RIGHTPTR_OF_TREE(ptr_fictive_tree)=NULL;               occurrences_table[i]=ptr_fictive_tree;               (void)qsort((char *)occurrences_table,i+1,sizeof(p_tree),weight_tree_comp);               if (i)        /* Is there an other node in the occurrence tables? */                  i++;       /* Yes, then takes care to the fictive node */             }     }  return (*occurrences_table);}void encode_codes_table(tree,codes_table,code_val)/* Returned parameters: The data of 'codes_table' can have been modified   Action: Stores the encoding tree as a binary encoding table to speed up the access.   'val_code' gives the encoding for the current node of the tree   Errors: None*/p_tree tree;t_bin_val codes_table[257],          *code_val;{ register unsigned int i;  t_bin_val tmp_code_val;  if (BYTE_OF_TREE(tree)==257)     { if (LEFTPTR_OF_TREE(tree)!=NULL)                             /* The sub-trees on left begin with an bit set to 1 */          { tmp_code_val = *code_val;            for (i=31;i>0;i--)                BITS_BIN_VAL(*code_val)[i]=(BITS_BIN_VAL(*code_val)[i] << 1)|(BITS_BIN_VAL(*code_val)[i-1] >> 7);            *BITS_BIN_VAL(*code_val)=(*BITS_BIN_VAL(*code_val) << 1) | 1;            BITS_NB_BIN_VAL(*code_val)++;            encode_codes_table(LEFTPTR_OF_TREE(tree),codes_table,code_val);            *code_val = tmp_code_val;          };       if (RIGHTPTR_OF_TREE(tree)!=NULL)                             /* The sub-trees on right begin with an bit set to 0 */          { tmp_code_val = *code_val;            for (i=31;i>0;i--)                BITS_BIN_VAL(*code_val)[i]=(BITS_BIN_VAL(*code_val)[i] << 1)|(BITS_BIN_VAL(*code_val)[i-1] >> 7);            *BITS_BIN_VAL(*code_val) <<= 1;            BITS_NB_BIN_VAL(*code_val)++;            encode_codes_table(RIGHTPTR_OF_TREE(tree),codes_table,code_val);            *code_val = tmp_code_val;          };     }  else codes_table[BYTE_OF_TREE(tree)] = *code_val;}void create_codes_table(tree,codes_table)/* Returned parameters: The data in 'codes_table' will be modified   Action: Stores the encoding tree as a binary encoding table to speed up the access by calling encode_codes_table   Errors: None*/p_tree tree;t_bin_val codes_table[257];{ register unsigned int i;  t_bin_val code_val;  (void)memset((char *)&code_val,0,sizeof(code_val));  (void)memset((char *)codes_table,0,257*sizeof(*codes_table));  encode_codes_table(tree,codes_table,&code_val);}void huffmanencoding()/* Returned parameters: None   Action: Compresses with Huffman method all bytes read by the function 'read_byte'   Errors: An input/output error could disturb the running of the program*/{ p_tree tree;  t_bin_val encoding_table[257];  unsigned char byte_read;  if (!end_of_data())                             /* Generates only whether there are data */     { tree=build_tree_encoding();                             /* Creation of the best adapted tree */       create_codes_table(tree,encoding_table);       suppress_tree(tree);                             /* Obtains the binary encoding in an array to speed up the accesses */       write_header(encoding_table);                             /* Writes the defintion of the encoding */       beginning_of_data();  /* Real compression of the data */       while (!end_of_data())             { byte_read=read_byte();               write_bin_val(encoding_table[byte_read]);             }       write_bin_val(encoding_table[256]);                             /* Code of the end of encoding */       fill_encoding();                             /* Fills the last byte before closing file, if any */     }}void help()/* Returned parameters: None   Action: Displays the help of the program and then stops its running   Errors: None*/{ printf("This utility enables you to compress a file by using Huffman method\n");  printf("as given in 'La Video et Les Imprimantes sur PC'\n");  printf("\nUse: codhuff source target\n");  printf("source: Name of the file to compress\n");  printf("target: Name of the compressed file\n");}int main(argc,argv)/* Returned parameters: Returns an error code (0=None)   Action: Main procedure   Errors: Detected, handled and an error code is returned, if any*/int argc;char *argv[];{ if (argc!=3)     { help();       exit(BAD_ARGUMENT);     }  else if ((source_file=fopen(argv[1],"rb"))==NULL)          { help();            exit(BAD_FILE_NAME);          }       else if ((dest_file=fopen(argv[2],"wb"))==NULL)               { help();                 exit(BAD_FILE_NAME);               }            else { huffmanencoding();                   fclose(source_file);                   fclose(dest_file);                 }  printf("Execution of codhuff completed.\n");  return (NO_ERROR);}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩高清不卡| 91小视频在线免费看| 国产一区二区调教| 国产乱子伦一区二区三区国色天香| 国产激情一区二区三区四区| 99v久久综合狠狠综合久久| 欧美日韩一级片在线观看| 亚洲精品一区二区三区影院| 中文字幕一区二区三区不卡在线| 亚洲一区二区精品3399| 精品一区在线看| 9l国产精品久久久久麻豆| 欧美精品丝袜中出| 国产视频911| 图片区小说区国产精品视频| 狠狠色狠狠色综合| 欧美怡红院视频| 久久这里只有精品6| 亚洲精品免费播放| 精品一区二区在线播放| 一本久道久久综合中文字幕 | 久久久久国产精品厨房| 亚洲精品亚洲人成人网| 精品一区二区免费看| 色综合色狠狠综合色| 日韩欧美国产综合| 亚洲男同性恋视频| 国产一区激情在线| 91国偷自产一区二区开放时间| 日韩免费高清视频| 亚洲精选视频在线| 国产成人亚洲综合a∨婷婷图片 | 午夜电影一区二区| av一区二区三区| 26uuu欧美日本| 亚洲一二三四区| 成人深夜视频在线观看| 欧美一级高清片| 一区二区三区四区亚洲| 丁香一区二区三区| 欧美电影免费观看高清完整版在线 | 一区二区三区在线观看网站| 亚洲成精国产精品女| 国产成人久久精品77777最新版本| 欧美精品久久一区| 亚洲男人天堂一区| 国产ts人妖一区二区| 日韩一级高清毛片| 亚洲v精品v日韩v欧美v专区| eeuss鲁片一区二区三区在线看| 日韩视频一区二区三区在线播放| 亚洲另类在线一区| 国产91在线|亚洲| 26uuu精品一区二区| 午夜欧美电影在线观看| 91在线国产观看| 日本一区二区三区电影| 国产一区在线视频| 欧美成人免费网站| 天堂一区二区在线| 欧美午夜一区二区三区| 亚洲精品乱码久久久久久黑人| thepron国产精品| 久久众筹精品私拍模特| 久久精品久久精品| 欧美一区二区三区成人| 日韩在线一二三区| 欧美日韩夫妻久久| 午夜精品视频在线观看| 欧美体内she精视频| 亚洲精选在线视频| 一本色道久久综合精品竹菊| 17c精品麻豆一区二区免费| 成人午夜免费av| 最近中文字幕一区二区三区| 成人综合日日夜夜| 国产精品久久久久久久浪潮网站| 国产成人在线免费观看| 国产欧美日韩不卡| av在线不卡免费看| 亚洲欧美区自拍先锋| 在线观看日韩电影| 亚洲国产日产av| 91麻豆精品国产91久久久久久| 日韩在线一区二区三区| 日韩免费在线观看| 狠狠色丁香久久婷婷综合丁香| 久久久久久久综合狠狠综合| 国产一区二三区好的| 国产精品午夜电影| 色婷婷久久99综合精品jk白丝| 亚洲精品成人精品456| 欧美在线制服丝袜| 日精品一区二区| 精品免费日韩av| 国产激情视频一区二区三区欧美 | 久久精品国产一区二区| 精品国产凹凸成av人导航| 国产一区二区调教| 最新久久zyz资源站| 在线视频亚洲一区| 日本欧美加勒比视频| 精品少妇一区二区三区免费观看| 激情五月婷婷综合网| 国产女人18毛片水真多成人如厕 | 中文字幕一区av| 欧美性色综合网| 麻豆高清免费国产一区| 久久久久久亚洲综合| 91麻豆免费在线观看| 午夜影院久久久| 久久女同性恋中文字幕| 91免费看视频| 日韩精品久久理论片| 久久一日本道色综合| 91免费精品国自产拍在线不卡| 亚洲大片一区二区三区| 精品人伦一区二区色婷婷| av电影在线不卡| 天天综合天天综合色| 久久久久国产精品人| 欧美亚洲高清一区| 狠狠色综合播放一区二区| 亚洲欧美自拍偷拍色图| 884aa四虎影成人精品一区| 国产成人8x视频一区二区| 一区二区久久久| 久久综合色播五月| 色狠狠一区二区| 国产精品伊人色| 亚洲国产综合视频在线观看| 精品国产免费人成电影在线观看四季 | 国产电影一区在线| 亚洲国产一区二区在线播放| 国产亚洲欧美在线| 欧美在线不卡一区| 国产一区二区三区精品视频| 亚洲国产综合人成综合网站| 国产欧美一区二区精品婷婷| 欧美日韩成人一区| 99热这里都是精品| 国产麻豆精品theporn| 亚洲一区二区三区四区五区中文 | 国产精品一区二区在线看| 亚洲一级片在线观看| 欧美国产精品v| 日韩欧美区一区二| 欧美在线观看一区二区| 成人精品一区二区三区中文字幕| 香蕉久久夜色精品国产使用方法| 中文字幕一区二区三区精华液 | 国产伦精品一区二区三区视频青涩| 一区二区三区小说| 欧美高清在线精品一区| 日韩精品一区二区在线观看| 欧美亚洲精品一区| 99麻豆久久久国产精品免费优播| 精品一区二区三区av| 日韩av不卡在线观看| 亚洲国产精品一区二区尤物区| 国产精品国产三级国产有无不卡 | 国模一区二区三区白浆| 日韩福利电影在线| 一区二区高清在线| 亚洲欧美日韩中文播放| 国产精品嫩草影院com| 久久婷婷一区二区三区| 日韩视频一区在线观看| 69堂精品视频| 欧美精品在线观看播放| 欧美午夜精品电影| 欧美伊人精品成人久久综合97 | 一区二区三区不卡视频在线观看 | 一本色道久久综合精品竹菊| 成人午夜视频网站| 成人涩涩免费视频| 国产成人久久精品77777最新版本 国产成人鲁色资源国产91色综 | 一区二区视频在线看| 国产精品成人一区二区三区夜夜夜| 精品久久久久久久一区二区蜜臀| 欧美电影在哪看比较好| 欧美亚洲日本国产| 欧美日韩一区不卡| 欧洲精品一区二区| 在线精品视频一区二区三四| 色悠久久久久综合欧美99| 91蜜桃网址入口| 一本久久a久久精品亚洲| 色综合久久久久| 日本精品免费观看高清观看| 91麻豆免费在线观看| 91久久人澡人人添人人爽欧美 | 日韩avvvv在线播放| 免费在线观看成人| 韩国欧美一区二区| 成人永久aaa| 91精彩视频在线观看| 欧美午夜一区二区三区免费大片| 欧美高清视频不卡网| 日韩欧美另类在线|