Beispiel #1
0
 /**
  * Encodes next value. If value is inside [-arithmeticCodeThreshold, arithmeticCodeThreshold]
  * range, then arithmetic encoding is used, otherwise 255 will be encoded by arithmetic encoding
  * and then actual value will be encoded by monotone encoding. For example, for value 300, firstly
  * - 255 will be encoded by arithmetic encoding and then 300 by monotone encoding.
  */
 public void encode(int value, BitOutput arithOut, BitOutput monoOut) throws IOException {
   if (value >= -arithmeticCodeThreshold
       && value <= arithmeticCodeThreshold) { // encode value by arithmetic coder
     arithmeticEncoder.encode(value + arithmeticCodeThreshold, arithOut);
   } else {
     // escape to switch fusion decoder to monotone decoder
     arithmeticEncoder.encode(FusionCoderConstants.ESCAPE_TO_SWITCH_TO_MONOTONE_CODE, arithOut);
     monotoneEncoder.encode(value, monoOut);
   }
 }
Beispiel #2
0
 /**
  * Close this output stream.
  *
  * @throws IOException If there is an exception in the underlying encoder.
  */
 public void close(BitOutput out) throws IOException {
   // must code EOF to allow decoding to halt
   arithmeticEncoder.encode(ArithCodeModel.EOF, out);
   // to allow arithmetic encoder to output buffered bits
   arithmeticEncoder.close(out);
 }