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

📄 decoder.c

📁 实现了JPEG-LS的标准算法
💻 C
📖 第 1 页 / 共 3 页
字号:
								local_cscanline=cscanline;								local_pscanline=pscanline;							}							if ( lossless_undoscanline(local_pscanline, local_cscanline, columns, n_c ) != 0 )							{								fprintf(stderr,"*** Premature EOF: expected %d rows, got %d\n",rows, n-1);								found_EOF = 1;								break;							}							if (components>1)								for (my_i=0;my_i<columns+LEFTMARGIN+RIGHTMARGIN;my_i++)									cscanline[-components+my_i*components+n_c]=local_cscanline[-1+my_i];						}						write_one_line(cscanline + components, components*columns, out);						tot_out += 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();						/* Take out the Restart Markers */						if (got_restart)						{							/* Look for restart markers only after a restart interval */							if ((MCUs_counted % restart_interval) == 0)							{								bitiflush();								read_n_bytes(in, 2);	/* read the RST marker */								bitiinit();							}							MCUs_counted++;													}					}	/* End of while loop for each file line */				else					/* LOSSY MODE */					while (++n <= rows)					{						/* 'extend' the edges */						for (n_c=0;n_c<components;n_c++)							cscanline[-components+n_c]=cscanline[n_c]=pscanline[components+n_c];						for (n_c=0;n_c<components;n_c++)						{							if (components>1)								for (my_i=0;my_i<columns+LEFTMARGIN+RIGHTMARGIN;my_i++)								{									local_cscanline[-1+my_i]=cscanline[-components+my_i*components+n_c];									local_pscanline[-1+my_i]=pscanline[-components+my_i*components+n_c];								}							else 							{								local_cscanline=cscanline;								local_pscanline=pscanline;							}							if ( lossy_undoscanline(local_pscanline, local_cscanline, columns, n_c ) != 0 )							{								fprintf(stderr,"*** Premature EOF: expected %d rows, got %d\n",rows, n-1);								found_EOF = 1;								break;							}							if (components>1)								for (my_i=0;my_i<columns+LEFTMARGIN+RIGHTMARGIN;my_i++)									cscanline[-components+my_i*components+n_c]=local_cscanline[-1+my_i];						}						write_one_line(cscanline + components, components*columns, out);						tot_out += 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();						/* Take out the Restart Markers */						if (got_restart)						{							/* Look for restart markers only after a restart interval */							if ((MCUs_counted % restart_interval) == 0)							{								bitiflush();								read_n_bytes(in, 2);	/* read the RST marker */								bitiinit();							}							MCUs_counted++;													}					}	/* End of while loop for each file line */			}			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++)							{								/* 'extend' the edges */								c_cscanline[n_c][-1]=c_cscanline[n_c][0]=c_pscanline[n_c][1];								if ( lossless_undoscanline(c_pscanline[n_c], c_cscanline[n_c], c_columns[n_c], n_c ) != 0 )								{									fprintf(stderr,"*** Premature EOF: expected %d rows, got %d\n",rows, n-1);									found_EOF = 1;									break;								}								write_one_line(c_cscanline[n_c] + 1, c_columns[n_c], c_out[n_c]);								tot_out += c_columns[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 for loop for each component */						n+=samplingy[whose_max_size_rows];						/* Take out the Restart Markers */						if (got_restart)						{							/* Look for restart markers only after a restart interval */							if ((MCUs_counted % restart_interval) == 0)							{								bitiflush();								read_n_bytes(in, 2);	/* read the RST marker */								bitiinit();							}							MCUs_counted++;													}					}	/* End of while loop for each line */				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++)							{								/* 'extend' the edges */								c_cscanline[n_c][-1]=c_cscanline[n_c][0]=c_pscanline[n_c][1];								if ( lossy_undoscanline(c_pscanline[n_c], c_cscanline[n_c], c_columns[n_c], n_c ) != 0 )								{									fprintf(stderr,"*** Premature EOF: expected %d rows, got %d\n",rows, n-1);									found_EOF = 1;									break;								}								write_one_line(c_cscanline[n_c] + 1, c_columns[n_c], c_out[n_c]);								tot_out += c_columns[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 for loop for each component */						n+=samplingy[whose_max_size_rows];						/* Take out the Restart Markers */						if (got_restart)						{							/* Look for restart markers only after a restart interval */							if ((MCUs_counted % restart_interval) == 0)							{								bitiflush();								read_n_bytes(in, 2);	/* read the RST marker */								bitiinit();							}							MCUs_counted++;													}					}	/* End of while loop for each line */			}		/* Closes the else, LINE_INT and multi=1 */		}		/* End of part for LINE_INT */		else {		/* Non LINE_INT mode */			if (color_mode==PIXEL_INT) {/***********************************************************************//*           Pixel interleaved mode with single file received          *//***********************************************************************/				if (lossy==FALSE)									/* LOSSLESS MODE */					while (++n <= rows)					{						/* 'extend' the edges */						for (n_c=0;n_c<components;n_c++)							cscanline[-components+n_c]=cscanline[n_c]=pscanline[components+n_c];						if ( lossless_undoscanline_pixel(pscanline, cscanline, components*columns) != 0 )						{							fprintf(stderr,"*** Premature EOF: expected %d rows, got %d\n",rows,n-1);							found_EOF = 1;							break;						}						write_one_line(cscanline+components, components*columns, out);								tot_out += 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();						/* Take out the Restart Markers */						if (got_restart)						{							/* Look for restart markers only after a restart interval */							if ((MCUs_counted % restart_interval) == 0)							{								bitiflush();								read_n_bytes(in, 2);	/* read the RST marker */								bitiinit();							}							MCUs_counted++;													}					}	/* End of line loop for PIXEL_INT */				else					/* LOSSY MODE */					while (++n <= rows)					{						/* 'extend' the edges */						for (n_c=0;n_c<components;n_c++)							cscanline[-components+n_c]=cscanline[n_c]=pscanline[components+n_c];						if ( lossy_undoscanline_pixel(pscanline, cscanline, components*columns) != 0 )						{							fprintf(stderr,"*** Premature EOF: expected %d rows, got %d\n",rows,n-1);							found_EOF = 1;							break;						}						write_one_line(cscanline+components, components*columns, out);						tot_out += 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();						/* Take out the Restart Markers */						if (got_restart)						{							/* Look for restart markers only after a restart interval */							if ((MCUs_counted % restart_interval) == 0)							{								bitiflush();								read_n_bytes(in, 2);	/* read the RST marker */								bitiinit();							}							MCUs_counted++;													}					}	/* End of line loop for PIXEL_INT */			}			else {/***********************************************************************//*           Plane interleaved mode 				       *//***********************************************************************/				if (lossy==FALSE)									/* LOSSLESS MODE */					while (++n <= c_rows[n_s])					{						/* 'extend' the edges */						c_cscanline[n_s][-1]=c_cscanline[n_s][0]=c_pscanline[n_s][1];						if (lossless_undoscanline(c_pscanline[n_s], c_cscanline[n_s], c_columns[n_s], n_s ) != 0 )						{							fprintf(stderr,"*** Premature EOF: expected %d rows, got %d\n",rows, n-1);							found_EOF = 1;							break;						}						write_one_line(c_cscanline[n_s]+1, c_columns[n_s], c_out[n_s]);						tot_out += c_columns[n_s];						/* extend the edges */						c_cscanline[n_s][c_columns[n_s]+1] = c_cscanline[n_s][c_columns[n_s]];						/* make the current scanline the previous one */						c_swaplines(n_s);						/* Take out the Restart Markers */						if (got_restart)						{							/* Look for restart markers only after a restart interval */							if ((MCUs_counted % restart_interval) == 0)							{								bitiflush();								read_n_bytes(in, 2);	/* read the RST marker */								bitiinit();							}							MCUs_counted++;													}					}	/* End of line loop in PLANE_INT */								else					/* LOSSY MODE */					while (++n <= c_rows[n_s])					{						/* 'extend' the edges */						c_cscanline[n_s][-1]=c_cscanline[n_s][0]=c_pscanline[n_s][1];						if (lossy_undoscanline(c_pscanline[n_s], c_cscanline[n_s], c_columns[n_s], n_s ) != 0 )						{							fprintf(stderr,"*** Premature EOF: expected %d rows, got %d\n",rows, n-1);							found_EOF = 1;							break;						}						write_one_line(c_cscanline[n_s]+1, c_columns[n_s], c_out[n_s]);						tot_out += c_columns[n_s];						/* extend the edges */						c_cscanline[n_s][c_columns[n_s]+1] = c_cscanline[n_s][c_columns[n_s]];						/* make the current scanline the previous one */						c_swaplines(n_s);						/* Take out the Restart Markers */						if (got_restart)						{							/* Look for restart markers only after a restart interval */							if ((MCUs_counted % restart_interval) == 0)							{								bitiflush();								read_n_bytes(in, 2);	/* read the RST marker */								bitiinit();							}							MCUs_counted++;													}					}	/* End of line loop in PLANE_INT */			}	/* End of each component for PLANE_INT */		}	/* End of non LINE_INT */		bitiflush();	} /* End of loop for scans */	mk = 0;	/* Read EOI */	seek_return=seek_marker(in,&mk);	if (seek_return==EOF)	{		fprintf(stderr,"Did not get EOI at end of compressed image\n");		exit(10);	}	if ( seek_return > 2 )	{	    fprintf(msgfile,"*** WARNING: %d extra bytes between end of scan and next marker.\n",seek_return-2);	    fprintf(msgfile,"***          Added to marker segment count.\n");	}	pos0 += seek_return;	if (mk != EOI)	{	  fprintf(stderr,"In this implementation last marker must be EOI\n");	  exit(10);	}	if (head_scan[0]->need_table)		fprintf(msgfile,"A mapping table was used which had %i entries of %i bytes each.\n",head_scan[0]->MAXTAB, head_scan[0]->Wt);	if (got_restart)		fprintf(msgfile,"Restart markers were found with a restart interval of %i.\n",restart_interval);	if ( verbose )		fprintf(msgfile,"Marker segment bytes: %ld\n",pos0);	/* position in input file */	pos1 = ftell(in);	/* tot_in = 8*(pos1-pos0); */	/* size of compressed file read (bits), incl. headers. */	tot_in = 8*pos1;	/* Close down */	close_process_run();	closebuffers(multi);	t1 = get_utime();	fprintf(msgfile,"Total bits  in: %ld  Symbols out: %ld  %5.3lf bps\n",		       tot_in,tot_out,tot_in/(double)tot_out);	fprintf(msgfile,"Time = %1.3lf secs : %1.0lf KSymbols/sec\n",t1-t0,					(tot_out)/(1024*(t1-t0)));	if ( found_EOF )		exit(0);	else		return 1;}usage(){	fprintf(stderr,"Usage: %s [flags] [infile] [outfile1 [outfile2, ...]]\n\DEFAULTS:\n\infile   = %s.\n\outfile1 = %s for color image in a single (PPM) output file.\n\outfile1 = %s for monochrome image in a single (PGM) output file.\n\outfile[1,2,...] = %s for multiple (PGM) output files \n\	   in plane or line interleaved modes.\n",	  "locod", "specified JLS file", OUTFILE ".out", 	  OUTFILE "1.out",	  OUTFILE "[1,2,...].out");fprintf(stderr,"FLAGS:\n\outfile2, ... : Multiple output specification for plane or line int. mode.\n\-i<infile>    : Alternate input specification, use -i- for stdin.\n\-o<outfile>   : Alternate output specification, use -o- for stdout.\n\-P            : Generate single (.ppm) output file for sample/line int. mode.\n\");    fprintf(stderr,"\-h            : Print this help.\n\*** No spaces allowed between a flag and its argument.\n\");	}bad_flag(char *s){    fprintf(stderr,"Bad flag %s\n",s);    usage();    exit(10);}

⌨️ 快捷键说明

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