📄 grp4deco.c
字号:
{ (char)0x7F, /* 01111111b: with & operator, it writes a zero to bit 0 */ (char)0xBF, /* 10111111b: with & operator, it writes a zero to bit 1 */ (char)0xDF, /* 11011111b: with & operator, it writes a zero to bit 2 */ (char)0xEF, /* 11101111b: with & operator, it writes a zero to bit 3 */ (char)0xF7, /* 11110111b: with & operator, it writes a zero to bit 4 */ (char)0xFB, /* 11111011b: with & operator, it writes a zero to bit 5 */ (char)0xFD, /* 11111101b: with & operator, it writes a zero to bit 6 */ (char)0xFE, /* 11111110b: with & operator, it writes a zero to bit 7 */};/************************* prepare_to_write_bits_d ****************************** initializes variables in preperation for writing decompressed data ******************************************************************************/ void prepare_to_write_bits_d( output_pointer, bytes_per_line )char *output_pointer;SHORT bytes_per_line;{ output_area = output_pointer; all_white = (char *)calloc( bytes_per_line, sizeof(char) ); all_black = (char *)calloc( bytes_per_line, sizeof(char) ); memset(all_black, Black_byte, bytes_per_line); /* set all the pixels in "all_black" to '1' */} /******************************* write_bits_d *********************************** writes a number of bits of the same color to the memory buffer that holds the decompressed image. ******************************************************************************/ void write_bits_d(length, color)unsigned SHORT length;unsigned SHORT color;{static unsigned SHORT write_on_this_bit = 0;static unsigned int write_on_this_byte = 0;unsigned int bytes; /* global switch added by Michael D. Garris 2/23/90 */ if(decomp_write_init_flag){ write_on_this_bit = 0; write_on_this_byte = 0; decomp_write_init_flag = False; } if (color == Black) { while( (length>0) && (write_on_this_bit != 0) ) { *(output_area + write_on_this_byte) |= write_one[write_on_this_bit]; length--; if (write_on_this_bit == Last_bit_in_a_byte) { write_on_this_bit = 0; write_on_this_byte++; } else write_on_this_bit++; } memcpy((output_area+write_on_this_byte), all_black, (bytes=(length/8))); write_on_this_byte += bytes; length %= Bits_per_byte; while( length>0 ) { *(output_area + write_on_this_byte) |= write_one[write_on_this_bit]; length--; if (write_on_this_bit == Last_bit_in_a_byte) { write_on_this_bit = 0; write_on_this_byte++; } else write_on_this_bit++; } } /* end if color is black */ else { while( (length>0) && (write_on_this_bit != 0) ) { *(output_area + write_on_this_byte) &=write_zero[write_on_this_bit]; length--; if (write_on_this_bit == Last_bit_in_a_byte) { write_on_this_bit = 0; write_on_this_byte++; } else write_on_this_bit++; } memcpy((output_area+write_on_this_byte), all_white, (bytes=(length/8))); write_on_this_byte += bytes; length %= Bits_per_byte; while( length>0 ) { *(output_area + write_on_this_byte) &=write_zero[write_on_this_bit]; length--; if (write_on_this_bit == Last_bit_in_a_byte) { write_on_this_bit = 0; write_on_this_byte++; } else write_on_this_bit++; } } /* end if color is white */} /* end write_bits_d() *//***************************************************************************//* Originally read.c *//***************************************************************************/static char *input_area;static char read_bit_mask[Pixels_per_byte] = { (char)0x80, /* 10000000b: with & operator, it reads bit 0 */ (char)0x40, /* 01000000b: with & operator, it reads bit 1 */ (char)0x20, /* 00100000b: with & operator, it reads bit 2 */ (char)0x10, /* 00010000b: with & operator, it reads bit 3 */ (char)0x8, /* 00001000b: with & operator, it reads bit 4 */ (char)0x4, /* 00000100b: with & operator, it reads bit 5 */ (char)0x2, /* 00000010b: with & operator, it reads bit 6 */ (char)0x1, /* 00000001b: with & operator, it reads bit 7 */};/************************* prepare_to_read_bits ****************************** initialize a local, static variable, input_area ******************************************************************************/ void prepare_to_read_bits( input_pointer )char *input_pointer;{ input_area = input_pointer;}/******************************* read_bit ************************************* returns the value of the current bit of the compressed image (e.g. 1 or 0) ******************************************************************************/SHORT read_bit(){SHORT bit;static unsigned SHORT read_this_bit = 0; static unsigned int read_this_byte = 0; /* global switch added by Michael D. Garris 2/23/90 */ if(decomp_read_init_flag){ read_this_bit = 0; read_this_byte = 0; decomp_read_init_flag = False; } /* * read_bits gets one bit from the compressed data file, * and returns it as an integer value of 0 or 1. */ bit = *(input_area + read_this_byte) & read_bit_mask[read_this_bit]; if(read_this_bit == Last_bit_in_a_byte) { read_this_bit = 0; read_this_byte++; } /* end if current byte completely read */ else read_this_bit++; /* * NOTE: bit contains 0 if the bit read was 0, * or a non-zero number if the bit was 1. */ return( !(bit == 0) ); /* * the above operation returns a zero if bit is equal to zero, or a * one if bit is not equal to zero. */} /* end read_bit() *//***************************************************************************//* Originally tree.c *//***************************************************************************/struct node { SHORT value; struct node *child_zero; struct node *child_one;}; /* end node struct */static struct node *node_ptr;/***************************************************************************** The following declarations create two ordered, unbalanced, binary trees.The trees contain run length values, and are ordered by the Huffman codesthat correspond to those values. ******************************************************************************/struct node black_tree[] = { -1, &black_tree[ 2], &black_tree[ 1], -1, &black_tree[ 4], &black_tree[ 3], -1, &black_tree[ 6], &black_tree[ 5], 2, NULL, NULL, 3, NULL, NULL, -1, &black_tree[ 8], &black_tree[ 7], -1, &black_tree[ 10], &black_tree[ 9], 4, NULL, NULL, 1, NULL, NULL, -1, &black_tree[ 12], &black_tree[ 11], -1, &black_tree[ 14], &black_tree[ 13], 5, NULL, NULL, 6, NULL, NULL, -1, &black_tree[ 16], &black_tree[ 15], -1, &black_tree[ 18], &black_tree[ 17], 7, NULL, NULL, -1, &black_tree[ 20], &black_tree[ 19], -1, &black_tree[ 22], &black_tree[ 21], -1, &black_tree[ 24], &black_tree[ 23], 8, NULL, NULL, 9, NULL, NULL, -1, &black_tree[ 26], &black_tree[ 25], -1, &black_tree[ 28], &black_tree[ 27], -1, &black_tree[ 30], &black_tree[ 29], -1, &black_tree[ 32], &black_tree[ 31], 12, NULL, NULL, -1, &black_tree[ 34], &black_tree[ 33], 11, NULL, NULL, 10, NULL, NULL, -1, &black_tree[ 36], &black_tree[ 35], -1, &black_tree[ 38], &black_tree[ 37], -1, &black_tree[ 40], &black_tree[ 39], -1, NULL, &black_tree[ 41], -1, &black_tree[ 43], &black_tree[ 42], -1, &black_tree[ 45], &black_tree[ 44], 14, NULL, NULL, -1, &black_tree[ 47], &black_tree[ 46], -1, &black_tree[ 49], &black_tree[ 48], 13, NULL, NULL, -1, &black_tree[ 51], &black_tree[ 50], -1, &black_tree[ 53], &black_tree[ 52], -1, &black_tree[ 55], &black_tree[ 54], -1, &black_tree[ 57], &black_tree[ 56], -1, &black_tree[ 59], &black_tree[ 58], -1, &black_tree[ 61], &black_tree[ 60], 15, NULL, NULL, -1, &black_tree[ 63], &black_tree[ 62], -1, &black_tree[ 65], &black_tree[ 64], -1, &black_tree[ 67], &black_tree[ 66], -1, &black_tree[ 69], &black_tree[ 68], -1, &black_tree[ 71], &black_tree[ 70], -1, &black_tree[ 73], &black_tree[ 72], -1, &black_tree[ 75], &black_tree[ 74], -1, &black_tree[ 77], &black_tree[ 76], -1, &black_tree[ 79], &black_tree[ 78], -1, &black_tree[ 81], &black_tree[ 80], 0, NULL, NULL, -1, &black_tree[ 83], &black_tree[ 82], -1, &black_tree[ 85], &black_tree[ 84], -1, &black_tree[ 87], &black_tree[ 86], -1, &black_tree[ 89], &black_tree[ 88], -1, &black_tree[ 91], &black_tree[ 90], -1, &black_tree[ 93], &black_tree[ 92], -1, &black_tree[ 95], &black_tree[ 94], -1, &black_tree[ 97], &black_tree[ 96], 17, NULL, NULL, 16, NULL, NULL, -1, &black_tree[ 99], &black_tree[ 98], -1, &black_tree[101], &black_tree[100], -1, &black_tree[103], &black_tree[102], 64, NULL, NULL, -1, &black_tree[105], &black_tree[104], -1, &black_tree[107], &black_tree[106], -1, &black_tree[109], &black_tree[108], -1, &black_tree[111], &black_tree[110], -1, &black_tree[113], &black_tree[112], -1, &black_tree[115], &black_tree[114], 18, NULL, NULL, -1, &black_tree[117], &black_tree[116], -1, &black_tree[119], &black_tree[118], -1, &black_tree[121], &black_tree[120], -1, &black_tree[123], &black_tree[122], -1, &black_tree[125], &black_tree[124], 21, NULL, NULL, -1, &black_tree[127], &black_tree[126], -1, &black_tree[129], &black_tree[128], -1, &black_tree[131], &black_tree[130], 20, NULL, NULL, 19, NULL, NULL, -1, &black_tree[133], &black_tree[132], -1, &black_tree[135], &black_tree[134], -1, &black_tree[137], &black_tree[136], 22, NULL, NULL, -1, &black_tree[139], &black_tree[138], -1, &black_tree[141], &black_tree[140], -1, &black_tree[143], &black_tree[142], -1, &black_tree[145], &black_tree[144], -1, &black_tree[147], &black_tree[146], -1, &black_tree[149], &black_tree[148], -1, &black_tree[151], &black_tree[150], -1, &black_tree[153], &black_tree[152], -1, &black_tree[155], &black_tree[154], -1, &black_tree[157], &black_tree[156], 23, NULL, NULL, -1, &black_tree[159], &black_tree[158], -1, &black_tree[161], &black_tree[160], -1, &black_tree[163], &black_tree[162], -1, &black_tree[165], &black_tree[164], -1, &black_tree[167], &black_tree[166], 25, NULL, NULL, 24, NULL, NULL, -1, &black_tree[169], &black_tree[168], -1, &black_tree[171], &black_tree[170], -1, &black_tree[173], &black_tree[172], -1, &black_tree[175], &black_tree[174], -1, &black_tree[177], &black_tree[176], -1, &black_tree[179], &black_tree[178], -1, &black_tree[181], &black_tree[180], 1920, NULL, NULL, 1856, NULL, NULL, -1, &black_tree[183], &black_tree[182], -1, &black_tree[185], &black_tree[184], -1, &black_tree[187], &black_tree[186], 1792, NULL, NULL, 43, NULL, NULL,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -