Advertisement
Guest User

Untitled

a guest
Sep 12th, 2012
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by deZender.Net
  5. * @ deZender (PHP5 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 1.1.5.0
  8. * @ Author : DeZender
  9. * @ Release on : 09.06.2012
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. class FilterPredictor {
  15. var $alwaysWritePredictorByte = true;
  16.  
  17. function error($msg) {
  18. exit( $msg );
  19. }
  20.  
  21. function paethPredictor($left, $above, $upperLeft) {
  22. $p = $left + $above - $upperLeft;
  23. $pLeft = abs( $p - $left );
  24. $pAbove = abs( $p - $above );
  25. $pUpperLeft = abs( $p - $upperLeft );
  26.  
  27. if (( $pLeft <= $pAbove && $pLeft <= $pUpperLeft )) {
  28. return $left;
  29. }
  30.  
  31.  
  32. if ($pAbove <= $pUpperLeft) {
  33. return $above;
  34. }
  35.  
  36. return $upperLeft;
  37. }
  38.  
  39. function decode($data, $predictor = 0, $columns = null, $colors = null, $bitsPerComponent = null) {
  40. if ($predictor == 1) {
  41. return $data;
  42. }
  43.  
  44.  
  45. if ($predictor == 2) {
  46. return $this->error( 'TIFF predictor not yet supported' );
  47. }
  48.  
  49.  
  50. if (( 10 <= $predictor && $predictor <= 15 )) {
  51. $columns = (is_null( $columns ) ? 1 : (int)$columns);
  52. $colors = (is_null( $colors ) ? 1 : (int)$colors);
  53. $bitsPerComponent = (is_null( $bitsPerComponent ) ? 8 : (int)$bitsPerComponent);
  54. $bytesPerPixel = $colors * $bitsPerComponent / 8;
  55. $bytesPerRow = (int)( $colors * $columns * $bitsPerComponent + 7 ) / 8;
  56. $out = '';
  57. $currRowString = '';
  58. $offset = 0;
  59. $currRowData = array( );
  60. $priorRowData = array_fill( 0, $bytesPerRow, 0 );
  61. $currPredictor = $predictor;
  62. $eof = false;
  63.  
  64. while (!$eof) {
  65. if (( $this->alwaysWritePredictorByte || $predictor == 15 )) {
  66. $currPredictor = ord( substr( $data, $offset++, 1 ) );
  67.  
  68. if (!is_null( $currPredictor )) {
  69. $currPredictor += 10;
  70. } else {
  71. $eof = true;
  72. }
  73. }
  74.  
  75.  
  76. if (!$eof) {
  77. $currRowString = substr( $data, $offset, $bytesPerRow );
  78.  
  79. if (strlen( $currRowString ) != $bytesPerRow) {
  80. $eof = true;
  81.  
  82. if (strlen( $currRowString ) != 0) {
  83. return $this->error( 'Could not read complete row while decoding data' );
  84. }
  85. }
  86.  
  87.  
  88. if (!$eof) {
  89. $currRowData = array( );
  90. $currRowLength = strlen( $currRowString );
  91. $i = 0;
  92.  
  93. while ($i < $currRowLength) {
  94. $currRowData[$i] = ord( $currRowString[$i] );
  95. ++$i;
  96. }
  97.  
  98. switch ($currPredictor) {
  99. case 10: {
  100. break;
  101. }
  102.  
  103. case 11: {
  104. $i = $bytesPerPixel;
  105.  
  106. while ($i < $bytesPerRow) {
  107. $currRowData[$i] = $currRowData[$i] + $currRowData[$i - $bytesPerPixel] & 255;
  108. ++$i;
  109. }
  110.  
  111. break;
  112. }
  113.  
  114. case 12: {
  115. $i = 0;
  116.  
  117. while ($i < $bytesPerRow) {
  118. $currRowData[$i] = $currRowData[$i] + $priorRowData[$i] & 255;
  119. ++$i;
  120. }
  121.  
  122. break;
  123. }
  124.  
  125. case 13: {
  126. $i = 0;
  127.  
  128. while ($i < $bytesPerPixel) {
  129. $currRowData[$i] = $currRowData[$i] + floor( $priorRowData[$i] / 2 ) & 255;
  130. ++$i;
  131. }
  132.  
  133. $i = $bytesPerPixel;
  134.  
  135. while ($i < $bytesPerRow) {
  136. $currRowData[$i] = $currRowData[$i] + floor( ( $currRowData[$i - $bytesPerPixel] + $priorRowData[$i] ) / 2 ) & 255;
  137. ++$i;
  138. }
  139.  
  140. break;
  141. }
  142.  
  143. case 14: {
  144. $i = 0;
  145.  
  146. while ($i < $bytesPerRow) {
  147. $left = ($i < $bytesPerPixel ? 0 : $currRowData[$i - $bytesPerPixel]);
  148. $above = $priorRowData[$i];
  149. $upperLeft = ($i < $bytesPerPixel ? 0 : $priorRowData[$i - $bytesPerPixel]);
  150. $predicted = $this->paethPredictor( $left, $above, $upperLeft );
  151. $currRowData[$i] = $currRowData[$i] + $predicted & 255;
  152. ++$i;
  153. }
  154.  
  155. break;
  156. }
  157.  
  158. default: {
  159. $this->error( 'unrecognized png predictor (' . $currPredictor . ') while decoding data' );
  160. }
  161. }
  162.  
  163. return ;
  164. $i = 0;
  165.  
  166. while ($i < $currRowLength) {
  167. $out .= chr( $currRowData[$i] );
  168. ++$i;
  169. }
  170.  
  171. $priorRowData = $currRowData;
  172. $offset += $bytesPerRow;
  173. continue;
  174. }
  175.  
  176. continue;
  177. }
  178. }
  179.  
  180. return $out;
  181. }
  182.  
  183. return $this->error( 'unrecognized predictor: ' . $predictor );
  184. }
  185. ........................................................
  186. .............................
  187. ..........
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement