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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? lzw.c

?? LZW編碼法的壓縮和解壓縮函數(shù)
?? C
字號:
/***********************************************************************************************************
	LZW.c

本演示程序提供了LZW編碼法的壓縮和解壓縮函數(shù),并實現(xiàn)了對圖象
文件的壓縮和解壓縮
**********************************************************************************************************/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define BITS 12                   /* Setting the number of bits to 12, 13*/
#define HASHING_SHIFT BITS-8      /* or 14 affects several constants.    */
#define MAX_VALUE (1 << BITS) - 1 /* Note that MS-DOS machines need to   */
#define MAX_CODE MAX_VALUE - 1    /* compile their code in large model if*/
                                  /* 14 bits are selected.               */
#if BITS == 14
  #define TABLE_SIZE 18041        /* The string table size needs to be a */
#endif                            /* prime number that is somewhat larger*/
#if BITS == 13                    /* than 2**BITS.                       */
  #define TABLE_SIZE 9029
#endif
#if BITS <= 12
  #define TABLE_SIZE 5021
#endif

/* 函數(shù)原型 */
int LZW_Compression(char *in_filename, char *out_filename);
int LZW_Decompression(char *in_filename, char *out_filename);

/* 內(nèi)部函數(shù) */
int find_match(int hash_prefix,unsigned int hash_character);
char *decode_string(unsigned char *buffer,unsigned int code);
unsigned int input_code(FILE *input);
void output_code(FILE *output,unsigned int code);

/* 全局變量,編碼/解碼使用的內(nèi)存緩沖區(qū) */
int *code_value;                  /* This is the code value array        */
unsigned int *prefix_code;        /* This array holds the prefix codes   */
unsigned char *append_character;  /* This array holds the appended chars */
unsigned char decode_stack[4000]; /* This array holds the decoded string */


/* 主程序 */
void main(int argc, char *argv[])
{
	printf("LZW compression and decompression utility\n");

	if (4 != argc) 
	{
		printf("\nUsage : lzw -c|d sourcefilename targetfilename\n");
		exit(0);
	}

	if (! strcmp(argv[1], "-c"))
		LZW_Compression(argv[2], argv[3]);
	else if (! strcmp(argv[1], "-d"))
		LZW_Decompression(argv[2], argv[3]);
	else
		printf("\nUnknow command.\n");
}

/**************************************************************************************************
	LZW_Compression()

  本函數(shù)用LZW算法壓縮指定的文件,并將結(jié)構(gòu)存儲到新的文件中                                     
***************************************************************************************************/
int LZW_Compression(char *in_filename, char *out_filename)
{
  unsigned int next_code;
  unsigned int character;
  unsigned int string_code;
  unsigned int index;
  int i;
  FILE *input;
  FILE *output;

  /* allocate memory for compression */
  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");
    return 0;
  }

  /* open files */
  input=fopen(in_filename,"rb");
  output=fopen(out_filename,"wb");
  if (input==NULL || output==NULL)
  {
    printf("Fatal error opening files.\n");
    return 0;
  };

  /* compressing... */

  next_code=256;              /* Next code is the next available string code*/
  for (i=0;i<TABLE_SIZE;i++)  /* Clear out the string table before starting */
    code_value[i]=-1;

  i=0;
  printf("Compressing...\n");
  string_code=getc(input);    /* Get the first code                         */
/*
** This is the main loop where it all happens.  This loop runs util all of
** the input has been exhausted.  Note that it stops adding codes to the
** table after all of the possible codes have been defined.
*/
  while ((character=getc(input)) != (unsigned)EOF)
  {
    if (++i==1000)                         /* Print a * every 1000    */
    {                                      /* input characters.  This */
      i=0;                                 /* is just a pacifier.     */
      printf(".");
    }
    index=find_match(string_code,character);/* See if the string is in */
    if (code_value[index] != -1)            /* the table.  If it is,   */
      string_code=code_value[index];        /* get the code value.  If */
    else                                    /* the string is not in the*/
    {                                       /* table, try to add it.   */
      if (next_code <= MAX_CODE)
      {
        code_value[index]=next_code++;
        prefix_code[index]=string_code;
        append_character[index]=character;
      }
      output_code(output,string_code);  /* When a string is found  */
      string_code=character;            /* that is not in the table*/
    }                                   /* I output the last string*/
  }                                     /* after adding the new one*/
/*
** End of the main loop.
*/
  output_code(output,string_code); /* Output the last code               */
  output_code(output,MAX_VALUE);   /* Output the end of buffer code      */
  output_code(output,0);           /* This code flushes the output buffer*/
  printf("\n");

  /* cleanup... */
  fclose(input);
  fclose(output);

  free(code_value);
  free(prefix_code);
  free(append_character);

  return 1;
}

/*
** This is the hashing routine.  It tries to find a match for the prefix+char
** string in the string table.  If it finds it, the index is returned.  If
** the string is not found, the first available index in the string table is
** returned instead.
*/

int find_match(int hash_prefix,unsigned int hash_character)
{
int index;
int offset;

  index = (hash_character << HASHING_SHIFT) ^ hash_prefix;
  if (index == 0)
    offset = 1;
  else
    offset = TABLE_SIZE - index;
  while (1)
  {
    if (code_value[index] == -1)
      return(index);
    if ((int)prefix_code[index] == hash_prefix && 
        append_character[index] == hash_character)
      return(index);
    index -= offset;
    if (index < 0)
      index += TABLE_SIZE;
  }
}

/*******************************************************************
	LZW_Decompression()

  用LZW對文件進(jìn)行解碼                                     
********************************************************************/
int LZW_Decompression(char *in_filename, char *out_filename)
{
  unsigned int next_code;
  unsigned int new_code;
  unsigned int old_code;
  int character;
  int counter;
  unsigned char *string;
  FILE *input;
  FILE *output;

  /* allocate memory for decompression */
  prefix_code=malloc(TABLE_SIZE*sizeof(unsigned int));
  append_character=malloc(TABLE_SIZE*sizeof(unsigned char));
  if (prefix_code==NULL || append_character==NULL)
  {
    printf("Fatal error allocating table space!\n");
    return 0;
  }

  /* open files */
  input=fopen(in_filename,"rb");
  output=fopen(out_filename,"wb");
  if (input==NULL || output==NULL)
  {
    printf("Fatal error opening files.\n");
    return 0;
  };

  /* decompress... */

  next_code=256;           /* This is the next available code to define */
  counter=0;               /* Counter is used as a pacifier.            */
  printf("Decompress...\n");

  old_code=input_code(input);  /* Read in the first code, initialize the */
  character=old_code;          /* character variable, and send the first */
  putc(old_code,output);       /* code to the output file                */
/*
**  This is the main expansion loop.  It reads in characters from the LZW file
**  until it sees the special code used to inidicate the end of the data.
*/
  while ((new_code=input_code(input)) != (MAX_VALUE))
  {
    if (++counter==1000)   /* This section of code prints out     */
    {                      /* an asterisk every 1000 characters   */
      counter=0;           /* It is just a pacifier.              */
      printf(".");
    }
/*
** This code checks for the special STRING+CHARACTER+STRING+CHARACTER+STRING
** case which generates an undefined code.  It handles it by decoding
** the last code, and adding a single character to the end of the decode string.
*/
    if (new_code>=next_code)
    {
      *decode_stack=character;
      string=decode_string(decode_stack+1,old_code);
    }
/*
** Otherwise we do a straight decode of the new code.
*/
    else
      string=decode_string(decode_stack,new_code);
/*
** Now we output the decoded string in reverse order.
*/
    character=*string;
    while (string >= decode_stack)
      putc(*string--,output);
/*
** Finally, if possible, add a new code to the string table.
*/
    if (next_code <= MAX_CODE)
    {
      prefix_code[next_code]=old_code;
      append_character[next_code]=character;
      next_code++;
    }
    old_code=new_code;
  }
  printf("\n");

  /* cleanup... */
  fclose(input);
  fclose(output);

  free(prefix_code);
  free(append_character);

  return 1;
}

/*
** This routine simply decodes a string from the string table, storing
** it in a buffer.  The buffer can then be output in reverse order by
** the expansion program.
*/

char *decode_string(unsigned char *buffer,unsigned int code)
{
int i;

  i=0;
  while (code > 255)
  {
    *buffer++ = append_character[code];
    code=prefix_code[code];
    if (i++>=4094)
    {
      printf("Fatal error during code expansion.\n");
      exit(0);
    }
  }
  *buffer=code;
  return(buffer);
}

/*
** The following two routines are used to output variable length
** codes.  They are written strictly for clarity, and are not
** particularyl efficient.
*/

unsigned int 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) << (24-input_bit_count);
    input_bit_count += 8;
  }
  return_value=input_bit_buffer >> (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 << (32-BITS-output_bit_count);
  output_bit_count += BITS;
  while (output_bit_count >= 8)
  {
    putc(output_bit_buffer >> 24,output);
    output_bit_buffer <<= 8;
    output_bit_count -= 8;
  }
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本欧美加勒比视频| 国内成人免费视频| 精品福利一区二区三区| 91麻豆高清视频| 老司机免费视频一区二区| 亚洲美女精品一区| 久久精品人人做人人爽97| 欧美日韩一级片在线观看| 成人免费视频视频在线观看免费| 亚洲成人在线免费| 自拍av一区二区三区| 久久精品一区二区三区四区| 欧美精品tushy高清| 9色porny自拍视频一区二区| 久久爱www久久做| 亚洲成年人影院| 国产精品国产三级国产| 2022国产精品视频| 91精品国产综合久久精品性色| 一本大道久久精品懂色aⅴ| 国产黄色精品网站| 久久精品99国产国产精| 日韩精品成人一区二区三区| 一区二区三区精品在线| 黄网站免费久久| 日韩不卡一区二区三区| 亚洲成年人影院| 亚洲一级电影视频| 一区二区三区蜜桃| 一区二区三区不卡在线观看| 亚洲欧美日韩中文字幕一区二区三区 | 欧美一二三区在线| 欧美视频精品在线| 欧美午夜电影网| 欧美自拍丝袜亚洲| 成人h动漫精品一区二| 国产盗摄一区二区三区| 国产黄色精品视频| 粉嫩av一区二区三区粉嫩| 国产精品91xxx| 成人h精品动漫一区二区三区| 高清久久久久久| 97精品视频在线观看自产线路二| a美女胸又www黄视频久久| 91视频国产资源| 色综合一个色综合亚洲| 欧美日韩精品欧美日韩精品一综合| 成人美女视频在线看| 99久久伊人精品| 91免费版在线看| 欧美三级在线播放| 日韩一级黄色大片| 久久久99久久| 亚洲视频免费在线| 亚洲一区二区免费视频| 免费日本视频一区| 国产在线精品视频| www.欧美精品一二区| 日本韩国一区二区三区| 欧美一区二区播放| 久久久久久日产精品| 中文字幕亚洲欧美在线不卡| 亚洲一区二区三区美女| 日韩av一区二区在线影视| 国产麻豆精品视频| 色欧美乱欧美15图片| 欧美二区三区91| 久久蜜桃av一区精品变态类天堂| 亚洲欧洲色图综合| 男男gaygay亚洲| 成人av在线电影| 欧美无砖专区一中文字| 精品久久久久久久人人人人传媒| 国产精品每日更新在线播放网址| 亚洲午夜免费电影| 国产综合色在线视频区| 色婷婷av久久久久久久| 欧美本精品男人aⅴ天堂| 中文字幕一区二区三区av| 奇米四色…亚洲| 99re8在线精品视频免费播放| 欧美男男青年gay1069videost| 久久天堂av综合合色蜜桃网| 亚洲精品成人a在线观看| 久久99精品国产麻豆不卡| 99精品热视频| 日韩一级二级三级| 亚洲靠逼com| 韩国女主播一区二区三区| 99精品偷自拍| 久久久五月婷婷| 午夜精品一区在线观看| 成人免费毛片app| 欧美一级搡bbbb搡bbbb| 国产精品自拍av| 精品视频在线看| 国产精品美女久久久久高潮| 看电影不卡的网站| 欧美午夜一区二区三区免费大片| 国产日韩欧美精品电影三级在线| 日韩电影在线一区二区| 97久久超碰国产精品| 国产午夜精品美女毛片视频| 日韩精品午夜视频| 在线视频你懂得一区二区三区| 久久精品亚洲国产奇米99| 日韩黄色小视频| 在线精品亚洲一区二区不卡| 日韩一区在线播放| 国产一区二区不卡| 精品女同一区二区| 日本va欧美va精品发布| 欧美偷拍一区二区| 亚洲国产成人私人影院tom| 久久国产精品一区二区| 7777精品伊人久久久大香线蕉完整版 | 国产精品白丝jk黑袜喷水| 欧日韩精品视频| 国产精品欧美久久久久无广告| 麻豆国产欧美日韩综合精品二区| 欧美性大战久久| 一区二区三区在线播| 9i在线看片成人免费| 国产精品久久国产精麻豆99网站| 国内精品久久久久影院一蜜桃| 717成人午夜免费福利电影| 亚洲综合久久久| 91黄色免费看| 亚洲综合一区二区三区| 91亚洲永久精品| 成人欧美一区二区三区黑人麻豆 | 午夜激情一区二区| 欧美视频日韩视频在线观看| 亚洲伊人伊色伊影伊综合网| 色94色欧美sute亚洲线路二| 亚洲欧美日韩国产综合在线| 99riav一区二区三区| 亚洲精品菠萝久久久久久久| 色一情一乱一乱一91av| 一区二区在线观看av| 欧美性生活大片视频| 手机精品视频在线观看| 欧美一区二区成人| 国内外成人在线视频| 欧美韩国日本综合| 91丨porny丨国产入口| 夜夜嗨av一区二区三区中文字幕| 在线精品国精品国产尤物884a| 亚洲成人在线网站| 欧美成人在线直播| 精品亚洲porn| 国产精品女上位| 色狠狠av一区二区三区| 亚洲成a人片在线不卡一二三区| 欧美精品色综合| 老汉av免费一区二区三区| 亚洲国产精品高清| 色悠悠久久综合| 日韩有码一区二区三区| 久久久国产午夜精品| 99久久免费国产| 性欧美大战久久久久久久久| 日韩欧美国产精品| 成人高清伦理免费影院在线观看| 一区二区三区蜜桃| 欧美不卡一二三| 99国产精品视频免费观看| 夜夜精品浪潮av一区二区三区| 日韩久久免费av| 99九九99九九九视频精品| 午夜视频在线观看一区| 久久综合给合久久狠狠狠97色69| 99视频在线精品| 日本系列欧美系列| 国产精品久久一级| 91精品在线免费| 成人国产免费视频| 日韩av网站在线观看| 国产精品久久久久久一区二区三区| 欧美日韩国产一区| 成人性生交大片| 日韩成人一区二区三区在线观看| 国产日产欧美一区二区视频| 欧美日本在线播放| youjizz国产精品| 精品一区二区在线观看| 亚洲黄网站在线观看| 久久亚洲一级片| 欧美精品123区| 91在线国产观看| 国内精品久久久久影院薰衣草| 亚洲国产精品欧美一二99| 国产欧美视频一区二区| 91精品国产麻豆| 91蜜桃网址入口| 国产91丝袜在线观看| 日韩av一区二区三区四区| 亚洲激情自拍视频| 中文字幕欧美三区| 精品久久国产字幕高潮|