Passed
Push — master ( 5a5c41...fade3b )
by Cody
04:50 queued 10s
created
lib/phpqrcode/qrencode.php 4 patches
Indentation   +381 added lines, -381 removed lines patch added patch discarded remove patch
@@ -25,478 +25,478 @@
 block discarded – undo
25 25
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 26
  */
27 27
  
28
-    class QRrsblock {
29
-        public $dataLength;
30
-        public $data = array();
31
-        public $eccLength;
32
-        public $ecc = array();
28
+	class QRrsblock {
29
+		public $dataLength;
30
+		public $data = array();
31
+		public $eccLength;
32
+		public $ecc = array();
33 33
         
34
-        public function __construct($dl, $data, $el, &$ecc, QRrsItem $rs)
35
-        {
36
-            $rs->encode_rs_char($data, $ecc);
34
+		public function __construct($dl, $data, $el, &$ecc, QRrsItem $rs)
35
+		{
36
+			$rs->encode_rs_char($data, $ecc);
37 37
         
38
-            $this->dataLength = $dl;
39
-            $this->data = $data;
40
-            $this->eccLength = $el;
41
-            $this->ecc = $ecc;
42
-        }
43
-    };
38
+			$this->dataLength = $dl;
39
+			$this->data = $data;
40
+			$this->eccLength = $el;
41
+			$this->ecc = $ecc;
42
+		}
43
+	};
44 44
     
45
-    //##########################################################################
45
+	//##########################################################################
46 46
 
47
-    class QRrawcode {
48
-        public $version;
49
-        public $datacode = array();
50
-        public $ecccode = array();
51
-        public $blocks;
52
-        public $rsblocks = array(); //of RSblock
53
-        public $count;
54
-        public $dataLength;
55
-        public $eccLength;
56
-        public $b1;
47
+	class QRrawcode {
48
+		public $version;
49
+		public $datacode = array();
50
+		public $ecccode = array();
51
+		public $blocks;
52
+		public $rsblocks = array(); //of RSblock
53
+		public $count;
54
+		public $dataLength;
55
+		public $eccLength;
56
+		public $b1;
57 57
         
58
-        //----------------------------------------------------------------------
59
-        public function __construct(QRinput $input)
60
-        {
61
-            $spec = array(0,0,0,0,0);
58
+		//----------------------------------------------------------------------
59
+		public function __construct(QRinput $input)
60
+		{
61
+			$spec = array(0,0,0,0,0);
62 62
             
63
-            $this->datacode = $input->getByteStream();
64
-            if(is_null($this->datacode)) {
65
-                throw new Exception('null imput string');
66
-            }
63
+			$this->datacode = $input->getByteStream();
64
+			if(is_null($this->datacode)) {
65
+				throw new Exception('null imput string');
66
+			}
67 67
 
68
-            QRspec::getEccSpec($input->getVersion(), $input->getErrorCorrectionLevel(), $spec);
68
+			QRspec::getEccSpec($input->getVersion(), $input->getErrorCorrectionLevel(), $spec);
69 69
 
70
-            $this->version = $input->getVersion();
71
-            $this->b1 = QRspec::rsBlockNum1($spec);
72
-            $this->dataLength = QRspec::rsDataLength($spec);
73
-            $this->eccLength = QRspec::rsEccLength($spec);
74
-            $this->ecccode = array_fill(0, $this->eccLength, 0);
75
-            $this->blocks = QRspec::rsBlockNum($spec);
70
+			$this->version = $input->getVersion();
71
+			$this->b1 = QRspec::rsBlockNum1($spec);
72
+			$this->dataLength = QRspec::rsDataLength($spec);
73
+			$this->eccLength = QRspec::rsEccLength($spec);
74
+			$this->ecccode = array_fill(0, $this->eccLength, 0);
75
+			$this->blocks = QRspec::rsBlockNum($spec);
76 76
             
77
-            $ret = $this->init($spec);
78
-            if($ret < 0) {
79
-                throw new Exception('block alloc error');
80
-                return null;
81
-            }
77
+			$ret = $this->init($spec);
78
+			if($ret < 0) {
79
+				throw new Exception('block alloc error');
80
+				return null;
81
+			}
82 82
 
83
-            $this->count = 0;
84
-        }
83
+			$this->count = 0;
84
+		}
85 85
         
86
-        //----------------------------------------------------------------------
87
-        public function init(array $spec)
88
-        {
89
-            $dl = QRspec::rsDataCodes1($spec);
90
-            $el = QRspec::rsEccCodes1($spec);
91
-            $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
86
+		//----------------------------------------------------------------------
87
+		public function init(array $spec)
88
+		{
89
+			$dl = QRspec::rsDataCodes1($spec);
90
+			$el = QRspec::rsEccCodes1($spec);
91
+			$rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
92 92
             
93 93
 
94
-            $blockNo = 0;
95
-            $dataPos = 0;
96
-            $eccPos = 0;
97
-            for($i=0; $i<QRspec::rsBlockNum1($spec); $i++) {
98
-                $ecc = array_slice($this->ecccode,$eccPos);
99
-                $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el,  $ecc, $rs);
100
-                $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
94
+			$blockNo = 0;
95
+			$dataPos = 0;
96
+			$eccPos = 0;
97
+			for($i=0; $i<QRspec::rsBlockNum1($spec); $i++) {
98
+				$ecc = array_slice($this->ecccode,$eccPos);
99
+				$this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el,  $ecc, $rs);
100
+				$this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
101 101
                 
102
-                $dataPos += $dl;
103
-                $eccPos += $el;
104
-                $blockNo++;
105
-            }
102
+				$dataPos += $dl;
103
+				$eccPos += $el;
104
+				$blockNo++;
105
+			}
106 106
 
107
-            if(QRspec::rsBlockNum2($spec) == 0)
108
-                return 0;
107
+			if(QRspec::rsBlockNum2($spec) == 0)
108
+				return 0;
109 109
 
110
-            $dl = QRspec::rsDataCodes2($spec);
111
-            $el = QRspec::rsEccCodes2($spec);
112
-            $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
110
+			$dl = QRspec::rsDataCodes2($spec);
111
+			$el = QRspec::rsEccCodes2($spec);
112
+			$rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
113 113
             
114
-            if($rs == NULL) return -1;
114
+			if($rs == NULL) return -1;
115 115
             
116
-            for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) {
117
-                $ecc = array_slice($this->ecccode,$eccPos);
118
-                $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs);
119
-                $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
116
+			for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) {
117
+				$ecc = array_slice($this->ecccode,$eccPos);
118
+				$this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs);
119
+				$this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
120 120
                 
121
-                $dataPos += $dl;
122
-                $eccPos += $el;
123
-                $blockNo++;
124
-            }
121
+				$dataPos += $dl;
122
+				$eccPos += $el;
123
+				$blockNo++;
124
+			}
125 125
 
126
-            return 0;
127
-        }
126
+			return 0;
127
+		}
128 128
         
129
-        //----------------------------------------------------------------------
130
-        public function getCode()
131
-        {
132
-            $ret = 0;
129
+		//----------------------------------------------------------------------
130
+		public function getCode()
131
+		{
132
+			$ret = 0;
133 133
 
134
-            if($this->count < $this->dataLength) {
135
-                $row = $this->count % $this->blocks;
136
-                $col = $this->count / $this->blocks;
137
-                if($col >= $this->rsblocks[0]->dataLength) {
138
-                    $row += $this->b1;
139
-                }
140
-                $ret = $this->rsblocks[$row]->data[$col];
141
-            } else if($this->count < $this->dataLength + $this->eccLength) {
142
-                $row = ($this->count - $this->dataLength) % $this->blocks;
143
-                $col = ($this->count - $this->dataLength) / $this->blocks;
144
-                $ret = $this->rsblocks[$row]->ecc[$col];
145
-            } else {
146
-                return 0;
147
-            }
148
-            $this->count++;
134
+			if($this->count < $this->dataLength) {
135
+				$row = $this->count % $this->blocks;
136
+				$col = $this->count / $this->blocks;
137
+				if($col >= $this->rsblocks[0]->dataLength) {
138
+					$row += $this->b1;
139
+				}
140
+				$ret = $this->rsblocks[$row]->data[$col];
141
+			} else if($this->count < $this->dataLength + $this->eccLength) {
142
+				$row = ($this->count - $this->dataLength) % $this->blocks;
143
+				$col = ($this->count - $this->dataLength) / $this->blocks;
144
+				$ret = $this->rsblocks[$row]->ecc[$col];
145
+			} else {
146
+				return 0;
147
+			}
148
+			$this->count++;
149 149
             
150
-            return $ret;
151
-        }
152
-    }
150
+			return $ret;
151
+		}
152
+	}
153 153
 
154
-    //##########################################################################
154
+	//##########################################################################
155 155
     
156
-    class QRcode {
156
+	class QRcode {
157 157
     
158
-        public $version;
159
-        public $width;
160
-        public $data; 
158
+		public $version;
159
+		public $width;
160
+		public $data; 
161 161
         
162
-        //----------------------------------------------------------------------
163
-        public function encodeMask(QRinput $input, $mask)
164
-        {
165
-            if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) {
166
-                throw new Exception('wrong version');
167
-            }
168
-            if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) {
169
-                throw new Exception('wrong level');
170
-            }
162
+		//----------------------------------------------------------------------
163
+		public function encodeMask(QRinput $input, $mask)
164
+		{
165
+			if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) {
166
+				throw new Exception('wrong version');
167
+			}
168
+			if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) {
169
+				throw new Exception('wrong level');
170
+			}
171 171
 
172
-            $raw = new QRrawcode($input);
172
+			$raw = new QRrawcode($input);
173 173
             
174
-            QRtools::markTime('after_raw');
174
+			QRtools::markTime('after_raw');
175 175
             
176
-            $version = $raw->version;
177
-            $width = QRspec::getWidth($version);
178
-            $frame = QRspec::newFrame($version);
176
+			$version = $raw->version;
177
+			$width = QRspec::getWidth($version);
178
+			$frame = QRspec::newFrame($version);
179 179
             
180
-            $filler = new FrameFiller($width, $frame);
181
-            if(is_null($filler)) {
182
-                return NULL;
183
-            }
180
+			$filler = new FrameFiller($width, $frame);
181
+			if(is_null($filler)) {
182
+				return NULL;
183
+			}
184 184
 
185
-            // inteleaved data and ecc codes
186
-            for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) {
187
-                $code = $raw->getCode();
188
-                $bit = 0x80;
189
-                for($j=0; $j<8; $j++) {
190
-                    $addr = $filler->next();
191
-                    $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0));
192
-                    $bit = $bit >> 1;
193
-                }
194
-            }
185
+			// inteleaved data and ecc codes
186
+			for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) {
187
+				$code = $raw->getCode();
188
+				$bit = 0x80;
189
+				for($j=0; $j<8; $j++) {
190
+					$addr = $filler->next();
191
+					$filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0));
192
+					$bit = $bit >> 1;
193
+				}
194
+			}
195 195
             
196
-            QRtools::markTime('after_filler');
196
+			QRtools::markTime('after_filler');
197 197
             
198
-            unset($raw);
198
+			unset($raw);
199 199
             
200
-            // remainder bits
201
-            $j = QRspec::getRemainder($version);
202
-            for($i=0; $i<$j; $i++) {
203
-                $addr = $filler->next();
204
-                $filler->setFrameAt($addr, 0x02);
205
-            }
200
+			// remainder bits
201
+			$j = QRspec::getRemainder($version);
202
+			for($i=0; $i<$j; $i++) {
203
+				$addr = $filler->next();
204
+				$filler->setFrameAt($addr, 0x02);
205
+			}
206 206
             
207
-            $frame = $filler->frame;
208
-            unset($filler);
207
+			$frame = $filler->frame;
208
+			unset($filler);
209 209
             
210 210
             
211
-            // masking
212
-            $maskObj = new QRmask();
213
-            if($mask < 0) {
211
+			// masking
212
+			$maskObj = new QRmask();
213
+			if($mask < 0) {
214 214
             
215
-                if (QR_FIND_BEST_MASK) {
216
-                    $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel());
217
-                } else {
218
-                    $masked = $maskObj->makeMask($width, $frame, (intval(QR_DEFAULT_MASK) % 8), $input->getErrorCorrectionLevel());
219
-                }
220
-            } else {
221
-                $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel());
222
-            }
215
+				if (QR_FIND_BEST_MASK) {
216
+					$masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel());
217
+				} else {
218
+					$masked = $maskObj->makeMask($width, $frame, (intval(QR_DEFAULT_MASK) % 8), $input->getErrorCorrectionLevel());
219
+				}
220
+			} else {
221
+				$masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel());
222
+			}
223 223
             
224
-            if($masked == NULL) {
225
-                return NULL;
226
-            }
224
+			if($masked == NULL) {
225
+				return NULL;
226
+			}
227 227
             
228
-            QRtools::markTime('after_mask');
228
+			QRtools::markTime('after_mask');
229 229
             
230
-            $this->version = $version;
231
-            $this->width = $width;
232
-            $this->data = $masked;
230
+			$this->version = $version;
231
+			$this->width = $width;
232
+			$this->data = $masked;
233 233
             
234
-            return $this;
235
-        }
234
+			return $this;
235
+		}
236 236
     
237
-        //----------------------------------------------------------------------
238
-        public function encodeInput(QRinput $input)
239
-        {
240
-            return $this->encodeMask($input, -1);
241
-        }
237
+		//----------------------------------------------------------------------
238
+		public function encodeInput(QRinput $input)
239
+		{
240
+			return $this->encodeMask($input, -1);
241
+		}
242 242
         
243
-        //----------------------------------------------------------------------
244
-        public function encodeString8bit($string, $version, $level)
245
-        {
246
-            if(string == NULL) {
247
-                throw new Exception('empty string!');
248
-                return NULL;
249
-            }
243
+		//----------------------------------------------------------------------
244
+		public function encodeString8bit($string, $version, $level)
245
+		{
246
+			if(string == NULL) {
247
+				throw new Exception('empty string!');
248
+				return NULL;
249
+			}
250 250
 
251
-            $input = new QRinput($version, $level);
252
-            if($input == NULL) return NULL;
251
+			$input = new QRinput($version, $level);
252
+			if($input == NULL) return NULL;
253 253
 
254
-            $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string));
255
-            if($ret < 0) {
256
-                unset($input);
257
-                return NULL;
258
-            }
259
-            return $this->encodeInput($input);
260
-        }
254
+			$ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string));
255
+			if($ret < 0) {
256
+				unset($input);
257
+				return NULL;
258
+			}
259
+			return $this->encodeInput($input);
260
+		}
261 261
 
262
-        //----------------------------------------------------------------------
263
-        public function encodeString($string, $version, $level, $hint, $casesensitive)
264
-        {
262
+		//----------------------------------------------------------------------
263
+		public function encodeString($string, $version, $level, $hint, $casesensitive)
264
+		{
265 265
 
266
-            if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) {
267
-                throw new Exception('bad hint');
268
-                return NULL;
269
-            }
266
+			if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) {
267
+				throw new Exception('bad hint');
268
+				return NULL;
269
+			}
270 270
 
271
-            $input = new QRinput($version, $level);
272
-            if($input == NULL) return NULL;
271
+			$input = new QRinput($version, $level);
272
+			if($input == NULL) return NULL;
273 273
 
274
-            $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive);
275
-            if($ret < 0) {
276
-                return NULL;
277
-            }
274
+			$ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive);
275
+			if($ret < 0) {
276
+				return NULL;
277
+			}
278 278
 
279
-            return $this->encodeInput($input);
280
-        }
279
+			return $this->encodeInput($input);
280
+		}
281 281
         
282
-        //----------------------------------------------------------------------
283
-        public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false) 
284
-        {
285
-            $enc = QRencode::factory($level, $size, $margin);
286
-            return $enc->encodePNG($text, $outfile, $saveandprint=false);
287
-        }
282
+		//----------------------------------------------------------------------
283
+		public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false) 
284
+		{
285
+			$enc = QRencode::factory($level, $size, $margin);
286
+			return $enc->encodePNG($text, $outfile, $saveandprint=false);
287
+		}
288 288
 
289
-        //----------------------------------------------------------------------
290
-        public static function text($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) 
291
-        {
292
-            $enc = QRencode::factory($level, $size, $margin);
293
-            return $enc->encode($text, $outfile);
294
-        }
289
+		//----------------------------------------------------------------------
290
+		public static function text($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) 
291
+		{
292
+			$enc = QRencode::factory($level, $size, $margin);
293
+			return $enc->encode($text, $outfile);
294
+		}
295 295
 
296
-        //----------------------------------------------------------------------
297
-        public static function raw($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) 
298
-        {
299
-            $enc = QRencode::factory($level, $size, $margin);
300
-            return $enc->encodeRAW($text, $outfile);
301
-        }
302
-    }
296
+		//----------------------------------------------------------------------
297
+		public static function raw($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) 
298
+		{
299
+			$enc = QRencode::factory($level, $size, $margin);
300
+			return $enc->encodeRAW($text, $outfile);
301
+		}
302
+	}
303 303
     
304
-    //##########################################################################
304
+	//##########################################################################
305 305
     
306
-    class FrameFiller {
306
+	class FrameFiller {
307 307
     
308
-        public $width;
309
-        public $frame;
310
-        public $x;
311
-        public $y;
312
-        public $dir;
313
-        public $bit;
308
+		public $width;
309
+		public $frame;
310
+		public $x;
311
+		public $y;
312
+		public $dir;
313
+		public $bit;
314 314
         
315
-        //----------------------------------------------------------------------
316
-        public function __construct($width, &$frame)
317
-        {
318
-            $this->width = $width;
319
-            $this->frame = $frame;
320
-            $this->x = $width - 1;
321
-            $this->y = $width - 1;
322
-            $this->dir = -1;
323
-            $this->bit = -1;
324
-        }
315
+		//----------------------------------------------------------------------
316
+		public function __construct($width, &$frame)
317
+		{
318
+			$this->width = $width;
319
+			$this->frame = $frame;
320
+			$this->x = $width - 1;
321
+			$this->y = $width - 1;
322
+			$this->dir = -1;
323
+			$this->bit = -1;
324
+		}
325 325
         
326
-        //----------------------------------------------------------------------
327
-        public function setFrameAt($at, $val)
328
-        {
329
-            $this->frame[$at['y']][$at['x']] = chr($val);
330
-        }
326
+		//----------------------------------------------------------------------
327
+		public function setFrameAt($at, $val)
328
+		{
329
+			$this->frame[$at['y']][$at['x']] = chr($val);
330
+		}
331 331
         
332
-        //----------------------------------------------------------------------
333
-        public function getFrameAt($at)
334
-        {
335
-            return ord($this->frame[$at['y']][$at['x']]);
336
-        }
332
+		//----------------------------------------------------------------------
333
+		public function getFrameAt($at)
334
+		{
335
+			return ord($this->frame[$at['y']][$at['x']]);
336
+		}
337 337
         
338
-        //----------------------------------------------------------------------
339
-        public function next()
340
-        {
341
-            do {
338
+		//----------------------------------------------------------------------
339
+		public function next()
340
+		{
341
+			do {
342 342
             
343
-                if($this->bit == -1) {
344
-                    $this->bit = 0;
345
-                    return array('x'=>$this->x, 'y'=>$this->y);
346
-                }
343
+				if($this->bit == -1) {
344
+					$this->bit = 0;
345
+					return array('x'=>$this->x, 'y'=>$this->y);
346
+				}
347 347
 
348
-                $x = $this->x;
349
-                $y = $this->y;
350
-                $w = $this->width;
348
+				$x = $this->x;
349
+				$y = $this->y;
350
+				$w = $this->width;
351 351
 
352
-                if($this->bit == 0) {
353
-                    $x--;
354
-                    $this->bit++;
355
-                } else {
356
-                    $x++;
357
-                    $y += $this->dir;
358
-                    $this->bit--;
359
-                }
352
+				if($this->bit == 0) {
353
+					$x--;
354
+					$this->bit++;
355
+				} else {
356
+					$x++;
357
+					$y += $this->dir;
358
+					$this->bit--;
359
+				}
360 360
 
361
-                if($this->dir < 0) {
362
-                    if($y < 0) {
363
-                        $y = 0;
364
-                        $x -= 2;
365
-                        $this->dir = 1;
366
-                        if($x == 6) {
367
-                            $x--;
368
-                            $y = 9;
369
-                        }
370
-                    }
371
-                } else {
372
-                    if($y == $w) {
373
-                        $y = $w - 1;
374
-                        $x -= 2;
375
-                        $this->dir = -1;
376
-                        if($x == 6) {
377
-                            $x--;
378
-                            $y -= 8;
379
-                        }
380
-                    }
381
-                }
382
-                if($x < 0 || $y < 0) return null;
361
+				if($this->dir < 0) {
362
+					if($y < 0) {
363
+						$y = 0;
364
+						$x -= 2;
365
+						$this->dir = 1;
366
+						if($x == 6) {
367
+							$x--;
368
+							$y = 9;
369
+						}
370
+					}
371
+				} else {
372
+					if($y == $w) {
373
+						$y = $w - 1;
374
+						$x -= 2;
375
+						$this->dir = -1;
376
+						if($x == 6) {
377
+							$x--;
378
+							$y -= 8;
379
+						}
380
+					}
381
+				}
382
+				if($x < 0 || $y < 0) return null;
383 383
 
384
-                $this->x = $x;
385
-                $this->y = $y;
384
+				$this->x = $x;
385
+				$this->y = $y;
386 386
 
387
-            } while(ord($this->frame[$y][$x]) & 0x80);
387
+			} while(ord($this->frame[$y][$x]) & 0x80);
388 388
                         
389
-            return array('x'=>$x, 'y'=>$y);
390
-        }
389
+			return array('x'=>$x, 'y'=>$y);
390
+		}
391 391
         
392
-    } ;
392
+	} ;
393 393
     
394
-    //##########################################################################    
394
+	//##########################################################################    
395 395
     
396
-    class QRencode {
396
+	class QRencode {
397 397
     
398
-        public $casesensitive = true;
399
-        public $eightbit = false;
398
+		public $casesensitive = true;
399
+		public $eightbit = false;
400 400
         
401
-        public $version = 0;
402
-        public $size = 3;
403
-        public $margin = 4;
401
+		public $version = 0;
402
+		public $size = 3;
403
+		public $margin = 4;
404 404
         
405
-        public $structured = 0; // not supported yet
405
+		public $structured = 0; // not supported yet
406 406
         
407
-        public $level = QR_ECLEVEL_L;
408
-        public $hint = QR_MODE_8;
407
+		public $level = QR_ECLEVEL_L;
408
+		public $hint = QR_MODE_8;
409 409
         
410
-        //----------------------------------------------------------------------
411
-        public static function factory($level = QR_ECLEVEL_L, $size = 3, $margin = 4)
412
-        {
413
-            $enc = new QRencode();
414
-            $enc->size = $size;
415
-            $enc->margin = $margin;
410
+		//----------------------------------------------------------------------
411
+		public static function factory($level = QR_ECLEVEL_L, $size = 3, $margin = 4)
412
+		{
413
+			$enc = new QRencode();
414
+			$enc->size = $size;
415
+			$enc->margin = $margin;
416 416
             
417
-            switch ($level.'') {
418
-                case '0':
419
-                case '1':
420
-                case '2':
421
-                case '3':
422
-                        $enc->level = $level;
423
-                    break;
424
-                case 'l':
425
-                case 'L':
426
-                        $enc->level = QR_ECLEVEL_L;
427
-                    break;
428
-                case 'm':
429
-                case 'M':
430
-                        $enc->level = QR_ECLEVEL_M;
431
-                    break;
432
-                case 'q':
433
-                case 'Q':
434
-                        $enc->level = QR_ECLEVEL_Q;
435
-                    break;
436
-                case 'h':
437
-                case 'H':
438
-                        $enc->level = QR_ECLEVEL_H;
439
-                    break;
440
-            }
417
+			switch ($level.'') {
418
+				case '0':
419
+				case '1':
420
+				case '2':
421
+				case '3':
422
+						$enc->level = $level;
423
+					break;
424
+				case 'l':
425
+				case 'L':
426
+						$enc->level = QR_ECLEVEL_L;
427
+					break;
428
+				case 'm':
429
+				case 'M':
430
+						$enc->level = QR_ECLEVEL_M;
431
+					break;
432
+				case 'q':
433
+				case 'Q':
434
+						$enc->level = QR_ECLEVEL_Q;
435
+					break;
436
+				case 'h':
437
+				case 'H':
438
+						$enc->level = QR_ECLEVEL_H;
439
+					break;
440
+			}
441 441
             
442
-            return $enc;
443
-        }
442
+			return $enc;
443
+		}
444 444
         
445
-        //----------------------------------------------------------------------
446
-        public function encodeRAW($intext, $outfile = false) 
447
-        {
448
-            $code = new QRcode();
445
+		//----------------------------------------------------------------------
446
+		public function encodeRAW($intext, $outfile = false) 
447
+		{
448
+			$code = new QRcode();
449 449
 
450
-            if($this->eightbit) {
451
-                $code->encodeString8bit($intext, $this->version, $this->level);
452
-            } else {
453
-                $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
454
-            }
450
+			if($this->eightbit) {
451
+				$code->encodeString8bit($intext, $this->version, $this->level);
452
+			} else {
453
+				$code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
454
+			}
455 455
             
456
-            return $code->data;
457
-        }
456
+			return $code->data;
457
+		}
458 458
 
459
-        //----------------------------------------------------------------------
460
-        public function encode($intext, $outfile = false) 
461
-        {
462
-            $code = new QRcode();
459
+		//----------------------------------------------------------------------
460
+		public function encode($intext, $outfile = false) 
461
+		{
462
+			$code = new QRcode();
463 463
 
464
-            if($this->eightbit) {
465
-                $code->encodeString8bit($intext, $this->version, $this->level);
466
-            } else {
467
-                $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
468
-            }
464
+			if($this->eightbit) {
465
+				$code->encodeString8bit($intext, $this->version, $this->level);
466
+			} else {
467
+				$code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
468
+			}
469 469
             
470
-            QRtools::markTime('after_encode');
470
+			QRtools::markTime('after_encode');
471 471
             
472
-            if ($outfile!== false) {
473
-                file_put_contents($outfile, join("\n", QRtools::binarize($code->data)));
474
-            } else {
475
-                return QRtools::binarize($code->data);
476
-            }
477
-        }
472
+			if ($outfile!== false) {
473
+				file_put_contents($outfile, join("\n", QRtools::binarize($code->data)));
474
+			} else {
475
+				return QRtools::binarize($code->data);
476
+			}
477
+		}
478 478
         
479
-        //----------------------------------------------------------------------
480
-        public function encodePNG($intext, $outfile = false,$saveandprint=false) 
481
-        {
482
-            try {
479
+		//----------------------------------------------------------------------
480
+		public function encodePNG($intext, $outfile = false,$saveandprint=false) 
481
+		{
482
+			try {
483 483
             
484
-                ob_start();
485
-                $tab = $this->encode($intext);
486
-                $err = ob_get_contents();
487
-                ob_end_clean();
484
+				ob_start();
485
+				$tab = $this->encode($intext);
486
+				$err = ob_get_contents();
487
+				ob_end_clean();
488 488
                 
489
-                if ($err != '')
490
-                    QRtools::log($outfile, $err);
489
+				if ($err != '')
490
+					QRtools::log($outfile, $err);
491 491
                 
492
-                $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin));
492
+				$maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin));
493 493
                 
494
-                QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint);
494
+				QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint);
495 495
             
496
-            } catch (Exception $e) {
496
+			} catch (Exception $e) {
497 497
             
498
-                QRtools::log($outfile, $e->getMessage());
498
+				QRtools::log($outfile, $e->getMessage());
499 499
             
500
-            }
501
-        }
502
-    }
500
+			}
501
+		}
502
+	}
Please login to merge, or discard this patch.
Switch Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -415,28 +415,28 @@
 block discarded – undo
415 415
             $enc->margin = $margin;
416 416
             
417 417
             switch ($level.'') {
418
-                case '0':
419
-                case '1':
420
-                case '2':
421
-                case '3':
422
-                        $enc->level = $level;
423
-                    break;
424
-                case 'l':
425
-                case 'L':
426
-                        $enc->level = QR_ECLEVEL_L;
427
-                    break;
428
-                case 'm':
429
-                case 'M':
430
-                        $enc->level = QR_ECLEVEL_M;
431
-                    break;
432
-                case 'q':
433
-                case 'Q':
434
-                        $enc->level = QR_ECLEVEL_Q;
435
-                    break;
436
-                case 'h':
437
-                case 'H':
438
-                        $enc->level = QR_ECLEVEL_H;
439
-                    break;
418
+            case '0':
419
+            case '1':
420
+            case '2':
421
+            case '3':
422
+                    $enc->level = $level;
423
+                break;
424
+            case 'l':
425
+            case 'L':
426
+                    $enc->level = QR_ECLEVEL_L;
427
+                break;
428
+            case 'm':
429
+            case 'M':
430
+                    $enc->level = QR_ECLEVEL_M;
431
+                break;
432
+            case 'q':
433
+            case 'Q':
434
+                    $enc->level = QR_ECLEVEL_Q;
435
+                break;
436
+            case 'h':
437
+            case 'H':
438
+                    $enc->level = QR_ECLEVEL_H;
439
+                break;
440 440
             }
441 441
             
442 442
             return $enc;
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -58,10 +58,10 @@  discard block
 block discarded – undo
58 58
         //----------------------------------------------------------------------
59 59
         public function __construct(QRinput $input)
60 60
         {
61
-            $spec = array(0,0,0,0,0);
61
+            $spec = array(0, 0, 0, 0, 0);
62 62
             
63 63
             $this->datacode = $input->getByteStream();
64
-            if(is_null($this->datacode)) {
64
+            if (is_null($this->datacode)) {
65 65
                 throw new Exception('null imput string');
66 66
             }
67 67
 
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
             $this->blocks = QRspec::rsBlockNum($spec);
76 76
             
77 77
             $ret = $this->init($spec);
78
-            if($ret < 0) {
78
+            if ($ret < 0) {
79 79
                 throw new Exception('block alloc error');
80 80
                 return null;
81 81
             }
@@ -94,29 +94,29 @@  discard block
 block discarded – undo
94 94
             $blockNo = 0;
95 95
             $dataPos = 0;
96 96
             $eccPos = 0;
97
-            for($i=0; $i<QRspec::rsBlockNum1($spec); $i++) {
98
-                $ecc = array_slice($this->ecccode,$eccPos);
99
-                $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el,  $ecc, $rs);
100
-                $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
97
+            for ($i = 0; $i < QRspec::rsBlockNum1($spec); $i++) {
98
+                $ecc = array_slice($this->ecccode, $eccPos);
99
+                $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs);
100
+                $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc);
101 101
                 
102 102
                 $dataPos += $dl;
103 103
                 $eccPos += $el;
104 104
                 $blockNo++;
105 105
             }
106 106
 
107
-            if(QRspec::rsBlockNum2($spec) == 0)
107
+            if (QRspec::rsBlockNum2($spec) == 0)
108 108
                 return 0;
109 109
 
110 110
             $dl = QRspec::rsDataCodes2($spec);
111 111
             $el = QRspec::rsEccCodes2($spec);
112 112
             $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
113 113
             
114
-            if($rs == NULL) return -1;
114
+            if ($rs == NULL) return -1;
115 115
             
116
-            for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) {
117
-                $ecc = array_slice($this->ecccode,$eccPos);
116
+            for ($i = 0; $i < QRspec::rsBlockNum2($spec); $i++) {
117
+                $ecc = array_slice($this->ecccode, $eccPos);
118 118
                 $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs);
119
-                $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
119
+                $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc);
120 120
                 
121 121
                 $dataPos += $dl;
122 122
                 $eccPos += $el;
@@ -131,14 +131,14 @@  discard block
 block discarded – undo
131 131
         {
132 132
             $ret = 0;
133 133
 
134
-            if($this->count < $this->dataLength) {
134
+            if ($this->count < $this->dataLength) {
135 135
                 $row = $this->count % $this->blocks;
136 136
                 $col = $this->count / $this->blocks;
137
-                if($col >= $this->rsblocks[0]->dataLength) {
137
+                if ($col >= $this->rsblocks[0]->dataLength) {
138 138
                     $row += $this->b1;
139 139
                 }
140 140
                 $ret = $this->rsblocks[$row]->data[$col];
141
-            } else if($this->count < $this->dataLength + $this->eccLength) {
141
+            } else if ($this->count < $this->dataLength + $this->eccLength) {
142 142
                 $row = ($this->count - $this->dataLength) % $this->blocks;
143 143
                 $col = ($this->count - $this->dataLength) / $this->blocks;
144 144
                 $ret = $this->rsblocks[$row]->ecc[$col];
@@ -162,10 +162,10 @@  discard block
 block discarded – undo
162 162
         //----------------------------------------------------------------------
163 163
         public function encodeMask(QRinput $input, $mask)
164 164
         {
165
-            if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) {
165
+            if ($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) {
166 166
                 throw new Exception('wrong version');
167 167
             }
168
-            if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) {
168
+            if ($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) {
169 169
                 throw new Exception('wrong level');
170 170
             }
171 171
 
@@ -178,15 +178,15 @@  discard block
 block discarded – undo
178 178
             $frame = QRspec::newFrame($version);
179 179
             
180 180
             $filler = new FrameFiller($width, $frame);
181
-            if(is_null($filler)) {
181
+            if (is_null($filler)) {
182 182
                 return NULL;
183 183
             }
184 184
 
185 185
             // inteleaved data and ecc codes
186
-            for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) {
186
+            for ($i = 0; $i < $raw->dataLength + $raw->eccLength; $i++) {
187 187
                 $code = $raw->getCode();
188 188
                 $bit = 0x80;
189
-                for($j=0; $j<8; $j++) {
189
+                for ($j = 0; $j < 8; $j++) {
190 190
                     $addr = $filler->next();
191 191
                     $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0));
192 192
                     $bit = $bit >> 1;
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
             
200 200
             // remainder bits
201 201
             $j = QRspec::getRemainder($version);
202
-            for($i=0; $i<$j; $i++) {
202
+            for ($i = 0; $i < $j; $i++) {
203 203
                 $addr = $filler->next();
204 204
                 $filler->setFrameAt($addr, 0x02);
205 205
             }
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
             
211 211
             // masking
212 212
             $maskObj = new QRmask();
213
-            if($mask < 0) {
213
+            if ($mask < 0) {
214 214
             
215 215
                 if (QR_FIND_BEST_MASK) {
216 216
                     $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel());
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
                 $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel());
222 222
             }
223 223
             
224
-            if($masked == NULL) {
224
+            if ($masked == NULL) {
225 225
                 return NULL;
226 226
             }
227 227
             
@@ -243,16 +243,16 @@  discard block
 block discarded – undo
243 243
         //----------------------------------------------------------------------
244 244
         public function encodeString8bit($string, $version, $level)
245 245
         {
246
-            if(string == NULL) {
246
+            if (string == NULL) {
247 247
                 throw new Exception('empty string!');
248 248
                 return NULL;
249 249
             }
250 250
 
251 251
             $input = new QRinput($version, $level);
252
-            if($input == NULL) return NULL;
252
+            if ($input == NULL) return NULL;
253 253
 
254 254
             $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string));
255
-            if($ret < 0) {
255
+            if ($ret < 0) {
256 256
                 unset($input);
257 257
                 return NULL;
258 258
             }
@@ -263,16 +263,16 @@  discard block
 block discarded – undo
263 263
         public function encodeString($string, $version, $level, $hint, $casesensitive)
264 264
         {
265 265
 
266
-            if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) {
266
+            if ($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) {
267 267
                 throw new Exception('bad hint');
268 268
                 return NULL;
269 269
             }
270 270
 
271 271
             $input = new QRinput($version, $level);
272
-            if($input == NULL) return NULL;
272
+            if ($input == NULL) return NULL;
273 273
 
274 274
             $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive);
275
-            if($ret < 0) {
275
+            if ($ret < 0) {
276 276
                 return NULL;
277 277
             }
278 278
 
@@ -280,10 +280,10 @@  discard block
 block discarded – undo
280 280
         }
281 281
         
282 282
         //----------------------------------------------------------------------
283
-        public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false) 
283
+        public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint = false) 
284 284
         {
285 285
             $enc = QRencode::factory($level, $size, $margin);
286
-            return $enc->encodePNG($text, $outfile, $saveandprint=false);
286
+            return $enc->encodePNG($text, $outfile, $saveandprint = false);
287 287
         }
288 288
 
289 289
         //----------------------------------------------------------------------
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
         {
341 341
             do {
342 342
             
343
-                if($this->bit == -1) {
343
+                if ($this->bit == -1) {
344 344
                     $this->bit = 0;
345 345
                     return array('x'=>$this->x, 'y'=>$this->y);
346 346
                 }
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
                 $y = $this->y;
350 350
                 $w = $this->width;
351 351
 
352
-                if($this->bit == 0) {
352
+                if ($this->bit == 0) {
353 353
                     $x--;
354 354
                     $this->bit++;
355 355
                 } else {
@@ -358,33 +358,33 @@  discard block
 block discarded – undo
358 358
                     $this->bit--;
359 359
                 }
360 360
 
361
-                if($this->dir < 0) {
362
-                    if($y < 0) {
361
+                if ($this->dir < 0) {
362
+                    if ($y < 0) {
363 363
                         $y = 0;
364 364
                         $x -= 2;
365 365
                         $this->dir = 1;
366
-                        if($x == 6) {
366
+                        if ($x == 6) {
367 367
                             $x--;
368 368
                             $y = 9;
369 369
                         }
370 370
                     }
371 371
                 } else {
372
-                    if($y == $w) {
372
+                    if ($y == $w) {
373 373
                         $y = $w - 1;
374 374
                         $x -= 2;
375 375
                         $this->dir = -1;
376
-                        if($x == 6) {
376
+                        if ($x == 6) {
377 377
                             $x--;
378 378
                             $y -= 8;
379 379
                         }
380 380
                     }
381 381
                 }
382
-                if($x < 0 || $y < 0) return null;
382
+                if ($x < 0 || $y < 0) return null;
383 383
 
384 384
                 $this->x = $x;
385 385
                 $this->y = $y;
386 386
 
387
-            } while(ord($this->frame[$y][$x]) & 0x80);
387
+            } while (ord($this->frame[$y][$x]) & 0x80);
388 388
                         
389 389
             return array('x'=>$x, 'y'=>$y);
390 390
         }
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
         {
448 448
             $code = new QRcode();
449 449
 
450
-            if($this->eightbit) {
450
+            if ($this->eightbit) {
451 451
                 $code->encodeString8bit($intext, $this->version, $this->level);
452 452
             } else {
453 453
                 $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
         {
462 462
             $code = new QRcode();
463 463
 
464
-            if($this->eightbit) {
464
+            if ($this->eightbit) {
465 465
                 $code->encodeString8bit($intext, $this->version, $this->level);
466 466
             } else {
467 467
                 $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
@@ -469,7 +469,7 @@  discard block
 block discarded – undo
469 469
             
470 470
             QRtools::markTime('after_encode');
471 471
             
472
-            if ($outfile!== false) {
472
+            if ($outfile !== false) {
473 473
                 file_put_contents($outfile, join("\n", QRtools::binarize($code->data)));
474 474
             } else {
475 475
                 return QRtools::binarize($code->data);
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
         }
478 478
         
479 479
         //----------------------------------------------------------------------
480
-        public function encodePNG($intext, $outfile = false,$saveandprint=false) 
480
+        public function encodePNG($intext, $outfile = false, $saveandprint = false) 
481 481
         {
482 482
             try {
483 483
             
@@ -489,9 +489,9 @@  discard block
 block discarded – undo
489 489
                 if ($err != '')
490 490
                     QRtools::log($outfile, $err);
491 491
                 
492
-                $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin));
492
+                $maxSize = (int) (QR_PNG_MAXIMUM_SIZE / (count($tab) + 2 * $this->margin));
493 493
                 
494
-                QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint);
494
+                QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin, $saveandprint);
495 495
             
496 496
             } catch (Exception $e) {
497 497
             
Please login to merge, or discard this patch.
Braces   +18 added lines, -8 removed lines patch added patch discarded remove patch
@@ -104,14 +104,17 @@  discard block
 block discarded – undo
104 104
                 $blockNo++;
105 105
             }
106 106
 
107
-            if(QRspec::rsBlockNum2($spec) == 0)
108
-                return 0;
107
+            if(QRspec::rsBlockNum2($spec) == 0) {
108
+                            return 0;
109
+            }
109 110
 
110 111
             $dl = QRspec::rsDataCodes2($spec);
111 112
             $el = QRspec::rsEccCodes2($spec);
112 113
             $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
113 114
             
114
-            if($rs == NULL) return -1;
115
+            if($rs == NULL) {
116
+            	return -1;
117
+            }
115 118
             
116 119
             for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) {
117 120
                 $ecc = array_slice($this->ecccode,$eccPos);
@@ -249,7 +252,9 @@  discard block
 block discarded – undo
249 252
             }
250 253
 
251 254
             $input = new QRinput($version, $level);
252
-            if($input == NULL) return NULL;
255
+            if($input == NULL) {
256
+            	return NULL;
257
+            }
253 258
 
254 259
             $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string));
255 260
             if($ret < 0) {
@@ -269,7 +274,9 @@  discard block
 block discarded – undo
269 274
             }
270 275
 
271 276
             $input = new QRinput($version, $level);
272
-            if($input == NULL) return NULL;
277
+            if($input == NULL) {
278
+            	return NULL;
279
+            }
273 280
 
274 281
             $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive);
275 282
             if($ret < 0) {
@@ -379,7 +386,9 @@  discard block
 block discarded – undo
379 386
                         }
380 387
                     }
381 388
                 }
382
-                if($x < 0 || $y < 0) return null;
389
+                if($x < 0 || $y < 0) {
390
+                	return null;
391
+                }
383 392
 
384 393
                 $this->x = $x;
385 394
                 $this->y = $y;
@@ -486,8 +495,9 @@  discard block
 block discarded – undo
486 495
                 $err = ob_get_contents();
487 496
                 ob_end_clean();
488 497
                 
489
-                if ($err != '')
490
-                    QRtools::log($outfile, $err);
498
+                if ($err != '') {
499
+                                    QRtools::log($outfile, $err);
500
+                }
491 501
                 
492 502
                 $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin));
493 503
                 
Please login to merge, or discard this patch.
lib/phpqrcode/qrrscode.php 3 patches
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -28,183 +28,183 @@
 block discarded – undo
28 28
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 29
  */
30 30
  
31
-    class QRrsItem {
31
+	class QRrsItem {
32 32
     
33
-        public $mm;                  // Bits per symbol 
34
-        public $nn;                  // Symbols per block (= (1<<mm)-1) 
35
-        public $alpha_to = array();  // log lookup table 
36
-        public $index_of = array();  // Antilog lookup table 
37
-        public $genpoly = array();   // Generator polynomial 
38
-        public $nroots;              // Number of generator roots = number of parity symbols 
39
-        public $fcr;                 // First consecutive root, index form 
40
-        public $prim;                // Primitive element, index form 
41
-        public $iprim;               // prim-th root of 1, index form 
42
-        public $pad;                 // Padding bytes in shortened block 
43
-        public $gfpoly;
33
+		public $mm;                  // Bits per symbol 
34
+		public $nn;                  // Symbols per block (= (1<<mm)-1) 
35
+		public $alpha_to = array();  // log lookup table 
36
+		public $index_of = array();  // Antilog lookup table 
37
+		public $genpoly = array();   // Generator polynomial 
38
+		public $nroots;              // Number of generator roots = number of parity symbols 
39
+		public $fcr;                 // First consecutive root, index form 
40
+		public $prim;                // Primitive element, index form 
41
+		public $iprim;               // prim-th root of 1, index form 
42
+		public $pad;                 // Padding bytes in shortened block 
43
+		public $gfpoly;
44 44
     
45
-        //----------------------------------------------------------------------
46
-        public function modnn($x)
47
-        {
48
-            while ($x >= $this->nn) {
49
-                $x -= $this->nn;
50
-                $x = ($x >> $this->mm) + ($x & $this->nn);
51
-            }
45
+		//----------------------------------------------------------------------
46
+		public function modnn($x)
47
+		{
48
+			while ($x >= $this->nn) {
49
+				$x -= $this->nn;
50
+				$x = ($x >> $this->mm) + ($x & $this->nn);
51
+			}
52 52
             
53
-            return $x;
54
-        }
53
+			return $x;
54
+		}
55 55
         
56
-        //----------------------------------------------------------------------
57
-        public static function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
58
-        {
59
-            // Common code for intializing a Reed-Solomon control block (char or int symbols)
60
-            // Copyright 2004 Phil Karn, KA9Q
61
-            // May be used under the terms of the GNU Lesser General Public License (LGPL)
56
+		//----------------------------------------------------------------------
57
+		public static function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
58
+		{
59
+			// Common code for intializing a Reed-Solomon control block (char or int symbols)
60
+			// Copyright 2004 Phil Karn, KA9Q
61
+			// May be used under the terms of the GNU Lesser General Public License (LGPL)
62 62
 
63
-            $rs = null;
63
+			$rs = null;
64 64
             
65
-            // Check parameter ranges
66
-            if($symsize < 0 || $symsize > 8)                     return $rs;
67
-            if($fcr < 0 || $fcr >= (1<<$symsize))                return $rs;
68
-            if($prim <= 0 || $prim >= (1<<$symsize))             return $rs;
69
-            if($nroots < 0 || $nroots >= (1<<$symsize))          return $rs; // Can't have more roots than symbol values!
70
-            if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding
65
+			// Check parameter ranges
66
+			if($symsize < 0 || $symsize > 8)                     return $rs;
67
+			if($fcr < 0 || $fcr >= (1<<$symsize))                return $rs;
68
+			if($prim <= 0 || $prim >= (1<<$symsize))             return $rs;
69
+			if($nroots < 0 || $nroots >= (1<<$symsize))          return $rs; // Can't have more roots than symbol values!
70
+			if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding
71 71
 
72
-            $rs = new QRrsItem();
73
-            $rs->mm = $symsize;
74
-            $rs->nn = (1<<$symsize)-1;
75
-            $rs->pad = $pad;
72
+			$rs = new QRrsItem();
73
+			$rs->mm = $symsize;
74
+			$rs->nn = (1<<$symsize)-1;
75
+			$rs->pad = $pad;
76 76
 
77
-            $rs->alpha_to = array_fill(0, $rs->nn+1, 0);
78
-            $rs->index_of = array_fill(0, $rs->nn+1, 0);
77
+			$rs->alpha_to = array_fill(0, $rs->nn+1, 0);
78
+			$rs->index_of = array_fill(0, $rs->nn+1, 0);
79 79
           
80
-            // PHP style macro replacement ;)
81
-            $NN =& $rs->nn;
82
-            $A0 =& $NN;
80
+			// PHP style macro replacement ;)
81
+			$NN =& $rs->nn;
82
+			$A0 =& $NN;
83 83
             
84
-            // Generate Galois field lookup tables
85
-            $rs->index_of[0] = $A0; // log(zero) = -inf
86
-            $rs->alpha_to[$A0] = 0; // alpha**-inf = 0
87
-            $sr = 1;
84
+			// Generate Galois field lookup tables
85
+			$rs->index_of[0] = $A0; // log(zero) = -inf
86
+			$rs->alpha_to[$A0] = 0; // alpha**-inf = 0
87
+			$sr = 1;
88 88
           
89
-            for($i=0; $i<$rs->nn; $i++) {
90
-                $rs->index_of[$sr] = $i;
91
-                $rs->alpha_to[$i] = $sr;
92
-                $sr <<= 1;
93
-                if($sr & (1<<$symsize)) {
94
-                    $sr ^= $gfpoly;
95
-                }
96
-                $sr &= $rs->nn;
97
-            }
89
+			for($i=0; $i<$rs->nn; $i++) {
90
+				$rs->index_of[$sr] = $i;
91
+				$rs->alpha_to[$i] = $sr;
92
+				$sr <<= 1;
93
+				if($sr & (1<<$symsize)) {
94
+					$sr ^= $gfpoly;
95
+				}
96
+				$sr &= $rs->nn;
97
+			}
98 98
             
99
-            if($sr != 1){
100
-                // field generator polynomial is not primitive!
101
-                $rs = NULL;
102
-                return $rs;
103
-            }
99
+			if($sr != 1){
100
+				// field generator polynomial is not primitive!
101
+				$rs = NULL;
102
+				return $rs;
103
+			}
104 104
 
105
-            /* Form RS code generator polynomial from its roots */
106
-            $rs->genpoly = array_fill(0, $nroots+1, 0);
105
+			/* Form RS code generator polynomial from its roots */
106
+			$rs->genpoly = array_fill(0, $nroots+1, 0);
107 107
         
108
-            $rs->fcr = $fcr;
109
-            $rs->prim = $prim;
110
-            $rs->nroots = $nroots;
111
-            $rs->gfpoly = $gfpoly;
108
+			$rs->fcr = $fcr;
109
+			$rs->prim = $prim;
110
+			$rs->nroots = $nroots;
111
+			$rs->gfpoly = $gfpoly;
112 112
 
113
-            /* Find prim-th root of 1, used in decoding */
114
-            for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn)
115
-            ; // intentional empty-body loop!
113
+			/* Find prim-th root of 1, used in decoding */
114
+			for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn)
115
+			; // intentional empty-body loop!
116 116
             
117
-            $rs->iprim = (int)($iprim / $prim);
118
-            $rs->genpoly[0] = 1;
117
+			$rs->iprim = (int)($iprim / $prim);
118
+			$rs->genpoly[0] = 1;
119 119
             
120
-            for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) {
121
-                $rs->genpoly[$i+1] = 1;
120
+			for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) {
121
+				$rs->genpoly[$i+1] = 1;
122 122
 
123
-                // Multiply rs->genpoly[] by  @**(root + x)
124
-                for ($j = $i; $j > 0; $j--) {
125
-                    if ($rs->genpoly[$j] != 0) {
126
-                        $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)];
127
-                    } else {
128
-                        $rs->genpoly[$j] = $rs->genpoly[$j-1];
129
-                    }
130
-                }
131
-                // rs->genpoly[0] can never be zero
132
-                $rs->genpoly[0] = $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[0]] + $root)];
133
-            }
123
+				// Multiply rs->genpoly[] by  @**(root + x)
124
+				for ($j = $i; $j > 0; $j--) {
125
+					if ($rs->genpoly[$j] != 0) {
126
+						$rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)];
127
+					} else {
128
+						$rs->genpoly[$j] = $rs->genpoly[$j-1];
129
+					}
130
+				}
131
+				// rs->genpoly[0] can never be zero
132
+				$rs->genpoly[0] = $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[0]] + $root)];
133
+			}
134 134
             
135
-            // convert rs->genpoly[] to index form for quicker encoding
136
-            for ($i = 0; $i <= $nroots; $i++)
137
-                $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]];
135
+			// convert rs->genpoly[] to index form for quicker encoding
136
+			for ($i = 0; $i <= $nroots; $i++)
137
+				$rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]];
138 138
 
139
-            return $rs;
140
-        }
139
+			return $rs;
140
+		}
141 141
         
142
-        //----------------------------------------------------------------------
143
-        public function encode_rs_char($data, &$parity)
144
-        {
145
-            $MM       =& $this->mm;
146
-            $NN       =& $this->nn;
147
-            $ALPHA_TO =& $this->alpha_to;
148
-            $INDEX_OF =& $this->index_of;
149
-            $GENPOLY  =& $this->genpoly;
150
-            $NROOTS   =& $this->nroots;
151
-            $FCR      =& $this->fcr;
152
-            $PRIM     =& $this->prim;
153
-            $IPRIM    =& $this->iprim;
154
-            $PAD      =& $this->pad;
155
-            $A0       =& $NN;
142
+		//----------------------------------------------------------------------
143
+		public function encode_rs_char($data, &$parity)
144
+		{
145
+			$MM       =& $this->mm;
146
+			$NN       =& $this->nn;
147
+			$ALPHA_TO =& $this->alpha_to;
148
+			$INDEX_OF =& $this->index_of;
149
+			$GENPOLY  =& $this->genpoly;
150
+			$NROOTS   =& $this->nroots;
151
+			$FCR      =& $this->fcr;
152
+			$PRIM     =& $this->prim;
153
+			$IPRIM    =& $this->iprim;
154
+			$PAD      =& $this->pad;
155
+			$A0       =& $NN;
156 156
 
157
-            $parity = array_fill(0, $NROOTS, 0);
157
+			$parity = array_fill(0, $NROOTS, 0);
158 158
 
159
-            for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) {
159
+			for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) {
160 160
                 
161
-                $feedback = $INDEX_OF[$data[$i] ^ $parity[0]];
162
-                if($feedback != $A0) {      
163
-                    // feedback term is non-zero
161
+				$feedback = $INDEX_OF[$data[$i] ^ $parity[0]];
162
+				if($feedback != $A0) {      
163
+					// feedback term is non-zero
164 164
             
165
-                    // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
166
-                    // always be for the polynomials constructed by init_rs()
167
-                    $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback);
165
+					// This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
166
+					// always be for the polynomials constructed by init_rs()
167
+					$feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback);
168 168
             
169
-                    for($j=1;$j<$NROOTS;$j++) {
170
-                        $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])];
171
-                    }
172
-                }
169
+					for($j=1;$j<$NROOTS;$j++) {
170
+						$parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])];
171
+					}
172
+				}
173 173
                 
174
-                // Shift 
175
-                array_shift($parity);
176
-                if($feedback != $A0) {
177
-                    array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]);
178
-                } else {
179
-                    array_push($parity, 0);
180
-                }
181
-            }
182
-        }
183
-    }
174
+				// Shift 
175
+				array_shift($parity);
176
+				if($feedback != $A0) {
177
+					array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]);
178
+				} else {
179
+					array_push($parity, 0);
180
+				}
181
+			}
182
+		}
183
+	}
184 184
     
185
-    //##########################################################################
185
+	//##########################################################################
186 186
     
187
-    class QRrs {
187
+	class QRrs {
188 188
     
189
-        public static $items = array();
189
+		public static $items = array();
190 190
         
191
-        //----------------------------------------------------------------------
192
-        public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
193
-        {
194
-            foreach(self::$items as $rs) {
195
-                if($rs->pad != $pad)       continue;
196
-                if($rs->nroots != $nroots) continue;
197
-                if($rs->mm != $symsize)    continue;
198
-                if($rs->gfpoly != $gfpoly) continue;
199
-                if($rs->fcr != $fcr)       continue;
200
-                if($rs->prim != $prim)     continue;
191
+		//----------------------------------------------------------------------
192
+		public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
193
+		{
194
+			foreach(self::$items as $rs) {
195
+				if($rs->pad != $pad)       continue;
196
+				if($rs->nroots != $nroots) continue;
197
+				if($rs->mm != $symsize)    continue;
198
+				if($rs->gfpoly != $gfpoly) continue;
199
+				if($rs->fcr != $fcr)       continue;
200
+				if($rs->prim != $prim)     continue;
201 201
 
202
-                return $rs;
203
-            }
202
+				return $rs;
203
+			}
204 204
 
205
-            $rs = QRrsItem::init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad);
206
-            array_unshift(self::$items, $rs);
205
+			$rs = QRrsItem::init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad);
206
+			array_unshift(self::$items, $rs);
207 207
 
208
-            return $rs;
209
-        }
210
-    }
211 208
\ No newline at end of file
209
+			return $rs;
210
+		}
211
+	}
212 212
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -30,16 +30,16 @@  discard block
 block discarded – undo
30 30
  
31 31
     class QRrsItem {
32 32
     
33
-        public $mm;                  // Bits per symbol 
34
-        public $nn;                  // Symbols per block (= (1<<mm)-1) 
35
-        public $alpha_to = array();  // log lookup table 
36
-        public $index_of = array();  // Antilog lookup table 
37
-        public $genpoly = array();   // Generator polynomial 
38
-        public $nroots;              // Number of generator roots = number of parity symbols 
39
-        public $fcr;                 // First consecutive root, index form 
40
-        public $prim;                // Primitive element, index form 
41
-        public $iprim;               // prim-th root of 1, index form 
42
-        public $pad;                 // Padding bytes in shortened block 
33
+        public $mm; // Bits per symbol 
34
+        public $nn; // Symbols per block (= (1<<mm)-1) 
35
+        public $alpha_to = array(); // log lookup table 
36
+        public $index_of = array(); // Antilog lookup table 
37
+        public $genpoly = array(); // Generator polynomial 
38
+        public $nroots; // Number of generator roots = number of parity symbols 
39
+        public $fcr; // First consecutive root, index form 
40
+        public $prim; // Primitive element, index form 
41
+        public $iprim; // prim-th root of 1, index form 
42
+        public $pad; // Padding bytes in shortened block 
43 43
         public $gfpoly;
44 44
     
45 45
         //----------------------------------------------------------------------
@@ -63,47 +63,47 @@  discard block
 block discarded – undo
63 63
             $rs = null;
64 64
             
65 65
             // Check parameter ranges
66
-            if($symsize < 0 || $symsize > 8)                     return $rs;
67
-            if($fcr < 0 || $fcr >= (1<<$symsize))                return $rs;
68
-            if($prim <= 0 || $prim >= (1<<$symsize))             return $rs;
69
-            if($nroots < 0 || $nroots >= (1<<$symsize))          return $rs; // Can't have more roots than symbol values!
70
-            if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding
66
+            if ($symsize < 0 || $symsize > 8)                     return $rs;
67
+            if ($fcr < 0 || $fcr >= (1 << $symsize))                return $rs;
68
+            if ($prim <= 0 || $prim >= (1 << $symsize))             return $rs;
69
+            if ($nroots < 0 || $nroots >= (1 << $symsize))          return $rs; // Can't have more roots than symbol values!
70
+            if ($pad < 0 || $pad >= ((1 << $symsize) - 1 - $nroots)) return $rs; // Too much padding
71 71
 
72 72
             $rs = new QRrsItem();
73 73
             $rs->mm = $symsize;
74
-            $rs->nn = (1<<$symsize)-1;
74
+            $rs->nn = (1 << $symsize) - 1;
75 75
             $rs->pad = $pad;
76 76
 
77
-            $rs->alpha_to = array_fill(0, $rs->nn+1, 0);
78
-            $rs->index_of = array_fill(0, $rs->nn+1, 0);
77
+            $rs->alpha_to = array_fill(0, $rs->nn + 1, 0);
78
+            $rs->index_of = array_fill(0, $rs->nn + 1, 0);
79 79
           
80 80
             // PHP style macro replacement ;)
81
-            $NN =& $rs->nn;
82
-            $A0 =& $NN;
81
+            $NN = & $rs->nn;
82
+            $A0 = & $NN;
83 83
             
84 84
             // Generate Galois field lookup tables
85 85
             $rs->index_of[0] = $A0; // log(zero) = -inf
86 86
             $rs->alpha_to[$A0] = 0; // alpha**-inf = 0
87 87
             $sr = 1;
88 88
           
89
-            for($i=0; $i<$rs->nn; $i++) {
89
+            for ($i = 0; $i < $rs->nn; $i++) {
90 90
                 $rs->index_of[$sr] = $i;
91 91
                 $rs->alpha_to[$i] = $sr;
92 92
                 $sr <<= 1;
93
-                if($sr & (1<<$symsize)) {
93
+                if ($sr & (1 << $symsize)) {
94 94
                     $sr ^= $gfpoly;
95 95
                 }
96 96
                 $sr &= $rs->nn;
97 97
             }
98 98
             
99
-            if($sr != 1){
99
+            if ($sr != 1) {
100 100
                 // field generator polynomial is not primitive!
101 101
                 $rs = NULL;
102 102
                 return $rs;
103 103
             }
104 104
 
105 105
             /* Form RS code generator polynomial from its roots */
106
-            $rs->genpoly = array_fill(0, $nroots+1, 0);
106
+            $rs->genpoly = array_fill(0, $nroots + 1, 0);
107 107
         
108 108
             $rs->fcr = $fcr;
109 109
             $rs->prim = $prim;
@@ -111,21 +111,21 @@  discard block
 block discarded – undo
111 111
             $rs->gfpoly = $gfpoly;
112 112
 
113 113
             /* Find prim-th root of 1, used in decoding */
114
-            for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn)
114
+            for ($iprim = 1; ($iprim % $prim) != 0; $iprim += $rs->nn)
115 115
             ; // intentional empty-body loop!
116 116
             
117
-            $rs->iprim = (int)($iprim / $prim);
117
+            $rs->iprim = (int) ($iprim / $prim);
118 118
             $rs->genpoly[0] = 1;
119 119
             
120
-            for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) {
121
-                $rs->genpoly[$i+1] = 1;
120
+            for ($i = 0, $root = $fcr * $prim; $i < $nroots; $i++, $root += $prim) {
121
+                $rs->genpoly[$i + 1] = 1;
122 122
 
123 123
                 // Multiply rs->genpoly[] by  @**(root + x)
124 124
                 for ($j = $i; $j > 0; $j--) {
125 125
                     if ($rs->genpoly[$j] != 0) {
126
-                        $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)];
126
+                        $rs->genpoly[$j] = $rs->genpoly[$j - 1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)];
127 127
                     } else {
128
-                        $rs->genpoly[$j] = $rs->genpoly[$j-1];
128
+                        $rs->genpoly[$j] = $rs->genpoly[$j - 1];
129 129
                     }
130 130
                 }
131 131
                 // rs->genpoly[0] can never be zero
@@ -142,38 +142,38 @@  discard block
 block discarded – undo
142 142
         //----------------------------------------------------------------------
143 143
         public function encode_rs_char($data, &$parity)
144 144
         {
145
-            $MM       =& $this->mm;
146
-            $NN       =& $this->nn;
147
-            $ALPHA_TO =& $this->alpha_to;
148
-            $INDEX_OF =& $this->index_of;
149
-            $GENPOLY  =& $this->genpoly;
150
-            $NROOTS   =& $this->nroots;
151
-            $FCR      =& $this->fcr;
152
-            $PRIM     =& $this->prim;
153
-            $IPRIM    =& $this->iprim;
154
-            $PAD      =& $this->pad;
155
-            $A0       =& $NN;
145
+            $MM       = & $this->mm;
146
+            $NN       = & $this->nn;
147
+            $ALPHA_TO = & $this->alpha_to;
148
+            $INDEX_OF = & $this->index_of;
149
+            $GENPOLY  = & $this->genpoly;
150
+            $NROOTS   = & $this->nroots;
151
+            $FCR      = & $this->fcr;
152
+            $PRIM     = & $this->prim;
153
+            $IPRIM    = & $this->iprim;
154
+            $PAD      = & $this->pad;
155
+            $A0       = & $NN;
156 156
 
157 157
             $parity = array_fill(0, $NROOTS, 0);
158 158
 
159
-            for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) {
159
+            for ($i = 0; $i < ($NN - $NROOTS - $PAD); $i++) {
160 160
                 
161 161
                 $feedback = $INDEX_OF[$data[$i] ^ $parity[0]];
162
-                if($feedback != $A0) {      
162
+                if ($feedback != $A0) {      
163 163
                     // feedback term is non-zero
164 164
             
165 165
                     // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
166 166
                     // always be for the polynomials constructed by init_rs()
167 167
                     $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback);
168 168
             
169
-                    for($j=1;$j<$NROOTS;$j++) {
170
-                        $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])];
169
+                    for ($j = 1; $j < $NROOTS; $j++) {
170
+                        $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS - $j])];
171 171
                     }
172 172
                 }
173 173
                 
174 174
                 // Shift 
175 175
                 array_shift($parity);
176
-                if($feedback != $A0) {
176
+                if ($feedback != $A0) {
177 177
                     array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]);
178 178
                 } else {
179 179
                     array_push($parity, 0);
@@ -191,13 +191,13 @@  discard block
 block discarded – undo
191 191
         //----------------------------------------------------------------------
192 192
         public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
193 193
         {
194
-            foreach(self::$items as $rs) {
195
-                if($rs->pad != $pad)       continue;
196
-                if($rs->nroots != $nroots) continue;
197
-                if($rs->mm != $symsize)    continue;
198
-                if($rs->gfpoly != $gfpoly) continue;
199
-                if($rs->fcr != $fcr)       continue;
200
-                if($rs->prim != $prim)     continue;
194
+            foreach (self::$items as $rs) {
195
+                if ($rs->pad != $pad)       continue;
196
+                if ($rs->nroots != $nroots) continue;
197
+                if ($rs->mm != $symsize)    continue;
198
+                if ($rs->gfpoly != $gfpoly) continue;
199
+                if ($rs->fcr != $fcr)       continue;
200
+                if ($rs->prim != $prim)     continue;
201 201
 
202 202
                 return $rs;
203 203
             }
Please login to merge, or discard this patch.
Braces   +38 added lines, -13 removed lines patch added patch discarded remove patch
@@ -63,11 +63,23 @@  discard block
 block discarded – undo
63 63
             $rs = null;
64 64
             
65 65
             // Check parameter ranges
66
-            if($symsize < 0 || $symsize > 8)                     return $rs;
67
-            if($fcr < 0 || $fcr >= (1<<$symsize))                return $rs;
68
-            if($prim <= 0 || $prim >= (1<<$symsize))             return $rs;
69
-            if($nroots < 0 || $nroots >= (1<<$symsize))          return $rs; // Can't have more roots than symbol values!
70
-            if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding
66
+            if($symsize < 0 || $symsize > 8) {
67
+            	return $rs;
68
+            }
69
+            if($fcr < 0 || $fcr >= (1<<$symsize)) {
70
+            	return $rs;
71
+            }
72
+            if($prim <= 0 || $prim >= (1<<$symsize)) {
73
+            	return $rs;
74
+            }
75
+            if($nroots < 0 || $nroots >= (1<<$symsize)) {
76
+            	return $rs;
77
+            }
78
+            // Can't have more roots than symbol values!
79
+            if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) {
80
+            	return $rs;
81
+            }
82
+            // Too much padding
71 83
 
72 84
             $rs = new QRrsItem();
73 85
             $rs->mm = $symsize;
@@ -133,8 +145,9 @@  discard block
 block discarded – undo
133 145
             }
134 146
             
135 147
             // convert rs->genpoly[] to index form for quicker encoding
136
-            for ($i = 0; $i <= $nroots; $i++)
137
-                $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]];
148
+            for ($i = 0; $i <= $nroots; $i++) {
149
+                            $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]];
150
+            }
138 151
 
139 152
             return $rs;
140 153
         }
@@ -192,12 +205,24 @@  discard block
 block discarded – undo
192 205
         public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
193 206
         {
194 207
             foreach(self::$items as $rs) {
195
-                if($rs->pad != $pad)       continue;
196
-                if($rs->nroots != $nroots) continue;
197
-                if($rs->mm != $symsize)    continue;
198
-                if($rs->gfpoly != $gfpoly) continue;
199
-                if($rs->fcr != $fcr)       continue;
200
-                if($rs->prim != $prim)     continue;
208
+                if($rs->pad != $pad) {
209
+                	continue;
210
+                }
211
+                if($rs->nroots != $nroots) {
212
+                	continue;
213
+                }
214
+                if($rs->mm != $symsize) {
215
+                	continue;
216
+                }
217
+                if($rs->gfpoly != $gfpoly) {
218
+                	continue;
219
+                }
220
+                if($rs->fcr != $fcr) {
221
+                	continue;
222
+                }
223
+                if($rs->prim != $prim) {
224
+                	continue;
225
+                }
201 226
 
202 227
                 return $rs;
203 228
             }
Please login to merge, or discard this patch.
lib/phpqrcode/qrspec.php 3 patches
Indentation   +484 added lines, -484 removed lines patch added patch discarded remove patch
@@ -31,497 +31,497 @@  discard block
 block discarded – undo
31 31
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 32
  */
33 33
  
34
-    define('QRSPEC_VERSION_MAX', 40);
35
-    define('QRSPEC_WIDTH_MAX',   177);
34
+	define('QRSPEC_VERSION_MAX', 40);
35
+	define('QRSPEC_WIDTH_MAX',   177);
36 36
 
37
-    define('QRCAP_WIDTH',        0);
38
-    define('QRCAP_WORDS',        1);
39
-    define('QRCAP_REMINDER',     2);
40
-    define('QRCAP_EC',           3);
37
+	define('QRCAP_WIDTH',        0);
38
+	define('QRCAP_WORDS',        1);
39
+	define('QRCAP_REMINDER',     2);
40
+	define('QRCAP_EC',           3);
41 41
 
42
-    class QRspec {
42
+	class QRspec {
43 43
     
44
-        public static $capacity = array(
45
-            array(  0,    0, 0, array(   0,    0,    0,    0)),
46
-            array( 21,   26, 0, array(   7,   10,   13,   17)), // 1
47
-            array( 25,   44, 7, array(  10,   16,   22,   28)),
48
-            array( 29,   70, 7, array(  15,   26,   36,   44)),
49
-            array( 33,  100, 7, array(  20,   36,   52,   64)),
50
-            array( 37,  134, 7, array(  26,   48,   72,   88)), // 5
51
-            array( 41,  172, 7, array(  36,   64,   96,  112)),
52
-            array( 45,  196, 0, array(  40,   72,  108,  130)),
53
-            array( 49,  242, 0, array(  48,   88,  132,  156)),
54
-            array( 53,  292, 0, array(  60,  110,  160,  192)),
55
-            array( 57,  346, 0, array(  72,  130,  192,  224)), //10
56
-            array( 61,  404, 0, array(  80,  150,  224,  264)),
57
-            array( 65,  466, 0, array(  96,  176,  260,  308)),
58
-            array( 69,  532, 0, array( 104,  198,  288,  352)),
59
-            array( 73,  581, 3, array( 120,  216,  320,  384)),
60
-            array( 77,  655, 3, array( 132,  240,  360,  432)), //15
61
-            array( 81,  733, 3, array( 144,  280,  408,  480)),
62
-            array( 85,  815, 3, array( 168,  308,  448,  532)),
63
-            array( 89,  901, 3, array( 180,  338,  504,  588)),
64
-            array( 93,  991, 3, array( 196,  364,  546,  650)),
65
-            array( 97, 1085, 3, array( 224,  416,  600,  700)), //20
66
-            array(101, 1156, 4, array( 224,  442,  644,  750)),
67
-            array(105, 1258, 4, array( 252,  476,  690,  816)),
68
-            array(109, 1364, 4, array( 270,  504,  750,  900)),
69
-            array(113, 1474, 4, array( 300,  560,  810,  960)),
70
-            array(117, 1588, 4, array( 312,  588,  870, 1050)), //25
71
-            array(121, 1706, 4, array( 336,  644,  952, 1110)),
72
-            array(125, 1828, 4, array( 360,  700, 1020, 1200)),
73
-            array(129, 1921, 3, array( 390,  728, 1050, 1260)),
74
-            array(133, 2051, 3, array( 420,  784, 1140, 1350)),
75
-            array(137, 2185, 3, array( 450,  812, 1200, 1440)), //30
76
-            array(141, 2323, 3, array( 480,  868, 1290, 1530)),
77
-            array(145, 2465, 3, array( 510,  924, 1350, 1620)),
78
-            array(149, 2611, 3, array( 540,  980, 1440, 1710)),
79
-            array(153, 2761, 3, array( 570, 1036, 1530, 1800)),
80
-            array(157, 2876, 0, array( 570, 1064, 1590, 1890)), //35
81
-            array(161, 3034, 0, array( 600, 1120, 1680, 1980)),
82
-            array(165, 3196, 0, array( 630, 1204, 1770, 2100)),
83
-            array(169, 3362, 0, array( 660, 1260, 1860, 2220)),
84
-            array(173, 3532, 0, array( 720, 1316, 1950, 2310)),
85
-            array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40
86
-        );
44
+		public static $capacity = array(
45
+			array(  0,    0, 0, array(   0,    0,    0,    0)),
46
+			array( 21,   26, 0, array(   7,   10,   13,   17)), // 1
47
+			array( 25,   44, 7, array(  10,   16,   22,   28)),
48
+			array( 29,   70, 7, array(  15,   26,   36,   44)),
49
+			array( 33,  100, 7, array(  20,   36,   52,   64)),
50
+			array( 37,  134, 7, array(  26,   48,   72,   88)), // 5
51
+			array( 41,  172, 7, array(  36,   64,   96,  112)),
52
+			array( 45,  196, 0, array(  40,   72,  108,  130)),
53
+			array( 49,  242, 0, array(  48,   88,  132,  156)),
54
+			array( 53,  292, 0, array(  60,  110,  160,  192)),
55
+			array( 57,  346, 0, array(  72,  130,  192,  224)), //10
56
+			array( 61,  404, 0, array(  80,  150,  224,  264)),
57
+			array( 65,  466, 0, array(  96,  176,  260,  308)),
58
+			array( 69,  532, 0, array( 104,  198,  288,  352)),
59
+			array( 73,  581, 3, array( 120,  216,  320,  384)),
60
+			array( 77,  655, 3, array( 132,  240,  360,  432)), //15
61
+			array( 81,  733, 3, array( 144,  280,  408,  480)),
62
+			array( 85,  815, 3, array( 168,  308,  448,  532)),
63
+			array( 89,  901, 3, array( 180,  338,  504,  588)),
64
+			array( 93,  991, 3, array( 196,  364,  546,  650)),
65
+			array( 97, 1085, 3, array( 224,  416,  600,  700)), //20
66
+			array(101, 1156, 4, array( 224,  442,  644,  750)),
67
+			array(105, 1258, 4, array( 252,  476,  690,  816)),
68
+			array(109, 1364, 4, array( 270,  504,  750,  900)),
69
+			array(113, 1474, 4, array( 300,  560,  810,  960)),
70
+			array(117, 1588, 4, array( 312,  588,  870, 1050)), //25
71
+			array(121, 1706, 4, array( 336,  644,  952, 1110)),
72
+			array(125, 1828, 4, array( 360,  700, 1020, 1200)),
73
+			array(129, 1921, 3, array( 390,  728, 1050, 1260)),
74
+			array(133, 2051, 3, array( 420,  784, 1140, 1350)),
75
+			array(137, 2185, 3, array( 450,  812, 1200, 1440)), //30
76
+			array(141, 2323, 3, array( 480,  868, 1290, 1530)),
77
+			array(145, 2465, 3, array( 510,  924, 1350, 1620)),
78
+			array(149, 2611, 3, array( 540,  980, 1440, 1710)),
79
+			array(153, 2761, 3, array( 570, 1036, 1530, 1800)),
80
+			array(157, 2876, 0, array( 570, 1064, 1590, 1890)), //35
81
+			array(161, 3034, 0, array( 600, 1120, 1680, 1980)),
82
+			array(165, 3196, 0, array( 630, 1204, 1770, 2100)),
83
+			array(169, 3362, 0, array( 660, 1260, 1860, 2220)),
84
+			array(173, 3532, 0, array( 720, 1316, 1950, 2310)),
85
+			array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40
86
+		);
87 87
         
88
-        //----------------------------------------------------------------------
89
-        public static function getDataLength($version, $level)
90
-        {
91
-            return self::$capacity[$version][QRCAP_WORDS] - self::$capacity[$version][QRCAP_EC][$level];
92
-        }
88
+		//----------------------------------------------------------------------
89
+		public static function getDataLength($version, $level)
90
+		{
91
+			return self::$capacity[$version][QRCAP_WORDS] - self::$capacity[$version][QRCAP_EC][$level];
92
+		}
93 93
         
94
-        //----------------------------------------------------------------------
95
-        public static function getECCLength($version, $level)
96
-        {
97
-            return self::$capacity[$version][QRCAP_EC][$level];
98
-        }
94
+		//----------------------------------------------------------------------
95
+		public static function getECCLength($version, $level)
96
+		{
97
+			return self::$capacity[$version][QRCAP_EC][$level];
98
+		}
99 99
         
100
-        //----------------------------------------------------------------------
101
-        public static function getWidth($version)
102
-        {
103
-            return self::$capacity[$version][QRCAP_WIDTH];
104
-        }
100
+		//----------------------------------------------------------------------
101
+		public static function getWidth($version)
102
+		{
103
+			return self::$capacity[$version][QRCAP_WIDTH];
104
+		}
105 105
         
106
-        //----------------------------------------------------------------------
107
-        public static function getRemainder($version)
108
-        {
109
-            return self::$capacity[$version][QRCAP_REMINDER];
110
-        }
106
+		//----------------------------------------------------------------------
107
+		public static function getRemainder($version)
108
+		{
109
+			return self::$capacity[$version][QRCAP_REMINDER];
110
+		}
111 111
         
112
-        //----------------------------------------------------------------------
113
-        public static function getMinimumVersion($size, $level)
114
-        {
115
-
116
-            for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) {
117
-                $words  = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level];
118
-                if($words >= $size) 
119
-                    return $i;
120
-            }
121
-
122
-            return -1;
123
-        }
112
+		//----------------------------------------------------------------------
113
+		public static function getMinimumVersion($size, $level)
114
+		{
115
+
116
+			for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) {
117
+				$words  = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level];
118
+				if($words >= $size) 
119
+					return $i;
120
+			}
121
+
122
+			return -1;
123
+		}
124 124
     
125
-        //######################################################################
125
+		//######################################################################
126 126
         
127
-        public static $lengthTableBits = array(
128
-            array(10, 12, 14),
129
-            array( 9, 11, 13),
130
-            array( 8, 16, 16),
131
-            array( 8, 10, 12)
132
-        );
127
+		public static $lengthTableBits = array(
128
+			array(10, 12, 14),
129
+			array( 9, 11, 13),
130
+			array( 8, 16, 16),
131
+			array( 8, 10, 12)
132
+		);
133 133
         
134
-        //----------------------------------------------------------------------
135
-        public static function lengthIndicator($mode, $version)
136
-        {
137
-            if ($mode == QR_MODE_STRUCTURE)
138
-                return 0;
134
+		//----------------------------------------------------------------------
135
+		public static function lengthIndicator($mode, $version)
136
+		{
137
+			if ($mode == QR_MODE_STRUCTURE)
138
+				return 0;
139 139
                 
140
-            if ($version <= 9) {
141
-                $l = 0;
142
-            } else if ($version <= 26) {
143
-                $l = 1;
144
-            } else {
145
-                $l = 2;
146
-            }
147
-
148
-            return self::$lengthTableBits[$mode][$l];
149
-        }
140
+			if ($version <= 9) {
141
+				$l = 0;
142
+			} else if ($version <= 26) {
143
+				$l = 1;
144
+			} else {
145
+				$l = 2;
146
+			}
147
+
148
+			return self::$lengthTableBits[$mode][$l];
149
+		}
150 150
         
151
-        //----------------------------------------------------------------------
152
-        public static function maximumWords($mode, $version)
153
-        {
154
-            if($mode == QR_MODE_STRUCTURE) 
155
-                return 3;
151
+		//----------------------------------------------------------------------
152
+		public static function maximumWords($mode, $version)
153
+		{
154
+			if($mode == QR_MODE_STRUCTURE) 
155
+				return 3;
156 156
                 
157
-            if($version <= 9) {
158
-                $l = 0;
159
-            } else if($version <= 26) {
160
-                $l = 1;
161
-            } else {
162
-                $l = 2;
163
-            }
164
-
165
-            $bits = self::$lengthTableBits[$mode][$l];
166
-            $words = (1 << $bits) - 1;
157
+			if($version <= 9) {
158
+				$l = 0;
159
+			} else if($version <= 26) {
160
+				$l = 1;
161
+			} else {
162
+				$l = 2;
163
+			}
164
+
165
+			$bits = self::$lengthTableBits[$mode][$l];
166
+			$words = (1 << $bits) - 1;
167 167
             
168
-            if($mode == QR_MODE_KANJI) {
169
-                $words *= 2; // the number of bytes is required
170
-            }
171
-
172
-            return $words;
173
-        }
174
-
175
-        // Error correction code -----------------------------------------------
176
-        // Table of the error correction code (Reed-Solomon block)
177
-        // See Table 12-16 (pp.30-36), JIS X0510:2004.
178
-
179
-        public static $eccTable = array(
180
-            array(array( 0,  0), array( 0,  0), array( 0,  0), array( 0,  0)),
181
-            array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)), // 1
182
-            array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)),
183
-            array(array( 1,  0), array( 1,  0), array( 2,  0), array( 2,  0)),
184
-            array(array( 1,  0), array( 2,  0), array( 2,  0), array( 4,  0)),
185
-            array(array( 1,  0), array( 2,  0), array( 2,  2), array( 2,  2)), // 5
186
-            array(array( 2,  0), array( 4,  0), array( 4,  0), array( 4,  0)),
187
-            array(array( 2,  0), array( 4,  0), array( 2,  4), array( 4,  1)),
188
-            array(array( 2,  0), array( 2,  2), array( 4,  2), array( 4,  2)),
189
-            array(array( 2,  0), array( 3,  2), array( 4,  4), array( 4,  4)),
190
-            array(array( 2,  2), array( 4,  1), array( 6,  2), array( 6,  2)), //10
191
-            array(array( 4,  0), array( 1,  4), array( 4,  4), array( 3,  8)),
192
-            array(array( 2,  2), array( 6,  2), array( 4,  6), array( 7,  4)),
193
-            array(array( 4,  0), array( 8,  1), array( 8,  4), array(12,  4)),
194
-            array(array( 3,  1), array( 4,  5), array(11,  5), array(11,  5)),
195
-            array(array( 5,  1), array( 5,  5), array( 5,  7), array(11,  7)), //15
196
-            array(array( 5,  1), array( 7,  3), array(15,  2), array( 3, 13)),
197
-            array(array( 1,  5), array(10,  1), array( 1, 15), array( 2, 17)),
198
-            array(array( 5,  1), array( 9,  4), array(17,  1), array( 2, 19)),
199
-            array(array( 3,  4), array( 3, 11), array(17,  4), array( 9, 16)),
200
-            array(array( 3,  5), array( 3, 13), array(15,  5), array(15, 10)), //20
201
-            array(array( 4,  4), array(17,  0), array(17,  6), array(19,  6)),
202
-            array(array( 2,  7), array(17,  0), array( 7, 16), array(34,  0)),
203
-            array(array( 4,  5), array( 4, 14), array(11, 14), array(16, 14)),
204
-            array(array( 6,  4), array( 6, 14), array(11, 16), array(30,  2)),
205
-            array(array( 8,  4), array( 8, 13), array( 7, 22), array(22, 13)), //25
206
-            array(array(10,  2), array(19,  4), array(28,  6), array(33,  4)),
207
-            array(array( 8,  4), array(22,  3), array( 8, 26), array(12, 28)),
208
-            array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)),
209
-            array(array( 7,  7), array(21,  7), array( 1, 37), array(19, 26)),
210
-            array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), //30
211
-            array(array(13,  3), array( 2, 29), array(42,  1), array(23, 28)),
212
-            array(array(17,  0), array(10, 23), array(10, 35), array(19, 35)),
213
-            array(array(17,  1), array(14, 21), array(29, 19), array(11, 46)),
214
-            array(array(13,  6), array(14, 23), array(44,  7), array(59,  1)),
215
-            array(array(12,  7), array(12, 26), array(39, 14), array(22, 41)), //35
216
-            array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)),
217
-            array(array(17,  4), array(29, 14), array(49, 10), array(24, 46)),
218
-            array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)),
219
-            array(array(20,  4), array(40,  7), array(43, 22), array(10, 67)),
220
-            array(array(19,  6), array(18, 31), array(34, 34), array(20, 61)),//40
221
-        );                                                                       
222
-
223
-        //----------------------------------------------------------------------
224
-        // CACHEABLE!!!
168
+			if($mode == QR_MODE_KANJI) {
169
+				$words *= 2; // the number of bytes is required
170
+			}
171
+
172
+			return $words;
173
+		}
174
+
175
+		// Error correction code -----------------------------------------------
176
+		// Table of the error correction code (Reed-Solomon block)
177
+		// See Table 12-16 (pp.30-36), JIS X0510:2004.
178
+
179
+		public static $eccTable = array(
180
+			array(array( 0,  0), array( 0,  0), array( 0,  0), array( 0,  0)),
181
+			array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)), // 1
182
+			array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)),
183
+			array(array( 1,  0), array( 1,  0), array( 2,  0), array( 2,  0)),
184
+			array(array( 1,  0), array( 2,  0), array( 2,  0), array( 4,  0)),
185
+			array(array( 1,  0), array( 2,  0), array( 2,  2), array( 2,  2)), // 5
186
+			array(array( 2,  0), array( 4,  0), array( 4,  0), array( 4,  0)),
187
+			array(array( 2,  0), array( 4,  0), array( 2,  4), array( 4,  1)),
188
+			array(array( 2,  0), array( 2,  2), array( 4,  2), array( 4,  2)),
189
+			array(array( 2,  0), array( 3,  2), array( 4,  4), array( 4,  4)),
190
+			array(array( 2,  2), array( 4,  1), array( 6,  2), array( 6,  2)), //10
191
+			array(array( 4,  0), array( 1,  4), array( 4,  4), array( 3,  8)),
192
+			array(array( 2,  2), array( 6,  2), array( 4,  6), array( 7,  4)),
193
+			array(array( 4,  0), array( 8,  1), array( 8,  4), array(12,  4)),
194
+			array(array( 3,  1), array( 4,  5), array(11,  5), array(11,  5)),
195
+			array(array( 5,  1), array( 5,  5), array( 5,  7), array(11,  7)), //15
196
+			array(array( 5,  1), array( 7,  3), array(15,  2), array( 3, 13)),
197
+			array(array( 1,  5), array(10,  1), array( 1, 15), array( 2, 17)),
198
+			array(array( 5,  1), array( 9,  4), array(17,  1), array( 2, 19)),
199
+			array(array( 3,  4), array( 3, 11), array(17,  4), array( 9, 16)),
200
+			array(array( 3,  5), array( 3, 13), array(15,  5), array(15, 10)), //20
201
+			array(array( 4,  4), array(17,  0), array(17,  6), array(19,  6)),
202
+			array(array( 2,  7), array(17,  0), array( 7, 16), array(34,  0)),
203
+			array(array( 4,  5), array( 4, 14), array(11, 14), array(16, 14)),
204
+			array(array( 6,  4), array( 6, 14), array(11, 16), array(30,  2)),
205
+			array(array( 8,  4), array( 8, 13), array( 7, 22), array(22, 13)), //25
206
+			array(array(10,  2), array(19,  4), array(28,  6), array(33,  4)),
207
+			array(array( 8,  4), array(22,  3), array( 8, 26), array(12, 28)),
208
+			array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)),
209
+			array(array( 7,  7), array(21,  7), array( 1, 37), array(19, 26)),
210
+			array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), //30
211
+			array(array(13,  3), array( 2, 29), array(42,  1), array(23, 28)),
212
+			array(array(17,  0), array(10, 23), array(10, 35), array(19, 35)),
213
+			array(array(17,  1), array(14, 21), array(29, 19), array(11, 46)),
214
+			array(array(13,  6), array(14, 23), array(44,  7), array(59,  1)),
215
+			array(array(12,  7), array(12, 26), array(39, 14), array(22, 41)), //35
216
+			array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)),
217
+			array(array(17,  4), array(29, 14), array(49, 10), array(24, 46)),
218
+			array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)),
219
+			array(array(20,  4), array(40,  7), array(43, 22), array(10, 67)),
220
+			array(array(19,  6), array(18, 31), array(34, 34), array(20, 61)),//40
221
+		);                                                                       
222
+
223
+		//----------------------------------------------------------------------
224
+		// CACHEABLE!!!
225 225
         
226
-        public static function getEccSpec($version, $level, array &$spec)
227
-        {
228
-            if (count($spec) < 5) {
229
-                $spec = array(0,0,0,0,0);
230
-            }
231
-
232
-            $b1   = self::$eccTable[$version][$level][0];
233
-            $b2   = self::$eccTable[$version][$level][1];
234
-            $data = self::getDataLength($version, $level);
235
-            $ecc  = self::getECCLength($version, $level);
236
-
237
-            if($b2 == 0) {
238
-                $spec[0] = $b1;
239
-                $spec[1] = (int)($data / $b1);
240
-                $spec[2] = (int)($ecc / $b1);
241
-                $spec[3] = 0; 
242
-                $spec[4] = 0;
243
-            } else {
244
-                $spec[0] = $b1;
245
-                $spec[1] = (int)($data / ($b1 + $b2));
246
-                $spec[2] = (int)($ecc  / ($b1 + $b2));
247
-                $spec[3] = $b2;
248
-                $spec[4] = $spec[1] + 1;
249
-            }
250
-        }
251
-
252
-        // Alignment pattern ---------------------------------------------------
253
-
254
-        // Positions of alignment patterns.
255
-        // This array includes only the second and the third position of the 
256
-        // alignment patterns. Rest of them can be calculated from the distance 
257
-        // between them.
226
+		public static function getEccSpec($version, $level, array &$spec)
227
+		{
228
+			if (count($spec) < 5) {
229
+				$spec = array(0,0,0,0,0);
230
+			}
231
+
232
+			$b1   = self::$eccTable[$version][$level][0];
233
+			$b2   = self::$eccTable[$version][$level][1];
234
+			$data = self::getDataLength($version, $level);
235
+			$ecc  = self::getECCLength($version, $level);
236
+
237
+			if($b2 == 0) {
238
+				$spec[0] = $b1;
239
+				$spec[1] = (int)($data / $b1);
240
+				$spec[2] = (int)($ecc / $b1);
241
+				$spec[3] = 0; 
242
+				$spec[4] = 0;
243
+			} else {
244
+				$spec[0] = $b1;
245
+				$spec[1] = (int)($data / ($b1 + $b2));
246
+				$spec[2] = (int)($ecc  / ($b1 + $b2));
247
+				$spec[3] = $b2;
248
+				$spec[4] = $spec[1] + 1;
249
+			}
250
+		}
251
+
252
+		// Alignment pattern ---------------------------------------------------
253
+
254
+		// Positions of alignment patterns.
255
+		// This array includes only the second and the third position of the 
256
+		// alignment patterns. Rest of them can be calculated from the distance 
257
+		// between them.
258 258
          
259
-        // See Table 1 in Appendix E (pp.71) of JIS X0510:2004.
259
+		// See Table 1 in Appendix E (pp.71) of JIS X0510:2004.
260 260
          
261
-        public static $alignmentPattern = array(      
262
-            array( 0,  0),
263
-            array( 0,  0), array(18,  0), array(22,  0), array(26,  0), array(30,  0), // 1- 5
264
-            array(34,  0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10
265
-            array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), //11-15
266
-            array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), //16-20
267
-            array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), //21-25
268
-            array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), //26-30
269
-            array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), //31-35
270
-            array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58), //35-40
271
-        );                                                                                  
261
+		public static $alignmentPattern = array(      
262
+			array( 0,  0),
263
+			array( 0,  0), array(18,  0), array(22,  0), array(26,  0), array(30,  0), // 1- 5
264
+			array(34,  0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10
265
+			array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), //11-15
266
+			array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), //16-20
267
+			array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), //21-25
268
+			array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), //26-30
269
+			array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), //31-35
270
+			array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58), //35-40
271
+		);                                                                                  
272 272
 
273 273
         
274
-        /** --------------------------------------------------------------------
275
-         * Put an alignment marker.
276
-         * @param frame
277
-         * @param width
278
-         * @param ox,oy center coordinate of the pattern
279
-         */
280
-        public static function putAlignmentMarker(array &$frame, $ox, $oy)
281
-        {
282
-            $finder = array(
283
-                "\xa1\xa1\xa1\xa1\xa1",
284
-                "\xa1\xa0\xa0\xa0\xa1",
285
-                "\xa1\xa0\xa1\xa0\xa1",
286
-                "\xa1\xa0\xa0\xa0\xa1",
287
-                "\xa1\xa1\xa1\xa1\xa1"
288
-            );                        
274
+		/** --------------------------------------------------------------------
275
+		 * Put an alignment marker.
276
+		 * @param frame
277
+		 * @param width
278
+		 * @param ox,oy center coordinate of the pattern
279
+		 */
280
+		public static function putAlignmentMarker(array &$frame, $ox, $oy)
281
+		{
282
+			$finder = array(
283
+				"\xa1\xa1\xa1\xa1\xa1",
284
+				"\xa1\xa0\xa0\xa0\xa1",
285
+				"\xa1\xa0\xa1\xa0\xa1",
286
+				"\xa1\xa0\xa0\xa0\xa1",
287
+				"\xa1\xa1\xa1\xa1\xa1"
288
+			);                        
289 289
             
290
-            $yStart = $oy-2;         
291
-            $xStart = $ox-2;
290
+			$yStart = $oy-2;         
291
+			$xStart = $ox-2;
292 292
             
293
-            for($y=0; $y<5; $y++) {
294
-                QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]);
295
-            }
296
-        }
297
-
298
-        //----------------------------------------------------------------------
299
-        public static function putAlignmentPattern($version, &$frame, $width)
300
-        {
301
-            if($version < 2)
302
-                return;
303
-
304
-            $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0];
305
-            if($d < 0) {
306
-                $w = 2;
307
-            } else {
308
-                $w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2);
309
-            }
310
-
311
-            if($w * $w - 3 == 1) {
312
-                $x = self::$alignmentPattern[$version][0];
313
-                $y = self::$alignmentPattern[$version][0];
314
-                self::putAlignmentMarker($frame, $x, $y);
315
-                return;
316
-            }
317
-
318
-            $cx = self::$alignmentPattern[$version][0];
319
-            for($x=1; $x<$w - 1; $x++) {
320
-                self::putAlignmentMarker($frame, 6, $cx);
321
-                self::putAlignmentMarker($frame, $cx,  6);
322
-                $cx += $d;
323
-            }
324
-
325
-            $cy = self::$alignmentPattern[$version][0];
326
-            for($y=0; $y<$w-1; $y++) {
327
-                $cx = self::$alignmentPattern[$version][0];
328
-                for($x=0; $x<$w-1; $x++) {
329
-                    self::putAlignmentMarker($frame, $cx, $cy);
330
-                    $cx += $d;
331
-                }
332
-                $cy += $d;
333
-            }
334
-        }
335
-
336
-        // Version information pattern -----------------------------------------
293
+			for($y=0; $y<5; $y++) {
294
+				QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]);
295
+			}
296
+		}
297
+
298
+		//----------------------------------------------------------------------
299
+		public static function putAlignmentPattern($version, &$frame, $width)
300
+		{
301
+			if($version < 2)
302
+				return;
303
+
304
+			$d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0];
305
+			if($d < 0) {
306
+				$w = 2;
307
+			} else {
308
+				$w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2);
309
+			}
310
+
311
+			if($w * $w - 3 == 1) {
312
+				$x = self::$alignmentPattern[$version][0];
313
+				$y = self::$alignmentPattern[$version][0];
314
+				self::putAlignmentMarker($frame, $x, $y);
315
+				return;
316
+			}
317
+
318
+			$cx = self::$alignmentPattern[$version][0];
319
+			for($x=1; $x<$w - 1; $x++) {
320
+				self::putAlignmentMarker($frame, 6, $cx);
321
+				self::putAlignmentMarker($frame, $cx,  6);
322
+				$cx += $d;
323
+			}
324
+
325
+			$cy = self::$alignmentPattern[$version][0];
326
+			for($y=0; $y<$w-1; $y++) {
327
+				$cx = self::$alignmentPattern[$version][0];
328
+				for($x=0; $x<$w-1; $x++) {
329
+					self::putAlignmentMarker($frame, $cx, $cy);
330
+					$cx += $d;
331
+				}
332
+				$cy += $d;
333
+			}
334
+		}
335
+
336
+		// Version information pattern -----------------------------------------
337 337
 
338 338
 		// Version information pattern (BCH coded).
339
-        // See Table 1 in Appendix D (pp.68) of JIS X0510:2004.
339
+		// See Table 1 in Appendix D (pp.68) of JIS X0510:2004.
340 340
         
341 341
 		// size: [QRSPEC_VERSION_MAX - 6]
342 342
 		
343
-        public static $versionPattern = array(
344
-            0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d,
345
-            0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9,
346
-            0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75,
347
-            0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64,
348
-            0x27541, 0x28c69
349
-        );
350
-
351
-        //----------------------------------------------------------------------
352
-        public static function getVersionPattern($version)
353
-        {
354
-            if($version < 7 || $version > QRSPEC_VERSION_MAX)
355
-                return 0;
356
-
357
-            return self::$versionPattern[$version -7];
358
-        }
359
-
360
-        // Format information --------------------------------------------------
361
-        // See calcFormatInfo in tests/test_qrspec.c (orginal qrencode c lib)
343
+		public static $versionPattern = array(
344
+			0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d,
345
+			0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9,
346
+			0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75,
347
+			0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64,
348
+			0x27541, 0x28c69
349
+		);
350
+
351
+		//----------------------------------------------------------------------
352
+		public static function getVersionPattern($version)
353
+		{
354
+			if($version < 7 || $version > QRSPEC_VERSION_MAX)
355
+				return 0;
356
+
357
+			return self::$versionPattern[$version -7];
358
+		}
359
+
360
+		// Format information --------------------------------------------------
361
+		// See calcFormatInfo in tests/test_qrspec.c (orginal qrencode c lib)
362 362
         
363
-        public static $formatInfo = array(
364
-            array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976),
365
-            array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0),
366
-            array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed),
367
-            array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b)
368
-        );
369
-
370
-        public static function getFormatInfo($mask, $level)
371
-        {
372
-            if($mask < 0 || $mask > 7)
373
-                return 0;
363
+		public static $formatInfo = array(
364
+			array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976),
365
+			array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0),
366
+			array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed),
367
+			array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b)
368
+		);
369
+
370
+		public static function getFormatInfo($mask, $level)
371
+		{
372
+			if($mask < 0 || $mask > 7)
373
+				return 0;
374 374
                 
375
-            if($level < 0 || $level > 3)
376
-                return 0;                
375
+			if($level < 0 || $level > 3)
376
+				return 0;                
377 377
 
378
-            return self::$formatInfo[$level][$mask];
379
-        }
378
+			return self::$formatInfo[$level][$mask];
379
+		}
380 380
 
381
-        // Frame ---------------------------------------------------------------
382
-        // Cache of initial frames.
381
+		// Frame ---------------------------------------------------------------
382
+		// Cache of initial frames.
383 383
          
384
-        public static $frames = array();
385
-
386
-        /** --------------------------------------------------------------------
387
-         * Put a finder pattern.
388
-         * @param frame
389
-         * @param width
390
-         * @param ox,oy upper-left coordinate of the pattern
391
-         */
392
-        public static function putFinderPattern(&$frame, $ox, $oy)
393
-        {
394
-            $finder = array(
395
-                "\xc1\xc1\xc1\xc1\xc1\xc1\xc1",
396
-                "\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
397
-                "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
398
-                "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
399
-                "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
400
-                "\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
401
-                "\xc1\xc1\xc1\xc1\xc1\xc1\xc1"
402
-            );                            
384
+		public static $frames = array();
385
+
386
+		/** --------------------------------------------------------------------
387
+		 * Put a finder pattern.
388
+		 * @param frame
389
+		 * @param width
390
+		 * @param ox,oy upper-left coordinate of the pattern
391
+		 */
392
+		public static function putFinderPattern(&$frame, $ox, $oy)
393
+		{
394
+			$finder = array(
395
+				"\xc1\xc1\xc1\xc1\xc1\xc1\xc1",
396
+				"\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
397
+				"\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
398
+				"\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
399
+				"\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
400
+				"\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
401
+				"\xc1\xc1\xc1\xc1\xc1\xc1\xc1"
402
+			);                            
403 403
             
404
-            for($y=0; $y<7; $y++) {
405
-                QRstr::set($frame, $ox, $oy+$y, $finder[$y]);
406
-            }
407
-        }
408
-
409
-        //----------------------------------------------------------------------
410
-        public static function createFrame($version)
411
-        {
412
-            $width = self::$capacity[$version][QRCAP_WIDTH];
413
-            $frameLine = str_repeat ("\0", $width);
414
-            $frame = array_fill(0, $width, $frameLine);
415
-
416
-            // Finder pattern
417
-            self::putFinderPattern($frame, 0, 0);
418
-            self::putFinderPattern($frame, $width - 7, 0);
419
-            self::putFinderPattern($frame, 0, $width - 7);
404
+			for($y=0; $y<7; $y++) {
405
+				QRstr::set($frame, $ox, $oy+$y, $finder[$y]);
406
+			}
407
+		}
408
+
409
+		//----------------------------------------------------------------------
410
+		public static function createFrame($version)
411
+		{
412
+			$width = self::$capacity[$version][QRCAP_WIDTH];
413
+			$frameLine = str_repeat ("\0", $width);
414
+			$frame = array_fill(0, $width, $frameLine);
415
+
416
+			// Finder pattern
417
+			self::putFinderPattern($frame, 0, 0);
418
+			self::putFinderPattern($frame, $width - 7, 0);
419
+			self::putFinderPattern($frame, 0, $width - 7);
420 420
             
421
-            // Separator
422
-            $yOffset = $width - 7;
421
+			// Separator
422
+			$yOffset = $width - 7;
423 423
             
424
-            for($y=0; $y<7; $y++) {
425
-                $frame[$y][7] = "\xc0";
426
-                $frame[$y][$width - 8] = "\xc0";
427
-                $frame[$yOffset][7] = "\xc0";
428
-                $yOffset++;
429
-            }
424
+			for($y=0; $y<7; $y++) {
425
+				$frame[$y][7] = "\xc0";
426
+				$frame[$y][$width - 8] = "\xc0";
427
+				$frame[$yOffset][7] = "\xc0";
428
+				$yOffset++;
429
+			}
430 430
             
431
-            $setPattern = str_repeat("\xc0", 8);
431
+			$setPattern = str_repeat("\xc0", 8);
432 432
             
433
-            QRstr::set($frame, 0, 7, $setPattern);
434
-            QRstr::set($frame, $width-8, 7, $setPattern);
435
-            QRstr::set($frame, 0, $width - 8, $setPattern);
433
+			QRstr::set($frame, 0, 7, $setPattern);
434
+			QRstr::set($frame, $width-8, 7, $setPattern);
435
+			QRstr::set($frame, 0, $width - 8, $setPattern);
436 436
         
437
-            // Format info
438
-            $setPattern = str_repeat("\x84", 9);
439
-            QRstr::set($frame, 0, 8, $setPattern);
440
-            QRstr::set($frame, $width - 8, 8, $setPattern, 8);
437
+			// Format info
438
+			$setPattern = str_repeat("\x84", 9);
439
+			QRstr::set($frame, 0, 8, $setPattern);
440
+			QRstr::set($frame, $width - 8, 8, $setPattern, 8);
441 441
             
442
-            $yOffset = $width - 8;
442
+			$yOffset = $width - 8;
443 443
 
444
-            for($y=0; $y<8; $y++,$yOffset++) {
445
-                $frame[$y][8] = "\x84";
446
-                $frame[$yOffset][8] = "\x84";
447
-            }
444
+			for($y=0; $y<8; $y++,$yOffset++) {
445
+				$frame[$y][8] = "\x84";
446
+				$frame[$yOffset][8] = "\x84";
447
+			}
448 448
 
449
-            // Timing pattern  
449
+			// Timing pattern  
450 450
             
451
-            for($i=1; $i<$width-15; $i++) {
452
-                $frame[6][7+$i] = chr(0x90 | ($i & 1));
453
-                $frame[7+$i][6] = chr(0x90 | ($i & 1));
454
-            }
451
+			for($i=1; $i<$width-15; $i++) {
452
+				$frame[6][7+$i] = chr(0x90 | ($i & 1));
453
+				$frame[7+$i][6] = chr(0x90 | ($i & 1));
454
+			}
455 455
             
456
-            // Alignment pattern  
457
-            self::putAlignmentPattern($version, $frame, $width);
456
+			// Alignment pattern  
457
+			self::putAlignmentPattern($version, $frame, $width);
458 458
             
459
-            // Version information 
460
-            if($version >= 7) {
461
-                $vinf = self::getVersionPattern($version);
459
+			// Version information 
460
+			if($version >= 7) {
461
+				$vinf = self::getVersionPattern($version);
462 462
 
463
-                $v = $vinf;
463
+				$v = $vinf;
464 464
                 
465
-                for($x=0; $x<6; $x++) {
466
-                    for($y=0; $y<3; $y++) {
467
-                        $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));
468
-                        $v = $v >> 1;
469
-                    }
470
-                }
471
-
472
-                $v = $vinf;
473
-                for($y=0; $y<6; $y++) {
474
-                    for($x=0; $x<3; $x++) {
475
-                        $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1));
476
-                        $v = $v >> 1;
477
-                    }
478
-                }
479
-            }
465
+				for($x=0; $x<6; $x++) {
466
+					for($y=0; $y<3; $y++) {
467
+						$frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));
468
+						$v = $v >> 1;
469
+					}
470
+				}
471
+
472
+				$v = $vinf;
473
+				for($y=0; $y<6; $y++) {
474
+					for($x=0; $x<3; $x++) {
475
+						$frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1));
476
+						$v = $v >> 1;
477
+					}
478
+				}
479
+			}
480 480
     
481
-            // and a little bit...  
482
-            $frame[$width - 8][8] = "\x81";
481
+			// and a little bit...  
482
+			$frame[$width - 8][8] = "\x81";
483 483
             
484
-            return $frame;
485
-        }
484
+			return $frame;
485
+		}
486 486
 
487
-        //----------------------------------------------------------------------
488
-        public static function debug($frame, $binary_mode = false)
489
-        {
490
-            if ($binary_mode) {
487
+		//----------------------------------------------------------------------
488
+		public static function debug($frame, $binary_mode = false)
489
+		{
490
+			if ($binary_mode) {
491 491
             
492
-                    foreach ($frame as &$frameLine) {
493
-                        $frameLine = join('<span class="m">&nbsp;&nbsp;</span>', explode('0', $frameLine));
494
-                        $frameLine = join('&#9608;&#9608;', explode('1', $frameLine));
495
-                    }
492
+					foreach ($frame as &$frameLine) {
493
+						$frameLine = join('<span class="m">&nbsp;&nbsp;</span>', explode('0', $frameLine));
494
+						$frameLine = join('&#9608;&#9608;', explode('1', $frameLine));
495
+					}
496 496
                     
497
-                    ?>
497
+					?>
498 498
                 <style>
499 499
                     .m { background-color: white; }
500 500
                 </style>
501 501
                 <?php
502
-                    echo '<pre><tt><br/ ><br/ ><br/ >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
503
-                    echo join("<br/ >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $frame);
504
-                    echo '</tt></pre><br/ ><br/ ><br/ ><br/ ><br/ ><br/ >';
502
+					echo '<pre><tt><br/ ><br/ ><br/ >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
503
+					echo join("<br/ >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $frame);
504
+					echo '</tt></pre><br/ ><br/ ><br/ ><br/ ><br/ ><br/ >';
505 505
             
506
-            } else {
506
+			} else {
507 507
             
508
-                foreach ($frame as &$frameLine) {
509
-                    $frameLine = join('<span class="m">&nbsp;</span>',  explode("\xc0", $frameLine));
510
-                    $frameLine = join('<span class="m">&#9618;</span>', explode("\xc1", $frameLine));
511
-                    $frameLine = join('<span class="p">&nbsp;</span>',  explode("\xa0", $frameLine));
512
-                    $frameLine = join('<span class="p">&#9618;</span>', explode("\xa1", $frameLine));
513
-                    $frameLine = join('<span class="s">&#9671;</span>', explode("\x84", $frameLine)); //format 0
514
-                    $frameLine = join('<span class="s">&#9670;</span>', explode("\x85", $frameLine)); //format 1
515
-                    $frameLine = join('<span class="x">&#9762;</span>', explode("\x81", $frameLine)); //special bit
516
-                    $frameLine = join('<span class="c">&nbsp;</span>',  explode("\x90", $frameLine)); //clock 0
517
-                    $frameLine = join('<span class="c">&#9719;</span>', explode("\x91", $frameLine)); //clock 1
518
-                    $frameLine = join('<span class="f">&nbsp;</span>',  explode("\x88", $frameLine)); //version
519
-                    $frameLine = join('<span class="f">&#9618;</span>', explode("\x89", $frameLine)); //version
520
-                    $frameLine = join('&#9830;', explode("\x01", $frameLine));
521
-                    $frameLine = join('&#8901;', explode("\0", $frameLine));
522
-                }
508
+				foreach ($frame as &$frameLine) {
509
+					$frameLine = join('<span class="m">&nbsp;</span>',  explode("\xc0", $frameLine));
510
+					$frameLine = join('<span class="m">&#9618;</span>', explode("\xc1", $frameLine));
511
+					$frameLine = join('<span class="p">&nbsp;</span>',  explode("\xa0", $frameLine));
512
+					$frameLine = join('<span class="p">&#9618;</span>', explode("\xa1", $frameLine));
513
+					$frameLine = join('<span class="s">&#9671;</span>', explode("\x84", $frameLine)); //format 0
514
+					$frameLine = join('<span class="s">&#9670;</span>', explode("\x85", $frameLine)); //format 1
515
+					$frameLine = join('<span class="x">&#9762;</span>', explode("\x81", $frameLine)); //special bit
516
+					$frameLine = join('<span class="c">&nbsp;</span>',  explode("\x90", $frameLine)); //clock 0
517
+					$frameLine = join('<span class="c">&#9719;</span>', explode("\x91", $frameLine)); //clock 1
518
+					$frameLine = join('<span class="f">&nbsp;</span>',  explode("\x88", $frameLine)); //version
519
+					$frameLine = join('<span class="f">&#9618;</span>', explode("\x89", $frameLine)); //version
520
+					$frameLine = join('&#9830;', explode("\x01", $frameLine));
521
+					$frameLine = join('&#8901;', explode("\0", $frameLine));
522
+				}
523 523
                 
524
-                ?>
524
+				?>
525 525
                 <style>
526 526
                     .p { background-color: yellow; }
527 527
                     .m { background-color: #00FF00; }
@@ -531,62 +531,62 @@  discard block
 block discarded – undo
531 531
                     .f { background-color: gold; }
532 532
                 </style>
533 533
                 <?php
534
-                echo "<pre><tt>";
535
-                echo join("<br/ >", $frame);
536
-                echo "</tt></pre>";
534
+				echo "<pre><tt>";
535
+				echo join("<br/ >", $frame);
536
+				echo "</tt></pre>";
537 537
             
538
-            }
539
-        }
540
-
541
-        //----------------------------------------------------------------------
542
-        public static function serial($frame)
543
-        {
544
-            return gzcompress(join("\n", $frame), 9);
545
-        }
538
+			}
539
+		}
540
+
541
+		//----------------------------------------------------------------------
542
+		public static function serial($frame)
543
+		{
544
+			return gzcompress(join("\n", $frame), 9);
545
+		}
546 546
         
547
-        //----------------------------------------------------------------------
548
-        public static function unserial($code)
549
-        {
550
-            return explode("\n", gzuncompress($code));
551
-        }
547
+		//----------------------------------------------------------------------
548
+		public static function unserial($code)
549
+		{
550
+			return explode("\n", gzuncompress($code));
551
+		}
552 552
         
553
-        //----------------------------------------------------------------------
554
-        public static function newFrame($version)
555
-        {
556
-            if($version < 1 || $version > QRSPEC_VERSION_MAX) 
557
-                return null;
553
+		//----------------------------------------------------------------------
554
+		public static function newFrame($version)
555
+		{
556
+			if($version < 1 || $version > QRSPEC_VERSION_MAX) 
557
+				return null;
558 558
 
559
-            if(!isset(self::$frames[$version])) {
559
+			if(!isset(self::$frames[$version])) {
560 560
                 
561
-                $fileName = QR_CACHE_DIR.'frame_'.$version.'.dat';
561
+				$fileName = QR_CACHE_DIR.'frame_'.$version.'.dat';
562 562
                 
563
-                if (QR_CACHEABLE) {
564
-                    if (file_exists($fileName)) {
565
-                        self::$frames[$version] = self::unserial(file_get_contents($fileName));
566
-                    } else {
567
-                        self::$frames[$version] = self::createFrame($version);
568
-                        file_put_contents($fileName, self::serial(self::$frames[$version]));
569
-                    }
570
-                } else {
571
-                    self::$frames[$version] = self::createFrame($version);
572
-                }
573
-            }
563
+				if (QR_CACHEABLE) {
564
+					if (file_exists($fileName)) {
565
+						self::$frames[$version] = self::unserial(file_get_contents($fileName));
566
+					} else {
567
+						self::$frames[$version] = self::createFrame($version);
568
+						file_put_contents($fileName, self::serial(self::$frames[$version]));
569
+					}
570
+				} else {
571
+					self::$frames[$version] = self::createFrame($version);
572
+				}
573
+			}
574 574
             
575
-            if(is_null(self::$frames[$version]))
576
-                return null;
577
-
578
-            return self::$frames[$version];
579
-        }
580
-
581
-        //----------------------------------------------------------------------
582
-        public static function rsBlockNum($spec)     { return $spec[0] + $spec[3]; }
583
-        public static function rsBlockNum1($spec)    { return $spec[0]; }
584
-        public static function rsDataCodes1($spec)   { return $spec[1]; }
585
-        public static function rsEccCodes1($spec)    { return $spec[2]; }
586
-        public static function rsBlockNum2($spec)    { return $spec[3]; }
587
-        public static function rsDataCodes2($spec)   { return $spec[4]; }
588
-        public static function rsEccCodes2($spec)    { return $spec[2]; }
589
-        public static function rsDataLength($spec)   { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]);    }
590
-        public static function rsEccLength($spec)    { return ($spec[0] + $spec[3]) * $spec[2]; }
575
+			if(is_null(self::$frames[$version]))
576
+				return null;
577
+
578
+			return self::$frames[$version];
579
+		}
580
+
581
+		//----------------------------------------------------------------------
582
+		public static function rsBlockNum($spec)     { return $spec[0] + $spec[3]; }
583
+		public static function rsBlockNum1($spec)    { return $spec[0]; }
584
+		public static function rsDataCodes1($spec)   { return $spec[1]; }
585
+		public static function rsEccCodes1($spec)    { return $spec[2]; }
586
+		public static function rsBlockNum2($spec)    { return $spec[3]; }
587
+		public static function rsDataCodes2($spec)   { return $spec[4]; }
588
+		public static function rsEccCodes2($spec)    { return $spec[2]; }
589
+		public static function rsDataLength($spec)   { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]);    }
590
+		public static function rsEccLength($spec)    { return ($spec[0] + $spec[3]) * $spec[2]; }
591 591
         
592
-    }
593 592
\ No newline at end of file
593
+	}
594 594
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -32,57 +32,57 @@  discard block
 block discarded – undo
32 32
  */
33 33
  
34 34
     define('QRSPEC_VERSION_MAX', 40);
35
-    define('QRSPEC_WIDTH_MAX',   177);
35
+    define('QRSPEC_WIDTH_MAX', 177);
36 36
 
37
-    define('QRCAP_WIDTH',        0);
38
-    define('QRCAP_WORDS',        1);
39
-    define('QRCAP_REMINDER',     2);
40
-    define('QRCAP_EC',           3);
37
+    define('QRCAP_WIDTH', 0);
38
+    define('QRCAP_WORDS', 1);
39
+    define('QRCAP_REMINDER', 2);
40
+    define('QRCAP_EC', 3);
41 41
 
42 42
     class QRspec {
43 43
     
44 44
         public static $capacity = array(
45
-            array(  0,    0, 0, array(   0,    0,    0,    0)),
46
-            array( 21,   26, 0, array(   7,   10,   13,   17)), // 1
47
-            array( 25,   44, 7, array(  10,   16,   22,   28)),
48
-            array( 29,   70, 7, array(  15,   26,   36,   44)),
49
-            array( 33,  100, 7, array(  20,   36,   52,   64)),
50
-            array( 37,  134, 7, array(  26,   48,   72,   88)), // 5
51
-            array( 41,  172, 7, array(  36,   64,   96,  112)),
52
-            array( 45,  196, 0, array(  40,   72,  108,  130)),
53
-            array( 49,  242, 0, array(  48,   88,  132,  156)),
54
-            array( 53,  292, 0, array(  60,  110,  160,  192)),
55
-            array( 57,  346, 0, array(  72,  130,  192,  224)), //10
56
-            array( 61,  404, 0, array(  80,  150,  224,  264)),
57
-            array( 65,  466, 0, array(  96,  176,  260,  308)),
58
-            array( 69,  532, 0, array( 104,  198,  288,  352)),
59
-            array( 73,  581, 3, array( 120,  216,  320,  384)),
60
-            array( 77,  655, 3, array( 132,  240,  360,  432)), //15
61
-            array( 81,  733, 3, array( 144,  280,  408,  480)),
62
-            array( 85,  815, 3, array( 168,  308,  448,  532)),
63
-            array( 89,  901, 3, array( 180,  338,  504,  588)),
64
-            array( 93,  991, 3, array( 196,  364,  546,  650)),
65
-            array( 97, 1085, 3, array( 224,  416,  600,  700)), //20
66
-            array(101, 1156, 4, array( 224,  442,  644,  750)),
67
-            array(105, 1258, 4, array( 252,  476,  690,  816)),
68
-            array(109, 1364, 4, array( 270,  504,  750,  900)),
69
-            array(113, 1474, 4, array( 300,  560,  810,  960)),
70
-            array(117, 1588, 4, array( 312,  588,  870, 1050)), //25
71
-            array(121, 1706, 4, array( 336,  644,  952, 1110)),
72
-            array(125, 1828, 4, array( 360,  700, 1020, 1200)),
73
-            array(129, 1921, 3, array( 390,  728, 1050, 1260)),
74
-            array(133, 2051, 3, array( 420,  784, 1140, 1350)),
75
-            array(137, 2185, 3, array( 450,  812, 1200, 1440)), //30
76
-            array(141, 2323, 3, array( 480,  868, 1290, 1530)),
77
-            array(145, 2465, 3, array( 510,  924, 1350, 1620)),
78
-            array(149, 2611, 3, array( 540,  980, 1440, 1710)),
79
-            array(153, 2761, 3, array( 570, 1036, 1530, 1800)),
80
-            array(157, 2876, 0, array( 570, 1064, 1590, 1890)), //35
81
-            array(161, 3034, 0, array( 600, 1120, 1680, 1980)),
82
-            array(165, 3196, 0, array( 630, 1204, 1770, 2100)),
83
-            array(169, 3362, 0, array( 660, 1260, 1860, 2220)),
84
-            array(173, 3532, 0, array( 720, 1316, 1950, 2310)),
85
-            array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40
45
+            array(0, 0, 0, array(0, 0, 0, 0)),
46
+            array(21, 26, 0, array(7, 10, 13, 17)), // 1
47
+            array(25, 44, 7, array(10, 16, 22, 28)),
48
+            array(29, 70, 7, array(15, 26, 36, 44)),
49
+            array(33, 100, 7, array(20, 36, 52, 64)),
50
+            array(37, 134, 7, array(26, 48, 72, 88)), // 5
51
+            array(41, 172, 7, array(36, 64, 96, 112)),
52
+            array(45, 196, 0, array(40, 72, 108, 130)),
53
+            array(49, 242, 0, array(48, 88, 132, 156)),
54
+            array(53, 292, 0, array(60, 110, 160, 192)),
55
+            array(57, 346, 0, array(72, 130, 192, 224)), //10
56
+            array(61, 404, 0, array(80, 150, 224, 264)),
57
+            array(65, 466, 0, array(96, 176, 260, 308)),
58
+            array(69, 532, 0, array(104, 198, 288, 352)),
59
+            array(73, 581, 3, array(120, 216, 320, 384)),
60
+            array(77, 655, 3, array(132, 240, 360, 432)), //15
61
+            array(81, 733, 3, array(144, 280, 408, 480)),
62
+            array(85, 815, 3, array(168, 308, 448, 532)),
63
+            array(89, 901, 3, array(180, 338, 504, 588)),
64
+            array(93, 991, 3, array(196, 364, 546, 650)),
65
+            array(97, 1085, 3, array(224, 416, 600, 700)), //20
66
+            array(101, 1156, 4, array(224, 442, 644, 750)),
67
+            array(105, 1258, 4, array(252, 476, 690, 816)),
68
+            array(109, 1364, 4, array(270, 504, 750, 900)),
69
+            array(113, 1474, 4, array(300, 560, 810, 960)),
70
+            array(117, 1588, 4, array(312, 588, 870, 1050)), //25
71
+            array(121, 1706, 4, array(336, 644, 952, 1110)),
72
+            array(125, 1828, 4, array(360, 700, 1020, 1200)),
73
+            array(129, 1921, 3, array(390, 728, 1050, 1260)),
74
+            array(133, 2051, 3, array(420, 784, 1140, 1350)),
75
+            array(137, 2185, 3, array(450, 812, 1200, 1440)), //30
76
+            array(141, 2323, 3, array(480, 868, 1290, 1530)),
77
+            array(145, 2465, 3, array(510, 924, 1350, 1620)),
78
+            array(149, 2611, 3, array(540, 980, 1440, 1710)),
79
+            array(153, 2761, 3, array(570, 1036, 1530, 1800)),
80
+            array(157, 2876, 0, array(570, 1064, 1590, 1890)), //35
81
+            array(161, 3034, 0, array(600, 1120, 1680, 1980)),
82
+            array(165, 3196, 0, array(630, 1204, 1770, 2100)),
83
+            array(169, 3362, 0, array(660, 1260, 1860, 2220)),
84
+            array(173, 3532, 0, array(720, 1316, 1950, 2310)),
85
+            array(177, 3706, 0, array(750, 1372, 2040, 2430)) //40
86 86
         );
87 87
         
88 88
         //----------------------------------------------------------------------
@@ -113,9 +113,9 @@  discard block
 block discarded – undo
113 113
         public static function getMinimumVersion($size, $level)
114 114
         {
115 115
 
116
-            for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) {
117
-                $words  = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level];
118
-                if($words >= $size) 
116
+            for ($i = 1; $i <= QRSPEC_VERSION_MAX; $i++) {
117
+                $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level];
118
+                if ($words >= $size) 
119 119
                     return $i;
120 120
             }
121 121
 
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
         
127 127
         public static $lengthTableBits = array(
128 128
             array(10, 12, 14),
129
-            array( 9, 11, 13),
130
-            array( 8, 16, 16),
131
-            array( 8, 10, 12)
129
+            array(9, 11, 13),
130
+            array(8, 16, 16),
131
+            array(8, 10, 12)
132 132
         );
133 133
         
134 134
         //----------------------------------------------------------------------
@@ -151,12 +151,12 @@  discard block
 block discarded – undo
151 151
         //----------------------------------------------------------------------
152 152
         public static function maximumWords($mode, $version)
153 153
         {
154
-            if($mode == QR_MODE_STRUCTURE) 
154
+            if ($mode == QR_MODE_STRUCTURE) 
155 155
                 return 3;
156 156
                 
157
-            if($version <= 9) {
157
+            if ($version <= 9) {
158 158
                 $l = 0;
159
-            } else if($version <= 26) {
159
+            } else if ($version <= 26) {
160 160
                 $l = 1;
161 161
             } else {
162 162
                 $l = 2;
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
             $bits = self::$lengthTableBits[$mode][$l];
166 166
             $words = (1 << $bits) - 1;
167 167
             
168
-            if($mode == QR_MODE_KANJI) {
168
+            if ($mode == QR_MODE_KANJI) {
169 169
                 $words *= 2; // the number of bytes is required
170 170
             }
171 171
 
@@ -177,47 +177,47 @@  discard block
 block discarded – undo
177 177
         // See Table 12-16 (pp.30-36), JIS X0510:2004.
178 178
 
179 179
         public static $eccTable = array(
180
-            array(array( 0,  0), array( 0,  0), array( 0,  0), array( 0,  0)),
181
-            array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)), // 1
182
-            array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)),
183
-            array(array( 1,  0), array( 1,  0), array( 2,  0), array( 2,  0)),
184
-            array(array( 1,  0), array( 2,  0), array( 2,  0), array( 4,  0)),
185
-            array(array( 1,  0), array( 2,  0), array( 2,  2), array( 2,  2)), // 5
186
-            array(array( 2,  0), array( 4,  0), array( 4,  0), array( 4,  0)),
187
-            array(array( 2,  0), array( 4,  0), array( 2,  4), array( 4,  1)),
188
-            array(array( 2,  0), array( 2,  2), array( 4,  2), array( 4,  2)),
189
-            array(array( 2,  0), array( 3,  2), array( 4,  4), array( 4,  4)),
190
-            array(array( 2,  2), array( 4,  1), array( 6,  2), array( 6,  2)), //10
191
-            array(array( 4,  0), array( 1,  4), array( 4,  4), array( 3,  8)),
192
-            array(array( 2,  2), array( 6,  2), array( 4,  6), array( 7,  4)),
193
-            array(array( 4,  0), array( 8,  1), array( 8,  4), array(12,  4)),
194
-            array(array( 3,  1), array( 4,  5), array(11,  5), array(11,  5)),
195
-            array(array( 5,  1), array( 5,  5), array( 5,  7), array(11,  7)), //15
196
-            array(array( 5,  1), array( 7,  3), array(15,  2), array( 3, 13)),
197
-            array(array( 1,  5), array(10,  1), array( 1, 15), array( 2, 17)),
198
-            array(array( 5,  1), array( 9,  4), array(17,  1), array( 2, 19)),
199
-            array(array( 3,  4), array( 3, 11), array(17,  4), array( 9, 16)),
200
-            array(array( 3,  5), array( 3, 13), array(15,  5), array(15, 10)), //20
201
-            array(array( 4,  4), array(17,  0), array(17,  6), array(19,  6)),
202
-            array(array( 2,  7), array(17,  0), array( 7, 16), array(34,  0)),
203
-            array(array( 4,  5), array( 4, 14), array(11, 14), array(16, 14)),
204
-            array(array( 6,  4), array( 6, 14), array(11, 16), array(30,  2)),
205
-            array(array( 8,  4), array( 8, 13), array( 7, 22), array(22, 13)), //25
206
-            array(array(10,  2), array(19,  4), array(28,  6), array(33,  4)),
207
-            array(array( 8,  4), array(22,  3), array( 8, 26), array(12, 28)),
208
-            array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)),
209
-            array(array( 7,  7), array(21,  7), array( 1, 37), array(19, 26)),
210
-            array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), //30
211
-            array(array(13,  3), array( 2, 29), array(42,  1), array(23, 28)),
212
-            array(array(17,  0), array(10, 23), array(10, 35), array(19, 35)),
213
-            array(array(17,  1), array(14, 21), array(29, 19), array(11, 46)),
214
-            array(array(13,  6), array(14, 23), array(44,  7), array(59,  1)),
215
-            array(array(12,  7), array(12, 26), array(39, 14), array(22, 41)), //35
216
-            array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)),
217
-            array(array(17,  4), array(29, 14), array(49, 10), array(24, 46)),
218
-            array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)),
219
-            array(array(20,  4), array(40,  7), array(43, 22), array(10, 67)),
220
-            array(array(19,  6), array(18, 31), array(34, 34), array(20, 61)),//40
180
+            array(array(0, 0), array(0, 0), array(0, 0), array(0, 0)),
181
+            array(array(1, 0), array(1, 0), array(1, 0), array(1, 0)), // 1
182
+            array(array(1, 0), array(1, 0), array(1, 0), array(1, 0)),
183
+            array(array(1, 0), array(1, 0), array(2, 0), array(2, 0)),
184
+            array(array(1, 0), array(2, 0), array(2, 0), array(4, 0)),
185
+            array(array(1, 0), array(2, 0), array(2, 2), array(2, 2)), // 5
186
+            array(array(2, 0), array(4, 0), array(4, 0), array(4, 0)),
187
+            array(array(2, 0), array(4, 0), array(2, 4), array(4, 1)),
188
+            array(array(2, 0), array(2, 2), array(4, 2), array(4, 2)),
189
+            array(array(2, 0), array(3, 2), array(4, 4), array(4, 4)),
190
+            array(array(2, 2), array(4, 1), array(6, 2), array(6, 2)), //10
191
+            array(array(4, 0), array(1, 4), array(4, 4), array(3, 8)),
192
+            array(array(2, 2), array(6, 2), array(4, 6), array(7, 4)),
193
+            array(array(4, 0), array(8, 1), array(8, 4), array(12, 4)),
194
+            array(array(3, 1), array(4, 5), array(11, 5), array(11, 5)),
195
+            array(array(5, 1), array(5, 5), array(5, 7), array(11, 7)), //15
196
+            array(array(5, 1), array(7, 3), array(15, 2), array(3, 13)),
197
+            array(array(1, 5), array(10, 1), array(1, 15), array(2, 17)),
198
+            array(array(5, 1), array(9, 4), array(17, 1), array(2, 19)),
199
+            array(array(3, 4), array(3, 11), array(17, 4), array(9, 16)),
200
+            array(array(3, 5), array(3, 13), array(15, 5), array(15, 10)), //20
201
+            array(array(4, 4), array(17, 0), array(17, 6), array(19, 6)),
202
+            array(array(2, 7), array(17, 0), array(7, 16), array(34, 0)),
203
+            array(array(4, 5), array(4, 14), array(11, 14), array(16, 14)),
204
+            array(array(6, 4), array(6, 14), array(11, 16), array(30, 2)),
205
+            array(array(8, 4), array(8, 13), array(7, 22), array(22, 13)), //25
206
+            array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)),
207
+            array(array(8, 4), array(22, 3), array(8, 26), array(12, 28)),
208
+            array(array(3, 10), array(3, 23), array(4, 31), array(11, 31)),
209
+            array(array(7, 7), array(21, 7), array(1, 37), array(19, 26)),
210
+            array(array(5, 10), array(19, 10), array(15, 25), array(23, 25)), //30
211
+            array(array(13, 3), array(2, 29), array(42, 1), array(23, 28)),
212
+            array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)),
213
+            array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)),
214
+            array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)),
215
+            array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), //35
216
+            array(array(6, 14), array(6, 34), array(46, 10), array(2, 64)),
217
+            array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)),
218
+            array(array(4, 18), array(13, 32), array(48, 14), array(42, 32)),
219
+            array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)),
220
+            array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)), //40
221 221
         );                                                                       
222 222
 
223 223
         //----------------------------------------------------------------------
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
         public static function getEccSpec($version, $level, array &$spec)
227 227
         {
228 228
             if (count($spec) < 5) {
229
-                $spec = array(0,0,0,0,0);
229
+                $spec = array(0, 0, 0, 0, 0);
230 230
             }
231 231
 
232 232
             $b1   = self::$eccTable[$version][$level][0];
@@ -234,16 +234,16 @@  discard block
 block discarded – undo
234 234
             $data = self::getDataLength($version, $level);
235 235
             $ecc  = self::getECCLength($version, $level);
236 236
 
237
-            if($b2 == 0) {
237
+            if ($b2 == 0) {
238 238
                 $spec[0] = $b1;
239
-                $spec[1] = (int)($data / $b1);
240
-                $spec[2] = (int)($ecc / $b1);
239
+                $spec[1] = (int) ($data / $b1);
240
+                $spec[2] = (int) ($ecc / $b1);
241 241
                 $spec[3] = 0; 
242 242
                 $spec[4] = 0;
243 243
             } else {
244 244
                 $spec[0] = $b1;
245
-                $spec[1] = (int)($data / ($b1 + $b2));
246
-                $spec[2] = (int)($ecc  / ($b1 + $b2));
245
+                $spec[1] = (int) ($data / ($b1 + $b2));
246
+                $spec[2] = (int) ($ecc / ($b1 + $b2));
247 247
                 $spec[3] = $b2;
248 248
                 $spec[4] = $spec[1] + 1;
249 249
             }
@@ -259,9 +259,9 @@  discard block
 block discarded – undo
259 259
         // See Table 1 in Appendix E (pp.71) of JIS X0510:2004.
260 260
          
261 261
         public static $alignmentPattern = array(      
262
-            array( 0,  0),
263
-            array( 0,  0), array(18,  0), array(22,  0), array(26,  0), array(30,  0), // 1- 5
264
-            array(34,  0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10
262
+            array(0, 0),
263
+            array(0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5
264
+            array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10
265 265
             array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), //11-15
266 266
             array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), //16-20
267 267
             array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), //21-25
@@ -287,28 +287,28 @@  discard block
 block discarded – undo
287 287
                 "\xa1\xa1\xa1\xa1\xa1"
288 288
             );                        
289 289
             
290
-            $yStart = $oy-2;         
291
-            $xStart = $ox-2;
290
+            $yStart = $oy - 2;         
291
+            $xStart = $ox - 2;
292 292
             
293
-            for($y=0; $y<5; $y++) {
294
-                QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]);
293
+            for ($y = 0; $y < 5; $y++) {
294
+                QRstr::set($frame, $xStart, $yStart + $y, $finder[$y]);
295 295
             }
296 296
         }
297 297
 
298 298
         //----------------------------------------------------------------------
299 299
         public static function putAlignmentPattern($version, &$frame, $width)
300 300
         {
301
-            if($version < 2)
301
+            if ($version < 2)
302 302
                 return;
303 303
 
304 304
             $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0];
305
-            if($d < 0) {
305
+            if ($d < 0) {
306 306
                 $w = 2;
307 307
             } else {
308
-                $w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2);
308
+                $w = (int) (($width - self::$alignmentPattern[$version][0]) / $d + 2);
309 309
             }
310 310
 
311
-            if($w * $w - 3 == 1) {
311
+            if ($w * $w - 3 == 1) {
312 312
                 $x = self::$alignmentPattern[$version][0];
313 313
                 $y = self::$alignmentPattern[$version][0];
314 314
                 self::putAlignmentMarker($frame, $x, $y);
@@ -316,16 +316,16 @@  discard block
 block discarded – undo
316 316
             }
317 317
 
318 318
             $cx = self::$alignmentPattern[$version][0];
319
-            for($x=1; $x<$w - 1; $x++) {
319
+            for ($x = 1; $x < $w - 1; $x++) {
320 320
                 self::putAlignmentMarker($frame, 6, $cx);
321
-                self::putAlignmentMarker($frame, $cx,  6);
321
+                self::putAlignmentMarker($frame, $cx, 6);
322 322
                 $cx += $d;
323 323
             }
324 324
 
325 325
             $cy = self::$alignmentPattern[$version][0];
326
-            for($y=0; $y<$w-1; $y++) {
326
+            for ($y = 0; $y < $w - 1; $y++) {
327 327
                 $cx = self::$alignmentPattern[$version][0];
328
-                for($x=0; $x<$w-1; $x++) {
328
+                for ($x = 0; $x < $w - 1; $x++) {
329 329
                     self::putAlignmentMarker($frame, $cx, $cy);
330 330
                     $cx += $d;
331 331
                 }
@@ -351,10 +351,10 @@  discard block
 block discarded – undo
351 351
         //----------------------------------------------------------------------
352 352
         public static function getVersionPattern($version)
353 353
         {
354
-            if($version < 7 || $version > QRSPEC_VERSION_MAX)
354
+            if ($version < 7 || $version > QRSPEC_VERSION_MAX)
355 355
                 return 0;
356 356
 
357
-            return self::$versionPattern[$version -7];
357
+            return self::$versionPattern[$version - 7];
358 358
         }
359 359
 
360 360
         // Format information --------------------------------------------------
@@ -369,10 +369,10 @@  discard block
 block discarded – undo
369 369
 
370 370
         public static function getFormatInfo($mask, $level)
371 371
         {
372
-            if($mask < 0 || $mask > 7)
372
+            if ($mask < 0 || $mask > 7)
373 373
                 return 0;
374 374
                 
375
-            if($level < 0 || $level > 3)
375
+            if ($level < 0 || $level > 3)
376 376
                 return 0;                
377 377
 
378 378
             return self::$formatInfo[$level][$mask];
@@ -401,8 +401,8 @@  discard block
 block discarded – undo
401 401
                 "\xc1\xc1\xc1\xc1\xc1\xc1\xc1"
402 402
             );                            
403 403
             
404
-            for($y=0; $y<7; $y++) {
405
-                QRstr::set($frame, $ox, $oy+$y, $finder[$y]);
404
+            for ($y = 0; $y < 7; $y++) {
405
+                QRstr::set($frame, $ox, $oy + $y, $finder[$y]);
406 406
             }
407 407
         }
408 408
 
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
         public static function createFrame($version)
411 411
         {
412 412
             $width = self::$capacity[$version][QRCAP_WIDTH];
413
-            $frameLine = str_repeat ("\0", $width);
413
+            $frameLine = str_repeat("\0", $width);
414 414
             $frame = array_fill(0, $width, $frameLine);
415 415
 
416 416
             // Finder pattern
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
             // Separator
422 422
             $yOffset = $width - 7;
423 423
             
424
-            for($y=0; $y<7; $y++) {
424
+            for ($y = 0; $y < 7; $y++) {
425 425
                 $frame[$y][7] = "\xc0";
426 426
                 $frame[$y][$width - 8] = "\xc0";
427 427
                 $frame[$yOffset][7] = "\xc0";
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
             $setPattern = str_repeat("\xc0", 8);
432 432
             
433 433
             QRstr::set($frame, 0, 7, $setPattern);
434
-            QRstr::set($frame, $width-8, 7, $setPattern);
434
+            QRstr::set($frame, $width - 8, 7, $setPattern);
435 435
             QRstr::set($frame, 0, $width - 8, $setPattern);
436 436
         
437 437
             // Format info
@@ -441,38 +441,38 @@  discard block
 block discarded – undo
441 441
             
442 442
             $yOffset = $width - 8;
443 443
 
444
-            for($y=0; $y<8; $y++,$yOffset++) {
444
+            for ($y = 0; $y < 8; $y++, $yOffset++) {
445 445
                 $frame[$y][8] = "\x84";
446 446
                 $frame[$yOffset][8] = "\x84";
447 447
             }
448 448
 
449 449
             // Timing pattern  
450 450
             
451
-            for($i=1; $i<$width-15; $i++) {
452
-                $frame[6][7+$i] = chr(0x90 | ($i & 1));
453
-                $frame[7+$i][6] = chr(0x90 | ($i & 1));
451
+            for ($i = 1; $i < $width - 15; $i++) {
452
+                $frame[6][7 + $i] = chr(0x90 | ($i & 1));
453
+                $frame[7 + $i][6] = chr(0x90 | ($i & 1));
454 454
             }
455 455
             
456 456
             // Alignment pattern  
457 457
             self::putAlignmentPattern($version, $frame, $width);
458 458
             
459 459
             // Version information 
460
-            if($version >= 7) {
460
+            if ($version >= 7) {
461 461
                 $vinf = self::getVersionPattern($version);
462 462
 
463 463
                 $v = $vinf;
464 464
                 
465
-                for($x=0; $x<6; $x++) {
466
-                    for($y=0; $y<3; $y++) {
467
-                        $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));
465
+                for ($x = 0; $x < 6; $x++) {
466
+                    for ($y = 0; $y < 3; $y++) {
467
+                        $frame[($width - 11) + $y][$x] = chr(0x88 | ($v & 1));
468 468
                         $v = $v >> 1;
469 469
                     }
470 470
                 }
471 471
 
472 472
                 $v = $vinf;
473
-                for($y=0; $y<6; $y++) {
474
-                    for($x=0; $x<3; $x++) {
475
-                        $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1));
473
+                for ($y = 0; $y < 6; $y++) {
474
+                    for ($x = 0; $x < 3; $x++) {
475
+                        $frame[$y][$x + ($width - 11)] = chr(0x88 | ($v & 1));
476 476
                         $v = $v >> 1;
477 477
                     }
478 478
                 }
@@ -506,16 +506,16 @@  discard block
 block discarded – undo
506 506
             } else {
507 507
             
508 508
                 foreach ($frame as &$frameLine) {
509
-                    $frameLine = join('<span class="m">&nbsp;</span>',  explode("\xc0", $frameLine));
509
+                    $frameLine = join('<span class="m">&nbsp;</span>', explode("\xc0", $frameLine));
510 510
                     $frameLine = join('<span class="m">&#9618;</span>', explode("\xc1", $frameLine));
511
-                    $frameLine = join('<span class="p">&nbsp;</span>',  explode("\xa0", $frameLine));
511
+                    $frameLine = join('<span class="p">&nbsp;</span>', explode("\xa0", $frameLine));
512 512
                     $frameLine = join('<span class="p">&#9618;</span>', explode("\xa1", $frameLine));
513 513
                     $frameLine = join('<span class="s">&#9671;</span>', explode("\x84", $frameLine)); //format 0
514 514
                     $frameLine = join('<span class="s">&#9670;</span>', explode("\x85", $frameLine)); //format 1
515 515
                     $frameLine = join('<span class="x">&#9762;</span>', explode("\x81", $frameLine)); //special bit
516
-                    $frameLine = join('<span class="c">&nbsp;</span>',  explode("\x90", $frameLine)); //clock 0
516
+                    $frameLine = join('<span class="c">&nbsp;</span>', explode("\x90", $frameLine)); //clock 0
517 517
                     $frameLine = join('<span class="c">&#9719;</span>', explode("\x91", $frameLine)); //clock 1
518
-                    $frameLine = join('<span class="f">&nbsp;</span>',  explode("\x88", $frameLine)); //version
518
+                    $frameLine = join('<span class="f">&nbsp;</span>', explode("\x88", $frameLine)); //version
519 519
                     $frameLine = join('<span class="f">&#9618;</span>', explode("\x89", $frameLine)); //version
520 520
                     $frameLine = join('&#9830;', explode("\x01", $frameLine));
521 521
                     $frameLine = join('&#8901;', explode("\0", $frameLine));
@@ -553,10 +553,10 @@  discard block
 block discarded – undo
553 553
         //----------------------------------------------------------------------
554 554
         public static function newFrame($version)
555 555
         {
556
-            if($version < 1 || $version > QRSPEC_VERSION_MAX) 
556
+            if ($version < 1 || $version > QRSPEC_VERSION_MAX) 
557 557
                 return null;
558 558
 
559
-            if(!isset(self::$frames[$version])) {
559
+            if (!isset(self::$frames[$version])) {
560 560
                 
561 561
                 $fileName = QR_CACHE_DIR.'frame_'.$version.'.dat';
562 562
                 
@@ -572,21 +572,21 @@  discard block
 block discarded – undo
572 572
                 }
573 573
             }
574 574
             
575
-            if(is_null(self::$frames[$version]))
575
+            if (is_null(self::$frames[$version]))
576 576
                 return null;
577 577
 
578 578
             return self::$frames[$version];
579 579
         }
580 580
 
581 581
         //----------------------------------------------------------------------
582
-        public static function rsBlockNum($spec)     { return $spec[0] + $spec[3]; }
583
-        public static function rsBlockNum1($spec)    { return $spec[0]; }
584
-        public static function rsDataCodes1($spec)   { return $spec[1]; }
585
-        public static function rsEccCodes1($spec)    { return $spec[2]; }
586
-        public static function rsBlockNum2($spec)    { return $spec[3]; }
587
-        public static function rsDataCodes2($spec)   { return $spec[4]; }
588
-        public static function rsEccCodes2($spec)    { return $spec[2]; }
589
-        public static function rsDataLength($spec)   { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]);    }
590
-        public static function rsEccLength($spec)    { return ($spec[0] + $spec[3]) * $spec[2]; }
582
+        public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; }
583
+        public static function rsBlockNum1($spec) { return $spec[0]; }
584
+        public static function rsDataCodes1($spec) { return $spec[1]; }
585
+        public static function rsEccCodes1($spec) { return $spec[2]; }
586
+        public static function rsBlockNum2($spec) { return $spec[3]; }
587
+        public static function rsDataCodes2($spec) { return $spec[4]; }
588
+        public static function rsEccCodes2($spec) { return $spec[2]; }
589
+        public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); }
590
+        public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; }
591 591
         
592 592
     }
593 593
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +27 added lines, -18 removed lines patch added patch discarded remove patch
@@ -115,8 +115,9 @@  discard block
 block discarded – undo
115 115
 
116 116
             for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) {
117 117
                 $words  = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level];
118
-                if($words >= $size) 
119
-                    return $i;
118
+                if($words >= $size) {
119
+                                    return $i;
120
+                }
120 121
             }
121 122
 
122 123
             return -1;
@@ -134,8 +135,9 @@  discard block
 block discarded – undo
134 135
         //----------------------------------------------------------------------
135 136
         public static function lengthIndicator($mode, $version)
136 137
         {
137
-            if ($mode == QR_MODE_STRUCTURE)
138
-                return 0;
138
+            if ($mode == QR_MODE_STRUCTURE) {
139
+                            return 0;
140
+            }
139 141
                 
140 142
             if ($version <= 9) {
141 143
                 $l = 0;
@@ -151,8 +153,9 @@  discard block
 block discarded – undo
151 153
         //----------------------------------------------------------------------
152 154
         public static function maximumWords($mode, $version)
153 155
         {
154
-            if($mode == QR_MODE_STRUCTURE) 
155
-                return 3;
156
+            if($mode == QR_MODE_STRUCTURE) {
157
+                            return 3;
158
+            }
156 159
                 
157 160
             if($version <= 9) {
158 161
                 $l = 0;
@@ -298,8 +301,9 @@  discard block
 block discarded – undo
298 301
         //----------------------------------------------------------------------
299 302
         public static function putAlignmentPattern($version, &$frame, $width)
300 303
         {
301
-            if($version < 2)
302
-                return;
304
+            if($version < 2) {
305
+                            return;
306
+            }
303 307
 
304 308
             $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0];
305 309
             if($d < 0) {
@@ -351,8 +355,9 @@  discard block
 block discarded – undo
351 355
         //----------------------------------------------------------------------
352 356
         public static function getVersionPattern($version)
353 357
         {
354
-            if($version < 7 || $version > QRSPEC_VERSION_MAX)
355
-                return 0;
358
+            if($version < 7 || $version > QRSPEC_VERSION_MAX) {
359
+                            return 0;
360
+            }
356 361
 
357 362
             return self::$versionPattern[$version -7];
358 363
         }
@@ -369,11 +374,13 @@  discard block
 block discarded – undo
369 374
 
370 375
         public static function getFormatInfo($mask, $level)
371 376
         {
372
-            if($mask < 0 || $mask > 7)
373
-                return 0;
377
+            if($mask < 0 || $mask > 7) {
378
+                            return 0;
379
+            }
374 380
                 
375
-            if($level < 0 || $level > 3)
376
-                return 0;                
381
+            if($level < 0 || $level > 3) {
382
+                            return 0;
383
+            }
377 384
 
378 385
             return self::$formatInfo[$level][$mask];
379 386
         }
@@ -553,8 +560,9 @@  discard block
 block discarded – undo
553 560
         //----------------------------------------------------------------------
554 561
         public static function newFrame($version)
555 562
         {
556
-            if($version < 1 || $version > QRSPEC_VERSION_MAX) 
557
-                return null;
563
+            if($version < 1 || $version > QRSPEC_VERSION_MAX) {
564
+                            return null;
565
+            }
558 566
 
559 567
             if(!isset(self::$frames[$version])) {
560 568
                 
@@ -572,8 +580,9 @@  discard block
 block discarded – undo
572 580
                 }
573 581
             }
574 582
             
575
-            if(is_null(self::$frames[$version]))
576
-                return null;
583
+            if(is_null(self::$frames[$version])) {
584
+                            return null;
585
+            }
577 586
 
578 587
             return self::$frames[$version];
579 588
         }
Please login to merge, or discard this patch.
lib/phpqrcode/phpqrcode.php 4 patches
Indentation   +2646 added lines, -2646 removed lines patch added patch discarded remove patch
@@ -114,15 +114,15 @@  discard block
 block discarded – undo
114 114
  * Config file, tuned-up for merged verion
115 115
  */
116 116
      
117
-    define('QR_CACHEABLE', false);       // use cache - more disk reads but less CPU power, masks and format templates are stored there
118
-    define('QR_CACHE_DIR', false);       // used when QR_CACHEABLE === true
119
-    define('QR_LOG_DIR', false);         // default error logs dir   
117
+	define('QR_CACHEABLE', false);       // use cache - more disk reads but less CPU power, masks and format templates are stored there
118
+	define('QR_CACHE_DIR', false);       // used when QR_CACHEABLE === true
119
+	define('QR_LOG_DIR', false);         // default error logs dir   
120 120
     
121
-    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
122
-    define('QR_FIND_FROM_RANDOM', 2);                                                       // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly
123
-    define('QR_DEFAULT_MASK', 2);                                                               // when QR_FIND_BEST_MASK === false
121
+	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
122
+	define('QR_FIND_FROM_RANDOM', 2);                                                       // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly
123
+	define('QR_DEFAULT_MASK', 2);                                                               // when QR_FIND_BEST_MASK === false
124 124
                                                   
125
-    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
125
+	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
126 126
                                                   
127 127
 
128 128
 
@@ -155,153 +155,153 @@  discard block
 block discarded – undo
155 155
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
156 156
  */
157 157
 
158
-    class QRtools {
158
+	class QRtools {
159 159
     
160
-        //----------------------------------------------------------------------
161
-        public static function binarize($frame)
162
-        {
163
-            $len = count($frame);
164
-            foreach ($frame as &$frameLine) {
160
+		//----------------------------------------------------------------------
161
+		public static function binarize($frame)
162
+		{
163
+			$len = count($frame);
164
+			foreach ($frame as &$frameLine) {
165 165
                 
166
-                for($i=0; $i<$len; $i++) {
167
-                    $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';
168
-                }
169
-            }
166
+				for($i=0; $i<$len; $i++) {
167
+					$frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';
168
+				}
169
+			}
170 170
             
171
-            return $frame;
172
-        }
171
+			return $frame;
172
+		}
173 173
         
174
-        //----------------------------------------------------------------------
175
-        public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037')
176
-        {
177
-            $barcode_array = array();
174
+		//----------------------------------------------------------------------
175
+		public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037')
176
+		{
177
+			$barcode_array = array();
178 178
             
179
-            if (!is_array($mode))
180
-                $mode = explode(',', $mode);
179
+			if (!is_array($mode))
180
+				$mode = explode(',', $mode);
181 181
                 
182
-            $eccLevel = 'L';
182
+			$eccLevel = 'L';
183 183
                 
184
-            if (count($mode) > 1) {
185
-                $eccLevel = $mode[1];
186
-            }
184
+			if (count($mode) > 1) {
185
+				$eccLevel = $mode[1];
186
+			}
187 187
                 
188
-            $qrTab = QRcode::text($code, false, $eccLevel);
189
-            $size = count($qrTab);
188
+			$qrTab = QRcode::text($code, false, $eccLevel);
189
+			$size = count($qrTab);
190 190
                 
191
-            $barcode_array['num_rows'] = $size;
192
-            $barcode_array['num_cols'] = $size;
193
-            $barcode_array['bcode'] = array();
191
+			$barcode_array['num_rows'] = $size;
192
+			$barcode_array['num_cols'] = $size;
193
+			$barcode_array['bcode'] = array();
194 194
                 
195
-            foreach ($qrTab as $line) {
196
-                $arrAdd = array();
197
-                foreach(str_split($line) as $char)
198
-                    $arrAdd[] = ($char=='1')?1:0;
199
-                $barcode_array['bcode'][] = $arrAdd;
200
-            }
195
+			foreach ($qrTab as $line) {
196
+				$arrAdd = array();
197
+				foreach(str_split($line) as $char)
198
+					$arrAdd[] = ($char=='1')?1:0;
199
+				$barcode_array['bcode'][] = $arrAdd;
200
+			}
201 201
                     
202
-            return $barcode_array;
203
-        }
204
-        
205
-        //----------------------------------------------------------------------
206
-        public static function clearCache()
207
-        {
208
-            self::$frames = array();
209
-        }
210
-        
211
-        //----------------------------------------------------------------------
212
-        public static function buildCache()
213
-        {
202
+			return $barcode_array;
203
+		}
204
+        
205
+		//----------------------------------------------------------------------
206
+		public static function clearCache()
207
+		{
208
+			self::$frames = array();
209
+		}
210
+        
211
+		//----------------------------------------------------------------------
212
+		public static function buildCache()
213
+		{
214 214
 			QRtools::markTime('before_build_cache');
215 215
 			
216 216
 			$mask = new QRmask();
217
-            for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) {
218
-                $frame = QRspec::newFrame($a);
219
-                if (QR_IMAGE) {
220
-                    $fileName = QR_CACHE_DIR.'frame_'.$a.'.png';
221
-                    QRimage::png(self::binarize($frame), $fileName, 1, 0);
222
-                }
217
+			for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) {
218
+				$frame = QRspec::newFrame($a);
219
+				if (QR_IMAGE) {
220
+					$fileName = QR_CACHE_DIR.'frame_'.$a.'.png';
221
+					QRimage::png(self::binarize($frame), $fileName, 1, 0);
222
+				}
223 223
 				
224 224
 				$width = count($frame);
225 225
 				$bitMask = array_fill(0, $width, array_fill(0, $width, 0));
226 226
 				for ($maskNo=0; $maskNo<8; $maskNo++)
227 227
 					$mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
228
-            }
228
+			}
229 229
 			
230 230
 			QRtools::markTime('after_build_cache');
231
-        }
232
-
233
-        //----------------------------------------------------------------------
234
-        public static function log($outfile, $err)
235
-        {
236
-            if (QR_LOG_DIR !== false) {
237
-                if ($err != '') {
238
-                    if ($outfile !== false) {
239
-                        file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
240
-                    } else {
241
-                        file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
242
-                    }
243
-                }    
244
-            }
245
-        }
246
-        
247
-        //----------------------------------------------------------------------
248
-        public static function dumpMask($frame) 
249
-        {
250
-            $width = count($frame);
251
-            for($y=0;$y<$width;$y++) {
252
-                for($x=0;$x<$width;$x++) {
253
-                    echo ord($frame[$y][$x]).',';
254
-                }
255
-            }
256
-        }
257
-        
258
-        //----------------------------------------------------------------------
259
-        public static function markTime($markerId)
260
-        {
261
-            list($usec, $sec) = explode(" ", microtime());
262
-            $time = ((float)$usec + (float)$sec);
263
-            
264
-            if (!isset($GLOBALS['qr_time_bench']))
265
-                $GLOBALS['qr_time_bench'] = array();
266
-            
267
-            $GLOBALS['qr_time_bench'][$markerId] = $time;
268
-        }
269
-        
270
-        //----------------------------------------------------------------------
271
-        public static function timeBenchmark()
272
-        {
273
-            self::markTime('finish');
274
-        
275
-            $lastTime = 0;
276
-            $startTime = 0;
277
-            $p = 0;
278
-
279
-            echo '<table cellpadding="3" cellspacing="1">
231
+		}
232
+
233
+		//----------------------------------------------------------------------
234
+		public static function log($outfile, $err)
235
+		{
236
+			if (QR_LOG_DIR !== false) {
237
+				if ($err != '') {
238
+					if ($outfile !== false) {
239
+						file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
240
+					} else {
241
+						file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
242
+					}
243
+				}    
244
+			}
245
+		}
246
+        
247
+		//----------------------------------------------------------------------
248
+		public static function dumpMask($frame) 
249
+		{
250
+			$width = count($frame);
251
+			for($y=0;$y<$width;$y++) {
252
+				for($x=0;$x<$width;$x++) {
253
+					echo ord($frame[$y][$x]).',';
254
+				}
255
+			}
256
+		}
257
+        
258
+		//----------------------------------------------------------------------
259
+		public static function markTime($markerId)
260
+		{
261
+			list($usec, $sec) = explode(" ", microtime());
262
+			$time = ((float)$usec + (float)$sec);
263
+            
264
+			if (!isset($GLOBALS['qr_time_bench']))
265
+				$GLOBALS['qr_time_bench'] = array();
266
+            
267
+			$GLOBALS['qr_time_bench'][$markerId] = $time;
268
+		}
269
+        
270
+		//----------------------------------------------------------------------
271
+		public static function timeBenchmark()
272
+		{
273
+			self::markTime('finish');
274
+        
275
+			$lastTime = 0;
276
+			$startTime = 0;
277
+			$p = 0;
278
+
279
+			echo '<table cellpadding="3" cellspacing="1">
280 280
                     <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead>
281 281
                     <tbody>';
282 282
 
283
-            foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
284
-                if ($p > 0) {
285
-                    echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>';
286
-                } else {
287
-                    $startTime = $thisTime;
288
-                }
283
+			foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
284
+				if ($p > 0) {
285
+					echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>';
286
+				} else {
287
+					$startTime = $thisTime;
288
+				}
289 289
                 
290
-                $p++;
291
-                $lastTime = $thisTime;
292
-            }
290
+				$p++;
291
+				$lastTime = $thisTime;
292
+			}
293 293
             
294
-            echo '</tbody><tfoot>
294
+			echo '</tbody><tfoot>
295 295
                 <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr>
296 296
             </tfoot>
297 297
             </table>';
298
-        }
298
+		}
299 299
         
300
-    }
300
+	}
301 301
     
302
-    //##########################################################################
302
+	//##########################################################################
303 303
     
304
-    QRtools::markTime('start');
304
+	QRtools::markTime('start');
305 305
     
306 306
 
307 307
 
@@ -343,497 +343,497 @@  discard block
 block discarded – undo
343 343
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
344 344
  */
345 345
  
346
-    define('QRSPEC_VERSION_MAX', 40);
347
-    define('QRSPEC_WIDTH_MAX',   177);
346
+	define('QRSPEC_VERSION_MAX', 40);
347
+	define('QRSPEC_WIDTH_MAX',   177);
348 348
 
349
-    define('QRCAP_WIDTH',        0);
350
-    define('QRCAP_WORDS',        1);
351
-    define('QRCAP_REMINDER',     2);
352
-    define('QRCAP_EC',           3);
349
+	define('QRCAP_WIDTH',        0);
350
+	define('QRCAP_WORDS',        1);
351
+	define('QRCAP_REMINDER',     2);
352
+	define('QRCAP_EC',           3);
353 353
 
354
-    class QRspec {
354
+	class QRspec {
355 355
     
356
-        public static $capacity = array(
357
-            array(  0,    0, 0, array(   0,    0,    0,    0)),
358
-            array( 21,   26, 0, array(   7,   10,   13,   17)), // 1
359
-            array( 25,   44, 7, array(  10,   16,   22,   28)),
360
-            array( 29,   70, 7, array(  15,   26,   36,   44)),
361
-            array( 33,  100, 7, array(  20,   36,   52,   64)),
362
-            array( 37,  134, 7, array(  26,   48,   72,   88)), // 5
363
-            array( 41,  172, 7, array(  36,   64,   96,  112)),
364
-            array( 45,  196, 0, array(  40,   72,  108,  130)),
365
-            array( 49,  242, 0, array(  48,   88,  132,  156)),
366
-            array( 53,  292, 0, array(  60,  110,  160,  192)),
367
-            array( 57,  346, 0, array(  72,  130,  192,  224)), //10
368
-            array( 61,  404, 0, array(  80,  150,  224,  264)),
369
-            array( 65,  466, 0, array(  96,  176,  260,  308)),
370
-            array( 69,  532, 0, array( 104,  198,  288,  352)),
371
-            array( 73,  581, 3, array( 120,  216,  320,  384)),
372
-            array( 77,  655, 3, array( 132,  240,  360,  432)), //15
373
-            array( 81,  733, 3, array( 144,  280,  408,  480)),
374
-            array( 85,  815, 3, array( 168,  308,  448,  532)),
375
-            array( 89,  901, 3, array( 180,  338,  504,  588)),
376
-            array( 93,  991, 3, array( 196,  364,  546,  650)),
377
-            array( 97, 1085, 3, array( 224,  416,  600,  700)), //20
378
-            array(101, 1156, 4, array( 224,  442,  644,  750)),
379
-            array(105, 1258, 4, array( 252,  476,  690,  816)),
380
-            array(109, 1364, 4, array( 270,  504,  750,  900)),
381
-            array(113, 1474, 4, array( 300,  560,  810,  960)),
382
-            array(117, 1588, 4, array( 312,  588,  870, 1050)), //25
383
-            array(121, 1706, 4, array( 336,  644,  952, 1110)),
384
-            array(125, 1828, 4, array( 360,  700, 1020, 1200)),
385
-            array(129, 1921, 3, array( 390,  728, 1050, 1260)),
386
-            array(133, 2051, 3, array( 420,  784, 1140, 1350)),
387
-            array(137, 2185, 3, array( 450,  812, 1200, 1440)), //30
388
-            array(141, 2323, 3, array( 480,  868, 1290, 1530)),
389
-            array(145, 2465, 3, array( 510,  924, 1350, 1620)),
390
-            array(149, 2611, 3, array( 540,  980, 1440, 1710)),
391
-            array(153, 2761, 3, array( 570, 1036, 1530, 1800)),
392
-            array(157, 2876, 0, array( 570, 1064, 1590, 1890)), //35
393
-            array(161, 3034, 0, array( 600, 1120, 1680, 1980)),
394
-            array(165, 3196, 0, array( 630, 1204, 1770, 2100)),
395
-            array(169, 3362, 0, array( 660, 1260, 1860, 2220)),
396
-            array(173, 3532, 0, array( 720, 1316, 1950, 2310)),
397
-            array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40
398
-        );
399
-        
400
-        //----------------------------------------------------------------------
401
-        public static function getDataLength($version, $level)
402
-        {
403
-            return self::$capacity[$version][QRCAP_WORDS] - self::$capacity[$version][QRCAP_EC][$level];
404
-        }
405
-        
406
-        //----------------------------------------------------------------------
407
-        public static function getECCLength($version, $level)
408
-        {
409
-            return self::$capacity[$version][QRCAP_EC][$level];
410
-        }
411
-        
412
-        //----------------------------------------------------------------------
413
-        public static function getWidth($version)
414
-        {
415
-            return self::$capacity[$version][QRCAP_WIDTH];
416
-        }
417
-        
418
-        //----------------------------------------------------------------------
419
-        public static function getRemainder($version)
420
-        {
421
-            return self::$capacity[$version][QRCAP_REMINDER];
422
-        }
423
-        
424
-        //----------------------------------------------------------------------
425
-        public static function getMinimumVersion($size, $level)
426
-        {
427
-
428
-            for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) {
429
-                $words  = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level];
430
-                if($words >= $size) 
431
-                    return $i;
432
-            }
433
-
434
-            return -1;
435
-        }
356
+		public static $capacity = array(
357
+			array(  0,    0, 0, array(   0,    0,    0,    0)),
358
+			array( 21,   26, 0, array(   7,   10,   13,   17)), // 1
359
+			array( 25,   44, 7, array(  10,   16,   22,   28)),
360
+			array( 29,   70, 7, array(  15,   26,   36,   44)),
361
+			array( 33,  100, 7, array(  20,   36,   52,   64)),
362
+			array( 37,  134, 7, array(  26,   48,   72,   88)), // 5
363
+			array( 41,  172, 7, array(  36,   64,   96,  112)),
364
+			array( 45,  196, 0, array(  40,   72,  108,  130)),
365
+			array( 49,  242, 0, array(  48,   88,  132,  156)),
366
+			array( 53,  292, 0, array(  60,  110,  160,  192)),
367
+			array( 57,  346, 0, array(  72,  130,  192,  224)), //10
368
+			array( 61,  404, 0, array(  80,  150,  224,  264)),
369
+			array( 65,  466, 0, array(  96,  176,  260,  308)),
370
+			array( 69,  532, 0, array( 104,  198,  288,  352)),
371
+			array( 73,  581, 3, array( 120,  216,  320,  384)),
372
+			array( 77,  655, 3, array( 132,  240,  360,  432)), //15
373
+			array( 81,  733, 3, array( 144,  280,  408,  480)),
374
+			array( 85,  815, 3, array( 168,  308,  448,  532)),
375
+			array( 89,  901, 3, array( 180,  338,  504,  588)),
376
+			array( 93,  991, 3, array( 196,  364,  546,  650)),
377
+			array( 97, 1085, 3, array( 224,  416,  600,  700)), //20
378
+			array(101, 1156, 4, array( 224,  442,  644,  750)),
379
+			array(105, 1258, 4, array( 252,  476,  690,  816)),
380
+			array(109, 1364, 4, array( 270,  504,  750,  900)),
381
+			array(113, 1474, 4, array( 300,  560,  810,  960)),
382
+			array(117, 1588, 4, array( 312,  588,  870, 1050)), //25
383
+			array(121, 1706, 4, array( 336,  644,  952, 1110)),
384
+			array(125, 1828, 4, array( 360,  700, 1020, 1200)),
385
+			array(129, 1921, 3, array( 390,  728, 1050, 1260)),
386
+			array(133, 2051, 3, array( 420,  784, 1140, 1350)),
387
+			array(137, 2185, 3, array( 450,  812, 1200, 1440)), //30
388
+			array(141, 2323, 3, array( 480,  868, 1290, 1530)),
389
+			array(145, 2465, 3, array( 510,  924, 1350, 1620)),
390
+			array(149, 2611, 3, array( 540,  980, 1440, 1710)),
391
+			array(153, 2761, 3, array( 570, 1036, 1530, 1800)),
392
+			array(157, 2876, 0, array( 570, 1064, 1590, 1890)), //35
393
+			array(161, 3034, 0, array( 600, 1120, 1680, 1980)),
394
+			array(165, 3196, 0, array( 630, 1204, 1770, 2100)),
395
+			array(169, 3362, 0, array( 660, 1260, 1860, 2220)),
396
+			array(173, 3532, 0, array( 720, 1316, 1950, 2310)),
397
+			array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40
398
+		);
399
+        
400
+		//----------------------------------------------------------------------
401
+		public static function getDataLength($version, $level)
402
+		{
403
+			return self::$capacity[$version][QRCAP_WORDS] - self::$capacity[$version][QRCAP_EC][$level];
404
+		}
405
+        
406
+		//----------------------------------------------------------------------
407
+		public static function getECCLength($version, $level)
408
+		{
409
+			return self::$capacity[$version][QRCAP_EC][$level];
410
+		}
411
+        
412
+		//----------------------------------------------------------------------
413
+		public static function getWidth($version)
414
+		{
415
+			return self::$capacity[$version][QRCAP_WIDTH];
416
+		}
417
+        
418
+		//----------------------------------------------------------------------
419
+		public static function getRemainder($version)
420
+		{
421
+			return self::$capacity[$version][QRCAP_REMINDER];
422
+		}
423
+        
424
+		//----------------------------------------------------------------------
425
+		public static function getMinimumVersion($size, $level)
426
+		{
427
+
428
+			for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) {
429
+				$words  = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level];
430
+				if($words >= $size) 
431
+					return $i;
432
+			}
433
+
434
+			return -1;
435
+		}
436 436
     
437
-        //######################################################################
438
-        
439
-        public static $lengthTableBits = array(
440
-            array(10, 12, 14),
441
-            array( 9, 11, 13),
442
-            array( 8, 16, 16),
443
-            array( 8, 10, 12)
444
-        );
445
-        
446
-        //----------------------------------------------------------------------
447
-        public static function lengthIndicator($mode, $version)
448
-        {
449
-            if ($mode == QR_MODE_STRUCTURE)
450
-                return 0;
437
+		//######################################################################
438
+        
439
+		public static $lengthTableBits = array(
440
+			array(10, 12, 14),
441
+			array( 9, 11, 13),
442
+			array( 8, 16, 16),
443
+			array( 8, 10, 12)
444
+		);
445
+        
446
+		//----------------------------------------------------------------------
447
+		public static function lengthIndicator($mode, $version)
448
+		{
449
+			if ($mode == QR_MODE_STRUCTURE)
450
+				return 0;
451 451
                 
452
-            if ($version <= 9) {
453
-                $l = 0;
454
-            } else if ($version <= 26) {
455
-                $l = 1;
456
-            } else {
457
-                $l = 2;
458
-            }
459
-
460
-            return self::$lengthTableBits[$mode][$l];
461
-        }
462
-        
463
-        //----------------------------------------------------------------------
464
-        public static function maximumWords($mode, $version)
465
-        {
466
-            if($mode == QR_MODE_STRUCTURE) 
467
-                return 3;
452
+			if ($version <= 9) {
453
+				$l = 0;
454
+			} else if ($version <= 26) {
455
+				$l = 1;
456
+			} else {
457
+				$l = 2;
458
+			}
459
+
460
+			return self::$lengthTableBits[$mode][$l];
461
+		}
462
+        
463
+		//----------------------------------------------------------------------
464
+		public static function maximumWords($mode, $version)
465
+		{
466
+			if($mode == QR_MODE_STRUCTURE) 
467
+				return 3;
468 468
                 
469
-            if($version <= 9) {
470
-                $l = 0;
471
-            } else if($version <= 26) {
472
-                $l = 1;
473
-            } else {
474
-                $l = 2;
475
-            }
476
-
477
-            $bits = self::$lengthTableBits[$mode][$l];
478
-            $words = (1 << $bits) - 1;
479
-            
480
-            if($mode == QR_MODE_KANJI) {
481
-                $words *= 2; // the number of bytes is required
482
-            }
483
-
484
-            return $words;
485
-        }
486
-
487
-        // Error correction code -----------------------------------------------
488
-        // Table of the error correction code (Reed-Solomon block)
489
-        // See Table 12-16 (pp.30-36), JIS X0510:2004.
490
-
491
-        public static $eccTable = array(
492
-            array(array( 0,  0), array( 0,  0), array( 0,  0), array( 0,  0)),
493
-            array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)), // 1
494
-            array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)),
495
-            array(array( 1,  0), array( 1,  0), array( 2,  0), array( 2,  0)),
496
-            array(array( 1,  0), array( 2,  0), array( 2,  0), array( 4,  0)),
497
-            array(array( 1,  0), array( 2,  0), array( 2,  2), array( 2,  2)), // 5
498
-            array(array( 2,  0), array( 4,  0), array( 4,  0), array( 4,  0)),
499
-            array(array( 2,  0), array( 4,  0), array( 2,  4), array( 4,  1)),
500
-            array(array( 2,  0), array( 2,  2), array( 4,  2), array( 4,  2)),
501
-            array(array( 2,  0), array( 3,  2), array( 4,  4), array( 4,  4)),
502
-            array(array( 2,  2), array( 4,  1), array( 6,  2), array( 6,  2)), //10
503
-            array(array( 4,  0), array( 1,  4), array( 4,  4), array( 3,  8)),
504
-            array(array( 2,  2), array( 6,  2), array( 4,  6), array( 7,  4)),
505
-            array(array( 4,  0), array( 8,  1), array( 8,  4), array(12,  4)),
506
-            array(array( 3,  1), array( 4,  5), array(11,  5), array(11,  5)),
507
-            array(array( 5,  1), array( 5,  5), array( 5,  7), array(11,  7)), //15
508
-            array(array( 5,  1), array( 7,  3), array(15,  2), array( 3, 13)),
509
-            array(array( 1,  5), array(10,  1), array( 1, 15), array( 2, 17)),
510
-            array(array( 5,  1), array( 9,  4), array(17,  1), array( 2, 19)),
511
-            array(array( 3,  4), array( 3, 11), array(17,  4), array( 9, 16)),
512
-            array(array( 3,  5), array( 3, 13), array(15,  5), array(15, 10)), //20
513
-            array(array( 4,  4), array(17,  0), array(17,  6), array(19,  6)),
514
-            array(array( 2,  7), array(17,  0), array( 7, 16), array(34,  0)),
515
-            array(array( 4,  5), array( 4, 14), array(11, 14), array(16, 14)),
516
-            array(array( 6,  4), array( 6, 14), array(11, 16), array(30,  2)),
517
-            array(array( 8,  4), array( 8, 13), array( 7, 22), array(22, 13)), //25
518
-            array(array(10,  2), array(19,  4), array(28,  6), array(33,  4)),
519
-            array(array( 8,  4), array(22,  3), array( 8, 26), array(12, 28)),
520
-            array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)),
521
-            array(array( 7,  7), array(21,  7), array( 1, 37), array(19, 26)),
522
-            array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), //30
523
-            array(array(13,  3), array( 2, 29), array(42,  1), array(23, 28)),
524
-            array(array(17,  0), array(10, 23), array(10, 35), array(19, 35)),
525
-            array(array(17,  1), array(14, 21), array(29, 19), array(11, 46)),
526
-            array(array(13,  6), array(14, 23), array(44,  7), array(59,  1)),
527
-            array(array(12,  7), array(12, 26), array(39, 14), array(22, 41)), //35
528
-            array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)),
529
-            array(array(17,  4), array(29, 14), array(49, 10), array(24, 46)),
530
-            array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)),
531
-            array(array(20,  4), array(40,  7), array(43, 22), array(10, 67)),
532
-            array(array(19,  6), array(18, 31), array(34, 34), array(20, 61)),//40
533
-        );                                                                       
534
-
535
-        //----------------------------------------------------------------------
536
-        // CACHEABLE!!!
537
-        
538
-        public static function getEccSpec($version, $level, array &$spec)
539
-        {
540
-            if (count($spec) < 5) {
541
-                $spec = array(0,0,0,0,0);
542
-            }
543
-
544
-            $b1   = self::$eccTable[$version][$level][0];
545
-            $b2   = self::$eccTable[$version][$level][1];
546
-            $data = self::getDataLength($version, $level);
547
-            $ecc  = self::getECCLength($version, $level);
548
-
549
-            if($b2 == 0) {
550
-                $spec[0] = $b1;
551
-                $spec[1] = (int)($data / $b1);
552
-                $spec[2] = (int)($ecc / $b1);
553
-                $spec[3] = 0; 
554
-                $spec[4] = 0;
555
-            } else {
556
-                $spec[0] = $b1;
557
-                $spec[1] = (int)($data / ($b1 + $b2));
558
-                $spec[2] = (int)($ecc  / ($b1 + $b2));
559
-                $spec[3] = $b2;
560
-                $spec[4] = $spec[1] + 1;
561
-            }
562
-        }
563
-
564
-        // Alignment pattern ---------------------------------------------------
565
-
566
-        // Positions of alignment patterns.
567
-        // This array includes only the second and the third position of the 
568
-        // alignment patterns. Rest of them can be calculated from the distance 
569
-        // between them.
469
+			if($version <= 9) {
470
+				$l = 0;
471
+			} else if($version <= 26) {
472
+				$l = 1;
473
+			} else {
474
+				$l = 2;
475
+			}
476
+
477
+			$bits = self::$lengthTableBits[$mode][$l];
478
+			$words = (1 << $bits) - 1;
479
+            
480
+			if($mode == QR_MODE_KANJI) {
481
+				$words *= 2; // the number of bytes is required
482
+			}
483
+
484
+			return $words;
485
+		}
486
+
487
+		// Error correction code -----------------------------------------------
488
+		// Table of the error correction code (Reed-Solomon block)
489
+		// See Table 12-16 (pp.30-36), JIS X0510:2004.
490
+
491
+		public static $eccTable = array(
492
+			array(array( 0,  0), array( 0,  0), array( 0,  0), array( 0,  0)),
493
+			array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)), // 1
494
+			array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)),
495
+			array(array( 1,  0), array( 1,  0), array( 2,  0), array( 2,  0)),
496
+			array(array( 1,  0), array( 2,  0), array( 2,  0), array( 4,  0)),
497
+			array(array( 1,  0), array( 2,  0), array( 2,  2), array( 2,  2)), // 5
498
+			array(array( 2,  0), array( 4,  0), array( 4,  0), array( 4,  0)),
499
+			array(array( 2,  0), array( 4,  0), array( 2,  4), array( 4,  1)),
500
+			array(array( 2,  0), array( 2,  2), array( 4,  2), array( 4,  2)),
501
+			array(array( 2,  0), array( 3,  2), array( 4,  4), array( 4,  4)),
502
+			array(array( 2,  2), array( 4,  1), array( 6,  2), array( 6,  2)), //10
503
+			array(array( 4,  0), array( 1,  4), array( 4,  4), array( 3,  8)),
504
+			array(array( 2,  2), array( 6,  2), array( 4,  6), array( 7,  4)),
505
+			array(array( 4,  0), array( 8,  1), array( 8,  4), array(12,  4)),
506
+			array(array( 3,  1), array( 4,  5), array(11,  5), array(11,  5)),
507
+			array(array( 5,  1), array( 5,  5), array( 5,  7), array(11,  7)), //15
508
+			array(array( 5,  1), array( 7,  3), array(15,  2), array( 3, 13)),
509
+			array(array( 1,  5), array(10,  1), array( 1, 15), array( 2, 17)),
510
+			array(array( 5,  1), array( 9,  4), array(17,  1), array( 2, 19)),
511
+			array(array( 3,  4), array( 3, 11), array(17,  4), array( 9, 16)),
512
+			array(array( 3,  5), array( 3, 13), array(15,  5), array(15, 10)), //20
513
+			array(array( 4,  4), array(17,  0), array(17,  6), array(19,  6)),
514
+			array(array( 2,  7), array(17,  0), array( 7, 16), array(34,  0)),
515
+			array(array( 4,  5), array( 4, 14), array(11, 14), array(16, 14)),
516
+			array(array( 6,  4), array( 6, 14), array(11, 16), array(30,  2)),
517
+			array(array( 8,  4), array( 8, 13), array( 7, 22), array(22, 13)), //25
518
+			array(array(10,  2), array(19,  4), array(28,  6), array(33,  4)),
519
+			array(array( 8,  4), array(22,  3), array( 8, 26), array(12, 28)),
520
+			array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)),
521
+			array(array( 7,  7), array(21,  7), array( 1, 37), array(19, 26)),
522
+			array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), //30
523
+			array(array(13,  3), array( 2, 29), array(42,  1), array(23, 28)),
524
+			array(array(17,  0), array(10, 23), array(10, 35), array(19, 35)),
525
+			array(array(17,  1), array(14, 21), array(29, 19), array(11, 46)),
526
+			array(array(13,  6), array(14, 23), array(44,  7), array(59,  1)),
527
+			array(array(12,  7), array(12, 26), array(39, 14), array(22, 41)), //35
528
+			array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)),
529
+			array(array(17,  4), array(29, 14), array(49, 10), array(24, 46)),
530
+			array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)),
531
+			array(array(20,  4), array(40,  7), array(43, 22), array(10, 67)),
532
+			array(array(19,  6), array(18, 31), array(34, 34), array(20, 61)),//40
533
+		);                                                                       
534
+
535
+		//----------------------------------------------------------------------
536
+		// CACHEABLE!!!
537
+        
538
+		public static function getEccSpec($version, $level, array &$spec)
539
+		{
540
+			if (count($spec) < 5) {
541
+				$spec = array(0,0,0,0,0);
542
+			}
543
+
544
+			$b1   = self::$eccTable[$version][$level][0];
545
+			$b2   = self::$eccTable[$version][$level][1];
546
+			$data = self::getDataLength($version, $level);
547
+			$ecc  = self::getECCLength($version, $level);
548
+
549
+			if($b2 == 0) {
550
+				$spec[0] = $b1;
551
+				$spec[1] = (int)($data / $b1);
552
+				$spec[2] = (int)($ecc / $b1);
553
+				$spec[3] = 0; 
554
+				$spec[4] = 0;
555
+			} else {
556
+				$spec[0] = $b1;
557
+				$spec[1] = (int)($data / ($b1 + $b2));
558
+				$spec[2] = (int)($ecc  / ($b1 + $b2));
559
+				$spec[3] = $b2;
560
+				$spec[4] = $spec[1] + 1;
561
+			}
562
+		}
563
+
564
+		// Alignment pattern ---------------------------------------------------
565
+
566
+		// Positions of alignment patterns.
567
+		// This array includes only the second and the third position of the 
568
+		// alignment patterns. Rest of them can be calculated from the distance 
569
+		// between them.
570 570
          
571
-        // See Table 1 in Appendix E (pp.71) of JIS X0510:2004.
571
+		// See Table 1 in Appendix E (pp.71) of JIS X0510:2004.
572 572
          
573
-        public static $alignmentPattern = array(      
574
-            array( 0,  0),
575
-            array( 0,  0), array(18,  0), array(22,  0), array(26,  0), array(30,  0), // 1- 5
576
-            array(34,  0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10
577
-            array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), //11-15
578
-            array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), //16-20
579
-            array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), //21-25
580
-            array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), //26-30
581
-            array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), //31-35
582
-            array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58), //35-40
583
-        );                                                                                  
584
-
585
-        
586
-        /** --------------------------------------------------------------------
587
-         * Put an alignment marker.
588
-         * @param frame
589
-         * @param width
590
-         * @param ox,oy center coordinate of the pattern
591
-         */
592
-        public static function putAlignmentMarker(array &$frame, $ox, $oy)
593
-        {
594
-            $finder = array(
595
-                "\xa1\xa1\xa1\xa1\xa1",
596
-                "\xa1\xa0\xa0\xa0\xa1",
597
-                "\xa1\xa0\xa1\xa0\xa1",
598
-                "\xa1\xa0\xa0\xa0\xa1",
599
-                "\xa1\xa1\xa1\xa1\xa1"
600
-            );                        
601
-            
602
-            $yStart = $oy-2;         
603
-            $xStart = $ox-2;
604
-            
605
-            for($y=0; $y<5; $y++) {
606
-                QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]);
607
-            }
608
-        }
609
-
610
-        //----------------------------------------------------------------------
611
-        public static function putAlignmentPattern($version, &$frame, $width)
612
-        {
613
-            if($version < 2)
614
-                return;
615
-
616
-            $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0];
617
-            if($d < 0) {
618
-                $w = 2;
619
-            } else {
620
-                $w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2);
621
-            }
622
-
623
-            if($w * $w - 3 == 1) {
624
-                $x = self::$alignmentPattern[$version][0];
625
-                $y = self::$alignmentPattern[$version][0];
626
-                self::putAlignmentMarker($frame, $x, $y);
627
-                return;
628
-            }
629
-
630
-            $cx = self::$alignmentPattern[$version][0];
631
-            for($x=1; $x<$w - 1; $x++) {
632
-                self::putAlignmentMarker($frame, 6, $cx);
633
-                self::putAlignmentMarker($frame, $cx,  6);
634
-                $cx += $d;
635
-            }
636
-
637
-            $cy = self::$alignmentPattern[$version][0];
638
-            for($y=0; $y<$w-1; $y++) {
639
-                $cx = self::$alignmentPattern[$version][0];
640
-                for($x=0; $x<$w-1; $x++) {
641
-                    self::putAlignmentMarker($frame, $cx, $cy);
642
-                    $cx += $d;
643
-                }
644
-                $cy += $d;
645
-            }
646
-        }
647
-
648
-        // Version information pattern -----------------------------------------
573
+		public static $alignmentPattern = array(      
574
+			array( 0,  0),
575
+			array( 0,  0), array(18,  0), array(22,  0), array(26,  0), array(30,  0), // 1- 5
576
+			array(34,  0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10
577
+			array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), //11-15
578
+			array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), //16-20
579
+			array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), //21-25
580
+			array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), //26-30
581
+			array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), //31-35
582
+			array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58), //35-40
583
+		);                                                                                  
584
+
585
+        
586
+		/** --------------------------------------------------------------------
587
+		 * Put an alignment marker.
588
+		 * @param frame
589
+		 * @param width
590
+		 * @param ox,oy center coordinate of the pattern
591
+		 */
592
+		public static function putAlignmentMarker(array &$frame, $ox, $oy)
593
+		{
594
+			$finder = array(
595
+				"\xa1\xa1\xa1\xa1\xa1",
596
+				"\xa1\xa0\xa0\xa0\xa1",
597
+				"\xa1\xa0\xa1\xa0\xa1",
598
+				"\xa1\xa0\xa0\xa0\xa1",
599
+				"\xa1\xa1\xa1\xa1\xa1"
600
+			);                        
601
+            
602
+			$yStart = $oy-2;         
603
+			$xStart = $ox-2;
604
+            
605
+			for($y=0; $y<5; $y++) {
606
+				QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]);
607
+			}
608
+		}
609
+
610
+		//----------------------------------------------------------------------
611
+		public static function putAlignmentPattern($version, &$frame, $width)
612
+		{
613
+			if($version < 2)
614
+				return;
615
+
616
+			$d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0];
617
+			if($d < 0) {
618
+				$w = 2;
619
+			} else {
620
+				$w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2);
621
+			}
622
+
623
+			if($w * $w - 3 == 1) {
624
+				$x = self::$alignmentPattern[$version][0];
625
+				$y = self::$alignmentPattern[$version][0];
626
+				self::putAlignmentMarker($frame, $x, $y);
627
+				return;
628
+			}
629
+
630
+			$cx = self::$alignmentPattern[$version][0];
631
+			for($x=1; $x<$w - 1; $x++) {
632
+				self::putAlignmentMarker($frame, 6, $cx);
633
+				self::putAlignmentMarker($frame, $cx,  6);
634
+				$cx += $d;
635
+			}
636
+
637
+			$cy = self::$alignmentPattern[$version][0];
638
+			for($y=0; $y<$w-1; $y++) {
639
+				$cx = self::$alignmentPattern[$version][0];
640
+				for($x=0; $x<$w-1; $x++) {
641
+					self::putAlignmentMarker($frame, $cx, $cy);
642
+					$cx += $d;
643
+				}
644
+				$cy += $d;
645
+			}
646
+		}
647
+
648
+		// Version information pattern -----------------------------------------
649 649
 
650 650
 		// Version information pattern (BCH coded).
651
-        // See Table 1 in Appendix D (pp.68) of JIS X0510:2004.
651
+		// See Table 1 in Appendix D (pp.68) of JIS X0510:2004.
652 652
         
653 653
 		// size: [QRSPEC_VERSION_MAX - 6]
654 654
 		
655
-        public static $versionPattern = array(
656
-            0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d,
657
-            0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9,
658
-            0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75,
659
-            0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64,
660
-            0x27541, 0x28c69
661
-        );
662
-
663
-        //----------------------------------------------------------------------
664
-        public static function getVersionPattern($version)
665
-        {
666
-            if($version < 7 || $version > QRSPEC_VERSION_MAX)
667
-                return 0;
668
-
669
-            return self::$versionPattern[$version -7];
670
-        }
671
-
672
-        // Format information --------------------------------------------------
673
-        // See calcFormatInfo in tests/test_qrspec.c (orginal qrencode c lib)
674
-        
675
-        public static $formatInfo = array(
676
-            array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976),
677
-            array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0),
678
-            array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed),
679
-            array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b)
680
-        );
681
-
682
-        public static function getFormatInfo($mask, $level)
683
-        {
684
-            if($mask < 0 || $mask > 7)
685
-                return 0;
655
+		public static $versionPattern = array(
656
+			0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d,
657
+			0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9,
658
+			0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75,
659
+			0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64,
660
+			0x27541, 0x28c69
661
+		);
662
+
663
+		//----------------------------------------------------------------------
664
+		public static function getVersionPattern($version)
665
+		{
666
+			if($version < 7 || $version > QRSPEC_VERSION_MAX)
667
+				return 0;
668
+
669
+			return self::$versionPattern[$version -7];
670
+		}
671
+
672
+		// Format information --------------------------------------------------
673
+		// See calcFormatInfo in tests/test_qrspec.c (orginal qrencode c lib)
674
+        
675
+		public static $formatInfo = array(
676
+			array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976),
677
+			array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0),
678
+			array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed),
679
+			array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b)
680
+		);
681
+
682
+		public static function getFormatInfo($mask, $level)
683
+		{
684
+			if($mask < 0 || $mask > 7)
685
+				return 0;
686 686
                 
687
-            if($level < 0 || $level > 3)
688
-                return 0;                
687
+			if($level < 0 || $level > 3)
688
+				return 0;                
689 689
 
690
-            return self::$formatInfo[$level][$mask];
691
-        }
690
+			return self::$formatInfo[$level][$mask];
691
+		}
692 692
 
693
-        // Frame ---------------------------------------------------------------
694
-        // Cache of initial frames.
693
+		// Frame ---------------------------------------------------------------
694
+		// Cache of initial frames.
695 695
          
696
-        public static $frames = array();
697
-
698
-        /** --------------------------------------------------------------------
699
-         * Put a finder pattern.
700
-         * @param frame
701
-         * @param width
702
-         * @param ox,oy upper-left coordinate of the pattern
703
-         */
704
-        public static function putFinderPattern(&$frame, $ox, $oy)
705
-        {
706
-            $finder = array(
707
-                "\xc1\xc1\xc1\xc1\xc1\xc1\xc1",
708
-                "\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
709
-                "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
710
-                "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
711
-                "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
712
-                "\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
713
-                "\xc1\xc1\xc1\xc1\xc1\xc1\xc1"
714
-            );                            
715
-            
716
-            for($y=0; $y<7; $y++) {
717
-                QRstr::set($frame, $ox, $oy+$y, $finder[$y]);
718
-            }
719
-        }
720
-
721
-        //----------------------------------------------------------------------
722
-        public static function createFrame($version)
723
-        {
724
-            $width = self::$capacity[$version][QRCAP_WIDTH];
725
-            $frameLine = str_repeat ("\0", $width);
726
-            $frame = array_fill(0, $width, $frameLine);
727
-
728
-            // Finder pattern
729
-            self::putFinderPattern($frame, 0, 0);
730
-            self::putFinderPattern($frame, $width - 7, 0);
731
-            self::putFinderPattern($frame, 0, $width - 7);
732
-            
733
-            // Separator
734
-            $yOffset = $width - 7;
735
-            
736
-            for($y=0; $y<7; $y++) {
737
-                $frame[$y][7] = "\xc0";
738
-                $frame[$y][$width - 8] = "\xc0";
739
-                $frame[$yOffset][7] = "\xc0";
740
-                $yOffset++;
741
-            }
742
-            
743
-            $setPattern = str_repeat("\xc0", 8);
744
-            
745
-            QRstr::set($frame, 0, 7, $setPattern);
746
-            QRstr::set($frame, $width-8, 7, $setPattern);
747
-            QRstr::set($frame, 0, $width - 8, $setPattern);
748
-        
749
-            // Format info
750
-            $setPattern = str_repeat("\x84", 9);
751
-            QRstr::set($frame, 0, 8, $setPattern);
752
-            QRstr::set($frame, $width - 8, 8, $setPattern, 8);
753
-            
754
-            $yOffset = $width - 8;
755
-
756
-            for($y=0; $y<8; $y++,$yOffset++) {
757
-                $frame[$y][8] = "\x84";
758
-                $frame[$yOffset][8] = "\x84";
759
-            }
760
-
761
-            // Timing pattern  
762
-            
763
-            for($i=1; $i<$width-15; $i++) {
764
-                $frame[6][7+$i] = chr(0x90 | ($i & 1));
765
-                $frame[7+$i][6] = chr(0x90 | ($i & 1));
766
-            }
767
-            
768
-            // Alignment pattern  
769
-            self::putAlignmentPattern($version, $frame, $width);
770
-            
771
-            // Version information 
772
-            if($version >= 7) {
773
-                $vinf = self::getVersionPattern($version);
774
-
775
-                $v = $vinf;
696
+		public static $frames = array();
697
+
698
+		/** --------------------------------------------------------------------
699
+		 * Put a finder pattern.
700
+		 * @param frame
701
+		 * @param width
702
+		 * @param ox,oy upper-left coordinate of the pattern
703
+		 */
704
+		public static function putFinderPattern(&$frame, $ox, $oy)
705
+		{
706
+			$finder = array(
707
+				"\xc1\xc1\xc1\xc1\xc1\xc1\xc1",
708
+				"\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
709
+				"\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
710
+				"\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
711
+				"\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
712
+				"\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
713
+				"\xc1\xc1\xc1\xc1\xc1\xc1\xc1"
714
+			);                            
715
+            
716
+			for($y=0; $y<7; $y++) {
717
+				QRstr::set($frame, $ox, $oy+$y, $finder[$y]);
718
+			}
719
+		}
720
+
721
+		//----------------------------------------------------------------------
722
+		public static function createFrame($version)
723
+		{
724
+			$width = self::$capacity[$version][QRCAP_WIDTH];
725
+			$frameLine = str_repeat ("\0", $width);
726
+			$frame = array_fill(0, $width, $frameLine);
727
+
728
+			// Finder pattern
729
+			self::putFinderPattern($frame, 0, 0);
730
+			self::putFinderPattern($frame, $width - 7, 0);
731
+			self::putFinderPattern($frame, 0, $width - 7);
732
+            
733
+			// Separator
734
+			$yOffset = $width - 7;
735
+            
736
+			for($y=0; $y<7; $y++) {
737
+				$frame[$y][7] = "\xc0";
738
+				$frame[$y][$width - 8] = "\xc0";
739
+				$frame[$yOffset][7] = "\xc0";
740
+				$yOffset++;
741
+			}
742
+            
743
+			$setPattern = str_repeat("\xc0", 8);
744
+            
745
+			QRstr::set($frame, 0, 7, $setPattern);
746
+			QRstr::set($frame, $width-8, 7, $setPattern);
747
+			QRstr::set($frame, 0, $width - 8, $setPattern);
748
+        
749
+			// Format info
750
+			$setPattern = str_repeat("\x84", 9);
751
+			QRstr::set($frame, 0, 8, $setPattern);
752
+			QRstr::set($frame, $width - 8, 8, $setPattern, 8);
753
+            
754
+			$yOffset = $width - 8;
755
+
756
+			for($y=0; $y<8; $y++,$yOffset++) {
757
+				$frame[$y][8] = "\x84";
758
+				$frame[$yOffset][8] = "\x84";
759
+			}
760
+
761
+			// Timing pattern  
762
+            
763
+			for($i=1; $i<$width-15; $i++) {
764
+				$frame[6][7+$i] = chr(0x90 | ($i & 1));
765
+				$frame[7+$i][6] = chr(0x90 | ($i & 1));
766
+			}
767
+            
768
+			// Alignment pattern  
769
+			self::putAlignmentPattern($version, $frame, $width);
770
+            
771
+			// Version information 
772
+			if($version >= 7) {
773
+				$vinf = self::getVersionPattern($version);
774
+
775
+				$v = $vinf;
776 776
                 
777
-                for($x=0; $x<6; $x++) {
778
-                    for($y=0; $y<3; $y++) {
779
-                        $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));
780
-                        $v = $v >> 1;
781
-                    }
782
-                }
783
-
784
-                $v = $vinf;
785
-                for($y=0; $y<6; $y++) {
786
-                    for($x=0; $x<3; $x++) {
787
-                        $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1));
788
-                        $v = $v >> 1;
789
-                    }
790
-                }
791
-            }
777
+				for($x=0; $x<6; $x++) {
778
+					for($y=0; $y<3; $y++) {
779
+						$frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));
780
+						$v = $v >> 1;
781
+					}
782
+				}
783
+
784
+				$v = $vinf;
785
+				for($y=0; $y<6; $y++) {
786
+					for($x=0; $x<3; $x++) {
787
+						$frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1));
788
+						$v = $v >> 1;
789
+					}
790
+				}
791
+			}
792 792
     
793
-            // and a little bit...  
794
-            $frame[$width - 8][8] = "\x81";
793
+			// and a little bit...  
794
+			$frame[$width - 8][8] = "\x81";
795 795
             
796
-            return $frame;
797
-        }
796
+			return $frame;
797
+		}
798 798
 
799
-        //----------------------------------------------------------------------
800
-        public static function debug($frame, $binary_mode = false)
801
-        {
802
-            if ($binary_mode) {
803
-            
804
-                    foreach ($frame as &$frameLine) {
805
-                        $frameLine = join('<span class="m">&nbsp;&nbsp;</span>', explode('0', $frameLine));
806
-                        $frameLine = join('&#9608;&#9608;', explode('1', $frameLine));
807
-                    }
799
+		//----------------------------------------------------------------------
800
+		public static function debug($frame, $binary_mode = false)
801
+		{
802
+			if ($binary_mode) {
803
+            
804
+					foreach ($frame as &$frameLine) {
805
+						$frameLine = join('<span class="m">&nbsp;&nbsp;</span>', explode('0', $frameLine));
806
+						$frameLine = join('&#9608;&#9608;', explode('1', $frameLine));
807
+					}
808 808
                     
809
-                    ?>
809
+					?>
810 810
                 <style>
811 811
                     .m { background-color: white; }
812 812
                 </style>
813 813
                 <?php
814
-                    echo '<pre><tt><br/ ><br/ ><br/ >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
815
-                    echo join("<br/ >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $frame);
816
-                    echo '</tt></pre><br/ ><br/ ><br/ ><br/ ><br/ ><br/ >';
817
-            
818
-            } else {
819
-            
820
-                foreach ($frame as &$frameLine) {
821
-                    $frameLine = join('<span class="m">&nbsp;</span>',  explode("\xc0", $frameLine));
822
-                    $frameLine = join('<span class="m">&#9618;</span>', explode("\xc1", $frameLine));
823
-                    $frameLine = join('<span class="p">&nbsp;</span>',  explode("\xa0", $frameLine));
824
-                    $frameLine = join('<span class="p">&#9618;</span>', explode("\xa1", $frameLine));
825
-                    $frameLine = join('<span class="s">&#9671;</span>', explode("\x84", $frameLine)); //format 0
826
-                    $frameLine = join('<span class="s">&#9670;</span>', explode("\x85", $frameLine)); //format 1
827
-                    $frameLine = join('<span class="x">&#9762;</span>', explode("\x81", $frameLine)); //special bit
828
-                    $frameLine = join('<span class="c">&nbsp;</span>',  explode("\x90", $frameLine)); //clock 0
829
-                    $frameLine = join('<span class="c">&#9719;</span>', explode("\x91", $frameLine)); //clock 1
830
-                    $frameLine = join('<span class="f">&nbsp;</span>',  explode("\x88", $frameLine)); //version
831
-                    $frameLine = join('<span class="f">&#9618;</span>', explode("\x89", $frameLine)); //version
832
-                    $frameLine = join('&#9830;', explode("\x01", $frameLine));
833
-                    $frameLine = join('&#8901;', explode("\0", $frameLine));
834
-                }
814
+					echo '<pre><tt><br/ ><br/ ><br/ >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
815
+					echo join("<br/ >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $frame);
816
+					echo '</tt></pre><br/ ><br/ ><br/ ><br/ ><br/ ><br/ >';
817
+            
818
+			} else {
819
+            
820
+				foreach ($frame as &$frameLine) {
821
+					$frameLine = join('<span class="m">&nbsp;</span>',  explode("\xc0", $frameLine));
822
+					$frameLine = join('<span class="m">&#9618;</span>', explode("\xc1", $frameLine));
823
+					$frameLine = join('<span class="p">&nbsp;</span>',  explode("\xa0", $frameLine));
824
+					$frameLine = join('<span class="p">&#9618;</span>', explode("\xa1", $frameLine));
825
+					$frameLine = join('<span class="s">&#9671;</span>', explode("\x84", $frameLine)); //format 0
826
+					$frameLine = join('<span class="s">&#9670;</span>', explode("\x85", $frameLine)); //format 1
827
+					$frameLine = join('<span class="x">&#9762;</span>', explode("\x81", $frameLine)); //special bit
828
+					$frameLine = join('<span class="c">&nbsp;</span>',  explode("\x90", $frameLine)); //clock 0
829
+					$frameLine = join('<span class="c">&#9719;</span>', explode("\x91", $frameLine)); //clock 1
830
+					$frameLine = join('<span class="f">&nbsp;</span>',  explode("\x88", $frameLine)); //version
831
+					$frameLine = join('<span class="f">&#9618;</span>', explode("\x89", $frameLine)); //version
832
+					$frameLine = join('&#9830;', explode("\x01", $frameLine));
833
+					$frameLine = join('&#8901;', explode("\0", $frameLine));
834
+				}
835 835
                 
836
-                ?>
836
+				?>
837 837
                 <style>
838 838
                     .p { background-color: yellow; }
839 839
                     .m { background-color: #00FF00; }
@@ -843,65 +843,65 @@  discard block
 block discarded – undo
843 843
                     .f { background-color: gold; }
844 844
                 </style>
845 845
                 <?php
846
-                echo "<pre><tt>";
847
-                echo join("<br/ >", $frame);
848
-                echo "</tt></pre>";
849
-            
850
-            }
851
-        }
852
-
853
-        //----------------------------------------------------------------------
854
-        public static function serial($frame)
855
-        {
856
-            return gzcompress(join("\n", $frame), 9);
857
-        }
858
-        
859
-        //----------------------------------------------------------------------
860
-        public static function unserial($code)
861
-        {
862
-            return explode("\n", gzuncompress($code));
863
-        }
864
-        
865
-        //----------------------------------------------------------------------
866
-        public static function newFrame($version)
867
-        {
868
-            if($version < 1 || $version > QRSPEC_VERSION_MAX) 
869
-                return null;
870
-
871
-            if(!isset(self::$frames[$version])) {
846
+				echo "<pre><tt>";
847
+				echo join("<br/ >", $frame);
848
+				echo "</tt></pre>";
849
+            
850
+			}
851
+		}
852
+
853
+		//----------------------------------------------------------------------
854
+		public static function serial($frame)
855
+		{
856
+			return gzcompress(join("\n", $frame), 9);
857
+		}
858
+        
859
+		//----------------------------------------------------------------------
860
+		public static function unserial($code)
861
+		{
862
+			return explode("\n", gzuncompress($code));
863
+		}
864
+        
865
+		//----------------------------------------------------------------------
866
+		public static function newFrame($version)
867
+		{
868
+			if($version < 1 || $version > QRSPEC_VERSION_MAX) 
869
+				return null;
870
+
871
+			if(!isset(self::$frames[$version])) {
872 872
                 
873
-                $fileName = QR_CACHE_DIR.'frame_'.$version.'.dat';
873
+				$fileName = QR_CACHE_DIR.'frame_'.$version.'.dat';
874 874
                 
875
-                if (QR_CACHEABLE) {
876
-                    if (file_exists($fileName)) {
877
-                        self::$frames[$version] = self::unserial(file_get_contents($fileName));
878
-                    } else {
879
-                        self::$frames[$version] = self::createFrame($version);
880
-                        file_put_contents($fileName, self::serial(self::$frames[$version]));
881
-                    }
882
-                } else {
883
-                    self::$frames[$version] = self::createFrame($version);
884
-                }
885
-            }
886
-            
887
-            if(is_null(self::$frames[$version]))
888
-                return null;
889
-
890
-            return self::$frames[$version];
891
-        }
892
-
893
-        //----------------------------------------------------------------------
894
-        public static function rsBlockNum($spec)     { return $spec[0] + $spec[3]; }
895
-        public static function rsBlockNum1($spec)    { return $spec[0]; }
896
-        public static function rsDataCodes1($spec)   { return $spec[1]; }
897
-        public static function rsEccCodes1($spec)    { return $spec[2]; }
898
-        public static function rsBlockNum2($spec)    { return $spec[3]; }
899
-        public static function rsDataCodes2($spec)   { return $spec[4]; }
900
-        public static function rsEccCodes2($spec)    { return $spec[2]; }
901
-        public static function rsDataLength($spec)   { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]);    }
902
-        public static function rsEccLength($spec)    { return ($spec[0] + $spec[3]) * $spec[2]; }
903
-        
904
-    }
875
+				if (QR_CACHEABLE) {
876
+					if (file_exists($fileName)) {
877
+						self::$frames[$version] = self::unserial(file_get_contents($fileName));
878
+					} else {
879
+						self::$frames[$version] = self::createFrame($version);
880
+						file_put_contents($fileName, self::serial(self::$frames[$version]));
881
+					}
882
+				} else {
883
+					self::$frames[$version] = self::createFrame($version);
884
+				}
885
+			}
886
+            
887
+			if(is_null(self::$frames[$version]))
888
+				return null;
889
+
890
+			return self::$frames[$version];
891
+		}
892
+
893
+		//----------------------------------------------------------------------
894
+		public static function rsBlockNum($spec)     { return $spec[0] + $spec[3]; }
895
+		public static function rsBlockNum1($spec)    { return $spec[0]; }
896
+		public static function rsDataCodes1($spec)   { return $spec[1]; }
897
+		public static function rsEccCodes1($spec)    { return $spec[2]; }
898
+		public static function rsBlockNum2($spec)    { return $spec[3]; }
899
+		public static function rsDataCodes2($spec)   { return $spec[4]; }
900
+		public static function rsEccCodes2($spec)    { return $spec[2]; }
901
+		public static function rsDataLength($spec)   { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]);    }
902
+		public static function rsEccLength($spec)    { return ($spec[0] + $spec[3]) * $spec[2]; }
903
+        
904
+	}
905 905
 
906 906
 
907 907
 
@@ -933,77 +933,77 @@  discard block
 block discarded – undo
933 933
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
934 934
  */
935 935
  
936
-    define('QR_IMAGE', true);
936
+	define('QR_IMAGE', true);
937 937
 
938
-    class QRimage {
938
+	class QRimage {
939 939
     
940
-        //----------------------------------------------------------------------
941
-        public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) 
942
-        {
943
-            $image = self::image($frame, $pixelPerPoint, $outerFrame);
944
-            
945
-            if ($filename === false) {
946
-                Header("Content-type: image/png");
947
-                ImagePng($image);
948
-            } else {
949
-                if($saveandprint===TRUE){
950
-                    ImagePng($image, $filename);
951
-                    header("Content-type: image/png");
952
-                    ImagePng($image);
953
-                }else{
954
-                    ImagePng($image, $filename);
955
-                }
956
-            }
957
-            
958
-            ImageDestroy($image);
959
-        }
940
+		//----------------------------------------------------------------------
941
+		public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) 
942
+		{
943
+			$image = self::image($frame, $pixelPerPoint, $outerFrame);
944
+            
945
+			if ($filename === false) {
946
+				Header("Content-type: image/png");
947
+				ImagePng($image);
948
+			} else {
949
+				if($saveandprint===TRUE){
950
+					ImagePng($image, $filename);
951
+					header("Content-type: image/png");
952
+					ImagePng($image);
953
+				}else{
954
+					ImagePng($image, $filename);
955
+				}
956
+			}
957
+            
958
+			ImageDestroy($image);
959
+		}
960 960
     
961
-        //----------------------------------------------------------------------
962
-        public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85) 
963
-        {
964
-            $image = self::image($frame, $pixelPerPoint, $outerFrame);
965
-            
966
-            if ($filename === false) {
967
-                Header("Content-type: image/jpeg");
968
-                ImageJpeg($image, null, $q);
969
-            } else {
970
-                ImageJpeg($image, $filename, $q);            
971
-            }
972
-            
973
-            ImageDestroy($image);
974
-        }
961
+		//----------------------------------------------------------------------
962
+		public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85) 
963
+		{
964
+			$image = self::image($frame, $pixelPerPoint, $outerFrame);
965
+            
966
+			if ($filename === false) {
967
+				Header("Content-type: image/jpeg");
968
+				ImageJpeg($image, null, $q);
969
+			} else {
970
+				ImageJpeg($image, $filename, $q);            
971
+			}
972
+            
973
+			ImageDestroy($image);
974
+		}
975 975
     
976
-        //----------------------------------------------------------------------
977
-        private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4) 
978
-        {
979
-            $h = count($frame);
980
-            $w = strlen($frame[0]);
976
+		//----------------------------------------------------------------------
977
+		private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4) 
978
+		{
979
+			$h = count($frame);
980
+			$w = strlen($frame[0]);
981 981
             
982
-            $imgW = $w + 2*$outerFrame;
983
-            $imgH = $h + 2*$outerFrame;
982
+			$imgW = $w + 2*$outerFrame;
983
+			$imgH = $h + 2*$outerFrame;
984 984
             
985
-            $base_image =ImageCreate($imgW, $imgH);
985
+			$base_image =ImageCreate($imgW, $imgH);
986 986
             
987
-            $col[0] = ImageColorAllocate($base_image,255,255,255);
988
-            $col[1] = ImageColorAllocate($base_image,0,0,0);
987
+			$col[0] = ImageColorAllocate($base_image,255,255,255);
988
+			$col[1] = ImageColorAllocate($base_image,0,0,0);
989 989
 
990
-            imagefill($base_image, 0, 0, $col[0]);
990
+			imagefill($base_image, 0, 0, $col[0]);
991 991
 
992
-            for($y=0; $y<$h; $y++) {
993
-                for($x=0; $x<$w; $x++) {
994
-                    if ($frame[$y][$x] == '1') {
995
-                        ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); 
996
-                    }
997
-                }
998
-            }
992
+			for($y=0; $y<$h; $y++) {
993
+				for($x=0; $x<$w; $x++) {
994
+					if ($frame[$y][$x] == '1') {
995
+						ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); 
996
+					}
997
+				}
998
+			}
999 999
             
1000
-            $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
1001
-            ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
1002
-            ImageDestroy($base_image);
1000
+			$target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
1001
+			ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
1002
+			ImageDestroy($base_image);
1003 1003
             
1004
-            return $target_image;
1005
-        }
1006
-    }
1004
+			return $target_image;
1005
+		}
1006
+	}
1007 1007
 
1008 1008
 
1009 1009
 
@@ -1038,705 +1038,705 @@  discard block
 block discarded – undo
1038 1038
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1039 1039
  */
1040 1040
  
1041
-    define('STRUCTURE_HEADER_BITS',  20);
1042
-    define('MAX_STRUCTURED_SYMBOLS', 16);
1041
+	define('STRUCTURE_HEADER_BITS',  20);
1042
+	define('MAX_STRUCTURED_SYMBOLS', 16);
1043 1043
 
1044
-    class QRinputItem {
1044
+	class QRinputItem {
1045 1045
     
1046
-        public $mode;
1047
-        public $size;
1048
-        public $data;
1049
-        public $bstream;
1050
-
1051
-        public function __construct($mode, $size, $data, $bstream = null) 
1052
-        {
1053
-            $setData = array_slice($data, 0, $size);
1054
-            
1055
-            if (count($setData) < $size) {
1056
-                $setData = array_merge($setData, array_fill(0,$size-count($setData),0));
1057
-            }
1058
-        
1059
-            if(!QRinput::check($mode, $size, $setData)) {
1060
-                throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData));
1061
-                return null;
1062
-            }
1063
-            
1064
-            $this->mode = $mode;
1065
-            $this->size = $size;
1066
-            $this->data = $setData;
1067
-            $this->bstream = $bstream;
1068
-        }
1069
-        
1070
-        //----------------------------------------------------------------------
1071
-        public function encodeModeNum($version)
1072
-        {
1073
-            try {
1074
-            
1075
-                $words = (int)($this->size / 3);
1076
-                $bs = new QRbitstream();
1046
+		public $mode;
1047
+		public $size;
1048
+		public $data;
1049
+		public $bstream;
1050
+
1051
+		public function __construct($mode, $size, $data, $bstream = null) 
1052
+		{
1053
+			$setData = array_slice($data, 0, $size);
1054
+            
1055
+			if (count($setData) < $size) {
1056
+				$setData = array_merge($setData, array_fill(0,$size-count($setData),0));
1057
+			}
1058
+        
1059
+			if(!QRinput::check($mode, $size, $setData)) {
1060
+				throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData));
1061
+				return null;
1062
+			}
1063
+            
1064
+			$this->mode = $mode;
1065
+			$this->size = $size;
1066
+			$this->data = $setData;
1067
+			$this->bstream = $bstream;
1068
+		}
1069
+        
1070
+		//----------------------------------------------------------------------
1071
+		public function encodeModeNum($version)
1072
+		{
1073
+			try {
1074
+            
1075
+				$words = (int)($this->size / 3);
1076
+				$bs = new QRbitstream();
1077 1077
                 
1078
-                $val = 0x1;
1079
-                $bs->appendNum(4, $val);
1080
-                $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size);
1081
-
1082
-                for($i=0; $i<$words; $i++) {
1083
-                    $val  = (ord($this->data[$i*3  ]) - ord('0')) * 100;
1084
-                    $val += (ord($this->data[$i*3+1]) - ord('0')) * 10;
1085
-                    $val += (ord($this->data[$i*3+2]) - ord('0'));
1086
-                    $bs->appendNum(10, $val);
1087
-                }
1088
-
1089
-                if($this->size - $words * 3 == 1) {
1090
-                    $val = ord($this->data[$words*3]) - ord('0');
1091
-                    $bs->appendNum(4, $val);
1092
-                } else if($this->size - $words * 3 == 2) {
1093
-                    $val  = (ord($this->data[$words*3  ]) - ord('0')) * 10;
1094
-                    $val += (ord($this->data[$words*3+1]) - ord('0'));
1095
-                    $bs->appendNum(7, $val);
1096
-                }
1097
-
1098
-                $this->bstream = $bs;
1099
-                return 0;
1078
+				$val = 0x1;
1079
+				$bs->appendNum(4, $val);
1080
+				$bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size);
1081
+
1082
+				for($i=0; $i<$words; $i++) {
1083
+					$val  = (ord($this->data[$i*3  ]) - ord('0')) * 100;
1084
+					$val += (ord($this->data[$i*3+1]) - ord('0')) * 10;
1085
+					$val += (ord($this->data[$i*3+2]) - ord('0'));
1086
+					$bs->appendNum(10, $val);
1087
+				}
1088
+
1089
+				if($this->size - $words * 3 == 1) {
1090
+					$val = ord($this->data[$words*3]) - ord('0');
1091
+					$bs->appendNum(4, $val);
1092
+				} else if($this->size - $words * 3 == 2) {
1093
+					$val  = (ord($this->data[$words*3  ]) - ord('0')) * 10;
1094
+					$val += (ord($this->data[$words*3+1]) - ord('0'));
1095
+					$bs->appendNum(7, $val);
1096
+				}
1097
+
1098
+				$this->bstream = $bs;
1099
+				return 0;
1100 1100
                 
1101
-            } catch (Exception $e) {
1102
-                return -1;
1103
-            }
1104
-        }
1105
-        
1106
-        //----------------------------------------------------------------------
1107
-        public function encodeModeAn($version)
1108
-        {
1109
-            try {
1110
-                $words = (int)($this->size / 2);
1111
-                $bs = new QRbitstream();
1101
+			} catch (Exception $e) {
1102
+				return -1;
1103
+			}
1104
+		}
1105
+        
1106
+		//----------------------------------------------------------------------
1107
+		public function encodeModeAn($version)
1108
+		{
1109
+			try {
1110
+				$words = (int)($this->size / 2);
1111
+				$bs = new QRbitstream();
1112 1112
                 
1113
-                $bs->appendNum(4, 0x02);
1114
-                $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size);
1113
+				$bs->appendNum(4, 0x02);
1114
+				$bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size);
1115 1115
 
1116
-                for($i=0; $i<$words; $i++) {
1117
-                    $val  = (int)QRinput::lookAnTable(ord($this->data[$i*2  ])) * 45;
1118
-                    $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1]));
1116
+				for($i=0; $i<$words; $i++) {
1117
+					$val  = (int)QRinput::lookAnTable(ord($this->data[$i*2  ])) * 45;
1118
+					$val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1]));
1119 1119
 
1120
-                    $bs->appendNum(11, $val);
1121
-                }
1120
+					$bs->appendNum(11, $val);
1121
+				}
1122 1122
 
1123
-                if($this->size & 1) {
1124
-                    $val = QRinput::lookAnTable(ord($this->data[$words * 2]));
1125
-                    $bs->appendNum(6, $val);
1126
-                }
1123
+				if($this->size & 1) {
1124
+					$val = QRinput::lookAnTable(ord($this->data[$words * 2]));
1125
+					$bs->appendNum(6, $val);
1126
+				}
1127 1127
         
1128
-                $this->bstream = $bs;
1129
-                return 0;
1128
+				$this->bstream = $bs;
1129
+				return 0;
1130 1130
             
1131
-            } catch (Exception $e) {
1132
-                return -1;
1133
-            }
1134
-        }
1131
+			} catch (Exception $e) {
1132
+				return -1;
1133
+			}
1134
+		}
1135 1135
         
1136
-        //----------------------------------------------------------------------
1137
-        public function encodeMode8($version)
1138
-        {
1139
-            try {
1140
-                $bs = new QRbitstream();
1136
+		//----------------------------------------------------------------------
1137
+		public function encodeMode8($version)
1138
+		{
1139
+			try {
1140
+				$bs = new QRbitstream();
1141 1141
 
1142
-                $bs->appendNum(4, 0x4);
1143
-                $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size);
1142
+				$bs->appendNum(4, 0x4);
1143
+				$bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size);
1144 1144
 
1145
-                for($i=0; $i<$this->size; $i++) {
1146
-                    $bs->appendNum(8, ord($this->data[$i]));
1147
-                }
1145
+				for($i=0; $i<$this->size; $i++) {
1146
+					$bs->appendNum(8, ord($this->data[$i]));
1147
+				}
1148 1148
 
1149
-                $this->bstream = $bs;
1150
-                return 0;
1149
+				$this->bstream = $bs;
1150
+				return 0;
1151 1151
             
1152
-            } catch (Exception $e) {
1153
-                return -1;
1154
-            }
1155
-        }
1152
+			} catch (Exception $e) {
1153
+				return -1;
1154
+			}
1155
+		}
1156 1156
         
1157
-        //----------------------------------------------------------------------
1158
-        public function encodeModeKanji($version)
1159
-        {
1160
-            try {
1157
+		//----------------------------------------------------------------------
1158
+		public function encodeModeKanji($version)
1159
+		{
1160
+			try {
1161 1161
 
1162
-                $bs = new QRbitrtream();
1162
+				$bs = new QRbitrtream();
1163 1163
                 
1164
-                $bs->appendNum(4, 0x8);
1165
-                $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2));
1166
-
1167
-                for($i=0; $i<$this->size; $i+=2) {
1168
-                    $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]);
1169
-                    if($val <= 0x9ffc) {
1170
-                        $val -= 0x8140;
1171
-                    } else {
1172
-                        $val -= 0xc140;
1173
-                    }
1164
+				$bs->appendNum(4, 0x8);
1165
+				$bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2));
1166
+
1167
+				for($i=0; $i<$this->size; $i+=2) {
1168
+					$val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]);
1169
+					if($val <= 0x9ffc) {
1170
+						$val -= 0x8140;
1171
+					} else {
1172
+						$val -= 0xc140;
1173
+					}
1174 1174
                     
1175
-                    $h = ($val >> 8) * 0xc0;
1176
-                    $val = ($val & 0xff) + $h;
1175
+					$h = ($val >> 8) * 0xc0;
1176
+					$val = ($val & 0xff) + $h;
1177 1177
 
1178
-                    $bs->appendNum(13, $val);
1179
-                }
1178
+					$bs->appendNum(13, $val);
1179
+				}
1180 1180
 
1181
-                $this->bstream = $bs;
1182
-                return 0;
1181
+				$this->bstream = $bs;
1182
+				return 0;
1183 1183
             
1184
-            } catch (Exception $e) {
1185
-                return -1;
1186
-            }
1187
-        }
1184
+			} catch (Exception $e) {
1185
+				return -1;
1186
+			}
1187
+		}
1188 1188
 
1189
-        //----------------------------------------------------------------------
1190
-        public function encodeModeStructure()
1191
-        {
1192
-            try {
1193
-                $bs =  new QRbitstream();
1189
+		//----------------------------------------------------------------------
1190
+		public function encodeModeStructure()
1191
+		{
1192
+			try {
1193
+				$bs =  new QRbitstream();
1194 1194
                 
1195
-                $bs->appendNum(4, 0x03);
1196
-                $bs->appendNum(4, ord($this->data[1]) - 1);
1197
-                $bs->appendNum(4, ord($this->data[0]) - 1);
1198
-                $bs->appendNum(8, ord($this->data[2]));
1199
-
1200
-                $this->bstream = $bs;
1201
-                return 0;
1202
-            
1203
-            } catch (Exception $e) {
1204
-                return -1;
1205
-            }
1206
-        }
1207
-        
1208
-        //----------------------------------------------------------------------
1209
-        public function estimateBitStreamSizeOfEntry($version)
1210
-        {
1211
-            $bits = 0;
1212
-
1213
-            if($version == 0) 
1214
-                $version = 1;
1215
-
1216
-            switch($this->mode) {
1217
-                case QR_MODE_NUM:        $bits = QRinput::estimateBitsModeNum($this->size);    break;
1218
-                case QR_MODE_AN:        $bits = QRinput::estimateBitsModeAn($this->size);    break;
1219
-                case QR_MODE_8:            $bits = QRinput::estimateBitsMode8($this->size);    break;
1220
-                case QR_MODE_KANJI:        $bits = QRinput::estimateBitsModeKanji($this->size);break;
1221
-                case QR_MODE_STRUCTURE:    return STRUCTURE_HEADER_BITS;            
1222
-                default:
1223
-                    return 0;
1224
-            }
1225
-
1226
-            $l = QRspec::lengthIndicator($this->mode, $version);
1227
-            $m = 1 << $l;
1228
-            $num = (int)(($this->size + $m - 1) / $m);
1229
-
1230
-            $bits += $num * (4 + $l);
1231
-
1232
-            return $bits;
1233
-        }
1234
-        
1235
-        //----------------------------------------------------------------------
1236
-        public function encodeBitStream($version)
1237
-        {
1238
-            try {
1239
-            
1240
-                unset($this->bstream);
1241
-                $words = QRspec::maximumWords($this->mode, $version);
1195
+				$bs->appendNum(4, 0x03);
1196
+				$bs->appendNum(4, ord($this->data[1]) - 1);
1197
+				$bs->appendNum(4, ord($this->data[0]) - 1);
1198
+				$bs->appendNum(8, ord($this->data[2]));
1199
+
1200
+				$this->bstream = $bs;
1201
+				return 0;
1202
+            
1203
+			} catch (Exception $e) {
1204
+				return -1;
1205
+			}
1206
+		}
1207
+        
1208
+		//----------------------------------------------------------------------
1209
+		public function estimateBitStreamSizeOfEntry($version)
1210
+		{
1211
+			$bits = 0;
1212
+
1213
+			if($version == 0) 
1214
+				$version = 1;
1215
+
1216
+			switch($this->mode) {
1217
+				case QR_MODE_NUM:        $bits = QRinput::estimateBitsModeNum($this->size);    break;
1218
+				case QR_MODE_AN:        $bits = QRinput::estimateBitsModeAn($this->size);    break;
1219
+				case QR_MODE_8:            $bits = QRinput::estimateBitsMode8($this->size);    break;
1220
+				case QR_MODE_KANJI:        $bits = QRinput::estimateBitsModeKanji($this->size);break;
1221
+				case QR_MODE_STRUCTURE:    return STRUCTURE_HEADER_BITS;            
1222
+				default:
1223
+					return 0;
1224
+			}
1225
+
1226
+			$l = QRspec::lengthIndicator($this->mode, $version);
1227
+			$m = 1 << $l;
1228
+			$num = (int)(($this->size + $m - 1) / $m);
1229
+
1230
+			$bits += $num * (4 + $l);
1231
+
1232
+			return $bits;
1233
+		}
1234
+        
1235
+		//----------------------------------------------------------------------
1236
+		public function encodeBitStream($version)
1237
+		{
1238
+			try {
1239
+            
1240
+				unset($this->bstream);
1241
+				$words = QRspec::maximumWords($this->mode, $version);
1242 1242
                 
1243
-                if($this->size > $words) {
1243
+				if($this->size > $words) {
1244 1244
                 
1245
-                    $st1 = new QRinputItem($this->mode, $words, $this->data);
1246
-                    $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words));
1245
+					$st1 = new QRinputItem($this->mode, $words, $this->data);
1246
+					$st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words));
1247 1247
 
1248
-                    $st1->encodeBitStream($version);
1249
-                    $st2->encodeBitStream($version);
1248
+					$st1->encodeBitStream($version);
1249
+					$st2->encodeBitStream($version);
1250 1250
                     
1251
-                    $this->bstream = new QRbitstream();
1252
-                    $this->bstream->append($st1->bstream);
1253
-                    $this->bstream->append($st2->bstream);
1251
+					$this->bstream = new QRbitstream();
1252
+					$this->bstream->append($st1->bstream);
1253
+					$this->bstream->append($st2->bstream);
1254 1254
                     
1255
-                    unset($st1);
1256
-                    unset($st2);
1255
+					unset($st1);
1256
+					unset($st2);
1257 1257
                     
1258
-                } else {
1258
+				} else {
1259 1259
                     
1260
-                    $ret = 0;
1260
+					$ret = 0;
1261 1261
                     
1262
-                    switch($this->mode) {
1263
-                        case QR_MODE_NUM:        $ret = $this->encodeModeNum($version);    break;
1264
-                        case QR_MODE_AN:        $ret = $this->encodeModeAn($version);    break;
1265
-                        case QR_MODE_8:            $ret = $this->encodeMode8($version);    break;
1266
-                        case QR_MODE_KANJI:        $ret = $this->encodeModeKanji($version);break;
1267
-                        case QR_MODE_STRUCTURE:    $ret = $this->encodeModeStructure();    break;
1262
+					switch($this->mode) {
1263
+						case QR_MODE_NUM:        $ret = $this->encodeModeNum($version);    break;
1264
+						case QR_MODE_AN:        $ret = $this->encodeModeAn($version);    break;
1265
+						case QR_MODE_8:            $ret = $this->encodeMode8($version);    break;
1266
+						case QR_MODE_KANJI:        $ret = $this->encodeModeKanji($version);break;
1267
+						case QR_MODE_STRUCTURE:    $ret = $this->encodeModeStructure();    break;
1268 1268
                         
1269
-                        default:
1270
-                            break;
1271
-                    }
1269
+						default:
1270
+							break;
1271
+					}
1272 1272
                     
1273
-                    if($ret < 0)
1274
-                        return -1;
1275
-                }
1273
+					if($ret < 0)
1274
+						return -1;
1275
+				}
1276 1276
 
1277
-                return $this->bstream->size();
1277
+				return $this->bstream->size();
1278 1278
             
1279
-            } catch (Exception $e) {
1280
-                return -1;
1281
-            }
1282
-        }
1283
-    };
1279
+			} catch (Exception $e) {
1280
+				return -1;
1281
+			}
1282
+		}
1283
+	};
1284 1284
     
1285
-    //##########################################################################
1286
-
1287
-    class QRinput {
1288
-
1289
-        public $items;
1290
-        
1291
-        private $version;
1292
-        private $level;
1293
-        
1294
-        //----------------------------------------------------------------------
1295
-        public function __construct($version = 0, $level = QR_ECLEVEL_L)
1296
-        {
1297
-            if ($version < 0 || $version > QRSPEC_VERSION_MAX || $level > QR_ECLEVEL_H) {
1298
-                throw new Exception('Invalid version no');
1299
-                return NULL;
1300
-            }
1301
-            
1302
-            $this->version = $version;
1303
-            $this->level = $level;
1304
-        }
1305
-        
1306
-        //----------------------------------------------------------------------
1307
-        public function getVersion()
1308
-        {
1309
-            return $this->version;
1310
-        }
1311
-        
1312
-        //----------------------------------------------------------------------
1313
-        public function setVersion($version)
1314
-        {
1315
-            if($version < 0 || $version > QRSPEC_VERSION_MAX) {
1316
-                throw new Exception('Invalid version no');
1317
-                return -1;
1318
-            }
1319
-
1320
-            $this->version = $version;
1321
-
1322
-            return 0;
1323
-        }
1324
-        
1325
-        //----------------------------------------------------------------------
1326
-        public function getErrorCorrectionLevel()
1327
-        {
1328
-            return $this->level;
1329
-        }
1330
-
1331
-        //----------------------------------------------------------------------
1332
-        public function setErrorCorrectionLevel($level)
1333
-        {
1334
-            if($level > QR_ECLEVEL_H) {
1335
-                throw new Exception('Invalid ECLEVEL');
1336
-                return -1;
1337
-            }
1338
-
1339
-            $this->level = $level;
1340
-
1341
-            return 0;
1342
-        }
1343
-        
1344
-        //----------------------------------------------------------------------
1345
-        public function appendEntry(QRinputItem $entry)
1346
-        {
1347
-            $this->items[] = $entry;
1348
-        }
1349
-        
1350
-        //----------------------------------------------------------------------
1351
-        public function append($mode, $size, $data)
1352
-        {
1353
-            try {
1354
-                $entry = new QRinputItem($mode, $size, $data);
1355
-                $this->items[] = $entry;
1356
-                return 0;
1357
-            } catch (Exception $e) {
1358
-                return -1;
1359
-            }
1360
-        }
1361
-        
1362
-        //----------------------------------------------------------------------
1363
-        
1364
-        public function insertStructuredAppendHeader($size, $index, $parity)
1365
-        {
1366
-            if( $size > MAX_STRUCTURED_SYMBOLS ) {
1367
-                throw new Exception('insertStructuredAppendHeader wrong size');
1368
-            }
1369
-            
1370
-            if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) {
1371
-                throw new Exception('insertStructuredAppendHeader wrong index');
1372
-            }
1373
-
1374
-            $buf = array($size, $index, $parity);
1375
-            
1376
-            try {
1377
-                $entry = new QRinputItem(QR_MODE_STRUCTURE, 3, buf);
1378
-                array_unshift($this->items, $entry);
1379
-                return 0;
1380
-            } catch (Exception $e) {
1381
-                return -1;
1382
-            }
1383
-        }
1384
-
1385
-        //----------------------------------------------------------------------
1386
-        public function calcParity()
1387
-        {
1388
-            $parity = 0;
1389
-            
1390
-            foreach($this->items as $item) {
1391
-                if($item->mode != QR_MODE_STRUCTURE) {
1392
-                    for($i=$item->size-1; $i>=0; $i--) {
1393
-                        $parity ^= $item->data[$i];
1394
-                    }
1395
-                }
1396
-            }
1397
-
1398
-            return $parity;
1399
-        }
1400
-        
1401
-        //----------------------------------------------------------------------
1402
-        public static function checkModeNum($size, $data)
1403
-        {
1404
-            for($i=0; $i<$size; $i++) {
1405
-                if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){
1406
-                    return false;
1407
-                }
1408
-            }
1409
-
1410
-            return true;
1411
-        }
1412
-
1413
-        //----------------------------------------------------------------------
1414
-        public static function estimateBitsModeNum($size)
1415
-        {
1416
-            $w = (int)$size / 3;
1417
-            $bits = $w * 10;
1418
-            
1419
-            switch($size - $w * 3) {
1420
-                case 1:
1421
-                    $bits += 4;
1422
-                    break;
1423
-                case 2:
1424
-                    $bits += 7;
1425
-                    break;
1426
-                default:
1427
-                    break;
1428
-            }
1429
-
1430
-            return $bits;
1431
-        }
1432
-        
1433
-        //----------------------------------------------------------------------
1434
-        public static $anTable = array(
1435
-            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1436
-            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1437
-            36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43,
1438
-             0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 44, -1, -1, -1, -1, -1,
1439
-            -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1440
-            25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
1441
-            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1442
-            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
1443
-        );
1444
-        
1445
-        //----------------------------------------------------------------------
1446
-        public static function lookAnTable($c)
1447
-        {
1448
-            return (($c > 127)?-1:self::$anTable[$c]);
1449
-        }
1450
-        
1451
-        //----------------------------------------------------------------------
1452
-        public static function checkModeAn($size, $data)
1453
-        {
1454
-            for($i=0; $i<$size; $i++) {
1455
-                if (self::lookAnTable(ord($data[$i])) == -1) {
1456
-                    return false;
1457
-                }
1458
-            }
1459
-
1460
-            return true;
1461
-        }
1462
-        
1463
-        //----------------------------------------------------------------------
1464
-        public static function estimateBitsModeAn($size)
1465
-        {
1466
-            $w = (int)($size / 2);
1467
-            $bits = $w * 11;
1468
-            
1469
-            if($size & 1) {
1470
-                $bits += 6;
1471
-            }
1472
-
1473
-            return $bits;
1474
-        }
1285
+	//##########################################################################
1286
+
1287
+	class QRinput {
1288
+
1289
+		public $items;
1290
+        
1291
+		private $version;
1292
+		private $level;
1293
+        
1294
+		//----------------------------------------------------------------------
1295
+		public function __construct($version = 0, $level = QR_ECLEVEL_L)
1296
+		{
1297
+			if ($version < 0 || $version > QRSPEC_VERSION_MAX || $level > QR_ECLEVEL_H) {
1298
+				throw new Exception('Invalid version no');
1299
+				return NULL;
1300
+			}
1301
+            
1302
+			$this->version = $version;
1303
+			$this->level = $level;
1304
+		}
1305
+        
1306
+		//----------------------------------------------------------------------
1307
+		public function getVersion()
1308
+		{
1309
+			return $this->version;
1310
+		}
1311
+        
1312
+		//----------------------------------------------------------------------
1313
+		public function setVersion($version)
1314
+		{
1315
+			if($version < 0 || $version > QRSPEC_VERSION_MAX) {
1316
+				throw new Exception('Invalid version no');
1317
+				return -1;
1318
+			}
1319
+
1320
+			$this->version = $version;
1321
+
1322
+			return 0;
1323
+		}
1324
+        
1325
+		//----------------------------------------------------------------------
1326
+		public function getErrorCorrectionLevel()
1327
+		{
1328
+			return $this->level;
1329
+		}
1330
+
1331
+		//----------------------------------------------------------------------
1332
+		public function setErrorCorrectionLevel($level)
1333
+		{
1334
+			if($level > QR_ECLEVEL_H) {
1335
+				throw new Exception('Invalid ECLEVEL');
1336
+				return -1;
1337
+			}
1338
+
1339
+			$this->level = $level;
1340
+
1341
+			return 0;
1342
+		}
1343
+        
1344
+		//----------------------------------------------------------------------
1345
+		public function appendEntry(QRinputItem $entry)
1346
+		{
1347
+			$this->items[] = $entry;
1348
+		}
1349
+        
1350
+		//----------------------------------------------------------------------
1351
+		public function append($mode, $size, $data)
1352
+		{
1353
+			try {
1354
+				$entry = new QRinputItem($mode, $size, $data);
1355
+				$this->items[] = $entry;
1356
+				return 0;
1357
+			} catch (Exception $e) {
1358
+				return -1;
1359
+			}
1360
+		}
1361
+        
1362
+		//----------------------------------------------------------------------
1363
+        
1364
+		public function insertStructuredAppendHeader($size, $index, $parity)
1365
+		{
1366
+			if( $size > MAX_STRUCTURED_SYMBOLS ) {
1367
+				throw new Exception('insertStructuredAppendHeader wrong size');
1368
+			}
1369
+            
1370
+			if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) {
1371
+				throw new Exception('insertStructuredAppendHeader wrong index');
1372
+			}
1373
+
1374
+			$buf = array($size, $index, $parity);
1375
+            
1376
+			try {
1377
+				$entry = new QRinputItem(QR_MODE_STRUCTURE, 3, buf);
1378
+				array_unshift($this->items, $entry);
1379
+				return 0;
1380
+			} catch (Exception $e) {
1381
+				return -1;
1382
+			}
1383
+		}
1384
+
1385
+		//----------------------------------------------------------------------
1386
+		public function calcParity()
1387
+		{
1388
+			$parity = 0;
1389
+            
1390
+			foreach($this->items as $item) {
1391
+				if($item->mode != QR_MODE_STRUCTURE) {
1392
+					for($i=$item->size-1; $i>=0; $i--) {
1393
+						$parity ^= $item->data[$i];
1394
+					}
1395
+				}
1396
+			}
1397
+
1398
+			return $parity;
1399
+		}
1400
+        
1401
+		//----------------------------------------------------------------------
1402
+		public static function checkModeNum($size, $data)
1403
+		{
1404
+			for($i=0; $i<$size; $i++) {
1405
+				if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){
1406
+					return false;
1407
+				}
1408
+			}
1409
+
1410
+			return true;
1411
+		}
1412
+
1413
+		//----------------------------------------------------------------------
1414
+		public static function estimateBitsModeNum($size)
1415
+		{
1416
+			$w = (int)$size / 3;
1417
+			$bits = $w * 10;
1418
+            
1419
+			switch($size - $w * 3) {
1420
+				case 1:
1421
+					$bits += 4;
1422
+					break;
1423
+				case 2:
1424
+					$bits += 7;
1425
+					break;
1426
+				default:
1427
+					break;
1428
+			}
1429
+
1430
+			return $bits;
1431
+		}
1432
+        
1433
+		//----------------------------------------------------------------------
1434
+		public static $anTable = array(
1435
+			-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1436
+			-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1437
+			36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43,
1438
+			 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 44, -1, -1, -1, -1, -1,
1439
+			-1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1440
+			25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
1441
+			-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1442
+			-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
1443
+		);
1444
+        
1445
+		//----------------------------------------------------------------------
1446
+		public static function lookAnTable($c)
1447
+		{
1448
+			return (($c > 127)?-1:self::$anTable[$c]);
1449
+		}
1450
+        
1451
+		//----------------------------------------------------------------------
1452
+		public static function checkModeAn($size, $data)
1453
+		{
1454
+			for($i=0; $i<$size; $i++) {
1455
+				if (self::lookAnTable(ord($data[$i])) == -1) {
1456
+					return false;
1457
+				}
1458
+			}
1459
+
1460
+			return true;
1461
+		}
1462
+        
1463
+		//----------------------------------------------------------------------
1464
+		public static function estimateBitsModeAn($size)
1465
+		{
1466
+			$w = (int)($size / 2);
1467
+			$bits = $w * 11;
1468
+            
1469
+			if($size & 1) {
1470
+				$bits += 6;
1471
+			}
1472
+
1473
+			return $bits;
1474
+		}
1475 1475
     
1476
-        //----------------------------------------------------------------------
1477
-        public static function estimateBitsMode8($size)
1478
-        {
1479
-            return $size * 8;
1480
-        }
1481
-        
1482
-        //----------------------------------------------------------------------
1483
-        public function estimateBitsModeKanji($size)
1484
-        {
1485
-            return (int)(($size / 2) * 13);
1486
-        }
1487
-        
1488
-        //----------------------------------------------------------------------
1489
-        public static function checkModeKanji($size, $data)
1490
-        {
1491
-            if($size & 1)
1492
-                return false;
1493
-
1494
-            for($i=0; $i<$size; $i+=2) {
1495
-                $val = (ord($data[$i]) << 8) | ord($data[$i+1]);
1496
-                if( $val < 0x8140 
1497
-                || ($val > 0x9ffc && $val < 0xe040) 
1498
-                || $val > 0xebbf) {
1499
-                    return false;
1500
-                }
1501
-            }
1502
-
1503
-            return true;
1504
-        }
1505
-
1506
-        /***********************************************************************
1476
+		//----------------------------------------------------------------------
1477
+		public static function estimateBitsMode8($size)
1478
+		{
1479
+			return $size * 8;
1480
+		}
1481
+        
1482
+		//----------------------------------------------------------------------
1483
+		public function estimateBitsModeKanji($size)
1484
+		{
1485
+			return (int)(($size / 2) * 13);
1486
+		}
1487
+        
1488
+		//----------------------------------------------------------------------
1489
+		public static function checkModeKanji($size, $data)
1490
+		{
1491
+			if($size & 1)
1492
+				return false;
1493
+
1494
+			for($i=0; $i<$size; $i+=2) {
1495
+				$val = (ord($data[$i]) << 8) | ord($data[$i+1]);
1496
+				if( $val < 0x8140 
1497
+				|| ($val > 0x9ffc && $val < 0xe040) 
1498
+				|| $val > 0xebbf) {
1499
+					return false;
1500
+				}
1501
+			}
1502
+
1503
+			return true;
1504
+		}
1505
+
1506
+		/***********************************************************************
1507 1507
          * Validation
1508 1508
          **********************************************************************/
1509 1509
 
1510
-        public static function check($mode, $size, $data)
1511
-        {
1512
-            if($size <= 0) 
1513
-                return false;
1514
-
1515
-            switch($mode) {
1516
-                case QR_MODE_NUM:       return self::checkModeNum($size, $data);   break;
1517
-                case QR_MODE_AN:        return self::checkModeAn($size, $data);    break;
1518
-                case QR_MODE_KANJI:     return self::checkModeKanji($size, $data); break;
1519
-                case QR_MODE_8:         return true; break;
1520
-                case QR_MODE_STRUCTURE: return true; break;
1510
+		public static function check($mode, $size, $data)
1511
+		{
1512
+			if($size <= 0) 
1513
+				return false;
1514
+
1515
+			switch($mode) {
1516
+				case QR_MODE_NUM:       return self::checkModeNum($size, $data);   break;
1517
+				case QR_MODE_AN:        return self::checkModeAn($size, $data);    break;
1518
+				case QR_MODE_KANJI:     return self::checkModeKanji($size, $data); break;
1519
+				case QR_MODE_8:         return true; break;
1520
+				case QR_MODE_STRUCTURE: return true; break;
1521 1521
                 
1522
-                default:
1523
-                    break;
1524
-            }
1525
-
1526
-            return false;
1527
-        }
1528
-        
1529
-        
1530
-        //----------------------------------------------------------------------
1531
-        public function estimateBitStreamSize($version)
1532
-        {
1533
-            $bits = 0;
1534
-
1535
-            foreach($this->items as $item) {
1536
-                $bits += $item->estimateBitStreamSizeOfEntry($version);
1537
-            }
1538
-
1539
-            return $bits;
1540
-        }
1541
-        
1542
-        //----------------------------------------------------------------------
1543
-        public function estimateVersion()
1544
-        {
1545
-            $version = 0;
1546
-            $prev = 0;
1547
-            do {
1548
-                $prev = $version;
1549
-                $bits = $this->estimateBitStreamSize($prev);
1550
-                $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
1551
-                if ($version < 0) {
1552
-                    return -1;
1553
-                }
1554
-            } while ($version > $prev);
1555
-
1556
-            return $version;
1557
-        }
1558
-        
1559
-        //----------------------------------------------------------------------
1560
-        public static function lengthOfCode($mode, $version, $bits)
1561
-        {
1562
-            $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version);
1563
-            switch($mode) {
1564
-                case QR_MODE_NUM:
1565
-                    $chunks = (int)($payload / 10);
1566
-                    $remain = $payload - $chunks * 10;
1567
-                    $size = $chunks * 3;
1568
-                    if($remain >= 7) {
1569
-                        $size += 2;
1570
-                    } else if($remain >= 4) {
1571
-                        $size += 1;
1572
-                    }
1573
-                    break;
1574
-                case QR_MODE_AN:
1575
-                    $chunks = (int)($payload / 11);
1576
-                    $remain = $payload - $chunks * 11;
1577
-                    $size = $chunks * 2;
1578
-                    if($remain >= 6) 
1579
-                        $size++;
1580
-                    break;
1581
-                case QR_MODE_8:
1582
-                    $size = (int)($payload / 8);
1583
-                    break;
1584
-                case QR_MODE_KANJI:
1585
-                    $size = (int)(($payload / 13) * 2);
1586
-                    break;
1587
-                case QR_MODE_STRUCTURE:
1588
-                    $size = (int)($payload / 8);
1589
-                    break;
1590
-                default:
1591
-                    $size = 0;
1592
-                    break;
1593
-            }
1594
-            
1595
-            $maxsize = QRspec::maximumWords($mode, $version);
1596
-            if($size < 0) $size = 0;
1597
-            if($size > $maxsize) $size = $maxsize;
1598
-
1599
-            return $size;
1600
-        }
1601
-        
1602
-        //----------------------------------------------------------------------
1603
-        public function createBitStream()
1604
-        {
1605
-            $total = 0;
1606
-
1607
-            foreach($this->items as $item) {
1608
-                $bits = $item->encodeBitStream($this->version);
1522
+				default:
1523
+					break;
1524
+			}
1525
+
1526
+			return false;
1527
+		}
1528
+        
1529
+        
1530
+		//----------------------------------------------------------------------
1531
+		public function estimateBitStreamSize($version)
1532
+		{
1533
+			$bits = 0;
1534
+
1535
+			foreach($this->items as $item) {
1536
+				$bits += $item->estimateBitStreamSizeOfEntry($version);
1537
+			}
1538
+
1539
+			return $bits;
1540
+		}
1541
+        
1542
+		//----------------------------------------------------------------------
1543
+		public function estimateVersion()
1544
+		{
1545
+			$version = 0;
1546
+			$prev = 0;
1547
+			do {
1548
+				$prev = $version;
1549
+				$bits = $this->estimateBitStreamSize($prev);
1550
+				$version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
1551
+				if ($version < 0) {
1552
+					return -1;
1553
+				}
1554
+			} while ($version > $prev);
1555
+
1556
+			return $version;
1557
+		}
1558
+        
1559
+		//----------------------------------------------------------------------
1560
+		public static function lengthOfCode($mode, $version, $bits)
1561
+		{
1562
+			$payload = $bits - 4 - QRspec::lengthIndicator($mode, $version);
1563
+			switch($mode) {
1564
+				case QR_MODE_NUM:
1565
+					$chunks = (int)($payload / 10);
1566
+					$remain = $payload - $chunks * 10;
1567
+					$size = $chunks * 3;
1568
+					if($remain >= 7) {
1569
+						$size += 2;
1570
+					} else if($remain >= 4) {
1571
+						$size += 1;
1572
+					}
1573
+					break;
1574
+				case QR_MODE_AN:
1575
+					$chunks = (int)($payload / 11);
1576
+					$remain = $payload - $chunks * 11;
1577
+					$size = $chunks * 2;
1578
+					if($remain >= 6) 
1579
+						$size++;
1580
+					break;
1581
+				case QR_MODE_8:
1582
+					$size = (int)($payload / 8);
1583
+					break;
1584
+				case QR_MODE_KANJI:
1585
+					$size = (int)(($payload / 13) * 2);
1586
+					break;
1587
+				case QR_MODE_STRUCTURE:
1588
+					$size = (int)($payload / 8);
1589
+					break;
1590
+				default:
1591
+					$size = 0;
1592
+					break;
1593
+			}
1594
+            
1595
+			$maxsize = QRspec::maximumWords($mode, $version);
1596
+			if($size < 0) $size = 0;
1597
+			if($size > $maxsize) $size = $maxsize;
1598
+
1599
+			return $size;
1600
+		}
1601
+        
1602
+		//----------------------------------------------------------------------
1603
+		public function createBitStream()
1604
+		{
1605
+			$total = 0;
1606
+
1607
+			foreach($this->items as $item) {
1608
+				$bits = $item->encodeBitStream($this->version);
1609 1609
                 
1610
-                if($bits < 0) 
1611
-                    return -1;
1610
+				if($bits < 0) 
1611
+					return -1;
1612 1612
                     
1613
-                $total += $bits;
1614
-            }
1615
-
1616
-            return $total;
1617
-        }
1618
-        
1619
-        //----------------------------------------------------------------------
1620
-        public function convertData()
1621
-        {
1622
-            $ver = $this->estimateVersion();
1623
-            if($ver > $this->getVersion()) {
1624
-                $this->setVersion($ver);
1625
-            }
1626
-
1627
-            for(;;) {
1628
-                $bits = $this->createBitStream();
1613
+				$total += $bits;
1614
+			}
1615
+
1616
+			return $total;
1617
+		}
1618
+        
1619
+		//----------------------------------------------------------------------
1620
+		public function convertData()
1621
+		{
1622
+			$ver = $this->estimateVersion();
1623
+			if($ver > $this->getVersion()) {
1624
+				$this->setVersion($ver);
1625
+			}
1626
+
1627
+			for(;;) {
1628
+				$bits = $this->createBitStream();
1629 1629
                 
1630
-                if($bits < 0) 
1631
-                    return -1;
1630
+				if($bits < 0) 
1631
+					return -1;
1632 1632
                     
1633
-                $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
1634
-                if($ver < 0) {
1635
-                    throw new Exception('WRONG VERSION');
1636
-                    return -1;
1637
-                } else if($ver > $this->getVersion()) {
1638
-                    $this->setVersion($ver);
1639
-                } else {
1640
-                    break;
1641
-                }
1642
-            }
1643
-
1644
-            return 0;
1645
-        }
1646
-        
1647
-        //----------------------------------------------------------------------
1648
-        public function appendPaddingBit(&$bstream)
1649
-        {
1650
-            $bits = $bstream->size();
1651
-            $maxwords = QRspec::getDataLength($this->version, $this->level);
1652
-            $maxbits = $maxwords * 8;
1653
-
1654
-            if ($maxbits == $bits) {
1655
-                return 0;
1656
-            }
1657
-
1658
-            if ($maxbits - $bits < 5) {
1659
-                return $bstream->appendNum($maxbits - $bits, 0);
1660
-            }
1661
-
1662
-            $bits += 4;
1663
-            $words = (int)(($bits + 7) / 8);
1664
-
1665
-            $padding = new QRbitstream();
1666
-            $ret = $padding->appendNum($words * 8 - $bits + 4, 0);
1667
-            
1668
-            if($ret < 0) 
1669
-                return $ret;
1670
-
1671
-            $padlen = $maxwords - $words;
1672
-            
1673
-            if($padlen > 0) {
1633
+				$ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
1634
+				if($ver < 0) {
1635
+					throw new Exception('WRONG VERSION');
1636
+					return -1;
1637
+				} else if($ver > $this->getVersion()) {
1638
+					$this->setVersion($ver);
1639
+				} else {
1640
+					break;
1641
+				}
1642
+			}
1643
+
1644
+			return 0;
1645
+		}
1646
+        
1647
+		//----------------------------------------------------------------------
1648
+		public function appendPaddingBit(&$bstream)
1649
+		{
1650
+			$bits = $bstream->size();
1651
+			$maxwords = QRspec::getDataLength($this->version, $this->level);
1652
+			$maxbits = $maxwords * 8;
1653
+
1654
+			if ($maxbits == $bits) {
1655
+				return 0;
1656
+			}
1657
+
1658
+			if ($maxbits - $bits < 5) {
1659
+				return $bstream->appendNum($maxbits - $bits, 0);
1660
+			}
1661
+
1662
+			$bits += 4;
1663
+			$words = (int)(($bits + 7) / 8);
1664
+
1665
+			$padding = new QRbitstream();
1666
+			$ret = $padding->appendNum($words * 8 - $bits + 4, 0);
1667
+            
1668
+			if($ret < 0) 
1669
+				return $ret;
1670
+
1671
+			$padlen = $maxwords - $words;
1672
+            
1673
+			if($padlen > 0) {
1674 1674
                 
1675
-                $padbuf = array();
1676
-                for($i=0; $i<$padlen; $i++) {
1677
-                    $padbuf[$i] = ($i&1)?0x11:0xec;
1678
-                }
1675
+				$padbuf = array();
1676
+				for($i=0; $i<$padlen; $i++) {
1677
+					$padbuf[$i] = ($i&1)?0x11:0xec;
1678
+				}
1679 1679
                 
1680
-                $ret = $padding->appendBytes($padlen, $padbuf);
1680
+				$ret = $padding->appendBytes($padlen, $padbuf);
1681 1681
                 
1682
-                if($ret < 0)
1683
-                    return $ret;
1682
+				if($ret < 0)
1683
+					return $ret;
1684 1684
                 
1685
-            }
1685
+			}
1686 1686
 
1687
-            $ret = $bstream->append($padding);
1687
+			$ret = $bstream->append($padding);
1688 1688
             
1689
-            return $ret;
1690
-        }
1691
-
1692
-        //----------------------------------------------------------------------
1693
-        public function mergeBitStream()
1694
-        {
1695
-            if($this->convertData() < 0) {
1696
-                return null;
1697
-            }
1698
-
1699
-            $bstream = new QRbitstream();
1700
-            
1701
-            foreach($this->items as $item) {
1702
-                $ret = $bstream->append($item->bstream);
1703
-                if($ret < 0) {
1704
-                    return null;
1705
-                }
1706
-            }
1689
+			return $ret;
1690
+		}
1707 1691
 
1708
-            return $bstream;
1709
-        }
1692
+		//----------------------------------------------------------------------
1693
+		public function mergeBitStream()
1694
+		{
1695
+			if($this->convertData() < 0) {
1696
+				return null;
1697
+			}
1698
+
1699
+			$bstream = new QRbitstream();
1700
+            
1701
+			foreach($this->items as $item) {
1702
+				$ret = $bstream->append($item->bstream);
1703
+				if($ret < 0) {
1704
+					return null;
1705
+				}
1706
+			}
1707
+
1708
+			return $bstream;
1709
+		}
1710 1710
 
1711
-        //----------------------------------------------------------------------
1712
-        public function getBitStream()
1713
-        {
1711
+		//----------------------------------------------------------------------
1712
+		public function getBitStream()
1713
+		{
1714 1714
 
1715
-            $bstream = $this->mergeBitStream();
1715
+			$bstream = $this->mergeBitStream();
1716 1716
             
1717
-            if($bstream == null) {
1718
-                return null;
1719
-            }
1717
+			if($bstream == null) {
1718
+				return null;
1719
+			}
1720 1720
             
1721
-            $ret = $this->appendPaddingBit($bstream);
1722
-            if($ret < 0) {
1723
-                return null;
1724
-            }
1721
+			$ret = $this->appendPaddingBit($bstream);
1722
+			if($ret < 0) {
1723
+				return null;
1724
+			}
1725 1725
 
1726
-            return $bstream;
1727
-        }
1726
+			return $bstream;
1727
+		}
1728 1728
         
1729
-        //----------------------------------------------------------------------
1730
-        public function getByteStream()
1731
-        {
1732
-            $bstream = $this->getBitStream();
1733
-            if($bstream == null) {
1734
-                return null;
1735
-            }
1736
-            
1737
-            return $bstream->toByte();
1738
-        }
1739
-    }
1729
+		//----------------------------------------------------------------------
1730
+		public function getByteStream()
1731
+		{
1732
+			$bstream = $this->getBitStream();
1733
+			if($bstream == null) {
1734
+				return null;
1735
+			}
1736
+            
1737
+			return $bstream->toByte();
1738
+		}
1739
+	}
1740 1740
         
1741 1741
         
1742 1742
     
@@ -1774,159 +1774,159 @@  discard block
 block discarded – undo
1774 1774
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1775 1775
  */
1776 1776
      
1777
-    class QRbitstream {
1777
+	class QRbitstream {
1778 1778
     
1779
-        public $data = array();
1780
-        
1781
-        //----------------------------------------------------------------------
1782
-        public function size()
1783
-        {
1784
-            return count($this->data);
1785
-        }
1786
-        
1787
-        //----------------------------------------------------------------------
1788
-        public function allocate($setLength)
1789
-        {
1790
-            $this->data = array_fill(0, $setLength, 0);
1791
-            return 0;
1792
-        }
1779
+		public $data = array();
1780
+        
1781
+		//----------------------------------------------------------------------
1782
+		public function size()
1783
+		{
1784
+			return count($this->data);
1785
+		}
1786
+        
1787
+		//----------------------------------------------------------------------
1788
+		public function allocate($setLength)
1789
+		{
1790
+			$this->data = array_fill(0, $setLength, 0);
1791
+			return 0;
1792
+		}
1793 1793
     
1794
-        //----------------------------------------------------------------------
1795
-        public static function newFromNum($bits, $num)
1796
-        {
1797
-            $bstream = new QRbitstream();
1798
-            $bstream->allocate($bits);
1799
-            
1800
-            $mask = 1 << ($bits - 1);
1801
-            for($i=0; $i<$bits; $i++) {
1802
-                if($num & $mask) {
1803
-                    $bstream->data[$i] = 1;
1804
-                } else {
1805
-                    $bstream->data[$i] = 0;
1806
-                }
1807
-                $mask = $mask >> 1;
1808
-            }
1809
-
1810
-            return $bstream;
1811
-        }
1812
-        
1813
-        //----------------------------------------------------------------------
1814
-        public static function newFromBytes($size, $data)
1815
-        {
1816
-            $bstream = new QRbitstream();
1817
-            $bstream->allocate($size * 8);
1818
-            $p=0;
1819
-
1820
-            for($i=0; $i<$size; $i++) {
1821
-                $mask = 0x80;
1822
-                for($j=0; $j<8; $j++) {
1823
-                    if($data[$i] & $mask) {
1824
-                        $bstream->data[$p] = 1;
1825
-                    } else {
1826
-                        $bstream->data[$p] = 0;
1827
-                    }
1828
-                    $p++;
1829
-                    $mask = $mask >> 1;
1830
-                }
1831
-            }
1832
-
1833
-            return $bstream;
1834
-        }
1835
-        
1836
-        //----------------------------------------------------------------------
1837
-        public function append(QRbitstream $arg)
1838
-        {
1839
-            if (is_null($arg)) {
1840
-                return -1;
1841
-            }
1842
-            
1843
-            if($arg->size() == 0) {
1844
-                return 0;
1845
-            }
1846
-            
1847
-            if($this->size() == 0) {
1848
-                $this->data = $arg->data;
1849
-                return 0;
1850
-            }
1851
-            
1852
-            $this->data = array_values(array_merge($this->data, $arg->data));
1853
-
1854
-            return 0;
1855
-        }
1856
-        
1857
-        //----------------------------------------------------------------------
1858
-        public function appendNum($bits, $num)
1859
-        {
1860
-            if ($bits == 0) 
1861
-                return 0;
1862
-
1863
-            $b = QRbitstream::newFromNum($bits, $num);
1864
-            
1865
-            if(is_null($b))
1866
-                return -1;
1867
-
1868
-            $ret = $this->append($b);
1869
-            unset($b);
1870
-
1871
-            return $ret;
1872
-        }
1873
-
1874
-        //----------------------------------------------------------------------
1875
-        public function appendBytes($size, $data)
1876
-        {
1877
-            if ($size == 0) 
1878
-                return 0;
1879
-
1880
-            $b = QRbitstream::newFromBytes($size, $data);
1881
-            
1882
-            if(is_null($b))
1883
-                return -1;
1884
-
1885
-            $ret = $this->append($b);
1886
-            unset($b);
1887
-
1888
-            return $ret;
1889
-        }
1890
-        
1891
-        //----------------------------------------------------------------------
1892
-        public function toByte()
1893
-        {
1894
-        
1895
-            $size = $this->size();
1896
-
1897
-            if($size == 0) {
1898
-                return array();
1899
-            }
1900
-            
1901
-            $data = array_fill(0, (int)(($size + 7) / 8), 0);
1902
-            $bytes = (int)($size / 8);
1794
+		//----------------------------------------------------------------------
1795
+		public static function newFromNum($bits, $num)
1796
+		{
1797
+			$bstream = new QRbitstream();
1798
+			$bstream->allocate($bits);
1799
+            
1800
+			$mask = 1 << ($bits - 1);
1801
+			for($i=0; $i<$bits; $i++) {
1802
+				if($num & $mask) {
1803
+					$bstream->data[$i] = 1;
1804
+				} else {
1805
+					$bstream->data[$i] = 0;
1806
+				}
1807
+				$mask = $mask >> 1;
1808
+			}
1809
+
1810
+			return $bstream;
1811
+		}
1812
+        
1813
+		//----------------------------------------------------------------------
1814
+		public static function newFromBytes($size, $data)
1815
+		{
1816
+			$bstream = new QRbitstream();
1817
+			$bstream->allocate($size * 8);
1818
+			$p=0;
1819
+
1820
+			for($i=0; $i<$size; $i++) {
1821
+				$mask = 0x80;
1822
+				for($j=0; $j<8; $j++) {
1823
+					if($data[$i] & $mask) {
1824
+						$bstream->data[$p] = 1;
1825
+					} else {
1826
+						$bstream->data[$p] = 0;
1827
+					}
1828
+					$p++;
1829
+					$mask = $mask >> 1;
1830
+				}
1831
+			}
1832
+
1833
+			return $bstream;
1834
+		}
1835
+        
1836
+		//----------------------------------------------------------------------
1837
+		public function append(QRbitstream $arg)
1838
+		{
1839
+			if (is_null($arg)) {
1840
+				return -1;
1841
+			}
1842
+            
1843
+			if($arg->size() == 0) {
1844
+				return 0;
1845
+			}
1846
+            
1847
+			if($this->size() == 0) {
1848
+				$this->data = $arg->data;
1849
+				return 0;
1850
+			}
1851
+            
1852
+			$this->data = array_values(array_merge($this->data, $arg->data));
1903 1853
 
1904
-            $p = 0;
1854
+			return 0;
1855
+		}
1856
+        
1857
+		//----------------------------------------------------------------------
1858
+		public function appendNum($bits, $num)
1859
+		{
1860
+			if ($bits == 0) 
1861
+				return 0;
1862
+
1863
+			$b = QRbitstream::newFromNum($bits, $num);
1905 1864
             
1906
-            for($i=0; $i<$bytes; $i++) {
1907
-                $v = 0;
1908
-                for($j=0; $j<8; $j++) {
1909
-                    $v = $v << 1;
1910
-                    $v |= $this->data[$p];
1911
-                    $p++;
1912
-                }
1913
-                $data[$i] = $v;
1914
-            }
1865
+			if(is_null($b))
1866
+				return -1;
1867
+
1868
+			$ret = $this->append($b);
1869
+			unset($b);
1870
+
1871
+			return $ret;
1872
+		}
1873
+
1874
+		//----------------------------------------------------------------------
1875
+		public function appendBytes($size, $data)
1876
+		{
1877
+			if ($size == 0) 
1878
+				return 0;
1879
+
1880
+			$b = QRbitstream::newFromBytes($size, $data);
1915 1881
             
1916
-            if($size & 7) {
1917
-                $v = 0;
1918
-                for($j=0; $j<($size & 7); $j++) {
1919
-                    $v = $v << 1;
1920
-                    $v |= $this->data[$p];
1921
-                    $p++;
1922
-                }
1923
-                $data[$bytes] = $v;
1924
-            }
1882
+			if(is_null($b))
1883
+				return -1;
1925 1884
 
1926
-            return $data;
1927
-        }
1885
+			$ret = $this->append($b);
1886
+			unset($b);
1928 1887
 
1929
-    }
1888
+			return $ret;
1889
+		}
1890
+        
1891
+		//----------------------------------------------------------------------
1892
+		public function toByte()
1893
+		{
1894
+        
1895
+			$size = $this->size();
1896
+
1897
+			if($size == 0) {
1898
+				return array();
1899
+			}
1900
+            
1901
+			$data = array_fill(0, (int)(($size + 7) / 8), 0);
1902
+			$bytes = (int)($size / 8);
1903
+
1904
+			$p = 0;
1905
+            
1906
+			for($i=0; $i<$bytes; $i++) {
1907
+				$v = 0;
1908
+				for($j=0; $j<8; $j++) {
1909
+					$v = $v << 1;
1910
+					$v |= $this->data[$p];
1911
+					$p++;
1912
+				}
1913
+				$data[$i] = $v;
1914
+			}
1915
+            
1916
+			if($size & 7) {
1917
+				$v = 0;
1918
+				for($j=0; $j<($size & 7); $j++) {
1919
+					$v = $v << 1;
1920
+					$v |= $this->data[$p];
1921
+					$p++;
1922
+				}
1923
+				$data[$bytes] = $v;
1924
+			}
1925
+
1926
+			return $data;
1927
+		}
1928
+
1929
+	}
1930 1930
 
1931 1931
 
1932 1932
 
@@ -1967,285 +1967,285 @@  discard block
 block discarded – undo
1967 1967
  * License along with this library; if not, write to the Free Software
1968 1968
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1969 1969
  */
1970
-    class QRsplit {
1971
-
1972
-        public $dataStr = '';
1973
-        public $input;
1974
-        public $modeHint;
1975
-
1976
-        //----------------------------------------------------------------------
1977
-        public function __construct($dataStr, $input, $modeHint) 
1978
-        {
1979
-            $this->dataStr  = $dataStr;
1980
-            $this->input    = $input;
1981
-            $this->modeHint = $modeHint;
1982
-        }
1983
-        
1984
-        //----------------------------------------------------------------------
1985
-        public static function isdigitat($str, $pos)
1986
-        {    
1987
-            if ($pos >= strlen($str))
1988
-                return false;
1989
-            
1990
-            return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
1991
-        }
1992
-        
1993
-        //----------------------------------------------------------------------
1994
-        public static function isalnumat($str, $pos)
1995
-        {
1996
-            if ($pos >= strlen($str))
1997
-                return false;
1970
+	class QRsplit {
1971
+
1972
+		public $dataStr = '';
1973
+		public $input;
1974
+		public $modeHint;
1975
+
1976
+		//----------------------------------------------------------------------
1977
+		public function __construct($dataStr, $input, $modeHint) 
1978
+		{
1979
+			$this->dataStr  = $dataStr;
1980
+			$this->input    = $input;
1981
+			$this->modeHint = $modeHint;
1982
+		}
1983
+        
1984
+		//----------------------------------------------------------------------
1985
+		public static function isdigitat($str, $pos)
1986
+		{    
1987
+			if ($pos >= strlen($str))
1988
+				return false;
1989
+            
1990
+			return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
1991
+		}
1992
+        
1993
+		//----------------------------------------------------------------------
1994
+		public static function isalnumat($str, $pos)
1995
+		{
1996
+			if ($pos >= strlen($str))
1997
+				return false;
1998 1998
                 
1999
-            return (QRinput::lookAnTable(ord($str[$pos])) >= 0);
2000
-        }
2001
-
2002
-        //----------------------------------------------------------------------
2003
-        public function identifyMode($pos)
2004
-        {
2005
-            if ($pos >= strlen($this->dataStr)) 
2006
-                return QR_MODE_NUL;
1999
+			return (QRinput::lookAnTable(ord($str[$pos])) >= 0);
2000
+		}
2001
+
2002
+		//----------------------------------------------------------------------
2003
+		public function identifyMode($pos)
2004
+		{
2005
+			if ($pos >= strlen($this->dataStr)) 
2006
+				return QR_MODE_NUL;
2007 2007
                 
2008
-            $c = $this->dataStr[$pos];
2009
-            
2010
-            if(self::isdigitat($this->dataStr, $pos)) {
2011
-                return QR_MODE_NUM;
2012
-            } else if(self::isalnumat($this->dataStr, $pos)) {
2013
-                return QR_MODE_AN;
2014
-            } else if($this->modeHint == QR_MODE_KANJI) {
2015
-            
2016
-                if ($pos+1 < strlen($this->dataStr)) 
2017
-                {
2018
-                    $d = $this->dataStr[$pos+1];
2019
-                    $word = (ord($c) << 8) | ord($d);
2020
-                    if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) {
2021
-                        return QR_MODE_KANJI;
2022
-                    }
2023
-                }
2024
-            }
2025
-
2026
-            return QR_MODE_8;
2027
-        } 
2028
-        
2029
-        //----------------------------------------------------------------------
2030
-        public function eatNum()
2031
-        {
2032
-            $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
2033
-
2034
-            $p = 0;
2035
-            while(self::isdigitat($this->dataStr, $p)) {
2036
-                $p++;
2037
-            }
2038
-            
2039
-            $run = $p;
2040
-            $mode = $this->identifyMode($p);
2041
-            
2042
-            if($mode == QR_MODE_8) {
2043
-                $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln
2044
-                     + QRinput::estimateBitsMode8(1)         // + 4 + l8
2045
-                     - QRinput::estimateBitsMode8($run + 1); // - 4 - l8
2046
-                if($dif > 0) {
2047
-                    return $this->eat8();
2048
-                }
2049
-            }
2050
-            if($mode == QR_MODE_AN) {
2051
-                $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln
2052
-                     + QRinput::estimateBitsModeAn(1)        // + 4 + la
2053
-                     - QRinput::estimateBitsModeAn($run + 1);// - 4 - la
2054
-                if($dif > 0) {
2055
-                    return $this->eatAn();
2056
-                }
2057
-            }
2058
-            
2059
-            $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr));
2060
-            if($ret < 0)
2061
-                return -1;
2062
-
2063
-            return $run;
2064
-        }
2065
-        
2066
-        //----------------------------------------------------------------------
2067
-        public function eatAn()
2068
-        {
2069
-            $la = QRspec::lengthIndicator(QR_MODE_AN,  $this->input->getVersion());
2070
-            $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
2071
-
2072
-            $p = 0;
2073
-            
2074
-            while(self::isalnumat($this->dataStr, $p)) {
2075
-                if(self::isdigitat($this->dataStr, $p)) {
2076
-                    $q = $p;
2077
-                    while(self::isdigitat($this->dataStr, $q)) {
2078
-                        $q++;
2079
-                    }
2008
+			$c = $this->dataStr[$pos];
2009
+            
2010
+			if(self::isdigitat($this->dataStr, $pos)) {
2011
+				return QR_MODE_NUM;
2012
+			} else if(self::isalnumat($this->dataStr, $pos)) {
2013
+				return QR_MODE_AN;
2014
+			} else if($this->modeHint == QR_MODE_KANJI) {
2015
+            
2016
+				if ($pos+1 < strlen($this->dataStr)) 
2017
+				{
2018
+					$d = $this->dataStr[$pos+1];
2019
+					$word = (ord($c) << 8) | ord($d);
2020
+					if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) {
2021
+						return QR_MODE_KANJI;
2022
+					}
2023
+				}
2024
+			}
2025
+
2026
+			return QR_MODE_8;
2027
+		} 
2028
+        
2029
+		//----------------------------------------------------------------------
2030
+		public function eatNum()
2031
+		{
2032
+			$ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
2033
+
2034
+			$p = 0;
2035
+			while(self::isdigitat($this->dataStr, $p)) {
2036
+				$p++;
2037
+			}
2038
+            
2039
+			$run = $p;
2040
+			$mode = $this->identifyMode($p);
2041
+            
2042
+			if($mode == QR_MODE_8) {
2043
+				$dif = QRinput::estimateBitsModeNum($run) + 4 + $ln
2044
+					 + QRinput::estimateBitsMode8(1)         // + 4 + l8
2045
+					 - QRinput::estimateBitsMode8($run + 1); // - 4 - l8
2046
+				if($dif > 0) {
2047
+					return $this->eat8();
2048
+				}
2049
+			}
2050
+			if($mode == QR_MODE_AN) {
2051
+				$dif = QRinput::estimateBitsModeNum($run) + 4 + $ln
2052
+					 + QRinput::estimateBitsModeAn(1)        // + 4 + la
2053
+					 - QRinput::estimateBitsModeAn($run + 1);// - 4 - la
2054
+				if($dif > 0) {
2055
+					return $this->eatAn();
2056
+				}
2057
+			}
2058
+            
2059
+			$ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr));
2060
+			if($ret < 0)
2061
+				return -1;
2062
+
2063
+			return $run;
2064
+		}
2065
+        
2066
+		//----------------------------------------------------------------------
2067
+		public function eatAn()
2068
+		{
2069
+			$la = QRspec::lengthIndicator(QR_MODE_AN,  $this->input->getVersion());
2070
+			$ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
2071
+
2072
+			$p = 0;
2073
+            
2074
+			while(self::isalnumat($this->dataStr, $p)) {
2075
+				if(self::isdigitat($this->dataStr, $p)) {
2076
+					$q = $p;
2077
+					while(self::isdigitat($this->dataStr, $q)) {
2078
+						$q++;
2079
+					}
2080 2080
                     
2081
-                    $dif = QRinput::estimateBitsModeAn($p) // + 4 + la
2082
-                         + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln
2083
-                         - QRinput::estimateBitsModeAn($q); // - 4 - la
2081
+					$dif = QRinput::estimateBitsModeAn($p) // + 4 + la
2082
+						 + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln
2083
+						 - QRinput::estimateBitsModeAn($q); // - 4 - la
2084 2084
                          
2085
-                    if($dif < 0) {
2086
-                        break;
2087
-                    } else {
2088
-                        $p = $q;
2089
-                    }
2090
-                } else {
2091
-                    $p++;
2092
-                }
2093
-            }
2094
-
2095
-            $run = $p;
2096
-
2097
-            if(!self::isalnumat($this->dataStr, $p)) {
2098
-                $dif = QRinput::estimateBitsModeAn($run) + 4 + $la
2099
-                     + QRinput::estimateBitsMode8(1) // + 4 + l8
2100
-                      - QRinput::estimateBitsMode8($run + 1); // - 4 - l8
2101
-                if($dif > 0) {
2102
-                    return $this->eat8();
2103
-                }
2104
-            }
2105
-
2106
-            $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr));
2107
-            if($ret < 0)
2108
-                return -1;
2109
-
2110
-            return $run;
2111
-        }
2112
-        
2113
-        //----------------------------------------------------------------------
2114
-        public function eatKanji()
2115
-        {
2116
-            $p = 0;
2117
-            
2118
-            while($this->identifyMode($p) == QR_MODE_KANJI) {
2119
-                $p += 2;
2120
-            }
2121
-            
2122
-            $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr));
2123
-            if($ret < 0)
2124
-                return -1;
2125
-
2126
-            return $run;
2127
-        }
2128
-
2129
-        //----------------------------------------------------------------------
2130
-        public function eat8()
2131
-        {
2132
-            $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion());
2133
-            $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
2134
-
2135
-            $p = 1;
2136
-            $dataStrLen = strlen($this->dataStr);
2137
-            
2138
-            while($p < $dataStrLen) {
2085
+					if($dif < 0) {
2086
+						break;
2087
+					} else {
2088
+						$p = $q;
2089
+					}
2090
+				} else {
2091
+					$p++;
2092
+				}
2093
+			}
2094
+
2095
+			$run = $p;
2096
+
2097
+			if(!self::isalnumat($this->dataStr, $p)) {
2098
+				$dif = QRinput::estimateBitsModeAn($run) + 4 + $la
2099
+					 + QRinput::estimateBitsMode8(1) // + 4 + l8
2100
+					  - QRinput::estimateBitsMode8($run + 1); // - 4 - l8
2101
+				if($dif > 0) {
2102
+					return $this->eat8();
2103
+				}
2104
+			}
2105
+
2106
+			$ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr));
2107
+			if($ret < 0)
2108
+				return -1;
2109
+
2110
+			return $run;
2111
+		}
2112
+        
2113
+		//----------------------------------------------------------------------
2114
+		public function eatKanji()
2115
+		{
2116
+			$p = 0;
2117
+            
2118
+			while($this->identifyMode($p) == QR_MODE_KANJI) {
2119
+				$p += 2;
2120
+			}
2121
+            
2122
+			$ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr));
2123
+			if($ret < 0)
2124
+				return -1;
2125
+
2126
+			return $run;
2127
+		}
2128
+
2129
+		//----------------------------------------------------------------------
2130
+		public function eat8()
2131
+		{
2132
+			$la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion());
2133
+			$ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
2134
+
2135
+			$p = 1;
2136
+			$dataStrLen = strlen($this->dataStr);
2137
+            
2138
+			while($p < $dataStrLen) {
2139 2139
                 
2140
-                $mode = $this->identifyMode($p);
2141
-                if($mode == QR_MODE_KANJI) {
2142
-                    break;
2143
-                }
2144
-                if($mode == QR_MODE_NUM) {
2145
-                    $q = $p;
2146
-                    while(self::isdigitat($this->dataStr, $q)) {
2147
-                        $q++;
2148
-                    }
2149
-                    $dif = QRinput::estimateBitsMode8($p) // + 4 + l8
2150
-                         + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln
2151
-                         - QRinput::estimateBitsMode8($q); // - 4 - l8
2152
-                    if($dif < 0) {
2153
-                        break;
2154
-                    } else {
2155
-                        $p = $q;
2156
-                    }
2157
-                } else if($mode == QR_MODE_AN) {
2158
-                    $q = $p;
2159
-                    while(self::isalnumat($this->dataStr, $q)) {
2160
-                        $q++;
2161
-                    }
2162
-                    $dif = QRinput::estimateBitsMode8($p)  // + 4 + l8
2163
-                         + QRinput::estimateBitsModeAn($q - $p) + 4 + $la
2164
-                         - QRinput::estimateBitsMode8($q); // - 4 - l8
2165
-                    if($dif < 0) {
2166
-                        break;
2167
-                    } else {
2168
-                        $p = $q;
2169
-                    }
2170
-                } else {
2171
-                    $p++;
2172
-                }
2173
-            }
2174
-
2175
-            $run = $p;
2176
-            $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr));
2177
-            
2178
-            if($ret < 0)
2179
-                return -1;
2180
-
2181
-            return $run;
2182
-        }
2183
-
2184
-        //----------------------------------------------------------------------
2185
-        public function splitString()
2186
-        {
2187
-            while (strlen($this->dataStr) > 0)
2188
-            {
2189
-                if($this->dataStr == '')
2190
-                    return 0;
2191
-
2192
-                $mode = $this->identifyMode(0);
2140
+				$mode = $this->identifyMode($p);
2141
+				if($mode == QR_MODE_KANJI) {
2142
+					break;
2143
+				}
2144
+				if($mode == QR_MODE_NUM) {
2145
+					$q = $p;
2146
+					while(self::isdigitat($this->dataStr, $q)) {
2147
+						$q++;
2148
+					}
2149
+					$dif = QRinput::estimateBitsMode8($p) // + 4 + l8
2150
+						 + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln
2151
+						 - QRinput::estimateBitsMode8($q); // - 4 - l8
2152
+					if($dif < 0) {
2153
+						break;
2154
+					} else {
2155
+						$p = $q;
2156
+					}
2157
+				} else if($mode == QR_MODE_AN) {
2158
+					$q = $p;
2159
+					while(self::isalnumat($this->dataStr, $q)) {
2160
+						$q++;
2161
+					}
2162
+					$dif = QRinput::estimateBitsMode8($p)  // + 4 + l8
2163
+						 + QRinput::estimateBitsModeAn($q - $p) + 4 + $la
2164
+						 - QRinput::estimateBitsMode8($q); // - 4 - l8
2165
+					if($dif < 0) {
2166
+						break;
2167
+					} else {
2168
+						$p = $q;
2169
+					}
2170
+				} else {
2171
+					$p++;
2172
+				}
2173
+			}
2174
+
2175
+			$run = $p;
2176
+			$ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr));
2177
+            
2178
+			if($ret < 0)
2179
+				return -1;
2180
+
2181
+			return $run;
2182
+		}
2183
+
2184
+		//----------------------------------------------------------------------
2185
+		public function splitString()
2186
+		{
2187
+			while (strlen($this->dataStr) > 0)
2188
+			{
2189
+				if($this->dataStr == '')
2190
+					return 0;
2191
+
2192
+				$mode = $this->identifyMode(0);
2193 2193
                 
2194
-                switch ($mode) {
2195
-                    case QR_MODE_NUM: $length = $this->eatNum(); break;
2196
-                    case QR_MODE_AN:  $length = $this->eatAn(); break;
2197
-                    case QR_MODE_KANJI:
2198
-                        if ($this->modeHint == QR_MODE_KANJI)
2199
-                                $length = $this->eatKanji();
2200
-                        else    $length = $this->eat8();
2201
-                        break;
2202
-                    default: $length = $this->eat8(); break;
2194
+				switch ($mode) {
2195
+					case QR_MODE_NUM: $length = $this->eatNum(); break;
2196
+					case QR_MODE_AN:  $length = $this->eatAn(); break;
2197
+					case QR_MODE_KANJI:
2198
+						if ($this->modeHint == QR_MODE_KANJI)
2199
+								$length = $this->eatKanji();
2200
+						else    $length = $this->eat8();
2201
+						break;
2202
+					default: $length = $this->eat8(); break;
2203 2203
                 
2204
-                }
2204
+				}
2205 2205
 
2206
-                if($length == 0) return 0;
2207
-                if($length < 0)  return -1;
2206
+				if($length == 0) return 0;
2207
+				if($length < 0)  return -1;
2208 2208
                 
2209
-                $this->dataStr = substr($this->dataStr, $length);
2210
-            }
2211
-        }
2212
-
2213
-        //----------------------------------------------------------------------
2214
-        public function toUpper()
2215
-        {
2216
-            $stringLen = strlen($this->dataStr);
2217
-            $p = 0;
2218
-            
2219
-            while ($p<$stringLen) {
2220
-                $mode = self::identifyMode(substr($this->dataStr, $p));
2221
-                if($mode == QR_MODE_KANJI) {
2222
-                    $p += 2;
2223
-                } else {
2224
-                    if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) {
2225
-                        $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32);
2226
-                    }
2227
-                    $p++;
2228
-                }
2229
-            }
2230
-
2231
-            return $this->dataStr;
2232
-        }
2233
-
2234
-        //----------------------------------------------------------------------
2235
-        public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true)
2236
-        {
2237
-            if(is_null($string) || $string == '\0' || $string == '') {
2238
-                throw new Exception('empty string!!!');
2239
-            }
2240
-
2241
-            $split = new QRsplit($string, $input, $modeHint);
2242
-            
2243
-            if(!$casesensitive)
2244
-                $split->toUpper();
2209
+				$this->dataStr = substr($this->dataStr, $length);
2210
+			}
2211
+		}
2212
+
2213
+		//----------------------------------------------------------------------
2214
+		public function toUpper()
2215
+		{
2216
+			$stringLen = strlen($this->dataStr);
2217
+			$p = 0;
2218
+            
2219
+			while ($p<$stringLen) {
2220
+				$mode = self::identifyMode(substr($this->dataStr, $p));
2221
+				if($mode == QR_MODE_KANJI) {
2222
+					$p += 2;
2223
+				} else {
2224
+					if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) {
2225
+						$this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32);
2226
+					}
2227
+					$p++;
2228
+				}
2229
+			}
2230
+
2231
+			return $this->dataStr;
2232
+		}
2233
+
2234
+		//----------------------------------------------------------------------
2235
+		public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true)
2236
+		{
2237
+			if(is_null($string) || $string == '\0' || $string == '') {
2238
+				throw new Exception('empty string!!!');
2239
+			}
2240
+
2241
+			$split = new QRsplit($string, $input, $modeHint);
2242
+            
2243
+			if(!$casesensitive)
2244
+				$split->toUpper();
2245 2245
                 
2246
-            return $split->splitString();
2247
-        }
2248
-    }
2246
+			return $split->splitString();
2247
+		}
2248
+	}
2249 2249
 
2250 2250
 
2251 2251
 
@@ -2283,186 +2283,186 @@  discard block
 block discarded – undo
2283 2283
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2284 2284
  */
2285 2285
  
2286
-    class QRrsItem {
2286
+	class QRrsItem {
2287 2287
     
2288
-        public $mm;                  // Bits per symbol 
2289
-        public $nn;                  // Symbols per block (= (1<<mm)-1) 
2290
-        public $alpha_to = array();  // log lookup table 
2291
-        public $index_of = array();  // Antilog lookup table 
2292
-        public $genpoly = array();   // Generator polynomial 
2293
-        public $nroots;              // Number of generator roots = number of parity symbols 
2294
-        public $fcr;                 // First consecutive root, index form 
2295
-        public $prim;                // Primitive element, index form 
2296
-        public $iprim;               // prim-th root of 1, index form 
2297
-        public $pad;                 // Padding bytes in shortened block 
2298
-        public $gfpoly;
2288
+		public $mm;                  // Bits per symbol 
2289
+		public $nn;                  // Symbols per block (= (1<<mm)-1) 
2290
+		public $alpha_to = array();  // log lookup table 
2291
+		public $index_of = array();  // Antilog lookup table 
2292
+		public $genpoly = array();   // Generator polynomial 
2293
+		public $nroots;              // Number of generator roots = number of parity symbols 
2294
+		public $fcr;                 // First consecutive root, index form 
2295
+		public $prim;                // Primitive element, index form 
2296
+		public $iprim;               // prim-th root of 1, index form 
2297
+		public $pad;                 // Padding bytes in shortened block 
2298
+		public $gfpoly;
2299 2299
     
2300
-        //----------------------------------------------------------------------
2301
-        public function modnn($x)
2302
-        {
2303
-            while ($x >= $this->nn) {
2304
-                $x -= $this->nn;
2305
-                $x = ($x >> $this->mm) + ($x & $this->nn);
2306
-            }
2307
-            
2308
-            return $x;
2309
-        }
2310
-        
2311
-        //----------------------------------------------------------------------
2312
-        public static function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
2313
-        {
2314
-            // Common code for intializing a Reed-Solomon control block (char or int symbols)
2315
-            // Copyright 2004 Phil Karn, KA9Q
2316
-            // May be used under the terms of the GNU Lesser General Public License (LGPL)
2317
-
2318
-            $rs = null;
2319
-            
2320
-            // Check parameter ranges
2321
-            if($symsize < 0 || $symsize > 8)                     return $rs;
2322
-            if($fcr < 0 || $fcr >= (1<<$symsize))                return $rs;
2323
-            if($prim <= 0 || $prim >= (1<<$symsize))             return $rs;
2324
-            if($nroots < 0 || $nroots >= (1<<$symsize))          return $rs; // Can't have more roots than symbol values!
2325
-            if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding
2326
-
2327
-            $rs = new QRrsItem();
2328
-            $rs->mm = $symsize;
2329
-            $rs->nn = (1<<$symsize)-1;
2330
-            $rs->pad = $pad;
2331
-
2332
-            $rs->alpha_to = array_fill(0, $rs->nn+1, 0);
2333
-            $rs->index_of = array_fill(0, $rs->nn+1, 0);
2300
+		//----------------------------------------------------------------------
2301
+		public function modnn($x)
2302
+		{
2303
+			while ($x >= $this->nn) {
2304
+				$x -= $this->nn;
2305
+				$x = ($x >> $this->mm) + ($x & $this->nn);
2306
+			}
2307
+            
2308
+			return $x;
2309
+		}
2310
+        
2311
+		//----------------------------------------------------------------------
2312
+		public static function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
2313
+		{
2314
+			// Common code for intializing a Reed-Solomon control block (char or int symbols)
2315
+			// Copyright 2004 Phil Karn, KA9Q
2316
+			// May be used under the terms of the GNU Lesser General Public License (LGPL)
2317
+
2318
+			$rs = null;
2319
+            
2320
+			// Check parameter ranges
2321
+			if($symsize < 0 || $symsize > 8)                     return $rs;
2322
+			if($fcr < 0 || $fcr >= (1<<$symsize))                return $rs;
2323
+			if($prim <= 0 || $prim >= (1<<$symsize))             return $rs;
2324
+			if($nroots < 0 || $nroots >= (1<<$symsize))          return $rs; // Can't have more roots than symbol values!
2325
+			if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding
2326
+
2327
+			$rs = new QRrsItem();
2328
+			$rs->mm = $symsize;
2329
+			$rs->nn = (1<<$symsize)-1;
2330
+			$rs->pad = $pad;
2331
+
2332
+			$rs->alpha_to = array_fill(0, $rs->nn+1, 0);
2333
+			$rs->index_of = array_fill(0, $rs->nn+1, 0);
2334 2334
           
2335
-            // PHP style macro replacement ;)
2336
-            $NN =& $rs->nn;
2337
-            $A0 =& $NN;
2338
-            
2339
-            // Generate Galois field lookup tables
2340
-            $rs->index_of[0] = $A0; // log(zero) = -inf
2341
-            $rs->alpha_to[$A0] = 0; // alpha**-inf = 0
2342
-            $sr = 1;
2335
+			// PHP style macro replacement ;)
2336
+			$NN =& $rs->nn;
2337
+			$A0 =& $NN;
2338
+            
2339
+			// Generate Galois field lookup tables
2340
+			$rs->index_of[0] = $A0; // log(zero) = -inf
2341
+			$rs->alpha_to[$A0] = 0; // alpha**-inf = 0
2342
+			$sr = 1;
2343 2343
           
2344
-            for($i=0; $i<$rs->nn; $i++) {
2345
-                $rs->index_of[$sr] = $i;
2346
-                $rs->alpha_to[$i] = $sr;
2347
-                $sr <<= 1;
2348
-                if($sr & (1<<$symsize)) {
2349
-                    $sr ^= $gfpoly;
2350
-                }
2351
-                $sr &= $rs->nn;
2352
-            }
2353
-            
2354
-            if($sr != 1){
2355
-                // field generator polynomial is not primitive!
2356
-                $rs = NULL;
2357
-                return $rs;
2358
-            }
2359
-
2360
-            /* Form RS code generator polynomial from its roots */
2361
-            $rs->genpoly = array_fill(0, $nroots+1, 0);
2362
-        
2363
-            $rs->fcr = $fcr;
2364
-            $rs->prim = $prim;
2365
-            $rs->nroots = $nroots;
2366
-            $rs->gfpoly = $gfpoly;
2367
-
2368
-            /* Find prim-th root of 1, used in decoding */
2369
-            for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn)
2370
-            ; // intentional empty-body loop!
2371
-            
2372
-            $rs->iprim = (int)($iprim / $prim);
2373
-            $rs->genpoly[0] = 1;
2374
-            
2375
-            for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) {
2376
-                $rs->genpoly[$i+1] = 1;
2377
-
2378
-                // Multiply rs->genpoly[] by  @**(root + x)
2379
-                for ($j = $i; $j > 0; $j--) {
2380
-                    if ($rs->genpoly[$j] != 0) {
2381
-                        $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)];
2382
-                    } else {
2383
-                        $rs->genpoly[$j] = $rs->genpoly[$j-1];
2384
-                    }
2385
-                }
2386
-                // rs->genpoly[0] can never be zero
2387
-                $rs->genpoly[0] = $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[0]] + $root)];
2388
-            }
2389
-            
2390
-            // convert rs->genpoly[] to index form for quicker encoding
2391
-            for ($i = 0; $i <= $nroots; $i++)
2392
-                $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]];
2393
-
2394
-            return $rs;
2395
-        }
2396
-        
2397
-        //----------------------------------------------------------------------
2398
-        public function encode_rs_char($data, &$parity)
2399
-        {
2400
-            $MM       =& $this->mm;
2401
-            $NN       =& $this->nn;
2402
-            $ALPHA_TO =& $this->alpha_to;
2403
-            $INDEX_OF =& $this->index_of;
2404
-            $GENPOLY  =& $this->genpoly;
2405
-            $NROOTS   =& $this->nroots;
2406
-            $FCR      =& $this->fcr;
2407
-            $PRIM     =& $this->prim;
2408
-            $IPRIM    =& $this->iprim;
2409
-            $PAD      =& $this->pad;
2410
-            $A0       =& $NN;
2411
-
2412
-            $parity = array_fill(0, $NROOTS, 0);
2413
-
2414
-            for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) {
2344
+			for($i=0; $i<$rs->nn; $i++) {
2345
+				$rs->index_of[$sr] = $i;
2346
+				$rs->alpha_to[$i] = $sr;
2347
+				$sr <<= 1;
2348
+				if($sr & (1<<$symsize)) {
2349
+					$sr ^= $gfpoly;
2350
+				}
2351
+				$sr &= $rs->nn;
2352
+			}
2353
+            
2354
+			if($sr != 1){
2355
+				// field generator polynomial is not primitive!
2356
+				$rs = NULL;
2357
+				return $rs;
2358
+			}
2359
+
2360
+			/* Form RS code generator polynomial from its roots */
2361
+			$rs->genpoly = array_fill(0, $nroots+1, 0);
2362
+        
2363
+			$rs->fcr = $fcr;
2364
+			$rs->prim = $prim;
2365
+			$rs->nroots = $nroots;
2366
+			$rs->gfpoly = $gfpoly;
2367
+
2368
+			/* Find prim-th root of 1, used in decoding */
2369
+			for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn)
2370
+			; // intentional empty-body loop!
2371
+            
2372
+			$rs->iprim = (int)($iprim / $prim);
2373
+			$rs->genpoly[0] = 1;
2374
+            
2375
+			for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) {
2376
+				$rs->genpoly[$i+1] = 1;
2377
+
2378
+				// Multiply rs->genpoly[] by  @**(root + x)
2379
+				for ($j = $i; $j > 0; $j--) {
2380
+					if ($rs->genpoly[$j] != 0) {
2381
+						$rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)];
2382
+					} else {
2383
+						$rs->genpoly[$j] = $rs->genpoly[$j-1];
2384
+					}
2385
+				}
2386
+				// rs->genpoly[0] can never be zero
2387
+				$rs->genpoly[0] = $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[0]] + $root)];
2388
+			}
2389
+            
2390
+			// convert rs->genpoly[] to index form for quicker encoding
2391
+			for ($i = 0; $i <= $nroots; $i++)
2392
+				$rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]];
2393
+
2394
+			return $rs;
2395
+		}
2396
+        
2397
+		//----------------------------------------------------------------------
2398
+		public function encode_rs_char($data, &$parity)
2399
+		{
2400
+			$MM       =& $this->mm;
2401
+			$NN       =& $this->nn;
2402
+			$ALPHA_TO =& $this->alpha_to;
2403
+			$INDEX_OF =& $this->index_of;
2404
+			$GENPOLY  =& $this->genpoly;
2405
+			$NROOTS   =& $this->nroots;
2406
+			$FCR      =& $this->fcr;
2407
+			$PRIM     =& $this->prim;
2408
+			$IPRIM    =& $this->iprim;
2409
+			$PAD      =& $this->pad;
2410
+			$A0       =& $NN;
2411
+
2412
+			$parity = array_fill(0, $NROOTS, 0);
2413
+
2414
+			for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) {
2415 2415
                 
2416
-                $feedback = $INDEX_OF[$data[$i] ^ $parity[0]];
2417
-                if($feedback != $A0) {      
2418
-                    // feedback term is non-zero
2419
-            
2420
-                    // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
2421
-                    // always be for the polynomials constructed by init_rs()
2422
-                    $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback);
2423
-            
2424
-                    for($j=1;$j<$NROOTS;$j++) {
2425
-                        $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])];
2426
-                    }
2427
-                }
2416
+				$feedback = $INDEX_OF[$data[$i] ^ $parity[0]];
2417
+				if($feedback != $A0) {      
2418
+					// feedback term is non-zero
2419
+            
2420
+					// This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
2421
+					// always be for the polynomials constructed by init_rs()
2422
+					$feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback);
2423
+            
2424
+					for($j=1;$j<$NROOTS;$j++) {
2425
+						$parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])];
2426
+					}
2427
+				}
2428 2428
                 
2429
-                // Shift 
2430
-                array_shift($parity);
2431
-                if($feedback != $A0) {
2432
-                    array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]);
2433
-                } else {
2434
-                    array_push($parity, 0);
2435
-                }
2436
-            }
2437
-        }
2438
-    }
2429
+				// Shift 
2430
+				array_shift($parity);
2431
+				if($feedback != $A0) {
2432
+					array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]);
2433
+				} else {
2434
+					array_push($parity, 0);
2435
+				}
2436
+			}
2437
+		}
2438
+	}
2439 2439
     
2440
-    //##########################################################################
2440
+	//##########################################################################
2441 2441
     
2442
-    class QRrs {
2442
+	class QRrs {
2443 2443
     
2444
-        public static $items = array();
2444
+		public static $items = array();
2445 2445
         
2446
-        //----------------------------------------------------------------------
2447
-        public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
2448
-        {
2449
-            foreach(self::$items as $rs) {
2450
-                if($rs->pad != $pad)       continue;
2451
-                if($rs->nroots != $nroots) continue;
2452
-                if($rs->mm != $symsize)    continue;
2453
-                if($rs->gfpoly != $gfpoly) continue;
2454
-                if($rs->fcr != $fcr)       continue;
2455
-                if($rs->prim != $prim)     continue;
2456
-
2457
-                return $rs;
2458
-            }
2459
-
2460
-            $rs = QRrsItem::init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad);
2461
-            array_unshift(self::$items, $rs);
2462
-
2463
-            return $rs;
2464
-        }
2465
-    }
2446
+		//----------------------------------------------------------------------
2447
+		public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
2448
+		{
2449
+			foreach(self::$items as $rs) {
2450
+				if($rs->pad != $pad)       continue;
2451
+				if($rs->nroots != $nroots) continue;
2452
+				if($rs->mm != $symsize)    continue;
2453
+				if($rs->gfpoly != $gfpoly) continue;
2454
+				if($rs->fcr != $fcr)       continue;
2455
+				if($rs->prim != $prim)     continue;
2456
+
2457
+				return $rs;
2458
+			}
2459
+
2460
+			$rs = QRrsItem::init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad);
2461
+			array_unshift(self::$items, $rs);
2462
+
2463
+			return $rs;
2464
+		}
2465
+	}
2466 2466
 
2467 2467
 
2468 2468
 
@@ -2508,296 +2508,296 @@  discard block
 block discarded – undo
2508 2508
 		
2509 2509
 		//----------------------------------------------------------------------
2510 2510
 		public function __construct() 
2511
-        {
2512
-            $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0);
2513
-        }
2514
-        
2515
-        //----------------------------------------------------------------------
2516
-        public function writeFormatInformation($width, &$frame, $mask, $level)
2517
-        {
2518
-            $blacks = 0;
2519
-            $format =  QRspec::getFormatInfo($mask, $level);
2520
-
2521
-            for($i=0; $i<8; $i++) {
2522
-                if($format & 1) {
2523
-                    $blacks += 2;
2524
-                    $v = 0x85;
2525
-                } else {
2526
-                    $v = 0x84;
2527
-                }
2511
+		{
2512
+			$this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0);
2513
+		}
2514
+        
2515
+		//----------------------------------------------------------------------
2516
+		public function writeFormatInformation($width, &$frame, $mask, $level)
2517
+		{
2518
+			$blacks = 0;
2519
+			$format =  QRspec::getFormatInfo($mask, $level);
2520
+
2521
+			for($i=0; $i<8; $i++) {
2522
+				if($format & 1) {
2523
+					$blacks += 2;
2524
+					$v = 0x85;
2525
+				} else {
2526
+					$v = 0x84;
2527
+				}
2528 2528
                 
2529
-                $frame[8][$width - 1 - $i] = chr($v);
2530
-                if($i < 6) {
2531
-                    $frame[$i][8] = chr($v);
2532
-                } else {
2533
-                    $frame[$i + 1][8] = chr($v);
2534
-                }
2535
-                $format = $format >> 1;
2536
-            }
2537
-            
2538
-            for($i=0; $i<7; $i++) {
2539
-                if($format & 1) {
2540
-                    $blacks += 2;
2541
-                    $v = 0x85;
2542
-                } else {
2543
-                    $v = 0x84;
2544
-                }
2529
+				$frame[8][$width - 1 - $i] = chr($v);
2530
+				if($i < 6) {
2531
+					$frame[$i][8] = chr($v);
2532
+				} else {
2533
+					$frame[$i + 1][8] = chr($v);
2534
+				}
2535
+				$format = $format >> 1;
2536
+			}
2537
+            
2538
+			for($i=0; $i<7; $i++) {
2539
+				if($format & 1) {
2540
+					$blacks += 2;
2541
+					$v = 0x85;
2542
+				} else {
2543
+					$v = 0x84;
2544
+				}
2545 2545
                 
2546
-                $frame[$width - 7 + $i][8] = chr($v);
2547
-                if($i == 0) {
2548
-                    $frame[8][7] = chr($v);
2549
-                } else {
2550
-                    $frame[8][6 - $i] = chr($v);
2551
-                }
2546
+				$frame[$width - 7 + $i][8] = chr($v);
2547
+				if($i == 0) {
2548
+					$frame[8][7] = chr($v);
2549
+				} else {
2550
+					$frame[8][6 - $i] = chr($v);
2551
+				}
2552 2552
                 
2553
-                $format = $format >> 1;
2554
-            }
2555
-
2556
-            return $blacks;
2557
-        }
2558
-        
2559
-        //----------------------------------------------------------------------
2560
-        public function mask0($x, $y) { return ($x+$y)&1;                       }
2561
-        public function mask1($x, $y) { return ($y&1);                          }
2562
-        public function mask2($x, $y) { return ($x%3);                          }
2563
-        public function mask3($x, $y) { return ($x+$y)%3;                       }
2564
-        public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; }
2565
-        public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3;           }
2566
-        public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1;       }
2567
-        public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1;     }
2568
-        
2569
-        //----------------------------------------------------------------------
2570
-        private function generateMaskNo($maskNo, $width, $frame)
2571
-        {
2572
-            $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
2573
-            
2574
-            for($y=0; $y<$width; $y++) {
2575
-                for($x=0; $x<$width; $x++) {
2576
-                    if(ord($frame[$y][$x]) & 0x80) {
2577
-                        $bitMask[$y][$x] = 0;
2578
-                    } else {
2579
-                        $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y);
2580
-                        $bitMask[$y][$x] = ($maskFunc == 0)?1:0;
2581
-                    }
2553
+				$format = $format >> 1;
2554
+			}
2555
+
2556
+			return $blacks;
2557
+		}
2558
+        
2559
+		//----------------------------------------------------------------------
2560
+		public function mask0($x, $y) { return ($x+$y)&1;                       }
2561
+		public function mask1($x, $y) { return ($y&1);                          }
2562
+		public function mask2($x, $y) { return ($x%3);                          }
2563
+		public function mask3($x, $y) { return ($x+$y)%3;                       }
2564
+		public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; }
2565
+		public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3;           }
2566
+		public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1;       }
2567
+		public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1;     }
2568
+        
2569
+		//----------------------------------------------------------------------
2570
+		private function generateMaskNo($maskNo, $width, $frame)
2571
+		{
2572
+			$bitMask = array_fill(0, $width, array_fill(0, $width, 0));
2573
+            
2574
+			for($y=0; $y<$width; $y++) {
2575
+				for($x=0; $x<$width; $x++) {
2576
+					if(ord($frame[$y][$x]) & 0x80) {
2577
+						$bitMask[$y][$x] = 0;
2578
+					} else {
2579
+						$maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y);
2580
+						$bitMask[$y][$x] = ($maskFunc == 0)?1:0;
2581
+					}
2582 2582
                     
2583
-                }
2584
-            }
2583
+				}
2584
+			}
2585 2585
             
2586
-            return $bitMask;
2587
-        }
2586
+			return $bitMask;
2587
+		}
2588 2588
         
2589
-        //----------------------------------------------------------------------
2590
-        public static function serial($bitFrame)
2591
-        {
2592
-            $codeArr = array();
2589
+		//----------------------------------------------------------------------
2590
+		public static function serial($bitFrame)
2591
+		{
2592
+			$codeArr = array();
2593 2593
             
2594
-            foreach ($bitFrame as $line)
2595
-                $codeArr[] = join('', $line);
2594
+			foreach ($bitFrame as $line)
2595
+				$codeArr[] = join('', $line);
2596 2596
                 
2597
-            return gzcompress(join("\n", $codeArr), 9);
2598
-        }
2599
-        
2600
-        //----------------------------------------------------------------------
2601
-        public static function unserial($code)
2602
-        {
2603
-            $codeArr = array();
2604
-            
2605
-            $codeLines = explode("\n", gzuncompress($code));
2606
-            foreach ($codeLines as $line)
2607
-                $codeArr[] = str_split($line);
2608
-            
2609
-            return $codeArr;
2610
-        }
2611
-        
2612
-        //----------------------------------------------------------------------
2613
-        public function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false) 
2614
-        {
2615
-            $b = 0;
2616
-            $bitMask = array();
2617
-            
2618
-            $fileName = QR_CACHE_DIR.'mask_'.$maskNo.DIRECTORY_SEPARATOR.'mask_'.$width.'_'.$maskNo.'.dat';
2619
-
2620
-            if (QR_CACHEABLE) {
2621
-                if (file_exists($fileName)) {
2622
-                    $bitMask = self::unserial(file_get_contents($fileName));
2623
-                } else {
2624
-                    $bitMask = $this->generateMaskNo($maskNo, $width, $s);
2625
-                    if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo))
2626
-                        mkdir(QR_CACHE_DIR.'mask_'.$maskNo);
2627
-                    file_put_contents($fileName, self::serial($bitMask));
2628
-                }
2629
-            } else {
2630
-                $bitMask = $this->generateMaskNo($maskNo, $width, $s);
2631
-            }
2632
-
2633
-            if ($maskGenOnly)
2634
-                return;
2597
+			return gzcompress(join("\n", $codeArr), 9);
2598
+		}
2599
+        
2600
+		//----------------------------------------------------------------------
2601
+		public static function unserial($code)
2602
+		{
2603
+			$codeArr = array();
2604
+            
2605
+			$codeLines = explode("\n", gzuncompress($code));
2606
+			foreach ($codeLines as $line)
2607
+				$codeArr[] = str_split($line);
2608
+            
2609
+			return $codeArr;
2610
+		}
2611
+        
2612
+		//----------------------------------------------------------------------
2613
+		public function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false) 
2614
+		{
2615
+			$b = 0;
2616
+			$bitMask = array();
2617
+            
2618
+			$fileName = QR_CACHE_DIR.'mask_'.$maskNo.DIRECTORY_SEPARATOR.'mask_'.$width.'_'.$maskNo.'.dat';
2619
+
2620
+			if (QR_CACHEABLE) {
2621
+				if (file_exists($fileName)) {
2622
+					$bitMask = self::unserial(file_get_contents($fileName));
2623
+				} else {
2624
+					$bitMask = $this->generateMaskNo($maskNo, $width, $s);
2625
+					if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo))
2626
+						mkdir(QR_CACHE_DIR.'mask_'.$maskNo);
2627
+					file_put_contents($fileName, self::serial($bitMask));
2628
+				}
2629
+			} else {
2630
+				$bitMask = $this->generateMaskNo($maskNo, $width, $s);
2631
+			}
2632
+
2633
+			if ($maskGenOnly)
2634
+				return;
2635 2635
                 
2636
-            $d = $s;
2637
-
2638
-            for($y=0; $y<$width; $y++) {
2639
-                for($x=0; $x<$width; $x++) {
2640
-                    if($bitMask[$y][$x] == 1) {
2641
-                        $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]);
2642
-                    }
2643
-                    $b += (int)(ord($d[$y][$x]) & 1);
2644
-                }
2645
-            }
2646
-
2647
-            return $b;
2648
-        }
2649
-        
2650
-        //----------------------------------------------------------------------
2651
-        public function makeMask($width, $frame, $maskNo, $level)
2652
-        {
2653
-            $masked = array_fill(0, $width, str_repeat("\0", $width));
2654
-            $this->makeMaskNo($maskNo, $width, $frame, $masked);
2655
-            $this->writeFormatInformation($width, $masked, $maskNo, $level);
2636
+			$d = $s;
2637
+
2638
+			for($y=0; $y<$width; $y++) {
2639
+				for($x=0; $x<$width; $x++) {
2640
+					if($bitMask[$y][$x] == 1) {
2641
+						$d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]);
2642
+					}
2643
+					$b += (int)(ord($d[$y][$x]) & 1);
2644
+				}
2645
+			}
2646
+
2647
+			return $b;
2648
+		}
2649
+        
2650
+		//----------------------------------------------------------------------
2651
+		public function makeMask($width, $frame, $maskNo, $level)
2652
+		{
2653
+			$masked = array_fill(0, $width, str_repeat("\0", $width));
2654
+			$this->makeMaskNo($maskNo, $width, $frame, $masked);
2655
+			$this->writeFormatInformation($width, $masked, $maskNo, $level);
2656 2656
        
2657
-            return $masked;
2658
-        }
2657
+			return $masked;
2658
+		}
2659 2659
         
2660
-        //----------------------------------------------------------------------
2661
-        public function calcN1N3($length)
2662
-        {
2663
-            $demerit = 0;
2660
+		//----------------------------------------------------------------------
2661
+		public function calcN1N3($length)
2662
+		{
2663
+			$demerit = 0;
2664 2664
 
2665
-            for($i=0; $i<$length; $i++) {
2665
+			for($i=0; $i<$length; $i++) {
2666 2666
                 
2667
-                if($this->runLength[$i] >= 5) {
2668
-                    $demerit += (N1 + ($this->runLength[$i] - 5));
2669
-                }
2670
-                if($i & 1) {
2671
-                    if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) {
2672
-                        $fact = (int)($this->runLength[$i] / 3);
2673
-                        if(($this->runLength[$i-2] == $fact) &&
2674
-                           ($this->runLength[$i-1] == $fact) &&
2675
-                           ($this->runLength[$i+1] == $fact) &&
2676
-                           ($this->runLength[$i+2] == $fact)) {
2677
-                            if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) {
2678
-                                $demerit += N3;
2679
-                            } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) {
2680
-                                $demerit += N3;
2681
-                            }
2682
-                        }
2683
-                    }
2684
-                }
2685
-            }
2686
-            return $demerit;
2687
-        }
2688
-        
2689
-        //----------------------------------------------------------------------
2690
-        public function evaluateSymbol($width, $frame)
2691
-        {
2692
-            $head = 0;
2693
-            $demerit = 0;
2694
-
2695
-            for($y=0; $y<$width; $y++) {
2696
-                $head = 0;
2697
-                $this->runLength[0] = 1;
2667
+				if($this->runLength[$i] >= 5) {
2668
+					$demerit += (N1 + ($this->runLength[$i] - 5));
2669
+				}
2670
+				if($i & 1) {
2671
+					if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) {
2672
+						$fact = (int)($this->runLength[$i] / 3);
2673
+						if(($this->runLength[$i-2] == $fact) &&
2674
+						   ($this->runLength[$i-1] == $fact) &&
2675
+						   ($this->runLength[$i+1] == $fact) &&
2676
+						   ($this->runLength[$i+2] == $fact)) {
2677
+							if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) {
2678
+								$demerit += N3;
2679
+							} else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) {
2680
+								$demerit += N3;
2681
+							}
2682
+						}
2683
+					}
2684
+				}
2685
+			}
2686
+			return $demerit;
2687
+		}
2688
+        
2689
+		//----------------------------------------------------------------------
2690
+		public function evaluateSymbol($width, $frame)
2691
+		{
2692
+			$head = 0;
2693
+			$demerit = 0;
2694
+
2695
+			for($y=0; $y<$width; $y++) {
2696
+				$head = 0;
2697
+				$this->runLength[0] = 1;
2698 2698
                 
2699
-                $frameY = $frame[$y];
2699
+				$frameY = $frame[$y];
2700 2700
                 
2701
-                if ($y>0)
2702
-                    $frameYM = $frame[$y-1];
2701
+				if ($y>0)
2702
+					$frameYM = $frame[$y-1];
2703 2703
                 
2704
-                for($x=0; $x<$width; $x++) {
2705
-                    if(($x > 0) && ($y > 0)) {
2706
-                        $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]);
2707
-                        $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]);
2704
+				for($x=0; $x<$width; $x++) {
2705
+					if(($x > 0) && ($y > 0)) {
2706
+						$b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]);
2707
+						$w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]);
2708 2708
                         
2709
-                        if(($b22 | ($w22 ^ 1))&1) {                                                                     
2710
-                            $demerit += N2;
2711
-                        }
2712
-                    }
2713
-                    if(($x == 0) && (ord($frameY[$x]) & 1)) {
2714
-                        $this->runLength[0] = -1;
2715
-                        $head = 1;
2716
-                        $this->runLength[$head] = 1;
2717
-                    } else if($x > 0) {
2718
-                        if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) {
2719
-                            $head++;
2720
-                            $this->runLength[$head] = 1;
2721
-                        } else {
2722
-                            $this->runLength[$head]++;
2723
-                        }
2724
-                    }
2725
-                }
2709
+						if(($b22 | ($w22 ^ 1))&1) {                                                                     
2710
+							$demerit += N2;
2711
+						}
2712
+					}
2713
+					if(($x == 0) && (ord($frameY[$x]) & 1)) {
2714
+						$this->runLength[0] = -1;
2715
+						$head = 1;
2716
+						$this->runLength[$head] = 1;
2717
+					} else if($x > 0) {
2718
+						if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) {
2719
+							$head++;
2720
+							$this->runLength[$head] = 1;
2721
+						} else {
2722
+							$this->runLength[$head]++;
2723
+						}
2724
+					}
2725
+				}
2726 2726
     
2727
-                $demerit += $this->calcN1N3($head+1);
2728
-            }
2727
+				$demerit += $this->calcN1N3($head+1);
2728
+			}
2729 2729
 
2730
-            for($x=0; $x<$width; $x++) {
2731
-                $head = 0;
2732
-                $this->runLength[0] = 1;
2730
+			for($x=0; $x<$width; $x++) {
2731
+				$head = 0;
2732
+				$this->runLength[0] = 1;
2733 2733
                 
2734
-                for($y=0; $y<$width; $y++) {
2735
-                    if($y == 0 && (ord($frame[$y][$x]) & 1)) {
2736
-                        $this->runLength[0] = -1;
2737
-                        $head = 1;
2738
-                        $this->runLength[$head] = 1;
2739
-                    } else if($y > 0) {
2740
-                        if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) {
2741
-                            $head++;
2742
-                            $this->runLength[$head] = 1;
2743
-                        } else {
2744
-                            $this->runLength[$head]++;
2745
-                        }
2746
-                    }
2747
-                }
2748
-            
2749
-                $demerit += $this->calcN1N3($head+1);
2750
-            }
2751
-
2752
-            return $demerit;
2753
-        }
2754
-        
2755
-        
2756
-        //----------------------------------------------------------------------
2757
-        public function mask($width, $frame, $level)
2758
-        {
2759
-            $minDemerit = PHP_INT_MAX;
2760
-            $bestMaskNum = 0;
2761
-            $bestMask = array();
2762
-            
2763
-            $checked_masks = array(0,1,2,3,4,5,6,7);
2764
-            
2765
-            if (QR_FIND_FROM_RANDOM !== false) {
2766
-            
2767
-                $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9);
2768
-                for ($i = 0; $i <  $howManuOut; $i++) {
2769
-                    $remPos = rand (0, count($checked_masks)-1);
2770
-                    unset($checked_masks[$remPos]);
2771
-                    $checked_masks = array_values($checked_masks);
2772
-                }
2773
-            
2774
-            }
2775
-            
2776
-            $bestMask = $frame;
2734
+				for($y=0; $y<$width; $y++) {
2735
+					if($y == 0 && (ord($frame[$y][$x]) & 1)) {
2736
+						$this->runLength[0] = -1;
2737
+						$head = 1;
2738
+						$this->runLength[$head] = 1;
2739
+					} else if($y > 0) {
2740
+						if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) {
2741
+							$head++;
2742
+							$this->runLength[$head] = 1;
2743
+						} else {
2744
+							$this->runLength[$head]++;
2745
+						}
2746
+					}
2747
+				}
2748
+            
2749
+				$demerit += $this->calcN1N3($head+1);
2750
+			}
2751
+
2752
+			return $demerit;
2753
+		}
2754
+        
2755
+        
2756
+		//----------------------------------------------------------------------
2757
+		public function mask($width, $frame, $level)
2758
+		{
2759
+			$minDemerit = PHP_INT_MAX;
2760
+			$bestMaskNum = 0;
2761
+			$bestMask = array();
2762
+            
2763
+			$checked_masks = array(0,1,2,3,4,5,6,7);
2764
+            
2765
+			if (QR_FIND_FROM_RANDOM !== false) {
2766
+            
2767
+				$howManuOut = 8-(QR_FIND_FROM_RANDOM % 9);
2768
+				for ($i = 0; $i <  $howManuOut; $i++) {
2769
+					$remPos = rand (0, count($checked_masks)-1);
2770
+					unset($checked_masks[$remPos]);
2771
+					$checked_masks = array_values($checked_masks);
2772
+				}
2773
+            
2774
+			}
2775
+            
2776
+			$bestMask = $frame;
2777 2777
              
2778
-            foreach($checked_masks as $i) {
2779
-                $mask = array_fill(0, $width, str_repeat("\0", $width));
2780
-
2781
-                $demerit = 0;
2782
-                $blacks = 0;
2783
-                $blacks  = $this->makeMaskNo($i, $width, $frame, $mask);
2784
-                $blacks += $this->writeFormatInformation($width, $mask, $i, $level);
2785
-                $blacks  = (int)(100 * $blacks / ($width * $width));
2786
-                $demerit = (int)((int)(abs($blacks - 50) / 5) * N4);
2787
-                $demerit += $this->evaluateSymbol($width, $mask);
2778
+			foreach($checked_masks as $i) {
2779
+				$mask = array_fill(0, $width, str_repeat("\0", $width));
2780
+
2781
+				$demerit = 0;
2782
+				$blacks = 0;
2783
+				$blacks  = $this->makeMaskNo($i, $width, $frame, $mask);
2784
+				$blacks += $this->writeFormatInformation($width, $mask, $i, $level);
2785
+				$blacks  = (int)(100 * $blacks / ($width * $width));
2786
+				$demerit = (int)((int)(abs($blacks - 50) / 5) * N4);
2787
+				$demerit += $this->evaluateSymbol($width, $mask);
2788 2788
                 
2789
-                if($demerit < $minDemerit) {
2790
-                    $minDemerit = $demerit;
2791
-                    $bestMask = $mask;
2792
-                    $bestMaskNum = $i;
2793
-                }
2794
-            }
2795
-            
2796
-            return $bestMask;
2797
-        }
2789
+				if($demerit < $minDemerit) {
2790
+					$minDemerit = $demerit;
2791
+					$bestMask = $mask;
2792
+					$bestMaskNum = $i;
2793
+				}
2794
+			}
2795
+            
2796
+			return $bestMask;
2797
+		}
2798 2798
         
2799
-        //----------------------------------------------------------------------
2800
-    }
2799
+		//----------------------------------------------------------------------
2800
+	}
2801 2801
 
2802 2802
 
2803 2803
 
@@ -2833,480 +2833,480 @@  discard block
 block discarded – undo
2833 2833
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2834 2834
  */
2835 2835
  
2836
-    class QRrsblock {
2837
-        public $dataLength;
2838
-        public $data = array();
2839
-        public $eccLength;
2840
-        public $ecc = array();
2841
-        
2842
-        public function __construct($dl, $data, $el, &$ecc, QRrsItem $rs)
2843
-        {
2844
-            $rs->encode_rs_char($data, $ecc);
2845
-        
2846
-            $this->dataLength = $dl;
2847
-            $this->data = $data;
2848
-            $this->eccLength = $el;
2849
-            $this->ecc = $ecc;
2850
-        }
2851
-    };
2836
+	class QRrsblock {
2837
+		public $dataLength;
2838
+		public $data = array();
2839
+		public $eccLength;
2840
+		public $ecc = array();
2841
+        
2842
+		public function __construct($dl, $data, $el, &$ecc, QRrsItem $rs)
2843
+		{
2844
+			$rs->encode_rs_char($data, $ecc);
2845
+        
2846
+			$this->dataLength = $dl;
2847
+			$this->data = $data;
2848
+			$this->eccLength = $el;
2849
+			$this->ecc = $ecc;
2850
+		}
2851
+	};
2852 2852
     
2853
-    //##########################################################################
2854
-
2855
-    class QRrawcode {
2856
-        public $version;
2857
-        public $datacode = array();
2858
-        public $ecccode = array();
2859
-        public $blocks;
2860
-        public $rsblocks = array(); //of RSblock
2861
-        public $count;
2862
-        public $dataLength;
2863
-        public $eccLength;
2864
-        public $b1;
2865
-        
2866
-        //----------------------------------------------------------------------
2867
-        public function __construct(QRinput $input)
2868
-        {
2869
-            $spec = array(0,0,0,0,0);
2870
-            
2871
-            $this->datacode = $input->getByteStream();
2872
-            if(is_null($this->datacode)) {
2873
-                throw new Exception('null imput string');
2874
-            }
2875
-
2876
-            QRspec::getEccSpec($input->getVersion(), $input->getErrorCorrectionLevel(), $spec);
2877
-
2878
-            $this->version = $input->getVersion();
2879
-            $this->b1 = QRspec::rsBlockNum1($spec);
2880
-            $this->dataLength = QRspec::rsDataLength($spec);
2881
-            $this->eccLength = QRspec::rsEccLength($spec);
2882
-            $this->ecccode = array_fill(0, $this->eccLength, 0);
2883
-            $this->blocks = QRspec::rsBlockNum($spec);
2884
-            
2885
-            $ret = $this->init($spec);
2886
-            if($ret < 0) {
2887
-                throw new Exception('block alloc error');
2888
-                return null;
2889
-            }
2890
-
2891
-            $this->count = 0;
2892
-        }
2893
-        
2894
-        //----------------------------------------------------------------------
2895
-        public function init(array $spec)
2896
-        {
2897
-            $dl = QRspec::rsDataCodes1($spec);
2898
-            $el = QRspec::rsEccCodes1($spec);
2899
-            $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
2900
-            
2901
-
2902
-            $blockNo = 0;
2903
-            $dataPos = 0;
2904
-            $eccPos = 0;
2905
-            for($i=0; $i<QRspec::rsBlockNum1($spec); $i++) {
2906
-                $ecc = array_slice($this->ecccode,$eccPos);
2907
-                $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el,  $ecc, $rs);
2908
-                $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
2853
+	//##########################################################################
2854
+
2855
+	class QRrawcode {
2856
+		public $version;
2857
+		public $datacode = array();
2858
+		public $ecccode = array();
2859
+		public $blocks;
2860
+		public $rsblocks = array(); //of RSblock
2861
+		public $count;
2862
+		public $dataLength;
2863
+		public $eccLength;
2864
+		public $b1;
2865
+        
2866
+		//----------------------------------------------------------------------
2867
+		public function __construct(QRinput $input)
2868
+		{
2869
+			$spec = array(0,0,0,0,0);
2870
+            
2871
+			$this->datacode = $input->getByteStream();
2872
+			if(is_null($this->datacode)) {
2873
+				throw new Exception('null imput string');
2874
+			}
2875
+
2876
+			QRspec::getEccSpec($input->getVersion(), $input->getErrorCorrectionLevel(), $spec);
2877
+
2878
+			$this->version = $input->getVersion();
2879
+			$this->b1 = QRspec::rsBlockNum1($spec);
2880
+			$this->dataLength = QRspec::rsDataLength($spec);
2881
+			$this->eccLength = QRspec::rsEccLength($spec);
2882
+			$this->ecccode = array_fill(0, $this->eccLength, 0);
2883
+			$this->blocks = QRspec::rsBlockNum($spec);
2884
+            
2885
+			$ret = $this->init($spec);
2886
+			if($ret < 0) {
2887
+				throw new Exception('block alloc error');
2888
+				return null;
2889
+			}
2890
+
2891
+			$this->count = 0;
2892
+		}
2893
+        
2894
+		//----------------------------------------------------------------------
2895
+		public function init(array $spec)
2896
+		{
2897
+			$dl = QRspec::rsDataCodes1($spec);
2898
+			$el = QRspec::rsEccCodes1($spec);
2899
+			$rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
2900
+            
2901
+
2902
+			$blockNo = 0;
2903
+			$dataPos = 0;
2904
+			$eccPos = 0;
2905
+			for($i=0; $i<QRspec::rsBlockNum1($spec); $i++) {
2906
+				$ecc = array_slice($this->ecccode,$eccPos);
2907
+				$this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el,  $ecc, $rs);
2908
+				$this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
2909 2909
                 
2910
-                $dataPos += $dl;
2911
-                $eccPos += $el;
2912
-                $blockNo++;
2913
-            }
2910
+				$dataPos += $dl;
2911
+				$eccPos += $el;
2912
+				$blockNo++;
2913
+			}
2914 2914
 
2915
-            if(QRspec::rsBlockNum2($spec) == 0)
2916
-                return 0;
2915
+			if(QRspec::rsBlockNum2($spec) == 0)
2916
+				return 0;
2917 2917
 
2918
-            $dl = QRspec::rsDataCodes2($spec);
2919
-            $el = QRspec::rsEccCodes2($spec);
2920
-            $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
2918
+			$dl = QRspec::rsDataCodes2($spec);
2919
+			$el = QRspec::rsEccCodes2($spec);
2920
+			$rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
2921 2921
             
2922
-            if($rs == NULL) return -1;
2922
+			if($rs == NULL) return -1;
2923 2923
             
2924
-            for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) {
2925
-                $ecc = array_slice($this->ecccode,$eccPos);
2926
-                $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs);
2927
-                $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
2924
+			for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) {
2925
+				$ecc = array_slice($this->ecccode,$eccPos);
2926
+				$this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs);
2927
+				$this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
2928 2928
                 
2929
-                $dataPos += $dl;
2930
-                $eccPos += $el;
2931
-                $blockNo++;
2932
-            }
2933
-
2934
-            return 0;
2935
-        }
2936
-        
2937
-        //----------------------------------------------------------------------
2938
-        public function getCode()
2939
-        {
2940
-            $ret = 0;
2941
-
2942
-            if($this->count < $this->dataLength) {
2943
-                $row = $this->count % $this->blocks;
2944
-                $col = $this->count / $this->blocks;
2945
-                if($col >= $this->rsblocks[0]->dataLength) {
2946
-                    $row += $this->b1;
2947
-                }
2948
-                $ret = $this->rsblocks[$row]->data[$col];
2949
-            } else if($this->count < $this->dataLength + $this->eccLength) {
2950
-                $row = ($this->count - $this->dataLength) % $this->blocks;
2951
-                $col = ($this->count - $this->dataLength) / $this->blocks;
2952
-                $ret = $this->rsblocks[$row]->ecc[$col];
2953
-            } else {
2954
-                return 0;
2955
-            }
2956
-            $this->count++;
2957
-            
2958
-            return $ret;
2959
-        }
2960
-    }
2961
-
2962
-    //##########################################################################
2929
+				$dataPos += $dl;
2930
+				$eccPos += $el;
2931
+				$blockNo++;
2932
+			}
2933
+
2934
+			return 0;
2935
+		}
2936
+        
2937
+		//----------------------------------------------------------------------
2938
+		public function getCode()
2939
+		{
2940
+			$ret = 0;
2941
+
2942
+			if($this->count < $this->dataLength) {
2943
+				$row = $this->count % $this->blocks;
2944
+				$col = $this->count / $this->blocks;
2945
+				if($col >= $this->rsblocks[0]->dataLength) {
2946
+					$row += $this->b1;
2947
+				}
2948
+				$ret = $this->rsblocks[$row]->data[$col];
2949
+			} else if($this->count < $this->dataLength + $this->eccLength) {
2950
+				$row = ($this->count - $this->dataLength) % $this->blocks;
2951
+				$col = ($this->count - $this->dataLength) / $this->blocks;
2952
+				$ret = $this->rsblocks[$row]->ecc[$col];
2953
+			} else {
2954
+				return 0;
2955
+			}
2956
+			$this->count++;
2957
+            
2958
+			return $ret;
2959
+		}
2960
+	}
2961
+
2962
+	//##########################################################################
2963 2963
     
2964
-    class QRcode {
2964
+	class QRcode {
2965 2965
     
2966
-        public $version;
2967
-        public $width;
2968
-        public $data; 
2969
-        
2970
-        //----------------------------------------------------------------------
2971
-        public function encodeMask(QRinput $input, $mask)
2972
-        {
2973
-            if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) {
2974
-                throw new Exception('wrong version');
2975
-            }
2976
-            if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) {
2977
-                throw new Exception('wrong level');
2978
-            }
2979
-
2980
-            $raw = new QRrawcode($input);
2981
-            
2982
-            QRtools::markTime('after_raw');
2983
-            
2984
-            $version = $raw->version;
2985
-            $width = QRspec::getWidth($version);
2986
-            $frame = QRspec::newFrame($version);
2987
-            
2988
-            $filler = new FrameFiller($width, $frame);
2989
-            if(is_null($filler)) {
2990
-                return NULL;
2991
-            }
2992
-
2993
-            // inteleaved data and ecc codes
2994
-            for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) {
2995
-                $code = $raw->getCode();
2996
-                $bit = 0x80;
2997
-                for($j=0; $j<8; $j++) {
2998
-                    $addr = $filler->next();
2999
-                    $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0));
3000
-                    $bit = $bit >> 1;
3001
-                }
3002
-            }
3003
-            
3004
-            QRtools::markTime('after_filler');
3005
-            
3006
-            unset($raw);
3007
-            
3008
-            // remainder bits
3009
-            $j = QRspec::getRemainder($version);
3010
-            for($i=0; $i<$j; $i++) {
3011
-                $addr = $filler->next();
3012
-                $filler->setFrameAt($addr, 0x02);
3013
-            }
3014
-            
3015
-            $frame = $filler->frame;
3016
-            unset($filler);
3017
-            
3018
-            
3019
-            // masking
3020
-            $maskObj = new QRmask();
3021
-            if($mask < 0) {
3022
-            
3023
-                if (QR_FIND_BEST_MASK) {
3024
-                    $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel());
3025
-                } else {
3026
-                    $masked = $maskObj->makeMask($width, $frame, (intval(QR_DEFAULT_MASK) % 8), $input->getErrorCorrectionLevel());
3027
-                }
3028
-            } else {
3029
-                $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel());
3030
-            }
3031
-            
3032
-            if($masked == NULL) {
3033
-                return NULL;
3034
-            }
3035
-            
3036
-            QRtools::markTime('after_mask');
3037
-            
3038
-            $this->version = $version;
3039
-            $this->width = $width;
3040
-            $this->data = $masked;
3041
-            
3042
-            return $this;
3043
-        }
2966
+		public $version;
2967
+		public $width;
2968
+		public $data; 
2969
+        
2970
+		//----------------------------------------------------------------------
2971
+		public function encodeMask(QRinput $input, $mask)
2972
+		{
2973
+			if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) {
2974
+				throw new Exception('wrong version');
2975
+			}
2976
+			if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) {
2977
+				throw new Exception('wrong level');
2978
+			}
2979
+
2980
+			$raw = new QRrawcode($input);
2981
+            
2982
+			QRtools::markTime('after_raw');
2983
+            
2984
+			$version = $raw->version;
2985
+			$width = QRspec::getWidth($version);
2986
+			$frame = QRspec::newFrame($version);
2987
+            
2988
+			$filler = new FrameFiller($width, $frame);
2989
+			if(is_null($filler)) {
2990
+				return NULL;
2991
+			}
2992
+
2993
+			// inteleaved data and ecc codes
2994
+			for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) {
2995
+				$code = $raw->getCode();
2996
+				$bit = 0x80;
2997
+				for($j=0; $j<8; $j++) {
2998
+					$addr = $filler->next();
2999
+					$filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0));
3000
+					$bit = $bit >> 1;
3001
+				}
3002
+			}
3003
+            
3004
+			QRtools::markTime('after_filler');
3005
+            
3006
+			unset($raw);
3007
+            
3008
+			// remainder bits
3009
+			$j = QRspec::getRemainder($version);
3010
+			for($i=0; $i<$j; $i++) {
3011
+				$addr = $filler->next();
3012
+				$filler->setFrameAt($addr, 0x02);
3013
+			}
3014
+            
3015
+			$frame = $filler->frame;
3016
+			unset($filler);
3017
+            
3018
+            
3019
+			// masking
3020
+			$maskObj = new QRmask();
3021
+			if($mask < 0) {
3022
+            
3023
+				if (QR_FIND_BEST_MASK) {
3024
+					$masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel());
3025
+				} else {
3026
+					$masked = $maskObj->makeMask($width, $frame, (intval(QR_DEFAULT_MASK) % 8), $input->getErrorCorrectionLevel());
3027
+				}
3028
+			} else {
3029
+				$masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel());
3030
+			}
3031
+            
3032
+			if($masked == NULL) {
3033
+				return NULL;
3034
+			}
3035
+            
3036
+			QRtools::markTime('after_mask');
3037
+            
3038
+			$this->version = $version;
3039
+			$this->width = $width;
3040
+			$this->data = $masked;
3041
+            
3042
+			return $this;
3043
+		}
3044 3044
     
3045
-        //----------------------------------------------------------------------
3046
-        public function encodeInput(QRinput $input)
3047
-        {
3048
-            return $this->encodeMask($input, -1);
3049
-        }
3050
-        
3051
-        //----------------------------------------------------------------------
3052
-        public function encodeString8bit($string, $version, $level)
3053
-        {
3054
-            if(string == NULL) {
3055
-                throw new Exception('empty string!');
3056
-                return NULL;
3057
-            }
3058
-
3059
-            $input = new QRinput($version, $level);
3060
-            if($input == NULL) return NULL;
3061
-
3062
-            $ret = $input->append(QR_MODE_8, strlen($string), str_split($string));
3063
-            if($ret < 0) {
3064
-                unset($input);
3065
-                return NULL;
3066
-            }
3067
-            return $this->encodeInput($input);
3068
-        }
3069
-
3070
-        //----------------------------------------------------------------------
3071
-        public function encodeString($string, $version, $level, $hint, $casesensitive)
3072
-        {
3073
-
3074
-            if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) {
3075
-                throw new Exception('bad hint');
3076
-                return NULL;
3077
-            }
3078
-
3079
-            $input = new QRinput($version, $level);
3080
-            if($input == NULL) return NULL;
3081
-
3082
-            $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive);
3083
-            if($ret < 0) {
3084
-                return NULL;
3085
-            }
3086
-
3087
-            return $this->encodeInput($input);
3088
-        }
3089
-        
3090
-        //----------------------------------------------------------------------
3091
-        public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false) 
3092
-        {
3093
-            $enc = QRencode::factory($level, $size, $margin);
3094
-            return $enc->encodePNG($text, $outfile, $saveandprint=false);
3095
-        }
3096
-
3097
-        //----------------------------------------------------------------------
3098
-        public static function text($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) 
3099
-        {
3100
-            $enc = QRencode::factory($level, $size, $margin);
3101
-            return $enc->encode($text, $outfile);
3102
-        }
3103
-
3104
-        //----------------------------------------------------------------------
3105
-        public static function raw($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) 
3106
-        {
3107
-            $enc = QRencode::factory($level, $size, $margin);
3108
-            return $enc->encodeRAW($text, $outfile);
3109
-        }
3110
-    }
3045
+		//----------------------------------------------------------------------
3046
+		public function encodeInput(QRinput $input)
3047
+		{
3048
+			return $this->encodeMask($input, -1);
3049
+		}
3050
+        
3051
+		//----------------------------------------------------------------------
3052
+		public function encodeString8bit($string, $version, $level)
3053
+		{
3054
+			if(string == NULL) {
3055
+				throw new Exception('empty string!');
3056
+				return NULL;
3057
+			}
3058
+
3059
+			$input = new QRinput($version, $level);
3060
+			if($input == NULL) return NULL;
3061
+
3062
+			$ret = $input->append(QR_MODE_8, strlen($string), str_split($string));
3063
+			if($ret < 0) {
3064
+				unset($input);
3065
+				return NULL;
3066
+			}
3067
+			return $this->encodeInput($input);
3068
+		}
3069
+
3070
+		//----------------------------------------------------------------------
3071
+		public function encodeString($string, $version, $level, $hint, $casesensitive)
3072
+		{
3073
+
3074
+			if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) {
3075
+				throw new Exception('bad hint');
3076
+				return NULL;
3077
+			}
3078
+
3079
+			$input = new QRinput($version, $level);
3080
+			if($input == NULL) return NULL;
3081
+
3082
+			$ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive);
3083
+			if($ret < 0) {
3084
+				return NULL;
3085
+			}
3086
+
3087
+			return $this->encodeInput($input);
3088
+		}
3089
+        
3090
+		//----------------------------------------------------------------------
3091
+		public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false) 
3092
+		{
3093
+			$enc = QRencode::factory($level, $size, $margin);
3094
+			return $enc->encodePNG($text, $outfile, $saveandprint=false);
3095
+		}
3096
+
3097
+		//----------------------------------------------------------------------
3098
+		public static function text($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) 
3099
+		{
3100
+			$enc = QRencode::factory($level, $size, $margin);
3101
+			return $enc->encode($text, $outfile);
3102
+		}
3103
+
3104
+		//----------------------------------------------------------------------
3105
+		public static function raw($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) 
3106
+		{
3107
+			$enc = QRencode::factory($level, $size, $margin);
3108
+			return $enc->encodeRAW($text, $outfile);
3109
+		}
3110
+	}
3111 3111
     
3112
-    //##########################################################################
3112
+	//##########################################################################
3113 3113
     
3114
-    class FrameFiller {
3114
+	class FrameFiller {
3115 3115
     
3116
-        public $width;
3117
-        public $frame;
3118
-        public $x;
3119
-        public $y;
3120
-        public $dir;
3121
-        public $bit;
3122
-        
3123
-        //----------------------------------------------------------------------
3124
-        public function __construct($width, &$frame)
3125
-        {
3126
-            $this->width = $width;
3127
-            $this->frame = $frame;
3128
-            $this->x = $width - 1;
3129
-            $this->y = $width - 1;
3130
-            $this->dir = -1;
3131
-            $this->bit = -1;
3132
-        }
3133
-        
3134
-        //----------------------------------------------------------------------
3135
-        public function setFrameAt($at, $val)
3136
-        {
3137
-            $this->frame[$at['y']][$at['x']] = chr($val);
3138
-        }
3139
-        
3140
-        //----------------------------------------------------------------------
3141
-        public function getFrameAt($at)
3142
-        {
3143
-            return ord($this->frame[$at['y']][$at['x']]);
3144
-        }
3145
-        
3146
-        //----------------------------------------------------------------------
3147
-        public function next()
3148
-        {
3149
-            do {
3150
-            
3151
-                if($this->bit == -1) {
3152
-                    $this->bit = 0;
3153
-                    return array('x'=>$this->x, 'y'=>$this->y);
3154
-                }
3155
-
3156
-                $x = $this->x;
3157
-                $y = $this->y;
3158
-                $w = $this->width;
3159
-
3160
-                if($this->bit == 0) {
3161
-                    $x--;
3162
-                    $this->bit++;
3163
-                } else {
3164
-                    $x++;
3165
-                    $y += $this->dir;
3166
-                    $this->bit--;
3167
-                }
3168
-
3169
-                if($this->dir < 0) {
3170
-                    if($y < 0) {
3171
-                        $y = 0;
3172
-                        $x -= 2;
3173
-                        $this->dir = 1;
3174
-                        if($x == 6) {
3175
-                            $x--;
3176
-                            $y = 9;
3177
-                        }
3178
-                    }
3179
-                } else {
3180
-                    if($y == $w) {
3181
-                        $y = $w - 1;
3182
-                        $x -= 2;
3183
-                        $this->dir = -1;
3184
-                        if($x == 6) {
3185
-                            $x--;
3186
-                            $y -= 8;
3187
-                        }
3188
-                    }
3189
-                }
3190
-                if($x < 0 || $y < 0) return null;
3191
-
3192
-                $this->x = $x;
3193
-                $this->y = $y;
3194
-
3195
-            } while(ord($this->frame[$y][$x]) & 0x80);
3116
+		public $width;
3117
+		public $frame;
3118
+		public $x;
3119
+		public $y;
3120
+		public $dir;
3121
+		public $bit;
3122
+        
3123
+		//----------------------------------------------------------------------
3124
+		public function __construct($width, &$frame)
3125
+		{
3126
+			$this->width = $width;
3127
+			$this->frame = $frame;
3128
+			$this->x = $width - 1;
3129
+			$this->y = $width - 1;
3130
+			$this->dir = -1;
3131
+			$this->bit = -1;
3132
+		}
3133
+        
3134
+		//----------------------------------------------------------------------
3135
+		public function setFrameAt($at, $val)
3136
+		{
3137
+			$this->frame[$at['y']][$at['x']] = chr($val);
3138
+		}
3139
+        
3140
+		//----------------------------------------------------------------------
3141
+		public function getFrameAt($at)
3142
+		{
3143
+			return ord($this->frame[$at['y']][$at['x']]);
3144
+		}
3145
+        
3146
+		//----------------------------------------------------------------------
3147
+		public function next()
3148
+		{
3149
+			do {
3150
+            
3151
+				if($this->bit == -1) {
3152
+					$this->bit = 0;
3153
+					return array('x'=>$this->x, 'y'=>$this->y);
3154
+				}
3155
+
3156
+				$x = $this->x;
3157
+				$y = $this->y;
3158
+				$w = $this->width;
3159
+
3160
+				if($this->bit == 0) {
3161
+					$x--;
3162
+					$this->bit++;
3163
+				} else {
3164
+					$x++;
3165
+					$y += $this->dir;
3166
+					$this->bit--;
3167
+				}
3168
+
3169
+				if($this->dir < 0) {
3170
+					if($y < 0) {
3171
+						$y = 0;
3172
+						$x -= 2;
3173
+						$this->dir = 1;
3174
+						if($x == 6) {
3175
+							$x--;
3176
+							$y = 9;
3177
+						}
3178
+					}
3179
+				} else {
3180
+					if($y == $w) {
3181
+						$y = $w - 1;
3182
+						$x -= 2;
3183
+						$this->dir = -1;
3184
+						if($x == 6) {
3185
+							$x--;
3186
+							$y -= 8;
3187
+						}
3188
+					}
3189
+				}
3190
+				if($x < 0 || $y < 0) return null;
3191
+
3192
+				$this->x = $x;
3193
+				$this->y = $y;
3194
+
3195
+			} while(ord($this->frame[$y][$x]) & 0x80);
3196 3196
                         
3197
-            return array('x'=>$x, 'y'=>$y);
3198
-        }
3197
+			return array('x'=>$x, 'y'=>$y);
3198
+		}
3199 3199
         
3200
-    } ;
3200
+	} ;
3201 3201
     
3202
-    //##########################################################################    
3202
+	//##########################################################################    
3203 3203
     
3204
-    class QRencode {
3204
+	class QRencode {
3205 3205
     
3206
-        public $casesensitive = true;
3207
-        public $eightbit = false;
3208
-        
3209
-        public $version = 0;
3210
-        public $size = 3;
3211
-        public $margin = 4;
3212
-        
3213
-        public $structured = 0; // not supported yet
3214
-        
3215
-        public $level = QR_ECLEVEL_L;
3216
-        public $hint = QR_MODE_8;
3217
-        
3218
-        //----------------------------------------------------------------------
3219
-        public static function factory($level = QR_ECLEVEL_L, $size = 3, $margin = 4)
3220
-        {
3221
-            $enc = new QRencode();
3222
-            $enc->size = $size;
3223
-            $enc->margin = $margin;
3224
-            
3225
-            switch ($level.'') {
3226
-                case '0':
3227
-                case '1':
3228
-                case '2':
3229
-                case '3':
3230
-                        $enc->level = $level;
3231
-                    break;
3232
-                case 'l':
3233
-                case 'L':
3234
-                        $enc->level = QR_ECLEVEL_L;
3235
-                    break;
3236
-                case 'm':
3237
-                case 'M':
3238
-                        $enc->level = QR_ECLEVEL_M;
3239
-                    break;
3240
-                case 'q':
3241
-                case 'Q':
3242
-                        $enc->level = QR_ECLEVEL_Q;
3243
-                    break;
3244
-                case 'h':
3245
-                case 'H':
3246
-                        $enc->level = QR_ECLEVEL_H;
3247
-                    break;
3248
-            }
3249
-            
3250
-            return $enc;
3251
-        }
3252
-        
3253
-        //----------------------------------------------------------------------
3254
-        public function encodeRAW($intext, $outfile = false) 
3255
-        {
3256
-            $code = new QRcode();
3257
-
3258
-            if($this->eightbit) {
3259
-                $code->encodeString8bit($intext, $this->version, $this->level);
3260
-            } else {
3261
-                $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
3262
-            }
3263
-            
3264
-            return $code->data;
3265
-        }
3266
-
3267
-        //----------------------------------------------------------------------
3268
-        public function encode($intext, $outfile = false) 
3269
-        {
3270
-            $code = new QRcode();
3271
-
3272
-            if($this->eightbit) {
3273
-                $code->encodeString8bit($intext, $this->version, $this->level);
3274
-            } else {
3275
-                $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
3276
-            }
3277
-            
3278
-            QRtools::markTime('after_encode');
3279
-            
3280
-            if ($outfile!== false) {
3281
-                file_put_contents($outfile, join("\n", QRtools::binarize($code->data)));
3282
-            } else {
3283
-                return QRtools::binarize($code->data);
3284
-            }
3285
-        }
3286
-        
3287
-        //----------------------------------------------------------------------
3288
-        public function encodePNG($intext, $outfile = false,$saveandprint=false) 
3289
-        {
3290
-            try {
3291
-            
3292
-                ob_start();
3293
-                $tab = $this->encode($intext);
3294
-                $err = ob_get_contents();
3295
-                ob_end_clean();
3206
+		public $casesensitive = true;
3207
+		public $eightbit = false;
3208
+        
3209
+		public $version = 0;
3210
+		public $size = 3;
3211
+		public $margin = 4;
3212
+        
3213
+		public $structured = 0; // not supported yet
3214
+        
3215
+		public $level = QR_ECLEVEL_L;
3216
+		public $hint = QR_MODE_8;
3217
+        
3218
+		//----------------------------------------------------------------------
3219
+		public static function factory($level = QR_ECLEVEL_L, $size = 3, $margin = 4)
3220
+		{
3221
+			$enc = new QRencode();
3222
+			$enc->size = $size;
3223
+			$enc->margin = $margin;
3224
+            
3225
+			switch ($level.'') {
3226
+				case '0':
3227
+				case '1':
3228
+				case '2':
3229
+				case '3':
3230
+						$enc->level = $level;
3231
+					break;
3232
+				case 'l':
3233
+				case 'L':
3234
+						$enc->level = QR_ECLEVEL_L;
3235
+					break;
3236
+				case 'm':
3237
+				case 'M':
3238
+						$enc->level = QR_ECLEVEL_M;
3239
+					break;
3240
+				case 'q':
3241
+				case 'Q':
3242
+						$enc->level = QR_ECLEVEL_Q;
3243
+					break;
3244
+				case 'h':
3245
+				case 'H':
3246
+						$enc->level = QR_ECLEVEL_H;
3247
+					break;
3248
+			}
3249
+            
3250
+			return $enc;
3251
+		}
3252
+        
3253
+		//----------------------------------------------------------------------
3254
+		public function encodeRAW($intext, $outfile = false) 
3255
+		{
3256
+			$code = new QRcode();
3257
+
3258
+			if($this->eightbit) {
3259
+				$code->encodeString8bit($intext, $this->version, $this->level);
3260
+			} else {
3261
+				$code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
3262
+			}
3263
+            
3264
+			return $code->data;
3265
+		}
3266
+
3267
+		//----------------------------------------------------------------------
3268
+		public function encode($intext, $outfile = false) 
3269
+		{
3270
+			$code = new QRcode();
3271
+
3272
+			if($this->eightbit) {
3273
+				$code->encodeString8bit($intext, $this->version, $this->level);
3274
+			} else {
3275
+				$code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
3276
+			}
3277
+            
3278
+			QRtools::markTime('after_encode');
3279
+            
3280
+			if ($outfile!== false) {
3281
+				file_put_contents($outfile, join("\n", QRtools::binarize($code->data)));
3282
+			} else {
3283
+				return QRtools::binarize($code->data);
3284
+			}
3285
+		}
3286
+        
3287
+		//----------------------------------------------------------------------
3288
+		public function encodePNG($intext, $outfile = false,$saveandprint=false) 
3289
+		{
3290
+			try {
3291
+            
3292
+				ob_start();
3293
+				$tab = $this->encode($intext);
3294
+				$err = ob_get_contents();
3295
+				ob_end_clean();
3296 3296
                 
3297
-                if ($err != '')
3298
-                    QRtools::log($outfile, $err);
3297
+				if ($err != '')
3298
+					QRtools::log($outfile, $err);
3299 3299
                 
3300
-                $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin));
3300
+				$maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin));
3301 3301
                 
3302
-                QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint);
3302
+				QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint);
3303 3303
             
3304
-            } catch (Exception $e) {
3304
+			} catch (Exception $e) {
3305 3305
             
3306
-                QRtools::log($outfile, $e->getMessage());
3306
+				QRtools::log($outfile, $e->getMessage());
3307 3307
             
3308
-            }
3309
-        }
3310
-    }
3308
+			}
3309
+		}
3310
+	}
3311 3311
 
3312 3312
 
Please login to merge, or discard this patch.
Switch Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -1214,13 +1214,13 @@  discard block
 block discarded – undo
1214 1214
                 $version = 1;
1215 1215
 
1216 1216
             switch($this->mode) {
1217
-                case QR_MODE_NUM:        $bits = QRinput::estimateBitsModeNum($this->size);    break;
1218
-                case QR_MODE_AN:        $bits = QRinput::estimateBitsModeAn($this->size);    break;
1219
-                case QR_MODE_8:            $bits = QRinput::estimateBitsMode8($this->size);    break;
1220
-                case QR_MODE_KANJI:        $bits = QRinput::estimateBitsModeKanji($this->size);break;
1221
-                case QR_MODE_STRUCTURE:    return STRUCTURE_HEADER_BITS;            
1222
-                default:
1223
-                    return 0;
1217
+            case QR_MODE_NUM:        $bits = QRinput::estimateBitsModeNum($this->size);    break;
1218
+            case QR_MODE_AN:        $bits = QRinput::estimateBitsModeAn($this->size);    break;
1219
+            case QR_MODE_8:            $bits = QRinput::estimateBitsMode8($this->size);    break;
1220
+            case QR_MODE_KANJI:        $bits = QRinput::estimateBitsModeKanji($this->size);break;
1221
+            case QR_MODE_STRUCTURE:    return STRUCTURE_HEADER_BITS;            
1222
+            default:
1223
+                return 0;
1224 1224
             }
1225 1225
 
1226 1226
             $l = QRspec::lengthIndicator($this->mode, $version);
@@ -1260,14 +1260,14 @@  discard block
 block discarded – undo
1260 1260
                     $ret = 0;
1261 1261
                     
1262 1262
                     switch($this->mode) {
1263
-                        case QR_MODE_NUM:        $ret = $this->encodeModeNum($version);    break;
1264
-                        case QR_MODE_AN:        $ret = $this->encodeModeAn($version);    break;
1265
-                        case QR_MODE_8:            $ret = $this->encodeMode8($version);    break;
1266
-                        case QR_MODE_KANJI:        $ret = $this->encodeModeKanji($version);break;
1267
-                        case QR_MODE_STRUCTURE:    $ret = $this->encodeModeStructure();    break;
1263
+                    case QR_MODE_NUM:        $ret = $this->encodeModeNum($version);    break;
1264
+                    case QR_MODE_AN:        $ret = $this->encodeModeAn($version);    break;
1265
+                    case QR_MODE_8:            $ret = $this->encodeMode8($version);    break;
1266
+                    case QR_MODE_KANJI:        $ret = $this->encodeModeKanji($version);break;
1267
+                    case QR_MODE_STRUCTURE:    $ret = $this->encodeModeStructure();    break;
1268 1268
                         
1269
-                        default:
1270
-                            break;
1269
+                    default:
1270
+                        break;
1271 1271
                     }
1272 1272
                     
1273 1273
                     if($ret < 0)
@@ -1417,14 +1417,14 @@  discard block
 block discarded – undo
1417 1417
             $bits = $w * 10;
1418 1418
             
1419 1419
             switch($size - $w * 3) {
1420
-                case 1:
1421
-                    $bits += 4;
1422
-                    break;
1423
-                case 2:
1424
-                    $bits += 7;
1425
-                    break;
1426
-                default:
1427
-                    break;
1420
+            case 1:
1421
+                $bits += 4;
1422
+                break;
1423
+            case 2:
1424
+                $bits += 7;
1425
+                break;
1426
+            default:
1427
+                break;
1428 1428
             }
1429 1429
 
1430 1430
             return $bits;
@@ -1513,14 +1513,14 @@  discard block
 block discarded – undo
1513 1513
                 return false;
1514 1514
 
1515 1515
             switch($mode) {
1516
-                case QR_MODE_NUM:       return self::checkModeNum($size, $data);   break;
1517
-                case QR_MODE_AN:        return self::checkModeAn($size, $data);    break;
1518
-                case QR_MODE_KANJI:     return self::checkModeKanji($size, $data); break;
1519
-                case QR_MODE_8:         return true; break;
1520
-                case QR_MODE_STRUCTURE: return true; break;
1516
+            case QR_MODE_NUM:       return self::checkModeNum($size, $data);   break;
1517
+            case QR_MODE_AN:        return self::checkModeAn($size, $data);    break;
1518
+            case QR_MODE_KANJI:     return self::checkModeKanji($size, $data); break;
1519
+            case QR_MODE_8:         return true; break;
1520
+            case QR_MODE_STRUCTURE: return true; break;
1521 1521
                 
1522
-                default:
1523
-                    break;
1522
+            default:
1523
+                break;
1524 1524
             }
1525 1525
 
1526 1526
             return false;
@@ -1561,35 +1561,35 @@  discard block
 block discarded – undo
1561 1561
         {
1562 1562
             $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version);
1563 1563
             switch($mode) {
1564
-                case QR_MODE_NUM:
1565
-                    $chunks = (int)($payload / 10);
1566
-                    $remain = $payload - $chunks * 10;
1567
-                    $size = $chunks * 3;
1568
-                    if($remain >= 7) {
1569
-                        $size += 2;
1570
-                    } else if($remain >= 4) {
1571
-                        $size += 1;
1572
-                    }
1573
-                    break;
1574
-                case QR_MODE_AN:
1575
-                    $chunks = (int)($payload / 11);
1576
-                    $remain = $payload - $chunks * 11;
1577
-                    $size = $chunks * 2;
1578
-                    if($remain >= 6) 
1579
-                        $size++;
1580
-                    break;
1581
-                case QR_MODE_8:
1582
-                    $size = (int)($payload / 8);
1583
-                    break;
1584
-                case QR_MODE_KANJI:
1585
-                    $size = (int)(($payload / 13) * 2);
1586
-                    break;
1587
-                case QR_MODE_STRUCTURE:
1588
-                    $size = (int)($payload / 8);
1589
-                    break;
1590
-                default:
1591
-                    $size = 0;
1592
-                    break;
1564
+            case QR_MODE_NUM:
1565
+                $chunks = (int)($payload / 10);
1566
+                $remain = $payload - $chunks * 10;
1567
+                $size = $chunks * 3;
1568
+                if($remain >= 7) {
1569
+                    $size += 2;
1570
+                } else if($remain >= 4) {
1571
+                    $size += 1;
1572
+                }
1573
+                break;
1574
+            case QR_MODE_AN:
1575
+                $chunks = (int)($payload / 11);
1576
+                $remain = $payload - $chunks * 11;
1577
+                $size = $chunks * 2;
1578
+                if($remain >= 6) 
1579
+                    $size++;
1580
+                break;
1581
+            case QR_MODE_8:
1582
+                $size = (int)($payload / 8);
1583
+                break;
1584
+            case QR_MODE_KANJI:
1585
+                $size = (int)(($payload / 13) * 2);
1586
+                break;
1587
+            case QR_MODE_STRUCTURE:
1588
+                $size = (int)($payload / 8);
1589
+                break;
1590
+            default:
1591
+                $size = 0;
1592
+                break;
1593 1593
             }
1594 1594
             
1595 1595
             $maxsize = QRspec::maximumWords($mode, $version);
@@ -2192,14 +2192,14 @@  discard block
 block discarded – undo
2192 2192
                 $mode = $this->identifyMode(0);
2193 2193
                 
2194 2194
                 switch ($mode) {
2195
-                    case QR_MODE_NUM: $length = $this->eatNum(); break;
2196
-                    case QR_MODE_AN:  $length = $this->eatAn(); break;
2197
-                    case QR_MODE_KANJI:
2198
-                        if ($this->modeHint == QR_MODE_KANJI)
2199
-                                $length = $this->eatKanji();
2200
-                        else    $length = $this->eat8();
2201
-                        break;
2202
-                    default: $length = $this->eat8(); break;
2195
+                case QR_MODE_NUM: $length = $this->eatNum(); break;
2196
+                case QR_MODE_AN:  $length = $this->eatAn(); break;
2197
+                case QR_MODE_KANJI:
2198
+                    if ($this->modeHint == QR_MODE_KANJI)
2199
+                            $length = $this->eatKanji();
2200
+                    else    $length = $this->eat8();
2201
+                    break;
2202
+                default: $length = $this->eat8(); break;
2203 2203
                 
2204 2204
                 }
2205 2205
 
@@ -3223,28 +3223,28 @@  discard block
 block discarded – undo
3223 3223
             $enc->margin = $margin;
3224 3224
             
3225 3225
             switch ($level.'') {
3226
-                case '0':
3227
-                case '1':
3228
-                case '2':
3229
-                case '3':
3230
-                        $enc->level = $level;
3231
-                    break;
3232
-                case 'l':
3233
-                case 'L':
3234
-                        $enc->level = QR_ECLEVEL_L;
3235
-                    break;
3236
-                case 'm':
3237
-                case 'M':
3238
-                        $enc->level = QR_ECLEVEL_M;
3239
-                    break;
3240
-                case 'q':
3241
-                case 'Q':
3242
-                        $enc->level = QR_ECLEVEL_Q;
3243
-                    break;
3244
-                case 'h':
3245
-                case 'H':
3246
-                        $enc->level = QR_ECLEVEL_H;
3247
-                    break;
3226
+            case '0':
3227
+            case '1':
3228
+            case '2':
3229
+            case '3':
3230
+                    $enc->level = $level;
3231
+                break;
3232
+            case 'l':
3233
+            case 'L':
3234
+                    $enc->level = QR_ECLEVEL_L;
3235
+                break;
3236
+            case 'm':
3237
+            case 'M':
3238
+                    $enc->level = QR_ECLEVEL_M;
3239
+                break;
3240
+            case 'q':
3241
+            case 'Q':
3242
+                    $enc->level = QR_ECLEVEL_Q;
3243
+                break;
3244
+            case 'h':
3245
+            case 'H':
3246
+                    $enc->level = QR_ECLEVEL_H;
3247
+                break;
3248 3248
             }
3249 3249
             
3250 3250
             return $enc;
Please login to merge, or discard this patch.
Spacing   +502 added lines, -502 removed lines patch added patch discarded remove patch
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
 	// Supported output formats
94 94
 	
95 95
 	define('QR_FORMAT_TEXT', 0);
96
-	define('QR_FORMAT_PNG',  1);
96
+	define('QR_FORMAT_PNG', 1);
97 97
 	
98 98
 	class qrstr {
99 99
 		public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
100
-			$srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl));
100
+			$srctab[$y] = substr_replace($srctab[$y], ($replLen !== false) ?substr($repl, 0, $replLen) : $repl, $x, ($replLen !== false) ? $replLen : strlen($repl));
101 101
 		}
102 102
 	}	
103 103
 
@@ -114,15 +114,15 @@  discard block
 block discarded – undo
114 114
  * Config file, tuned-up for merged verion
115 115
  */
116 116
      
117
-    define('QR_CACHEABLE', false);       // use cache - more disk reads but less CPU power, masks and format templates are stored there
118
-    define('QR_CACHE_DIR', false);       // used when QR_CACHEABLE === true
119
-    define('QR_LOG_DIR', false);         // default error logs dir   
117
+    define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there
118
+    define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true
119
+    define('QR_LOG_DIR', false); // default error logs dir   
120 120
     
121
-    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
122
-    define('QR_FIND_FROM_RANDOM', 2);                                                       // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly
123
-    define('QR_DEFAULT_MASK', 2);                                                               // when QR_FIND_BEST_MASK === false
121
+    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
122
+    define('QR_FIND_FROM_RANDOM', 2); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly
123
+    define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false
124 124
                                                   
125
-    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
125
+    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
126 126
                                                   
127 127
 
128 128
 
@@ -163,8 +163,8 @@  discard block
 block discarded – undo
163 163
             $len = count($frame);
164 164
             foreach ($frame as &$frameLine) {
165 165
                 
166
-                for($i=0; $i<$len; $i++) {
167
-                    $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';
166
+                for ($i = 0; $i < $len; $i++) {
167
+                    $frameLine[$i] = (ord($frameLine[$i]) & 1) ? '1' : '0';
168 168
                 }
169 169
             }
170 170
             
@@ -194,8 +194,8 @@  discard block
 block discarded – undo
194 194
                 
195 195
             foreach ($qrTab as $line) {
196 196
                 $arrAdd = array();
197
-                foreach(str_split($line) as $char)
198
-                    $arrAdd[] = ($char=='1')?1:0;
197
+                foreach (str_split($line) as $char)
198
+                    $arrAdd[] = ($char == '1') ? 1 : 0;
199 199
                 $barcode_array['bcode'][] = $arrAdd;
200 200
             }
201 201
                     
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 			QRtools::markTime('before_build_cache');
215 215
 			
216 216
 			$mask = new QRmask();
217
-            for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) {
217
+            for ($a = 1; $a <= QRSPEC_VERSION_MAX; $a++) {
218 218
                 $frame = QRspec::newFrame($a);
219 219
                 if (QR_IMAGE) {
220 220
                     $fileName = QR_CACHE_DIR.'frame_'.$a.'.png';
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 				
224 224
 				$width = count($frame);
225 225
 				$bitMask = array_fill(0, $width, array_fill(0, $width, 0));
226
-				for ($maskNo=0; $maskNo<8; $maskNo++)
226
+				for ($maskNo = 0; $maskNo < 8; $maskNo++)
227 227
 					$mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
228 228
             }
229 229
 			
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
         public static function dumpMask($frame) 
249 249
         {
250 250
             $width = count($frame);
251
-            for($y=0;$y<$width;$y++) {
252
-                for($x=0;$x<$width;$x++) {
251
+            for ($y = 0; $y < $width; $y++) {
252
+                for ($x = 0; $x < $width; $x++) {
253 253
                     echo ord($frame[$y][$x]).',';
254 254
                 }
255 255
             }
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
         public static function markTime($markerId)
260 260
         {
261 261
             list($usec, $sec) = explode(" ", microtime());
262
-            $time = ((float)$usec + (float)$sec);
262
+            $time = ((float) $usec + (float) $sec);
263 263
             
264 264
             if (!isset($GLOBALS['qr_time_bench']))
265 265
                 $GLOBALS['qr_time_bench'] = array();
@@ -280,9 +280,9 @@  discard block
 block discarded – undo
280 280
                     <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead>
281 281
                     <tbody>';
282 282
 
283
-            foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
283
+            foreach ($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
284 284
                 if ($p > 0) {
285
-                    echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>';
285
+                    echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime - $lastTime, 6).'s</td></tr>';
286 286
                 } else {
287 287
                     $startTime = $thisTime;
288 288
                 }
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
             }
293 293
             
294 294
             echo '</tbody><tfoot>
295
-                <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr>
295
+                <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime - $startTime, 6).'s</td></tr>
296 296
             </tfoot>
297 297
             </table>';
298 298
         }
@@ -344,57 +344,57 @@  discard block
 block discarded – undo
344 344
  */
345 345
  
346 346
     define('QRSPEC_VERSION_MAX', 40);
347
-    define('QRSPEC_WIDTH_MAX',   177);
347
+    define('QRSPEC_WIDTH_MAX', 177);
348 348
 
349
-    define('QRCAP_WIDTH',        0);
350
-    define('QRCAP_WORDS',        1);
351
-    define('QRCAP_REMINDER',     2);
352
-    define('QRCAP_EC',           3);
349
+    define('QRCAP_WIDTH', 0);
350
+    define('QRCAP_WORDS', 1);
351
+    define('QRCAP_REMINDER', 2);
352
+    define('QRCAP_EC', 3);
353 353
 
354 354
     class QRspec {
355 355
     
356 356
         public static $capacity = array(
357
-            array(  0,    0, 0, array(   0,    0,    0,    0)),
358
-            array( 21,   26, 0, array(   7,   10,   13,   17)), // 1
359
-            array( 25,   44, 7, array(  10,   16,   22,   28)),
360
-            array( 29,   70, 7, array(  15,   26,   36,   44)),
361
-            array( 33,  100, 7, array(  20,   36,   52,   64)),
362
-            array( 37,  134, 7, array(  26,   48,   72,   88)), // 5
363
-            array( 41,  172, 7, array(  36,   64,   96,  112)),
364
-            array( 45,  196, 0, array(  40,   72,  108,  130)),
365
-            array( 49,  242, 0, array(  48,   88,  132,  156)),
366
-            array( 53,  292, 0, array(  60,  110,  160,  192)),
367
-            array( 57,  346, 0, array(  72,  130,  192,  224)), //10
368
-            array( 61,  404, 0, array(  80,  150,  224,  264)),
369
-            array( 65,  466, 0, array(  96,  176,  260,  308)),
370
-            array( 69,  532, 0, array( 104,  198,  288,  352)),
371
-            array( 73,  581, 3, array( 120,  216,  320,  384)),
372
-            array( 77,  655, 3, array( 132,  240,  360,  432)), //15
373
-            array( 81,  733, 3, array( 144,  280,  408,  480)),
374
-            array( 85,  815, 3, array( 168,  308,  448,  532)),
375
-            array( 89,  901, 3, array( 180,  338,  504,  588)),
376
-            array( 93,  991, 3, array( 196,  364,  546,  650)),
377
-            array( 97, 1085, 3, array( 224,  416,  600,  700)), //20
378
-            array(101, 1156, 4, array( 224,  442,  644,  750)),
379
-            array(105, 1258, 4, array( 252,  476,  690,  816)),
380
-            array(109, 1364, 4, array( 270,  504,  750,  900)),
381
-            array(113, 1474, 4, array( 300,  560,  810,  960)),
382
-            array(117, 1588, 4, array( 312,  588,  870, 1050)), //25
383
-            array(121, 1706, 4, array( 336,  644,  952, 1110)),
384
-            array(125, 1828, 4, array( 360,  700, 1020, 1200)),
385
-            array(129, 1921, 3, array( 390,  728, 1050, 1260)),
386
-            array(133, 2051, 3, array( 420,  784, 1140, 1350)),
387
-            array(137, 2185, 3, array( 450,  812, 1200, 1440)), //30
388
-            array(141, 2323, 3, array( 480,  868, 1290, 1530)),
389
-            array(145, 2465, 3, array( 510,  924, 1350, 1620)),
390
-            array(149, 2611, 3, array( 540,  980, 1440, 1710)),
391
-            array(153, 2761, 3, array( 570, 1036, 1530, 1800)),
392
-            array(157, 2876, 0, array( 570, 1064, 1590, 1890)), //35
393
-            array(161, 3034, 0, array( 600, 1120, 1680, 1980)),
394
-            array(165, 3196, 0, array( 630, 1204, 1770, 2100)),
395
-            array(169, 3362, 0, array( 660, 1260, 1860, 2220)),
396
-            array(173, 3532, 0, array( 720, 1316, 1950, 2310)),
397
-            array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40
357
+            array(0, 0, 0, array(0, 0, 0, 0)),
358
+            array(21, 26, 0, array(7, 10, 13, 17)), // 1
359
+            array(25, 44, 7, array(10, 16, 22, 28)),
360
+            array(29, 70, 7, array(15, 26, 36, 44)),
361
+            array(33, 100, 7, array(20, 36, 52, 64)),
362
+            array(37, 134, 7, array(26, 48, 72, 88)), // 5
363
+            array(41, 172, 7, array(36, 64, 96, 112)),
364
+            array(45, 196, 0, array(40, 72, 108, 130)),
365
+            array(49, 242, 0, array(48, 88, 132, 156)),
366
+            array(53, 292, 0, array(60, 110, 160, 192)),
367
+            array(57, 346, 0, array(72, 130, 192, 224)), //10
368
+            array(61, 404, 0, array(80, 150, 224, 264)),
369
+            array(65, 466, 0, array(96, 176, 260, 308)),
370
+            array(69, 532, 0, array(104, 198, 288, 352)),
371
+            array(73, 581, 3, array(120, 216, 320, 384)),
372
+            array(77, 655, 3, array(132, 240, 360, 432)), //15
373
+            array(81, 733, 3, array(144, 280, 408, 480)),
374
+            array(85, 815, 3, array(168, 308, 448, 532)),
375
+            array(89, 901, 3, array(180, 338, 504, 588)),
376
+            array(93, 991, 3, array(196, 364, 546, 650)),
377
+            array(97, 1085, 3, array(224, 416, 600, 700)), //20
378
+            array(101, 1156, 4, array(224, 442, 644, 750)),
379
+            array(105, 1258, 4, array(252, 476, 690, 816)),
380
+            array(109, 1364, 4, array(270, 504, 750, 900)),
381
+            array(113, 1474, 4, array(300, 560, 810, 960)),
382
+            array(117, 1588, 4, array(312, 588, 870, 1050)), //25
383
+            array(121, 1706, 4, array(336, 644, 952, 1110)),
384
+            array(125, 1828, 4, array(360, 700, 1020, 1200)),
385
+            array(129, 1921, 3, array(390, 728, 1050, 1260)),
386
+            array(133, 2051, 3, array(420, 784, 1140, 1350)),
387
+            array(137, 2185, 3, array(450, 812, 1200, 1440)), //30
388
+            array(141, 2323, 3, array(480, 868, 1290, 1530)),
389
+            array(145, 2465, 3, array(510, 924, 1350, 1620)),
390
+            array(149, 2611, 3, array(540, 980, 1440, 1710)),
391
+            array(153, 2761, 3, array(570, 1036, 1530, 1800)),
392
+            array(157, 2876, 0, array(570, 1064, 1590, 1890)), //35
393
+            array(161, 3034, 0, array(600, 1120, 1680, 1980)),
394
+            array(165, 3196, 0, array(630, 1204, 1770, 2100)),
395
+            array(169, 3362, 0, array(660, 1260, 1860, 2220)),
396
+            array(173, 3532, 0, array(720, 1316, 1950, 2310)),
397
+            array(177, 3706, 0, array(750, 1372, 2040, 2430)) //40
398 398
         );
399 399
         
400 400
         //----------------------------------------------------------------------
@@ -425,9 +425,9 @@  discard block
 block discarded – undo
425 425
         public static function getMinimumVersion($size, $level)
426 426
         {
427 427
 
428
-            for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) {
429
-                $words  = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level];
430
-                if($words >= $size) 
428
+            for ($i = 1; $i <= QRSPEC_VERSION_MAX; $i++) {
429
+                $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level];
430
+                if ($words >= $size) 
431 431
                     return $i;
432 432
             }
433 433
 
@@ -438,9 +438,9 @@  discard block
 block discarded – undo
438 438
         
439 439
         public static $lengthTableBits = array(
440 440
             array(10, 12, 14),
441
-            array( 9, 11, 13),
442
-            array( 8, 16, 16),
443
-            array( 8, 10, 12)
441
+            array(9, 11, 13),
442
+            array(8, 16, 16),
443
+            array(8, 10, 12)
444 444
         );
445 445
         
446 446
         //----------------------------------------------------------------------
@@ -463,12 +463,12 @@  discard block
 block discarded – undo
463 463
         //----------------------------------------------------------------------
464 464
         public static function maximumWords($mode, $version)
465 465
         {
466
-            if($mode == QR_MODE_STRUCTURE) 
466
+            if ($mode == QR_MODE_STRUCTURE) 
467 467
                 return 3;
468 468
                 
469
-            if($version <= 9) {
469
+            if ($version <= 9) {
470 470
                 $l = 0;
471
-            } else if($version <= 26) {
471
+            } else if ($version <= 26) {
472 472
                 $l = 1;
473 473
             } else {
474 474
                 $l = 2;
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
             $bits = self::$lengthTableBits[$mode][$l];
478 478
             $words = (1 << $bits) - 1;
479 479
             
480
-            if($mode == QR_MODE_KANJI) {
480
+            if ($mode == QR_MODE_KANJI) {
481 481
                 $words *= 2; // the number of bytes is required
482 482
             }
483 483
 
@@ -489,47 +489,47 @@  discard block
 block discarded – undo
489 489
         // See Table 12-16 (pp.30-36), JIS X0510:2004.
490 490
 
491 491
         public static $eccTable = array(
492
-            array(array( 0,  0), array( 0,  0), array( 0,  0), array( 0,  0)),
493
-            array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)), // 1
494
-            array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)),
495
-            array(array( 1,  0), array( 1,  0), array( 2,  0), array( 2,  0)),
496
-            array(array( 1,  0), array( 2,  0), array( 2,  0), array( 4,  0)),
497
-            array(array( 1,  0), array( 2,  0), array( 2,  2), array( 2,  2)), // 5
498
-            array(array( 2,  0), array( 4,  0), array( 4,  0), array( 4,  0)),
499
-            array(array( 2,  0), array( 4,  0), array( 2,  4), array( 4,  1)),
500
-            array(array( 2,  0), array( 2,  2), array( 4,  2), array( 4,  2)),
501
-            array(array( 2,  0), array( 3,  2), array( 4,  4), array( 4,  4)),
502
-            array(array( 2,  2), array( 4,  1), array( 6,  2), array( 6,  2)), //10
503
-            array(array( 4,  0), array( 1,  4), array( 4,  4), array( 3,  8)),
504
-            array(array( 2,  2), array( 6,  2), array( 4,  6), array( 7,  4)),
505
-            array(array( 4,  0), array( 8,  1), array( 8,  4), array(12,  4)),
506
-            array(array( 3,  1), array( 4,  5), array(11,  5), array(11,  5)),
507
-            array(array( 5,  1), array( 5,  5), array( 5,  7), array(11,  7)), //15
508
-            array(array( 5,  1), array( 7,  3), array(15,  2), array( 3, 13)),
509
-            array(array( 1,  5), array(10,  1), array( 1, 15), array( 2, 17)),
510
-            array(array( 5,  1), array( 9,  4), array(17,  1), array( 2, 19)),
511
-            array(array( 3,  4), array( 3, 11), array(17,  4), array( 9, 16)),
512
-            array(array( 3,  5), array( 3, 13), array(15,  5), array(15, 10)), //20
513
-            array(array( 4,  4), array(17,  0), array(17,  6), array(19,  6)),
514
-            array(array( 2,  7), array(17,  0), array( 7, 16), array(34,  0)),
515
-            array(array( 4,  5), array( 4, 14), array(11, 14), array(16, 14)),
516
-            array(array( 6,  4), array( 6, 14), array(11, 16), array(30,  2)),
517
-            array(array( 8,  4), array( 8, 13), array( 7, 22), array(22, 13)), //25
518
-            array(array(10,  2), array(19,  4), array(28,  6), array(33,  4)),
519
-            array(array( 8,  4), array(22,  3), array( 8, 26), array(12, 28)),
520
-            array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)),
521
-            array(array( 7,  7), array(21,  7), array( 1, 37), array(19, 26)),
522
-            array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), //30
523
-            array(array(13,  3), array( 2, 29), array(42,  1), array(23, 28)),
524
-            array(array(17,  0), array(10, 23), array(10, 35), array(19, 35)),
525
-            array(array(17,  1), array(14, 21), array(29, 19), array(11, 46)),
526
-            array(array(13,  6), array(14, 23), array(44,  7), array(59,  1)),
527
-            array(array(12,  7), array(12, 26), array(39, 14), array(22, 41)), //35
528
-            array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)),
529
-            array(array(17,  4), array(29, 14), array(49, 10), array(24, 46)),
530
-            array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)),
531
-            array(array(20,  4), array(40,  7), array(43, 22), array(10, 67)),
532
-            array(array(19,  6), array(18, 31), array(34, 34), array(20, 61)),//40
492
+            array(array(0, 0), array(0, 0), array(0, 0), array(0, 0)),
493
+            array(array(1, 0), array(1, 0), array(1, 0), array(1, 0)), // 1
494
+            array(array(1, 0), array(1, 0), array(1, 0), array(1, 0)),
495
+            array(array(1, 0), array(1, 0), array(2, 0), array(2, 0)),
496
+            array(array(1, 0), array(2, 0), array(2, 0), array(4, 0)),
497
+            array(array(1, 0), array(2, 0), array(2, 2), array(2, 2)), // 5
498
+            array(array(2, 0), array(4, 0), array(4, 0), array(4, 0)),
499
+            array(array(2, 0), array(4, 0), array(2, 4), array(4, 1)),
500
+            array(array(2, 0), array(2, 2), array(4, 2), array(4, 2)),
501
+            array(array(2, 0), array(3, 2), array(4, 4), array(4, 4)),
502
+            array(array(2, 2), array(4, 1), array(6, 2), array(6, 2)), //10
503
+            array(array(4, 0), array(1, 4), array(4, 4), array(3, 8)),
504
+            array(array(2, 2), array(6, 2), array(4, 6), array(7, 4)),
505
+            array(array(4, 0), array(8, 1), array(8, 4), array(12, 4)),
506
+            array(array(3, 1), array(4, 5), array(11, 5), array(11, 5)),
507
+            array(array(5, 1), array(5, 5), array(5, 7), array(11, 7)), //15
508
+            array(array(5, 1), array(7, 3), array(15, 2), array(3, 13)),
509
+            array(array(1, 5), array(10, 1), array(1, 15), array(2, 17)),
510
+            array(array(5, 1), array(9, 4), array(17, 1), array(2, 19)),
511
+            array(array(3, 4), array(3, 11), array(17, 4), array(9, 16)),
512
+            array(array(3, 5), array(3, 13), array(15, 5), array(15, 10)), //20
513
+            array(array(4, 4), array(17, 0), array(17, 6), array(19, 6)),
514
+            array(array(2, 7), array(17, 0), array(7, 16), array(34, 0)),
515
+            array(array(4, 5), array(4, 14), array(11, 14), array(16, 14)),
516
+            array(array(6, 4), array(6, 14), array(11, 16), array(30, 2)),
517
+            array(array(8, 4), array(8, 13), array(7, 22), array(22, 13)), //25
518
+            array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)),
519
+            array(array(8, 4), array(22, 3), array(8, 26), array(12, 28)),
520
+            array(array(3, 10), array(3, 23), array(4, 31), array(11, 31)),
521
+            array(array(7, 7), array(21, 7), array(1, 37), array(19, 26)),
522
+            array(array(5, 10), array(19, 10), array(15, 25), array(23, 25)), //30
523
+            array(array(13, 3), array(2, 29), array(42, 1), array(23, 28)),
524
+            array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)),
525
+            array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)),
526
+            array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)),
527
+            array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), //35
528
+            array(array(6, 14), array(6, 34), array(46, 10), array(2, 64)),
529
+            array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)),
530
+            array(array(4, 18), array(13, 32), array(48, 14), array(42, 32)),
531
+            array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)),
532
+            array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)), //40
533 533
         );                                                                       
534 534
 
535 535
         //----------------------------------------------------------------------
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
         public static function getEccSpec($version, $level, array &$spec)
539 539
         {
540 540
             if (count($spec) < 5) {
541
-                $spec = array(0,0,0,0,0);
541
+                $spec = array(0, 0, 0, 0, 0);
542 542
             }
543 543
 
544 544
             $b1   = self::$eccTable[$version][$level][0];
@@ -546,16 +546,16 @@  discard block
 block discarded – undo
546 546
             $data = self::getDataLength($version, $level);
547 547
             $ecc  = self::getECCLength($version, $level);
548 548
 
549
-            if($b2 == 0) {
549
+            if ($b2 == 0) {
550 550
                 $spec[0] = $b1;
551
-                $spec[1] = (int)($data / $b1);
552
-                $spec[2] = (int)($ecc / $b1);
551
+                $spec[1] = (int) ($data / $b1);
552
+                $spec[2] = (int) ($ecc / $b1);
553 553
                 $spec[3] = 0; 
554 554
                 $spec[4] = 0;
555 555
             } else {
556 556
                 $spec[0] = $b1;
557
-                $spec[1] = (int)($data / ($b1 + $b2));
558
-                $spec[2] = (int)($ecc  / ($b1 + $b2));
557
+                $spec[1] = (int) ($data / ($b1 + $b2));
558
+                $spec[2] = (int) ($ecc / ($b1 + $b2));
559 559
                 $spec[3] = $b2;
560 560
                 $spec[4] = $spec[1] + 1;
561 561
             }
@@ -571,9 +571,9 @@  discard block
 block discarded – undo
571 571
         // See Table 1 in Appendix E (pp.71) of JIS X0510:2004.
572 572
          
573 573
         public static $alignmentPattern = array(      
574
-            array( 0,  0),
575
-            array( 0,  0), array(18,  0), array(22,  0), array(26,  0), array(30,  0), // 1- 5
576
-            array(34,  0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10
574
+            array(0, 0),
575
+            array(0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5
576
+            array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10
577 577
             array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), //11-15
578 578
             array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), //16-20
579 579
             array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), //21-25
@@ -599,28 +599,28 @@  discard block
 block discarded – undo
599 599
                 "\xa1\xa1\xa1\xa1\xa1"
600 600
             );                        
601 601
             
602
-            $yStart = $oy-2;         
603
-            $xStart = $ox-2;
602
+            $yStart = $oy - 2;         
603
+            $xStart = $ox - 2;
604 604
             
605
-            for($y=0; $y<5; $y++) {
606
-                QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]);
605
+            for ($y = 0; $y < 5; $y++) {
606
+                QRstr::set($frame, $xStart, $yStart + $y, $finder[$y]);
607 607
             }
608 608
         }
609 609
 
610 610
         //----------------------------------------------------------------------
611 611
         public static function putAlignmentPattern($version, &$frame, $width)
612 612
         {
613
-            if($version < 2)
613
+            if ($version < 2)
614 614
                 return;
615 615
 
616 616
             $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0];
617
-            if($d < 0) {
617
+            if ($d < 0) {
618 618
                 $w = 2;
619 619
             } else {
620
-                $w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2);
620
+                $w = (int) (($width - self::$alignmentPattern[$version][0]) / $d + 2);
621 621
             }
622 622
 
623
-            if($w * $w - 3 == 1) {
623
+            if ($w * $w - 3 == 1) {
624 624
                 $x = self::$alignmentPattern[$version][0];
625 625
                 $y = self::$alignmentPattern[$version][0];
626 626
                 self::putAlignmentMarker($frame, $x, $y);
@@ -628,16 +628,16 @@  discard block
 block discarded – undo
628 628
             }
629 629
 
630 630
             $cx = self::$alignmentPattern[$version][0];
631
-            for($x=1; $x<$w - 1; $x++) {
631
+            for ($x = 1; $x < $w - 1; $x++) {
632 632
                 self::putAlignmentMarker($frame, 6, $cx);
633
-                self::putAlignmentMarker($frame, $cx,  6);
633
+                self::putAlignmentMarker($frame, $cx, 6);
634 634
                 $cx += $d;
635 635
             }
636 636
 
637 637
             $cy = self::$alignmentPattern[$version][0];
638
-            for($y=0; $y<$w-1; $y++) {
638
+            for ($y = 0; $y < $w - 1; $y++) {
639 639
                 $cx = self::$alignmentPattern[$version][0];
640
-                for($x=0; $x<$w-1; $x++) {
640
+                for ($x = 0; $x < $w - 1; $x++) {
641 641
                     self::putAlignmentMarker($frame, $cx, $cy);
642 642
                     $cx += $d;
643 643
                 }
@@ -663,10 +663,10 @@  discard block
 block discarded – undo
663 663
         //----------------------------------------------------------------------
664 664
         public static function getVersionPattern($version)
665 665
         {
666
-            if($version < 7 || $version > QRSPEC_VERSION_MAX)
666
+            if ($version < 7 || $version > QRSPEC_VERSION_MAX)
667 667
                 return 0;
668 668
 
669
-            return self::$versionPattern[$version -7];
669
+            return self::$versionPattern[$version - 7];
670 670
         }
671 671
 
672 672
         // Format information --------------------------------------------------
@@ -681,10 +681,10 @@  discard block
 block discarded – undo
681 681
 
682 682
         public static function getFormatInfo($mask, $level)
683 683
         {
684
-            if($mask < 0 || $mask > 7)
684
+            if ($mask < 0 || $mask > 7)
685 685
                 return 0;
686 686
                 
687
-            if($level < 0 || $level > 3)
687
+            if ($level < 0 || $level > 3)
688 688
                 return 0;                
689 689
 
690 690
             return self::$formatInfo[$level][$mask];
@@ -713,8 +713,8 @@  discard block
 block discarded – undo
713 713
                 "\xc1\xc1\xc1\xc1\xc1\xc1\xc1"
714 714
             );                            
715 715
             
716
-            for($y=0; $y<7; $y++) {
717
-                QRstr::set($frame, $ox, $oy+$y, $finder[$y]);
716
+            for ($y = 0; $y < 7; $y++) {
717
+                QRstr::set($frame, $ox, $oy + $y, $finder[$y]);
718 718
             }
719 719
         }
720 720
 
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
         public static function createFrame($version)
723 723
         {
724 724
             $width = self::$capacity[$version][QRCAP_WIDTH];
725
-            $frameLine = str_repeat ("\0", $width);
725
+            $frameLine = str_repeat("\0", $width);
726 726
             $frame = array_fill(0, $width, $frameLine);
727 727
 
728 728
             // Finder pattern
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
             // Separator
734 734
             $yOffset = $width - 7;
735 735
             
736
-            for($y=0; $y<7; $y++) {
736
+            for ($y = 0; $y < 7; $y++) {
737 737
                 $frame[$y][7] = "\xc0";
738 738
                 $frame[$y][$width - 8] = "\xc0";
739 739
                 $frame[$yOffset][7] = "\xc0";
@@ -743,7 +743,7 @@  discard block
 block discarded – undo
743 743
             $setPattern = str_repeat("\xc0", 8);
744 744
             
745 745
             QRstr::set($frame, 0, 7, $setPattern);
746
-            QRstr::set($frame, $width-8, 7, $setPattern);
746
+            QRstr::set($frame, $width - 8, 7, $setPattern);
747 747
             QRstr::set($frame, 0, $width - 8, $setPattern);
748 748
         
749 749
             // Format info
@@ -753,38 +753,38 @@  discard block
 block discarded – undo
753 753
             
754 754
             $yOffset = $width - 8;
755 755
 
756
-            for($y=0; $y<8; $y++,$yOffset++) {
756
+            for ($y = 0; $y < 8; $y++, $yOffset++) {
757 757
                 $frame[$y][8] = "\x84";
758 758
                 $frame[$yOffset][8] = "\x84";
759 759
             }
760 760
 
761 761
             // Timing pattern  
762 762
             
763
-            for($i=1; $i<$width-15; $i++) {
764
-                $frame[6][7+$i] = chr(0x90 | ($i & 1));
765
-                $frame[7+$i][6] = chr(0x90 | ($i & 1));
763
+            for ($i = 1; $i < $width - 15; $i++) {
764
+                $frame[6][7 + $i] = chr(0x90 | ($i & 1));
765
+                $frame[7 + $i][6] = chr(0x90 | ($i & 1));
766 766
             }
767 767
             
768 768
             // Alignment pattern  
769 769
             self::putAlignmentPattern($version, $frame, $width);
770 770
             
771 771
             // Version information 
772
-            if($version >= 7) {
772
+            if ($version >= 7) {
773 773
                 $vinf = self::getVersionPattern($version);
774 774
 
775 775
                 $v = $vinf;
776 776
                 
777
-                for($x=0; $x<6; $x++) {
778
-                    for($y=0; $y<3; $y++) {
779
-                        $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));
777
+                for ($x = 0; $x < 6; $x++) {
778
+                    for ($y = 0; $y < 3; $y++) {
779
+                        $frame[($width - 11) + $y][$x] = chr(0x88 | ($v & 1));
780 780
                         $v = $v >> 1;
781 781
                     }
782 782
                 }
783 783
 
784 784
                 $v = $vinf;
785
-                for($y=0; $y<6; $y++) {
786
-                    for($x=0; $x<3; $x++) {
787
-                        $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1));
785
+                for ($y = 0; $y < 6; $y++) {
786
+                    for ($x = 0; $x < 3; $x++) {
787
+                        $frame[$y][$x + ($width - 11)] = chr(0x88 | ($v & 1));
788 788
                         $v = $v >> 1;
789 789
                     }
790 790
                 }
@@ -818,16 +818,16 @@  discard block
 block discarded – undo
818 818
             } else {
819 819
             
820 820
                 foreach ($frame as &$frameLine) {
821
-                    $frameLine = join('<span class="m">&nbsp;</span>',  explode("\xc0", $frameLine));
821
+                    $frameLine = join('<span class="m">&nbsp;</span>', explode("\xc0", $frameLine));
822 822
                     $frameLine = join('<span class="m">&#9618;</span>', explode("\xc1", $frameLine));
823
-                    $frameLine = join('<span class="p">&nbsp;</span>',  explode("\xa0", $frameLine));
823
+                    $frameLine = join('<span class="p">&nbsp;</span>', explode("\xa0", $frameLine));
824 824
                     $frameLine = join('<span class="p">&#9618;</span>', explode("\xa1", $frameLine));
825 825
                     $frameLine = join('<span class="s">&#9671;</span>', explode("\x84", $frameLine)); //format 0
826 826
                     $frameLine = join('<span class="s">&#9670;</span>', explode("\x85", $frameLine)); //format 1
827 827
                     $frameLine = join('<span class="x">&#9762;</span>', explode("\x81", $frameLine)); //special bit
828
-                    $frameLine = join('<span class="c">&nbsp;</span>',  explode("\x90", $frameLine)); //clock 0
828
+                    $frameLine = join('<span class="c">&nbsp;</span>', explode("\x90", $frameLine)); //clock 0
829 829
                     $frameLine = join('<span class="c">&#9719;</span>', explode("\x91", $frameLine)); //clock 1
830
-                    $frameLine = join('<span class="f">&nbsp;</span>',  explode("\x88", $frameLine)); //version
830
+                    $frameLine = join('<span class="f">&nbsp;</span>', explode("\x88", $frameLine)); //version
831 831
                     $frameLine = join('<span class="f">&#9618;</span>', explode("\x89", $frameLine)); //version
832 832
                     $frameLine = join('&#9830;', explode("\x01", $frameLine));
833 833
                     $frameLine = join('&#8901;', explode("\0", $frameLine));
@@ -865,10 +865,10 @@  discard block
 block discarded – undo
865 865
         //----------------------------------------------------------------------
866 866
         public static function newFrame($version)
867 867
         {
868
-            if($version < 1 || $version > QRSPEC_VERSION_MAX) 
868
+            if ($version < 1 || $version > QRSPEC_VERSION_MAX) 
869 869
                 return null;
870 870
 
871
-            if(!isset(self::$frames[$version])) {
871
+            if (!isset(self::$frames[$version])) {
872 872
                 
873 873
                 $fileName = QR_CACHE_DIR.'frame_'.$version.'.dat';
874 874
                 
@@ -884,22 +884,22 @@  discard block
 block discarded – undo
884 884
                 }
885 885
             }
886 886
             
887
-            if(is_null(self::$frames[$version]))
887
+            if (is_null(self::$frames[$version]))
888 888
                 return null;
889 889
 
890 890
             return self::$frames[$version];
891 891
         }
892 892
 
893 893
         //----------------------------------------------------------------------
894
-        public static function rsBlockNum($spec)     { return $spec[0] + $spec[3]; }
895
-        public static function rsBlockNum1($spec)    { return $spec[0]; }
896
-        public static function rsDataCodes1($spec)   { return $spec[1]; }
897
-        public static function rsEccCodes1($spec)    { return $spec[2]; }
898
-        public static function rsBlockNum2($spec)    { return $spec[3]; }
899
-        public static function rsDataCodes2($spec)   { return $spec[4]; }
900
-        public static function rsEccCodes2($spec)    { return $spec[2]; }
901
-        public static function rsDataLength($spec)   { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]);    }
902
-        public static function rsEccLength($spec)    { return ($spec[0] + $spec[3]) * $spec[2]; }
894
+        public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; }
895
+        public static function rsBlockNum1($spec) { return $spec[0]; }
896
+        public static function rsDataCodes1($spec) { return $spec[1]; }
897
+        public static function rsEccCodes1($spec) { return $spec[2]; }
898
+        public static function rsBlockNum2($spec) { return $spec[3]; }
899
+        public static function rsDataCodes2($spec) { return $spec[4]; }
900
+        public static function rsEccCodes2($spec) { return $spec[2]; }
901
+        public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); }
902
+        public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; }
903 903
         
904 904
     }
905 905
 
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
     class QRimage {
939 939
     
940 940
         //----------------------------------------------------------------------
941
-        public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) 
941
+        public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4, $saveandprint = FALSE) 
942 942
         {
943 943
             $image = self::image($frame, $pixelPerPoint, $outerFrame);
944 944
             
@@ -946,11 +946,11 @@  discard block
 block discarded – undo
946 946
                 Header("Content-type: image/png");
947 947
                 ImagePng($image);
948 948
             } else {
949
-                if($saveandprint===TRUE){
949
+                if ($saveandprint === TRUE) {
950 950
                     ImagePng($image, $filename);
951 951
                     header("Content-type: image/png");
952 952
                     ImagePng($image);
953
-                }else{
953
+                } else {
954 954
                     ImagePng($image, $filename);
955 955
                 }
956 956
             }
@@ -979,25 +979,25 @@  discard block
 block discarded – undo
979 979
             $h = count($frame);
980 980
             $w = strlen($frame[0]);
981 981
             
982
-            $imgW = $w + 2*$outerFrame;
983
-            $imgH = $h + 2*$outerFrame;
982
+            $imgW = $w + 2 * $outerFrame;
983
+            $imgH = $h + 2 * $outerFrame;
984 984
             
985
-            $base_image =ImageCreate($imgW, $imgH);
985
+            $base_image = ImageCreate($imgW, $imgH);
986 986
             
987
-            $col[0] = ImageColorAllocate($base_image,255,255,255);
988
-            $col[1] = ImageColorAllocate($base_image,0,0,0);
987
+            $col[0] = ImageColorAllocate($base_image, 255, 255, 255);
988
+            $col[1] = ImageColorAllocate($base_image, 0, 0, 0);
989 989
 
990 990
             imagefill($base_image, 0, 0, $col[0]);
991 991
 
992
-            for($y=0; $y<$h; $y++) {
993
-                for($x=0; $x<$w; $x++) {
992
+            for ($y = 0; $y < $h; $y++) {
993
+                for ($x = 0; $x < $w; $x++) {
994 994
                     if ($frame[$y][$x] == '1') {
995
-                        ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); 
995
+                        ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]); 
996 996
                     }
997 997
                 }
998 998
             }
999 999
             
1000
-            $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
1000
+            $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
1001 1001
             ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
1002 1002
             ImageDestroy($base_image);
1003 1003
             
@@ -1038,7 +1038,7 @@  discard block
 block discarded – undo
1038 1038
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1039 1039
  */
1040 1040
  
1041
-    define('STRUCTURE_HEADER_BITS',  20);
1041
+    define('STRUCTURE_HEADER_BITS', 20);
1042 1042
     define('MAX_STRUCTURED_SYMBOLS', 16);
1043 1043
 
1044 1044
     class QRinputItem {
@@ -1053,11 +1053,11 @@  discard block
 block discarded – undo
1053 1053
             $setData = array_slice($data, 0, $size);
1054 1054
             
1055 1055
             if (count($setData) < $size) {
1056
-                $setData = array_merge($setData, array_fill(0,$size-count($setData),0));
1056
+                $setData = array_merge($setData, array_fill(0, $size - count($setData), 0));
1057 1057
             }
1058 1058
         
1059
-            if(!QRinput::check($mode, $size, $setData)) {
1060
-                throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData));
1059
+            if (!QRinput::check($mode, $size, $setData)) {
1060
+                throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',', $setData));
1061 1061
                 return null;
1062 1062
             }
1063 1063
             
@@ -1072,26 +1072,26 @@  discard block
 block discarded – undo
1072 1072
         {
1073 1073
             try {
1074 1074
             
1075
-                $words = (int)($this->size / 3);
1075
+                $words = (int) ($this->size / 3);
1076 1076
                 $bs = new QRbitstream();
1077 1077
                 
1078 1078
                 $val = 0x1;
1079 1079
                 $bs->appendNum(4, $val);
1080 1080
                 $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size);
1081 1081
 
1082
-                for($i=0; $i<$words; $i++) {
1083
-                    $val  = (ord($this->data[$i*3  ]) - ord('0')) * 100;
1084
-                    $val += (ord($this->data[$i*3+1]) - ord('0')) * 10;
1085
-                    $val += (ord($this->data[$i*3+2]) - ord('0'));
1082
+                for ($i = 0; $i < $words; $i++) {
1083
+                    $val  = (ord($this->data[$i * 3]) - ord('0')) * 100;
1084
+                    $val += (ord($this->data[$i * 3 + 1]) - ord('0')) * 10;
1085
+                    $val += (ord($this->data[$i * 3 + 2]) - ord('0'));
1086 1086
                     $bs->appendNum(10, $val);
1087 1087
                 }
1088 1088
 
1089
-                if($this->size - $words * 3 == 1) {
1090
-                    $val = ord($this->data[$words*3]) - ord('0');
1089
+                if ($this->size - $words * 3 == 1) {
1090
+                    $val = ord($this->data[$words * 3]) - ord('0');
1091 1091
                     $bs->appendNum(4, $val);
1092
-                } else if($this->size - $words * 3 == 2) {
1093
-                    $val  = (ord($this->data[$words*3  ]) - ord('0')) * 10;
1094
-                    $val += (ord($this->data[$words*3+1]) - ord('0'));
1092
+                } else if ($this->size - $words * 3 == 2) {
1093
+                    $val  = (ord($this->data[$words * 3]) - ord('0')) * 10;
1094
+                    $val += (ord($this->data[$words * 3 + 1]) - ord('0'));
1095 1095
                     $bs->appendNum(7, $val);
1096 1096
                 }
1097 1097
 
@@ -1107,20 +1107,20 @@  discard block
 block discarded – undo
1107 1107
         public function encodeModeAn($version)
1108 1108
         {
1109 1109
             try {
1110
-                $words = (int)($this->size / 2);
1110
+                $words = (int) ($this->size / 2);
1111 1111
                 $bs = new QRbitstream();
1112 1112
                 
1113 1113
                 $bs->appendNum(4, 0x02);
1114 1114
                 $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size);
1115 1115
 
1116
-                for($i=0; $i<$words; $i++) {
1117
-                    $val  = (int)QRinput::lookAnTable(ord($this->data[$i*2  ])) * 45;
1118
-                    $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1]));
1116
+                for ($i = 0; $i < $words; $i++) {
1117
+                    $val  = (int) QRinput::lookAnTable(ord($this->data[$i * 2])) * 45;
1118
+                    $val += (int) QRinput::lookAnTable(ord($this->data[$i * 2 + 1]));
1119 1119
 
1120 1120
                     $bs->appendNum(11, $val);
1121 1121
                 }
1122 1122
 
1123
-                if($this->size & 1) {
1123
+                if ($this->size & 1) {
1124 1124
                     $val = QRinput::lookAnTable(ord($this->data[$words * 2]));
1125 1125
                     $bs->appendNum(6, $val);
1126 1126
                 }
@@ -1142,7 +1142,7 @@  discard block
 block discarded – undo
1142 1142
                 $bs->appendNum(4, 0x4);
1143 1143
                 $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size);
1144 1144
 
1145
-                for($i=0; $i<$this->size; $i++) {
1145
+                for ($i = 0; $i < $this->size; $i++) {
1146 1146
                     $bs->appendNum(8, ord($this->data[$i]));
1147 1147
                 }
1148 1148
 
@@ -1162,11 +1162,11 @@  discard block
 block discarded – undo
1162 1162
                 $bs = new QRbitrtream();
1163 1163
                 
1164 1164
                 $bs->appendNum(4, 0x8);
1165
-                $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2));
1165
+                $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int) ($this->size / 2));
1166 1166
 
1167
-                for($i=0; $i<$this->size; $i+=2) {
1168
-                    $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]);
1169
-                    if($val <= 0x9ffc) {
1167
+                for ($i = 0; $i < $this->size; $i += 2) {
1168
+                    $val = (ord($this->data[$i]) << 8) | ord($this->data[$i + 1]);
1169
+                    if ($val <= 0x9ffc) {
1170 1170
                         $val -= 0x8140;
1171 1171
                     } else {
1172 1172
                         $val -= 0xc140;
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
         public function encodeModeStructure()
1191 1191
         {
1192 1192
             try {
1193
-                $bs =  new QRbitstream();
1193
+                $bs = new QRbitstream();
1194 1194
                 
1195 1195
                 $bs->appendNum(4, 0x03);
1196 1196
                 $bs->appendNum(4, ord($this->data[1]) - 1);
@@ -1210,14 +1210,14 @@  discard block
 block discarded – undo
1210 1210
         {
1211 1211
             $bits = 0;
1212 1212
 
1213
-            if($version == 0) 
1213
+            if ($version == 0) 
1214 1214
                 $version = 1;
1215 1215
 
1216
-            switch($this->mode) {
1217
-                case QR_MODE_NUM:        $bits = QRinput::estimateBitsModeNum($this->size);    break;
1218
-                case QR_MODE_AN:        $bits = QRinput::estimateBitsModeAn($this->size);    break;
1219
-                case QR_MODE_8:            $bits = QRinput::estimateBitsMode8($this->size);    break;
1220
-                case QR_MODE_KANJI:        $bits = QRinput::estimateBitsModeKanji($this->size);break;
1216
+            switch ($this->mode) {
1217
+                case QR_MODE_NUM:        $bits = QRinput::estimateBitsModeNum($this->size); break;
1218
+                case QR_MODE_AN:        $bits = QRinput::estimateBitsModeAn($this->size); break;
1219
+                case QR_MODE_8:            $bits = QRinput::estimateBitsMode8($this->size); break;
1220
+                case QR_MODE_KANJI:        $bits = QRinput::estimateBitsModeKanji($this->size); break;
1221 1221
                 case QR_MODE_STRUCTURE:    return STRUCTURE_HEADER_BITS;            
1222 1222
                 default:
1223 1223
                     return 0;
@@ -1225,7 +1225,7 @@  discard block
 block discarded – undo
1225 1225
 
1226 1226
             $l = QRspec::lengthIndicator($this->mode, $version);
1227 1227
             $m = 1 << $l;
1228
-            $num = (int)(($this->size + $m - 1) / $m);
1228
+            $num = (int) (($this->size + $m - 1) / $m);
1229 1229
 
1230 1230
             $bits += $num * (4 + $l);
1231 1231
 
@@ -1240,7 +1240,7 @@  discard block
 block discarded – undo
1240 1240
                 unset($this->bstream);
1241 1241
                 $words = QRspec::maximumWords($this->mode, $version);
1242 1242
                 
1243
-                if($this->size > $words) {
1243
+                if ($this->size > $words) {
1244 1244
                 
1245 1245
                     $st1 = new QRinputItem($this->mode, $words, $this->data);
1246 1246
                     $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words));
@@ -1259,18 +1259,18 @@  discard block
 block discarded – undo
1259 1259
                     
1260 1260
                     $ret = 0;
1261 1261
                     
1262
-                    switch($this->mode) {
1263
-                        case QR_MODE_NUM:        $ret = $this->encodeModeNum($version);    break;
1264
-                        case QR_MODE_AN:        $ret = $this->encodeModeAn($version);    break;
1265
-                        case QR_MODE_8:            $ret = $this->encodeMode8($version);    break;
1266
-                        case QR_MODE_KANJI:        $ret = $this->encodeModeKanji($version);break;
1267
-                        case QR_MODE_STRUCTURE:    $ret = $this->encodeModeStructure();    break;
1262
+                    switch ($this->mode) {
1263
+                        case QR_MODE_NUM:        $ret = $this->encodeModeNum($version); break;
1264
+                        case QR_MODE_AN:        $ret = $this->encodeModeAn($version); break;
1265
+                        case QR_MODE_8:            $ret = $this->encodeMode8($version); break;
1266
+                        case QR_MODE_KANJI:        $ret = $this->encodeModeKanji($version); break;
1267
+                        case QR_MODE_STRUCTURE:    $ret = $this->encodeModeStructure(); break;
1268 1268
                         
1269 1269
                         default:
1270 1270
                             break;
1271 1271
                     }
1272 1272
                     
1273
-                    if($ret < 0)
1273
+                    if ($ret < 0)
1274 1274
                         return -1;
1275 1275
                 }
1276 1276
 
@@ -1312,7 +1312,7 @@  discard block
 block discarded – undo
1312 1312
         //----------------------------------------------------------------------
1313 1313
         public function setVersion($version)
1314 1314
         {
1315
-            if($version < 0 || $version > QRSPEC_VERSION_MAX) {
1315
+            if ($version < 0 || $version > QRSPEC_VERSION_MAX) {
1316 1316
                 throw new Exception('Invalid version no');
1317 1317
                 return -1;
1318 1318
             }
@@ -1331,7 +1331,7 @@  discard block
 block discarded – undo
1331 1331
         //----------------------------------------------------------------------
1332 1332
         public function setErrorCorrectionLevel($level)
1333 1333
         {
1334
-            if($level > QR_ECLEVEL_H) {
1334
+            if ($level > QR_ECLEVEL_H) {
1335 1335
                 throw new Exception('Invalid ECLEVEL');
1336 1336
                 return -1;
1337 1337
             }
@@ -1363,11 +1363,11 @@  discard block
 block discarded – undo
1363 1363
         
1364 1364
         public function insertStructuredAppendHeader($size, $index, $parity)
1365 1365
         {
1366
-            if( $size > MAX_STRUCTURED_SYMBOLS ) {
1366
+            if ($size > MAX_STRUCTURED_SYMBOLS) {
1367 1367
                 throw new Exception('insertStructuredAppendHeader wrong size');
1368 1368
             }
1369 1369
             
1370
-            if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) {
1370
+            if ($index <= 0 || $index > MAX_STRUCTURED_SYMBOLS) {
1371 1371
                 throw new Exception('insertStructuredAppendHeader wrong index');
1372 1372
             }
1373 1373
 
@@ -1387,9 +1387,9 @@  discard block
 block discarded – undo
1387 1387
         {
1388 1388
             $parity = 0;
1389 1389
             
1390
-            foreach($this->items as $item) {
1391
-                if($item->mode != QR_MODE_STRUCTURE) {
1392
-                    for($i=$item->size-1; $i>=0; $i--) {
1390
+            foreach ($this->items as $item) {
1391
+                if ($item->mode != QR_MODE_STRUCTURE) {
1392
+                    for ($i = $item->size - 1; $i >= 0; $i--) {
1393 1393
                         $parity ^= $item->data[$i];
1394 1394
                     }
1395 1395
                 }
@@ -1401,8 +1401,8 @@  discard block
 block discarded – undo
1401 1401
         //----------------------------------------------------------------------
1402 1402
         public static function checkModeNum($size, $data)
1403 1403
         {
1404
-            for($i=0; $i<$size; $i++) {
1405
-                if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){
1404
+            for ($i = 0; $i < $size; $i++) {
1405
+                if ((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))) {
1406 1406
                     return false;
1407 1407
                 }
1408 1408
             }
@@ -1413,10 +1413,10 @@  discard block
 block discarded – undo
1413 1413
         //----------------------------------------------------------------------
1414 1414
         public static function estimateBitsModeNum($size)
1415 1415
         {
1416
-            $w = (int)$size / 3;
1416
+            $w = (int) $size / 3;
1417 1417
             $bits = $w * 10;
1418 1418
             
1419
-            switch($size - $w * 3) {
1419
+            switch ($size - $w * 3) {
1420 1420
                 case 1:
1421 1421
                     $bits += 4;
1422 1422
                     break;
@@ -1435,7 +1435,7 @@  discard block
 block discarded – undo
1435 1435
             -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1436 1436
             -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1437 1437
             36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43,
1438
-             0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 44, -1, -1, -1, -1, -1,
1438
+             0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1,
1439 1439
             -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1440 1440
             25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
1441 1441
             -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -1445,13 +1445,13 @@  discard block
 block discarded – undo
1445 1445
         //----------------------------------------------------------------------
1446 1446
         public static function lookAnTable($c)
1447 1447
         {
1448
-            return (($c > 127)?-1:self::$anTable[$c]);
1448
+            return (($c > 127) ?-1 : self::$anTable[$c]);
1449 1449
         }
1450 1450
         
1451 1451
         //----------------------------------------------------------------------
1452 1452
         public static function checkModeAn($size, $data)
1453 1453
         {
1454
-            for($i=0; $i<$size; $i++) {
1454
+            for ($i = 0; $i < $size; $i++) {
1455 1455
                 if (self::lookAnTable(ord($data[$i])) == -1) {
1456 1456
                     return false;
1457 1457
                 }
@@ -1463,10 +1463,10 @@  discard block
 block discarded – undo
1463 1463
         //----------------------------------------------------------------------
1464 1464
         public static function estimateBitsModeAn($size)
1465 1465
         {
1466
-            $w = (int)($size / 2);
1466
+            $w = (int) ($size / 2);
1467 1467
             $bits = $w * 11;
1468 1468
             
1469
-            if($size & 1) {
1469
+            if ($size & 1) {
1470 1470
                 $bits += 6;
1471 1471
             }
1472 1472
 
@@ -1482,18 +1482,18 @@  discard block
 block discarded – undo
1482 1482
         //----------------------------------------------------------------------
1483 1483
         public function estimateBitsModeKanji($size)
1484 1484
         {
1485
-            return (int)(($size / 2) * 13);
1485
+            return (int) (($size / 2) * 13);
1486 1486
         }
1487 1487
         
1488 1488
         //----------------------------------------------------------------------
1489 1489
         public static function checkModeKanji($size, $data)
1490 1490
         {
1491
-            if($size & 1)
1491
+            if ($size & 1)
1492 1492
                 return false;
1493 1493
 
1494
-            for($i=0; $i<$size; $i+=2) {
1495
-                $val = (ord($data[$i]) << 8) | ord($data[$i+1]);
1496
-                if( $val < 0x8140 
1494
+            for ($i = 0; $i < $size; $i += 2) {
1495
+                $val = (ord($data[$i]) << 8) | ord($data[$i + 1]);
1496
+                if ($val < 0x8140 
1497 1497
                 || ($val > 0x9ffc && $val < 0xe040) 
1498 1498
                 || $val > 0xebbf) {
1499 1499
                     return false;
@@ -1509,12 +1509,12 @@  discard block
 block discarded – undo
1509 1509
 
1510 1510
         public static function check($mode, $size, $data)
1511 1511
         {
1512
-            if($size <= 0) 
1512
+            if ($size <= 0) 
1513 1513
                 return false;
1514 1514
 
1515
-            switch($mode) {
1516
-                case QR_MODE_NUM:       return self::checkModeNum($size, $data);   break;
1517
-                case QR_MODE_AN:        return self::checkModeAn($size, $data);    break;
1515
+            switch ($mode) {
1516
+                case QR_MODE_NUM:       return self::checkModeNum($size, $data); break;
1517
+                case QR_MODE_AN:        return self::checkModeAn($size, $data); break;
1518 1518
                 case QR_MODE_KANJI:     return self::checkModeKanji($size, $data); break;
1519 1519
                 case QR_MODE_8:         return true; break;
1520 1520
                 case QR_MODE_STRUCTURE: return true; break;
@@ -1532,7 +1532,7 @@  discard block
 block discarded – undo
1532 1532
         {
1533 1533
             $bits = 0;
1534 1534
 
1535
-            foreach($this->items as $item) {
1535
+            foreach ($this->items as $item) {
1536 1536
                 $bits += $item->estimateBitStreamSizeOfEntry($version);
1537 1537
             }
1538 1538
 
@@ -1547,7 +1547,7 @@  discard block
 block discarded – undo
1547 1547
             do {
1548 1548
                 $prev = $version;
1549 1549
                 $bits = $this->estimateBitStreamSize($prev);
1550
-                $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
1550
+                $version = QRspec::getMinimumVersion((int) (($bits + 7) / 8), $this->level);
1551 1551
                 if ($version < 0) {
1552 1552
                     return -1;
1553 1553
                 }
@@ -1560,32 +1560,32 @@  discard block
 block discarded – undo
1560 1560
         public static function lengthOfCode($mode, $version, $bits)
1561 1561
         {
1562 1562
             $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version);
1563
-            switch($mode) {
1563
+            switch ($mode) {
1564 1564
                 case QR_MODE_NUM:
1565
-                    $chunks = (int)($payload / 10);
1565
+                    $chunks = (int) ($payload / 10);
1566 1566
                     $remain = $payload - $chunks * 10;
1567 1567
                     $size = $chunks * 3;
1568
-                    if($remain >= 7) {
1568
+                    if ($remain >= 7) {
1569 1569
                         $size += 2;
1570
-                    } else if($remain >= 4) {
1570
+                    } else if ($remain >= 4) {
1571 1571
                         $size += 1;
1572 1572
                     }
1573 1573
                     break;
1574 1574
                 case QR_MODE_AN:
1575
-                    $chunks = (int)($payload / 11);
1575
+                    $chunks = (int) ($payload / 11);
1576 1576
                     $remain = $payload - $chunks * 11;
1577 1577
                     $size = $chunks * 2;
1578
-                    if($remain >= 6) 
1578
+                    if ($remain >= 6) 
1579 1579
                         $size++;
1580 1580
                     break;
1581 1581
                 case QR_MODE_8:
1582
-                    $size = (int)($payload / 8);
1582
+                    $size = (int) ($payload / 8);
1583 1583
                     break;
1584 1584
                 case QR_MODE_KANJI:
1585
-                    $size = (int)(($payload / 13) * 2);
1585
+                    $size = (int) (($payload / 13) * 2);
1586 1586
                     break;
1587 1587
                 case QR_MODE_STRUCTURE:
1588
-                    $size = (int)($payload / 8);
1588
+                    $size = (int) ($payload / 8);
1589 1589
                     break;
1590 1590
                 default:
1591 1591
                     $size = 0;
@@ -1593,8 +1593,8 @@  discard block
 block discarded – undo
1593 1593
             }
1594 1594
             
1595 1595
             $maxsize = QRspec::maximumWords($mode, $version);
1596
-            if($size < 0) $size = 0;
1597
-            if($size > $maxsize) $size = $maxsize;
1596
+            if ($size < 0) $size = 0;
1597
+            if ($size > $maxsize) $size = $maxsize;
1598 1598
 
1599 1599
             return $size;
1600 1600
         }
@@ -1604,10 +1604,10 @@  discard block
 block discarded – undo
1604 1604
         {
1605 1605
             $total = 0;
1606 1606
 
1607
-            foreach($this->items as $item) {
1607
+            foreach ($this->items as $item) {
1608 1608
                 $bits = $item->encodeBitStream($this->version);
1609 1609
                 
1610
-                if($bits < 0) 
1610
+                if ($bits < 0) 
1611 1611
                     return -1;
1612 1612
                     
1613 1613
                 $total += $bits;
@@ -1620,21 +1620,21 @@  discard block
 block discarded – undo
1620 1620
         public function convertData()
1621 1621
         {
1622 1622
             $ver = $this->estimateVersion();
1623
-            if($ver > $this->getVersion()) {
1623
+            if ($ver > $this->getVersion()) {
1624 1624
                 $this->setVersion($ver);
1625 1625
             }
1626 1626
 
1627
-            for(;;) {
1627
+            for (;;) {
1628 1628
                 $bits = $this->createBitStream();
1629 1629
                 
1630
-                if($bits < 0) 
1630
+                if ($bits < 0) 
1631 1631
                     return -1;
1632 1632
                     
1633
-                $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
1634
-                if($ver < 0) {
1633
+                $ver = QRspec::getMinimumVersion((int) (($bits + 7) / 8), $this->level);
1634
+                if ($ver < 0) {
1635 1635
                     throw new Exception('WRONG VERSION');
1636 1636
                     return -1;
1637
-                } else if($ver > $this->getVersion()) {
1637
+                } else if ($ver > $this->getVersion()) {
1638 1638
                     $this->setVersion($ver);
1639 1639
                 } else {
1640 1640
                     break;
@@ -1660,26 +1660,26 @@  discard block
 block discarded – undo
1660 1660
             }
1661 1661
 
1662 1662
             $bits += 4;
1663
-            $words = (int)(($bits + 7) / 8);
1663
+            $words = (int) (($bits + 7) / 8);
1664 1664
 
1665 1665
             $padding = new QRbitstream();
1666 1666
             $ret = $padding->appendNum($words * 8 - $bits + 4, 0);
1667 1667
             
1668
-            if($ret < 0) 
1668
+            if ($ret < 0) 
1669 1669
                 return $ret;
1670 1670
 
1671 1671
             $padlen = $maxwords - $words;
1672 1672
             
1673
-            if($padlen > 0) {
1673
+            if ($padlen > 0) {
1674 1674
                 
1675 1675
                 $padbuf = array();
1676
-                for($i=0; $i<$padlen; $i++) {
1677
-                    $padbuf[$i] = ($i&1)?0x11:0xec;
1676
+                for ($i = 0; $i < $padlen; $i++) {
1677
+                    $padbuf[$i] = ($i & 1) ? 0x11 : 0xec;
1678 1678
                 }
1679 1679
                 
1680 1680
                 $ret = $padding->appendBytes($padlen, $padbuf);
1681 1681
                 
1682
-                if($ret < 0)
1682
+                if ($ret < 0)
1683 1683
                     return $ret;
1684 1684
                 
1685 1685
             }
@@ -1692,15 +1692,15 @@  discard block
 block discarded – undo
1692 1692
         //----------------------------------------------------------------------
1693 1693
         public function mergeBitStream()
1694 1694
         {
1695
-            if($this->convertData() < 0) {
1695
+            if ($this->convertData() < 0) {
1696 1696
                 return null;
1697 1697
             }
1698 1698
 
1699 1699
             $bstream = new QRbitstream();
1700 1700
             
1701
-            foreach($this->items as $item) {
1701
+            foreach ($this->items as $item) {
1702 1702
                 $ret = $bstream->append($item->bstream);
1703
-                if($ret < 0) {
1703
+                if ($ret < 0) {
1704 1704
                     return null;
1705 1705
                 }
1706 1706
             }
@@ -1714,12 +1714,12 @@  discard block
 block discarded – undo
1714 1714
 
1715 1715
             $bstream = $this->mergeBitStream();
1716 1716
             
1717
-            if($bstream == null) {
1717
+            if ($bstream == null) {
1718 1718
                 return null;
1719 1719
             }
1720 1720
             
1721 1721
             $ret = $this->appendPaddingBit($bstream);
1722
-            if($ret < 0) {
1722
+            if ($ret < 0) {
1723 1723
                 return null;
1724 1724
             }
1725 1725
 
@@ -1730,7 +1730,7 @@  discard block
 block discarded – undo
1730 1730
         public function getByteStream()
1731 1731
         {
1732 1732
             $bstream = $this->getBitStream();
1733
-            if($bstream == null) {
1733
+            if ($bstream == null) {
1734 1734
                 return null;
1735 1735
             }
1736 1736
             
@@ -1798,8 +1798,8 @@  discard block
 block discarded – undo
1798 1798
             $bstream->allocate($bits);
1799 1799
             
1800 1800
             $mask = 1 << ($bits - 1);
1801
-            for($i=0; $i<$bits; $i++) {
1802
-                if($num & $mask) {
1801
+            for ($i = 0; $i < $bits; $i++) {
1802
+                if ($num & $mask) {
1803 1803
                     $bstream->data[$i] = 1;
1804 1804
                 } else {
1805 1805
                     $bstream->data[$i] = 0;
@@ -1815,12 +1815,12 @@  discard block
 block discarded – undo
1815 1815
         {
1816 1816
             $bstream = new QRbitstream();
1817 1817
             $bstream->allocate($size * 8);
1818
-            $p=0;
1818
+            $p = 0;
1819 1819
 
1820
-            for($i=0; $i<$size; $i++) {
1820
+            for ($i = 0; $i < $size; $i++) {
1821 1821
                 $mask = 0x80;
1822
-                for($j=0; $j<8; $j++) {
1823
-                    if($data[$i] & $mask) {
1822
+                for ($j = 0; $j < 8; $j++) {
1823
+                    if ($data[$i] & $mask) {
1824 1824
                         $bstream->data[$p] = 1;
1825 1825
                     } else {
1826 1826
                         $bstream->data[$p] = 0;
@@ -1840,11 +1840,11 @@  discard block
 block discarded – undo
1840 1840
                 return -1;
1841 1841
             }
1842 1842
             
1843
-            if($arg->size() == 0) {
1843
+            if ($arg->size() == 0) {
1844 1844
                 return 0;
1845 1845
             }
1846 1846
             
1847
-            if($this->size() == 0) {
1847
+            if ($this->size() == 0) {
1848 1848
                 $this->data = $arg->data;
1849 1849
                 return 0;
1850 1850
             }
@@ -1862,7 +1862,7 @@  discard block
 block discarded – undo
1862 1862
 
1863 1863
             $b = QRbitstream::newFromNum($bits, $num);
1864 1864
             
1865
-            if(is_null($b))
1865
+            if (is_null($b))
1866 1866
                 return -1;
1867 1867
 
1868 1868
             $ret = $this->append($b);
@@ -1879,7 +1879,7 @@  discard block
 block discarded – undo
1879 1879
 
1880 1880
             $b = QRbitstream::newFromBytes($size, $data);
1881 1881
             
1882
-            if(is_null($b))
1882
+            if (is_null($b))
1883 1883
                 return -1;
1884 1884
 
1885 1885
             $ret = $this->append($b);
@@ -1894,18 +1894,18 @@  discard block
 block discarded – undo
1894 1894
         
1895 1895
             $size = $this->size();
1896 1896
 
1897
-            if($size == 0) {
1897
+            if ($size == 0) {
1898 1898
                 return array();
1899 1899
             }
1900 1900
             
1901
-            $data = array_fill(0, (int)(($size + 7) / 8), 0);
1902
-            $bytes = (int)($size / 8);
1901
+            $data = array_fill(0, (int) (($size + 7) / 8), 0);
1902
+            $bytes = (int) ($size / 8);
1903 1903
 
1904 1904
             $p = 0;
1905 1905
             
1906
-            for($i=0; $i<$bytes; $i++) {
1906
+            for ($i = 0; $i < $bytes; $i++) {
1907 1907
                 $v = 0;
1908
-                for($j=0; $j<8; $j++) {
1908
+                for ($j = 0; $j < 8; $j++) {
1909 1909
                     $v = $v << 1;
1910 1910
                     $v |= $this->data[$p];
1911 1911
                     $p++;
@@ -1913,9 +1913,9 @@  discard block
 block discarded – undo
1913 1913
                 $data[$i] = $v;
1914 1914
             }
1915 1915
             
1916
-            if($size & 7) {
1916
+            if ($size & 7) {
1917 1917
                 $v = 0;
1918
-                for($j=0; $j<($size & 7); $j++) {
1918
+                for ($j = 0; $j < ($size & 7); $j++) {
1919 1919
                     $v = $v << 1;
1920 1920
                     $v |= $this->data[$p];
1921 1921
                     $p++;
@@ -1987,7 +1987,7 @@  discard block
 block discarded – undo
1987 1987
             if ($pos >= strlen($str))
1988 1988
                 return false;
1989 1989
             
1990
-            return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
1990
+            return ((ord($str[$pos]) >= ord('0')) && (ord($str[$pos]) <= ord('9')));
1991 1991
         }
1992 1992
         
1993 1993
         //----------------------------------------------------------------------
@@ -2007,17 +2007,17 @@  discard block
 block discarded – undo
2007 2007
                 
2008 2008
             $c = $this->dataStr[$pos];
2009 2009
             
2010
-            if(self::isdigitat($this->dataStr, $pos)) {
2010
+            if (self::isdigitat($this->dataStr, $pos)) {
2011 2011
                 return QR_MODE_NUM;
2012
-            } else if(self::isalnumat($this->dataStr, $pos)) {
2012
+            } else if (self::isalnumat($this->dataStr, $pos)) {
2013 2013
                 return QR_MODE_AN;
2014
-            } else if($this->modeHint == QR_MODE_KANJI) {
2014
+            } else if ($this->modeHint == QR_MODE_KANJI) {
2015 2015
             
2016
-                if ($pos+1 < strlen($this->dataStr)) 
2016
+                if ($pos + 1 < strlen($this->dataStr)) 
2017 2017
                 {
2018
-                    $d = $this->dataStr[$pos+1];
2018
+                    $d = $this->dataStr[$pos + 1];
2019 2019
                     $word = (ord($c) << 8) | ord($d);
2020
-                    if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) {
2020
+                    if (($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) {
2021 2021
                         return QR_MODE_KANJI;
2022 2022
                     }
2023 2023
                 }
@@ -2032,32 +2032,32 @@  discard block
 block discarded – undo
2032 2032
             $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
2033 2033
 
2034 2034
             $p = 0;
2035
-            while(self::isdigitat($this->dataStr, $p)) {
2035
+            while (self::isdigitat($this->dataStr, $p)) {
2036 2036
                 $p++;
2037 2037
             }
2038 2038
             
2039 2039
             $run = $p;
2040 2040
             $mode = $this->identifyMode($p);
2041 2041
             
2042
-            if($mode == QR_MODE_8) {
2042
+            if ($mode == QR_MODE_8) {
2043 2043
                 $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln
2044 2044
                      + QRinput::estimateBitsMode8(1)         // + 4 + l8
2045 2045
                      - QRinput::estimateBitsMode8($run + 1); // - 4 - l8
2046
-                if($dif > 0) {
2046
+                if ($dif > 0) {
2047 2047
                     return $this->eat8();
2048 2048
                 }
2049 2049
             }
2050
-            if($mode == QR_MODE_AN) {
2050
+            if ($mode == QR_MODE_AN) {
2051 2051
                 $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln
2052 2052
                      + QRinput::estimateBitsModeAn(1)        // + 4 + la
2053
-                     - QRinput::estimateBitsModeAn($run + 1);// - 4 - la
2054
-                if($dif > 0) {
2053
+                     - QRinput::estimateBitsModeAn($run + 1); // - 4 - la
2054
+                if ($dif > 0) {
2055 2055
                     return $this->eatAn();
2056 2056
                 }
2057 2057
             }
2058 2058
             
2059 2059
             $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr));
2060
-            if($ret < 0)
2060
+            if ($ret < 0)
2061 2061
                 return -1;
2062 2062
 
2063 2063
             return $run;
@@ -2066,15 +2066,15 @@  discard block
 block discarded – undo
2066 2066
         //----------------------------------------------------------------------
2067 2067
         public function eatAn()
2068 2068
         {
2069
-            $la = QRspec::lengthIndicator(QR_MODE_AN,  $this->input->getVersion());
2069
+            $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion());
2070 2070
             $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
2071 2071
 
2072 2072
             $p = 0;
2073 2073
             
2074
-            while(self::isalnumat($this->dataStr, $p)) {
2075
-                if(self::isdigitat($this->dataStr, $p)) {
2074
+            while (self::isalnumat($this->dataStr, $p)) {
2075
+                if (self::isdigitat($this->dataStr, $p)) {
2076 2076
                     $q = $p;
2077
-                    while(self::isdigitat($this->dataStr, $q)) {
2077
+                    while (self::isdigitat($this->dataStr, $q)) {
2078 2078
                         $q++;
2079 2079
                     }
2080 2080
                     
@@ -2082,7 +2082,7 @@  discard block
 block discarded – undo
2082 2082
                          + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln
2083 2083
                          - QRinput::estimateBitsModeAn($q); // - 4 - la
2084 2084
                          
2085
-                    if($dif < 0) {
2085
+                    if ($dif < 0) {
2086 2086
                         break;
2087 2087
                     } else {
2088 2088
                         $p = $q;
@@ -2094,17 +2094,17 @@  discard block
 block discarded – undo
2094 2094
 
2095 2095
             $run = $p;
2096 2096
 
2097
-            if(!self::isalnumat($this->dataStr, $p)) {
2097
+            if (!self::isalnumat($this->dataStr, $p)) {
2098 2098
                 $dif = QRinput::estimateBitsModeAn($run) + 4 + $la
2099 2099
                      + QRinput::estimateBitsMode8(1) // + 4 + l8
2100 2100
                       - QRinput::estimateBitsMode8($run + 1); // - 4 - l8
2101
-                if($dif > 0) {
2101
+                if ($dif > 0) {
2102 2102
                     return $this->eat8();
2103 2103
                 }
2104 2104
             }
2105 2105
 
2106 2106
             $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr));
2107
-            if($ret < 0)
2107
+            if ($ret < 0)
2108 2108
                 return -1;
2109 2109
 
2110 2110
             return $run;
@@ -2115,12 +2115,12 @@  discard block
 block discarded – undo
2115 2115
         {
2116 2116
             $p = 0;
2117 2117
             
2118
-            while($this->identifyMode($p) == QR_MODE_KANJI) {
2118
+            while ($this->identifyMode($p) == QR_MODE_KANJI) {
2119 2119
                 $p += 2;
2120 2120
             }
2121 2121
             
2122 2122
             $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr));
2123
-            if($ret < 0)
2123
+            if ($ret < 0)
2124 2124
                 return -1;
2125 2125
 
2126 2126
             return $run;
@@ -2135,34 +2135,34 @@  discard block
 block discarded – undo
2135 2135
             $p = 1;
2136 2136
             $dataStrLen = strlen($this->dataStr);
2137 2137
             
2138
-            while($p < $dataStrLen) {
2138
+            while ($p < $dataStrLen) {
2139 2139
                 
2140 2140
                 $mode = $this->identifyMode($p);
2141
-                if($mode == QR_MODE_KANJI) {
2141
+                if ($mode == QR_MODE_KANJI) {
2142 2142
                     break;
2143 2143
                 }
2144
-                if($mode == QR_MODE_NUM) {
2144
+                if ($mode == QR_MODE_NUM) {
2145 2145
                     $q = $p;
2146
-                    while(self::isdigitat($this->dataStr, $q)) {
2146
+                    while (self::isdigitat($this->dataStr, $q)) {
2147 2147
                         $q++;
2148 2148
                     }
2149 2149
                     $dif = QRinput::estimateBitsMode8($p) // + 4 + l8
2150 2150
                          + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln
2151 2151
                          - QRinput::estimateBitsMode8($q); // - 4 - l8
2152
-                    if($dif < 0) {
2152
+                    if ($dif < 0) {
2153 2153
                         break;
2154 2154
                     } else {
2155 2155
                         $p = $q;
2156 2156
                     }
2157
-                } else if($mode == QR_MODE_AN) {
2157
+                } else if ($mode == QR_MODE_AN) {
2158 2158
                     $q = $p;
2159
-                    while(self::isalnumat($this->dataStr, $q)) {
2159
+                    while (self::isalnumat($this->dataStr, $q)) {
2160 2160
                         $q++;
2161 2161
                     }
2162 2162
                     $dif = QRinput::estimateBitsMode8($p)  // + 4 + l8
2163 2163
                          + QRinput::estimateBitsModeAn($q - $p) + 4 + $la
2164 2164
                          - QRinput::estimateBitsMode8($q); // - 4 - l8
2165
-                    if($dif < 0) {
2165
+                    if ($dif < 0) {
2166 2166
                         break;
2167 2167
                     } else {
2168 2168
                         $p = $q;
@@ -2175,7 +2175,7 @@  discard block
 block discarded – undo
2175 2175
             $run = $p;
2176 2176
             $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr));
2177 2177
             
2178
-            if($ret < 0)
2178
+            if ($ret < 0)
2179 2179
                 return -1;
2180 2180
 
2181 2181
             return $run;
@@ -2186,7 +2186,7 @@  discard block
 block discarded – undo
2186 2186
         {
2187 2187
             while (strlen($this->dataStr) > 0)
2188 2188
             {
2189
-                if($this->dataStr == '')
2189
+                if ($this->dataStr == '')
2190 2190
                     return 0;
2191 2191
 
2192 2192
                 $mode = $this->identifyMode(0);
@@ -2203,8 +2203,8 @@  discard block
 block discarded – undo
2203 2203
                 
2204 2204
                 }
2205 2205
 
2206
-                if($length == 0) return 0;
2207
-                if($length < 0)  return -1;
2206
+                if ($length == 0) return 0;
2207
+                if ($length < 0)  return -1;
2208 2208
                 
2209 2209
                 $this->dataStr = substr($this->dataStr, $length);
2210 2210
             }
@@ -2216,9 +2216,9 @@  discard block
 block discarded – undo
2216 2216
             $stringLen = strlen($this->dataStr);
2217 2217
             $p = 0;
2218 2218
             
2219
-            while ($p<$stringLen) {
2219
+            while ($p < $stringLen) {
2220 2220
                 $mode = self::identifyMode(substr($this->dataStr, $p));
2221
-                if($mode == QR_MODE_KANJI) {
2221
+                if ($mode == QR_MODE_KANJI) {
2222 2222
                     $p += 2;
2223 2223
                 } else {
2224 2224
                     if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) {
@@ -2234,13 +2234,13 @@  discard block
 block discarded – undo
2234 2234
         //----------------------------------------------------------------------
2235 2235
         public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true)
2236 2236
         {
2237
-            if(is_null($string) || $string == '\0' || $string == '') {
2237
+            if (is_null($string) || $string == '\0' || $string == '') {
2238 2238
                 throw new Exception('empty string!!!');
2239 2239
             }
2240 2240
 
2241 2241
             $split = new QRsplit($string, $input, $modeHint);
2242 2242
             
2243
-            if(!$casesensitive)
2243
+            if (!$casesensitive)
2244 2244
                 $split->toUpper();
2245 2245
                 
2246 2246
             return $split->splitString();
@@ -2285,16 +2285,16 @@  discard block
 block discarded – undo
2285 2285
  
2286 2286
     class QRrsItem {
2287 2287
     
2288
-        public $mm;                  // Bits per symbol 
2289
-        public $nn;                  // Symbols per block (= (1<<mm)-1) 
2290
-        public $alpha_to = array();  // log lookup table 
2291
-        public $index_of = array();  // Antilog lookup table 
2292
-        public $genpoly = array();   // Generator polynomial 
2293
-        public $nroots;              // Number of generator roots = number of parity symbols 
2294
-        public $fcr;                 // First consecutive root, index form 
2295
-        public $prim;                // Primitive element, index form 
2296
-        public $iprim;               // prim-th root of 1, index form 
2297
-        public $pad;                 // Padding bytes in shortened block 
2288
+        public $mm; // Bits per symbol 
2289
+        public $nn; // Symbols per block (= (1<<mm)-1) 
2290
+        public $alpha_to = array(); // log lookup table 
2291
+        public $index_of = array(); // Antilog lookup table 
2292
+        public $genpoly = array(); // Generator polynomial 
2293
+        public $nroots; // Number of generator roots = number of parity symbols 
2294
+        public $fcr; // First consecutive root, index form 
2295
+        public $prim; // Primitive element, index form 
2296
+        public $iprim; // prim-th root of 1, index form 
2297
+        public $pad; // Padding bytes in shortened block 
2298 2298
         public $gfpoly;
2299 2299
     
2300 2300
         //----------------------------------------------------------------------
@@ -2318,47 +2318,47 @@  discard block
 block discarded – undo
2318 2318
             $rs = null;
2319 2319
             
2320 2320
             // Check parameter ranges
2321
-            if($symsize < 0 || $symsize > 8)                     return $rs;
2322
-            if($fcr < 0 || $fcr >= (1<<$symsize))                return $rs;
2323
-            if($prim <= 0 || $prim >= (1<<$symsize))             return $rs;
2324
-            if($nroots < 0 || $nroots >= (1<<$symsize))          return $rs; // Can't have more roots than symbol values!
2325
-            if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding
2321
+            if ($symsize < 0 || $symsize > 8)                     return $rs;
2322
+            if ($fcr < 0 || $fcr >= (1 << $symsize))                return $rs;
2323
+            if ($prim <= 0 || $prim >= (1 << $symsize))             return $rs;
2324
+            if ($nroots < 0 || $nroots >= (1 << $symsize))          return $rs; // Can't have more roots than symbol values!
2325
+            if ($pad < 0 || $pad >= ((1 << $symsize) - 1 - $nroots)) return $rs; // Too much padding
2326 2326
 
2327 2327
             $rs = new QRrsItem();
2328 2328
             $rs->mm = $symsize;
2329
-            $rs->nn = (1<<$symsize)-1;
2329
+            $rs->nn = (1 << $symsize) - 1;
2330 2330
             $rs->pad = $pad;
2331 2331
 
2332
-            $rs->alpha_to = array_fill(0, $rs->nn+1, 0);
2333
-            $rs->index_of = array_fill(0, $rs->nn+1, 0);
2332
+            $rs->alpha_to = array_fill(0, $rs->nn + 1, 0);
2333
+            $rs->index_of = array_fill(0, $rs->nn + 1, 0);
2334 2334
           
2335 2335
             // PHP style macro replacement ;)
2336
-            $NN =& $rs->nn;
2337
-            $A0 =& $NN;
2336
+            $NN = & $rs->nn;
2337
+            $A0 = & $NN;
2338 2338
             
2339 2339
             // Generate Galois field lookup tables
2340 2340
             $rs->index_of[0] = $A0; // log(zero) = -inf
2341 2341
             $rs->alpha_to[$A0] = 0; // alpha**-inf = 0
2342 2342
             $sr = 1;
2343 2343
           
2344
-            for($i=0; $i<$rs->nn; $i++) {
2344
+            for ($i = 0; $i < $rs->nn; $i++) {
2345 2345
                 $rs->index_of[$sr] = $i;
2346 2346
                 $rs->alpha_to[$i] = $sr;
2347 2347
                 $sr <<= 1;
2348
-                if($sr & (1<<$symsize)) {
2348
+                if ($sr & (1 << $symsize)) {
2349 2349
                     $sr ^= $gfpoly;
2350 2350
                 }
2351 2351
                 $sr &= $rs->nn;
2352 2352
             }
2353 2353
             
2354
-            if($sr != 1){
2354
+            if ($sr != 1) {
2355 2355
                 // field generator polynomial is not primitive!
2356 2356
                 $rs = NULL;
2357 2357
                 return $rs;
2358 2358
             }
2359 2359
 
2360 2360
             /* Form RS code generator polynomial from its roots */
2361
-            $rs->genpoly = array_fill(0, $nroots+1, 0);
2361
+            $rs->genpoly = array_fill(0, $nroots + 1, 0);
2362 2362
         
2363 2363
             $rs->fcr = $fcr;
2364 2364
             $rs->prim = $prim;
@@ -2366,21 +2366,21 @@  discard block
 block discarded – undo
2366 2366
             $rs->gfpoly = $gfpoly;
2367 2367
 
2368 2368
             /* Find prim-th root of 1, used in decoding */
2369
-            for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn)
2369
+            for ($iprim = 1; ($iprim % $prim) != 0; $iprim += $rs->nn)
2370 2370
             ; // intentional empty-body loop!
2371 2371
             
2372
-            $rs->iprim = (int)($iprim / $prim);
2372
+            $rs->iprim = (int) ($iprim / $prim);
2373 2373
             $rs->genpoly[0] = 1;
2374 2374
             
2375
-            for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) {
2376
-                $rs->genpoly[$i+1] = 1;
2375
+            for ($i = 0, $root = $fcr * $prim; $i < $nroots; $i++, $root += $prim) {
2376
+                $rs->genpoly[$i + 1] = 1;
2377 2377
 
2378 2378
                 // Multiply rs->genpoly[] by  @**(root + x)
2379 2379
                 for ($j = $i; $j > 0; $j--) {
2380 2380
                     if ($rs->genpoly[$j] != 0) {
2381
-                        $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)];
2381
+                        $rs->genpoly[$j] = $rs->genpoly[$j - 1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)];
2382 2382
                     } else {
2383
-                        $rs->genpoly[$j] = $rs->genpoly[$j-1];
2383
+                        $rs->genpoly[$j] = $rs->genpoly[$j - 1];
2384 2384
                     }
2385 2385
                 }
2386 2386
                 // rs->genpoly[0] can never be zero
@@ -2397,38 +2397,38 @@  discard block
 block discarded – undo
2397 2397
         //----------------------------------------------------------------------
2398 2398
         public function encode_rs_char($data, &$parity)
2399 2399
         {
2400
-            $MM       =& $this->mm;
2401
-            $NN       =& $this->nn;
2402
-            $ALPHA_TO =& $this->alpha_to;
2403
-            $INDEX_OF =& $this->index_of;
2404
-            $GENPOLY  =& $this->genpoly;
2405
-            $NROOTS   =& $this->nroots;
2406
-            $FCR      =& $this->fcr;
2407
-            $PRIM     =& $this->prim;
2408
-            $IPRIM    =& $this->iprim;
2409
-            $PAD      =& $this->pad;
2410
-            $A0       =& $NN;
2400
+            $MM       = & $this->mm;
2401
+            $NN       = & $this->nn;
2402
+            $ALPHA_TO = & $this->alpha_to;
2403
+            $INDEX_OF = & $this->index_of;
2404
+            $GENPOLY  = & $this->genpoly;
2405
+            $NROOTS   = & $this->nroots;
2406
+            $FCR      = & $this->fcr;
2407
+            $PRIM     = & $this->prim;
2408
+            $IPRIM    = & $this->iprim;
2409
+            $PAD      = & $this->pad;
2410
+            $A0       = & $NN;
2411 2411
 
2412 2412
             $parity = array_fill(0, $NROOTS, 0);
2413 2413
 
2414
-            for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) {
2414
+            for ($i = 0; $i < ($NN - $NROOTS - $PAD); $i++) {
2415 2415
                 
2416 2416
                 $feedback = $INDEX_OF[$data[$i] ^ $parity[0]];
2417
-                if($feedback != $A0) {      
2417
+                if ($feedback != $A0) {      
2418 2418
                     // feedback term is non-zero
2419 2419
             
2420 2420
                     // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
2421 2421
                     // always be for the polynomials constructed by init_rs()
2422 2422
                     $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback);
2423 2423
             
2424
-                    for($j=1;$j<$NROOTS;$j++) {
2425
-                        $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])];
2424
+                    for ($j = 1; $j < $NROOTS; $j++) {
2425
+                        $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS - $j])];
2426 2426
                     }
2427 2427
                 }
2428 2428
                 
2429 2429
                 // Shift 
2430 2430
                 array_shift($parity);
2431
-                if($feedback != $A0) {
2431
+                if ($feedback != $A0) {
2432 2432
                     array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]);
2433 2433
                 } else {
2434 2434
                     array_push($parity, 0);
@@ -2446,13 +2446,13 @@  discard block
 block discarded – undo
2446 2446
         //----------------------------------------------------------------------
2447 2447
         public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
2448 2448
         {
2449
-            foreach(self::$items as $rs) {
2450
-                if($rs->pad != $pad)       continue;
2451
-                if($rs->nroots != $nroots) continue;
2452
-                if($rs->mm != $symsize)    continue;
2453
-                if($rs->gfpoly != $gfpoly) continue;
2454
-                if($rs->fcr != $fcr)       continue;
2455
-                if($rs->prim != $prim)     continue;
2449
+            foreach (self::$items as $rs) {
2450
+                if ($rs->pad != $pad)       continue;
2451
+                if ($rs->nroots != $nroots) continue;
2452
+                if ($rs->mm != $symsize)    continue;
2453
+                if ($rs->gfpoly != $gfpoly) continue;
2454
+                if ($rs->fcr != $fcr)       continue;
2455
+                if ($rs->prim != $prim)     continue;
2456 2456
 
2457 2457
                 return $rs;
2458 2458
             }
@@ -2516,10 +2516,10 @@  discard block
 block discarded – undo
2516 2516
         public function writeFormatInformation($width, &$frame, $mask, $level)
2517 2517
         {
2518 2518
             $blacks = 0;
2519
-            $format =  QRspec::getFormatInfo($mask, $level);
2519
+            $format = QRspec::getFormatInfo($mask, $level);
2520 2520
 
2521
-            for($i=0; $i<8; $i++) {
2522
-                if($format & 1) {
2521
+            for ($i = 0; $i < 8; $i++) {
2522
+                if ($format & 1) {
2523 2523
                     $blacks += 2;
2524 2524
                     $v = 0x85;
2525 2525
                 } else {
@@ -2527,7 +2527,7 @@  discard block
 block discarded – undo
2527 2527
                 }
2528 2528
                 
2529 2529
                 $frame[8][$width - 1 - $i] = chr($v);
2530
-                if($i < 6) {
2530
+                if ($i < 6) {
2531 2531
                     $frame[$i][8] = chr($v);
2532 2532
                 } else {
2533 2533
                     $frame[$i + 1][8] = chr($v);
@@ -2535,8 +2535,8 @@  discard block
 block discarded – undo
2535 2535
                 $format = $format >> 1;
2536 2536
             }
2537 2537
             
2538
-            for($i=0; $i<7; $i++) {
2539
-                if($format & 1) {
2538
+            for ($i = 0; $i < 7; $i++) {
2539
+                if ($format & 1) {
2540 2540
                     $blacks += 2;
2541 2541
                     $v = 0x85;
2542 2542
                 } else {
@@ -2544,7 +2544,7 @@  discard block
 block discarded – undo
2544 2544
                 }
2545 2545
                 
2546 2546
                 $frame[$width - 7 + $i][8] = chr($v);
2547
-                if($i == 0) {
2547
+                if ($i == 0) {
2548 2548
                     $frame[8][7] = chr($v);
2549 2549
                 } else {
2550 2550
                     $frame[8][6 - $i] = chr($v);
@@ -2557,27 +2557,27 @@  discard block
 block discarded – undo
2557 2557
         }
2558 2558
         
2559 2559
         //----------------------------------------------------------------------
2560
-        public function mask0($x, $y) { return ($x+$y)&1;                       }
2561
-        public function mask1($x, $y) { return ($y&1);                          }
2562
-        public function mask2($x, $y) { return ($x%3);                          }
2563
-        public function mask3($x, $y) { return ($x+$y)%3;                       }
2564
-        public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; }
2565
-        public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3;           }
2566
-        public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1;       }
2567
-        public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1;     }
2560
+        public function mask0($x, $y) { return ($x + $y) & 1; }
2561
+        public function mask1($x, $y) { return ($y & 1); }
2562
+        public function mask2($x, $y) { return ($x % 3); }
2563
+        public function mask3($x, $y) { return ($x + $y) % 3; }
2564
+        public function mask4($x, $y) { return (((int) ($y / 2)) + ((int) ($x / 3))) & 1; }
2565
+        public function mask5($x, $y) { return (($x * $y) & 1) + ($x * $y) % 3; }
2566
+        public function mask6($x, $y) { return ((($x * $y) & 1) + ($x * $y) % 3) & 1; }
2567
+        public function mask7($x, $y) { return ((($x * $y) % 3) + (($x + $y) & 1)) & 1; }
2568 2568
         
2569 2569
         //----------------------------------------------------------------------
2570 2570
         private function generateMaskNo($maskNo, $width, $frame)
2571 2571
         {
2572 2572
             $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
2573 2573
             
2574
-            for($y=0; $y<$width; $y++) {
2575
-                for($x=0; $x<$width; $x++) {
2576
-                    if(ord($frame[$y][$x]) & 0x80) {
2574
+            for ($y = 0; $y < $width; $y++) {
2575
+                for ($x = 0; $x < $width; $x++) {
2576
+                    if (ord($frame[$y][$x]) & 0x80) {
2577 2577
                         $bitMask[$y][$x] = 0;
2578 2578
                     } else {
2579 2579
                         $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y);
2580
-                        $bitMask[$y][$x] = ($maskFunc == 0)?1:0;
2580
+                        $bitMask[$y][$x] = ($maskFunc == 0) ? 1 : 0;
2581 2581
                     }
2582 2582
                     
2583 2583
                 }
@@ -2635,12 +2635,12 @@  discard block
 block discarded – undo
2635 2635
                 
2636 2636
             $d = $s;
2637 2637
 
2638
-            for($y=0; $y<$width; $y++) {
2639
-                for($x=0; $x<$width; $x++) {
2640
-                    if($bitMask[$y][$x] == 1) {
2641
-                        $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]);
2638
+            for ($y = 0; $y < $width; $y++) {
2639
+                for ($x = 0; $x < $width; $x++) {
2640
+                    if ($bitMask[$y][$x] == 1) {
2641
+                        $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int) $bitMask[$y][$x]);
2642 2642
                     }
2643
-                    $b += (int)(ord($d[$y][$x]) & 1);
2643
+                    $b += (int) (ord($d[$y][$x]) & 1);
2644 2644
                 }
2645 2645
             }
2646 2646
 
@@ -2662,21 +2662,21 @@  discard block
 block discarded – undo
2662 2662
         {
2663 2663
             $demerit = 0;
2664 2664
 
2665
-            for($i=0; $i<$length; $i++) {
2665
+            for ($i = 0; $i < $length; $i++) {
2666 2666
                 
2667
-                if($this->runLength[$i] >= 5) {
2667
+                if ($this->runLength[$i] >= 5) {
2668 2668
                     $demerit += (N1 + ($this->runLength[$i] - 5));
2669 2669
                 }
2670
-                if($i & 1) {
2671
-                    if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) {
2672
-                        $fact = (int)($this->runLength[$i] / 3);
2673
-                        if(($this->runLength[$i-2] == $fact) &&
2674
-                           ($this->runLength[$i-1] == $fact) &&
2675
-                           ($this->runLength[$i+1] == $fact) &&
2676
-                           ($this->runLength[$i+2] == $fact)) {
2677
-                            if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) {
2670
+                if ($i & 1) {
2671
+                    if (($i >= 3) && ($i < ($length - 2)) && ($this->runLength[$i] % 3 == 0)) {
2672
+                        $fact = (int) ($this->runLength[$i] / 3);
2673
+                        if (($this->runLength[$i - 2] == $fact) &&
2674
+                           ($this->runLength[$i - 1] == $fact) &&
2675
+                           ($this->runLength[$i + 1] == $fact) &&
2676
+                           ($this->runLength[$i + 2] == $fact)) {
2677
+                            if (($this->runLength[$i - 3] < 0) || ($this->runLength[$i - 3] >= (4 * $fact))) {
2678 2678
                                 $demerit += N3;
2679
-                            } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) {
2679
+                            } else if ((($i + 3) >= $length) || ($this->runLength[$i + 3] >= (4 * $fact))) {
2680 2680
                                 $demerit += N3;
2681 2681
                             }
2682 2682
                         }
@@ -2692,30 +2692,30 @@  discard block
 block discarded – undo
2692 2692
             $head = 0;
2693 2693
             $demerit = 0;
2694 2694
 
2695
-            for($y=0; $y<$width; $y++) {
2695
+            for ($y = 0; $y < $width; $y++) {
2696 2696
                 $head = 0;
2697 2697
                 $this->runLength[0] = 1;
2698 2698
                 
2699 2699
                 $frameY = $frame[$y];
2700 2700
                 
2701
-                if ($y>0)
2702
-                    $frameYM = $frame[$y-1];
2701
+                if ($y > 0)
2702
+                    $frameYM = $frame[$y - 1];
2703 2703
                 
2704
-                for($x=0; $x<$width; $x++) {
2705
-                    if(($x > 0) && ($y > 0)) {
2706
-                        $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]);
2707
-                        $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]);
2704
+                for ($x = 0; $x < $width; $x++) {
2705
+                    if (($x > 0) && ($y > 0)) {
2706
+                        $b22 = ord($frameY[$x]) & ord($frameY[$x - 1]) & ord($frameYM[$x]) & ord($frameYM[$x - 1]);
2707
+                        $w22 = ord($frameY[$x]) | ord($frameY[$x - 1]) | ord($frameYM[$x]) | ord($frameYM[$x - 1]);
2708 2708
                         
2709
-                        if(($b22 | ($w22 ^ 1))&1) {                                                                     
2709
+                        if (($b22 | ($w22 ^ 1)) & 1) {                                                                     
2710 2710
                             $demerit += N2;
2711 2711
                         }
2712 2712
                     }
2713
-                    if(($x == 0) && (ord($frameY[$x]) & 1)) {
2713
+                    if (($x == 0) && (ord($frameY[$x]) & 1)) {
2714 2714
                         $this->runLength[0] = -1;
2715 2715
                         $head = 1;
2716 2716
                         $this->runLength[$head] = 1;
2717
-                    } else if($x > 0) {
2718
-                        if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) {
2717
+                    } else if ($x > 0) {
2718
+                        if ((ord($frameY[$x]) ^ ord($frameY[$x - 1])) & 1) {
2719 2719
                             $head++;
2720 2720
                             $this->runLength[$head] = 1;
2721 2721
                         } else {
@@ -2724,20 +2724,20 @@  discard block
 block discarded – undo
2724 2724
                     }
2725 2725
                 }
2726 2726
     
2727
-                $demerit += $this->calcN1N3($head+1);
2727
+                $demerit += $this->calcN1N3($head + 1);
2728 2728
             }
2729 2729
 
2730
-            for($x=0; $x<$width; $x++) {
2730
+            for ($x = 0; $x < $width; $x++) {
2731 2731
                 $head = 0;
2732 2732
                 $this->runLength[0] = 1;
2733 2733
                 
2734
-                for($y=0; $y<$width; $y++) {
2735
-                    if($y == 0 && (ord($frame[$y][$x]) & 1)) {
2734
+                for ($y = 0; $y < $width; $y++) {
2735
+                    if ($y == 0 && (ord($frame[$y][$x]) & 1)) {
2736 2736
                         $this->runLength[0] = -1;
2737 2737
                         $head = 1;
2738 2738
                         $this->runLength[$head] = 1;
2739
-                    } else if($y > 0) {
2740
-                        if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) {
2739
+                    } else if ($y > 0) {
2740
+                        if ((ord($frame[$y][$x]) ^ ord($frame[$y - 1][$x])) & 1) {
2741 2741
                             $head++;
2742 2742
                             $this->runLength[$head] = 1;
2743 2743
                         } else {
@@ -2746,7 +2746,7 @@  discard block
 block discarded – undo
2746 2746
                     }
2747 2747
                 }
2748 2748
             
2749
-                $demerit += $this->calcN1N3($head+1);
2749
+                $demerit += $this->calcN1N3($head + 1);
2750 2750
             }
2751 2751
 
2752 2752
             return $demerit;
@@ -2760,13 +2760,13 @@  discard block
 block discarded – undo
2760 2760
             $bestMaskNum = 0;
2761 2761
             $bestMask = array();
2762 2762
             
2763
-            $checked_masks = array(0,1,2,3,4,5,6,7);
2763
+            $checked_masks = array(0, 1, 2, 3, 4, 5, 6, 7);
2764 2764
             
2765 2765
             if (QR_FIND_FROM_RANDOM !== false) {
2766 2766
             
2767
-                $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9);
2768
-                for ($i = 0; $i <  $howManuOut; $i++) {
2769
-                    $remPos = rand (0, count($checked_masks)-1);
2767
+                $howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9);
2768
+                for ($i = 0; $i < $howManuOut; $i++) {
2769
+                    $remPos = rand(0, count($checked_masks) - 1);
2770 2770
                     unset($checked_masks[$remPos]);
2771 2771
                     $checked_masks = array_values($checked_masks);
2772 2772
                 }
@@ -2775,18 +2775,18 @@  discard block
 block discarded – undo
2775 2775
             
2776 2776
             $bestMask = $frame;
2777 2777
              
2778
-            foreach($checked_masks as $i) {
2778
+            foreach ($checked_masks as $i) {
2779 2779
                 $mask = array_fill(0, $width, str_repeat("\0", $width));
2780 2780
 
2781 2781
                 $demerit = 0;
2782 2782
                 $blacks = 0;
2783 2783
                 $blacks  = $this->makeMaskNo($i, $width, $frame, $mask);
2784 2784
                 $blacks += $this->writeFormatInformation($width, $mask, $i, $level);
2785
-                $blacks  = (int)(100 * $blacks / ($width * $width));
2786
-                $demerit = (int)((int)(abs($blacks - 50) / 5) * N4);
2785
+                $blacks  = (int) (100 * $blacks / ($width * $width));
2786
+                $demerit = (int) ((int) (abs($blacks - 50) / 5) * N4);
2787 2787
                 $demerit += $this->evaluateSymbol($width, $mask);
2788 2788
                 
2789
-                if($demerit < $minDemerit) {
2789
+                if ($demerit < $minDemerit) {
2790 2790
                     $minDemerit = $demerit;
2791 2791
                     $bestMask = $mask;
2792 2792
                     $bestMaskNum = $i;
@@ -2866,10 +2866,10 @@  discard block
 block discarded – undo
2866 2866
         //----------------------------------------------------------------------
2867 2867
         public function __construct(QRinput $input)
2868 2868
         {
2869
-            $spec = array(0,0,0,0,0);
2869
+            $spec = array(0, 0, 0, 0, 0);
2870 2870
             
2871 2871
             $this->datacode = $input->getByteStream();
2872
-            if(is_null($this->datacode)) {
2872
+            if (is_null($this->datacode)) {
2873 2873
                 throw new Exception('null imput string');
2874 2874
             }
2875 2875
 
@@ -2883,7 +2883,7 @@  discard block
 block discarded – undo
2883 2883
             $this->blocks = QRspec::rsBlockNum($spec);
2884 2884
             
2885 2885
             $ret = $this->init($spec);
2886
-            if($ret < 0) {
2886
+            if ($ret < 0) {
2887 2887
                 throw new Exception('block alloc error');
2888 2888
                 return null;
2889 2889
             }
@@ -2902,29 +2902,29 @@  discard block
 block discarded – undo
2902 2902
             $blockNo = 0;
2903 2903
             $dataPos = 0;
2904 2904
             $eccPos = 0;
2905
-            for($i=0; $i<QRspec::rsBlockNum1($spec); $i++) {
2906
-                $ecc = array_slice($this->ecccode,$eccPos);
2907
-                $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el,  $ecc, $rs);
2908
-                $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
2905
+            for ($i = 0; $i < QRspec::rsBlockNum1($spec); $i++) {
2906
+                $ecc = array_slice($this->ecccode, $eccPos);
2907
+                $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs);
2908
+                $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc);
2909 2909
                 
2910 2910
                 $dataPos += $dl;
2911 2911
                 $eccPos += $el;
2912 2912
                 $blockNo++;
2913 2913
             }
2914 2914
 
2915
-            if(QRspec::rsBlockNum2($spec) == 0)
2915
+            if (QRspec::rsBlockNum2($spec) == 0)
2916 2916
                 return 0;
2917 2917
 
2918 2918
             $dl = QRspec::rsDataCodes2($spec);
2919 2919
             $el = QRspec::rsEccCodes2($spec);
2920 2920
             $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
2921 2921
             
2922
-            if($rs == NULL) return -1;
2922
+            if ($rs == NULL) return -1;
2923 2923
             
2924
-            for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) {
2925
-                $ecc = array_slice($this->ecccode,$eccPos);
2924
+            for ($i = 0; $i < QRspec::rsBlockNum2($spec); $i++) {
2925
+                $ecc = array_slice($this->ecccode, $eccPos);
2926 2926
                 $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs);
2927
-                $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
2927
+                $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc);
2928 2928
                 
2929 2929
                 $dataPos += $dl;
2930 2930
                 $eccPos += $el;
@@ -2939,14 +2939,14 @@  discard block
 block discarded – undo
2939 2939
         {
2940 2940
             $ret = 0;
2941 2941
 
2942
-            if($this->count < $this->dataLength) {
2942
+            if ($this->count < $this->dataLength) {
2943 2943
                 $row = $this->count % $this->blocks;
2944 2944
                 $col = $this->count / $this->blocks;
2945
-                if($col >= $this->rsblocks[0]->dataLength) {
2945
+                if ($col >= $this->rsblocks[0]->dataLength) {
2946 2946
                     $row += $this->b1;
2947 2947
                 }
2948 2948
                 $ret = $this->rsblocks[$row]->data[$col];
2949
-            } else if($this->count < $this->dataLength + $this->eccLength) {
2949
+            } else if ($this->count < $this->dataLength + $this->eccLength) {
2950 2950
                 $row = ($this->count - $this->dataLength) % $this->blocks;
2951 2951
                 $col = ($this->count - $this->dataLength) / $this->blocks;
2952 2952
                 $ret = $this->rsblocks[$row]->ecc[$col];
@@ -2970,10 +2970,10 @@  discard block
 block discarded – undo
2970 2970
         //----------------------------------------------------------------------
2971 2971
         public function encodeMask(QRinput $input, $mask)
2972 2972
         {
2973
-            if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) {
2973
+            if ($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) {
2974 2974
                 throw new Exception('wrong version');
2975 2975
             }
2976
-            if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) {
2976
+            if ($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) {
2977 2977
                 throw new Exception('wrong level');
2978 2978
             }
2979 2979
 
@@ -2986,15 +2986,15 @@  discard block
 block discarded – undo
2986 2986
             $frame = QRspec::newFrame($version);
2987 2987
             
2988 2988
             $filler = new FrameFiller($width, $frame);
2989
-            if(is_null($filler)) {
2989
+            if (is_null($filler)) {
2990 2990
                 return NULL;
2991 2991
             }
2992 2992
 
2993 2993
             // inteleaved data and ecc codes
2994
-            for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) {
2994
+            for ($i = 0; $i < $raw->dataLength + $raw->eccLength; $i++) {
2995 2995
                 $code = $raw->getCode();
2996 2996
                 $bit = 0x80;
2997
-                for($j=0; $j<8; $j++) {
2997
+                for ($j = 0; $j < 8; $j++) {
2998 2998
                     $addr = $filler->next();
2999 2999
                     $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0));
3000 3000
                     $bit = $bit >> 1;
@@ -3007,7 +3007,7 @@  discard block
 block discarded – undo
3007 3007
             
3008 3008
             // remainder bits
3009 3009
             $j = QRspec::getRemainder($version);
3010
-            for($i=0; $i<$j; $i++) {
3010
+            for ($i = 0; $i < $j; $i++) {
3011 3011
                 $addr = $filler->next();
3012 3012
                 $filler->setFrameAt($addr, 0x02);
3013 3013
             }
@@ -3018,7 +3018,7 @@  discard block
 block discarded – undo
3018 3018
             
3019 3019
             // masking
3020 3020
             $maskObj = new QRmask();
3021
-            if($mask < 0) {
3021
+            if ($mask < 0) {
3022 3022
             
3023 3023
                 if (QR_FIND_BEST_MASK) {
3024 3024
                     $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel());
@@ -3029,7 +3029,7 @@  discard block
 block discarded – undo
3029 3029
                 $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel());
3030 3030
             }
3031 3031
             
3032
-            if($masked == NULL) {
3032
+            if ($masked == NULL) {
3033 3033
                 return NULL;
3034 3034
             }
3035 3035
             
@@ -3051,16 +3051,16 @@  discard block
 block discarded – undo
3051 3051
         //----------------------------------------------------------------------
3052 3052
         public function encodeString8bit($string, $version, $level)
3053 3053
         {
3054
-            if(string == NULL) {
3054
+            if (string == NULL) {
3055 3055
                 throw new Exception('empty string!');
3056 3056
                 return NULL;
3057 3057
             }
3058 3058
 
3059 3059
             $input = new QRinput($version, $level);
3060
-            if($input == NULL) return NULL;
3060
+            if ($input == NULL) return NULL;
3061 3061
 
3062 3062
             $ret = $input->append(QR_MODE_8, strlen($string), str_split($string));
3063
-            if($ret < 0) {
3063
+            if ($ret < 0) {
3064 3064
                 unset($input);
3065 3065
                 return NULL;
3066 3066
             }
@@ -3071,16 +3071,16 @@  discard block
 block discarded – undo
3071 3071
         public function encodeString($string, $version, $level, $hint, $casesensitive)
3072 3072
         {
3073 3073
 
3074
-            if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) {
3074
+            if ($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) {
3075 3075
                 throw new Exception('bad hint');
3076 3076
                 return NULL;
3077 3077
             }
3078 3078
 
3079 3079
             $input = new QRinput($version, $level);
3080
-            if($input == NULL) return NULL;
3080
+            if ($input == NULL) return NULL;
3081 3081
 
3082 3082
             $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive);
3083
-            if($ret < 0) {
3083
+            if ($ret < 0) {
3084 3084
                 return NULL;
3085 3085
             }
3086 3086
 
@@ -3088,10 +3088,10 @@  discard block
 block discarded – undo
3088 3088
         }
3089 3089
         
3090 3090
         //----------------------------------------------------------------------
3091
-        public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false) 
3091
+        public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint = false) 
3092 3092
         {
3093 3093
             $enc = QRencode::factory($level, $size, $margin);
3094
-            return $enc->encodePNG($text, $outfile, $saveandprint=false);
3094
+            return $enc->encodePNG($text, $outfile, $saveandprint = false);
3095 3095
         }
3096 3096
 
3097 3097
         //----------------------------------------------------------------------
@@ -3148,7 +3148,7 @@  discard block
 block discarded – undo
3148 3148
         {
3149 3149
             do {
3150 3150
             
3151
-                if($this->bit == -1) {
3151
+                if ($this->bit == -1) {
3152 3152
                     $this->bit = 0;
3153 3153
                     return array('x'=>$this->x, 'y'=>$this->y);
3154 3154
                 }
@@ -3157,7 +3157,7 @@  discard block
 block discarded – undo
3157 3157
                 $y = $this->y;
3158 3158
                 $w = $this->width;
3159 3159
 
3160
-                if($this->bit == 0) {
3160
+                if ($this->bit == 0) {
3161 3161
                     $x--;
3162 3162
                     $this->bit++;
3163 3163
                 } else {
@@ -3166,33 +3166,33 @@  discard block
 block discarded – undo
3166 3166
                     $this->bit--;
3167 3167
                 }
3168 3168
 
3169
-                if($this->dir < 0) {
3170
-                    if($y < 0) {
3169
+                if ($this->dir < 0) {
3170
+                    if ($y < 0) {
3171 3171
                         $y = 0;
3172 3172
                         $x -= 2;
3173 3173
                         $this->dir = 1;
3174
-                        if($x == 6) {
3174
+                        if ($x == 6) {
3175 3175
                             $x--;
3176 3176
                             $y = 9;
3177 3177
                         }
3178 3178
                     }
3179 3179
                 } else {
3180
-                    if($y == $w) {
3180
+                    if ($y == $w) {
3181 3181
                         $y = $w - 1;
3182 3182
                         $x -= 2;
3183 3183
                         $this->dir = -1;
3184
-                        if($x == 6) {
3184
+                        if ($x == 6) {
3185 3185
                             $x--;
3186 3186
                             $y -= 8;
3187 3187
                         }
3188 3188
                     }
3189 3189
                 }
3190
-                if($x < 0 || $y < 0) return null;
3190
+                if ($x < 0 || $y < 0) return null;
3191 3191
 
3192 3192
                 $this->x = $x;
3193 3193
                 $this->y = $y;
3194 3194
 
3195
-            } while(ord($this->frame[$y][$x]) & 0x80);
3195
+            } while (ord($this->frame[$y][$x]) & 0x80);
3196 3196
                         
3197 3197
             return array('x'=>$x, 'y'=>$y);
3198 3198
         }
@@ -3255,7 +3255,7 @@  discard block
 block discarded – undo
3255 3255
         {
3256 3256
             $code = new QRcode();
3257 3257
 
3258
-            if($this->eightbit) {
3258
+            if ($this->eightbit) {
3259 3259
                 $code->encodeString8bit($intext, $this->version, $this->level);
3260 3260
             } else {
3261 3261
                 $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
@@ -3269,7 +3269,7 @@  discard block
 block discarded – undo
3269 3269
         {
3270 3270
             $code = new QRcode();
3271 3271
 
3272
-            if($this->eightbit) {
3272
+            if ($this->eightbit) {
3273 3273
                 $code->encodeString8bit($intext, $this->version, $this->level);
3274 3274
             } else {
3275 3275
                 $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
@@ -3277,7 +3277,7 @@  discard block
 block discarded – undo
3277 3277
             
3278 3278
             QRtools::markTime('after_encode');
3279 3279
             
3280
-            if ($outfile!== false) {
3280
+            if ($outfile !== false) {
3281 3281
                 file_put_contents($outfile, join("\n", QRtools::binarize($code->data)));
3282 3282
             } else {
3283 3283
                 return QRtools::binarize($code->data);
@@ -3285,7 +3285,7 @@  discard block
 block discarded – undo
3285 3285
         }
3286 3286
         
3287 3287
         //----------------------------------------------------------------------
3288
-        public function encodePNG($intext, $outfile = false,$saveandprint=false) 
3288
+        public function encodePNG($intext, $outfile = false, $saveandprint = false) 
3289 3289
         {
3290 3290
             try {
3291 3291
             
@@ -3297,9 +3297,9 @@  discard block
 block discarded – undo
3297 3297
                 if ($err != '')
3298 3298
                     QRtools::log($outfile, $err);
3299 3299
                 
3300
-                $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin));
3300
+                $maxSize = (int) (QR_PNG_MAXIMUM_SIZE / (count($tab) + 2 * $this->margin));
3301 3301
                 
3302
-                QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint);
3302
+                QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin, $saveandprint);
3303 3303
             
3304 3304
             } catch (Exception $e) {
3305 3305
             
Please login to merge, or discard this patch.
Braces   +194 added lines, -109 removed lines patch added patch discarded remove patch
@@ -176,8 +176,9 @@  discard block
 block discarded – undo
176 176
         {
177 177
             $barcode_array = array();
178 178
             
179
-            if (!is_array($mode))
180
-                $mode = explode(',', $mode);
179
+            if (!is_array($mode)) {
180
+                            $mode = explode(',', $mode);
181
+            }
181 182
                 
182 183
             $eccLevel = 'L';
183 184
                 
@@ -194,8 +195,9 @@  discard block
 block discarded – undo
194 195
                 
195 196
             foreach ($qrTab as $line) {
196 197
                 $arrAdd = array();
197
-                foreach(str_split($line) as $char)
198
-                    $arrAdd[] = ($char=='1')?1:0;
198
+                foreach(str_split($line) as $char) {
199
+                                    $arrAdd[] = ($char=='1')?1:0;
200
+                }
199 201
                 $barcode_array['bcode'][] = $arrAdd;
200 202
             }
201 203
                     
@@ -223,8 +225,9 @@  discard block
 block discarded – undo
223 225
 				
224 226
 				$width = count($frame);
225 227
 				$bitMask = array_fill(0, $width, array_fill(0, $width, 0));
226
-				for ($maskNo=0; $maskNo<8; $maskNo++)
227
-					$mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
228
+				for ($maskNo=0; $maskNo<8; $maskNo++) {
229
+									$mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
230
+				}
228 231
             }
229 232
 			
230 233
 			QRtools::markTime('after_build_cache');
@@ -261,8 +264,9 @@  discard block
 block discarded – undo
261 264
             list($usec, $sec) = explode(" ", microtime());
262 265
             $time = ((float)$usec + (float)$sec);
263 266
             
264
-            if (!isset($GLOBALS['qr_time_bench']))
265
-                $GLOBALS['qr_time_bench'] = array();
267
+            if (!isset($GLOBALS['qr_time_bench'])) {
268
+                            $GLOBALS['qr_time_bench'] = array();
269
+            }
266 270
             
267 271
             $GLOBALS['qr_time_bench'][$markerId] = $time;
268 272
         }
@@ -427,8 +431,9 @@  discard block
 block discarded – undo
427 431
 
428 432
             for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) {
429 433
                 $words  = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level];
430
-                if($words >= $size) 
431
-                    return $i;
434
+                if($words >= $size) {
435
+                                    return $i;
436
+                }
432 437
             }
433 438
 
434 439
             return -1;
@@ -446,8 +451,9 @@  discard block
 block discarded – undo
446 451
         //----------------------------------------------------------------------
447 452
         public static function lengthIndicator($mode, $version)
448 453
         {
449
-            if ($mode == QR_MODE_STRUCTURE)
450
-                return 0;
454
+            if ($mode == QR_MODE_STRUCTURE) {
455
+                            return 0;
456
+            }
451 457
                 
452 458
             if ($version <= 9) {
453 459
                 $l = 0;
@@ -463,8 +469,9 @@  discard block
 block discarded – undo
463 469
         //----------------------------------------------------------------------
464 470
         public static function maximumWords($mode, $version)
465 471
         {
466
-            if($mode == QR_MODE_STRUCTURE) 
467
-                return 3;
472
+            if($mode == QR_MODE_STRUCTURE) {
473
+                            return 3;
474
+            }
468 475
                 
469 476
             if($version <= 9) {
470 477
                 $l = 0;
@@ -610,8 +617,9 @@  discard block
 block discarded – undo
610 617
         //----------------------------------------------------------------------
611 618
         public static function putAlignmentPattern($version, &$frame, $width)
612 619
         {
613
-            if($version < 2)
614
-                return;
620
+            if($version < 2) {
621
+                            return;
622
+            }
615 623
 
616 624
             $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0];
617 625
             if($d < 0) {
@@ -663,8 +671,9 @@  discard block
 block discarded – undo
663 671
         //----------------------------------------------------------------------
664 672
         public static function getVersionPattern($version)
665 673
         {
666
-            if($version < 7 || $version > QRSPEC_VERSION_MAX)
667
-                return 0;
674
+            if($version < 7 || $version > QRSPEC_VERSION_MAX) {
675
+                            return 0;
676
+            }
668 677
 
669 678
             return self::$versionPattern[$version -7];
670 679
         }
@@ -681,11 +690,13 @@  discard block
 block discarded – undo
681 690
 
682 691
         public static function getFormatInfo($mask, $level)
683 692
         {
684
-            if($mask < 0 || $mask > 7)
685
-                return 0;
693
+            if($mask < 0 || $mask > 7) {
694
+                            return 0;
695
+            }
686 696
                 
687
-            if($level < 0 || $level > 3)
688
-                return 0;                
697
+            if($level < 0 || $level > 3) {
698
+                            return 0;
699
+            }
689 700
 
690 701
             return self::$formatInfo[$level][$mask];
691 702
         }
@@ -865,8 +876,9 @@  discard block
 block discarded – undo
865 876
         //----------------------------------------------------------------------
866 877
         public static function newFrame($version)
867 878
         {
868
-            if($version < 1 || $version > QRSPEC_VERSION_MAX) 
869
-                return null;
879
+            if($version < 1 || $version > QRSPEC_VERSION_MAX) {
880
+                            return null;
881
+            }
870 882
 
871 883
             if(!isset(self::$frames[$version])) {
872 884
                 
@@ -884,8 +896,9 @@  discard block
 block discarded – undo
884 896
                 }
885 897
             }
886 898
             
887
-            if(is_null(self::$frames[$version]))
888
-                return null;
899
+            if(is_null(self::$frames[$version])) {
900
+                            return null;
901
+            }
889 902
 
890 903
             return self::$frames[$version];
891 904
         }
@@ -950,7 +963,7 @@  discard block
 block discarded – undo
950 963
                     ImagePng($image, $filename);
951 964
                     header("Content-type: image/png");
952 965
                     ImagePng($image);
953
-                }else{
966
+                } else{
954 967
                     ImagePng($image, $filename);
955 968
                 }
956 969
             }
@@ -1210,8 +1223,9 @@  discard block
 block discarded – undo
1210 1223
         {
1211 1224
             $bits = 0;
1212 1225
 
1213
-            if($version == 0) 
1214
-                $version = 1;
1226
+            if($version == 0) {
1227
+                            $version = 1;
1228
+            }
1215 1229
 
1216 1230
             switch($this->mode) {
1217 1231
                 case QR_MODE_NUM:        $bits = QRinput::estimateBitsModeNum($this->size);    break;
@@ -1270,8 +1284,9 @@  discard block
 block discarded – undo
1270 1284
                             break;
1271 1285
                     }
1272 1286
                     
1273
-                    if($ret < 0)
1274
-                        return -1;
1287
+                    if($ret < 0) {
1288
+                                            return -1;
1289
+                    }
1275 1290
                 }
1276 1291
 
1277 1292
                 return $this->bstream->size();
@@ -1488,8 +1503,9 @@  discard block
 block discarded – undo
1488 1503
         //----------------------------------------------------------------------
1489 1504
         public static function checkModeKanji($size, $data)
1490 1505
         {
1491
-            if($size & 1)
1492
-                return false;
1506
+            if($size & 1) {
1507
+                            return false;
1508
+            }
1493 1509
 
1494 1510
             for($i=0; $i<$size; $i+=2) {
1495 1511
                 $val = (ord($data[$i]) << 8) | ord($data[$i+1]);
@@ -1509,8 +1525,9 @@  discard block
 block discarded – undo
1509 1525
 
1510 1526
         public static function check($mode, $size, $data)
1511 1527
         {
1512
-            if($size <= 0) 
1513
-                return false;
1528
+            if($size <= 0) {
1529
+                            return false;
1530
+            }
1514 1531
 
1515 1532
             switch($mode) {
1516 1533
                 case QR_MODE_NUM:       return self::checkModeNum($size, $data);   break;
@@ -1575,8 +1592,9 @@  discard block
 block discarded – undo
1575 1592
                     $chunks = (int)($payload / 11);
1576 1593
                     $remain = $payload - $chunks * 11;
1577 1594
                     $size = $chunks * 2;
1578
-                    if($remain >= 6) 
1579
-                        $size++;
1595
+                    if($remain >= 6) {
1596
+                                            $size++;
1597
+                    }
1580 1598
                     break;
1581 1599
                 case QR_MODE_8:
1582 1600
                     $size = (int)($payload / 8);
@@ -1593,8 +1611,12 @@  discard block
 block discarded – undo
1593 1611
             }
1594 1612
             
1595 1613
             $maxsize = QRspec::maximumWords($mode, $version);
1596
-            if($size < 0) $size = 0;
1597
-            if($size > $maxsize) $size = $maxsize;
1614
+            if($size < 0) {
1615
+            	$size = 0;
1616
+            }
1617
+            if($size > $maxsize) {
1618
+            	$size = $maxsize;
1619
+            }
1598 1620
 
1599 1621
             return $size;
1600 1622
         }
@@ -1607,8 +1629,9 @@  discard block
 block discarded – undo
1607 1629
             foreach($this->items as $item) {
1608 1630
                 $bits = $item->encodeBitStream($this->version);
1609 1631
                 
1610
-                if($bits < 0) 
1611
-                    return -1;
1632
+                if($bits < 0) {
1633
+                                    return -1;
1634
+                }
1612 1635
                     
1613 1636
                 $total += $bits;
1614 1637
             }
@@ -1627,8 +1650,9 @@  discard block
 block discarded – undo
1627 1650
             for(;;) {
1628 1651
                 $bits = $this->createBitStream();
1629 1652
                 
1630
-                if($bits < 0) 
1631
-                    return -1;
1653
+                if($bits < 0) {
1654
+                                    return -1;
1655
+                }
1632 1656
                     
1633 1657
                 $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
1634 1658
                 if($ver < 0) {
@@ -1665,8 +1689,9 @@  discard block
 block discarded – undo
1665 1689
             $padding = new QRbitstream();
1666 1690
             $ret = $padding->appendNum($words * 8 - $bits + 4, 0);
1667 1691
             
1668
-            if($ret < 0) 
1669
-                return $ret;
1692
+            if($ret < 0) {
1693
+                            return $ret;
1694
+            }
1670 1695
 
1671 1696
             $padlen = $maxwords - $words;
1672 1697
             
@@ -1679,8 +1704,9 @@  discard block
 block discarded – undo
1679 1704
                 
1680 1705
                 $ret = $padding->appendBytes($padlen, $padbuf);
1681 1706
                 
1682
-                if($ret < 0)
1683
-                    return $ret;
1707
+                if($ret < 0) {
1708
+                                    return $ret;
1709
+                }
1684 1710
                 
1685 1711
             }
1686 1712
 
@@ -1857,13 +1883,15 @@  discard block
 block discarded – undo
1857 1883
         //----------------------------------------------------------------------
1858 1884
         public function appendNum($bits, $num)
1859 1885
         {
1860
-            if ($bits == 0) 
1861
-                return 0;
1886
+            if ($bits == 0) {
1887
+                            return 0;
1888
+            }
1862 1889
 
1863 1890
             $b = QRbitstream::newFromNum($bits, $num);
1864 1891
             
1865
-            if(is_null($b))
1866
-                return -1;
1892
+            if(is_null($b)) {
1893
+                            return -1;
1894
+            }
1867 1895
 
1868 1896
             $ret = $this->append($b);
1869 1897
             unset($b);
@@ -1874,13 +1902,15 @@  discard block
 block discarded – undo
1874 1902
         //----------------------------------------------------------------------
1875 1903
         public function appendBytes($size, $data)
1876 1904
         {
1877
-            if ($size == 0) 
1878
-                return 0;
1905
+            if ($size == 0) {
1906
+                            return 0;
1907
+            }
1879 1908
 
1880 1909
             $b = QRbitstream::newFromBytes($size, $data);
1881 1910
             
1882
-            if(is_null($b))
1883
-                return -1;
1911
+            if(is_null($b)) {
1912
+                            return -1;
1913
+            }
1884 1914
 
1885 1915
             $ret = $this->append($b);
1886 1916
             unset($b);
@@ -1984,8 +2014,9 @@  discard block
 block discarded – undo
1984 2014
         //----------------------------------------------------------------------
1985 2015
         public static function isdigitat($str, $pos)
1986 2016
         {    
1987
-            if ($pos >= strlen($str))
1988
-                return false;
2017
+            if ($pos >= strlen($str)) {
2018
+                            return false;
2019
+            }
1989 2020
             
1990 2021
             return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
1991 2022
         }
@@ -1993,8 +2024,9 @@  discard block
 block discarded – undo
1993 2024
         //----------------------------------------------------------------------
1994 2025
         public static function isalnumat($str, $pos)
1995 2026
         {
1996
-            if ($pos >= strlen($str))
1997
-                return false;
2027
+            if ($pos >= strlen($str)) {
2028
+                            return false;
2029
+            }
1998 2030
                 
1999 2031
             return (QRinput::lookAnTable(ord($str[$pos])) >= 0);
2000 2032
         }
@@ -2002,8 +2034,9 @@  discard block
 block discarded – undo
2002 2034
         //----------------------------------------------------------------------
2003 2035
         public function identifyMode($pos)
2004 2036
         {
2005
-            if ($pos >= strlen($this->dataStr)) 
2006
-                return QR_MODE_NUL;
2037
+            if ($pos >= strlen($this->dataStr)) {
2038
+                            return QR_MODE_NUL;
2039
+            }
2007 2040
                 
2008 2041
             $c = $this->dataStr[$pos];
2009 2042
             
@@ -2057,8 +2090,9 @@  discard block
 block discarded – undo
2057 2090
             }
2058 2091
             
2059 2092
             $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr));
2060
-            if($ret < 0)
2061
-                return -1;
2093
+            if($ret < 0) {
2094
+                            return -1;
2095
+            }
2062 2096
 
2063 2097
             return $run;
2064 2098
         }
@@ -2104,8 +2138,9 @@  discard block
 block discarded – undo
2104 2138
             }
2105 2139
 
2106 2140
             $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr));
2107
-            if($ret < 0)
2108
-                return -1;
2141
+            if($ret < 0) {
2142
+                            return -1;
2143
+            }
2109 2144
 
2110 2145
             return $run;
2111 2146
         }
@@ -2120,8 +2155,9 @@  discard block
 block discarded – undo
2120 2155
             }
2121 2156
             
2122 2157
             $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr));
2123
-            if($ret < 0)
2124
-                return -1;
2158
+            if($ret < 0) {
2159
+                            return -1;
2160
+            }
2125 2161
 
2126 2162
             return $run;
2127 2163
         }
@@ -2175,8 +2211,9 @@  discard block
 block discarded – undo
2175 2211
             $run = $p;
2176 2212
             $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr));
2177 2213
             
2178
-            if($ret < 0)
2179
-                return -1;
2214
+            if($ret < 0) {
2215
+                            return -1;
2216
+            }
2180 2217
 
2181 2218
             return $run;
2182 2219
         }
@@ -2186,8 +2223,9 @@  discard block
 block discarded – undo
2186 2223
         {
2187 2224
             while (strlen($this->dataStr) > 0)
2188 2225
             {
2189
-                if($this->dataStr == '')
2190
-                    return 0;
2226
+                if($this->dataStr == '') {
2227
+                                    return 0;
2228
+                }
2191 2229
 
2192 2230
                 $mode = $this->identifyMode(0);
2193 2231
                 
@@ -2195,16 +2233,22 @@  discard block
 block discarded – undo
2195 2233
                     case QR_MODE_NUM: $length = $this->eatNum(); break;
2196 2234
                     case QR_MODE_AN:  $length = $this->eatAn(); break;
2197 2235
                     case QR_MODE_KANJI:
2198
-                        if ($this->modeHint == QR_MODE_KANJI)
2199
-                                $length = $this->eatKanji();
2200
-                        else    $length = $this->eat8();
2236
+                        if ($this->modeHint == QR_MODE_KANJI) {
2237
+                                                        $length = $this->eatKanji();
2238
+                        } else {
2239
+                        	$length = $this->eat8();
2240
+                        }
2201 2241
                         break;
2202 2242
                     default: $length = $this->eat8(); break;
2203 2243
                 
2204 2244
                 }
2205 2245
 
2206
-                if($length == 0) return 0;
2207
-                if($length < 0)  return -1;
2246
+                if($length == 0) {
2247
+                	return 0;
2248
+                }
2249
+                if($length < 0) {
2250
+                	return -1;
2251
+                }
2208 2252
                 
2209 2253
                 $this->dataStr = substr($this->dataStr, $length);
2210 2254
             }
@@ -2240,8 +2284,9 @@  discard block
 block discarded – undo
2240 2284
 
2241 2285
             $split = new QRsplit($string, $input, $modeHint);
2242 2286
             
2243
-            if(!$casesensitive)
2244
-                $split->toUpper();
2287
+            if(!$casesensitive) {
2288
+                            $split->toUpper();
2289
+            }
2245 2290
                 
2246 2291
             return $split->splitString();
2247 2292
         }
@@ -2318,11 +2363,23 @@  discard block
 block discarded – undo
2318 2363
             $rs = null;
2319 2364
             
2320 2365
             // Check parameter ranges
2321
-            if($symsize < 0 || $symsize > 8)                     return $rs;
2322
-            if($fcr < 0 || $fcr >= (1<<$symsize))                return $rs;
2323
-            if($prim <= 0 || $prim >= (1<<$symsize))             return $rs;
2324
-            if($nroots < 0 || $nroots >= (1<<$symsize))          return $rs; // Can't have more roots than symbol values!
2325
-            if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding
2366
+            if($symsize < 0 || $symsize > 8) {
2367
+            	return $rs;
2368
+            }
2369
+            if($fcr < 0 || $fcr >= (1<<$symsize)) {
2370
+            	return $rs;
2371
+            }
2372
+            if($prim <= 0 || $prim >= (1<<$symsize)) {
2373
+            	return $rs;
2374
+            }
2375
+            if($nroots < 0 || $nroots >= (1<<$symsize)) {
2376
+            	return $rs;
2377
+            }
2378
+            // Can't have more roots than symbol values!
2379
+            if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) {
2380
+            	return $rs;
2381
+            }
2382
+            // Too much padding
2326 2383
 
2327 2384
             $rs = new QRrsItem();
2328 2385
             $rs->mm = $symsize;
@@ -2388,8 +2445,9 @@  discard block
 block discarded – undo
2388 2445
             }
2389 2446
             
2390 2447
             // convert rs->genpoly[] to index form for quicker encoding
2391
-            for ($i = 0; $i <= $nroots; $i++)
2392
-                $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]];
2448
+            for ($i = 0; $i <= $nroots; $i++) {
2449
+                            $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]];
2450
+            }
2393 2451
 
2394 2452
             return $rs;
2395 2453
         }
@@ -2447,12 +2505,24 @@  discard block
 block discarded – undo
2447 2505
         public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
2448 2506
         {
2449 2507
             foreach(self::$items as $rs) {
2450
-                if($rs->pad != $pad)       continue;
2451
-                if($rs->nroots != $nroots) continue;
2452
-                if($rs->mm != $symsize)    continue;
2453
-                if($rs->gfpoly != $gfpoly) continue;
2454
-                if($rs->fcr != $fcr)       continue;
2455
-                if($rs->prim != $prim)     continue;
2508
+                if($rs->pad != $pad) {
2509
+                	continue;
2510
+                }
2511
+                if($rs->nroots != $nroots) {
2512
+                	continue;
2513
+                }
2514
+                if($rs->mm != $symsize) {
2515
+                	continue;
2516
+                }
2517
+                if($rs->gfpoly != $gfpoly) {
2518
+                	continue;
2519
+                }
2520
+                if($rs->fcr != $fcr) {
2521
+                	continue;
2522
+                }
2523
+                if($rs->prim != $prim) {
2524
+                	continue;
2525
+                }
2456 2526
 
2457 2527
                 return $rs;
2458 2528
             }
@@ -2591,8 +2661,9 @@  discard block
 block discarded – undo
2591 2661
         {
2592 2662
             $codeArr = array();
2593 2663
             
2594
-            foreach ($bitFrame as $line)
2595
-                $codeArr[] = join('', $line);
2664
+            foreach ($bitFrame as $line) {
2665
+                            $codeArr[] = join('', $line);
2666
+            }
2596 2667
                 
2597 2668
             return gzcompress(join("\n", $codeArr), 9);
2598 2669
         }
@@ -2603,8 +2674,9 @@  discard block
 block discarded – undo
2603 2674
             $codeArr = array();
2604 2675
             
2605 2676
             $codeLines = explode("\n", gzuncompress($code));
2606
-            foreach ($codeLines as $line)
2607
-                $codeArr[] = str_split($line);
2677
+            foreach ($codeLines as $line) {
2678
+                            $codeArr[] = str_split($line);
2679
+            }
2608 2680
             
2609 2681
             return $codeArr;
2610 2682
         }
@@ -2622,16 +2694,18 @@  discard block
 block discarded – undo
2622 2694
                     $bitMask = self::unserial(file_get_contents($fileName));
2623 2695
                 } else {
2624 2696
                     $bitMask = $this->generateMaskNo($maskNo, $width, $s);
2625
-                    if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo))
2626
-                        mkdir(QR_CACHE_DIR.'mask_'.$maskNo);
2697
+                    if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) {
2698
+                                            mkdir(QR_CACHE_DIR.'mask_'.$maskNo);
2699
+                    }
2627 2700
                     file_put_contents($fileName, self::serial($bitMask));
2628 2701
                 }
2629 2702
             } else {
2630 2703
                 $bitMask = $this->generateMaskNo($maskNo, $width, $s);
2631 2704
             }
2632 2705
 
2633
-            if ($maskGenOnly)
2634
-                return;
2706
+            if ($maskGenOnly) {
2707
+                            return;
2708
+            }
2635 2709
                 
2636 2710
             $d = $s;
2637 2711
 
@@ -2698,8 +2772,9 @@  discard block
 block discarded – undo
2698 2772
                 
2699 2773
                 $frameY = $frame[$y];
2700 2774
                 
2701
-                if ($y>0)
2702
-                    $frameYM = $frame[$y-1];
2775
+                if ($y>0) {
2776
+                                    $frameYM = $frame[$y-1];
2777
+                }
2703 2778
                 
2704 2779
                 for($x=0; $x<$width; $x++) {
2705 2780
                     if(($x > 0) && ($y > 0)) {
@@ -2912,14 +2987,17 @@  discard block
 block discarded – undo
2912 2987
                 $blockNo++;
2913 2988
             }
2914 2989
 
2915
-            if(QRspec::rsBlockNum2($spec) == 0)
2916
-                return 0;
2990
+            if(QRspec::rsBlockNum2($spec) == 0) {
2991
+                            return 0;
2992
+            }
2917 2993
 
2918 2994
             $dl = QRspec::rsDataCodes2($spec);
2919 2995
             $el = QRspec::rsEccCodes2($spec);
2920 2996
             $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
2921 2997
             
2922
-            if($rs == NULL) return -1;
2998
+            if($rs == NULL) {
2999
+            	return -1;
3000
+            }
2923 3001
             
2924 3002
             for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) {
2925 3003
                 $ecc = array_slice($this->ecccode,$eccPos);
@@ -3057,7 +3135,9 @@  discard block
 block discarded – undo
3057 3135
             }
3058 3136
 
3059 3137
             $input = new QRinput($version, $level);
3060
-            if($input == NULL) return NULL;
3138
+            if($input == NULL) {
3139
+            	return NULL;
3140
+            }
3061 3141
 
3062 3142
             $ret = $input->append(QR_MODE_8, strlen($string), str_split($string));
3063 3143
             if($ret < 0) {
@@ -3077,7 +3157,9 @@  discard block
 block discarded – undo
3077 3157
             }
3078 3158
 
3079 3159
             $input = new QRinput($version, $level);
3080
-            if($input == NULL) return NULL;
3160
+            if($input == NULL) {
3161
+            	return NULL;
3162
+            }
3081 3163
 
3082 3164
             $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive);
3083 3165
             if($ret < 0) {
@@ -3187,7 +3269,9 @@  discard block
 block discarded – undo
3187 3269
                         }
3188 3270
                     }
3189 3271
                 }
3190
-                if($x < 0 || $y < 0) return null;
3272
+                if($x < 0 || $y < 0) {
3273
+                	return null;
3274
+                }
3191 3275
 
3192 3276
                 $this->x = $x;
3193 3277
                 $this->y = $y;
@@ -3294,8 +3378,9 @@  discard block
 block discarded – undo
3294 3378
                 $err = ob_get_contents();
3295 3379
                 ob_end_clean();
3296 3380
                 
3297
-                if ($err != '')
3298
-                    QRtools::log($outfile, $err);
3381
+                if ($err != '') {
3382
+                                    QRtools::log($outfile, $err);
3383
+                }
3299 3384
                 
3300 3385
                 $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin));
3301 3386
                 
Please login to merge, or discard this patch.
lib/phpqrcode/qrmask.php 3 patches
Indentation   +237 added lines, -237 removed lines patch added patch discarded remove patch
@@ -36,293 +36,293 @@
 block discarded – undo
36 36
 		
37 37
 		//----------------------------------------------------------------------
38 38
 		public function __construct() 
39
-        {
40
-            $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0);
41
-        }
39
+		{
40
+			$this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0);
41
+		}
42 42
         
43
-        //----------------------------------------------------------------------
44
-        public function writeFormatInformation($width, &$frame, $mask, $level)
45
-        {
46
-            $blacks = 0;
47
-            $format =  QRspec::getFormatInfo($mask, $level);
43
+		//----------------------------------------------------------------------
44
+		public function writeFormatInformation($width, &$frame, $mask, $level)
45
+		{
46
+			$blacks = 0;
47
+			$format =  QRspec::getFormatInfo($mask, $level);
48 48
 
49
-            for($i=0; $i<8; $i++) {
50
-                if($format & 1) {
51
-                    $blacks += 2;
52
-                    $v = 0x85;
53
-                } else {
54
-                    $v = 0x84;
55
-                }
49
+			for($i=0; $i<8; $i++) {
50
+				if($format & 1) {
51
+					$blacks += 2;
52
+					$v = 0x85;
53
+				} else {
54
+					$v = 0x84;
55
+				}
56 56
                 
57
-                $frame[8][$width - 1 - $i] = chr($v);
58
-                if($i < 6) {
59
-                    $frame[$i][8] = chr($v);
60
-                } else {
61
-                    $frame[$i + 1][8] = chr($v);
62
-                }
63
-                $format = $format >> 1;
64
-            }
57
+				$frame[8][$width - 1 - $i] = chr($v);
58
+				if($i < 6) {
59
+					$frame[$i][8] = chr($v);
60
+				} else {
61
+					$frame[$i + 1][8] = chr($v);
62
+				}
63
+				$format = $format >> 1;
64
+			}
65 65
             
66
-            for($i=0; $i<7; $i++) {
67
-                if($format & 1) {
68
-                    $blacks += 2;
69
-                    $v = 0x85;
70
-                } else {
71
-                    $v = 0x84;
72
-                }
66
+			for($i=0; $i<7; $i++) {
67
+				if($format & 1) {
68
+					$blacks += 2;
69
+					$v = 0x85;
70
+				} else {
71
+					$v = 0x84;
72
+				}
73 73
                 
74
-                $frame[$width - 7 + $i][8] = chr($v);
75
-                if($i == 0) {
76
-                    $frame[8][7] = chr($v);
77
-                } else {
78
-                    $frame[8][6 - $i] = chr($v);
79
-                }
74
+				$frame[$width - 7 + $i][8] = chr($v);
75
+				if($i == 0) {
76
+					$frame[8][7] = chr($v);
77
+				} else {
78
+					$frame[8][6 - $i] = chr($v);
79
+				}
80 80
                 
81
-                $format = $format >> 1;
82
-            }
81
+				$format = $format >> 1;
82
+			}
83 83
 
84
-            return $blacks;
85
-        }
84
+			return $blacks;
85
+		}
86 86
         
87
-        //----------------------------------------------------------------------
88
-        public function mask0($x, $y) { return ($x+$y)&1;                       }
89
-        public function mask1($x, $y) { return ($y&1);                          }
90
-        public function mask2($x, $y) { return ($x%3);                          }
91
-        public function mask3($x, $y) { return ($x+$y)%3;                       }
92
-        public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; }
93
-        public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3;           }
94
-        public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1;       }
95
-        public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1;     }
87
+		//----------------------------------------------------------------------
88
+		public function mask0($x, $y) { return ($x+$y)&1;                       }
89
+		public function mask1($x, $y) { return ($y&1);                          }
90
+		public function mask2($x, $y) { return ($x%3);                          }
91
+		public function mask3($x, $y) { return ($x+$y)%3;                       }
92
+		public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; }
93
+		public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3;           }
94
+		public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1;       }
95
+		public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1;     }
96 96
         
97
-        //----------------------------------------------------------------------
98
-        private function generateMaskNo($maskNo, $width, $frame)
99
-        {
100
-            $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
97
+		//----------------------------------------------------------------------
98
+		private function generateMaskNo($maskNo, $width, $frame)
99
+		{
100
+			$bitMask = array_fill(0, $width, array_fill(0, $width, 0));
101 101
             
102
-            for($y=0; $y<$width; $y++) {
103
-                for($x=0; $x<$width; $x++) {
104
-                    if(ord($frame[$y][$x]) & 0x80) {
105
-                        $bitMask[$y][$x] = 0;
106
-                    } else {
107
-                        $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y);
108
-                        $bitMask[$y][$x] = ($maskFunc == 0)?1:0;
109
-                    }
102
+			for($y=0; $y<$width; $y++) {
103
+				for($x=0; $x<$width; $x++) {
104
+					if(ord($frame[$y][$x]) & 0x80) {
105
+						$bitMask[$y][$x] = 0;
106
+					} else {
107
+						$maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y);
108
+						$bitMask[$y][$x] = ($maskFunc == 0)?1:0;
109
+					}
110 110
                     
111
-                }
112
-            }
111
+				}
112
+			}
113 113
             
114
-            return $bitMask;
115
-        }
114
+			return $bitMask;
115
+		}
116 116
         
117
-        //----------------------------------------------------------------------
118
-        public static function serial($bitFrame)
119
-        {
120
-            $codeArr = array();
117
+		//----------------------------------------------------------------------
118
+		public static function serial($bitFrame)
119
+		{
120
+			$codeArr = array();
121 121
             
122
-            foreach ($bitFrame as $line)
123
-                $codeArr[] = join('', $line);
122
+			foreach ($bitFrame as $line)
123
+				$codeArr[] = join('', $line);
124 124
                 
125
-            return gzcompress(join("\n", $codeArr), 9);
126
-        }
125
+			return gzcompress(join("\n", $codeArr), 9);
126
+		}
127 127
         
128
-        //----------------------------------------------------------------------
129
-        public static function unserial($code)
130
-        {
131
-            $codeArr = array();
128
+		//----------------------------------------------------------------------
129
+		public static function unserial($code)
130
+		{
131
+			$codeArr = array();
132 132
             
133
-            $codeLines = explode("\n", gzuncompress($code));
134
-            foreach ($codeLines as $line)
135
-                $codeArr[] = str_split($line);
133
+			$codeLines = explode("\n", gzuncompress($code));
134
+			foreach ($codeLines as $line)
135
+				$codeArr[] = str_split($line);
136 136
             
137
-            return $codeArr;
138
-        }
137
+			return $codeArr;
138
+		}
139 139
         
140
-        //----------------------------------------------------------------------
141
-        public function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false) 
142
-        {
143
-            $b = 0;
144
-            $bitMask = array();
140
+		//----------------------------------------------------------------------
141
+		public function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false) 
142
+		{
143
+			$b = 0;
144
+			$bitMask = array();
145 145
             
146
-            $fileName = QR_CACHE_DIR.'mask_'.$maskNo.DIRECTORY_SEPARATOR.'mask_'.$width.'_'.$maskNo.'.dat';
146
+			$fileName = QR_CACHE_DIR.'mask_'.$maskNo.DIRECTORY_SEPARATOR.'mask_'.$width.'_'.$maskNo.'.dat';
147 147
 
148
-            if (QR_CACHEABLE) {
149
-                if (file_exists($fileName)) {
150
-                    $bitMask = self::unserial(file_get_contents($fileName));
151
-                } else {
152
-                    $bitMask = $this->generateMaskNo($maskNo, $width, $s);
153
-                    if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo))
154
-                        mkdir(QR_CACHE_DIR.'mask_'.$maskNo);
155
-                    file_put_contents($fileName, self::serial($bitMask));
156
-                }
157
-            } else {
158
-                $bitMask = $this->generateMaskNo($maskNo, $width, $s);
159
-            }
148
+			if (QR_CACHEABLE) {
149
+				if (file_exists($fileName)) {
150
+					$bitMask = self::unserial(file_get_contents($fileName));
151
+				} else {
152
+					$bitMask = $this->generateMaskNo($maskNo, $width, $s);
153
+					if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo))
154
+						mkdir(QR_CACHE_DIR.'mask_'.$maskNo);
155
+					file_put_contents($fileName, self::serial($bitMask));
156
+				}
157
+			} else {
158
+				$bitMask = $this->generateMaskNo($maskNo, $width, $s);
159
+			}
160 160
 
161
-            if ($maskGenOnly)
162
-                return;
161
+			if ($maskGenOnly)
162
+				return;
163 163
                 
164
-            $d = $s;
164
+			$d = $s;
165 165
 
166
-            for($y=0; $y<$width; $y++) {
167
-                for($x=0; $x<$width; $x++) {
168
-                    if($bitMask[$y][$x] == 1) {
169
-                        $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]);
170
-                    }
171
-                    $b += (int)(ord($d[$y][$x]) & 1);
172
-                }
173
-            }
166
+			for($y=0; $y<$width; $y++) {
167
+				for($x=0; $x<$width; $x++) {
168
+					if($bitMask[$y][$x] == 1) {
169
+						$d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]);
170
+					}
171
+					$b += (int)(ord($d[$y][$x]) & 1);
172
+				}
173
+			}
174 174
 
175
-            return $b;
176
-        }
175
+			return $b;
176
+		}
177 177
         
178
-        //----------------------------------------------------------------------
179
-        public function makeMask($width, $frame, $maskNo, $level)
180
-        {
181
-            $masked = array_fill(0, $width, str_repeat("\0", $width));
182
-            $this->makeMaskNo($maskNo, $width, $frame, $masked);
183
-            $this->writeFormatInformation($width, $masked, $maskNo, $level);
178
+		//----------------------------------------------------------------------
179
+		public function makeMask($width, $frame, $maskNo, $level)
180
+		{
181
+			$masked = array_fill(0, $width, str_repeat("\0", $width));
182
+			$this->makeMaskNo($maskNo, $width, $frame, $masked);
183
+			$this->writeFormatInformation($width, $masked, $maskNo, $level);
184 184
        
185
-            return $masked;
186
-        }
185
+			return $masked;
186
+		}
187 187
         
188
-        //----------------------------------------------------------------------
189
-        public function calcN1N3($length)
190
-        {
191
-            $demerit = 0;
188
+		//----------------------------------------------------------------------
189
+		public function calcN1N3($length)
190
+		{
191
+			$demerit = 0;
192 192
 
193
-            for($i=0; $i<$length; $i++) {
193
+			for($i=0; $i<$length; $i++) {
194 194
                 
195
-                if($this->runLength[$i] >= 5) {
196
-                    $demerit += (N1 + ($this->runLength[$i] - 5));
197
-                }
198
-                if($i & 1) {
199
-                    if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) {
200
-                        $fact = (int)($this->runLength[$i] / 3);
201
-                        if(($this->runLength[$i-2] == $fact) &&
202
-                           ($this->runLength[$i-1] == $fact) &&
203
-                           ($this->runLength[$i+1] == $fact) &&
204
-                           ($this->runLength[$i+2] == $fact)) {
205
-                            if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) {
206
-                                $demerit += N3;
207
-                            } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) {
208
-                                $demerit += N3;
209
-                            }
210
-                        }
211
-                    }
212
-                }
213
-            }
214
-            return $demerit;
215
-        }
195
+				if($this->runLength[$i] >= 5) {
196
+					$demerit += (N1 + ($this->runLength[$i] - 5));
197
+				}
198
+				if($i & 1) {
199
+					if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) {
200
+						$fact = (int)($this->runLength[$i] / 3);
201
+						if(($this->runLength[$i-2] == $fact) &&
202
+						   ($this->runLength[$i-1] == $fact) &&
203
+						   ($this->runLength[$i+1] == $fact) &&
204
+						   ($this->runLength[$i+2] == $fact)) {
205
+							if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) {
206
+								$demerit += N3;
207
+							} else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) {
208
+								$demerit += N3;
209
+							}
210
+						}
211
+					}
212
+				}
213
+			}
214
+			return $demerit;
215
+		}
216 216
         
217
-        //----------------------------------------------------------------------
218
-        public function evaluateSymbol($width, $frame)
219
-        {
220
-            $head = 0;
221
-            $demerit = 0;
217
+		//----------------------------------------------------------------------
218
+		public function evaluateSymbol($width, $frame)
219
+		{
220
+			$head = 0;
221
+			$demerit = 0;
222 222
 
223
-            for($y=0; $y<$width; $y++) {
224
-                $head = 0;
225
-                $this->runLength[0] = 1;
223
+			for($y=0; $y<$width; $y++) {
224
+				$head = 0;
225
+				$this->runLength[0] = 1;
226 226
                 
227
-                $frameY = $frame[$y];
227
+				$frameY = $frame[$y];
228 228
                 
229
-                if ($y>0)
230
-                    $frameYM = $frame[$y-1];
229
+				if ($y>0)
230
+					$frameYM = $frame[$y-1];
231 231
                 
232
-                for($x=0; $x<$width; $x++) {
233
-                    if(($x > 0) && ($y > 0)) {
234
-                        $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]);
235
-                        $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]);
232
+				for($x=0; $x<$width; $x++) {
233
+					if(($x > 0) && ($y > 0)) {
234
+						$b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]);
235
+						$w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]);
236 236
                         
237
-                        if(($b22 | ($w22 ^ 1))&1) {                                                                     
238
-                            $demerit += N2;
239
-                        }
240
-                    }
241
-                    if(($x == 0) && (ord($frameY[$x]) & 1)) {
242
-                        $this->runLength[0] = -1;
243
-                        $head = 1;
244
-                        $this->runLength[$head] = 1;
245
-                    } else if($x > 0) {
246
-                        if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) {
247
-                            $head++;
248
-                            $this->runLength[$head] = 1;
249
-                        } else {
250
-                            $this->runLength[$head]++;
251
-                        }
252
-                    }
253
-                }
237
+						if(($b22 | ($w22 ^ 1))&1) {                                                                     
238
+							$demerit += N2;
239
+						}
240
+					}
241
+					if(($x == 0) && (ord($frameY[$x]) & 1)) {
242
+						$this->runLength[0] = -1;
243
+						$head = 1;
244
+						$this->runLength[$head] = 1;
245
+					} else if($x > 0) {
246
+						if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) {
247
+							$head++;
248
+							$this->runLength[$head] = 1;
249
+						} else {
250
+							$this->runLength[$head]++;
251
+						}
252
+					}
253
+				}
254 254
     
255
-                $demerit += $this->calcN1N3($head+1);
256
-            }
255
+				$demerit += $this->calcN1N3($head+1);
256
+			}
257 257
 
258
-            for($x=0; $x<$width; $x++) {
259
-                $head = 0;
260
-                $this->runLength[0] = 1;
258
+			for($x=0; $x<$width; $x++) {
259
+				$head = 0;
260
+				$this->runLength[0] = 1;
261 261
                 
262
-                for($y=0; $y<$width; $y++) {
263
-                    if($y == 0 && (ord($frame[$y][$x]) & 1)) {
264
-                        $this->runLength[0] = -1;
265
-                        $head = 1;
266
-                        $this->runLength[$head] = 1;
267
-                    } else if($y > 0) {
268
-                        if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) {
269
-                            $head++;
270
-                            $this->runLength[$head] = 1;
271
-                        } else {
272
-                            $this->runLength[$head]++;
273
-                        }
274
-                    }
275
-                }
262
+				for($y=0; $y<$width; $y++) {
263
+					if($y == 0 && (ord($frame[$y][$x]) & 1)) {
264
+						$this->runLength[0] = -1;
265
+						$head = 1;
266
+						$this->runLength[$head] = 1;
267
+					} else if($y > 0) {
268
+						if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) {
269
+							$head++;
270
+							$this->runLength[$head] = 1;
271
+						} else {
272
+							$this->runLength[$head]++;
273
+						}
274
+					}
275
+				}
276 276
             
277
-                $demerit += $this->calcN1N3($head+1);
278
-            }
277
+				$demerit += $this->calcN1N3($head+1);
278
+			}
279 279
 
280
-            return $demerit;
281
-        }
280
+			return $demerit;
281
+		}
282 282
         
283 283
         
284
-        //----------------------------------------------------------------------
285
-        public function mask($width, $frame, $level)
286
-        {
287
-            $minDemerit = PHP_INT_MAX;
288
-            $bestMaskNum = 0;
289
-            $bestMask = array();
284
+		//----------------------------------------------------------------------
285
+		public function mask($width, $frame, $level)
286
+		{
287
+			$minDemerit = PHP_INT_MAX;
288
+			$bestMaskNum = 0;
289
+			$bestMask = array();
290 290
             
291
-            $checked_masks = array(0,1,2,3,4,5,6,7);
291
+			$checked_masks = array(0,1,2,3,4,5,6,7);
292 292
             
293
-            if (QR_FIND_FROM_RANDOM !== false) {
293
+			if (QR_FIND_FROM_RANDOM !== false) {
294 294
             
295
-                $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9);
296
-                for ($i = 0; $i <  $howManuOut; $i++) {
297
-                    $remPos = rand (0, count($checked_masks)-1);
298
-                    unset($checked_masks[$remPos]);
299
-                    $checked_masks = array_values($checked_masks);
300
-                }
295
+				$howManuOut = 8-(QR_FIND_FROM_RANDOM % 9);
296
+				for ($i = 0; $i <  $howManuOut; $i++) {
297
+					$remPos = rand (0, count($checked_masks)-1);
298
+					unset($checked_masks[$remPos]);
299
+					$checked_masks = array_values($checked_masks);
300
+				}
301 301
             
302
-            }
302
+			}
303 303
             
304
-            $bestMask = $frame;
304
+			$bestMask = $frame;
305 305
              
306
-            foreach($checked_masks as $i) {
307
-                $mask = array_fill(0, $width, str_repeat("\0", $width));
306
+			foreach($checked_masks as $i) {
307
+				$mask = array_fill(0, $width, str_repeat("\0", $width));
308 308
 
309
-                $demerit = 0;
310
-                $blacks = 0;
311
-                $blacks  = $this->makeMaskNo($i, $width, $frame, $mask);
312
-                $blacks += $this->writeFormatInformation($width, $mask, $i, $level);
313
-                $blacks  = (int)(100 * $blacks / ($width * $width));
314
-                $demerit = (int)((int)(abs($blacks - 50) / 5) * N4);
315
-                $demerit += $this->evaluateSymbol($width, $mask);
309
+				$demerit = 0;
310
+				$blacks = 0;
311
+				$blacks  = $this->makeMaskNo($i, $width, $frame, $mask);
312
+				$blacks += $this->writeFormatInformation($width, $mask, $i, $level);
313
+				$blacks  = (int)(100 * $blacks / ($width * $width));
314
+				$demerit = (int)((int)(abs($blacks - 50) / 5) * N4);
315
+				$demerit += $this->evaluateSymbol($width, $mask);
316 316
                 
317
-                if($demerit < $minDemerit) {
318
-                    $minDemerit = $demerit;
319
-                    $bestMask = $mask;
320
-                    $bestMaskNum = $i;
321
-                }
322
-            }
317
+				if($demerit < $minDemerit) {
318
+					$minDemerit = $demerit;
319
+					$bestMask = $mask;
320
+					$bestMaskNum = $i;
321
+				}
322
+			}
323 323
             
324
-            return $bestMask;
325
-        }
324
+			return $bestMask;
325
+		}
326 326
         
327
-        //----------------------------------------------------------------------
328
-    }
327
+		//----------------------------------------------------------------------
328
+	}
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -44,10 +44,10 @@  discard block
 block discarded – undo
44 44
         public function writeFormatInformation($width, &$frame, $mask, $level)
45 45
         {
46 46
             $blacks = 0;
47
-            $format =  QRspec::getFormatInfo($mask, $level);
47
+            $format = QRspec::getFormatInfo($mask, $level);
48 48
 
49
-            for($i=0; $i<8; $i++) {
50
-                if($format & 1) {
49
+            for ($i = 0; $i < 8; $i++) {
50
+                if ($format & 1) {
51 51
                     $blacks += 2;
52 52
                     $v = 0x85;
53 53
                 } else {
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
                 }
56 56
                 
57 57
                 $frame[8][$width - 1 - $i] = chr($v);
58
-                if($i < 6) {
58
+                if ($i < 6) {
59 59
                     $frame[$i][8] = chr($v);
60 60
                 } else {
61 61
                     $frame[$i + 1][8] = chr($v);
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
                 $format = $format >> 1;
64 64
             }
65 65
             
66
-            for($i=0; $i<7; $i++) {
67
-                if($format & 1) {
66
+            for ($i = 0; $i < 7; $i++) {
67
+                if ($format & 1) {
68 68
                     $blacks += 2;
69 69
                     $v = 0x85;
70 70
                 } else {
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
                 }
73 73
                 
74 74
                 $frame[$width - 7 + $i][8] = chr($v);
75
-                if($i == 0) {
75
+                if ($i == 0) {
76 76
                     $frame[8][7] = chr($v);
77 77
                 } else {
78 78
                     $frame[8][6 - $i] = chr($v);
@@ -85,27 +85,27 @@  discard block
 block discarded – undo
85 85
         }
86 86
         
87 87
         //----------------------------------------------------------------------
88
-        public function mask0($x, $y) { return ($x+$y)&1;                       }
89
-        public function mask1($x, $y) { return ($y&1);                          }
90
-        public function mask2($x, $y) { return ($x%3);                          }
91
-        public function mask3($x, $y) { return ($x+$y)%3;                       }
92
-        public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; }
93
-        public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3;           }
94
-        public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1;       }
95
-        public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1;     }
88
+        public function mask0($x, $y) { return ($x + $y) & 1; }
89
+        public function mask1($x, $y) { return ($y & 1); }
90
+        public function mask2($x, $y) { return ($x % 3); }
91
+        public function mask3($x, $y) { return ($x + $y) % 3; }
92
+        public function mask4($x, $y) { return (((int) ($y / 2)) + ((int) ($x / 3))) & 1; }
93
+        public function mask5($x, $y) { return (($x * $y) & 1) + ($x * $y) % 3; }
94
+        public function mask6($x, $y) { return ((($x * $y) & 1) + ($x * $y) % 3) & 1; }
95
+        public function mask7($x, $y) { return ((($x * $y) % 3) + (($x + $y) & 1)) & 1; }
96 96
         
97 97
         //----------------------------------------------------------------------
98 98
         private function generateMaskNo($maskNo, $width, $frame)
99 99
         {
100 100
             $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
101 101
             
102
-            for($y=0; $y<$width; $y++) {
103
-                for($x=0; $x<$width; $x++) {
104
-                    if(ord($frame[$y][$x]) & 0x80) {
102
+            for ($y = 0; $y < $width; $y++) {
103
+                for ($x = 0; $x < $width; $x++) {
104
+                    if (ord($frame[$y][$x]) & 0x80) {
105 105
                         $bitMask[$y][$x] = 0;
106 106
                     } else {
107 107
                         $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y);
108
-                        $bitMask[$y][$x] = ($maskFunc == 0)?1:0;
108
+                        $bitMask[$y][$x] = ($maskFunc == 0) ? 1 : 0;
109 109
                     }
110 110
                     
111 111
                 }
@@ -163,12 +163,12 @@  discard block
 block discarded – undo
163 163
                 
164 164
             $d = $s;
165 165
 
166
-            for($y=0; $y<$width; $y++) {
167
-                for($x=0; $x<$width; $x++) {
168
-                    if($bitMask[$y][$x] == 1) {
169
-                        $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]);
166
+            for ($y = 0; $y < $width; $y++) {
167
+                for ($x = 0; $x < $width; $x++) {
168
+                    if ($bitMask[$y][$x] == 1) {
169
+                        $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int) $bitMask[$y][$x]);
170 170
                     }
171
-                    $b += (int)(ord($d[$y][$x]) & 1);
171
+                    $b += (int) (ord($d[$y][$x]) & 1);
172 172
                 }
173 173
             }
174 174
 
@@ -190,21 +190,21 @@  discard block
 block discarded – undo
190 190
         {
191 191
             $demerit = 0;
192 192
 
193
-            for($i=0; $i<$length; $i++) {
193
+            for ($i = 0; $i < $length; $i++) {
194 194
                 
195
-                if($this->runLength[$i] >= 5) {
195
+                if ($this->runLength[$i] >= 5) {
196 196
                     $demerit += (N1 + ($this->runLength[$i] - 5));
197 197
                 }
198
-                if($i & 1) {
199
-                    if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) {
200
-                        $fact = (int)($this->runLength[$i] / 3);
201
-                        if(($this->runLength[$i-2] == $fact) &&
202
-                           ($this->runLength[$i-1] == $fact) &&
203
-                           ($this->runLength[$i+1] == $fact) &&
204
-                           ($this->runLength[$i+2] == $fact)) {
205
-                            if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) {
198
+                if ($i & 1) {
199
+                    if (($i >= 3) && ($i < ($length - 2)) && ($this->runLength[$i] % 3 == 0)) {
200
+                        $fact = (int) ($this->runLength[$i] / 3);
201
+                        if (($this->runLength[$i - 2] == $fact) &&
202
+                           ($this->runLength[$i - 1] == $fact) &&
203
+                           ($this->runLength[$i + 1] == $fact) &&
204
+                           ($this->runLength[$i + 2] == $fact)) {
205
+                            if (($this->runLength[$i - 3] < 0) || ($this->runLength[$i - 3] >= (4 * $fact))) {
206 206
                                 $demerit += N3;
207
-                            } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) {
207
+                            } else if ((($i + 3) >= $length) || ($this->runLength[$i + 3] >= (4 * $fact))) {
208 208
                                 $demerit += N3;
209 209
                             }
210 210
                         }
@@ -220,30 +220,30 @@  discard block
 block discarded – undo
220 220
             $head = 0;
221 221
             $demerit = 0;
222 222
 
223
-            for($y=0; $y<$width; $y++) {
223
+            for ($y = 0; $y < $width; $y++) {
224 224
                 $head = 0;
225 225
                 $this->runLength[0] = 1;
226 226
                 
227 227
                 $frameY = $frame[$y];
228 228
                 
229
-                if ($y>0)
230
-                    $frameYM = $frame[$y-1];
229
+                if ($y > 0)
230
+                    $frameYM = $frame[$y - 1];
231 231
                 
232
-                for($x=0; $x<$width; $x++) {
233
-                    if(($x > 0) && ($y > 0)) {
234
-                        $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]);
235
-                        $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]);
232
+                for ($x = 0; $x < $width; $x++) {
233
+                    if (($x > 0) && ($y > 0)) {
234
+                        $b22 = ord($frameY[$x]) & ord($frameY[$x - 1]) & ord($frameYM[$x]) & ord($frameYM[$x - 1]);
235
+                        $w22 = ord($frameY[$x]) | ord($frameY[$x - 1]) | ord($frameYM[$x]) | ord($frameYM[$x - 1]);
236 236
                         
237
-                        if(($b22 | ($w22 ^ 1))&1) {                                                                     
237
+                        if (($b22 | ($w22 ^ 1)) & 1) {                                                                     
238 238
                             $demerit += N2;
239 239
                         }
240 240
                     }
241
-                    if(($x == 0) && (ord($frameY[$x]) & 1)) {
241
+                    if (($x == 0) && (ord($frameY[$x]) & 1)) {
242 242
                         $this->runLength[0] = -1;
243 243
                         $head = 1;
244 244
                         $this->runLength[$head] = 1;
245
-                    } else if($x > 0) {
246
-                        if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) {
245
+                    } else if ($x > 0) {
246
+                        if ((ord($frameY[$x]) ^ ord($frameY[$x - 1])) & 1) {
247 247
                             $head++;
248 248
                             $this->runLength[$head] = 1;
249 249
                         } else {
@@ -252,20 +252,20 @@  discard block
 block discarded – undo
252 252
                     }
253 253
                 }
254 254
     
255
-                $demerit += $this->calcN1N3($head+1);
255
+                $demerit += $this->calcN1N3($head + 1);
256 256
             }
257 257
 
258
-            for($x=0; $x<$width; $x++) {
258
+            for ($x = 0; $x < $width; $x++) {
259 259
                 $head = 0;
260 260
                 $this->runLength[0] = 1;
261 261
                 
262
-                for($y=0; $y<$width; $y++) {
263
-                    if($y == 0 && (ord($frame[$y][$x]) & 1)) {
262
+                for ($y = 0; $y < $width; $y++) {
263
+                    if ($y == 0 && (ord($frame[$y][$x]) & 1)) {
264 264
                         $this->runLength[0] = -1;
265 265
                         $head = 1;
266 266
                         $this->runLength[$head] = 1;
267
-                    } else if($y > 0) {
268
-                        if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) {
267
+                    } else if ($y > 0) {
268
+                        if ((ord($frame[$y][$x]) ^ ord($frame[$y - 1][$x])) & 1) {
269 269
                             $head++;
270 270
                             $this->runLength[$head] = 1;
271 271
                         } else {
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
                     }
275 275
                 }
276 276
             
277
-                $demerit += $this->calcN1N3($head+1);
277
+                $demerit += $this->calcN1N3($head + 1);
278 278
             }
279 279
 
280 280
             return $demerit;
@@ -288,13 +288,13 @@  discard block
 block discarded – undo
288 288
             $bestMaskNum = 0;
289 289
             $bestMask = array();
290 290
             
291
-            $checked_masks = array(0,1,2,3,4,5,6,7);
291
+            $checked_masks = array(0, 1, 2, 3, 4, 5, 6, 7);
292 292
             
293 293
             if (QR_FIND_FROM_RANDOM !== false) {
294 294
             
295
-                $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9);
296
-                for ($i = 0; $i <  $howManuOut; $i++) {
297
-                    $remPos = rand (0, count($checked_masks)-1);
295
+                $howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9);
296
+                for ($i = 0; $i < $howManuOut; $i++) {
297
+                    $remPos = rand(0, count($checked_masks) - 1);
298 298
                     unset($checked_masks[$remPos]);
299 299
                     $checked_masks = array_values($checked_masks);
300 300
                 }
@@ -303,18 +303,18 @@  discard block
 block discarded – undo
303 303
             
304 304
             $bestMask = $frame;
305 305
              
306
-            foreach($checked_masks as $i) {
306
+            foreach ($checked_masks as $i) {
307 307
                 $mask = array_fill(0, $width, str_repeat("\0", $width));
308 308
 
309 309
                 $demerit = 0;
310 310
                 $blacks = 0;
311 311
                 $blacks  = $this->makeMaskNo($i, $width, $frame, $mask);
312 312
                 $blacks += $this->writeFormatInformation($width, $mask, $i, $level);
313
-                $blacks  = (int)(100 * $blacks / ($width * $width));
314
-                $demerit = (int)((int)(abs($blacks - 50) / 5) * N4);
313
+                $blacks  = (int) (100 * $blacks / ($width * $width));
314
+                $demerit = (int) ((int) (abs($blacks - 50) / 5) * N4);
315 315
                 $demerit += $this->evaluateSymbol($width, $mask);
316 316
                 
317
-                if($demerit < $minDemerit) {
317
+                if ($demerit < $minDemerit) {
318 318
                     $minDemerit = $demerit;
319 319
                     $bestMask = $mask;
320 320
                     $bestMaskNum = $i;
Please login to merge, or discard this patch.
Braces   +15 added lines, -10 removed lines patch added patch discarded remove patch
@@ -119,8 +119,9 @@  discard block
 block discarded – undo
119 119
         {
120 120
             $codeArr = array();
121 121
             
122
-            foreach ($bitFrame as $line)
123
-                $codeArr[] = join('', $line);
122
+            foreach ($bitFrame as $line) {
123
+                            $codeArr[] = join('', $line);
124
+            }
124 125
                 
125 126
             return gzcompress(join("\n", $codeArr), 9);
126 127
         }
@@ -131,8 +132,9 @@  discard block
 block discarded – undo
131 132
             $codeArr = array();
132 133
             
133 134
             $codeLines = explode("\n", gzuncompress($code));
134
-            foreach ($codeLines as $line)
135
-                $codeArr[] = str_split($line);
135
+            foreach ($codeLines as $line) {
136
+                            $codeArr[] = str_split($line);
137
+            }
136 138
             
137 139
             return $codeArr;
138 140
         }
@@ -150,16 +152,18 @@  discard block
 block discarded – undo
150 152
                     $bitMask = self::unserial(file_get_contents($fileName));
151 153
                 } else {
152 154
                     $bitMask = $this->generateMaskNo($maskNo, $width, $s);
153
-                    if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo))
154
-                        mkdir(QR_CACHE_DIR.'mask_'.$maskNo);
155
+                    if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) {
156
+                                            mkdir(QR_CACHE_DIR.'mask_'.$maskNo);
157
+                    }
155 158
                     file_put_contents($fileName, self::serial($bitMask));
156 159
                 }
157 160
             } else {
158 161
                 $bitMask = $this->generateMaskNo($maskNo, $width, $s);
159 162
             }
160 163
 
161
-            if ($maskGenOnly)
162
-                return;
164
+            if ($maskGenOnly) {
165
+                            return;
166
+            }
163 167
                 
164 168
             $d = $s;
165 169
 
@@ -226,8 +230,9 @@  discard block
 block discarded – undo
226 230
                 
227 231
                 $frameY = $frame[$y];
228 232
                 
229
-                if ($y>0)
230
-                    $frameYM = $frame[$y-1];
233
+                if ($y>0) {
234
+                                    $frameYM = $frame[$y-1];
235
+                }
231 236
                 
232 237
                 for($x=0; $x<$width; $x++) {
233 238
                     if(($x > 0) && ($y > 0)) {
Please login to merge, or discard this patch.
lib/phpqrcode/qrconfig.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -5,13 +5,13 @@
 block discarded – undo
5 5
  * Config file, feel free to modify
6 6
  */
7 7
      
8
-    define('QR_CACHEABLE', true);                                                               // use cache - more disk reads but less CPU power, masks and format templates are stored there
9
-    define('QR_CACHE_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR);  // used when QR_CACHEABLE === true
10
-    define('QR_LOG_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR);                                // default error logs dir   
8
+	define('QR_CACHEABLE', true);                                                               // use cache - more disk reads but less CPU power, masks and format templates are stored there
9
+	define('QR_CACHE_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR);  // used when QR_CACHEABLE === true
10
+	define('QR_LOG_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR);                                // default error logs dir   
11 11
     
12
-    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
13
-    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
14
-    define('QR_DEFAULT_MASK', 2);                                                               // when QR_FIND_BEST_MASK === false
12
+	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
13
+	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
14
+	define('QR_DEFAULT_MASK', 2);                                                               // when QR_FIND_BEST_MASK === false
15 15
                                                   
16
-    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
17
-                                                  
18 16
\ No newline at end of file
17
+	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
18
+												  
19 19
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -5,13 +5,13 @@
 block discarded – undo
5 5
  * Config file, feel free to modify
6 6
  */
7 7
      
8
-    define('QR_CACHEABLE', true);                                                               // use cache - more disk reads but less CPU power, masks and format templates are stored there
9
-    define('QR_CACHE_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR);  // used when QR_CACHEABLE === true
10
-    define('QR_LOG_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR);                                // default error logs dir   
8
+    define('QR_CACHEABLE', true); // use cache - more disk reads but less CPU power, masks and format templates are stored there
9
+    define('QR_CACHE_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR); // used when QR_CACHEABLE === true
10
+    define('QR_LOG_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR); // default error logs dir   
11 11
     
12
-    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
13
-    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
14
-    define('QR_DEFAULT_MASK', 2);                                                               // when QR_FIND_BEST_MASK === false
12
+    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
13
+    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
14
+    define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false
15 15
                                                   
16
-    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
16
+    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
17 17
                                                   
18 18
\ No newline at end of file
Please login to merge, or discard this patch.
lib/phpqrcode/index.php 3 patches
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -22,57 +22,57 @@  discard block
 block discarded – undo
22 22
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 23
  */
24 24
     
25
-    echo "<h1>PHP QR Code</h1><hr/>";
25
+	echo "<h1>PHP QR Code</h1><hr/>";
26 26
     
27
-    //set it to writable location, a place for temp generated PNG files
28
-    $PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR;
27
+	//set it to writable location, a place for temp generated PNG files
28
+	$PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR;
29 29
     
30
-    //html PNG location prefix
31
-    $PNG_WEB_DIR = 'temp/';
30
+	//html PNG location prefix
31
+	$PNG_WEB_DIR = 'temp/';
32 32
 
33
-    include "qrlib.php";    
33
+	include "qrlib.php";    
34 34
     
35
-    //ofcourse we need rights to create temp dir
36
-    if (!file_exists($PNG_TEMP_DIR))
37
-        mkdir($PNG_TEMP_DIR);
35
+	//ofcourse we need rights to create temp dir
36
+	if (!file_exists($PNG_TEMP_DIR))
37
+		mkdir($PNG_TEMP_DIR);
38 38
     
39 39
     
40
-    $filename = $PNG_TEMP_DIR.'test.png';
40
+	$filename = $PNG_TEMP_DIR.'test.png';
41 41
     
42
-    //processing form input
43
-    //remember to sanitize user input in real-life solution !!!
44
-    $errorCorrectionLevel = 'L';
45
-    if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H')))
46
-        $errorCorrectionLevel = $_REQUEST['level'];    
42
+	//processing form input
43
+	//remember to sanitize user input in real-life solution !!!
44
+	$errorCorrectionLevel = 'L';
45
+	if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H')))
46
+		$errorCorrectionLevel = $_REQUEST['level'];    
47 47
 
48
-    $matrixPointSize = 4;
49
-    if (isset($_REQUEST['size']))
50
-        $matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10);
48
+	$matrixPointSize = 4;
49
+	if (isset($_REQUEST['size']))
50
+		$matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10);
51 51
 
52 52
 
53
-    if (isset($_REQUEST['data'])) { 
53
+	if (isset($_REQUEST['data'])) { 
54 54
     
55
-        //it's very important!
56
-        if (trim($_REQUEST['data']) == '')
57
-            die('data cannot be empty! <a href="?">back</a>');
55
+		//it's very important!
56
+		if (trim($_REQUEST['data']) == '')
57
+			die('data cannot be empty! <a href="?">back</a>');
58 58
             
59
-        // user data
60
-        $filename = $PNG_TEMP_DIR.'test'.md5($_REQUEST['data'].'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png';
61
-        QRcode::png($_REQUEST['data'], $filename, $errorCorrectionLevel, $matrixPointSize, 2);    
59
+		// user data
60
+		$filename = $PNG_TEMP_DIR.'test'.md5($_REQUEST['data'].'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png';
61
+		QRcode::png($_REQUEST['data'], $filename, $errorCorrectionLevel, $matrixPointSize, 2);    
62 62
         
63
-    } else {    
63
+	} else {    
64 64
     
65
-        //default data
66
-        echo 'You can provide data in GET parameter: <a href="?data=like_that">like that</a><hr/>';    
67
-        QRcode::png('PHP QR Code :)', $filename, $errorCorrectionLevel, $matrixPointSize, 2);    
65
+		//default data
66
+		echo 'You can provide data in GET parameter: <a href="?data=like_that">like that</a><hr/>';    
67
+		QRcode::png('PHP QR Code :)', $filename, $errorCorrectionLevel, $matrixPointSize, 2);    
68 68
         
69
-    }    
69
+	}    
70 70
         
71
-    //display generated file
72
-    echo '<img src="'.$PNG_WEB_DIR.basename($filename).'" /><hr/>';  
71
+	//display generated file
72
+	echo '<img src="'.$PNG_WEB_DIR.basename($filename).'" /><hr/>';  
73 73
     
74
-    //config form
75
-    echo '<form action="index.php" method="post">
74
+	//config form
75
+	echo '<form action="index.php" method="post">
76 76
         Data:&nbsp;<input name="data" value="'.(isset($_REQUEST['data'])?htmlspecialchars($_REQUEST['data']):'PHP QR Code :)').'" />&nbsp;
77 77
         ECC:&nbsp;<select name="level">
78 78
             <option value="L"'.(($errorCorrectionLevel=='L')?' selected':'').'>L - smallest</option>
@@ -82,13 +82,13 @@  discard block
 block discarded – undo
82 82
         </select>&nbsp;
83 83
         Size:&nbsp;<select name="size">';
84 84
         
85
-    for($i=1;$i<=10;$i++)
86
-        echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>';
85
+	for($i=1;$i<=10;$i++)
86
+		echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>';
87 87
         
88
-    echo '</select>&nbsp;
88
+	echo '</select>&nbsp;
89 89
         <input type="submit" value="GENERATE"></form><hr/>';
90 90
         
91
-    // benchmark
92
-    QRtools::timeBenchmark();    
91
+	// benchmark
92
+	QRtools::timeBenchmark();    
93 93
 
94
-    
95 94
\ No newline at end of file
95
+	
96 96
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
42 42
     //processing form input
43 43
     //remember to sanitize user input in real-life solution !!!
44 44
     $errorCorrectionLevel = 'L';
45
-    if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H')))
45
+    if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L', 'M', 'Q', 'H')))
46 46
         $errorCorrectionLevel = $_REQUEST['level'];    
47 47
 
48 48
     $matrixPointSize = 4;
49 49
     if (isset($_REQUEST['size']))
50
-        $matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10);
50
+        $matrixPointSize = min(max((int) $_REQUEST['size'], 1), 10);
51 51
 
52 52
 
53 53
     if (isset($_REQUEST['data'])) { 
@@ -73,17 +73,17 @@  discard block
 block discarded – undo
73 73
     
74 74
     //config form
75 75
     echo '<form action="index.php" method="post">
76
-        Data:&nbsp;<input name="data" value="'.(isset($_REQUEST['data'])?htmlspecialchars($_REQUEST['data']):'PHP QR Code :)').'" />&nbsp;
76
+        Data:&nbsp;<input name="data" value="'.(isset($_REQUEST['data']) ?htmlspecialchars($_REQUEST['data']) : 'PHP QR Code :)').'" />&nbsp;
77 77
         ECC:&nbsp;<select name="level">
78
-            <option value="L"'.(($errorCorrectionLevel=='L')?' selected':'').'>L - smallest</option>
79
-            <option value="M"'.(($errorCorrectionLevel=='M')?' selected':'').'>M</option>
80
-            <option value="Q"'.(($errorCorrectionLevel=='Q')?' selected':'').'>Q</option>
81
-            <option value="H"'.(($errorCorrectionLevel=='H')?' selected':'').'>H - best</option>
78
+            <option value="L"'.(($errorCorrectionLevel == 'L') ? ' selected' : '').'>L - smallest</option>
79
+            <option value="M"'.(($errorCorrectionLevel == 'M') ? ' selected' : '').'>M</option>
80
+            <option value="Q"'.(($errorCorrectionLevel == 'Q') ? ' selected' : '').'>Q</option>
81
+            <option value="H"'.(($errorCorrectionLevel == 'H') ? ' selected' : '').'>H - best</option>
82 82
         </select>&nbsp;
83 83
         Size:&nbsp;<select name="size">';
84 84
         
85
-    for($i=1;$i<=10;$i++)
86
-        echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>';
85
+    for ($i = 1; $i <= 10; $i++)
86
+        echo '<option value="'.$i.'"'.(($matrixPointSize == $i) ? ' selected' : '').'>'.$i.'</option>';
87 87
         
88 88
     echo '</select>&nbsp;
89 89
         <input type="submit" value="GENERATE"></form><hr/>';
Please login to merge, or discard this patch.
Braces   +15 added lines, -10 removed lines patch added patch discarded remove patch
@@ -33,8 +33,9 @@  discard block
 block discarded – undo
33 33
     include "qrlib.php";    
34 34
     
35 35
     //ofcourse we need rights to create temp dir
36
-    if (!file_exists($PNG_TEMP_DIR))
37
-        mkdir($PNG_TEMP_DIR);
36
+    if (!file_exists($PNG_TEMP_DIR)) {
37
+            mkdir($PNG_TEMP_DIR);
38
+    }
38 39
     
39 40
     
40 41
     $filename = $PNG_TEMP_DIR.'test.png';
@@ -42,19 +43,22 @@  discard block
 block discarded – undo
42 43
     //processing form input
43 44
     //remember to sanitize user input in real-life solution !!!
44 45
     $errorCorrectionLevel = 'L';
45
-    if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H')))
46
-        $errorCorrectionLevel = $_REQUEST['level'];    
46
+    if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H'))) {
47
+            $errorCorrectionLevel = $_REQUEST['level'];
48
+    }
47 49
 
48 50
     $matrixPointSize = 4;
49
-    if (isset($_REQUEST['size']))
50
-        $matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10);
51
+    if (isset($_REQUEST['size'])) {
52
+            $matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10);
53
+    }
51 54
 
52 55
 
53 56
     if (isset($_REQUEST['data'])) { 
54 57
     
55 58
         //it's very important!
56
-        if (trim($_REQUEST['data']) == '')
57
-            die('data cannot be empty! <a href="?">back</a>');
59
+        if (trim($_REQUEST['data']) == '') {
60
+                    die('data cannot be empty! <a href="?">back</a>');
61
+        }
58 62
             
59 63
         // user data
60 64
         $filename = $PNG_TEMP_DIR.'test'.md5($_REQUEST['data'].'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png';
@@ -82,8 +86,9 @@  discard block
 block discarded – undo
82 86
         </select>&nbsp;
83 87
         Size:&nbsp;<select name="size">';
84 88
         
85
-    for($i=1;$i<=10;$i++)
86
-        echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>';
89
+    for($i=1;$i<=10;$i++) {
90
+            echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>';
91
+    }
87 92
         
88 93
     echo '</select>&nbsp;
89 94
         <input type="submit" value="GENERATE"></form><hr/>';
Please login to merge, or discard this patch.
lib/phpqrcode/qrtools.php 3 patches
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -22,151 +22,151 @@
 block discarded – undo
22 22
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 23
  */
24 24
 
25
-    class QRtools {
25
+	class QRtools {
26 26
     
27
-        //----------------------------------------------------------------------
28
-        public static function binarize($frame)
29
-        {
30
-            $len = count($frame);
31
-            foreach ($frame as &$frameLine) {
27
+		//----------------------------------------------------------------------
28
+		public static function binarize($frame)
29
+		{
30
+			$len = count($frame);
31
+			foreach ($frame as &$frameLine) {
32 32
                 
33
-                for($i=0; $i<$len; $i++) {
34
-                    $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';
35
-                }
36
-            }
33
+				for($i=0; $i<$len; $i++) {
34
+					$frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';
35
+				}
36
+			}
37 37
             
38
-            return $frame;
39
-        }
38
+			return $frame;
39
+		}
40 40
         
41
-        //----------------------------------------------------------------------
42
-        public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037')
43
-        {
44
-            $barcode_array = array();
41
+		//----------------------------------------------------------------------
42
+		public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037')
43
+		{
44
+			$barcode_array = array();
45 45
             
46
-            if (!is_array($mode))
47
-                $mode = explode(',', $mode);
46
+			if (!is_array($mode))
47
+				$mode = explode(',', $mode);
48 48
                 
49
-            $eccLevel = 'L';
49
+			$eccLevel = 'L';
50 50
                 
51
-            if (count($mode) > 1) {
52
-                $eccLevel = $mode[1];
53
-            }
51
+			if (count($mode) > 1) {
52
+				$eccLevel = $mode[1];
53
+			}
54 54
                 
55
-            $qrTab = QRcode::text($code, false, $eccLevel);
56
-            $size = count($qrTab);
55
+			$qrTab = QRcode::text($code, false, $eccLevel);
56
+			$size = count($qrTab);
57 57
                 
58
-            $barcode_array['num_rows'] = $size;
59
-            $barcode_array['num_cols'] = $size;
60
-            $barcode_array['bcode'] = array();
58
+			$barcode_array['num_rows'] = $size;
59
+			$barcode_array['num_cols'] = $size;
60
+			$barcode_array['bcode'] = array();
61 61
                 
62
-            foreach ($qrTab as $line) {
63
-                $arrAdd = array();
64
-                foreach(str_split($line) as $char)
65
-                    $arrAdd[] = ($char=='1')?1:0;
66
-                $barcode_array['bcode'][] = $arrAdd;
67
-            }
62
+			foreach ($qrTab as $line) {
63
+				$arrAdd = array();
64
+				foreach(str_split($line) as $char)
65
+					$arrAdd[] = ($char=='1')?1:0;
66
+				$barcode_array['bcode'][] = $arrAdd;
67
+			}
68 68
                     
69
-            return $barcode_array;
70
-        }
69
+			return $barcode_array;
70
+		}
71 71
         
72
-        //----------------------------------------------------------------------
73
-        public static function clearCache()
74
-        {
75
-            self::$frames = array();
76
-        }
72
+		//----------------------------------------------------------------------
73
+		public static function clearCache()
74
+		{
75
+			self::$frames = array();
76
+		}
77 77
         
78
-        //----------------------------------------------------------------------
79
-        public static function buildCache()
80
-        {
78
+		//----------------------------------------------------------------------
79
+		public static function buildCache()
80
+		{
81 81
 			QRtools::markTime('before_build_cache');
82 82
 			
83 83
 			$mask = new QRmask();
84
-            for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) {
85
-                $frame = QRspec::newFrame($a);
86
-                if (QR_IMAGE) {
87
-                    $fileName = QR_CACHE_DIR.'frame_'.$a.'.png';
88
-                    QRimage::png(self::binarize($frame), $fileName, 1, 0);
89
-                }
84
+			for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) {
85
+				$frame = QRspec::newFrame($a);
86
+				if (QR_IMAGE) {
87
+					$fileName = QR_CACHE_DIR.'frame_'.$a.'.png';
88
+					QRimage::png(self::binarize($frame), $fileName, 1, 0);
89
+				}
90 90
 				
91 91
 				$width = count($frame);
92 92
 				$bitMask = array_fill(0, $width, array_fill(0, $width, 0));
93 93
 				for ($maskNo=0; $maskNo<8; $maskNo++)
94 94
 					$mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
95
-            }
95
+			}
96 96
 			
97 97
 			QRtools::markTime('after_build_cache');
98
-        }
98
+		}
99 99
 
100
-        //----------------------------------------------------------------------
101
-        public static function log($outfile, $err)
102
-        {
103
-            if (QR_LOG_DIR !== false) {
104
-                if ($err != '') {
105
-                    if ($outfile !== false) {
106
-                        file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
107
-                    } else {
108
-                        file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
109
-                    }
110
-                }    
111
-            }
112
-        }
100
+		//----------------------------------------------------------------------
101
+		public static function log($outfile, $err)
102
+		{
103
+			if (QR_LOG_DIR !== false) {
104
+				if ($err != '') {
105
+					if ($outfile !== false) {
106
+						file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
107
+					} else {
108
+						file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
109
+					}
110
+				}    
111
+			}
112
+		}
113 113
         
114
-        //----------------------------------------------------------------------
115
-        public static function dumpMask($frame) 
116
-        {
117
-            $width = count($frame);
118
-            for($y=0;$y<$width;$y++) {
119
-                for($x=0;$x<$width;$x++) {
120
-                    echo ord($frame[$y][$x]).',';
121
-                }
122
-            }
123
-        }
114
+		//----------------------------------------------------------------------
115
+		public static function dumpMask($frame) 
116
+		{
117
+			$width = count($frame);
118
+			for($y=0;$y<$width;$y++) {
119
+				for($x=0;$x<$width;$x++) {
120
+					echo ord($frame[$y][$x]).',';
121
+				}
122
+			}
123
+		}
124 124
         
125
-        //----------------------------------------------------------------------
126
-        public static function markTime($markerId)
127
-        {
128
-            list($usec, $sec) = explode(" ", microtime());
129
-            $time = ((float)$usec + (float)$sec);
125
+		//----------------------------------------------------------------------
126
+		public static function markTime($markerId)
127
+		{
128
+			list($usec, $sec) = explode(" ", microtime());
129
+			$time = ((float)$usec + (float)$sec);
130 130
             
131
-            if (!isset($GLOBALS['qr_time_bench']))
132
-                $GLOBALS['qr_time_bench'] = array();
131
+			if (!isset($GLOBALS['qr_time_bench']))
132
+				$GLOBALS['qr_time_bench'] = array();
133 133
             
134
-            $GLOBALS['qr_time_bench'][$markerId] = $time;
135
-        }
134
+			$GLOBALS['qr_time_bench'][$markerId] = $time;
135
+		}
136 136
         
137
-        //----------------------------------------------------------------------
138
-        public static function timeBenchmark()
139
-        {
140
-            self::markTime('finish');
137
+		//----------------------------------------------------------------------
138
+		public static function timeBenchmark()
139
+		{
140
+			self::markTime('finish');
141 141
         
142
-            $lastTime = 0;
143
-            $startTime = 0;
144
-            $p = 0;
142
+			$lastTime = 0;
143
+			$startTime = 0;
144
+			$p = 0;
145 145
 
146
-            echo '<table cellpadding="3" cellspacing="1">
146
+			echo '<table cellpadding="3" cellspacing="1">
147 147
                     <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead>
148 148
                     <tbody>';
149 149
 
150
-            foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
151
-                if ($p > 0) {
152
-                    echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>';
153
-                } else {
154
-                    $startTime = $thisTime;
155
-                }
150
+			foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
151
+				if ($p > 0) {
152
+					echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>';
153
+				} else {
154
+					$startTime = $thisTime;
155
+				}
156 156
                 
157
-                $p++;
158
-                $lastTime = $thisTime;
159
-            }
157
+				$p++;
158
+				$lastTime = $thisTime;
159
+			}
160 160
             
161
-            echo '</tbody><tfoot>
161
+			echo '</tbody><tfoot>
162 162
                 <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr>
163 163
             </tfoot>
164 164
             </table>';
165
-        }
165
+		}
166 166
         
167
-    }
167
+	}
168 168
     
169
-    //##########################################################################
169
+	//##########################################################################
170 170
     
171
-    QRtools::markTime('start');
172
-    
173 171
\ No newline at end of file
172
+	QRtools::markTime('start');
173
+	
174 174
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
             $len = count($frame);
31 31
             foreach ($frame as &$frameLine) {
32 32
                 
33
-                for($i=0; $i<$len; $i++) {
34
-                    $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';
33
+                for ($i = 0; $i < $len; $i++) {
34
+                    $frameLine[$i] = (ord($frameLine[$i]) & 1) ? '1' : '0';
35 35
                 }
36 36
             }
37 37
             
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
                 
62 62
             foreach ($qrTab as $line) {
63 63
                 $arrAdd = array();
64
-                foreach(str_split($line) as $char)
65
-                    $arrAdd[] = ($char=='1')?1:0;
64
+                foreach (str_split($line) as $char)
65
+                    $arrAdd[] = ($char == '1') ? 1 : 0;
66 66
                 $barcode_array['bcode'][] = $arrAdd;
67 67
             }
68 68
                     
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 			QRtools::markTime('before_build_cache');
82 82
 			
83 83
 			$mask = new QRmask();
84
-            for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) {
84
+            for ($a = 1; $a <= QRSPEC_VERSION_MAX; $a++) {
85 85
                 $frame = QRspec::newFrame($a);
86 86
                 if (QR_IMAGE) {
87 87
                     $fileName = QR_CACHE_DIR.'frame_'.$a.'.png';
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 				
91 91
 				$width = count($frame);
92 92
 				$bitMask = array_fill(0, $width, array_fill(0, $width, 0));
93
-				for ($maskNo=0; $maskNo<8; $maskNo++)
93
+				for ($maskNo = 0; $maskNo < 8; $maskNo++)
94 94
 					$mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
95 95
             }
96 96
 			
@@ -115,8 +115,8 @@  discard block
 block discarded – undo
115 115
         public static function dumpMask($frame) 
116 116
         {
117 117
             $width = count($frame);
118
-            for($y=0;$y<$width;$y++) {
119
-                for($x=0;$x<$width;$x++) {
118
+            for ($y = 0; $y < $width; $y++) {
119
+                for ($x = 0; $x < $width; $x++) {
120 120
                     echo ord($frame[$y][$x]).',';
121 121
                 }
122 122
             }
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
         public static function markTime($markerId)
127 127
         {
128 128
             list($usec, $sec) = explode(" ", microtime());
129
-            $time = ((float)$usec + (float)$sec);
129
+            $time = ((float) $usec + (float) $sec);
130 130
             
131 131
             if (!isset($GLOBALS['qr_time_bench']))
132 132
                 $GLOBALS['qr_time_bench'] = array();
@@ -147,9 +147,9 @@  discard block
 block discarded – undo
147 147
                     <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead>
148 148
                     <tbody>';
149 149
 
150
-            foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
150
+            foreach ($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
151 151
                 if ($p > 0) {
152
-                    echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>';
152
+                    echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime - $lastTime, 6).'s</td></tr>';
153 153
                 } else {
154 154
                     $startTime = $thisTime;
155 155
                 }
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
             }
160 160
             
161 161
             echo '</tbody><tfoot>
162
-                <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr>
162
+                <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime - $startTime, 6).'s</td></tr>
163 163
             </tfoot>
164 164
             </table>';
165 165
         }
Please login to merge, or discard this patch.
Braces   +12 added lines, -8 removed lines patch added patch discarded remove patch
@@ -43,8 +43,9 @@  discard block
 block discarded – undo
43 43
         {
44 44
             $barcode_array = array();
45 45
             
46
-            if (!is_array($mode))
47
-                $mode = explode(',', $mode);
46
+            if (!is_array($mode)) {
47
+                            $mode = explode(',', $mode);
48
+            }
48 49
                 
49 50
             $eccLevel = 'L';
50 51
                 
@@ -61,8 +62,9 @@  discard block
 block discarded – undo
61 62
                 
62 63
             foreach ($qrTab as $line) {
63 64
                 $arrAdd = array();
64
-                foreach(str_split($line) as $char)
65
-                    $arrAdd[] = ($char=='1')?1:0;
65
+                foreach(str_split($line) as $char) {
66
+                                    $arrAdd[] = ($char=='1')?1:0;
67
+                }
66 68
                 $barcode_array['bcode'][] = $arrAdd;
67 69
             }
68 70
                     
@@ -90,8 +92,9 @@  discard block
 block discarded – undo
90 92
 				
91 93
 				$width = count($frame);
92 94
 				$bitMask = array_fill(0, $width, array_fill(0, $width, 0));
93
-				for ($maskNo=0; $maskNo<8; $maskNo++)
94
-					$mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
95
+				for ($maskNo=0; $maskNo<8; $maskNo++) {
96
+									$mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
97
+				}
95 98
             }
96 99
 			
97 100
 			QRtools::markTime('after_build_cache');
@@ -128,8 +131,9 @@  discard block
 block discarded – undo
128 131
             list($usec, $sec) = explode(" ", microtime());
129 132
             $time = ((float)$usec + (float)$sec);
130 133
             
131
-            if (!isset($GLOBALS['qr_time_bench']))
132
-                $GLOBALS['qr_time_bench'] = array();
134
+            if (!isset($GLOBALS['qr_time_bench'])) {
135
+                            $GLOBALS['qr_time_bench'] = array();
136
+            }
133 137
             
134 138
             $GLOBALS['qr_time_bench'][$markerId] = $time;
135 139
         }
Please login to merge, or discard this patch.
lib/phpqrcode/qrimage.php 3 patches
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -22,74 +22,74 @@
 block discarded – undo
22 22
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 23
  */
24 24
  
25
-    define('QR_IMAGE', true);
25
+	define('QR_IMAGE', true);
26 26
 
27
-    class QRimage {
27
+	class QRimage {
28 28
     
29
-        //----------------------------------------------------------------------
30
-        public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) 
31
-        {
32
-            $image = self::image($frame, $pixelPerPoint, $outerFrame);
29
+		//----------------------------------------------------------------------
30
+		public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) 
31
+		{
32
+			$image = self::image($frame, $pixelPerPoint, $outerFrame);
33 33
             
34
-            if ($filename === false) {
35
-                Header("Content-type: image/png");
36
-                ImagePng($image);
37
-            } else {
38
-                if($saveandprint===TRUE){
39
-                    ImagePng($image, $filename);
40
-                    header("Content-type: image/png");
41
-                    ImagePng($image);
42
-                }else{
43
-                    ImagePng($image, $filename);
44
-                }
45
-            }
34
+			if ($filename === false) {
35
+				Header("Content-type: image/png");
36
+				ImagePng($image);
37
+			} else {
38
+				if($saveandprint===TRUE){
39
+					ImagePng($image, $filename);
40
+					header("Content-type: image/png");
41
+					ImagePng($image);
42
+				}else{
43
+					ImagePng($image, $filename);
44
+				}
45
+			}
46 46
             
47
-            ImageDestroy($image);
48
-        }
47
+			ImageDestroy($image);
48
+		}
49 49
     
50
-        //----------------------------------------------------------------------
51
-        public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85) 
52
-        {
53
-            $image = self::image($frame, $pixelPerPoint, $outerFrame);
50
+		//----------------------------------------------------------------------
51
+		public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85) 
52
+		{
53
+			$image = self::image($frame, $pixelPerPoint, $outerFrame);
54 54
             
55
-            if ($filename === false) {
56
-                Header("Content-type: image/jpeg");
57
-                ImageJpeg($image, null, $q);
58
-            } else {
59
-                ImageJpeg($image, $filename, $q);            
60
-            }
55
+			if ($filename === false) {
56
+				Header("Content-type: image/jpeg");
57
+				ImageJpeg($image, null, $q);
58
+			} else {
59
+				ImageJpeg($image, $filename, $q);            
60
+			}
61 61
             
62
-            ImageDestroy($image);
63
-        }
62
+			ImageDestroy($image);
63
+		}
64 64
     
65
-        //----------------------------------------------------------------------
66
-        private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4) 
67
-        {
68
-            $h = count($frame);
69
-            $w = strlen($frame[0]);
65
+		//----------------------------------------------------------------------
66
+		private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4) 
67
+		{
68
+			$h = count($frame);
69
+			$w = strlen($frame[0]);
70 70
             
71
-            $imgW = $w + 2*$outerFrame;
72
-            $imgH = $h + 2*$outerFrame;
71
+			$imgW = $w + 2*$outerFrame;
72
+			$imgH = $h + 2*$outerFrame;
73 73
             
74
-            $base_image =ImageCreate($imgW, $imgH);
74
+			$base_image =ImageCreate($imgW, $imgH);
75 75
             
76
-            $col[0] = ImageColorAllocate($base_image,255,255,255);
77
-            $col[1] = ImageColorAllocate($base_image,0,0,0);
76
+			$col[0] = ImageColorAllocate($base_image,255,255,255);
77
+			$col[1] = ImageColorAllocate($base_image,0,0,0);
78 78
 
79
-            imagefill($base_image, 0, 0, $col[0]);
79
+			imagefill($base_image, 0, 0, $col[0]);
80 80
 
81
-            for($y=0; $y<$h; $y++) {
82
-                for($x=0; $x<$w; $x++) {
83
-                    if ($frame[$y][$x] == '1') {
84
-                        ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); 
85
-                    }
86
-                }
87
-            }
81
+			for($y=0; $y<$h; $y++) {
82
+				for($x=0; $x<$w; $x++) {
83
+					if ($frame[$y][$x] == '1') {
84
+						ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); 
85
+					}
86
+				}
87
+			}
88 88
             
89
-            $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
90
-            ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
91
-            ImageDestroy($base_image);
89
+			$target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
90
+			ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
91
+			ImageDestroy($base_image);
92 92
             
93
-            return $target_image;
94
-        }
95
-    }
96 93
\ No newline at end of file
94
+			return $target_image;
95
+		}
96
+	}
97 97
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
     class QRimage {
28 28
     
29 29
         //----------------------------------------------------------------------
30
-        public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) 
30
+        public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4, $saveandprint = FALSE) 
31 31
         {
32 32
             $image = self::image($frame, $pixelPerPoint, $outerFrame);
33 33
             
@@ -35,11 +35,11 @@  discard block
 block discarded – undo
35 35
                 Header("Content-type: image/png");
36 36
                 ImagePng($image);
37 37
             } else {
38
-                if($saveandprint===TRUE){
38
+                if ($saveandprint === TRUE) {
39 39
                     ImagePng($image, $filename);
40 40
                     header("Content-type: image/png");
41 41
                     ImagePng($image);
42
-                }else{
42
+                } else {
43 43
                     ImagePng($image, $filename);
44 44
                 }
45 45
             }
@@ -68,25 +68,25 @@  discard block
 block discarded – undo
68 68
             $h = count($frame);
69 69
             $w = strlen($frame[0]);
70 70
             
71
-            $imgW = $w + 2*$outerFrame;
72
-            $imgH = $h + 2*$outerFrame;
71
+            $imgW = $w + 2 * $outerFrame;
72
+            $imgH = $h + 2 * $outerFrame;
73 73
             
74
-            $base_image =ImageCreate($imgW, $imgH);
74
+            $base_image = ImageCreate($imgW, $imgH);
75 75
             
76
-            $col[0] = ImageColorAllocate($base_image,255,255,255);
77
-            $col[1] = ImageColorAllocate($base_image,0,0,0);
76
+            $col[0] = ImageColorAllocate($base_image, 255, 255, 255);
77
+            $col[1] = ImageColorAllocate($base_image, 0, 0, 0);
78 78
 
79 79
             imagefill($base_image, 0, 0, $col[0]);
80 80
 
81
-            for($y=0; $y<$h; $y++) {
82
-                for($x=0; $x<$w; $x++) {
81
+            for ($y = 0; $y < $h; $y++) {
82
+                for ($x = 0; $x < $w; $x++) {
83 83
                     if ($frame[$y][$x] == '1') {
84
-                        ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); 
84
+                        ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]); 
85 85
                     }
86 86
                 }
87 87
             }
88 88
             
89
-            $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
89
+            $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
90 90
             ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
91 91
             ImageDestroy($base_image);
92 92
             
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
                     ImagePng($image, $filename);
40 40
                     header("Content-type: image/png");
41 41
                     ImagePng($image);
42
-                }else{
42
+                } else{
43 43
                     ImagePng($image, $filename);
44 44
                 }
45 45
             }
Please login to merge, or discard this patch.