| 218 | typename cc_high |
| 219 | > |
| 220 | void entropy_encoder_model_kernel_3<alphabet_size,entropy_encoder,cc,cc_high>:: |
| 221 | encode ( |
| 222 | unsigned long symbol |
| 223 | ) |
| 224 | { |
| 225 | unsigned long low_count = 0, high_count = 0, total_count = 0; |
| 226 | |
| 227 | |
| 228 | // order-2 context stuff |
| 229 | { |
| 230 | unsigned long temp = previous_symbol + (previous_symbol2 * alphabet_size); |
| 231 | previous_symbol2 = previous_symbol; |
| 232 | |
| 233 | if (order_2[temp] != 0) |
| 234 | { |
| 235 | if (order_2[temp]->get_range(symbol,low_count,high_count,total_count)) |
| 236 | { |
| 237 | // there was an entry for this symbol in this context |
| 238 | |
| 239 | // update the count for this symbol |
| 240 | order_2[temp]->increment_count(symbol,2); |
| 241 | // encode this symbol |
| 242 | coder.encode(low_count,high_count,total_count); |
| 243 | previous_symbol = symbol; |
| 244 | return; |
| 245 | } |
| 246 | |
| 247 | // there was no entry for this symbol in this context so we must |
| 248 | // escape to order-1 |
| 249 | |
| 250 | // escape to the order-1 context |
| 251 | order_2[temp]->get_range(alphabet_size,low_count,high_count,total_count); |
| 252 | coder.encode(low_count,high_count,total_count); |
| 253 | |
| 254 | // increment the count for the escape symbol |
| 255 | order_2[temp]->increment_count(alphabet_size); |
| 256 | |
| 257 | } |
| 258 | else |
| 259 | { |
| 260 | order_2[temp] = new cc_high(gs_high); |
| 261 | |
| 262 | // in this case the decoder knows to escape to order-1 because |
| 263 | // there was no conditioning_class object in this context yet. |
| 264 | // so we don't need to actually write the escape symbol |
| 265 | } |
| 266 | |
| 267 | // update the count for this symbol in this context |
| 268 | order_2[temp]->increment_count(symbol,2); |
| 269 | } |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | // order-1 context stuff |
| 275 | { |
| 276 | cc& context = *order_1[previous_symbol]; |
| 277 | |