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

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

?? arith-n.cpp

?? 算術(shù)編碼壓縮算法,高壓縮比,但運(yùn)行時(shí)間較長的算法.
?? CPP
?? 第 1 頁 / 共 2 頁
字號:

//------------------------------------------------------------
// arith-n.cpp - order-n arithmetic coding module

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "errhand.h"
#include "bitio.h"

// low_count 和 high_count 唯一地定義了在 0 到 1 范圍中符號的所在位置
// scale 指 0 到 1 范圍內(nèi)的總量程,即有多少字符要記數(shù)
typedef struct
{
	unsigned short int low_count;
	unsigned short int high_count;
	unsigned short int scale;
}SYMBOL;

#define MAXIMUM_SCALE	16383		// maximum allowed frequency count 
#define ESCAPE			256			// the escape symbol
#define DONE			( -1 )		// the output stream empty symbol
#define FLUSH			( -2 )		// the symbol to flush the model

void initialize_options( int argc, char ** argv );
int check_compression( FILE* input, BIT_FILE* output );
void initialize_model( void );
void update_model( int symbol );
int convert_int_to_symbol( int symbol, SYMBOL* s );
void get_symbol_scale( SYMBOL* s);
int convert_symbol_to_int( int count, SYMBOL* s );
void add_character_to_model( int c );
void flush_model( void );
void initialize_arithmetic_decoder( BIT_FILE* stream );
void remove_symbol_from_stream( BIT_FILE* stream, SYMBOL* s );
void initialize_arithmetic_encoder( void );
void encode_symbol( BIT_FILE* stream, SYMBOL* s );
void flush_arithmetic_encoder( BIT_FILE* stream );
short int get_current_count( SYMBOL* s );

char* CompressionName	= "Adaptive order n moder with arithmetic coding";
char* Usage				= "in-file out-file [-o order]\n\n";
int max_order			= 3;

void CompressFile( FILE* input, BIT_FILE* output, int argc, char * argv[] )
{
	SYMBOL s;
	int c;
	int escaped;
	int flush = 0;
	long int text_count = 0;

	initialize_options( argc, argv );
	initialize_model();
	initialize_arithmetic_encoder();
	for(;;)
	{
		if (( ++ text_count & 0xff ) == 0 )
			flush = check_compression( input, output );
		if (!flush)
			c = getc( input );
		else
			c = FLUSH;
		if (c == EOF)
			c = DONE;
		do 
		{
			escaped = convert_int_to_symbol( c, &s );
			encode_symbol( output, &s );
		}while(escaped);
		if ( c == DONE )
			break;
		if ( c == FLUSH )
		{
			flush_model();
			flush = 0;
		}
		update_model( c );
		add_character_to_model( c );
	}
	flush_arithmetic_encoder( output );	
}

void ExpandFile( BIT_FILE* input, FILE* output, int argc, char* argv[])
{
	SYMBOL s;
	int c;
	int count;

	initialize_options( argc, argv );
	initialize_model();
	initialize_arithmetic_decoder( input );
	for (;;)
	{
		do 
		{
			get_symbol_scale( &s );
			count = get_current_count( &s );
			c = convert_symbol_to_int( count, &s );
			remove_symbol_from_stream( input, &s );
		}while( c == ESCAPE );
		if ( c == DONE )
			break;
		if ( c != FLUSH )
			putc( (char) c, output );
		else
			flush_model();
		update_model( c );
		add_character_to_model( c );
	}
}

void initialize_options( int argc, char* argv[] )
{
	while ( argc-- > 0)
	{
		if (strcmp( *argv, "-o" ) == 0)
		{
			argc--;
			max_order = atoi(*++argv);
		}
		else
			printf("Uknown argument on command line: %s\n", *argv);
		argc--;
		argv++;
	}
}

int check_compression( FILE* input, BIT_FILE* output )
{
	static long local_input_marker = 0L;
	static long local_output_marker = 0L;
	long total_input_bytes;
	long total_output_bytes;
	int local_ratio;

	total_input_bytes = ftell( input ) - local_input_marker;
	total_output_bytes = ftell( output->file );
	total_output_bytes -= local_output_marker;
	if (total_output_bytes == 0)
		total_output_bytes = 1;
	local_ratio = (int)(( total_output_bytes * 100 ) / total_input_bytes );
	local_input_marker = ftell( input );
	local_output_marker = ftell( output->file );

	return (local_ratio > 90);
}


//----------------------------------------------------------
// the next few routines contain all of the code and data used to
// perfoem modeling for thes program.

// a context table contains a list of the counts for all symbols
// that have been seen in the defined context.  for example, a 
// context of "Zor" might have only had 2 different characters 
// appear.   't' might have appeared 10 times, and 'l' might have 
// appeared once. these two counts are stored in and array of STATS.
// as new characters are added to a particular contexts, the STATS
// array will grow.  sometimes, the STATS array will shrink 
// after flushing the model.
typedef struct
{
	unsigned char symbol;
	unsigned char counts;
}STATS;


// each context has to have links to higher order contexts. These
// links are used to navigate through the context tables. For example, 
// to find the context table for "ABC", I start at the roder 0 table.
// then find the pointer to the "A" context table by looking through
// the LINKS array.  At that table, we find the "B" link  and go to 
// that table. The process continues until the destination table is 
// found.  The table pointed to by the LINKS array corresponds to the 
// symbol found at the same offset in the STATS table.  The reason that
// LINKS is in a separate structure instead of being combined with 
// STATS is to save space.  All of the leaf context nodes don't need
// next pointers, since they are in the highest order context.  In the 
// leaf nodes, the LINKS array is a NULL pointers.
typedef struct
{
	struct context* next;
}LINKS;


// The CONTEXT structure holds all of the known information about
// a particular context.  The links and stats pointers are discussed 
// immediately above here.  The max_index element gives the maximum
// index that can be applied to the stats or link array. When the 
// table is first created, and stats is set to NULL, max_index si set 
// to -1. As soon as single element is added to stats, max_index is 
// incremented to 0.
//
// The lesser context pointer is a navigational aid. It points to 
// the context that is one less than the current order. For example
// if the current is "ABC", the lesser_context pointer will 
// point to "BC". The reason for maintaining this pointer is that 
// this particular bit of table searching is done frequently, but
// the pointer only needs to be built once, when the context is 
// created.
//
typedef struct context
{
	int max_index;
	LINKS* links;
	STATS* stats;
	struct context* lesser_context;
}CONTEXT;

CONTEXT ** contexts;

// current_order contains the current order of the model. it starts 
// at max_order, and is decremented every time an ESCAPE is sent. it
// will only go down to -1 for normal symbols, but can go to -2 for
// EOF and FLUSH
int current_order;

// this table contains the cumulative totals for the current context.
// because this program is using exclusion, totals has to be calculated 
// every time a context is used. the scoreboard array keeps track of
// symbols that have appeared in higher order models, so that they
// can be excluded from lower order context total calculations.
short int totals[258];
char scoreboard[256];

void update_table( CONTEXT* table, int symbol );
void rescale_table( CONTEXT* table );
void totalize_table( CONTEXT* table );
CONTEXT* shift_to_next_context( CONTEXT* table, int c, int order );
CONTEXT* allocate_next_order_table( CONTEXT* table, int symbol, CONTEXT* lesser_context );
void recursive_flush( CONTEXT* table );

void initialize_model()
{
	int i;
	CONTEXT* null_table;
	CONTEXT* control_table;

	current_order = max_order;
	contexts = (CONTEXT**)calloc(sizeof(CONTEXT*), 10);
	if (contexts == NULL)
		fatal_error("Failure #1: allocating context table!");
	contexts += 2;
	null_table = (CONTEXT*)calloc(sizeof(CONTEXT), 1);
	if (null_table == NULL)
		fatal_error("Failure #2: allocating null table!");
	null_table->max_index = -1;
	contexts[-1] = null_table;
	for (i = 0; i <= max_order; i++)
		contexts[i] = allocate_next_order_table(contexts[i - 1], 0, contexts[i - 1]);
	free((char*)null_table->stats);
	null_table->stats = (STATS*)calloc(sizeof(STATS), 256);
	if(null_table->stats == NULL)
		fatal_error("Failure #3: allocating null table!");
	null_table->max_index = 255;
	for (i = 0; i < 256; i ++)
	{
		null_table->stats[i].symbol = (unsigned char)i;
		null_table->stats[i].counts = 1;
	}

	control_table = (CONTEXT*)calloc(sizeof(CONTEXT), 1);
	if (control_table == NULL)
		fatal_error("Failure #4: allocating control table!");
	control_table->stats = (STATS*)calloc(sizeof(STATS), 2);
	if ( control_table->stats == NULL)
		fatal_error("Failure #5: allocating control table!");
	contexts[-2] = control_table;
	control_table->max_index = 1;
	control_table->stats[0].symbol = -FLUSH;
	control_table->stats[0].counts = 1;
	control_table->stats[1].symbol = -DONE;
	control_table->stats[1].counts = 1;

	for (i = 0; i < 256; i++)
		scoreboard[i] = 0;
}

CONTEXT* allocate_next_order_table( CONTEXT* table, int symbol, CONTEXT* lesser_context )
{
	CONTEXT* new_table;
	int i;
	unsigned int new_size;

	for ( i = 0; i <= table->max_index; i++)
		if (table->stats[i].symbol == ( unsigned char )symbol)
			break;
	if ( i > table->max_index )
	{
		table->max_index++;
		new_size = sizeof(LINKS);
		new_size *= table->max_index + 1;
		if (table->links == NULL)
			table->links = (LINKS*)calloc(new_size, 1);
		else
			table->links = (LINKS*)realloc((char*)table->links, new_size);
		new_size = sizeof(STATS);
		new_size *= table->max_index + 1;
		if (table->stats == NULL)
			table->stats = (STATS*)calloc(new_size, 1);
		else
			table->stats = (STATS*)realloc((char*)table->stats, new_size);
		if (table->links == NULL)
			fatal_error("Failure #6: allocating new talbe");
		if (table->stats == NULL)
			fatal_error("Failure #7: allocating new table");
		table->stats[i].symbol = (unsigned char)symbol;
		table->stats[i].counts = 0;
	}
	new_table = (CONTEXT*)calloc(sizeof(CONTEXT), 1);
	if (new_table == NULL)
		fatal_error("Failure #8: allocating new table");
	new_table->max_index = -1;
	table->links[i].next = new_table;
	new_table->lesser_context = lesser_context;
	return (new_table);
}

// the routine is called to increment the counts for the current 
// contexts. It is called after a character has been encoded or 
// decoded. All it does is call update_table for each of the 
// current contexts, which does the work of incrementing the count.
// This particular version of update_model() practices update exclusion.
// which means that if lower order models weren't used to encode 
// or decode the character, they don't get their counts updated.
// this seems to improve compression performance quite a bit.
// to disable update exclusion, the loop would be changed to run 
// from 0 to max_order, instead of current_order to max_order
void update_model( int symbol )
{
	int i;
	int local_order;

	if (current_order < 0)
		local_order = 0;
	else
		local_order = current_order;
	if (symbol >= 0)
	{
		while ( local_order <= max_order )
		{
			if (symbol >= 0)
				update_table( contexts[local_order], symbol );
			local_order++;
		}
	}
	current_order = max_order;
	for( i = 0; i < 256; i++ )
		scoreboard[i] = 0;
}

void update_table( CONTEXT* table, int symbol )
{
	int i;
	int index;
	unsigned char temp;
	CONTEXT* temp_ptr;
	unsigned int new_size;

	// first, find the symbol in the apropriate context table. The first
	// symbol in the table is the most active. so start there.
	index = 0;
	while( index <= table->max_index && 
			table->stats[index].symbol != (unsigned char)symbol )
		index++;
	if ( index > table->max_index )
	{
		table->max_index++;
		new_size = sizeof(LINKS);
		new_size *= table->max_index + 1;
		if (current_order < max_order)
		{
			if (table->max_index == 0)
				table->links = (LINKS*)calloc(new_size, 1);

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
9191久久久久久久久久久| 99国产精品久久久久| 亚洲欧美另类小说| 精品三级av在线| 91视视频在线直接观看在线看网页在线看| 日韩电影在线看| 亚洲男人电影天堂| 久久免费视频一区| 日韩欧美国产成人一区二区| 色综合久久久久久久久| 国产很黄免费观看久久| 琪琪一区二区三区| 亚洲成av人在线观看| 亚洲日本在线a| 国产精品久久久久久久久免费桃花| 91精品国产欧美一区二区成人| 91精品国产欧美一区二区成人 | 国产亚洲欧美在线| 日韩西西人体444www| 欧美日韩一区二区三区在线看| 成人动漫一区二区三区| 国产精品性做久久久久久| 免费不卡在线观看| 午夜成人免费视频| 亚洲一区视频在线| 亚洲黄色av一区| 亚洲精品成人在线| 一区二区三区四区亚洲| 国产精品第13页| 国产日韩av一区| 久久欧美一区二区| 久久精品欧美日韩精品 | 中文字幕精品一区二区三区精品| 欧美一区二区成人6969| 欧美群妇大交群的观看方式| 欧美日韩在线精品一区二区三区激情| 色香蕉成人二区免费| 91蜜桃在线观看| 9色porny自拍视频一区二区| 99久久99久久精品免费观看| 99视频在线观看一区三区| 不卡一区二区在线| 91首页免费视频| 在线观看国产日韩| 欧美男男青年gay1069videost | 国产成人午夜电影网| 久久草av在线| 国产精品综合二区| 国产成人无遮挡在线视频| 成人午夜视频免费看| av男人天堂一区| 欧洲精品一区二区| 在线播放欧美女士性生活| 欧美一卡2卡三卡4卡5免费| 欧美哺乳videos| 久久嫩草精品久久久精品| 国产农村妇女精品| 亚洲欧美激情在线| 亚洲国产另类av| 秋霞影院一区二区| 国产传媒一区在线| 91浏览器在线视频| 欧美色中文字幕| 精品国产人成亚洲区| 国产精品久久久久aaaa| 国产在线不卡一区| 成人动漫视频在线| 欧美日韩国产另类不卡| 精品久久久久久久久久久院品网| 中文字幕成人网| 亚洲国产aⅴ天堂久久| 久久国产人妖系列| 99精品欧美一区二区三区小说| 欧美日韩欧美一区二区| 久久精品夜色噜噜亚洲a∨| 中文字幕一区二区在线播放| 香蕉久久夜色精品国产使用方法 | 国产精品美女久久福利网站| 亚洲在线视频免费观看| 国产在线不卡视频| 欧美图片一区二区三区| 国产日韩一级二级三级| 一区二区三区在线不卡| 精品中文字幕一区二区| 一本一道久久a久久精品| 91麻豆精品国产综合久久久久久| 国产精品嫩草影院com| 日韩激情在线观看| 99国产欧美另类久久久精品| 日韩一区二区三区视频| 亚洲男同性恋视频| 国产一级精品在线| 7777精品伊人久久久大香线蕉的 | aaa国产一区| 精品日韩一区二区三区| 亚洲男人的天堂av| 国产又黄又大久久| 欧美精品乱码久久久久久按摩| 国产精品美女久久久久aⅴ国产馆| 日本麻豆一区二区三区视频| av一区二区不卡| 2022国产精品视频| 亚洲超碰97人人做人人爱| av网站一区二区三区| 亚洲日韩欧美一区二区在线| 国产精品一区二区在线看| 欧美狂野另类xxxxoooo| 亚洲欧美日本韩国| 波多野结衣中文字幕一区 | 9l国产精品久久久久麻豆| 精品三级av在线| 日本亚洲免费观看| 欧美日本视频在线| 亚洲精品成人在线| 99精品久久只有精品| 欧美韩国日本一区| 国产一区二区精品久久91| 日韩免费观看高清完整版| 亚洲国产精品久久人人爱| 91免费视频观看| 欧美激情在线看| 国产成人aaa| 欧美激情自拍偷拍| 国产成人在线影院 | 午夜影院在线观看欧美| 91麻豆免费观看| 中文字幕一区二区三区蜜月| 久久99精品国产麻豆婷婷 | 欧美视频一区二区三区在线观看 | 精品视频一区三区九区| 亚洲午夜久久久久| 欧美在线你懂得| 日韩一区精品字幕| 欧美精品一区二区三区四区| 成人精品一区二区三区四区| 亚洲人成网站色在线观看| 欧美日韩大陆一区二区| 男人的j进女人的j一区| 国产日韩欧美综合一区| 欧美伊人久久久久久午夜久久久久| 图片区小说区国产精品视频| 久久久99久久| 97精品久久久午夜一区二区三区 | 日韩一级在线观看| 欧美日韩一区二区在线观看视频 | 欧美亚洲综合网| 97久久超碰国产精品电影| 欧美巨大另类极品videosbest| 国产日韩欧美综合一区| 欧美一区二区三区男人的天堂 | 极品少妇xxxx精品少妇偷拍| 精品国产一区二区精华| 国产成人免费高清| 中文字幕日韩欧美一区二区三区| 94-欧美-setu| 亚洲福中文字幕伊人影院| 5858s免费视频成人| 日本网站在线观看一区二区三区| 日韩一二在线观看| 国产精品77777| 国产精品久久久久久久久动漫 | 六月丁香综合在线视频| 久久精品一区二区三区不卡牛牛| 成人国产精品免费观看动漫| 亚洲欧美日韩国产综合| 欧美绝品在线观看成人午夜影视| 激情综合色播激情啊| 中文字幕成人在线观看| 欧美午夜寂寞影院| 久草中文综合在线| 亚洲色图都市小说| 欧美一区二区福利视频| 成人午夜免费电影| 五月天网站亚洲| 欧美激情一区不卡| 久久网这里都是精品| 99精品一区二区三区| 免费高清成人在线| 国产欧美日韩亚州综合| 欧美色综合久久| 成人做爰69片免费看网站| 亚洲第四色夜色| 国产偷国产偷精品高清尤物| 欧美色欧美亚洲另类二区| 国产一区在线观看视频| 亚洲午夜在线电影| 久久精品欧美一区二区三区麻豆| 欧美影片第一页| 成人免费毛片aaaaa**| 日韩成人午夜电影| 成人免费在线播放视频| 欧美草草影院在线视频| 欧美日免费三级在线| 高清av一区二区| 麻豆精品精品国产自在97香蕉| 亚洲激情六月丁香| 国产精品乱人伦| 精品国产乱码久久久久久浪潮 | 欧美偷拍一区二区| 国产成人精品在线看|