Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * @ This file is created by deZender.Net
- * @ deZender (PHP5 Decoder for ionCube Encoder)
- *
- * @ Version : 1.1.5.0
- * @ Author : DeZender
- * @ Release on : 09.06.2012
- * @ Official site : http://DeZender.Net
- *
- */
- class FilterPredictor {
- var $alwaysWritePredictorByte = true;
- function error($msg) {
- exit( $msg );
- }
- function paethPredictor($left, $above, $upperLeft) {
- $p = $left + $above - $upperLeft;
- $pLeft = abs( $p - $left );
- $pAbove = abs( $p - $above );
- $pUpperLeft = abs( $p - $upperLeft );
- if (( $pLeft <= $pAbove && $pLeft <= $pUpperLeft )) {
- return $left;
- }
- if ($pAbove <= $pUpperLeft) {
- return $above;
- }
- return $upperLeft;
- }
- function decode($data, $predictor = 0, $columns = null, $colors = null, $bitsPerComponent = null) {
- if ($predictor == 1) {
- return $data;
- }
- if ($predictor == 2) {
- return $this->error( 'TIFF predictor not yet supported' );
- }
- if (( 10 <= $predictor && $predictor <= 15 )) {
- $columns = (is_null( $columns ) ? 1 : (int)$columns);
- $colors = (is_null( $colors ) ? 1 : (int)$colors);
- $bitsPerComponent = (is_null( $bitsPerComponent ) ? 8 : (int)$bitsPerComponent);
- $bytesPerPixel = $colors * $bitsPerComponent / 8;
- $bytesPerRow = (int)( $colors * $columns * $bitsPerComponent + 7 ) / 8;
- $out = '';
- $currRowString = '';
- $offset = 0;
- $currRowData = array( );
- $priorRowData = array_fill( 0, $bytesPerRow, 0 );
- $currPredictor = $predictor;
- $eof = false;
- while (!$eof) {
- if (( $this->alwaysWritePredictorByte || $predictor == 15 )) {
- $currPredictor = ord( substr( $data, $offset++, 1 ) );
- if (!is_null( $currPredictor )) {
- $currPredictor += 10;
- } else {
- $eof = true;
- }
- }
- if (!$eof) {
- $currRowString = substr( $data, $offset, $bytesPerRow );
- if (strlen( $currRowString ) != $bytesPerRow) {
- $eof = true;
- if (strlen( $currRowString ) != 0) {
- return $this->error( 'Could not read complete row while decoding data' );
- }
- }
- if (!$eof) {
- $currRowData = array( );
- $currRowLength = strlen( $currRowString );
- $i = 0;
- while ($i < $currRowLength) {
- $currRowData[$i] = ord( $currRowString[$i] );
- ++$i;
- }
- switch ($currPredictor) {
- case 10: {
- break;
- }
- case 11: {
- $i = $bytesPerPixel;
- while ($i < $bytesPerRow) {
- $currRowData[$i] = $currRowData[$i] + $currRowData[$i - $bytesPerPixel] & 255;
- ++$i;
- }
- break;
- }
- case 12: {
- $i = 0;
- while ($i < $bytesPerRow) {
- $currRowData[$i] = $currRowData[$i] + $priorRowData[$i] & 255;
- ++$i;
- }
- break;
- }
- case 13: {
- $i = 0;
- while ($i < $bytesPerPixel) {
- $currRowData[$i] = $currRowData[$i] + floor( $priorRowData[$i] / 2 ) & 255;
- ++$i;
- }
- $i = $bytesPerPixel;
- while ($i < $bytesPerRow) {
- $currRowData[$i] = $currRowData[$i] + floor( ( $currRowData[$i - $bytesPerPixel] + $priorRowData[$i] ) / 2 ) & 255;
- ++$i;
- }
- break;
- }
- case 14: {
- $i = 0;
- while ($i < $bytesPerRow) {
- $left = ($i < $bytesPerPixel ? 0 : $currRowData[$i - $bytesPerPixel]);
- $above = $priorRowData[$i];
- $upperLeft = ($i < $bytesPerPixel ? 0 : $priorRowData[$i - $bytesPerPixel]);
- $predicted = $this->paethPredictor( $left, $above, $upperLeft );
- $currRowData[$i] = $currRowData[$i] + $predicted & 255;
- ++$i;
- }
- break;
- }
- default: {
- $this->error( 'unrecognized png predictor (' . $currPredictor . ') while decoding data' );
- }
- }
- return ;
- $i = 0;
- while ($i < $currRowLength) {
- $out .= chr( $currRowData[$i] );
- ++$i;
- }
- $priorRowData = $currRowData;
- $offset += $bytesPerRow;
- continue;
- }
- continue;
- }
- }
- return $out;
- }
- return $this->error( 'unrecognized predictor: ' . $predictor );
- }
- ........................................................
- .............................
- ..........
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement