| 255 | } |
| 256 | |
| 257 | void ArithmeticEncoder::writeBits(U32 bits, U32 sym) |
| 258 | { |
| 259 | assert(bits && (bits <= 32) && (sym < (1u<<bits))); |
| 260 | |
| 261 | if (bits > 19) |
| 262 | { |
| 263 | writeShort(sym&U16_MAX); |
| 264 | sym = sym >> 16; |
| 265 | bits = bits - 16; |
| 266 | } |
| 267 | |
| 268 | U32 init_base = base; |
| 269 | base += sym * (length >>= bits); // new interval base and length |
| 270 | |
| 271 | if (init_base > base) propagate_carry(); // overflow = carry |
| 272 | if (length < AC__MinLength) renorm_enc_interval(); // renormalization |
| 273 | } |
| 274 | |
| 275 | void ArithmeticEncoder::writeByte(U8 sym) |
| 276 | { |