draco/docs/spec/symbol.decoding.md
Frank Galligan 4efc3d27cc Update bitstream spec
This PR is associated with #134.
2017-07-22 22:35:54 -07:00

2.2 KiB

Symbol Decoding

DecodeSymbols()

DecodeSymbols(num_symbols, out_values) {
  scheme                                                                UI8
  If (scheme == 0) {
    DecodeTaggedSymbols(num_symbols, out_values)
  } else if (scheme == 1) {
    DecodeRawSymbols(num_symbols, out_values)
  }
}

{:.draco-syntax }

DecodeTaggedSymbols()

DecodeTaggedSymbols() {
  FIXME
}

{:.draco-syntax }

DecodeRawSymbols()

DecodeRawSymbols(num_values, out_values) {
  max_bit_length                                                        UI8
  decoder = CreateRansSymbolDecoder(max_bit_length)
  decoder.StartDecoding()
  // RansSymbolDecoder_StartDecoding
  for (i = 0; i < num_values; ++i) {
    out_values[i] = decoder.DecodeSymbol()
    // RansSymbolDecoder_DecodeSymbol
  }
}

{:.draco-syntax }

CreateRansSymbolDecoder()

CreateRansSymbolDecoder(max_bit_length) {
  rans_precision_bits  = (3 * max_bit_length) / 2;
  rans_precision_bits = min(rans_precision_bits, 20)
  rans_precision_bits = max(rans_precision_bits, 12)
  rans_precision = 1 << rans_precision_bits_;
  l_rans_base = rans_precision * 4;
  num_symbols_                                                          UI32
  for (i = 0; i < num_symbols_; ++i) {
    prob_data                                                           UI8
    if ((prob_data & 3) == 3) {
      offset = prob_data >> 2
      for (j = 0; j < offset + 1; ++j) {
        probability_table_[i + j] = 0;
      }
      i += offset;
    } else {
      prob = prob_data >> 2
      for (j = 0; j < token; ++j) {
        eb                                                              UI8
        prob = prob | (eb << (8 * (j + 1) - 2)
      }
      probability_table_[i] = prob;
    }
  }
  rans_build_look_up_table()
}

{:.draco-syntax }

RansSymbolDecoder_StartDecoding()

RansSymbolDecoder_StartDecoding() {
  bytes_encoded                                                         UI64
  buffer                                                                bytes_encoded * UI8
  rans_read_init(buffer, bytes_encoded)
}

{:.draco-syntax }

RansSymbolDecoder_DecodeSymbol()

RansSymbolDecoder_DecodeSymbol() {
  return ans_.rans_read()
}

{:.draco-syntax }