first commit
This commit is contained in:
97
standort/prints/decoders/ascii85.php
Normal file
97
standort/prints/decoders/ascii85.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
//
|
||||
// FPDI - Version 1.1
|
||||
//
|
||||
// Copyright 2004,2005 Setasign - Jan Slabon
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
if (!defined("ORD_z"))
|
||||
define("ORD_z",ord('z'));
|
||||
if (!defined("ORD_!"))
|
||||
define("ORD_exclmark", ord('!'));
|
||||
if (!defined("ORD_u"))
|
||||
define("ORD_u", ord("u"));
|
||||
if (!defined("ORD_tilde"))
|
||||
define("ORD_tilde", ord('~'));
|
||||
|
||||
class ASCII85Decode {
|
||||
|
||||
function ASCII85Decode(&$fpdi) {
|
||||
$this->fpdi =& $fpdi;
|
||||
}
|
||||
|
||||
|
||||
function decode($in) {
|
||||
$out = "";
|
||||
$state = 0;
|
||||
$chn = null;
|
||||
|
||||
$l = strlen($in);
|
||||
|
||||
for ($k = 0; $k < $l; ++$k) {
|
||||
$ch = ord($in[$k]) & 0xff;
|
||||
|
||||
if ($ch == ORD_tilde) {
|
||||
break;
|
||||
}
|
||||
if (preg_match("/^\s$/",chr($ch))) {
|
||||
continue;
|
||||
}
|
||||
if ($ch == ORD_z && $state == 0) {
|
||||
$out .= chr(0).chr(0).chr(0).chr(0);
|
||||
continue;
|
||||
}
|
||||
if ($ch < ORD_exclmark || $ch > ORD_u) {
|
||||
$this->fpdi->error("Illegal character in ASCII85Decode.");
|
||||
}
|
||||
|
||||
$chn[$state++] = $ch - ORD_exclmark;
|
||||
|
||||
if ($state == 5) {
|
||||
$state = 0;
|
||||
$r = 0;
|
||||
for ($j = 0; $j < 5; ++$j)
|
||||
$r = $r * 85 + $chn[$j];
|
||||
$out .= chr($r >> 24);
|
||||
$out .= chr($r >> 16);
|
||||
$out .= chr($r >> 8);
|
||||
$out .= chr($r);
|
||||
}
|
||||
}
|
||||
$r = 0;
|
||||
|
||||
if ($state == 1)
|
||||
$this->fpdi->error("Illegal length in ASCII85Decode.");
|
||||
if ($state == 2) {
|
||||
$r = $chn[0] * 85 * 85 * 85 * 85 + ($chn[1]+1) * 85 * 85 * 85;
|
||||
$out .= chr($r >> 24);
|
||||
}
|
||||
else if ($state == 3) {
|
||||
$r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85 + ($chn[2]+1) * 85 * 85;
|
||||
$out .= chr($r >> 24);
|
||||
$out .= chr($r >> 16);
|
||||
}
|
||||
else if ($state == 4) {
|
||||
$r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85 + $chn[2] * 85 * 85 + ($chn[3]+1) * 85 ;
|
||||
$out .= chr($r >> 24);
|
||||
$out .= chr($r >> 16);
|
||||
$out .= chr($r >> 8);
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
151
standort/prints/decoders/lzw.php
Normal file
151
standort/prints/decoders/lzw.php
Normal file
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
//
|
||||
// FPDI - Version 1.1
|
||||
//
|
||||
// Copyright 2004,2005 Setasign - Jan Slabon
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
class LZWDecode {
|
||||
|
||||
var $sTable = array();
|
||||
var $data = null;
|
||||
var $tIdx;
|
||||
var $bitsToGet = 9;
|
||||
var $bytePointer;
|
||||
var $bitPointer;
|
||||
var $nextData = 0;
|
||||
var $nextBits = 0;
|
||||
var $andTable = array(511, 1023, 2047, 4095);
|
||||
|
||||
function LZWDecode(&$fpdi) {
|
||||
$this->fpdi =& $fpdi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to decode LZW compressed data.
|
||||
*
|
||||
* @param string data The compressed data.
|
||||
*/
|
||||
function decode(&$data) {
|
||||
|
||||
if($data[0] == 0x00 && $data[1] == 0x01) {
|
||||
$this->fpdi->error("LZW flavour not supported.");
|
||||
}
|
||||
|
||||
$this->initsTable();
|
||||
|
||||
$this->data =& $data;
|
||||
|
||||
// Initialize pointers
|
||||
$this->bytePointer = 0;
|
||||
$this->bitPointer = 0;
|
||||
|
||||
$this->nextData = 0;
|
||||
$this->nextBits = 0;
|
||||
|
||||
$oldCode = 0;
|
||||
|
||||
$string = "";
|
||||
$uncompData = "";
|
||||
|
||||
while (($code = $this->getNextCode()) != 257) {
|
||||
if ($code == 256) {
|
||||
$this->initsTable();
|
||||
$code = $this->getNextCode();
|
||||
|
||||
if ($code == 257) {
|
||||
break;
|
||||
}
|
||||
|
||||
$uncompData .= $this->sTable[$code];
|
||||
$oldCode = $code;
|
||||
|
||||
} else {
|
||||
|
||||
if ($code < $this->tIdx) {
|
||||
$string = $this->sTable[$code];
|
||||
$uncompData .= $string;
|
||||
|
||||
$this->addStringToTable($this->sTable[$oldCode], $string[0]);
|
||||
$oldCode = $code;
|
||||
} else {
|
||||
$string = $this->sTable[$oldCode];
|
||||
$string = $string.$string[0];
|
||||
$uncompData .= $string;
|
||||
|
||||
$this->addStringToTable($string);
|
||||
$oldCode = $code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $uncompData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize the string table.
|
||||
*/
|
||||
function initsTable() {
|
||||
$this->sTable = array();
|
||||
|
||||
for ($i = 0; $i < 256; $i++)
|
||||
$this->sTable[$i] = chr($i);
|
||||
|
||||
$this->tIdx = 258;
|
||||
$this->bitsToGet = 9;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new string to the string table.
|
||||
*/
|
||||
function addStringToTable ($oldString, $newString="") {
|
||||
$string = $oldString.$newString;
|
||||
|
||||
// Add this new String to the table
|
||||
$this->sTable[$this->tIdx++] = $string;
|
||||
|
||||
if ($this->tIdx == 511) {
|
||||
$this->bitsToGet = 10;
|
||||
} else if ($this->tIdx == 1023) {
|
||||
$this->bitsToGet = 11;
|
||||
} else if ($this->tIdx == 2047) {
|
||||
$this->bitsToGet = 12;
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the next 9, 10, 11 or 12 bits
|
||||
function getNextCode() {
|
||||
if ($this->bytePointer == strlen($this->data))
|
||||
return 257;
|
||||
|
||||
$this->nextData = ($this->nextData << 8) | (ord($this->data[$this->bytePointer++]) & 0xff);
|
||||
$this->nextBits += 8;
|
||||
|
||||
if ($this->nextBits < $this->bitsToGet) {
|
||||
$this->nextData = ($this->nextData << 8) | (ord($this->data[$this->bytePointer++]) & 0xff);
|
||||
$this->nextBits += 8;
|
||||
}
|
||||
|
||||
$code = ($this->nextData >> ($this->nextBits - $this->bitsToGet)) & $this->andTable[$this->bitsToGet-9];
|
||||
$this->nextBits -= $this->bitsToGet;
|
||||
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
Reference in New Issue
Block a user