@kinocode/dsh-mobile-bridge 0.0.0-stage → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2291 @@
1
+ // Vendored from qrcode-generator 1.4.4 (npm), Copyright (c) 2009 Kazuhiko Arase, MIT license.
2
+ // Unmodified except: the UMD wrapper at the end is replaced by an ES module export.
3
+ //---------------------------------------------------------------------
4
+ //
5
+ // QR Code Generator for JavaScript
6
+ //
7
+ // Copyright (c) 2009 Kazuhiko Arase
8
+ //
9
+ // URL: http://www.d-project.com/
10
+ //
11
+ // Licensed under the MIT license:
12
+ // http://www.opensource.org/licenses/mit-license.php
13
+ //
14
+ // The word 'QR Code' is registered trademark of
15
+ // DENSO WAVE INCORPORATED
16
+ // http://www.denso-wave.com/qrcode/faqpatent-e.html
17
+ //
18
+ //---------------------------------------------------------------------
19
+
20
+ var qrcode = function() {
21
+
22
+ //---------------------------------------------------------------------
23
+ // qrcode
24
+ //---------------------------------------------------------------------
25
+
26
+ /**
27
+ * qrcode
28
+ * @param typeNumber 1 to 40
29
+ * @param errorCorrectionLevel 'L','M','Q','H'
30
+ */
31
+ var qrcode = function(typeNumber, errorCorrectionLevel) {
32
+
33
+ var PAD0 = 0xEC;
34
+ var PAD1 = 0x11;
35
+
36
+ var _typeNumber = typeNumber;
37
+ var _errorCorrectionLevel = QRErrorCorrectionLevel[errorCorrectionLevel];
38
+ var _modules = null;
39
+ var _moduleCount = 0;
40
+ var _dataCache = null;
41
+ var _dataList = [];
42
+
43
+ var _this = {};
44
+
45
+ var makeImpl = function(test, maskPattern) {
46
+
47
+ _moduleCount = _typeNumber * 4 + 17;
48
+ _modules = function(moduleCount) {
49
+ var modules = new Array(moduleCount);
50
+ for (var row = 0; row < moduleCount; row += 1) {
51
+ modules[row] = new Array(moduleCount);
52
+ for (var col = 0; col < moduleCount; col += 1) {
53
+ modules[row][col] = null;
54
+ }
55
+ }
56
+ return modules;
57
+ }(_moduleCount);
58
+
59
+ setupPositionProbePattern(0, 0);
60
+ setupPositionProbePattern(_moduleCount - 7, 0);
61
+ setupPositionProbePattern(0, _moduleCount - 7);
62
+ setupPositionAdjustPattern();
63
+ setupTimingPattern();
64
+ setupTypeInfo(test, maskPattern);
65
+
66
+ if (_typeNumber >= 7) {
67
+ setupTypeNumber(test);
68
+ }
69
+
70
+ if (_dataCache == null) {
71
+ _dataCache = createData(_typeNumber, _errorCorrectionLevel, _dataList);
72
+ }
73
+
74
+ mapData(_dataCache, maskPattern);
75
+ };
76
+
77
+ var setupPositionProbePattern = function(row, col) {
78
+
79
+ for (var r = -1; r <= 7; r += 1) {
80
+
81
+ if (row + r <= -1 || _moduleCount <= row + r) continue;
82
+
83
+ for (var c = -1; c <= 7; c += 1) {
84
+
85
+ if (col + c <= -1 || _moduleCount <= col + c) continue;
86
+
87
+ if ( (0 <= r && r <= 6 && (c == 0 || c == 6) )
88
+ || (0 <= c && c <= 6 && (r == 0 || r == 6) )
89
+ || (2 <= r && r <= 4 && 2 <= c && c <= 4) ) {
90
+ _modules[row + r][col + c] = true;
91
+ } else {
92
+ _modules[row + r][col + c] = false;
93
+ }
94
+ }
95
+ }
96
+ };
97
+
98
+ var getBestMaskPattern = function() {
99
+
100
+ var minLostPoint = 0;
101
+ var pattern = 0;
102
+
103
+ for (var i = 0; i < 8; i += 1) {
104
+
105
+ makeImpl(true, i);
106
+
107
+ var lostPoint = QRUtil.getLostPoint(_this);
108
+
109
+ if (i == 0 || minLostPoint > lostPoint) {
110
+ minLostPoint = lostPoint;
111
+ pattern = i;
112
+ }
113
+ }
114
+
115
+ return pattern;
116
+ };
117
+
118
+ var setupTimingPattern = function() {
119
+
120
+ for (var r = 8; r < _moduleCount - 8; r += 1) {
121
+ if (_modules[r][6] != null) {
122
+ continue;
123
+ }
124
+ _modules[r][6] = (r % 2 == 0);
125
+ }
126
+
127
+ for (var c = 8; c < _moduleCount - 8; c += 1) {
128
+ if (_modules[6][c] != null) {
129
+ continue;
130
+ }
131
+ _modules[6][c] = (c % 2 == 0);
132
+ }
133
+ };
134
+
135
+ var setupPositionAdjustPattern = function() {
136
+
137
+ var pos = QRUtil.getPatternPosition(_typeNumber);
138
+
139
+ for (var i = 0; i < pos.length; i += 1) {
140
+
141
+ for (var j = 0; j < pos.length; j += 1) {
142
+
143
+ var row = pos[i];
144
+ var col = pos[j];
145
+
146
+ if (_modules[row][col] != null) {
147
+ continue;
148
+ }
149
+
150
+ for (var r = -2; r <= 2; r += 1) {
151
+
152
+ for (var c = -2; c <= 2; c += 1) {
153
+
154
+ if (r == -2 || r == 2 || c == -2 || c == 2
155
+ || (r == 0 && c == 0) ) {
156
+ _modules[row + r][col + c] = true;
157
+ } else {
158
+ _modules[row + r][col + c] = false;
159
+ }
160
+ }
161
+ }
162
+ }
163
+ }
164
+ };
165
+
166
+ var setupTypeNumber = function(test) {
167
+
168
+ var bits = QRUtil.getBCHTypeNumber(_typeNumber);
169
+
170
+ for (var i = 0; i < 18; i += 1) {
171
+ var mod = (!test && ( (bits >> i) & 1) == 1);
172
+ _modules[Math.floor(i / 3)][i % 3 + _moduleCount - 8 - 3] = mod;
173
+ }
174
+
175
+ for (var i = 0; i < 18; i += 1) {
176
+ var mod = (!test && ( (bits >> i) & 1) == 1);
177
+ _modules[i % 3 + _moduleCount - 8 - 3][Math.floor(i / 3)] = mod;
178
+ }
179
+ };
180
+
181
+ var setupTypeInfo = function(test, maskPattern) {
182
+
183
+ var data = (_errorCorrectionLevel << 3) | maskPattern;
184
+ var bits = QRUtil.getBCHTypeInfo(data);
185
+
186
+ // vertical
187
+ for (var i = 0; i < 15; i += 1) {
188
+
189
+ var mod = (!test && ( (bits >> i) & 1) == 1);
190
+
191
+ if (i < 6) {
192
+ _modules[i][8] = mod;
193
+ } else if (i < 8) {
194
+ _modules[i + 1][8] = mod;
195
+ } else {
196
+ _modules[_moduleCount - 15 + i][8] = mod;
197
+ }
198
+ }
199
+
200
+ // horizontal
201
+ for (var i = 0; i < 15; i += 1) {
202
+
203
+ var mod = (!test && ( (bits >> i) & 1) == 1);
204
+
205
+ if (i < 8) {
206
+ _modules[8][_moduleCount - i - 1] = mod;
207
+ } else if (i < 9) {
208
+ _modules[8][15 - i - 1 + 1] = mod;
209
+ } else {
210
+ _modules[8][15 - i - 1] = mod;
211
+ }
212
+ }
213
+
214
+ // fixed module
215
+ _modules[_moduleCount - 8][8] = (!test);
216
+ };
217
+
218
+ var mapData = function(data, maskPattern) {
219
+
220
+ var inc = -1;
221
+ var row = _moduleCount - 1;
222
+ var bitIndex = 7;
223
+ var byteIndex = 0;
224
+ var maskFunc = QRUtil.getMaskFunction(maskPattern);
225
+
226
+ for (var col = _moduleCount - 1; col > 0; col -= 2) {
227
+
228
+ if (col == 6) col -= 1;
229
+
230
+ while (true) {
231
+
232
+ for (var c = 0; c < 2; c += 1) {
233
+
234
+ if (_modules[row][col - c] == null) {
235
+
236
+ var dark = false;
237
+
238
+ if (byteIndex < data.length) {
239
+ dark = ( ( (data[byteIndex] >>> bitIndex) & 1) == 1);
240
+ }
241
+
242
+ var mask = maskFunc(row, col - c);
243
+
244
+ if (mask) {
245
+ dark = !dark;
246
+ }
247
+
248
+ _modules[row][col - c] = dark;
249
+ bitIndex -= 1;
250
+
251
+ if (bitIndex == -1) {
252
+ byteIndex += 1;
253
+ bitIndex = 7;
254
+ }
255
+ }
256
+ }
257
+
258
+ row += inc;
259
+
260
+ if (row < 0 || _moduleCount <= row) {
261
+ row -= inc;
262
+ inc = -inc;
263
+ break;
264
+ }
265
+ }
266
+ }
267
+ };
268
+
269
+ var createBytes = function(buffer, rsBlocks) {
270
+
271
+ var offset = 0;
272
+
273
+ var maxDcCount = 0;
274
+ var maxEcCount = 0;
275
+
276
+ var dcdata = new Array(rsBlocks.length);
277
+ var ecdata = new Array(rsBlocks.length);
278
+
279
+ for (var r = 0; r < rsBlocks.length; r += 1) {
280
+
281
+ var dcCount = rsBlocks[r].dataCount;
282
+ var ecCount = rsBlocks[r].totalCount - dcCount;
283
+
284
+ maxDcCount = Math.max(maxDcCount, dcCount);
285
+ maxEcCount = Math.max(maxEcCount, ecCount);
286
+
287
+ dcdata[r] = new Array(dcCount);
288
+
289
+ for (var i = 0; i < dcdata[r].length; i += 1) {
290
+ dcdata[r][i] = 0xff & buffer.getBuffer()[i + offset];
291
+ }
292
+ offset += dcCount;
293
+
294
+ var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
295
+ var rawPoly = qrPolynomial(dcdata[r], rsPoly.getLength() - 1);
296
+
297
+ var modPoly = rawPoly.mod(rsPoly);
298
+ ecdata[r] = new Array(rsPoly.getLength() - 1);
299
+ for (var i = 0; i < ecdata[r].length; i += 1) {
300
+ var modIndex = i + modPoly.getLength() - ecdata[r].length;
301
+ ecdata[r][i] = (modIndex >= 0)? modPoly.getAt(modIndex) : 0;
302
+ }
303
+ }
304
+
305
+ var totalCodeCount = 0;
306
+ for (var i = 0; i < rsBlocks.length; i += 1) {
307
+ totalCodeCount += rsBlocks[i].totalCount;
308
+ }
309
+
310
+ var data = new Array(totalCodeCount);
311
+ var index = 0;
312
+
313
+ for (var i = 0; i < maxDcCount; i += 1) {
314
+ for (var r = 0; r < rsBlocks.length; r += 1) {
315
+ if (i < dcdata[r].length) {
316
+ data[index] = dcdata[r][i];
317
+ index += 1;
318
+ }
319
+ }
320
+ }
321
+
322
+ for (var i = 0; i < maxEcCount; i += 1) {
323
+ for (var r = 0; r < rsBlocks.length; r += 1) {
324
+ if (i < ecdata[r].length) {
325
+ data[index] = ecdata[r][i];
326
+ index += 1;
327
+ }
328
+ }
329
+ }
330
+
331
+ return data;
332
+ };
333
+
334
+ var createData = function(typeNumber, errorCorrectionLevel, dataList) {
335
+
336
+ var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectionLevel);
337
+
338
+ var buffer = qrBitBuffer();
339
+
340
+ for (var i = 0; i < dataList.length; i += 1) {
341
+ var data = dataList[i];
342
+ buffer.put(data.getMode(), 4);
343
+ buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber) );
344
+ data.write(buffer);
345
+ }
346
+
347
+ // calc num max data.
348
+ var totalDataCount = 0;
349
+ for (var i = 0; i < rsBlocks.length; i += 1) {
350
+ totalDataCount += rsBlocks[i].dataCount;
351
+ }
352
+
353
+ if (buffer.getLengthInBits() > totalDataCount * 8) {
354
+ throw 'code length overflow. ('
355
+ + buffer.getLengthInBits()
356
+ + '>'
357
+ + totalDataCount * 8
358
+ + ')';
359
+ }
360
+
361
+ // end code
362
+ if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) {
363
+ buffer.put(0, 4);
364
+ }
365
+
366
+ // padding
367
+ while (buffer.getLengthInBits() % 8 != 0) {
368
+ buffer.putBit(false);
369
+ }
370
+
371
+ // padding
372
+ while (true) {
373
+
374
+ if (buffer.getLengthInBits() >= totalDataCount * 8) {
375
+ break;
376
+ }
377
+ buffer.put(PAD0, 8);
378
+
379
+ if (buffer.getLengthInBits() >= totalDataCount * 8) {
380
+ break;
381
+ }
382
+ buffer.put(PAD1, 8);
383
+ }
384
+
385
+ return createBytes(buffer, rsBlocks);
386
+ };
387
+
388
+ _this.addData = function(data, mode) {
389
+
390
+ mode = mode || 'Byte';
391
+
392
+ var newData = null;
393
+
394
+ switch(mode) {
395
+ case 'Numeric' :
396
+ newData = qrNumber(data);
397
+ break;
398
+ case 'Alphanumeric' :
399
+ newData = qrAlphaNum(data);
400
+ break;
401
+ case 'Byte' :
402
+ newData = qr8BitByte(data);
403
+ break;
404
+ case 'Kanji' :
405
+ newData = qrKanji(data);
406
+ break;
407
+ default :
408
+ throw 'mode:' + mode;
409
+ }
410
+
411
+ _dataList.push(newData);
412
+ _dataCache = null;
413
+ };
414
+
415
+ _this.isDark = function(row, col) {
416
+ if (row < 0 || _moduleCount <= row || col < 0 || _moduleCount <= col) {
417
+ throw row + ',' + col;
418
+ }
419
+ return _modules[row][col];
420
+ };
421
+
422
+ _this.getModuleCount = function() {
423
+ return _moduleCount;
424
+ };
425
+
426
+ _this.make = function() {
427
+ if (_typeNumber < 1) {
428
+ var typeNumber = 1;
429
+
430
+ for (; typeNumber < 40; typeNumber++) {
431
+ var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, _errorCorrectionLevel);
432
+ var buffer = qrBitBuffer();
433
+
434
+ for (var i = 0; i < _dataList.length; i++) {
435
+ var data = _dataList[i];
436
+ buffer.put(data.getMode(), 4);
437
+ buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber) );
438
+ data.write(buffer);
439
+ }
440
+
441
+ var totalDataCount = 0;
442
+ for (var i = 0; i < rsBlocks.length; i++) {
443
+ totalDataCount += rsBlocks[i].dataCount;
444
+ }
445
+
446
+ if (buffer.getLengthInBits() <= totalDataCount * 8) {
447
+ break;
448
+ }
449
+ }
450
+
451
+ _typeNumber = typeNumber;
452
+ }
453
+
454
+ makeImpl(false, getBestMaskPattern() );
455
+ };
456
+
457
+ _this.createTableTag = function(cellSize, margin) {
458
+
459
+ cellSize = cellSize || 2;
460
+ margin = (typeof margin == 'undefined')? cellSize * 4 : margin;
461
+
462
+ var qrHtml = '';
463
+
464
+ qrHtml += '<table style="';
465
+ qrHtml += ' border-width: 0px; border-style: none;';
466
+ qrHtml += ' border-collapse: collapse;';
467
+ qrHtml += ' padding: 0px; margin: ' + margin + 'px;';
468
+ qrHtml += '">';
469
+ qrHtml += '<tbody>';
470
+
471
+ for (var r = 0; r < _this.getModuleCount(); r += 1) {
472
+
473
+ qrHtml += '<tr>';
474
+
475
+ for (var c = 0; c < _this.getModuleCount(); c += 1) {
476
+ qrHtml += '<td style="';
477
+ qrHtml += ' border-width: 0px; border-style: none;';
478
+ qrHtml += ' border-collapse: collapse;';
479
+ qrHtml += ' padding: 0px; margin: 0px;';
480
+ qrHtml += ' width: ' + cellSize + 'px;';
481
+ qrHtml += ' height: ' + cellSize + 'px;';
482
+ qrHtml += ' background-color: ';
483
+ qrHtml += _this.isDark(r, c)? '#000000' : '#ffffff';
484
+ qrHtml += ';';
485
+ qrHtml += '"/>';
486
+ }
487
+
488
+ qrHtml += '</tr>';
489
+ }
490
+
491
+ qrHtml += '</tbody>';
492
+ qrHtml += '</table>';
493
+
494
+ return qrHtml;
495
+ };
496
+
497
+ _this.createSvgTag = function(cellSize, margin, alt, title) {
498
+
499
+ var opts = {};
500
+ if (typeof arguments[0] == 'object') {
501
+ // Called by options.
502
+ opts = arguments[0];
503
+ // overwrite cellSize and margin.
504
+ cellSize = opts.cellSize;
505
+ margin = opts.margin;
506
+ alt = opts.alt;
507
+ title = opts.title;
508
+ }
509
+
510
+ cellSize = cellSize || 2;
511
+ margin = (typeof margin == 'undefined')? cellSize * 4 : margin;
512
+
513
+ // Compose alt property surrogate
514
+ alt = (typeof alt === 'string') ? {text: alt} : alt || {};
515
+ alt.text = alt.text || null;
516
+ alt.id = (alt.text) ? alt.id || 'qrcode-description' : null;
517
+
518
+ // Compose title property surrogate
519
+ title = (typeof title === 'string') ? {text: title} : title || {};
520
+ title.text = title.text || null;
521
+ title.id = (title.text) ? title.id || 'qrcode-title' : null;
522
+
523
+ var size = _this.getModuleCount() * cellSize + margin * 2;
524
+ var c, mc, r, mr, qrSvg='', rect;
525
+
526
+ rect = 'l' + cellSize + ',0 0,' + cellSize +
527
+ ' -' + cellSize + ',0 0,-' + cellSize + 'z ';
528
+
529
+ qrSvg += '<svg version="1.1" xmlns="http://www.w3.org/2000/svg"';
530
+ qrSvg += !opts.scalable ? ' width="' + size + 'px" height="' + size + 'px"' : '';
531
+ qrSvg += ' viewBox="0 0 ' + size + ' ' + size + '" ';
532
+ qrSvg += ' preserveAspectRatio="xMinYMin meet"';
533
+ qrSvg += (title.text || alt.text) ? ' role="img" aria-labelledby="' +
534
+ escapeXml([title.id, alt.id].join(' ').trim() ) + '"' : '';
535
+ qrSvg += '>';
536
+ qrSvg += (title.text) ? '<title id="' + escapeXml(title.id) + '">' +
537
+ escapeXml(title.text) + '</title>' : '';
538
+ qrSvg += (alt.text) ? '<description id="' + escapeXml(alt.id) + '">' +
539
+ escapeXml(alt.text) + '</description>' : '';
540
+ qrSvg += '<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>';
541
+ qrSvg += '<path d="';
542
+
543
+ for (r = 0; r < _this.getModuleCount(); r += 1) {
544
+ mr = r * cellSize + margin;
545
+ for (c = 0; c < _this.getModuleCount(); c += 1) {
546
+ if (_this.isDark(r, c) ) {
547
+ mc = c*cellSize+margin;
548
+ qrSvg += 'M' + mc + ',' + mr + rect;
549
+ }
550
+ }
551
+ }
552
+
553
+ qrSvg += '" stroke="transparent" fill="black"/>';
554
+ qrSvg += '</svg>';
555
+
556
+ return qrSvg;
557
+ };
558
+
559
+ _this.createDataURL = function(cellSize, margin) {
560
+
561
+ cellSize = cellSize || 2;
562
+ margin = (typeof margin == 'undefined')? cellSize * 4 : margin;
563
+
564
+ var size = _this.getModuleCount() * cellSize + margin * 2;
565
+ var min = margin;
566
+ var max = size - margin;
567
+
568
+ return createDataURL(size, size, function(x, y) {
569
+ if (min <= x && x < max && min <= y && y < max) {
570
+ var c = Math.floor( (x - min) / cellSize);
571
+ var r = Math.floor( (y - min) / cellSize);
572
+ return _this.isDark(r, c)? 0 : 1;
573
+ } else {
574
+ return 1;
575
+ }
576
+ } );
577
+ };
578
+
579
+ _this.createImgTag = function(cellSize, margin, alt) {
580
+
581
+ cellSize = cellSize || 2;
582
+ margin = (typeof margin == 'undefined')? cellSize * 4 : margin;
583
+
584
+ var size = _this.getModuleCount() * cellSize + margin * 2;
585
+
586
+ var img = '';
587
+ img += '<img';
588
+ img += '\u0020src="';
589
+ img += _this.createDataURL(cellSize, margin);
590
+ img += '"';
591
+ img += '\u0020width="';
592
+ img += size;
593
+ img += '"';
594
+ img += '\u0020height="';
595
+ img += size;
596
+ img += '"';
597
+ if (alt) {
598
+ img += '\u0020alt="';
599
+ img += escapeXml(alt);
600
+ img += '"';
601
+ }
602
+ img += '/>';
603
+
604
+ return img;
605
+ };
606
+
607
+ var escapeXml = function(s) {
608
+ var escaped = '';
609
+ for (var i = 0; i < s.length; i += 1) {
610
+ var c = s.charAt(i);
611
+ switch(c) {
612
+ case '<': escaped += '&lt;'; break;
613
+ case '>': escaped += '&gt;'; break;
614
+ case '&': escaped += '&amp;'; break;
615
+ case '"': escaped += '&quot;'; break;
616
+ default : escaped += c; break;
617
+ }
618
+ }
619
+ return escaped;
620
+ };
621
+
622
+ var _createHalfASCII = function(margin) {
623
+ var cellSize = 1;
624
+ margin = (typeof margin == 'undefined')? cellSize * 2 : margin;
625
+
626
+ var size = _this.getModuleCount() * cellSize + margin * 2;
627
+ var min = margin;
628
+ var max = size - margin;
629
+
630
+ var y, x, r1, r2, p;
631
+
632
+ var blocks = {
633
+ '██': '█',
634
+ '█ ': '▀',
635
+ ' █': '▄',
636
+ ' ': ' '
637
+ };
638
+
639
+ var blocksLastLineNoMargin = {
640
+ '██': '▀',
641
+ '█ ': '▀',
642
+ ' █': ' ',
643
+ ' ': ' '
644
+ };
645
+
646
+ var ascii = '';
647
+ for (y = 0; y < size; y += 2) {
648
+ r1 = Math.floor((y - min) / cellSize);
649
+ r2 = Math.floor((y + 1 - min) / cellSize);
650
+ for (x = 0; x < size; x += 1) {
651
+ p = '█';
652
+
653
+ if (min <= x && x < max && min <= y && y < max && _this.isDark(r1, Math.floor((x - min) / cellSize))) {
654
+ p = ' ';
655
+ }
656
+
657
+ if (min <= x && x < max && min <= y+1 && y+1 < max && _this.isDark(r2, Math.floor((x - min) / cellSize))) {
658
+ p += ' ';
659
+ }
660
+ else {
661
+ p += '█';
662
+ }
663
+
664
+ // Output 2 characters per pixel, to create full square. 1 character per pixels gives only half width of square.
665
+ ascii += (margin < 1 && y+1 >= max) ? blocksLastLineNoMargin[p] : blocks[p];
666
+ }
667
+
668
+ ascii += '\n';
669
+ }
670
+
671
+ if (size % 2 && margin > 0) {
672
+ return ascii.substring(0, ascii.length - size - 1) + Array(size+1).join('▀');
673
+ }
674
+
675
+ return ascii.substring(0, ascii.length-1);
676
+ };
677
+
678
+ _this.createASCII = function(cellSize, margin) {
679
+ cellSize = cellSize || 1;
680
+
681
+ if (cellSize < 2) {
682
+ return _createHalfASCII(margin);
683
+ }
684
+
685
+ cellSize -= 1;
686
+ margin = (typeof margin == 'undefined')? cellSize * 2 : margin;
687
+
688
+ var size = _this.getModuleCount() * cellSize + margin * 2;
689
+ var min = margin;
690
+ var max = size - margin;
691
+
692
+ var y, x, r, p;
693
+
694
+ var white = Array(cellSize+1).join('██');
695
+ var black = Array(cellSize+1).join(' ');
696
+
697
+ var ascii = '';
698
+ var line = '';
699
+ for (y = 0; y < size; y += 1) {
700
+ r = Math.floor( (y - min) / cellSize);
701
+ line = '';
702
+ for (x = 0; x < size; x += 1) {
703
+ p = 1;
704
+
705
+ if (min <= x && x < max && min <= y && y < max && _this.isDark(r, Math.floor((x - min) / cellSize))) {
706
+ p = 0;
707
+ }
708
+
709
+ // Output 2 characters per pixel, to create full square. 1 character per pixels gives only half width of square.
710
+ line += p ? white : black;
711
+ }
712
+
713
+ for (r = 0; r < cellSize; r += 1) {
714
+ ascii += line + '\n';
715
+ }
716
+ }
717
+
718
+ return ascii.substring(0, ascii.length-1);
719
+ };
720
+
721
+ _this.renderTo2dContext = function(context, cellSize) {
722
+ cellSize = cellSize || 2;
723
+ var length = _this.getModuleCount();
724
+ for (var row = 0; row < length; row++) {
725
+ for (var col = 0; col < length; col++) {
726
+ context.fillStyle = _this.isDark(row, col) ? 'black' : 'white';
727
+ context.fillRect(row * cellSize, col * cellSize, cellSize, cellSize);
728
+ }
729
+ }
730
+ }
731
+
732
+ return _this;
733
+ };
734
+
735
+ //---------------------------------------------------------------------
736
+ // qrcode.stringToBytes
737
+ //---------------------------------------------------------------------
738
+
739
+ qrcode.stringToBytesFuncs = {
740
+ 'default' : function(s) {
741
+ var bytes = [];
742
+ for (var i = 0; i < s.length; i += 1) {
743
+ var c = s.charCodeAt(i);
744
+ bytes.push(c & 0xff);
745
+ }
746
+ return bytes;
747
+ }
748
+ };
749
+
750
+ qrcode.stringToBytes = qrcode.stringToBytesFuncs['default'];
751
+
752
+ //---------------------------------------------------------------------
753
+ // qrcode.createStringToBytes
754
+ //---------------------------------------------------------------------
755
+
756
+ /**
757
+ * @param unicodeData base64 string of byte array.
758
+ * [16bit Unicode],[16bit Bytes], ...
759
+ * @param numChars
760
+ */
761
+ qrcode.createStringToBytes = function(unicodeData, numChars) {
762
+
763
+ // create conversion map.
764
+
765
+ var unicodeMap = function() {
766
+
767
+ var bin = base64DecodeInputStream(unicodeData);
768
+ var read = function() {
769
+ var b = bin.read();
770
+ if (b == -1) throw 'eof';
771
+ return b;
772
+ };
773
+
774
+ var count = 0;
775
+ var unicodeMap = {};
776
+ while (true) {
777
+ var b0 = bin.read();
778
+ if (b0 == -1) break;
779
+ var b1 = read();
780
+ var b2 = read();
781
+ var b3 = read();
782
+ var k = String.fromCharCode( (b0 << 8) | b1);
783
+ var v = (b2 << 8) | b3;
784
+ unicodeMap[k] = v;
785
+ count += 1;
786
+ }
787
+ if (count != numChars) {
788
+ throw count + ' != ' + numChars;
789
+ }
790
+
791
+ return unicodeMap;
792
+ }();
793
+
794
+ var unknownChar = '?'.charCodeAt(0);
795
+
796
+ return function(s) {
797
+ var bytes = [];
798
+ for (var i = 0; i < s.length; i += 1) {
799
+ var c = s.charCodeAt(i);
800
+ if (c < 128) {
801
+ bytes.push(c);
802
+ } else {
803
+ var b = unicodeMap[s.charAt(i)];
804
+ if (typeof b == 'number') {
805
+ if ( (b & 0xff) == b) {
806
+ // 1byte
807
+ bytes.push(b);
808
+ } else {
809
+ // 2bytes
810
+ bytes.push(b >>> 8);
811
+ bytes.push(b & 0xff);
812
+ }
813
+ } else {
814
+ bytes.push(unknownChar);
815
+ }
816
+ }
817
+ }
818
+ return bytes;
819
+ };
820
+ };
821
+
822
+ //---------------------------------------------------------------------
823
+ // QRMode
824
+ //---------------------------------------------------------------------
825
+
826
+ var QRMode = {
827
+ MODE_NUMBER : 1 << 0,
828
+ MODE_ALPHA_NUM : 1 << 1,
829
+ MODE_8BIT_BYTE : 1 << 2,
830
+ MODE_KANJI : 1 << 3
831
+ };
832
+
833
+ //---------------------------------------------------------------------
834
+ // QRErrorCorrectionLevel
835
+ //---------------------------------------------------------------------
836
+
837
+ var QRErrorCorrectionLevel = {
838
+ L : 1,
839
+ M : 0,
840
+ Q : 3,
841
+ H : 2
842
+ };
843
+
844
+ //---------------------------------------------------------------------
845
+ // QRMaskPattern
846
+ //---------------------------------------------------------------------
847
+
848
+ var QRMaskPattern = {
849
+ PATTERN000 : 0,
850
+ PATTERN001 : 1,
851
+ PATTERN010 : 2,
852
+ PATTERN011 : 3,
853
+ PATTERN100 : 4,
854
+ PATTERN101 : 5,
855
+ PATTERN110 : 6,
856
+ PATTERN111 : 7
857
+ };
858
+
859
+ //---------------------------------------------------------------------
860
+ // QRUtil
861
+ //---------------------------------------------------------------------
862
+
863
+ var QRUtil = function() {
864
+
865
+ var PATTERN_POSITION_TABLE = [
866
+ [],
867
+ [6, 18],
868
+ [6, 22],
869
+ [6, 26],
870
+ [6, 30],
871
+ [6, 34],
872
+ [6, 22, 38],
873
+ [6, 24, 42],
874
+ [6, 26, 46],
875
+ [6, 28, 50],
876
+ [6, 30, 54],
877
+ [6, 32, 58],
878
+ [6, 34, 62],
879
+ [6, 26, 46, 66],
880
+ [6, 26, 48, 70],
881
+ [6, 26, 50, 74],
882
+ [6, 30, 54, 78],
883
+ [6, 30, 56, 82],
884
+ [6, 30, 58, 86],
885
+ [6, 34, 62, 90],
886
+ [6, 28, 50, 72, 94],
887
+ [6, 26, 50, 74, 98],
888
+ [6, 30, 54, 78, 102],
889
+ [6, 28, 54, 80, 106],
890
+ [6, 32, 58, 84, 110],
891
+ [6, 30, 58, 86, 114],
892
+ [6, 34, 62, 90, 118],
893
+ [6, 26, 50, 74, 98, 122],
894
+ [6, 30, 54, 78, 102, 126],
895
+ [6, 26, 52, 78, 104, 130],
896
+ [6, 30, 56, 82, 108, 134],
897
+ [6, 34, 60, 86, 112, 138],
898
+ [6, 30, 58, 86, 114, 142],
899
+ [6, 34, 62, 90, 118, 146],
900
+ [6, 30, 54, 78, 102, 126, 150],
901
+ [6, 24, 50, 76, 102, 128, 154],
902
+ [6, 28, 54, 80, 106, 132, 158],
903
+ [6, 32, 58, 84, 110, 136, 162],
904
+ [6, 26, 54, 82, 110, 138, 166],
905
+ [6, 30, 58, 86, 114, 142, 170]
906
+ ];
907
+ var G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0);
908
+ var G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0);
909
+ var G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1);
910
+
911
+ var _this = {};
912
+
913
+ var getBCHDigit = function(data) {
914
+ var digit = 0;
915
+ while (data != 0) {
916
+ digit += 1;
917
+ data >>>= 1;
918
+ }
919
+ return digit;
920
+ };
921
+
922
+ _this.getBCHTypeInfo = function(data) {
923
+ var d = data << 10;
924
+ while (getBCHDigit(d) - getBCHDigit(G15) >= 0) {
925
+ d ^= (G15 << (getBCHDigit(d) - getBCHDigit(G15) ) );
926
+ }
927
+ return ( (data << 10) | d) ^ G15_MASK;
928
+ };
929
+
930
+ _this.getBCHTypeNumber = function(data) {
931
+ var d = data << 12;
932
+ while (getBCHDigit(d) - getBCHDigit(G18) >= 0) {
933
+ d ^= (G18 << (getBCHDigit(d) - getBCHDigit(G18) ) );
934
+ }
935
+ return (data << 12) | d;
936
+ };
937
+
938
+ _this.getPatternPosition = function(typeNumber) {
939
+ return PATTERN_POSITION_TABLE[typeNumber - 1];
940
+ };
941
+
942
+ _this.getMaskFunction = function(maskPattern) {
943
+
944
+ switch (maskPattern) {
945
+
946
+ case QRMaskPattern.PATTERN000 :
947
+ return function(i, j) { return (i + j) % 2 == 0; };
948
+ case QRMaskPattern.PATTERN001 :
949
+ return function(i, j) { return i % 2 == 0; };
950
+ case QRMaskPattern.PATTERN010 :
951
+ return function(i, j) { return j % 3 == 0; };
952
+ case QRMaskPattern.PATTERN011 :
953
+ return function(i, j) { return (i + j) % 3 == 0; };
954
+ case QRMaskPattern.PATTERN100 :
955
+ return function(i, j) { return (Math.floor(i / 2) + Math.floor(j / 3) ) % 2 == 0; };
956
+ case QRMaskPattern.PATTERN101 :
957
+ return function(i, j) { return (i * j) % 2 + (i * j) % 3 == 0; };
958
+ case QRMaskPattern.PATTERN110 :
959
+ return function(i, j) { return ( (i * j) % 2 + (i * j) % 3) % 2 == 0; };
960
+ case QRMaskPattern.PATTERN111 :
961
+ return function(i, j) { return ( (i * j) % 3 + (i + j) % 2) % 2 == 0; };
962
+
963
+ default :
964
+ throw 'bad maskPattern:' + maskPattern;
965
+ }
966
+ };
967
+
968
+ _this.getErrorCorrectPolynomial = function(errorCorrectLength) {
969
+ var a = qrPolynomial([1], 0);
970
+ for (var i = 0; i < errorCorrectLength; i += 1) {
971
+ a = a.multiply(qrPolynomial([1, QRMath.gexp(i)], 0) );
972
+ }
973
+ return a;
974
+ };
975
+
976
+ _this.getLengthInBits = function(mode, type) {
977
+
978
+ if (1 <= type && type < 10) {
979
+
980
+ // 1 - 9
981
+
982
+ switch(mode) {
983
+ case QRMode.MODE_NUMBER : return 10;
984
+ case QRMode.MODE_ALPHA_NUM : return 9;
985
+ case QRMode.MODE_8BIT_BYTE : return 8;
986
+ case QRMode.MODE_KANJI : return 8;
987
+ default :
988
+ throw 'mode:' + mode;
989
+ }
990
+
991
+ } else if (type < 27) {
992
+
993
+ // 10 - 26
994
+
995
+ switch(mode) {
996
+ case QRMode.MODE_NUMBER : return 12;
997
+ case QRMode.MODE_ALPHA_NUM : return 11;
998
+ case QRMode.MODE_8BIT_BYTE : return 16;
999
+ case QRMode.MODE_KANJI : return 10;
1000
+ default :
1001
+ throw 'mode:' + mode;
1002
+ }
1003
+
1004
+ } else if (type < 41) {
1005
+
1006
+ // 27 - 40
1007
+
1008
+ switch(mode) {
1009
+ case QRMode.MODE_NUMBER : return 14;
1010
+ case QRMode.MODE_ALPHA_NUM : return 13;
1011
+ case QRMode.MODE_8BIT_BYTE : return 16;
1012
+ case QRMode.MODE_KANJI : return 12;
1013
+ default :
1014
+ throw 'mode:' + mode;
1015
+ }
1016
+
1017
+ } else {
1018
+ throw 'type:' + type;
1019
+ }
1020
+ };
1021
+
1022
+ _this.getLostPoint = function(qrcode) {
1023
+
1024
+ var moduleCount = qrcode.getModuleCount();
1025
+
1026
+ var lostPoint = 0;
1027
+
1028
+ // LEVEL1
1029
+
1030
+ for (var row = 0; row < moduleCount; row += 1) {
1031
+ for (var col = 0; col < moduleCount; col += 1) {
1032
+
1033
+ var sameCount = 0;
1034
+ var dark = qrcode.isDark(row, col);
1035
+
1036
+ for (var r = -1; r <= 1; r += 1) {
1037
+
1038
+ if (row + r < 0 || moduleCount <= row + r) {
1039
+ continue;
1040
+ }
1041
+
1042
+ for (var c = -1; c <= 1; c += 1) {
1043
+
1044
+ if (col + c < 0 || moduleCount <= col + c) {
1045
+ continue;
1046
+ }
1047
+
1048
+ if (r == 0 && c == 0) {
1049
+ continue;
1050
+ }
1051
+
1052
+ if (dark == qrcode.isDark(row + r, col + c) ) {
1053
+ sameCount += 1;
1054
+ }
1055
+ }
1056
+ }
1057
+
1058
+ if (sameCount > 5) {
1059
+ lostPoint += (3 + sameCount - 5);
1060
+ }
1061
+ }
1062
+ };
1063
+
1064
+ // LEVEL2
1065
+
1066
+ for (var row = 0; row < moduleCount - 1; row += 1) {
1067
+ for (var col = 0; col < moduleCount - 1; col += 1) {
1068
+ var count = 0;
1069
+ if (qrcode.isDark(row, col) ) count += 1;
1070
+ if (qrcode.isDark(row + 1, col) ) count += 1;
1071
+ if (qrcode.isDark(row, col + 1) ) count += 1;
1072
+ if (qrcode.isDark(row + 1, col + 1) ) count += 1;
1073
+ if (count == 0 || count == 4) {
1074
+ lostPoint += 3;
1075
+ }
1076
+ }
1077
+ }
1078
+
1079
+ // LEVEL3
1080
+
1081
+ for (var row = 0; row < moduleCount; row += 1) {
1082
+ for (var col = 0; col < moduleCount - 6; col += 1) {
1083
+ if (qrcode.isDark(row, col)
1084
+ && !qrcode.isDark(row, col + 1)
1085
+ && qrcode.isDark(row, col + 2)
1086
+ && qrcode.isDark(row, col + 3)
1087
+ && qrcode.isDark(row, col + 4)
1088
+ && !qrcode.isDark(row, col + 5)
1089
+ && qrcode.isDark(row, col + 6) ) {
1090
+ lostPoint += 40;
1091
+ }
1092
+ }
1093
+ }
1094
+
1095
+ for (var col = 0; col < moduleCount; col += 1) {
1096
+ for (var row = 0; row < moduleCount - 6; row += 1) {
1097
+ if (qrcode.isDark(row, col)
1098
+ && !qrcode.isDark(row + 1, col)
1099
+ && qrcode.isDark(row + 2, col)
1100
+ && qrcode.isDark(row + 3, col)
1101
+ && qrcode.isDark(row + 4, col)
1102
+ && !qrcode.isDark(row + 5, col)
1103
+ && qrcode.isDark(row + 6, col) ) {
1104
+ lostPoint += 40;
1105
+ }
1106
+ }
1107
+ }
1108
+
1109
+ // LEVEL4
1110
+
1111
+ var darkCount = 0;
1112
+
1113
+ for (var col = 0; col < moduleCount; col += 1) {
1114
+ for (var row = 0; row < moduleCount; row += 1) {
1115
+ if (qrcode.isDark(row, col) ) {
1116
+ darkCount += 1;
1117
+ }
1118
+ }
1119
+ }
1120
+
1121
+ var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
1122
+ lostPoint += ratio * 10;
1123
+
1124
+ return lostPoint;
1125
+ };
1126
+
1127
+ return _this;
1128
+ }();
1129
+
1130
+ //---------------------------------------------------------------------
1131
+ // QRMath
1132
+ //---------------------------------------------------------------------
1133
+
1134
+ var QRMath = function() {
1135
+
1136
+ var EXP_TABLE = new Array(256);
1137
+ var LOG_TABLE = new Array(256);
1138
+
1139
+ // initialize tables
1140
+ for (var i = 0; i < 8; i += 1) {
1141
+ EXP_TABLE[i] = 1 << i;
1142
+ }
1143
+ for (var i = 8; i < 256; i += 1) {
1144
+ EXP_TABLE[i] = EXP_TABLE[i - 4]
1145
+ ^ EXP_TABLE[i - 5]
1146
+ ^ EXP_TABLE[i - 6]
1147
+ ^ EXP_TABLE[i - 8];
1148
+ }
1149
+ for (var i = 0; i < 255; i += 1) {
1150
+ LOG_TABLE[EXP_TABLE[i] ] = i;
1151
+ }
1152
+
1153
+ var _this = {};
1154
+
1155
+ _this.glog = function(n) {
1156
+
1157
+ if (n < 1) {
1158
+ throw 'glog(' + n + ')';
1159
+ }
1160
+
1161
+ return LOG_TABLE[n];
1162
+ };
1163
+
1164
+ _this.gexp = function(n) {
1165
+
1166
+ while (n < 0) {
1167
+ n += 255;
1168
+ }
1169
+
1170
+ while (n >= 256) {
1171
+ n -= 255;
1172
+ }
1173
+
1174
+ return EXP_TABLE[n];
1175
+ };
1176
+
1177
+ return _this;
1178
+ }();
1179
+
1180
+ //---------------------------------------------------------------------
1181
+ // qrPolynomial
1182
+ //---------------------------------------------------------------------
1183
+
1184
+ function qrPolynomial(num, shift) {
1185
+
1186
+ if (typeof num.length == 'undefined') {
1187
+ throw num.length + '/' + shift;
1188
+ }
1189
+
1190
+ var _num = function() {
1191
+ var offset = 0;
1192
+ while (offset < num.length && num[offset] == 0) {
1193
+ offset += 1;
1194
+ }
1195
+ var _num = new Array(num.length - offset + shift);
1196
+ for (var i = 0; i < num.length - offset; i += 1) {
1197
+ _num[i] = num[i + offset];
1198
+ }
1199
+ return _num;
1200
+ }();
1201
+
1202
+ var _this = {};
1203
+
1204
+ _this.getAt = function(index) {
1205
+ return _num[index];
1206
+ };
1207
+
1208
+ _this.getLength = function() {
1209
+ return _num.length;
1210
+ };
1211
+
1212
+ _this.multiply = function(e) {
1213
+
1214
+ var num = new Array(_this.getLength() + e.getLength() - 1);
1215
+
1216
+ for (var i = 0; i < _this.getLength(); i += 1) {
1217
+ for (var j = 0; j < e.getLength(); j += 1) {
1218
+ num[i + j] ^= QRMath.gexp(QRMath.glog(_this.getAt(i) ) + QRMath.glog(e.getAt(j) ) );
1219
+ }
1220
+ }
1221
+
1222
+ return qrPolynomial(num, 0);
1223
+ };
1224
+
1225
+ _this.mod = function(e) {
1226
+
1227
+ if (_this.getLength() - e.getLength() < 0) {
1228
+ return _this;
1229
+ }
1230
+
1231
+ var ratio = QRMath.glog(_this.getAt(0) ) - QRMath.glog(e.getAt(0) );
1232
+
1233
+ var num = new Array(_this.getLength() );
1234
+ for (var i = 0; i < _this.getLength(); i += 1) {
1235
+ num[i] = _this.getAt(i);
1236
+ }
1237
+
1238
+ for (var i = 0; i < e.getLength(); i += 1) {
1239
+ num[i] ^= QRMath.gexp(QRMath.glog(e.getAt(i) ) + ratio);
1240
+ }
1241
+
1242
+ // recursive call
1243
+ return qrPolynomial(num, 0).mod(e);
1244
+ };
1245
+
1246
+ return _this;
1247
+ };
1248
+
1249
+ //---------------------------------------------------------------------
1250
+ // QRRSBlock
1251
+ //---------------------------------------------------------------------
1252
+
1253
+ var QRRSBlock = function() {
1254
+
1255
+ var RS_BLOCK_TABLE = [
1256
+
1257
+ // L
1258
+ // M
1259
+ // Q
1260
+ // H
1261
+
1262
+ // 1
1263
+ [1, 26, 19],
1264
+ [1, 26, 16],
1265
+ [1, 26, 13],
1266
+ [1, 26, 9],
1267
+
1268
+ // 2
1269
+ [1, 44, 34],
1270
+ [1, 44, 28],
1271
+ [1, 44, 22],
1272
+ [1, 44, 16],
1273
+
1274
+ // 3
1275
+ [1, 70, 55],
1276
+ [1, 70, 44],
1277
+ [2, 35, 17],
1278
+ [2, 35, 13],
1279
+
1280
+ // 4
1281
+ [1, 100, 80],
1282
+ [2, 50, 32],
1283
+ [2, 50, 24],
1284
+ [4, 25, 9],
1285
+
1286
+ // 5
1287
+ [1, 134, 108],
1288
+ [2, 67, 43],
1289
+ [2, 33, 15, 2, 34, 16],
1290
+ [2, 33, 11, 2, 34, 12],
1291
+
1292
+ // 6
1293
+ [2, 86, 68],
1294
+ [4, 43, 27],
1295
+ [4, 43, 19],
1296
+ [4, 43, 15],
1297
+
1298
+ // 7
1299
+ [2, 98, 78],
1300
+ [4, 49, 31],
1301
+ [2, 32, 14, 4, 33, 15],
1302
+ [4, 39, 13, 1, 40, 14],
1303
+
1304
+ // 8
1305
+ [2, 121, 97],
1306
+ [2, 60, 38, 2, 61, 39],
1307
+ [4, 40, 18, 2, 41, 19],
1308
+ [4, 40, 14, 2, 41, 15],
1309
+
1310
+ // 9
1311
+ [2, 146, 116],
1312
+ [3, 58, 36, 2, 59, 37],
1313
+ [4, 36, 16, 4, 37, 17],
1314
+ [4, 36, 12, 4, 37, 13],
1315
+
1316
+ // 10
1317
+ [2, 86, 68, 2, 87, 69],
1318
+ [4, 69, 43, 1, 70, 44],
1319
+ [6, 43, 19, 2, 44, 20],
1320
+ [6, 43, 15, 2, 44, 16],
1321
+
1322
+ // 11
1323
+ [4, 101, 81],
1324
+ [1, 80, 50, 4, 81, 51],
1325
+ [4, 50, 22, 4, 51, 23],
1326
+ [3, 36, 12, 8, 37, 13],
1327
+
1328
+ // 12
1329
+ [2, 116, 92, 2, 117, 93],
1330
+ [6, 58, 36, 2, 59, 37],
1331
+ [4, 46, 20, 6, 47, 21],
1332
+ [7, 42, 14, 4, 43, 15],
1333
+
1334
+ // 13
1335
+ [4, 133, 107],
1336
+ [8, 59, 37, 1, 60, 38],
1337
+ [8, 44, 20, 4, 45, 21],
1338
+ [12, 33, 11, 4, 34, 12],
1339
+
1340
+ // 14
1341
+ [3, 145, 115, 1, 146, 116],
1342
+ [4, 64, 40, 5, 65, 41],
1343
+ [11, 36, 16, 5, 37, 17],
1344
+ [11, 36, 12, 5, 37, 13],
1345
+
1346
+ // 15
1347
+ [5, 109, 87, 1, 110, 88],
1348
+ [5, 65, 41, 5, 66, 42],
1349
+ [5, 54, 24, 7, 55, 25],
1350
+ [11, 36, 12, 7, 37, 13],
1351
+
1352
+ // 16
1353
+ [5, 122, 98, 1, 123, 99],
1354
+ [7, 73, 45, 3, 74, 46],
1355
+ [15, 43, 19, 2, 44, 20],
1356
+ [3, 45, 15, 13, 46, 16],
1357
+
1358
+ // 17
1359
+ [1, 135, 107, 5, 136, 108],
1360
+ [10, 74, 46, 1, 75, 47],
1361
+ [1, 50, 22, 15, 51, 23],
1362
+ [2, 42, 14, 17, 43, 15],
1363
+
1364
+ // 18
1365
+ [5, 150, 120, 1, 151, 121],
1366
+ [9, 69, 43, 4, 70, 44],
1367
+ [17, 50, 22, 1, 51, 23],
1368
+ [2, 42, 14, 19, 43, 15],
1369
+
1370
+ // 19
1371
+ [3, 141, 113, 4, 142, 114],
1372
+ [3, 70, 44, 11, 71, 45],
1373
+ [17, 47, 21, 4, 48, 22],
1374
+ [9, 39, 13, 16, 40, 14],
1375
+
1376
+ // 20
1377
+ [3, 135, 107, 5, 136, 108],
1378
+ [3, 67, 41, 13, 68, 42],
1379
+ [15, 54, 24, 5, 55, 25],
1380
+ [15, 43, 15, 10, 44, 16],
1381
+
1382
+ // 21
1383
+ [4, 144, 116, 4, 145, 117],
1384
+ [17, 68, 42],
1385
+ [17, 50, 22, 6, 51, 23],
1386
+ [19, 46, 16, 6, 47, 17],
1387
+
1388
+ // 22
1389
+ [2, 139, 111, 7, 140, 112],
1390
+ [17, 74, 46],
1391
+ [7, 54, 24, 16, 55, 25],
1392
+ [34, 37, 13],
1393
+
1394
+ // 23
1395
+ [4, 151, 121, 5, 152, 122],
1396
+ [4, 75, 47, 14, 76, 48],
1397
+ [11, 54, 24, 14, 55, 25],
1398
+ [16, 45, 15, 14, 46, 16],
1399
+
1400
+ // 24
1401
+ [6, 147, 117, 4, 148, 118],
1402
+ [6, 73, 45, 14, 74, 46],
1403
+ [11, 54, 24, 16, 55, 25],
1404
+ [30, 46, 16, 2, 47, 17],
1405
+
1406
+ // 25
1407
+ [8, 132, 106, 4, 133, 107],
1408
+ [8, 75, 47, 13, 76, 48],
1409
+ [7, 54, 24, 22, 55, 25],
1410
+ [22, 45, 15, 13, 46, 16],
1411
+
1412
+ // 26
1413
+ [10, 142, 114, 2, 143, 115],
1414
+ [19, 74, 46, 4, 75, 47],
1415
+ [28, 50, 22, 6, 51, 23],
1416
+ [33, 46, 16, 4, 47, 17],
1417
+
1418
+ // 27
1419
+ [8, 152, 122, 4, 153, 123],
1420
+ [22, 73, 45, 3, 74, 46],
1421
+ [8, 53, 23, 26, 54, 24],
1422
+ [12, 45, 15, 28, 46, 16],
1423
+
1424
+ // 28
1425
+ [3, 147, 117, 10, 148, 118],
1426
+ [3, 73, 45, 23, 74, 46],
1427
+ [4, 54, 24, 31, 55, 25],
1428
+ [11, 45, 15, 31, 46, 16],
1429
+
1430
+ // 29
1431
+ [7, 146, 116, 7, 147, 117],
1432
+ [21, 73, 45, 7, 74, 46],
1433
+ [1, 53, 23, 37, 54, 24],
1434
+ [19, 45, 15, 26, 46, 16],
1435
+
1436
+ // 30
1437
+ [5, 145, 115, 10, 146, 116],
1438
+ [19, 75, 47, 10, 76, 48],
1439
+ [15, 54, 24, 25, 55, 25],
1440
+ [23, 45, 15, 25, 46, 16],
1441
+
1442
+ // 31
1443
+ [13, 145, 115, 3, 146, 116],
1444
+ [2, 74, 46, 29, 75, 47],
1445
+ [42, 54, 24, 1, 55, 25],
1446
+ [23, 45, 15, 28, 46, 16],
1447
+
1448
+ // 32
1449
+ [17, 145, 115],
1450
+ [10, 74, 46, 23, 75, 47],
1451
+ [10, 54, 24, 35, 55, 25],
1452
+ [19, 45, 15, 35, 46, 16],
1453
+
1454
+ // 33
1455
+ [17, 145, 115, 1, 146, 116],
1456
+ [14, 74, 46, 21, 75, 47],
1457
+ [29, 54, 24, 19, 55, 25],
1458
+ [11, 45, 15, 46, 46, 16],
1459
+
1460
+ // 34
1461
+ [13, 145, 115, 6, 146, 116],
1462
+ [14, 74, 46, 23, 75, 47],
1463
+ [44, 54, 24, 7, 55, 25],
1464
+ [59, 46, 16, 1, 47, 17],
1465
+
1466
+ // 35
1467
+ [12, 151, 121, 7, 152, 122],
1468
+ [12, 75, 47, 26, 76, 48],
1469
+ [39, 54, 24, 14, 55, 25],
1470
+ [22, 45, 15, 41, 46, 16],
1471
+
1472
+ // 36
1473
+ [6, 151, 121, 14, 152, 122],
1474
+ [6, 75, 47, 34, 76, 48],
1475
+ [46, 54, 24, 10, 55, 25],
1476
+ [2, 45, 15, 64, 46, 16],
1477
+
1478
+ // 37
1479
+ [17, 152, 122, 4, 153, 123],
1480
+ [29, 74, 46, 14, 75, 47],
1481
+ [49, 54, 24, 10, 55, 25],
1482
+ [24, 45, 15, 46, 46, 16],
1483
+
1484
+ // 38
1485
+ [4, 152, 122, 18, 153, 123],
1486
+ [13, 74, 46, 32, 75, 47],
1487
+ [48, 54, 24, 14, 55, 25],
1488
+ [42, 45, 15, 32, 46, 16],
1489
+
1490
+ // 39
1491
+ [20, 147, 117, 4, 148, 118],
1492
+ [40, 75, 47, 7, 76, 48],
1493
+ [43, 54, 24, 22, 55, 25],
1494
+ [10, 45, 15, 67, 46, 16],
1495
+
1496
+ // 40
1497
+ [19, 148, 118, 6, 149, 119],
1498
+ [18, 75, 47, 31, 76, 48],
1499
+ [34, 54, 24, 34, 55, 25],
1500
+ [20, 45, 15, 61, 46, 16]
1501
+ ];
1502
+
1503
+ var qrRSBlock = function(totalCount, dataCount) {
1504
+ var _this = {};
1505
+ _this.totalCount = totalCount;
1506
+ _this.dataCount = dataCount;
1507
+ return _this;
1508
+ };
1509
+
1510
+ var _this = {};
1511
+
1512
+ var getRsBlockTable = function(typeNumber, errorCorrectionLevel) {
1513
+
1514
+ switch(errorCorrectionLevel) {
1515
+ case QRErrorCorrectionLevel.L :
1516
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0];
1517
+ case QRErrorCorrectionLevel.M :
1518
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];
1519
+ case QRErrorCorrectionLevel.Q :
1520
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];
1521
+ case QRErrorCorrectionLevel.H :
1522
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];
1523
+ default :
1524
+ return undefined;
1525
+ }
1526
+ };
1527
+
1528
+ _this.getRSBlocks = function(typeNumber, errorCorrectionLevel) {
1529
+
1530
+ var rsBlock = getRsBlockTable(typeNumber, errorCorrectionLevel);
1531
+
1532
+ if (typeof rsBlock == 'undefined') {
1533
+ throw 'bad rs block @ typeNumber:' + typeNumber +
1534
+ '/errorCorrectionLevel:' + errorCorrectionLevel;
1535
+ }
1536
+
1537
+ var length = rsBlock.length / 3;
1538
+
1539
+ var list = [];
1540
+
1541
+ for (var i = 0; i < length; i += 1) {
1542
+
1543
+ var count = rsBlock[i * 3 + 0];
1544
+ var totalCount = rsBlock[i * 3 + 1];
1545
+ var dataCount = rsBlock[i * 3 + 2];
1546
+
1547
+ for (var j = 0; j < count; j += 1) {
1548
+ list.push(qrRSBlock(totalCount, dataCount) );
1549
+ }
1550
+ }
1551
+
1552
+ return list;
1553
+ };
1554
+
1555
+ return _this;
1556
+ }();
1557
+
1558
+ //---------------------------------------------------------------------
1559
+ // qrBitBuffer
1560
+ //---------------------------------------------------------------------
1561
+
1562
+ var qrBitBuffer = function() {
1563
+
1564
+ var _buffer = [];
1565
+ var _length = 0;
1566
+
1567
+ var _this = {};
1568
+
1569
+ _this.getBuffer = function() {
1570
+ return _buffer;
1571
+ };
1572
+
1573
+ _this.getAt = function(index) {
1574
+ var bufIndex = Math.floor(index / 8);
1575
+ return ( (_buffer[bufIndex] >>> (7 - index % 8) ) & 1) == 1;
1576
+ };
1577
+
1578
+ _this.put = function(num, length) {
1579
+ for (var i = 0; i < length; i += 1) {
1580
+ _this.putBit( ( (num >>> (length - i - 1) ) & 1) == 1);
1581
+ }
1582
+ };
1583
+
1584
+ _this.getLengthInBits = function() {
1585
+ return _length;
1586
+ };
1587
+
1588
+ _this.putBit = function(bit) {
1589
+
1590
+ var bufIndex = Math.floor(_length / 8);
1591
+ if (_buffer.length <= bufIndex) {
1592
+ _buffer.push(0);
1593
+ }
1594
+
1595
+ if (bit) {
1596
+ _buffer[bufIndex] |= (0x80 >>> (_length % 8) );
1597
+ }
1598
+
1599
+ _length += 1;
1600
+ };
1601
+
1602
+ return _this;
1603
+ };
1604
+
1605
+ //---------------------------------------------------------------------
1606
+ // qrNumber
1607
+ //---------------------------------------------------------------------
1608
+
1609
+ var qrNumber = function(data) {
1610
+
1611
+ var _mode = QRMode.MODE_NUMBER;
1612
+ var _data = data;
1613
+
1614
+ var _this = {};
1615
+
1616
+ _this.getMode = function() {
1617
+ return _mode;
1618
+ };
1619
+
1620
+ _this.getLength = function(buffer) {
1621
+ return _data.length;
1622
+ };
1623
+
1624
+ _this.write = function(buffer) {
1625
+
1626
+ var data = _data;
1627
+
1628
+ var i = 0;
1629
+
1630
+ while (i + 2 < data.length) {
1631
+ buffer.put(strToNum(data.substring(i, i + 3) ), 10);
1632
+ i += 3;
1633
+ }
1634
+
1635
+ if (i < data.length) {
1636
+ if (data.length - i == 1) {
1637
+ buffer.put(strToNum(data.substring(i, i + 1) ), 4);
1638
+ } else if (data.length - i == 2) {
1639
+ buffer.put(strToNum(data.substring(i, i + 2) ), 7);
1640
+ }
1641
+ }
1642
+ };
1643
+
1644
+ var strToNum = function(s) {
1645
+ var num = 0;
1646
+ for (var i = 0; i < s.length; i += 1) {
1647
+ num = num * 10 + chatToNum(s.charAt(i) );
1648
+ }
1649
+ return num;
1650
+ };
1651
+
1652
+ var chatToNum = function(c) {
1653
+ if ('0' <= c && c <= '9') {
1654
+ return c.charCodeAt(0) - '0'.charCodeAt(0);
1655
+ }
1656
+ throw 'illegal char :' + c;
1657
+ };
1658
+
1659
+ return _this;
1660
+ };
1661
+
1662
+ //---------------------------------------------------------------------
1663
+ // qrAlphaNum
1664
+ //---------------------------------------------------------------------
1665
+
1666
+ var qrAlphaNum = function(data) {
1667
+
1668
+ var _mode = QRMode.MODE_ALPHA_NUM;
1669
+ var _data = data;
1670
+
1671
+ var _this = {};
1672
+
1673
+ _this.getMode = function() {
1674
+ return _mode;
1675
+ };
1676
+
1677
+ _this.getLength = function(buffer) {
1678
+ return _data.length;
1679
+ };
1680
+
1681
+ _this.write = function(buffer) {
1682
+
1683
+ var s = _data;
1684
+
1685
+ var i = 0;
1686
+
1687
+ while (i + 1 < s.length) {
1688
+ buffer.put(
1689
+ getCode(s.charAt(i) ) * 45 +
1690
+ getCode(s.charAt(i + 1) ), 11);
1691
+ i += 2;
1692
+ }
1693
+
1694
+ if (i < s.length) {
1695
+ buffer.put(getCode(s.charAt(i) ), 6);
1696
+ }
1697
+ };
1698
+
1699
+ var getCode = function(c) {
1700
+
1701
+ if ('0' <= c && c <= '9') {
1702
+ return c.charCodeAt(0) - '0'.charCodeAt(0);
1703
+ } else if ('A' <= c && c <= 'Z') {
1704
+ return c.charCodeAt(0) - 'A'.charCodeAt(0) + 10;
1705
+ } else {
1706
+ switch (c) {
1707
+ case ' ' : return 36;
1708
+ case '$' : return 37;
1709
+ case '%' : return 38;
1710
+ case '*' : return 39;
1711
+ case '+' : return 40;
1712
+ case '-' : return 41;
1713
+ case '.' : return 42;
1714
+ case '/' : return 43;
1715
+ case ':' : return 44;
1716
+ default :
1717
+ throw 'illegal char :' + c;
1718
+ }
1719
+ }
1720
+ };
1721
+
1722
+ return _this;
1723
+ };
1724
+
1725
+ //---------------------------------------------------------------------
1726
+ // qr8BitByte
1727
+ //---------------------------------------------------------------------
1728
+
1729
+ var qr8BitByte = function(data) {
1730
+
1731
+ var _mode = QRMode.MODE_8BIT_BYTE;
1732
+ var _data = data;
1733
+ var _bytes = qrcode.stringToBytes(data);
1734
+
1735
+ var _this = {};
1736
+
1737
+ _this.getMode = function() {
1738
+ return _mode;
1739
+ };
1740
+
1741
+ _this.getLength = function(buffer) {
1742
+ return _bytes.length;
1743
+ };
1744
+
1745
+ _this.write = function(buffer) {
1746
+ for (var i = 0; i < _bytes.length; i += 1) {
1747
+ buffer.put(_bytes[i], 8);
1748
+ }
1749
+ };
1750
+
1751
+ return _this;
1752
+ };
1753
+
1754
+ //---------------------------------------------------------------------
1755
+ // qrKanji
1756
+ //---------------------------------------------------------------------
1757
+
1758
+ var qrKanji = function(data) {
1759
+
1760
+ var _mode = QRMode.MODE_KANJI;
1761
+ var _data = data;
1762
+
1763
+ var stringToBytes = qrcode.stringToBytesFuncs['SJIS'];
1764
+ if (!stringToBytes) {
1765
+ throw 'sjis not supported.';
1766
+ }
1767
+ !function(c, code) {
1768
+ // self test for sjis support.
1769
+ var test = stringToBytes(c);
1770
+ if (test.length != 2 || ( (test[0] << 8) | test[1]) != code) {
1771
+ throw 'sjis not supported.';
1772
+ }
1773
+ }('\u53cb', 0x9746);
1774
+
1775
+ var _bytes = stringToBytes(data);
1776
+
1777
+ var _this = {};
1778
+
1779
+ _this.getMode = function() {
1780
+ return _mode;
1781
+ };
1782
+
1783
+ _this.getLength = function(buffer) {
1784
+ return ~~(_bytes.length / 2);
1785
+ };
1786
+
1787
+ _this.write = function(buffer) {
1788
+
1789
+ var data = _bytes;
1790
+
1791
+ var i = 0;
1792
+
1793
+ while (i + 1 < data.length) {
1794
+
1795
+ var c = ( (0xff & data[i]) << 8) | (0xff & data[i + 1]);
1796
+
1797
+ if (0x8140 <= c && c <= 0x9FFC) {
1798
+ c -= 0x8140;
1799
+ } else if (0xE040 <= c && c <= 0xEBBF) {
1800
+ c -= 0xC140;
1801
+ } else {
1802
+ throw 'illegal char at ' + (i + 1) + '/' + c;
1803
+ }
1804
+
1805
+ c = ( (c >>> 8) & 0xff) * 0xC0 + (c & 0xff);
1806
+
1807
+ buffer.put(c, 13);
1808
+
1809
+ i += 2;
1810
+ }
1811
+
1812
+ if (i < data.length) {
1813
+ throw 'illegal char at ' + (i + 1);
1814
+ }
1815
+ };
1816
+
1817
+ return _this;
1818
+ };
1819
+
1820
+ //=====================================================================
1821
+ // GIF Support etc.
1822
+ //
1823
+
1824
+ //---------------------------------------------------------------------
1825
+ // byteArrayOutputStream
1826
+ //---------------------------------------------------------------------
1827
+
1828
+ var byteArrayOutputStream = function() {
1829
+
1830
+ var _bytes = [];
1831
+
1832
+ var _this = {};
1833
+
1834
+ _this.writeByte = function(b) {
1835
+ _bytes.push(b & 0xff);
1836
+ };
1837
+
1838
+ _this.writeShort = function(i) {
1839
+ _this.writeByte(i);
1840
+ _this.writeByte(i >>> 8);
1841
+ };
1842
+
1843
+ _this.writeBytes = function(b, off, len) {
1844
+ off = off || 0;
1845
+ len = len || b.length;
1846
+ for (var i = 0; i < len; i += 1) {
1847
+ _this.writeByte(b[i + off]);
1848
+ }
1849
+ };
1850
+
1851
+ _this.writeString = function(s) {
1852
+ for (var i = 0; i < s.length; i += 1) {
1853
+ _this.writeByte(s.charCodeAt(i) );
1854
+ }
1855
+ };
1856
+
1857
+ _this.toByteArray = function() {
1858
+ return _bytes;
1859
+ };
1860
+
1861
+ _this.toString = function() {
1862
+ var s = '';
1863
+ s += '[';
1864
+ for (var i = 0; i < _bytes.length; i += 1) {
1865
+ if (i > 0) {
1866
+ s += ',';
1867
+ }
1868
+ s += _bytes[i];
1869
+ }
1870
+ s += ']';
1871
+ return s;
1872
+ };
1873
+
1874
+ return _this;
1875
+ };
1876
+
1877
+ //---------------------------------------------------------------------
1878
+ // base64EncodeOutputStream
1879
+ //---------------------------------------------------------------------
1880
+
1881
+ var base64EncodeOutputStream = function() {
1882
+
1883
+ var _buffer = 0;
1884
+ var _buflen = 0;
1885
+ var _length = 0;
1886
+ var _base64 = '';
1887
+
1888
+ var _this = {};
1889
+
1890
+ var writeEncoded = function(b) {
1891
+ _base64 += String.fromCharCode(encode(b & 0x3f) );
1892
+ };
1893
+
1894
+ var encode = function(n) {
1895
+ if (n < 0) {
1896
+ // error.
1897
+ } else if (n < 26) {
1898
+ return 0x41 + n;
1899
+ } else if (n < 52) {
1900
+ return 0x61 + (n - 26);
1901
+ } else if (n < 62) {
1902
+ return 0x30 + (n - 52);
1903
+ } else if (n == 62) {
1904
+ return 0x2b;
1905
+ } else if (n == 63) {
1906
+ return 0x2f;
1907
+ }
1908
+ throw 'n:' + n;
1909
+ };
1910
+
1911
+ _this.writeByte = function(n) {
1912
+
1913
+ _buffer = (_buffer << 8) | (n & 0xff);
1914
+ _buflen += 8;
1915
+ _length += 1;
1916
+
1917
+ while (_buflen >= 6) {
1918
+ writeEncoded(_buffer >>> (_buflen - 6) );
1919
+ _buflen -= 6;
1920
+ }
1921
+ };
1922
+
1923
+ _this.flush = function() {
1924
+
1925
+ if (_buflen > 0) {
1926
+ writeEncoded(_buffer << (6 - _buflen) );
1927
+ _buffer = 0;
1928
+ _buflen = 0;
1929
+ }
1930
+
1931
+ if (_length % 3 != 0) {
1932
+ // padding
1933
+ var padlen = 3 - _length % 3;
1934
+ for (var i = 0; i < padlen; i += 1) {
1935
+ _base64 += '=';
1936
+ }
1937
+ }
1938
+ };
1939
+
1940
+ _this.toString = function() {
1941
+ return _base64;
1942
+ };
1943
+
1944
+ return _this;
1945
+ };
1946
+
1947
+ //---------------------------------------------------------------------
1948
+ // base64DecodeInputStream
1949
+ //---------------------------------------------------------------------
1950
+
1951
+ var base64DecodeInputStream = function(str) {
1952
+
1953
+ var _str = str;
1954
+ var _pos = 0;
1955
+ var _buffer = 0;
1956
+ var _buflen = 0;
1957
+
1958
+ var _this = {};
1959
+
1960
+ _this.read = function() {
1961
+
1962
+ while (_buflen < 8) {
1963
+
1964
+ if (_pos >= _str.length) {
1965
+ if (_buflen == 0) {
1966
+ return -1;
1967
+ }
1968
+ throw 'unexpected end of file./' + _buflen;
1969
+ }
1970
+
1971
+ var c = _str.charAt(_pos);
1972
+ _pos += 1;
1973
+
1974
+ if (c == '=') {
1975
+ _buflen = 0;
1976
+ return -1;
1977
+ } else if (c.match(/^\s$/) ) {
1978
+ // ignore if whitespace.
1979
+ continue;
1980
+ }
1981
+
1982
+ _buffer = (_buffer << 6) | decode(c.charCodeAt(0) );
1983
+ _buflen += 6;
1984
+ }
1985
+
1986
+ var n = (_buffer >>> (_buflen - 8) ) & 0xff;
1987
+ _buflen -= 8;
1988
+ return n;
1989
+ };
1990
+
1991
+ var decode = function(c) {
1992
+ if (0x41 <= c && c <= 0x5a) {
1993
+ return c - 0x41;
1994
+ } else if (0x61 <= c && c <= 0x7a) {
1995
+ return c - 0x61 + 26;
1996
+ } else if (0x30 <= c && c <= 0x39) {
1997
+ return c - 0x30 + 52;
1998
+ } else if (c == 0x2b) {
1999
+ return 62;
2000
+ } else if (c == 0x2f) {
2001
+ return 63;
2002
+ } else {
2003
+ throw 'c:' + c;
2004
+ }
2005
+ };
2006
+
2007
+ return _this;
2008
+ };
2009
+
2010
+ //---------------------------------------------------------------------
2011
+ // gifImage (B/W)
2012
+ //---------------------------------------------------------------------
2013
+
2014
+ var gifImage = function(width, height) {
2015
+
2016
+ var _width = width;
2017
+ var _height = height;
2018
+ var _data = new Array(width * height);
2019
+
2020
+ var _this = {};
2021
+
2022
+ _this.setPixel = function(x, y, pixel) {
2023
+ _data[y * _width + x] = pixel;
2024
+ };
2025
+
2026
+ _this.write = function(out) {
2027
+
2028
+ //---------------------------------
2029
+ // GIF Signature
2030
+
2031
+ out.writeString('GIF87a');
2032
+
2033
+ //---------------------------------
2034
+ // Screen Descriptor
2035
+
2036
+ out.writeShort(_width);
2037
+ out.writeShort(_height);
2038
+
2039
+ out.writeByte(0x80); // 2bit
2040
+ out.writeByte(0);
2041
+ out.writeByte(0);
2042
+
2043
+ //---------------------------------
2044
+ // Global Color Map
2045
+
2046
+ // black
2047
+ out.writeByte(0x00);
2048
+ out.writeByte(0x00);
2049
+ out.writeByte(0x00);
2050
+
2051
+ // white
2052
+ out.writeByte(0xff);
2053
+ out.writeByte(0xff);
2054
+ out.writeByte(0xff);
2055
+
2056
+ //---------------------------------
2057
+ // Image Descriptor
2058
+
2059
+ out.writeString(',');
2060
+ out.writeShort(0);
2061
+ out.writeShort(0);
2062
+ out.writeShort(_width);
2063
+ out.writeShort(_height);
2064
+ out.writeByte(0);
2065
+
2066
+ //---------------------------------
2067
+ // Local Color Map
2068
+
2069
+ //---------------------------------
2070
+ // Raster Data
2071
+
2072
+ var lzwMinCodeSize = 2;
2073
+ var raster = getLZWRaster(lzwMinCodeSize);
2074
+
2075
+ out.writeByte(lzwMinCodeSize);
2076
+
2077
+ var offset = 0;
2078
+
2079
+ while (raster.length - offset > 255) {
2080
+ out.writeByte(255);
2081
+ out.writeBytes(raster, offset, 255);
2082
+ offset += 255;
2083
+ }
2084
+
2085
+ out.writeByte(raster.length - offset);
2086
+ out.writeBytes(raster, offset, raster.length - offset);
2087
+ out.writeByte(0x00);
2088
+
2089
+ //---------------------------------
2090
+ // GIF Terminator
2091
+ out.writeString(';');
2092
+ };
2093
+
2094
+ var bitOutputStream = function(out) {
2095
+
2096
+ var _out = out;
2097
+ var _bitLength = 0;
2098
+ var _bitBuffer = 0;
2099
+
2100
+ var _this = {};
2101
+
2102
+ _this.write = function(data, length) {
2103
+
2104
+ if ( (data >>> length) != 0) {
2105
+ throw 'length over';
2106
+ }
2107
+
2108
+ while (_bitLength + length >= 8) {
2109
+ _out.writeByte(0xff & ( (data << _bitLength) | _bitBuffer) );
2110
+ length -= (8 - _bitLength);
2111
+ data >>>= (8 - _bitLength);
2112
+ _bitBuffer = 0;
2113
+ _bitLength = 0;
2114
+ }
2115
+
2116
+ _bitBuffer = (data << _bitLength) | _bitBuffer;
2117
+ _bitLength = _bitLength + length;
2118
+ };
2119
+
2120
+ _this.flush = function() {
2121
+ if (_bitLength > 0) {
2122
+ _out.writeByte(_bitBuffer);
2123
+ }
2124
+ };
2125
+
2126
+ return _this;
2127
+ };
2128
+
2129
+ var getLZWRaster = function(lzwMinCodeSize) {
2130
+
2131
+ var clearCode = 1 << lzwMinCodeSize;
2132
+ var endCode = (1 << lzwMinCodeSize) + 1;
2133
+ var bitLength = lzwMinCodeSize + 1;
2134
+
2135
+ // Setup LZWTable
2136
+ var table = lzwTable();
2137
+
2138
+ for (var i = 0; i < clearCode; i += 1) {
2139
+ table.add(String.fromCharCode(i) );
2140
+ }
2141
+ table.add(String.fromCharCode(clearCode) );
2142
+ table.add(String.fromCharCode(endCode) );
2143
+
2144
+ var byteOut = byteArrayOutputStream();
2145
+ var bitOut = bitOutputStream(byteOut);
2146
+
2147
+ // clear code
2148
+ bitOut.write(clearCode, bitLength);
2149
+
2150
+ var dataIndex = 0;
2151
+
2152
+ var s = String.fromCharCode(_data[dataIndex]);
2153
+ dataIndex += 1;
2154
+
2155
+ while (dataIndex < _data.length) {
2156
+
2157
+ var c = String.fromCharCode(_data[dataIndex]);
2158
+ dataIndex += 1;
2159
+
2160
+ if (table.contains(s + c) ) {
2161
+
2162
+ s = s + c;
2163
+
2164
+ } else {
2165
+
2166
+ bitOut.write(table.indexOf(s), bitLength);
2167
+
2168
+ if (table.size() < 0xfff) {
2169
+
2170
+ if (table.size() == (1 << bitLength) ) {
2171
+ bitLength += 1;
2172
+ }
2173
+
2174
+ table.add(s + c);
2175
+ }
2176
+
2177
+ s = c;
2178
+ }
2179
+ }
2180
+
2181
+ bitOut.write(table.indexOf(s), bitLength);
2182
+
2183
+ // end code
2184
+ bitOut.write(endCode, bitLength);
2185
+
2186
+ bitOut.flush();
2187
+
2188
+ return byteOut.toByteArray();
2189
+ };
2190
+
2191
+ var lzwTable = function() {
2192
+
2193
+ var _map = {};
2194
+ var _size = 0;
2195
+
2196
+ var _this = {};
2197
+
2198
+ _this.add = function(key) {
2199
+ if (_this.contains(key) ) {
2200
+ throw 'dup key:' + key;
2201
+ }
2202
+ _map[key] = _size;
2203
+ _size += 1;
2204
+ };
2205
+
2206
+ _this.size = function() {
2207
+ return _size;
2208
+ };
2209
+
2210
+ _this.indexOf = function(key) {
2211
+ return _map[key];
2212
+ };
2213
+
2214
+ _this.contains = function(key) {
2215
+ return typeof _map[key] != 'undefined';
2216
+ };
2217
+
2218
+ return _this;
2219
+ };
2220
+
2221
+ return _this;
2222
+ };
2223
+
2224
+ var createDataURL = function(width, height, getPixel) {
2225
+ var gif = gifImage(width, height);
2226
+ for (var y = 0; y < height; y += 1) {
2227
+ for (var x = 0; x < width; x += 1) {
2228
+ gif.setPixel(x, y, getPixel(x, y) );
2229
+ }
2230
+ }
2231
+
2232
+ var b = byteArrayOutputStream();
2233
+ gif.write(b);
2234
+
2235
+ var base64 = base64EncodeOutputStream();
2236
+ var bytes = b.toByteArray();
2237
+ for (var i = 0; i < bytes.length; i += 1) {
2238
+ base64.writeByte(bytes[i]);
2239
+ }
2240
+ base64.flush();
2241
+
2242
+ return 'data:image/gif;base64,' + base64;
2243
+ };
2244
+
2245
+ //---------------------------------------------------------------------
2246
+ // returns qrcode function.
2247
+
2248
+ return qrcode;
2249
+ }();
2250
+
2251
+ // multibyte support
2252
+ !function() {
2253
+
2254
+ qrcode.stringToBytesFuncs['UTF-8'] = function(s) {
2255
+ // http://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array
2256
+ function toUTF8Array(str) {
2257
+ var utf8 = [];
2258
+ for (var i=0; i < str.length; i++) {
2259
+ var charcode = str.charCodeAt(i);
2260
+ if (charcode < 0x80) utf8.push(charcode);
2261
+ else if (charcode < 0x800) {
2262
+ utf8.push(0xc0 | (charcode >> 6),
2263
+ 0x80 | (charcode & 0x3f));
2264
+ }
2265
+ else if (charcode < 0xd800 || charcode >= 0xe000) {
2266
+ utf8.push(0xe0 | (charcode >> 12),
2267
+ 0x80 | ((charcode>>6) & 0x3f),
2268
+ 0x80 | (charcode & 0x3f));
2269
+ }
2270
+ // surrogate pair
2271
+ else {
2272
+ i++;
2273
+ // UTF-16 encodes 0x10000-0x10FFFF by
2274
+ // subtracting 0x10000 and splitting the
2275
+ // 20 bits of 0x0-0xFFFFF into two halves
2276
+ charcode = 0x10000 + (((charcode & 0x3ff)<<10)
2277
+ | (str.charCodeAt(i) & 0x3ff));
2278
+ utf8.push(0xf0 | (charcode >>18),
2279
+ 0x80 | ((charcode>>12) & 0x3f),
2280
+ 0x80 | ((charcode>>6) & 0x3f),
2281
+ 0x80 | (charcode & 0x3f));
2282
+ }
2283
+ }
2284
+ return utf8;
2285
+ }
2286
+ return toUTF8Array(s);
2287
+ };
2288
+
2289
+ }();
2290
+
2291
+ export default qrcode