@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * http://www.barcodephp.com |
12 | 12 | */ |
13 | 13 | class BCGColor { |
14 | - protected $r, $g, $b; // int Hexadecimal Value |
|
14 | + protected $r, $g, $b; // int Hexadecimal Value |
|
15 | 15 | protected $transparent; |
16 | 16 | |
17 | 17 | /** |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * @param string $default |
113 | 113 | */ |
114 | 114 | public static function getColor($code, $default = 'white') { |
115 | - switch(strtolower($code)) { |
|
115 | + switch (strtolower($code)) { |
|
116 | 116 | case '': |
117 | 117 | case 'white': |
118 | 118 | return 0xffffff; |
@@ -45,10 +45,10 @@ discard block |
||
45 | 45 | public function writeFormatInformation($width, &$frame, $mask, $level) |
46 | 46 | { |
47 | 47 | $blacks = 0; |
48 | - $format = QRspec::getFormatInfo($mask, $level); |
|
48 | + $format = QRspec::getFormatInfo($mask, $level); |
|
49 | 49 | |
50 | - for($i=0; $i<8; $i++) { |
|
51 | - if($format & 1) { |
|
50 | + for ($i = 0; $i < 8; $i++) { |
|
51 | + if ($format & 1) { |
|
52 | 52 | $blacks += 2; |
53 | 53 | $v = 0x85; |
54 | 54 | } else { |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | $frame[8][$width - 1 - $i] = chr($v); |
59 | - if($i < 6) { |
|
59 | + if ($i < 6) { |
|
60 | 60 | $frame[$i][8] = chr($v); |
61 | 61 | } else { |
62 | 62 | $frame[$i + 1][8] = chr($v); |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | $format = $format >> 1; |
65 | 65 | } |
66 | 66 | |
67 | - for($i=0; $i<7; $i++) { |
|
68 | - if($format & 1) { |
|
67 | + for ($i = 0; $i < 7; $i++) { |
|
68 | + if ($format & 1) { |
|
69 | 69 | $blacks += 2; |
70 | 70 | $v = 0x85; |
71 | 71 | } else { |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | } |
74 | 74 | |
75 | 75 | $frame[$width - 7 + $i][8] = chr($v); |
76 | - if($i == 0) { |
|
76 | + if ($i == 0) { |
|
77 | 77 | $frame[8][7] = chr($v); |
78 | 78 | } else { |
79 | 79 | $frame[8][6 - $i] = chr($v); |
@@ -86,27 +86,27 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | //---------------------------------------------------------------------- |
89 | - public function mask0($x, $y) { return ($x+$y)&1; } |
|
90 | - public function mask1($x, $y) { return ($y&1); } |
|
91 | - public function mask2($x, $y) { return ($x%3); } |
|
92 | - public function mask3($x, $y) { return ($x+$y)%3; } |
|
93 | - public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; } |
|
94 | - public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3; } |
|
95 | - public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1; } |
|
96 | - public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1; } |
|
89 | + public function mask0($x, $y) { return ($x + $y)&1; } |
|
90 | + public function mask1($x, $y) { return ($y&1); } |
|
91 | + public function mask2($x, $y) { return ($x % 3); } |
|
92 | + public function mask3($x, $y) { return ($x + $y) % 3; } |
|
93 | + public function mask4($x, $y) { return (((int) ($y / 2)) + ((int) ($x / 3)))&1; } |
|
94 | + public function mask5($x, $y) { return (($x * $y)&1) + ($x * $y) % 3; } |
|
95 | + public function mask6($x, $y) { return ((($x * $y)&1) + ($x * $y) % 3)&1; } |
|
96 | + public function mask7($x, $y) { return ((($x * $y) % 3) + (($x + $y)&1))&1; } |
|
97 | 97 | |
98 | 98 | //---------------------------------------------------------------------- |
99 | 99 | private function generateMaskNo($maskNo, $width, $frame) |
100 | 100 | { |
101 | 101 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
102 | 102 | |
103 | - for($y=0; $y<$width; $y++) { |
|
104 | - for($x=0; $x<$width; $x++) { |
|
105 | - if(ord($frame[$y][$x]) & 0x80) { |
|
103 | + for ($y = 0; $y < $width; $y++) { |
|
104 | + for ($x = 0; $x < $width; $x++) { |
|
105 | + if (ord($frame[$y][$x]) & 0x80) { |
|
106 | 106 | $bitMask[$y][$x] = 0; |
107 | 107 | } else { |
108 | 108 | $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y); |
109 | - $bitMask[$y][$x] = ($maskFunc == 0)?1:0; |
|
109 | + $bitMask[$y][$x] = ($maskFunc == 0) ? 1 : 0; |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | } |
@@ -164,12 +164,12 @@ discard block |
||
164 | 164 | |
165 | 165 | $d = $s; |
166 | 166 | |
167 | - for($y=0; $y<$width; $y++) { |
|
168 | - for($x=0; $x<$width; $x++) { |
|
169 | - if($bitMask[$y][$x] == 1) { |
|
170 | - $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]); |
|
167 | + for ($y = 0; $y < $width; $y++) { |
|
168 | + for ($x = 0; $x < $width; $x++) { |
|
169 | + if ($bitMask[$y][$x] == 1) { |
|
170 | + $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int) $bitMask[$y][$x]); |
|
171 | 171 | } |
172 | - $b += (int)(ord($d[$y][$x]) & 1); |
|
172 | + $b += (int) (ord($d[$y][$x]) & 1); |
|
173 | 173 | } |
174 | 174 | } |
175 | 175 | |
@@ -191,21 +191,21 @@ discard block |
||
191 | 191 | { |
192 | 192 | $demerit = 0; |
193 | 193 | |
194 | - for($i=0; $i<$length; $i++) { |
|
194 | + for ($i = 0; $i < $length; $i++) { |
|
195 | 195 | |
196 | - if($this->runLength[$i] >= 5) { |
|
196 | + if ($this->runLength[$i] >= 5) { |
|
197 | 197 | $demerit += (N1 + ($this->runLength[$i] - 5)); |
198 | 198 | } |
199 | - if($i & 1) { |
|
200 | - if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) { |
|
201 | - $fact = (int)($this->runLength[$i] / 3); |
|
202 | - if(($this->runLength[$i-2] == $fact) && |
|
203 | - ($this->runLength[$i-1] == $fact) && |
|
204 | - ($this->runLength[$i+1] == $fact) && |
|
205 | - ($this->runLength[$i+2] == $fact)) { |
|
206 | - if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) { |
|
199 | + if ($i & 1) { |
|
200 | + if (($i >= 3) && ($i < ($length - 2)) && ($this->runLength[$i] % 3 == 0)) { |
|
201 | + $fact = (int) ($this->runLength[$i] / 3); |
|
202 | + if (($this->runLength[$i - 2] == $fact) && |
|
203 | + ($this->runLength[$i - 1] == $fact) && |
|
204 | + ($this->runLength[$i + 1] == $fact) && |
|
205 | + ($this->runLength[$i + 2] == $fact)) { |
|
206 | + if (($this->runLength[$i - 3] < 0) || ($this->runLength[$i - 3] >= (4 * $fact))) { |
|
207 | 207 | $demerit += N3; |
208 | - } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) { |
|
208 | + } else if ((($i + 3) >= $length) || ($this->runLength[$i + 3] >= (4 * $fact))) { |
|
209 | 209 | $demerit += N3; |
210 | 210 | } |
211 | 211 | } |
@@ -221,30 +221,30 @@ discard block |
||
221 | 221 | $head = 0; |
222 | 222 | $demerit = 0; |
223 | 223 | |
224 | - for($y=0; $y<$width; $y++) { |
|
224 | + for ($y = 0; $y < $width; $y++) { |
|
225 | 225 | $head = 0; |
226 | 226 | $this->runLength[0] = 1; |
227 | 227 | |
228 | 228 | $frameY = $frame[$y]; |
229 | 229 | |
230 | - if ($y>0) |
|
231 | - $frameYM = $frame[$y-1]; |
|
230 | + if ($y > 0) |
|
231 | + $frameYM = $frame[$y - 1]; |
|
232 | 232 | |
233 | - for($x=0; $x<$width; $x++) { |
|
234 | - if(($x > 0) && ($y > 0)) { |
|
235 | - $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]); |
|
236 | - $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]); |
|
233 | + for ($x = 0; $x < $width; $x++) { |
|
234 | + if (($x > 0) && ($y > 0)) { |
|
235 | + $b22 = ord($frameY[$x]) & ord($frameY[$x - 1]) & ord($frameYM[$x]) & ord($frameYM[$x - 1]); |
|
236 | + $w22 = ord($frameY[$x]) | ord($frameY[$x - 1]) | ord($frameYM[$x]) | ord($frameYM[$x - 1]); |
|
237 | 237 | |
238 | - if(($b22 | ($w22 ^ 1))&1) { |
|
238 | + if (($b22 | ($w22 ^ 1))&1) { |
|
239 | 239 | $demerit += N2; |
240 | 240 | } |
241 | 241 | } |
242 | - if(($x == 0) && (ord($frameY[$x]) & 1)) { |
|
242 | + if (($x == 0) && (ord($frameY[$x]) & 1)) { |
|
243 | 243 | $this->runLength[0] = -1; |
244 | 244 | $head = 1; |
245 | 245 | $this->runLength[$head] = 1; |
246 | - } else if($x > 0) { |
|
247 | - if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) { |
|
246 | + } else if ($x > 0) { |
|
247 | + if ((ord($frameY[$x]) ^ ord($frameY[$x - 1])) & 1) { |
|
248 | 248 | $head++; |
249 | 249 | $this->runLength[$head] = 1; |
250 | 250 | } else { |
@@ -253,20 +253,20 @@ discard block |
||
253 | 253 | } |
254 | 254 | } |
255 | 255 | |
256 | - $demerit += $this->calcN1N3($head+1); |
|
256 | + $demerit += $this->calcN1N3($head + 1); |
|
257 | 257 | } |
258 | 258 | |
259 | - for($x=0; $x<$width; $x++) { |
|
259 | + for ($x = 0; $x < $width; $x++) { |
|
260 | 260 | $head = 0; |
261 | 261 | $this->runLength[0] = 1; |
262 | 262 | |
263 | - for($y=0; $y<$width; $y++) { |
|
264 | - if($y == 0 && (ord($frame[$y][$x]) & 1)) { |
|
263 | + for ($y = 0; $y < $width; $y++) { |
|
264 | + if ($y == 0 && (ord($frame[$y][$x]) & 1)) { |
|
265 | 265 | $this->runLength[0] = -1; |
266 | 266 | $head = 1; |
267 | 267 | $this->runLength[$head] = 1; |
268 | - } else if($y > 0) { |
|
269 | - if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) { |
|
268 | + } else if ($y > 0) { |
|
269 | + if ((ord($frame[$y][$x]) ^ ord($frame[$y - 1][$x])) & 1) { |
|
270 | 270 | $head++; |
271 | 271 | $this->runLength[$head] = 1; |
272 | 272 | } else { |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | } |
276 | 276 | } |
277 | 277 | |
278 | - $demerit += $this->calcN1N3($head+1); |
|
278 | + $demerit += $this->calcN1N3($head + 1); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | return $demerit; |
@@ -289,13 +289,13 @@ discard block |
||
289 | 289 | $bestMaskNum = 0; |
290 | 290 | $bestMask = array(); |
291 | 291 | |
292 | - $checked_masks = array(0,1,2,3,4,5,6,7); |
|
292 | + $checked_masks = array(0, 1, 2, 3, 4, 5, 6, 7); |
|
293 | 293 | |
294 | 294 | if (QR_FIND_FROM_RANDOM !== false) { |
295 | 295 | |
296 | - $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9); |
|
297 | - for ($i = 0; $i < $howManuOut; $i++) { |
|
298 | - $remPos = rand (0, count($checked_masks)-1); |
|
296 | + $howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9); |
|
297 | + for ($i = 0; $i < $howManuOut; $i++) { |
|
298 | + $remPos = rand(0, count($checked_masks) - 1); |
|
299 | 299 | unset($checked_masks[$remPos]); |
300 | 300 | $checked_masks = array_values($checked_masks); |
301 | 301 | } |
@@ -304,18 +304,18 @@ discard block |
||
304 | 304 | |
305 | 305 | $bestMask = $frame; |
306 | 306 | |
307 | - foreach($checked_masks as $i) { |
|
307 | + foreach ($checked_masks as $i) { |
|
308 | 308 | $mask = array_fill(0, $width, str_repeat("\0", $width)); |
309 | 309 | |
310 | 310 | $demerit = 0; |
311 | 311 | $blacks = 0; |
312 | 312 | $blacks = $this->makeMaskNo($i, $width, $frame, $mask); |
313 | 313 | $blacks += $this->writeFormatInformation($width, $mask, $i, $level); |
314 | - $blacks = (int)(100 * $blacks / ($width * $width)); |
|
315 | - $demerit = (int)((int)(abs($blacks - 50) / 5) * N4); |
|
314 | + $blacks = (int) (100 * $blacks / ($width * $width)); |
|
315 | + $demerit = (int) ((int) (abs($blacks - 50) / 5) * N4); |
|
316 | 316 | $demerit += $this->evaluateSymbol($width, $mask); |
317 | 317 | |
318 | - if($demerit < $minDemerit) { |
|
318 | + if ($demerit < $minDemerit) { |
|
319 | 319 | $minDemerit = $demerit; |
320 | 320 | $bestMask = $mask; |
321 | 321 | $bestMaskNum = $i; |
@@ -120,8 +120,9 @@ discard block |
||
120 | 120 | { |
121 | 121 | $codeArr = array(); |
122 | 122 | |
123 | - foreach ($bitFrame as $line) |
|
124 | - $codeArr[] = join('', $line); |
|
123 | + foreach ($bitFrame as $line) { |
|
124 | + $codeArr[] = join('', $line); |
|
125 | + } |
|
125 | 126 | |
126 | 127 | return gzcompress(join("\n", $codeArr), 9); |
127 | 128 | } |
@@ -132,8 +133,9 @@ discard block |
||
132 | 133 | $codeArr = array(); |
133 | 134 | |
134 | 135 | $codeLines = explode("\n", gzuncompress($code)); |
135 | - foreach ($codeLines as $line) |
|
136 | - $codeArr[] = str_split($line); |
|
136 | + foreach ($codeLines as $line) { |
|
137 | + $codeArr[] = str_split($line); |
|
138 | + } |
|
137 | 139 | |
138 | 140 | return $codeArr; |
139 | 141 | } |
@@ -151,16 +153,18 @@ discard block |
||
151 | 153 | $bitMask = self::unserial(file_get_contents($fileName)); |
152 | 154 | } else { |
153 | 155 | $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); |
154 | - if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) |
|
155 | - mkdir(QR_CACHE_DIR.'mask_'.$maskNo); |
|
156 | + if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) { |
|
157 | + mkdir(QR_CACHE_DIR.'mask_'.$maskNo); |
|
158 | + } |
|
156 | 159 | file_put_contents($fileName, self::serial($bitMask)); |
157 | 160 | } |
158 | 161 | } else { |
159 | 162 | $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); |
160 | 163 | } |
161 | 164 | |
162 | - if ($maskGenOnly) |
|
163 | - return; |
|
165 | + if ($maskGenOnly) { |
|
166 | + return; |
|
167 | + } |
|
164 | 168 | |
165 | 169 | $d = $s; |
166 | 170 | |
@@ -227,8 +231,9 @@ discard block |
||
227 | 231 | |
228 | 232 | $frameY = $frame[$y]; |
229 | 233 | |
230 | - if ($y>0) |
|
231 | - $frameYM = $frame[$y-1]; |
|
234 | + if ($y>0) { |
|
235 | + $frameYM = $frame[$y-1]; |
|
236 | + } |
|
232 | 237 | |
233 | 238 | for($x=0; $x<$width; $x++) { |
234 | 239 | if(($x > 0) && ($y > 0)) { |
@@ -180,7 +180,7 @@ |
||
180 | 180 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
181 | 181 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
182 | 182 | 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, |
183 | - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
183 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
184 | 184 | -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
185 | 185 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, |
186 | 186 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | namespace tinymeng\code\Gateways\qrcode; |
28 | 28 | |
29 | -define('STRUCTURE_HEADER_BITS', 20); |
|
29 | +define('STRUCTURE_HEADER_BITS', 20); |
|
30 | 30 | define('MAX_STRUCTURED_SYMBOLS', 16); |
31 | 31 | |
32 | 32 | class QRinput { |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | //---------------------------------------------------------------------- |
58 | 58 | public function setVersion($version) |
59 | 59 | { |
60 | - if($version < 0 || $version > QRSPEC_VERSION_MAX) { |
|
60 | + if ($version < 0 || $version > QRSPEC_VERSION_MAX) { |
|
61 | 61 | throw new Exception('Invalid version no'); |
62 | 62 | return -1; |
63 | 63 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | //---------------------------------------------------------------------- |
77 | 77 | public function setErrorCorrectionLevel($level) |
78 | 78 | { |
79 | - if($level > QR_ECLEVEL_H) { |
|
79 | + if ($level > QR_ECLEVEL_H) { |
|
80 | 80 | throw new Exception('Invalid ECLEVEL'); |
81 | 81 | return -1; |
82 | 82 | } |
@@ -108,11 +108,11 @@ discard block |
||
108 | 108 | |
109 | 109 | public function insertStructuredAppendHeader($size, $index, $parity) |
110 | 110 | { |
111 | - if( $size > MAX_STRUCTURED_SYMBOLS ) { |
|
111 | + if ($size > MAX_STRUCTURED_SYMBOLS) { |
|
112 | 112 | throw new Exception('insertStructuredAppendHeader wrong size'); |
113 | 113 | } |
114 | 114 | |
115 | - if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) { |
|
115 | + if ($index <= 0 || $index > MAX_STRUCTURED_SYMBOLS) { |
|
116 | 116 | throw new Exception('insertStructuredAppendHeader wrong index'); |
117 | 117 | } |
118 | 118 | |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | { |
133 | 133 | $parity = 0; |
134 | 134 | |
135 | - foreach($this->items as $item) { |
|
136 | - if($item->mode != QR_MODE_STRUCTURE) { |
|
137 | - for($i=$item->size-1; $i>=0; $i--) { |
|
135 | + foreach ($this->items as $item) { |
|
136 | + if ($item->mode != QR_MODE_STRUCTURE) { |
|
137 | + for ($i = $item->size - 1; $i >= 0; $i--) { |
|
138 | 138 | $parity ^= $item->data[$i]; |
139 | 139 | } |
140 | 140 | } |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | //---------------------------------------------------------------------- |
147 | 147 | public static function checkModeNum($size, $data) |
148 | 148 | { |
149 | - for($i=0; $i<$size; $i++) { |
|
150 | - if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){ |
|
149 | + for ($i = 0; $i < $size; $i++) { |
|
150 | + if ((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))) { |
|
151 | 151 | return false; |
152 | 152 | } |
153 | 153 | } |
@@ -158,10 +158,10 @@ discard block |
||
158 | 158 | //---------------------------------------------------------------------- |
159 | 159 | public static function estimateBitsModeNum($size) |
160 | 160 | { |
161 | - $w = (int)$size / 3; |
|
161 | + $w = (int) $size / 3; |
|
162 | 162 | $bits = $w * 10; |
163 | 163 | |
164 | - switch($size - $w * 3) { |
|
164 | + switch ($size - $w * 3) { |
|
165 | 165 | case 1: |
166 | 166 | $bits += 4; |
167 | 167 | break; |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
181 | 181 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
182 | 182 | 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, |
183 | - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
183 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
184 | 184 | -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
185 | 185 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, |
186 | 186 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
@@ -190,13 +190,13 @@ discard block |
||
190 | 190 | //---------------------------------------------------------------------- |
191 | 191 | public static function lookAnTable($c) |
192 | 192 | { |
193 | - return (($c > 127)?-1:self::$anTable[$c]); |
|
193 | + return (($c > 127) ?-1 : self::$anTable[$c]); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | //---------------------------------------------------------------------- |
197 | 197 | public static function checkModeAn($size, $data) |
198 | 198 | { |
199 | - for($i=0; $i<$size; $i++) { |
|
199 | + for ($i = 0; $i < $size; $i++) { |
|
200 | 200 | if (self::lookAnTable(ord($data[$i])) == -1) { |
201 | 201 | return false; |
202 | 202 | } |
@@ -208,10 +208,10 @@ discard block |
||
208 | 208 | //---------------------------------------------------------------------- |
209 | 209 | public static function estimateBitsModeAn($size) |
210 | 210 | { |
211 | - $w = (int)($size / 2); |
|
211 | + $w = (int) ($size / 2); |
|
212 | 212 | $bits = $w * 11; |
213 | 213 | |
214 | - if($size & 1) { |
|
214 | + if ($size & 1) { |
|
215 | 215 | $bits += 6; |
216 | 216 | } |
217 | 217 | |
@@ -227,18 +227,18 @@ discard block |
||
227 | 227 | //---------------------------------------------------------------------- |
228 | 228 | public function estimateBitsModeKanji($size) |
229 | 229 | { |
230 | - return (int)(($size / 2) * 13); |
|
230 | + return (int) (($size / 2) * 13); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | //---------------------------------------------------------------------- |
234 | 234 | public static function checkModeKanji($size, $data) |
235 | 235 | { |
236 | - if($size & 1) |
|
236 | + if ($size & 1) |
|
237 | 237 | return false; |
238 | 238 | |
239 | - for($i=0; $i<$size; $i+=2) { |
|
240 | - $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
|
241 | - if( $val < 0x8140 |
|
239 | + for ($i = 0; $i < $size; $i += 2) { |
|
240 | + $val = (ord($data[$i]) << 8) | ord($data[$i + 1]); |
|
241 | + if ($val < 0x8140 |
|
242 | 242 | || ($val > 0x9ffc && $val < 0xe040) |
243 | 243 | || $val > 0xebbf) { |
244 | 244 | return false; |
@@ -254,12 +254,12 @@ discard block |
||
254 | 254 | |
255 | 255 | public static function check($mode, $size, $data) |
256 | 256 | { |
257 | - if($size <= 0) |
|
257 | + if ($size <= 0) |
|
258 | 258 | return false; |
259 | 259 | |
260 | - switch($mode) { |
|
261 | - case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
262 | - case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
260 | + switch ($mode) { |
|
261 | + case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
262 | + case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
263 | 263 | case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break; |
264 | 264 | case QR_MODE_8: return true; break; |
265 | 265 | case QR_MODE_STRUCTURE: return true; break; |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | { |
278 | 278 | $bits = 0; |
279 | 279 | |
280 | - foreach($this->items as $item) { |
|
280 | + foreach ($this->items as $item) { |
|
281 | 281 | $bits += $item->estimateBitStreamSizeOfEntry($version); |
282 | 282 | } |
283 | 283 | |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | do { |
293 | 293 | $prev = $version; |
294 | 294 | $bits = $this->estimateBitStreamSize($prev); |
295 | - $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
295 | + $version = QRspec::getMinimumVersion((int) (($bits + 7) / 8), $this->level); |
|
296 | 296 | if ($version < 0) { |
297 | 297 | return -1; |
298 | 298 | } |
@@ -305,32 +305,32 @@ discard block |
||
305 | 305 | public static function lengthOfCode($mode, $version, $bits) |
306 | 306 | { |
307 | 307 | $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version); |
308 | - switch($mode) { |
|
308 | + switch ($mode) { |
|
309 | 309 | case QR_MODE_NUM: |
310 | - $chunks = (int)($payload / 10); |
|
310 | + $chunks = (int) ($payload / 10); |
|
311 | 311 | $remain = $payload - $chunks * 10; |
312 | 312 | $size = $chunks * 3; |
313 | - if($remain >= 7) { |
|
313 | + if ($remain >= 7) { |
|
314 | 314 | $size += 2; |
315 | - } else if($remain >= 4) { |
|
315 | + } else if ($remain >= 4) { |
|
316 | 316 | $size += 1; |
317 | 317 | } |
318 | 318 | break; |
319 | 319 | case QR_MODE_AN: |
320 | - $chunks = (int)($payload / 11); |
|
320 | + $chunks = (int) ($payload / 11); |
|
321 | 321 | $remain = $payload - $chunks * 11; |
322 | 322 | $size = $chunks * 2; |
323 | - if($remain >= 6) |
|
323 | + if ($remain >= 6) |
|
324 | 324 | $size++; |
325 | 325 | break; |
326 | 326 | case QR_MODE_8: |
327 | - $size = (int)($payload / 8); |
|
327 | + $size = (int) ($payload / 8); |
|
328 | 328 | break; |
329 | 329 | case QR_MODE_KANJI: |
330 | - $size = (int)(($payload / 13) * 2); |
|
330 | + $size = (int) (($payload / 13) * 2); |
|
331 | 331 | break; |
332 | 332 | case QR_MODE_STRUCTURE: |
333 | - $size = (int)($payload / 8); |
|
333 | + $size = (int) ($payload / 8); |
|
334 | 334 | break; |
335 | 335 | default: |
336 | 336 | $size = 0; |
@@ -338,8 +338,8 @@ discard block |
||
338 | 338 | } |
339 | 339 | |
340 | 340 | $maxsize = QRspec::maximumWords($mode, $version); |
341 | - if($size < 0) $size = 0; |
|
342 | - if($size > $maxsize) $size = $maxsize; |
|
341 | + if ($size < 0) $size = 0; |
|
342 | + if ($size > $maxsize) $size = $maxsize; |
|
343 | 343 | |
344 | 344 | return $size; |
345 | 345 | } |
@@ -349,10 +349,10 @@ discard block |
||
349 | 349 | { |
350 | 350 | $total = 0; |
351 | 351 | |
352 | - foreach($this->items as $item) { |
|
352 | + foreach ($this->items as $item) { |
|
353 | 353 | $bits = $item->encodeBitStream($this->version); |
354 | 354 | |
355 | - if($bits < 0) |
|
355 | + if ($bits < 0) |
|
356 | 356 | return -1; |
357 | 357 | |
358 | 358 | $total += $bits; |
@@ -365,21 +365,21 @@ discard block |
||
365 | 365 | public function convertData() |
366 | 366 | { |
367 | 367 | $ver = $this->estimateVersion(); |
368 | - if($ver > $this->getVersion()) { |
|
368 | + if ($ver > $this->getVersion()) { |
|
369 | 369 | $this->setVersion($ver); |
370 | 370 | } |
371 | 371 | |
372 | - for(;;) { |
|
372 | + for (;;) { |
|
373 | 373 | $bits = $this->createBitStream(); |
374 | 374 | |
375 | - if($bits < 0) |
|
375 | + if ($bits < 0) |
|
376 | 376 | return -1; |
377 | 377 | |
378 | - $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
379 | - if($ver < 0) { |
|
378 | + $ver = QRspec::getMinimumVersion((int) (($bits + 7) / 8), $this->level); |
|
379 | + if ($ver < 0) { |
|
380 | 380 | throw new Exception('WRONG VERSION'); |
381 | 381 | return -1; |
382 | - } else if($ver > $this->getVersion()) { |
|
382 | + } else if ($ver > $this->getVersion()) { |
|
383 | 383 | $this->setVersion($ver); |
384 | 384 | } else { |
385 | 385 | break; |
@@ -405,26 +405,26 @@ discard block |
||
405 | 405 | } |
406 | 406 | |
407 | 407 | $bits += 4; |
408 | - $words = (int)(($bits + 7) / 8); |
|
408 | + $words = (int) (($bits + 7) / 8); |
|
409 | 409 | |
410 | 410 | $padding = new QRbitstream(); |
411 | 411 | $ret = $padding->appendNum($words * 8 - $bits + 4, 0); |
412 | 412 | |
413 | - if($ret < 0) |
|
413 | + if ($ret < 0) |
|
414 | 414 | return $ret; |
415 | 415 | |
416 | 416 | $padlen = $maxwords - $words; |
417 | 417 | |
418 | - if($padlen > 0) { |
|
418 | + if ($padlen > 0) { |
|
419 | 419 | |
420 | 420 | $padbuf = array(); |
421 | - for($i=0; $i<$padlen; $i++) { |
|
422 | - $padbuf[$i] = ($i&1)?0x11:0xec; |
|
421 | + for ($i = 0; $i < $padlen; $i++) { |
|
422 | + $padbuf[$i] = ($i&1) ? 0x11 : 0xec; |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | $ret = $padding->appendBytes($padlen, $padbuf); |
426 | 426 | |
427 | - if($ret < 0) |
|
427 | + if ($ret < 0) |
|
428 | 428 | return $ret; |
429 | 429 | |
430 | 430 | } |
@@ -437,15 +437,15 @@ discard block |
||
437 | 437 | //---------------------------------------------------------------------- |
438 | 438 | public function mergeBitStream() |
439 | 439 | { |
440 | - if($this->convertData() < 0) { |
|
440 | + if ($this->convertData() < 0) { |
|
441 | 441 | return null; |
442 | 442 | } |
443 | 443 | |
444 | 444 | $bstream = new QRbitstream(); |
445 | 445 | |
446 | - foreach($this->items as $item) { |
|
446 | + foreach ($this->items as $item) { |
|
447 | 447 | $ret = $bstream->append($item->bstream); |
448 | - if($ret < 0) { |
|
448 | + if ($ret < 0) { |
|
449 | 449 | return null; |
450 | 450 | } |
451 | 451 | } |
@@ -459,12 +459,12 @@ discard block |
||
459 | 459 | |
460 | 460 | $bstream = $this->mergeBitStream(); |
461 | 461 | |
462 | - if($bstream == null) { |
|
462 | + if ($bstream == null) { |
|
463 | 463 | return null; |
464 | 464 | } |
465 | 465 | |
466 | 466 | $ret = $this->appendPaddingBit($bstream); |
467 | - if($ret < 0) { |
|
467 | + if ($ret < 0) { |
|
468 | 468 | return null; |
469 | 469 | } |
470 | 470 | |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | public function getByteStream() |
476 | 476 | { |
477 | 477 | $bstream = $this->getBitStream(); |
478 | - if($bstream == null) { |
|
478 | + if ($bstream == null) { |
|
479 | 479 | return null; |
480 | 480 | } |
481 | 481 |
@@ -233,8 +233,9 @@ discard block |
||
233 | 233 | //---------------------------------------------------------------------- |
234 | 234 | public static function checkModeKanji($size, $data) |
235 | 235 | { |
236 | - if($size & 1) |
|
237 | - return false; |
|
236 | + if($size & 1) { |
|
237 | + return false; |
|
238 | + } |
|
238 | 239 | |
239 | 240 | for($i=0; $i<$size; $i+=2) { |
240 | 241 | $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
@@ -254,8 +255,9 @@ discard block |
||
254 | 255 | |
255 | 256 | public static function check($mode, $size, $data) |
256 | 257 | { |
257 | - if($size <= 0) |
|
258 | - return false; |
|
258 | + if($size <= 0) { |
|
259 | + return false; |
|
260 | + } |
|
259 | 261 | |
260 | 262 | switch($mode) { |
261 | 263 | case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
@@ -320,8 +322,9 @@ discard block |
||
320 | 322 | $chunks = (int)($payload / 11); |
321 | 323 | $remain = $payload - $chunks * 11; |
322 | 324 | $size = $chunks * 2; |
323 | - if($remain >= 6) |
|
324 | - $size++; |
|
325 | + if($remain >= 6) { |
|
326 | + $size++; |
|
327 | + } |
|
325 | 328 | break; |
326 | 329 | case QR_MODE_8: |
327 | 330 | $size = (int)($payload / 8); |
@@ -338,8 +341,12 @@ discard block |
||
338 | 341 | } |
339 | 342 | |
340 | 343 | $maxsize = QRspec::maximumWords($mode, $version); |
341 | - if($size < 0) $size = 0; |
|
342 | - if($size > $maxsize) $size = $maxsize; |
|
344 | + if($size < 0) { |
|
345 | + $size = 0; |
|
346 | + } |
|
347 | + if($size > $maxsize) { |
|
348 | + $size = $maxsize; |
|
349 | + } |
|
343 | 350 | |
344 | 351 | return $size; |
345 | 352 | } |
@@ -352,8 +359,9 @@ discard block |
||
352 | 359 | foreach($this->items as $item) { |
353 | 360 | $bits = $item->encodeBitStream($this->version); |
354 | 361 | |
355 | - if($bits < 0) |
|
356 | - return -1; |
|
362 | + if($bits < 0) { |
|
363 | + return -1; |
|
364 | + } |
|
357 | 365 | |
358 | 366 | $total += $bits; |
359 | 367 | } |
@@ -372,8 +380,9 @@ discard block |
||
372 | 380 | for(;;) { |
373 | 381 | $bits = $this->createBitStream(); |
374 | 382 | |
375 | - if($bits < 0) |
|
376 | - return -1; |
|
383 | + if($bits < 0) { |
|
384 | + return -1; |
|
385 | + } |
|
377 | 386 | |
378 | 387 | $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
379 | 388 | if($ver < 0) { |
@@ -410,8 +419,9 @@ discard block |
||
410 | 419 | $padding = new QRbitstream(); |
411 | 420 | $ret = $padding->appendNum($words * 8 - $bits + 4, 0); |
412 | 421 | |
413 | - if($ret < 0) |
|
414 | - return $ret; |
|
422 | + if($ret < 0) { |
|
423 | + return $ret; |
|
424 | + } |
|
415 | 425 | |
416 | 426 | $padlen = $maxwords - $words; |
417 | 427 | |
@@ -424,8 +434,9 @@ discard block |
||
424 | 434 | |
425 | 435 | $ret = $padding->appendBytes($padlen, $padbuf); |
426 | 436 | |
427 | - if($ret < 0) |
|
428 | - return $ret; |
|
437 | + if($ret < 0) { |
|
438 | + return $ret; |
|
439 | + } |
|
429 | 440 | |
430 | 441 | } |
431 | 442 |
@@ -8,16 +8,16 @@ discard block |
||
8 | 8 | |
9 | 9 | class QRrsItem { |
10 | 10 | |
11 | - public $mm; // Bits per symbol |
|
12 | - public $nn; // Symbols per block (= (1<<mm)-1) |
|
13 | - public $alpha_to = array(); // log lookup table |
|
14 | - public $index_of = array(); // Antilog lookup table |
|
15 | - public $genpoly = array(); // Generator polynomial |
|
16 | - public $nroots; // Number of generator roots = number of parity symbols |
|
17 | - public $fcr; // First consecutive root, index form |
|
18 | - public $prim; // Primitive element, index form |
|
19 | - public $iprim; // prim-th root of 1, index form |
|
20 | - public $pad; // Padding bytes in shortened block |
|
11 | + public $mm; // Bits per symbol |
|
12 | + public $nn; // Symbols per block (= (1<<mm)-1) |
|
13 | + public $alpha_to = array(); // log lookup table |
|
14 | + public $index_of = array(); // Antilog lookup table |
|
15 | + public $genpoly = array(); // Generator polynomial |
|
16 | + public $nroots; // Number of generator roots = number of parity symbols |
|
17 | + public $fcr; // First consecutive root, index form |
|
18 | + public $prim; // Primitive element, index form |
|
19 | + public $iprim; // prim-th root of 1, index form |
|
20 | + public $pad; // Padding bytes in shortened block |
|
21 | 21 | public $gfpoly; |
22 | 22 | |
23 | 23 | //---------------------------------------------------------------------- |
@@ -41,47 +41,47 @@ discard block |
||
41 | 41 | $rs = null; |
42 | 42 | |
43 | 43 | // Check parameter ranges |
44 | - if($symsize < 0 || $symsize > 8) return $rs; |
|
45 | - if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs; |
|
46 | - if($prim <= 0 || $prim >= (1<<$symsize)) return $rs; |
|
47 | - if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values! |
|
48 | - if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding |
|
44 | + if ($symsize < 0 || $symsize > 8) return $rs; |
|
45 | + if ($fcr < 0 || $fcr >= (1 << $symsize)) return $rs; |
|
46 | + if ($prim <= 0 || $prim >= (1 << $symsize)) return $rs; |
|
47 | + if ($nroots < 0 || $nroots >= (1 << $symsize)) return $rs; // Can't have more roots than symbol values! |
|
48 | + if ($pad < 0 || $pad >= ((1 << $symsize) - 1 - $nroots)) return $rs; // Too much padding |
|
49 | 49 | |
50 | 50 | $rs = new QRrsItem(); |
51 | 51 | $rs->mm = $symsize; |
52 | - $rs->nn = (1<<$symsize)-1; |
|
52 | + $rs->nn = (1 << $symsize) - 1; |
|
53 | 53 | $rs->pad = $pad; |
54 | 54 | |
55 | - $rs->alpha_to = array_fill(0, $rs->nn+1, 0); |
|
56 | - $rs->index_of = array_fill(0, $rs->nn+1, 0); |
|
55 | + $rs->alpha_to = array_fill(0, $rs->nn + 1, 0); |
|
56 | + $rs->index_of = array_fill(0, $rs->nn + 1, 0); |
|
57 | 57 | |
58 | 58 | // PHP style macro replacement ;) |
59 | - $NN =& $rs->nn; |
|
60 | - $A0 =& $NN; |
|
59 | + $NN = & $rs->nn; |
|
60 | + $A0 = & $NN; |
|
61 | 61 | |
62 | 62 | // Generate Galois field lookup tables |
63 | 63 | $rs->index_of[0] = $A0; // log(zero) = -inf |
64 | 64 | $rs->alpha_to[$A0] = 0; // alpha**-inf = 0 |
65 | 65 | $sr = 1; |
66 | 66 | |
67 | - for($i=0; $i<$rs->nn; $i++) { |
|
67 | + for ($i = 0; $i < $rs->nn; $i++) { |
|
68 | 68 | $rs->index_of[$sr] = $i; |
69 | 69 | $rs->alpha_to[$i] = $sr; |
70 | 70 | $sr <<= 1; |
71 | - if($sr & (1<<$symsize)) { |
|
71 | + if ($sr & (1 << $symsize)) { |
|
72 | 72 | $sr ^= $gfpoly; |
73 | 73 | } |
74 | 74 | $sr &= $rs->nn; |
75 | 75 | } |
76 | 76 | |
77 | - if($sr != 1){ |
|
77 | + if ($sr != 1) { |
|
78 | 78 | // field generator polynomial is not primitive! |
79 | 79 | $rs = NULL; |
80 | 80 | return $rs; |
81 | 81 | } |
82 | 82 | |
83 | 83 | /* Form RS code generator polynomial from its roots */ |
84 | - $rs->genpoly = array_fill(0, $nroots+1, 0); |
|
84 | + $rs->genpoly = array_fill(0, $nroots + 1, 0); |
|
85 | 85 | |
86 | 86 | $rs->fcr = $fcr; |
87 | 87 | $rs->prim = $prim; |
@@ -89,21 +89,21 @@ discard block |
||
89 | 89 | $rs->gfpoly = $gfpoly; |
90 | 90 | |
91 | 91 | /* Find prim-th root of 1, used in decoding */ |
92 | - for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn) |
|
92 | + for ($iprim = 1; ($iprim % $prim) != 0; $iprim += $rs->nn) |
|
93 | 93 | ; // intentional empty-body loop! |
94 | 94 | |
95 | - $rs->iprim = (int)($iprim / $prim); |
|
95 | + $rs->iprim = (int) ($iprim / $prim); |
|
96 | 96 | $rs->genpoly[0] = 1; |
97 | 97 | |
98 | - for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) { |
|
99 | - $rs->genpoly[$i+1] = 1; |
|
98 | + for ($i = 0, $root = $fcr * $prim; $i < $nroots; $i++, $root += $prim) { |
|
99 | + $rs->genpoly[$i + 1] = 1; |
|
100 | 100 | |
101 | 101 | // Multiply rs->genpoly[] by @**(root + x) |
102 | 102 | for ($j = $i; $j > 0; $j--) { |
103 | 103 | if ($rs->genpoly[$j] != 0) { |
104 | - $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)]; |
|
104 | + $rs->genpoly[$j] = $rs->genpoly[$j - 1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)]; |
|
105 | 105 | } else { |
106 | - $rs->genpoly[$j] = $rs->genpoly[$j-1]; |
|
106 | + $rs->genpoly[$j] = $rs->genpoly[$j - 1]; |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | // rs->genpoly[0] can never be zero |
@@ -120,38 +120,38 @@ discard block |
||
120 | 120 | //---------------------------------------------------------------------- |
121 | 121 | public function encode_rs_char($data, &$parity) |
122 | 122 | { |
123 | - $MM =& $this->mm; |
|
124 | - $NN =& $this->nn; |
|
125 | - $ALPHA_TO =& $this->alpha_to; |
|
126 | - $INDEX_OF =& $this->index_of; |
|
127 | - $GENPOLY =& $this->genpoly; |
|
128 | - $NROOTS =& $this->nroots; |
|
129 | - $FCR =& $this->fcr; |
|
130 | - $PRIM =& $this->prim; |
|
131 | - $IPRIM =& $this->iprim; |
|
132 | - $PAD =& $this->pad; |
|
133 | - $A0 =& $NN; |
|
123 | + $MM = & $this->mm; |
|
124 | + $NN = & $this->nn; |
|
125 | + $ALPHA_TO = & $this->alpha_to; |
|
126 | + $INDEX_OF = & $this->index_of; |
|
127 | + $GENPOLY = & $this->genpoly; |
|
128 | + $NROOTS = & $this->nroots; |
|
129 | + $FCR = & $this->fcr; |
|
130 | + $PRIM = & $this->prim; |
|
131 | + $IPRIM = & $this->iprim; |
|
132 | + $PAD = & $this->pad; |
|
133 | + $A0 = & $NN; |
|
134 | 134 | |
135 | 135 | $parity = array_fill(0, $NROOTS, 0); |
136 | 136 | |
137 | - for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) { |
|
137 | + for ($i = 0; $i < ($NN - $NROOTS - $PAD); $i++) { |
|
138 | 138 | |
139 | 139 | $feedback = $INDEX_OF[$data[$i] ^ $parity[0]]; |
140 | - if($feedback != $A0) { |
|
140 | + if ($feedback != $A0) { |
|
141 | 141 | // feedback term is non-zero |
142 | 142 | |
143 | 143 | // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must |
144 | 144 | // always be for the polynomials constructed by init_rs() |
145 | 145 | $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback); |
146 | 146 | |
147 | - for($j=1;$j<$NROOTS;$j++) { |
|
148 | - $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])]; |
|
147 | + for ($j = 1; $j < $NROOTS; $j++) { |
|
148 | + $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS - $j])]; |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
152 | 152 | // Shift |
153 | 153 | array_shift($parity); |
154 | - if($feedback != $A0) { |
|
154 | + if ($feedback != $A0) { |
|
155 | 155 | array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]); |
156 | 156 | } else { |
157 | 157 | array_push($parity, 0); |
@@ -41,11 +41,23 @@ discard block |
||
41 | 41 | $rs = null; |
42 | 42 | |
43 | 43 | // Check parameter ranges |
44 | - if($symsize < 0 || $symsize > 8) return $rs; |
|
45 | - if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs; |
|
46 | - if($prim <= 0 || $prim >= (1<<$symsize)) return $rs; |
|
47 | - if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values! |
|
48 | - if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding |
|
44 | + if($symsize < 0 || $symsize > 8) { |
|
45 | + return $rs; |
|
46 | + } |
|
47 | + if($fcr < 0 || $fcr >= (1<<$symsize)) { |
|
48 | + return $rs; |
|
49 | + } |
|
50 | + if($prim <= 0 || $prim >= (1<<$symsize)) { |
|
51 | + return $rs; |
|
52 | + } |
|
53 | + if($nroots < 0 || $nroots >= (1<<$symsize)) { |
|
54 | + return $rs; |
|
55 | + } |
|
56 | + // Can't have more roots than symbol values! |
|
57 | + if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) { |
|
58 | + return $rs; |
|
59 | + } |
|
60 | + // Too much padding |
|
49 | 61 | |
50 | 62 | $rs = new QRrsItem(); |
51 | 63 | $rs->mm = $symsize; |
@@ -111,8 +123,9 @@ discard block |
||
111 | 123 | } |
112 | 124 | |
113 | 125 | // convert rs->genpoly[] to index form for quicker encoding |
114 | - for ($i = 0; $i <= $nroots; $i++) |
|
115 | - $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]]; |
|
126 | + for ($i = 0; $i <= $nroots; $i++) { |
|
127 | + $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]]; |
|
128 | + } |
|
116 | 129 | |
117 | 130 | return $rs; |
118 | 131 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | if ($pos >= strlen($str)) |
53 | 53 | return false; |
54 | 54 | |
55 | - return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); |
|
55 | + return ((ord($str[$pos]) >= ord('0')) && (ord($str[$pos]) <= ord('9'))); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | //---------------------------------------------------------------------- |
@@ -72,17 +72,17 @@ discard block |
||
72 | 72 | |
73 | 73 | $c = $this->dataStr[$pos]; |
74 | 74 | |
75 | - if(self::isdigitat($this->dataStr, $pos)) { |
|
75 | + if (self::isdigitat($this->dataStr, $pos)) { |
|
76 | 76 | return QR_MODE_NUM; |
77 | - } else if(self::isalnumat($this->dataStr, $pos)) { |
|
77 | + } else if (self::isalnumat($this->dataStr, $pos)) { |
|
78 | 78 | return QR_MODE_AN; |
79 | - } else if($this->modeHint == QR_MODE_KANJI) { |
|
79 | + } else if ($this->modeHint == QR_MODE_KANJI) { |
|
80 | 80 | |
81 | - if ($pos+1 < strlen($this->dataStr)) |
|
81 | + if ($pos + 1 < strlen($this->dataStr)) |
|
82 | 82 | { |
83 | - $d = $this->dataStr[$pos+1]; |
|
83 | + $d = $this->dataStr[$pos + 1]; |
|
84 | 84 | $word = (ord($c) << 8) | ord($d); |
85 | - if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) { |
|
85 | + if (($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) { |
|
86 | 86 | return QR_MODE_KANJI; |
87 | 87 | } |
88 | 88 | } |
@@ -97,32 +97,32 @@ discard block |
||
97 | 97 | $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
98 | 98 | |
99 | 99 | $p = 0; |
100 | - while(self::isdigitat($this->dataStr, $p)) { |
|
100 | + while (self::isdigitat($this->dataStr, $p)) { |
|
101 | 101 | $p++; |
102 | 102 | } |
103 | 103 | |
104 | 104 | $run = $p; |
105 | 105 | $mode = $this->identifyMode($p); |
106 | 106 | |
107 | - if($mode == QR_MODE_8) { |
|
107 | + if ($mode == QR_MODE_8) { |
|
108 | 108 | $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
109 | 109 | + QRinput::estimateBitsMode8(1) // + 4 + l8 |
110 | 110 | - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
111 | - if($dif > 0) { |
|
111 | + if ($dif > 0) { |
|
112 | 112 | return $this->eat8(); |
113 | 113 | } |
114 | 114 | } |
115 | - if($mode == QR_MODE_AN) { |
|
115 | + if ($mode == QR_MODE_AN) { |
|
116 | 116 | $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
117 | 117 | + QRinput::estimateBitsModeAn(1) // + 4 + la |
118 | - - QRinput::estimateBitsModeAn($run + 1);// - 4 - la |
|
119 | - if($dif > 0) { |
|
118 | + - QRinput::estimateBitsModeAn($run + 1); // - 4 - la |
|
119 | + if ($dif > 0) { |
|
120 | 120 | return $this->eatAn(); |
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | 124 | $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); |
125 | - if($ret < 0) |
|
125 | + if ($ret < 0) |
|
126 | 126 | return -1; |
127 | 127 | |
128 | 128 | return $run; |
@@ -131,15 +131,15 @@ discard block |
||
131 | 131 | //---------------------------------------------------------------------- |
132 | 132 | public function eatAn() |
133 | 133 | { |
134 | - $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
|
134 | + $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
|
135 | 135 | $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
136 | 136 | |
137 | 137 | $p = 0; |
138 | 138 | |
139 | - while(self::isalnumat($this->dataStr, $p)) { |
|
140 | - if(self::isdigitat($this->dataStr, $p)) { |
|
139 | + while (self::isalnumat($this->dataStr, $p)) { |
|
140 | + if (self::isdigitat($this->dataStr, $p)) { |
|
141 | 141 | $q = $p; |
142 | - while(self::isdigitat($this->dataStr, $q)) { |
|
142 | + while (self::isdigitat($this->dataStr, $q)) { |
|
143 | 143 | $q++; |
144 | 144 | } |
145 | 145 | |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
148 | 148 | - QRinput::estimateBitsModeAn($q); // - 4 - la |
149 | 149 | |
150 | - if($dif < 0) { |
|
150 | + if ($dif < 0) { |
|
151 | 151 | break; |
152 | 152 | } else { |
153 | 153 | $p = $q; |
@@ -159,17 +159,17 @@ discard block |
||
159 | 159 | |
160 | 160 | $run = $p; |
161 | 161 | |
162 | - if(!self::isalnumat($this->dataStr, $p)) { |
|
162 | + if (!self::isalnumat($this->dataStr, $p)) { |
|
163 | 163 | $dif = QRinput::estimateBitsModeAn($run) + 4 + $la |
164 | 164 | + QRinput::estimateBitsMode8(1) // + 4 + l8 |
165 | 165 | - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
166 | - if($dif > 0) { |
|
166 | + if ($dif > 0) { |
|
167 | 167 | return $this->eat8(); |
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | 171 | $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); |
172 | - if($ret < 0) |
|
172 | + if ($ret < 0) |
|
173 | 173 | return -1; |
174 | 174 | |
175 | 175 | return $run; |
@@ -180,12 +180,12 @@ discard block |
||
180 | 180 | { |
181 | 181 | $p = 0; |
182 | 182 | |
183 | - while($this->identifyMode($p) == QR_MODE_KANJI) { |
|
183 | + while ($this->identifyMode($p) == QR_MODE_KANJI) { |
|
184 | 184 | $p += 2; |
185 | 185 | } |
186 | 186 | |
187 | 187 | $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); |
188 | - if($ret < 0) |
|
188 | + if ($ret < 0) |
|
189 | 189 | return -1; |
190 | 190 | |
191 | 191 | return $run; |
@@ -200,34 +200,34 @@ discard block |
||
200 | 200 | $p = 1; |
201 | 201 | $dataStrLen = strlen($this->dataStr); |
202 | 202 | |
203 | - while($p < $dataStrLen) { |
|
203 | + while ($p < $dataStrLen) { |
|
204 | 204 | |
205 | 205 | $mode = $this->identifyMode($p); |
206 | - if($mode == QR_MODE_KANJI) { |
|
206 | + if ($mode == QR_MODE_KANJI) { |
|
207 | 207 | break; |
208 | 208 | } |
209 | - if($mode == QR_MODE_NUM) { |
|
209 | + if ($mode == QR_MODE_NUM) { |
|
210 | 210 | $q = $p; |
211 | - while(self::isdigitat($this->dataStr, $q)) { |
|
211 | + while (self::isdigitat($this->dataStr, $q)) { |
|
212 | 212 | $q++; |
213 | 213 | } |
214 | 214 | $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
215 | 215 | + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
216 | 216 | - QRinput::estimateBitsMode8($q); // - 4 - l8 |
217 | - if($dif < 0) { |
|
217 | + if ($dif < 0) { |
|
218 | 218 | break; |
219 | 219 | } else { |
220 | 220 | $p = $q; |
221 | 221 | } |
222 | - } else if($mode == QR_MODE_AN) { |
|
222 | + } else if ($mode == QR_MODE_AN) { |
|
223 | 223 | $q = $p; |
224 | - while(self::isalnumat($this->dataStr, $q)) { |
|
224 | + while (self::isalnumat($this->dataStr, $q)) { |
|
225 | 225 | $q++; |
226 | 226 | } |
227 | 227 | $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
228 | 228 | + QRinput::estimateBitsModeAn($q - $p) + 4 + $la |
229 | 229 | - QRinput::estimateBitsMode8($q); // - 4 - l8 |
230 | - if($dif < 0) { |
|
230 | + if ($dif < 0) { |
|
231 | 231 | break; |
232 | 232 | } else { |
233 | 233 | $p = $q; |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | $run = $p; |
241 | 241 | $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); |
242 | 242 | |
243 | - if($ret < 0) |
|
243 | + if ($ret < 0) |
|
244 | 244 | return -1; |
245 | 245 | |
246 | 246 | return $run; |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | { |
252 | 252 | while (strlen($this->dataStr) > 0) |
253 | 253 | { |
254 | - if($this->dataStr == '') |
|
254 | + if ($this->dataStr == '') |
|
255 | 255 | return 0; |
256 | 256 | |
257 | 257 | $mode = $this->identifyMode(0); |
@@ -268,8 +268,8 @@ discard block |
||
268 | 268 | |
269 | 269 | } |
270 | 270 | |
271 | - if($length == 0) return 0; |
|
272 | - if($length < 0) return -1; |
|
271 | + if ($length == 0) return 0; |
|
272 | + if ($length < 0) return -1; |
|
273 | 273 | |
274 | 274 | $this->dataStr = substr($this->dataStr, $length); |
275 | 275 | } |
@@ -281,9 +281,9 @@ discard block |
||
281 | 281 | $stringLen = strlen($this->dataStr); |
282 | 282 | $p = 0; |
283 | 283 | |
284 | - while ($p<$stringLen) { |
|
284 | + while ($p < $stringLen) { |
|
285 | 285 | $mode = self::identifyMode(substr($this->dataStr, $p), $this->modeHint); |
286 | - if($mode == QR_MODE_KANJI) { |
|
286 | + if ($mode == QR_MODE_KANJI) { |
|
287 | 287 | $p += 2; |
288 | 288 | } else { |
289 | 289 | if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) { |
@@ -299,13 +299,13 @@ discard block |
||
299 | 299 | //---------------------------------------------------------------------- |
300 | 300 | public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true) |
301 | 301 | { |
302 | - if(is_null($string) || $string == '\0' || $string == '') { |
|
302 | + if (is_null($string) || $string == '\0' || $string == '') { |
|
303 | 303 | throw new Exception('empty string!!!'); |
304 | 304 | } |
305 | 305 | |
306 | 306 | $split = new QRsplit($string, $input, $modeHint); |
307 | 307 | |
308 | - if(!$casesensitive) |
|
308 | + if (!$casesensitive) |
|
309 | 309 | $split->toUpper(); |
310 | 310 | |
311 | 311 | return $split->splitString(); |
@@ -49,8 +49,9 @@ discard block |
||
49 | 49 | //---------------------------------------------------------------------- |
50 | 50 | public static function isdigitat($str, $pos) |
51 | 51 | { |
52 | - if ($pos >= strlen($str)) |
|
53 | - return false; |
|
52 | + if ($pos >= strlen($str)) { |
|
53 | + return false; |
|
54 | + } |
|
54 | 55 | |
55 | 56 | return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); |
56 | 57 | } |
@@ -58,8 +59,9 @@ discard block |
||
58 | 59 | //---------------------------------------------------------------------- |
59 | 60 | public static function isalnumat($str, $pos) |
60 | 61 | { |
61 | - if ($pos >= strlen($str)) |
|
62 | - return false; |
|
62 | + if ($pos >= strlen($str)) { |
|
63 | + return false; |
|
64 | + } |
|
63 | 65 | |
64 | 66 | return (QRinput::lookAnTable(ord($str[$pos])) >= 0); |
65 | 67 | } |
@@ -67,8 +69,9 @@ discard block |
||
67 | 69 | //---------------------------------------------------------------------- |
68 | 70 | public function identifyMode($pos) |
69 | 71 | { |
70 | - if ($pos >= strlen($this->dataStr)) |
|
71 | - return QR_MODE_NUL; |
|
72 | + if ($pos >= strlen($this->dataStr)) { |
|
73 | + return QR_MODE_NUL; |
|
74 | + } |
|
72 | 75 | |
73 | 76 | $c = $this->dataStr[$pos]; |
74 | 77 | |
@@ -122,8 +125,9 @@ discard block |
||
122 | 125 | } |
123 | 126 | |
124 | 127 | $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); |
125 | - if($ret < 0) |
|
126 | - return -1; |
|
128 | + if($ret < 0) { |
|
129 | + return -1; |
|
130 | + } |
|
127 | 131 | |
128 | 132 | return $run; |
129 | 133 | } |
@@ -169,8 +173,9 @@ discard block |
||
169 | 173 | } |
170 | 174 | |
171 | 175 | $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); |
172 | - if($ret < 0) |
|
173 | - return -1; |
|
176 | + if($ret < 0) { |
|
177 | + return -1; |
|
178 | + } |
|
174 | 179 | |
175 | 180 | return $run; |
176 | 181 | } |
@@ -185,8 +190,9 @@ discard block |
||
185 | 190 | } |
186 | 191 | |
187 | 192 | $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); |
188 | - if($ret < 0) |
|
189 | - return -1; |
|
193 | + if($ret < 0) { |
|
194 | + return -1; |
|
195 | + } |
|
190 | 196 | |
191 | 197 | return $run; |
192 | 198 | } |
@@ -240,8 +246,9 @@ discard block |
||
240 | 246 | $run = $p; |
241 | 247 | $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); |
242 | 248 | |
243 | - if($ret < 0) |
|
244 | - return -1; |
|
249 | + if($ret < 0) { |
|
250 | + return -1; |
|
251 | + } |
|
245 | 252 | |
246 | 253 | return $run; |
247 | 254 | } |
@@ -251,8 +258,9 @@ discard block |
||
251 | 258 | { |
252 | 259 | while (strlen($this->dataStr) > 0) |
253 | 260 | { |
254 | - if($this->dataStr == '') |
|
255 | - return 0; |
|
261 | + if($this->dataStr == '') { |
|
262 | + return 0; |
|
263 | + } |
|
256 | 264 | |
257 | 265 | $mode = $this->identifyMode(0); |
258 | 266 | |
@@ -260,16 +268,22 @@ discard block |
||
260 | 268 | case QR_MODE_NUM: $length = $this->eatNum(); break; |
261 | 269 | case QR_MODE_AN: $length = $this->eatAn(); break; |
262 | 270 | case QR_MODE_KANJI: |
263 | - if ($hint == QR_MODE_KANJI) |
|
264 | - $length = $this->eatKanji(); |
|
265 | - else $length = $this->eat8(); |
|
271 | + if ($hint == QR_MODE_KANJI) { |
|
272 | + $length = $this->eatKanji(); |
|
273 | + } else { |
|
274 | + $length = $this->eat8(); |
|
275 | + } |
|
266 | 276 | break; |
267 | 277 | default: $length = $this->eat8(); break; |
268 | 278 | |
269 | 279 | } |
270 | 280 | |
271 | - if($length == 0) return 0; |
|
272 | - if($length < 0) return -1; |
|
281 | + if($length == 0) { |
|
282 | + return 0; |
|
283 | + } |
|
284 | + if($length < 0) { |
|
285 | + return -1; |
|
286 | + } |
|
273 | 287 | |
274 | 288 | $this->dataStr = substr($this->dataStr, $length); |
275 | 289 | } |
@@ -305,8 +319,9 @@ discard block |
||
305 | 319 | |
306 | 320 | $split = new QRsplit($string, $input, $modeHint); |
307 | 321 | |
308 | - if(!$casesensitive) |
|
309 | - $split->toUpper(); |
|
322 | + if(!$casesensitive) { |
|
323 | + $split->toUpper(); |
|
324 | + } |
|
310 | 325 | |
311 | 326 | return $split->splitString(); |
312 | 327 | } |
@@ -23,10 +23,10 @@ discard block |
||
23 | 23 | //---------------------------------------------------------------------- |
24 | 24 | public function __construct(QRinput $input) |
25 | 25 | { |
26 | - $spec = array(0,0,0,0,0); |
|
26 | + $spec = array(0, 0, 0, 0, 0); |
|
27 | 27 | |
28 | 28 | $this->datacode = $input->getByteStream(); |
29 | - if(is_null($this->datacode)) { |
|
29 | + if (is_null($this->datacode)) { |
|
30 | 30 | throw new Exception('null imput string'); |
31 | 31 | } |
32 | 32 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | $this->blocks = QRspec::rsBlockNum($spec); |
41 | 41 | |
42 | 42 | $ret = $this->init($spec); |
43 | - if($ret < 0) { |
|
43 | + if ($ret < 0) { |
|
44 | 44 | throw new Exception('block alloc error'); |
45 | 45 | return null; |
46 | 46 | } |
@@ -59,29 +59,29 @@ discard block |
||
59 | 59 | $blockNo = 0; |
60 | 60 | $dataPos = 0; |
61 | 61 | $eccPos = 0; |
62 | - for($i=0; $i<QRspec::rsBlockNum1($spec); $i++) { |
|
63 | - $ecc = array_slice($this->ecccode,$eccPos); |
|
64 | - $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
|
65 | - $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); |
|
62 | + for ($i = 0; $i < QRspec::rsBlockNum1($spec); $i++) { |
|
63 | + $ecc = array_slice($this->ecccode, $eccPos); |
|
64 | + $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
|
65 | + $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); |
|
66 | 66 | |
67 | 67 | $dataPos += $dl; |
68 | 68 | $eccPos += $el; |
69 | 69 | $blockNo++; |
70 | 70 | } |
71 | 71 | |
72 | - if(QRspec::rsBlockNum2($spec) == 0) |
|
72 | + if (QRspec::rsBlockNum2($spec) == 0) |
|
73 | 73 | return 0; |
74 | 74 | |
75 | 75 | $dl = QRspec::rsDataCodes2($spec); |
76 | 76 | $el = QRspec::rsEccCodes2($spec); |
77 | 77 | $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); |
78 | 78 | |
79 | - if($rs == NULL) return -1; |
|
79 | + if ($rs == NULL) return -1; |
|
80 | 80 | |
81 | - for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) { |
|
82 | - $ecc = array_slice($this->ecccode,$eccPos); |
|
81 | + for ($i = 0; $i < QRspec::rsBlockNum2($spec); $i++) { |
|
82 | + $ecc = array_slice($this->ecccode, $eccPos); |
|
83 | 83 | $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
84 | - $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); |
|
84 | + $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); |
|
85 | 85 | |
86 | 86 | $dataPos += $dl; |
87 | 87 | $eccPos += $el; |
@@ -96,14 +96,14 @@ discard block |
||
96 | 96 | { |
97 | 97 | $ret; |
98 | 98 | |
99 | - if($this->count < $this->dataLength) { |
|
99 | + if ($this->count < $this->dataLength) { |
|
100 | 100 | $row = $this->count % $this->blocks; |
101 | 101 | $col = $this->count / $this->blocks; |
102 | - if($col >= $this->rsblocks[0]->dataLength) { |
|
102 | + if ($col >= $this->rsblocks[0]->dataLength) { |
|
103 | 103 | $row += $this->b1; |
104 | 104 | } |
105 | 105 | $ret = $this->rsblocks[$row]->data[$col]; |
106 | - } else if($this->count < $this->dataLength + $this->eccLength) { |
|
106 | + } else if ($this->count < $this->dataLength + $this->eccLength) { |
|
107 | 107 | $row = ($this->count - $this->dataLength) % $this->blocks; |
108 | 108 | $col = ($this->count - $this->dataLength) / $this->blocks; |
109 | 109 | $ret = $this->rsblocks[$row]->ecc[$col]; |
@@ -69,14 +69,17 @@ |
||
69 | 69 | $blockNo++; |
70 | 70 | } |
71 | 71 | |
72 | - if(QRspec::rsBlockNum2($spec) == 0) |
|
73 | - return 0; |
|
72 | + if(QRspec::rsBlockNum2($spec) == 0) { |
|
73 | + return 0; |
|
74 | + } |
|
74 | 75 | |
75 | 76 | $dl = QRspec::rsDataCodes2($spec); |
76 | 77 | $el = QRspec::rsEccCodes2($spec); |
77 | 78 | $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); |
78 | 79 | |
79 | - if($rs == NULL) return -1; |
|
80 | + if($rs == NULL) { |
|
81 | + return -1; |
|
82 | + } |
|
80 | 83 | |
81 | 84 | for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) { |
82 | 85 | $ecc = array_slice($this->ecccode,$eccPos); |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | $len = count($frame); |
32 | 32 | foreach ($frame as &$frameLine) { |
33 | 33 | |
34 | - for($i=0; $i<$len; $i++) { |
|
35 | - $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; |
|
34 | + for ($i = 0; $i < $len; $i++) { |
|
35 | + $frameLine[$i] = (ord($frameLine[$i])&1) ? '1' : '0'; |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | |
63 | 63 | foreach ($qrTab as $line) { |
64 | 64 | $arrAdd = array(); |
65 | - foreach(str_split($line) as $char) |
|
66 | - $arrAdd[] = ($char=='1')?1:0; |
|
65 | + foreach (str_split($line) as $char) |
|
66 | + $arrAdd[] = ($char == '1') ? 1 : 0; |
|
67 | 67 | $barcode_array['bcode'][] = $arrAdd; |
68 | 68 | } |
69 | 69 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | QRtools::markTime('before_build_cache'); |
83 | 83 | |
84 | 84 | $mask = new QRmask(); |
85 | - for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) { |
|
85 | + for ($a = 1; $a <= QRSPEC_VERSION_MAX; $a++) { |
|
86 | 86 | $frame = QRspec::newFrame($a); |
87 | 87 | if (QR_IMAGE) { |
88 | 88 | $fileName = QR_CACHE_DIR.'frame_'.$a.'.png'; |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | |
92 | 92 | $width = count($frame); |
93 | 93 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
94 | - for ($maskNo=0; $maskNo<8; $maskNo++) |
|
94 | + for ($maskNo = 0; $maskNo < 8; $maskNo++) |
|
95 | 95 | $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
96 | 96 | } |
97 | 97 | |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | public static function dumpMask($frame) |
117 | 117 | { |
118 | 118 | $width = count($frame); |
119 | - for($y=0;$y<$width;$y++) { |
|
120 | - for($x=0;$x<$width;$x++) { |
|
119 | + for ($y = 0; $y < $width; $y++) { |
|
120 | + for ($x = 0; $x < $width; $x++) { |
|
121 | 121 | echo ord($frame[$y][$x]).','; |
122 | 122 | } |
123 | 123 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | public static function markTime($markerId) |
128 | 128 | { |
129 | 129 | list($usec, $sec) = explode(" ", microtime()); |
130 | - $time = ((float)$usec + (float)$sec); |
|
130 | + $time = ((float) $usec + (float) $sec); |
|
131 | 131 | |
132 | 132 | if (!isset($GLOBALS['qr_time_bench'])) |
133 | 133 | $GLOBALS['qr_time_bench'] = array(); |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead> |
149 | 149 | <tbody>'; |
150 | 150 | |
151 | - foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) { |
|
151 | + foreach ($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) { |
|
152 | 152 | if ($p > 0) { |
153 | - echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>'; |
|
153 | + echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime - $lastTime, 6).'s</td></tr>'; |
|
154 | 154 | } else { |
155 | 155 | $startTime = $thisTime; |
156 | 156 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | } |
161 | 161 | |
162 | 162 | echo '</tbody><tfoot> |
163 | - <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr> |
|
163 | + <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime - $startTime, 6).'s</td></tr> |
|
164 | 164 | </tfoot> |
165 | 165 | </table>'; |
166 | 166 | } |
@@ -44,8 +44,9 @@ discard block |
||
44 | 44 | { |
45 | 45 | $barcode_array = array(); |
46 | 46 | |
47 | - if (!is_array($mode)) |
|
48 | - $mode = explode(',', $mode); |
|
47 | + if (!is_array($mode)) { |
|
48 | + $mode = explode(',', $mode); |
|
49 | + } |
|
49 | 50 | |
50 | 51 | $eccLevel = 'L'; |
51 | 52 | |
@@ -62,8 +63,9 @@ discard block |
||
62 | 63 | |
63 | 64 | foreach ($qrTab as $line) { |
64 | 65 | $arrAdd = array(); |
65 | - foreach(str_split($line) as $char) |
|
66 | - $arrAdd[] = ($char=='1')?1:0; |
|
66 | + foreach(str_split($line) as $char) { |
|
67 | + $arrAdd[] = ($char=='1')?1:0; |
|
68 | + } |
|
67 | 69 | $barcode_array['bcode'][] = $arrAdd; |
68 | 70 | } |
69 | 71 | |
@@ -91,8 +93,9 @@ discard block |
||
91 | 93 | |
92 | 94 | $width = count($frame); |
93 | 95 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
94 | - for ($maskNo=0; $maskNo<8; $maskNo++) |
|
95 | - $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
96 | + for ($maskNo=0; $maskNo<8; $maskNo++) { |
|
97 | + $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
98 | + } |
|
96 | 99 | } |
97 | 100 | |
98 | 101 | QRtools::markTime('after_build_cache'); |
@@ -129,8 +132,9 @@ discard block |
||
129 | 132 | list($usec, $sec) = explode(" ", microtime()); |
130 | 133 | $time = ((float)$usec + (float)$sec); |
131 | 134 | |
132 | - if (!isset($GLOBALS['qr_time_bench'])) |
|
133 | - $GLOBALS['qr_time_bench'] = array(); |
|
135 | + if (!isset($GLOBALS['qr_time_bench'])) { |
|
136 | + $GLOBALS['qr_time_bench'] = array(); |
|
137 | + } |
|
134 | 138 | |
135 | 139 | $GLOBALS['qr_time_bench'][$markerId] = $time; |
136 | 140 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | { |
45 | 45 | do { |
46 | 46 | |
47 | - if($this->bit == -1) { |
|
47 | + if ($this->bit == -1) { |
|
48 | 48 | $this->bit = 0; |
49 | 49 | return array('x'=>$this->x, 'y'=>$this->y); |
50 | 50 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $y = $this->y; |
54 | 54 | $w = $this->width; |
55 | 55 | |
56 | - if($this->bit == 0) { |
|
56 | + if ($this->bit == 0) { |
|
57 | 57 | $x--; |
58 | 58 | $this->bit++; |
59 | 59 | } else { |
@@ -62,33 +62,33 @@ discard block |
||
62 | 62 | $this->bit--; |
63 | 63 | } |
64 | 64 | |
65 | - if($this->dir < 0) { |
|
66 | - if($y < 0) { |
|
65 | + if ($this->dir < 0) { |
|
66 | + if ($y < 0) { |
|
67 | 67 | $y = 0; |
68 | 68 | $x -= 2; |
69 | 69 | $this->dir = 1; |
70 | - if($x == 6) { |
|
70 | + if ($x == 6) { |
|
71 | 71 | $x--; |
72 | 72 | $y = 9; |
73 | 73 | } |
74 | 74 | } |
75 | 75 | } else { |
76 | - if($y == $w) { |
|
76 | + if ($y == $w) { |
|
77 | 77 | $y = $w - 1; |
78 | 78 | $x -= 2; |
79 | 79 | $this->dir = -1; |
80 | - if($x == 6) { |
|
80 | + if ($x == 6) { |
|
81 | 81 | $x--; |
82 | 82 | $y -= 8; |
83 | 83 | } |
84 | 84 | } |
85 | 85 | } |
86 | - if($x < 0 || $y < 0) return null; |
|
86 | + if ($x < 0 || $y < 0) return null; |
|
87 | 87 | |
88 | 88 | $this->x = $x; |
89 | 89 | $this->y = $y; |
90 | 90 | |
91 | - } while(ord($this->frame[$y][$x]) & 0x80); |
|
91 | + } while (ord($this->frame[$y][$x]) & 0x80); |
|
92 | 92 | |
93 | 93 | return array('x'=>$x, 'y'=>$y); |
94 | 94 | } |
@@ -83,7 +83,9 @@ |
||
83 | 83 | } |
84 | 84 | } |
85 | 85 | } |
86 | - if($x < 0 || $y < 0) return null; |
|
86 | + if($x < 0 || $y < 0) { |
|
87 | + return null; |
|
88 | + } |
|
87 | 89 | |
88 | 90 | $this->x = $x; |
89 | 91 | $this->y = $y; |
@@ -24,25 +24,25 @@ discard block |
||
24 | 24 | define('QR_ECLEVEL_H', 3); |
25 | 25 | // Supported output formats |
26 | 26 | define('QR_FORMAT_TEXT', 0); |
27 | -define('QR_FORMAT_PNG', 1); |
|
27 | +define('QR_FORMAT_PNG', 1); |
|
28 | 28 | /** |
29 | 29 | * config |
30 | 30 | */ |
31 | -define('QR_CACHEABLE', true); // use cache - more disk reads but less CPU power, masks and format templates are stored there |
|
32 | -define('QR_CACHE_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR); // used when QR_CACHEABLE === true |
|
33 | -define('QR_LOG_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR); // default error logs dir |
|
34 | -define('QR_FIND_BEST_MASK', true); // if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code |
|
35 | -define('QR_FIND_FROM_RANDOM', false); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly |
|
36 | -define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false |
|
37 | -define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images |
|
31 | +define('QR_CACHEABLE', true); // use cache - more disk reads but less CPU power, masks and format templates are stored there |
|
32 | +define('QR_CACHE_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR); // used when QR_CACHEABLE === true |
|
33 | +define('QR_LOG_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR); // default error logs dir |
|
34 | +define('QR_FIND_BEST_MASK', true); // if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code |
|
35 | +define('QR_FIND_FROM_RANDOM', false); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly |
|
36 | +define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false |
|
37 | +define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images |
|
38 | 38 | |
39 | 39 | define('QRSPEC_VERSION_MAX', 40); |
40 | -define('QRSPEC_WIDTH_MAX', 177); |
|
41 | -define('QRCAP_WIDTH', 0); |
|
42 | -define('QRCAP_WORDS', 1); |
|
43 | -define('QRCAP_REMINDER', 2); |
|
44 | -define('QRCAP_EC', 3); |
|
45 | -class Qrcode{ |
|
40 | +define('QRSPEC_WIDTH_MAX', 177); |
|
41 | +define('QRCAP_WIDTH', 0); |
|
42 | +define('QRCAP_WORDS', 1); |
|
43 | +define('QRCAP_REMINDER', 2); |
|
44 | +define('QRCAP_EC', 3); |
|
45 | +class Qrcode { |
|
46 | 46 | |
47 | 47 | |
48 | 48 | public $version; |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | //---------------------------------------------------------------------- |
53 | 53 | public function encodeMask(QRinput $input, $mask) |
54 | 54 | { |
55 | - if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) { |
|
55 | + if ($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) { |
|
56 | 56 | throw new Exception('wrong version'); |
57 | 57 | } |
58 | - if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) { |
|
58 | + if ($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) { |
|
59 | 59 | throw new Exception('wrong level'); |
60 | 60 | } |
61 | 61 | |
@@ -68,15 +68,15 @@ discard block |
||
68 | 68 | $frame = QRspec::newFrame($version); |
69 | 69 | |
70 | 70 | $filler = new FrameFiller($width, $frame); |
71 | - if(is_null($filler)) { |
|
71 | + if (is_null($filler)) { |
|
72 | 72 | return NULL; |
73 | 73 | } |
74 | 74 | |
75 | 75 | // inteleaved data and ecc codes |
76 | - for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) { |
|
76 | + for ($i = 0; $i < $raw->dataLength + $raw->eccLength; $i++) { |
|
77 | 77 | $code = $raw->getCode(); |
78 | 78 | $bit = 0x80; |
79 | - for($j=0; $j<8; $j++) { |
|
79 | + for ($j = 0; $j < 8; $j++) { |
|
80 | 80 | $addr = $filler->next(); |
81 | 81 | $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0)); |
82 | 82 | $bit = $bit >> 1; |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | |
90 | 90 | // remainder bits |
91 | 91 | $j = QRspec::getRemainder($version); |
92 | - for($i=0; $i<$j; $i++) { |
|
92 | + for ($i = 0; $i < $j; $i++) { |
|
93 | 93 | $addr = $filler->next(); |
94 | 94 | $filler->setFrameAt($addr, 0x02); |
95 | 95 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | |
101 | 101 | // masking |
102 | 102 | $maskObj = new QRmask(); |
103 | - if($mask < 0) { |
|
103 | + if ($mask < 0) { |
|
104 | 104 | |
105 | 105 | if (QR_FIND_BEST_MASK) { |
106 | 106 | $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel()); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel()); |
112 | 112 | } |
113 | 113 | |
114 | - if($masked == NULL) { |
|
114 | + if ($masked == NULL) { |
|
115 | 115 | return NULL; |
116 | 116 | } |
117 | 117 | |
@@ -133,16 +133,16 @@ discard block |
||
133 | 133 | //---------------------------------------------------------------------- |
134 | 134 | public function encodeString8bit($string, $version, $level) |
135 | 135 | { |
136 | - if(string == NULL) { |
|
136 | + if (string == NULL) { |
|
137 | 137 | throw new Exception('empty string!'); |
138 | 138 | return NULL; |
139 | 139 | } |
140 | 140 | |
141 | 141 | $input = new QRinput($version, $level); |
142 | - if($input == NULL) return NULL; |
|
142 | + if ($input == NULL) return NULL; |
|
143 | 143 | |
144 | 144 | $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string)); |
145 | - if($ret < 0) { |
|
145 | + if ($ret < 0) { |
|
146 | 146 | unset($input); |
147 | 147 | return NULL; |
148 | 148 | } |
@@ -153,16 +153,16 @@ discard block |
||
153 | 153 | public function encodeString($string, $version, $level, $hint, $casesensitive) |
154 | 154 | { |
155 | 155 | |
156 | - if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) { |
|
156 | + if ($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) { |
|
157 | 157 | throw new Exception('bad hint'); |
158 | 158 | return NULL; |
159 | 159 | } |
160 | 160 | |
161 | 161 | $input = new QRinput($version, $level); |
162 | - if($input == NULL) return NULL; |
|
162 | + if ($input == NULL) return NULL; |
|
163 | 163 | |
164 | 164 | $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive); |
165 | - if($ret < 0) { |
|
165 | + if ($ret < 0) { |
|
166 | 166 | return NULL; |
167 | 167 | } |
168 | 168 | |
@@ -170,10 +170,10 @@ discard block |
||
170 | 170 | } |
171 | 171 | |
172 | 172 | //---------------------------------------------------------------------- |
173 | - public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false) |
|
173 | + public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint = false) |
|
174 | 174 | { |
175 | 175 | $enc = QRencode::factory($level, $size, $margin); |
176 | - return $enc->encodePNG($text, $outfile, $saveandprint=false); |
|
176 | + return $enc->encodePNG($text, $outfile, $saveandprint = false); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | //---------------------------------------------------------------------- |
@@ -139,7 +139,9 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | $input = new QRinput($version, $level); |
142 | - if($input == NULL) return NULL; |
|
142 | + if($input == NULL) { |
|
143 | + return NULL; |
|
144 | + } |
|
143 | 145 | |
144 | 146 | $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string)); |
145 | 147 | if($ret < 0) { |
@@ -159,7 +161,9 @@ discard block |
||
159 | 161 | } |
160 | 162 | |
161 | 163 | $input = new QRinput($version, $level); |
162 | - if($input == NULL) return NULL; |
|
164 | + if($input == NULL) { |
|
165 | + return NULL; |
|
166 | + } |
|
163 | 167 | |
164 | 168 | $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive); |
165 | 169 | if($ret < 0) { |