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

📄 lossless_e.c

📁 实现图像的jpeg无损压缩
💻 C
📖 第 1 页 / 共 2 页
字号:
				RUNcnt = 0;				if (Ix == Ra) {					while ( 1 ) {											++RUNcnt;						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]);						if (Ix != Ra)	/* 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 */				lossless_end_of_run(Ra, Rb, Ix, (Ra==Rb));			}			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 */				lossless_regular_mode(cont, SIGN, Px, &Ix);			}			/* context for next pixel: */			sl[i] = ENDIAN16(Ix);			Ra = Ix;			Rc = Rb;			Rb = Rd;		} while (++i <= no);	}}/* For pixel interleaved mode for LOSSLESS encoding */void lossless_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] = ENDIAN8(psl[n_c]);			c_bb[n_c] = ENDIAN8(psl[components+n_c]);			c_aa[n_c] = ENDIAN8(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 = ENDIAN8(sl[i]);			for (n_c=0;n_c<components;n_c++)				c_xx[n_c]=ENDIAN8(sl[i+n_c]);			if (color == 0)				for (n_c=0;n_c<components;n_c++)				{					c_dd[n_c] = ENDIAN8(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;					}			}			/* Run state? */			if ( test_run ) { 			/*************** RUN STATE ***************************/				enter_run = was_in_run = 1;				for (n_c=0;n_c<components;n_c++) 					if (ENDIAN8(sl[i+n_c]) != c_bb[n_c]) enter_run=0;				RUNcnt = 0;				if (enter_run)				{					while ( 1 ) {						++RUNcnt;						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] = ENDIAN8(sl[i+n_c]);						break_run=0;						for (n_c=0;n_c<components;n_c++) 							if (c_xx[n_c] != c_aa[n_c]) break_run=1;						if (break_run) 	/* Run is broken */						{							for(n_c=0;n_c<components;n_c++){								c_dd[n_c] = ENDIAN8(psl[i+components+n_c]);								c_bb[n_c] = ENDIAN8(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];					Ra = c_aa[n_c];					Rb = c_bb[n_c];					lossless_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 */				lossless_regular_mode(cont, SIGN, Px, &Ix);			}			/* context for next pixel: */			if (!was_in_run) {				c_aa[color] = Ix;				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];					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						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;					}			}			/* Run state? */			if ( test_run ) { 			/*************** RUN STATE ***************************/				enter_run = was_in_run = 1;				for (n_c=0;n_c<components;n_c++) 					if (ENDIAN16(sl[i+n_c]) != c_bb[n_c]) enter_run=0;				RUNcnt = 0;				if (enter_run)				{					while ( 1 ) {						++RUNcnt;						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++) 							if (c_xx[n_c] != c_aa[n_c]) break_run=1;						if (break_run) 	/* Run is broken */						{							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];					Ra = c_aa[n_c];					Rb = c_bb[n_c];										lossless_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 */				lossless_regular_mode(cont, SIGN, Px, &Ix);			}			/* context for next pixel: */			if (!was_in_run) {				c_aa[color] = Ix;				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];					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 + -