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

📄 encoder.c

📁 实现图像的jpeg无损压缩
💻 C
📖 第 1 页 / 共 3 页
字号:
							cscanline[components*(columns+1)+n_c]=cscanline[components*columns+n_c];						/* make the current scanline the previous one */						swaplines();						/* Insert restart markers if enabled */						if (need_restart)						{							/* Insert restart markers only after a restart interval */							if ((MCUs_counted % restart_interval) == 0)							{								bitoflush();								write_marker(out, (RSTm + ((MCUs_counted / restart_interval)%8)));							}							MCUs_counted++;						}					}			}			else {	/* Multiple files */				/* color_mode==LINE_INT and multi==1  */				/***********************************************************************/				/*           Line interleaved mode with multiple files received        */				/***********************************************************************/				n++;				if (lossy==FALSE)					/* LOSSLESS mode */					while (n <= c_rows[whose_max_size_rows]) {						for (n_c=0;n_c<components;n_c++) {							for (n_r=0;n_r<samplingy[n_c];n_r++) {								read_one_line(c_cscanline[n_c] + 1, c_columns[n_c], c_in[n_c]);								tot_in += c_columns[n_c];								/* 'extend' the edges */								c_cscanline[n_c][-1]=c_cscanline[n_c][0]=c_pscanline[n_c][1];								/* process the lines */								lossless_doscanline(c_pscanline[n_c], c_cscanline[n_c], c_columns[n_c],n_c);								/* 'extend' the edges */								c_cscanline[n_c][c_columns[n_c]+1]=c_cscanline[n_c][c_columns[n_c]];								/* make the current scanline the previous one */								c_swaplines(n_c);							}						}	/* End of loop for each file */						n+=samplingy[whose_max_size_rows];						/* Insert restart markers if enabled */						if (need_restart)						{							/* Insert restart markers only after a restart interval */							if ((MCUs_counted % restart_interval) == 0)							{								bitoflush();								write_marker(out, (RSTm + ((MCUs_counted / restart_interval)%8)));							}							MCUs_counted++;						}					}	/* End while of LINE_INT with multiple input files */				else					/* LOSSY mode */					while (n <= c_rows[whose_max_size_rows]) {						for (n_c=0;n_c<components;n_c++) {							for (n_r=0;n_r<samplingy[n_c];n_r++) {								read_one_line(c_cscanline[n_c] + 1, c_columns[n_c], c_in[n_c]);								tot_in += c_columns[n_c];								/* 'extend' the edges */								c_cscanline[n_c][-1]=c_cscanline[n_c][0]=c_pscanline[n_c][1];								/* process the lines */								lossy_doscanline(c_pscanline[n_c], c_cscanline[n_c], c_columns[n_c],n_c);								/* 'extend' the edges */								c_cscanline[n_c][c_columns[n_c]+1]=c_cscanline[n_c][c_columns[n_c]];								/* make the current scanline the previous one */								c_swaplines(n_c);							}						}	/* End of loop for each file */						n+=samplingy[whose_max_size_rows];						/* Insert restart markers if enabled */						if (need_restart)						{							/* Insert restart markers only after a restart interval */							if ((MCUs_counted % restart_interval) == 0)							{								bitoflush();								write_marker(out, (RSTm + ((MCUs_counted / restart_interval)%8)));							}							MCUs_counted++;						}					}	/* End while of LINE_INT with multiple input files */			}	/* Closes the else, LINE_INT and multi=1 */		}	/* Closes part for color_mode=LINE_INT */		else {			if (color_mode==PIXEL_INT) {				/***********************************************************************/				/*           Pixel interleaved mode with single file received          */				/***********************************************************************/				if (lossy==FALSE)					/* LOSSLESS mode */					while (++n <= rows) {						read_one_line(cscanline+components, components*columns, in);						tot_in += components*columns;						/* 'extend' the edges */						for (n_c=0;n_c<components;n_c++)							cscanline[-components+n_c]=cscanline[n_c]=pscanline[components+n_c];						/* process the lines */						lossless_doscanline_pixel(pscanline, cscanline, components*columns);						/* 'extend' the edges */						for (n_c=0;n_c<components;n_c++)							cscanline[components*(columns+1)+n_c] = cscanline[components*columns+n_c];						/* make the current scanline the previous one */						swaplines();						/* Insert restart markers if enabled */						if (need_restart)						{							/* Insert restart markers only after a restart interval */							if ((MCUs_counted % restart_interval) == 0)							{								bitoflush();								write_marker(out, (RSTm + ((MCUs_counted / restart_interval)%8)));							}							MCUs_counted++;						}					}				else					/* LOSSY mode */					while (++n <= rows) {						read_one_line(cscanline+components, components*columns, in);						tot_in += components*columns;						/* 'extend' the edges */						for (n_c=0;n_c<components;n_c++)							cscanline[-components+n_c]=cscanline[n_c]=pscanline[components+n_c];						/* process the lines */						lossy_doscanline_pixel(pscanline, cscanline, components*columns);						/* 'extend' the edges */						for (n_c=0;n_c<components;n_c++)							cscanline[components*(columns+1)+n_c] = cscanline[components*columns+n_c];						/* make the current scanline the previous one */						swaplines();						/* Insert restart markers if enabled */						if (need_restart)						{							/* Insert restart markers only after a restart interval */							if ((MCUs_counted % restart_interval) == 0)							{								bitoflush();								write_marker(out, (RSTm + ((MCUs_counted / restart_interval)%8)));							}							MCUs_counted++;						}					}			}	/* Closes if PIXEL_INT */			else {	/* NON PIXEL_INT */				/***********************************************************************/				/*           Plane interleaved mode 								   */				/***********************************************************************/				if (lossy==FALSE)					/* LOSSLESS mode */					while (++n <= c_rows[n_s]) {						temp_columns = c_columns[n_s];						read_one_line(c_cscanline[n_s]+1, temp_columns, c_in[n_s]);						tot_in += temp_columns;						/* 'extend' the edges */						c_cscanline[n_s][-1]=c_cscanline[n_s][0]=c_pscanline[n_s][1];						/* process the lines */						lossless_doscanline(c_pscanline[n_s], c_cscanline[n_s], temp_columns, n_s);						/* 'extend' the edges */						c_cscanline[n_s][temp_columns+1] = c_cscanline[n_s][temp_columns];						/* make the current scanline the previous one */						c_swaplines(n_s);						/* Insert restart markers if enabled */						if (need_restart)						{							/* Insert restart markers only after a restart interval */							if ((MCUs_counted % restart_interval) == 0)							{								bitoflush();								write_marker(out, (RSTm + ((MCUs_counted / restart_interval)%8)));							}							MCUs_counted++;						}					}				else					/* LOSSY mode */					while (++n <= c_rows[n_s]) {						temp_columns = c_columns[n_s];						read_one_line(c_cscanline[n_s]+1, temp_columns, c_in[n_s]);						tot_in += temp_columns;						/* 'extend' the edges */						c_cscanline[n_s][-1]=c_cscanline[n_s][0]=c_pscanline[n_s][1];						/* process the lines */						lossy_doscanline(c_pscanline[n_s], c_cscanline[n_s], temp_columns,n_s);						/* 'extend' the edges */						c_cscanline[n_s][temp_columns+1] = c_cscanline[n_s][temp_columns];						/* make the current scanline the previous one */						c_swaplines(n_s);						/* Insert restart markers if enabled */						if (need_restart)						{							/* Insert restart markers only after a restart interval */							if ((MCUs_counted % restart_interval) == 0)							{								bitoflush();								write_marker(out, (RSTm + ((MCUs_counted / restart_interval)%8)));							}							MCUs_counted++;						}					}			}	/* End for each component in PLANE_INT */		}	/* End for non LINE_INT */		bitoflush();	}	/* End of loop on scans */	all_header += write_marker(out, EOI);	/* Close down */	close_process_run();	pos1= closebuffers(multi);	/* total bytes out, including JPEG-LS header, but not	application-specific header bytes */	/* tot_out = (pos1-all_header)*8; */	tot_out = pos1*8;	t1 = get_utime();	if (need_table)		fprintf(msgfile, "Used the mapping table from file : %s\n",mappingtablefilename);	if (need_restart)		fprintf(msgfile, "Used restart markers with restart interval : %i\n", restart_interval);	if ( verbose )		fprintf(msgfile,"Marker segment bytes: %ld\n",all_header);	fprintf(msgfile,"Total bits out: %ld  Symbols in: %ld  %5.3lf bps  (%5.3lf : 1)\n",		tot_out,		tot_in,tot_out/(double)tot_in, 		(log((double)alpha)/log(2.0))*tot_in/tot_out);	fprintf(msgfile,"Time = %1.3lf secs : %1.0lf KSymbols/sec\n",t1-t0,		(tot_in)/(1024*(t1-t0)));	return 0;                                       /* OK! */}/* Message to show how to use program */usage(){	fprintf(stderr,"%s\n",banner);	fprintf(stderr,"Usage: %s [flags] infile1 [infile2,infile3,...] [-ooutfile]\n\				   infile1    : Input file: must be in PGM or PPM format\n\				   infile2,...: Additional input files for \"plane interleaved\"\n\				   or \"line interleaved\" modes. Must be in PGM (P5) format.\n\				   FLAGS  :\n\				   -i<infile> : Alternate input specification, use -i- for stdin.\n\				   -o<outfile>: Output specification, use -o- for stdout (default=%s).\n\				   -Ta<num>, -Tb<num>, -Tc<num>: thresholds for context quantization (a.k.a.\n\				   T1,T2,T3; must have Ta<=Tb<=Tc<=maxs; defaults depend on alphabet\n\				   size and lossless/near-lossless mode; see standard specification).\n\				   -r<num>    : Reset interval for statistics (standard default=%d).\n\				   ", "locoe", OUTFILE COMPSUFFIX,DEFAULT_RESET);	fprintf(stderr,"\				   -c<num>    : Mode for multi-component images (program default=%d):\n\				   %d:%s  %d:%s  %d:%s.\n",				   DEFAULT_COLOR_MODE,				   PLANE_INT, "plane-interleaved",				   LINE_INT,  "line-interleaved",				   PIXEL_INT, "sample-interleaved"				   );	fprintf(stderr,"\				   -n<error> or\n\				   -e<error>  : Max allowed loss per symbol (default = %d).\n",				   DEF_NEAR);	fprintf(stderr,"\				   -m<table>  : Use mapping table where <table> is a file in the format:\n\				   1st byte of <table> is the Table ID,\n\				   2nd byte of <table> is the Width of each table entry (in bytes),\n\				   3rd - 6th byte of <table> is the Max Table Index Value specified\n\				   as an integer (4 bytes),\n\				   7th byte and on are the table entries.\n");	fprintf(stderr,"\				   -t<num>    : Use Restart Markers where <num> is the restart interval \n\				   (ie. number of MCU's between restart markers).\n");	fprintf(stderr,"\				   -h         : Print this help.\n");	fprintf(stderr,"\				   *** No spaces allowed between a flag and its argument.\n\				   *** Use -Ta,-Tb,-Tc,-r only if you know what you are doing!\n\				   ");}/* Print out message for a bad flag */bad_flag(char *s){	fprintf(stderr,"Bad flag %s\n",s);	usage();	exit(10);}/* Functions that read the PGM header */#define HEADER_MAXLINE 256int read_header_6(FILE *fin, int *widthp, int *heightp, int *maxvalp, int *comp){	char line[HEADER_MAXLINE];	int  cols,rows,maxval;	if ( nextline(line, fin) != 0 )		return -10;	if (strncmp(line,"P5",2)==0) *comp=1;	else if (strncmp(line,"P6",2)==0) *comp=3;	else if (strncmp(line,"P7",2)==0) *comp=4;	else return -1;	if ( nextline(line, fin) != 0 )		return -10;	if ( sscanf(line,"%d %d",&cols,&rows) != 2 )		return -1;	if ( nextline(line, fin) != 0 )		return -10;	if ( sscanf(line,"%d",&maxval) != 1 )		return -1;	*widthp = cols;	*heightp = rows;	*maxvalp = maxval;	return 0;}int read_header_5(FILE *fin, int *widthp, int *heightp, int *maxvalp){	char line[HEADER_MAXLINE];	int  cols,rows,maxval;	if ( nextline(line, fin) != 0 )		return -10;	if (strncmp(line,"P5",2)!=0)		return -1;	if ( nextline(line, fin) != 0 )		return -10;	if ( sscanf(line,"%d %d",&cols,&rows) != 2 )		return -1;	if ( nextline(line, fin) != 0 )		return -10;	if ( sscanf(line,"%d",&maxval) != 1 )		return -1;	*widthp = cols;	*heightp = rows;	*maxvalp = maxval;	return 0;}/* Used to read in header lines of PGM/PPM files */int nextline(char *line, FILE *fp){	char *p;	do {		p = fgets(line, HEADER_MAXLINE, fp);		/*		if ( p != NULL )		fprintf(stderr,"%s",line);		*/	} while ( p != NULL && *p == '#' );	if ( p==NULL )		return -1;	return 0;}

⌨️ 快捷键说明

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