Пример #1
0
 /**
  * @param FileHandler $fh
  *
  * @throws Exception
  */
 public function decode($fh)
 {
     if ($fh->getRemainingBytes() < 6) {
         throw new Exception("Insufficient data. Need 6 bytes, got " . $fh->getRemainingBytes());
     }
     $this->signature = $fh->readData(3);
     $this->version = $fh->readData(3);
 }
 /**
  * @param FileHandler $fh
  *
  * @throws Exception
  */
 public function decode($fh)
 {
     if ($fh->getRemainingBytes() < 7) {
         throw new Exception("Insufficient data. Need 7 bytes, got " . $fh->getRemainingBytes());
     }
     $this->screenWidth = $fh->readUint16();
     $this->screenHeight = $fh->readUint16();
     $packedFields = ord($fh->readByte());
     $this->colorTableFlag = ($packedFields & 0x80) > 0;
     $this->colorResolution = ($packedFields & 0x70) >> 4;
     $this->sortFlag = ($packedFields & 0x8) > 0;
     // For just 8 possible values, the lookup table is faster.
     // the commented lines below is the pedantic way of doing it.
     // $v = ($packedFields & 0x07);
     // $this->colorTableSize = pow(2, $v + 1);
     $this->colorTableSize = $this->ctSizeListRev[$packedFields & 0x7];
     $this->bgColorIndex = $fh->readByteUint();
     $v = $fh->readByteUint();
     $this->pixelAspectRatio = $v > 0 ? ($v + 15) / 64 : 0;
     if ($this->colorTableFlag && $this->colorTableSize > 0) {
         $this->colorTable = $fh->readData($this->colorTableSize * 3);
     }
 }