示例#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);
 }
示例#2
0
 /**
  * @param FileHandler $fh
  */
 public function decode($fh)
 {
     $fh->seekForward(1);
     // skip block label.
     $this->readDataSubBlocks($fh);
     while ($fh->peekByte() == "") {
         $fh->seekForward(1);
     }
 }
 /**
  * @param FileHandler $fh
  */
 public function readDataSubBlocks($fh)
 {
     $this->dataSubBlocks = "";
     while (!$fh->compareByte("")) {
         $subBlockLength = $fh->readByteUint();
         if ($subBlockLength == 0) {
             return;
         }
         $this->dataSubBlocks .= chr($subBlockLength) . $fh->readData($subBlockLength);
     }
 }
 /**
  * @param FileHandler $fh
  */
 public function decode($fh)
 {
     $fh->seekForward(1);
     // skip block label.
     $this->blockLength = $fh->readByteUint();
     // 11
     $this->applicationIdentifier = $fh->readData(8);
     $this->applicationAuthenticationCode = $fh->readData(3);
     $this->readDataSubBlocks($fh);
     while ($fh->peekByte() == "") {
         $fh->seekForward(1);
     }
 }
 /**
  * @param FileHandler $fh
  */
 public function decode($fh)
 {
     $fh->seekForward(1);
     // skip block label.
     $this->blockLength = $fh->readByteUint();
     // 4
     $packedFields = $fh->readByteUint();
     $this->reserved = ($packedFields & 0x70) >> 5;
     $this->disposalMethod = ($packedFields & 0x1c) >> 2;
     $this->userInputFlag = ($packedFields & 0x2) > 0;
     $this->transparentColorFlag = ($packedFields & 0x1) > 0;
     $this->delayTime = $fh->readUint16();
     $this->transparentColorIndex = $fh->readByteUint();
     // Spool past the \x00 terminator byte. There *should* only be one.
     while ($fh->compareByte("")) {
         $fh->readByte();
     }
     // The GCE will always be followed by the Image Descriptor.
     $this->imageDescriptor = new ImageDescriptor($fh);
     $this->imageDescriptor->parentGCE = $this;
 }
 /**
  * @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);
     }
 }
示例#7
0
 /**
  * @param FileHandler             $fh
  * @param FileHandler             $fhW
  * @param float                   $ratio
  * @param LogicalScreenDescriptor $lsd
  */
 private static function readExtensionBlock($fh, $fhW, $ratio, $lsd)
 {
     $fh->seekForward(1);
     $blockLabel = $fh->peekByte();
     switch (ord($blockLabel)) {
         case AbstractExtensionBlock::LABEL_APPLICATION:
             $adb = new ApplicationExtension($fh);
             $adb->encodeToFile($fhW);
             break;
         case AbstractExtensionBlock::LABEL_COMMENT:
             $ceb = new CommentExtension($fh);
             $ceb->encodeToFile($fhW);
             break;
         case AbstractExtensionBlock::LABEL_GRAPHICS_CONTROL:
             $gce = new GraphicControlExtension($fh);
             self::resizeGraphicControlExtensionBlock($gce, $ratio, $fhW, $lsd);
             break;
         case AbstractExtensionBlock::LABEL_PLAIN_TEXT:
             $pte = new PlainTextExtension($fh);
             $pte->encodeToFile($fhW);
             break;
         case AbstractExtensionBlock::CONTROL_TRAILER:
             break;
         default:
             $fh->seekForward(1);
             while (!$fh->compareByte("")) {
                 $fh->seekForward(1);
             }
     }
     if ($fh->compareByte("")) {
         $fh->readByte();
     }
 }
示例#8
0
 /**
  * @param string                  $dstPath
  * @param int                     $frameCount
  * @param LogicalScreenDescriptor $lsd
  * @param AbstractExtensionBlock  $aeb
  *
  * @throws Exception
  */
 private static function writeFrame($dstPath, &$frameCount, $lsd, $aeb)
 {
     $frameCount++;
     if ($dstPath !== null) {
         $dstFileName = $dstPath . str_pad(strval($frameCount), 3, "0", STR_PAD_LEFT) . ".gif";
         $fhW = new FileHandler();
         $fhW->openFile($dstFileName, true);
         $fhW->writeData("GIF89a");
         $lsd->encodeToFile($fhW);
         $aeb->encodeToFile($fhW);
         $fhW->writeData(";");
         $fhW->closeFile();
     }
 }
 /**
  * @param FileHandler $fh
  */
 public function decode($fh)
 {
     $fh->seekForward(1);
     // skip block label.
     $this->blockLength = $fh->readByteUint();
     // 12
     $this->textGridLeftPosition = $fh->readUint16();
     $this->textGridTopPosition = $fh->readUint16();
     $this->textGridWidth = $fh->readUint16();
     $this->textGridHeight = $fh->readUint16();
     $this->characterCellWidth = $fh->readByteUint();
     $this->characterCellHeight = $fh->readByteUint();
     $this->textFGColorIndex = $fh->readByteUint();
     $this->textBGColorIndex = $fh->readByteUint();
     $this->readDataSubBlocks($fh);
     // Spool past the \x00 terminator byte. There *should* only be one.
     while ($fh->peekByte() == "") {
         $fh->seekForward(1);
     }
 }
示例#10
0
 /**
  * @param FileHandler             $fh
  * @param GraphicControlExtension $gce
  *
  * @return ImageDescriptor|GraphicControlExtension
  */
 public static function getFirstImageFrame($fh, $gce = null)
 {
     $nId = null;
     while ($nId == null && !$fh->isEOF()) {
         $blockLabel = $fh->peekByte();
         if (ord($blockLabel) == AbstractExtensionBlock::CONTROL_IMAGE) {
             $nId = new ImageDescriptor($fh);
             if ($gce != null) {
                 $gce->transparentColorFlag = false;
                 $gce->transparentColorIndex = 0;
             }
             return $nId;
         } else {
             if (ord($blockLabel) == AbstractExtensionBlock::CONTROL_EXTENSION) {
                 $fh->seekForward(1);
                 $blockLabel = $fh->peekByte();
                 if (ord($blockLabel) == AbstractExtensionBlock::LABEL_GRAPHICS_CONTROL) {
                     $nGce = new GraphicControlExtension($fh);
                     if ($gce != null) {
                         $gce->transparentColorFlag = $nGce->transparentColorFlag;
                         $gce->transparentColorIndex = $nGce->transparentColorIndex;
                     }
                     return $nGce;
                 }
             }
         }
     }
     return null;
 }