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

📄 grp4deco.c

📁 NIST Handwriting OCR Testbed
💻 C
📖 第 1 页 / 共 4 页
字号:
********************************************************************/void swap_the_reference_and_coding_lines( params )struct parameters *params;{SHORT *temp;		temp = params->reference_line;	params->reference_line 	= params->coding_line;	params->coding_line = temp;		} /* end swap_the_reference_and_coding_lines() */ /*********************************** crash_d ***********************************			forces the program to crash and create a core file			******************************************************************************/	void crash_d(){FILE *crash_program = NULL;	fprintf(crash_program,"This will kill the program and create a core file");}/***************************************************************************//* Originally decomp.c                                                     *//***************************************************************************/static struct changing_element {	SHORT color; 					/* the color of the pixel */	SHORT pixel; 					/* the position of the pixel on the line */} a0, a1; 		 		static SHORT  	b1, b2;				/* an index into reference_line *//******************************* decompress_line *****************************					decompress one line of the compressed image			******************************************************************************/SHORT decompress_line( params )struct parameters *params;{SHORT mode;#if Debug	static SHORT current_line = 0;	printf("\n\nLINE: %d\n", current_line);	current_line++;#endif	b1 = 1; /* this puts b1 on the first black element in the reference line ,			 * which is appropriate  because a0 is white and on -1 */	a0.pixel = 0;	a0.color = White; 	do {		#if Debug		printf("a0:%d, a1:%d, b1:%d", a0.pixel, a1.pixel,		 *(params->reference_line + b1));#endif		mode =  get_mode();		switch( mode ) {		case	V0:					case	VR1:				case	VL1:				case	VR2:				case	VL2:				case	VR3:				case 	VL3:	vertical_mode_d( params, mode );						break;		case	H:		horizontal_mode_d( params );						break;		case	P:		pass_mode_d( params );						continue;		case	EOFB:   return( EOFB );		default:		crash_d();		} /* end case of different modes */			} while(a0.pixel < params->max_pixel);	return( Not_done_yet );	} 	/* end decompress_line *//********************************** get_mode **********************************					read a mode code from the compressed image			******************************************************************************/SHORT get_mode(){SHORT i;	if (read_bit() == 1)	 		return(V0);								/* 1 */	if (read_bit() == 1) {		if (read_bit() == 1)  			return(VR1);						/* 011 */		else		   	return(VL1);						/* 010 */	}						else {		if (read_bit() == 1)  		   	return(H);							/* 001 */		if (read_bit() == 1)  		   	return(P);							/* 0001 */	    if (read_bit() == 1) {	    	if (read_bit() == 1)	    		return(VR2);					/* 000011 */	    	else	    		return(VL2);					/* 000010 */		}		else {			if (read_bit() == 1) {		    	if (read_bit() == 1)		    		return(VR3);				/* 0000011 */		    	else	    			return(VL3);				/* 0000010 */	    	}			else {							/*				 * Have read 6 zero's so far.  The only valid code now				 * possible is EOFB: 00000000000100000000001.				 */								for(i=0;i<5;i++) 					if (read_bit() != 0)  						crash_d(); 		 				if (read_bit() != 1)  					crash_d(); 			 				for(i=0;i<11;i++) 					if (read_bit() != 0)  						crash_d();	 				if (read_bit() != 1)  					crash_d();						return(EOFB);					/* 00000000000100000000001 */			}		}	}	} /* end get_mode() *//********************************** pass_mode_d ********************************							decompress a pass mode code			******************************************************************************/void pass_mode_d(params)struct parameters *params;{SHORT run_length;		b2 = b1 + 1;	run_length = *(params->reference_line + b2) - a0.pixel;	write_bits_d(run_length, a0.color);	#if Debug	printf(" P   Run:%d,  Color:%d\n", run_length, a0.color);#endif	a0.pixel += run_length;	/* a0.color does not change during pass_mode_d() */	b1 += 2;} /* end pass_mode_d() *//******************************* vertical_mode_d *******************************			decompress a vertical mode code			******************************************************************************/void vertical_mode_d(params, offset)struct parameters *params;SHORT offset;{SHORT run_length;		a1.pixel = *(params->reference_line + b1) + offset;	run_length = a1.pixel - a0.pixel;	write_bits_d(run_length, a0.color);	#if Debug	printf(" V%d   Run:%d,  Color:%d\n", offset, run_length, a0.color);#endif	a0.pixel = a1.pixel;	a0.color = ! a0.color;	*(params->coding_line + ++params->index) = a0.pixel;	/* 	 * The color of a0 changes after each vertical mode coding.	 */	 	if ((offset == -1) || (offset == 0)) {		if ( *(params->reference_line + b1) != params->max_pixel ) 			b1++;		return;	}		if ((offset == 1) || (offset == 2)) {		b1++;		if ( (*(params->reference_line + b1) <= a0.pixel)  && 		 (*(params->reference_line + b1) != params->max_pixel) ) 					b1 += 2;		return;	}		if ((offset == -2) || (offset == -3)) {		if ( *(params->reference_line + b1 - 1) > a0.pixel ) 			b1--;		else { if ( *(params->reference_line + b1) != params->max_pixel ) 			b1++;		return;		}	}					 	if (offset == 3) {		b1++;		while ( (*(params->reference_line + b1) <= a0.pixel)  && 		 (*(params->reference_line + b1) != params->max_pixel) ) 			b1 += 2;		return;	}	} /* end vertical_mode_d() */	/******************************* horizontal_mode_d *****************************			decompress a horizontal mode code			******************************************************************************/void horizontal_mode_d(params)struct parameters *params;{SHORT length, total_length = 0;	do {		length = find_run_length_code(a0.color);			total_length += length;	} while (length > Max_terminating_length);	/*	 *  Run lengths greater than 63 are followed by terminating codes.	 *  Thus if "length" is greater than 63, the terminating code must	 *  also be fetched in order to determine the total run length.	 *	 */		write_bits_d(total_length, a0.color);#if Debug	printf(" H   Run:%d,  Color:%d\n", total_length, a0.color);#endif	a0.pixel += total_length;	a0.color = !a0.color;	*(params->coding_line + ++params->index) = a0.pixel;	/*	 * a0's color changes after each run color.	 */	total_length = 0;	do {		length = find_run_length_code(a0.color);			total_length += length;	} while (length > Max_terminating_length);	write_bits_d(total_length, a0.color);	#if Debug	printf("   Run:%d,  Color:%d\n", total_length, a0.color);#endif	a0.pixel += total_length;	a0.color = !a0.color;	*(params->coding_line + ++params->index) = a0.pixel;		while (  (*(params->reference_line + b1) <= a0.pixel)  && 	 ( *(params->reference_line + b1) < params->max_pixel)  )		{		b1 += 2;   /* must move ahead by 2 to maintain color difference with */				   /* a0, whose color does not change in this mode. */		}		} /* end horizontal_mode_d() *//***************************************************************************//* Originally write.c                                                      *//***************************************************************************/static char		write_one[Pixels_per_byte] = {	(char)0x80, /* 10000000b: with | operator, it writes a one to bit 0 */	(char)0x40, /* 01000000b: with | operator, it writes a one to bit 1 */	(char)0x20, /* 00100000b: with | operator, it writes a one to bit 2 */	(char)0x10, /* 00010000b: with | operator, it writes a one to bit 3 */	(char)0x8,  /* 00001000b: with | operator, it writes a one to bit 4 */	(char)0x4,  /* 00000100b: with | operator, it writes a one to bit 5 */	(char)0x2,  /* 00000010b: with | operator, it writes a one to bit 6 */	(char)0x1,  /* 00000001b: with | operator, it writes a one to bit 7 */};static char 	write_zero[Pixels_per_byte] =

⌨️ 快捷键说明

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