Finish encoding */ actually not that many bytes need to be output, but who */ cares. I output them because decode will read them :) */ the return value is the number of bytes written */
| 76 | /* cares. I output them because decode will read them :) */ |
| 77 | /* the return value is the number of bytes written */ |
| 78 | void RangeEncoder::done() |
| 79 | { |
| 80 | U32 tmp; |
| 81 | normalize(); /* now we have a normalized state */ |
| 82 | bytecount += 5; |
| 83 | if ((low & (BOTTOM_VALUE-1)) < ((bytecount&0xffffffL)>>1)) |
| 84 | { |
| 85 | tmp = low >> SHIFT_BITS; |
| 86 | } |
| 87 | else |
| 88 | { |
| 89 | tmp = (low >> SHIFT_BITS) + 1; |
| 90 | } |
| 91 | if (tmp > 0xff) /* we have a carry */ |
| 92 | { |
| 93 | outstream->putByte(buffer+1); |
| 94 | for(; help; help--) |
| 95 | { |
| 96 | outstream->putByte(0); |
| 97 | } |
| 98 | } |
| 99 | else /* no carry */ |
| 100 | { |
| 101 | outstream->putByte(buffer); |
| 102 | for(; help; help--) |
| 103 | { |
| 104 | outstream->putByte(0xff); |
| 105 | } |
| 106 | } |
| 107 | outstream->putByte(tmp & 0xff); |
| 108 | outstream->putByte((bytecount>>16) & 0xff); |
| 109 | outstream->putByte((bytecount>>8) & 0xff); |
| 110 | outstream->putByte(bytecount & 0xff); |
| 111 | outstream = 0; |
| 112 | } |
| 113 | |
| 114 | EntropyModel* RangeEncoder::createBitModel() |
| 115 | { |