1<?php 2 3namespace Mpdf\Gif; 4 5/** 6 * GIF Util - (C) 2003 Yamasoft (S/C) 7 * 8 * All Rights Reserved 9 * 10 * This file can be freely copied, distributed, modified, updated by anyone under the only 11 * condition to leave the original address (Yamasoft, http://www.yamasoft.com) and this header. 12 * 13 * @link http://www.yamasoft.com 14 */ 15class FileHeader 16{ 17 18 var $m_lpVer; 19 20 var $m_nWidth; 21 22 var $m_nHeight; 23 24 var $m_bGlobalClr; 25 26 var $m_nColorRes; 27 28 var $m_bSorted; 29 30 var $m_nTableSize; 31 32 var $m_nBgColor; 33 34 var $m_nPixelRatio; 35 36 /** 37 * @var \Mpdf\Gif\ColorTable 38 */ 39 var $m_colorTable; 40 41 public function __construct() 42 { 43 unset($this->m_lpVer); 44 unset($this->m_nWidth); 45 unset($this->m_nHeight); 46 unset($this->m_bGlobalClr); 47 unset($this->m_nColorRes); 48 unset($this->m_bSorted); 49 unset($this->m_nTableSize); 50 unset($this->m_nBgColor); 51 unset($this->m_nPixelRatio); 52 unset($this->m_colorTable); 53 } 54 55 function load($lpData, &$hdrLen) 56 { 57 $hdrLen = 0; 58 59 $this->m_lpVer = substr($lpData, 0, 6); 60 if (($this->m_lpVer <> "GIF87a") && ($this->m_lpVer <> "GIF89a")) { 61 return false; 62 } 63 64 $this->m_nWidth = $this->w2i(substr($lpData, 6, 2)); 65 $this->m_nHeight = $this->w2i(substr($lpData, 8, 2)); 66 if (!$this->m_nWidth || !$this->m_nHeight) { 67 return false; 68 } 69 70 $b = ord(substr($lpData, 10, 1)); 71 $this->m_bGlobalClr = ($b & 0x80) ? true : false; 72 $this->m_nColorRes = ($b & 0x70) >> 4; 73 $this->m_bSorted = ($b & 0x08) ? true : false; 74 $this->m_nTableSize = 2 << ($b & 0x07); 75 $this->m_nBgColor = ord(substr($lpData, 11, 1)); 76 $this->m_nPixelRatio = ord(substr($lpData, 12, 1)); 77 $hdrLen = 13; 78 79 if ($this->m_bGlobalClr) { 80 $this->m_colorTable = new ColorTable(); 81 if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) { 82 return false; 83 } 84 $hdrLen += 3 * $this->m_nTableSize; 85 } 86 87 return true; 88 } 89 90 function w2i($str) 91 { 92 return ord(substr($str, 0, 1)) + (ord(substr($str, 1, 1)) << 8); 93 } 94} 95