CGIFLZW

The Gravity PDF CGIFLZW class.

Defined (1)

The class is defined in the following location(s).

/vendor/blueliquiddesigns/mpdf/classes/gif.php  
  1. class CGIFLZW 
  2.  
  3. var $MAX_LZW_BITS; 
  4.  
  5. var $Fresh, $CodeSize, $SetCodeSize, $MaxCode, $MaxCodeSize, $FirstCode, $OldCode; 
  6.  
  7. var $ClearCode, $EndCode, $Next, $Vals, $Stack, $sp, $Buf, $CurBit, $LastBit, $Done, $LastByte; 
  8.  
  9. public function __construct() 
  10. $this->MAX_LZW_BITS = 12; 
  11. unSet($this->Next); 
  12. unSet($this->Vals); 
  13. unSet($this->Stack); 
  14. unSet($this->Buf); 
  15.  
  16. $this->Next = range(0, (1 << $this->MAX_LZW_BITS) - 1); 
  17. $this->Vals = range(0, (1 << $this->MAX_LZW_BITS) - 1); 
  18. $this->Stack = range(0, (1 << ($this->MAX_LZW_BITS + 1)) - 1); 
  19. $this->Buf = range(0, 279); 
  20.  
  21. function deCompress($data, &$datLen) 
  22. $stLen = strlen($data); 
  23. $datLen = 0; 
  24. $ret = ""; 
  25. $dp = 0; // data pointer 
  26. // INITIALIZATION 
  27. $this->LZWCommandInit($data, $dp); 
  28.  
  29. while (($iIndex = $this->LZWCommand($data, $dp)) >= 0) { 
  30. $ret .= chr($iIndex); 
  31.  
  32. $datLen = $dp; 
  33.  
  34. if ($iIndex != -2) { 
  35. return false; 
  36.  
  37. return $ret; 
  38.  
  39. function LZWCommandInit(&$data, &$dp) 
  40. $this->SetCodeSize = ord($data[0]); 
  41. $dp += 1; 
  42.  
  43. $this->CodeSize = $this->SetCodeSize + 1; 
  44. $this->ClearCode = 1 << $this->SetCodeSize; 
  45. $this->EndCode = $this->ClearCode + 1; 
  46. $this->MaxCode = $this->ClearCode + 2; 
  47. $this->MaxCodeSize = $this->ClearCode << 1; 
  48.  
  49. $this->GetCodeInit($data, $dp); 
  50.  
  51. $this->Fresh = 1; 
  52. for ($i = 0; $i < $this->ClearCode; $i++) { 
  53. $this->Next[$i] = 0; 
  54. $this->Vals[$i] = $i; 
  55.  
  56. for (; $i < (1 << $this->MAX_LZW_BITS); $i++) { 
  57. $this->Next[$i] = 0; 
  58. $this->Vals[$i] = 0; 
  59.  
  60. $this->sp = 0; 
  61. return 1; 
  62.  
  63. function LZWCommand(&$data, &$dp) 
  64. if ($this->Fresh) { 
  65. $this->Fresh = 0; 
  66. do { 
  67. $this->FirstCode = $this->GetCode($data, $dp); 
  68. $this->OldCode = $this->FirstCode; 
  69. } while ($this->FirstCode == $this->ClearCode); 
  70.  
  71. return $this->FirstCode; 
  72.  
  73. if ($this->sp > 0) { 
  74. $this->sp--; 
  75. return $this->Stack[$this->sp]; 
  76.  
  77. while (($Code = $this->GetCode($data, $dp)) >= 0) { 
  78. if ($Code == $this->ClearCode) { 
  79. for ($i = 0; $i < $this->ClearCode; $i++) { 
  80. $this->Next[$i] = 0; 
  81. $this->Vals[$i] = $i; 
  82.  
  83. for (; $i < (1 << $this->MAX_LZW_BITS); $i++) { 
  84. $this->Next[$i] = 0; 
  85. $this->Vals[$i] = 0; 
  86.  
  87. $this->CodeSize = $this->SetCodeSize + 1; 
  88. $this->MaxCodeSize = $this->ClearCode << 1; 
  89. $this->MaxCode = $this->ClearCode + 2; 
  90. $this->sp = 0; 
  91. $this->FirstCode = $this->GetCode($data, $dp); 
  92. $this->OldCode = $this->FirstCode; 
  93.  
  94. return $this->FirstCode; 
  95.  
  96. if ($Code == $this->EndCode) { 
  97. return -2; 
  98.  
  99. $InCode = $Code; 
  100. if ($Code >= $this->MaxCode) { 
  101. $this->Stack[$this->sp++] = $this->FirstCode; 
  102. $Code = $this->OldCode; 
  103.  
  104. while ($Code >= $this->ClearCode) { 
  105. $this->Stack[$this->sp++] = $this->Vals[$Code]; 
  106.  
  107. if ($Code == $this->Next[$Code]) // Circular table entry, big GIF Error! 
  108. return -1; 
  109.  
  110. $Code = $this->Next[$Code]; 
  111.  
  112. $this->FirstCode = $this->Vals[$Code]; 
  113. $this->Stack[$this->sp++] = $this->FirstCode; 
  114.  
  115. if (($Code = $this->MaxCode) < (1 << $this->MAX_LZW_BITS)) { 
  116. $this->Next[$Code] = $this->OldCode; 
  117. $this->Vals[$Code] = $this->FirstCode; 
  118. $this->MaxCode++; 
  119.  
  120. if (($this->MaxCode >= $this->MaxCodeSize) && ($this->MaxCodeSize < (1 << $this->MAX_LZW_BITS))) { 
  121. $this->MaxCodeSize *= 2; 
  122. $this->CodeSize++; 
  123.  
  124. $this->OldCode = $InCode; 
  125. if ($this->sp > 0) { 
  126. $this->sp--; 
  127. return $this->Stack[$this->sp]; 
  128.  
  129. return $Code; 
  130.  
  131. function GetCodeInit(&$data, &$dp) 
  132. $this->CurBit = 0; 
  133. $this->LastBit = 0; 
  134. $this->Done = 0; 
  135. $this->LastByte = 2; 
  136. return 1; 
  137.  
  138. function GetCode(&$data, &$dp) 
  139. if (($this->CurBit + $this->CodeSize) >= $this->LastBit) { 
  140. if ($this->Done) { 
  141. if ($this->CurBit >= $this->LastBit) { 
  142. // Ran off the end of my bits 
  143. return 0; 
  144. return -1; 
  145.  
  146. $this->Buf[0] = $this->Buf[$this->LastByte - 2]; 
  147. $this->Buf[1] = $this->Buf[$this->LastByte - 1]; 
  148.  
  149. $Count = ord($data[$dp]); 
  150. $dp += 1; 
  151.  
  152. if ($Count) { 
  153. for ($i = 0; $i < $Count; $i++) { 
  154. $this->Buf[2 + $i] = ord($data[$dp + $i]); 
  155. $dp += $Count; 
  156. } else { 
  157. $this->Done = 1; 
  158.  
  159. $this->LastByte = 2 + $Count; 
  160. $this->CurBit = ($this->CurBit - $this->LastBit) + 16; 
  161. $this->LastBit = (2 + $Count) << 3; 
  162.  
  163. $iRet = 0; 
  164. for ($i = $this->CurBit, $j = 0; $j < $this->CodeSize; $i++, $j++) { 
  165. $iRet |= (($this->Buf[intval($i / 8)] & (1 << ($i % 8))) != 0) << $j; 
  166.  
  167. $this->CurBit += $this->CodeSize; 
  168. return $iRet; 
  169.