77 int clear_code, end_code, cur_code;
78 int i, found, num_colors, prefix, compress_size;
79 int cur_char, end_of_data, bits_per_pix;
86 if (heap == NULL)
error(
"can't allocate heap");
89 if (heap[i] == NULL)
error(
"can't allocate heap");
91 bits_per_pix = code_size - 1;
92 compress_size = code_size;
93 num_colors = 1<<(bits_per_pix);
94 clear_code = num_colors;
95 end_code = clear_code + 1;
96 cur_code = end_code + 1;
99 if (!root)
error(
"memory allocation failure (root)");
100 for(i=0; i<num_colors; i++) {
101 root[
i] = heap[heap_index++];
105 root[
i]->
left = NULL;
111 pack_bits(compress_size, clear_code, os);
114 while (!end_of_data) {
116 cur_node = root[prefix];
119 end_of_data = 1;
break;
121 while(cur_node->
children && found) {
124 if (cur_char < cur_node->entry.suffix) {
125 if (cur_node->
left) cur_node = cur_node->
left;
127 cur_node->
left = heap[heap_index++];
128 cur_node = cur_node->
left;
133 if (cur_node->
right) cur_node = cur_node->
right;
135 cur_node->
right = heap[heap_index++];
136 cur_node = cur_node->
right;
144 end_of_data = 1;
break;
148 if (end_of_data)
break;
150 cur_node->
children = heap[heap_index++];
154 cur_node->
left = NULL;
155 cur_node->
right = NULL;
160 if (cur_code > ((1<<(compress_size))-1))
162 if (cur_code < MAXIMUMCODE) {
166 heap_index = num_colors;
167 for (i=0; i < num_colors; i++ ) root[i]->children = NULL;
168 pack_bits(compress_size, clear_code, os);
169 compress_size = bits_per_pix + 1;
170 cur_code = end_code + 1;
struct str_table_node * children
struct str_table_node * right
struct str_table_node * strTableNodePtr
struct str_table_node * left
struct str_table_node ** strTable