/** * @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(); } }
/** * @param FileHandler $fh * @param int $frameCount * @param LogicalScreenDescriptor $lsd * @param string $dstPath */ public static function dumpExtensionBlock($fh, &$frameCount, $lsd, $dstPath = null) { $fh->seekForward(1); $blockLabel = $fh->peekByte(); switch (ord($blockLabel)) { case AbstractExtensionBlock::LABEL_APPLICATION: $adb = new ApplicationExtension($fh); self::dumpApplicationExtensionBlock($adb); break; case AbstractExtensionBlock::LABEL_COMMENT: $ceb = new CommentExtension($fh); self::dumpCommentExtensionBlock($ceb); break; case AbstractExtensionBlock::LABEL_GRAPHICS_CONTROL: $gce = new GraphicControlExtension($fh); $frameCount++; self::dumpGraphicControlExtensionBlock($gce, $frameCount, $lsd, $dstPath); break; case AbstractExtensionBlock::LABEL_PLAIN_TEXT: $pte = new PlainTextExtension($fh); self::dumpPlainTextExtensionBlock($pte); break; case AbstractExtensionBlock::CONTROL_TRAILER: break; default: $fh->seekForward(1); echo "Unknown Extension block found.......: 0x" . bin2hex($blockLabel) . " (" . ord($blockLabel) . ")\n"; while (!$fh->compareByte("")) { $fh->seekForward(1); } } if ($fh->compareByte("")) { $fh->readByte(); } }
/** * @param FileHandler $fh * @param int $frameCount * @param LogicalScreenDescriptor $lsd * @param string $dstPath */ private static function readExtensionBlock($fh, &$frameCount, $lsd, $dstPath) { $fh->seekForward(1); $blockLabel = $fh->peekByte(); switch (ord($blockLabel)) { case AbstractExtensionBlock::LABEL_APPLICATION: new ApplicationExtension($fh); break; case AbstractExtensionBlock::LABEL_COMMENT: new CommentExtension($fh); break; case AbstractExtensionBlock::LABEL_GRAPHICS_CONTROL: $gce = new GraphicControlExtension($fh); self::writeFrame($dstPath, $frameCount, $lsd, $gce); break; case AbstractExtensionBlock::LABEL_PLAIN_TEXT: new PlainTextExtension($fh); break; case AbstractExtensionBlock::CONTROL_TRAILER: break; default: $fh->seekForward(1); while (!$fh->compareByte("")) { $fh->seekForward(1); } } if ($fh->compareByte("")) { $fh->readByte(); } }
/** * @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; }