Issues (4542)

config/qrcode/qrinput.php (9 issues)

1
<?php
2
/*
3
 * PHP QR Code encoder
4
 *
5
 * Input encoding class
6
 *
7
 * Based on libqrencode C library distributed under LGPL 2.1
8
 * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <[email protected]>
9
 *
10
 * PHP QR Code is distributed under LGPL 3
11
 * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
12
 *
13
 * This library is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU Lesser General Public
15
 * License as published by the Free Software Foundation; either
16
 * version 3 of the License, or any later version.
17
 *
18
 * This library is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21
 * Lesser General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Lesser General Public
24
 * License along with this library; if not, write to the Free Software
25
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
 */
27
28
    define('STRUCTURE_HEADER_BITS', 20);
29
    define('MAX_STRUCTURED_SYMBOLS', 16);
30
31
    class QRinputItem
32
    {
33
        public $mode;
34
        public $size;
35
        public $data;
36
        public $bstream;
37
38
        public function __construct($mode, $size, $data, $bstream = null)
39
        {
40
            $setData = array_slice($data, 0, $size);
41
42
            if (count($setData) < $size) {
43
                $setData = array_merge($setData, array_fill(0, $size - count($setData), 0));
44
            }
45
46
            if (!QRinput::check($mode, $size, $setData)) {
47
                throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.implode(',', $setData));
48
                return;
0 ignored issues
show
return is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
49
            }
50
51
            $this->mode = $mode;
52
            $this->size = $size;
53
            $this->data = $setData;
54
            $this->bstream = $bstream;
55
        }
56
57
        //----------------------------------------------------------------------
58
        public function encodeModeNum($version)
59
        {
60
            try {
61
                $words = (int) ($this->size / 3);
62
                $bs = new QRbitstream();
63
64
                $val = 0x1;
65
                $bs->appendNum(4, $val);
66
                $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size);
67
68
                for ($i = 0; $i < $words; $i++) {
69
                    $val = (ord($this->data[$i * 3]) - ord('0')) * 100;
70
                    $val += (ord($this->data[$i * 3 + 1]) - ord('0')) * 10;
71
                    $val += (ord($this->data[$i * 3 + 2]) - ord('0'));
72
                    $bs->appendNum(10, $val);
73
                }
74
75
                if ($this->size - $words * 3 == 1) {
76
                    $val = ord($this->data[$words * 3]) - ord('0');
77
                    $bs->appendNum(4, $val);
78
                } elseif ($this->size - $words * 3 == 2) {
79
                    $val = (ord($this->data[$words * 3]) - ord('0')) * 10;
80
                    $val += (ord($this->data[$words * 3 + 1]) - ord('0'));
81
                    $bs->appendNum(7, $val);
82
                }
83
84
                $this->bstream = $bs;
85
86
                return 0;
87
            } catch (Exception $e) {
88
                return 0;
89
            }
90
        }
91
92
        //----------------------------------------------------------------------
93
        public function encodeModeAn($version)
94
        {
95
            try {
96
                $words = (int) ($this->size / 2);
97
                $bs = new QRbitstream();
98
99
                $bs->appendNum(4, 0x02);
100
                $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size);
101
102
                for ($i = 0; $i < $words; $i++) {
103
                    $val = (int) QRinput::lookAnTable(ord($this->data[$i * 2])) * 45;
104
                    $val += (int) QRinput::lookAnTable(ord($this->data[$i * 2 + 1]));
105
106
                    $bs->appendNum(11, $val);
107
                }
108
109
                if ($this->size & 1) {
110
                    $val = QRinput::lookAnTable(ord($this->data[$words * 2]));
111
                    $bs->appendNum(6, $val);
112
                }
113
114
                $this->bstream = $bs;
115
116
                return 0;
117
            } catch (Exception $e) {
118
                return 0;
119
            }
120
        }
121
122
        //----------------------------------------------------------------------
123
        public function encodeMode8($version)
124
        {
125
            try {
126
                $bs = new QRbitstream();
127
128
                $bs->appendNum(4, 0x4);
129
                $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size);
130
131
                for ($i = 0; $i < $this->size; $i++) {
132
                    $bs->appendNum(8, ord($this->data[$i]));
133
                }
134
135
                $this->bstream = $bs;
136
137
                return 0;
138
            } catch (Exception $e) {
139
                return 0;
140
            }
141
        }
142
143
        //----------------------------------------------------------------------
144
        public function encodeModeKanji($version)
145
        {
146
            try {
147
                $bs = new QRbitrtream();
0 ignored issues
show
The type QRbitrtream was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
148
149
                $bs->appendNum(4, 0x8);
150
                $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int) ($this->size / 2));
151
152
                for ($i = 0; $i < $this->size; $i += 2) {
153
                    $val = (ord($this->data[$i]) << 8) | ord($this->data[$i + 1]);
154
                    if ($val <= 0x9ffc) {
155
                        $val -= 0x8140;
156
                    } else {
157
                        $val -= 0xc140;
158
                    }
159
160
                    $h = ($val >> 8) * 0xc0;
161
                    $val = ($val & 0xff) + $h;
162
163
                    $bs->appendNum(13, $val);
164
                }
165
166
                $this->bstream = $bs;
167
168
                return 0;
169
            } catch (Exception $e) {
170
                return 0;
171
            }
172
        }
173
174
        //----------------------------------------------------------------------
175
        public function encodeModeStructure()
176
        {
177
            try {
178
                $bs = new QRbitstream();
179
180
                $bs->appendNum(4, 0x03);
181
                $bs->appendNum(4, ord($this->data[1]) - 1);
182
                $bs->appendNum(4, ord($this->data[0]) - 1);
183
                $bs->appendNum(8, ord($this->data[2]));
184
185
                $this->bstream = $bs;
186
187
                return 0;
188
            } catch (Exception $e) {
189
                return 0;
190
            }
191
        }
192
193
        //----------------------------------------------------------------------
194
        public function estimateBitStreamSizeOfEntry($version)
195
        {
196
            $bits = 0;
197
198
            if ($version == 0) {
199
                $version = 1;
200
            }
201
202
            switch ($this->mode) {
203
                case QR_MODE_NUM:        $bits = QRinput::estimateBitsModeNum($this->size); break;
204
                case QR_MODE_AN:        $bits = QRinput::estimateBitsModeAn($this->size); break;
205
                case QR_MODE_8:            $bits = QRinput::estimateBitsMode8($this->size); break;
206
                case QR_MODE_KANJI:        $bits = QRinput::estimateBitsModeKanji($this->size); break;
0 ignored issues
show
Bug Best Practice introduced by
The method QRinput::estimateBitsModeKanji() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

206
                case QR_MODE_KANJI:        /** @scrutinizer ignore-call */ $bits = QRinput::estimateBitsModeKanji($this->size); break;
Loading history...
207
                case QR_MODE_STRUCTURE:    return STRUCTURE_HEADER_BITS;
208
                default:
209
                    return 0;
210
            }
211
212
            $l = QRspec::lengthIndicator($this->mode, $version);
213
            $m = 1 << $l;
214
            $num = (int) (($this->size + $m - 1) / $m);
215
216
            $bits += $num * (4 + $l);
217
218
            return $bits;
219
        }
220
221
        //----------------------------------------------------------------------
222
        public function encodeBitStream($version)
223
        {
224
            try {
225
                unset($this->bstream);
226
                $words = QRspec::maximumWords($this->mode, $version);
227
228
                if ($this->size > $words) {
229
                    $st1 = new self($this->mode, $words, $this->data);
230
                    $st2 = new self($this->mode, $this->size - $words, array_slice($this->data, $words));
231
232
                    $st1->encodeBitStream($version);
233
                    $st2->encodeBitStream($version);
234
235
                    $this->bstream = new QRbitstream();
236
                    $this->bstream->append($st1->bstream);
237
                    $this->bstream->append($st2->bstream);
238
239
                    unset($st1);
240
                    unset($st2);
241
                } else {
242
                    $ret = 0;
243
244
                    switch ($this->mode) {
245
                        case QR_MODE_NUM:        $ret = $this->encodeModeNum($version); break;
246
                        case QR_MODE_AN:        $ret = $this->encodeModeAn($version); break;
247
                        case QR_MODE_8:            $ret = $this->encodeMode8($version); break;
248
                        case QR_MODE_KANJI:        $ret = $this->encodeModeKanji($version); break;
249
                        case QR_MODE_STRUCTURE:    $ret = $this->encodeModeStructure(); break;
250
251
                        default:
252
                            break;
253
                    }
254
255
                    if ($ret < 0) {
256
                        return 0;
257
                    }
258
                }
259
260
                return $this->bstream->size();
261
            } catch (Exception $e) {
262
                return 0;
263
            }
264
        }
265
    }
266
267
    //##########################################################################
268
269
    class QRinput
270
    {
271
        public $items;
272
273
        private $version;
274
        private $level;
275
276
        //----------------------------------------------------------------------
277
        public function __construct($version = 0, $level = QR_ECLEVEL_L)
278
        {
279
            if ($version < 0 || $version > QRSPEC_VERSION_MAX || $level > QR_ECLEVEL_H) {
280
                throw new Exception('Invalid version no');
281
                return false;
0 ignored issues
show
return false is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
282
            }
283
284
            $this->version = $version;
285
            $this->level = $level;
286
        }
287
288
        //----------------------------------------------------------------------
289
        public function getVersion()
290
        {
291
            return $this->version;
292
        }
293
294
        //----------------------------------------------------------------------
295
        public function setVersion($version)
296
        {
297
            if ($version < 0 || $version > QRSPEC_VERSION_MAX) {
298
                throw new Exception('Invalid version no');
299
                return 0;
0 ignored issues
show
return 0 is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
300
            }
301
302
            $this->version = $version;
303
304
            return 0;
305
        }
306
307
        //----------------------------------------------------------------------
308
        public function getErrorCorrectionLevel()
309
        {
310
            return $this->level;
311
        }
312
313
        //----------------------------------------------------------------------
314
        public function setErrorCorrectionLevel($level)
315
        {
316
            if ($level > QR_ECLEVEL_H) {
317
                throw new Exception('Invalid ECLEVEL');
318
                return 0;
0 ignored issues
show
return 0 is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
319
            }
320
321
            $this->level = $level;
322
323
            return 0;
324
        }
325
326
        //----------------------------------------------------------------------
327
        public function appendEntry(QRinputItem $entry)
328
        {
329
            $this->items[] = $entry;
330
        }
331
332
        //----------------------------------------------------------------------
333
        public function append($mode, $size, $data)
334
        {
335
            try {
336
                $entry = new QRinputItem($mode, $size, $data);
337
                $this->items[] = $entry;
338
339
                return 0;
340
            } catch (Exception $e) {
341
                return 0;
342
            }
343
        }
344
345
        //----------------------------------------------------------------------
346
347
        public function insertStructuredAppendHeader($size, $index, $parity)
348
        {
349
            if ($size > MAX_STRUCTURED_SYMBOLS) {
350
                throw new Exception('insertStructuredAppendHeader wrong size');
351
            }
352
353
            if ($index <= 0 || $index > MAX_STRUCTURED_SYMBOLS) {
354
                throw new Exception('insertStructuredAppendHeader wrong index');
355
            }
356
357
            $buf = [$size, $index, $parity];
0 ignored issues
show
The assignment to $buf is dead and can be removed.
Loading history...
358
359
            try {
360
                $entry = new QRinputItem(QR_MODE_STRUCTURE, 3, buf);
0 ignored issues
show
The constant buf was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
361
                array_unshift($this->items, $entry);
362
363
                return 0;
364
            } catch (Exception $e) {
365
                return 0;
366
            }
367
        }
368
369
        //----------------------------------------------------------------------
370
        public function calcParity()
371
        {
372
            $parity = 0;
373
374
            foreach ($this->items as $item) {
375
                if ($item->mode != QR_MODE_STRUCTURE) {
376
                    for ($i = $item->size - 1; $i >= 0; $i--) {
377
                        $parity ^= $item->data[$i];
378
                    }
379
                }
380
            }
381
382
            return $parity;
383
        }
384
385
        //----------------------------------------------------------------------
386
        public static function checkModeNum($size, $data)
387
        {
388
            for ($i = 0; $i < $size; $i++) {
389
                if ((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))) {
390
                    return false;
391
                }
392
            }
393
394
            return true;
395
        }
396
397
        //----------------------------------------------------------------------
398
        public static function estimateBitsModeNum($size)
399
        {
400
            $w = (int) $size / 3;
401
            $bits = $w * 10;
402
403
            switch ($size - $w * 3) {
404
                case 1:
405
                    $bits += 4;
406
                    break;
407
                case 2:
408
                    $bits += 7;
409
                    break;
410
                default:
411
                    break;
412
            }
413
414
            return $bits;
415
        }
416
417
        //----------------------------------------------------------------------
418
        public static $anTable = [
419
            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
420
            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
421
            36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43,
422
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1,
423
            -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
424
            25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
425
            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
426
            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
427
        ];
428
429
        //----------------------------------------------------------------------
430
        public static function lookAnTable($c)
431
        {
432
            return ($c > 127) ? -1 : self::$anTable[$c];
433
        }
434
435
        //----------------------------------------------------------------------
436
        public static function checkModeAn($size, $data)
437
        {
438
            for ($i = 0; $i < $size; $i++) {
439
                if (self::lookAnTable(ord($data[$i])) == -1) {
440
                    return false;
441
                }
442
            }
443
444
            return true;
445
        }
446
447
        //----------------------------------------------------------------------
448
        public static function estimateBitsModeAn($size)
449
        {
450
            $w = (int) ($size / 2);
451
            $bits = $w * 11;
452
453
            if ($size & 1) {
454
                $bits += 6;
455
            }
456
457
            return $bits;
458
        }
459
460
        //----------------------------------------------------------------------
461
        public static function estimateBitsMode8($size)
462
        {
463
            return $size * 8;
464
        }
465
466
        //----------------------------------------------------------------------
467
        public function estimateBitsModeKanji($size)
468
        {
469
            return (int) (($size / 2) * 13);
470
        }
471
472
        //----------------------------------------------------------------------
473
        public static function checkModeKanji($size, $data)
474
        {
475
            if ($size & 1) {
476
                return false;
477
            }
478
479
            for ($i = 0; $i < $size; $i += 2) {
480
                $val = (ord($data[$i]) << 8) | ord($data[$i + 1]);
481
                if ($val < 0x8140
482
                || ($val > 0x9ffc && $val < 0xe040)
483
                || $val > 0xebbf) {
484
                    return false;
485
                }
486
            }
487
488
            return true;
489
        }
490
491
        /***********************************************************************
492
         * Validation
493
         **********************************************************************/
494
495
        public static function check($mode, $size, $data)
496
        {
497
            if ($size <= 0) {
498
                return false;
499
            }
500
501
            switch ($mode) {
502
                case QR_MODE_NUM:       return self::checkModeNum($size, $data);
503
                case QR_MODE_AN:        return self::checkModeAn($size, $data);
504
                case QR_MODE_KANJI:     return self::checkModeKanji($size, $data);
505
                case QR_MODE_8:         return true;
506
                case QR_MODE_STRUCTURE: return true;
507
508
                default:
509
                    break;
510
            }
511
512
            return false;
513
        }
514
515
        //----------------------------------------------------------------------
516
        public function estimateBitStreamSize($version)
517
        {
518
            $bits = 0;
519
520
            foreach ($this->items as $item) {
521
                $bits += $item->estimateBitStreamSizeOfEntry($version);
522
            }
523
524
            return $bits;
525
        }
526
527
        //----------------------------------------------------------------------
528
        public function estimateVersion()
529
        {
530
            $version = 0;
531
            do {
532
                $prev = $version;
533
                $bits = $this->estimateBitStreamSize($prev);
534
                $version = QRspec::getMinimumVersion((int) (($bits + 7) / 8), $this->level);
535
                if ($version < 0) {
536
                    return 0;
537
                }
538
            } while ($version > $prev);
539
540
            return $version;
541
        }
542
543
        //----------------------------------------------------------------------
544
        public static function lengthOfCode($mode, $version, $bits)
545
        {
546
            $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version);
547
            switch ($mode) {
548
                case QR_MODE_NUM:
549
                    $chunks = (int) ($payload / 10);
550
                    $remain = $payload - $chunks * 10;
551
                    $size = $chunks * 3;
552
                    if ($remain >= 7) {
553
                        $size += 2;
554
                    } elseif ($remain >= 4) {
555
                        $size += 1;
556
                    }
557
                    break;
558
                case QR_MODE_AN:
559
                    $chunks = (int) ($payload / 11);
560
                    $remain = $payload - $chunks * 11;
561
                    $size = $chunks * 2;
562
                    if ($remain >= 6) {
563
                        $size++;
564
                    }
565
                    break;
566
                case QR_MODE_8:
567
                    $size = (int) ($payload / 8);
568
                    break;
569
                case QR_MODE_KANJI:
570
                    $size = (int) (($payload / 13) * 2);
571
                    break;
572
                case QR_MODE_STRUCTURE:
573
                    $size = (int) ($payload / 8);
574
                    break;
575
                default:
576
                    $size = 0;
577
                    break;
578
            }
579
580
            $maxsize = QRspec::maximumWords($mode, $version);
581
            if ($size < 0) {
582
                $size = 0;
583
            }
584
            if ($size > $maxsize) {
585
                $size = $maxsize;
586
            }
587
588
            return $size;
589
        }
590
591
        //----------------------------------------------------------------------
592
        public function createBitStream()
593
        {
594
            $total = 0;
595
596
            foreach ($this->items as $item) {
597
                $bits = $item->encodeBitStream($this->version);
598
599
                if ($bits < 0) {
600
                    return 0;
601
                }
602
603
                $total += $bits;
604
            }
605
606
            return $total;
607
        }
608
609
        //----------------------------------------------------------------------
610
        public function convertData()
611
        {
612
            $ver = $this->estimateVersion();
613
            if ($ver > $this->getVersion()) {
614
                $this->setVersion($ver);
615
            }
616
617
            for (; ;) {
618
                $bits = $this->createBitStream();
619
620
                if ($bits < 0) {
621
                    return 0;
622
                }
623
624
                $ver = QRspec::getMinimumVersion((int) (($bits + 7) / 8), $this->level);
625
                if ($ver < 0) {
626
                    throw new Exception('WRONG VERSION');
627
                    return 0;
0 ignored issues
show
return 0 is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
628
                } elseif ($ver > $this->getVersion()) {
629
                    $this->setVersion($ver);
630
                } else {
631
                    break;
632
                }
633
            }
634
635
            return 0;
636
        }
637
638
        //----------------------------------------------------------------------
639
        public function appendPaddingBit(&$bstream)
640
        {
641
            $bits = $bstream->size();
642
            $maxwords = QRspec::getDataLength($this->version, $this->level);
643
            $maxbits = $maxwords * 8;
644
645
            if ($maxbits == $bits) {
646
                return 0;
647
            }
648
649
            if ($maxbits - $bits < 5) {
650
                return $bstream->appendNum($maxbits - $bits, 0);
651
            }
652
653
            $bits += 4;
654
            $words = (int) (($bits + 7) / 8);
655
656
            $padding = new QRbitstream();
657
            $ret = $padding->appendNum($words * 8 - $bits + 4, 0);
658
659
            if ($ret < 0) {
660
                return $ret;
661
            }
662
663
            $padlen = $maxwords - $words;
664
665
            if ($padlen > 0) {
666
                $padbuf = [];
667
                for ($i = 0; $i < $padlen; $i++) {
668
                    $padbuf[$i] = ($i & 1) ? 0x11 : 0xec;
669
                }
670
671
                $ret = $padding->appendBytes($padlen, $padbuf);
672
673
                if ($ret < 0) {
674
                    return $ret;
675
                }
676
            }
677
678
            $ret = $bstream->append($padding);
679
680
            return $ret;
681
        }
682
683
        //----------------------------------------------------------------------
684
        public function mergeBitStream()
685
        {
686
            if ($this->convertData() < 0) {
687
                return;
688
            }
689
690
            $bstream = new QRbitstream();
691
692
            foreach ($this->items as $item) {
693
                $ret = $bstream->append($item->bstream);
694
                if ($ret < 0) {
695
                    return;
696
                }
697
            }
698
699
            return $bstream;
700
        }
701
702
        //----------------------------------------------------------------------
703
        public function getBitStream()
704
        {
705
            $bstream = $this->mergeBitStream();
706
707
            if ($bstream == null) {
708
                return;
709
            }
710
711
            $ret = $this->appendPaddingBit($bstream);
712
            if ($ret < 0) {
713
                return;
714
            }
715
716
            return $bstream;
717
        }
718
719
        //----------------------------------------------------------------------
720
        public function getByteStream()
721
        {
722
            $bstream = $this->getBitStream();
723
            if ($bstream == null) {
724
                return;
725
            }
726
727
            return $bstream->toByte();
728
        }
729
    }
730