]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/mpdf/mpdfi/filters/FilterLZW.php
3 // FPDI - Version 1.3.1
5 // Copyright 2004-2009 Setasign - Jan Slabon
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
22 var $sTable = array();
31 var $andTable = array(511, 1023, 2047, 4095);
33 function error($msg) {
38 * Method to decode LZW compressed data.
40 * @param string data The compressed data.
42 function decode($data) {
44 if($data[0] == 0x00 && $data[1] == 0x01) {
45 $this->error('LZW flavour not supported.');
51 $this->dataLength
= strlen($data);
53 // Initialize pointers
54 $this->bytePointer
= 0;
55 $this->bitPointer
= 0;
65 while (($code = $this->getNextCode()) != 257) {
68 $code = $this->getNextCode();
74 $uncompData .= $this->sTable
[$code];
79 if ($code < $this->tIdx
) {
80 $string = $this->sTable
[$code];
81 $uncompData .= $string;
83 $this->addStringToTable($this->sTable
[$oldCode], $string[0]);
86 $string = $this->sTable
[$oldCode];
87 $string = $string.$string[0];
88 $uncompData .= $string;
90 $this->addStringToTable($string);
101 * Initialize the string table.
103 function initsTable() {
104 $this->sTable
= array();
106 for ($i = 0; $i < 256; $i++
)
107 $this->sTable
[$i] = chr($i);
110 $this->bitsToGet
= 9;
114 * Add a new string to the string table.
116 function addStringToTable ($oldString, $newString='') {
117 $string = $oldString.$newString;
119 // Add this new String to the table
120 $this->sTable
[$this->tIdx++
] = $string;
122 if ($this->tIdx
== 511) {
123 $this->bitsToGet
= 10;
124 } else if ($this->tIdx
== 1023) {
125 $this->bitsToGet
= 11;
126 } else if ($this->tIdx
== 2047) {
127 $this->bitsToGet
= 12;
131 // Returns the next 9, 10, 11 or 12 bits
132 function getNextCode() {
133 if ($this->bytePointer
== $this->dataLength
) {
137 $this->nextData
= ($this->nextData
<< 8) | (ord($this->data
[$this->bytePointer++
]) & 0xff);
138 $this->nextBits +
= 8;
140 if ($this->nextBits
< $this->bitsToGet
) {
141 $this->nextData
= ($this->nextData
<< 8) | (ord($this->data
[$this->bytePointer++
]) & 0xff);
142 $this->nextBits +
= 8;
145 $code = ($this->nextData
>> ($this->nextBits
- $this->bitsToGet
)) & $this->andTable
[$this->bitsToGet
-9];
146 $this->nextBits
-= $this->bitsToGet
;
151 function encode($in) {
152 $this->error("LZW encoding not implemented.");