Beispiel #1
0
 /**
  * Decode a Huffman symbol from the bitstream using the stated table and return it.
  *
  * @param BitReader $reader The reader that provides the data.
  *
  * @throws Exception Throws an Exception in case of errors.
  *
  * @return int
  */
 public function readHuffmanSymbol(BitReader $reader)
 {
     $next = $reader->peek(16, true);
     $symbol = $this->symbols[$reader->peek($this->bits, true)];
     if ($symbol >= $this->maxSymbol) {
         $j = 1 << 16 - $this->bits;
         do {
             $j >>= 1;
             $symbol <<= 1;
             $symbol |= ($next & $j) > 0 ? 1 : 0;
             $symbol = $this->symbols[$symbol];
         } while ($symbol >= $this->maxSymbol);
     }
     $reader->readLE($this->lens[$symbol]);
     return $symbol;
 }