I do the normalization before I need a defined state instead of */ after messing it up. This simplifies starting and ending. */
| 307 | /* I do the normalization before I need a defined state instead of */ |
| 308 | /* after messing it up. This simplifies starting and ending. */ |
| 309 | inline void RangeEncoder::normalize() |
| 310 | { |
| 311 | while(range <= BOTTOM_VALUE) /* do we need renormalisation? */ |
| 312 | { |
| 313 | if (low < (U32)0xff<<SHIFT_BITS) /* no carry possible --> output */ |
| 314 | { |
| 315 | outstream->putByte(buffer); |
| 316 | for(; help; help--) |
| 317 | { |
| 318 | outstream->putByte(0xff); |
| 319 | } |
| 320 | buffer = (U8)(low >> SHIFT_BITS); |
| 321 | } |
| 322 | else if (low & TOP_VALUE) /* carry now, no future carry */ |
| 323 | { |
| 324 | outstream->putByte(buffer+1); |
| 325 | for(; help; help--) |
| 326 | { |
| 327 | outstream->putByte(0); |
| 328 | } |
| 329 | buffer = (U8)(low >> SHIFT_BITS); |
| 330 | } |
| 331 | else /* passes on a potential carry */ |
| 332 | { |
| 333 | help++; |
| 334 | } |
| 335 | range <<= 8; |
| 336 | low = (low<<8) & (TOP_VALUE-1); |
| 337 | bytecount++; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | |
| 342 | /* |