]>
Raphaƫl G. Git Repositories - cdn/blob - vendor/phpqrcode/qrbitstream.php
7 * Based on libqrencode C library distributed under LGPL 2.1
8 * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
10 * PHP QR Code is distributed under LGPL 3
11 * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
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.
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.
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
30 public $data = array();
32 //----------------------------------------------------------------------
33 public function size()
35 return count($this->data
);
38 //----------------------------------------------------------------------
39 public function allocate($setLength)
41 $this->data
= array_fill(0, $setLength, 0);
45 //----------------------------------------------------------------------
46 public static function newFromNum($bits, $num)
48 $bstream = new QRbitstream();
49 $bstream->allocate($bits);
51 $mask = 1 << ($bits - 1);
52 for($i=0; $i<$bits; $i++
) {
54 $bstream->data
[$i] = 1;
56 $bstream->data
[$i] = 0;
64 //----------------------------------------------------------------------
65 public static function newFromBytes($size, $data)
67 $bstream = new QRbitstream();
68 $bstream->allocate($size * 8);
71 for($i=0; $i<$size; $i++
) {
73 for($j=0; $j<8; $j++
) {
74 if($data[$i] & $mask) {
75 $bstream->data
[$p] = 1;
77 $bstream->data
[$p] = 0;
87 //----------------------------------------------------------------------
88 public function append(QRbitstream
$arg)
94 if($arg->size() == 0) {
98 if($this->size() == 0) {
99 $this->data
= $arg->data
;
103 $this->data
= array_values(array_merge($this->data
, $arg->data
));
108 //----------------------------------------------------------------------
109 public function appendNum($bits, $num)
114 $b = QRbitstream
::newFromNum($bits, $num);
119 $ret = $this->append($b);
125 //----------------------------------------------------------------------
126 public function appendBytes($size, $data)
131 $b = QRbitstream
::newFromBytes($size, $data);
136 $ret = $this->append($b);
142 //----------------------------------------------------------------------
143 public function toByte()
146 $size = $this->size();
152 $data = array_fill(0, (int)(($size +
7) / 8), 0);
153 $bytes = (int)($size / 8);
157 for($i=0; $i<$bytes; $i++
) {
159 for($j=0; $j<8; $j++
) {
161 $v |= $this->data
[$p];
169 for($j=0; $j<($size & 7); $j++
) {
171 $v |= $this->data
[$p];