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

📄 lossy_e.c

📁 实现了JPEG-LS的标准算法
💻 C
📖 第 1 页 / 共 2 页
字号:
				register delta = Ix - Ra;				RUNcnt = 0;				if ( delta <= NEAR && delta >= negNEAR )				{					while ( 1 )					{						++RUNcnt;							sl[i] = ENDIAN16(Ra);							if (++i > no) {								/* Run-lenght coding when reach end of line (A.7.1.2) */							process_run(RUNcnt, EOLINE, color);							return;	 /* end of line */						}							Ix = ENDIAN16(sl[i]);							delta = Ix-Ra;						if ( delta > NEAR || delta < negNEAR )  /*  Run is broken */						{							Rd = ENDIAN16(psl[i + 1]);							Rb = ENDIAN16(psl[i]);							break;  /* out of while loop */						}						/* Run continues */					}				}					/* we only get here if the run is broken by					a non-matching symbol */				/* Run-lenght coding when end of line not reached (A.7.1.2) */				process_run(RUNcnt,NOEOLINE, color);				/* This is the END_OF_RUN state */				RItype = ((Rb-Ra)<=NEAR && (Rb-Ra)>=negNEAR);				Ix = lossy_end_of_run(Ra, Rb, Ix, RItype);			}			else {						/*************** REGULAR CONTEXT *******************/				predict(Rb, Ra, Rc);				/* do symmetric context merging */				cont = classmap[cont];				if (cont<0) {					SIGN=-1;					cont = -cont;				} else					SIGN=+1;				/* output a rice code */				lossy_regular_mode(cont, SIGN, Px, &Ix);			}			/* context for next pixel: */			sl[i] = ENDIAN16(Ix);			Ra = Ix;			Rc = Rb;			Rb = Rd;		} while (++i <= no);	} /* for "if" 16 or 8 bit mode */}/* For pixel interleavde mode for LOSSY encoding */void lossy_doscanline_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,n_c, enter_run=0, break_run, was_in_run=0, test_run;	int color;		/* Index to the component, 0..COMPONENTS-1 */	pixel c_aa[MAX_COMPONENTS],	      c_bb[MAX_COMPONENTS],	      c_cc[MAX_COMPONENTS],	      c_dd[MAX_COMPONENTS],	      c_xx[MAX_COMPONENTS],	      Ra, Rb, Rc, Rd,	/* context pixels */	      Ix,				/* current pixel */	      Px;				/* predicted current pixel */	int SIGN;		    /* sign of current context */	int cont,c_cont[MAX_COMPONENTS];		    /* context */	if (bpp16==FALSE)	{	/**********************************************/	/* Do for all pixels in the row in 8-bit mode */	/**********************************************/		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;    /* pixel indices in a scan line go from COMPONENTS to no */		color = -1;		do {			int RUNcnt;			if (!was_in_run) color = (color+1)%components;			else color = 0;			Ix = sl[i];			for (n_c=0;n_c<components;n_c++)				c_xx[n_c] = sl[i+n_c];			if (color == 0)			for (n_c=0;n_c<components;n_c++) {				c_dd[n_c] = psl[i+components+n_c];				/* Context determination */				/* Quantize the gradient */				/* partial context number: if (b-e) is used					then its contribution is added after					determination of the run state.					Also, sign flipping, if any, occurs after run					state determination */			    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 ***************************/				int delta[MAX_COMPONENTS];				enter_run = was_in_run = 1;				for (n_c=0;n_c<components;n_c++) {					delta[n_c] = sl[i+n_c] - c_aa[n_c];					if (delta[n_c]>NEAR || delta[n_c]<negNEAR) enter_run=0;				}				RUNcnt = 0;				if (enter_run)				{					while ( 1 ) {						++RUNcnt;						for (n_c=0; n_c<components; n_c++) 							sl[i+n_c] = c_aa[n_c];						if((i=i+components)>(no+components-1)){								process_run(RUNcnt, EOLINE, 0);							return;	 /* end of line */						}						for (n_c=0;n_c<components;n_c++) 							c_xx[n_c] = sl[i+n_c];						break_run=0;						for (n_c=0;n_c<components;n_c++) {							delta[n_c] = c_xx[n_c] - c_aa[n_c];							if(delta[n_c]>NEAR || delta[n_c]<negNEAR) break_run=1;						}						if ( break_run )						{							for(n_c=0; n_c<components; n_c++){								c_dd[n_c] = psl[i+components+n_c];								c_bb[n_c] = psl[i+n_c];							}							break;  /* out of while loop */						}						/* Run continues */					}				}				/* we only get here if the run is broken by					a non-matching symbol */				process_run(RUNcnt, NOEOLINE, 0);				/* This is the END_OF_RUN state */				for (n_c=0;n_c<components;n_c++) {					/* The end of run is done for each component */					Ix = c_xx[n_c];					Rb = c_bb[n_c];					Ra = c_aa[n_c];					/* Handle two special EOR states */					c_xx[n_c] = Ix = lossy_end_of_run(Ra, Rb, Ix, 0);									}   /* loop for components */			}           /* Run state block */			else {						/*************** REGULAR CONTEXT *******************/				predict(Rb, Ra, Rc);				cont = classmap[cont];								if (cont<0)				{	SIGN=-1;					cont=-cont;				}				else					SIGN=1;				/* output a rice code */				lossy_regular_mode(cont, SIGN, Px, &Ix);			}			/* context for next pixel: */			if (!was_in_run) {				c_aa[color] = Ix; 				sl[i] = Ix;   /* store reconstructed x */				c_cc[color] = Rb;				c_bb[color] = Rd;				i++;			}			else {				for(n_c=0;n_c<components;n_c++) {					c_aa[n_c] = c_xx[n_c];					sl[i+n_c] = c_xx[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;    /* pixel indices in a scan line go from COMPONENTS to no */		color = -1;		do {			int RUNcnt;			if (!was_in_run) color = (color+1)%components;			else color = 0;			Ix = ENDIAN16(sl[i]);			for (n_c=0;n_c<components;n_c++)				c_xx[n_c] = ENDIAN16(sl[i+n_c]);			if (color == 0)			for (n_c=0;n_c<components;n_c++) {				c_dd[n_c] = ENDIAN16(psl[i+components+n_c]);				/* Context determination */				/* Quantize the gradient */				/* partial context number: if (b-e) is used					then its contribution is added after					determination of the run state.					Also, sign flipping, if any, occurs after run					state determination */				{				register int diff;				/* Following segment assumes that Sc <= LUTMAX16 */				/* This condition should have been checked when the			   l	ookup 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 ***************************/				int delta[MAX_COMPONENTS];				enter_run = was_in_run = 1;				for (n_c=0;n_c<components;n_c++) {					delta[n_c] = ENDIAN16(sl[i+n_c]) - c_aa[n_c];					if (delta[n_c]>NEAR || delta[n_c]<negNEAR) enter_run=0;				}				RUNcnt = 0;				if (enter_run)				{					while ( 1 ) {						++RUNcnt;						for (n_c=0; n_c<components; n_c++) 							sl[i+n_c] = ENDIAN16(c_aa[n_c]);						if((i=i+components)>(no+components-1)){								process_run(RUNcnt, EOLINE, 0);							return;	 /* end of line */						}						for (n_c=0;n_c<components;n_c++) 							c_xx[n_c] = ENDIAN16(sl[i+n_c]);						break_run=0;						for (n_c=0;n_c<components;n_c++) {							delta[n_c] = c_xx[n_c] - c_aa[n_c];							if(delta[n_c]>NEAR || delta[n_c]<negNEAR) break_run=1;						}						if ( break_run )						{							for(n_c=0; n_c<components; n_c++){								c_dd[n_c] = ENDIAN16(psl[i+components+n_c]);								c_bb[n_c] = ENDIAN16(psl[i+n_c]);							}							break;  /* out of while loop */						}						/* Run continues */					}				}				/* we only get here if the run is broken by					a non-matching symbol */				process_run(RUNcnt, NOEOLINE, 0);				/* This is the END_OF_RUN state */				for (n_c=0;n_c<components;n_c++) {					/* The end of run is done for each component */					Ix = c_xx[n_c];					Rb = c_bb[n_c];					Ra = c_aa[n_c];					/* Handle two special EOR states */					c_xx[n_c] = Ix = lossy_end_of_run(Ra, Rb, Ix, 0);									}   /* loop for components */			}           /* Run state block */			else {						/*************** REGULAR CONTEXT *******************/				predict(Rb, Ra, Rc);				cont = classmap[cont];								if (cont<0)				{	SIGN=-1;					cont=-cont;				}				else					SIGN=1;				/* output a rice code */				lossy_regular_mode(cont, SIGN, Px, &Ix);			}			/* context for next pixel: */			if (!was_in_run) {				c_aa[color] = Ix; 				sl[i] = ENDIAN16(Ix);   /* store reconstructed x */				c_cc[color] = Rb;				c_bb[color] = Rd;				i++;			}			else {				for(n_c=0;n_c<components;n_c++) {					c_aa[n_c] = c_xx[n_c];					sl[i+n_c] = ENDIAN16(c_xx[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));	}	/* ends 'if' for 8 or 16 bit */}

⌨️ 快捷键说明

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