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

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

?? stats.cpp

?? 一種無損圖象壓縮算法,可用于珍貴圖象的保存.
?? CPP
字號:
/******************************************************************************
File: 		stats.c

Authors: 	John Carpinelli   (johnfc@ecr.mu.oz.au)
	 	Wayne Salamonsen  (wbs@mundil.cs.mu.oz.au)

Purpose:	Data compression using a word-based model and revised 
		arithmetic coding method.

Based on: 	P.M. Fenwick, "A new data structure for cumulative probability
		tables", Software- Practice and Experience, 24:327-336,
		March 1994.

		A. Moffat, R. Neal, I.H. Witten, "Arithmetic Coding Revisited",
		Proc. IEEE Data Compression Conference, Snowbird, Utah, 
		March 1995.


Copyright 1995 John Carpinelli and Wayne Salamonsen, All Rights Reserved.

These programs are supplied free of charge for research purposes only,
and may not sold or incorporated into any commercial product.  There is
ABSOLUTELY NO WARRANTY of any sort, nor any undertaking that they are
fit for ANY PURPOSE WHATSOEVER.  Use them at your own risk.  If you do
happen to find a bug, or have modifications to suggest, please report
the same to Alistair Moffat, alistair@cs.mu.oz.au.  The copyright
notice above and this statement of conditions must remain an integral
part of each and every copy made of these files.

******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "stats.h"
#include "coder.h"


/* variables local to stats module */
int f_bits = DEFAULT_F;				/* bits in frequency counts */
unsigned int max_frequency = 1 << DEFAULT_F;	/* max. total frequency */


/*
 *
 * create a new frequency table using a binary index tree
 * table may be STATIC or DYNAMIC depending on the type parameter
 * DYNAMIC tables may grow above their intial length as new symbols
 * are installed
 *
 */
context 
*create_context(int length, int type)
{
    context	*pContext;
    int		i;
    int		size = 1;

    /*
     * increment length to accommodate the fact 
     * that symbol 0 is stored at pos 1 in the array.
     */
    length++;

    /* round length up to next power of two */
    while (size < length)
	size = size << 1;

    /* malloc context structure and array for frequencies */
    if (((pContext = (context *) malloc(sizeof(context))) == NULL) ||
	((pContext->tree = (unsigned long *) malloc((size+1)*sizeof(long)))
	 == NULL))
    {
	fprintf(stderr, "stats: not enough memory to create context\n");
	exit(1);
    }
    pContext->initial_size = size;	/* save for purging later */
    pContext->length = 0;		/* current no. of symbols */
    pContext->total = 0;		/* total frequency */
    pContext->nSymbols = 0;		/* count of symbols set to zero */
    pContext->type = type;		/* is context DYNAMIC or STATIC */
    pContext->max_length = size;	/* no. symbols before growing */
    
    /* initialise contents of tree array to zero */
    for (i = 0; i < size; i++)
	pContext->tree[i] = 0;

    pContext->incr = 1 << f_bits;	/* increment is initially 2 ^ f */
    if (type  == DYNAMIC)
	pContext->nSingletons = pContext->incr;
    else
	pContext->nSingletons = 0;
    return pContext;	    		/* return a pointer to the context */
}


/*
 *
 * install a new symbol in a context's frequency table
 * returns 0 if successful, TOO_MANY_SYMBOLS or NO_MEMORY if install fails
 *
 */
int 
install_symbol(context *pContext, int symbol)
{
    int i;

    symbol++;	/* increment because first symbol at position one */
    /* 
     * if new symbol is greater than current array length then double length 
     * of array 
     */	
    while (symbol >= pContext->max_length) 
    {
	pContext->tree = (unsigned long *) 
	    realloc(pContext->tree, 
		    pContext->max_length * GROWTH_RATE * sizeof(long));
	if (pContext->tree == NULL)
	{
	    fprintf(stderr, "stats: not enough memory to expand context\n");
	    return NO_MEMORY;
	}

	/* clear new part of table to zero */
	for (i=pContext->max_length; i<GROWTH_RATE*pContext->max_length; i++)
	    pContext->tree[i] = 0;
	
	/* 
	 * initialize new part by setting first element of top half
	 * to total of bottom half
	 * this method depends on table length being a power of two 
	 */
	pContext->tree[pContext->max_length] = pContext->total;
	pContext->max_length *= GROWTH_RATE;
    }

    /* check that we are not installing too many symbols */
    if (((pContext->nSymbols + 1) << 1) >= max_frequency)
	/* 
	 * cannot install another symbol as all frequencies will 
	 * halve to one and an infinite loop will result
	 */
	return TOO_MANY_SYMBOLS;	       
	
    if (symbol > pContext->length)	/* update length if necessary */
	pContext->length = symbol;
    pContext->nSymbols++;		/* increment count of symbols */
    i = symbol;	    			/* update elements in tree below */
    do {
	pContext->tree[i] += pContext->incr;
	i = FORW(i);
    } while (i < pContext->max_length);


    /* update the number of singletons if an context is DYNAMIC */
    if (pContext->type == DYNAMIC)
	pContext->nSingletons += pContext->incr;

    pContext->total += pContext->incr;			/* update total */
    /* halve frequency counts if total greater than max_frequency */
    while (pContext->total+pContext->nSingletons > max_frequency)
	halve_context(pContext);

    return 0;
}



/*
 *
 * encode a symbol given its context
 * the lower and upper bounds are determined using the frequency table,
 * and then passed on to the coder
 * if the symbol has zero frequency, code an escape symbol and
 * return NOT_KNOWN otherwise returns 0
 *
 */
int 
encode(context *pContext, int symbol)
{
    int low, high;

    symbol++;
    if ((symbol > 0) && (symbol < pContext->max_length))
	get_interval(pContext, &low, &high, symbol);
    else
	low = high;
	
    if (low == high)
    {
	if (pContext->nSingletons == 0) 
	{
	    fprintf(stderr,
		"stats: cannot code zero-probability novel symbol");
	    exit(1);
	}
	/* encode the escape symbol if unknown symbol */
	arithmetic_encode(pContext->total, pContext->total+
			  pContext->nSingletons,
			  pContext->total+pContext->nSingletons);
	return NOT_KNOWN;
    }

    /* call the coder with the low, high and total for this symbol */
    arithmetic_encode(low, high, pContext->total+pContext->nSingletons);

    /* update the singleton count if symbol was previously a singleton */
    if (pContext->type == DYNAMIC)
	if ((unsigned int)(high-low) == pContext->incr)
	    pContext->nSingletons -= pContext->incr;

    /* increment the symbol's frequency count */
    while (symbol<pContext->max_length)
    {
	pContext->tree[symbol] += pContext->incr;
	symbol = FORW(symbol);
    }
    pContext->total += pContext->incr;

    while (pContext->total+pContext->nSingletons > max_frequency)
	halve_context(pContext);

    return 0;
}




/*
 *
 * decode function is passed a context, and returns a symbol
 *
 */
int 
decode(context *pContext)
{
    int	mid, symbol, i, target;
    int low, high;
    
    target = arithmetic_decode_target(pContext->total+pContext->nSingletons);

    /* check if the escape symbol has been received */
    if ((unsigned int)target >= pContext->total)
    {
	arithmetic_decode(pContext->total, 
			  pContext->total+pContext->nSingletons,
			  pContext->total+pContext->nSingletons);
	return NOT_KNOWN;
    }

    symbol = 0;
    mid = pContext->max_length / 2;		/* midpoint is half length */
    /* determine symbol from target value */
    while (mid > 0)
    {
	if (pContext->tree[symbol+mid] <= (unsigned int)target)
	{
	    symbol = symbol+mid;
	    target = target-pContext->tree[symbol];
	}
	mid /= 2;
    }
    
    /* 
     * pass in symbol and symbol+1 instead of symbol-1 and symbol to
     * account for array starting at 1 not 0 
     */
    i = symbol+1;
    get_interval(pContext, &low, &high, i);

    arithmetic_decode(low, high, pContext->total+pContext->nSingletons);

    /* update the singleton count if symbol was previously a singleton */
    if (pContext->type == DYNAMIC)
	if ((unsigned int)(high-low) == pContext->incr)
	    pContext->nSingletons -= pContext->incr;

    /* increment the symbol's frequency count */
    pContext->tree[i] += pContext->incr;
    i = FORW(i);
    while (i<pContext->max_length)
    {
	pContext->tree[i] += pContext->incr;
	i = FORW(i);
    }
    pContext->total += pContext->incr; 

    /* halve all frequencies if necessary */
    while (pContext->total+pContext->nSingletons > max_frequency)
	halve_context(pContext);

    return symbol;
}



/*
 *
 * get the low and high limits of the frequency interval
 * occupied by a symbol.
 * this function is faster than calculating the upper bound of the two 
 * symbols individually as it exploits the shared parents of s and s-1.
 *
 */
void 
get_interval(context *pContext, int *pLow, int *pHigh, int symbol)
{
    int low, high, shared, parent;

    /* calculate first part of high path */
    high = pContext->tree[symbol];
    parent = BACK(symbol);
    
    /* calculate first part of low path */
    symbol--;
    low = 0;
    while (symbol != parent)
    {
	low += pContext->tree[symbol];
	symbol = BACK(symbol);
    }

    /* sum the shared part of the path back to root */
    shared = 0;
    while (symbol > 0)
    {
	shared += pContext->tree[symbol];
	symbol = BACK(symbol);
    }
    *pLow = shared+low;
    *pHigh = shared+high;
}
 

/*
 *
 * halve_context is responsible for halving all the frequency counts in a 
 * context.
 * halves context in linear time by keeping track of the old and new 
 * values of certain parts of the array
 * also recalculates the number of singletons in the new halved context.
 *
 */

void
halve_context(context *pContext)
{
    int	old_values[MAX_F_BITS], new_values[MAX_F_BITS];
    int	i, zero_count, temp, sum_old, sum_new;

    pContext->incr = (pContext->incr + MIN_INCR) >> 1;	/* halve increment */
    pContext->nSingletons = pContext->incr;
    for (i = 1; i < pContext->max_length; i++)
    {
	temp = i;

	/* work out position to store element in old and new values arrays */
	for (zero_count = 0; !(temp&1); temp >>= 1)
	    zero_count++;

	/* move through context halving as you go */
	old_values[zero_count] = pContext->tree[i];
	for (temp = zero_count-1, sum_old = 0, sum_new = 0; temp >=0; temp--)
	{
	    sum_old += old_values[temp];
	    sum_new += new_values[temp];
	}
	pContext->tree[i] -= sum_old;
	pContext->total -= (pContext->tree[i]>>1);
	pContext->tree[i] -= (pContext->tree[i]>>1);
	if (pContext->tree[i] == pContext->incr)
	    pContext->nSingletons += pContext->incr;
	pContext->tree[i] += sum_new;
	      
	new_values[zero_count] = pContext->tree[i];
    }

    if (pContext->type == STATIC)
	pContext->nSingletons = 0;
}


/*
 *
 * free memory allocated for a context and initialize empty context
 * of original size
 *
 */
void 
purge_context(context *pContext)
{
    int i;

    free(pContext->tree);
    
    /* malloc new tree of original size */
    if ((pContext->tree = (unsigned long *)malloc((pContext->initial_size + 1)
						  * sizeof(long))) == NULL)
    {
	fprintf(stderr, "stats: not enough memory to create context\n");
	exit(1);
    }
    pContext->length = 0;
    pContext->total = 0;
    pContext->nSymbols = 0;
    pContext->max_length = pContext->initial_size;
    for (i = 0; i < pContext->initial_size; i++)
	pContext->tree[i] = 0;
    
    pContext->incr = 1 << f_bits;   	/* increment is initially 2 ^ f */
    if (pContext->type  == DYNAMIC)
	pContext->nSingletons = pContext->incr;
    else
	pContext->nSingletons = 0;
}

/******************************************************************************
*
* functions for binary contexts
*
******************************************************************************/


/*
 *
 * create a binary_context for binary contexts
 * contexts consists of two counts and an increment which
 * is normalized
 *
 */
binary_context *create_binary_context(void)
{
    binary_context *pContext;

    pContext = (binary_context *) malloc(sizeof(binary_context));
    if (pContext == NULL)
    {
	fprintf(stderr, "stats: not enough memory to create context\n");
	exit(1);
    }
    
    pContext->incr = 1 << (f_bits - 1);		/* start with incr=2^(f-1) */
    pContext->c0 = pContext->incr;
    pContext->c1 = pContext->incr;
    return pContext;
}



/*
 *
 * encode a binary symbol using special binary arithmetic
 * coding functions
 * returns 0 if successful
 *
 */
int
binary_encode(binary_context *pContext, int bit)
{
    binary_arithmetic_encode(pContext->c0, pContext->c1, bit);

    /* increment symbol count */
    if (bit == 0)
	pContext->c0 += pContext->incr;
    else
	pContext->c1 += pContext->incr;

    /* halve frequencies if necessary */
    if (pContext->c0 + pContext->c1 >= max_frequency)
    {
	pContext->c0 = (pContext->c0 + 1) >> 1;
	pContext->c1 = (pContext->c1 + 1) >> 1;
	pContext->incr = (pContext->incr + MIN_INCR) >> 1;
    }
    return 0;
}	



/*
 *
 * decode a binary symbol using specialised binary arithmetic
 * coding functions
 *
 */
int
binary_decode(binary_context *pContext)
{
    int bit;

    bit = binary_arithmetic_decode(pContext->c0, pContext->c1);

    /* increment symbol count */
    if (bit == 0)
	pContext->c0 += pContext->incr;
    else
	pContext->c1 += pContext->incr;

    /* halve frequencies if necessary */
    if (pContext->c0 + pContext->c1 >= max_frequency)
    {
	pContext->c0 = (pContext->c0 + 1) >> 1;
	pContext->c1 = (pContext->c1 + 1) >> 1;
	pContext->incr = (pContext->incr + MIN_INCR) >> 1;
    }    
    return bit;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲综合色视频| 欧美亚洲动漫另类| 欧美性xxxxxx少妇| 日韩一区二区三区电影在线观看| 国产欧美在线观看一区| 亚洲一二三区视频在线观看| 国产黑丝在线一区二区三区| 欧美日韩在线不卡| 国产精品久久久久影院色老大 | 欧美日韩一区高清| 国产午夜精品一区二区三区嫩草 | 91麻豆国产福利精品| 欧美成人aa大片| 香蕉乱码成人久久天堂爱免费| 成人精品一区二区三区四区| 日韩免费观看2025年上映的电影| 亚洲精品免费在线| 成人激情电影免费在线观看| 久久亚洲精品国产精品紫薇| 日韩不卡手机在线v区| 欧美日韩一区二区三区四区| 亚洲欧美日韩久久精品| 风间由美一区二区三区在线观看 | 日韩不卡一区二区三区 | 成人久久视频在线观看| 337p粉嫩大胆噜噜噜噜噜91av| 日韩精品亚洲专区| 91精品国产欧美一区二区18| 亚洲综合久久久| 欧美性猛片xxxx免费看久爱| 亚洲乱码一区二区三区在线观看| 高清beeg欧美| 日本一区二区动态图| 国产精品亚洲专一区二区三区| 精品久久国产老人久久综合| 久久精品国内一区二区三区| 精品国产不卡一区二区三区| 经典三级一区二区| 国产欧美一区二区三区网站| 国产高清视频一区| 中文字幕在线一区二区三区| 91论坛在线播放| 亚洲一区二区三区在线看| 欧美三级韩国三级日本一级| 午夜精品福利在线| 欧美一区二区三区啪啪| 久久国产三级精品| 久久精品一区蜜桃臀影院| 丁香一区二区三区| 亚洲乱码中文字幕| 8x8x8国产精品| 国产综合色在线| 最新高清无码专区| 欧美日韩三级视频| 久久成人免费日本黄色| 久久综合九色综合97婷婷| 国产成人自拍在线| 亚洲免费av网站| 51久久夜色精品国产麻豆| 激情综合色播激情啊| 国产精品视频看| 欧美亚洲综合色| 久久成人久久鬼色| 亚洲色欲色欲www| 欧美三区在线视频| 国产精品99久久不卡二区| 亚洲蜜臀av乱码久久精品蜜桃| 911精品国产一区二区在线| 国产盗摄女厕一区二区三区| 日韩毛片一二三区| 欧美变态tickling挠脚心| caoporm超碰国产精品| 日韩不卡免费视频| 成人欧美一区二区三区视频网页| 欧美吻胸吃奶大尺度电影 | 国产精品乱人伦中文| 91丨九色丨国产丨porny| 日韩中文字幕区一区有砖一区 | 国产91精品欧美| 亚洲国产成人av| 久久久久久久久97黄色工厂| 色乱码一区二区三区88| 经典三级视频一区| 亚洲一级二级三级| 国产精品久久久久久久午夜片| 欧美日韩国产一二三| 丰满少妇在线播放bd日韩电影| 五月婷婷综合在线| 亚洲三级在线免费| 久久嫩草精品久久久精品| 在线播放91灌醉迷j高跟美女 | 免费在线欧美视频| 亚洲精品国产品国语在线app| 精品国产一区二区三区久久影院 | 亚洲综合在线视频| 国产欧美日韩卡一| 日韩视频一区在线观看| 欧美亚洲愉拍一区二区| 暴力调教一区二区三区| 精品一区二区影视| 性感美女久久精品| 一区二区三区日韩欧美精品| 国产色综合久久| 日韩欧美不卡在线观看视频| 91久久一区二区| 99精品久久久久久| 高清beeg欧美| 国产精品91一区二区| 韩国女主播一区| 久久国产剧场电影| 久久se这里有精品| 麻豆精品久久精品色综合| 亚洲电影第三页| 亚洲动漫第一页| 亚洲午夜视频在线观看| 一区二区三区波多野结衣在线观看| 欧美精彩视频一区二区三区| 2020国产精品自拍| 久久这里只有精品视频网| 精品美女一区二区三区| 日韩一级免费一区| 日韩欧美第一区| 肉色丝袜一区二区| 亚洲福中文字幕伊人影院| 亚洲无人区一区| 天天色综合天天| 日本伊人色综合网| 欧美aaaaaa午夜精品| 久久草av在线| 国产麻豆91精品| 成av人片一区二区| 99精品国产99久久久久久白柏 | 国产精品视频麻豆| 亚洲男人的天堂在线观看| 亚洲成av人**亚洲成av**| 午夜精品福利一区二区蜜股av| 日韩电影在线免费观看| 久久精品av麻豆的观看方式| 久久成人免费日本黄色| 成人一级片网址| 97se亚洲国产综合自在线| 日本大香伊一区二区三区| 欧美美女网站色| 精品国产第一区二区三区观看体验| 久久丝袜美腿综合| 亚洲三级视频在线观看| 日韩成人一区二区| 国产真实乱子伦精品视频| 99精品视频一区二区| 这里只有精品99re| 国产亚洲欧美日韩在线一区| 亚洲美女在线一区| 加勒比av一区二区| 欧美性三三影院| 久久精品一区二区三区不卡牛牛| 国产精品久久久一本精品 | 成人欧美一区二区三区白人| 亚洲精选视频免费看| 麻豆国产精品777777在线| 成人永久aaa| 欧美成人猛片aaaaaaa| 《视频一区视频二区| 日本sm残虐另类| 91亚洲永久精品| 欧美videossexotv100| 亚洲伊人伊色伊影伊综合网| 极品销魂美女一区二区三区| 91色porny| 国产女人aaa级久久久级| 亚洲综合免费观看高清完整版在线| 麻豆免费看一区二区三区| 91极品美女在线| 中文字幕 久热精品 视频在线| 日韩成人伦理电影在线观看| 日本道精品一区二区三区| 亚洲国产高清在线| 美女精品一区二区| 欧美日韩精品久久久| 中文字幕字幕中文在线中不卡视频| 奇米影视一区二区三区| 欧美中文字幕一区二区三区亚洲| 久久婷婷国产综合精品青草| 日韩国产一二三区| 91久久奴性调教| 亚洲天堂av老司机| 白白色 亚洲乱淫| 久久夜色精品国产欧美乱极品| 日本欧美一区二区三区乱码| 色婷婷一区二区| 亚洲人妖av一区二区| 成人精品一区二区三区四区| 国产日韩综合av| 韩国毛片一区二区三区| 日韩视频在线观看一区二区| 日韩制服丝袜先锋影音| 精品视频一区三区九区| 亚洲精品高清在线| 91成人在线精品| 亚洲一区在线观看视频| 欧美午夜一区二区三区|