├── images
├── logo.png
├── place.png
├── icon_32.png
├── loading.gif
└── screenshot
│ ├── 1.png
│ ├── 2.png
│ └── 3.png
├── README.md
├── popup.html
├── manifest.json
├── .gitattributes
├── _locales
├── zh_CN
│ └── messages.json
└── en
│ └── messages.json
├── js
├── options.js
├── popup.js
├── jsqrcode
│ ├── errorlevel.js
│ ├── gf256.js
│ ├── bitmat.js
│ ├── decoder.js
│ ├── datablock.js
│ ├── test.html
│ ├── formatinf.js
│ ├── datamask.js
│ ├── grid.js
│ ├── rsdecoder.js
│ ├── bmparser.js
│ ├── gf256poly.js
│ ├── alignpat.js
│ ├── databr.js
│ ├── qrcode.js
│ ├── detector.js
│ ├── version.js
│ └── findpat.js
├── config.js
├── background.js
├── zepto.qrcode.min.js
└── zepto.min.js
├── options.html
├── .gitignore
└── style
└── qr_helper.css
/images/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wujunze/chrome-qrHelper/master/images/logo.png
--------------------------------------------------------------------------------
/images/place.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wujunze/chrome-qrHelper/master/images/place.png
--------------------------------------------------------------------------------
/images/icon_32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wujunze/chrome-qrHelper/master/images/icon_32.png
--------------------------------------------------------------------------------
/images/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wujunze/chrome-qrHelper/master/images/loading.gif
--------------------------------------------------------------------------------
/images/screenshot/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wujunze/chrome-qrHelper/master/images/screenshot/1.png
--------------------------------------------------------------------------------
/images/screenshot/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wujunze/chrome-qrHelper/master/images/screenshot/2.png
--------------------------------------------------------------------------------
/images/screenshot/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wujunze/chrome-qrHelper/master/images/screenshot/3.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Chrome插件,二维码小助手
2 |
3 | 
4 |
5 | ##功能简介
6 |
7 | 1. 根据当前页面URL生成二维码
8 | 2. 解析页面上某个二维码
9 |
10 | ##版本历史
11 |
12 | `0.1.1` 完成功能
13 |
14 | `0.1.2` 修正网址过长生成失败;切换生成API为:`http://qr.liantu.com/api.php?text=`
--------------------------------------------------------------------------------
/popup.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 二维码小助手 - Laoshu133.com
6 |
7 |
8 |
9 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "manifest_version": 2,
3 | "version": "0.2.1",
4 | "name": "__MSG_name__",
5 | "default_locale": "zh_CN",
6 | "description": "__MSG_description__",
7 | "icons": {
8 | "48": "images/icon_32.png",
9 | "128": "images/logo.png"
10 | },
11 | "browser_action": {
12 | "default_icon": "images/icon_32.png",
13 | "default_popup": "popup.html"
14 | },
15 | "permissions": [ "tabs", "contextMenus", "*://*/*" ],
16 | "background": {
17 | "scripts": [ "js/jsqrcode.js", "js/config.js", "js/background.js"]
18 | },
19 | "options_page": "options.html"
20 | }
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/_locales/zh_CN/messages.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": {
3 | "message": "二维码小助手"
4 | },
5 | "description": {
6 | "message": "二维码小助手,根据当前页面URL生成二维码;解析页面上某个二维码"
7 | },
8 | "generate_qr_error": {
9 | "message": "二维码创建失败,请检查网络连接或与管理员联系!\nhttp://laoshu133.com"
10 | },
11 | "read_qr_title": {
12 | "message": "读取二维码"
13 | },
14 | "read_qr_txt_tips": {
15 | "message": "二维码解析成功且已复制,请粘贴使用:"
16 | },
17 | "read_qr_error_0": {
18 | "message": "图片加载失败!"
19 | },
20 | "read_qr_error_1": {
21 | "message": "网络或者服务器错误,请重试!"
22 | },
23 | "read_qr_error_2": {
24 | "message": "解码失败!"
25 | }
26 | }
--------------------------------------------------------------------------------
/js/options.js:
--------------------------------------------------------------------------------
1 | Zepto(function($){
2 | var configs = QRHelper.getConfig();
3 |
4 | for(var k in configs){
5 | var elem = $('#' + k)[0];
6 | if(elem.type === 'checkbox' || elem.type === 'radio'){
7 | elem.checked = !!configs[k];
8 | }
9 | else{
10 | elem.value = configs[k];
11 | }
12 | }
13 |
14 | function setConfig(elem){
15 | var val = elem.value;
16 | if(elem.type === 'checkbox' || elem.type === 'radio'){
17 | val = elem.checked;
18 | }
19 |
20 | QRHelper.setConfig(elem.id, val);
21 | }
22 |
23 | $('#content').delegate('input', 'change input', function(){
24 | setConfig(this);
25 | });
26 | });
--------------------------------------------------------------------------------
/js/popup.js:
--------------------------------------------------------------------------------
1 | /**
2 | * 读取页面URL 创建二维码
3 | * @author admin@laoshu133.com
4 | * @date 2015.03.20
5 | *
6 | * @dep https://github.com/jeromeetienne/jquery-qrcode
7 | */
8 |
9 | Zepto(function($) {
10 | var qrPanel = $('#qr_panel');
11 | var qrIcon = $('#qr_icon');
12 |
13 | chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
14 | var tab = tabs[0];
15 |
16 | qrPanel.qrcode({
17 | render: 'canvas',
18 | text: tab.url,
19 | height: 200,
20 | width: 200
21 | });
22 |
23 | if(tab.favIconUrl && tab.favIconUrl.indexOf('chrome://theme') !== 0){
24 | qrIcon.css('backgroundImage', 'url('+ tab.favIconUrl +')').show();
25 | }
26 |
27 | setTimeout(function() {
28 | qrPanel.addClass('active');
29 | }, 0);
30 | });
31 | });
32 |
--------------------------------------------------------------------------------
/_locales/en/messages.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": {
3 | "message": "QR Helper"
4 | },
5 | "description": {
6 | "message": "Qr code helper, generated qr code by the current page URL; Parsing a qr code on a page"
7 | },
8 | "generate_qr_error": {
9 | "message": "Qr code creation failed, please check the network connection or contact the administrator!"
10 | },
11 | "read_qr_title": {
12 | "message": "Read the qr code"
13 | },
14 | "read_qr_txt_tips": {
15 | "message": "Qr code parsing and replicated success, please paste the use:"
16 | },
17 | "read_qr_error_0": {
18 | "message": "Image loading failure!"
19 | },
20 | "read_qr_error_1": {
21 | "message": "The network or server error, please try again!"
22 | },
23 | "read_qr_error_2": {
24 | "message": "Decoding failure!"
25 | }
26 | }
--------------------------------------------------------------------------------
/options.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 二维码小助手 - Laoshu133.com
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
配置选项
14 |
22 |
23 |
感谢
24 |
25 |
26 | - http://www.liantu.com/
27 | - http://tool.oschina.net/
28 | - Matthew 的Logo设计
29 |
30 |
31 |
32 |
33 |
34 |
35 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/js/jsqrcode/errorlevel.js:
--------------------------------------------------------------------------------
1 | /*
2 | Ported to JavaScript by Lazar Laszlo 2011
3 |
4 | lazarsoft@gmail.com, www.lazarsoft.info
5 |
6 | */
7 |
8 | /*
9 | *
10 | * Copyright 2007 ZXing authors
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License");
13 | * you may not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS,
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 |
26 | function ErrorCorrectionLevel(ordinal, bits, name)
27 | {
28 | this.ordinal_Renamed_Field = ordinal;
29 | this.bits = bits;
30 | this.name = name;
31 | this.__defineGetter__("Bits", function()
32 | {
33 | return this.bits;
34 | });
35 | this.__defineGetter__("Name", function()
36 | {
37 | return this.name;
38 | });
39 | this.ordinal=function()
40 | {
41 | return this.ordinal_Renamed_Field;
42 | }
43 | }
44 |
45 | ErrorCorrectionLevel.forBits=function( bits)
46 | {
47 | if (bits < 0 || bits >= FOR_BITS.length)
48 | {
49 | throw "ArgumentException";
50 | }
51 | return FOR_BITS[bits];
52 | }
53 |
54 | var L = new ErrorCorrectionLevel(0, 0x01, "L");
55 | var M = new ErrorCorrectionLevel(1, 0x00, "M");
56 | var Q = new ErrorCorrectionLevel(2, 0x03, "Q");
57 | var H = new ErrorCorrectionLevel(3, 0x02, "H");
58 | var FOR_BITS = new Array( M, L, H, Q);
59 |
--------------------------------------------------------------------------------
/js/config.js:
--------------------------------------------------------------------------------
1 | /**
2 | * QRHelper config
3 | * @author admin@laoshu133.com
4 | * @date 2014.02.26
5 | */
6 | ;(function(){
7 | var
8 | QRHelper = window.QRHelper = {
9 | config_key: 'qr_helper_config',
10 | _defaults: {
11 | qr_read_enabled: true
12 | },
13 | getConfig: function(name){
14 | var configs = localStorage[this.config_key];
15 | if(!configs){
16 | this.setConfig(this._defaults);
17 | configs = localStorage[this.config_key];
18 | }
19 | configs = JSON.parse(configs);
20 | return name ? configs[name] : configs;
21 | },
22 | setConfig: function(name, val){
23 | var configs = localStorage[this.config_key];
24 | if(!configs){
25 | configs = {};
26 | for(var k in this._defaults){
27 | configs[k] = this._defaults[k];
28 | }
29 | }
30 | else{
31 | configs = JSON.parse(configs);
32 | }
33 |
34 | if(typeof name === 'object'){
35 | for(var k in name){
36 | configs[k] = name[k];
37 | }
38 | }
39 | else{
40 | configs[name] = val;
41 | }
42 | localStorage[this.config_key] = JSON.stringify(configs);
43 |
44 | if(location.pathname.replace('/', '') !== 'background.html'){
45 | var view = chrome.extension.getBackgroundPage();
46 | view.QRHelper.fire('config');
47 | }
48 | },
49 |
50 | //getLang
51 | getLang: function(name){
52 | return chrome.i18n.getMessage(name);
53 | },
54 |
55 | //Events
56 | on: function(type, callback){
57 | var
58 | events = this._events || (this._events = {}),
59 | handlers = events[type] || (events[type] = []);
60 | if(typeof callback === 'function'){
61 | handlers.push(callback);
62 | }
63 | return this;
64 | },
65 | off: function(type, callback){
66 | var events;
67 | if(type && (events = this._events)){
68 | if(!callback){
69 | events[type] = [];
70 | }
71 | else{
72 | for(var i = events[type].length; i>=0; i--){
73 | if(callback === events[type][i]){
74 | events[type].splice(i, 1);
75 | }
76 | }
77 | }
78 | }
79 | return this;
80 | },
81 | fire: function(evtent, data){
82 | var evt = { target: this };
83 | if(typeof evtent === 'string'){
84 | evt.type = evtent;
85 | }
86 | else if(typeof evtent === 'object'){
87 | for(var k in evtent){
88 | evt[k] = evtent[k];
89 | }
90 | }
91 |
92 | if(!evt.type){ throw 'Param type error'; }
93 |
94 | var
95 | ops = this.ops,
96 | events = this._events || {},
97 | handlers = [].concat(events[evt.type] || []);
98 | if(handlers.length > 0){
99 | for(var i = 0,len=handlers.length; i= 0x100)
36 | {
37 | x ^= primitive;
38 | }
39 | }
40 | for (var i = 0; i < 255; i++)
41 | {
42 | this.logTable[this.expTable[i]] = i;
43 | }
44 | // logTable[0] == 0 but this should never be used
45 | var at0=new Array(1);at0[0]=0;
46 | this.zero = new GF256Poly(this, new Array(at0));
47 | var at1=new Array(1);at1[0]=1;
48 | this.one = new GF256Poly(this, new Array(at1));
49 |
50 | this.__defineGetter__("Zero", function()
51 | {
52 | return this.zero;
53 | });
54 | this.__defineGetter__("One", function()
55 | {
56 | return this.one;
57 | });
58 | this.buildMonomial=function( degree, coefficient)
59 | {
60 | if (degree < 0)
61 | {
62 | throw "System.ArgumentException";
63 | }
64 | if (coefficient == 0)
65 | {
66 | return zero;
67 | }
68 | var coefficients = new Array(degree + 1);
69 | for(var i=0;i> 5;
37 | if ((width & 0x1f) != 0)
38 | {
39 | rowSize++;
40 | }
41 | this.rowSize = rowSize;
42 | this.bits = new Array(rowSize * height);
43 | for(var i=0;i> 5);
66 | return ((URShift(this.bits[offset], (x & 0x1f))) & 1) != 0;
67 | }
68 | this.set_Renamed=function( x, y)
69 | {
70 | var offset = y * this.rowSize + (x >> 5);
71 | this.bits[offset] |= 1 << (x & 0x1f);
72 | }
73 | this.flip=function( x, y)
74 | {
75 | var offset = y * this.rowSize + (x >> 5);
76 | this.bits[offset] ^= 1 << (x & 0x1f);
77 | }
78 | this.clear=function()
79 | {
80 | var max = this.bits.length;
81 | for (var i = 0; i < max; i++)
82 | {
83 | this.bits[i] = 0;
84 | }
85 | }
86 | this.setRegion=function( left, top, width, height)
87 | {
88 | if (top < 0 || left < 0)
89 | {
90 | throw "Left and top must be nonnegative";
91 | }
92 | if (height < 1 || width < 1)
93 | {
94 | throw "Height and width must be at least 1";
95 | }
96 | var right = left + width;
97 | var bottom = top + height;
98 | if (bottom > this.height || right > this.width)
99 | {
100 | throw "The region must fit inside the matrix";
101 | }
102 | for (var y = top; y < bottom; y++)
103 | {
104 | var offset = y * this.rowSize;
105 | for (var x = left; x < right; x++)
106 | {
107 | this.bits[offset + (x >> 5)] |= 1 << (x & 0x1f);
108 | }
109 | }
110 | }
111 | }
--------------------------------------------------------------------------------
/js/jsqrcode/decoder.js:
--------------------------------------------------------------------------------
1 | /*
2 | Ported to JavaScript by Lazar Laszlo 2011
3 |
4 | lazarsoft@gmail.com, www.lazarsoft.info
5 |
6 | */
7 |
8 | /*
9 | *
10 | * Copyright 2007 ZXing authors
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License");
13 | * you may not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS,
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 |
26 | Decoder={};
27 | Decoder.rsDecoder = new ReedSolomonDecoder(GF256.QR_CODE_FIELD);
28 |
29 | Decoder.correctErrors=function( codewordBytes, numDataCodewords)
30 | {
31 | var numCodewords = codewordBytes.length;
32 | // First read into an array of ints
33 | var codewordsInts = new Array(numCodewords);
34 | for (var i = 0; i < numCodewords; i++)
35 | {
36 | codewordsInts[i] = codewordBytes[i] & 0xFF;
37 | }
38 | var numECCodewords = codewordBytes.length - numDataCodewords;
39 | try
40 | {
41 | Decoder.rsDecoder.decode(codewordsInts, numECCodewords);
42 | //var corrector = new ReedSolomon(codewordsInts, numECCodewords);
43 | //corrector.correct();
44 | }
45 | catch ( rse)
46 | {
47 | throw rse;
48 | }
49 | // Copy back into array of bytes -- only need to worry about the bytes that were data
50 | // We don't care about errors in the error-correction codewords
51 | for (var i = 0; i < numDataCodewords; i++)
52 | {
53 | codewordBytes[i] = codewordsInts[i];
54 | }
55 | }
56 |
57 | Decoder.decode=function(bits)
58 | {
59 | var parser = new BitMatrixParser(bits);
60 | var version = parser.readVersion();
61 | var ecLevel = parser.readFormatInformation().ErrorCorrectionLevel;
62 |
63 | // Read codewords
64 | var codewords = parser.readCodewords();
65 |
66 | // Separate into data blocks
67 | var dataBlocks = DataBlock.getDataBlocks(codewords, version, ecLevel);
68 |
69 | // Count total number of data bytes
70 | var totalBytes = 0;
71 | for (var i = 0; i < dataBlocks.length; i++)
72 | {
73 | totalBytes += dataBlocks[i].NumDataCodewords;
74 | }
75 | var resultBytes = new Array(totalBytes);
76 | var resultOffset = 0;
77 |
78 | // Error-correct and copy data blocks together into a stream of bytes
79 | for (var j = 0; j < dataBlocks.length; j++)
80 | {
81 | var dataBlock = dataBlocks[j];
82 | var codewordBytes = dataBlock.Codewords;
83 | var numDataCodewords = dataBlock.NumDataCodewords;
84 | Decoder.correctErrors(codewordBytes, numDataCodewords);
85 | for (var i = 0; i < numDataCodewords; i++)
86 | {
87 | resultBytes[resultOffset++] = codewordBytes[i];
88 | }
89 | }
90 |
91 | // Decode the contents of that stream of bytes
92 | var reader = new QRCodeDataBlockReader(resultBytes, version.VersionNumber, ecLevel.Bits);
93 | return reader;
94 | //return DecodedBitStreamParser.decode(resultBytes, version, ecLevel);
95 | }
96 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #################
2 | ## Eclipse
3 | #################
4 |
5 | *.pydevproject
6 | .project
7 | .metadata
8 | bin/
9 | tmp/
10 | *.tmp
11 | *.bak
12 | *.swp
13 | *~.nib
14 | local.properties
15 | .classpath
16 | .settings/
17 | .loadpath
18 |
19 | # External tool builders
20 | .externalToolBuilders/
21 |
22 | # Locally stored "Eclipse launch configurations"
23 | *.launch
24 |
25 | # CDT-specific
26 | .cproject
27 |
28 | # PDT-specific
29 | .buildpath
30 |
31 |
32 | #################
33 | ## Visual Studio
34 | #################
35 |
36 | ## Ignore Visual Studio temporary files, build results, and
37 | ## files generated by popular Visual Studio add-ons.
38 |
39 | # User-specific files
40 | *.suo
41 | *.user
42 | *.sln.docstates
43 |
44 | # Build results
45 |
46 | [Dd]ebug/
47 | [Rr]elease/
48 | x64/
49 | build/
50 | [Bb]in/
51 | [Oo]bj/
52 |
53 | # MSTest test Results
54 | [Tt]est[Rr]esult*/
55 | [Bb]uild[Ll]og.*
56 |
57 | *_i.c
58 | *_p.c
59 | *.ilk
60 | *.meta
61 | *.obj
62 | *.pch
63 | *.pdb
64 | *.pgc
65 | *.pgd
66 | *.rsp
67 | *.sbr
68 | *.tlb
69 | *.tli
70 | *.tlh
71 | *.tmp
72 | *.tmp_proj
73 | *.log
74 | *.vspscc
75 | *.vssscc
76 | .builds
77 | *.pidb
78 | *.log
79 | *.scc
80 |
81 | # Visual C++ cache files
82 | ipch/
83 | *.aps
84 | *.ncb
85 | *.opensdf
86 | *.sdf
87 | *.cachefile
88 |
89 | # Visual Studio profiler
90 | *.psess
91 | *.vsp
92 | *.vspx
93 |
94 | # Guidance Automation Toolkit
95 | *.gpState
96 |
97 | # ReSharper is a .NET coding add-in
98 | _ReSharper*/
99 | *.[Rr]e[Ss]harper
100 |
101 | # TeamCity is a build add-in
102 | _TeamCity*
103 |
104 | # DotCover is a Code Coverage Tool
105 | *.dotCover
106 |
107 | # NCrunch
108 | *.ncrunch*
109 | .*crunch*.local.xml
110 |
111 | # Installshield output folder
112 | [Ee]xpress/
113 |
114 | # DocProject is a documentation generator add-in
115 | DocProject/buildhelp/
116 | DocProject/Help/*.HxT
117 | DocProject/Help/*.HxC
118 | DocProject/Help/*.hhc
119 | DocProject/Help/*.hhk
120 | DocProject/Help/*.hhp
121 | DocProject/Help/Html2
122 | DocProject/Help/html
123 |
124 | # Click-Once directory
125 | publish/
126 |
127 | # Publish Web Output
128 | *.Publish.xml
129 | *.pubxml
130 |
131 | # NuGet Packages Directory
132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
133 | #packages/
134 |
135 | # Windows Azure Build Output
136 | csx
137 | *.build.csdef
138 |
139 | # Windows Store app package directory
140 | AppPackages/
141 |
142 | # Others
143 | sql/
144 | *.Cache
145 | ClientBin/
146 | [Ss]tyle[Cc]op.*
147 | ~$*
148 | *~
149 | *.dbmdl
150 | *.[Pp]ublish.xml
151 | *.pfx
152 | *.publishsettings
153 |
154 | # RIA/Silverlight projects
155 | Generated_Code/
156 |
157 | # Backup & report files from converting an old project file to a newer
158 | # Visual Studio version. Backup files are not needed, because we have git ;-)
159 | _UpgradeReport_Files/
160 | Backup*/
161 | UpgradeLog*.XML
162 | UpgradeLog*.htm
163 |
164 | # SQL Server files
165 | App_Data/*.mdf
166 | App_Data/*.ldf
167 |
168 | #############
169 | ## Windows detritus
170 | #############
171 |
172 | # Windows image file caches
173 | Thumbs.db
174 | ehthumbs.db
175 |
176 | # Folder config file
177 | Desktop.ini
178 |
179 | # Recycle Bin used on file shares
180 | $RECYCLE.BIN/
181 |
182 | # Mac crap
183 | .DS_Store
184 |
185 |
186 | #############
187 | ## Python
188 | #############
189 |
190 | *.py[co]
191 |
192 | # Packages
193 | *.egg
194 | *.egg-info
195 | dist/
196 | build/
197 | eggs/
198 | parts/
199 | var/
200 | sdist/
201 | develop-eggs/
202 | .installed.cfg
203 |
204 | # Installer logs
205 | pip-log.txt
206 |
207 | # Unit test / coverage reports
208 | .coverage
209 | .tox
210 |
211 | #Translations
212 | *.mo
213 |
214 | #Mr Developer
215 | .mr.developer.cfg
216 | .svn
217 |
--------------------------------------------------------------------------------
/js/jsqrcode/datablock.js:
--------------------------------------------------------------------------------
1 | /*
2 | Ported to JavaScript by Lazar Laszlo 2011
3 |
4 | lazarsoft@gmail.com, www.lazarsoft.info
5 |
6 | */
7 |
8 | /*
9 | *
10 | * Copyright 2007 ZXing authors
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License");
13 | * you may not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS,
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 |
26 | function DataBlock(numDataCodewords, codewords)
27 | {
28 | this.numDataCodewords = numDataCodewords;
29 | this.codewords = codewords;
30 |
31 | this.__defineGetter__("NumDataCodewords", function()
32 | {
33 | return this.numDataCodewords;
34 | });
35 | this.__defineGetter__("Codewords", function()
36 | {
37 | return this.codewords;
38 | });
39 | }
40 |
41 | DataBlock.getDataBlocks=function(rawCodewords, version, ecLevel)
42 | {
43 |
44 | if (rawCodewords.length != version.TotalCodewords)
45 | {
46 | throw "ArgumentException";
47 | }
48 |
49 | // Figure out the number and size of data blocks used by this version and
50 | // error correction level
51 | var ecBlocks = version.getECBlocksForLevel(ecLevel);
52 |
53 | // First count the total number of data blocks
54 | var totalBlocks = 0;
55 | var ecBlockArray = ecBlocks.getECBlocks();
56 | for (var i = 0; i < ecBlockArray.length; i++)
57 | {
58 | totalBlocks += ecBlockArray[i].Count;
59 | }
60 |
61 | // Now establish DataBlocks of the appropriate size and number of data codewords
62 | var result = new Array(totalBlocks);
63 | var numResultBlocks = 0;
64 | for (var j = 0; j < ecBlockArray.length; j++)
65 | {
66 | var ecBlock = ecBlockArray[j];
67 | for (var i = 0; i < ecBlock.Count; i++)
68 | {
69 | var numDataCodewords = ecBlock.DataCodewords;
70 | var numBlockCodewords = ecBlocks.ECCodewordsPerBlock + numDataCodewords;
71 | result[numResultBlocks++] = new DataBlock(numDataCodewords, new Array(numBlockCodewords));
72 | }
73 | }
74 |
75 | // All blocks have the same amount of data, except that the last n
76 | // (where n may be 0) have 1 more byte. Figure out where these start.
77 | var shorterBlocksTotalCodewords = result[0].codewords.length;
78 | var longerBlocksStartAt = result.length - 1;
79 | while (longerBlocksStartAt >= 0)
80 | {
81 | var numCodewords = result[longerBlocksStartAt].codewords.length;
82 | if (numCodewords == shorterBlocksTotalCodewords)
83 | {
84 | break;
85 | }
86 | longerBlocksStartAt--;
87 | }
88 | longerBlocksStartAt++;
89 |
90 | var shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBlocks.ECCodewordsPerBlock;
91 | // The last elements of result may be 1 element longer;
92 | // first fill out as many elements as all of them have
93 | var rawCodewordsOffset = 0;
94 | for (var i = 0; i < shorterBlocksNumDataCodewords; i++)
95 | {
96 | for (var j = 0; j < numResultBlocks; j++)
97 | {
98 | result[j].codewords[i] = rawCodewords[rawCodewordsOffset++];
99 | }
100 | }
101 | // Fill out the last data block in the longer ones
102 | for (var j = longerBlocksStartAt; j < numResultBlocks; j++)
103 | {
104 | result[j].codewords[shorterBlocksNumDataCodewords] = rawCodewords[rawCodewordsOffset++];
105 | }
106 | // Now add in error correction blocks
107 | var max = result[0].codewords.length;
108 | for (var i = shorterBlocksNumDataCodewords; i < max; i++)
109 | {
110 | for (var j = 0; j < numResultBlocks; j++)
111 | {
112 | var iOffset = j < longerBlocksStartAt?i:i + 1;
113 | result[j].codewords[iOffset] = rawCodewords[rawCodewordsOffset++];
114 | }
115 | }
116 | return result;
117 | }
118 |
--------------------------------------------------------------------------------
/js/jsqrcode/test.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | QRCODE
4 |
5 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
131 |
132 |
133 |
134 |
135 |
145 |
146 |
147 |
148 |
149 |
--------------------------------------------------------------------------------
/js/jsqrcode/formatinf.js:
--------------------------------------------------------------------------------
1 | /*
2 | Ported to JavaScript by Lazar Laszlo 2011
3 |
4 | lazarsoft@gmail.com, www.lazarsoft.info
5 |
6 | */
7 |
8 | /*
9 | *
10 | * Copyright 2007 ZXing authors
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License");
13 | * you may not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS,
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 |
26 | var FORMAT_INFO_MASK_QR = 0x5412;
27 | var FORMAT_INFO_DECODE_LOOKUP = new Array(new Array(0x5412, 0x00), new Array(0x5125, 0x01), new Array(0x5E7C, 0x02), new Array(0x5B4B, 0x03), new Array(0x45F9, 0x04), new Array(0x40CE, 0x05), new Array(0x4F97, 0x06), new Array(0x4AA0, 0x07), new Array(0x77C4, 0x08), new Array(0x72F3, 0x09), new Array(0x7DAA, 0x0A), new Array(0x789D, 0x0B), new Array(0x662F, 0x0C), new Array(0x6318, 0x0D), new Array(0x6C41, 0x0E), new Array(0x6976, 0x0F), new Array(0x1689, 0x10), new Array(0x13BE, 0x11), new Array(0x1CE7, 0x12), new Array(0x19D0, 0x13), new Array(0x0762, 0x14), new Array(0x0255, 0x15), new Array(0x0D0C, 0x16), new Array(0x083B, 0x17), new Array(0x355F, 0x18), new Array(0x3068, 0x19), new Array(0x3F31, 0x1A), new Array(0x3A06, 0x1B), new Array(0x24B4, 0x1C), new Array(0x2183, 0x1D), new Array(0x2EDA, 0x1E), new Array(0x2BED, 0x1F));
28 | var BITS_SET_IN_HALF_BYTE = new Array(0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4);
29 |
30 |
31 | function FormatInformation(formatInfo)
32 | {
33 | this.errorCorrectionLevel = ErrorCorrectionLevel.forBits((formatInfo >> 3) & 0x03);
34 | this.dataMask = (formatInfo & 0x07);
35 |
36 | this.__defineGetter__("ErrorCorrectionLevel", function()
37 | {
38 | return this.errorCorrectionLevel;
39 | });
40 | this.__defineGetter__("DataMask", function()
41 | {
42 | return this.dataMask;
43 | });
44 | this.GetHashCode=function()
45 | {
46 | return (this.errorCorrectionLevel.ordinal() << 3) | dataMask;
47 | }
48 | this.Equals=function( o)
49 | {
50 | var other = o;
51 | return this.errorCorrectionLevel == other.errorCorrectionLevel && this.dataMask == other.dataMask;
52 | }
53 | }
54 |
55 | FormatInformation.numBitsDiffering=function( a, b)
56 | {
57 | a ^= b; // a now has a 1 bit exactly where its bit differs with b's
58 | // Count bits set quickly with a series of lookups:
59 | return BITS_SET_IN_HALF_BYTE[a & 0x0F] + BITS_SET_IN_HALF_BYTE[(URShift(a, 4) & 0x0F)] + BITS_SET_IN_HALF_BYTE[(URShift(a, 8) & 0x0F)] + BITS_SET_IN_HALF_BYTE[(URShift(a, 12) & 0x0F)] + BITS_SET_IN_HALF_BYTE[(URShift(a, 16) & 0x0F)] + BITS_SET_IN_HALF_BYTE[(URShift(a, 20) & 0x0F)] + BITS_SET_IN_HALF_BYTE[(URShift(a, 24) & 0x0F)] + BITS_SET_IN_HALF_BYTE[(URShift(a, 28) & 0x0F)];
60 | }
61 |
62 | FormatInformation.decodeFormatInformation=function( maskedFormatInfo)
63 | {
64 | var formatInfo = FormatInformation.doDecodeFormatInformation(maskedFormatInfo);
65 | if (formatInfo != null)
66 | {
67 | return formatInfo;
68 | }
69 | // Should return null, but, some QR codes apparently
70 | // do not mask this info. Try again by actually masking the pattern
71 | // first
72 | return FormatInformation.doDecodeFormatInformation(maskedFormatInfo ^ FORMAT_INFO_MASK_QR);
73 | }
74 | FormatInformation.doDecodeFormatInformation=function( maskedFormatInfo)
75 | {
76 | // Find the int in FORMAT_INFO_DECODE_LOOKUP with fewest bits differing
77 | var bestDifference = 0xffffffff;
78 | var bestFormatInfo = 0;
79 | for (var i = 0; i < FORMAT_INFO_DECODE_LOOKUP.length; i++)
80 | {
81 | var decodeInfo = FORMAT_INFO_DECODE_LOOKUP[i];
82 | var targetInfo = decodeInfo[0];
83 | if (targetInfo == maskedFormatInfo)
84 | {
85 | // Found an exact match
86 | return new FormatInformation(decodeInfo[1]);
87 | }
88 | var bitsDifference = this.numBitsDiffering(maskedFormatInfo, targetInfo);
89 | if (bitsDifference < bestDifference)
90 | {
91 | bestFormatInfo = decodeInfo[1];
92 | bestDifference = bitsDifference;
93 | }
94 | }
95 | // Hamming distance of the 32 masked codes is 7, by construction, so <= 3 bits
96 | // differing means we found a match
97 | if (bestDifference <= 3)
98 | {
99 | return new FormatInformation(bestFormatInfo);
100 | }
101 | return null;
102 | }
103 |
104 |
--------------------------------------------------------------------------------
/js/jsqrcode/datamask.js:
--------------------------------------------------------------------------------
1 | /*
2 | Ported to JavaScript by Lazar Laszlo 2011
3 |
4 | lazarsoft@gmail.com, www.lazarsoft.info
5 |
6 | */
7 |
8 | /*
9 | *
10 | * Copyright 2007 ZXing authors
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License");
13 | * you may not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS,
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 |
26 | DataMask = {};
27 |
28 | DataMask.forReference = function(reference)
29 | {
30 | if (reference < 0 || reference > 7)
31 | {
32 | throw "System.ArgumentException";
33 | }
34 | return DataMask.DATA_MASKS[reference];
35 | }
36 |
37 | function DataMask000()
38 | {
39 | this.unmaskBitMatrix=function(bits, dimension)
40 | {
41 | for (var i = 0; i < dimension; i++)
42 | {
43 | for (var j = 0; j < dimension; j++)
44 | {
45 | if (this.isMasked(i, j))
46 | {
47 | bits.flip(j, i);
48 | }
49 | }
50 | }
51 | }
52 | this.isMasked=function( i, j)
53 | {
54 | return ((i + j) & 0x01) == 0;
55 | }
56 | }
57 |
58 | function DataMask001()
59 | {
60 | this.unmaskBitMatrix=function(bits, dimension)
61 | {
62 | for (var i = 0; i < dimension; i++)
63 | {
64 | for (var j = 0; j < dimension; j++)
65 | {
66 | if (this.isMasked(i, j))
67 | {
68 | bits.flip(j, i);
69 | }
70 | }
71 | }
72 | }
73 | this.isMasked=function( i, j)
74 | {
75 | return (i & 0x01) == 0;
76 | }
77 | }
78 |
79 | function DataMask010()
80 | {
81 | this.unmaskBitMatrix=function(bits, dimension)
82 | {
83 | for (var i = 0; i < dimension; i++)
84 | {
85 | for (var j = 0; j < dimension; j++)
86 | {
87 | if (this.isMasked(i, j))
88 | {
89 | bits.flip(j, i);
90 | }
91 | }
92 | }
93 | }
94 | this.isMasked=function( i, j)
95 | {
96 | return j % 3 == 0;
97 | }
98 | }
99 |
100 | function DataMask011()
101 | {
102 | this.unmaskBitMatrix=function(bits, dimension)
103 | {
104 | for (var i = 0; i < dimension; i++)
105 | {
106 | for (var j = 0; j < dimension; j++)
107 | {
108 | if (this.isMasked(i, j))
109 | {
110 | bits.flip(j, i);
111 | }
112 | }
113 | }
114 | }
115 | this.isMasked=function( i, j)
116 | {
117 | return (i + j) % 3 == 0;
118 | }
119 | }
120 |
121 | function DataMask100()
122 | {
123 | this.unmaskBitMatrix=function(bits, dimension)
124 | {
125 | for (var i = 0; i < dimension; i++)
126 | {
127 | for (var j = 0; j < dimension; j++)
128 | {
129 | if (this.isMasked(i, j))
130 | {
131 | bits.flip(j, i);
132 | }
133 | }
134 | }
135 | }
136 | this.isMasked=function( i, j)
137 | {
138 | return (((URShift(i, 1)) + (j / 3)) & 0x01) == 0;
139 | }
140 | }
141 |
142 | function DataMask101()
143 | {
144 | this.unmaskBitMatrix=function(bits, dimension)
145 | {
146 | for (var i = 0; i < dimension; i++)
147 | {
148 | for (var j = 0; j < dimension; j++)
149 | {
150 | if (this.isMasked(i, j))
151 | {
152 | bits.flip(j, i);
153 | }
154 | }
155 | }
156 | }
157 | this.isMasked=function( i, j)
158 | {
159 | var temp = i * j;
160 | return (temp & 0x01) + (temp % 3) == 0;
161 | }
162 | }
163 |
164 | function DataMask110()
165 | {
166 | this.unmaskBitMatrix=function(bits, dimension)
167 | {
168 | for (var i = 0; i < dimension; i++)
169 | {
170 | for (var j = 0; j < dimension; j++)
171 | {
172 | if (this.isMasked(i, j))
173 | {
174 | bits.flip(j, i);
175 | }
176 | }
177 | }
178 | }
179 | this.isMasked=function( i, j)
180 | {
181 | var temp = i * j;
182 | return (((temp & 0x01) + (temp % 3)) & 0x01) == 0;
183 | }
184 | }
185 | function DataMask111()
186 | {
187 | this.unmaskBitMatrix=function(bits, dimension)
188 | {
189 | for (var i = 0; i < dimension; i++)
190 | {
191 | for (var j = 0; j < dimension; j++)
192 | {
193 | if (this.isMasked(i, j))
194 | {
195 | bits.flip(j, i);
196 | }
197 | }
198 | }
199 | }
200 | this.isMasked=function( i, j)
201 | {
202 | return ((((i + j) & 0x01) + ((i * j) % 3)) & 0x01) == 0;
203 | }
204 | }
205 |
206 | DataMask.DATA_MASKS = new Array(new DataMask000(), new DataMask001(), new DataMask010(), new DataMask011(), new DataMask100(), new DataMask101(), new DataMask110(), new DataMask111());
207 |
208 |
--------------------------------------------------------------------------------
/js/jsqrcode/grid.js:
--------------------------------------------------------------------------------
1 | /*
2 | Ported to JavaScript by Lazar Laszlo 2011
3 |
4 | lazarsoft@gmail.com, www.lazarsoft.info
5 |
6 | */
7 |
8 | /*
9 | *
10 | * Copyright 2007 ZXing authors
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License");
13 | * you may not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS,
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 |
26 | GridSampler = {};
27 |
28 | GridSampler.checkAndNudgePoints=function( image, points)
29 | {
30 | var width = qrcode.width;
31 | var height = qrcode.height;
32 | // Check and nudge points from start until we see some that are OK:
33 | var nudged = true;
34 | for (var offset = 0; offset < points.length && nudged; offset += 2)
35 | {
36 | var x = Math.floor (points[offset]);
37 | var y = Math.floor( points[offset + 1]);
38 | if (x < - 1 || x > width || y < - 1 || y > height)
39 | {
40 | throw "Error.checkAndNudgePoints ";
41 | }
42 | nudged = false;
43 | if (x == - 1)
44 | {
45 | points[offset] = 0.0;
46 | nudged = true;
47 | }
48 | else if (x == width)
49 | {
50 | points[offset] = width - 1;
51 | nudged = true;
52 | }
53 | if (y == - 1)
54 | {
55 | points[offset + 1] = 0.0;
56 | nudged = true;
57 | }
58 | else if (y == height)
59 | {
60 | points[offset + 1] = height - 1;
61 | nudged = true;
62 | }
63 | }
64 | // Check and nudge points from end:
65 | nudged = true;
66 | for (var offset = points.length - 2; offset >= 0 && nudged; offset -= 2)
67 | {
68 | var x = Math.floor( points[offset]);
69 | var y = Math.floor( points[offset + 1]);
70 | if (x < - 1 || x > width || y < - 1 || y > height)
71 | {
72 | throw "Error.checkAndNudgePoints ";
73 | }
74 | nudged = false;
75 | if (x == - 1)
76 | {
77 | points[offset] = 0.0;
78 | nudged = true;
79 | }
80 | else if (x == width)
81 | {
82 | points[offset] = width - 1;
83 | nudged = true;
84 | }
85 | if (y == - 1)
86 | {
87 | points[offset + 1] = 0.0;
88 | nudged = true;
89 | }
90 | else if (y == height)
91 | {
92 | points[offset + 1] = height - 1;
93 | nudged = true;
94 | }
95 | }
96 | }
97 |
98 |
99 |
100 | GridSampler.sampleGrid3=function( image, dimension, transform)
101 | {
102 | var bits = new BitMatrix(dimension);
103 | var points = new Array(dimension << 1);
104 | for (var y = 0; y < dimension; y++)
105 | {
106 | var max = points.length;
107 | var iValue = y + 0.5;
108 | for (var x = 0; x < max; x += 2)
109 | {
110 | points[x] = (x >> 1) + 0.5;
111 | points[x + 1] = iValue;
112 | }
113 | transform.transformPoints1(points);
114 | // Quick check to see if points transformed to something inside the image;
115 | // sufficient to check the endpoints
116 | GridSampler.checkAndNudgePoints(image, points);
117 | try
118 | {
119 | for (var x = 0; x < max; x += 2)
120 | {
121 | var xpoint = (Math.floor( points[x]) * 4) + (Math.floor( points[x + 1]) * qrcode.width * 4);
122 | var bit = image[Math.floor( points[x])+ qrcode.width* Math.floor( points[x + 1])];
123 | qrcode.imagedata.data[xpoint] = bit?255:0;
124 | qrcode.imagedata.data[xpoint+1] = bit?255:0;
125 | qrcode.imagedata.data[xpoint+2] = 0;
126 | qrcode.imagedata.data[xpoint+3] = 255;
127 | //bits[x >> 1][ y]=bit;
128 | if(bit)
129 | bits.set_Renamed(x >> 1, y);
130 | }
131 | }
132 | catch ( aioobe)
133 | {
134 | // This feels wrong, but, sometimes if the finder patterns are misidentified, the resulting
135 | // transform gets "twisted" such that it maps a straight line of points to a set of points
136 | // whose endpoints are in bounds, but others are not. There is probably some mathematical
137 | // way to detect this about the transformation that I don't know yet.
138 | // This results in an ugly runtime exception despite our clever checks above -- can't have
139 | // that. We could check each point's coordinates but that feels duplicative. We settle for
140 | // catching and wrapping ArrayIndexOutOfBoundsException.
141 | throw "Error.checkAndNudgePoints";
142 | }
143 | }
144 | return bits;
145 | }
146 |
147 | GridSampler.sampleGridx=function( image, dimension, p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY)
148 | {
149 | var transform = PerspectiveTransform.quadrilateralToQuadrilateral(p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY);
150 |
151 | return GridSampler.sampleGrid3(image, dimension, transform);
152 | }
153 |
--------------------------------------------------------------------------------
/style/qr_helper.css:
--------------------------------------------------------------------------------
1 | *{ margin:0; padding:0;}
2 | body{ background:#FFF; font:14px/1.5 '\5FAE\8F6F\96C5\9ED1',Arial,HELVETICA;}
3 |
4 | /* popup */
5 | .popup{ background-repeat:no-repeat; background-position:50% 50%; padding:5px;}
6 | .popup .qr_panel,
7 | .popup .icon{ visibility: hidden; opacity: 0; transition: all linear .2s .24s;}
8 | .popup .qr_panel{ background: #FFF; height: 200px; width: 200px;}
9 | .popup .qr_panel.active,
10 | .popup .qr_panel.active + .icon{ visibility: visible; opacity: 1;}
11 | .popup .icon{ display: none; background:#FFF url(../images/place.png) no-repeat; background-size:contain; border-radius:5px; margin:-12px 0 0 -12px; height:24px; width:24px; position:absolute; left:50%; top:50%; opacity:.96; pointer-events:none;}
12 |
13 | /* options_page */
14 | .options_page{ background:#F0F0F0;}
15 | .options_page h2{ font-size:30px; font-weight:normal;}
16 | .options_page h3{ font-size:16px; font-weight:normal;}
17 | .options_page a{ color:#333;}
18 | .options_page a:hover{ color:#F3BC00;}
19 | .options_page header{ margin-bottom:10px; padding:24px 0; text-align:center;}
20 | .options_page .content{ background:#FFF; border:1px solid #DDD; border-radius:5px; margin:0 auto; padding:30px 45px; width:680px;}
21 | .options_page .content h2{ margin-bottom:15px;}
22 | .options_page .content h3{ color:#666;}
23 | .options_page .option{ border-top:1px solid #DDD; padding:15px 0;}
24 | .options_page .option::after{ clear:both; display:block; content:''; height:0;}
25 | .options_page .option .main{ float:left;}
26 | .options_page .option ul{ list-style:none;}
27 | .options_page .option li{ padding-bottom:5px; vertical-align:top;}
28 | .options_page .option input[type=checkbox], .options_page .option input[type=radio]{ margin:-2px 5px 0 0; height:13px; width:13px; vertical-align:middle;}
29 | .options_page .option h3{ float:left; width:30%;}
30 | .options_page footer{ color:#999; font-size:12px; padding:20px 0; text-align:center;}
31 |
32 | /* bgs */
33 | .popup{ background-image:url(data:image/gif;base64,R0lGODlhHwAfAPUAAP///zMzM+zs7Nra2snJyb6+vrS0tOLi4sbGxq6urunp6d/f37q6urKysr+/v9bW1vf397m5udzc3Orq6l5eXlFRUXJycs/Pz4yMjKenp3d3d/r6+oaGhmpqatHR0fn5+WxsbFpaWgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH+GkNyZWF0ZWQgd2l0aCBhamF4bG9hZC5pbmZvACH5BAAKAAAAIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAHwAfAAAG/0CAcEgUDAgFA4BiwSQexKh0eEAkrldAZbvlOD5TqYKALWu5XIwnPFwwymY0GsRgAxrwuJwbCi8aAHlYZ3sVdwtRCm8JgVgODwoQAAIXGRpojQwKRGSDCRESYRsGHYZlBFR5AJt2a3kHQlZlERN2QxMRcAiTeaG2QxJ5RnAOv1EOcEdwUMZDD3BIcKzNq3BJcJLUABBwStrNBtjf3GUGBdLfCtadWMzUz6cDxN/IZQMCvdTBcAIAsli0jOHSJeSAqmlhNr0awo7RJ19TJORqdAXVEEVZyjyKtE3Bg3oZE2iK8oeiKkFZGiCaggelSTiA2LhxiZLBSjZjBL2siNBOFQ84LxHA+mYEiRJzBO7ZCQIAIfkEAAoAAQAsAAAAAB8AHwAABv9AgHBIFAwIBQPAUCAMBMSodHhAJK5XAPaKOEynCsIWqx0nCIrvcMEwZ90JxkINaMATZXfju9jf82YAIQxRCm14Ww4PChAAEAoPDlsAFRUgHkRiZAkREmoSEXiVlRgfQgeBaXRpo6MOQlZbERN0Qx4drRUcAAJmnrVDBrkVDwNjr8BDGxq5Z2MPyUQZuRgFY6rRABe5FgZjjdm8uRTh2d5b4NkQY0zX5QpjTc/lD2NOx+WSW0++2RJmUGJhmZVsQqgtCE6lqpXGjBchmt50+hQKEAEiht5gUcTIESR9GhlgE9IH0BiTkxrMmWIHDkose9SwcQlHDsOIk9ygiVbl5JgMLuV4HUmypMkTOkEAACH5BAAKAAIALAAAAAAfAB8AAAb/QIBwSBQMCAUDwFAgDATEqHR4QCSuVwD2ijhMpwrCFqsdJwiK73DBMGfdCcZCDWjAE2V347vY3/NmdXNECm14Ww4PChAAEAoPDltlDGlDYmQJERJqEhGHWARUgZVqaWZeAFZbERN0QxOeWwgAAmabrkMSZkZjDrhRkVtHYw+/RA9jSGOkxgpjSWOMxkIQY0rT0wbR2LQV3t4UBcvcF9/eFpdYxdgZ5hUYA73YGxruCbVjt78G7hXFqlhY/fLQwR0HIQdGuUrTz5eQdIc0cfIEwByGD0MKvcGSaFGjR8GyeAPhIUofQGNQSgrB4IsdOCqx7FHDBiYcOQshYjKDxliVDpRjunCjdSTJkiZP6AQBACH5BAAKAAMALAAAAAAfAB8AAAb/QIBwSBQMCAUDwFAgDATEqHR4QCSuVwD2ijhMpwrCFqsdJwiK73DBMGfdCcZCDWjAE2V347vY3/NmdXNECm14Ww4PChAAEAoPDltlDGlDYmQJERJqEhGHWARUgZVqaWZeAFZbERN0QxOeWwgAAmabrkMSZkZjDrhRkVtHYw+/RA9jSGOkxgpjSWOMxkIQY0rT0wbR2I3WBcvczltNxNzIW0693MFYT7bTumNQqlisv7BjswAHo64egFdQAbj0RtOXDQY6VAAUakihN1gSLaJ1IYOGChgXXqEUpQ9ASRlDYhT0xQ4cACJDhqDD5mRKjCAYuArjBmVKDP9+VRljMyMHDwcfuBlBooSCBQwJiqkJAgAh+QQACgAEACwAAAAAHwAfAAAG/0CAcEgUDAgFA8BQIAwExKh0eEAkrlcA9oo4TKcKwharHScIiu9wwTBn3QnGQg1owBNld+O72N/zZnVzRApteFsODwoQABAKDw5bZQxpQ2JkCRESahIRh1gEVIGVamlmXgBWWxETdEMTnlsIAAJmm65DEmZGYw64UZFbR2MPv0QPY0hjpMYKY0ljjMZCEGNK09MG0diN1gXL3M5bTcTcyFtOvdzBWE+207pjUKpYrL+wY7MAB4EerqZjUAG4lKVCBwMbvnT6dCXUkEIFK0jUkOECFEeQJF2hFKUPAIkgQwIaI+hLiJAoR27Zo4YBCJQgVW4cpMYDBpgVZKL59cEBhw+U+QROQ4bBAoUlTZ7QCQIAIfkEAAoABQAsAAAAAB8AHwAABv9AgHBIFAwIBQPAUCAMBMSodHhAJK5XAPaKOEynCsIWqx0nCIrvcMEwZ90JxkINaMATZXfju9jf82Z1c0QKbXhbDg8KEAAQCg8OW2UMaUNiZAkREmoSEYdYBFSBlWppZl4AVlsRE3RDE55bCAACZpuuQxJmRmMOuFGRW0djD79ED2NIY6TGCmNJY4zGQhBjStPTFBXb21DY1VsGFtzbF9gAzlsFGOQVGefIW2LtGhvYwVgDD+0V17+6Y6BwaNfBwy9YY2YBcMAPnStTY1B9YMdNiyZOngCFGuIBxDZAiRY1eoTvE6UoDEIAGrNSUoNBUuzAaYlljxo2M+HIeXiJpRsRNMaq+JSFCpsRJEqYOPH2JQgAIfkEAAoABgAsAAAAAB8AHwAABv9AgHBIFAwIBQPAUCAMBMSodHhAJK5XAPaKOEynCsIWqx0nCIrvcMEwZ90JxkINaMATZXfjywjlzX9jdXNEHiAVFX8ODwoQABAKDw5bZQxpQh8YiIhaERJqEhF4WwRDDpubAJdqaWZeAByoFR0edEMTolsIAA+yFUq2QxJmAgmyGhvBRJNbA5qoGcpED2MEFrIX0kMKYwUUslDaj2PA4soGY47iEOQFY6vS3FtNYw/m1KQDYw7mzFhPZj5JGzYGipUtESYowzVmF4ADgOCBCZTgFQAxZBJ4AiXqT6ltbUZhWdToUSR/Ii1FWbDnDkUyDQhJsQPn5ZU9atjUhCPHVhgTNy/RSKsiqKFFbUaQKGHiJNyXIAAh+QQACgAHACwAAAAAHwAfAAAG/0CAcEh8JDAWCsBQIAwExKhU+HFwKlgsIMHlIg7TqQeTLW+7XYIiPGSAymY0mrFgA0LwuLzbCC/6eVlnewkADXVECgxcAGUaGRdQEAoPDmhnDGtDBJcVHQYbYRIRhWgEQwd7AB52AGt7YAAIchETrUITpGgIAAJ7ErdDEnsCA3IOwUSWaAOcaA/JQ0amBXKa0QpyBQZyENFCEHIG39HcaN7f4WhM1uTZaE1y0N/TacZoyN/LXU+/0cNyoMxCUytYLjm8AKSS46rVKzmxADhjlCACMFGkBiU4NUQRxS4OHijwNqnSJS6ZovzRyJAQo0NhGrgs5bIPmwWLCLHsQsfhxBWTe9QkOzCwC8sv5Ho127akyRM7QQAAOwAAAAAAAAAAAA==);}
--------------------------------------------------------------------------------
/js/background.js:
--------------------------------------------------------------------------------
1 | /**
2 | * 根据图片解析 二维码
3 | * @author admin@laoshu133.com
4 | * @date 2015.03.20
5 | *
6 | * @dep https://github.com/LazarSoft/jsqrcode
7 | */
8 |
9 | ;(function(){
10 | QRHelper.on('config', function(){
11 | updateConfig();
12 | });
13 | updateConfig();
14 |
15 | function updateConfig(configs){
16 | var configs = QRHelper.getConfig();
17 |
18 | removeContextMenu();
19 | if(configs['qr_read_enabled']){
20 | addContextMenu();
21 | }
22 | }
23 |
24 | function addContextMenu(){
25 | chrome.contextMenus.create({
26 | type: 'normal',
27 | contexts: ['image'],
28 | title: QRHelper.getLang('read_qr_title'),
29 | onclick: function(info, tab){
30 | showLoading();
31 |
32 | qrcode.decode(info.srcUrl, function(text, data){
33 | setClipboard(text);
34 | hideLoading();
35 |
36 | var rurl = /^(?:https?|ftp|file|chrome):\/\/\w+/i;
37 | if(rurl.test(text)){
38 | chrome.tabs.create({ url:text });
39 | }
40 | else{
41 | alert(QRHelper.getLang('read_qr_txt_tips') +'\n\n' + text + '');
42 | }
43 | }, function(code, msg){
44 | hideLoading();
45 | alert(msg);
46 | });
47 | }
48 | });
49 | }
50 |
51 | function removeContextMenu(){
52 | chrome.contextMenus.removeAll();
53 | }
54 |
55 | function setClipboard(text){
56 | var inpId = 'qr_helper_copy_inp', inp = document.getElementById(inpId);
57 | if(!inp){
58 | inp = document.createElement('input');
59 | inp.id = inpId;
60 | document.body.appendChild(inp);
61 | }
62 | inp.value = text;
63 | inp.select();
64 |
65 | document.execCommand('copy', false, null);
66 | }
67 |
68 | function showLoading(){
69 | var count = 4, currInx = showLoading.currInx || 0;
70 | var txt = new Array(currInx+1).join('.') + new Array(count-currInx+1).join(' ');
71 | chrome.browserAction.setBadgeText({ text:txt });
72 |
73 | showLoading.timer = setTimeout(showLoading, 400);
74 | showLoading.currInx = ++currInx % count;
75 | }
76 |
77 | function hideLoading(){
78 | clearTimeout(showLoading.timer);
79 | chrome.browserAction.setBadgeText({ text:'' });
80 | }
81 | })();
82 |
83 |
84 |
85 | /**
86 | * qrcode, online
87 | *
88 | * @deprecated http://tool.oschina.net/action/qrcode/decode
89 | *
90 | */
91 | ;(function(){
92 | var qrcode = window.qrcode;
93 |
94 | var _decode = qrcode.decode;
95 | qrcode.decode = function(url, onsuccess, onerror) {
96 | qrcode.callback = function(msg) {
97 | var errMsg = '';
98 | var hasErr = false;
99 |
100 | if(msg && msg.indexOf('error decoding') > -1) {
101 | hasErr = true;
102 | errMsg = msg;
103 | }
104 |
105 | if(hasErr) {
106 | onerror && onerror(3, QRHelper.getLang('read_qr_error_2') + '\n' + errMsg);
107 | return;
108 | }
109 |
110 | if(onsuccess) {
111 | onsuccess(msg);
112 | }
113 | };
114 |
115 | _decode.call(qrcode, url);
116 | };
117 |
118 | // // deprecated
119 | // // http://tool.oschina.net/action/qrcode/decode
120 | // var qrcode = {
121 | // decodeUrl: 'http://tool.oschina.net/action/qrcode/decode',
122 | // decode: function(url, success, error){
123 | // var self = this;
124 | // this.loadImageByXHR(url, function(blob, xhr){
125 | // self.decodeByFile(blob, success, error);
126 | // }, function(){
127 | // self.throwError(1, error);
128 | // });
129 | // },
130 | // decodeByFile: function(blob, success, error){
131 | // var
132 | // self = this,
133 | // formData = new FormData(),
134 | // xhr = new XMLHttpRequest();
135 |
136 | // xhr.onload = function(){
137 | // var data;
138 | // try{
139 | // data = JSON.parse(xhr.responseText);
140 | // }
141 | // catch(_){
142 | // self.throwError(2, error);
143 | // return;
144 | // }
145 |
146 | // if(data && data[0] && data[0].text){
147 | // success && success(data[0].text, data[0]);
148 | // }
149 | // else{
150 | // self.throwError(3, error);
151 | // }
152 | // };
153 | // xhr.onerror = function(){
154 | // self.throwError(2, error);
155 | // };
156 |
157 | // formData.append('qrcode', blob);
158 | // xhr.open('POST', this.decodeUrl, true);
159 | // xhr.send(formData);
160 | // },
161 | // loadImageByXHR: function(url, success, error){
162 | // var xhr = new XMLHttpRequest();
163 | // xhr.responseType = 'blob';
164 | // xhr.onload = function(){
165 | // success && success(xhr.response, xhr);
166 | // };
167 | // xhr.onerror = function(){
168 | // error && error(xhr);
169 | // };
170 | // xhr.open('GET', url, true);
171 | // xhr.send(null);
172 | // },
173 | // loadImage: function(url, success, error){
174 | // console.log(url);
175 | // var img = new Image();
176 | // img.onload = function(){
177 | // img.onload = img.onerror = null;
178 |
179 | // success && success(img.url, img);
180 | // };
181 | // img.onerror = function(){
182 | // img.onload = img.onerror = null;
183 |
184 | // error && error();
185 | // }
186 | // img.src = url;
187 | // },
188 | // throwError: function(code, callback){
189 | // var errMsgs = [
190 | // QRHelper.getLang('read_qr_error_0'),
191 | // QRHelper.getLang('read_qr_error_1'),
192 | // QRHelper.getLang('read_qr_error_2')
193 | // ];
194 |
195 | // callback && callback(code, errMsgs[code - 1]);
196 | // }
197 | // };
198 |
199 | window.qrcode = qrcode;
200 | })();
--------------------------------------------------------------------------------
/js/jsqrcode/rsdecoder.js:
--------------------------------------------------------------------------------
1 | /*
2 | Ported to JavaScript by Lazar Laszlo 2011
3 |
4 | lazarsoft@gmail.com, www.lazarsoft.info
5 |
6 | */
7 |
8 | /*
9 | *
10 | * Copyright 2007 ZXing authors
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License");
13 | * you may not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS,
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 |
26 | function ReedSolomonDecoder(field)
27 | {
28 | this.field = field;
29 | this.decode=function(received, twoS)
30 | {
31 | var poly = new GF256Poly(this.field, received);
32 | var syndromeCoefficients = new Array(twoS);
33 | for(var i=0;i= b's
70 | if (a.Degree < b.Degree)
71 | {
72 | var temp = a;
73 | a = b;
74 | b = temp;
75 | }
76 |
77 | var rLast = a;
78 | var r = b;
79 | var sLast = this.field.One;
80 | var s = this.field.Zero;
81 | var tLast = this.field.Zero;
82 | var t = this.field.One;
83 |
84 | // Run Euclidean algorithm until r's degree is less than R/2
85 | while (r.Degree >= Math.floor(R / 2))
86 | {
87 | var rLastLast = rLast;
88 | var sLastLast = sLast;
89 | var tLastLast = tLast;
90 | rLast = r;
91 | sLast = s;
92 | tLast = t;
93 |
94 | // Divide rLastLast by rLast, with quotient in q and remainder in r
95 | if (rLast.Zero)
96 | {
97 | // Oops, Euclidean algorithm already terminated?
98 | throw "r_{i-1} was zero";
99 | }
100 | r = rLastLast;
101 | var q = this.field.Zero;
102 | var denominatorLeadingTerm = rLast.getCoefficient(rLast.Degree);
103 | var dltInverse = this.field.inverse(denominatorLeadingTerm);
104 | while (r.Degree >= rLast.Degree && !r.Zero)
105 | {
106 | var degreeDiff = r.Degree - rLast.Degree;
107 | var scale = this.field.multiply(r.getCoefficient(r.Degree), dltInverse);
108 | q = q.addOrSubtract(this.field.buildMonomial(degreeDiff, scale));
109 | r = r.addOrSubtract(rLast.multiplyByMonomial(degreeDiff, scale));
110 | //r.EXE();
111 | }
112 |
113 | s = q.multiply1(sLast).addOrSubtract(sLastLast);
114 | t = q.multiply1(tLast).addOrSubtract(tLastLast);
115 | }
116 |
117 | var sigmaTildeAtZero = t.getCoefficient(0);
118 | if (sigmaTildeAtZero == 0)
119 | {
120 | throw "ReedSolomonException sigmaTilde(0) was zero";
121 | }
122 |
123 | var inverse = this.field.inverse(sigmaTildeAtZero);
124 | var sigma = t.multiply2(inverse);
125 | var omega = r.multiply2(inverse);
126 | return new Array(sigma, omega);
127 | }
128 | this.findErrorLocations=function( errorLocator)
129 | {
130 | // This is a direct application of Chien's search
131 | var numErrors = errorLocator.Degree;
132 | if (numErrors == 1)
133 | {
134 | // shortcut
135 | return new Array(errorLocator.getCoefficient(1));
136 | }
137 | var result = new Array(numErrors);
138 | var e = 0;
139 | for (var i = 1; i < 256 && e < numErrors; i++)
140 | {
141 | if (errorLocator.evaluateAt(i) == 0)
142 | {
143 | result[e] = this.field.inverse(i);
144 | e++;
145 | }
146 | }
147 | if (e != numErrors)
148 | {
149 | throw "Error locator degree does not match number of roots";
150 | }
151 | return result;
152 | }
153 | this.findErrorMagnitudes=function( errorEvaluator, errorLocations, dataMatrix)
154 | {
155 | // This is directly applying Forney's Formula
156 | var s = errorLocations.length;
157 | var result = new Array(s);
158 | for (var i = 0; i < s; i++)
159 | {
160 | var xiInverse = this.field.inverse(errorLocations[i]);
161 | var denominator = 1;
162 | for (var j = 0; j < s; j++)
163 | {
164 | if (i != j)
165 | {
166 | denominator = this.field.multiply(denominator, GF256.addOrSubtract(1, this.field.multiply(errorLocations[j], xiInverse)));
167 | }
168 | }
169 | result[i] = this.field.multiply(errorEvaluator.evaluateAt(xiInverse), this.field.inverse(denominator));
170 | // Thanks to sanfordsquires for this fix:
171 | if (dataMatrix)
172 | {
173 | result[i] = this.field.multiply(result[i], xiInverse);
174 | }
175 | }
176 | return result;
177 | }
178 | }
--------------------------------------------------------------------------------
/js/jsqrcode/bmparser.js:
--------------------------------------------------------------------------------
1 | /*
2 | Ported to JavaScript by Lazar Laszlo 2011
3 |
4 | lazarsoft@gmail.com, www.lazarsoft.info
5 |
6 | */
7 |
8 | /*
9 | *
10 | * Copyright 2007 ZXing authors
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License");
13 | * you may not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS,
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 |
26 | function BitMatrixParser(bitMatrix)
27 | {
28 | var dimension = bitMatrix.Dimension;
29 | if (dimension < 21 || (dimension & 0x03) != 1)
30 | {
31 | throw "Error BitMatrixParser";
32 | }
33 | this.bitMatrix = bitMatrix;
34 | this.parsedVersion = null;
35 | this.parsedFormatInfo = null;
36 |
37 | this.copyBit=function( i, j, versionBits)
38 | {
39 | return this.bitMatrix.get_Renamed(i, j)?(versionBits << 1) | 0x1:versionBits << 1;
40 | }
41 |
42 | this.readFormatInformation=function()
43 | {
44 | if (this.parsedFormatInfo != null)
45 | {
46 | return this.parsedFormatInfo;
47 | }
48 |
49 | // Read top-left format info bits
50 | var formatInfoBits = 0;
51 | for (var i = 0; i < 6; i++)
52 | {
53 | formatInfoBits = this.copyBit(i, 8, formatInfoBits);
54 | }
55 | // .. and skip a bit in the timing pattern ...
56 | formatInfoBits = this.copyBit(7, 8, formatInfoBits);
57 | formatInfoBits = this.copyBit(8, 8, formatInfoBits);
58 | formatInfoBits = this.copyBit(8, 7, formatInfoBits);
59 | // .. and skip a bit in the timing pattern ...
60 | for (var j = 5; j >= 0; j--)
61 | {
62 | formatInfoBits = this.copyBit(8, j, formatInfoBits);
63 | }
64 |
65 | this.parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits);
66 | if (this.parsedFormatInfo != null)
67 | {
68 | return this.parsedFormatInfo;
69 | }
70 |
71 | // Hmm, failed. Try the top-right/bottom-left pattern
72 | var dimension = this.bitMatrix.Dimension;
73 | formatInfoBits = 0;
74 | var iMin = dimension - 8;
75 | for (var i = dimension - 1; i >= iMin; i--)
76 | {
77 | formatInfoBits = this.copyBit(i, 8, formatInfoBits);
78 | }
79 | for (var j = dimension - 7; j < dimension; j++)
80 | {
81 | formatInfoBits = this.copyBit(8, j, formatInfoBits);
82 | }
83 |
84 | this.parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits);
85 | if (this.parsedFormatInfo != null)
86 | {
87 | return this.parsedFormatInfo;
88 | }
89 | throw "Error readFormatInformation";
90 | }
91 | this.readVersion=function()
92 | {
93 |
94 | if (this.parsedVersion != null)
95 | {
96 | return this.parsedVersion;
97 | }
98 |
99 | var dimension = this.bitMatrix.Dimension;
100 |
101 | var provisionalVersion = (dimension - 17) >> 2;
102 | if (provisionalVersion <= 6)
103 | {
104 | return Version.getVersionForNumber(provisionalVersion);
105 | }
106 |
107 | // Read top-right version info: 3 wide by 6 tall
108 | var versionBits = 0;
109 | var ijMin = dimension - 11;
110 | for (var j = 5; j >= 0; j--)
111 | {
112 | for (var i = dimension - 9; i >= ijMin; i--)
113 | {
114 | versionBits = this.copyBit(i, j, versionBits);
115 | }
116 | }
117 |
118 | this.parsedVersion = Version.decodeVersionInformation(versionBits);
119 | if (this.parsedVersion != null && this.parsedVersion.DimensionForVersion == dimension)
120 | {
121 | return this.parsedVersion;
122 | }
123 |
124 | // Hmm, failed. Try bottom left: 6 wide by 3 tall
125 | versionBits = 0;
126 | for (var i = 5; i >= 0; i--)
127 | {
128 | for (var j = dimension - 9; j >= ijMin; j--)
129 | {
130 | versionBits = this.copyBit(i, j, versionBits);
131 | }
132 | }
133 |
134 | this.parsedVersion = Version.decodeVersionInformation(versionBits);
135 | if (this.parsedVersion != null && this.parsedVersion.DimensionForVersion == dimension)
136 | {
137 | return this.parsedVersion;
138 | }
139 | throw "Error readVersion";
140 | }
141 | this.readCodewords=function()
142 | {
143 |
144 | var formatInfo = this.readFormatInformation();
145 | var version = this.readVersion();
146 |
147 | // Get the data mask for the format used in this QR Code. This will exclude
148 | // some bits from reading as we wind through the bit matrix.
149 | var dataMask = DataMask.forReference( formatInfo.DataMask);
150 | var dimension = this.bitMatrix.Dimension;
151 | dataMask.unmaskBitMatrix(this.bitMatrix, dimension);
152 |
153 | var functionPattern = version.buildFunctionPattern();
154 |
155 | var readingUp = true;
156 | var result = new Array(version.TotalCodewords);
157 | var resultOffset = 0;
158 | var currentByte = 0;
159 | var bitsRead = 0;
160 | // Read columns in pairs, from right to left
161 | for (var j = dimension - 1; j > 0; j -= 2)
162 | {
163 | if (j == 6)
164 | {
165 | // Skip whole column with vertical alignment pattern;
166 | // saves time and makes the other code proceed more cleanly
167 | j--;
168 | }
169 | // Read alternatingly from bottom to top then top to bottom
170 | for (var count = 0; count < dimension; count++)
171 | {
172 | var i = readingUp?dimension - 1 - count:count;
173 | for (var col = 0; col < 2; col++)
174 | {
175 | // Ignore bits covered by the function pattern
176 | if (!functionPattern.get_Renamed(j - col, i))
177 | {
178 | // Read a bit
179 | bitsRead++;
180 | currentByte <<= 1;
181 | if (this.bitMatrix.get_Renamed(j - col, i))
182 | {
183 | currentByte |= 1;
184 | }
185 | // If we've made a whole byte, save it off
186 | if (bitsRead == 8)
187 | {
188 | result[resultOffset++] = currentByte;
189 | bitsRead = 0;
190 | currentByte = 0;
191 | }
192 | }
193 | }
194 | }
195 | readingUp ^= true; // readingUp = !readingUp; // switch directions
196 | }
197 | if (resultOffset != version.TotalCodewords)
198 | {
199 | throw "Error readCodewords";
200 | }
201 | return result;
202 | }
203 | }
--------------------------------------------------------------------------------
/js/jsqrcode/gf256poly.js:
--------------------------------------------------------------------------------
1 | /*
2 | Ported to JavaScript by Lazar Laszlo 2011
3 |
4 | lazarsoft@gmail.com, www.lazarsoft.info
5 |
6 | */
7 |
8 | /*
9 | *
10 | * Copyright 2007 ZXing authors
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License");
13 | * you may not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS,
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 |
26 | function GF256Poly(field, coefficients)
27 | {
28 | if (coefficients == null || coefficients.length == 0)
29 | {
30 | throw "System.ArgumentException";
31 | }
32 | this.field = field;
33 | var coefficientsLength = coefficients.length;
34 | if (coefficientsLength > 1 && coefficients[0] == 0)
35 | {
36 | // Leading term must be non-zero for anything except the constant polynomial "0"
37 | var firstNonZero = 1;
38 | while (firstNonZero < coefficientsLength && coefficients[firstNonZero] == 0)
39 | {
40 | firstNonZero++;
41 | }
42 | if (firstNonZero == coefficientsLength)
43 | {
44 | this.coefficients = field.Zero.coefficients;
45 | }
46 | else
47 | {
48 | this.coefficients = new Array(coefficientsLength - firstNonZero);
49 | for(var i=0;i largerCoefficients.length)
121 | {
122 | var temp = smallerCoefficients;
123 | smallerCoefficients = largerCoefficients;
124 | largerCoefficients = temp;
125 | }
126 | var sumDiff = new Array(largerCoefficients.length);
127 | var lengthDiff = largerCoefficients.length - smallerCoefficients.length;
128 | // Copy high-order terms only found in higher-degree polynomial's coefficients
129 | //Array.Copy(largerCoefficients, 0, sumDiff, 0, lengthDiff);
130 | for(var ci=0;ci= other.Degree && !remainder.Zero)
219 | {
220 | var degreeDifference = remainder.Degree - other.Degree;
221 | var scale = this.field.multiply(remainder.getCoefficient(remainder.Degree), inverseDenominatorLeadingTerm);
222 | var term = other.multiplyByMonomial(degreeDifference, scale);
223 | var iterationQuotient = this.field.buildMonomial(degreeDifference, scale);
224 | quotient = quotient.addOrSubtract(iterationQuotient);
225 | remainder = remainder.addOrSubtract(term);
226 | }
227 |
228 | return new Array(quotient, remainder);
229 | }
230 | }
--------------------------------------------------------------------------------
/js/jsqrcode/alignpat.js:
--------------------------------------------------------------------------------
1 | /*
2 | Ported to JavaScript by Lazar Laszlo 2011
3 |
4 | lazarsoft@gmail.com, www.lazarsoft.info
5 |
6 | */
7 |
8 | /*
9 | *
10 | * Copyright 2007 ZXing authors
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License");
13 | * you may not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS,
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 |
26 | function AlignmentPattern(posX, posY, estimatedModuleSize)
27 | {
28 | this.x=posX;
29 | this.y=posY;
30 | this.count = 1;
31 | this.estimatedModuleSize = estimatedModuleSize;
32 |
33 | this.__defineGetter__("EstimatedModuleSize", function()
34 | {
35 | return this.estimatedModuleSize;
36 | });
37 | this.__defineGetter__("Count", function()
38 | {
39 | return this.count;
40 | });
41 | this.__defineGetter__("X", function()
42 | {
43 | return Math.floor(this.x);
44 | });
45 | this.__defineGetter__("Y", function()
46 | {
47 | return Math.floor(this.y);
48 | });
49 | this.incrementCount = function()
50 | {
51 | this.count++;
52 | }
53 | this.aboutEquals=function( moduleSize, i, j)
54 | {
55 | if (Math.abs(i - this.y) <= moduleSize && Math.abs(j - this.x) <= moduleSize)
56 | {
57 | var moduleSizeDiff = Math.abs(moduleSize - this.estimatedModuleSize);
58 | return moduleSizeDiff <= 1.0 || moduleSizeDiff / this.estimatedModuleSize <= 1.0;
59 | }
60 | return false;
61 | }
62 |
63 | }
64 |
65 | function AlignmentPatternFinder( image, startX, startY, width, height, moduleSize, resultPointCallback)
66 | {
67 | this.image = image;
68 | this.possibleCenters = new Array();
69 | this.startX = startX;
70 | this.startY = startY;
71 | this.width = width;
72 | this.height = height;
73 | this.moduleSize = moduleSize;
74 | this.crossCheckStateCount = new Array(0,0,0);
75 | this.resultPointCallback = resultPointCallback;
76 |
77 | this.centerFromEnd=function(stateCount, end)
78 | {
79 | return (end - stateCount[2]) - stateCount[1] / 2.0;
80 | }
81 | this.foundPatternCross = function(stateCount)
82 | {
83 | var moduleSize = this.moduleSize;
84 | var maxVariance = moduleSize / 2.0;
85 | for (var i = 0; i < 3; i++)
86 | {
87 | if (Math.abs(moduleSize - stateCount[i]) >= maxVariance)
88 | {
89 | return false;
90 | }
91 | }
92 | return true;
93 | }
94 |
95 | this.crossCheckVertical=function( startI, centerJ, maxCount, originalStateCountTotal)
96 | {
97 | var image = this.image;
98 |
99 | var maxI = qrcode.height;
100 | var stateCount = this.crossCheckStateCount;
101 | stateCount[0] = 0;
102 | stateCount[1] = 0;
103 | stateCount[2] = 0;
104 |
105 | // Start counting up from center
106 | var i = startI;
107 | while (i >= 0 && image[centerJ + i*qrcode.width] && stateCount[1] <= maxCount)
108 | {
109 | stateCount[1]++;
110 | i--;
111 | }
112 | // If already too many modules in this state or ran off the edge:
113 | if (i < 0 || stateCount[1] > maxCount)
114 | {
115 | return NaN;
116 | }
117 | while (i >= 0 && !image[centerJ + i*qrcode.width] && stateCount[0] <= maxCount)
118 | {
119 | stateCount[0]++;
120 | i--;
121 | }
122 | if (stateCount[0] > maxCount)
123 | {
124 | return NaN;
125 | }
126 |
127 | // Now also count down from center
128 | i = startI + 1;
129 | while (i < maxI && image[centerJ + i*qrcode.width] && stateCount[1] <= maxCount)
130 | {
131 | stateCount[1]++;
132 | i++;
133 | }
134 | if (i == maxI || stateCount[1] > maxCount)
135 | {
136 | return NaN;
137 | }
138 | while (i < maxI && !image[centerJ + i*qrcode.width] && stateCount[2] <= maxCount)
139 | {
140 | stateCount[2]++;
141 | i++;
142 | }
143 | if (stateCount[2] > maxCount)
144 | {
145 | return NaN;
146 | }
147 |
148 | var stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];
149 | if (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal)
150 | {
151 | return NaN;
152 | }
153 |
154 | return this.foundPatternCross(stateCount)?this.centerFromEnd(stateCount, i):NaN;
155 | }
156 |
157 | this.handlePossibleCenter=function( stateCount, i, j)
158 | {
159 | var stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];
160 | var centerJ = this.centerFromEnd(stateCount, j);
161 | var centerI = this.crossCheckVertical(i, Math.floor (centerJ), 2 * stateCount[1], stateCountTotal);
162 | if (!isNaN(centerI))
163 | {
164 | var estimatedModuleSize = (stateCount[0] + stateCount[1] + stateCount[2]) / 3.0;
165 | var max = this.possibleCenters.length;
166 | for (var index = 0; index < max; index++)
167 | {
168 | var center = this.possibleCenters[index];
169 | // Look for about the same center and module size:
170 | if (center.aboutEquals(estimatedModuleSize, centerI, centerJ))
171 | {
172 | return new AlignmentPattern(centerJ, centerI, estimatedModuleSize);
173 | }
174 | }
175 | // Hadn't found this before; save it
176 | var point = new AlignmentPattern(centerJ, centerI, estimatedModuleSize);
177 | this.possibleCenters.push(point);
178 | if (this.resultPointCallback != null)
179 | {
180 | this.resultPointCallback.foundPossibleResultPoint(point);
181 | }
182 | }
183 | return null;
184 | }
185 |
186 | this.find = function()
187 | {
188 | var startX = this.startX;
189 | var height = this.height;
190 | var maxJ = startX + width;
191 | var middleI = startY + (height >> 1);
192 | // We are looking for black/white/black modules in 1:1:1 ratio;
193 | // this tracks the number of black/white/black modules seen so far
194 | var stateCount = new Array(0,0,0);
195 | for (var iGen = 0; iGen < height; iGen++)
196 | {
197 | // Search from middle outwards
198 | var i = middleI + ((iGen & 0x01) == 0?((iGen + 1) >> 1):- ((iGen + 1) >> 1));
199 | stateCount[0] = 0;
200 | stateCount[1] = 0;
201 | stateCount[2] = 0;
202 | var j = startX;
203 | // Burn off leading white pixels before anything else; if we start in the middle of
204 | // a white run, it doesn't make sense to count its length, since we don't know if the
205 | // white run continued to the left of the start point
206 | while (j < maxJ && !image[j + qrcode.width* i])
207 | {
208 | j++;
209 | }
210 | var currentState = 0;
211 | while (j < maxJ)
212 | {
213 | if (image[j + i*qrcode.width])
214 | {
215 | // Black pixel
216 | if (currentState == 1)
217 | {
218 | // Counting black pixels
219 | stateCount[currentState]++;
220 | }
221 | else
222 | {
223 | // Counting white pixels
224 | if (currentState == 2)
225 | {
226 | // A winner?
227 | if (this.foundPatternCross(stateCount))
228 | {
229 | // Yes
230 | var confirmed = this.handlePossibleCenter(stateCount, i, j);
231 | if (confirmed != null)
232 | {
233 | return confirmed;
234 | }
235 | }
236 | stateCount[0] = stateCount[2];
237 | stateCount[1] = 1;
238 | stateCount[2] = 0;
239 | currentState = 1;
240 | }
241 | else
242 | {
243 | stateCount[++currentState]++;
244 | }
245 | }
246 | }
247 | else
248 | {
249 | // White pixel
250 | if (currentState == 1)
251 | {
252 | // Counting black pixels
253 | currentState++;
254 | }
255 | stateCount[currentState]++;
256 | }
257 | j++;
258 | }
259 | if (this.foundPatternCross(stateCount))
260 | {
261 | var confirmed = this.handlePossibleCenter(stateCount, i, maxJ);
262 | if (confirmed != null)
263 | {
264 | return confirmed;
265 | }
266 | }
267 | }
268 |
269 | // Hmm, nothing we saw was observed and confirmed twice. If we had
270 | // any guess at all, return it.
271 | if (!(this.possibleCenters.length == 0))
272 | {
273 | return this.possibleCenters[0];
274 | }
275 |
276 | throw "Couldn't find enough alignment patterns";
277 | }
278 |
279 | }
--------------------------------------------------------------------------------
/js/jsqrcode/databr.js:
--------------------------------------------------------------------------------
1 | /*
2 | Ported to JavaScript by Lazar Laszlo 2011
3 |
4 | lazarsoft@gmail.com, www.lazarsoft.info
5 |
6 | */
7 |
8 | /*
9 | *
10 | * Copyright 2007 ZXing authors
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License");
13 | * you may not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS,
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 |
26 | function QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode)
27 | {
28 | this.blockPointer = 0;
29 | this.bitPointer = 7;
30 | this.dataLength = 0;
31 | this.blocks = blocks;
32 | this.numErrorCorrectionCode = numErrorCorrectionCode;
33 | if (version <= 9)
34 | this.dataLengthMode = 0;
35 | else if (version >= 10 && version <= 26)
36 | this.dataLengthMode = 1;
37 | else if (version >= 27 && version <= 40)
38 | this.dataLengthMode = 2;
39 |
40 | this.getNextBits = function( numBits)
41 | {
42 | var bits = 0;
43 | if (numBits < this.bitPointer + 1)
44 | {
45 | // next word fits into current data block
46 | var mask = 0;
47 | for (var i = 0; i < numBits; i++)
48 | {
49 | mask += (1 << i);
50 | }
51 | mask <<= (this.bitPointer - numBits + 1);
52 |
53 | bits = (this.blocks[this.blockPointer] & mask) >> (this.bitPointer - numBits + 1);
54 | this.bitPointer -= numBits;
55 | return bits;
56 | }
57 | else if (numBits < this.bitPointer + 1 + 8)
58 | {
59 | // next word crosses 2 data blocks
60 | var mask1 = 0;
61 | for (var i = 0; i < this.bitPointer + 1; i++)
62 | {
63 | mask1 += (1 << i);
64 | }
65 | bits = (this.blocks[this.blockPointer] & mask1) << (numBits - (this.bitPointer + 1));
66 | this.blockPointer++;
67 | bits += ((this.blocks[this.blockPointer]) >> (8 - (numBits - (this.bitPointer + 1))));
68 |
69 | this.bitPointer = this.bitPointer - numBits % 8;
70 | if (this.bitPointer < 0)
71 | {
72 | this.bitPointer = 8 + this.bitPointer;
73 | }
74 | return bits;
75 | }
76 | else if (numBits < this.bitPointer + 1 + 16)
77 | {
78 | // next word crosses 3 data blocks
79 | var mask1 = 0; // mask of first block
80 | var mask3 = 0; // mask of 3rd block
81 | //bitPointer + 1 : number of bits of the 1st block
82 | //8 : number of the 2nd block (note that use already 8bits because next word uses 3 data blocks)
83 | //numBits - (bitPointer + 1 + 8) : number of bits of the 3rd block
84 | for (var i = 0; i < this.bitPointer + 1; i++)
85 | {
86 | mask1 += (1 << i);
87 | }
88 | var bitsFirstBlock = (this.blocks[this.blockPointer] & mask1) << (numBits - (this.bitPointer + 1));
89 | this.blockPointer++;
90 |
91 | var bitsSecondBlock = this.blocks[this.blockPointer] << (numBits - (this.bitPointer + 1 + 8));
92 | this.blockPointer++;
93 |
94 | for (var i = 0; i < numBits - (this.bitPointer + 1 + 8); i++)
95 | {
96 | mask3 += (1 << i);
97 | }
98 | mask3 <<= 8 - (numBits - (this.bitPointer + 1 + 8));
99 | var bitsThirdBlock = (this.blocks[this.blockPointer] & mask3) >> (8 - (numBits - (this.bitPointer + 1 + 8)));
100 |
101 | bits = bitsFirstBlock + bitsSecondBlock + bitsThirdBlock;
102 | this.bitPointer = this.bitPointer - (numBits - 8) % 8;
103 | if (this.bitPointer < 0)
104 | {
105 | this.bitPointer = 8 + this.bitPointer;
106 | }
107 | return bits;
108 | }
109 | else
110 | {
111 | return 0;
112 | }
113 | }
114 | this.NextMode=function()
115 | {
116 | if ((this.blockPointer > this.blocks.length - this.numErrorCorrectionCode - 2))
117 | return 0;
118 | else
119 | return this.getNextBits(4);
120 | }
121 | this.getDataLength=function( modeIndicator)
122 | {
123 | var index = 0;
124 | while (true)
125 | {
126 | if ((modeIndicator >> index) == 1)
127 | break;
128 | index++;
129 | }
130 |
131 | return this.getNextBits(qrcode.sizeOfDataLengthInfo[this.dataLengthMode][index]);
132 | }
133 | this.getRomanAndFigureString=function( dataLength)
134 | {
135 | var length = dataLength;
136 | var intData = 0;
137 | var strData = "";
138 | var tableRomanAndFigure = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '$', '%', '*', '+', '-', '.', '/', ':');
139 | do
140 | {
141 | if (length > 1)
142 | {
143 | intData = this.getNextBits(11);
144 | var firstLetter = Math.floor(intData / 45);
145 | var secondLetter = intData % 45;
146 | strData += tableRomanAndFigure[firstLetter];
147 | strData += tableRomanAndFigure[secondLetter];
148 | length -= 2;
149 | }
150 | else if (length == 1)
151 | {
152 | intData = this.getNextBits(6);
153 | strData += tableRomanAndFigure[intData];
154 | length -= 1;
155 | }
156 | }
157 | while (length > 0);
158 |
159 | return strData;
160 | }
161 | this.getFigureString=function( dataLength)
162 | {
163 | var length = dataLength;
164 | var intData = 0;
165 | var strData = "";
166 | do
167 | {
168 | if (length >= 3)
169 | {
170 | intData = this.getNextBits(10);
171 | if (intData < 100)
172 | strData += "0";
173 | if (intData < 10)
174 | strData += "0";
175 | length -= 3;
176 | }
177 | else if (length == 2)
178 | {
179 | intData = this.getNextBits(7);
180 | if (intData < 10)
181 | strData += "0";
182 | length -= 2;
183 | }
184 | else if (length == 1)
185 | {
186 | intData = this.getNextBits(4);
187 | length -= 1;
188 | }
189 | strData += intData;
190 | }
191 | while (length > 0);
192 |
193 | return strData;
194 | }
195 | this.get8bitByteArray=function( dataLength)
196 | {
197 | var length = dataLength;
198 | var intData = 0;
199 | var output = new Array();
200 |
201 | do
202 | {
203 | intData = this.getNextBits(8);
204 | output.push( intData);
205 | length--;
206 | }
207 | while (length > 0);
208 | return output;
209 | }
210 | this.getKanjiString=function( dataLength)
211 | {
212 | var length = dataLength;
213 | var intData = 0;
214 | var unicodeString = "";
215 | do
216 | {
217 | intData = getNextBits(13);
218 | var lowerByte = intData % 0xC0;
219 | var higherByte = intData / 0xC0;
220 |
221 | var tempWord = (higherByte << 8) + lowerByte;
222 | var shiftjisWord = 0;
223 | if (tempWord + 0x8140 <= 0x9FFC)
224 | {
225 | // between 8140 - 9FFC on Shift_JIS character set
226 | shiftjisWord = tempWord + 0x8140;
227 | }
228 | else
229 | {
230 | // between E040 - EBBF on Shift_JIS character set
231 | shiftjisWord = tempWord + 0xC140;
232 | }
233 |
234 | //var tempByte = new Array(0,0);
235 | //tempByte[0] = (sbyte) (shiftjisWord >> 8);
236 | //tempByte[1] = (sbyte) (shiftjisWord & 0xFF);
237 | //unicodeString += new String(SystemUtils.ToCharArray(SystemUtils.ToByteArray(tempByte)));
238 | unicodeString += String.fromCharCode(shiftjisWord);
239 | length--;
240 | }
241 | while (length > 0);
242 |
243 |
244 | return unicodeString;
245 | }
246 |
247 | this.__defineGetter__("DataByte", function()
248 | {
249 | var output = new Array();
250 | var MODE_NUMBER = 1;
251 | var MODE_ROMAN_AND_NUMBER = 2;
252 | var MODE_8BIT_BYTE = 4;
253 | var MODE_KANJI = 8;
254 | do
255 | {
256 | var mode = this.NextMode();
257 | //canvas.println("mode: " + mode);
258 | if (mode == 0)
259 | {
260 | if (output.length > 0)
261 | break;
262 | else
263 | throw "Empty data block";
264 | }
265 | //if (mode != 1 && mode != 2 && mode != 4 && mode != 8)
266 | // break;
267 | //}
268 | if (mode != MODE_NUMBER && mode != MODE_ROMAN_AND_NUMBER && mode != MODE_8BIT_BYTE && mode != MODE_KANJI)
269 | {
270 | /* canvas.println("Invalid mode: " + mode);
271 | mode = guessMode(mode);
272 | canvas.println("Guessed mode: " + mode); */
273 | throw "Invalid mode: " + mode + " in (block:" + this.blockPointer + " bit:" + this.bitPointer + ")";
274 | }
275 | dataLength = this.getDataLength(mode);
276 | if (dataLength < 1)
277 | throw "Invalid data length: " + dataLength;
278 | //canvas.println("length: " + dataLength);
279 | switch (mode)
280 | {
281 |
282 | case MODE_NUMBER:
283 | //canvas.println("Mode: Figure");
284 | var temp_str = this.getFigureString(dataLength);
285 | var ta = new Array(temp_str.length);
286 | for(var j=0;jqrcode.maxImgSize)
55 | {
56 | var ir = image.width / image.height;
57 | nheight = Math.sqrt(qrcode.maxImgSize/ir);
58 | nwidth=ir*nheight;
59 | }
60 |
61 | canvas_qr.width = nwidth;
62 | canvas_qr.height = nheight;
63 |
64 | context.drawImage(image, 0, 0, canvas_qr.width, canvas_qr.height );
65 | qrcode.width = canvas_qr.width;
66 | qrcode.height = canvas_qr.height;
67 | try{
68 | qrcode.imagedata = context.getImageData(0, 0, canvas_qr.width, canvas_qr.height);
69 | }catch(e){
70 | qrcode.result = "Cross domain image reading not supported in your browser! Save it to your computer then drag and drop the file!";
71 | if(qrcode.callback!=null)
72 | qrcode.callback(qrcode.result);
73 | return;
74 | }
75 |
76 | try
77 | {
78 | qrcode.result = qrcode.process(context);
79 | }
80 | catch(e)
81 | {
82 | console.log(e);
83 | qrcode.result = "error decoding QR Code";
84 | }
85 | if(qrcode.callback!=null)
86 | qrcode.callback(qrcode.result);
87 | }
88 | image.src = src;
89 | }
90 | }
91 |
92 | qrcode.isUrl = function(s)
93 | {
94 | var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
95 | return regexp.test(s);
96 | }
97 |
98 | qrcode.decode_url = function (s)
99 | {
100 | var escaped = "";
101 | try{
102 | escaped = escape( s );
103 | }
104 | catch(e)
105 | {
106 | console.log(e);
107 | escaped = s;
108 | }
109 | var ret = "";
110 | try{
111 | ret = decodeURIComponent( escaped );
112 | }
113 | catch(e)
114 | {
115 | console.log(e);
116 | ret = escaped;
117 | }
118 | return ret;
119 | }
120 |
121 | qrcode.decode_utf8 = function ( s )
122 | {
123 | if(qrcode.isUrl(s))
124 | return qrcode.decode_url(s);
125 | else
126 | return s;
127 | }
128 |
129 | qrcode.process = function(ctx){
130 |
131 | var start = new Date().getTime();
132 |
133 | var image = qrcode.grayScaleToBitmap(qrcode.grayscale());
134 | //var image = qrcode.binarize(128);
135 |
136 | if(qrcode.debug)
137 | {
138 | for (var y = 0; y < qrcode.height; y++)
139 | {
140 | for (var x = 0; x < qrcode.width; x++)
141 | {
142 | var point = (x * 4) + (y * qrcode.width * 4);
143 | qrcode.imagedata.data[point] = image[x+y*qrcode.width]?0:0;
144 | qrcode.imagedata.data[point+1] = image[x+y*qrcode.width]?0:0;
145 | qrcode.imagedata.data[point+2] = image[x+y*qrcode.width]?255:0;
146 | }
147 | }
148 | ctx.putImageData(qrcode.imagedata, 0, 0);
149 | }
150 |
151 | //var finderPatternInfo = new FinderPatternFinder().findFinderPattern(image);
152 |
153 | var detector = new Detector(image);
154 |
155 | var qRCodeMatrix = detector.detect();
156 |
157 | /*for (var y = 0; y < qRCodeMatrix.bits.Height; y++)
158 | {
159 | for (var x = 0; x < qRCodeMatrix.bits.Width; x++)
160 | {
161 | var point = (x * 4*2) + (y*2 * qrcode.width * 4);
162 | qrcode.imagedata.data[point] = qRCodeMatrix.bits.get_Renamed(x,y)?0:0;
163 | qrcode.imagedata.data[point+1] = qRCodeMatrix.bits.get_Renamed(x,y)?0:0;
164 | qrcode.imagedata.data[point+2] = qRCodeMatrix.bits.get_Renamed(x,y)?255:0;
165 | }
166 | }*/
167 | if(qrcode.debug)
168 | ctx.putImageData(qrcode.imagedata, 0, 0);
169 |
170 | var reader = Decoder.decode(qRCodeMatrix.bits);
171 | var data = reader.DataByte;
172 | var str="";
173 | for(var i=0;i minmax[ax][ay][1])
241 | minmax[ax][ay][1] = target;
242 | }
243 | }
244 | //minmax[ax][ay][0] = (minmax[ax][ay][0] + minmax[ax][ay][1]) / 2;
245 | }
246 | }
247 | var middle = new Array(numSqrtArea);
248 | for (var i3 = 0; i3 < numSqrtArea; i3++)
249 | {
250 | middle[i3] = new Array(numSqrtArea);
251 | }
252 | for (var ay = 0; ay < numSqrtArea; ay++)
253 | {
254 | for (var ax = 0; ax < numSqrtArea; ax++)
255 | {
256 | middle[ax][ay] = Math.floor((minmax[ax][ay][0] + minmax[ax][ay][1]) / 2);
257 | //Console.out.print(middle[ax][ay] + ",");
258 | }
259 | //Console.out.println("");
260 | }
261 | //Console.out.println("");
262 |
263 | return middle;
264 | }
265 |
266 | qrcode.grayScaleToBitmap=function(grayScale)
267 | {
268 | var middle = qrcode.getMiddleBrightnessPerArea(grayScale);
269 | var sqrtNumArea = middle.length;
270 | var areaWidth = Math.floor(qrcode.width / sqrtNumArea);
271 | var areaHeight = Math.floor(qrcode.height / sqrtNumArea);
272 | var bitmap = new Array(qrcode.height*qrcode.width);
273 |
274 | for (var ay = 0; ay < sqrtNumArea; ay++)
275 | {
276 | for (var ax = 0; ax < sqrtNumArea; ax++)
277 | {
278 | for (var dy = 0; dy < areaHeight; dy++)
279 | {
280 | for (var dx = 0; dx < areaWidth; dx++)
281 | {
282 | bitmap[areaWidth * ax + dx+ (areaHeight * ay + dy)*qrcode.width] = (grayScale[areaWidth * ax + dx+ (areaHeight * ay + dy)*qrcode.width] < middle[ax][ay])?true:false;
283 | }
284 | }
285 | }
286 | }
287 | return bitmap;
288 | }
289 |
290 | qrcode.grayscale = function(){
291 | var ret = new Array(qrcode.width*qrcode.height);
292 | for (var y = 0; y < qrcode.height; y++)
293 | {
294 | for (var x = 0; x < qrcode.width; x++)
295 | {
296 | var gray = qrcode.getPixel(x, y);
297 |
298 | ret[x+y*qrcode.width] = gray;
299 | }
300 | }
301 | return ret;
302 | }
303 |
304 |
305 |
306 |
307 | function URShift( number, bits)
308 | {
309 | if (number >= 0)
310 | return number >> bits;
311 | else
312 | return (number >> bits) + (2 << ~bits);
313 | }
314 |
315 |
316 | Array.prototype.remove = function(from, to) {
317 | var rest = this.slice((to || from) + 1 || this.length);
318 | this.length = from < 0 ? this.length + from : from;
319 | return this.push.apply(this, rest);
320 | };
321 |
--------------------------------------------------------------------------------
/js/zepto.qrcode.min.js:
--------------------------------------------------------------------------------
1 | (function(r){r.fn.qrcode=function(h){var s;function u(a){this.mode=s;this.data=a}function o(a,c){this.typeNumber=a;this.errorCorrectLevel=c;this.modules=null;this.moduleCount=0;this.dataCache=null;this.dataList=[]}function q(a,c){if(void 0==a.length)throw Error(a.length+"/"+c);for(var d=0;da||this.moduleCount<=a||0>c||this.moduleCount<=c)throw Error(a+","+c);return this.modules[a][c]},getModuleCount:function(){return this.moduleCount},make:function(){if(1>this.typeNumber){for(var a=1,a=1;40>a;a++){for(var c=p.getRSBlocks(a,this.errorCorrectLevel),d=new t,b=0,e=0;e=d;d++)if(!(-1>=a+d||this.moduleCount<=a+d))for(var b=-1;7>=b;b++)-1>=c+b||this.moduleCount<=c+b||(this.modules[a+d][c+b]=
5 | 0<=d&&6>=d&&(0==b||6==b)||0<=b&&6>=b&&(0==d||6==d)||2<=d&&4>=d&&2<=b&&4>=b?!0:!1)},getBestMaskPattern:function(){for(var a=0,c=0,d=0;8>d;d++){this.makeImpl(!0,d);var b=j.getLostPoint(this);if(0==d||a>b)a=b,c=d}return c},createMovieClip:function(a,c,d){a=a.createEmptyMovieClip(c,d);this.make();for(c=0;c=f;f++)for(var i=-2;2>=i;i++)this.modules[b+f][e+i]=-2==f||2==f||-2==i||2==i||0==f&&0==i?!0:!1}},setupTypeNumber:function(a){for(var c=
7 | j.getBCHTypeNumber(this.typeNumber),d=0;18>d;d++){var b=!a&&1==(c>>d&1);this.modules[Math.floor(d/3)][d%3+this.moduleCount-8-3]=b}for(d=0;18>d;d++)b=!a&&1==(c>>d&1),this.modules[d%3+this.moduleCount-8-3][Math.floor(d/3)]=b},setupTypeInfo:function(a,c){for(var d=j.getBCHTypeInfo(this.errorCorrectLevel<<3|c),b=0;15>b;b++){var e=!a&&1==(d>>b&1);6>b?this.modules[b][8]=e:8>b?this.modules[b+1][8]=e:this.modules[this.moduleCount-15+b][8]=e}for(b=0;15>b;b++)e=!a&&1==(d>>b&1),8>b?this.modules[8][this.moduleCount-
8 | b-1]=e:9>b?this.modules[8][15-b-1+1]=e:this.modules[8][15-b-1]=e;this.modules[this.moduleCount-8][8]=!a},mapData:function(a,c){for(var d=-1,b=this.moduleCount-1,e=7,f=0,i=this.moduleCount-1;0g;g++)if(null==this.modules[b][i-g]){var n=!1;f>>e&1));j.getMask(c,b,i-g)&&(n=!n);this.modules[b][i-g]=n;e--; -1==e&&(f++,e=7)}b+=d;if(0>b||this.moduleCount<=b){b-=d;d=-d;break}}}};o.PAD0=236;o.PAD1=17;o.createData=function(a,c,d){for(var c=p.getRSBlocks(a,
9 | c),b=new t,e=0;e8*a)throw Error("code length overflow. ("+b.getLengthInBits()+">"+8*a+")");for(b.getLengthInBits()+4<=8*a&&b.put(0,4);0!=b.getLengthInBits()%8;)b.putBit(!1);for(;!(b.getLengthInBits()>=8*a);){b.put(o.PAD0,8);if(b.getLengthInBits()>=8*a)break;b.put(o.PAD1,8)}return o.createBytes(b,c)};o.createBytes=function(a,c){for(var d=
10 | 0,b=0,e=0,f=Array(c.length),i=Array(c.length),g=0;g>>=1;return c},getPatternPosition:function(a){return j.PATTERN_POSITION_TABLE[a-1]},getMask:function(a,c,d){switch(a){case 0:return 0==(c+d)%2;case 1:return 0==c%2;case 2:return 0==d%3;case 3:return 0==(c+d)%3;case 4:return 0==(Math.floor(c/2)+Math.floor(d/3))%2;case 5:return 0==c*d%2+c*d%3;case 6:return 0==(c*d%2+c*d%3)%2;case 7:return 0==(c*d%3+(c+d)%2)%2;default:throw Error("bad maskPattern:"+
14 | a);}},getErrorCorrectPolynomial:function(a){for(var c=new q([1],0),d=0;dc)switch(a){case 1:return 10;case 2:return 9;case s:return 8;case 8:return 8;default:throw Error("mode:"+a);}else if(27>c)switch(a){case 1:return 12;case 2:return 11;case s:return 16;case 8:return 10;default:throw Error("mode:"+a);}else if(41>c)switch(a){case 1:return 14;case 2:return 13;case s:return 16;case 8:return 12;default:throw Error("mode:"+
15 | a);}else throw Error("type:"+c);},getLostPoint:function(a){for(var c=a.getModuleCount(),d=0,b=0;b=g;g++)if(!(0>b+g||c<=b+g))for(var h=-1;1>=h;h++)0>e+h||c<=e+h||0==g&&0==h||i==a.isDark(b+g,e+h)&&f++;5a)throw Error("glog("+a+")");return l.LOG_TABLE[a]},gexp:function(a){for(;0>a;)a+=255;for(;256<=a;)a-=255;return l.EXP_TABLE[a]},EXP_TABLE:Array(256),
17 | LOG_TABLE:Array(256)},m=0;8>m;m++)l.EXP_TABLE[m]=1<m;m++)l.EXP_TABLE[m]=l.EXP_TABLE[m-4]^l.EXP_TABLE[m-5]^l.EXP_TABLE[m-6]^l.EXP_TABLE[m-8];for(m=0;255>m;m++)l.LOG_TABLE[l.EXP_TABLE[m]]=m;q.prototype={get:function(a){return this.num[a]},getLength:function(){return this.num.length},multiply:function(a){for(var c=Array(this.getLength()+a.getLength()-1),d=0;d
18 | this.getLength()-a.getLength())return this;for(var c=l.glog(this.get(0))-l.glog(a.get(0)),d=Array(this.getLength()),b=0;b>>7-a%8&1)},put:function(a,c){for(var d=0;d>>c-d-1&1))},getLengthInBits:function(){return this.length},putBit:function(a){var c=Math.floor(this.length/8);this.buffer.length<=c&&this.buffer.push(0);a&&(this.buffer[c]|=128>>>this.length%8);this.length++}};"string"===typeof h&&(h={text:h});h=r.extend({},{render:"canvas",width:256,height:256,typeNumber:-1,
26 | correctLevel:2,background:"#ffffff",foreground:"#000000"},h);return this.each(function(){var a;if("canvas"==h.render){a=new o(h.typeNumber,h.correctLevel);a.addData(h.text);a.make();var c=document.createElement("canvas");c.width=h.width;c.height=h.height;for(var d=c.getContext("2d"),b=h.width/a.getModuleCount(),e=h.height/a.getModuleCount(),f=0;f").css("width",h.width+"px").css("height",h.height+"px").css("border","0px").css("border-collapse","collapse").css("background-color",h.background);d=h.width/a.getModuleCount();b=h.height/a.getModuleCount();for(e=0;e").css("height",b+"px").appendTo(c);for(i=0;i").css("width",
28 | d+"px").css("background-color",a.isDark(e,i)?h.foreground:h.background).appendTo(f)}}a=c;$(a).appendTo(this)})}})(Zepto);
29 |
--------------------------------------------------------------------------------
/js/jsqrcode/detector.js:
--------------------------------------------------------------------------------
1 | /*
2 | Ported to JavaScript by Lazar Laszlo 2011
3 |
4 | lazarsoft@gmail.com, www.lazarsoft.info
5 |
6 | */
7 |
8 | /*
9 | *
10 | * Copyright 2007 ZXing authors
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License");
13 | * you may not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS,
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 |
26 | function PerspectiveTransform( a11, a21, a31, a12, a22, a32, a13, a23, a33)
27 | {
28 | this.a11 = a11;
29 | this.a12 = a12;
30 | this.a13 = a13;
31 | this.a21 = a21;
32 | this.a22 = a22;
33 | this.a23 = a23;
34 | this.a31 = a31;
35 | this.a32 = a32;
36 | this.a33 = a33;
37 | this.transformPoints1=function( points)
38 | {
39 | var max = points.length;
40 | var a11 = this.a11;
41 | var a12 = this.a12;
42 | var a13 = this.a13;
43 | var a21 = this.a21;
44 | var a22 = this.a22;
45 | var a23 = this.a23;
46 | var a31 = this.a31;
47 | var a32 = this.a32;
48 | var a33 = this.a33;
49 | for (var i = 0; i < max; i += 2)
50 | {
51 | var x = points[i];
52 | var y = points[i + 1];
53 | var denominator = a13 * x + a23 * y + a33;
54 | points[i] = (a11 * x + a21 * y + a31) / denominator;
55 | points[i + 1] = (a12 * x + a22 * y + a32) / denominator;
56 | }
57 | }
58 | this. transformPoints2=function(xValues, yValues)
59 | {
60 | var n = xValues.length;
61 | for (var i = 0; i < n; i++)
62 | {
63 | var x = xValues[i];
64 | var y = yValues[i];
65 | var denominator = this.a13 * x + this.a23 * y + this.a33;
66 | xValues[i] = (this.a11 * x + this.a21 * y + this.a31) / denominator;
67 | yValues[i] = (this.a12 * x + this.a22 * y + this.a32) / denominator;
68 | }
69 | }
70 |
71 | this.buildAdjoint=function()
72 | {
73 | // Adjoint is the transpose of the cofactor matrix:
74 | return new PerspectiveTransform(this.a22 * this.a33 - this.a23 * this.a32, this.a23 * this.a31 - this.a21 * this.a33, this.a21 * this.a32 - this.a22 * this.a31, this.a13 * this.a32 - this.a12 * this.a33, this.a11 * this.a33 - this.a13 * this.a31, this.a12 * this.a31 - this.a11 * this.a32, this.a12 * this.a23 - this.a13 * this.a22, this.a13 * this.a21 - this.a11 * this.a23, this.a11 * this.a22 - this.a12 * this.a21);
75 | }
76 | this.times=function( other)
77 | {
78 | return new PerspectiveTransform(this.a11 * other.a11 + this.a21 * other.a12 + this.a31 * other.a13, this.a11 * other.a21 + this.a21 * other.a22 + this.a31 * other.a23, this.a11 * other.a31 + this.a21 * other.a32 + this.a31 * other.a33, this.a12 * other.a11 + this.a22 * other.a12 + this.a32 * other.a13, this.a12 * other.a21 + this.a22 * other.a22 + this.a32 * other.a23, this.a12 * other.a31 + this.a22 * other.a32 + this.a32 * other.a33, this.a13 * other.a11 + this.a23 * other.a12 +this.a33 * other.a13, this.a13 * other.a21 + this.a23 * other.a22 + this.a33 * other.a23, this.a13 * other.a31 + this.a23 * other.a32 + this.a33 * other.a33);
79 | }
80 |
81 | }
82 |
83 | PerspectiveTransform.quadrilateralToQuadrilateral=function( x0, y0, x1, y1, x2, y2, x3, y3, x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p)
84 | {
85 |
86 | var qToS = this.quadrilateralToSquare(x0, y0, x1, y1, x2, y2, x3, y3);
87 | var sToQ = this.squareToQuadrilateral(x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p);
88 | return sToQ.times(qToS);
89 | }
90 |
91 | PerspectiveTransform.squareToQuadrilateral=function( x0, y0, x1, y1, x2, y2, x3, y3)
92 | {
93 | dy2 = y3 - y2;
94 | dy3 = y0 - y1 + y2 - y3;
95 | if (dy2 == 0.0 && dy3 == 0.0)
96 | {
97 | return new PerspectiveTransform(x1 - x0, x2 - x1, x0, y1 - y0, y2 - y1, y0, 0.0, 0.0, 1.0);
98 | }
99 | else
100 | {
101 | dx1 = x1 - x2;
102 | dx2 = x3 - x2;
103 | dx3 = x0 - x1 + x2 - x3;
104 | dy1 = y1 - y2;
105 | denominator = dx1 * dy2 - dx2 * dy1;
106 | a13 = (dx3 * dy2 - dx2 * dy3) / denominator;
107 | a23 = (dx1 * dy3 - dx3 * dy1) / denominator;
108 | return new PerspectiveTransform(x1 - x0 + a13 * x1, x3 - x0 + a23 * x3, x0, y1 - y0 + a13 * y1, y3 - y0 + a23 * y3, y0, a13, a23, 1.0);
109 | }
110 | }
111 |
112 | PerspectiveTransform.quadrilateralToSquare=function( x0, y0, x1, y1, x2, y2, x3, y3)
113 | {
114 | // Here, the adjoint serves as the inverse:
115 | return this.squareToQuadrilateral(x0, y0, x1, y1, x2, y2, x3, y3).buildAdjoint();
116 | }
117 |
118 | function DetectorResult(bits, points)
119 | {
120 | this.bits = bits;
121 | this.points = points;
122 | }
123 |
124 |
125 | function Detector(image)
126 | {
127 | this.image=image;
128 | this.resultPointCallback = null;
129 |
130 | this.sizeOfBlackWhiteBlackRun=function( fromX, fromY, toX, toY)
131 | {
132 | // Mild variant of Bresenham's algorithm;
133 | // see http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
134 | var steep = Math.abs(toY - fromY) > Math.abs(toX - fromX);
135 | if (steep)
136 | {
137 | var temp = fromX;
138 | fromX = fromY;
139 | fromY = temp;
140 | temp = toX;
141 | toX = toY;
142 | toY = temp;
143 | }
144 |
145 | var dx = Math.abs(toX - fromX);
146 | var dy = Math.abs(toY - fromY);
147 | var error = - dx >> 1;
148 | var ystep = fromY < toY?1:- 1;
149 | var xstep = fromX < toX?1:- 1;
150 | var state = 0; // In black pixels, looking for white, first or second time
151 | for (var x = fromX, y = fromY; x != toX; x += xstep)
152 | {
153 |
154 | var realX = steep?y:x;
155 | var realY = steep?x:y;
156 | if (state == 1)
157 | {
158 | // In white pixels, looking for black
159 | if (this.image[realX + realY*qrcode.width])
160 | {
161 | state++;
162 | }
163 | }
164 | else
165 | {
166 | if (!this.image[realX + realY*qrcode.width])
167 | {
168 | state++;
169 | }
170 | }
171 |
172 | if (state == 3)
173 | {
174 | // Found black, white, black, and stumbled back onto white; done
175 | var diffX = x - fromX;
176 | var diffY = y - fromY;
177 | return Math.sqrt( (diffX * diffX + diffY * diffY));
178 | }
179 | error += dy;
180 | if (error > 0)
181 | {
182 | if (y == toY)
183 | {
184 | break;
185 | }
186 | y += ystep;
187 | error -= dx;
188 | }
189 | }
190 | var diffX2 = toX - fromX;
191 | var diffY2 = toY - fromY;
192 | return Math.sqrt( (diffX2 * diffX2 + diffY2 * diffY2));
193 | }
194 |
195 |
196 | this.sizeOfBlackWhiteBlackRunBothWays=function( fromX, fromY, toX, toY)
197 | {
198 |
199 | var result = this.sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY);
200 |
201 | // Now count other way -- don't run off image though of course
202 | var scale = 1.0;
203 | var otherToX = fromX - (toX - fromX);
204 | if (otherToX < 0)
205 | {
206 | scale = fromX / (fromX - otherToX);
207 | otherToX = 0;
208 | }
209 | else if (otherToX >= qrcode.width)
210 | {
211 | scale = (qrcode.width - 1 - fromX) / (otherToX - fromX);
212 | otherToX = qrcode.width - 1;
213 | }
214 | var otherToY = Math.floor (fromY - (toY - fromY) * scale);
215 |
216 | scale = 1.0;
217 | if (otherToY < 0)
218 | {
219 | scale = fromY / (fromY - otherToY);
220 | otherToY = 0;
221 | }
222 | else if (otherToY >= qrcode.height)
223 | {
224 | scale = (qrcode.height - 1 - fromY) / (otherToY - fromY);
225 | otherToY = qrcode.height - 1;
226 | }
227 | otherToX = Math.floor (fromX + (otherToX - fromX) * scale);
228 |
229 | result += this.sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY);
230 | return result - 1.0; // -1 because we counted the middle pixel twice
231 | }
232 |
233 |
234 |
235 | this.calculateModuleSizeOneWay=function( pattern, otherPattern)
236 | {
237 | var moduleSizeEst1 = this.sizeOfBlackWhiteBlackRunBothWays(Math.floor( pattern.X), Math.floor( pattern.Y), Math.floor( otherPattern.X), Math.floor(otherPattern.Y));
238 | var moduleSizeEst2 = this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(otherPattern.X), Math.floor(otherPattern.Y), Math.floor( pattern.X), Math.floor(pattern.Y));
239 | if (isNaN(moduleSizeEst1))
240 | {
241 | return moduleSizeEst2 / 7.0;
242 | }
243 | if (isNaN(moduleSizeEst2))
244 | {
245 | return moduleSizeEst1 / 7.0;
246 | }
247 | // Average them, and divide by 7 since we've counted the width of 3 black modules,
248 | // and 1 white and 1 black module on either side. Ergo, divide sum by 14.
249 | return (moduleSizeEst1 + moduleSizeEst2) / 14.0;
250 | }
251 |
252 |
253 | this.calculateModuleSize=function( topLeft, topRight, bottomLeft)
254 | {
255 | // Take the average
256 | return (this.calculateModuleSizeOneWay(topLeft, topRight) + this.calculateModuleSizeOneWay(topLeft, bottomLeft)) / 2.0;
257 | }
258 |
259 | this.distance=function( pattern1, pattern2)
260 | {
261 | xDiff = pattern1.X - pattern2.X;
262 | yDiff = pattern1.Y - pattern2.Y;
263 | return Math.sqrt( (xDiff * xDiff + yDiff * yDiff));
264 | }
265 | this.computeDimension=function( topLeft, topRight, bottomLeft, moduleSize)
266 | {
267 |
268 | var tltrCentersDimension = Math.round(this.distance(topLeft, topRight) / moduleSize);
269 | var tlblCentersDimension = Math.round(this.distance(topLeft, bottomLeft) / moduleSize);
270 | var dimension = ((tltrCentersDimension + tlblCentersDimension) >> 1) + 7;
271 | switch (dimension & 0x03)
272 | {
273 |
274 | // mod 4
275 | case 0:
276 | dimension++;
277 | break;
278 | // 1? do nothing
279 |
280 | case 2:
281 | dimension--;
282 | break;
283 |
284 | case 3:
285 | throw "Error";
286 | }
287 | return dimension;
288 | }
289 |
290 | this.findAlignmentInRegion=function( overallEstModuleSize, estAlignmentX, estAlignmentY, allowanceFactor)
291 | {
292 | // Look for an alignment pattern (3 modules in size) around where it
293 | // should be
294 | var allowance = Math.floor (allowanceFactor * overallEstModuleSize);
295 | var alignmentAreaLeftX = Math.max(0, estAlignmentX - allowance);
296 | var alignmentAreaRightX = Math.min(qrcode.width - 1, estAlignmentX + allowance);
297 | if (alignmentAreaRightX - alignmentAreaLeftX < overallEstModuleSize * 3)
298 | {
299 | throw "Error";
300 | }
301 |
302 | var alignmentAreaTopY = Math.max(0, estAlignmentY - allowance);
303 | var alignmentAreaBottomY = Math.min(qrcode.height - 1, estAlignmentY + allowance);
304 |
305 | var alignmentFinder = new AlignmentPatternFinder(this.image, alignmentAreaLeftX, alignmentAreaTopY, alignmentAreaRightX - alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize, this.resultPointCallback);
306 | return alignmentFinder.find();
307 | }
308 |
309 | this.createTransform=function( topLeft, topRight, bottomLeft, alignmentPattern, dimension)
310 | {
311 | var dimMinusThree = dimension - 3.5;
312 | var bottomRightX;
313 | var bottomRightY;
314 | var sourceBottomRightX;
315 | var sourceBottomRightY;
316 | if (alignmentPattern != null)
317 | {
318 | bottomRightX = alignmentPattern.X;
319 | bottomRightY = alignmentPattern.Y;
320 | sourceBottomRightX = sourceBottomRightY = dimMinusThree - 3.0;
321 | }
322 | else
323 | {
324 | // Don't have an alignment pattern, just make up the bottom-right point
325 | bottomRightX = (topRight.X - topLeft.X) + bottomLeft.X;
326 | bottomRightY = (topRight.Y - topLeft.Y) + bottomLeft.Y;
327 | sourceBottomRightX = sourceBottomRightY = dimMinusThree;
328 | }
329 |
330 | var transform = PerspectiveTransform.quadrilateralToQuadrilateral(3.5, 3.5, dimMinusThree, 3.5, sourceBottomRightX, sourceBottomRightY, 3.5, dimMinusThree, topLeft.X, topLeft.Y, topRight.X, topRight.Y, bottomRightX, bottomRightY, bottomLeft.X, bottomLeft.Y);
331 |
332 | return transform;
333 | }
334 |
335 | this.sampleGrid=function( image, transform, dimension)
336 | {
337 |
338 | var sampler = GridSampler;
339 | return sampler.sampleGrid3(image, dimension, transform);
340 | }
341 |
342 | this.processFinderPatternInfo = function( info)
343 | {
344 |
345 | var topLeft = info.TopLeft;
346 | var topRight = info.TopRight;
347 | var bottomLeft = info.BottomLeft;
348 |
349 | var moduleSize = this.calculateModuleSize(topLeft, topRight, bottomLeft);
350 | if (moduleSize < 1.0)
351 | {
352 | throw "Error";
353 | }
354 | var dimension = this.computeDimension(topLeft, topRight, bottomLeft, moduleSize);
355 | var provisionalVersion = Version.getProvisionalVersionForDimension(dimension);
356 | var modulesBetweenFPCenters = provisionalVersion.DimensionForVersion - 7;
357 |
358 | var alignmentPattern = null;
359 | // Anything above version 1 has an alignment pattern
360 | if (provisionalVersion.AlignmentPatternCenters.length > 0)
361 | {
362 |
363 | // Guess where a "bottom right" finder pattern would have been
364 | var bottomRightX = topRight.X - topLeft.X + bottomLeft.X;
365 | var bottomRightY = topRight.Y - topLeft.Y + bottomLeft.Y;
366 |
367 | // Estimate that alignment pattern is closer by 3 modules
368 | // from "bottom right" to known top left location
369 | var correctionToTopLeft = 1.0 - 3.0 / modulesBetweenFPCenters;
370 | var estAlignmentX = Math.floor (topLeft.X + correctionToTopLeft * (bottomRightX - topLeft.X));
371 | var estAlignmentY = Math.floor (topLeft.Y + correctionToTopLeft * (bottomRightY - topLeft.Y));
372 |
373 | // Kind of arbitrary -- expand search radius before giving up
374 | for (var i = 4; i <= 16; i <<= 1)
375 | {
376 | //try
377 | //{
378 | alignmentPattern = this.findAlignmentInRegion(moduleSize, estAlignmentX, estAlignmentY, i);
379 | break;
380 | //}
381 | //catch (re)
382 | //{
383 | // try next round
384 | //}
385 | }
386 | // If we didn't find alignment pattern... well try anyway without it
387 | }
388 |
389 | var transform = this.createTransform(topLeft, topRight, bottomLeft, alignmentPattern, dimension);
390 |
391 | var bits = this.sampleGrid(this.image, transform, dimension);
392 |
393 | var points;
394 | if (alignmentPattern == null)
395 | {
396 | points = new Array(bottomLeft, topLeft, topRight);
397 | }
398 | else
399 | {
400 | points = new Array(bottomLeft, topLeft, topRight, alignmentPattern);
401 | }
402 | return new DetectorResult(bits, points);
403 | }
404 |
405 |
406 |
407 | this.detect=function()
408 | {
409 | var info = new FinderPatternFinder().findFinderPattern(this.image);
410 |
411 | return this.processFinderPatternInfo(info);
412 | }
413 | }
--------------------------------------------------------------------------------
/js/jsqrcode/version.js:
--------------------------------------------------------------------------------
1 | /*
2 | Ported to JavaScript by Lazar Laszlo 2011
3 |
4 | lazarsoft@gmail.com, www.lazarsoft.info
5 |
6 | */
7 |
8 | /*
9 | *
10 | * Copyright 2007 ZXing authors
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License");
13 | * you may not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS,
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 |
26 |
27 | function ECB(count, dataCodewords)
28 | {
29 | this.count = count;
30 | this.dataCodewords = dataCodewords;
31 |
32 | this.__defineGetter__("Count", function()
33 | {
34 | return this.count;
35 | });
36 | this.__defineGetter__("DataCodewords", function()
37 | {
38 | return this.dataCodewords;
39 | });
40 | }
41 |
42 | function ECBlocks( ecCodewordsPerBlock, ecBlocks1, ecBlocks2)
43 | {
44 | this.ecCodewordsPerBlock = ecCodewordsPerBlock;
45 | if(ecBlocks2)
46 | this.ecBlocks = new Array(ecBlocks1, ecBlocks2);
47 | else
48 | this.ecBlocks = new Array(ecBlocks1);
49 |
50 | this.__defineGetter__("ECCodewordsPerBlock", function()
51 | {
52 | return this.ecCodewordsPerBlock;
53 | });
54 |
55 | this.__defineGetter__("TotalECCodewords", function()
56 | {
57 | return this.ecCodewordsPerBlock * this.NumBlocks;
58 | });
59 |
60 | this.__defineGetter__("NumBlocks", function()
61 | {
62 | var total = 0;
63 | for (var i = 0; i < this.ecBlocks.length; i++)
64 | {
65 | total += this.ecBlocks[i].length;
66 | }
67 | return total;
68 | });
69 |
70 | this.getECBlocks=function()
71 | {
72 | return this.ecBlocks;
73 | }
74 | }
75 |
76 | function Version( versionNumber, alignmentPatternCenters, ecBlocks1, ecBlocks2, ecBlocks3, ecBlocks4)
77 | {
78 | this.versionNumber = versionNumber;
79 | this.alignmentPatternCenters = alignmentPatternCenters;
80 | this.ecBlocks = new Array(ecBlocks1, ecBlocks2, ecBlocks3, ecBlocks4);
81 |
82 | var total = 0;
83 | var ecCodewords = ecBlocks1.ECCodewordsPerBlock;
84 | var ecbArray = ecBlocks1.getECBlocks();
85 | for (var i = 0; i < ecbArray.length; i++)
86 | {
87 | var ecBlock = ecbArray[i];
88 | total += ecBlock.Count * (ecBlock.DataCodewords + ecCodewords);
89 | }
90 | this.totalCodewords = total;
91 |
92 | this.__defineGetter__("VersionNumber", function()
93 | {
94 | return this.versionNumber;
95 | });
96 |
97 | this.__defineGetter__("AlignmentPatternCenters", function()
98 | {
99 | return this.alignmentPatternCenters;
100 | });
101 | this.__defineGetter__("TotalCodewords", function()
102 | {
103 | return this.totalCodewords;
104 | });
105 | this.__defineGetter__("DimensionForVersion", function()
106 | {
107 | return 17 + 4 * this.versionNumber;
108 | });
109 |
110 | this.buildFunctionPattern=function()
111 | {
112 | var dimension = this.DimensionForVersion;
113 | var bitMatrix = new BitMatrix(dimension);
114 |
115 | // Top left finder pattern + separator + format
116 | bitMatrix.setRegion(0, 0, 9, 9);
117 | // Top right finder pattern + separator + format
118 | bitMatrix.setRegion(dimension - 8, 0, 8, 9);
119 | // Bottom left finder pattern + separator + format
120 | bitMatrix.setRegion(0, dimension - 8, 9, 8);
121 |
122 | // Alignment patterns
123 | var max = this.alignmentPatternCenters.length;
124 | for (var x = 0; x < max; x++)
125 | {
126 | var i = this.alignmentPatternCenters[x] - 2;
127 | for (var y = 0; y < max; y++)
128 | {
129 | if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0))
130 | {
131 | // No alignment patterns near the three finder paterns
132 | continue;
133 | }
134 | bitMatrix.setRegion(this.alignmentPatternCenters[y] - 2, i, 5, 5);
135 | }
136 | }
137 |
138 | // Vertical timing pattern
139 | bitMatrix.setRegion(6, 9, 1, dimension - 17);
140 | // Horizontal timing pattern
141 | bitMatrix.setRegion(9, 6, dimension - 17, 1);
142 |
143 | if (this.versionNumber > 6)
144 | {
145 | // Version info, top right
146 | bitMatrix.setRegion(dimension - 11, 0, 3, 6);
147 | // Version info, bottom left
148 | bitMatrix.setRegion(0, dimension - 11, 6, 3);
149 | }
150 |
151 | return bitMatrix;
152 | }
153 | this.getECBlocksForLevel=function( ecLevel)
154 | {
155 | return this.ecBlocks[ecLevel.ordinal()];
156 | }
157 | }
158 |
159 | Version.VERSION_DECODE_INFO = new Array(0x07C94, 0x085BC, 0x09A99, 0x0A4D3, 0x0BBF6, 0x0C762, 0x0D847, 0x0E60D, 0x0F928, 0x10B78, 0x1145D, 0x12A17, 0x13532, 0x149A6, 0x15683, 0x168C9, 0x177EC, 0x18EC4, 0x191E1, 0x1AFAB, 0x1B08E, 0x1CC1A, 0x1D33F, 0x1ED75, 0x1F250, 0x209D5, 0x216F0, 0x228BA, 0x2379F, 0x24B0B, 0x2542E, 0x26A64, 0x27541, 0x28C69);
160 |
161 | Version.VERSIONS = buildVersions();
162 |
163 | Version.getVersionForNumber=function( versionNumber)
164 | {
165 | if (versionNumber < 1 || versionNumber > 40)
166 | {
167 | throw "ArgumentException";
168 | }
169 | return Version.VERSIONS[versionNumber - 1];
170 | }
171 |
172 | Version.getProvisionalVersionForDimension=function(dimension)
173 | {
174 | if (dimension % 4 != 1)
175 | {
176 | throw "Error getProvisionalVersionForDimension";
177 | }
178 | try
179 | {
180 | return Version.getVersionForNumber((dimension - 17) >> 2);
181 | }
182 | catch ( iae)
183 | {
184 | throw "Error getVersionForNumber";
185 | }
186 | }
187 |
188 | Version.decodeVersionInformation=function( versionBits)
189 | {
190 | var bestDifference = 0xffffffff;
191 | var bestVersion = 0;
192 | for (var i = 0; i < Version.VERSION_DECODE_INFO.length; i++)
193 | {
194 | var targetVersion = Version.VERSION_DECODE_INFO[i];
195 | // Do the version info bits match exactly? done.
196 | if (targetVersion == versionBits)
197 | {
198 | return this.getVersionForNumber(i + 7);
199 | }
200 | // Otherwise see if this is the closest to a real version info bit string
201 | // we have seen so far
202 | var bitsDifference = FormatInformation.numBitsDiffering(versionBits, targetVersion);
203 | if (bitsDifference < bestDifference)
204 | {
205 | bestVersion = i + 7;
206 | bestDifference = bitsDifference;
207 | }
208 | }
209 | // We can tolerate up to 3 bits of error since no two version info codewords will
210 | // differ in less than 4 bits.
211 | if (bestDifference <= 3)
212 | {
213 | return this.getVersionForNumber(bestVersion);
214 | }
215 | // If we didn't find a close enough match, fail
216 | return null;
217 | }
218 |
219 | function buildVersions()
220 | {
221 | return new Array(new Version(1, new Array(), new ECBlocks(7, new ECB(1, 19)), new ECBlocks(10, new ECB(1, 16)), new ECBlocks(13, new ECB(1, 13)), new ECBlocks(17, new ECB(1, 9))),
222 | new Version(2, new Array(6, 18), new ECBlocks(10, new ECB(1, 34)), new ECBlocks(16, new ECB(1, 28)), new ECBlocks(22, new ECB(1, 22)), new ECBlocks(28, new ECB(1, 16))),
223 | new Version(3, new Array(6, 22), new ECBlocks(15, new ECB(1, 55)), new ECBlocks(26, new ECB(1, 44)), new ECBlocks(18, new ECB(2, 17)), new ECBlocks(22, new ECB(2, 13))),
224 | new Version(4, new Array(6, 26), new ECBlocks(20, new ECB(1, 80)), new ECBlocks(18, new ECB(2, 32)), new ECBlocks(26, new ECB(2, 24)), new ECBlocks(16, new ECB(4, 9))),
225 | new Version(5, new Array(6, 30), new ECBlocks(26, new ECB(1, 108)), new ECBlocks(24, new ECB(2, 43)), new ECBlocks(18, new ECB(2, 15), new ECB(2, 16)), new ECBlocks(22, new ECB(2, 11), new ECB(2, 12))),
226 | new Version(6, new Array(6, 34), new ECBlocks(18, new ECB(2, 68)), new ECBlocks(16, new ECB(4, 27)), new ECBlocks(24, new ECB(4, 19)), new ECBlocks(28, new ECB(4, 15))),
227 | new Version(7, new Array(6, 22, 38), new ECBlocks(20, new ECB(2, 78)), new ECBlocks(18, new ECB(4, 31)), new ECBlocks(18, new ECB(2, 14), new ECB(4, 15)), new ECBlocks(26, new ECB(4, 13), new ECB(1, 14))),
228 | new Version(8, new Array(6, 24, 42), new ECBlocks(24, new ECB(2, 97)), new ECBlocks(22, new ECB(2, 38), new ECB(2, 39)), new ECBlocks(22, new ECB(4, 18), new ECB(2, 19)), new ECBlocks(26, new ECB(4, 14), new ECB(2, 15))),
229 | new Version(9, new Array(6, 26, 46), new ECBlocks(30, new ECB(2, 116)), new ECBlocks(22, new ECB(3, 36), new ECB(2, 37)), new ECBlocks(20, new ECB(4, 16), new ECB(4, 17)), new ECBlocks(24, new ECB(4, 12), new ECB(4, 13))),
230 | new Version(10, new Array(6, 28, 50), new ECBlocks(18, new ECB(2, 68), new ECB(2, 69)), new ECBlocks(26, new ECB(4, 43), new ECB(1, 44)), new ECBlocks(24, new ECB(6, 19), new ECB(2, 20)), new ECBlocks(28, new ECB(6, 15), new ECB(2, 16))),
231 | new Version(11, new Array(6, 30, 54), new ECBlocks(20, new ECB(4, 81)), new ECBlocks(30, new ECB(1, 50), new ECB(4, 51)), new ECBlocks(28, new ECB(4, 22), new ECB(4, 23)), new ECBlocks(24, new ECB(3, 12), new ECB(8, 13))),
232 | new Version(12, new Array(6, 32, 58), new ECBlocks(24, new ECB(2, 92), new ECB(2, 93)), new ECBlocks(22, new ECB(6, 36), new ECB(2, 37)), new ECBlocks(26, new ECB(4, 20), new ECB(6, 21)), new ECBlocks(28, new ECB(7, 14), new ECB(4, 15))),
233 | new Version(13, new Array(6, 34, 62), new ECBlocks(26, new ECB(4, 107)), new ECBlocks(22, new ECB(8, 37), new ECB(1, 38)), new ECBlocks(24, new ECB(8, 20), new ECB(4, 21)), new ECBlocks(22, new ECB(12, 11), new ECB(4, 12))),
234 | new Version(14, new Array(6, 26, 46, 66), new ECBlocks(30, new ECB(3, 115), new ECB(1, 116)), new ECBlocks(24, new ECB(4, 40), new ECB(5, 41)), new ECBlocks(20, new ECB(11, 16), new ECB(5, 17)), new ECBlocks(24, new ECB(11, 12), new ECB(5, 13))),
235 | new Version(15, new Array(6, 26, 48, 70), new ECBlocks(22, new ECB(5, 87), new ECB(1, 88)), new ECBlocks(24, new ECB(5, 41), new ECB(5, 42)), new ECBlocks(30, new ECB(5, 24), new ECB(7, 25)), new ECBlocks(24, new ECB(11, 12), new ECB(7, 13))),
236 | new Version(16, new Array(6, 26, 50, 74), new ECBlocks(24, new ECB(5, 98), new ECB(1, 99)), new ECBlocks(28, new ECB(7, 45), new ECB(3, 46)), new ECBlocks(24, new ECB(15, 19), new ECB(2, 20)), new ECBlocks(30, new ECB(3, 15), new ECB(13, 16))),
237 | new Version(17, new Array(6, 30, 54, 78), new ECBlocks(28, new ECB(1, 107), new ECB(5, 108)), new ECBlocks(28, new ECB(10, 46), new ECB(1, 47)), new ECBlocks(28, new ECB(1, 22), new ECB(15, 23)), new ECBlocks(28, new ECB(2, 14), new ECB(17, 15))),
238 | new Version(18, new Array(6, 30, 56, 82), new ECBlocks(30, new ECB(5, 120), new ECB(1, 121)), new ECBlocks(26, new ECB(9, 43), new ECB(4, 44)), new ECBlocks(28, new ECB(17, 22), new ECB(1, 23)), new ECBlocks(28, new ECB(2, 14), new ECB(19, 15))),
239 | new Version(19, new Array(6, 30, 58, 86), new ECBlocks(28, new ECB(3, 113), new ECB(4, 114)), new ECBlocks(26, new ECB(3, 44), new ECB(11, 45)), new ECBlocks(26, new ECB(17, 21), new ECB(4, 22)), new ECBlocks(26, new ECB(9, 13), new ECB(16, 14))),
240 | new Version(20, new Array(6, 34, 62, 90), new ECBlocks(28, new ECB(3, 107), new ECB(5, 108)), new ECBlocks(26, new ECB(3, 41), new ECB(13, 42)), new ECBlocks(30, new ECB(15, 24), new ECB(5, 25)), new ECBlocks(28, new ECB(15, 15), new ECB(10, 16))),
241 | new Version(21, new Array(6, 28, 50, 72, 94), new ECBlocks(28, new ECB(4, 116), new ECB(4, 117)), new ECBlocks(26, new ECB(17, 42)), new ECBlocks(28, new ECB(17, 22), new ECB(6, 23)), new ECBlocks(30, new ECB(19, 16), new ECB(6, 17))),
242 | new Version(22, new Array(6, 26, 50, 74, 98), new ECBlocks(28, new ECB(2, 111), new ECB(7, 112)), new ECBlocks(28, new ECB(17, 46)), new ECBlocks(30, new ECB(7, 24), new ECB(16, 25)), new ECBlocks(24, new ECB(34, 13))),
243 | new Version(23, new Array(6, 30, 54, 74, 102), new ECBlocks(30, new ECB(4, 121), new ECB(5, 122)), new ECBlocks(28, new ECB(4, 47), new ECB(14, 48)), new ECBlocks(30, new ECB(11, 24), new ECB(14, 25)), new ECBlocks(30, new ECB(16, 15), new ECB(14, 16))),
244 | new Version(24, new Array(6, 28, 54, 80, 106), new ECBlocks(30, new ECB(6, 117), new ECB(4, 118)), new ECBlocks(28, new ECB(6, 45), new ECB(14, 46)), new ECBlocks(30, new ECB(11, 24), new ECB(16, 25)), new ECBlocks(30, new ECB(30, 16), new ECB(2, 17))),
245 | new Version(25, new Array(6, 32, 58, 84, 110), new ECBlocks(26, new ECB(8, 106), new ECB(4, 107)), new ECBlocks(28, new ECB(8, 47), new ECB(13, 48)), new ECBlocks(30, new ECB(7, 24), new ECB(22, 25)), new ECBlocks(30, new ECB(22, 15), new ECB(13, 16))),
246 | new Version(26, new Array(6, 30, 58, 86, 114), new ECBlocks(28, new ECB(10, 114), new ECB(2, 115)), new ECBlocks(28, new ECB(19, 46), new ECB(4, 47)), new ECBlocks(28, new ECB(28, 22), new ECB(6, 23)), new ECBlocks(30, new ECB(33, 16), new ECB(4, 17))),
247 | new Version(27, new Array(6, 34, 62, 90, 118), new ECBlocks(30, new ECB(8, 122), new ECB(4, 123)), new ECBlocks(28, new ECB(22, 45), new ECB(3, 46)), new ECBlocks(30, new ECB(8, 23), new ECB(26, 24)), new ECBlocks(30, new ECB(12, 15), new ECB(28, 16))),
248 | new Version(28, new Array(6, 26, 50, 74, 98, 122), new ECBlocks(30, new ECB(3, 117), new ECB(10, 118)), new ECBlocks(28, new ECB(3, 45), new ECB(23, 46)), new ECBlocks(30, new ECB(4, 24), new ECB(31, 25)), new ECBlocks(30, new ECB(11, 15), new ECB(31, 16))),
249 | new Version(29, new Array(6, 30, 54, 78, 102, 126), new ECBlocks(30, new ECB(7, 116), new ECB(7, 117)), new ECBlocks(28, new ECB(21, 45), new ECB(7, 46)), new ECBlocks(30, new ECB(1, 23), new ECB(37, 24)), new ECBlocks(30, new ECB(19, 15), new ECB(26, 16))),
250 | new Version(30, new Array(6, 26, 52, 78, 104, 130), new ECBlocks(30, new ECB(5, 115), new ECB(10, 116)), new ECBlocks(28, new ECB(19, 47), new ECB(10, 48)), new ECBlocks(30, new ECB(15, 24), new ECB(25, 25)), new ECBlocks(30, new ECB(23, 15), new ECB(25, 16))),
251 | new Version(31, new Array(6, 30, 56, 82, 108, 134), new ECBlocks(30, new ECB(13, 115), new ECB(3, 116)), new ECBlocks(28, new ECB(2, 46), new ECB(29, 47)), new ECBlocks(30, new ECB(42, 24), new ECB(1, 25)), new ECBlocks(30, new ECB(23, 15), new ECB(28, 16))),
252 | new Version(32, new Array(6, 34, 60, 86, 112, 138), new ECBlocks(30, new ECB(17, 115)), new ECBlocks(28, new ECB(10, 46), new ECB(23, 47)), new ECBlocks(30, new ECB(10, 24), new ECB(35, 25)), new ECBlocks(30, new ECB(19, 15), new ECB(35, 16))),
253 | new Version(33, new Array(6, 30, 58, 86, 114, 142), new ECBlocks(30, new ECB(17, 115), new ECB(1, 116)), new ECBlocks(28, new ECB(14, 46), new ECB(21, 47)), new ECBlocks(30, new ECB(29, 24), new ECB(19, 25)), new ECBlocks(30, new ECB(11, 15), new ECB(46, 16))),
254 | new Version(34, new Array(6, 34, 62, 90, 118, 146), new ECBlocks(30, new ECB(13, 115), new ECB(6, 116)), new ECBlocks(28, new ECB(14, 46), new ECB(23, 47)), new ECBlocks(30, new ECB(44, 24), new ECB(7, 25)), new ECBlocks(30, new ECB(59, 16), new ECB(1, 17))),
255 | new Version(35, new Array(6, 30, 54, 78, 102, 126, 150), new ECBlocks(30, new ECB(12, 121), new ECB(7, 122)), new ECBlocks(28, new ECB(12, 47), new ECB(26, 48)), new ECBlocks(30, new ECB(39, 24), new ECB(14, 25)),new ECBlocks(30, new ECB(22, 15), new ECB(41, 16))),
256 | new Version(36, new Array(6, 24, 50, 76, 102, 128, 154), new ECBlocks(30, new ECB(6, 121), new ECB(14, 122)), new ECBlocks(28, new ECB(6, 47), new ECB(34, 48)), new ECBlocks(30, new ECB(46, 24), new ECB(10, 25)), new ECBlocks(30, new ECB(2, 15), new ECB(64, 16))),
257 | new Version(37, new Array(6, 28, 54, 80, 106, 132, 158), new ECBlocks(30, new ECB(17, 122), new ECB(4, 123)), new ECBlocks(28, new ECB(29, 46), new ECB(14, 47)), new ECBlocks(30, new ECB(49, 24), new ECB(10, 25)), new ECBlocks(30, new ECB(24, 15), new ECB(46, 16))),
258 | new Version(38, new Array(6, 32, 58, 84, 110, 136, 162), new ECBlocks(30, new ECB(4, 122), new ECB(18, 123)), new ECBlocks(28, new ECB(13, 46), new ECB(32, 47)), new ECBlocks(30, new ECB(48, 24), new ECB(14, 25)), new ECBlocks(30, new ECB(42, 15), new ECB(32, 16))),
259 | new Version(39, new Array(6, 26, 54, 82, 110, 138, 166), new ECBlocks(30, new ECB(20, 117), new ECB(4, 118)), new ECBlocks(28, new ECB(40, 47), new ECB(7, 48)), new ECBlocks(30, new ECB(43, 24), new ECB(22, 25)), new ECBlocks(30, new ECB(10, 15), new ECB(67, 16))),
260 | new Version(40, new Array(6, 30, 58, 86, 114, 142, 170), new ECBlocks(30, new ECB(19, 118), new ECB(6, 119)), new ECBlocks(28, new ECB(18, 47), new ECB(31, 48)), new ECBlocks(30, new ECB(34, 24), new ECB(34, 25)), new ECBlocks(30, new ECB(20, 15), new ECB(61, 16))));
261 | }
--------------------------------------------------------------------------------
/js/jsqrcode/findpat.js:
--------------------------------------------------------------------------------
1 | /*
2 | Ported to JavaScript by Lazar Laszlo 2011
3 |
4 | lazarsoft@gmail.com, www.lazarsoft.info
5 |
6 | */
7 |
8 | /*
9 | *
10 | * Copyright 2007 ZXing authors
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License");
13 | * you may not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS,
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 |
26 | var MIN_SKIP = 3;
27 | var MAX_MODULES = 57;
28 | var INTEGER_MATH_SHIFT = 8;
29 | var CENTER_QUORUM = 2;
30 |
31 | qrcode.orderBestPatterns=function(patterns)
32 | {
33 |
34 | function distance( pattern1, pattern2)
35 | {
36 | xDiff = pattern1.X - pattern2.X;
37 | yDiff = pattern1.Y - pattern2.Y;
38 | return Math.sqrt( (xDiff * xDiff + yDiff * yDiff));
39 | }
40 |
41 | /// Returns the z component of the cross product between vectors BC and BA.
42 | function crossProductZ( pointA, pointB, pointC)
43 | {
44 | var bX = pointB.x;
45 | var bY = pointB.y;
46 | return ((pointC.x - bX) * (pointA.y - bY)) - ((pointC.y - bY) * (pointA.x - bX));
47 | }
48 |
49 |
50 | // Find distances between pattern centers
51 | var zeroOneDistance = distance(patterns[0], patterns[1]);
52 | var oneTwoDistance = distance(patterns[1], patterns[2]);
53 | var zeroTwoDistance = distance(patterns[0], patterns[2]);
54 |
55 | var pointA, pointB, pointC;
56 | // Assume one closest to other two is B; A and C will just be guesses at first
57 | if (oneTwoDistance >= zeroOneDistance && oneTwoDistance >= zeroTwoDistance)
58 | {
59 | pointB = patterns[0];
60 | pointA = patterns[1];
61 | pointC = patterns[2];
62 | }
63 | else if (zeroTwoDistance >= oneTwoDistance && zeroTwoDistance >= zeroOneDistance)
64 | {
65 | pointB = patterns[1];
66 | pointA = patterns[0];
67 | pointC = patterns[2];
68 | }
69 | else
70 | {
71 | pointB = patterns[2];
72 | pointA = patterns[0];
73 | pointC = patterns[1];
74 | }
75 |
76 | // Use cross product to figure out whether A and C are correct or flipped.
77 | // This asks whether BC x BA has a positive z component, which is the arrangement
78 | // we want for A, B, C. If it's negative, then we've got it flipped around and
79 | // should swap A and C.
80 | if (crossProductZ(pointA, pointB, pointC) < 0.0)
81 | {
82 | var temp = pointA;
83 | pointA = pointC;
84 | pointC = temp;
85 | }
86 |
87 | patterns[0] = pointA;
88 | patterns[1] = pointB;
89 | patterns[2] = pointC;
90 | }
91 |
92 |
93 | function FinderPattern(posX, posY, estimatedModuleSize)
94 | {
95 | this.x=posX;
96 | this.y=posY;
97 | this.count = 1;
98 | this.estimatedModuleSize = estimatedModuleSize;
99 |
100 | this.__defineGetter__("EstimatedModuleSize", function()
101 | {
102 | return this.estimatedModuleSize;
103 | });
104 | this.__defineGetter__("Count", function()
105 | {
106 | return this.count;
107 | });
108 | this.__defineGetter__("X", function()
109 | {
110 | return this.x;
111 | });
112 | this.__defineGetter__("Y", function()
113 | {
114 | return this.y;
115 | });
116 | this.incrementCount = function()
117 | {
118 | this.count++;
119 | }
120 | this.aboutEquals=function( moduleSize, i, j)
121 | {
122 | if (Math.abs(i - this.y) <= moduleSize && Math.abs(j - this.x) <= moduleSize)
123 | {
124 | var moduleSizeDiff = Math.abs(moduleSize - this.estimatedModuleSize);
125 | return moduleSizeDiff <= 1.0 || moduleSizeDiff / this.estimatedModuleSize <= 1.0;
126 | }
127 | return false;
128 | }
129 |
130 | }
131 |
132 | function FinderPatternInfo(patternCenters)
133 | {
134 | this.bottomLeft = patternCenters[0];
135 | this.topLeft = patternCenters[1];
136 | this.topRight = patternCenters[2];
137 | this.__defineGetter__("BottomLeft", function()
138 | {
139 | return this.bottomLeft;
140 | });
141 | this.__defineGetter__("TopLeft", function()
142 | {
143 | return this.topLeft;
144 | });
145 | this.__defineGetter__("TopRight", function()
146 | {
147 | return this.topRight;
148 | });
149 | }
150 |
151 | function FinderPatternFinder()
152 | {
153 | this.image=null;
154 | this.possibleCenters = [];
155 | this.hasSkipped = false;
156 | this.crossCheckStateCount = new Array(0,0,0,0,0);
157 | this.resultPointCallback = null;
158 |
159 | this.__defineGetter__("CrossCheckStateCount", function()
160 | {
161 | this.crossCheckStateCount[0] = 0;
162 | this.crossCheckStateCount[1] = 0;
163 | this.crossCheckStateCount[2] = 0;
164 | this.crossCheckStateCount[3] = 0;
165 | this.crossCheckStateCount[4] = 0;
166 | return this.crossCheckStateCount;
167 | });
168 |
169 | this.foundPatternCross=function( stateCount)
170 | {
171 | var totalModuleSize = 0;
172 | for (var i = 0; i < 5; i++)
173 | {
174 | var count = stateCount[i];
175 | if (count == 0)
176 | {
177 | return false;
178 | }
179 | totalModuleSize += count;
180 | }
181 | if (totalModuleSize < 7)
182 | {
183 | return false;
184 | }
185 | var moduleSize = Math.floor((totalModuleSize << INTEGER_MATH_SHIFT) / 7);
186 | var maxVariance = Math.floor(moduleSize / 2);
187 | // Allow less than 50% variance from 1-1-3-1-1 proportions
188 | return Math.abs(moduleSize - (stateCount[0] << INTEGER_MATH_SHIFT)) < maxVariance && Math.abs(moduleSize - (stateCount[1] << INTEGER_MATH_SHIFT)) < maxVariance && Math.abs(3 * moduleSize - (stateCount[2] << INTEGER_MATH_SHIFT)) < 3 * maxVariance && Math.abs(moduleSize - (stateCount[3] << INTEGER_MATH_SHIFT)) < maxVariance && Math.abs(moduleSize - (stateCount[4] << INTEGER_MATH_SHIFT)) < maxVariance;
189 | }
190 | this.centerFromEnd=function( stateCount, end)
191 | {
192 | return (end - stateCount[4] - stateCount[3]) - stateCount[2] / 2.0;
193 | }
194 | this.crossCheckVertical=function( startI, centerJ, maxCount, originalStateCountTotal)
195 | {
196 | var image = this.image;
197 |
198 | var maxI = qrcode.height;
199 | var stateCount = this.CrossCheckStateCount;
200 |
201 | // Start counting up from center
202 | var i = startI;
203 | while (i >= 0 && image[centerJ + i*qrcode.width])
204 | {
205 | stateCount[2]++;
206 | i--;
207 | }
208 | if (i < 0)
209 | {
210 | return NaN;
211 | }
212 | while (i >= 0 && !image[centerJ +i*qrcode.width] && stateCount[1] <= maxCount)
213 | {
214 | stateCount[1]++;
215 | i--;
216 | }
217 | // If already too many modules in this state or ran off the edge:
218 | if (i < 0 || stateCount[1] > maxCount)
219 | {
220 | return NaN;
221 | }
222 | while (i >= 0 && image[centerJ + i*qrcode.width] && stateCount[0] <= maxCount)
223 | {
224 | stateCount[0]++;
225 | i--;
226 | }
227 | if (stateCount[0] > maxCount)
228 | {
229 | return NaN;
230 | }
231 |
232 | // Now also count down from center
233 | i = startI + 1;
234 | while (i < maxI && image[centerJ +i*qrcode.width])
235 | {
236 | stateCount[2]++;
237 | i++;
238 | }
239 | if (i == maxI)
240 | {
241 | return NaN;
242 | }
243 | while (i < maxI && !image[centerJ + i*qrcode.width] && stateCount[3] < maxCount)
244 | {
245 | stateCount[3]++;
246 | i++;
247 | }
248 | if (i == maxI || stateCount[3] >= maxCount)
249 | {
250 | return NaN;
251 | }
252 | while (i < maxI && image[centerJ + i*qrcode.width] && stateCount[4] < maxCount)
253 | {
254 | stateCount[4]++;
255 | i++;
256 | }
257 | if (stateCount[4] >= maxCount)
258 | {
259 | return NaN;
260 | }
261 |
262 | // If we found a finder-pattern-like section, but its size is more than 40% different than
263 | // the original, assume it's a false positive
264 | var stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];
265 | if (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal)
266 | {
267 | return NaN;
268 | }
269 |
270 | return this.foundPatternCross(stateCount)?this.centerFromEnd(stateCount, i):NaN;
271 | }
272 | this.crossCheckHorizontal=function( startJ, centerI, maxCount, originalStateCountTotal)
273 | {
274 | var image = this.image;
275 |
276 | var maxJ = qrcode.width;
277 | var stateCount = this.CrossCheckStateCount;
278 |
279 | var j = startJ;
280 | while (j >= 0 && image[j+ centerI*qrcode.width])
281 | {
282 | stateCount[2]++;
283 | j--;
284 | }
285 | if (j < 0)
286 | {
287 | return NaN;
288 | }
289 | while (j >= 0 && !image[j+ centerI*qrcode.width] && stateCount[1] <= maxCount)
290 | {
291 | stateCount[1]++;
292 | j--;
293 | }
294 | if (j < 0 || stateCount[1] > maxCount)
295 | {
296 | return NaN;
297 | }
298 | while (j >= 0 && image[j+ centerI*qrcode.width] && stateCount[0] <= maxCount)
299 | {
300 | stateCount[0]++;
301 | j--;
302 | }
303 | if (stateCount[0] > maxCount)
304 | {
305 | return NaN;
306 | }
307 |
308 | j = startJ + 1;
309 | while (j < maxJ && image[j+ centerI*qrcode.width])
310 | {
311 | stateCount[2]++;
312 | j++;
313 | }
314 | if (j == maxJ)
315 | {
316 | return NaN;
317 | }
318 | while (j < maxJ && !image[j+ centerI*qrcode.width] && stateCount[3] < maxCount)
319 | {
320 | stateCount[3]++;
321 | j++;
322 | }
323 | if (j == maxJ || stateCount[3] >= maxCount)
324 | {
325 | return NaN;
326 | }
327 | while (j < maxJ && image[j+ centerI*qrcode.width] && stateCount[4] < maxCount)
328 | {
329 | stateCount[4]++;
330 | j++;
331 | }
332 | if (stateCount[4] >= maxCount)
333 | {
334 | return NaN;
335 | }
336 |
337 | // If we found a finder-pattern-like section, but its size is significantly different than
338 | // the original, assume it's a false positive
339 | var stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];
340 | if (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= originalStateCountTotal)
341 | {
342 | return NaN;
343 | }
344 |
345 | return this.foundPatternCross(stateCount)?this.centerFromEnd(stateCount, j):NaN;
346 | }
347 | this.handlePossibleCenter=function( stateCount, i, j)
348 | {
349 | var stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];
350 | var centerJ = this.centerFromEnd(stateCount, j); //float
351 | var centerI = this.crossCheckVertical(i, Math.floor( centerJ), stateCount[2], stateCountTotal); //float
352 | if (!isNaN(centerI))
353 | {
354 | // Re-cross check
355 | centerJ = this.crossCheckHorizontal(Math.floor( centerJ), Math.floor( centerI), stateCount[2], stateCountTotal);
356 | if (!isNaN(centerJ))
357 | {
358 | var estimatedModuleSize = stateCountTotal / 7.0;
359 | var found = false;
360 | var max = this.possibleCenters.length;
361 | for (var index = 0; index < max; index++)
362 | {
363 | var center = this.possibleCenters[index];
364 | // Look for about the same center and module size:
365 | if (center.aboutEquals(estimatedModuleSize, centerI, centerJ))
366 | {
367 | center.incrementCount();
368 | found = true;
369 | break;
370 | }
371 | }
372 | if (!found)
373 | {
374 | var point = new FinderPattern(centerJ, centerI, estimatedModuleSize);
375 | this.possibleCenters.push(point);
376 | if (this.resultPointCallback != null)
377 | {
378 | this.resultPointCallback.foundPossibleResultPoint(point);
379 | }
380 | }
381 | return true;
382 | }
383 | }
384 | return false;
385 | }
386 |
387 | this.selectBestPatterns=function()
388 | {
389 |
390 | var startSize = this.possibleCenters.length;
391 | if (startSize < 3)
392 | {
393 | // Couldn't find enough finder patterns
394 | throw "Couldn't find enough finder patterns";
395 | }
396 |
397 | // Filter outlier possibilities whose module size is too different
398 | if (startSize > 3)
399 | {
400 | // But we can only afford to do so if we have at least 4 possibilities to choose from
401 | var totalModuleSize = 0.0;
402 | var square = 0.0;
403 | for (var i = 0; i < startSize; i++)
404 | {
405 | //totalModuleSize += this.possibleCenters[i].EstimatedModuleSize;
406 | var centerValue=this.possibleCenters[i].EstimatedModuleSize;
407 | totalModuleSize += centerValue;
408 | square += (centerValue * centerValue);
409 | }
410 | var average = totalModuleSize / startSize;
411 | this.possibleCenters.sort(function(center1,center2) {
412 | var dA=Math.abs(center2.EstimatedModuleSize - average);
413 | var dB=Math.abs(center1.EstimatedModuleSize - average);
414 | if (dA < dB) {
415 | return (-1);
416 | } else if (dA == dB) {
417 | return 0;
418 | } else {
419 | return 1;
420 | }
421 | });
422 |
423 | var stdDev = Math.sqrt(square / startSize - average * average);
424 | var limit = Math.max(0.2 * average, stdDev);
425 | for (var i = this.possibleCenters.length - 1; i >= 0 ; i--)
426 | {
427 | var pattern = this.possibleCenters[i];
428 | //if (Math.abs(pattern.EstimatedModuleSize - average) > 0.2 * average)
429 | if (Math.abs(pattern.EstimatedModuleSize - average) > limit)
430 | {
431 | this.possibleCenters.remove(i);
432 | }
433 | }
434 | }
435 |
436 | if (this.possibleCenters.length > 3)
437 | {
438 | // Throw away all but those first size candidate points we found.
439 | this.possibleCenters.sort(function(a, b){
440 | if (a.count > b.count){return -1;}
441 | if (a.count < b.count){return 1;}
442 | return 0;
443 | });
444 | }
445 |
446 | return new Array( this.possibleCenters[0], this.possibleCenters[1], this.possibleCenters[2]);
447 | }
448 |
449 | this.findRowSkip=function()
450 | {
451 | var max = this.possibleCenters.length;
452 | if (max <= 1)
453 | {
454 | return 0;
455 | }
456 | var firstConfirmedCenter = null;
457 | for (var i = 0; i < max; i++)
458 | {
459 | var center = this.possibleCenters[i];
460 | if (center.Count >= CENTER_QUORUM)
461 | {
462 | if (firstConfirmedCenter == null)
463 | {
464 | firstConfirmedCenter = center;
465 | }
466 | else
467 | {
468 | // We have two confirmed centers
469 | // How far down can we skip before resuming looking for the next
470 | // pattern? In the worst case, only the difference between the
471 | // difference in the x / y coordinates of the two centers.
472 | // This is the case where you find top left last.
473 | this.hasSkipped = true;
474 | return Math.floor ((Math.abs(firstConfirmedCenter.X - center.X) - Math.abs(firstConfirmedCenter.Y - center.Y)) / 2);
475 | }
476 | }
477 | }
478 | return 0;
479 | }
480 |
481 | this.haveMultiplyConfirmedCenters=function()
482 | {
483 | var confirmedCount = 0;
484 | var totalModuleSize = 0.0;
485 | var max = this.possibleCenters.length;
486 | for (var i = 0; i < max; i++)
487 | {
488 | var pattern = this.possibleCenters[i];
489 | if (pattern.Count >= CENTER_QUORUM)
490 | {
491 | confirmedCount++;
492 | totalModuleSize += pattern.EstimatedModuleSize;
493 | }
494 | }
495 | if (confirmedCount < 3)
496 | {
497 | return false;
498 | }
499 | // OK, we have at least 3 confirmed centers, but, it's possible that one is a "false positive"
500 | // and that we need to keep looking. We detect this by asking if the estimated module sizes
501 | // vary too much. We arbitrarily say that when the total deviation from average exceeds
502 | // 5% of the total module size estimates, it's too much.
503 | var average = totalModuleSize / max;
504 | var totalDeviation = 0.0;
505 | for (var i = 0; i < max; i++)
506 | {
507 | pattern = this.possibleCenters[i];
508 | totalDeviation += Math.abs(pattern.EstimatedModuleSize - average);
509 | }
510 | return totalDeviation <= 0.05 * totalModuleSize;
511 | }
512 |
513 | this.findFinderPattern = function(image){
514 | var tryHarder = false;
515 | this.image=image;
516 | var maxI = qrcode.height;
517 | var maxJ = qrcode.width;
518 | var iSkip = Math.floor((3 * maxI) / (4 * MAX_MODULES));
519 | if (iSkip < MIN_SKIP || tryHarder)
520 | {
521 | iSkip = MIN_SKIP;
522 | }
523 |
524 | var done = false;
525 | var stateCount = new Array(5);
526 | for (var i = iSkip - 1; i < maxI && !done; i += iSkip)
527 | {
528 | // Get a row of black/white values
529 | stateCount[0] = 0;
530 | stateCount[1] = 0;
531 | stateCount[2] = 0;
532 | stateCount[3] = 0;
533 | stateCount[4] = 0;
534 | var currentState = 0;
535 | for (var j = 0; j < maxJ; j++)
536 | {
537 | if (image[j+i*qrcode.width] )
538 | {
539 | // Black pixel
540 | if ((currentState & 1) == 1)
541 | {
542 | // Counting white pixels
543 | currentState++;
544 | }
545 | stateCount[currentState]++;
546 | }
547 | else
548 | {
549 | // White pixel
550 | if ((currentState & 1) == 0)
551 | {
552 | // Counting black pixels
553 | if (currentState == 4)
554 | {
555 | // A winner?
556 | if (this.foundPatternCross(stateCount))
557 | {
558 | // Yes
559 | var confirmed = this.handlePossibleCenter(stateCount, i, j);
560 | if (confirmed)
561 | {
562 | // Start examining every other line. Checking each line turned out to be too
563 | // expensive and didn't improve performance.
564 | iSkip = 2;
565 | if (this.hasSkipped)
566 | {
567 | done = this.haveMultiplyConfirmedCenters();
568 | }
569 | else
570 | {
571 | var rowSkip = this.findRowSkip();
572 | if (rowSkip > stateCount[2])
573 | {
574 | // Skip rows between row of lower confirmed center
575 | // and top of presumed third confirmed center
576 | // but back up a bit to get a full chance of detecting
577 | // it, entire width of center of finder pattern
578 |
579 | // Skip by rowSkip, but back off by stateCount[2] (size of last center
580 | // of pattern we saw) to be conservative, and also back off by iSkip which
581 | // is about to be re-added
582 | i += rowSkip - stateCount[2] - iSkip;
583 | j = maxJ - 1;
584 | }
585 | }
586 | }
587 | else
588 | {
589 | // Advance to next black pixel
590 | do
591 | {
592 | j++;
593 | }
594 | while (j < maxJ && !image[j + i*qrcode.width]);
595 | j--; // back up to that last white pixel
596 | }
597 | // Clear state to start looking again
598 | currentState = 0;
599 | stateCount[0] = 0;
600 | stateCount[1] = 0;
601 | stateCount[2] = 0;
602 | stateCount[3] = 0;
603 | stateCount[4] = 0;
604 | }
605 | else
606 | {
607 | // No, shift counts back by two
608 | stateCount[0] = stateCount[2];
609 | stateCount[1] = stateCount[3];
610 | stateCount[2] = stateCount[4];
611 | stateCount[3] = 1;
612 | stateCount[4] = 0;
613 | currentState = 3;
614 | }
615 | }
616 | else
617 | {
618 | stateCount[++currentState]++;
619 | }
620 | }
621 | else
622 | {
623 | // Counting white pixels
624 | stateCount[currentState]++;
625 | }
626 | }
627 | }
628 | if (this.foundPatternCross(stateCount))
629 | {
630 | var confirmed = this.handlePossibleCenter(stateCount, i, maxJ);
631 | if (confirmed)
632 | {
633 | iSkip = stateCount[0];
634 | if (this.hasSkipped)
635 | {
636 | // Found a third one
637 | done = haveMultiplyConfirmedCenters();
638 | }
639 | }
640 | }
641 | }
642 |
643 | var patternInfo = this.selectBestPatterns();
644 | qrcode.orderBestPatterns(patternInfo);
645 |
646 | return new FinderPatternInfo(patternInfo);
647 | };
648 | }
649 |
--------------------------------------------------------------------------------
/js/zepto.min.js:
--------------------------------------------------------------------------------
1 | /* Zepto v1.1.2 - zepto event ajax form ie - zeptojs.com/license */
2 | var Zepto=function(){function G(a){return a==null?String(a):z[A.call(a)]||"object"}function H(a){return G(a)=="function"}function I(a){return a!=null&&a==a.window}function J(a){return a!=null&&a.nodeType==a.DOCUMENT_NODE}function K(a){return G(a)=="object"}function L(a){return K(a)&&!I(a)&&Object.getPrototypeOf(a)==Object.prototype}function M(a){return a instanceof Array}function N(a){return typeof a.length=="number"}function O(a){return g.call(a,function(a){return a!=null})}function P(a){return a.length>0?c.fn.concat.apply([],a):a}function Q(a){return a.replace(/::/g,"/").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/_/g,"-").toLowerCase()}function R(a){return a in j?j[a]:j[a]=new RegExp("(^|\\s)"+a+"(\\s|$)")}function S(a,b){return typeof b=="number"&&!k[Q(a)]?b+"px":b}function T(a){var b,c;return i[a]||(b=h.createElement(a),h.body.appendChild(b),c=getComputedStyle(b,"").getPropertyValue("display"),b.parentNode.removeChild(b),c=="none"&&(c="block"),i[a]=c),i[a]}function U(a){return"children"in a?f.call(a.children):c.map(a.childNodes,function(a){if(a.nodeType==1)return a})}function V(c,d,e){for(b in d)e&&(L(d[b])||M(d[b]))?(L(d[b])&&!L(c[b])&&(c[b]={}),M(d[b])&&!M(c[b])&&(c[b]=[]),V(c[b],d[b],e)):d[b]!==a&&(c[b]=d[b])}function W(a,b){return b==null?c(a):c(a).filter(b)}function X(a,b,c,d){return H(b)?b.call(a,c,d):b}function Y(a,b,c){c==null?a.removeAttribute(b):a.setAttribute(b,c)}function Z(b,c){var d=b.className,e=d&&d.baseVal!==a;if(c===a)return e?d.baseVal:d;e?d.baseVal=c:b.className=c}function $(a){var b;try{return a?a=="true"||(a=="false"?!1:a=="null"?null:!/^0/.test(a)&&!isNaN(b=Number(a))?b:/^[\[\{]/.test(a)?c.parseJSON(a):a):a}catch(d){return a}}function _(a,b){b(a);for(var c in a.childNodes)_(a.childNodes[c],b)}var a,b,c,d,e=[],f=e.slice,g=e.filter,h=window.document,i={},j={},k={"column-count":1,columns:1,"font-weight":1,"line-height":1,opacity:1,"z-index":1,zoom:1},l=/^\s*<(\w+|!)[^>]*>/,m=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,n=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,o=/^(?:body|html)$/i,p=/([A-Z])/g,q=["val","css","html","text","data","width","height","offset"],r=["after","prepend","before","append"],s=h.createElement("table"),t=h.createElement("tr"),u={tr:h.createElement("tbody"),tbody:s,thead:s,tfoot:s,td:t,th:t,"*":h.createElement("div")},v=/complete|loaded|interactive/,w=/^\.([\w-]+)$/,x=/^#([\w-]*)$/,y=/^[\w-]*$/,z={},A=z.toString,B={},C,D,E=h.createElement("div"),F={tabindex:"tabIndex",readonly:"readOnly","for":"htmlFor","class":"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"};return B.matches=function(a,b){if(!b||!a||a.nodeType!==1)return!1;var c=a.webkitMatchesSelector||a.mozMatchesSelector||a.oMatchesSelector||a.matchesSelector;if(c)return c.call(a,b);var d,e=a.parentNode,f=!e;return f&&(e=E).appendChild(a),d=~B.qsa(e,b).indexOf(a),f&&E.removeChild(a),d},C=function(a){return a.replace(/-+(.)?/g,function(a,b){return b?b.toUpperCase():""})},D=function(a){return g.call(a,function(b,c){return a.indexOf(b)==c})},B.fragment=function(b,d,e){var g,i,j;return m.test(b)&&(g=c(h.createElement(RegExp.$1))),g||(b.replace&&(b=b.replace(n,"<$1>$2>")),d===a&&(d=l.test(b)&&RegExp.$1),d in u||(d="*"),j=u[d],j.innerHTML=""+b,g=c.each(f.call(j.childNodes),function(){j.removeChild(this)})),L(e)&&(i=c(g),c.each(e,function(a,b){q.indexOf(a)>-1?i[a](b):i.attr(a,b)})),g},B.Z=function(a,b){return a=a||[],a.__proto__=c.fn,a.selector=b||"",a},B.isZ=function(a){return a instanceof B.Z},B.init=function(b,d){var e;if(!b)return B.Z();if(typeof b=="string"){b=b.trim();if(b[0]=="<"&&l.test(b))e=B.fragment(b,RegExp.$1,d),b=null;else{if(d!==a)return c(d).find(b);e=B.qsa(h,b)}}else{if(H(b))return c(h).ready(b);if(B.isZ(b))return b;if(M(b))e=O(b);else if(K(b))e=[b],b=null;else if(l.test(b))e=B.fragment(b.trim(),RegExp.$1,d),b=null;else{if(d!==a)return c(d).find(b);e=B.qsa(h,b)}}return B.Z(e,b)},c=function(a,b){return B.init(a,b)},c.extend=function(a){var b,c=f.call(arguments,1);return typeof a=="boolean"&&(b=a,a=c.shift()),c.forEach(function(c){V(a,c,b)}),a},B.qsa=function(a,b){var c,d=b[0]=="#",e=!d&&b[0]==".",g=d||e?b.slice(1):b,h=y.test(g);return J(a)&&h&&d?(c=a.getElementById(g))?[c]:[]:a.nodeType!==1&&a.nodeType!==9?[]:f.call(h&&!d?e?a.getElementsByClassName(g):a.getElementsByTagName(b):a.querySelectorAll(b))},c.contains=function(a,b){return a!==b&&a.contains(b)},c.type=G,c.isFunction=H,c.isWindow=I,c.isArray=M,c.isPlainObject=L,c.isEmptyObject=function(a){var b;for(b in a)return!1;return!0},c.inArray=function(a,b,c){return e.indexOf.call(b,a,c)},c.camelCase=C,c.trim=function(a){return a==null?"":String.prototype.trim.call(a)},c.uuid=0,c.support={},c.expr={},c.map=function(a,b){var c,d=[],e,f;if(N(a))for(e=0;e=0?b:b+this.length]},toArray:function(){return this.get()},size:function(){return this.length},remove:function(){return this.each(function(){this.parentNode!=null&&this.parentNode.removeChild(this)})},each:function(a){return e.every.call(this,function(b,c){return a.call(b,c,b)!==!1}),this},filter:function(a){return H(a)?this.not(this.not(a)):c(g.call(this,function(b){return B.matches(b,a)}))},add:function(a,b){return c(D(this.concat(c(a,b))))},is:function(a){return this.length>0&&B.matches(this[0],a)},not:function(b){var d=[];if(H(b)&&b.call!==a)this.each(function(a){b.call(this,a)||d.push(this)});else{var e=typeof b=="string"?this.filter(b):N(b)&&H(b.item)?f.call(b):c(b);this.forEach(function(a){e.indexOf(a)<0&&d.push(a)})}return c(d)},has:function(a){return this.filter(function(){return K(a)?c.contains(this,a):c(this).find(a).size()})},eq:function(a){return a===-1?this.slice(a):this.slice(a,+a+1)},first:function(){var a=this[0];return a&&!K(a)?a:c(a)},last:function(){var a=this[this.length-1];return a&&!K(a)?a:c(a)},find:function(a){var b,d=this;return typeof a=="object"?b=c(a).filter(function(){var a=this;return e.some.call(d,function(b){return c.contains(b,a)})}):this.length==1?b=c(B.qsa(this[0],a)):b=this.map(function(){return B.qsa(this,a)}),b},closest:function(a,b){var d=this[0],e=!1;typeof a=="object"&&(e=c(a));while(d&&!(e?e.indexOf(d)>=0:B.matches(d,a)))d=d!==b&&!J(d)&&d.parentNode;return c(d)},parents:function(a){var b=[],d=this;while(d.length>0)d=c.map(d,function(a){if((a=a.parentNode)&&!J(a)&&b.indexOf(a)<0)return b.push(a),a});return W(b,a)},parent:function(a){return W(D(this.pluck("parentNode")),a)},children:function(a){return W(this.map(function(){return U(this)}),a)},contents:function(){return this.map(function(){return f.call(this.childNodes)})},siblings:function(a){return W(this.map(function(a,b){return g.call(U(b.parentNode),function(a){return a!==b})}),a)},empty:function(){return this.each(function(){this.innerHTML=""})},pluck:function(a){return c.map(this,function(b){return b[a]})},show:function(){return this.each(function(){this.style.display=="none"&&(this.style.display=""),getComputedStyle(this,"").getPropertyValue("display")=="none"&&(this.style.display=T(this.nodeName))})},replaceWith:function(a){return this.before(a).remove()},wrap:function(a){var b=H(a);if(this[0]&&!b)var d=c(a).get(0),e=d.parentNode||this.length>1;return this.each(function(f){c(this).wrapAll(b?a.call(this,f):e?d.cloneNode(!0):d)})},wrapAll:function(a){if(this[0]){c(this[0]).before(a=c(a));var b;while((b=a.children()).length)a=b.first();c(a).append(this)}return this},wrapInner:function(a){var b=H(a);return this.each(function(d){var e=c(this),f=e.contents(),g=b?a.call(this,d):a;f.length?f.wrapAll(g):e.append(g)})},unwrap:function(){return this.parent().each(function(){c(this).replaceWith(c(this).children())}),this},clone:function(){return this.map(function(){return this.cloneNode(!0)})},hide:function(){return this.css("display","none")},toggle:function(b){return this.each(function(){var d=c(this);(b===a?d.css("display")=="none":b)?d.show():d.hide()})},prev:function(a){return c(this.pluck("previousElementSibling")).filter(a||"*")},next:function(a){return c(this.pluck("nextElementSibling")).filter(a||"*")},html:function(a){return arguments.length===0?this.length>0?this[0].innerHTML:null:this.each(function(b){var d=this.innerHTML;c(this).empty().append(X(this,a,b,d))})},text:function(b){return arguments.length===0?this.length>0?this[0].textContent:null:this.each(function(){this.textContent=b===a?"":""+b})},attr:function(c,d){var e;return typeof c=="string"&&d===a?this.length==0||this[0].nodeType!==1?a:c=="value"&&this[0].nodeName=="INPUT"?this.val():!(e=this[0].getAttribute(c))&&c in this[0]?this[0][c]:e:this.each(function(a){if(this.nodeType!==1)return;if(K(c))for(b in c)Y(this,b,c[b]);else Y(this,c,X(this,d,a,this.getAttribute(c)))})},removeAttr:function(a){return this.each(function(){this.nodeType===1&&Y(this,a)})},prop:function(b,c){return b=F[b]||b,c===a?this[0]&&this[0][b]:this.each(function(a){this[b]=X(this,c,a,this[b])})},data:function(b,c){var d=this.attr("data-"+b.replace(p,"-$1").toLowerCase(),c);return d!==null?$(d):a},val:function(a){return arguments.length===0?this[0]&&(this[0].multiple?c(this[0]).find("option").filter(function(){return this.selected}).pluck("value"):this[0].value):this.each(function(b){this.value=X(this,a,b,this.value)})},offset:function(a){if(a)return this.each(function(b){var d=c(this),e=X(this,a,b,d.offset()),f=d.offsetParent().offset(),g={top:e.top-f.top,left:e.left-f.left};d.css("position")=="static"&&(g.position="relative"),d.css(g)});if(this.length==0)return null;var b=this[0].getBoundingClientRect();return{left:b.left+window.pageXOffset,top:b.top+window.pageYOffset,width:Math.round(b.width),height:Math.round(b.height)}},css:function(a,d){if(arguments.length<2){var e=this[0],f=getComputedStyle(e,"");if(!e)return;if(typeof a=="string")return e.style[C(a)]||f.getPropertyValue(a);if(M(a)){var g={};return c.each(M(a)?a:[a],function(a,b){g[b]=e.style[C(b)]||f.getPropertyValue(b)}),g}}var h="";if(G(a)=="string")!d&&d!==0?this.each(function(){this.style.removeProperty(Q(a))}):h=Q(a)+":"+S(a,d);else for(b in a)!a[b]&&a[b]!==0?this.each(function(){this.style.removeProperty(Q(b))}):h+=Q(b)+":"+S(b,a[b])+";";return this.each(function(){this.style.cssText+=";"+h})},index:function(a){return a?this.indexOf(c(a)[0]):this.parent().children().indexOf(this[0])},hasClass:function(a){return a?e.some.call(this,function(a){return this.test(Z(a))},R(a)):!1},addClass:function(a){return a?this.each(function(b){d=[];var e=Z(this),f=X(this,a,b,e);f.split(/\s+/g).forEach(function(a){c(this).hasClass(a)||d.push(a)},this),d.length&&Z(this,e+(e?" ":"")+d.join(" "))}):this},removeClass:function(b){return this.each(function(c){if(b===a)return Z(this,"");d=Z(this),X(this,b,c,d).split(/\s+/g).forEach(function(a){d=d.replace(R(a)," ")}),Z(this,d.trim())})},toggleClass:function(b,d){return b?this.each(function(e){var f=c(this),g=X(this,b,e,Z(this));g.split(/\s+/g).forEach(function(b){(d===a?!f.hasClass(b):d)?f.addClass(b):f.removeClass(b)})}):this},scrollTop:function(b){if(!this.length)return;var c="scrollTop"in this[0];return b===a?c?this[0].scrollTop:this[0].pageYOffset:this.each(c?function(){this.scrollTop=b}:function(){this.scrollTo(this.scrollX,b)})},scrollLeft:function(b){if(!this.length)return;var c="scrollLeft"in this[0];return b===a?c?this[0].scrollLeft:this[0].pageXOffset:this.each(c?function(){this.scrollLeft=b}:function(){this.scrollTo(b,this.scrollY)})},position:function(){if(!this.length)return;var a=this[0],b=this.offsetParent(),d=this.offset(),e=o.test(b[0].nodeName)?{top:0,left:0}:b.offset();return d.top-=parseFloat(c(a).css("margin-top"))||0,d.left-=parseFloat(c(a).css("margin-left"))||0,e.top+=parseFloat(c(b[0]).css("border-top-width"))||0,e.left+=parseFloat(c(b[0]).css("border-left-width"))||0,{top:d.top-e.top,left:d.left-e.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||h.body;while(a&&!o.test(a.nodeName)&&c(a).css("position")=="static")a=a.offsetParent;return a})}},c.fn.detach=c.fn.remove,["width","height"].forEach(function(b){var d=b.replace(/./,function(a){return a[0].toUpperCase()});c.fn[b]=function(e){var f,g=this[0];return e===a?I(g)?g["inner"+d]:J(g)?g.documentElement["scroll"+d]:(f=this.offset())&&f[b]:this.each(function(a){g=c(this),g.css(b,X(this,e,a,g[b]()))})}}),r.forEach(function(a,b){var d=b%2;c.fn[a]=function(){var a,e=c.map(arguments,function(b){return a=G(b),a=="object"||a=="array"||b==null?b:B.fragment(b)}),f,g=this.length>1;return e.length<1?this:this.each(function(a,h){f=d?h:h.parentNode,h=b==0?h.nextSibling:b==1?h.firstChild:b==2?h:null,e.forEach(function(a){if(g)a=a.cloneNode(!0);else if(!f)return c(a).remove();_(f.insertBefore(a,h),function(a){a.nodeName!=null&&a.nodeName.toUpperCase()==="SCRIPT"&&(!a.type||a.type==="text/javascript")&&!a.src&&window.eval.call(window,a.innerHTML)})})})},c.fn[d?a+"To":"insert"+(b?"Before":"After")]=function(b){return c(b)[a](this),this}}),B.Z.prototype=c.fn,B.uniq=D,B.deserializeValue=$,c.zepto=B,c}();window.Zepto=Zepto,window.$===undefined&&(window.$=Zepto),function(a){function m(a){return a._zid||(a._zid=c++)}function n(a,b,c,d){b=o(b);if(b.ns)var e=p(b.ns);return(h[m(a)]||[]).filter(function(a){return a&&(!b.e||a.e==b.e)&&(!b.ns||e.test(a.ns))&&(!c||m(a.fn)===m(c))&&(!d||a.sel==d)})}function o(a){var b=(""+a).split(".");return{e:b[0],ns:b.slice(1).sort().join(" ")}}function p(a){return new RegExp("(?:^| )"+a.replace(" "," .* ?")+"(?: |$)")}function q(a,b){return a.del&&!j&&a.e in k||!!b}function r(a){return l[a]||j&&k[a]||a}function s(b,c,e,f,g,i,j){var k=m(b),n=h[k]||(h[k]=[]);c.split(/\s/).forEach(function(c){if(c=="ready")return a(document).ready(e);var h=o(c);h.fn=e,h.sel=g,h.e in l&&(e=function(b){var c=b.relatedTarget;if(!c||c!==this&&!a.contains(this,c))return h.fn.apply(this,arguments)}),h.del=i;var k=i||e;h.proxy=function(a){a=y(a);if(a.isImmediatePropagationStopped())return;a.data=f;var c=k.apply(b,a._args==d?[a]:[a].concat(a._args));return c===!1&&(a.preventDefault(),a.stopPropagation()),c},h.i=n.length,n.push(h),"addEventListener"in b&&b.addEventListener(r(h.e),h.proxy,q(h,j))})}function t(a,b,c,d,e){var f=m(a);(b||"").split(/\s/).forEach(function(b){n(a,b,c,d).forEach(function(b){delete h[f][b.i],"removeEventListener"in a&&a.removeEventListener(r(b.e),b.proxy,q(b,e))})})}function y(b,c){if(c||!b.isDefaultPrevented){c||(c=b),a.each(x,function(a,d){var e=c[a];b[a]=function(){return this[d]=u,e&&e.apply(c,arguments)},b[d]=v});if(c.defaultPrevented!==d?c.defaultPrevented:"returnValue"in c?c.returnValue===!1:c.getPreventDefault&&c.getPreventDefault())b.isDefaultPrevented=u}return b}function z(a){var b,c={originalEvent:a};for(b in a)!w.test(b)&&a[b]!==d&&(c[b]=a[b]);return y(c,a)}var b=a.zepto.qsa,c=1,d,e=Array.prototype.slice,f=a.isFunction,g=function(a){return typeof a=="string"},h={},i={},j="onfocusin"in window,k={focus:"focusin",blur:"focusout"},l={mouseenter:"mouseover",mouseleave:"mouseout"};i.click=i.mousedown=i.mouseup=i.mousemove="MouseEvents",a.event={add:s,remove:t},a.proxy=function(b,c){if(f(b)){var d=function(){return b.apply(c,arguments)};return d._zid=m(b),d}if(g(c))return a.proxy(b[c],b);throw new TypeError("expected function")},a.fn.bind=function(a,b,c){return this.on(a,b,c)},a.fn.unbind=function(a,b){return this.off(a,b)},a.fn.one=function(a,b,c,d){return this.on(a,b,c,d,1)};var u=function(){return!0},v=function(){return!1},w=/^([A-Z]|returnValue$|layer[XY]$)/,x={preventDefault:"isDefaultPrevented",stopImmediatePropagation:"isImmediatePropagationStopped",stopPropagation:"isPropagationStopped"};a.fn.delegate=function(a,b,c){return this.on(b,a,c)},a.fn.undelegate=function(a,b,c){return this.off(b,a,c)},a.fn.live=function(b,c){return a(document.body).delegate(this.selector,b,c),this},a.fn.die=function(b,c){return a(document.body).undelegate(this.selector,b,c),this},a.fn.on=function(b,c,h,i,j){var k,l,m=this;if(b&&!g(b))return a.each(b,function(a,b){m.on(a,c,h,b,j)}),m;!g(c)&&!f(i)&&i!==!1&&(i=h,h=c,c=d);if(f(h)||h===!1)i=h,h=d;return i===!1&&(i=v),m.each(function(d,f){j&&(k=function(a){return t(f,a.type,i),i.apply(this,arguments)}),c&&(l=function(b){var d,g=a(b.target).closest(c,f).get(0);if(g&&g!==f)return d=a.extend(z(b),{currentTarget:g,liveFired:f}),(k||i).apply(g,[d].concat(e.call(arguments,1)))}),s(f,b,i,h,c,l||k)})},a.fn.off=function(b,c,e){var h=this;return b&&!g(b)?(a.each(b,function(a,b){h.off(a,c,b)}),h):(!g(c)&&!f(e)&&e!==!1&&(e=c,c=d),e===!1&&(e=v),h.each(function(){t(this,b,e,c)}))},a.fn.trigger=function(b,c){return b=g(b)||a.isPlainObject(b)?a.Event(b):y(b),b._args=c,this.each(function(){"dispatchEvent"in this?this.dispatchEvent(b):a(this).triggerHandler(b,c)})},a.fn.triggerHandler=function(b,c){var d,e;return this.each(function(f,h){d=z(g(b)?a.Event(b):b),d._args=c,d.target=h,a.each(n(h,b.type||b),function(a,b){e=b.proxy(d);if(d.isImmediatePropagationStopped())return!1})}),e},"focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select keydown keypress keyup error".split(" ").forEach(function(b){a.fn[b]=function(a){return a?this.bind(b,a):this.trigger(b)}}),["focus","blur"].forEach(function(b){a.fn[b]=function(a){return a?this.bind(b,a):this.each(function(){try{this[b]()}catch(a){}}),this}}),a.Event=function(a,b){g(a)||(b=a,a=b.type);var c=document.createEvent(i[a]||"Events"),d=!0;if(b)for(var e in b)e=="bubbles"?d=!!b[e]:c[e]=b[e];return c.initEvent(a,d,!0),y(c)}}(Zepto),function($){function triggerAndReturn(a,b,c){var d=$.Event(b);return $(a).trigger(d,c),!d.isDefaultPrevented()}function triggerGlobal(a,b,c,d){if(a.global)return triggerAndReturn(b||document,c,d)}function ajaxStart(a){a.global&&$.active++===0&&triggerGlobal(a,null,"ajaxStart")}function ajaxStop(a){a.global&&!--$.active&&triggerGlobal(a,null,"ajaxStop")}function ajaxBeforeSend(a,b){var c=b.context;if(b.beforeSend.call(c,a,b)===!1||triggerGlobal(b,c,"ajaxBeforeSend",[a,b])===!1)return!1;triggerGlobal(b,c,"ajaxSend",[a,b])}function ajaxSuccess(a,b,c,d){var e=c.context,f="success";c.success.call(e,a,f,b),d&&d.resolveWith(e,[a,f,b]),triggerGlobal(c,e,"ajaxSuccess",[b,c,a]),ajaxComplete(f,b,c)}function ajaxError(a,b,c,d,e){var f=d.context;d.error.call(f,c,b,a),e&&e.rejectWith(f,[c,b,a]),triggerGlobal(d,f,"ajaxError",[c,d,a||b]),ajaxComplete(b,c,d)}function ajaxComplete(a,b,c){var d=c.context;c.complete.call(d,b,a),triggerGlobal(c,d,"ajaxComplete",[b,c]),ajaxStop(c)}function empty(){}function mimeToDataType(a){return a&&(a=a.split(";",2)[0]),a&&(a==htmlType?"html":a==jsonType?"json":scriptTypeRE.test(a)?"script":xmlTypeRE.test(a)&&"xml")||"text"}function appendQuery(a,b){return b==""?a:(a+"&"+b).replace(/[&?]{1,2}/,"?")}function serializeData(a){a.processData&&a.data&&$.type(a.data)!="string"&&(a.data=$.param(a.data,a.traditional)),a.data&&(!a.type||a.type.toUpperCase()=="GET")&&(a.url=appendQuery(a.url,a.data),a.data=undefined)}function parseArguments(a,b,c,d){var e=!$.isFunction(b);return{url:a,data:e?b:undefined,success:e?$.isFunction(c)?c:undefined:b,dataType:e?d||c:c}}function serialize(a,b,c,d){var e,f=$.isArray(b),g=$.isPlainObject(b);$.each(b,function(b,h){e=$.type(h),d&&(b=c?d:d+"["+(g||e=="object"||e=="array"?b:"")+"]"),!d&&f?a.add(h.name,h.value):e=="array"||!c&&e=="object"?serialize(a,h,c,b):a.add(b,h)})}var jsonpID=0,document=window.document,key,name,rscript=/