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

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

?? decode.cpp

?? 一種無損圖象壓縮算法,可用于珍貴圖象的保存.
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
//Header Files
#include "const.h"
extern void init_bdecoder  ();
extern void init_sdecoder  ();
extern void init_mydecoder ();
extern void stop_mydecoder (); 
extern int bdecode_symbol (int);
extern int decode_symbol (int);
//Constant Definitions
//Options included in the encoder
#define OPTION_NEARLY_LOSSLESS
//Misc. constants
#define N_SEQ     NUM_CONTEXT     /* Number of coding histograms        */
#define N_BSEQ    NUM_BCONTEXT    /* Number of binary coding histograms */
#define UPPER     255             /* Largest possible pixel value       */
#define ERR_SPAN  (UPPER + 1)
//Macro Definitions
#define ABS(X)      (((X) < 0)   ? -(X) : (X))
#define MIN(X,Y)    (((X) < (Y)) ?  (X) : (Y))
#define MAX(X,Y)    (((X) < (Y)) ?  (Y) : (X))
//NEARLY LOSSLESS COMPRESSION
#ifdef OPTION_NEARLY_LOSSLESS
//Variable Definitions
int tolerance = 7;
int mask      = 15;
int QT[8];
int QS[8];
FILE *infile;
FILE *outfile;
#endif
//NEARLY LOSSLESS COMPRESSION

//Misc. operations
//Function : nh
//static int T0 =   5 + 1;
//static int T1 =  15 + 0;
//static int T2 =  25 + 6;
//static int T3 =  42 + 4;
//static int T4 =  60 + 6;
//static int T5 =  85 + 6;
//static int T6 = 140 + 10;
static int T0 =   5 - 1;
static int T1 =  15 - 5;
static int T2 =  25 - 4;
static int T3 =  42;
static int T4 =  60;
static int T5 =  85;
static int T6 = 140;
int nh (int k)
{
	if (k <= T0)      return (0);
	else if (k <= T1) return (1);
	else if (k <= T2) return (2);
	else if (k <= T3) return (3);
	else if (k <= T4) return (4);
	else if (k <= T5) return (5);
	else if (k <= T6) return (6);
	else return (7);
}
//Function : nreremap
int nreremap (int err, int p, int flip)
{
	if (err == 0) return (0);
	//NEARLY LOSSLESS COMPRESSION
	#ifdef OPTION_NEARLY_LOSSLESS
	{
		if (p <= (UPPER/2))
		{
			if (err <= 2*((p + tolerance)/mask))
			{
				if ((err % 2) == 0) err = -err/2;
				else                err = (err + 1)/2;
			}
			else
			{
				if (flip) err = -(err - (p + tolerance)/mask);
				else      err = err - (p + tolerance)/mask;
			}
		}
		else
		{
			if (err <= 2*((UPPER - p + tolerance)/mask))
			{
				if ((err % 2) == 0) err = -err/2;
				else                err = (err + 1)/2; 
			}
			else
			{
				if (flip) err = err - (UPPER - p + tolerance)/mask;
				else      err = -(err - (UPPER - p + tolerance)/mask);
			}
		}
		err = err*mask;
	}
	#else
		if (p <= (UPPER/2))
		{
			if (err <= 2*p)
			{
				if ((err % 2) == 0) err = -err/2;
				else                err = (err + 1)/2;
			}
			else
			{
				if (flip) err = -(err - p);
				else      err = err - p;
			}
		}
		else
		{
			if (err <= 2*(UPPER - p))
			{
				if ((err % 2) == 0) err = -err/2;
				else                err = (err + 1)/2; 
			}
			else
			{
				if (flip) err = err - (UPPER - p);
				else      err = -(err - (UPPER - p));
			}
		}
	#endif
	//NEARLY LOSSLESS COMPRESSION 
    return (err);
}

//Operations for saving images
//Function : create_buffer
void create_buffer (unsigned char **u0, unsigned char **u1, unsigned char **u2, int width)
{
	//Allocate space for the first line of the image.
	if ((*u2 = (unsigned char *) calloc (width + 2, sizeof (unsigned char))) == NULL)
	{
		fprintf (stderr, "ERROR : not enough space for buffer!\n");
		exit    (1);
	}
	//Allocate space for the second line of the image.
	if ((*u1 = (unsigned char *) calloc (width + 2, sizeof (unsigned char))) == NULL)
	{
		fprintf (stderr, "ERROR : not enough space for buffer!\n");
		exit    (1);
	}
	//Allocate space for the third line of the image.
	if ((*u0 = (unsigned char *) calloc (width + 2, sizeof (unsigned char))) == NULL)
	{
		fprintf (stderr, "ERROR : not enough space for buffer!\n");
		exit    (1);
	}
}

//Function : update_buffer
void update_buffer (unsigned char **u0, unsigned char **u1, unsigned char **u2, int width)
{
	unsigned char *temp;
	temp = *u2;
	*u2  = *u1;
	*u1  = *u0;
	*u0  = temp;
	//Save a line to the image.
	if ((fwrite (*u0 + 1, sizeof (unsigned char), width, outfile)) !=(unsigned int)width)
	{
		fprintf (stderr, "ERROR : in writing image!\n");
		exit    (1);
	}
}

//Function : flush_buffer
void flush_buffer (unsigned char *u0, unsigned char *u1, unsigned char *u2, int width)
{
	//Save the last three lines to the image.
	if ((fwrite (u2 + 1, sizeof (unsigned char), width, outfile)) !=(unsigned int)width)
	{
		fprintf (stderr, "ERROR : in writing image!\n");
		exit    (1);
	}
	if ((fwrite (u1 + 1, sizeof (unsigned char), width, outfile)) !=(unsigned int)width)
	{
		fprintf (stderr, "ERROR : in writing image!\n");
		exit    (1);
	}
	if ((fwrite (u0 + 1, sizeof (unsigned char), width, outfile)) !=(unsigned int)width)
	{
		fprintf (stderr, "ERROR : in writing image!\n");
		exit    (1);
	}
}

//Function : destory_buffer
void destory_buffer (unsigned char **u0, unsigned char **u1, unsigned char **u2)
{
	//Free all the buffer space.
	free (*u0);  *u0 = NULL;
	free (*u1);  *u1 = NULL;
	free (*u2);  *u2 = NULL;
}

//Function : decode_buffer
void decode_buffer (unsigned char *u0, unsigned char *u1, unsigned char *u2, int width, int height)
{
	register unsigned short ptn, ptn0, ptn1, ptn2;
	int *N1, *N2; 
	int *S1, *S2;
	int *Dh, *Dv;
	int *Pr;
	int *E0, err, aerr, berr;
	int H[N_SEQ][ERR_SPAN], BH[N_BSEQ][3];
	register int dh, dv, max, min, adjust, temp;
	register int symb1, symb2, bflag;
	register int nnww, nnw, nn, nne, nww, nw, n, ne, nee, www, ww, w, curr;
	register int x, j, k;
	
	//Allocate space ("Gradient")
	if ((Dh = (int *) calloc (width + 2, sizeof (int))) == NULL)
	{
		fprintf (stderr, "ERROR : no enough space for Dh\n");
		exit    (1);
	}
	if ((Dv = (int *) calloc (width + 2, sizeof (int))) == NULL)
	{
		fprintf (stderr, "ERROR : no enough space for Dv\n");
		exit    (1);
	}
	memset (Dh, 0, (width + 2)*sizeof (int));
	memset (Dv, 0, (width + 2)*sizeof (int));
	
	//Allocate space ("Prediction Error")
	if ((E0 = (int *) calloc (width + 2, sizeof (int))) == NULL)
	{
		fprintf (stderr, "ERROR : no enough space for E0\n");
		exit    (1);
	}
	aerr = err = 0;
	memset (E0, 0, (width + 2)*sizeof (int));
	//lw
	if ((Pr = (int *) calloc (width + 2, sizeof (int))) == NULL)
	{
		fprintf (stderr, "ERROR : no enough space for E0\n");
		exit    (1);
	}
	memset (Pr, 0, (width + 2)*sizeof (int));

	//Allocate space ("Context Modeling")
	if ((N1 = (int *) calloc (4096, sizeof (int))) == NULL)
	{
		fprintf (stderr, "ERROR : no enough space for N1\n");
		exit    (1);
	}
	if ((S1 = (int *) calloc (4096, sizeof (int))) == NULL)
	{
		fprintf (stderr, "ERROR : no enough space for S1\n");
		exit    (1);
	}
	if ((N2 = (int *) calloc (4096, sizeof (int))) == NULL)
	{
		fprintf (stderr, "ERROR : no enough space for N2\n");
		exit    (1);
	}
	if ((S2 = (int *) calloc (4096, sizeof (int))) == NULL)
	{
		fprintf (stderr, "ERROR : no enough space for S2\n");
		exit    (1);
	}
	
	ptn = ptn0 = ptn1 = ptn2= 0;
	memset (N1, 0, 4096*sizeof (int));
	memset (S1, 0, 4096*sizeof (int));
	memset (N2, 0, 4096*sizeof (int));
	memset (S2, 0, 4096*sizeof (int));
	
	//Initialize variables
	for (k = 0; k < N_SEQ; ++k)
		for (j = 0; j < ERR_SPAN; ++j) H[k][j] = 0;
	for (k = 0; k < N_BSEQ; ++k) 
		for (j = 0; j < 3; ++j) BH[k][j] = 0;
	//First pixel in the first row
	temp = UPPER/4;
	err  = nreremap (decode_symbol (3), temp, 0);
	aerr = ABS (err);
	curr = temp + err;
	//NEARLY LOSSLESS COMPRESSION 
	#ifdef OPTION_NEARLY_LOSSLESS
	{
		if (curr < 0)     curr = 0;
		if (curr > UPPER) curr = UPPER;
	}
	#endif
	//NEARLY LOSSLESS COMPRESSION
	u2[1] = curr;
	u2[0] = u2[1];        /* Duplicate the first pixel */
   
	//Second pixel in the first row
	w    = u2[1];
	temp = w;
	k = nh (aerr << 2);
	err  = nreremap (decode_symbol (k), temp, 0);
	aerr = ABS (err);
	curr = temp + err;
	//NEARLY LOSSLESS COMPRESSION
	#ifdef OPTION_NEARLY_LOSSLESS
	{
		if (curr < 0)     curr = 0;
		if (curr > UPPER) curr = UPPER;
	}
	#endif
	//NEARLY LOSSLESS COMPRESSION
	u2[2] = curr;
	//Rest of the first row
	for (x = 3; x <= width; ++x)
	{
		ww   = u2[x-2];
		w    = u2[x-1];
		temp = w;
		if (temp > UPPER)  temp = UPPER; 
		else if (temp < 0) temp = 0;
		k = nh ((aerr + ABS (ww - w)) << 2);
		err  = nreremap (decode_symbol (k), temp, 0);
		aerr = ABS (err);
		curr = temp + err;
		//NEARLY LOSSLESS COMPRESSION
		#ifdef OPTION_NEARLY_LOSSLESS
		{
			if (curr < 0)     curr = 0;
			if (curr > UPPER) curr = UPPER;
		}
		#endif
		//NEARLY LOSSLESS COMPRESSION
		u2[x] = curr;
	}
	u2[width+1] = u2[width];    /* Duplicate the last  pixel */
	//Second row first pixel
	n    = u2[1];
	temp = n;
	E0[1] = err = nreremap (decode_symbol (2), temp, 0);
	aerr  = ABS (err);
	curr = temp + err;
	//NEARLY LOSSLESS COMPRESSION
	#ifdef OPTION_NEARLY_LOSSLESS
	{
		if (curr < 0)     curr = 0;
		if (curr > UPPER) curr = UPPER;
	}
	#endif
	//NEARLY LOSSLESS COMPRESSION
	u1[1] = curr;
	u1[0] = u1[1];        /* Duplicate the first pixel */

	//Second row second pixel
	nw   = u2[1];
	n    = u2[2];
	ne   = u2[3];
	w    = u1[1];
	temp = (w + n + 1)/2 + (ne - nw)/4;
	if (temp > UPPER)  temp = UPPER; 
	else if (temp < 0) temp = 0;
	k = nh (aerr + ABS (n - nw) + ABS (n - ne) + 2*ABS (w - nw));
	E0[2] = err = nreremap (decode_symbol (k), temp, 0);
	aerr  = ABS (err);
	curr = temp + err;
	//NEARLY LOSSLESS COMPRESSION
	#ifdef OPTION_NEARLY_LOSSLESS
	{
		if (curr < 0)     curr = 0;
		if (curr > UPPER) curr = UPPER;
	}
	#endif
	//NEARLY LOSSLESS COMPRESSION
	u1[2] = curr;
	Dh[2] = ABS (curr - w);
	Dv[2] = ABS (curr - n);
	//2nd row
	for (x = 3; x <= width - 1; ++x)
	{
		nw   = u2[x-1];
		n    = u2[x];
		ne   = u2[x+1];
		ww   = u1[x-2];
		w    = u1[x-1];
		temp = (w + n + 1)/2 + (ne - nw)/4;
		if (temp > UPPER)  temp = UPPER; 
		else if (temp < 0) temp = 0;
		k = nh (aerr + ABS (ww - w) + ABS (n - nw) + ABS (n - ne) + 2*ABS (w - nw));
		E0[x] = err = nreremap (decode_symbol (k), temp, 0);
		aerr  = ABS (err);
		curr = temp + err;
		//NEARLY LOSSLESS COMPRESSION
		#ifdef OPTION_NEARLY_LOSSLESS
		{
			if (curr < 0)     curr = 0;
			if (curr > UPPER) curr = UPPER;
		}
		#endif
		//NEARLY LOSSLESS COMPRESSION
		u1[x] = curr;
		Dh[x] = ABS (curr - w);
		Dv[x] = ABS (curr - n);
	}
	//Second row last pixel
	nw   = u2[width-1];
	n    = u2[width];
	ww   = u1[width-2];
	w    = u1[width-1];
	temp = (w + n + 1)/2;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美三级视频在线| 最新日韩在线视频| 26uuu亚洲综合色欧美| 中文乱码免费一区二区| 亚洲综合丁香婷婷六月香| 麻豆精品久久精品色综合| 国产精品一卡二| 日本中文在线一区| 国产精品亚洲第一区在线暖暖韩国| 97超碰欧美中文字幕| 欧美一区二区私人影院日本| 欧美一级国产精品| 国产精品久久久久一区二区三区共| 香蕉久久一区二区不卡无毒影院| 麻豆高清免费国产一区| 91麻豆.com| 久久亚洲一级片| 亚洲电影在线免费观看| 国产成人精品三级| 88在线观看91蜜桃国自产| 亚洲欧美日韩系列| 日韩不卡一区二区三区| 91亚洲午夜精品久久久久久| 日韩一区二区三区三四区视频在线观看| 欧美国产激情二区三区| 奇米影视一区二区三区小说| 一本大道久久a久久综合| 国产婷婷一区二区| 五月天激情小说综合| 一本大道久久a久久综合| 亚洲国产精品传媒在线观看| 久久99国产精品久久| 欧美日韩一区二区三区高清| 亚洲三级电影网站| 成人免费的视频| 久久综合资源网| 日av在线不卡| 欧美日韩一卡二卡三卡| 亚洲综合色自拍一区| www.性欧美| 国产精品久久久久精k8| 成人妖精视频yjsp地址| 欧美美女网站色| 一区二区三区丝袜| 色噜噜夜夜夜综合网| 亚洲日本护士毛茸茸| 99国产精品视频免费观看| 久久九九全国免费| 国产69精品久久777的优势| 精品国精品自拍自在线| 激情六月婷婷综合| 26uuu亚洲综合色| 韩国午夜理伦三级不卡影院| 日韩免费电影网站| 老司机一区二区| 精品久久人人做人人爱| 国产一区二三区| 久久久久久一二三区| 国产精品正在播放| 久久久影视传媒| 国产 欧美在线| 国产精品三级电影| 91免费国产在线观看| 一区二区三区产品免费精品久久75| 色综合久久九月婷婷色综合| 日本伊人色综合网| 国产精品私人影院| 日韩亚洲欧美成人一区| a4yy欧美一区二区三区| 午夜伦欧美伦电影理论片| 国产亲近乱来精品视频| 欧美在线免费观看视频| 久久99精品久久久久久动态图| 亚洲天堂2014| 久久综合狠狠综合久久激情 | 蜜臀av性久久久久蜜臀av麻豆| 欧美精品一区二区三| 一本一道综合狠狠老| 国内成人免费视频| 亚洲成av人影院在线观看网| 国产欧美日韩综合| 日韩精品在线网站| 欧美日韩视频在线一区二区| 国产成人高清视频| 奇米色777欧美一区二区| 亚洲日本韩国一区| 中文字幕+乱码+中文字幕一区| 3d成人h动漫网站入口| 91欧美一区二区| 国产福利91精品一区二区三区| 日韩中文字幕亚洲一区二区va在线| 国产精品色在线观看| 欧美www视频| 91精品国产欧美日韩| 在线视频国内自拍亚洲视频| www.亚洲国产| 懂色av中文一区二区三区| 美女视频黄免费的久久| 亚洲成va人在线观看| 亚洲男同1069视频| 成人欧美一区二区三区小说| 久久影视一区二区| 精品国产电影一区二区| 日韩欧美你懂的| 91精品国产色综合久久ai换脸| 欧美三级三级三级| 欧美视频第二页| 精品视频全国免费看| 欧美日韩免费在线视频| 欧美亚洲国产bt| 欧美日韩中字一区| 在线免费一区三区| 91久久一区二区| 欧美色成人综合| 欧美精品久久久久久久多人混战| 欧美色网站导航| 欧美福利一区二区| 日韩一级黄色大片| 欧美变态tickling挠脚心| 欧美mv和日韩mv的网站| 日韩欧美成人一区二区| www国产亚洲精品久久麻豆| 欧美一级一区二区| 337p粉嫩大胆色噜噜噜噜亚洲| 久久久国产精华| 国产精品久久三区| 亚洲欧美日韩电影| 日韩国产欧美三级| 国产综合色精品一区二区三区| 丰满少妇久久久久久久| 日本高清视频一区二区| 欧美日韩国产影片| 精品国一区二区三区| 国产精品久久久久永久免费观看| 亚洲日本成人在线观看| 亚洲18女电影在线观看| 韩日欧美一区二区三区| 成人av在线一区二区| 欧美写真视频网站| 欧美成人在线直播| 国产精品福利在线播放| 亚洲一区二区三区四区在线观看| 男女激情视频一区| 国产精品18久久久久久久久 | 日韩免费高清av| 成人免费一区二区三区在线观看| 一区二区三区在线视频免费 | 成人av电影观看| 欧美久久免费观看| 久久九九久精品国产免费直播| 亚洲丝袜美腿综合| 久草热8精品视频在线观看| 成人黄色电影在线| 欧美精品高清视频| 中文字幕欧美国产| 日韩va欧美va亚洲va久久| 成人天堂资源www在线| 91麻豆精品国产| 国产区在线观看成人精品 | 91精品在线观看入口| 国产精品色哟哟| 毛片不卡一区二区| 在线观看av一区二区| 国产日韩欧美精品在线| 青青草精品视频| 色婷婷国产精品| 中文字幕av不卡| 久久99蜜桃精品| 欧美日韩国产123区| 国产精品区一区二区三| 美女视频黄 久久| 欧美午夜理伦三级在线观看| 久久久美女艺术照精彩视频福利播放| 亚洲精品菠萝久久久久久久| 国产精品99久久久久久宅男| 欧美福利视频导航| 亚洲一卡二卡三卡四卡无卡久久 | 国产精品亚洲第一区在线暖暖韩国| 欧美三级日韩在线| 亚洲女同ⅹxx女同tv| 成人精品免费视频| 国产亚洲一区二区三区四区| 免费一级欧美片在线观看| 欧美日韩久久久久久| 亚洲黄网站在线观看| 91麻豆福利精品推荐| 日韩毛片高清在线播放| 成人黄色av电影| 国产精品色在线| 国产69精品久久久久毛片 | 亚洲1区2区3区视频| 在线亚洲免费视频| 一区二区三区日韩在线观看| 91美女在线观看| 亚洲另类春色国产| 日本电影欧美片| 丝袜美腿成人在线| 日韩一区二区三区四区五区六区| 日韩成人av影视| 日韩精品一区二区三区在线|