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 ImageHeader 16{ 17 18 var $m_nLeft; 19 20 var $m_nTop; 21 22 var $m_nWidth; 23 24 var $m_nHeight; 25 26 var $m_bLocalClr; 27 28 var $m_bInterlace; 29 30 var $m_bSorted; 31 32 var $m_nTableSize; 33 34 /** 35 * @var \Mpdf\Gif\ColorTable 36 */ 37 var $m_colorTable; 38 39 public function __construct() 40 { 41 unset($this->m_nLeft); 42 unset($this->m_nTop); 43 unset($this->m_nWidth); 44 unset($this->m_nHeight); 45 unset($this->m_bLocalClr); 46 unset($this->m_bInterlace); 47 unset($this->m_bSorted); 48 unset($this->m_nTableSize); 49 unset($this->m_colorTable); 50 } 51 52 function load($lpData, &$hdrLen) 53 { 54 $hdrLen = 0; 55 56 $this->m_nLeft = $this->w2i(substr($lpData, 0, 2)); 57 $this->m_nTop = $this->w2i(substr($lpData, 2, 2)); 58 $this->m_nWidth = $this->w2i(substr($lpData, 4, 2)); 59 $this->m_nHeight = $this->w2i(substr($lpData, 6, 2)); 60 61 if (!$this->m_nWidth || !$this->m_nHeight) { 62 return false; 63 } 64 65 $b = ord($lpData[8]); 66 $this->m_bLocalClr = ($b & 0x80) ? true : false; 67 $this->m_bInterlace = ($b & 0x40) ? true : false; 68 $this->m_bSorted = ($b & 0x20) ? true : false; 69 $this->m_nTableSize = 2 << ($b & 0x07); 70 $hdrLen = 9; 71 72 if ($this->m_bLocalClr) { 73 $this->m_colorTable = new ColorTable(); 74 if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) { 75 return false; 76 } 77 $hdrLen += 3 * $this->m_nTableSize; 78 } 79 80 return true; 81 } 82 83 function w2i($str) 84 { 85 return ord(substr($str, 0, 1)) + (ord(substr($str, 1, 1)) << 8); 86 } 87} 88