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

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

?? lzw.c

?? LZW compression example with java
?? C
字號:
/*The LZW Lib, Included as a part of the compression tutorial
 *Written By Martin Zolnieryk 
 *
 *Thanks Goes to Mark Nelson and ever other person whos tutorials
 *aided in the writing of this.
 *
 *This code is freeware, however if you use this some credit
 *be nice.
*/
#include <stdio.h>
#include <string.h>
#include "allegro.h"
#include "lzw.h"


//Creates the table
int create_lzw_table (LZW *table, int bits)
{
table->prefix = malloc(sizeof(unsigned short int) * (1<<(bits)));
table->character = malloc(sizeof(short int) * (1<<(bits)));
table->lzw_size = (1<<(bits))-1; //One less, becuase of 0 :)
table->codes_used = 0;
table->codes_reserved = 255;
table->buffer = 0;
table->buffer_bits = 0;
table->bits = bits;
table->buffer_size = 0; //tells how big buffer chunks are
table->to_nbuffer = 0;
table->string = malloc(sizeof(unsigned char) * (1<<bits));
clear_lzw_table (table);
return 0;
}

//This is a little handy tool that returns the string
//Corrosponding to the appropriate string ID.
//Returns the size of the string
int lzw_get_string( LZW *table,int code_number)
{
int looper= 0;
 while(code_number > table->codes_reserved)
 { 
  table->string[looper] = table->character[code_number];
  code_number = table->prefix[code_number];
  looper++; 
 }
 table->string[looper] = code_number;
 looper++;
 table->string[looper] = '\0'; //End of string
 return looper;
}


//Free's the table
int delete_lzw_table (LZW *table)
{
//Error Checking
if(!table)
 return 1; //Error
//Free memory
if(table->prefix)
    free(table->prefix);
if(table->character)
    free(table->character);
if(table->string)
    free(table->string);
//Clear pointers
table->string = NULL;
table->prefix = NULL;
table->character = NULL;
//Set Defaults
table->codes_used = 0;
table->codes_reserved = 255; //255 by default
return 0;
}

//Clears the table's values
//Used mainly for gif clearing
int clear_lzw_table(LZW *table)
{
int looper;
//Some Error Checking
if(!table)
 return 1;
if(!table->prefix || !table->character)
 return 1;
//Clear Table
for(looper = 0; looper < table->lzw_size+1; looper++)
{
    table->prefix[looper] = 0; 
    table->character[looper] = -1; //Would use 0, but NULL uses it
    table->string[looper] = 0;
}
return 0;
}

//Completely Clears the table
//This is the proper use, above is used mainly for gifs, to reset the
//values at clear code
int clear_lzw_tablef(LZW *table,int bits)
{
int looper;
//Some Error Checking
if(!table)
 return 1;
if(!table->prefix || !table->character)
 return 1;
//Clear Table
for(looper = 0; looper < table->lzw_size+1; looper++)
{
    table->prefix[looper] = 0; 
    table->character[looper] = -1; //Would use 0, but NULL uses it
    table->string[looper] = 0;
}
table->codes_used = 0;
table->codes_reserved = 255;
table->buffer = 0;
table->buffer_bits = 0;
table->bits = bits;
table->buffer_size = 0; //tells how big buffer chunks are
table->to_nbuffer = 0;

return 0;
}

//This formula is really easy to understand
//Simply Does a brute-force search throught the entire table
//However, it is optimized not to look at lower code values then itself
int lzw_find_code(LZW *table, int string_buffer, int character)
{
int looper;
int counter = 0;
looper = string_buffer; //A code after string buffer cant be below
//The Search
for(looper; looper <= table->codes_used+table->codes_reserved;looper++)
 {
  //If we find a match
  if(string_buffer == table->prefix[looper] && character == table->character[looper])
    return looper;
 }
//If not we return the next available code 
return table->codes_used + 1 +table->codes_reserved;
}

//Compress a file with LZW encoding,
//This is a nice little example of how it can be used
int lzw_compress_file(LZW *table,const char *in, const char *out)
{
FILE *file_in, *file_out;
char written = 0;
short int next_char;      //Check psuedo code, grabs next char
short int string_buffer;  //Check the psuedo code, hold string info
short int code_number;    //Holds code value for STRING_BUFFER

file_in = fopen(in,"rb"); //We open files and make sure they opened correctly
if(file_in == NULL)
 return -1;
file_out = fopen(out,"wb");
if(file_out ==NULL)
 return -1;

clear_lzw_tablef(table,table->bits);
string_buffer=fgetc(file_in);  //Get the first code
while(!feof(file_in)) //End when the file is finished
  {
    next_char = fgetc(file_in); //get next code
    code_number = lzw_find_code(table,string_buffer,next_char); //look for entry
    if (table->character[code_number] != -1)  //If its in the table
	{
        string_buffer= code_number;     
		written = 0;
	}
    else   //If its not in the table
    {                                      
        //We can only add new entries if the table is not full  
        if (table->codes_used+ table->codes_reserved < table->lzw_size-1)
        {
          table->prefix[code_number]= string_buffer;
          table->character[code_number]=next_char;
          table->codes_used++;
        }

        //We write the code
        written = 1;
		lzw_write_code(table,file_out,string_buffer);
        //Start again
        string_buffer=next_char;     
    }                                
  }                                  
//This is our little way of saying the file is finished, this code number
//is not used
if(!written)
lzw_write_code(table,file_out,string_buffer); //In case last byte was not written
lzw_write_code(table,file_out,table->lzw_size); //ENDOFFILE
//Will flush the buffer if any codes need to be flushed
lzw_flush_write_code(table, file_out);
fclose(file_in);
fclose(file_out);
return 0;
}


//Does the oposite of the routine above
int lzw_decompress_file(LZW *table,const char *in, const char *out)
{
FILE *file_in, *file_out;
short int looper;
short int first_code = -1;      //Check psuedo code, is the previous code
unsigned short int next_code;  //Name is self explanatory   
unsigned char first_char;      //Is used if the code is not in the table

file_in = fopen(in,"rb"); //We open files and make sure they opened correctly
if(file_in == NULL)
 return -1;
file_out = fopen(out,"wb");
if(file_out ==NULL)
 return -1;
clear_lzw_tablef(table,table->bits);
//Do the initialization
first_code = lzw_get_code(table,file_in);
first_char = first_code;         
fputc(first_code,file_out);  


//We start the main loop
while((next_code = lzw_get_code(table,file_in))!= table->lzw_size)
  {

   //This is some error checking, basically
   //If a the buffer is empty, and the file is finshed, exit!
   if(feof(file_in))
   {
     if(!table->buffer_bits)
      break;
   }  

    //If not in table
    if (next_code > table->codes_used + table->codes_reserved)          
    {
      table->codes_used++;
      table->prefix[next_code]= first_code;
      table->character[next_code]=first_char;
      looper = lzw_get_string(table,next_code);
    }
    //If the code was already in the table
    //See if we can add a new code to the table
    //Make sure we have not gone over the table size
    else if(table->codes_used + table->codes_reserved < table->lzw_size )                                   
    {                                       
        looper = lzw_get_string(table,next_code);
        table->codes_used++;
        table->prefix[table->codes_used +table->codes_reserved]= first_code;
        table->character[table->codes_used +table->codes_reserved]=table->string[looper-1];
    }
    else //Normal 0-255 ascii char
      looper = lzw_get_string(table,next_code);


    //We write out the decompressed code to the file
    first_char = table->string[looper-1];    
    first_code = next_code;
    while(looper > 0)
     {
 
      fputc(table->string[looper-1],file_out);
      looper--;
     }
 
  } 
fclose(file_in);
fclose(file_out);
 return 0;
}

//This writes a code to a file, really cool stuff.
//We support a max of 16 bit compression
int lzw_write_code(LZW *table,FILE *fp, unsigned int code)
{
//Some bit manipulation
table->buffer |= code << (sizeof(int)*8 - table->bits - table->buffer_bits);
table->buffer_bits+=table->bits;
while(table->buffer_bits >=8)//Never go less than 8 or we loose data
 {
  fputc((table->buffer >> ((sizeof(int) - sizeof(char))*8)),fp);
  table->buffer <<=8; //Remove the char from the buffer
  table->buffer_bits-= 8; //Buffer now stores one less char.
 }
return 0;
}

//Flushes if anything left
int lzw_flush_write_code(LZW *table,FILE *fp)
{
if(table->buffer_bits > 0)
 lzw_write_code(table,fp, 0);
return 0;
}
//This gets a gif code from the file
//this time, we work backwards
int lzw_get_code(LZW*table,FILE *fp)
{
int temp;
while(table->buffer_bits <=((sizeof(int)-sizeof(char))*8))//Never go over than size - or we loose data
 {
//No point reading anymore, files done :p
if(feof(fp))
      break;
   table->buffer |= (unsigned char)getc(fp) <<((sizeof(int)-sizeof(char))*8 - table->buffer_bits);
   table->buffer_bits+= 8; //Buffer now stores one less char.
 }
temp = table->buffer >>(sizeof(int)*8 -table->bits);
table->buffer <<= table->bits;
table->buffer_bits -= table->bits;
return temp;
}




?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲色图欧美激情| 岛国av在线一区| 岛国精品在线播放| 欧美猛男gaygay网站| 国产精品妹子av| 激情另类小说区图片区视频区| 97国产一区二区| 国产欧美一区二区在线| 久久精品国产一区二区| 欧美日韩国产高清一区| 亚洲欧美在线高清| 国产成人av一区二区| 日韩欧美不卡在线观看视频| 婷婷综合五月天| 欧美亚洲精品一区| 亚洲第一精品在线| 91黄色免费看| 亚洲卡通动漫在线| www.亚洲人| 亚洲私人影院在线观看| av一二三不卡影片| 国产精品麻豆网站| 成人高清伦理免费影院在线观看| 亚洲精品在线观看网站| 久久99精品久久久久婷婷| 欧美高清hd18日本| 三级亚洲高清视频| 欧美一区二区三区四区五区| 午夜精品久久久久久久99水蜜桃| 欧美日韩一区二区三区免费看| 依依成人综合视频| 欧美三级视频在线观看| 午夜日韩在线电影| 欧美va亚洲va| 国产成人精品一区二| 亚洲欧洲日韩女同| 在线视频观看一区| 日韩二区在线观看| 久久久亚洲精品一区二区三区 | 成人午夜电影小说| 国产婷婷色一区二区三区四区| 国产美女在线精品| 国产精品高潮久久久久无| 91在线精品一区二区三区| 亚洲免费资源在线播放| 欧美日韩国产天堂| 久久国产尿小便嘘嘘| 中文字幕精品三区| 欧美在线小视频| 久久99精品国产麻豆婷婷洗澡| 久久久99精品久久| 91同城在线观看| 午夜精品一区二区三区三上悠亚| 欧美一激情一区二区三区| 国产专区欧美精品| 最新久久zyz资源站| 欧美日韩国产一级片| 国产美女一区二区| 一区二区成人在线| 精品日韩一区二区| caoporen国产精品视频| 日韩制服丝袜先锋影音| 久久蜜桃一区二区| 欧美性生活影院| 国产成人丝袜美腿| 午夜不卡在线视频| 国产精品色一区二区三区| 欧美三级电影在线看| 国产乱人伦偷精品视频不卡| 亚洲亚洲精品在线观看| 久久精品人人做人人综合| 欧美性猛交xxxx乱大交退制版 | 久久久久99精品国产片| 在线观看中文字幕不卡| 国产精品99久久久久久宅男| 亚洲一区二区三区四区五区黄 | 视频精品一区二区| 中文字幕av一区二区三区| 欧美日韩精品欧美日韩精品| 国产成人自拍网| 三级在线观看一区二区| 亚洲乱码中文字幕| 国产三级精品视频| 日韩久久精品一区| 欧美色倩网站大全免费| 成人h动漫精品一区二| 蜜桃在线一区二区三区| 亚洲综合色在线| 中文字幕一区二区三区色视频| 欧美岛国在线观看| 欧美一级夜夜爽| 色综合天天综合狠狠| 国产成人精品影院| 国产精品自在欧美一区| 免费成人小视频| 亚洲一区自拍偷拍| 亚洲色图制服丝袜| 国产精品伦一区| 国产亚洲福利社区一区| 精品不卡在线视频| 久久久蜜臀国产一区二区| 日韩女优毛片在线| 538在线一区二区精品国产| 欧美日韩一区在线| 欧美午夜在线观看| 欧美又粗又大又爽| 欧美性猛交xxxx乱大交退制版| 色欧美88888久久久久久影院| 成人黄色片在线观看| 成人三级伦理片| av亚洲精华国产精华精| fc2成人免费人成在线观看播放| 成人a级免费电影| 成人av午夜电影| 色综合天天性综合| 欧美在线高清视频| 欧美精品自拍偷拍动漫精品| 911国产精品| 日韩欧美中文一区二区| 亚洲精品一区二区三区香蕉| 久久综合狠狠综合久久综合88| 欧美第一区第二区| 国产精品视频一二三区| 中文字幕视频一区二区三区久| 亚洲欧美中日韩| 亚洲国产一区二区三区| 日韩影院精彩在线| 国产精品18久久久久久久网站| 国产成人免费视频精品含羞草妖精| 国产成人欧美日韩在线电影| 97精品久久久午夜一区二区三区| 欧美亚一区二区| 日韩精品中午字幕| 欧美国产激情一区二区三区蜜月 | 91浏览器打开| 欧美日韩一区高清| www国产精品av| 国产精品成人免费| 亚洲.国产.中文慕字在线| 日本va欧美va欧美va精品| 国产成人免费视频网站| 91福利视频在线| 精品88久久久久88久久久| 亚洲女女做受ⅹxx高潮| 麻豆免费精品视频| 91丝袜美女网| 日韩一区二区三区电影在线观看| 国产精品色哟哟网站| 五月天久久比比资源色| 国产99久久久国产精品| 欧美日韩三级在线| 国产精品不卡视频| 麻豆专区一区二区三区四区五区| 不卡一区中文字幕| 日韩精品一区在线| 一区二区三区四区在线播放| 国内一区二区视频| 欧美日韩免费在线视频| 国产日产欧美一区| 日韩vs国产vs欧美| 97精品久久久午夜一区二区三区 | 国产精品夜夜嗨| 欧美精选在线播放| 亚洲视频中文字幕| 国产福利91精品| 制服丝袜国产精品| 亚洲一区二区五区| 波多野结衣在线一区| 精品三级av在线| 亚洲超碰精品一区二区| 91毛片在线观看| 国产欧美1区2区3区| 久久er99精品| 日韩一级片在线播放| 亚洲国产综合91精品麻豆| av成人老司机| 国产欧美一区二区三区鸳鸯浴 | 亚洲精品视频自拍| 成人aa视频在线观看| 国产日韩精品视频一区| 精品一区免费av| 欧美一级日韩免费不卡| 亚洲成人免费在线| 在线观看一区日韩| 一区二区三区四区蜜桃| 99久久精品情趣| 国产精品二三区| 成人av网址在线观看| 亚洲国产高清不卡| 高潮精品一区videoshd| 欧美国产视频在线| 成人免费av资源| 国产精品色哟哟| 99国内精品久久| 亚洲日本va在线观看| 一本大道久久a久久综合婷婷| 国产精品久久久久久久久免费相片| 国产精品91xxx| 中文字幕一区日韩精品欧美| 99久久精品国产观看|