grp4comp.c

来自「NIST Handwriting OCR Testbed」· C语言 代码 · 共 1,421 行 · 第 1/4 页

C
1,421
字号
};/*************************** prepare_to_write_bits_c **************************		initializes variables in preperation for writing compressed images				*****************************************************************************/void prepare_to_write_bits_c( compressed )struct compressed_descriptor *compressed;{     if(comp_alloc_flag){	(char *)compressed->data = calloc( (compressed->pixels_per_line * 	 compressed->number_of_lines / Pixels_per_byte), sizeof(char) );     }   /*    *  This allocation is usually very wasteful, but because there is no    *  way of knowing how much space is needed, I decided to be generous.    */        if (compressed->data == NULL){        printf("\nMemory allocation error for compressed output data.\n");    	crash_c();    }	output_area = compressed->data;}/******************************** write_bits_c **********************************		writes a variable length series of bits represented by a string of '1's	and '0's, which it receives as a parameter				*****************************************************************************/void write_bits_c(string_ptr)char *string_ptr;{      /* global switch added by Michael D. Garris 2/26/90 */      if(comp_write_init_flag){         bit_place_mark = 0;         byte_place_mark = 0;         comp_write_init_flag = False;      }	while(*string_ptr != '\0') {	      if(*string_ptr == '1')	  	 *(output_area + byte_place_mark) |= write_one[bit_place_mark];	      else		 *(output_area + byte_place_mark) &= write_zero[bit_place_mark];	      if(bit_place_mark == Last_bit_in_a_byte) {	 	 bit_place_mark = 0;		 byte_place_mark++;	      } /* end if byte is full */ 	      else		 bit_place_mark++;	      string_ptr++;	} /* end while */	} /******************************** flush_buffer *******************************		writes to memory whatever bits are left in the bit buffer followed by 	enough zero-bits to pad the compressed image out to a byte boundary.				*****************************************************************************/unsigned int flush_buffer(){SHORT i;	if (bit_place_mark != 0) {       	    for (i=bit_place_mark; i<Pixels_per_byte; i++)		*(output_area + byte_place_mark) &= write_zero[i];		/*		 * pad the rest of the last byte with '0' bits.		 */		++byte_place_mark;	}	return byte_place_mark;} /***************************************************************************//* Originally write_run.c                                                  *//***************************************************************************//******************************************************************************		The arrays that follow contain character representations of the binary	run length codes written during compression.			******************************************************************************/static char *white_terminating_code[64] ={	"00110101",	"000111",	"0111",	"1000",	"1011",	"1100",	"1110",	"1111",	"10011",	"10100",	"00111",	"01000",	"001000",	"000011",	"110100",	"110101",	"101010",	"101011",	"0100111",	"0001100",	"0001000",	"0010111",	"0000011",	"0000100",	"0101000",	"0101011",	"0010011",	"0100100",	"0011000",	"00000010",	"00000011",	"00011010",	"00011011",	"00010010",	"00010011",	"00010100",	"00010101",	"00010110",	"00010111",	"00101000",	"00101001",	"00101010",	"00101011",	"00101100",	"00101101",	"00000100",	"00000101",	"00001010",	"00001011",	"01010010",	"01010011",	"01010100",	"01010101",	"00100100",	"00100101",	"01011000",	"01011001",	"01011010",	"01011011",	"01001010",	"01001011",	"00110010",	"00110011",	"00110100",};/* end array of white terminating code */static char *black_terminating_code[64] ={	"0000110111",	"010",	"11",	"10",	"011",	"0011",	"0010",	"00011",	"000101",	"000100",	"0000100",	"0000101",	"0000111",	"00000100",	"00000111",	"000011000",	"0000010111",	"0000011000",	"0000001000",	"00001100111",	"00001101000",	"00001101100",	"00000110111",	"00000101000",	"00000010111",	"00000011000",	"000011001010",	"000011001011",	"000011001100",	"000011001101",	"000001101000",	"000001101001",	"000001101010",	"000001101011",	"000011010010",	"000011010011",	"000011010100",	"000011010101",	"000011010110",	"000011010111",	"000001101100",	"000001101101",	"000011011010",	"000011011011",	"000001010100",	"000001010101",	"000001010110",	"000001010111",	"000001100100",	"000001100101",	"000001010010",	"000001010011",	"000000100100",	"000000110111",	"000000111000",	"000000100111",	"000000101000",	"000001011000",	"000001011001",	"000000101011",	"000000101100",	"000001011010",	"000001100110",	"000001100111",}; /* end black_terminating_array */static char *white_make_up_code[40] ={	"11011",	"10010",	"010111",	"0110111",	"00110110",	"00110111",	"01100100",	"01100101",	"01101000",	"01100111",	"011001100",	"011001101",	"011010010",	"011010011",	"011010100",	"011010101",	"011010110",	"011010111",	"011011000",	"011011001",	"011011010",	"011011011",	"010011000",	"010011001",	"010011010",	"011000",	"010011011",	   /*    * from this line on, the codes are colorless and represnt runs from    * 1792 pixels to 2560 pixels.  In other words, the longest run length     * codes have been added onto both the white make up codes and the black    * make up codes.  This has been done to make the procedure     * "write_run_length()" easier to write and to understand.  No other     * procedure in the compression algorithm is affected by this merging of    * different types of run length codes, and the compatibility of the    * program is in no way effected.    */    	"00000001000",	"00000001100",	"00000001101",	"000000010010",	"000000010011",	"000000010100",	"000000010101",	"000000010110",	"000000010111",	"000000011100",	"000000011101",	"000000011110",	"000000011111",}; /* end case of white makeup code */		static char *black_make_up_code[40] ={	"0000001111",	"000011001000",	"000011001001",	"000001011011",	"000000110011",	"000000110100",	"000000110101",	"0000001101100",	"0000001101101",	"0000001001010",	"0000001001011",	"0000001001100",	"0000001001101",	"0000001110010",	"0000001110011",	"0000001110100",	"0000001110101",	"0000001110110",	"0000001110111",	"0000001010010",	"0000001010011",	"0000001010100",	"0000001010101",	"0000001011010",	"0000001011011",	"0000001100100",	"0000001100101",	   /*    * from this line on, the codes are colorless and represnt runs from    * 1792 pixels to 2560 pixels.  In other words, the longest run length     * codes have been added onto both the white make up codes and the black    * make up codes.  This has been done to make the procedure     * "write_run_length()" easier to write and to understand.  No other     * procedure in the compression algorithm is affected by this merging of    * different types of run length codes, and the compatibility of the    * program is in no way compromised.    */    	"00000001000",	"00000001100",	"00000001101",	"000000010010",	"000000010011",	"000000010100",	"000000010101",	"000000010110",	"000000010111",	"000000011100",	"000000011101",	"000000011110",	"000000011111",}; /* end black makeup code */char *largest_colorless_code ={	"000000011111"};/****************************** write_run_length() *****************************	writes the code, or series of codes, that represent a given run length	of a given color.

⌨️ 快捷键说明

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