source-class-Com.Tecnick.Pdf.Filter.Type.RunLength

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.
 1: <?php
 2: /**
 3:  * RunLength.php
 4:  *
 5:  * @since       2011-05-23
 6:  * @category    Library
 7:  * @package     PdfFilter
 8:  * @author      Nicola Asuni <info@tecnick.com>
 9:  * @copyright   2011-2015 Nicola Asuni - Tecnick.com LTD
10:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
11:  * @link        https://github.com/tecnickcom/tc-lib-pdf-filter
12:  *
13:  * This file is part of tc-lib-pdf-filter software library.
14:  */
15: 
16: namespace Com\Tecnick\Pdf\Filter\Type;
17: 
18: use \Com\Tecnick\Pdf\Filter\Exception as PPException;
19: 
20: /**
21:  * Com\Tecnick\Pdf\Filter\Type\RunLength
22:  *
23:  * RunLengthe
24:  * Decompresses data encoded using the zlib/deflate compression method,
25:  * reproducing the original text or binary data.
26:  *
27:  * @since       2011-05-23
28:  * @category    Library
29:  * @package     PdfFilter
30:  * @author      Nicola Asuni <info@tecnick.com>
31:  * @copyright   2011-2015 Nicola Asuni - Tecnick.com LTD
32:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
33:  * @link        https://github.com/tecnickcom/tc-lib-pdf-filter
34:  */
35: class RunLength
36: {
37:     /**
38:      * Decode the data
39:      *
40:      * @param string $data Data to decode.
41:      *
42:      * @return string Decoded data string.
43:      */
44:     public function decode($data)
45:     {
46:         // initialize string to return
47:         $decoded = '';
48:         // data length
49:         $data_length = strlen($data);
50:         $idx = 0;
51:         while ($idx < $data_length) {
52:             // get current byte value
53:             $byte = ord($data[$idx]);
54:             if ($byte == 128) {
55:                 // a length value of 128 denote EOD
56:                 break;
57:             } elseif ($byte < 128) {
58:                 // if the length byte is in the range 0 to 127
59:                 // the following length + 1 (1 to 128) bytes shall be copied literally during decompression
60:                 $decoded .= substr($data, ($idx + 1), ($byte + 1));
61:                 // move to next block
62:                 $idx += ($byte + 2);
63:             } else {
64:                 // if length is in the range 129 to 255,
65:                 // the following single byte shall be copied 257 - length (2 to 128) times during decompression
66:                 $decoded .= str_repeat($data[($idx + 1)], (257 - $byte));
67:                 // move to next block
68:                 $idx += 2;
69:             }
70:         }
71:         return $decoded;
72:     }
73: }
74: 
 

© 2004-2017 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy