⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lossy_d.c

📁 实现图像的jpeg无损压缩
💻 C
📖 第 1 页 / 共 2 页
字号:
		Ra = ENDIAN16(sl[0]);		i = 1;		do {			pixel Px;			Rd = ENDIAN16(psl[i + 1]);			/* Quantize the gradient */			{				register int diff;				/* Following segment assumes that T3 <= LUTMAX16 */				/* This condition should have been checked when the				   lookup tables were built */				diff = Rd - Rb;				if (diff < 0)					cont = (diff > -LUTMAX16) ? vLUT[0][diff + LUTMAX16] : 7*CREGIONS*CREGIONS;				else 					cont = (diff < LUTMAX16) ? vLUT[0][diff + LUTMAX16] : 8*CREGIONS*CREGIONS;				diff = Rb - Rc;				if (diff < 0)					cont += (diff > -LUTMAX16) ? vLUT[1][diff + LUTMAX16] : 7*CREGIONS;				else 					cont += (diff < LUTMAX16) ? vLUT[1][diff + LUTMAX16] : 8*CREGIONS;				diff = Rc - Ra;				if (diff < 0)					cont += (diff > -LUTMAX16) ? vLUT[2][diff + LUTMAX16] : 7;				else 					cont += (diff < LUTMAX16) ? vLUT[2][diff + LUTMAX16] : 8;			}			if ( cont == 0 ) {		    /********* RUN STATE *********/				register int n, m;				/* get length of the run */				/* arg is # of pixels left */				m = n = process_run_dec(no-i+1, color); 			    if ( m > 0 )  {  /* run of nonzero length, otherwise									we go directly to the end-of-run 									state */					do {						sl[i++] = ENDIAN16(Ra);					} while(--n > 0);					if (i > no)					    /* end of line */				    return 0;					/* update context pixels */				    Rb = ENDIAN16(psl[i]);				    Rd = ENDIAN16(psl[i + 1]);				}				/* here we handle the "end-of-run" state, which is 					treated separately from regular states */				run_int_type = ( (Rb-Ra) <= NEAR && (Rb-Ra) >= negNEAR);				Ra = lossy_end_of_run_d(Ra, Rb, run_int_type);			}			else {			/******REGULAR CONTEXT ******/				predict(Rb, Ra, Rc);				/* map symmetric contexts */				cont = classmap[cont];				if (cont < 0) 				{					SIGN = -1;					cont = -cont;				}				else					SIGN = +1;				/* decode a Rice code of a given context */			    Ra = lossy_regular_mode_d(cont, SIGN, Px);			}			sl[i] = ENDIAN16(Ra);			Rc = Rb;			Rb = Rd;			++i;		} while (i <= no);	} /* ends "if 8/16 bit" */	return 0;}/* For DECODING pixel interleaved mode in LOSSY mode */int lossy_undoscanline_pixel(	pixel *psl,		/* previous scanline */								pixel *sl,		/* current scanline */								int no)			/* number of values in it *//*** watch it! actual pixels in the scan line are numbered 1 to no .     pixels with indices < 1 or > no are dummy "border" pixels  */{	int i, psfix, n_c, color, enter_run=0, break_run, was_in_run = 0,	    test_run;	pixel Ra, Rb, Rc, Rd;	pixel c_aa[MAX_COMPONENTS],	      c_bb[MAX_COMPONENTS],	      c_cc[MAX_COMPONENTS],	      c_dd[MAX_COMPONENTS],	      c_xx[MAX_COMPONENTS];	int	SIGN;	int cont,c_cont[MAX_COMPONENTS];	psfix = 0;	/**********************************************/	/* Do for all pixels in the row in 8-bit mode */	/**********************************************/	if (bpp16==FALSE)	{		for (n_c=0; n_c<components; n_c++) {			c_cc[n_c] = psl[n_c];			c_bb[n_c] = psl[components+n_c];			c_aa[n_c] = sl[n_c];		}		i = components;		color = -1;		do {			pixel Px;			if (!was_in_run) color = (color+1)%components;			else color = 0;			if (color == 0)			for (n_c=0;n_c<components;n_c++) {				c_dd[n_c] = psl[i + components + n_c];				/* Quantize the gradient */				c_cont[n_c] =	vLUT[0][c_dd[n_c] - c_bb[n_c] + LUTMAX8] +								vLUT[1][c_bb[n_c] - c_cc[n_c] + LUTMAX8] +								vLUT[2][c_cc[n_c] - c_aa[n_c] + LUTMAX8];			}			Ra=c_aa[color];			Rb=c_bb[color];			Rc=c_cc[color];			Rd=c_dd[color];			cont=c_cont[color];			enter_run = was_in_run = test_run = 0;					if (color == 0) {				test_run = 1;				for (n_c=0;n_c<components;n_c++)					if (c_cont[n_c]!=0) {						test_run=0;						break;					}			}			if ( test_run ) {		    /********* RUN STATE *********/				register int n, m;				enter_run = was_in_run = 1;				/* get length of the run */				/* arg is # of pixels left */				m = n = process_run_dec((no+components-1-i+1)/components, 0); 				if ( m > 0 )  {  /* run of nonzero length, otherwise									we go directly to the end-of-run 									state */					do {						for (n_c=0;n_c<components;n_c++) {							sl[i++] = c_aa[n_c];						}					} while(--n > 0);					if (i > no+components-1)						/* end of line */						return 0;					/* update context pixels */					for (n_c=0;n_c<components;n_c++) {			    		c_bb[n_c] = psl[i+n_c];			    		c_dd[n_c] = psl[i+components+n_c];					}				}				/* here we handle the "end-of-run" state */				for (n_c=0;n_c<components;n_c++) {					/* The end of run is processed for each component */					Ra = c_aa[n_c];					Rb = c_bb[n_c];					c_aa[n_c] = c_xx[n_c] = lossy_end_of_run_d(Ra, Rb, 0);				}       /* Components loop */			} 			else {			/****** REGULAR CONTEXT *******/				predict(Rb, Ra, Rc);				cont = classmap[cont];				if (cont < 0) 				{					SIGN = -1;					cont = -cont;				}				else					SIGN = +1;				/* decode a Rice code of a given context */			    c_aa[color] = Ra = lossy_regular_mode_d(cont, SIGN, Px);			}			if (!was_in_run) {				sl[i] = Ra;				c_cc[color] = Rb;				c_bb[color] = Rd;				i++;			}			else {				for (n_c=0;n_c<components;n_c++) {					sl[i+n_c] = c_aa[n_c];					c_cc[n_c] = c_bb[n_c];					c_bb[n_c] = c_dd[n_c];				}				i+=components;			}			} while (i <= (no+components-1));	} else	/***********************************************/	/* Do for all pixels in the row in 16-bit mode */	/***********************************************/	{		for (n_c=0; n_c<components; n_c++) {			c_cc[n_c] = ENDIAN16(psl[n_c]);			c_bb[n_c] = ENDIAN16(psl[components+n_c]);			c_aa[n_c] = ENDIAN16(sl[n_c]);		}		i = components;		color = -1;		do {			pixel Px;			if (!was_in_run) color = (color+1)%components;			else color = 0;			if (color == 0)				for (n_c=0;n_c<components;n_c++) {					c_dd[n_c] = ENDIAN16(psl[i + components + n_c]);					/* Quantize the gradient */					{						register int diff;						/* Following segment assumes that T3 <= LUTMAX16 */						/* This condition should have been checked when the							lookup tables were built */						diff = c_dd[n_c] - c_bb[n_c];						if (diff < 0)							c_cont[n_c] = (diff > -LUTMAX16) ? vLUT[0][diff + LUTMAX16] : 7*CREGIONS*CREGIONS;						else 							c_cont[n_c] = (diff < LUTMAX16) ? vLUT[0][diff + LUTMAX16] : 8*CREGIONS*CREGIONS;						diff = c_bb[n_c] - c_cc[n_c];						if (diff < 0)							c_cont[n_c] += (diff > -LUTMAX16) ? vLUT[1][diff + LUTMAX16] : 7*CREGIONS;						else 							c_cont[n_c] += (diff < LUTMAX16) ? vLUT[1][diff + LUTMAX16] : 8*CREGIONS;						diff = c_cc[n_c] - c_aa[n_c];						if (diff < 0)							c_cont[n_c] += (diff > -LUTMAX16) ? vLUT[2][diff + LUTMAX16] : 7;						else 							c_cont[n_c] += (diff < LUTMAX16) ? vLUT[2][diff + LUTMAX16] : 8;					}				}			Ra=c_aa[color];			Rb=c_bb[color];			Rc=c_cc[color];			Rd=c_dd[color];			cont=c_cont[color];			enter_run = was_in_run = test_run = 0;					if (color == 0) {				test_run = 1;				for (n_c=0;n_c<components;n_c++)					if (c_cont[n_c]!=0) {						test_run=0;						break;					}			}			if ( test_run ) {		    /********* RUN STATE *********/				register int n, m;				enter_run = was_in_run = 1;				/* get length of the run */				/* arg is # of pixels left */				m = n = process_run_dec((no+components-1-i+1)/components, 0); 				if ( m > 0 )  {  /* run of nonzero length, otherwise									we go directly to the end-of-run 									state */					do {						for (n_c=0;n_c<components;n_c++) {							sl[i++] = ENDIAN16(c_aa[n_c]);						}					} while(--n > 0);					if (i > no+components-1)						/* end of line */						return 0;					/* update context pixels */					for (n_c=0;n_c<components;n_c++) {			    		c_bb[n_c] = ENDIAN16(psl[i+n_c]);			    		c_dd[n_c] = ENDIAN16(psl[i+components+n_c]);					}				}				/* here we handle the "end-of-run" state */			    for (n_c=0;n_c<components;n_c++) {				    /* The end of run is processed for each component */					Ra = c_aa[n_c];					Rb = c_bb[n_c];					c_aa[n_c] = c_xx[n_c] = lossy_end_of_run_d(Ra, Rb, 0);				}       /* Components loop */			}			else {			/******* REGULAR CONTEXT *******/			    predict(Rb, Ra, Rc);								cont = classmap[cont];				if (cont < 0) 				{					SIGN = -1;					cont = -cont;				}				else					SIGN = +1;				/* decode a Rice code of a given context */			    c_aa[color] = Ra = lossy_regular_mode_d(cont, SIGN, Px);			}			if (!was_in_run) {				sl[i] = ENDIAN16(Ra);				c_cc[color] = Rb;				c_bb[color] = Rd;				i++;			}			else {				for (n_c=0;n_c<components;n_c++) {					sl[i+n_c] = ENDIAN16(c_aa[n_c]);					c_cc[n_c] = c_bb[n_c];					c_bb[n_c] = c_dd[n_c];				}				i+=components;			}		} while (i <= (no+components-1));	} /* for "if 8/16 bit" mode */	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -