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

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

?? arith-n.cpp

?? 是算術編碼界碼的程序
?? 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 范圍內的總量程,即有多少字符要記數
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);

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久精品人人爽人人爽| 99精品在线免费| 91精品国产乱| 日本 国产 欧美色综合| 欧美日韩国产精品成人| 天天av天天翘天天综合网 | 成a人片国产精品| 亚洲视频在线一区二区| 欧美中文一区二区三区| 石原莉奈在线亚洲二区| 精品国产一区二区国模嫣然| 国产999精品久久久久久绿帽| 中文字幕一区二区三区视频| 欧美丝袜丝交足nylons| 蜜桃视频第一区免费观看| 精品日产卡一卡二卡麻豆| 国产乱码精品一区二区三区av| 国产精品网站一区| 欧美伊人久久大香线蕉综合69| 日韩成人精品在线| 国产人成一区二区三区影院| 日本福利一区二区| 老色鬼精品视频在线观看播放| 中文字幕第一区| 欧美剧情片在线观看| 国产精品一区二区久激情瑜伽| 亚洲视频一区在线观看| 制服丝袜av成人在线看| 国产成人av一区二区三区在线观看| 亚洲精品成人a在线观看| 精品成人私密视频| 色婷婷综合久久久| 国内外成人在线视频| 亚洲视频小说图片| 亚洲精品一区二区三区香蕉| 91在线免费播放| 玖玖九九国产精品| 亚洲日本在线天堂| 久久综合狠狠综合久久激情| 在线观看av不卡| 成人手机在线视频| 蜜臀精品久久久久久蜜臀 | 成人夜色视频网站在线观看| 亚洲成av人片在线| 国产精品剧情在线亚洲| 日韩欧美视频一区| 欧美中文一区二区三区| 成人综合在线视频| 国产在线一区二区综合免费视频| 天堂一区二区在线| 亚洲一级在线观看| 国产精品久久久久久久久免费相片 | 99天天综合性| 精品亚洲国内自在自线福利| 亚洲国产精品久久艾草纯爱| 国产精品不卡在线| 国产偷国产偷精品高清尤物| 91精品国产综合久久久久久久久久| 91免费版pro下载短视频| 国产精品一线二线三线| 麻豆精品精品国产自在97香蕉| 亚洲线精品一区二区三区 | 欧美视频三区在线播放| av一区二区三区四区| 国产乱码精品1区2区3区| 麻豆精品精品国产自在97香蕉| 午夜精品在线看| 亚洲成人动漫在线免费观看| 亚洲大片精品永久免费| 亚洲影视资源网| 亚洲与欧洲av电影| 午夜久久久影院| 日韩黄色免费网站| 亚洲已满18点击进入久久| 在线区一区二视频| 亚洲精品一卡二卡| 国产精品国产三级国产有无不卡 | 成人av网址在线| 欧美一级片在线观看| 欧美日韩精品一区二区三区| 欧美性大战久久久久久久| 91麻豆swag| 欧美色视频一区| 欧美日韩国产电影| 欧美一区二区三区性视频| 欧美一区二区在线免费观看| 日韩一区二区电影| 日韩精品中午字幕| 国产视频一区二区三区在线观看| 欧美激情资源网| 最近中文字幕一区二区三区| 一个色在线综合| 婷婷一区二区三区| 经典一区二区三区| 国产福利精品导航| 调教+趴+乳夹+国产+精品| 波多野结衣精品在线| 成人免费视频app| 粉嫩在线一区二区三区视频| 91在线国内视频| 欧美午夜精品久久久久久孕妇| 欧美日韩一区三区| 精品噜噜噜噜久久久久久久久试看| 精品国精品国产尤物美女| 国产欧美一二三区| 一区二区三区免费观看| 日韩av电影免费观看高清完整版| 精品一区二区三区免费观看| 成人国产免费视频| 欧美精品一卡两卡| 日韩精品中文字幕在线一区| 国产精品免费丝袜| 午夜精品久久久久久久久| 国产一区二区三区在线观看免费| av男人天堂一区| 欧美精品久久一区二区三区| 国产视频一区二区三区在线观看| 亚洲美女在线国产| 久88久久88久久久| av中文字幕在线不卡| 制服视频三区第一页精品| 国产精品久久久一本精品| 亚洲大片精品永久免费| 国产98色在线|日韩| 欧美日本在线看| 亚洲国产成人一区二区三区| 视频一区视频二区中文| 不卡视频在线观看| 日韩精品一区二区在线| 亚洲狠狠丁香婷婷综合久久久| 久久草av在线| 色国产精品一区在线观看| 精品国产伦一区二区三区免费| 亚洲蜜臀av乱码久久精品| 国产成人高清在线| 这里只有精品电影| 亚洲欧美日韩精品久久久久| 黄页网站大全一区二区| 欧美日本国产视频| 日本中文一区二区三区| 97精品久久久久中文字幕| 精品少妇一区二区三区在线播放| 亚洲福利视频一区二区| 99久久精品国产麻豆演员表| 久久久亚洲综合| 蜜乳av一区二区| 777欧美精品| 天堂蜜桃91精品| 欧美揉bbbbb揉bbbbb| 亚洲精品v日韩精品| 成人精品高清在线| 日本一区二区视频在线观看| 国产综合色在线| 日韩午夜在线影院| 日日夜夜精品视频天天综合网| 欧美综合一区二区| 自拍偷拍欧美激情| 9久草视频在线视频精品| 国产精品私人影院| 国产一区二区0| 精品精品国产高清a毛片牛牛| 男男视频亚洲欧美| 91精品国产色综合久久| 五月天激情小说综合| 欧美日韩二区三区| 偷拍亚洲欧洲综合| 欧美一区二区在线免费播放| 男女男精品视频| 精品国产成人系列| 国产一本一道久久香蕉| 久久影院视频免费| 国产精品一区二区视频| 国产日韩欧美精品在线| 懂色av一区二区三区免费看| 欧美激情一区二区三区全黄| gogogo免费视频观看亚洲一| 亚洲视频在线一区二区| 欧美日韩在线三区| 日韩成人一区二区| 精品国产a毛片| 成人免费黄色大片| 亚洲精品免费在线观看| 国产人成亚洲第一网站在线播放| 风间由美中文字幕在线看视频国产欧美| 国产欧美日韩中文久久| a在线欧美一区| 日韩精品三区四区| 久久美女艺术照精彩视频福利播放| 国产91丝袜在线18| 亚洲另类在线制服丝袜| 在线观看91av| 国产福利一区二区| 夜夜亚洲天天久久| 日韩视频免费直播| 国产.欧美.日韩| 亚洲精品国产视频| 日韩欧美你懂的| jlzzjlzz国产精品久久| 亚洲图片自拍偷拍| 欧美精品一区二区三区高清aⅴ|