From 1110d7608b0dd055524b9d96d1883dc65dcc7b1d Mon Sep 17 00:00:00 2001 From: danimoh Date: Tue, 5 Dec 2017 14:18:41 -0600 Subject: [PATCH] use closure-compiler --- gulpfile.js | 75 ++++++++++++++++-------------------- package.json | 9 +---- qr-scanner-worker.min.js | 67 +++++++++++++++++++++++++++++++- qr-scanner-worker.min.js.map | 2 +- src/alignpat.js | 20 ++++------ src/bitmat.js | 12 +++--- src/bmparser.js | 18 ++++----- src/datablock.js | 20 +++++----- src/databr.js | 4 +- src/decoder.js | 10 ++--- src/detector.js | 42 ++++++++++---------- src/errorlevel.js | 8 ++-- src/findpat.js | 62 ++++++++++++++--------------- src/formatinf.js | 10 ++--- src/gf256.js | 8 ++-- src/gf256poly.js | 38 +++++++++--------- src/prefix.js | 1 - src/qrcode.js | 6 +-- src/rsdecoder.js | 26 ++++++------- src/suffix.js | 1 - src/version.js | 48 +++++++++++------------ 21 files changed, 266 insertions(+), 221 deletions(-) delete mode 100644 src/prefix.js delete mode 100644 src/suffix.js diff --git a/gulpfile.js b/gulpfile.js index 82e45b0..7c28517 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,47 +1,38 @@ var gulp = require('gulp'); -var concat = require('gulp-concat'); var sourcemaps = require('gulp-sourcemaps'); -var babel = require('gulp-babel'); -var merge = require('merge2'); -var uglify = require('gulp-uglify'); +var closureCompiler = require('google-closure-compiler').gulp(); gulp.task('build', function() { - return merge( - gulp.src('./src/prefix.js') - .pipe(sourcemaps.init()), - - gulp.src([ - './src/worker.js', - './src/binarizer.js', - './src/grid.js', - './src/version.js', - './src/detector.js', - './src/formatinf.js', - './src/errorlevel.js', - './src/bitmat.js', - './src/datablock.js', - './src/bmparser.js', - './src/datamask.js', - './src/rsdecoder.js', - './src/gf256poly.js', - './src/gf256.js', - './src/decoder.js', - './src/qrcode.js', - './src/findpat.js', - './src/alignpat.js', - './src/databr.js' - ]) - .pipe(sourcemaps.init()) - .pipe(concat('tmp.js')) - .pipe(babel({ - presets: ['env'] - })), - - gulp.src('./src/suffix.js') - .pipe(sourcemaps.init()) - ) - .pipe(concat('qr-scanner-worker.min.js')) - .pipe(uglify()) - .pipe(sourcemaps.write('.')) - .pipe(gulp.dest('.')); + return gulp.src([ + './src/worker.js', + './src/binarizer.js', + './src/grid.js', + './src/version.js', + './src/detector.js', + './src/formatinf.js', + './src/errorlevel.js', + './src/bitmat.js', + './src/datablock.js', + './src/bmparser.js', + './src/datamask.js', + './src/rsdecoder.js', + './src/gf256poly.js', + './src/gf256.js', + './src/decoder.js', + './src/qrcode.js', + './src/findpat.js', + './src/alignpat.js', + './src/databr.js' + ], { base: './' }) + .pipe(sourcemaps.init()) + .pipe(closureCompiler({ + compilation_level: 'ADVANCED', + warning_level: 'DEFAULT', + language_in: 'ECMASCRIPT6_STRICT', + language_out: 'ECMASCRIPT5_STRICT', + output_wrapper: '(function(){\n%output%\n}).call(this)', + js_output_file: 'qr-scanner-worker.min.js' + })) + .pipe(sourcemaps.write('.')) + .pipe(gulp.dest('.')); }); \ No newline at end of file diff --git a/package.json b/package.json index 34f4199..d46a70f 100644 --- a/package.json +++ b/package.json @@ -25,13 +25,8 @@ }, "homepage": "https://github.com/nimiq/qr-scanner#readme", "devDependencies": { - "babel-core": "^6.26.0", - "babel-preset-env": "^1.6.1", + "google-closure-compiler": "^20171112.0.0", "gulp": "^3.9.1", - "gulp-babel": "^7.0.0", - "gulp-concat": "^2.6.1", - "gulp-sourcemaps": "^2.6.1", - "gulp-uglify": "^3.0.0", - "merge2": "^1.2.0" + "gulp-sourcemaps": "^2.6.1" } } diff --git a/qr-scanner-worker.min.js b/qr-scanner-worker.min.js index 6edd1ae..a6272ce 100644 --- a/qr-scanner-worker.min.js +++ b/qr-scanner-worker.min.js @@ -1,2 +1,67 @@ -!function(){"use strict";function e(e,t){this.count=e,this.dataCodewords=t,this.__defineGetter__("Count",function(){return this.count}),this.__defineGetter__("DataCodewords",function(){return this.dataCodewords})}function t(e,t,r){this.ecCodewordsPerBlock=e,this.ecBlocks=r?new Array(t,r):new Array(t),this.__defineGetter__("ECCodewordsPerBlock",function(){return this.ecCodewordsPerBlock}),this.__defineGetter__("TotalECCodewords",function(){return this.ecCodewordsPerBlock*this.NumBlocks}),this.__defineGetter__("NumBlocks",function(){for(var e=0,t=0;t6&&(t.setRegion(e-11,0,3,6),t.setRegion(0,e-11,6,3)),t},this.getECBlocksForLevel=function(e){return this.ecBlocks[e.ordinal()]}}function n(e,t,r,i,o,s,a,h,w){this.a11=e,this.a12=i,this.a13=a,this.a21=t,this.a22=o,this.a23=h,this.a31=r,this.a32=s,this.a33=w,this.transformPoints1=function(e){for(var t=e.length,r=this.a11,n=this.a12,i=this.a13,o=this.a21,s=this.a22,a=this.a23,h=this.a31,w=this.a32,f=this.a33,u=0;uMath.abs(r-e);if(i){var o=e;e=t,t=o,o=r,r=n,n=o}for(var s=Math.abs(r-e),a=Math.abs(n-t),h=-s>>1,w=t0){if(c==n)break;c+=w,h-=s}}var b=r-e,y=n-t;return Math.sqrt(b*b+y*y)},this.sizeOfBlackWhiteBlackRunBothWays=function(e,t,r,n){var i=this.sizeOfBlackWhiteBlackRun(e,t,r,n),o=1,s=e-(r-e);s<0?(o=e/(e-s),s=0):s>=k.width&&(o=(k.width-1-e)/(s-e),s=k.width-1);var a=Math.floor(t-(n-t)*o);return o=1,a<0?(o=t/(t-a),a=0):a>=k.height&&(o=(k.height-1-t)/(a-t),a=k.height-1),s=Math.floor(e+(s-e)*o),(i+=this.sizeOfBlackWhiteBlackRun(e,t,s,a))-1},this.calculateModuleSizeOneWay=function(e,t){var r=this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(e.X),Math.floor(e.Y),Math.floor(t.X),Math.floor(t.Y)),n=this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(t.X),Math.floor(t.Y),Math.floor(e.X),Math.floor(e.Y));return isNaN(r)?n/7:isNaN(n)?r/7:(r+n)/14},this.calculateModuleSize=function(e,t,r){return(this.calculateModuleSizeOneWay(e,t)+this.calculateModuleSizeOneWay(e,r))/2},this.distance=function(e,t){var r=e.X-t.X,n=e.Y-t.Y;return Math.sqrt(r*r+n*n)},this.computeDimension=function(e,t,r,n){var i=7+(Math.round(this.distance(e,t)/n)+Math.round(this.distance(e,r)/n)>>1);switch(3&i){case 0:i++;break;case 2:i--;break;case 3:throw new Error("QR Error: in detector")}return i},this.findAlignmentInRegion=function(e,t,r,n){var i=Math.floor(n*e),o=Math.max(0,t-i),s=Math.min(k.width-1,t+i);if(s-o<3*e)throw new Error("QR Error: in detector");var a=Math.max(0,r-i),h=Math.min(k.height-1,r+i);return new function(e,t,r,n,i,o,s){this.image=e,this.possibleCenters=new Array,this.startX=t,this.startY=r,this.width=n,this.height=i,this.moduleSize=o,this.crossCheckStateCount=new Array(0,0,0),this.resultPointCallback=s,this.centerFromEnd=function(e,t){return t-e[2]-e[1]/2},this.foundPatternCross=function(e){for(var t=this.moduleSize,r=t/2,n=0;n<3;n++)if(Math.abs(t-e[n])>=r)return!1;return!0},this.crossCheckVertical=function(e,t,r,n){var i=this.image,o=k.height,s=this.crossCheckStateCount;s[0]=0,s[1]=0,s[2]=0;for(var a=e;a>=0&&i[t+a*k.width]&&s[1]<=r;)s[1]++,a--;if(a<0||s[1]>r)return NaN;for(;a>=0&&!i[t+a*k.width]&&s[0]<=r;)s[0]++,a--;if(s[0]>r)return NaN;for(a=e+1;ar)return NaN;for(;ar)return NaN;var h=s[0]+s[1]+s[2];return 5*Math.abs(h-n)>=2*n?NaN:this.foundPatternCross(s)?this.centerFromEnd(s,a):NaN},this.handlePossibleCenter=function(e,t,r){var n=e[0]+e[1]+e[2],i=this.centerFromEnd(e,r),o=this.crossCheckVertical(t,Math.floor(i),2*e[1],n);if(!isNaN(o)){for(var s=(e[0]+e[1]+e[2])/3,a=this.possibleCenters.length,h=0;h>1),a=new Array(0,0,0),h=0;h>1:-(h+1>>1));a[0]=0,a[1]=0,a[2]=0;for(var f=t;f0)for(var f=n.X-t.X+i.X,u=n.Y-t.Y+i.Y,l=1-3/h,c=Math.floor(t.X+l*(f-t.X)),d=Math.floor(t.Y+l*(u-t.Y)),v=4;v<=16;v<<=1)try{w=this.findAlignmentInRegion(o,c,d,v);break}catch(e){}var g,m=this.createTransform(t,n,i,w,s),b=this.sampleGrid(this.image,m,s);return g=null==w?new Array(i,t,n):new Array(i,t,n,w),new function(e,t){this.bits=e,this.points=t}(b,g)},this.detect=function(){var e=(new function(){this.image=null,this.possibleCenters=[],this.hasSkipped=!1,this.crossCheckStateCount=new Array(0,0,0,0,0),this.resultPointCallback=null,this.__defineGetter__("CrossCheckStateCount",function(){return this.crossCheckStateCount[0]=0,this.crossCheckStateCount[1]=0,this.crossCheckStateCount[2]=0,this.crossCheckStateCount[3]=0,this.crossCheckStateCount[4]=0,this.crossCheckStateCount}),this.foundPatternCross=function(e){for(var t=0,r=0;r<5;r++){var n=e[r];if(0==n)return!1;t+=n}if(t<7)return!1;var i=Math.floor(t/7),o=Math.floor(.7*i);return Math.abs(i-e[0])=0&&i[t+a*k.width];)s[2]++,a--;if(a<0)return NaN;for(;a>=0&&!i[t+a*k.width]&&s[1]<=r;)s[1]++,a--;if(a<0||s[1]>r)return NaN;for(;a>=0&&i[t+a*k.width]&&s[0]<=r;)s[0]++,a--;if(s[0]>r)return NaN;for(a=e+1;a=r)return NaN;for(;a=r)return NaN;var h=s[0]+s[1]+s[2]+s[3]+s[4];return 5*Math.abs(h-n)>=2*n?NaN:this.foundPatternCross(s)?this.centerFromEnd(s,a):NaN},this.crossCheckHorizontal=function(e,t,r,n){for(var i=this.image,o=k.width,s=this.CrossCheckStateCount,a=e;a>=0&&i[a+t*k.width];)s[2]++,a--;if(a<0)return NaN;for(;a>=0&&!i[a+t*k.width]&&s[1]<=r;)s[1]++,a--;if(a<0||s[1]>r)return NaN;for(;a>=0&&i[a+t*k.width]&&s[0]<=r;)s[0]++,a--;if(s[0]>r)return NaN;for(a=e+1;a=r)return NaN;for(;a=r)return NaN;var h=s[0]+s[1]+s[2]+s[3]+s[4];return 5*Math.abs(h-n)>=n?NaN:this.foundPatternCross(s)?this.centerFromEnd(s,a):NaN},this.handlePossibleCenter=function(e,t,r){var n=e[0]+e[1]+e[2]+e[3]+e[4],i=this.centerFromEnd(e,r),o=this.crossCheckVertical(t,Math.floor(i),e[2],n);if(!isNaN(o)&&(i=this.crossCheckHorizontal(Math.floor(i),Math.floor(o),e[2],n),!isNaN(i))){for(var s=n/7,a=!1,h=this.possibleCenters.length,w=0;w3){for(var t=0,r=0,n=0;n=0;n--){var h=this.possibleCenters[n];Math.abs(h.EstimatedModuleSize-o)>a&&this.possibleCenters.splice(n,1)}}return this.possibleCenters.length>3&&this.possibleCenters.sort(function(e,t){return e.count>t.count?-1:e.count=P){if(null!=t)return this.hasSkipped=!0,Math.floor((Math.abs(t.X-n.X)-Math.abs(t.Y-n.Y))/2);t=n}}return 0},this.haveMultiplyConfirmedCenters=function(){for(var e=0,t=0,r=this.possibleCenters.length,n=0;n=P&&(e++,t+=i.EstimatedModuleSize)}if(e<3)return!1;for(var o=t/r,s=0,n=0;no[2]&&(s+=w-o[2]-n,h=r-1)}else{do{h++}while(h>3&3),this.dataMask=7&e,this.__defineGetter__("ErrorCorrectionLevel",function(){return this.errorCorrectionLevel}),this.__defineGetter__("DataMask",function(){return this.dataMask}),this.GetHashCode=function(){return this.errorCorrectionLevel.ordinal()<<3|this.dataMask},this.Equals=function(e){var t=e;return this.errorCorrectionLevel==t.errorCorrectionLevel&&this.dataMask==t.dataMask}}function s(e,t,r){this.ordinal_Renamed_Field=e,this.bits=t,this.name=r,this.__defineGetter__("Bits",function(){return this.bits}),this.__defineGetter__("Name",function(){return this.name}),this.ordinal=function(){return this.ordinal_Renamed_Field}}function a(e,t){if(t||(t=e),e<1||t<1)throw new Error("QR Error: Both dimensions must be greater than 0");this.width=e,this.height=t;var r=e>>5;0!=(31&e)&&r++,this.rowSize=r,this.bits=new Array(r*t);for(var n=0;n>5);return 0!=(1&u(this.bits[r],31&e))},this.set_Renamed=function(e,t){var r=t*this.rowSize+(e>>5);this.bits[r]|=1<<(31&e)},this.flip=function(e,t){var r=t*this.rowSize+(e>>5);this.bits[r]^=1<<(31&e)},this.clear=function(){for(var e=this.bits.length,t=0;tthis.height||i>this.width)throw new Error("QR Error: The region must fit inside the matrix");for(var s=t;s>5)]|=1<<(31&h)}}function h(e,t){this.numDataCodewords=e,this.codewords=t,this.__defineGetter__("NumDataCodewords",function(){return this.numDataCodewords}),this.__defineGetter__("Codewords",function(){return this.codewords})}function w(e,t){if(null==t||0==t.length)throw new Error("QR Error: System.ArgumentException");this.field=e;var r=t.length;if(r>1&&0==t[0]){for(var n=1;nn.length){var i=r;r=n,n=i}for(var o=new Array(n.length),s=n.length-r.length,a=0;a=e.Degree&&!r.Zero;){var o=r.Degree-e.Degree,s=this.field.multiply(r.getCoefficient(r.Degree),i),a=e.multiplyByMonomial(o,s),h=this.field.buildMonomial(o,s);t=t.addOrSubtract(h),r=r.addOrSubtract(a)}return new Array(t,r)}}function f(e){this.expTable=new Array(256),this.logTable=new Array(256);for(var t=1,r=0;r<256;r++)this.expTable[r]=t,(t<<=1)>=256&&(t^=e);for(r=0;r<255;r++)this.logTable[this.expTable[r]]=r;var n=new Array(1);n[0]=0,this.zero=new w(this,new Array(n));var i=new Array(1);i[0]=1,this.one=new w(this,new Array(i)),this.__defineGetter__("Zero",function(){return this.zero}),this.__defineGetter__("One",function(){return this.one}),this.buildMonomial=function(e,t){if(e<0)throw new Error("QR Error: System.ArgumentException");if(0==t)return this.zero;for(var r=new Array(e+1),n=0;n=0?e>>t:(e>>t)+(2<<~t)}function l(e,t,r){this.x=e,this.y=t,this.count=1,this.estimatedModuleSize=r,this.__defineGetter__("EstimatedModuleSize",function(){return this.estimatedModuleSize}),this.__defineGetter__("Count",function(){return this.count}),this.__defineGetter__("X",function(){return Math.floor(this.x)}),this.__defineGetter__("Y",function(){return Math.floor(this.y)}),this.incrementCount=function(){this.count++},this.aboutEquals=function(e,t,r){if(Math.abs(t-this.y)<=e&&Math.abs(r-this.x)<=e){var n=Math.abs(e-this.estimatedModuleSize);return n<=1||n/this.estimatedModuleSize<=1}return!1}}var c=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],n=!0,i=!1,o=void 0;try{for(var s,a=e[Symbol.iterator]();!(n=(s=a.next()).done)&&(r.push(s.value),!t||r.length!==t);n=!0);}catch(e){i=!0,o=e}finally{try{!n&&a.return&&a.return()}finally{if(i)throw o}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),d=function(){function e(e,t){for(var r=0;r3&&void 0!==arguments[3]?arguments[3]:t,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,s=e._calculateBlockSize(r,n),a=c(s,3),h=a[0],w=a[1],f=a[2],u=void 0;if(o){if(!(o instanceof Uint8ClampedArray)||o.byteLength!==w*f)throw new Error("QR Error: Illegal Buffer.");u=o}else u=new Uint8ClampedArray(w*f);for(var l=0;lf&&(f=v)}l+=r}if(f-w>e.MIN_DYNAMIC_RANGE)return(w+f)/2;if(0===i||0===o)return w/2;var g=o*s+i,m=(h[g-1]+h[g-s]+s[g-s-1])/3;return m>w?m:w/2}},{key:"_applyThresholdToBlock",value:function(e,t,r,n,i,o,s){for(var a=arguments.length>7&&void 0!==arguments[7]?arguments[7]:e,h=Math.min(n*o,t-o),w=Math.min(i*o,r-o)*t+h,f=0;fr||a<-1||a>n)throw new Error("QR Error: Error.checkAndNudgePoints");i=!1,-1==s?(t[o]=0,i=!0):s==r&&(t[o]=r-1,i=!0),-1==a?(t[o+1]=0,i=!0):a==n&&(t[o+1]=n-1,i=!0)}i=!0;for(o=t.length-2;o>=0&&i;o-=2){var s=Math.floor(t[o]),a=Math.floor(t[o+1]);if(s<-1||s>r||a<-1||a>n)throw new Error("QR Error: Error.checkAndNudgePoints");i=!1,-1==s?(t[o]=0,i=!0):s==r&&(t[o]=r-1,i=!0),-1==a?(t[o+1]=0,i=!0):a==n&&(t[o+1]=n-1,i=!0)}},g.sampleGrid3=function(e,t,r){for(var n=new a(t),i=new Array(t<<1),o=0;o>1),i[w+1]=h;r.transformPoints1(i),g.checkAndNudgePoints(e,i);try{for(w=0;w>1,o)}}catch(e){throw new Error("QR Error: Error.checkAndNudgePoints")}}return n},g.sampleGridx=function(e,t,r,i,o,s,a,h,w,f,u,l,c,d,v,m,b,y){var C=n.quadrilateralToQuadrilateral(r,i,o,s,a,h,w,f,u,l,c,d,v,m,b,y);return g.sampleGrid3(e,t,C)},r.VERSION_DECODE_INFO=new Array(31892,34236,39577,42195,48118,51042,55367,58893,63784,68472,70749,76311,79154,84390,87683,92361,96236,102084,102881,110507,110734,117786,119615,126325,127568,133589,136944,141498,145311,150283,152622,158308,161089,167017),r.VERSIONS=new Array(new r(1,new Array,new t(7,new e(1,19)),new t(10,new e(1,16)),new t(13,new e(1,13)),new t(17,new e(1,9))),new r(2,new Array(6,18),new t(10,new e(1,34)),new t(16,new e(1,28)),new t(22,new e(1,22)),new t(28,new e(1,16))),new r(3,new Array(6,22),new t(15,new e(1,55)),new t(26,new e(1,44)),new t(18,new e(2,17)),new t(22,new e(2,13))),new r(4,new Array(6,26),new t(20,new e(1,80)),new t(18,new e(2,32)),new t(26,new e(2,24)),new t(16,new e(4,9))),new r(5,new Array(6,30),new t(26,new e(1,108)),new t(24,new e(2,43)),new t(18,new e(2,15),new e(2,16)),new t(22,new e(2,11),new e(2,12))),new r(6,new Array(6,34),new t(18,new e(2,68)),new t(16,new e(4,27)),new t(24,new e(4,19)),new t(28,new e(4,15))),new r(7,new Array(6,22,38),new t(20,new e(2,78)),new t(18,new e(4,31)),new t(18,new e(2,14),new e(4,15)),new t(26,new e(4,13),new e(1,14))),new r(8,new Array(6,24,42),new t(24,new e(2,97)),new t(22,new e(2,38),new e(2,39)),new t(22,new e(4,18),new e(2,19)),new t(26,new e(4,14),new e(2,15))),new r(9,new Array(6,26,46),new t(30,new e(2,116)),new t(22,new e(3,36),new e(2,37)),new t(20,new e(4,16),new e(4,17)),new t(24,new e(4,12),new e(4,13))),new r(10,new Array(6,28,50),new t(18,new e(2,68),new e(2,69)),new t(26,new e(4,43),new e(1,44)),new t(24,new e(6,19),new e(2,20)),new t(28,new e(6,15),new e(2,16))),new r(11,new Array(6,30,54),new t(20,new e(4,81)),new t(30,new e(1,50),new e(4,51)),new t(28,new e(4,22),new e(4,23)),new t(24,new e(3,12),new e(8,13))),new r(12,new Array(6,32,58),new t(24,new e(2,92),new e(2,93)),new t(22,new e(6,36),new e(2,37)),new t(26,new e(4,20),new e(6,21)),new t(28,new e(7,14),new e(4,15))),new r(13,new Array(6,34,62),new t(26,new e(4,107)),new t(22,new e(8,37),new e(1,38)),new t(24,new e(8,20),new e(4,21)),new t(22,new e(12,11),new e(4,12))),new r(14,new Array(6,26,46,66),new t(30,new e(3,115),new e(1,116)),new t(24,new e(4,40),new e(5,41)),new t(20,new e(11,16),new e(5,17)),new t(24,new e(11,12),new e(5,13))),new r(15,new Array(6,26,48,70),new t(22,new e(5,87),new e(1,88)),new t(24,new e(5,41),new e(5,42)),new t(30,new e(5,24),new e(7,25)),new t(24,new e(11,12),new e(7,13))),new r(16,new Array(6,26,50,74),new t(24,new e(5,98),new e(1,99)),new t(28,new e(7,45),new e(3,46)),new t(24,new e(15,19),new e(2,20)),new t(30,new e(3,15),new e(13,16))),new r(17,new Array(6,30,54,78),new t(28,new e(1,107),new e(5,108)),new t(28,new e(10,46),new e(1,47)),new t(28,new e(1,22),new e(15,23)),new t(28,new e(2,14),new e(17,15))),new r(18,new Array(6,30,56,82),new t(30,new e(5,120),new e(1,121)),new t(26,new e(9,43),new e(4,44)),new t(28,new e(17,22),new e(1,23)),new t(28,new e(2,14),new e(19,15))),new r(19,new Array(6,30,58,86),new t(28,new e(3,113),new e(4,114)),new t(26,new e(3,44),new e(11,45)),new t(26,new e(17,21),new e(4,22)),new t(26,new e(9,13),new e(16,14))),new r(20,new Array(6,34,62,90),new t(28,new e(3,107),new e(5,108)),new t(26,new e(3,41),new e(13,42)),new t(30,new e(15,24),new e(5,25)),new t(28,new e(15,15),new e(10,16))),new r(21,new Array(6,28,50,72,94),new t(28,new e(4,116),new e(4,117)),new t(26,new e(17,42)),new t(28,new e(17,22),new e(6,23)),new t(30,new e(19,16),new e(6,17))),new r(22,new Array(6,26,50,74,98),new t(28,new e(2,111),new e(7,112)),new t(28,new e(17,46)),new t(30,new e(7,24),new e(16,25)),new t(24,new e(34,13))),new r(23,new Array(6,30,54,74,102),new t(30,new e(4,121),new e(5,122)),new t(28,new e(4,47),new e(14,48)),new t(30,new e(11,24),new e(14,25)),new t(30,new e(16,15),new e(14,16))),new r(24,new Array(6,28,54,80,106),new t(30,new e(6,117),new e(4,118)),new t(28,new e(6,45),new e(14,46)),new t(30,new e(11,24),new e(16,25)),new t(30,new e(30,16),new e(2,17))),new r(25,new Array(6,32,58,84,110),new t(26,new e(8,106),new e(4,107)),new t(28,new e(8,47),new e(13,48)),new t(30,new e(7,24),new e(22,25)),new t(30,new e(22,15),new e(13,16))),new r(26,new Array(6,30,58,86,114),new t(28,new e(10,114),new e(2,115)),new t(28,new e(19,46),new e(4,47)),new t(28,new e(28,22),new e(6,23)),new t(30,new e(33,16),new e(4,17))),new r(27,new Array(6,34,62,90,118),new t(30,new e(8,122),new e(4,123)),new t(28,new e(22,45),new e(3,46)),new t(30,new e(8,23),new e(26,24)),new t(30,new e(12,15),new e(28,16))),new r(28,new Array(6,26,50,74,98,122),new t(30,new e(3,117),new e(10,118)),new t(28,new e(3,45),new e(23,46)),new t(30,new e(4,24),new e(31,25)),new t(30,new e(11,15),new e(31,16))),new r(29,new Array(6,30,54,78,102,126),new t(30,new e(7,116),new e(7,117)),new t(28,new e(21,45),new e(7,46)),new t(30,new e(1,23),new e(37,24)),new t(30,new e(19,15),new e(26,16))),new r(30,new Array(6,26,52,78,104,130),new t(30,new e(5,115),new e(10,116)),new t(28,new e(19,47),new e(10,48)),new t(30,new e(15,24),new e(25,25)),new t(30,new e(23,15),new e(25,16))),new r(31,new Array(6,30,56,82,108,134),new t(30,new e(13,115),new e(3,116)),new t(28,new e(2,46),new e(29,47)),new t(30,new e(42,24),new e(1,25)),new t(30,new e(23,15),new e(28,16))),new r(32,new Array(6,34,60,86,112,138),new t(30,new e(17,115)),new t(28,new e(10,46),new e(23,47)),new t(30,new e(10,24),new e(35,25)),new t(30,new e(19,15),new e(35,16))),new r(33,new Array(6,30,58,86,114,142),new t(30,new e(17,115),new e(1,116)),new t(28,new e(14,46),new e(21,47)),new t(30,new e(29,24),new e(19,25)),new t(30,new e(11,15),new e(46,16))),new r(34,new Array(6,34,62,90,118,146),new t(30,new e(13,115),new e(6,116)),new t(28,new e(14,46),new e(23,47)),new t(30,new e(44,24),new e(7,25)),new t(30,new e(59,16),new e(1,17))),new r(35,new Array(6,30,54,78,102,126,150),new t(30,new e(12,121),new e(7,122)),new t(28,new e(12,47),new e(26,48)),new t(30,new e(39,24),new e(14,25)),new t(30,new e(22,15),new e(41,16))),new r(36,new Array(6,24,50,76,102,128,154),new t(30,new e(6,121),new e(14,122)),new t(28,new e(6,47),new e(34,48)),new t(30,new e(46,24),new e(10,25)),new t(30,new e(2,15),new e(64,16))),new r(37,new Array(6,28,54,80,106,132,158),new t(30,new e(17,122),new e(4,123)),new t(28,new e(29,46),new e(14,47)),new t(30,new e(49,24),new e(10,25)),new t(30,new e(24,15),new e(46,16))),new r(38,new Array(6,32,58,84,110,136,162),new t(30,new e(4,122),new e(18,123)),new t(28,new e(13,46),new e(32,47)),new t(30,new e(48,24),new e(14,25)),new t(30,new e(42,15),new e(32,16))),new r(39,new Array(6,26,54,82,110,138,166),new t(30,new e(20,117),new e(4,118)),new t(28,new e(40,47),new e(7,48)),new t(30,new e(43,24),new e(22,25)),new t(30,new e(10,15),new e(67,16))),new r(40,new Array(6,30,58,86,114,142,170),new t(30,new e(19,118),new e(6,119)),new t(28,new e(18,47),new e(31,48)),new t(30,new e(34,24),new e(34,25)),new t(30,new e(20,15),new e(61,16)))),r.getVersionForNumber=function(e){if(e<1||e>40)throw new Error("QR Error: ArgumentException");return r.VERSIONS[e-1]},r.getProvisionalVersionForDimension=function(e){if(e%4!=1)throw new Error("QR Error: Error getProvisionalVersionForDimension");try{return r.getVersionForNumber(e-17>>2)}catch(e){throw new Error("QR Error: Error getVersionForNumber")}},r.decodeVersionInformation=function(e){for(var t=4294967295,n=0,i=0;i=p.length)throw new Error("QR Error: ArgumentException");return p[e]};var y=new s(0,1,"L"),C=new s(1,0,"M"),_=new s(2,3,"Q"),A=new s(3,2,"H"),p=new Array(C,y,A,_);h.getDataBlocks=function(e,t,r){if(e.length!=t.TotalCodewords)throw new Error("QR Error: ArgumentException");for(var n=t.getECBlocksForLevel(r),i=0,o=n.getECBlocks(),s=0;s=0;){if(a[v].codewords.length==d)break;v--}v++;for(var g=d-n.ECCodewordsPerBlock,m=0,s=0;s7)throw new Error("QR Error: System.ArgumentException");return E.DATA_MASKS[e]},E.DATA_MASKS=new Array(new function(){this.unmaskBitMatrix=function(e,t){for(var r=0;r=Math.floor(r/2);){var f=i,u=s,l=h;if(i=o,s=a,h=w,i.Zero)throw new Error("QR Error: r_{i-1} was zero");o=f;for(var c=this.field.Zero,d=i.getCoefficient(i.Degree),v=this.field.inverse(d);o.Degree>=i.Degree&&!o.Zero;){var g=o.Degree-i.Degree,m=this.field.multiply(o.getCoefficient(o.Degree),v);c=c.addOrSubtract(this.field.buildMonomial(g,m)),o=o.addOrSubtract(i.multiplyByMonomial(g,m))}a=c.multiply1(s).addOrSubtract(u),w=c.multiply1(h).addOrSubtract(l)}var b=w.getCoefficient(0);if(0==b)throw new Error("QR Error: ReedSolomonException sigmaTilde(0) was zero");var y=this.field.inverse(b),C=w.multiply2(y),_=o.multiply2(y);return new Array(C,_)},this.findErrorLocations=function(e){var t=e.Degree;if(1==t)return new Array(e.getCoefficient(1));for(var r=new Array(t),n=0,i=1;i<256&&n=0;i--)e=this.copyBit(8,i,e);if(this.parsedFormatInfo=o.decodeFormatInformation(e),null!=this.parsedFormatInfo)return this.parsedFormatInfo;var r=this.bitMatrix.Dimension;e=0;for(var n=r-8,t=r-1;t>=n;t--)e=this.copyBit(t,8,e);for(var i=r-7;i>2;if(t<=6)return r.getVersionForNumber(t);for(var n=0,i=e-11,o=5;o>=0;o--)for(s=e-9;s>=i;s--)n=this.copyBit(s,o,n);if(this.parsedVersion=r.decodeVersionInformation(n),null!=this.parsedVersion&&this.parsedVersion.DimensionForVersion==e)return this.parsedVersion;n=0;for(var s=5;s>=0;s--)for(o=e-9;o>=i;o--)n=this.copyBit(s,o,n);if(this.parsedVersion=r.decodeVersionInformation(n),null!=this.parsedVersion&&this.parsedVersion.DimensionForVersion==e)return this.parsedVersion;throw new Error("QR Error: Error readVersion")},this.readCodewords=function(){var e=this.readFormatInformation(),t=this.readVersion(),r=E.forReference(e.DataMask),n=this.bitMatrix.Dimension;r.unmaskBitMatrix(this.bitMatrix,n);for(var i=t.buildFunctionPattern(),o=!0,s=new Array(t.TotalCodewords),a=0,h=0,w=0,f=n-1;f>0;f-=2){6==f&&f--;for(var u=0;u=10&&t<=26?this.dataLengthMode=1:t>=27&&t<=40&&(this.dataLengthMode=2),this.getNextBits=function(e){var t=0;if(e>this.bitPointer-e+1,this.bitPointer-=e,t}if(e>8-(e-(this.bitPointer+1)),this.bitPointer=this.bitPointer-e%8,this.bitPointer<0&&(this.bitPointer=8+this.bitPointer),t}if(e>8-(e-(this.bitPointer+1+8))),this.bitPointer=this.bitPointer-(e-8)%8,this.bitPointer<0&&(this.bitPointer=8+this.bitPointer),t}return 0},this.NextMode=function(){return this.blockPointer>this.blocks.length-this.numErrorCorrectionCode-2?0:this.getNextBits(4)},this.getDataLength=function(e){for(var t=0;e>>t!=1;)t++;return this.getNextBits(k.sizeOfDataLengthInfo[this.dataLengthMode][t])},this.getRomanAndFigureString=function(e){var t=e,r=0,n="",i=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"," ","$","%","*","+","-",".","/",":");do{if(t>1){var o=(r=this.getNextBits(11))%45;n+=i[Math.floor(r/45)],n+=i[o],t-=2}else 1==t&&(n+=i[r=this.getNextBits(6)],t-=1)}while(t>0);return n},this.getFigureString=function(e){var t=e,r=0,n="";do{t>=3?((r=this.getNextBits(10))<100&&(n+="0"),r<10&&(n+="0"),t-=3):2==t?((r=this.getNextBits(7))<10&&(n+="0"),t-=2):1==t&&(r=this.getNextBits(4),t-=1),n+=r}while(t>0);return n},this.get8bitByteArray=function(e){var t=e,r=0,n=new Array;do{r=this.getNextBits(8),n.push(r),t--}while(t>0);return n},this.getKanjiString=function(e){var t=e,r=0,n="";do{var i=((r=this.getNextBits(13))/192<<8)+r%192,o=0;o=i+33088<=40956?i+33088:i+49472,n+=String.fromCharCode(o),t--}while(t>0);return n},this.parseECIValue=function(){var e=0,t=this.getNextBits(8);return 0==(128&t)&&(e=127&t),128==(192&t)&&(e=(63&t)<<8|this.getNextBits(8)),192==(224&t)&&(e=(31&t)<<16|this.getNextBits(8)),e},this.__defineGetter__("DataByte",function(){for(var e=new Array;;){var t=this.NextMode();if(0==t){if(e.length>0)break;throw new Error("QR Error: Empty data block")}if(1!=t&&2!=t&&4!=t&&8!=t&&7!=t)throw new Error("QR Error: Invalid mode: "+t+" in (block:"+this.blockPointer+" bit:"+this.bitPointer+")");if(7==t)s=this.parseECIValue();else{var r=this.getDataLength(t);if(r<1)throw new Error("QR Error: Invalid data length: "+r);switch(t){case 1:for(var n=this.getFigureString(r),i=new Array(n.length),o=0;o>8}};var N=3,B=57,P=2;k.orderBestPatterns=function(e){function t(e,t){var r=e.X-t.X,n=e.Y-t.Y;return Math.sqrt(r*r+n*n)}var r,n,i,o=t(e[0],e[1]),s=t(e[1],e[2]),a=t(e[0],e[2]);if(s>=o&&s>=a?(n=e[0],r=e[1],i=e[2]):a>=s&&a>=o?(n=e[1],r=e[0],i=e[2]):(n=e[2],r=e[0],i=e[1]),function(e,t,r){var n=t.x,i=t.y;return(r.x-n)*(e.y-i)-(r.y-i)*(e.x-n)}(r,n,i)<0){var h=r;r=i,i=h}e[0]=r,e[1]=n,e[2]=i}}(); +(function(){ +'use strict';var aa="function"==typeof Object.defineProperties?Object.defineProperty:function(c,d,a){c!=Array.prototype&&c!=Object.prototype&&(c[d]=a.value)},e="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this;function qa(){qa=function(){};e.Symbol||(e.Symbol=ra)}var ra=function(){var c=0;return function(d){return"jscomp_symbol_"+(d||"")+c++}}(); +function f(){qa();var c=e.Symbol.iterator;c||(c=e.Symbol.iterator=e.Symbol("iterator"));"function"!=typeof Array.prototype[c]&&aa(Array.prototype,c,{configurable:!0,writable:!0,value:function(){return sa(this)}});f=function(){}}function sa(c){var d=0;return ta(function(){return d=c}}); +Pa("Array.prototype.find",function(c){return c?c:function(d,a){a:{var b=this;b instanceof String&&(b=String(b));for(var g=b.length,c=0;c>8}var ba=l,F=q,C=n,Q=r;ba= +void 0===ba?h:ba;F=void 0===F?null:F;var R=Oa(Sa(C,Q)),A=R.next().value,E=R.next().value,X=R.next().value;if(F){if(!(F instanceof Uint8ClampedArray)||F.byteLength!==E*X)throw Error("QR Error: Illegal Buffer.");var Y=F}else Y=new Uint8ClampedArray(E*X);for(var U=0;Uca&&(ca=da)}Va+=C}if(ca-S>Ta)var xa=(S+ca)/2;else if(0===V||0===U)xa=S/2;else{var ya= +U*E+V,Xa=(Y[ya-1]+Y[ya-E]+E[ya-E-1])/3;xa=Xa>S?Xa:S/2}Y[U*E+V]=xa}for(var ea=0;ea=za;++za)for(var Aa=-2;2>=Aa;++Aa)Ya+=Y[Math.max(0,Math.min(X-1,ea+Aa))*E+Math.max(0,Math.min(E-1,fa+za))];var Za=h,Ba=C,Jb=Ya/25,ha=ba;ha=void 0===ha?Za:ha;for(var $a=Math.min(ea*A,Q-A)*Ba+Math.min(fa*A,Ba-A),ab=0;abc||40=d?Cb(a):null};function Fb(c,d,a,b,g,k,h,l,m){this.o=c;this.s=b;this.u=h;this.v=d;this.w=g;this.A=l;this.B=a;this.C=k;this.D=m;this.sb=function(b){for(var a=b.length,g=this.o,d=this.s,c=this.u,k=this.v,h=this.w,l=this.A,m=this.B,p=this.C,F=this.D,C=0;CMath.abs(b-d);if(c){var h=d;d=a;a=h;h=b;b=g;g=h}var l=Math.abs(b-d),m=Math.abs(g-a),p=-l>>1,w=ab?(h=d/(d-b),b=0):b>=n&&(h= +(n-1-d)/(b-d),b=n-1);g=Math.floor(a-(g-a)*h);h=1;0>g?(h=a/(a-g),g=0):g>=r&&(h=(r-1-a)/(g-a),g=r-1);b=Math.floor(d+(b-d)*h);c+=this.Ca(d,a,b,g);return c-1};this.qa=function(d,a){var b=this.Da(Math.floor(d.g()),Math.floor(d.h()),Math.floor(a.g()),Math.floor(a.h()));d=this.Da(Math.floor(a.g()),Math.floor(a.h()),Math.floor(d.g()),Math.floor(d.h()));return isNaN(b)?d/7:isNaN(d)?b/7:(b+d)/14};this.Ja=function(d,a,b){return(this.qa(d,a)+this.qa(d,b))/2};this.sa=function(d,a){var b=d.g()-a.g();d=d.h()-a.h(); +return Math.sqrt(b*b+d*d)};this.Ka=function(d,a,b,g){d=(Math.round(this.sa(d,a)/g)+Math.round(this.sa(d,b)/g)>>1)+7;switch(d&3){case 0:d++;break;case 2:d--;break;case 3:throw Error("QR Error: in detector");}return d};this.Qa=function(d,a,b,g){g=Math.floor(g*d);var c=Math.max(0,a-g);a=Math.min(n-1,a+g);if(a-c<3*d)throw Error("QR Error: in detector");var h=Math.max(0,b-g);return(new Ib(this.H,c,h,a-c,Math.min(r-1,b+g)-h,d,this.U)).find()};this.La=function(d,a,b,g,c){c-=3.5;var k;if(null!=g){var l=g.g(); +g=g.h();var m=k=c-3}else l=a.g()-d.g()+b.g(),g=a.h()-d.h()+b.h(),m=k=c;return Gb(d.g(),d.h(),a.g(),a.h(),l,g,b.g(),b.h()).pb(Gb(3.5,3.5,c,3.5,m,k,3.5,c).Ha())};this.lb=function(d,a,b){for(var g=new zb(b),c=Array(b<<1),h=0;h>1)+.5,c[p+1]=m;a.sb(c);m=c;for(var w=n,q=r,u=!0,t=0;tx||x>w||-1>v||v>q)throw Error("QR Error: Error.checkAndNudgePoints");u=!1;-1==x?(m[t]=0,u=!0):x==w&& +(m[t]=w-1,u=!0);-1==v?(m[t+1]=0,u=!0):v==q&&(m[t+1]=q-1,u=!0)}u=!0;for(t=m.length-2;0<=t&&u;t-=2){x=Math.floor(m[t]);v=Math.floor(m[t+1]);if(-1>x||x>w||-1>v||v>q)throw Error("QR Error: Error.checkAndNudgePoints");u=!1;-1==x?(m[t]=0,u=!0):x==w&&(m[t]=w-1,u=!0);-1==v?(m[t+1]=0,u=!0):v==q&&(m[t+1]=q-1,u=!0)}try{for(p=0;p>1,h)}catch(ua){throw Error("QR Error: Error.checkAndNudgePoints");}}return g};this.ib=function(d){var a=d.qb,b=d.rb;d=d.Ga;var g= +this.Ja(a,b,d);if(1>g)throw Error("QR Error: in detector");var c=this.Ka(a,b,d,g);if(1!=c%4)throw Error("QR Error: Error getProvisionalVersionForDimension");try{var h=Cb(c-17>>2)}catch(w){throw Error("QR Error: Error getVersionForNumber");}var l=h.fa()-7,m=null;if(0=p;p<<=1)try{m=this.Qa(g,h,l,p);break}catch(w){}}a=this.lb(this.H,this.La(a,b,d,m,c),c);return new Hb(a)}; +this.Oa=function(){var d=(new Kb).Ta(this.H);return this.ib(d)}};var Lb=[[21522,0],[20773,1],[24188,2],[23371,3],[17913,4],[16590,5],[20375,6],[19104,7],[30660,8],[29427,9],[32170,10],[30877,11],[26159,12],[25368,13],[27713,14],[26998,15],[5769,16],[5054,17],[7399,18],[6608,19],[1890,20],[597,21],[3340,22],[2107,23],[13663,24],[12392,25],[16177,26],[14854,27],[9396,28],[8579,29],[11994,30],[11245,31]],O=[0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4];function Nb(c){var d=c>>3&3;if(0>d||d>=Rb.length)throw Error("QR Error: ArgumentException");this.Pa=Rb[d];this.Na=c&7} +function Eb(c,d){c^=d;return O[c&15]+O[P(c,4)&15]+O[P(c,8)&15]+O[P(c,12)&15]+O[P(c,16)&15]+O[P(c,20)&15]+O[P(c,24)&15]+O[P(c,28)&15]}function Sb(c){var d=Tb(c);return null!=d?d:Tb(c^21522)}function Tb(c){for(var d=4294967295,a=0,b=0;b=d?new Nb(a):null};function Ub(c,d,a){this.gb=c;this.i=d;this.name=a;this.getName=function(){return this.name}}var Rb=[new Ub(1,0,"M"),new Ub(0,1,"L"),new Ub(3,2,"H"),new Ub(2,3,"Q")];function zb(c){var d;d||(d=c);if(1>c||1>d)throw Error("QR Error: Both dimensions must be greater than 0");this.width=c;this.height=d;var a=c>>5;0!=(c&31)&&a++;this.X=a;this.i=Array(a*d);for(c=0;c>5)],b&31)&1)};this.nb=function(b,a){this.i[a*this.X+(b>>5)]|=1<<(b&31)};this.M=function(b, +a){this.i[a*this.X+(b>>5)]^=1<<(b&31)};this.clear=function(){for(var b=this.i.length,a=0;aa||0>b)throw Error("QR Error: Left and top must be nonnegative");if(1>c||1>d)throw Error("QR Error: Height and width must be at least 1");d=b+d;c=a+c;if(c>this.height||d>this.width)throw Error("QR Error: The region must fit inside the matrix");for(;a>5)]|=1<<(k&31)}};function tb(c,d){this.ya=c;this.T=d};function sb(c){var d=c.ea();if(21>d||1!=(d&3))throw Error("QR Error: Error BitMatrixParser");this.V=c;this.O=this.J=null;this.K=function(a,b,d){return this.V.ga(a,b)?d<<1|1:d<<1};this.Aa=function(){if(null!=this.O)return this.O;for(var a=0,b=0;6>b;b++)a=this.K(b,8,a);a=this.K(7,8,a);a=this.K(8,8,a);a=this.K(8,7,a);for(b=5;0<=b;b--)a=this.K(8,b,a);this.O=Sb(a);if(null!=this.O)return this.O;var d=this.V.ea();a=0;var c=d-8;for(b=d-1;b>=c;b--)a=this.K(b,8,a);for(b=d-7;b>2;if(6>=b)return Cb(b);b=0;for(var d=a-11,c=5;0<=c;c--)for(var h=a-9;h>=d;h--)b=this.K(h,c,b);this.J=Db(b);if(null!=this.J&&this.J.fa()==a)return this.J;b=0;for(h=5;0<=h;h--)for(c=a-9;c>=d;c--)b=this.K(h,c,b);this.J=Db(b);if(null!=this.J&&this.J.fa()==a)return this.J;throw Error("QR Error: Error readVersion");};this.jb=function(){var a=this.Aa(), +b=this.Ba();a=a.Na;if(0>a||7t;t++)d.ga(w-t,u)||(p++,m<<=1,this.V.ga(w-t,u)&&(m|=1),8==p&&(h[l++]=m,m=p=0));c^=1}if(l!=b.na)throw Error("QR Error: Error readCodewords");return h}};var Vb=[new function(){this.R=function(c,d){for(var a=0;ab.length){var d=a;a=b;b=d}d=Array(b.length);for(var g=b.length-a.length,m=0;mb)throw Error("QR Error: System.ArgumentException");if(0==a)return this.a.l();var d=this.f.length; +b=Array(d+b);for(var c=0;ca;a++)this.Y[a]=d,d<<=1,256<=d&&(d^=c);for(a=0;255>a;a++)this.aa[this.Y[a]]=a;c=Array(1);c[0]=0;this.Ea=new Z(this,Array(c));c=Array(1);c[0]=1;this.za=new Z(this,Array(c));this.l=function(){return this.Ea};this.pa=function(b,a){if(0>b)throw Error("QR Error: System.ArgumentException");if(0==a)return this.Ea;b=Array(b+1);for(var d=0;dc)throw Error("QR Error: ReedSolomonException Bad error location");d[c]^=b[k]}};this.kb=function(d,a,b){if(d.I()=Math.floor(b/2);){var m=d,p=c,w=h;d=a;c=k;h=l;if(d.l())throw Error("QR Error: r_{i-1} was zero");a=m;l=this.a.l();for(k=this.a.inverse(d.Z(d.I()));a.I()>=d.I()&&!a.l();){m=a.I()-d.I();var q=this.a.multiply(a.Z(a.I()),k);l=l.ba(this.a.pa(m,q));a=a.ba(d.eb(m,q))}k=l.wa(c).ba(p);l=l.wa(h).ba(w)}b=l.Z(0);if(0==b)throw Error("QR Error: ReedSolomonException sigmaTilde(0) was zero");b=this.a.inverse(b);d=l.xa(b);b=a.xa(b);return[d,b]};this.Ra=function(d){var a= +d.I();if(1==a)return Array(d.Z(1));for(var b=Array(a),c=0,k=1;256>k&&c>d:(c>>d)+(2<<~d)};var $b=3,ac=57,bc=2;function cc(c){function d(b,a){var c=b.g()-a.g();b=b.h()-a.h();return Math.sqrt(c*c+b*b)}var a=d(c[0],c[1]),b=d(c[1],c[2]),g=d(c[0],c[2]);b>=a&&b>=g?(b=c[0],a=c[1],g=c[2]):g>=b&&g>=a?(b=c[1],a=c[0],g=c[2]):(b=c[2],a=c[0],g=c[1]);if(0>function(b,a,c){var d=a.x;a=a.y;return(c.x-d)*(b.y-a)-(c.y-a)*(b.x-d)}(a,b,g)){var k=a;a=g;g=k}c[0]=a;c[1]=b;c[2]=g} +function dc(c,d,a){this.x=c;this.y=d;this.count=1;this.G=a;this.g=function(){return this.x};this.h=function(){return this.y};this.va=function(){this.count++};this.ha=function(b,a,c){return Math.abs(a-this.y)<=b&&Math.abs(c-this.x)<=b?(b=Math.abs(b-this.G),1>=b||1>=b/this.G):!1}}function ec(c){this.Ga=c[0];this.qb=c[1];this.rb=c[2]} +function Kb(){this.H=null;this.c=[];this.ma=!1;this.L=[0,0,0,0,0];this.U=null;this.ta=function(){this.L[0]=0;this.L[1]=0;this.L[2]=0;this.L[3]=0;this.L[4]=0;return this.L};this.N=function(c){for(var d=0,a=0;5>a;a++){var b=c[a];if(0==b)return!1;d+=b}if(7>d)return!1;d=Math.floor(d/7);a=Math.floor(.7*d);return Math.abs(d-c[0])l)return NaN;for(;0<=l&&!g[d+l*n]&&h[1]<=a;)h[1]++,l--;if(0>l||h[1]>a)return NaN;for(;0<=l&&g[d+l*n]&&h[0]<=a;)h[0]++,l--;if(h[0]>a)return NaN;for(l=c+1;l=a)return NaN;for(;l=a||5*Math.abs(h[0]+h[1]+h[2]+h[3]+h[4]-b)>=2*b?NaN:this.N(h)?this.W(h,l):NaN};this.Ma=function(c,d,a,b){for(var g=this.H,k=n,h=this.ta(), +l=c;0<=l&&g[l+d*n];)h[2]++,l--;if(0>l)return NaN;for(;0<=l&&!g[l+d*n]&&h[1]<=a;)h[1]++,l--;if(0>l||h[1]>a)return NaN;for(;0<=l&&g[l+d*n]&&h[0]<=a;)h[0]++,l--;if(h[0]>a)return NaN;for(l=c+1;l=a)return NaN;for(;l=a||5*Math.abs(h[0]+h[1]+h[2]+h[3]+h[4]-b)>=b?NaN:this.N(h)?this.W(h,l):NaN};this.$=function(c,d,a){var b=c[0]+c[1]+c[2]+c[3]+c[4];a=this.W(c,a);d=this.ia(d, +Math.floor(a),c[2],b);if(!isNaN(d)&&(a=this.Ma(Math.floor(a),Math.floor(d),c[2],b),!isNaN(a))){c=b/7;b=!1;for(var g=this.c.length,k=0;kc)throw Error("QR Error: Couldn't find enough finder patterns (found "+c+")");if(3c&&this.c.splice(b,1)}3a.count?-1:b.count=c)return 0;for(var d=null,a=0;a=bc)if(null==d)d=b;else return this.ma=!0,Math.floor((Math.abs(d.g()-b.g())-Math.abs(d.h()- +b.h()))/2)}return 0};this.ua=function(){for(var c=0,d=0,a=this.c.length,b=0;b=bc&&(c++,d+=g.G)}if(3>c)return!1;c=d/a;var k=0;for(b=0;bk[2]&&(h+=l-k[2]-b,m=a-1));else{do m++;while(m=b||1>=b/this.G):!1}} +function Ib(c,d,a,b,g,k,h){this.H=c;this.c=[];this.ob=d;this.width=b;this.height=g;this.cb=k;this.L=[0,0,0];this.U=h;this.W=function(b,a){return a-b[2]-b[1]/2};this.N=function(b){for(var a=this.cb,c=a/2,d=0;3>d;d++)if(Math.abs(a-b[d])>=c)return!1;return!0};this.ia=function(b,a,c,d){var g=this.H,k=r,h=this.L;h[0]=0;h[1]=0;h[2]=0;for(var l=b;0<=l&&g[a+l*n]&&h[1]<=c;)h[1]++,l--;if(0>l||h[1]>c)return NaN;for(;0<=l&&!g[a+l*n]&&h[0]<=c;)h[0]++,l--;if(h[0]>c)return NaN;for(l=b+1;lc)return NaN;for(;lc||5*Math.abs(h[0]+h[1]+h[2]-d)>=2*d?NaN:this.N(h)?this.W(h,l):NaN};this.$=function(b,a,c){c=this.W(b,c);a=this.ia(a,Math.floor(c),2*b[1],b[0]+b[1]+b[2]);if(!isNaN(a)){b=(b[0]+b[1]+b[2])/3;for(var d=this.c.length,g=0;g>1),q=[0,0, +0],u=0;u>1:-(u+1>>1));q[0]=0;q[1]=0;q[2]=0;for(var x=d;x=d?this.ja=0:10<=d&&26>=d?this.ja=1:27<=d&&40>=d&&(this.ja=2);this.m=function(b){var a;if(b>this.b-b+1;this.b-=b;return a}if(b>8-(b-(this.b+1));this.b=this.b-b%8;0>this.b&&(this.b=8+this.b);return a}if(b>8-(b-(this.b+1+8)));this.b=this.b-(b-8)%8;0>this.b&&(this.b=8+this.b);return a}return 0};this.Fa=function(){return this.F>this.S.length-this.fb-2?0:this.m(4)};this.Ya=function(b){for(var a=0;1!=b>>a;)a++;return this.m(Zb[this.ja][a])};this.bb=function(b){var a="",c="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:".split(""); +do if(1a&&(c+="0"),10>a&&(c+="0"),b-=3):2==b?(a=this.m(7),10>a&&(c+="0"),b-=2):1==b&&(a=this.m(4),--b),c+=a;while(0=c+33088? +c+33088:c+49472);b--}while(0c)throw Error("QR Error: Invalid data length: "+c);switch(a){case 1:a=this.$a(c);c=Array(a.length); +for(var d=0;d 6)\r\n\t\t\t{\r\n\t\t\t\t// Version info, top right\r\n\t\t\t\tbitMatrix.setRegion(dimension - 11, 0, 3, 6);\r\n\t\t\t\t// Version info, bottom left\r\n\t\t\t\tbitMatrix.setRegion(0, dimension - 11, 6, 3);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\treturn bitMatrix;\r\n\t\t}\r\n\tthis.getECBlocksForLevel=function( ecLevel)\r\n\t{\r\n\t\treturn this.ecBlocks[ecLevel.ordinal()];\r\n\t}\r\n}\r\n\r\nVersion.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);\r\n\r\nVersion.VERSIONS = buildVersions();\r\n\r\nVersion.getVersionForNumber=function( versionNumber)\r\n{\r\n\tif (versionNumber < 1 || versionNumber > 40)\r\n\t{\r\n\t\tthrow new Error(\"QR Error: ArgumentException\");\r\n\t}\r\n\treturn Version.VERSIONS[versionNumber - 1];\r\n}\r\n\r\nVersion.getProvisionalVersionForDimension=function(dimension)\r\n{\r\n\tif (dimension % 4 != 1)\r\n\t{\r\n\t\tthrow new Error(\"QR Error: Error getProvisionalVersionForDimension\");\r\n\t}\r\n\ttry\r\n\t{\r\n\t\treturn Version.getVersionForNumber((dimension - 17) >> 2);\r\n\t}\r\n\tcatch ( iae)\r\n\t{\r\n\t\tthrow new Error(\"QR Error: Error getVersionForNumber\");\r\n\t}\r\n}\r\n\r\nVersion.decodeVersionInformation=function( versionBits)\r\n{\r\n\tvar bestDifference = 0xffffffff;\r\n\tvar bestVersion = 0;\r\n\tfor (var i = 0; i < Version.VERSION_DECODE_INFO.length; i++)\r\n\t{\r\n\t\tvar targetVersion = Version.VERSION_DECODE_INFO[i];\r\n\t\t// Do the version info bits match exactly? done.\r\n\t\tif (targetVersion == versionBits)\r\n\t\t{\r\n\t\t\treturn this.getVersionForNumber(i + 7);\r\n\t\t}\r\n\t\t// Otherwise see if this is the closest to a real version info bit string\r\n\t\t// we have seen so far\r\n\t\tvar bitsDifference = FormatInformation.numBitsDiffering(versionBits, targetVersion);\r\n\t\tif (bitsDifference < bestDifference)\r\n\t\t{\r\n\t\t\tbestVersion = i + 7;\r\n\t\t\tbestDifference = bitsDifference;\r\n\t\t}\r\n\t}\r\n\t// We can tolerate up to 3 bits of error since no two version info codewords will\r\n\t// differ in less than 4 bits.\r\n\tif (bestDifference <= 3)\r\n\t{\r\n\t\treturn this.getVersionForNumber(bestVersion);\r\n\t}\r\n\t// If we didn't find a close enough match, fail\r\n\treturn null;\r\n}\r\n\r\nfunction buildVersions()\r\n{\r\n\treturn 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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), \t\tnew ECB(28, 16))),\r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))));\r\n}","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nfunction PerspectiveTransform( a11, a21, a31, a12, a22, a32, a13, a23, a33)\r\n{\r\n\tthis.a11 = a11;\r\n\tthis.a12 = a12;\r\n\tthis.a13 = a13;\r\n\tthis.a21 = a21;\r\n\tthis.a22 = a22;\r\n\tthis.a23 = a23;\r\n\tthis.a31 = a31;\r\n\tthis.a32 = a32;\r\n\tthis.a33 = a33;\r\n\tthis.transformPoints1=function( points)\r\n\t\t{\r\n\t\t\tvar max = points.length;\r\n\t\t\tvar a11 = this.a11;\r\n\t\t\tvar a12 = this.a12;\r\n\t\t\tvar a13 = this.a13;\r\n\t\t\tvar a21 = this.a21;\r\n\t\t\tvar a22 = this.a22;\r\n\t\t\tvar a23 = this.a23;\r\n\t\t\tvar a31 = this.a31;\r\n\t\t\tvar a32 = this.a32;\r\n\t\t\tvar a33 = this.a33;\r\n\t\t\tfor (var i = 0; i < max; i += 2)\r\n\t\t\t{\r\n\t\t\t\tvar x = points[i];\r\n\t\t\t\tvar y = points[i + 1];\r\n\t\t\t\tvar denominator = a13 * x + a23 * y + a33;\r\n\t\t\t\tpoints[i] = (a11 * x + a21 * y + a31) / denominator;\r\n\t\t\t\tpoints[i + 1] = (a12 * x + a22 * y + a32) / denominator;\r\n\t\t\t}\r\n\t\t}\r\n\tthis. transformPoints2=function(xValues, yValues)\r\n\t\t{\r\n\t\t\tvar n = xValues.length;\r\n\t\t\tfor (var i = 0; i < n; i++)\r\n\t\t\t{\r\n\t\t\t\tvar x = xValues[i];\r\n\t\t\t\tvar y = yValues[i];\r\n\t\t\t\tvar denominator = this.a13 * x + this.a23 * y + this.a33;\r\n\t\t\t\txValues[i] = (this.a11 * x + this.a21 * y + this.a31) / denominator;\r\n\t\t\t\tyValues[i] = (this.a12 * x + this.a22 * y + this.a32) / denominator;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\tthis.buildAdjoint=function()\r\n\t\t{\r\n\t\t\t// Adjoint is the transpose of the cofactor matrix:\r\n\t\t\treturn 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);\r\n\t\t}\r\n\tthis.times=function( other)\r\n\t\t{\r\n\t\t\treturn 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);\r\n\t\t}\r\n\r\n}\r\n\r\nPerspectiveTransform.quadrilateralToQuadrilateral=function( x0, y0, x1, y1, x2, y2, x3, y3, x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p)\r\n{\r\n\t\r\n\tvar qToS = this.quadrilateralToSquare(x0, y0, x1, y1, x2, y2, x3, y3);\r\n\tvar sToQ = this.squareToQuadrilateral(x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p);\r\n\treturn sToQ.times(qToS);\r\n}\r\n\r\nPerspectiveTransform.squareToQuadrilateral=function( x0, y0, x1, y1, x2, y2, x3, y3)\r\n{\r\n\tvar dy2 = y3 - y2;\r\n\tvar dy3 = y0 - y1 + y2 - y3;\r\n\tif (dy2 == 0.0 && dy3 == 0.0)\r\n\t{\r\n\t\treturn new PerspectiveTransform(x1 - x0, x2 - x1, x0, y1 - y0, y2 - y1, y0, 0.0, 0.0, 1.0);\r\n\t}\r\n\telse\r\n\t{\r\n\t\tvar dx1 = x1 - x2;\r\n\t\tvar dx2 = x3 - x2;\r\n\t\tvar dx3 = x0 - x1 + x2 - x3;\r\n\t\tvar dy1 = y1 - y2;\r\n\t\tvar denominator = dx1 * dy2 - dx2 * dy1;\r\n\t\tvar a13 = (dx3 * dy2 - dx2 * dy3) / denominator;\r\n\t\tvar a23 = (dx1 * dy3 - dx3 * dy1) / denominator;\r\n\t\treturn new PerspectiveTransform(x1 - x0 + a13 * x1, x3 - x0 + a23 * x3, x0, y1 - y0 + a13 * y1, y3 - y0 + a23 * y3, y0, a13, a23, 1.0);\r\n\t}\r\n}\r\n\r\nPerspectiveTransform.quadrilateralToSquare=function( x0, y0, x1, y1, x2, y2, x3, y3)\r\n{\r\n\t// Here, the adjoint serves as the inverse:\r\n\treturn this.squareToQuadrilateral(x0, y0, x1, y1, x2, y2, x3, y3).buildAdjoint();\r\n}\r\n\r\nfunction DetectorResult(bits, points)\r\n{\r\n\tthis.bits = bits;\r\n\tthis.points = points;\r\n}\r\n\r\n\r\nfunction Detector(image)\r\n{\r\n\tthis.image=image;\r\n\tthis.resultPointCallback = null;\r\n\t\r\n\tthis.sizeOfBlackWhiteBlackRun=function( fromX, fromY, toX, toY)\r\n\t\t{\r\n\t\t\t// Mild variant of Bresenham's algorithm;\r\n\t\t\t// see http://en.wikipedia.org/wiki/Bresenham's_line_algorithm\r\n\t\t\tvar steep = Math.abs(toY - fromY) > Math.abs(toX - fromX);\r\n\t\t\tif (steep)\r\n\t\t\t{\r\n\t\t\t\tvar temp = fromX;\r\n\t\t\t\tfromX = fromY;\r\n\t\t\t\tfromY = temp;\r\n\t\t\t\ttemp = toX;\r\n\t\t\t\ttoX = toY;\r\n\t\t\t\ttoY = temp;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvar dx = Math.abs(toX - fromX);\r\n\t\t\tvar dy = Math.abs(toY - fromY);\r\n\t\t\tvar error = - dx >> 1;\r\n\t\t\tvar ystep = fromY < toY?1:- 1;\r\n\t\t\tvar xstep = fromX < toX?1:- 1;\r\n\t\t\tvar state = 0; // In black pixels, looking for white, first or second time\r\n\t\t\tfor (var x = fromX, y = fromY; x != toX; x += xstep)\r\n\t\t\t{\r\n\t\t\t\t\r\n\t\t\t\tvar realX = steep?y:x;\r\n\t\t\t\tvar realY = steep?x:y;\r\n\t\t\t\tif (state == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\t// In white pixels, looking for black\r\n\t\t\t\t\tif (this.image[realX + realY*qrcode.width])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tstate++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tif (!this.image[realX + realY*qrcode.width])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tstate++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\tif (state == 3)\r\n\t\t\t\t{\r\n\t\t\t\t\t// Found black, white, black, and stumbled back onto white; done\r\n\t\t\t\t\tvar diffX = x - fromX;\r\n\t\t\t\t\tvar diffY = y - fromY;\r\n\t\t\t\t\treturn Math.sqrt( (diffX * diffX + diffY * diffY));\r\n\t\t\t\t}\r\n\t\t\t\terror += dy;\r\n\t\t\t\tif (error > 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (y == toY)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\ty += ystep;\r\n\t\t\t\t\terror -= dx;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tvar diffX2 = toX - fromX;\r\n\t\t\tvar diffY2 = toY - fromY;\r\n\t\t\treturn Math.sqrt( (diffX2 * diffX2 + diffY2 * diffY2));\r\n\t\t}\r\n\r\n\t\r\n\tthis.sizeOfBlackWhiteBlackRunBothWays=function( fromX, fromY, toX, toY)\r\n\t\t{\r\n\t\t\t\r\n\t\t\tvar result = this.sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY);\r\n\t\t\t\r\n\t\t\t// Now count other way -- don't run off image though of course\r\n\t\t\tvar scale = 1.0;\r\n\t\t\tvar otherToX = fromX - (toX - fromX);\r\n\t\t\tif (otherToX < 0)\r\n\t\t\t{\r\n\t\t\t\tscale = fromX / (fromX - otherToX);\r\n\t\t\t\totherToX = 0;\r\n\t\t\t}\r\n\t\t\telse if (otherToX >= qrcode.width)\r\n\t\t\t{\r\n\t\t\t\tscale = (qrcode.width - 1 - fromX) / (otherToX - fromX);\r\n\t\t\t\totherToX = qrcode.width - 1;\r\n\t\t\t}\r\n\t\t\tvar otherToY = Math.floor (fromY - (toY - fromY) * scale);\r\n\t\t\t\r\n\t\t\tscale = 1.0;\r\n\t\t\tif (otherToY < 0)\r\n\t\t\t{\r\n\t\t\t\tscale = fromY / (fromY - otherToY);\r\n\t\t\t\totherToY = 0;\r\n\t\t\t}\r\n\t\t\telse if (otherToY >= qrcode.height)\r\n\t\t\t{\r\n\t\t\t\tscale = (qrcode.height - 1 - fromY) / (otherToY - fromY);\r\n\t\t\t\totherToY = qrcode.height - 1;\r\n\t\t\t}\r\n\t\t\totherToX = Math.floor (fromX + (otherToX - fromX) * scale);\r\n\t\t\t\r\n\t\t\tresult += this.sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY);\r\n\t\t\treturn result - 1.0; // -1 because we counted the middle pixel twice\r\n\t\t}\r\n\t\t\r\n\r\n\t\r\n\tthis.calculateModuleSizeOneWay=function( pattern, otherPattern)\r\n\t\t{\r\n\t\t\tvar moduleSizeEst1 = this.sizeOfBlackWhiteBlackRunBothWays(Math.floor( pattern.X), Math.floor( pattern.Y), Math.floor( otherPattern.X), Math.floor(otherPattern.Y));\r\n\t\t\tvar moduleSizeEst2 = this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(otherPattern.X), Math.floor(otherPattern.Y), Math.floor( pattern.X), Math.floor(pattern.Y));\r\n\t\t\tif (isNaN(moduleSizeEst1))\r\n\t\t\t{\r\n\t\t\t\treturn moduleSizeEst2 / 7.0;\r\n\t\t\t}\r\n\t\t\tif (isNaN(moduleSizeEst2))\r\n\t\t\t{\r\n\t\t\t\treturn moduleSizeEst1 / 7.0;\r\n\t\t\t}\r\n\t\t\t// Average them, and divide by 7 since we've counted the width of 3 black modules,\r\n\t\t\t// and 1 white and 1 black module on either side. Ergo, divide sum by 14.\r\n\t\t\treturn (moduleSizeEst1 + moduleSizeEst2) / 14.0;\r\n\t\t}\r\n\r\n\t\r\n\tthis.calculateModuleSize=function( topLeft, topRight, bottomLeft)\r\n\t\t{\r\n\t\t\t// Take the average\r\n\t\t\treturn (this.calculateModuleSizeOneWay(topLeft, topRight) + this.calculateModuleSizeOneWay(topLeft, bottomLeft)) / 2.0;\r\n\t\t}\r\n\r\n\tthis.distance=function( pattern1, pattern2)\r\n\t{\r\n\t\tvar xDiff = pattern1.X - pattern2.X;\r\n\t\tvar yDiff = pattern1.Y - pattern2.Y;\r\n\t\treturn Math.sqrt( (xDiff * xDiff + yDiff * yDiff));\r\n\t}\r\n\tthis.computeDimension=function( topLeft, topRight, bottomLeft, moduleSize)\r\n\t\t{\r\n\t\t\t\r\n\t\t\tvar tltrCentersDimension = Math.round(this.distance(topLeft, topRight) / moduleSize);\r\n\t\t\tvar tlblCentersDimension = Math.round(this.distance(topLeft, bottomLeft) / moduleSize);\r\n\t\t\tvar dimension = ((tltrCentersDimension + tlblCentersDimension) >> 1) + 7;\r\n\t\t\tswitch (dimension & 0x03)\r\n\t\t\t{\r\n\t\t\t\t\r\n\t\t\t\t// mod 4\r\n\t\t\t\tcase 0: \r\n\t\t\t\t\tdimension++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t// 1? do nothing\r\n\t\t\t\t\r\n\t\t\t\tcase 2: \r\n\t\t\t\t\tdimension--;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\r\n\t\t\t\tcase 3: \r\n\t\t\t\t\tthrow new Error(\"QR Error: in detector\");\r\n\t\t\t\t}\r\n\t\t\treturn dimension;\r\n\t\t}\r\n\r\n\tthis.findAlignmentInRegion=function( overallEstModuleSize, estAlignmentX, estAlignmentY, allowanceFactor)\r\n\t\t{\r\n\t\t\t// Look for an alignment pattern (3 modules in size) around where it\r\n\t\t\t// should be\r\n\t\t\tvar allowance = Math.floor (allowanceFactor * overallEstModuleSize);\r\n\t\t\tvar alignmentAreaLeftX = Math.max(0, estAlignmentX - allowance);\r\n\t\t\tvar alignmentAreaRightX = Math.min(qrcode.width - 1, estAlignmentX + allowance);\r\n\t\t\tif (alignmentAreaRightX - alignmentAreaLeftX < overallEstModuleSize * 3)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(\"QR Error: in detector\");\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvar alignmentAreaTopY = Math.max(0, estAlignmentY - allowance);\r\n\t\t\tvar alignmentAreaBottomY = Math.min(qrcode.height - 1, estAlignmentY + allowance);\r\n\t\t\t\r\n\t\t\tvar alignmentFinder = new AlignmentPatternFinder(this.image, alignmentAreaLeftX, alignmentAreaTopY, alignmentAreaRightX - alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize, this.resultPointCallback);\r\n\t\t\treturn alignmentFinder.find();\r\n\t\t}\r\n\t\t\r\n\tthis.createTransform=function( topLeft, topRight, bottomLeft, alignmentPattern, dimension)\r\n\t\t{\r\n\t\t\tvar dimMinusThree = dimension - 3.5;\r\n\t\t\tvar bottomRightX;\r\n\t\t\tvar bottomRightY;\r\n\t\t\tvar sourceBottomRightX;\r\n\t\t\tvar sourceBottomRightY;\r\n\t\t\tif (alignmentPattern != null)\r\n\t\t\t{\r\n\t\t\t\tbottomRightX = alignmentPattern.X;\r\n\t\t\t\tbottomRightY = alignmentPattern.Y;\r\n\t\t\t\tsourceBottomRightX = sourceBottomRightY = dimMinusThree - 3.0;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t// Don't have an alignment pattern, just make up the bottom-right point\r\n\t\t\t\tbottomRightX = (topRight.X - topLeft.X) + bottomLeft.X;\r\n\t\t\t\tbottomRightY = (topRight.Y - topLeft.Y) + bottomLeft.Y;\r\n\t\t\t\tsourceBottomRightX = sourceBottomRightY = dimMinusThree;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvar 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);\r\n\t\t\t\r\n\t\t\treturn transform;\r\n\t\t}\t\t\r\n\t\r\n\tthis.sampleGrid=function( image, transform, dimension)\r\n\t\t{\r\n\t\t\t\r\n\t\t\tvar sampler = GridSampler;\r\n\t\t\treturn sampler.sampleGrid3(image, dimension, transform);\r\n\t\t}\r\n\t\r\n\tthis.processFinderPatternInfo = function( info)\r\n\t\t{\r\n\t\t\t\r\n\t\t\tvar topLeft = info.TopLeft;\r\n\t\t\tvar topRight = info.TopRight;\r\n\t\t\tvar bottomLeft = info.BottomLeft;\r\n\t\t\t\r\n\t\t\tvar moduleSize = this.calculateModuleSize(topLeft, topRight, bottomLeft);\r\n\t\t\tif (moduleSize < 1.0)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(\"QR Error: in detector\");\r\n\t\t\t}\r\n\t\t\tvar dimension = this.computeDimension(topLeft, topRight, bottomLeft, moduleSize);\r\n\t\t\tvar provisionalVersion = Version.getProvisionalVersionForDimension(dimension);\r\n\t\t\tvar modulesBetweenFPCenters = provisionalVersion.DimensionForVersion - 7;\r\n\t\t\t\r\n\t\t\tvar alignmentPattern = null;\r\n\t\t\t// Anything above version 1 has an alignment pattern\r\n\t\t\tif (provisionalVersion.AlignmentPatternCenters.length > 0)\r\n\t\t\t{\r\n\t\t\t\t\r\n\t\t\t\t// Guess where a \"bottom right\" finder pattern would have been\r\n\t\t\t\tvar bottomRightX = topRight.X - topLeft.X + bottomLeft.X;\r\n\t\t\t\tvar bottomRightY = topRight.Y - topLeft.Y + bottomLeft.Y;\r\n\t\t\t\t\r\n\t\t\t\t// Estimate that alignment pattern is closer by 3 modules\r\n\t\t\t\t// from \"bottom right\" to known top left location\r\n\t\t\t\tvar correctionToTopLeft = 1.0 - 3.0 / modulesBetweenFPCenters;\r\n\t\t\t\tvar estAlignmentX = Math.floor (topLeft.X + correctionToTopLeft * (bottomRightX - topLeft.X));\r\n\t\t\t\tvar estAlignmentY = Math.floor (topLeft.Y + correctionToTopLeft * (bottomRightY - topLeft.Y));\r\n\t\t\t\t\r\n\t\t\t\t// Kind of arbitrary -- expand search radius before giving up\r\n\t\t\t\tfor (var i = 4; i <= 16; i <<= 1)\r\n\t\t\t\t{\r\n\t\t\t\t\ttry\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\talignmentPattern = this.findAlignmentInRegion(moduleSize, estAlignmentX, estAlignmentY, i);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcatch (re)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// try next round\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t// If we didn't find alignment pattern... well try anyway without it\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvar transform = this.createTransform(topLeft, topRight, bottomLeft, alignmentPattern, dimension);\r\n\t\t\t\r\n\t\t\tvar bits = this.sampleGrid(this.image, transform, dimension);\r\n\t\t\t\r\n\t\t\tvar points;\r\n\t\t\tif (alignmentPattern == null)\r\n\t\t\t{\r\n\t\t\t\tpoints = new Array(bottomLeft, topLeft, topRight);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tpoints = new Array(bottomLeft, topLeft, topRight, alignmentPattern);\r\n\t\t\t}\r\n\t\t\treturn new DetectorResult(bits, points);\r\n\t\t}\r\n\t\t\r\n\r\n\t\r\n\tthis.detect=function()\r\n\t{\r\n\t\tvar info = new FinderPatternFinder().findFinderPattern(this.image);\r\n\t\t\t\r\n\t\treturn this.processFinderPatternInfo(info); \r\n\t}\r\n}","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nfunction AlignmentPattern(posX, posY, estimatedModuleSize)\r\n{\r\n\tthis.x=posX;\r\n\tthis.y=posY;\r\n\tthis.count = 1;\r\n\tthis.estimatedModuleSize = estimatedModuleSize;\r\n\t\r\n\tthis.__defineGetter__(\"EstimatedModuleSize\", function()\r\n\t{\r\n\t\treturn this.estimatedModuleSize;\r\n\t}); \r\n\tthis.__defineGetter__(\"Count\", function()\r\n\t{\r\n\t\treturn this.count;\r\n\t});\r\n\tthis.__defineGetter__(\"X\", function()\r\n\t{\r\n\t\treturn Math.floor(this.x);\r\n\t});\r\n\tthis.__defineGetter__(\"Y\", function()\r\n\t{\r\n\t\treturn Math.floor(this.y);\r\n\t});\r\n\tthis.incrementCount = function()\r\n\t{\r\n\t\tthis.count++;\r\n\t}\r\n\tthis.aboutEquals=function( moduleSize, i, j)\r\n\t\t{\r\n\t\t\tif (Math.abs(i - this.y) <= moduleSize && Math.abs(j - this.x) <= moduleSize)\r\n\t\t\t{\r\n\t\t\t\tvar moduleSizeDiff = Math.abs(moduleSize - this.estimatedModuleSize);\r\n\t\t\t\treturn moduleSizeDiff <= 1.0 || moduleSizeDiff / this.estimatedModuleSize <= 1.0;\r\n\t\t\t}\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\r\n}\r\n\r\nfunction AlignmentPatternFinder( image, startX, startY, width, height, moduleSize, resultPointCallback)\r\n{\r\n\tthis.image = image;\r\n\tthis.possibleCenters = new Array();\r\n\tthis.startX = startX;\r\n\tthis.startY = startY;\r\n\tthis.width = width;\r\n\tthis.height = height;\r\n\tthis.moduleSize = moduleSize;\r\n\tthis.crossCheckStateCount = new Array(0,0,0);\r\n\tthis.resultPointCallback = resultPointCallback;\r\n\t\r\n\tthis.centerFromEnd=function(stateCount, end)\r\n\t\t{\r\n\t\t\treturn (end - stateCount[2]) - stateCount[1] / 2.0;\r\n\t\t}\r\n\tthis.foundPatternCross = function(stateCount)\r\n\t\t{\r\n\t\t\tvar moduleSize = this.moduleSize;\r\n\t\t\tvar maxVariance = moduleSize / 2.0;\r\n\t\t\tfor (var i = 0; i < 3; i++)\r\n\t\t\t{\r\n\t\t\t\tif (Math.abs(moduleSize - stateCount[i]) >= maxVariance)\r\n\t\t\t\t{\r\n\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\tthis.crossCheckVertical=function( startI, centerJ, maxCount, originalStateCountTotal)\r\n\t\t{\r\n\t\t\tvar image = this.image;\r\n\t\t\t\r\n\t\t\tvar maxI = qrcode.height;\r\n\t\t\tvar stateCount = this.crossCheckStateCount;\r\n\t\t\tstateCount[0] = 0;\r\n\t\t\tstateCount[1] = 0;\r\n\t\t\tstateCount[2] = 0;\r\n\t\t\t\r\n\t\t\t// Start counting up from center\r\n\t\t\tvar i = startI;\r\n\t\t\twhile (i >= 0 && image[centerJ + i*qrcode.width] && stateCount[1] <= maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[1]++;\r\n\t\t\t\ti--;\r\n\t\t\t}\r\n\t\t\t// If already too many modules in this state or ran off the edge:\r\n\t\t\tif (i < 0 || stateCount[1] > maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (i >= 0 && !image[centerJ + i*qrcode.width] && stateCount[0] <= maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[0]++;\r\n\t\t\t\ti--;\r\n\t\t\t}\r\n\t\t\tif (stateCount[0] > maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Now also count down from center\r\n\t\t\ti = startI + 1;\r\n\t\t\twhile (i < maxI && image[centerJ + i*qrcode.width] && stateCount[1] <= maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[1]++;\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t\tif (i == maxI || stateCount[1] > maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (i < maxI && !image[centerJ + i*qrcode.width] && stateCount[2] <= maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[2]++;\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t\tif (stateCount[2] > maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvar stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];\r\n\t\t\tif (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\treturn this.foundPatternCross(stateCount)?this.centerFromEnd(stateCount, i):NaN;\r\n\t\t}\r\n\t\t\r\n\tthis.handlePossibleCenter=function( stateCount, i, j)\r\n\t\t{\r\n\t\t\tvar stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];\r\n\t\t\tvar centerJ = this.centerFromEnd(stateCount, j);\r\n\t\t\tvar centerI = this.crossCheckVertical(i, Math.floor (centerJ), 2 * stateCount[1], stateCountTotal);\r\n\t\t\tif (!isNaN(centerI))\r\n\t\t\t{\r\n\t\t\t\tvar estimatedModuleSize = (stateCount[0] + stateCount[1] + stateCount[2]) / 3.0;\r\n\t\t\t\tvar max = this.possibleCenters.length;\r\n\t\t\t\tfor (var index = 0; index < max; index++)\r\n\t\t\t\t{\r\n\t\t\t\t\tvar center = this.possibleCenters[index];\r\n\t\t\t\t\t// Look for about the same center and module size:\r\n\t\t\t\t\tif (center.aboutEquals(estimatedModuleSize, centerI, centerJ))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treturn new AlignmentPattern(centerJ, centerI, estimatedModuleSize);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t// Hadn't found this before; save it\r\n\t\t\t\tvar point = new AlignmentPattern(centerJ, centerI, estimatedModuleSize);\r\n\t\t\t\tthis.possibleCenters.push(point);\r\n\t\t\t\tif (this.resultPointCallback != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tthis.resultPointCallback.foundPossibleResultPoint(point);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn null;\r\n\t\t}\r\n\t\t\r\n\tthis.find = function()\r\n\t{\r\n\t\t\tvar startX = this.startX;\r\n\t\t\tvar height = this.height;\r\n\t\t\tvar maxJ = startX + width;\r\n\t\t\tvar middleI = startY + (height >> 1);\r\n\t\t\t// We are looking for black/white/black modules in 1:1:1 ratio;\r\n\t\t\t// this tracks the number of black/white/black modules seen so far\r\n\t\t\tvar stateCount = new Array(0,0,0);\r\n\t\t\tfor (var iGen = 0; iGen < height; iGen++)\r\n\t\t\t{\r\n\t\t\t\t// Search from middle outwards\r\n\t\t\t\tvar i = middleI + ((iGen & 0x01) == 0?((iGen + 1) >> 1):- ((iGen + 1) >> 1));\r\n\t\t\t\tstateCount[0] = 0;\r\n\t\t\t\tstateCount[1] = 0;\r\n\t\t\t\tstateCount[2] = 0;\r\n\t\t\t\tvar j = startX;\r\n\t\t\t\t// Burn off leading white pixels before anything else; if we start in the middle of\r\n\t\t\t\t// a white run, it doesn't make sense to count its length, since we don't know if the\r\n\t\t\t\t// white run continued to the left of the start point\r\n\t\t\t\twhile (j < maxJ && !image[j + qrcode.width* i])\r\n\t\t\t\t{\r\n\t\t\t\t\tj++;\r\n\t\t\t\t}\r\n\t\t\t\tvar currentState = 0;\r\n\t\t\t\twhile (j < maxJ)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (image[j + i*qrcode.width])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// Black pixel\r\n\t\t\t\t\t\tif (currentState == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t// Counting black pixels\r\n\t\t\t\t\t\t\tstateCount[currentState]++;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t// Counting white pixels\r\n\t\t\t\t\t\t\tif (currentState == 2)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t// A winner?\r\n\t\t\t\t\t\t\t\tif (this.foundPatternCross(stateCount))\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t// Yes\r\n\t\t\t\t\t\t\t\t\tvar confirmed = this.handlePossibleCenter(stateCount, i, j);\r\n\t\t\t\t\t\t\t\t\tif (confirmed != null)\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\treturn confirmed;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\tstateCount[0] = stateCount[2];\r\n\t\t\t\t\t\t\t\tstateCount[1] = 1;\r\n\t\t\t\t\t\t\t\tstateCount[2] = 0;\r\n\t\t\t\t\t\t\t\tcurrentState = 1;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tstateCount[++currentState]++;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// White pixel\r\n\t\t\t\t\t\tif (currentState == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t// Counting black pixels\r\n\t\t\t\t\t\t\tcurrentState++;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tstateCount[currentState]++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tj++;\r\n\t\t\t\t}\r\n\t\t\t\tif (this.foundPatternCross(stateCount))\r\n\t\t\t\t{\r\n\t\t\t\t\tvar confirmed = this.handlePossibleCenter(stateCount, i, maxJ);\r\n\t\t\t\t\tif (confirmed != null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treturn confirmed;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Hmm, nothing we saw was observed and confirmed twice. If we had\r\n\t\t\t// any guess at all, return it.\r\n\t\t\tif (!(this.possibleCenters.length == 0))\r\n\t\t\t{\r\n\t\t\t\treturn this.possibleCenters[0];\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tthrow new Error(\"QR Error: Couldn't find enough alignment patterns\");\r\n\t\t}\r\n\t\r\n}","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nvar MIN_SKIP = 3; // 1 pixel/module times 3 modules/center\r\nvar MAX_MODULES = 57; // support up to version 10 for mobile clients\r\nvar CENTER_QUORUM = 2;\r\n\r\nqrcode.orderBestPatterns=function(patterns)\r\n\t\t{\r\n\t\t\t\r\n\t\t\tfunction distance( pattern1, pattern2)\r\n\t\t\t{\r\n\t\t\t\tvar xDiff = pattern1.X - pattern2.X;\r\n\t\t\t\tvar yDiff = pattern1.Y - pattern2.Y;\r\n\t\t\t\treturn Math.sqrt( (xDiff * xDiff + yDiff * yDiff));\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t/// Returns the z component of the cross product between vectors BC and BA.\r\n\t\t\tfunction crossProductZ( pointA, pointB, pointC)\r\n\t\t\t{\r\n\t\t\t\tvar bX = pointB.x;\r\n\t\t\t\tvar bY = pointB.y;\r\n\t\t\t\treturn ((pointC.x - bX) * (pointA.y - bY)) - ((pointC.y - bY) * (pointA.x - bX));\r\n\t\t\t}\r\n\r\n\t\t\t\r\n\t\t\t// Find distances between pattern centers\r\n\t\t\tvar zeroOneDistance = distance(patterns[0], patterns[1]);\r\n\t\t\tvar oneTwoDistance = distance(patterns[1], patterns[2]);\r\n\t\t\tvar zeroTwoDistance = distance(patterns[0], patterns[2]);\r\n\t\t\t\r\n\t\t\tvar pointA, pointB, pointC;\r\n\t\t\t// Assume one closest to other two is B; A and C will just be guesses at first\r\n\t\t\tif (oneTwoDistance >= zeroOneDistance && oneTwoDistance >= zeroTwoDistance)\r\n\t\t\t{\r\n\t\t\t\tpointB = patterns[0];\r\n\t\t\t\tpointA = patterns[1];\r\n\t\t\t\tpointC = patterns[2];\r\n\t\t\t}\r\n\t\t\telse if (zeroTwoDistance >= oneTwoDistance && zeroTwoDistance >= zeroOneDistance)\r\n\t\t\t{\r\n\t\t\t\tpointB = patterns[1];\r\n\t\t\t\tpointA = patterns[0];\r\n\t\t\t\tpointC = patterns[2];\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tpointB = patterns[2];\r\n\t\t\t\tpointA = patterns[0];\r\n\t\t\t\tpointC = patterns[1];\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Use cross product to figure out whether A and C are correct or flipped.\r\n\t\t\t// This asks whether BC x BA has a positive z component, which is the arrangement\r\n\t\t\t// we want for A, B, C. If it's negative, then we've got it flipped around and\r\n\t\t\t// should swap A and C.\r\n\t\t\tif (crossProductZ(pointA, pointB, pointC) < 0.0)\r\n\t\t\t{\r\n\t\t\t\tvar temp = pointA;\r\n\t\t\t\tpointA = pointC;\r\n\t\t\t\tpointC = temp;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpatterns[0] = pointA;\r\n\t\t\tpatterns[1] = pointB;\r\n\t\t\tpatterns[2] = pointC;\r\n\t\t}\r\n\r\n\r\nfunction FinderPattern(posX, posY, estimatedModuleSize)\r\n{\r\n\tthis.x=posX;\r\n\tthis.y=posY;\r\n\tthis.count = 1;\r\n\tthis.estimatedModuleSize = estimatedModuleSize;\r\n\t\r\n\tthis.__defineGetter__(\"EstimatedModuleSize\", function()\r\n\t{\r\n\t\treturn this.estimatedModuleSize;\r\n\t}); \r\n\tthis.__defineGetter__(\"Count\", function()\r\n\t{\r\n\t\treturn this.count;\r\n\t});\r\n\tthis.__defineGetter__(\"X\", function()\r\n\t{\r\n\t\treturn this.x;\r\n\t});\r\n\tthis.__defineGetter__(\"Y\", function()\r\n\t{\r\n\t\treturn this.y;\r\n\t});\r\n\tthis.incrementCount = function()\r\n\t{\r\n\t\tthis.count++;\r\n\t}\r\n\tthis.aboutEquals=function( moduleSize, i, j)\r\n\t\t{\r\n\t\t\tif (Math.abs(i - this.y) <= moduleSize && Math.abs(j - this.x) <= moduleSize)\r\n\t\t\t{\r\n\t\t\t\tvar moduleSizeDiff = Math.abs(moduleSize - this.estimatedModuleSize);\r\n\t\t\t\treturn moduleSizeDiff <= 1.0 || moduleSizeDiff / this.estimatedModuleSize <= 1.0;\r\n\t\t\t}\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\r\n}\r\n\r\nfunction FinderPatternInfo(patternCenters)\r\n{\r\n\tthis.bottomLeft = patternCenters[0];\r\n\tthis.topLeft = patternCenters[1];\r\n\tthis.topRight = patternCenters[2];\r\n\tthis.__defineGetter__(\"BottomLeft\", function()\r\n\t{\r\n\t\treturn this.bottomLeft;\r\n\t}); \r\n\tthis.__defineGetter__(\"TopLeft\", function()\r\n\t{\r\n\t\treturn this.topLeft;\r\n\t}); \r\n\tthis.__defineGetter__(\"TopRight\", function()\r\n\t{\r\n\t\treturn this.topRight;\r\n\t}); \r\n}\r\n\r\n/**\r\n * Finds a finder pattern. A finder pattern is one of the patterns in the corners\r\n * of the QR codes. The patterns consist of black and white squares of specific proportions.\r\n * If you consider a line through the pattern, the color changes proportionally between white and black:\r\n * 1 - 1 - 3 - 1 - 1\r\n * black - white - black - white - black\r\n */\r\nfunction FinderPatternFinder()\r\n{\r\n\tthis.image=null;\r\n\tthis.possibleCenters = [];\r\n\tthis.hasSkipped = false;\r\n\tthis.crossCheckStateCount = new Array(0,0,0,0,0);\r\n\tthis.resultPointCallback = null;\r\n\t\r\n\tthis.__defineGetter__(\"CrossCheckStateCount\", function()\r\n\t{\r\n\t\tthis.crossCheckStateCount[0] = 0;\r\n\t\tthis.crossCheckStateCount[1] = 0;\r\n\t\tthis.crossCheckStateCount[2] = 0;\r\n\t\tthis.crossCheckStateCount[3] = 0;\r\n\t\tthis.crossCheckStateCount[4] = 0;\r\n\t\treturn this.crossCheckStateCount;\r\n\t}); \r\n\t\r\n\tthis.foundPatternCross=function( stateCount)\r\n\t\t{\r\n\t\t\tvar totalModuleSize = 0;\r\n\t\t\tfor (var i = 0; i < 5; i++)\r\n\t\t\t{\r\n\t\t\t\tvar count = stateCount[i];\r\n\t\t\t\tif (count == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\ttotalModuleSize += count;\r\n\t\t\t}\r\n\t\t\tif (totalModuleSize < 7)\r\n\t\t\t{\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\tvar moduleSize = Math.floor(totalModuleSize / 7);\r\n\t\t\tvar maxVariance = Math.floor(moduleSize * 0.7);\r\n\t\t\t// Allow less than 70% variance from 1-1-3-1-1 proportions\r\n\t\t\treturn Math.abs(moduleSize - stateCount[0]) < maxVariance\r\n\t\t\t\t&& Math.abs(moduleSize - stateCount[1]) < maxVariance\r\n\t\t\t\t&& Math.abs(3 * moduleSize - stateCount[2]) < 3 * maxVariance\r\n\t\t\t\t&& Math.abs(moduleSize - stateCount[3]) < maxVariance\r\n\t\t\t\t&& Math.abs(moduleSize - stateCount[4]) < maxVariance;\r\n\t\t}\r\n\tthis.centerFromEnd=function( stateCount, end)\r\n\t\t{\r\n\t\t\treturn (end - stateCount[4] - stateCount[3]) - stateCount[2] / 2.0;\r\n\t\t}\r\n\tthis.crossCheckVertical=function( startI, centerJ, maxCount, originalStateCountTotal)\r\n\t\t{\r\n\t\t\tvar image = this.image;\r\n\t\t\t\r\n\t\t\tvar maxI = qrcode.height;\r\n\t\t\tvar stateCount = this.CrossCheckStateCount;\r\n\t\t\t\r\n\t\t\t// Start counting up from center\r\n\t\t\tvar i = startI;\r\n\t\t\twhile (i >= 0 && image[centerJ + i*qrcode.width])\r\n\t\t\t{\r\n\t\t\t\tstateCount[2]++;\r\n\t\t\t\ti--;\r\n\t\t\t}\r\n\t\t\tif (i < 0)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (i >= 0 && !image[centerJ +i*qrcode.width] && stateCount[1] <= maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[1]++;\r\n\t\t\t\ti--;\r\n\t\t\t}\r\n\t\t\t// If already too many modules in this state or ran off the edge:\r\n\t\t\tif (i < 0 || stateCount[1] > maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (i >= 0 && image[centerJ + i*qrcode.width] && stateCount[0] <= maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[0]++;\r\n\t\t\t\ti--;\r\n\t\t\t}\r\n\t\t\tif (stateCount[0] > maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Now also count down from center\r\n\t\t\ti = startI + 1;\r\n\t\t\twhile (i < maxI && image[centerJ +i*qrcode.width])\r\n\t\t\t{\r\n\t\t\t\tstateCount[2]++;\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t\tif (i == maxI)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (i < maxI && !image[centerJ + i*qrcode.width] && stateCount[3] < maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[3]++;\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t\tif (i == maxI || stateCount[3] >= maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (i < maxI && image[centerJ + i*qrcode.width] && stateCount[4] < maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[4]++;\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t\tif (stateCount[4] >= maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// If we found a finder-pattern-like section, but its size is more than 40% different than\r\n\t\t\t// the original, assume it's a false positive\r\n\t\t\tvar stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];\r\n\t\t\tif (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\treturn this.foundPatternCross(stateCount)?this.centerFromEnd(stateCount, i):NaN;\r\n\t\t}\r\n\tthis.crossCheckHorizontal=function( startJ, centerI, maxCount, originalStateCountTotal)\r\n\t\t{\r\n\t\t\tvar image = this.image;\r\n\t\t\t\r\n\t\t\tvar maxJ = qrcode.width;\r\n\t\t\tvar stateCount = this.CrossCheckStateCount;\r\n\t\t\t\r\n\t\t\tvar j = startJ;\r\n\t\t\twhile (j >= 0 && image[j+ centerI*qrcode.width])\r\n\t\t\t{\r\n\t\t\t\tstateCount[2]++;\r\n\t\t\t\tj--;\r\n\t\t\t}\r\n\t\t\tif (j < 0)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (j >= 0 && !image[j+ centerI*qrcode.width] && stateCount[1] <= maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[1]++;\r\n\t\t\t\tj--;\r\n\t\t\t}\r\n\t\t\tif (j < 0 || stateCount[1] > maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (j >= 0 && image[j+ centerI*qrcode.width] && stateCount[0] <= maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[0]++;\r\n\t\t\t\tj--;\r\n\t\t\t}\r\n\t\t\tif (stateCount[0] > maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tj = startJ + 1;\r\n\t\t\twhile (j < maxJ && image[j+ centerI*qrcode.width])\r\n\t\t\t{\r\n\t\t\t\tstateCount[2]++;\r\n\t\t\t\tj++;\r\n\t\t\t}\r\n\t\t\tif (j == maxJ)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (j < maxJ && !image[j+ centerI*qrcode.width] && stateCount[3] < maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[3]++;\r\n\t\t\t\tj++;\r\n\t\t\t}\r\n\t\t\tif (j == maxJ || stateCount[3] >= maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (j < maxJ && image[j+ centerI*qrcode.width] && stateCount[4] < maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[4]++;\r\n\t\t\t\tj++;\r\n\t\t\t}\r\n\t\t\tif (stateCount[4] >= maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// If we found a finder-pattern-like section, but its size is significantly different than\r\n\t\t\t// the original, assume it's a false positive\r\n\t\t\tvar stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];\r\n\t\t\tif (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= originalStateCountTotal)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\treturn this.foundPatternCross(stateCount)?this.centerFromEnd(stateCount, j):NaN;\r\n\t\t}\r\n\tthis.handlePossibleCenter=function( stateCount, i, j)\r\n\t\t{\r\n\t\t\tvar stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];\r\n\t\t\tvar centerJ = this.centerFromEnd(stateCount, j); //float\r\n\t\t\tvar centerI = this.crossCheckVertical(i, Math.floor( centerJ), stateCount[2], stateCountTotal); //float\r\n\t\t\tif (!isNaN(centerI))\r\n\t\t\t{\r\n\t\t\t\t// Re-cross check\r\n\t\t\t\tcenterJ = this.crossCheckHorizontal(Math.floor( centerJ), Math.floor( centerI), stateCount[2], stateCountTotal);\r\n\t\t\t\tif (!isNaN(centerJ))\r\n\t\t\t\t{\r\n\t\t\t\t\tvar estimatedModuleSize = stateCountTotal / 7.0;\r\n\t\t\t\t\tvar found = false;\r\n\t\t\t\t\tvar max = this.possibleCenters.length;\r\n\t\t\t\t\tfor (var index = 0; index < max; index++)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tvar center = this.possibleCenters[index];\r\n\t\t\t\t\t\t// Look for about the same center and module size:\r\n\t\t\t\t\t\tif (center.aboutEquals(estimatedModuleSize, centerI, centerJ))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tcenter.incrementCount();\r\n\t\t\t\t\t\t\tfound = true;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (!found)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tvar point = new FinderPattern(centerJ, centerI, estimatedModuleSize);\r\n\t\t\t\t\t\tthis.possibleCenters.push(point);\r\n\t\t\t\t\t\tif (this.resultPointCallback != null)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tthis.resultPointCallback.foundPossibleResultPoint(point);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\t\r\n\tthis.selectBestPatterns=function()\r\n\t\t{\r\n\t\t\t\r\n\t\t\tvar startSize = this.possibleCenters.length;\r\n\t\t\tif (startSize < 3)\r\n\t\t\t{\r\n\t\t\t\t// Couldn't find enough finder patterns\r\n\t\t\t\tthrow new Error(\"QR Error: Couldn't find enough finder patterns (found \" + startSize + \")\");\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Filter outlier possibilities whose module size is too different\r\n\t\t\tif (startSize > 3)\r\n\t\t\t{\r\n\t\t\t\t// But we can only afford to do so if we have at least 4 possibilities to choose from\r\n\t\t\t\tvar totalModuleSize = 0.0;\r\n var square = 0.0;\r\n\t\t\t\tfor (var i = 0; i < startSize; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\t//totalModuleSize += this.possibleCenters[i].EstimatedModuleSize;\r\n var\tcenterValue=this.possibleCenters[i].EstimatedModuleSize;\r\n\t\t\t\t\ttotalModuleSize += centerValue;\r\n\t\t\t\t\tsquare += (centerValue * centerValue);\r\n\t\t\t\t}\r\n\t\t\t\tvar average = totalModuleSize / startSize;\r\n this.possibleCenters.sort(function(center1,center2) {\r\n\t\t\t\t var dA=Math.abs(center2.EstimatedModuleSize - average);\r\n\t\t\t\t var dB=Math.abs(center1.EstimatedModuleSize - average);\r\n\t\t\t\t if (dA < dB) {\r\n\t\t\t\t \t return (-1);\r\n\t\t\t\t } else if (dA == dB) {\r\n\t\t\t\t \t return 0;\r\n\t\t\t\t } else {\r\n\t\t\t\t \t return 1;\r\n\t\t\t\t }\r\n\t\t\t\t\t});\r\n\r\n\t\t\t\tvar stdDev = Math.sqrt(square / startSize - average * average);\r\n\t\t\t\tvar limit = Math.max(0.2 * average, stdDev);\r\n\t\t\t\t//for (var i = 0; i < this.possibleCenters.length && this.possibleCenters.length > 3; i++)\r\n\t\t\t\tfor (var i = this.possibleCenters.length - 1; i >= 0 ; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tvar pattern = this.possibleCenters[i];\r\n\t\t\t\t\t//if (Math.abs(pattern.EstimatedModuleSize - average) > 0.2 * average)\r\n if (Math.abs(pattern.EstimatedModuleSize - average) > limit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t//this.possibleCenters.remove(i);\r\n\t\t\t\t\t\tthis.possibleCenters.splice(i,1);\r\n\t\t\t\t\t\t//i--;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif (this.possibleCenters.length > 3)\r\n\t\t\t{\r\n\t\t\t\t// Throw away all but those first size candidate points we found.\r\n\t\t\t\tthis.possibleCenters.sort(function(a, b){\r\n\t\t\t\t\tif (a.count > b.count){return -1;}\r\n\t\t\t\t\tif (a.count < b.count){return 1;}\r\n\t\t\t\t\treturn 0;\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\treturn new Array( this.possibleCenters[0], this.possibleCenters[1], this.possibleCenters[2]);\r\n\t\t}\r\n\t\t\r\n\tthis.findRowSkip=function()\r\n\t\t{\r\n\t\t\tvar max = this.possibleCenters.length;\r\n\t\t\tif (max <= 1)\r\n\t\t\t{\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t\tvar firstConfirmedCenter = null;\r\n\t\t\tfor (var i = 0; i < max; i++)\r\n\t\t\t{\r\n\t\t\t\tvar center = this.possibleCenters[i];\r\n\t\t\t\tif (center.Count >= CENTER_QUORUM)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (firstConfirmedCenter == null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfirstConfirmedCenter = center;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// We have two confirmed centers\r\n\t\t\t\t\t\t// How far down can we skip before resuming looking for the next\r\n\t\t\t\t\t\t// pattern? In the worst case, only the difference between the\r\n\t\t\t\t\t\t// difference in the x / y coordinates of the two centers.\r\n\t\t\t\t\t\t// This is the case where you find top left last.\r\n\t\t\t\t\t\tthis.hasSkipped = true;\r\n\t\t\t\t\t\treturn Math.floor ((Math.abs(firstConfirmedCenter.X - center.X) - Math.abs(firstConfirmedCenter.Y - center.Y)) / 2);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\r\n\tthis.haveMultiplyConfirmedCenters=function()\r\n\t\t{\r\n\t\t\tvar confirmedCount = 0;\r\n\t\t\tvar totalModuleSize = 0.0;\r\n\t\t\tvar max = this.possibleCenters.length;\r\n\t\t\tfor (var i = 0; i < max; i++)\r\n\t\t\t{\r\n\t\t\t\tvar pattern = this.possibleCenters[i];\r\n\t\t\t\tif (pattern.Count >= CENTER_QUORUM)\r\n\t\t\t\t{\r\n\t\t\t\t\tconfirmedCount++;\r\n\t\t\t\t\ttotalModuleSize += pattern.EstimatedModuleSize;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (confirmedCount < 3)\r\n\t\t\t{\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\t// OK, we have at least 3 confirmed centers, but, it's possible that one is a \"false positive\"\r\n\t\t\t// and that we need to keep looking. We detect this by asking if the estimated module sizes\r\n\t\t\t// vary too much. We arbitrarily say that when the total deviation from average exceeds\r\n\t\t\t// 5% of the total module size estimates, it's too much.\r\n\t\t\tvar average = totalModuleSize / max;\r\n\t\t\tvar totalDeviation = 0.0;\r\n\t\t\tfor (var i = 0; i < max; i++)\r\n\t\t\t{\r\n\t\t\t\tpattern = this.possibleCenters[i];\r\n\t\t\t\ttotalDeviation += Math.abs(pattern.EstimatedModuleSize - average);\r\n\t\t\t}\r\n\t\t\treturn totalDeviation <= 0.05 * totalModuleSize;\r\n\t\t}\r\n\t\t\r\n\tthis.findFinderPattern = function(image){\r\n\t\tvar tryHarder = false;\r\n\t\tthis.image=image;\r\n\t\tvar maxI = qrcode.height;\r\n\t\tvar maxJ = qrcode.width;\r\n // Let's assume that the maximum version QR Code we support takes up 1/4 the height of the\r\n // image, and then account for the center being 3 modules in size. This gives the smallest\r\n // number of pixels the center could be, so skip this often. When trying harder, look for all\r\n // QR versions regardless of how dense they are.\r\n var iSkip = Math.floor((3 * maxI) / (4 * MAX_MODULES));\r\n if (iSkip < MIN_SKIP || tryHarder)\r\n\t\t{\r\n\t\t\t\tiSkip = MIN_SKIP;\r\n\t\t}\r\n\t\t\r\n\t\tvar done = false;\r\n\t\tvar stateCount = new Array(5);\r\n\t\tfor (var i = iSkip - 1; i < maxI && !done; i += iSkip)\r\n\t\t{\r\n\t\t\t// Get a row of black/white values\r\n\t\t\tstateCount[0] = 0;\r\n\t\t\tstateCount[1] = 0;\r\n\t\t\tstateCount[2] = 0;\r\n\t\t\tstateCount[3] = 0;\r\n\t\t\tstateCount[4] = 0;\r\n\t\t\tvar currentState = 0;\r\n\t\t\tfor (var j = 0; j < maxJ; j++)\r\n\t\t\t{\r\n\t\t\t\tif (image[j+i*qrcode.width] )\r\n\t\t\t\t{\r\n\t\t\t\t\t// Black pixel\r\n\t\t\t\t\tif ((currentState & 1) == 1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// Counting white pixels\r\n\t\t\t\t\t\tcurrentState++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tstateCount[currentState]++;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t// White pixel\r\n\t\t\t\t\tif ((currentState & 1) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// Counting black pixels\r\n\t\t\t\t\t\tif (currentState == 4)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t// A winner?\r\n\t\t\t\t\t\t\tif (this.foundPatternCross(stateCount))\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t// Yes\r\n\t\t\t\t\t\t\t\tvar confirmed = this.handlePossibleCenter(stateCount, i, j);\r\n\t\t\t\t\t\t\t\tif (confirmed)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t// Start examining every other line. Checking each line turned out to be too\r\n\t\t\t\t\t\t\t\t\t// expensive and didn't improve performance.\r\n\t\t\t\t\t\t\t\t\tiSkip = 2;\r\n\t\t\t\t\t\t\t\t\tif (this.hasSkipped)\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\tdone = this.haveMultiplyConfirmedCenters();\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\tvar rowSkip = this.findRowSkip();\r\n\t\t\t\t\t\t\t\t\t\tif (rowSkip > stateCount[2])\r\n\t\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\t\t// Skip rows between row of lower confirmed center\r\n\t\t\t\t\t\t\t\t\t\t\t// and top of presumed third confirmed center\r\n\t\t\t\t\t\t\t\t\t\t\t// but back up a bit to get a full chance of detecting\r\n\t\t\t\t\t\t\t\t\t\t\t// it, entire width of center of finder pattern\r\n\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t// Skip by rowSkip, but back off by stateCount[2] (size of last center\r\n\t\t\t\t\t\t\t\t\t\t\t// of pattern we saw) to be conservative, and also back off by iSkip which\r\n\t\t\t\t\t\t\t\t\t\t\t// is about to be re-added\r\n\t\t\t\t\t\t\t\t\t\t\ti += rowSkip - stateCount[2] - iSkip;\r\n\t\t\t\t\t\t\t\t\t\t\tj = maxJ - 1;\r\n\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t// Advance to next black pixel\r\n\t\t\t\t\t\t\t\t\tdo \r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\tj++;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\twhile (j < maxJ && !image[j + i*qrcode.width]);\r\n\t\t\t\t\t\t\t\t\tj--; // back up to that last white pixel\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t// Clear state to start looking again\r\n\t\t\t\t\t\t\t\tcurrentState = 0;\r\n\t\t\t\t\t\t\t\tstateCount[0] = 0;\r\n\t\t\t\t\t\t\t\tstateCount[1] = 0;\r\n\t\t\t\t\t\t\t\tstateCount[2] = 0;\r\n\t\t\t\t\t\t\t\tstateCount[3] = 0;\r\n\t\t\t\t\t\t\t\tstateCount[4] = 0;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t// No, shift counts back by two\r\n\t\t\t\t\t\t\t\tstateCount[0] = stateCount[2];\r\n\t\t\t\t\t\t\t\tstateCount[1] = stateCount[3];\r\n\t\t\t\t\t\t\t\tstateCount[2] = stateCount[4];\r\n\t\t\t\t\t\t\t\tstateCount[3] = 1;\r\n\t\t\t\t\t\t\t\tstateCount[4] = 0;\r\n\t\t\t\t\t\t\t\tcurrentState = 3;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tstateCount[++currentState]++;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// Counting white pixels\r\n\t\t\t\t\t\tstateCount[currentState]++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (this.foundPatternCross(stateCount))\r\n\t\t\t{\r\n\t\t\t\tvar confirmed = this.handlePossibleCenter(stateCount, i, maxJ);\r\n\t\t\t\tif (confirmed)\r\n\t\t\t\t{\r\n\t\t\t\t\tiSkip = stateCount[0];\r\n\t\t\t\t\tif (this.hasSkipped)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// Found a third one\r\n\t\t\t\t\t\tdone = this.haveMultiplyConfirmedCenters();\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tvar patternInfo = this.selectBestPatterns();\r\n\t\tqrcode.orderBestPatterns(patternInfo);\r\n\t\t\r\n\t\treturn new FinderPatternInfo(patternInfo);\r\n\t};\r\n}","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nvar FORMAT_INFO_MASK_QR = 0x5412;\r\nvar 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));\r\nvar BITS_SET_IN_HALF_BYTE = new Array(0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4);\r\n\r\n\r\nfunction FormatInformation(formatInfo)\r\n{\r\n\tthis.errorCorrectionLevel = ErrorCorrectionLevel.forBits((formatInfo >> 3) & 0x03);\r\n\tthis.dataMask = (formatInfo & 0x07);\r\n\r\n\tthis.__defineGetter__(\"ErrorCorrectionLevel\", function()\r\n\t{\r\n\t\treturn this.errorCorrectionLevel;\r\n\t});\r\n\tthis.__defineGetter__(\"DataMask\", function()\r\n\t{\r\n\t\treturn this.dataMask;\r\n\t});\r\n\tthis.GetHashCode=function()\r\n\t{\r\n\t\treturn (this.errorCorrectionLevel.ordinal() << 3) | this.dataMask;\r\n\t}\r\n\tthis.Equals=function( o)\r\n\t{\r\n\t\tvar other = o;\r\n\t\treturn this.errorCorrectionLevel == other.errorCorrectionLevel && this.dataMask == other.dataMask;\r\n\t}\r\n}\r\n\r\nFormatInformation.numBitsDiffering=function( a, b)\r\n{\r\n\ta ^= b; // a now has a 1 bit exactly where its bit differs with b's\r\n\t// Count bits set quickly with a series of lookups:\r\n\treturn 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)];\r\n}\r\n\r\nFormatInformation.decodeFormatInformation=function( maskedFormatInfo)\r\n{\r\n\tvar formatInfo = FormatInformation.doDecodeFormatInformation(maskedFormatInfo);\r\n\tif (formatInfo != null)\r\n\t{\r\n\t\treturn formatInfo;\r\n\t}\r\n\t// Should return null, but, some QR codes apparently\r\n\t// do not mask this info. Try again by actually masking the pattern\r\n\t// first\r\n\treturn FormatInformation.doDecodeFormatInformation(maskedFormatInfo ^ FORMAT_INFO_MASK_QR);\r\n}\r\nFormatInformation.doDecodeFormatInformation=function( maskedFormatInfo)\r\n{\r\n\t// Find the int in FORMAT_INFO_DECODE_LOOKUP with fewest bits differing\r\n\tvar bestDifference = 0xffffffff;\r\n\tvar bestFormatInfo = 0;\r\n\tfor (var i = 0; i < FORMAT_INFO_DECODE_LOOKUP.length; i++)\r\n\t{\r\n\t\tvar decodeInfo = FORMAT_INFO_DECODE_LOOKUP[i];\r\n\t\tvar targetInfo = decodeInfo[0];\r\n\t\tif (targetInfo == maskedFormatInfo)\r\n\t\t{\r\n\t\t\t// Found an exact match\r\n\t\t\treturn new FormatInformation(decodeInfo[1]);\r\n\t\t}\r\n\t\tvar bitsDifference = this.numBitsDiffering(maskedFormatInfo, targetInfo);\r\n\t\tif (bitsDifference < bestDifference)\r\n\t\t{\r\n\t\t\tbestFormatInfo = decodeInfo[1];\r\n\t\t\tbestDifference = bitsDifference;\r\n\t\t}\r\n\t}\r\n\t// Hamming distance of the 32 masked codes is 7, by construction, so <= 3 bits\r\n\t// differing means we found a match\r\n\tif (bestDifference <= 3)\r\n\t{\r\n\t\treturn new FormatInformation(bestFormatInfo);\r\n\t}\r\n\treturn null;\r\n}\r\n\r\n\t\t","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nfunction ErrorCorrectionLevel(ordinal, bits, name)\r\n{\r\n\tthis.ordinal_Renamed_Field = ordinal;\r\n\tthis.bits = bits;\r\n\tthis.name = name;\r\n\tthis.__defineGetter__(\"Bits\", function()\r\n\t{\r\n\t\treturn this.bits;\r\n\t});\r\n\tthis.__defineGetter__(\"Name\", function()\r\n\t{\r\n\t\treturn this.name;\r\n\t});\r\n\tthis.ordinal=function()\r\n\t{\r\n\t\treturn this.ordinal_Renamed_Field;\r\n\t}\r\n}\r\n\r\nErrorCorrectionLevel.forBits=function( bits)\r\n{\r\n\tif (bits < 0 || bits >= FOR_BITS.length)\r\n\t{\r\n\t\tthrow new Error(\"QR Error: ArgumentException\");\r\n\t}\r\n\treturn FOR_BITS[bits];\r\n}\r\n\r\nvar L = new ErrorCorrectionLevel(0, 0x01, \"L\");\r\nvar M = new ErrorCorrectionLevel(1, 0x00, \"M\");\r\nvar Q = new ErrorCorrectionLevel(2, 0x03, \"Q\");\r\nvar H = new ErrorCorrectionLevel(3, 0x02, \"H\");\r\nvar FOR_BITS = new Array( M, L, H, Q);","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nfunction BitMatrix( width, height)\r\n{\r\n\tif(!height)\r\n\t\theight=width;\r\n\tif (width < 1 || height < 1)\r\n\t{\r\n\t\tthrow new Error(\"QR Error: Both dimensions must be greater than 0\");\r\n\t}\r\n\tthis.width = width;\r\n\tthis.height = height;\r\n\tvar rowSize = width >> 5;\r\n\tif ((width & 0x1f) != 0)\r\n\t{\r\n\t\trowSize++;\r\n\t}\r\n\tthis.rowSize = rowSize;\r\n\tthis.bits = new Array(rowSize * height);\r\n\tfor(var i=0;i> 5);\r\n\t\t\treturn ((URShift(this.bits[offset], (x & 0x1f))) & 1) != 0;\r\n\t\t}\r\n\tthis.set_Renamed=function( x, y)\r\n\t\t{\r\n\t\t\tvar offset = y * this.rowSize + (x >> 5);\r\n\t\t\tthis.bits[offset] |= 1 << (x & 0x1f);\r\n\t\t}\r\n\tthis.flip=function( x, y)\r\n\t\t{\r\n\t\t\tvar offset = y * this.rowSize + (x >> 5);\r\n\t\t\tthis.bits[offset] ^= 1 << (x & 0x1f);\r\n\t\t}\r\n\tthis.clear=function()\r\n\t\t{\r\n\t\t\tvar max = this.bits.length;\r\n\t\t\tfor (var i = 0; i < max; i++)\r\n\t\t\t{\r\n\t\t\t\tthis.bits[i] = 0;\r\n\t\t\t}\r\n\t\t}\r\n\tthis.setRegion=function( left, top, width, height)\r\n\t\t{\r\n\t\t\tif (top < 0 || left < 0)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(\"QR Error: Left and top must be nonnegative\");\r\n\t\t\t}\r\n\t\t\tif (height < 1 || width < 1)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(\"QR Error: Height and width must be at least 1\");\r\n\t\t\t}\r\n\t\t\tvar right = left + width;\r\n\t\t\tvar bottom = top + height;\r\n\t\t\tif (bottom > this.height || right > this.width)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(\"QR Error: The region must fit inside the matrix\");\r\n\t\t\t}\r\n\t\t\tfor (var y = top; y < bottom; y++)\r\n\t\t\t{\r\n\t\t\t\tvar offset = y * this.rowSize;\r\n\t\t\t\tfor (var x = left; x < right; x++)\r\n\t\t\t\t{\r\n\t\t\t\t\tthis.bits[offset + (x >> 5)] |= 1 << (x & 0x1f);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n}","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nfunction DataBlock(numDataCodewords, codewords)\r\n{\r\n\tthis.numDataCodewords = numDataCodewords;\r\n\tthis.codewords = codewords;\r\n\t\r\n\tthis.__defineGetter__(\"NumDataCodewords\", function()\r\n\t{\r\n\t\treturn this.numDataCodewords;\r\n\t});\r\n\tthis.__defineGetter__(\"Codewords\", function()\r\n\t{\r\n\t\treturn this.codewords;\r\n\t});\r\n}\t\r\n\t\r\nDataBlock.getDataBlocks=function(rawCodewords, version, ecLevel)\r\n{\r\n\t\r\n\tif (rawCodewords.length != version.TotalCodewords)\r\n\t{\r\n\t\tthrow new Error(\"QR Error: ArgumentException\");\r\n\t}\r\n\t\r\n\t// Figure out the number and size of data blocks used by this version and\r\n\t// error correction level\r\n\tvar ecBlocks = version.getECBlocksForLevel(ecLevel);\r\n\t\r\n\t// First count the total number of data blocks\r\n\tvar totalBlocks = 0;\r\n\tvar ecBlockArray = ecBlocks.getECBlocks();\r\n\tfor (var i = 0; i < ecBlockArray.length; i++)\r\n\t{\r\n\t\ttotalBlocks += ecBlockArray[i].Count;\r\n\t}\r\n\t\r\n\t// Now establish DataBlocks of the appropriate size and number of data codewords\r\n\tvar result = new Array(totalBlocks);\r\n\tvar numResultBlocks = 0;\r\n\tfor (var j = 0; j < ecBlockArray.length; j++)\r\n\t{\r\n\t\tvar ecBlock = ecBlockArray[j];\r\n\t\tfor (var i = 0; i < ecBlock.Count; i++)\r\n\t\t{\r\n\t\t\tvar numDataCodewords = ecBlock.DataCodewords;\r\n\t\t\tvar numBlockCodewords = ecBlocks.ECCodewordsPerBlock + numDataCodewords;\r\n\t\t\tresult[numResultBlocks++] = new DataBlock(numDataCodewords, new Array(numBlockCodewords));\r\n\t\t}\r\n\t}\r\n\t\r\n\t// All blocks have the same amount of data, except that the last n\r\n\t// (where n may be 0) have 1 more byte. Figure out where these start.\r\n\tvar shorterBlocksTotalCodewords = result[0].codewords.length;\r\n\tvar longerBlocksStartAt = result.length - 1;\r\n\twhile (longerBlocksStartAt >= 0)\r\n\t{\r\n\t\tvar numCodewords = result[longerBlocksStartAt].codewords.length;\r\n\t\tif (numCodewords == shorterBlocksTotalCodewords)\r\n\t\t{\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tlongerBlocksStartAt--;\r\n\t}\r\n\tlongerBlocksStartAt++;\r\n\t\r\n\tvar shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBlocks.ECCodewordsPerBlock;\r\n\t// The last elements of result may be 1 element longer;\r\n\t// first fill out as many elements as all of them have\r\n\tvar rawCodewordsOffset = 0;\r\n\tfor (var i = 0; i < shorterBlocksNumDataCodewords; i++)\r\n\t{\r\n\t\tfor (var j = 0; j < numResultBlocks; j++)\r\n\t\t{\r\n\t\t\tresult[j].codewords[i] = rawCodewords[rawCodewordsOffset++];\r\n\t\t}\r\n\t}\r\n\t// Fill out the last data block in the longer ones\r\n\tfor (var j = longerBlocksStartAt; j < numResultBlocks; j++)\r\n\t{\r\n\t\tresult[j].codewords[shorterBlocksNumDataCodewords] = rawCodewords[rawCodewordsOffset++];\r\n\t}\r\n\t// Now add in error correction blocks\r\n\tvar max = result[0].codewords.length;\r\n\tfor (var i = shorterBlocksNumDataCodewords; i < max; i++)\r\n\t{\r\n\t\tfor (var j = 0; j < numResultBlocks; j++)\r\n\t\t{\r\n\t\t\tvar iOffset = j < longerBlocksStartAt?i:i + 1;\r\n\t\t\tresult[j].codewords[iOffset] = rawCodewords[rawCodewordsOffset++];\r\n\t\t}\r\n\t}\r\n\treturn result;\r\n}\r\n","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nfunction GF256Poly(field, coefficients)\r\n{\r\n\tif (coefficients == null || coefficients.length == 0)\r\n\t{\r\n\t\tthrow new Error(\"QR Error: System.ArgumentException\");\r\n\t}\r\n\tthis.field = field;\r\n\tvar coefficientsLength = coefficients.length;\r\n\tif (coefficientsLength > 1 && coefficients[0] == 0)\r\n\t{\r\n\t\t// Leading term must be non-zero for anything except the constant polynomial \"0\"\r\n\t\tvar firstNonZero = 1;\r\n\t\twhile (firstNonZero < coefficientsLength && coefficients[firstNonZero] == 0)\r\n\t\t{\r\n\t\t\tfirstNonZero++;\r\n\t\t}\r\n\t\tif (firstNonZero == coefficientsLength)\r\n\t\t{\r\n\t\t\tthis.coefficients = field.Zero.coefficients;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tthis.coefficients = new Array(coefficientsLength - firstNonZero);\r\n\t\t\tfor(var i=0;i largerCoefficients.length)\r\n\t\t\t{\r\n\t\t\t\tvar temp = smallerCoefficients;\r\n\t\t\t\tsmallerCoefficients = largerCoefficients;\r\n\t\t\t\tlargerCoefficients = temp;\r\n\t\t\t}\r\n\t\t\tvar sumDiff = new Array(largerCoefficients.length);\r\n\t\t\tvar lengthDiff = largerCoefficients.length - smallerCoefficients.length;\r\n\t\t\t// Copy high-order terms only found in higher-degree polynomial's coefficients\r\n\t\t\t//Array.Copy(largerCoefficients, 0, sumDiff, 0, lengthDiff);\r\n\t\t\tfor(var ci=0;ci= other.Degree && !remainder.Zero)\r\n\t\t\t{\r\n\t\t\t\tvar degreeDifference = remainder.Degree - other.Degree;\r\n\t\t\t\tvar scale = this.field.multiply(remainder.getCoefficient(remainder.Degree), inverseDenominatorLeadingTerm);\r\n\t\t\t\tvar term = other.multiplyByMonomial(degreeDifference, scale);\r\n\t\t\t\tvar iterationQuotient = this.field.buildMonomial(degreeDifference, scale);\r\n\t\t\t\tquotient = quotient.addOrSubtract(iterationQuotient);\r\n\t\t\t\tremainder = remainder.addOrSubtract(term);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\treturn new Array(quotient, remainder);\r\n\t\t}\r\n}","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nfunction GF256( primitive)\r\n{\r\n\tthis.expTable = new Array(256);\r\n\tthis.logTable = new Array(256);\r\n\tvar x = 1;\r\n\tfor (var i = 0; i < 256; i++)\r\n\t{\r\n\t\tthis.expTable[i] = x;\r\n\t\tx <<= 1; // x = x * 2; we're assuming the generator alpha is 2\r\n\t\tif (x >= 0x100)\r\n\t\t{\r\n\t\t\tx ^= primitive;\r\n\t\t}\r\n\t}\r\n\tfor (var i = 0; i < 255; i++)\r\n\t{\r\n\t\tthis.logTable[this.expTable[i]] = i;\r\n\t}\r\n\t// logTable[0] == 0 but this should never be used\r\n\tvar at0=new Array(1);at0[0]=0;\r\n\tthis.zero = new GF256Poly(this, new Array(at0));\r\n\tvar at1=new Array(1);at1[0]=1;\r\n\tthis.one = new GF256Poly(this, new Array(at1));\r\n\t\r\n\tthis.__defineGetter__(\"Zero\", function()\r\n\t{\r\n\t\treturn this.zero;\r\n\t});\r\n\tthis.__defineGetter__(\"One\", function()\r\n\t{\r\n\t\treturn this.one;\r\n\t});\r\n\tthis.buildMonomial=function( degree, coefficient)\r\n\t\t{\r\n\t\t\tif (degree < 0)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(\"QR Error: System.ArgumentException\");\r\n\t\t\t}\r\n\t\t\tif (coefficient == 0)\r\n\t\t\t{\r\n\t\t\t\treturn this.zero;\r\n\t\t\t}\r\n\t\t\tvar coefficients = new Array(degree + 1);\r\n\t\t\tfor(var i=0;i> 8;\r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n\r\nfunction URShift( number, bits)\r\n{\r\n if (number >= 0)\r\n return number >> bits;\r\n else\r\n return (number >> bits) + (2 << ~bits);\r\n}","self.onmessage = event => {\n const type = event.data.type;\n const data = event.data.data;\n if (type === 'setDebug') {\n qrcode.debug = data;\n } else if (type === 'decode') {\n let result = null;\n try {\n result = qrcode.decode(data);\n } catch(e) {\n if (!e.message.startsWith('QR Error')) {\n throw e; // some unexpected error\n }\n // console.log(e);\n } finally {\n self.postMessage({\n type: 'qrResult',\n data: result\n });\n }\n }\n};\n\n\nfunction sendDebugImage(debugImage) {\n self.postMessage({\n type: 'debugImage',\n data: debugImage\n }, [debugImage.data.buffer]);\n}","// Implementation taken from https://github.com/nimiq-design/nimiqode and follows the idea of\n// https://github.com/zxing/zxing/blob/master/core/src/main/java/com/google/zxing/common/HybridBinarizer.java\n\n\nclass Binarizer {\n static calculateRequiredBufferSize(imageWidth, imageHeight) {\n // memory for threshold for every block\n const [, blockCountX, blockCountY] = Binarizer._calculateBlockSize(imageWidth, imageHeight);\n return blockCountX * blockCountY;\n }\n\n static _calculateBlockSize(imageWidth, imageHeight) {\n const blockSize = Math.max(\n Math.floor(Math.min(imageWidth, imageHeight) / Binarizer.TARGET_BLOCK_COUNT_ALONG_SHORTER_SIDE),\n Binarizer.MIN_BLOCK_SIZE\n );\n\n const blockCountX = Math.ceil(imageWidth / blockSize);\n const blockCountY = Math.ceil(imageHeight / blockSize);\n return [blockSize, blockCountX, blockCountY];\n }\n\n static binarize(inputGrayscale, imageWidth, imageHeight, outputBinary = inputGrayscale, buffer = null) {\n const [blockSize, blockCountX, blockCountY] =\n Binarizer._calculateBlockSize(imageWidth, imageHeight);\n let blockThresholds;\n if (buffer) {\n if (!(buffer instanceof Uint8ClampedArray) || buffer.byteLength !== blockCountX * blockCountY) {\n throw new Error('QR Error: Illegal Buffer.');\n }\n blockThresholds = buffer;\n } else {\n blockThresholds = new Uint8ClampedArray(blockCountX * blockCountY);\n }\n // calculate the thresholds for the blocks\n for (let blockIndexY=0; blockIndexY < blockCountY; ++blockIndexY) {\n for (let blockIndexX=0; blockIndexX < blockCountX; ++blockIndexX) {\n const threshold = Binarizer._calculateBlockThreshold(inputGrayscale, imageWidth, imageHeight,\n blockIndexX, blockIndexY, blockCountX, blockSize, blockThresholds);\n blockThresholds[blockIndexY * blockCountX + blockIndexX] = threshold;\n }\n }\n for (let blockIndexY=0; blockIndexY < blockCountY; ++blockIndexY) {\n for (let blockIndexX=0; blockIndexX < blockCountX; ++blockIndexX) {\n // calculate the average threshold over a 5x5 grid to essentially make the area bigger and increase\n // the chance that we have a bright and dark pixel in the area for good threshold computation. By\n // keeping the real block size small we ensure a good local threshold estimate (the step size in x and\n // y direction is essentially smaller).\n //\n // Instead of (min+max)/2 like in _calculateBlockThreshold, here we use a real average to be more prune\n // against outliers. E.g. imagine whats behind the scanned screen is really dark, the screen (including\n // dark pixels on the screen) rather bright. In this case, we want the threshold on the screen to be\n // rather bright and therefore not to factor in the background too much.\n let sum = 0;\n for (let i = -2; i<=2; ++i) {\n for (let j = -2; j<=2; ++j) {\n const neighborIndexX = Math.max(0, Math.min(blockCountX-1, blockIndexX+i));\n const neighborIndexY = Math.max(0, Math.min(blockCountY-1, blockIndexY+j));\n sum += blockThresholds[neighborIndexY * blockCountX + neighborIndexX];\n }\n }\n Binarizer._applyThresholdToBlock(inputGrayscale, imageWidth, imageHeight, blockIndexX, blockIndexY,\n blockSize, sum / 25, outputBinary);\n }\n }\n }\n\n static _calculateBlockThreshold(inputGrayscale, imageWidth, imageHeight, blockIndexX, blockIndexY, blockCountX, blockSize,\n blockThresholds) {\n let min = 0xFF, max = 0;\n const left = Math.min(blockIndexX * blockSize, imageWidth - blockSize);\n const top = Math.min(blockIndexY * blockSize, imageHeight - blockSize);\n let rowStart = top * imageWidth + left;\n for (let y=0; y max) {\n max = pixel;\n }\n }\n rowStart += imageWidth;\n }\n if (max - min > Binarizer.MIN_DYNAMIC_RANGE) {\n // The values span a minimum dynamic range, so we can assume we have bright and dark pixels. Return the\n // average of min and max as threshold. We could also compute the real average of all pixel but following\n // the assumption that the nimiqode consists of bright and dark pixels and essentially not much in between\n // then by (min + max)/2 we make the cut really between those two classes. If using the average over all\n // pixel then in a block of mostly bright pixels and few dark pixels, the avg would tend to the bright side\n // and darker bright pixels could be interpreted as dark.\n return (min + max) / 2;\n } else {\n // We have a low dynamic range and assume the block is of solid bright or dark color.\n // TODO this zxing implementation is somewhat weird. Think of a better threshold propagation strategy.\n // Ideas:\n // - start the propagation in the middle of the screen following the assumption that the nimiqode / screen\n // is centered in the image. By this, we avoid propagation of thresholds from the surrounding to the\n // screen which hold the only interesting information to us.\n // - Combine the threshold propagation with edge detection\n // - When propagating a threshold adapt it by comparing the average brightness in my block to the average\n // brightness in block we are propagating from\n if (blockIndexX === 0 || blockIndexY === 0) {\n // cant compare to the neighbours. Assume it's a light background\n return min / 2;\n } else {\n const myIndex = blockIndexY * blockCountX + blockIndexX;\n const leftBlockThreshold = blockThresholds[myIndex - 1];\n const topBlockThreshold = blockThresholds[myIndex - blockCountX];\n const topLeftBlockThreshold = blockCountX[myIndex - blockCountX - 1];\n const neighbourAverage = (leftBlockThreshold + topBlockThreshold + topLeftBlockThreshold) / 3;\n if (neighbourAverage > min) {\n return neighbourAverage;\n } else {\n return min / 2;\n }\n }\n }\n }\n\n\n static _applyThresholdToBlock(inputGrayscale, imageWidth, imageHeight, blockIndexX, blockIndexY, blockSize, threshold,\n outputBinary = inputGrayscale) {\n const left = Math.min(blockIndexX * blockSize, imageWidth - blockSize);\n const top = Math.min(blockIndexY * blockSize, imageHeight - blockSize);\n let rowStart = top * imageWidth + left;\n for (let y=0; y width || y < - 1 || y > height)\r\n\t\t\t\t{\r\n\t\t\t\t\tthrow new Error(\"QR Error: Error.checkAndNudgePoints\");\r\n\t\t\t\t}\r\n\t\t\t\tnudged = false;\r\n\t\t\t\tif (x == - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tpoints[offset] = 0.0;\r\n\t\t\t\t\tnudged = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if (x == width)\r\n\t\t\t\t{\r\n\t\t\t\t\tpoints[offset] = width - 1;\r\n\t\t\t\t\tnudged = true;\r\n\t\t\t\t}\r\n\t\t\t\tif (y == - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tpoints[offset + 1] = 0.0;\r\n\t\t\t\t\tnudged = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if (y == height)\r\n\t\t\t\t{\r\n\t\t\t\t\tpoints[offset + 1] = height - 1;\r\n\t\t\t\t\tnudged = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t// Check and nudge points from end:\r\n\t\t\tnudged = true;\r\n\t\t\tfor (var offset = points.length - 2; offset >= 0 && nudged; offset -= 2)\r\n\t\t\t{\r\n\t\t\t\tvar x = Math.floor( points[offset]);\r\n\t\t\t\tvar y = Math.floor( points[offset + 1]);\r\n\t\t\t\tif (x < - 1 || x > width || y < - 1 || y > height)\r\n\t\t\t\t{\r\n\t\t\t\t\tthrow new Error(\"QR Error: Error.checkAndNudgePoints\");\r\n\t\t\t\t}\r\n\t\t\t\tnudged = false;\r\n\t\t\t\tif (x == - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tpoints[offset] = 0.0;\r\n\t\t\t\t\tnudged = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if (x == width)\r\n\t\t\t\t{\r\n\t\t\t\t\tpoints[offset] = width - 1;\r\n\t\t\t\t\tnudged = true;\r\n\t\t\t\t}\r\n\t\t\t\tif (y == - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tpoints[offset + 1] = 0.0;\r\n\t\t\t\t\tnudged = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if (y == height)\r\n\t\t\t\t{\r\n\t\t\t\t\tpoints[offset + 1] = height - 1;\r\n\t\t\t\t\tnudged = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\r\n\r\n\r\nGridSampler.sampleGrid3=function( image, dimension, transform)\r\n\t\t{\r\n\t\t\tvar bits = new BitMatrix(dimension);\r\n\t\t\tvar points = new Array(dimension << 1);\r\n\t\t\tfor (var y = 0; y < dimension; y++)\r\n\t\t\t{\r\n\t\t\t\tvar max = points.length;\r\n\t\t\t\tvar iValue = y + 0.5;\r\n\t\t\t\tfor (var x = 0; x < max; x += 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tpoints[x] = (x >> 1) + 0.5;\r\n\t\t\t\t\tpoints[x + 1] = iValue;\r\n\t\t\t\t}\r\n\t\t\t\ttransform.transformPoints1(points);\r\n\t\t\t\t// Quick check to see if points transformed to something inside the image;\r\n\t\t\t\t// sufficient to check the endpoints\r\n\t\t\t\tGridSampler.checkAndNudgePoints(image, points);\r\n\t\t\t\ttry\r\n\t\t\t\t{\r\n\t\t\t\t\tfor (var x = 0; x < max; x += 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t//var xpoint = (Math.floor( points[x]) * 4) + (Math.floor( points[x + 1]) * qrcode.width * 4);\r\n var bit = image[Math.floor( points[x])+ qrcode.width* Math.floor( points[x + 1])];\r\n\t\t\t\t\t\t//qrcode.imagedata.data[xpoint] = bit?255:0;\r\n\t\t\t\t\t\t//qrcode.imagedata.data[xpoint+1] = bit?255:0;\r\n\t\t\t\t\t\t//qrcode.imagedata.data[xpoint+2] = 0;\r\n\t\t\t\t\t\t//qrcode.imagedata.data[xpoint+3] = 255;\r\n\t\t\t\t\t\t//bits[x >> 1][ y]=bit;\r\n\t\t\t\t\t\tif(bit)\r\n\t\t\t\t\t\t\tbits.set_Renamed(x >> 1, y);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tcatch ( aioobe)\r\n\t\t\t\t{\r\n\t\t\t\t\t// This feels wrong, but, sometimes if the finder patterns are misidentified, the resulting\r\n\t\t\t\t\t// transform gets \"twisted\" such that it maps a straight line of points to a set of points\r\n\t\t\t\t\t// whose endpoints are in bounds, but others are not. There is probably some mathematical\r\n\t\t\t\t\t// way to detect this about the transformation that I don't know yet.\r\n\t\t\t\t\t// This results in an ugly runtime exception despite our clever checks above -- can't have\r\n\t\t\t\t\t// that. We could check each point's coordinates but that feels duplicative. We settle for\r\n\t\t\t\t\t// catching and wrapping ArrayIndexOutOfBoundsException.\r\n\t\t\t\t\tthrow new Error(\"QR Error: Error.checkAndNudgePoints\");\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn bits;\r\n\t\t}\r\n\r\nGridSampler.sampleGridx=function( image, dimension, p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY)\r\n{\r\n\tvar transform = PerspectiveTransform.quadrilateralToQuadrilateral(p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY);\r\n\t\t\t\r\n\treturn GridSampler.sampleGrid3(image, dimension, transform);\r\n}","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nvar DataMask = {};\r\n\r\nDataMask.forReference = function(reference)\r\n{\r\n\tif (reference < 0 || reference > 7)\r\n\t{\r\n\t\tthrow new Error(\"QR Error: System.ArgumentException\");\r\n\t}\r\n\treturn DataMask.DATA_MASKS[reference];\r\n}\r\n\r\nfunction DataMask000()\r\n{\r\n\tthis.unmaskBitMatrix=function(bits, dimension)\r\n\t{\r\n\t\tfor (var i = 0; i < dimension; i++)\r\n\t\t{\r\n\t\t\tfor (var j = 0; j < dimension; j++)\r\n\t\t\t{\r\n\t\t\t\tif (this.isMasked(i, j))\r\n\t\t\t\t{\r\n\t\t\t\t\tbits.flip(j, i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tthis.isMasked=function( i, j)\r\n\t{\r\n\t\treturn ((i + j) & 0x01) == 0;\r\n\t}\r\n}\r\n\r\nfunction DataMask001()\r\n{\r\n\tthis.unmaskBitMatrix=function(bits, dimension)\r\n\t{\r\n\t\tfor (var i = 0; i < dimension; i++)\r\n\t\t{\r\n\t\t\tfor (var j = 0; j < dimension; j++)\r\n\t\t\t{\r\n\t\t\t\tif (this.isMasked(i, j))\r\n\t\t\t\t{\r\n\t\t\t\t\tbits.flip(j, i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tthis.isMasked=function( i, j)\r\n\t{\r\n\t\treturn (i & 0x01) == 0;\r\n\t}\r\n}\r\n\r\nfunction DataMask010()\r\n{\r\n\tthis.unmaskBitMatrix=function(bits, dimension)\r\n\t{\r\n\t\tfor (var i = 0; i < dimension; i++)\r\n\t\t{\r\n\t\t\tfor (var j = 0; j < dimension; j++)\r\n\t\t\t{\r\n\t\t\t\tif (this.isMasked(i, j))\r\n\t\t\t\t{\r\n\t\t\t\t\tbits.flip(j, i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tthis.isMasked=function( i, j)\r\n\t{\r\n\t\treturn j % 3 == 0;\r\n\t}\r\n}\r\n\r\nfunction DataMask011()\r\n{\r\n\tthis.unmaskBitMatrix=function(bits, dimension)\r\n\t{\r\n\t\tfor (var i = 0; i < dimension; i++)\r\n\t\t{\r\n\t\t\tfor (var j = 0; j < dimension; j++)\r\n\t\t\t{\r\n\t\t\t\tif (this.isMasked(i, j))\r\n\t\t\t\t{\r\n\t\t\t\t\tbits.flip(j, i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tthis.isMasked=function( i, j)\r\n\t{\r\n\t\treturn (i + j) % 3 == 0;\r\n\t}\r\n}\r\n\r\nfunction DataMask100()\r\n{\r\n\tthis.unmaskBitMatrix=function(bits, dimension)\r\n\t{\r\n\t\tfor (var i = 0; i < dimension; i++)\r\n\t\t{\r\n\t\t\tfor (var j = 0; j < dimension; j++)\r\n\t\t\t{\r\n\t\t\t\tif (this.isMasked(i, j))\r\n\t\t\t\t{\r\n\t\t\t\t\tbits.flip(j, i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tthis.isMasked=function( i, j)\r\n\t{\r\n\t\treturn (((URShift(i, 1)) + (j / 3)) & 0x01) == 0;\r\n\t}\r\n}\r\n\r\nfunction DataMask101()\r\n{\r\n\tthis.unmaskBitMatrix=function(bits, dimension)\r\n\t{\r\n\t\tfor (var i = 0; i < dimension; i++)\r\n\t\t{\r\n\t\t\tfor (var j = 0; j < dimension; j++)\r\n\t\t\t{\r\n\t\t\t\tif (this.isMasked(i, j))\r\n\t\t\t\t{\r\n\t\t\t\t\tbits.flip(j, i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tthis.isMasked=function( i, j)\r\n\t{\r\n\t\tvar temp = i * j;\r\n\t\treturn (temp & 0x01) + (temp % 3) == 0;\r\n\t}\r\n}\r\n\r\nfunction DataMask110()\r\n{\r\n\tthis.unmaskBitMatrix=function(bits, dimension)\r\n\t{\r\n\t\tfor (var i = 0; i < dimension; i++)\r\n\t\t{\r\n\t\t\tfor (var j = 0; j < dimension; j++)\r\n\t\t\t{\r\n\t\t\t\tif (this.isMasked(i, j))\r\n\t\t\t\t{\r\n\t\t\t\t\tbits.flip(j, i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tthis.isMasked=function( i, j)\r\n\t{\r\n\t\tvar temp = i * j;\r\n\t\treturn (((temp & 0x01) + (temp % 3)) & 0x01) == 0;\r\n\t}\r\n}\r\nfunction DataMask111()\r\n{\r\n\tthis.unmaskBitMatrix=function(bits, dimension)\r\n\t{\r\n\t\tfor (var i = 0; i < dimension; i++)\r\n\t\t{\r\n\t\t\tfor (var j = 0; j < dimension; j++)\r\n\t\t\t{\r\n\t\t\t\tif (this.isMasked(i, j))\r\n\t\t\t\t{\r\n\t\t\t\t\tbits.flip(j, i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tthis.isMasked=function( i, j)\r\n\t{\r\n\t\treturn ((((i + j) & 0x01) + ((i * j) % 3)) & 0x01) == 0;\r\n\t}\r\n}\r\n\r\nDataMask.DATA_MASKS = new Array(new DataMask000(), new DataMask001(), new DataMask010(), new DataMask011(), new DataMask100(), new DataMask101(), new DataMask110(), new DataMask111());\r\n\r\n","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nvar Decoder={};\r\nDecoder.rsDecoder = new ReedSolomonDecoder(GF256.QR_CODE_FIELD);\r\n\r\nDecoder.correctErrors=function( codewordBytes, numDataCodewords)\r\n{\r\n\tvar numCodewords = codewordBytes.length;\r\n\t// First read into an array of ints\r\n\tvar codewordsInts = new Array(numCodewords);\r\n\tfor (var i = 0; i < numCodewords; i++)\r\n\t{\r\n\t\tcodewordsInts[i] = codewordBytes[i] & 0xFF;\r\n\t}\r\n\tvar numECCodewords = codewordBytes.length - numDataCodewords;\r\n\ttry\r\n\t{\r\n\t\tDecoder.rsDecoder.decode(codewordsInts, numECCodewords);\r\n\t\t//var corrector = new ReedSolomon(codewordsInts, numECCodewords);\r\n\t\t//corrector.correct();\r\n\t}\r\n\tcatch ( rse)\r\n\t{\r\n\t\tthrow rse;\r\n\t}\r\n\t// Copy back into array of bytes -- only need to worry about the bytes that were data\r\n\t// We don't care about errors in the error-correction codewords\r\n\tfor (var i = 0; i < numDataCodewords; i++)\r\n\t{\r\n\t\tcodewordBytes[i] = codewordsInts[i];\r\n\t}\r\n}\r\n\r\nDecoder.decode=function(bits)\r\n{\r\n\tvar parser = new BitMatrixParser(bits);\r\n\tvar version = parser.readVersion();\r\n\tvar ecLevel = parser.readFormatInformation().ErrorCorrectionLevel;\r\n\t\r\n\t// Read codewords\r\n\tvar codewords = parser.readCodewords();\r\n\r\n\t// Separate into data blocks\r\n\tvar dataBlocks = DataBlock.getDataBlocks(codewords, version, ecLevel);\r\n\t\r\n\t// Count total number of data bytes\r\n\tvar totalBytes = 0;\r\n\tfor (var i = 0; i < dataBlocks.length; i++)\r\n\t{\r\n\t\ttotalBytes += dataBlocks[i].NumDataCodewords;\r\n\t}\r\n\tvar resultBytes = new Array(totalBytes);\r\n\tvar resultOffset = 0;\r\n\t\r\n\t// Error-correct and copy data blocks together into a stream of bytes\r\n\tfor (var j = 0; j < dataBlocks.length; j++)\r\n\t{\r\n\t\tvar dataBlock = dataBlocks[j];\r\n\t\tvar codewordBytes = dataBlock.Codewords;\r\n\t\tvar numDataCodewords = dataBlock.NumDataCodewords;\r\n\t\tDecoder.correctErrors(codewordBytes, numDataCodewords);\r\n\t\tfor (var i = 0; i < numDataCodewords; i++)\r\n\t\t{\r\n\t\t\tresultBytes[resultOffset++] = codewordBytes[i];\r\n\t\t}\r\n\t}\r\n\t\r\n\t// Decode the contents of that stream of bytes\r\n\tvar reader = new QRCodeDataBlockReader(resultBytes, version.VersionNumber, ecLevel.Bits);\r\n\treturn reader;\r\n\t//return DecodedBitStreamParser.decode(resultBytes, version, ecLevel);\r\n}\r\n","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nfunction ReedSolomonDecoder(field)\r\n{\r\n\tthis.field = field;\r\n\tthis.decode=function(received, twoS)\r\n\t{\r\n\t\t\tvar poly = new GF256Poly(this.field, received);\r\n\t\t\tvar syndromeCoefficients = new Array(twoS);\r\n\t\t\tfor(var i=0;i= b's\r\n\t\t\tif (a.Degree < b.Degree)\r\n\t\t\t{\r\n\t\t\t\tvar temp = a;\r\n\t\t\t\ta = b;\r\n\t\t\t\tb = temp;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvar rLast = a;\r\n\t\t\tvar r = b;\r\n\t\t\tvar sLast = this.field.One;\r\n\t\t\tvar s = this.field.Zero;\r\n\t\t\tvar tLast = this.field.Zero;\r\n\t\t\tvar t = this.field.One;\r\n\t\t\t\r\n\t\t\t// Run Euclidean algorithm until r's degree is less than R/2\r\n\t\t\twhile (r.Degree >= Math.floor(R / 2))\r\n\t\t\t{\r\n\t\t\t\tvar rLastLast = rLast;\r\n\t\t\t\tvar sLastLast = sLast;\r\n\t\t\t\tvar tLastLast = tLast;\r\n\t\t\t\trLast = r;\r\n\t\t\t\tsLast = s;\r\n\t\t\t\ttLast = t;\r\n\t\t\t\t\r\n\t\t\t\t// Divide rLastLast by rLast, with quotient in q and remainder in r\r\n\t\t\t\tif (rLast.Zero)\r\n\t\t\t\t{\r\n\t\t\t\t\t// Oops, Euclidean algorithm already terminated?\r\n\t\t\t\t\tthrow new Error(\"QR Error: r_{i-1} was zero\");\r\n\t\t\t\t}\r\n\t\t\t\tr = rLastLast;\r\n\t\t\t\tvar q = this.field.Zero;\r\n\t\t\t\tvar denominatorLeadingTerm = rLast.getCoefficient(rLast.Degree);\r\n\t\t\t\tvar dltInverse = this.field.inverse(denominatorLeadingTerm);\r\n\t\t\t\twhile (r.Degree >= rLast.Degree && !r.Zero)\r\n\t\t\t\t{\r\n\t\t\t\t\tvar degreeDiff = r.Degree - rLast.Degree;\r\n\t\t\t\t\tvar scale = this.field.multiply(r.getCoefficient(r.Degree), dltInverse);\r\n\t\t\t\t\tq = q.addOrSubtract(this.field.buildMonomial(degreeDiff, scale));\r\n\t\t\t\t\tr = r.addOrSubtract(rLast.multiplyByMonomial(degreeDiff, scale));\r\n\t\t\t\t\t//r.EXE();\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\ts = q.multiply1(sLast).addOrSubtract(sLastLast);\r\n\t\t\t\tt = q.multiply1(tLast).addOrSubtract(tLastLast);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvar sigmaTildeAtZero = t.getCoefficient(0);\r\n\t\t\tif (sigmaTildeAtZero == 0)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(\"QR Error: ReedSolomonException sigmaTilde(0) was zero\");\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvar inverse = this.field.inverse(sigmaTildeAtZero);\r\n\t\t\tvar sigma = t.multiply2(inverse);\r\n\t\t\tvar omega = r.multiply2(inverse);\r\n\t\t\treturn new Array(sigma, omega);\r\n\t\t}\r\n\tthis.findErrorLocations=function( errorLocator)\r\n\t\t{\r\n\t\t\t// This is a direct application of Chien's search\r\n\t\t\tvar numErrors = errorLocator.Degree;\r\n\t\t\tif (numErrors == 1)\r\n\t\t\t{\r\n\t\t\t\t// shortcut\r\n\t\t\t\treturn new Array(errorLocator.getCoefficient(1));\r\n\t\t\t}\r\n\t\t\tvar result = new Array(numErrors);\r\n\t\t\tvar e = 0;\r\n\t\t\tfor (var i = 1; i < 256 && e < numErrors; i++)\r\n\t\t\t{\r\n\t\t\t\tif (errorLocator.evaluateAt(i) == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tresult[e] = this.field.inverse(i);\r\n\t\t\t\t\te++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (e != numErrors)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(\"QR Error: Error locator degree does not match number of roots\");\r\n\t\t\t}\r\n\t\t\treturn result;\r\n\t\t}\r\n\tthis.findErrorMagnitudes=function( errorEvaluator, errorLocations, dataMatrix)\r\n\t\t{\r\n\t\t\t// This is directly applying Forney's Formula\r\n\t\t\tvar s = errorLocations.length;\r\n\t\t\tvar result = new Array(s);\r\n\t\t\tfor (var i = 0; i < s; i++)\r\n\t\t\t{\r\n\t\t\t\tvar xiInverse = this.field.inverse(errorLocations[i]);\r\n\t\t\t\tvar denominator = 1;\r\n\t\t\t\tfor (var j = 0; j < s; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i != j)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdenominator = this.field.multiply(denominator, GF256.addOrSubtract(1, this.field.multiply(errorLocations[j], xiInverse)));\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tresult[i] = this.field.multiply(errorEvaluator.evaluateAt(xiInverse), this.field.inverse(denominator));\r\n\t\t\t\t// Thanks to sanfordsquires for this fix:\r\n\t\t\t\tif (dataMatrix)\r\n\t\t\t\t{\r\n\t\t\t\t\tresult[i] = this.field.multiply(result[i], xiInverse);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn result;\r\n\t\t}\r\n}","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nfunction BitMatrixParser(bitMatrix)\r\n{\r\n\tvar dimension = bitMatrix.Dimension;\r\n\tif (dimension < 21 || (dimension & 0x03) != 1)\r\n\t{\r\n\t\tthrow new Error(\"QR Error: Error BitMatrixParser\");\r\n\t}\r\n\tthis.bitMatrix = bitMatrix;\r\n\tthis.parsedVersion = null;\r\n\tthis.parsedFormatInfo = null;\r\n\t\r\n\tthis.copyBit=function( i, j, versionBits)\r\n\t{\r\n\t\treturn this.bitMatrix.get_Renamed(i, j)?(versionBits << 1) | 0x1:versionBits << 1;\r\n\t}\r\n\t\r\n\tthis.readFormatInformation=function()\r\n\t{\r\n\t\t\tif (this.parsedFormatInfo != null)\r\n\t\t\t{\r\n\t\t\t\treturn this.parsedFormatInfo;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Read top-left format info bits\r\n\t\t\tvar formatInfoBits = 0;\r\n\t\t\tfor (var i = 0; i < 6; i++)\r\n\t\t\t{\r\n\t\t\t\tformatInfoBits = this.copyBit(i, 8, formatInfoBits);\r\n\t\t\t}\r\n\t\t\t// .. and skip a bit in the timing pattern ...\r\n\t\t\tformatInfoBits = this.copyBit(7, 8, formatInfoBits);\r\n\t\t\tformatInfoBits = this.copyBit(8, 8, formatInfoBits);\r\n\t\t\tformatInfoBits = this.copyBit(8, 7, formatInfoBits);\r\n\t\t\t// .. and skip a bit in the timing pattern ...\r\n\t\t\tfor (var j = 5; j >= 0; j--)\r\n\t\t\t{\r\n\t\t\t\tformatInfoBits = this.copyBit(8, j, formatInfoBits);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tthis.parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits);\r\n\t\t\tif (this.parsedFormatInfo != null)\r\n\t\t\t{\r\n\t\t\t\treturn this.parsedFormatInfo;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Hmm, failed. Try the top-right/bottom-left pattern\r\n\t\t\tvar dimension = this.bitMatrix.Dimension;\r\n\t\t\tformatInfoBits = 0;\r\n\t\t\tvar iMin = dimension - 8;\r\n\t\t\tfor (var i = dimension - 1; i >= iMin; i--)\r\n\t\t\t{\r\n\t\t\t\tformatInfoBits = this.copyBit(i, 8, formatInfoBits);\r\n\t\t\t}\r\n\t\t\tfor (var j = dimension - 7; j < dimension; j++)\r\n\t\t\t{\r\n\t\t\t\tformatInfoBits = this.copyBit(8, j, formatInfoBits);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tthis.parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits);\r\n\t\t\tif (this.parsedFormatInfo != null)\r\n\t\t\t{\r\n\t\t\t\treturn this.parsedFormatInfo;\r\n\t\t\t}\r\n\t\t\tthrow new Error(\"QR Error: Error readFormatInformation\");\r\n\t}\r\n\tthis.readVersion=function()\r\n\t\t{\r\n\t\t\t\r\n\t\t\tif (this.parsedVersion != null)\r\n\t\t\t{\r\n\t\t\t\treturn this.parsedVersion;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvar dimension = this.bitMatrix.Dimension;\r\n\t\t\t\r\n\t\t\tvar provisionalVersion = (dimension - 17) >> 2;\r\n\t\t\tif (provisionalVersion <= 6)\r\n\t\t\t{\r\n\t\t\t\treturn Version.getVersionForNumber(provisionalVersion);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Read top-right version info: 3 wide by 6 tall\r\n\t\t\tvar versionBits = 0;\r\n\t\t\tvar ijMin = dimension - 11;\r\n\t\t\tfor (var j = 5; j >= 0; j--)\r\n\t\t\t{\r\n\t\t\t\tfor (var i = dimension - 9; i >= ijMin; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tversionBits = this.copyBit(i, j, versionBits);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tthis.parsedVersion = Version.decodeVersionInformation(versionBits);\r\n\t\t\tif (this.parsedVersion != null && this.parsedVersion.DimensionForVersion == dimension)\r\n\t\t\t{\r\n\t\t\t\treturn this.parsedVersion;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Hmm, failed. Try bottom left: 6 wide by 3 tall\r\n\t\t\tversionBits = 0;\r\n\t\t\tfor (var i = 5; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tfor (var j = dimension - 9; j >= ijMin; j--)\r\n\t\t\t\t{\r\n\t\t\t\t\tversionBits = this.copyBit(i, j, versionBits);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tthis.parsedVersion = Version.decodeVersionInformation(versionBits);\r\n\t\t\tif (this.parsedVersion != null && this.parsedVersion.DimensionForVersion == dimension)\r\n\t\t\t{\r\n\t\t\t\treturn this.parsedVersion;\r\n\t\t\t}\r\n\t\t\tthrow new Error(\"QR Error: Error readVersion\");\r\n\t\t}\r\n\tthis.readCodewords=function()\r\n\t\t{\r\n\t\t\t\r\n\t\t\tvar formatInfo = this.readFormatInformation();\r\n\t\t\tvar version = this.readVersion();\r\n\t\t\t\r\n\t\t\t// Get the data mask for the format used in this QR Code. This will exclude\r\n\t\t\t// some bits from reading as we wind through the bit matrix.\r\n\t\t\tvar dataMask = DataMask.forReference( formatInfo.DataMask);\r\n\t\t\tvar dimension = this.bitMatrix.Dimension;\r\n\t\t\tdataMask.unmaskBitMatrix(this.bitMatrix, dimension);\r\n\t\t\t\r\n\t\t\tvar functionPattern = version.buildFunctionPattern();\r\n\t\t\t\r\n\t\t\tvar readingUp = true;\r\n\t\t\tvar result = new Array(version.TotalCodewords);\r\n\t\t\tvar resultOffset = 0;\r\n\t\t\tvar currentByte = 0;\r\n\t\t\tvar bitsRead = 0;\r\n\t\t\t// Read columns in pairs, from right to left\r\n\t\t\tfor (var j = dimension - 1; j > 0; j -= 2)\r\n\t\t\t{\r\n\t\t\t\tif (j == 6)\r\n\t\t\t\t{\r\n\t\t\t\t\t// Skip whole column with vertical alignment pattern;\r\n\t\t\t\t\t// saves time and makes the other code proceed more cleanly\r\n\t\t\t\t\tj--;\r\n\t\t\t\t}\r\n\t\t\t\t// Read alternatingly from bottom to top then top to bottom\r\n\t\t\t\tfor (var count = 0; count < dimension; count++)\r\n\t\t\t\t{\r\n\t\t\t\t\tvar i = readingUp?dimension - 1 - count:count;\r\n\t\t\t\t\tfor (var col = 0; col < 2; col++)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// Ignore bits covered by the function pattern\r\n\t\t\t\t\t\tif (!functionPattern.get_Renamed(j - col, i))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t// Read a bit\r\n\t\t\t\t\t\t\tbitsRead++;\r\n\t\t\t\t\t\t\tcurrentByte <<= 1;\r\n\t\t\t\t\t\t\tif (this.bitMatrix.get_Renamed(j - col, i))\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tcurrentByte |= 1;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t// If we've made a whole byte, save it off\r\n\t\t\t\t\t\t\tif (bitsRead == 8)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tresult[resultOffset++] = currentByte;\r\n\t\t\t\t\t\t\t\tbitsRead = 0;\r\n\t\t\t\t\t\t\t\tcurrentByte = 0;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\treadingUp ^= true; // readingUp = !readingUp; // switch directions\r\n\t\t\t}\r\n\t\t\tif (resultOffset != version.TotalCodewords)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(\"QR Error: Error readCodewords\");\r\n\t\t\t}\r\n\t\t\treturn result;\r\n\t\t}\r\n}","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nfunction QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode)\r\n{\r\n\tthis.blockPointer = 0;\r\n\tthis.bitPointer = 7;\r\n\tthis.dataLength = 0;\r\n\tthis.blocks = blocks;\r\n\tthis.numErrorCorrectionCode = numErrorCorrectionCode;\r\n\tif (version <= 9)\r\n\t\tthis.dataLengthMode = 0;\r\n\telse if (version >= 10 && version <= 26)\r\n\t\tthis.dataLengthMode = 1;\r\n\telse if (version >= 27 && version <= 40)\r\n\t\tthis.dataLengthMode = 2;\r\n\t\t\r\n\tthis.getNextBits = function( numBits)\r\n\t\t{\t\t\t\r\n\t\t\tvar bits = 0;\r\n\t\t\tif (numBits < this.bitPointer + 1)\r\n\t\t\t{\r\n\t\t\t\t// next word fits into current data block\r\n\t\t\t\tvar mask = 0;\r\n\t\t\t\tfor (var i = 0; i < numBits; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tmask += (1 << i);\r\n\t\t\t\t}\r\n\t\t\t\tmask <<= (this.bitPointer - numBits + 1);\r\n\t\t\t\t\r\n\t\t\t\tbits = (this.blocks[this.blockPointer] & mask) >> (this.bitPointer - numBits + 1);\r\n\t\t\t\tthis.bitPointer -= numBits;\r\n\t\t\t\treturn bits;\r\n\t\t\t}\r\n\t\t\telse if (numBits < this.bitPointer + 1 + 8)\r\n\t\t\t{\r\n\t\t\t\t// next word crosses 2 data blocks\r\n\t\t\t\tvar mask1 = 0;\r\n\t\t\t\tfor (var i = 0; i < this.bitPointer + 1; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tmask1 += (1 << i);\r\n\t\t\t\t}\r\n\t\t\t\tbits = (this.blocks[this.blockPointer] & mask1) << (numBits - (this.bitPointer + 1));\r\n this.blockPointer++;\r\n\t\t\t\tbits += ((this.blocks[this.blockPointer]) >> (8 - (numBits - (this.bitPointer + 1))));\r\n\t\t\t\t\r\n\t\t\t\tthis.bitPointer = this.bitPointer - numBits % 8;\r\n\t\t\t\tif (this.bitPointer < 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tthis.bitPointer = 8 + this.bitPointer;\r\n\t\t\t\t}\r\n\t\t\t\treturn bits;\r\n\t\t\t}\r\n\t\t\telse if (numBits < this.bitPointer + 1 + 16)\r\n\t\t\t{\r\n\t\t\t\t// next word crosses 3 data blocks\r\n\t\t\t\tvar mask1 = 0; // mask of first block\r\n\t\t\t\tvar mask3 = 0; // mask of 3rd block\r\n\t\t\t\t//bitPointer + 1 : number of bits of the 1st block\r\n\t\t\t\t//8 : number of the 2nd block (note that use already 8bits because next word uses 3 data blocks)\r\n\t\t\t\t//numBits - (bitPointer + 1 + 8) : number of bits of the 3rd block \r\n\t\t\t\tfor (var i = 0; i < this.bitPointer + 1; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tmask1 += (1 << i);\r\n\t\t\t\t}\r\n\t\t\t\tvar bitsFirstBlock = (this.blocks[this.blockPointer] & mask1) << (numBits - (this.bitPointer + 1));\r\n\t\t\t\tthis.blockPointer++;\r\n\t\t\t\t\r\n\t\t\t\tvar bitsSecondBlock = this.blocks[this.blockPointer] << (numBits - (this.bitPointer + 1 + 8));\r\n\t\t\t\tthis.blockPointer++;\r\n\t\t\t\t\r\n\t\t\t\tfor (var i = 0; i < numBits - (this.bitPointer + 1 + 8); i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tmask3 += (1 << i);\r\n\t\t\t\t}\r\n\t\t\t\tmask3 <<= 8 - (numBits - (this.bitPointer + 1 + 8));\r\n\t\t\t\tvar bitsThirdBlock = (this.blocks[this.blockPointer] & mask3) >> (8 - (numBits - (this.bitPointer + 1 + 8)));\r\n\t\t\t\t\r\n\t\t\t\tbits = bitsFirstBlock + bitsSecondBlock + bitsThirdBlock;\r\n\t\t\t\tthis.bitPointer = this.bitPointer - (numBits - 8) % 8;\r\n\t\t\t\tif (this.bitPointer < 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tthis.bitPointer = 8 + this.bitPointer;\r\n\t\t\t\t}\r\n\t\t\t\treturn bits;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t}\r\n\tthis.NextMode=function()\r\n\t{\r\n\t\tif ((this.blockPointer > this.blocks.length - this.numErrorCorrectionCode - 2))\r\n\t\t\treturn 0;\r\n\t\telse\r\n\t\t\treturn this.getNextBits(4);\r\n\t}\r\n\tthis.getDataLength=function( modeIndicator)\r\n\t\t{\r\n\t\t\tvar index = 0;\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tif ((modeIndicator >> index) == 1)\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tindex++;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\treturn this.getNextBits(qrcode.sizeOfDataLengthInfo[this.dataLengthMode][index]);\r\n\t\t}\r\n\tthis.getRomanAndFigureString=function( dataLength)\r\n\t\t{\r\n\t\t\tvar length = dataLength;\r\n\t\t\tvar intData = 0;\r\n\t\t\tvar strData = \"\";\r\n\t\t\tvar 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', ' ', '$', '%', '*', '+', '-', '.', '/', ':');\r\n\t\t\tdo \r\n\t\t\t{\r\n\t\t\t\tif (length > 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tintData = this.getNextBits(11);\r\n\t\t\t\t\tvar firstLetter = Math.floor(intData / 45);\r\n\t\t\t\t\tvar secondLetter = intData % 45;\r\n\t\t\t\t\tstrData += tableRomanAndFigure[firstLetter];\r\n\t\t\t\t\tstrData += tableRomanAndFigure[secondLetter];\r\n\t\t\t\t\tlength -= 2;\r\n\t\t\t\t}\r\n\t\t\t\telse if (length == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tintData = this.getNextBits(6);\r\n\t\t\t\t\tstrData += tableRomanAndFigure[intData];\r\n\t\t\t\t\tlength -= 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\twhile (length > 0);\r\n\t\t\t\r\n\t\t\treturn strData;\r\n\t\t}\r\n\tthis.getFigureString=function( dataLength)\r\n\t\t{\r\n\t\t\tvar length = dataLength;\r\n\t\t\tvar intData = 0;\r\n\t\t\tvar strData = \"\";\r\n\t\t\tdo \r\n\t\t\t{\r\n\t\t\t\tif (length >= 3)\r\n\t\t\t\t{\r\n\t\t\t\t\tintData = this.getNextBits(10);\r\n\t\t\t\t\tif (intData < 100)\r\n\t\t\t\t\t\tstrData += \"0\";\r\n\t\t\t\t\tif (intData < 10)\r\n\t\t\t\t\t\tstrData += \"0\";\r\n\t\t\t\t\tlength -= 3;\r\n\t\t\t\t}\r\n\t\t\t\telse if (length == 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tintData = this.getNextBits(7);\r\n\t\t\t\t\tif (intData < 10)\r\n\t\t\t\t\t\tstrData += \"0\";\r\n\t\t\t\t\tlength -= 2;\r\n\t\t\t\t}\r\n\t\t\t\telse if (length == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tintData = this.getNextBits(4);\r\n\t\t\t\t\tlength -= 1;\r\n\t\t\t\t}\r\n\t\t\t\tstrData += intData;\r\n\t\t\t}\r\n\t\t\twhile (length > 0);\r\n\t\t\t\r\n\t\t\treturn strData;\r\n\t\t}\r\n\tthis.get8bitByteArray=function( dataLength)\r\n\t\t{\r\n\t\t\tvar length = dataLength;\r\n\t\t\tvar intData = 0;\r\n\t\t\tvar output = new Array();\r\n\t\t\t\r\n\t\t\tdo \r\n\t\t\t{\r\n\t\t\t\tintData = this.getNextBits(8);\r\n\t\t\t\toutput.push( intData);\r\n\t\t\t\tlength--;\r\n\t\t\t}\r\n\t\t\twhile (length > 0);\r\n\t\t\treturn output;\r\n\t\t}\r\n this.getKanjiString=function( dataLength)\r\n\t\t{\r\n\t\t\tvar length = dataLength;\r\n\t\t\tvar intData = 0;\r\n\t\t\tvar unicodeString = \"\";\r\n\t\t\tdo \r\n\t\t\t{\r\n\t\t\t\tintData = this.getNextBits(13);\r\n\t\t\t\tvar lowerByte = intData % 0xC0;\r\n\t\t\t\tvar higherByte = intData / 0xC0;\r\n\t\t\t\t\r\n\t\t\t\tvar tempWord = (higherByte << 8) + lowerByte;\r\n\t\t\t\tvar shiftjisWord = 0;\r\n\t\t\t\tif (tempWord + 0x8140 <= 0x9FFC)\r\n\t\t\t\t{\r\n\t\t\t\t\t// between 8140 - 9FFC on Shift_JIS character set\r\n\t\t\t\t\tshiftjisWord = tempWord + 0x8140;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t// between E040 - EBBF on Shift_JIS character set\r\n\t\t\t\t\tshiftjisWord = tempWord + 0xC140;\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\t//var tempByte = new Array(0,0);\r\n\t\t\t\t//tempByte[0] = (sbyte) (shiftjisWord >> 8);\r\n\t\t\t\t//tempByte[1] = (sbyte) (shiftjisWord & 0xFF);\r\n\t\t\t\t//unicodeString += new String(SystemUtils.ToCharArray(SystemUtils.ToByteArray(tempByte)));\r\n unicodeString += String.fromCharCode(shiftjisWord);\r\n\t\t\t\tlength--;\r\n\t\t\t}\r\n\t\t\twhile (length > 0);\r\n\t\t\t\r\n\t\t\t\r\n\t\t\treturn unicodeString;\r\n\t\t}\r\n\r\n\tthis.parseECIValue = function ()\r\n\t{\r\n\t\tvar intData = 0;\r\n\t\tvar firstByte = this.getNextBits(8);\r\n\t\tif ((firstByte & 0x80) == 0) {\r\n\t\t\tintData = firstByte & 0x7F;\r\n\t\t}\r\n\t\tif ((firstByte & 0xC0) == 0x80) {\r\n\t\t\t// two bytes\r\n\t\t\tvar secondByte = this.getNextBits(8);\r\n\t\t\tintData = ((firstByte & 0x3F) << 8) | secondByte;\r\n\t\t}\r\n\t\tif ((firstByte & 0xE0) == 0xC0) {\r\n\t\t\t// three bytes\r\n\t\t\tvar secondThirdBytes = this.getNextBits(8);;\r\n\t\t\tintData = ((firstByte & 0x1F) << 16) | secondThirdBytes;\r\n\t\t}\r\n\t\treturn intData;\r\n\t}\r\n\r\n\tthis.__defineGetter__(\"DataByte\", function()\r\n\t{\r\n\t\tvar output = new Array();\r\n\t\tvar MODE_NUMBER = 1;\r\n\t var MODE_ROMAN_AND_NUMBER = 2;\r\n\t var MODE_8BIT_BYTE = 4;\r\n\t\tvar MODE_ECI = 7;\r\n\t var MODE_KANJI = 8;\r\n\t\tdo \r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tvar mode = this.NextMode();\r\n\t\t\t\t\t\t//canvas.println(\"mode: \" + mode);\r\n\t\t\t\t\t\tif (mode == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (output.length > 0)\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\tthrow new Error(\"QR Error: Empty data block\");\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (mode != MODE_NUMBER && mode != MODE_ROMAN_AND_NUMBER && mode != MODE_8BIT_BYTE && mode != MODE_KANJI && mode != MODE_ECI)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tthrow new Error(\"QR Error: Invalid mode: \" + mode + \" in (block:\" + this.blockPointer + \" bit:\" + this.bitPointer + \")\");\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif(mode == MODE_ECI)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tvar temp_sbyteArray3 = this.parseECIValue();\r\n\t\t\t\t\t\t\t//output.push(temp_sbyteArray3);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\r\n\t\t\t\t\t\t\tvar dataLength = this.getDataLength(mode);\r\n\t\t\t\t\t\t\tif (dataLength < 1)\r\n\t\t\t\t\t\t\t\tthrow new Error(\"QR Error: Invalid data length: \" + dataLength);\r\n\t\t\t\t\t\t\tswitch (mode)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\tcase MODE_NUMBER: \r\n\t\t\t\t\t\t\t\t\tvar temp_str = this.getFigureString(dataLength);\r\n\t\t\t\t\t\t\t\t\tvar ta = new Array(temp_str.length);\r\n\t\t\t\t\t\t\t\t\tfor(var j=0;j {\n const type = event.data.type;\n const data = event.data.data;\n if (type === 'setDebug') {\n qrcode.debug = data;\n } else if (type === 'decode') {\n let result = null;\n try {\n result = qrcode.decode(data);\n } catch(e) {\n if (!e.message.startsWith('QR Error')) {\n throw e; // some unexpected error\n }\n // console.log(e);\n } finally {\n self.postMessage({\n type: 'qrResult',\n data: result\n });\n }\n }\n};\n\n\nfunction sendDebugImage(debugImage) {\n self.postMessage({\n type: 'debugImage',\n data: debugImage\n }, [debugImage.data.buffer]);\n}","/*\r\n Copyright 2011 Lazar Laszlo (lazarsoft@gmail.com, www.lazarsoft.info)\r\n \r\n Licensed under the Apache License, Version 2.0 (the \"License\");\r\n you may not use this file except in compliance with the License.\r\n You may obtain a copy of the License at\r\n\r\n http://www.apache.org/licenses/LICENSE-2.0\r\n\r\n Unless required by applicable law or agreed to in writing, software\r\n distributed under the License is distributed on an \"AS IS\" BASIS,\r\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n See the License for the specific language governing permissions and\r\n limitations under the License.\r\n*/\r\n\r\n\r\nvar qrcode = {};\r\nqrcode.imagedata = null;\r\nqrcode.width = 0;\r\nqrcode.height = 0;\r\nqrcode.qrCodeSymbol = null;\r\nqrcode.debug = false;\r\nqrcode.maxImgSize = 1024*1024;\r\n\r\nqrcode.sizeOfDataLengthInfo = [ [ 10, 9, 8, 8 ], [ 12, 11, 16, 10 ], [ 14, 13, 16, 12 ] ];\r\n\r\nqrcode.callback = null;\r\n\r\nqrcode.decode = function(imageData) {\r\n qrcode.imagedata = imageData;\r\n qrcode.width = imageData.width;\r\n qrcode.height = imageData.height;\r\n qrcode.result = qrcode.process();\r\n if(qrcode.callback!=null)\r\n qrcode.callback(qrcode.result);\r\n return qrcode.result;\r\n}\r\n\r\nqrcode.isUrl = function(s)\r\n{\r\n try {\r\n new URL(s);\r\n return true;\r\n } catch(e) {\r\n return false;\r\n }\r\n}\r\n\r\nqrcode.decode_url = function (s)\r\n{\r\n var escaped = \"\";\r\n try{\r\n escaped = escape( s );\r\n }\r\n catch(e)\r\n {\r\n console.log(e);\r\n escaped = s;\r\n }\r\n var ret = \"\";\r\n try{\r\n ret = decodeURIComponent( escaped );\r\n }\r\n catch(e)\r\n {\r\n console.log(e);\r\n ret = escaped;\r\n }\r\n return ret;\r\n}\r\n\r\nqrcode.decode_utf8 = function ( s )\r\n{\r\n if(qrcode.isUrl(s))\r\n return qrcode.decode_url(s);\r\n else\r\n return s;\r\n}\r\n\r\nqrcode.process = function(){\r\n var inputRgba = qrcode.imagedata.data;\r\n // asign the grayscale and binary image within the rgba buffer as the rgba image will not be needed anymore\r\n var offset = 0;\r\n var grayscaleImage = new Uint8ClampedArray(inputRgba.buffer, offset, qrcode.width * qrcode.height);\r\n offset += qrcode.width * qrcode.height;\r\n var binaryImage = new Uint8ClampedArray(inputRgba.buffer, offset, qrcode.width * qrcode.height);\r\n offset += qrcode.width * qrcode.height;\r\n var binarizerBufferSize = Binarizer.calculateRequiredBufferSize(qrcode.width, qrcode.height);\r\n var binarizerBuffer = new Uint8ClampedArray(inputRgba.buffer, offset, binarizerBufferSize);\r\n\r\n qrcode.grayscale(inputRgba, qrcode.width, qrcode.height, grayscaleImage);\r\n Binarizer.binarize(grayscaleImage, qrcode.width, qrcode.height, binaryImage, binarizerBuffer);\r\n\r\n var debugImage;\r\n if(qrcode.debug)\r\n {\r\n debugImage = new ImageData(new Uint8ClampedArray(qrcode.width * qrcode.height * 4), qrcode.width, qrcode.height);\r\n for (var y = 0; y < qrcode.height; y++)\r\n {\r\n for (var x = 0; x < qrcode.width; x++)\r\n {\r\n var point = (x * 4) + (y * qrcode.width * 4);\r\n var pixel = /*grayscaleImage[y * qrcode.width + x];*/ binaryImage[y * qrcode.width + x]? 0 : 255;\r\n debugImage.data[point] = pixel;\r\n debugImage.data[point+1] = pixel;\r\n debugImage.data[point+2] = pixel;\r\n debugImage.data[point+3] = 255; // alpha\r\n }\r\n }\r\n }\r\n\r\n try {\r\n var detector = new Detector(binaryImage);\r\n\r\n var qRCodeMatrix = detector.detect(); // throws if no qr code was found\r\n\r\n if (qrcode.debug) {\r\n for (var y = 0; y < qRCodeMatrix.bits.getHeight(); y++) {\r\n for (var x = 0; x < qRCodeMatrix.bits.getWidth(); x++) {\r\n var point = (x * 4 * 2) + (y * 2 * qrcode.width * 4);\r\n var isSet = qRCodeMatrix.bits.get_Renamed(x, y)\r\n debugImage.data[point] = isSet ? 0 : 255;\r\n debugImage.data[point + 1] = isSet ? 0 : 255;\r\n debugImage.data[point + 2] = 255;\r\n }\r\n }\r\n }\r\n } finally {\r\n if (qrcode.debug) {\r\n sendDebugImage(debugImage);\r\n }\r\n }\r\n\r\n \r\n \r\n var reader = Decoder.decode(qRCodeMatrix.bits);\r\n var data = reader.getDataByte();\r\n var str=\"\";\r\n for(var i=0;i> 8;\r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n\r\nfunction URShift( number, bits)\r\n{\r\n if (number >= 0)\r\n return number >> bits;\r\n else\r\n return (number >> bits) + (2 << ~bits);\r\n}","// Implementation taken from https://github.com/nimiq-design/nimiqode and follows the idea of\n// https://github.com/zxing/zxing/blob/master/core/src/main/java/com/google/zxing/common/HybridBinarizer.java\n\n\nclass Binarizer {\n static calculateRequiredBufferSize(imageWidth, imageHeight) {\n // memory for threshold for every block\n const [, blockCountX, blockCountY] = Binarizer._calculateBlockSize(imageWidth, imageHeight);\n return blockCountX * blockCountY;\n }\n\n static _calculateBlockSize(imageWidth, imageHeight) {\n const blockSize = Math.max(\n Math.floor(Math.min(imageWidth, imageHeight) / Binarizer.TARGET_BLOCK_COUNT_ALONG_SHORTER_SIDE),\n Binarizer.MIN_BLOCK_SIZE\n );\n\n const blockCountX = Math.ceil(imageWidth / blockSize);\n const blockCountY = Math.ceil(imageHeight / blockSize);\n return [blockSize, blockCountX, blockCountY];\n }\n\n static binarize(inputGrayscale, imageWidth, imageHeight, outputBinary = inputGrayscale, buffer = null) {\n const [blockSize, blockCountX, blockCountY] =\n Binarizer._calculateBlockSize(imageWidth, imageHeight);\n let blockThresholds;\n if (buffer) {\n if (!(buffer instanceof Uint8ClampedArray) || buffer.byteLength !== blockCountX * blockCountY) {\n throw new Error('QR Error: Illegal Buffer.');\n }\n blockThresholds = buffer;\n } else {\n blockThresholds = new Uint8ClampedArray(blockCountX * blockCountY);\n }\n // calculate the thresholds for the blocks\n for (let blockIndexY=0; blockIndexY < blockCountY; ++blockIndexY) {\n for (let blockIndexX=0; blockIndexX < blockCountX; ++blockIndexX) {\n const threshold = Binarizer._calculateBlockThreshold(inputGrayscale, imageWidth, imageHeight,\n blockIndexX, blockIndexY, blockCountX, blockSize, blockThresholds);\n blockThresholds[blockIndexY * blockCountX + blockIndexX] = threshold;\n }\n }\n for (let blockIndexY=0; blockIndexY < blockCountY; ++blockIndexY) {\n for (let blockIndexX=0; blockIndexX < blockCountX; ++blockIndexX) {\n // calculate the average threshold over a 5x5 grid to essentially make the area bigger and increase\n // the chance that we have a bright and dark pixel in the area for good threshold computation. By\n // keeping the real block size small we ensure a good local threshold estimate (the step size in x and\n // y direction is essentially smaller).\n //\n // Instead of (min+max)/2 like in _calculateBlockThreshold, here we use a real average to be more prune\n // against outliers. E.g. imagine whats behind the scanned screen is really dark, the screen (including\n // dark pixels on the screen) rather bright. In this case, we want the threshold on the screen to be\n // rather bright and therefore not to factor in the background too much.\n let sum = 0;\n for (let i = -2; i<=2; ++i) {\n for (let j = -2; j<=2; ++j) {\n const neighborIndexX = Math.max(0, Math.min(blockCountX-1, blockIndexX+i));\n const neighborIndexY = Math.max(0, Math.min(blockCountY-1, blockIndexY+j));\n sum += blockThresholds[neighborIndexY * blockCountX + neighborIndexX];\n }\n }\n Binarizer._applyThresholdToBlock(inputGrayscale, imageWidth, imageHeight, blockIndexX, blockIndexY,\n blockSize, sum / 25, outputBinary);\n }\n }\n }\n\n static _calculateBlockThreshold(inputGrayscale, imageWidth, imageHeight, blockIndexX, blockIndexY, blockCountX, blockSize,\n blockThresholds) {\n let min = 0xFF, max = 0;\n const left = Math.min(blockIndexX * blockSize, imageWidth - blockSize);\n const top = Math.min(blockIndexY * blockSize, imageHeight - blockSize);\n let rowStart = top * imageWidth + left;\n for (let y=0; y max) {\n max = pixel;\n }\n }\n rowStart += imageWidth;\n }\n if (max - min > Binarizer.MIN_DYNAMIC_RANGE) {\n // The values span a minimum dynamic range, so we can assume we have bright and dark pixels. Return the\n // average of min and max as threshold. We could also compute the real average of all pixel but following\n // the assumption that the nimiqode consists of bright and dark pixels and essentially not much in between\n // then by (min + max)/2 we make the cut really between those two classes. If using the average over all\n // pixel then in a block of mostly bright pixels and few dark pixels, the avg would tend to the bright side\n // and darker bright pixels could be interpreted as dark.\n return (min + max) / 2;\n } else {\n // We have a low dynamic range and assume the block is of solid bright or dark color.\n // TODO this zxing implementation is somewhat weird. Think of a better threshold propagation strategy.\n // Ideas:\n // - start the propagation in the middle of the screen following the assumption that the nimiqode / screen\n // is centered in the image. By this, we avoid propagation of thresholds from the surrounding to the\n // screen which hold the only interesting information to us.\n // - Combine the threshold propagation with edge detection\n // - When propagating a threshold adapt it by comparing the average brightness in my block to the average\n // brightness in block we are propagating from\n if (blockIndexX === 0 || blockIndexY === 0) {\n // cant compare to the neighbours. Assume it's a light background\n return min / 2;\n } else {\n const myIndex = blockIndexY * blockCountX + blockIndexX;\n const leftBlockThreshold = blockThresholds[myIndex - 1];\n const topBlockThreshold = blockThresholds[myIndex - blockCountX];\n const topLeftBlockThreshold = blockCountX[myIndex - blockCountX - 1];\n const neighbourAverage = (leftBlockThreshold + topBlockThreshold + topLeftBlockThreshold) / 3;\n if (neighbourAverage > min) {\n return neighbourAverage;\n } else {\n return min / 2;\n }\n }\n }\n }\n\n\n static _applyThresholdToBlock(inputGrayscale, imageWidth, imageHeight, blockIndexX, blockIndexY, blockSize, threshold,\n outputBinary = inputGrayscale) {\n const left = Math.min(blockIndexX * blockSize, imageWidth - blockSize);\n const top = Math.min(blockIndexY * blockSize, imageHeight - blockSize);\n let rowStart = top * imageWidth + left;\n for (let y=0; y> 5;\r\n\tif ((width & 0x1f) != 0)\r\n\t{\r\n\t\trowSize++;\r\n\t}\r\n\tthis.rowSize = rowSize;\r\n\tthis.bits = new Array(rowSize * height);\r\n\tfor(var i=0;i> 5);\r\n\t\t\treturn ((URShift(this.bits[offset], (x & 0x1f))) & 1) != 0;\r\n\t\t}\r\n\tthis.set_Renamed=function( x, y)\r\n\t\t{\r\n\t\t\tvar offset = y * this.rowSize + (x >> 5);\r\n\t\t\tthis.bits[offset] |= 1 << (x & 0x1f);\r\n\t\t}\r\n\tthis.flip=function( x, y)\r\n\t\t{\r\n\t\t\tvar offset = y * this.rowSize + (x >> 5);\r\n\t\t\tthis.bits[offset] ^= 1 << (x & 0x1f);\r\n\t\t}\r\n\tthis.clear=function()\r\n\t\t{\r\n\t\t\tvar max = this.bits.length;\r\n\t\t\tfor (var i = 0; i < max; i++)\r\n\t\t\t{\r\n\t\t\t\tthis.bits[i] = 0;\r\n\t\t\t}\r\n\t\t}\r\n\tthis.setRegion=function( left, top, width, height)\r\n\t\t{\r\n\t\t\tif (top < 0 || left < 0)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(\"QR Error: Left and top must be nonnegative\");\r\n\t\t\t}\r\n\t\t\tif (height < 1 || width < 1)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(\"QR Error: Height and width must be at least 1\");\r\n\t\t\t}\r\n\t\t\tvar right = left + width;\r\n\t\t\tvar bottom = top + height;\r\n\t\t\tif (bottom > this.height || right > this.width)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(\"QR Error: The region must fit inside the matrix\");\r\n\t\t\t}\r\n\t\t\tfor (var y = top; y < bottom; y++)\r\n\t\t\t{\r\n\t\t\t\tvar offset = y * this.rowSize;\r\n\t\t\t\tfor (var x = left; x < right; x++)\r\n\t\t\t\t{\r\n\t\t\t\t\tthis.bits[offset + (x >> 5)] |= 1 << (x & 0x1f);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n}","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nvar Decoder={};\r\nDecoder.rsDecoder = new ReedSolomonDecoder(GF256.QR_CODE_FIELD);\r\n\r\nDecoder.correctErrors=function( codewordBytes, numDataCodewords)\r\n{\r\n\tvar numCodewords = codewordBytes.length;\r\n\t// First read into an array of ints\r\n\tvar codewordsInts = new Array(numCodewords);\r\n\tfor (var i = 0; i < numCodewords; i++)\r\n\t{\r\n\t\tcodewordsInts[i] = codewordBytes[i] & 0xFF;\r\n\t}\r\n\tvar numECCodewords = codewordBytes.length - numDataCodewords;\r\n\ttry\r\n\t{\r\n\t\tDecoder.rsDecoder.decode(codewordsInts, numECCodewords);\r\n\t\t//var corrector = new ReedSolomon(codewordsInts, numECCodewords);\r\n\t\t//corrector.correct();\r\n\t}\r\n\tcatch ( rse)\r\n\t{\r\n\t\tthrow rse;\r\n\t}\r\n\t// Copy back into array of bytes -- only need to worry about the bytes that were data\r\n\t// We don't care about errors in the error-correction codewords\r\n\tfor (var i = 0; i < numDataCodewords; i++)\r\n\t{\r\n\t\tcodewordBytes[i] = codewordsInts[i];\r\n\t}\r\n}\r\n\r\nDecoder.decode=function(bits)\r\n{\r\n\tvar parser = new BitMatrixParser(bits);\r\n\tvar version = parser.readVersion();\r\n\tvar ecLevel = parser.readFormatInformation().getErrorCorrectionLevel();\r\n\t\r\n\t// Read codewords\r\n\tvar codewords = parser.readCodewords();\r\n\r\n\t// Separate into data blocks\r\n\tvar dataBlocks = DataBlock.getDataBlocks(codewords, version, ecLevel);\r\n\t\r\n\t// Count total number of data bytes\r\n\tvar totalBytes = 0;\r\n\tfor (var i = 0; i < dataBlocks.length; i++)\r\n\t{\r\n\t\ttotalBytes += dataBlocks[i].getNumDataCodewords();\r\n\t}\r\n\tvar resultBytes = new Array(totalBytes);\r\n\tvar resultOffset = 0;\r\n\t\r\n\t// Error-correct and copy data blocks together into a stream of bytes\r\n\tfor (var j = 0; j < dataBlocks.length; j++)\r\n\t{\r\n\t\tvar dataBlock = dataBlocks[j];\r\n\t\tvar codewordBytes = dataBlock.getCodewords();\r\n\t\tvar numDataCodewords = dataBlock.getNumDataCodewords();\r\n\t\tDecoder.correctErrors(codewordBytes, numDataCodewords);\r\n\t\tfor (var i = 0; i < numDataCodewords; i++)\r\n\t\t{\r\n\t\t\tresultBytes[resultOffset++] = codewordBytes[i];\r\n\t\t}\r\n\t}\r\n\t\r\n\t// Decode the contents of that stream of bytes\r\n\tvar reader = new QRCodeDataBlockReader(resultBytes, version.getVersionNumber(), ecLevel.getBits());\r\n\treturn reader;\r\n\t//return DecodedBitStreamParser.decode(resultBytes, version, ecLevel);\r\n}\r\n","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nvar FORMAT_INFO_MASK_QR = 0x5412;\r\nvar 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));\r\nvar BITS_SET_IN_HALF_BYTE = new Array(0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4);\r\n\r\n\r\nfunction FormatInformation(formatInfo)\r\n{\r\n\tthis.errorCorrectionLevel = ErrorCorrectionLevel.forBits((formatInfo >> 3) & 0x03);\r\n\tthis.dataMask = (formatInfo & 0x07);\r\n\r\n\tthis.getErrorCorrectionLevel = function()\r\n\t{\r\n\t\treturn this.errorCorrectionLevel;\r\n\t};\r\n\tthis.getDataMask = function()\r\n\t{\r\n\t\treturn this.dataMask;\r\n\t};\r\n\tthis.GetHashCode=function()\r\n\t{\r\n\t\treturn (this.errorCorrectionLevel.ordinal() << 3) | this.dataMask;\r\n\t}\r\n\tthis.Equals=function( o)\r\n\t{\r\n\t\tvar other = o;\r\n\t\treturn this.errorCorrectionLevel == other.errorCorrectionLevel && this.dataMask == other.dataMask;\r\n\t}\r\n}\r\n\r\nFormatInformation.numBitsDiffering=function( a, b)\r\n{\r\n\ta ^= b; // a now has a 1 bit exactly where its bit differs with b's\r\n\t// Count bits set quickly with a series of lookups:\r\n\treturn 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)];\r\n}\r\n\r\nFormatInformation.decodeFormatInformation=function( maskedFormatInfo)\r\n{\r\n\tvar formatInfo = FormatInformation.doDecodeFormatInformation(maskedFormatInfo);\r\n\tif (formatInfo != null)\r\n\t{\r\n\t\treturn formatInfo;\r\n\t}\r\n\t// Should return null, but, some QR codes apparently\r\n\t// do not mask this info. Try again by actually masking the pattern\r\n\t// first\r\n\treturn FormatInformation.doDecodeFormatInformation(maskedFormatInfo ^ FORMAT_INFO_MASK_QR);\r\n}\r\nFormatInformation.doDecodeFormatInformation=function( maskedFormatInfo)\r\n{\r\n\t// Find the int in FORMAT_INFO_DECODE_LOOKUP with fewest bits differing\r\n\tvar bestDifference = 0xffffffff;\r\n\tvar bestFormatInfo = 0;\r\n\tfor (var i = 0; i < FORMAT_INFO_DECODE_LOOKUP.length; i++)\r\n\t{\r\n\t\tvar decodeInfo = FORMAT_INFO_DECODE_LOOKUP[i];\r\n\t\tvar targetInfo = decodeInfo[0];\r\n\t\tif (targetInfo == maskedFormatInfo)\r\n\t\t{\r\n\t\t\t// Found an exact match\r\n\t\t\treturn new FormatInformation(decodeInfo[1]);\r\n\t\t}\r\n\t\tvar bitsDifference = FormatInformation.numBitsDiffering(maskedFormatInfo, targetInfo);\r\n\t\tif (bitsDifference < bestDifference)\r\n\t\t{\r\n\t\t\tbestFormatInfo = decodeInfo[1];\r\n\t\t\tbestDifference = bitsDifference;\r\n\t\t}\r\n\t}\r\n\t// Hamming distance of the 32 masked codes is 7, by construction, so <= 3 bits\r\n\t// differing means we found a match\r\n\tif (bestDifference <= 3)\r\n\t{\r\n\t\treturn new FormatInformation(bestFormatInfo);\r\n\t}\r\n\treturn null;\r\n}\r\n\r\n\t\t","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nfunction DataBlock(numDataCodewords, codewords)\r\n{\r\n\tthis.numDataCodewords = numDataCodewords;\r\n\tthis.codewords = codewords;\r\n\t\r\n\tthis.getNumDataCodewords = function()\r\n\t{\r\n\t\treturn this.numDataCodewords;\r\n\t};\r\n\tthis.getCodewords = function()\r\n\t{\r\n\t\treturn this.codewords;\r\n\t};\r\n}\t\r\n\t\r\nDataBlock.getDataBlocks=function(rawCodewords, version, ecLevel)\r\n{\r\n\t\r\n\tif (rawCodewords.length != version.getTotalCodewords())\r\n\t{\r\n\t\tthrow new Error(\"QR Error: ArgumentException\");\r\n\t}\r\n\t\r\n\t// Figure out the number and size of data blocks used by this version and\r\n\t// error correction level\r\n\tvar ecBlocks = version.getECBlocksForLevel(ecLevel);\r\n\t\r\n\t// First count the total number of data blocks\r\n\tvar totalBlocks = 0;\r\n\tvar ecBlockArray = ecBlocks.getECBlocks();\r\n\tfor (var i = 0; i < ecBlockArray.length; i++)\r\n\t{\r\n\t\ttotalBlocks += ecBlockArray[i].getCount();\r\n\t}\r\n\t\r\n\t// Now establish DataBlocks of the appropriate size and number of data codewords\r\n\tvar result = new Array(totalBlocks);\r\n\tvar numResultBlocks = 0;\r\n\tfor (var j = 0; j < ecBlockArray.length; j++)\r\n\t{\r\n\t\tvar ecBlock = ecBlockArray[j];\r\n\t\tfor (var i = 0; i < ecBlock.getCount(); i++)\r\n\t\t{\r\n\t\t\tvar numDataCodewords = ecBlock.getDataCodewords();\r\n\t\t\tvar numBlockCodewords = ecBlocks.getECCodewordsPerBlock() + numDataCodewords;\r\n\t\t\tresult[numResultBlocks++] = new DataBlock(numDataCodewords, new Array(numBlockCodewords));\r\n\t\t}\r\n\t}\r\n\t\r\n\t// All blocks have the same amount of data, except that the last n\r\n\t// (where n may be 0) have 1 more byte. Figure out where these start.\r\n\tvar shorterBlocksTotalCodewords = result[0].codewords.length;\r\n\tvar longerBlocksStartAt = result.length - 1;\r\n\twhile (longerBlocksStartAt >= 0)\r\n\t{\r\n\t\tvar numCodewords = result[longerBlocksStartAt].codewords.length;\r\n\t\tif (numCodewords == shorterBlocksTotalCodewords)\r\n\t\t{\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tlongerBlocksStartAt--;\r\n\t}\r\n\tlongerBlocksStartAt++;\r\n\t\r\n\tvar shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBlocks.getECCodewordsPerBlock();\r\n\t// The last elements of result may be 1 element longer;\r\n\t// first fill out as many elements as all of them have\r\n\tvar rawCodewordsOffset = 0;\r\n\tfor (var i = 0; i < shorterBlocksNumDataCodewords; i++)\r\n\t{\r\n\t\tfor (var j = 0; j < numResultBlocks; j++)\r\n\t\t{\r\n\t\t\tresult[j].codewords[i] = rawCodewords[rawCodewordsOffset++];\r\n\t\t}\r\n\t}\r\n\t// Fill out the last data block in the longer ones\r\n\tfor (var j = longerBlocksStartAt; j < numResultBlocks; j++)\r\n\t{\r\n\t\tresult[j].codewords[shorterBlocksNumDataCodewords] = rawCodewords[rawCodewordsOffset++];\r\n\t}\r\n\t// Now add in error correction blocks\r\n\tvar max = result[0].codewords.length;\r\n\tfor (var i = shorterBlocksNumDataCodewords; i < max; i++)\r\n\t{\r\n\t\tfor (var j = 0; j < numResultBlocks; j++)\r\n\t\t{\r\n\t\t\tvar iOffset = j < longerBlocksStartAt?i:i + 1;\r\n\t\t\tresult[j].codewords[iOffset] = rawCodewords[rawCodewordsOffset++];\r\n\t\t}\r\n\t}\r\n\treturn result;\r\n}\r\n","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\n\r\nfunction ECB(count, dataCodewords)\r\n{\r\n\tthis.count = count;\r\n\tthis.dataCodewords = dataCodewords;\r\n\t\r\n\tthis.getCount = function()\r\n\t{\r\n\t\treturn this.count;\r\n\t};\r\n\tthis.getDataCodewords = function()\r\n\t{\r\n\t\treturn this.dataCodewords;\r\n\t};\r\n}\r\n\r\nfunction ECBlocks( ecCodewordsPerBlock, ecBlocks1, ecBlocks2)\r\n{\r\n\tthis.ecCodewordsPerBlock = ecCodewordsPerBlock;\r\n\tif(ecBlocks2)\r\n\t\tthis.ecBlocks = new Array(ecBlocks1, ecBlocks2);\r\n\telse\r\n\t\tthis.ecBlocks = new Array(ecBlocks1);\r\n\t\r\n\tthis.getECCodewordsPerBlock = function()\r\n\t{\r\n\t\treturn this.ecCodewordsPerBlock;\r\n\t};\r\n\t\r\n\tthis.getTotalECCodewords = function()\r\n\t{\r\n\t\treturn this.ecCodewordsPerBlock * this.getNumBlocks();\r\n\t};\r\n\t\r\n\tthis.getNumBlocks = function()\r\n\t{\r\n\t\tvar total = 0;\r\n\t\tfor (var i = 0; i < this.ecBlocks.length; i++)\r\n\t\t{\r\n\t\t\ttotal += this.ecBlocks[i].length;\r\n\t\t}\r\n\t\treturn total;\r\n\t};\r\n\t\r\n\tthis.getECBlocks=function()\r\n\t\t\t{\r\n\t\t\t\treturn this.ecBlocks;\r\n\t\t\t}\r\n}\r\n\r\nfunction Version( versionNumber, alignmentPatternCenters, ecBlocks1, ecBlocks2, ecBlocks3, ecBlocks4)\r\n{\r\n\tthis.versionNumber = versionNumber;\r\n\tthis.alignmentPatternCenters = alignmentPatternCenters;\r\n\tthis.ecBlocks = new Array(ecBlocks1, ecBlocks2, ecBlocks3, ecBlocks4);\r\n\t\r\n\tvar total = 0;\r\n\tvar ecCodewords = ecBlocks1.getECCodewordsPerBlock();\r\n\tvar ecbArray = ecBlocks1.getECBlocks();\r\n\tfor (var i = 0; i < ecbArray.length; i++)\r\n\t{\r\n\t\tvar ecBlock = ecbArray[i];\r\n\t\ttotal += ecBlock.getCount() * (ecBlock.getDataCodewords() + ecCodewords);\r\n\t}\r\n\tthis.totalCodewords = total;\r\n\t\r\n\tthis.getVersionNumber = function()\r\n\t{\r\n\t\treturn this.versionNumber;\r\n\t};\r\n\t\r\n\tthis.getAlignmentPatternCenters = function()\r\n\t{\r\n\t\treturn this.alignmentPatternCenters;\r\n\t};\r\n\tthis.getTotalCodewords = function()\r\n\t{\r\n\t\treturn this.totalCodewords;\r\n\t};\r\n\tthis.getDimensionForVersion = function()\r\n\t{\r\n\t\treturn 17 + 4 * this.versionNumber;\r\n\t};\r\n\t\r\n\tthis.buildFunctionPattern=function()\r\n\t\t{\r\n\t\t\tvar dimension = this.getDimensionForVersion();\r\n\t\t\tvar bitMatrix = new BitMatrix(dimension);\r\n\t\t\t\r\n\t\t\t// Top left finder pattern + separator + format\r\n\t\t\tbitMatrix.setRegion(0, 0, 9, 9);\r\n\t\t\t// Top right finder pattern + separator + format\r\n\t\t\tbitMatrix.setRegion(dimension - 8, 0, 8, 9);\r\n\t\t\t// Bottom left finder pattern + separator + format\r\n\t\t\tbitMatrix.setRegion(0, dimension - 8, 9, 8);\r\n\t\t\t\r\n\t\t\t// Alignment patterns\r\n\t\t\tvar max = this.alignmentPatternCenters.length;\r\n\t\t\tfor (var x = 0; x < max; x++)\r\n\t\t\t{\r\n\t\t\t\tvar i = this.alignmentPatternCenters[x] - 2;\r\n\t\t\t\tfor (var y = 0; y < max; y++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// No alignment patterns near the three finder paterns\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tbitMatrix.setRegion(this.alignmentPatternCenters[y] - 2, i, 5, 5);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Vertical timing pattern\r\n\t\t\tbitMatrix.setRegion(6, 9, 1, dimension - 17);\r\n\t\t\t// Horizontal timing pattern\r\n\t\t\tbitMatrix.setRegion(9, 6, dimension - 17, 1);\r\n\t\t\t\r\n\t\t\tif (this.versionNumber > 6)\r\n\t\t\t{\r\n\t\t\t\t// Version info, top right\r\n\t\t\t\tbitMatrix.setRegion(dimension - 11, 0, 3, 6);\r\n\t\t\t\t// Version info, bottom left\r\n\t\t\t\tbitMatrix.setRegion(0, dimension - 11, 6, 3);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\treturn bitMatrix;\r\n\t\t}\r\n\tthis.getECBlocksForLevel=function( ecLevel)\r\n\t{\r\n\t\treturn this.ecBlocks[ecLevel.ordinal()];\r\n\t}\r\n}\r\n\r\nVersion.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);\r\n\r\nVersion.VERSIONS = buildVersions();\r\n\r\nVersion.getVersionForNumber=function( versionNumber)\r\n{\r\n\tif (versionNumber < 1 || versionNumber > 40)\r\n\t{\r\n\t\tthrow new Error(\"QR Error: ArgumentException\");\r\n\t}\r\n\treturn Version.VERSIONS[versionNumber - 1];\r\n}\r\n\r\nVersion.getProvisionalVersionForDimension=function(dimension)\r\n{\r\n\tif (dimension % 4 != 1)\r\n\t{\r\n\t\tthrow new Error(\"QR Error: Error getProvisionalVersionForDimension\");\r\n\t}\r\n\ttry\r\n\t{\r\n\t\treturn Version.getVersionForNumber((dimension - 17) >> 2);\r\n\t}\r\n\tcatch ( iae)\r\n\t{\r\n\t\tthrow new Error(\"QR Error: Error getVersionForNumber\");\r\n\t}\r\n}\r\n\r\nVersion.decodeVersionInformation=function( versionBits)\r\n{\r\n\tvar bestDifference = 0xffffffff;\r\n\tvar bestVersion = 0;\r\n\tfor (var i = 0; i < Version.VERSION_DECODE_INFO.length; i++)\r\n\t{\r\n\t\tvar targetVersion = Version.VERSION_DECODE_INFO[i];\r\n\t\t// Do the version info bits match exactly? done.\r\n\t\tif (targetVersion == versionBits)\r\n\t\t{\r\n\t\t\treturn Version.getVersionForNumber(i + 7);\r\n\t\t}\r\n\t\t// Otherwise see if this is the closest to a real version info bit string\r\n\t\t// we have seen so far\r\n\t\tvar bitsDifference = FormatInformation.numBitsDiffering(versionBits, targetVersion);\r\n\t\tif (bitsDifference < bestDifference)\r\n\t\t{\r\n\t\t\tbestVersion = i + 7;\r\n\t\t\tbestDifference = bitsDifference;\r\n\t\t}\r\n\t}\r\n\t// We can tolerate up to 3 bits of error since no two version info codewords will\r\n\t// differ in less than 4 bits.\r\n\tif (bestDifference <= 3)\r\n\t{\r\n\t\treturn Version.getVersionForNumber(bestVersion);\r\n\t}\r\n\t// If we didn't find a close enough match, fail\r\n\treturn null;\r\n}\r\n\r\nfunction buildVersions()\r\n{\r\n\treturn 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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), \t\tnew ECB(28, 16))),\r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))), \r\n\tnew 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))));\r\n}","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nfunction ErrorCorrectionLevel(ordinal, bits, name)\r\n{\r\n\tthis.ordinal_Renamed_Field = ordinal;\r\n\tthis.bits = bits;\r\n\tthis.name = name;\r\n\tthis.getBits = function()\r\n\t{\r\n\t\treturn this.bits;\r\n\t};\r\n\tthis.getName = function()\r\n\t{\r\n\t\treturn this.name;\r\n\t};\r\n\tthis.ordinal=function()\r\n\t{\r\n\t\treturn this.ordinal_Renamed_Field;\r\n\t}\r\n}\r\n\r\nErrorCorrectionLevel.forBits=function( bits)\r\n{\r\n\tif (bits < 0 || bits >= FOR_BITS.length)\r\n\t{\r\n\t\tthrow new Error(\"QR Error: ArgumentException\");\r\n\t}\r\n\treturn FOR_BITS[bits];\r\n}\r\n\r\nvar L = new ErrorCorrectionLevel(0, 0x01, \"L\");\r\nvar M = new ErrorCorrectionLevel(1, 0x00, \"M\");\r\nvar Q = new ErrorCorrectionLevel(2, 0x03, \"Q\");\r\nvar H = new ErrorCorrectionLevel(3, 0x02, \"H\");\r\nvar FOR_BITS = new Array( M, L, H, Q);","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nfunction PerspectiveTransform( a11, a21, a31, a12, a22, a32, a13, a23, a33)\r\n{\r\n\tthis.a11 = a11;\r\n\tthis.a12 = a12;\r\n\tthis.a13 = a13;\r\n\tthis.a21 = a21;\r\n\tthis.a22 = a22;\r\n\tthis.a23 = a23;\r\n\tthis.a31 = a31;\r\n\tthis.a32 = a32;\r\n\tthis.a33 = a33;\r\n\tthis.transformPoints1=function( points)\r\n\t\t{\r\n\t\t\tvar max = points.length;\r\n\t\t\tvar a11 = this.a11;\r\n\t\t\tvar a12 = this.a12;\r\n\t\t\tvar a13 = this.a13;\r\n\t\t\tvar a21 = this.a21;\r\n\t\t\tvar a22 = this.a22;\r\n\t\t\tvar a23 = this.a23;\r\n\t\t\tvar a31 = this.a31;\r\n\t\t\tvar a32 = this.a32;\r\n\t\t\tvar a33 = this.a33;\r\n\t\t\tfor (var i = 0; i < max; i += 2)\r\n\t\t\t{\r\n\t\t\t\tvar x = points[i];\r\n\t\t\t\tvar y = points[i + 1];\r\n\t\t\t\tvar denominator = a13 * x + a23 * y + a33;\r\n\t\t\t\tpoints[i] = (a11 * x + a21 * y + a31) / denominator;\r\n\t\t\t\tpoints[i + 1] = (a12 * x + a22 * y + a32) / denominator;\r\n\t\t\t}\r\n\t\t}\r\n\tthis. transformPoints2=function(xValues, yValues)\r\n\t\t{\r\n\t\t\tvar n = xValues.length;\r\n\t\t\tfor (var i = 0; i < n; i++)\r\n\t\t\t{\r\n\t\t\t\tvar x = xValues[i];\r\n\t\t\t\tvar y = yValues[i];\r\n\t\t\t\tvar denominator = this.a13 * x + this.a23 * y + this.a33;\r\n\t\t\t\txValues[i] = (this.a11 * x + this.a21 * y + this.a31) / denominator;\r\n\t\t\t\tyValues[i] = (this.a12 * x + this.a22 * y + this.a32) / denominator;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\tthis.buildAdjoint=function()\r\n\t\t{\r\n\t\t\t// Adjoint is the transpose of the cofactor matrix:\r\n\t\t\treturn 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);\r\n\t\t}\r\n\tthis.times=function( other)\r\n\t\t{\r\n\t\t\treturn 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);\r\n\t\t}\r\n\r\n}\r\n\r\nPerspectiveTransform.quadrilateralToQuadrilateral=function( x0, y0, x1, y1, x2, y2, x3, y3, x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p)\r\n{\r\n\t\r\n\tvar qToS = PerspectiveTransform.quadrilateralToSquare(x0, y0, x1, y1, x2, y2, x3, y3);\r\n\tvar sToQ = PerspectiveTransform.squareToQuadrilateral(x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p);\r\n\treturn sToQ.times(qToS);\r\n}\r\n\r\nPerspectiveTransform.squareToQuadrilateral=function( x0, y0, x1, y1, x2, y2, x3, y3)\r\n{\r\n\tvar dy2 = y3 - y2;\r\n\tvar dy3 = y0 - y1 + y2 - y3;\r\n\tif (dy2 == 0.0 && dy3 == 0.0)\r\n\t{\r\n\t\treturn new PerspectiveTransform(x1 - x0, x2 - x1, x0, y1 - y0, y2 - y1, y0, 0.0, 0.0, 1.0);\r\n\t}\r\n\telse\r\n\t{\r\n\t\tvar dx1 = x1 - x2;\r\n\t\tvar dx2 = x3 - x2;\r\n\t\tvar dx3 = x0 - x1 + x2 - x3;\r\n\t\tvar dy1 = y1 - y2;\r\n\t\tvar denominator = dx1 * dy2 - dx2 * dy1;\r\n\t\tvar a13 = (dx3 * dy2 - dx2 * dy3) / denominator;\r\n\t\tvar a23 = (dx1 * dy3 - dx3 * dy1) / denominator;\r\n\t\treturn new PerspectiveTransform(x1 - x0 + a13 * x1, x3 - x0 + a23 * x3, x0, y1 - y0 + a13 * y1, y3 - y0 + a23 * y3, y0, a13, a23, 1.0);\r\n\t}\r\n}\r\n\r\nPerspectiveTransform.quadrilateralToSquare=function( x0, y0, x1, y1, x2, y2, x3, y3)\r\n{\r\n\t// Here, the adjoint serves as the inverse:\r\n\treturn PerspectiveTransform.squareToQuadrilateral(x0, y0, x1, y1, x2, y2, x3, y3).buildAdjoint();\r\n}\r\n\r\nfunction DetectorResult(bits, points)\r\n{\r\n\tthis.bits = bits;\r\n\tthis.points = points;\r\n}\r\n\r\n\r\nfunction Detector(image)\r\n{\r\n\tthis.image=image;\r\n\tthis.resultPointCallback = null;\r\n\t\r\n\tthis.sizeOfBlackWhiteBlackRun=function( fromX, fromY, toX, toY)\r\n\t\t{\r\n\t\t\t// Mild variant of Bresenham's algorithm;\r\n\t\t\t// see http://en.wikipedia.org/wiki/Bresenham's_line_algorithm\r\n\t\t\tvar steep = Math.abs(toY - fromY) > Math.abs(toX - fromX);\r\n\t\t\tif (steep)\r\n\t\t\t{\r\n\t\t\t\tvar temp = fromX;\r\n\t\t\t\tfromX = fromY;\r\n\t\t\t\tfromY = temp;\r\n\t\t\t\ttemp = toX;\r\n\t\t\t\ttoX = toY;\r\n\t\t\t\ttoY = temp;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvar dx = Math.abs(toX - fromX);\r\n\t\t\tvar dy = Math.abs(toY - fromY);\r\n\t\t\tvar error = - dx >> 1;\r\n\t\t\tvar ystep = fromY < toY?1:- 1;\r\n\t\t\tvar xstep = fromX < toX?1:- 1;\r\n\t\t\tvar state = 0; // In black pixels, looking for white, first or second time\r\n\t\t\tfor (var x = fromX, y = fromY; x != toX; x += xstep)\r\n\t\t\t{\r\n\t\t\t\t\r\n\t\t\t\tvar realX = steep?y:x;\r\n\t\t\t\tvar realY = steep?x:y;\r\n\t\t\t\tif (state == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\t// In white pixels, looking for black\r\n\t\t\t\t\tif (this.image[realX + realY*qrcode.width])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tstate++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tif (!this.image[realX + realY*qrcode.width])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tstate++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\tif (state == 3)\r\n\t\t\t\t{\r\n\t\t\t\t\t// Found black, white, black, and stumbled back onto white; done\r\n\t\t\t\t\tvar diffX = x - fromX;\r\n\t\t\t\t\tvar diffY = y - fromY;\r\n\t\t\t\t\treturn Math.sqrt( (diffX * diffX + diffY * diffY));\r\n\t\t\t\t}\r\n\t\t\t\terror += dy;\r\n\t\t\t\tif (error > 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (y == toY)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\ty += ystep;\r\n\t\t\t\t\terror -= dx;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tvar diffX2 = toX - fromX;\r\n\t\t\tvar diffY2 = toY - fromY;\r\n\t\t\treturn Math.sqrt( (diffX2 * diffX2 + diffY2 * diffY2));\r\n\t\t}\r\n\r\n\t\r\n\tthis.sizeOfBlackWhiteBlackRunBothWays=function( fromX, fromY, toX, toY)\r\n\t\t{\r\n\t\t\t\r\n\t\t\tvar result = this.sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY);\r\n\t\t\t\r\n\t\t\t// Now count other way -- don't run off image though of course\r\n\t\t\tvar scale = 1.0;\r\n\t\t\tvar otherToX = fromX - (toX - fromX);\r\n\t\t\tif (otherToX < 0)\r\n\t\t\t{\r\n\t\t\t\tscale = fromX / (fromX - otherToX);\r\n\t\t\t\totherToX = 0;\r\n\t\t\t}\r\n\t\t\telse if (otherToX >= qrcode.width)\r\n\t\t\t{\r\n\t\t\t\tscale = (qrcode.width - 1 - fromX) / (otherToX - fromX);\r\n\t\t\t\totherToX = qrcode.width - 1;\r\n\t\t\t}\r\n\t\t\tvar otherToY = Math.floor (fromY - (toY - fromY) * scale);\r\n\t\t\t\r\n\t\t\tscale = 1.0;\r\n\t\t\tif (otherToY < 0)\r\n\t\t\t{\r\n\t\t\t\tscale = fromY / (fromY - otherToY);\r\n\t\t\t\totherToY = 0;\r\n\t\t\t}\r\n\t\t\telse if (otherToY >= qrcode.height)\r\n\t\t\t{\r\n\t\t\t\tscale = (qrcode.height - 1 - fromY) / (otherToY - fromY);\r\n\t\t\t\totherToY = qrcode.height - 1;\r\n\t\t\t}\r\n\t\t\totherToX = Math.floor (fromX + (otherToX - fromX) * scale);\r\n\t\t\t\r\n\t\t\tresult += this.sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY);\r\n\t\t\treturn result - 1.0; // -1 because we counted the middle pixel twice\r\n\t\t}\r\n\t\t\r\n\r\n\t\r\n\tthis.calculateModuleSizeOneWay=function( pattern, otherPattern)\r\n\t\t{\r\n\t\t\tvar moduleSizeEst1 = this.sizeOfBlackWhiteBlackRunBothWays(Math.floor( pattern.getX()), Math.floor( pattern.getY()), Math.floor( otherPattern.getX()), Math.floor(otherPattern.getY()));\r\n\t\t\tvar moduleSizeEst2 = this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(otherPattern.getX()), Math.floor(otherPattern.getY()), Math.floor( pattern.getX()), Math.floor(pattern.getY()));\r\n\t\t\tif (isNaN(moduleSizeEst1))\r\n\t\t\t{\r\n\t\t\t\treturn moduleSizeEst2 / 7.0;\r\n\t\t\t}\r\n\t\t\tif (isNaN(moduleSizeEst2))\r\n\t\t\t{\r\n\t\t\t\treturn moduleSizeEst1 / 7.0;\r\n\t\t\t}\r\n\t\t\t// Average them, and divide by 7 since we've counted the width of 3 black modules,\r\n\t\t\t// and 1 white and 1 black module on either side. Ergo, divide sum by 14.\r\n\t\t\treturn (moduleSizeEst1 + moduleSizeEst2) / 14.0;\r\n\t\t}\r\n\r\n\t\r\n\tthis.calculateModuleSize=function( topLeft, topRight, bottomLeft)\r\n\t\t{\r\n\t\t\t// Take the average\r\n\t\t\treturn (this.calculateModuleSizeOneWay(topLeft, topRight) + this.calculateModuleSizeOneWay(topLeft, bottomLeft)) / 2.0;\r\n\t\t}\r\n\r\n\tthis.distance=function( pattern1, pattern2)\r\n\t{\r\n\t\tvar xDiff = pattern1.getX() - pattern2.getX();\r\n\t\tvar yDiff = pattern1.getY() - pattern2.getY();\r\n\t\treturn Math.sqrt( (xDiff * xDiff + yDiff * yDiff));\r\n\t}\r\n\tthis.computeDimension=function( topLeft, topRight, bottomLeft, moduleSize)\r\n\t\t{\r\n\t\t\t\r\n\t\t\tvar tltrCentersDimension = Math.round(this.distance(topLeft, topRight) / moduleSize);\r\n\t\t\tvar tlblCentersDimension = Math.round(this.distance(topLeft, bottomLeft) / moduleSize);\r\n\t\t\tvar dimension = ((tltrCentersDimension + tlblCentersDimension) >> 1) + 7;\r\n\t\t\tswitch (dimension & 0x03)\r\n\t\t\t{\r\n\t\t\t\t\r\n\t\t\t\t// mod 4\r\n\t\t\t\tcase 0: \r\n\t\t\t\t\tdimension++;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\t// 1? do nothing\r\n\t\t\t\t\r\n\t\t\t\tcase 2: \r\n\t\t\t\t\tdimension--;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\r\n\t\t\t\tcase 3: \r\n\t\t\t\t\tthrow new Error(\"QR Error: in detector\");\r\n\t\t\t\t}\r\n\t\t\treturn dimension;\r\n\t\t}\r\n\r\n\tthis.findAlignmentInRegion=function( overallEstModuleSize, estAlignmentX, estAlignmentY, allowanceFactor)\r\n\t\t{\r\n\t\t\t// Look for an alignment pattern (3 modules in size) around where it\r\n\t\t\t// should be\r\n\t\t\tvar allowance = Math.floor (allowanceFactor * overallEstModuleSize);\r\n\t\t\tvar alignmentAreaLeftX = Math.max(0, estAlignmentX - allowance);\r\n\t\t\tvar alignmentAreaRightX = Math.min(qrcode.width - 1, estAlignmentX + allowance);\r\n\t\t\tif (alignmentAreaRightX - alignmentAreaLeftX < overallEstModuleSize * 3)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(\"QR Error: in detector\");\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvar alignmentAreaTopY = Math.max(0, estAlignmentY - allowance);\r\n\t\t\tvar alignmentAreaBottomY = Math.min(qrcode.height - 1, estAlignmentY + allowance);\r\n\t\t\t\r\n\t\t\tvar alignmentFinder = new AlignmentPatternFinder(this.image, alignmentAreaLeftX, alignmentAreaTopY, alignmentAreaRightX - alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize, this.resultPointCallback);\r\n\t\t\treturn alignmentFinder.find();\r\n\t\t}\r\n\t\t\r\n\tthis.createTransform=function( topLeft, topRight, bottomLeft, alignmentPattern, dimension)\r\n\t\t{\r\n\t\t\tvar dimMinusThree = dimension - 3.5;\r\n\t\t\tvar bottomRightX;\r\n\t\t\tvar bottomRightY;\r\n\t\t\tvar sourceBottomRightX;\r\n\t\t\tvar sourceBottomRightY;\r\n\t\t\tif (alignmentPattern != null)\r\n\t\t\t{\r\n\t\t\t\tbottomRightX = alignmentPattern.getX();\r\n\t\t\t\tbottomRightY = alignmentPattern.getY();\r\n\t\t\t\tsourceBottomRightX = sourceBottomRightY = dimMinusThree - 3.0;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t// Don't have an alignment pattern, just make up the bottom-right point\r\n\t\t\t\tbottomRightX = (topRight.getX() - topLeft.getX()) + bottomLeft.getX();\r\n\t\t\t\tbottomRightY = (topRight.getY() - topLeft.getY()) + bottomLeft.getY();\r\n\t\t\t\tsourceBottomRightX = sourceBottomRightY = dimMinusThree;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvar transform = PerspectiveTransform.quadrilateralToQuadrilateral(3.5, 3.5, dimMinusThree, 3.5, sourceBottomRightX, sourceBottomRightY, 3.5, dimMinusThree, topLeft.getX(), topLeft.getY(), topRight.getX(), topRight.getY(), bottomRightX, bottomRightY, bottomLeft.getX(), bottomLeft.getY());\r\n\t\t\t\r\n\t\t\treturn transform;\r\n\t\t}\t\t\r\n\t\r\n\tthis.sampleGrid=function( image, transform, dimension)\r\n\t\t{\r\n\t\t\t\r\n\t\t\tvar sampler = GridSampler;\r\n\t\t\treturn sampler.sampleGrid3(image, dimension, transform);\r\n\t\t}\r\n\t\r\n\tthis.processFinderPatternInfo = function( info)\r\n\t\t{\r\n\t\t\t\r\n\t\t\tvar topLeft = info.getTopLeft();\r\n\t\t\tvar topRight = info.getTopRight();\r\n\t\t\tvar bottomLeft = info.getBottomLeft();\r\n\t\t\t\r\n\t\t\tvar moduleSize = this.calculateModuleSize(topLeft, topRight, bottomLeft);\r\n\t\t\tif (moduleSize < 1.0)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(\"QR Error: in detector\");\r\n\t\t\t}\r\n\t\t\tvar dimension = this.computeDimension(topLeft, topRight, bottomLeft, moduleSize);\r\n\t\t\tvar provisionalVersion = Version.getProvisionalVersionForDimension(dimension);\r\n\t\t\tvar modulesBetweenFPCenters = provisionalVersion.getDimensionForVersion() - 7;\r\n\t\t\t\r\n\t\t\tvar alignmentPattern = null;\r\n\t\t\t// Anything above version 1 has an alignment pattern\r\n\t\t\tif (provisionalVersion.getAlignmentPatternCenters().length > 0)\r\n\t\t\t{\r\n\t\t\t\t\r\n\t\t\t\t// Guess where a \"bottom right\" finder pattern would have been\r\n\t\t\t\tvar bottomRightX = topRight.getX() - topLeft.getX() + bottomLeft.getX();\r\n\t\t\t\tvar bottomRightY = topRight.getY() - topLeft.getY() + bottomLeft.getY();\r\n\t\t\t\t\r\n\t\t\t\t// Estimate that alignment pattern is closer by 3 modules\r\n\t\t\t\t// from \"bottom right\" to known top left location\r\n\t\t\t\tvar correctionToTopLeft = 1.0 - 3.0 / modulesBetweenFPCenters;\r\n\t\t\t\tvar estAlignmentX = Math.floor (topLeft.getX() + correctionToTopLeft * (bottomRightX - topLeft.getX()));\r\n\t\t\t\tvar estAlignmentY = Math.floor (topLeft.getY() + correctionToTopLeft * (bottomRightY - topLeft.getY()));\r\n\t\t\t\t\r\n\t\t\t\t// Kind of arbitrary -- expand search radius before giving up\r\n\t\t\t\tfor (var i = 4; i <= 16; i <<= 1)\r\n\t\t\t\t{\r\n\t\t\t\t\ttry\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\talignmentPattern = this.findAlignmentInRegion(moduleSize, estAlignmentX, estAlignmentY, i);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcatch (re)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// try next round\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t// If we didn't find alignment pattern... well try anyway without it\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvar transform = this.createTransform(topLeft, topRight, bottomLeft, alignmentPattern, dimension);\r\n\t\t\t\r\n\t\t\tvar bits = this.sampleGrid(this.image, transform, dimension);\r\n\t\t\t\r\n\t\t\tvar points;\r\n\t\t\tif (alignmentPattern == null)\r\n\t\t\t{\r\n\t\t\t\tpoints = new Array(bottomLeft, topLeft, topRight);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tpoints = new Array(bottomLeft, topLeft, topRight, alignmentPattern);\r\n\t\t\t}\r\n\t\t\treturn new DetectorResult(bits, points);\r\n\t\t}\r\n\t\t\r\n\r\n\t\r\n\tthis.detect=function()\r\n\t{\r\n\t\tvar info = new FinderPatternFinder().findFinderPattern(this.image);\r\n\t\t\t\r\n\t\treturn this.processFinderPatternInfo(info); \r\n\t}\r\n}","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nvar GridSampler = {};\r\n\r\nGridSampler.checkAndNudgePoints=function( image, points)\r\n\t\t{\r\n\t\t\tvar width = qrcode.width;\r\n\t\t\tvar height = qrcode.height;\r\n\t\t\t// Check and nudge points from start until we see some that are OK:\r\n\t\t\tvar nudged = true;\r\n\t\t\tfor (var offset = 0; offset < points.length && nudged; offset += 2)\r\n\t\t\t{\r\n\t\t\t\tvar x = Math.floor (points[offset]);\r\n\t\t\t\tvar y = Math.floor( points[offset + 1]);\r\n\t\t\t\tif (x < - 1 || x > width || y < - 1 || y > height)\r\n\t\t\t\t{\r\n\t\t\t\t\tthrow new Error(\"QR Error: Error.checkAndNudgePoints\");\r\n\t\t\t\t}\r\n\t\t\t\tnudged = false;\r\n\t\t\t\tif (x == - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tpoints[offset] = 0.0;\r\n\t\t\t\t\tnudged = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if (x == width)\r\n\t\t\t\t{\r\n\t\t\t\t\tpoints[offset] = width - 1;\r\n\t\t\t\t\tnudged = true;\r\n\t\t\t\t}\r\n\t\t\t\tif (y == - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tpoints[offset + 1] = 0.0;\r\n\t\t\t\t\tnudged = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if (y == height)\r\n\t\t\t\t{\r\n\t\t\t\t\tpoints[offset + 1] = height - 1;\r\n\t\t\t\t\tnudged = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t// Check and nudge points from end:\r\n\t\t\tnudged = true;\r\n\t\t\tfor (var offset = points.length - 2; offset >= 0 && nudged; offset -= 2)\r\n\t\t\t{\r\n\t\t\t\tvar x = Math.floor( points[offset]);\r\n\t\t\t\tvar y = Math.floor( points[offset + 1]);\r\n\t\t\t\tif (x < - 1 || x > width || y < - 1 || y > height)\r\n\t\t\t\t{\r\n\t\t\t\t\tthrow new Error(\"QR Error: Error.checkAndNudgePoints\");\r\n\t\t\t\t}\r\n\t\t\t\tnudged = false;\r\n\t\t\t\tif (x == - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tpoints[offset] = 0.0;\r\n\t\t\t\t\tnudged = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if (x == width)\r\n\t\t\t\t{\r\n\t\t\t\t\tpoints[offset] = width - 1;\r\n\t\t\t\t\tnudged = true;\r\n\t\t\t\t}\r\n\t\t\t\tif (y == - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tpoints[offset + 1] = 0.0;\r\n\t\t\t\t\tnudged = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if (y == height)\r\n\t\t\t\t{\r\n\t\t\t\t\tpoints[offset + 1] = height - 1;\r\n\t\t\t\t\tnudged = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\r\n\r\n\r\nGridSampler.sampleGrid3=function( image, dimension, transform)\r\n\t\t{\r\n\t\t\tvar bits = new BitMatrix(dimension);\r\n\t\t\tvar points = new Array(dimension << 1);\r\n\t\t\tfor (var y = 0; y < dimension; y++)\r\n\t\t\t{\r\n\t\t\t\tvar max = points.length;\r\n\t\t\t\tvar iValue = y + 0.5;\r\n\t\t\t\tfor (var x = 0; x < max; x += 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tpoints[x] = (x >> 1) + 0.5;\r\n\t\t\t\t\tpoints[x + 1] = iValue;\r\n\t\t\t\t}\r\n\t\t\t\ttransform.transformPoints1(points);\r\n\t\t\t\t// Quick check to see if points transformed to something inside the image;\r\n\t\t\t\t// sufficient to check the endpoints\r\n\t\t\t\tGridSampler.checkAndNudgePoints(image, points);\r\n\t\t\t\ttry\r\n\t\t\t\t{\r\n\t\t\t\t\tfor (var x = 0; x < max; x += 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t//var xpoint = (Math.floor( points[x]) * 4) + (Math.floor( points[x + 1]) * qrcode.width * 4);\r\n var bit = image[Math.floor( points[x])+ qrcode.width* Math.floor( points[x + 1])];\r\n\t\t\t\t\t\t//qrcode.imagedata.data[xpoint] = bit?255:0;\r\n\t\t\t\t\t\t//qrcode.imagedata.data[xpoint+1] = bit?255:0;\r\n\t\t\t\t\t\t//qrcode.imagedata.data[xpoint+2] = 0;\r\n\t\t\t\t\t\t//qrcode.imagedata.data[xpoint+3] = 255;\r\n\t\t\t\t\t\t//bits[x >> 1][ y]=bit;\r\n\t\t\t\t\t\tif(bit)\r\n\t\t\t\t\t\t\tbits.set_Renamed(x >> 1, y);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tcatch ( aioobe)\r\n\t\t\t\t{\r\n\t\t\t\t\t// This feels wrong, but, sometimes if the finder patterns are misidentified, the resulting\r\n\t\t\t\t\t// transform gets \"twisted\" such that it maps a straight line of points to a set of points\r\n\t\t\t\t\t// whose endpoints are in bounds, but others are not. There is probably some mathematical\r\n\t\t\t\t\t// way to detect this about the transformation that I don't know yet.\r\n\t\t\t\t\t// This results in an ugly runtime exception despite our clever checks above -- can't have\r\n\t\t\t\t\t// that. We could check each point's coordinates but that feels duplicative. We settle for\r\n\t\t\t\t\t// catching and wrapping ArrayIndexOutOfBoundsException.\r\n\t\t\t\t\tthrow new Error(\"QR Error: Error.checkAndNudgePoints\");\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn bits;\r\n\t\t}\r\n\r\nGridSampler.sampleGridx=function( image, dimension, p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY)\r\n{\r\n\tvar transform = PerspectiveTransform.quadrilateralToQuadrilateral(p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY);\r\n\t\t\t\r\n\treturn GridSampler.sampleGrid3(image, dimension, transform);\r\n}","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nvar MIN_SKIP = 3; // 1 pixel/module times 3 modules/center\r\nvar MAX_MODULES = 57; // support up to version 10 for mobile clients\r\nvar CENTER_QUORUM = 2;\r\n\r\nqrcode.orderBestPatterns=function(patterns)\r\n\t\t{\r\n\t\t\t\r\n\t\t\tfunction distance( pattern1, pattern2)\r\n\t\t\t{\r\n\t\t\t\tvar xDiff = pattern1.getX() - pattern2.getX();\r\n\t\t\t\tvar yDiff = pattern1.getY() - pattern2.getY();\r\n\t\t\t\treturn Math.sqrt( (xDiff * xDiff + yDiff * yDiff));\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t/// Returns the z component of the cross product between vectors BC and BA.\r\n\t\t\tfunction crossProductZ( pointA, pointB, pointC)\r\n\t\t\t{\r\n\t\t\t\tvar bX = pointB.x;\r\n\t\t\t\tvar bY = pointB.y;\r\n\t\t\t\treturn ((pointC.x - bX) * (pointA.y - bY)) - ((pointC.y - bY) * (pointA.x - bX));\r\n\t\t\t}\r\n\r\n\t\t\t\r\n\t\t\t// Find distances between pattern centers\r\n\t\t\tvar zeroOneDistance = distance(patterns[0], patterns[1]);\r\n\t\t\tvar oneTwoDistance = distance(patterns[1], patterns[2]);\r\n\t\t\tvar zeroTwoDistance = distance(patterns[0], patterns[2]);\r\n\t\t\t\r\n\t\t\tvar pointA, pointB, pointC;\r\n\t\t\t// Assume one closest to other two is B; A and C will just be guesses at first\r\n\t\t\tif (oneTwoDistance >= zeroOneDistance && oneTwoDistance >= zeroTwoDistance)\r\n\t\t\t{\r\n\t\t\t\tpointB = patterns[0];\r\n\t\t\t\tpointA = patterns[1];\r\n\t\t\t\tpointC = patterns[2];\r\n\t\t\t}\r\n\t\t\telse if (zeroTwoDistance >= oneTwoDistance && zeroTwoDistance >= zeroOneDistance)\r\n\t\t\t{\r\n\t\t\t\tpointB = patterns[1];\r\n\t\t\t\tpointA = patterns[0];\r\n\t\t\t\tpointC = patterns[2];\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tpointB = patterns[2];\r\n\t\t\t\tpointA = patterns[0];\r\n\t\t\t\tpointC = patterns[1];\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Use cross product to figure out whether A and C are correct or flipped.\r\n\t\t\t// This asks whether BC x BA has a positive z component, which is the arrangement\r\n\t\t\t// we want for A, B, C. If it's negative, then we've got it flipped around and\r\n\t\t\t// should swap A and C.\r\n\t\t\tif (crossProductZ(pointA, pointB, pointC) < 0.0)\r\n\t\t\t{\r\n\t\t\t\tvar temp = pointA;\r\n\t\t\t\tpointA = pointC;\r\n\t\t\t\tpointC = temp;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpatterns[0] = pointA;\r\n\t\t\tpatterns[1] = pointB;\r\n\t\t\tpatterns[2] = pointC;\r\n\t\t}\r\n\r\n\r\nfunction FinderPattern(posX, posY, estimatedModuleSize)\r\n{\r\n\tthis.x=posX;\r\n\tthis.y=posY;\r\n\tthis.count = 1;\r\n\tthis.estimatedModuleSize = estimatedModuleSize;\r\n\t\r\n\tthis.getEstimatedModuleSize = function()\r\n\t{\r\n\t\treturn this.estimatedModuleSize;\r\n\t};\r\n\tthis.getCount = function()\r\n\t{\r\n\t\treturn this.count;\r\n\t};\r\n\tthis.getX = function()\r\n\t{\r\n\t\treturn this.x;\r\n\t};\r\n\tthis.getY = function()\r\n\t{\r\n\t\treturn this.y;\r\n\t};\r\n\tthis.incrementCount = function()\r\n\t{\r\n\t\tthis.count++;\r\n\t}\r\n\tthis.aboutEquals=function( moduleSize, i, j)\r\n\t\t{\r\n\t\t\tif (Math.abs(i - this.y) <= moduleSize && Math.abs(j - this.x) <= moduleSize)\r\n\t\t\t{\r\n\t\t\t\tvar moduleSizeDiff = Math.abs(moduleSize - this.estimatedModuleSize);\r\n\t\t\t\treturn moduleSizeDiff <= 1.0 || moduleSizeDiff / this.estimatedModuleSize <= 1.0;\r\n\t\t\t}\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\r\n}\r\n\r\nfunction FinderPatternInfo(patternCenters)\r\n{\r\n\tthis.bottomLeft = patternCenters[0];\r\n\tthis.topLeft = patternCenters[1];\r\n\tthis.topRight = patternCenters[2];\r\n\tthis.getBottomLeft = function()\r\n\t{\r\n\t\treturn this.bottomLeft;\r\n\t};\r\n\tthis.getTopLeft = function()\r\n\t{\r\n\t\treturn this.topLeft;\r\n\t};\r\n\tthis.getTopRight = function()\r\n\t{\r\n\t\treturn this.topRight;\r\n\t};\r\n}\r\n\r\n/**\r\n * Finds a finder pattern. A finder pattern is one of the patterns in the corners\r\n * of the QR codes. The patterns consist of black and white squares of specific proportions.\r\n * If you consider a line through the pattern, the color changes proportionally between white and black:\r\n * 1 - 1 - 3 - 1 - 1\r\n * black - white - black - white - black\r\n */\r\nfunction FinderPatternFinder()\r\n{\r\n\tthis.image=null;\r\n\tthis.possibleCenters = [];\r\n\tthis.hasSkipped = false;\r\n\tthis.crossCheckStateCount = new Array(0,0,0,0,0);\r\n\tthis.resultPointCallback = null;\r\n\t\r\n\tthis.getCrossCheckStateCount = function()\r\n\t{\r\n\t\tthis.crossCheckStateCount[0] = 0;\r\n\t\tthis.crossCheckStateCount[1] = 0;\r\n\t\tthis.crossCheckStateCount[2] = 0;\r\n\t\tthis.crossCheckStateCount[3] = 0;\r\n\t\tthis.crossCheckStateCount[4] = 0;\r\n\t\treturn this.crossCheckStateCount;\r\n\t};\r\n\t\r\n\tthis.foundPatternCross=function( stateCount)\r\n\t\t{\r\n\t\t\tvar totalModuleSize = 0;\r\n\t\t\tfor (var i = 0; i < 5; i++)\r\n\t\t\t{\r\n\t\t\t\tvar count = stateCount[i];\r\n\t\t\t\tif (count == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\ttotalModuleSize += count;\r\n\t\t\t}\r\n\t\t\tif (totalModuleSize < 7)\r\n\t\t\t{\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\tvar moduleSize = Math.floor(totalModuleSize / 7);\r\n\t\t\tvar maxVariance = Math.floor(moduleSize * 0.7);\r\n\t\t\t// Allow less than 70% variance from 1-1-3-1-1 proportions\r\n\t\t\treturn Math.abs(moduleSize - stateCount[0]) < maxVariance\r\n\t\t\t\t&& Math.abs(moduleSize - stateCount[1]) < maxVariance\r\n\t\t\t\t&& Math.abs(3 * moduleSize - stateCount[2]) < 3 * maxVariance\r\n\t\t\t\t&& Math.abs(moduleSize - stateCount[3]) < maxVariance\r\n\t\t\t\t&& Math.abs(moduleSize - stateCount[4]) < maxVariance;\r\n\t\t}\r\n\tthis.centerFromEnd=function( stateCount, end)\r\n\t\t{\r\n\t\t\treturn (end - stateCount[4] - stateCount[3]) - stateCount[2] / 2.0;\r\n\t\t}\r\n\tthis.crossCheckVertical=function( startI, centerJ, maxCount, originalStateCountTotal)\r\n\t\t{\r\n\t\t\tvar image = this.image;\r\n\t\t\t\r\n\t\t\tvar maxI = qrcode.height;\r\n\t\t\tvar stateCount = this.getCrossCheckStateCount();\r\n\t\t\t\r\n\t\t\t// Start counting up from center\r\n\t\t\tvar i = startI;\r\n\t\t\twhile (i >= 0 && image[centerJ + i*qrcode.width])\r\n\t\t\t{\r\n\t\t\t\tstateCount[2]++;\r\n\t\t\t\ti--;\r\n\t\t\t}\r\n\t\t\tif (i < 0)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (i >= 0 && !image[centerJ +i*qrcode.width] && stateCount[1] <= maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[1]++;\r\n\t\t\t\ti--;\r\n\t\t\t}\r\n\t\t\t// If already too many modules in this state or ran off the edge:\r\n\t\t\tif (i < 0 || stateCount[1] > maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (i >= 0 && image[centerJ + i*qrcode.width] && stateCount[0] <= maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[0]++;\r\n\t\t\t\ti--;\r\n\t\t\t}\r\n\t\t\tif (stateCount[0] > maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Now also count down from center\r\n\t\t\ti = startI + 1;\r\n\t\t\twhile (i < maxI && image[centerJ +i*qrcode.width])\r\n\t\t\t{\r\n\t\t\t\tstateCount[2]++;\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t\tif (i == maxI)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (i < maxI && !image[centerJ + i*qrcode.width] && stateCount[3] < maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[3]++;\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t\tif (i == maxI || stateCount[3] >= maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (i < maxI && image[centerJ + i*qrcode.width] && stateCount[4] < maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[4]++;\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t\tif (stateCount[4] >= maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// If we found a finder-pattern-like section, but its size is more than 40% different than\r\n\t\t\t// the original, assume it's a false positive\r\n\t\t\tvar stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];\r\n\t\t\tif (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\treturn this.foundPatternCross(stateCount)?this.centerFromEnd(stateCount, i):NaN;\r\n\t\t}\r\n\tthis.crossCheckHorizontal=function( startJ, centerI, maxCount, originalStateCountTotal)\r\n\t\t{\r\n\t\t\tvar image = this.image;\r\n\t\t\t\r\n\t\t\tvar maxJ = qrcode.width;\r\n\t\t\tvar stateCount = this.getCrossCheckStateCount();\r\n\t\t\t\r\n\t\t\tvar j = startJ;\r\n\t\t\twhile (j >= 0 && image[j+ centerI*qrcode.width])\r\n\t\t\t{\r\n\t\t\t\tstateCount[2]++;\r\n\t\t\t\tj--;\r\n\t\t\t}\r\n\t\t\tif (j < 0)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (j >= 0 && !image[j+ centerI*qrcode.width] && stateCount[1] <= maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[1]++;\r\n\t\t\t\tj--;\r\n\t\t\t}\r\n\t\t\tif (j < 0 || stateCount[1] > maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (j >= 0 && image[j+ centerI*qrcode.width] && stateCount[0] <= maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[0]++;\r\n\t\t\t\tj--;\r\n\t\t\t}\r\n\t\t\tif (stateCount[0] > maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tj = startJ + 1;\r\n\t\t\twhile (j < maxJ && image[j+ centerI*qrcode.width])\r\n\t\t\t{\r\n\t\t\t\tstateCount[2]++;\r\n\t\t\t\tj++;\r\n\t\t\t}\r\n\t\t\tif (j == maxJ)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (j < maxJ && !image[j+ centerI*qrcode.width] && stateCount[3] < maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[3]++;\r\n\t\t\t\tj++;\r\n\t\t\t}\r\n\t\t\tif (j == maxJ || stateCount[3] >= maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (j < maxJ && image[j+ centerI*qrcode.width] && stateCount[4] < maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[4]++;\r\n\t\t\t\tj++;\r\n\t\t\t}\r\n\t\t\tif (stateCount[4] >= maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// If we found a finder-pattern-like section, but its size is significantly different than\r\n\t\t\t// the original, assume it's a false positive\r\n\t\t\tvar stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];\r\n\t\t\tif (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= originalStateCountTotal)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\treturn this.foundPatternCross(stateCount)?this.centerFromEnd(stateCount, j):NaN;\r\n\t\t}\r\n\tthis.handlePossibleCenter=function( stateCount, i, j)\r\n\t\t{\r\n\t\t\tvar stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];\r\n\t\t\tvar centerJ = this.centerFromEnd(stateCount, j); //float\r\n\t\t\tvar centerI = this.crossCheckVertical(i, Math.floor( centerJ), stateCount[2], stateCountTotal); //float\r\n\t\t\tif (!isNaN(centerI))\r\n\t\t\t{\r\n\t\t\t\t// Re-cross check\r\n\t\t\t\tcenterJ = this.crossCheckHorizontal(Math.floor( centerJ), Math.floor( centerI), stateCount[2], stateCountTotal);\r\n\t\t\t\tif (!isNaN(centerJ))\r\n\t\t\t\t{\r\n\t\t\t\t\tvar estimatedModuleSize = stateCountTotal / 7.0;\r\n\t\t\t\t\tvar found = false;\r\n\t\t\t\t\tvar max = this.possibleCenters.length;\r\n\t\t\t\t\tfor (var index = 0; index < max; index++)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tvar center = this.possibleCenters[index];\r\n\t\t\t\t\t\t// Look for about the same center and module size:\r\n\t\t\t\t\t\tif (center.aboutEquals(estimatedModuleSize, centerI, centerJ))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tcenter.incrementCount();\r\n\t\t\t\t\t\t\tfound = true;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (!found)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tvar point = new FinderPattern(centerJ, centerI, estimatedModuleSize);\r\n\t\t\t\t\t\tthis.possibleCenters.push(point);\r\n\t\t\t\t\t\tif (this.resultPointCallback != null)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tthis.resultPointCallback.foundPossibleResultPoint(point);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\t\r\n\tthis.selectBestPatterns=function()\r\n\t\t{\r\n\t\t\t\r\n\t\t\tvar startSize = this.possibleCenters.length;\r\n\t\t\tif (startSize < 3)\r\n\t\t\t{\r\n\t\t\t\t// Couldn't find enough finder patterns\r\n\t\t\t\tthrow new Error(\"QR Error: Couldn't find enough finder patterns (found \" + startSize + \")\");\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Filter outlier possibilities whose module size is too different\r\n\t\t\tif (startSize > 3)\r\n\t\t\t{\r\n\t\t\t\t// But we can only afford to do so if we have at least 4 possibilities to choose from\r\n\t\t\t\tvar totalModuleSize = 0.0;\r\n var square = 0.0;\r\n\t\t\t\tfor (var i = 0; i < startSize; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\t//totalModuleSize += this.possibleCenters[i].getEstimatedModuleSize();\r\n var\tcenterValue=this.possibleCenters[i].getEstimatedModuleSize();\r\n\t\t\t\t\ttotalModuleSize += centerValue;\r\n\t\t\t\t\tsquare += (centerValue * centerValue);\r\n\t\t\t\t}\r\n\t\t\t\tvar average = totalModuleSize / startSize;\r\n this.possibleCenters.sort(function(center1,center2) {\r\n\t\t\t\t var dA=Math.abs(center2.getEstimatedModuleSize() - average);\r\n\t\t\t\t var dB=Math.abs(center1.getEstimatedModuleSize() - average);\r\n\t\t\t\t if (dA < dB) {\r\n\t\t\t\t \t return (-1);\r\n\t\t\t\t } else if (dA == dB) {\r\n\t\t\t\t \t return 0;\r\n\t\t\t\t } else {\r\n\t\t\t\t \t return 1;\r\n\t\t\t\t }\r\n\t\t\t\t\t});\r\n\r\n\t\t\t\tvar stdDev = Math.sqrt(square / startSize - average * average);\r\n\t\t\t\tvar limit = Math.max(0.2 * average, stdDev);\r\n\t\t\t\t//for (var i = 0; i < this.possibleCenters.length && this.possibleCenters.length > 3; i++)\r\n\t\t\t\tfor (var i = this.possibleCenters.length - 1; i >= 0 ; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tvar pattern = this.possibleCenters[i];\r\n\t\t\t\t\t//if (Math.abs(pattern.getEstimatedModuleSize() - average) > 0.2 * average)\r\n if (Math.abs(pattern.getEstimatedModuleSize() - average) > limit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t//this.possibleCenters.remove(i);\r\n\t\t\t\t\t\tthis.possibleCenters.splice(i,1);\r\n\t\t\t\t\t\t//i--;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif (this.possibleCenters.length > 3)\r\n\t\t\t{\r\n\t\t\t\t// Throw away all but those first size candidate points we found.\r\n\t\t\t\tthis.possibleCenters.sort(function(a, b){\r\n\t\t\t\t\tif (a.count > b.count){return -1;}\r\n\t\t\t\t\tif (a.count < b.count){return 1;}\r\n\t\t\t\t\treturn 0;\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\treturn new Array( this.possibleCenters[0], this.possibleCenters[1], this.possibleCenters[2]);\r\n\t\t}\r\n\t\t\r\n\tthis.findRowSkip=function()\r\n\t\t{\r\n\t\t\tvar max = this.possibleCenters.length;\r\n\t\t\tif (max <= 1)\r\n\t\t\t{\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t\tvar firstConfirmedCenter = null;\r\n\t\t\tfor (var i = 0; i < max; i++)\r\n\t\t\t{\r\n\t\t\t\tvar center = this.possibleCenters[i];\r\n\t\t\t\tif (center.getCount() >= CENTER_QUORUM)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (firstConfirmedCenter == null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfirstConfirmedCenter = center;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// We have two confirmed centers\r\n\t\t\t\t\t\t// How far down can we skip before resuming looking for the next\r\n\t\t\t\t\t\t// pattern? In the worst case, only the difference between the\r\n\t\t\t\t\t\t// difference in the x / y coordinates of the two centers.\r\n\t\t\t\t\t\t// This is the case where you find top left last.\r\n\t\t\t\t\t\tthis.hasSkipped = true;\r\n\t\t\t\t\t\treturn Math.floor ((Math.abs(firstConfirmedCenter.getX() - center.getX()) - Math.abs(firstConfirmedCenter.getY() - center.getY())) / 2);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\r\n\tthis.haveMultiplyConfirmedCenters=function()\r\n\t\t{\r\n\t\t\tvar confirmedCount = 0;\r\n\t\t\tvar totalModuleSize = 0.0;\r\n\t\t\tvar max = this.possibleCenters.length;\r\n\t\t\tfor (var i = 0; i < max; i++)\r\n\t\t\t{\r\n\t\t\t\tvar pattern = this.possibleCenters[i];\r\n\t\t\t\tif (pattern.getCount() >= CENTER_QUORUM)\r\n\t\t\t\t{\r\n\t\t\t\t\tconfirmedCount++;\r\n\t\t\t\t\ttotalModuleSize += pattern.getEstimatedModuleSize();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (confirmedCount < 3)\r\n\t\t\t{\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\t// OK, we have at least 3 confirmed centers, but, it's possible that one is a \"false positive\"\r\n\t\t\t// and that we need to keep looking. We detect this by asking if the estimated module sizes\r\n\t\t\t// vary too much. We arbitrarily say that when the total deviation from average exceeds\r\n\t\t\t// 5% of the total module size estimates, it's too much.\r\n\t\t\tvar average = totalModuleSize / max;\r\n\t\t\tvar totalDeviation = 0.0;\r\n\t\t\tfor (var i = 0; i < max; i++)\r\n\t\t\t{\r\n\t\t\t\tpattern = this.possibleCenters[i];\r\n\t\t\t\ttotalDeviation += Math.abs(pattern.getEstimatedModuleSize() - average);\r\n\t\t\t}\r\n\t\t\treturn totalDeviation <= 0.05 * totalModuleSize;\r\n\t\t}\r\n\t\t\r\n\tthis.findFinderPattern = function(image){\r\n\t\tvar tryHarder = false;\r\n\t\tthis.image=image;\r\n\t\tvar maxI = qrcode.height;\r\n\t\tvar maxJ = qrcode.width;\r\n // Let's assume that the maximum version QR Code we support takes up 1/4 the height of the\r\n // image, and then account for the center being 3 modules in size. This gives the smallest\r\n // number of pixels the center could be, so skip this often. When trying harder, look for all\r\n // QR versions regardless of how dense they are.\r\n var iSkip = Math.floor((3 * maxI) / (4 * MAX_MODULES));\r\n if (iSkip < MIN_SKIP || tryHarder)\r\n\t\t{\r\n\t\t\t\tiSkip = MIN_SKIP;\r\n\t\t}\r\n\t\t\r\n\t\tvar done = false;\r\n\t\tvar stateCount = new Array(5);\r\n\t\tfor (var i = iSkip - 1; i < maxI && !done; i += iSkip)\r\n\t\t{\r\n\t\t\t// Get a row of black/white values\r\n\t\t\tstateCount[0] = 0;\r\n\t\t\tstateCount[1] = 0;\r\n\t\t\tstateCount[2] = 0;\r\n\t\t\tstateCount[3] = 0;\r\n\t\t\tstateCount[4] = 0;\r\n\t\t\tvar currentState = 0;\r\n\t\t\tfor (var j = 0; j < maxJ; j++)\r\n\t\t\t{\r\n\t\t\t\tif (image[j+i*qrcode.width] )\r\n\t\t\t\t{\r\n\t\t\t\t\t// Black pixel\r\n\t\t\t\t\tif ((currentState & 1) == 1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// Counting white pixels\r\n\t\t\t\t\t\tcurrentState++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tstateCount[currentState]++;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t// White pixel\r\n\t\t\t\t\tif ((currentState & 1) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// Counting black pixels\r\n\t\t\t\t\t\tif (currentState == 4)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t// A winner?\r\n\t\t\t\t\t\t\tif (this.foundPatternCross(stateCount))\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t// Yes\r\n\t\t\t\t\t\t\t\tvar confirmed = this.handlePossibleCenter(stateCount, i, j);\r\n\t\t\t\t\t\t\t\tif (confirmed)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t// Start examining every other line. Checking each line turned out to be too\r\n\t\t\t\t\t\t\t\t\t// expensive and didn't improve performance.\r\n\t\t\t\t\t\t\t\t\tiSkip = 2;\r\n\t\t\t\t\t\t\t\t\tif (this.hasSkipped)\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\tdone = this.haveMultiplyConfirmedCenters();\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\tvar rowSkip = this.findRowSkip();\r\n\t\t\t\t\t\t\t\t\t\tif (rowSkip > stateCount[2])\r\n\t\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\t\t// Skip rows between row of lower confirmed center\r\n\t\t\t\t\t\t\t\t\t\t\t// and top of presumed third confirmed center\r\n\t\t\t\t\t\t\t\t\t\t\t// but back up a bit to get a full chance of detecting\r\n\t\t\t\t\t\t\t\t\t\t\t// it, entire width of center of finder pattern\r\n\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t// Skip by rowSkip, but back off by stateCount[2] (size of last center\r\n\t\t\t\t\t\t\t\t\t\t\t// of pattern we saw) to be conservative, and also back off by iSkip which\r\n\t\t\t\t\t\t\t\t\t\t\t// is about to be re-added\r\n\t\t\t\t\t\t\t\t\t\t\ti += rowSkip - stateCount[2] - iSkip;\r\n\t\t\t\t\t\t\t\t\t\t\tj = maxJ - 1;\r\n\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t// Advance to next black pixel\r\n\t\t\t\t\t\t\t\t\tdo \r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\tj++;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\twhile (j < maxJ && !image[j + i*qrcode.width]);\r\n\t\t\t\t\t\t\t\t\tj--; // back up to that last white pixel\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t// Clear state to start looking again\r\n\t\t\t\t\t\t\t\tcurrentState = 0;\r\n\t\t\t\t\t\t\t\tstateCount[0] = 0;\r\n\t\t\t\t\t\t\t\tstateCount[1] = 0;\r\n\t\t\t\t\t\t\t\tstateCount[2] = 0;\r\n\t\t\t\t\t\t\t\tstateCount[3] = 0;\r\n\t\t\t\t\t\t\t\tstateCount[4] = 0;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t// No, shift counts back by two\r\n\t\t\t\t\t\t\t\tstateCount[0] = stateCount[2];\r\n\t\t\t\t\t\t\t\tstateCount[1] = stateCount[3];\r\n\t\t\t\t\t\t\t\tstateCount[2] = stateCount[4];\r\n\t\t\t\t\t\t\t\tstateCount[3] = 1;\r\n\t\t\t\t\t\t\t\tstateCount[4] = 0;\r\n\t\t\t\t\t\t\t\tcurrentState = 3;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tstateCount[++currentState]++;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// Counting white pixels\r\n\t\t\t\t\t\tstateCount[currentState]++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (this.foundPatternCross(stateCount))\r\n\t\t\t{\r\n\t\t\t\tvar confirmed = this.handlePossibleCenter(stateCount, i, maxJ);\r\n\t\t\t\tif (confirmed)\r\n\t\t\t\t{\r\n\t\t\t\t\tiSkip = stateCount[0];\r\n\t\t\t\t\tif (this.hasSkipped)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// Found a third one\r\n\t\t\t\t\t\tdone = this.haveMultiplyConfirmedCenters();\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tvar patternInfo = this.selectBestPatterns();\r\n\t\tqrcode.orderBestPatterns(patternInfo);\r\n\t\t\r\n\t\treturn new FinderPatternInfo(patternInfo);\r\n\t};\r\n}","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nfunction BitMatrixParser(bitMatrix)\r\n{\r\n\tvar dimension = bitMatrix.getDimension();\r\n\tif (dimension < 21 || (dimension & 0x03) != 1)\r\n\t{\r\n\t\tthrow new Error(\"QR Error: Error BitMatrixParser\");\r\n\t}\r\n\tthis.bitMatrix = bitMatrix;\r\n\tthis.parsedVersion = null;\r\n\tthis.parsedFormatInfo = null;\r\n\t\r\n\tthis.copyBit=function( i, j, versionBits)\r\n\t{\r\n\t\treturn this.bitMatrix.get_Renamed(i, j)?(versionBits << 1) | 0x1:versionBits << 1;\r\n\t}\r\n\t\r\n\tthis.readFormatInformation=function()\r\n\t{\r\n\t\t\tif (this.parsedFormatInfo != null)\r\n\t\t\t{\r\n\t\t\t\treturn this.parsedFormatInfo;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Read top-left format info bits\r\n\t\t\tvar formatInfoBits = 0;\r\n\t\t\tfor (var i = 0; i < 6; i++)\r\n\t\t\t{\r\n\t\t\t\tformatInfoBits = this.copyBit(i, 8, formatInfoBits);\r\n\t\t\t}\r\n\t\t\t// .. and skip a bit in the timing pattern ...\r\n\t\t\tformatInfoBits = this.copyBit(7, 8, formatInfoBits);\r\n\t\t\tformatInfoBits = this.copyBit(8, 8, formatInfoBits);\r\n\t\t\tformatInfoBits = this.copyBit(8, 7, formatInfoBits);\r\n\t\t\t// .. and skip a bit in the timing pattern ...\r\n\t\t\tfor (var j = 5; j >= 0; j--)\r\n\t\t\t{\r\n\t\t\t\tformatInfoBits = this.copyBit(8, j, formatInfoBits);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tthis.parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits);\r\n\t\t\tif (this.parsedFormatInfo != null)\r\n\t\t\t{\r\n\t\t\t\treturn this.parsedFormatInfo;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Hmm, failed. Try the top-right/bottom-left pattern\r\n\t\t\tvar dimension = this.bitMatrix.getDimension();\r\n\t\t\tformatInfoBits = 0;\r\n\t\t\tvar iMin = dimension - 8;\r\n\t\t\tfor (var i = dimension - 1; i >= iMin; i--)\r\n\t\t\t{\r\n\t\t\t\tformatInfoBits = this.copyBit(i, 8, formatInfoBits);\r\n\t\t\t}\r\n\t\t\tfor (var j = dimension - 7; j < dimension; j++)\r\n\t\t\t{\r\n\t\t\t\tformatInfoBits = this.copyBit(8, j, formatInfoBits);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tthis.parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits);\r\n\t\t\tif (this.parsedFormatInfo != null)\r\n\t\t\t{\r\n\t\t\t\treturn this.parsedFormatInfo;\r\n\t\t\t}\r\n\t\t\tthrow new Error(\"QR Error: Error readFormatInformation\");\r\n\t}\r\n\tthis.readVersion=function()\r\n\t\t{\r\n\t\t\t\r\n\t\t\tif (this.parsedVersion != null)\r\n\t\t\t{\r\n\t\t\t\treturn this.parsedVersion;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvar dimension = this.bitMatrix.getDimension();\r\n\t\t\t\r\n\t\t\tvar provisionalVersion = (dimension - 17) >> 2;\r\n\t\t\tif (provisionalVersion <= 6)\r\n\t\t\t{\r\n\t\t\t\treturn Version.getVersionForNumber(provisionalVersion);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Read top-right version info: 3 wide by 6 tall\r\n\t\t\tvar versionBits = 0;\r\n\t\t\tvar ijMin = dimension - 11;\r\n\t\t\tfor (var j = 5; j >= 0; j--)\r\n\t\t\t{\r\n\t\t\t\tfor (var i = dimension - 9; i >= ijMin; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tversionBits = this.copyBit(i, j, versionBits);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tthis.parsedVersion = Version.decodeVersionInformation(versionBits);\r\n\t\t\tif (this.parsedVersion != null && this.parsedVersion.getDimensionForVersion() == dimension)\r\n\t\t\t{\r\n\t\t\t\treturn this.parsedVersion;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Hmm, failed. Try bottom left: 6 wide by 3 tall\r\n\t\t\tversionBits = 0;\r\n\t\t\tfor (var i = 5; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tfor (var j = dimension - 9; j >= ijMin; j--)\r\n\t\t\t\t{\r\n\t\t\t\t\tversionBits = this.copyBit(i, j, versionBits);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tthis.parsedVersion = Version.decodeVersionInformation(versionBits);\r\n\t\t\tif (this.parsedVersion != null && this.parsedVersion.getDimensionForVersion() == dimension)\r\n\t\t\t{\r\n\t\t\t\treturn this.parsedVersion;\r\n\t\t\t}\r\n\t\t\tthrow new Error(\"QR Error: Error readVersion\");\r\n\t\t}\r\n\tthis.readCodewords=function()\r\n\t\t{\r\n\t\t\t\r\n\t\t\tvar formatInfo = this.readFormatInformation();\r\n\t\t\tvar version = this.readVersion();\r\n\t\t\t\r\n\t\t\t// Get the data mask for the format used in this QR Code. This will exclude\r\n\t\t\t// some bits from reading as we wind through the bit matrix.\r\n\t\t\tvar dataMask = DataMask.forReference( formatInfo.getDataMask());\r\n\t\t\tvar dimension = this.bitMatrix.getDimension();\r\n\t\t\tdataMask.unmaskBitMatrix(this.bitMatrix, dimension);\r\n\t\t\t\r\n\t\t\tvar functionPattern = version.buildFunctionPattern();\r\n\t\t\t\r\n\t\t\tvar readingUp = true;\r\n\t\t\tvar result = new Array(version.getTotalCodewords());\r\n\t\t\tvar resultOffset = 0;\r\n\t\t\tvar currentByte = 0;\r\n\t\t\tvar bitsRead = 0;\r\n\t\t\t// Read columns in pairs, from right to left\r\n\t\t\tfor (var j = dimension - 1; j > 0; j -= 2)\r\n\t\t\t{\r\n\t\t\t\tif (j == 6)\r\n\t\t\t\t{\r\n\t\t\t\t\t// Skip whole column with vertical alignment pattern;\r\n\t\t\t\t\t// saves time and makes the other code proceed more cleanly\r\n\t\t\t\t\tj--;\r\n\t\t\t\t}\r\n\t\t\t\t// Read alternatingly from bottom to top then top to bottom\r\n\t\t\t\tfor (var count = 0; count < dimension; count++)\r\n\t\t\t\t{\r\n\t\t\t\t\tvar i = readingUp?dimension - 1 - count:count;\r\n\t\t\t\t\tfor (var col = 0; col < 2; col++)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// Ignore bits covered by the function pattern\r\n\t\t\t\t\t\tif (!functionPattern.get_Renamed(j - col, i))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t// Read a bit\r\n\t\t\t\t\t\t\tbitsRead++;\r\n\t\t\t\t\t\t\tcurrentByte <<= 1;\r\n\t\t\t\t\t\t\tif (this.bitMatrix.get_Renamed(j - col, i))\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tcurrentByte |= 1;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t// If we've made a whole byte, save it off\r\n\t\t\t\t\t\t\tif (bitsRead == 8)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tresult[resultOffset++] = currentByte;\r\n\t\t\t\t\t\t\t\tbitsRead = 0;\r\n\t\t\t\t\t\t\t\tcurrentByte = 0;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\treadingUp ^= true; // readingUp = !readingUp; // switch directions\r\n\t\t\t}\r\n\t\t\tif (resultOffset != version.getTotalCodewords())\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(\"QR Error: Error readCodewords\");\r\n\t\t\t}\r\n\t\t\treturn result;\r\n\t\t}\r\n}","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nvar DataMask = {};\r\n\r\nDataMask.forReference = function(reference)\r\n{\r\n\tif (reference < 0 || reference > 7)\r\n\t{\r\n\t\tthrow new Error(\"QR Error: System.ArgumentException\");\r\n\t}\r\n\treturn DataMask.DATA_MASKS[reference];\r\n}\r\n\r\nfunction DataMask000()\r\n{\r\n\tthis.unmaskBitMatrix=function(bits, dimension)\r\n\t{\r\n\t\tfor (var i = 0; i < dimension; i++)\r\n\t\t{\r\n\t\t\tfor (var j = 0; j < dimension; j++)\r\n\t\t\t{\r\n\t\t\t\tif (this.isMasked(i, j))\r\n\t\t\t\t{\r\n\t\t\t\t\tbits.flip(j, i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tthis.isMasked=function( i, j)\r\n\t{\r\n\t\treturn ((i + j) & 0x01) == 0;\r\n\t}\r\n}\r\n\r\nfunction DataMask001()\r\n{\r\n\tthis.unmaskBitMatrix=function(bits, dimension)\r\n\t{\r\n\t\tfor (var i = 0; i < dimension; i++)\r\n\t\t{\r\n\t\t\tfor (var j = 0; j < dimension; j++)\r\n\t\t\t{\r\n\t\t\t\tif (this.isMasked(i, j))\r\n\t\t\t\t{\r\n\t\t\t\t\tbits.flip(j, i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tthis.isMasked=function( i, j)\r\n\t{\r\n\t\treturn (i & 0x01) == 0;\r\n\t}\r\n}\r\n\r\nfunction DataMask010()\r\n{\r\n\tthis.unmaskBitMatrix=function(bits, dimension)\r\n\t{\r\n\t\tfor (var i = 0; i < dimension; i++)\r\n\t\t{\r\n\t\t\tfor (var j = 0; j < dimension; j++)\r\n\t\t\t{\r\n\t\t\t\tif (this.isMasked(i, j))\r\n\t\t\t\t{\r\n\t\t\t\t\tbits.flip(j, i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tthis.isMasked=function( i, j)\r\n\t{\r\n\t\treturn j % 3 == 0;\r\n\t}\r\n}\r\n\r\nfunction DataMask011()\r\n{\r\n\tthis.unmaskBitMatrix=function(bits, dimension)\r\n\t{\r\n\t\tfor (var i = 0; i < dimension; i++)\r\n\t\t{\r\n\t\t\tfor (var j = 0; j < dimension; j++)\r\n\t\t\t{\r\n\t\t\t\tif (this.isMasked(i, j))\r\n\t\t\t\t{\r\n\t\t\t\t\tbits.flip(j, i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tthis.isMasked=function( i, j)\r\n\t{\r\n\t\treturn (i + j) % 3 == 0;\r\n\t}\r\n}\r\n\r\nfunction DataMask100()\r\n{\r\n\tthis.unmaskBitMatrix=function(bits, dimension)\r\n\t{\r\n\t\tfor (var i = 0; i < dimension; i++)\r\n\t\t{\r\n\t\t\tfor (var j = 0; j < dimension; j++)\r\n\t\t\t{\r\n\t\t\t\tif (this.isMasked(i, j))\r\n\t\t\t\t{\r\n\t\t\t\t\tbits.flip(j, i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tthis.isMasked=function( i, j)\r\n\t{\r\n\t\treturn (((URShift(i, 1)) + (j / 3)) & 0x01) == 0;\r\n\t}\r\n}\r\n\r\nfunction DataMask101()\r\n{\r\n\tthis.unmaskBitMatrix=function(bits, dimension)\r\n\t{\r\n\t\tfor (var i = 0; i < dimension; i++)\r\n\t\t{\r\n\t\t\tfor (var j = 0; j < dimension; j++)\r\n\t\t\t{\r\n\t\t\t\tif (this.isMasked(i, j))\r\n\t\t\t\t{\r\n\t\t\t\t\tbits.flip(j, i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tthis.isMasked=function( i, j)\r\n\t{\r\n\t\tvar temp = i * j;\r\n\t\treturn (temp & 0x01) + (temp % 3) == 0;\r\n\t}\r\n}\r\n\r\nfunction DataMask110()\r\n{\r\n\tthis.unmaskBitMatrix=function(bits, dimension)\r\n\t{\r\n\t\tfor (var i = 0; i < dimension; i++)\r\n\t\t{\r\n\t\t\tfor (var j = 0; j < dimension; j++)\r\n\t\t\t{\r\n\t\t\t\tif (this.isMasked(i, j))\r\n\t\t\t\t{\r\n\t\t\t\t\tbits.flip(j, i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tthis.isMasked=function( i, j)\r\n\t{\r\n\t\tvar temp = i * j;\r\n\t\treturn (((temp & 0x01) + (temp % 3)) & 0x01) == 0;\r\n\t}\r\n}\r\nfunction DataMask111()\r\n{\r\n\tthis.unmaskBitMatrix=function(bits, dimension)\r\n\t{\r\n\t\tfor (var i = 0; i < dimension; i++)\r\n\t\t{\r\n\t\t\tfor (var j = 0; j < dimension; j++)\r\n\t\t\t{\r\n\t\t\t\tif (this.isMasked(i, j))\r\n\t\t\t\t{\r\n\t\t\t\t\tbits.flip(j, i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tthis.isMasked=function( i, j)\r\n\t{\r\n\t\treturn ((((i + j) & 0x01) + ((i * j) % 3)) & 0x01) == 0;\r\n\t}\r\n}\r\n\r\nDataMask.DATA_MASKS = new Array(new DataMask000(), new DataMask001(), new DataMask010(), new DataMask011(), new DataMask100(), new DataMask101(), new DataMask110(), new DataMask111());\r\n\r\n","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nfunction GF256Poly(field, coefficients)\r\n{\r\n\tif (coefficients == null || coefficients.length == 0)\r\n\t{\r\n\t\tthrow new Error(\"QR Error: System.ArgumentException\");\r\n\t}\r\n\tthis.field = field;\r\n\tvar coefficientsLength = coefficients.length;\r\n\tif (coefficientsLength > 1 && coefficients[0] == 0)\r\n\t{\r\n\t\t// Leading term must be non-zero for anything except the constant polynomial \"0\"\r\n\t\tvar firstNonZero = 1;\r\n\t\twhile (firstNonZero < coefficientsLength && coefficients[firstNonZero] == 0)\r\n\t\t{\r\n\t\t\tfirstNonZero++;\r\n\t\t}\r\n\t\tif (firstNonZero == coefficientsLength)\r\n\t\t{\r\n\t\t\tthis.coefficients = field.getZero().coefficients;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tthis.coefficients = new Array(coefficientsLength - firstNonZero);\r\n\t\t\tfor(var i=0;i largerCoefficients.length)\r\n\t\t\t{\r\n\t\t\t\tvar temp = smallerCoefficients;\r\n\t\t\t\tsmallerCoefficients = largerCoefficients;\r\n\t\t\t\tlargerCoefficients = temp;\r\n\t\t\t}\r\n\t\t\tvar sumDiff = new Array(largerCoefficients.length);\r\n\t\t\tvar lengthDiff = largerCoefficients.length - smallerCoefficients.length;\r\n\t\t\t// Copy high-order terms only found in higher-degree polynomial's coefficients\r\n\t\t\t//Array.Copy(largerCoefficients, 0, sumDiff, 0, lengthDiff);\r\n\t\t\tfor(var ci=0;ci= other.getDegree() && !remainder.getZero())\r\n\t\t\t{\r\n\t\t\t\tvar degreeDifference = remainder.getDegree() - other.getDegree();\r\n\t\t\t\tvar scale = this.field.multiply(remainder.getCoefficient(remainder.getDegree()), inverseDenominatorLeadingTerm);\r\n\t\t\t\tvar term = other.multiplyByMonomial(degreeDifference, scale);\r\n\t\t\t\tvar iterationQuotient = this.field.buildMonomial(degreeDifference, scale);\r\n\t\t\t\tquotient = quotient.addOrSubtract(iterationQuotient);\r\n\t\t\t\tremainder = remainder.addOrSubtract(term);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\treturn new Array(quotient, remainder);\r\n\t\t}\r\n}","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nfunction GF256( primitive)\r\n{\r\n\tthis.expTable = new Array(256);\r\n\tthis.logTable = new Array(256);\r\n\tvar x = 1;\r\n\tfor (var i = 0; i < 256; i++)\r\n\t{\r\n\t\tthis.expTable[i] = x;\r\n\t\tx <<= 1; // x = x * 2; we're assuming the generator alpha is 2\r\n\t\tif (x >= 0x100)\r\n\t\t{\r\n\t\t\tx ^= primitive;\r\n\t\t}\r\n\t}\r\n\tfor (var i = 0; i < 255; i++)\r\n\t{\r\n\t\tthis.logTable[this.expTable[i]] = i;\r\n\t}\r\n\t// logTable[0] == 0 but this should never be used\r\n\tvar at0=new Array(1);at0[0]=0;\r\n\tthis.zero = new GF256Poly(this, new Array(at0));\r\n\tvar at1=new Array(1);at1[0]=1;\r\n\tthis.one = new GF256Poly(this, new Array(at1));\r\n\t\r\n\tthis.getZero = function()\r\n\t{\r\n\t\treturn this.zero;\r\n\t};\r\n\tthis.getOne = function()\r\n\t{\r\n\t\treturn this.one;\r\n\t};\r\n\tthis.buildMonomial=function( degree, coefficient)\r\n\t\t{\r\n\t\t\tif (degree < 0)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(\"QR Error: System.ArgumentException\");\r\n\t\t\t}\r\n\t\t\tif (coefficient == 0)\r\n\t\t\t{\r\n\t\t\t\treturn this.zero;\r\n\t\t\t}\r\n\t\t\tvar coefficients = new Array(degree + 1);\r\n\t\t\tfor(var i=0;i= b's\r\n\t\t\tif (a.getDegree() < b.getDegree())\r\n\t\t\t{\r\n\t\t\t\tvar temp = a;\r\n\t\t\t\ta = b;\r\n\t\t\t\tb = temp;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvar rLast = a;\r\n\t\t\tvar r = b;\r\n\t\t\tvar sLast = this.field.getOne();\r\n\t\t\tvar s = this.field.getZero();\r\n\t\t\tvar tLast = this.field.getZero();\r\n\t\t\tvar t = this.field.getOne();\r\n\t\t\t\r\n\t\t\t// Run Euclidean algorithm until r's degree is less than R/2\r\n\t\t\twhile (r.getDegree() >= Math.floor(R / 2))\r\n\t\t\t{\r\n\t\t\t\tvar rLastLast = rLast;\r\n\t\t\t\tvar sLastLast = sLast;\r\n\t\t\t\tvar tLastLast = tLast;\r\n\t\t\t\trLast = r;\r\n\t\t\t\tsLast = s;\r\n\t\t\t\ttLast = t;\r\n\t\t\t\t\r\n\t\t\t\t// Divide rLastLast by rLast, with quotient in q and remainder in r\r\n\t\t\t\tif (rLast.getZero())\r\n\t\t\t\t{\r\n\t\t\t\t\t// Oops, Euclidean algorithm already terminated?\r\n\t\t\t\t\tthrow new Error(\"QR Error: r_{i-1} was zero\");\r\n\t\t\t\t}\r\n\t\t\t\tr = rLastLast;\r\n\t\t\t\tvar q = this.field.getZero();\r\n\t\t\t\tvar denominatorLeadingTerm = rLast.getCoefficient(rLast.getDegree());\r\n\t\t\t\tvar dltInverse = this.field.inverse(denominatorLeadingTerm);\r\n\t\t\t\twhile (r.getDegree() >= rLast.getDegree() && !r.getZero())\r\n\t\t\t\t{\r\n\t\t\t\t\tvar degreeDiff = r.getDegree() - rLast.getDegree();\r\n\t\t\t\t\tvar scale = this.field.multiply(r.getCoefficient(r.getDegree()), dltInverse);\r\n\t\t\t\t\tq = q.addOrSubtract(this.field.buildMonomial(degreeDiff, scale));\r\n\t\t\t\t\tr = r.addOrSubtract(rLast.multiplyByMonomial(degreeDiff, scale));\r\n\t\t\t\t\t//r.EXE();\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\ts = q.multiply1(sLast).addOrSubtract(sLastLast);\r\n\t\t\t\tt = q.multiply1(tLast).addOrSubtract(tLastLast);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvar sigmaTildeAtZero = t.getCoefficient(0);\r\n\t\t\tif (sigmaTildeAtZero == 0)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(\"QR Error: ReedSolomonException sigmaTilde(0) was zero\");\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvar inverse = this.field.inverse(sigmaTildeAtZero);\r\n\t\t\tvar sigma = t.multiply2(inverse);\r\n\t\t\tvar omega = r.multiply2(inverse);\r\n\t\t\treturn new Array(sigma, omega);\r\n\t\t}\r\n\tthis.findErrorLocations=function( errorLocator)\r\n\t\t{\r\n\t\t\t// This is a direct application of Chien's search\r\n\t\t\tvar numErrors = errorLocator.getDegree();\r\n\t\t\tif (numErrors == 1)\r\n\t\t\t{\r\n\t\t\t\t// shortcut\r\n\t\t\t\treturn new Array(errorLocator.getCoefficient(1));\r\n\t\t\t}\r\n\t\t\tvar result = new Array(numErrors);\r\n\t\t\tvar e = 0;\r\n\t\t\tfor (var i = 1; i < 256 && e < numErrors; i++)\r\n\t\t\t{\r\n\t\t\t\tif (errorLocator.evaluateAt(i) == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tresult[e] = this.field.inverse(i);\r\n\t\t\t\t\te++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (e != numErrors)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(\"QR Error: Error locator degree does not match number of roots\");\r\n\t\t\t}\r\n\t\t\treturn result;\r\n\t\t}\r\n\tthis.findErrorMagnitudes=function( errorEvaluator, errorLocations, dataMatrix)\r\n\t\t{\r\n\t\t\t// This is directly applying Forney's Formula\r\n\t\t\tvar s = errorLocations.length;\r\n\t\t\tvar result = new Array(s);\r\n\t\t\tfor (var i = 0; i < s; i++)\r\n\t\t\t{\r\n\t\t\t\tvar xiInverse = this.field.inverse(errorLocations[i]);\r\n\t\t\t\tvar denominator = 1;\r\n\t\t\t\tfor (var j = 0; j < s; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i != j)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdenominator = this.field.multiply(denominator, GF256.addOrSubtract(1, this.field.multiply(errorLocations[j], xiInverse)));\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tresult[i] = this.field.multiply(errorEvaluator.evaluateAt(xiInverse), this.field.inverse(denominator));\r\n\t\t\t\t// Thanks to sanfordsquires for this fix:\r\n\t\t\t\tif (dataMatrix)\r\n\t\t\t\t{\r\n\t\t\t\t\tresult[i] = this.field.multiply(result[i], xiInverse);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn result;\r\n\t\t}\r\n}","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nfunction AlignmentPattern(posX, posY, estimatedModuleSize)\r\n{\r\n\tthis.x=posX;\r\n\tthis.y=posY;\r\n\tthis.count = 1;\r\n\tthis.estimatedModuleSize = estimatedModuleSize;\r\n\t\r\n\tthis.getEstimatedModuleSize = function() {\r\n\t\treturn this.estimatedModuleSize;\r\n\t};\r\n\tthis.getCount = function() {\r\n\t\treturn this.count;\r\n\t};\r\n\tthis.getX = function() {\r\n\t\treturn Math.floor(this.x);\r\n\t};\r\n\tthis.getY = function() {\r\n\t\treturn Math.floor(this.y);\r\n\t};\r\n\tthis.incrementCount = function()\r\n\t{\r\n\t\tthis.count++;\r\n\t}\r\n\tthis.aboutEquals=function( moduleSize, i, j)\r\n\t\t{\r\n\t\t\tif (Math.abs(i - this.y) <= moduleSize && Math.abs(j - this.x) <= moduleSize)\r\n\t\t\t{\r\n\t\t\t\tvar moduleSizeDiff = Math.abs(moduleSize - this.estimatedModuleSize);\r\n\t\t\t\treturn moduleSizeDiff <= 1.0 || moduleSizeDiff / this.estimatedModuleSize <= 1.0;\r\n\t\t\t}\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\r\n}\r\n\r\nfunction AlignmentPatternFinder( image, startX, startY, width, height, moduleSize, resultPointCallback)\r\n{\r\n\tthis.image = image;\r\n\tthis.possibleCenters = new Array();\r\n\tthis.startX = startX;\r\n\tthis.startY = startY;\r\n\tthis.width = width;\r\n\tthis.height = height;\r\n\tthis.moduleSize = moduleSize;\r\n\tthis.crossCheckStateCount = new Array(0,0,0);\r\n\tthis.resultPointCallback = resultPointCallback;\r\n\t\r\n\tthis.centerFromEnd=function(stateCount, end)\r\n\t\t{\r\n\t\t\treturn (end - stateCount[2]) - stateCount[1] / 2.0;\r\n\t\t}\r\n\tthis.foundPatternCross = function(stateCount)\r\n\t\t{\r\n\t\t\tvar moduleSize = this.moduleSize;\r\n\t\t\tvar maxVariance = moduleSize / 2.0;\r\n\t\t\tfor (var i = 0; i < 3; i++)\r\n\t\t\t{\r\n\t\t\t\tif (Math.abs(moduleSize - stateCount[i]) >= maxVariance)\r\n\t\t\t\t{\r\n\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\tthis.crossCheckVertical=function( startI, centerJ, maxCount, originalStateCountTotal)\r\n\t\t{\r\n\t\t\tvar image = this.image;\r\n\t\t\t\r\n\t\t\tvar maxI = qrcode.height;\r\n\t\t\tvar stateCount = this.crossCheckStateCount;\r\n\t\t\tstateCount[0] = 0;\r\n\t\t\tstateCount[1] = 0;\r\n\t\t\tstateCount[2] = 0;\r\n\t\t\t\r\n\t\t\t// Start counting up from center\r\n\t\t\tvar i = startI;\r\n\t\t\twhile (i >= 0 && image[centerJ + i*qrcode.width] && stateCount[1] <= maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[1]++;\r\n\t\t\t\ti--;\r\n\t\t\t}\r\n\t\t\t// If already too many modules in this state or ran off the edge:\r\n\t\t\tif (i < 0 || stateCount[1] > maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (i >= 0 && !image[centerJ + i*qrcode.width] && stateCount[0] <= maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[0]++;\r\n\t\t\t\ti--;\r\n\t\t\t}\r\n\t\t\tif (stateCount[0] > maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Now also count down from center\r\n\t\t\ti = startI + 1;\r\n\t\t\twhile (i < maxI && image[centerJ + i*qrcode.width] && stateCount[1] <= maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[1]++;\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t\tif (i == maxI || stateCount[1] > maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\twhile (i < maxI && !image[centerJ + i*qrcode.width] && stateCount[2] <= maxCount)\r\n\t\t\t{\r\n\t\t\t\tstateCount[2]++;\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t\tif (stateCount[2] > maxCount)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvar stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];\r\n\t\t\tif (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal)\r\n\t\t\t{\r\n\t\t\t\treturn NaN;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\treturn this.foundPatternCross(stateCount)?this.centerFromEnd(stateCount, i):NaN;\r\n\t\t}\r\n\t\t\r\n\tthis.handlePossibleCenter=function( stateCount, i, j)\r\n\t\t{\r\n\t\t\tvar stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];\r\n\t\t\tvar centerJ = this.centerFromEnd(stateCount, j);\r\n\t\t\tvar centerI = this.crossCheckVertical(i, Math.floor (centerJ), 2 * stateCount[1], stateCountTotal);\r\n\t\t\tif (!isNaN(centerI))\r\n\t\t\t{\r\n\t\t\t\tvar estimatedModuleSize = (stateCount[0] + stateCount[1] + stateCount[2]) / 3.0;\r\n\t\t\t\tvar max = this.possibleCenters.length;\r\n\t\t\t\tfor (var index = 0; index < max; index++)\r\n\t\t\t\t{\r\n\t\t\t\t\tvar center = this.possibleCenters[index];\r\n\t\t\t\t\t// Look for about the same center and module size:\r\n\t\t\t\t\tif (center.aboutEquals(estimatedModuleSize, centerI, centerJ))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treturn new AlignmentPattern(centerJ, centerI, estimatedModuleSize);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t// Hadn't found this before; save it\r\n\t\t\t\tvar point = new AlignmentPattern(centerJ, centerI, estimatedModuleSize);\r\n\t\t\t\tthis.possibleCenters.push(point);\r\n\t\t\t\tif (this.resultPointCallback != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tthis.resultPointCallback.foundPossibleResultPoint(point);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn null;\r\n\t\t}\r\n\t\t\r\n\tthis.find = function()\r\n\t{\r\n\t\t\tvar startX = this.startX;\r\n\t\t\tvar height = this.height;\r\n\t\t\tvar maxJ = startX + width;\r\n\t\t\tvar middleI = startY + (height >> 1);\r\n\t\t\t// We are looking for black/white/black modules in 1:1:1 ratio;\r\n\t\t\t// this tracks the number of black/white/black modules seen so far\r\n\t\t\tvar stateCount = new Array(0,0,0);\r\n\t\t\tfor (var iGen = 0; iGen < height; iGen++)\r\n\t\t\t{\r\n\t\t\t\t// Search from middle outwards\r\n\t\t\t\tvar i = middleI + ((iGen & 0x01) == 0?((iGen + 1) >> 1):- ((iGen + 1) >> 1));\r\n\t\t\t\tstateCount[0] = 0;\r\n\t\t\t\tstateCount[1] = 0;\r\n\t\t\t\tstateCount[2] = 0;\r\n\t\t\t\tvar j = startX;\r\n\t\t\t\t// Burn off leading white pixels before anything else; if we start in the middle of\r\n\t\t\t\t// a white run, it doesn't make sense to count its length, since we don't know if the\r\n\t\t\t\t// white run continued to the left of the start point\r\n\t\t\t\twhile (j < maxJ && !image[j + qrcode.width* i])\r\n\t\t\t\t{\r\n\t\t\t\t\tj++;\r\n\t\t\t\t}\r\n\t\t\t\tvar currentState = 0;\r\n\t\t\t\twhile (j < maxJ)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (image[j + i*qrcode.width])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// Black pixel\r\n\t\t\t\t\t\tif (currentState == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t// Counting black pixels\r\n\t\t\t\t\t\t\tstateCount[currentState]++;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t// Counting white pixels\r\n\t\t\t\t\t\t\tif (currentState == 2)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t// A winner?\r\n\t\t\t\t\t\t\t\tif (this.foundPatternCross(stateCount))\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t// Yes\r\n\t\t\t\t\t\t\t\t\tvar confirmed = this.handlePossibleCenter(stateCount, i, j);\r\n\t\t\t\t\t\t\t\t\tif (confirmed != null)\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\treturn confirmed;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\tstateCount[0] = stateCount[2];\r\n\t\t\t\t\t\t\t\tstateCount[1] = 1;\r\n\t\t\t\t\t\t\t\tstateCount[2] = 0;\r\n\t\t\t\t\t\t\t\tcurrentState = 1;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tstateCount[++currentState]++;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// White pixel\r\n\t\t\t\t\t\tif (currentState == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t// Counting black pixels\r\n\t\t\t\t\t\t\tcurrentState++;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tstateCount[currentState]++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tj++;\r\n\t\t\t\t}\r\n\t\t\t\tif (this.foundPatternCross(stateCount))\r\n\t\t\t\t{\r\n\t\t\t\t\tvar confirmed = this.handlePossibleCenter(stateCount, i, maxJ);\r\n\t\t\t\t\tif (confirmed != null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treturn confirmed;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Hmm, nothing we saw was observed and confirmed twice. If we had\r\n\t\t\t// any guess at all, return it.\r\n\t\t\tif (!(this.possibleCenters.length == 0))\r\n\t\t\t{\r\n\t\t\t\treturn this.possibleCenters[0];\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tthrow new Error(\"QR Error: Couldn't find enough alignment patterns\");\r\n\t\t}\r\n\t\r\n}","/*\r\n Ported to JavaScript by Lazar Laszlo 2011 \r\n \r\n lazarsoft@gmail.com, www.lazarsoft.info\r\n \r\n*/\r\n\r\n/*\r\n*\r\n* Copyright 2007 ZXing authors\r\n*\r\n* Licensed under the Apache License, Version 2.0 (the \"License\");\r\n* you may not use this file except in compliance with the License.\r\n* You may obtain a copy of the License at\r\n*\r\n* http://www.apache.org/licenses/LICENSE-2.0\r\n*\r\n* Unless required by applicable law or agreed to in writing, software\r\n* distributed under the License is distributed on an \"AS IS\" BASIS,\r\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n* See the License for the specific language governing permissions and\r\n* limitations under the License.\r\n*/\r\n\r\n\r\nfunction QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode)\r\n{\r\n\tthis.blockPointer = 0;\r\n\tthis.bitPointer = 7;\r\n\tthis.dataLength = 0;\r\n\tthis.blocks = blocks;\r\n\tthis.numErrorCorrectionCode = numErrorCorrectionCode;\r\n\tif (version <= 9)\r\n\t\tthis.dataLengthMode = 0;\r\n\telse if (version >= 10 && version <= 26)\r\n\t\tthis.dataLengthMode = 1;\r\n\telse if (version >= 27 && version <= 40)\r\n\t\tthis.dataLengthMode = 2;\r\n\t\t\r\n\tthis.getNextBits = function( numBits)\r\n\t\t{\t\t\t\r\n\t\t\tvar bits = 0;\r\n\t\t\tif (numBits < this.bitPointer + 1)\r\n\t\t\t{\r\n\t\t\t\t// next word fits into current data block\r\n\t\t\t\tvar mask = 0;\r\n\t\t\t\tfor (var i = 0; i < numBits; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tmask += (1 << i);\r\n\t\t\t\t}\r\n\t\t\t\tmask <<= (this.bitPointer - numBits + 1);\r\n\t\t\t\t\r\n\t\t\t\tbits = (this.blocks[this.blockPointer] & mask) >> (this.bitPointer - numBits + 1);\r\n\t\t\t\tthis.bitPointer -= numBits;\r\n\t\t\t\treturn bits;\r\n\t\t\t}\r\n\t\t\telse if (numBits < this.bitPointer + 1 + 8)\r\n\t\t\t{\r\n\t\t\t\t// next word crosses 2 data blocks\r\n\t\t\t\tvar mask1 = 0;\r\n\t\t\t\tfor (var i = 0; i < this.bitPointer + 1; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tmask1 += (1 << i);\r\n\t\t\t\t}\r\n\t\t\t\tbits = (this.blocks[this.blockPointer] & mask1) << (numBits - (this.bitPointer + 1));\r\n this.blockPointer++;\r\n\t\t\t\tbits += ((this.blocks[this.blockPointer]) >> (8 - (numBits - (this.bitPointer + 1))));\r\n\t\t\t\t\r\n\t\t\t\tthis.bitPointer = this.bitPointer - numBits % 8;\r\n\t\t\t\tif (this.bitPointer < 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tthis.bitPointer = 8 + this.bitPointer;\r\n\t\t\t\t}\r\n\t\t\t\treturn bits;\r\n\t\t\t}\r\n\t\t\telse if (numBits < this.bitPointer + 1 + 16)\r\n\t\t\t{\r\n\t\t\t\t// next word crosses 3 data blocks\r\n\t\t\t\tvar mask1 = 0; // mask of first block\r\n\t\t\t\tvar mask3 = 0; // mask of 3rd block\r\n\t\t\t\t//bitPointer + 1 : number of bits of the 1st block\r\n\t\t\t\t//8 : number of the 2nd block (note that use already 8bits because next word uses 3 data blocks)\r\n\t\t\t\t//numBits - (bitPointer + 1 + 8) : number of bits of the 3rd block \r\n\t\t\t\tfor (var i = 0; i < this.bitPointer + 1; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tmask1 += (1 << i);\r\n\t\t\t\t}\r\n\t\t\t\tvar bitsFirstBlock = (this.blocks[this.blockPointer] & mask1) << (numBits - (this.bitPointer + 1));\r\n\t\t\t\tthis.blockPointer++;\r\n\t\t\t\t\r\n\t\t\t\tvar bitsSecondBlock = this.blocks[this.blockPointer] << (numBits - (this.bitPointer + 1 + 8));\r\n\t\t\t\tthis.blockPointer++;\r\n\t\t\t\t\r\n\t\t\t\tfor (var i = 0; i < numBits - (this.bitPointer + 1 + 8); i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tmask3 += (1 << i);\r\n\t\t\t\t}\r\n\t\t\t\tmask3 <<= 8 - (numBits - (this.bitPointer + 1 + 8));\r\n\t\t\t\tvar bitsThirdBlock = (this.blocks[this.blockPointer] & mask3) >> (8 - (numBits - (this.bitPointer + 1 + 8)));\r\n\t\t\t\t\r\n\t\t\t\tbits = bitsFirstBlock + bitsSecondBlock + bitsThirdBlock;\r\n\t\t\t\tthis.bitPointer = this.bitPointer - (numBits - 8) % 8;\r\n\t\t\t\tif (this.bitPointer < 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tthis.bitPointer = 8 + this.bitPointer;\r\n\t\t\t\t}\r\n\t\t\t\treturn bits;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t}\r\n\tthis.NextMode=function()\r\n\t{\r\n\t\tif ((this.blockPointer > this.blocks.length - this.numErrorCorrectionCode - 2))\r\n\t\t\treturn 0;\r\n\t\telse\r\n\t\t\treturn this.getNextBits(4);\r\n\t}\r\n\tthis.getDataLength=function( modeIndicator)\r\n\t\t{\r\n\t\t\tvar index = 0;\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tif ((modeIndicator >> index) == 1)\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tindex++;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\treturn this.getNextBits(qrcode.sizeOfDataLengthInfo[this.dataLengthMode][index]);\r\n\t\t}\r\n\tthis.getRomanAndFigureString=function( dataLength)\r\n\t\t{\r\n\t\t\tvar length = dataLength;\r\n\t\t\tvar intData = 0;\r\n\t\t\tvar strData = \"\";\r\n\t\t\tvar 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', ' ', '$', '%', '*', '+', '-', '.', '/', ':');\r\n\t\t\tdo \r\n\t\t\t{\r\n\t\t\t\tif (length > 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tintData = this.getNextBits(11);\r\n\t\t\t\t\tvar firstLetter = Math.floor(intData / 45);\r\n\t\t\t\t\tvar secondLetter = intData % 45;\r\n\t\t\t\t\tstrData += tableRomanAndFigure[firstLetter];\r\n\t\t\t\t\tstrData += tableRomanAndFigure[secondLetter];\r\n\t\t\t\t\tlength -= 2;\r\n\t\t\t\t}\r\n\t\t\t\telse if (length == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tintData = this.getNextBits(6);\r\n\t\t\t\t\tstrData += tableRomanAndFigure[intData];\r\n\t\t\t\t\tlength -= 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\twhile (length > 0);\r\n\t\t\t\r\n\t\t\treturn strData;\r\n\t\t}\r\n\tthis.getFigureString=function( dataLength)\r\n\t\t{\r\n\t\t\tvar length = dataLength;\r\n\t\t\tvar intData = 0;\r\n\t\t\tvar strData = \"\";\r\n\t\t\tdo \r\n\t\t\t{\r\n\t\t\t\tif (length >= 3)\r\n\t\t\t\t{\r\n\t\t\t\t\tintData = this.getNextBits(10);\r\n\t\t\t\t\tif (intData < 100)\r\n\t\t\t\t\t\tstrData += \"0\";\r\n\t\t\t\t\tif (intData < 10)\r\n\t\t\t\t\t\tstrData += \"0\";\r\n\t\t\t\t\tlength -= 3;\r\n\t\t\t\t}\r\n\t\t\t\telse if (length == 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tintData = this.getNextBits(7);\r\n\t\t\t\t\tif (intData < 10)\r\n\t\t\t\t\t\tstrData += \"0\";\r\n\t\t\t\t\tlength -= 2;\r\n\t\t\t\t}\r\n\t\t\t\telse if (length == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tintData = this.getNextBits(4);\r\n\t\t\t\t\tlength -= 1;\r\n\t\t\t\t}\r\n\t\t\t\tstrData += intData;\r\n\t\t\t}\r\n\t\t\twhile (length > 0);\r\n\t\t\t\r\n\t\t\treturn strData;\r\n\t\t}\r\n\tthis.get8bitByteArray=function( dataLength)\r\n\t\t{\r\n\t\t\tvar length = dataLength;\r\n\t\t\tvar intData = 0;\r\n\t\t\tvar output = new Array();\r\n\t\t\t\r\n\t\t\tdo \r\n\t\t\t{\r\n\t\t\t\tintData = this.getNextBits(8);\r\n\t\t\t\toutput.push( intData);\r\n\t\t\t\tlength--;\r\n\t\t\t}\r\n\t\t\twhile (length > 0);\r\n\t\t\treturn output;\r\n\t\t}\r\n this.getKanjiString=function( dataLength)\r\n\t\t{\r\n\t\t\tvar length = dataLength;\r\n\t\t\tvar intData = 0;\r\n\t\t\tvar unicodeString = \"\";\r\n\t\t\tdo \r\n\t\t\t{\r\n\t\t\t\tintData = this.getNextBits(13);\r\n\t\t\t\tvar lowerByte = intData % 0xC0;\r\n\t\t\t\tvar higherByte = intData / 0xC0;\r\n\t\t\t\t\r\n\t\t\t\tvar tempWord = (higherByte << 8) + lowerByte;\r\n\t\t\t\tvar shiftjisWord = 0;\r\n\t\t\t\tif (tempWord + 0x8140 <= 0x9FFC)\r\n\t\t\t\t{\r\n\t\t\t\t\t// between 8140 - 9FFC on Shift_JIS character set\r\n\t\t\t\t\tshiftjisWord = tempWord + 0x8140;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t// between E040 - EBBF on Shift_JIS character set\r\n\t\t\t\t\tshiftjisWord = tempWord + 0xC140;\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\t//var tempByte = new Array(0,0);\r\n\t\t\t\t//tempByte[0] = (sbyte) (shiftjisWord >> 8);\r\n\t\t\t\t//tempByte[1] = (sbyte) (shiftjisWord & 0xFF);\r\n\t\t\t\t//unicodeString += new String(SystemUtils.ToCharArray(SystemUtils.ToByteArray(tempByte)));\r\n unicodeString += String.fromCharCode(shiftjisWord);\r\n\t\t\t\tlength--;\r\n\t\t\t}\r\n\t\t\twhile (length > 0);\r\n\t\t\t\r\n\t\t\t\r\n\t\t\treturn unicodeString;\r\n\t\t}\r\n\r\n\tthis.parseECIValue = function ()\r\n\t{\r\n\t\tvar intData = 0;\r\n\t\tvar firstByte = this.getNextBits(8);\r\n\t\tif ((firstByte & 0x80) == 0) {\r\n\t\t\tintData = firstByte & 0x7F;\r\n\t\t}\r\n\t\tif ((firstByte & 0xC0) == 0x80) {\r\n\t\t\t// two bytes\r\n\t\t\tvar secondByte = this.getNextBits(8);\r\n\t\t\tintData = ((firstByte & 0x3F) << 8) | secondByte;\r\n\t\t}\r\n\t\tif ((firstByte & 0xE0) == 0xC0) {\r\n\t\t\t// three bytes\r\n\t\t\tvar secondThirdBytes = this.getNextBits(8);;\r\n\t\t\tintData = ((firstByte & 0x1F) << 16) | secondThirdBytes;\r\n\t\t}\r\n\t\treturn intData;\r\n\t}\r\n\r\n\tthis.getDataByte = function()\r\n\t{\r\n\t\tvar output = new Array();\r\n\t\tvar MODE_NUMBER = 1;\r\n\t var MODE_ROMAN_AND_NUMBER = 2;\r\n\t var MODE_8BIT_BYTE = 4;\r\n\t\tvar MODE_ECI = 7;\r\n\t var MODE_KANJI = 8;\r\n\t\tdo \r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tvar mode = this.NextMode();\r\n\t\t\t\t\t\t//canvas.println(\"mode: \" + mode);\r\n\t\t\t\t\t\tif (mode == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (output.length > 0)\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\tthrow new Error(\"QR Error: Empty data block\");\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (mode != MODE_NUMBER && mode != MODE_ROMAN_AND_NUMBER && mode != MODE_8BIT_BYTE && mode != MODE_KANJI && mode != MODE_ECI)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tthrow new Error(\"QR Error: Invalid mode: \" + mode + \" in (block:\" + this.blockPointer + \" bit:\" + this.bitPointer + \")\");\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif(mode == MODE_ECI)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tvar temp_sbyteArray3 = this.parseECIValue();\r\n\t\t\t\t\t\t\t//output.push(temp_sbyteArray3);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\r\n\t\t\t\t\t\t\tvar dataLength = this.getDataLength(mode);\r\n\t\t\t\t\t\t\tif (dataLength < 1)\r\n\t\t\t\t\t\t\t\tthrow new Error(\"QR Error: Invalid data length: \" + dataLength);\r\n\t\t\t\t\t\t\tswitch (mode)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\tcase MODE_NUMBER: \r\n\t\t\t\t\t\t\t\t\tvar temp_str = this.getFigureString(dataLength);\r\n\t\t\t\t\t\t\t\t\tvar ta = new Array(temp_str.length);\r\n\t\t\t\t\t\t\t\t\tfor(var j=0;j= iMin; i--) @@ -96,7 +96,7 @@ function BitMatrixParser(bitMatrix) return this.parsedVersion; } - var dimension = this.bitMatrix.Dimension; + var dimension = this.bitMatrix.getDimension(); var provisionalVersion = (dimension - 17) >> 2; if (provisionalVersion <= 6) @@ -116,7 +116,7 @@ function BitMatrixParser(bitMatrix) } this.parsedVersion = Version.decodeVersionInformation(versionBits); - if (this.parsedVersion != null && this.parsedVersion.DimensionForVersion == dimension) + if (this.parsedVersion != null && this.parsedVersion.getDimensionForVersion() == dimension) { return this.parsedVersion; } @@ -132,7 +132,7 @@ function BitMatrixParser(bitMatrix) } this.parsedVersion = Version.decodeVersionInformation(versionBits); - if (this.parsedVersion != null && this.parsedVersion.DimensionForVersion == dimension) + if (this.parsedVersion != null && this.parsedVersion.getDimensionForVersion() == dimension) { return this.parsedVersion; } @@ -146,14 +146,14 @@ function BitMatrixParser(bitMatrix) // Get the data mask for the format used in this QR Code. This will exclude // some bits from reading as we wind through the bit matrix. - var dataMask = DataMask.forReference( formatInfo.DataMask); - var dimension = this.bitMatrix.Dimension; + var dataMask = DataMask.forReference( formatInfo.getDataMask()); + var dimension = this.bitMatrix.getDimension(); dataMask.unmaskBitMatrix(this.bitMatrix, dimension); var functionPattern = version.buildFunctionPattern(); var readingUp = true; - var result = new Array(version.TotalCodewords); + var result = new Array(version.getTotalCodewords()); var resultOffset = 0; var currentByte = 0; var bitsRead = 0; @@ -194,7 +194,7 @@ function BitMatrixParser(bitMatrix) } readingUp ^= true; // readingUp = !readingUp; // switch directions } - if (resultOffset != version.TotalCodewords) + if (resultOffset != version.getTotalCodewords()) { throw new Error("QR Error: Error readCodewords"); } diff --git a/src/datablock.js b/src/datablock.js index 89ecfea..abdf0b7 100644 --- a/src/datablock.js +++ b/src/datablock.js @@ -28,20 +28,20 @@ function DataBlock(numDataCodewords, codewords) this.numDataCodewords = numDataCodewords; this.codewords = codewords; - this.__defineGetter__("NumDataCodewords", function() + this.getNumDataCodewords = function() { return this.numDataCodewords; - }); - this.__defineGetter__("Codewords", function() + }; + this.getCodewords = function() { return this.codewords; - }); + }; } DataBlock.getDataBlocks=function(rawCodewords, version, ecLevel) { - if (rawCodewords.length != version.TotalCodewords) + if (rawCodewords.length != version.getTotalCodewords()) { throw new Error("QR Error: ArgumentException"); } @@ -55,7 +55,7 @@ DataBlock.getDataBlocks=function(rawCodewords, version, ecLevel) var ecBlockArray = ecBlocks.getECBlocks(); for (var i = 0; i < ecBlockArray.length; i++) { - totalBlocks += ecBlockArray[i].Count; + totalBlocks += ecBlockArray[i].getCount(); } // Now establish DataBlocks of the appropriate size and number of data codewords @@ -64,10 +64,10 @@ DataBlock.getDataBlocks=function(rawCodewords, version, ecLevel) for (var j = 0; j < ecBlockArray.length; j++) { var ecBlock = ecBlockArray[j]; - for (var i = 0; i < ecBlock.Count; i++) + for (var i = 0; i < ecBlock.getCount(); i++) { - var numDataCodewords = ecBlock.DataCodewords; - var numBlockCodewords = ecBlocks.ECCodewordsPerBlock + numDataCodewords; + var numDataCodewords = ecBlock.getDataCodewords(); + var numBlockCodewords = ecBlocks.getECCodewordsPerBlock() + numDataCodewords; result[numResultBlocks++] = new DataBlock(numDataCodewords, new Array(numBlockCodewords)); } } @@ -87,7 +87,7 @@ DataBlock.getDataBlocks=function(rawCodewords, version, ecLevel) } longerBlocksStartAt++; - var shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBlocks.ECCodewordsPerBlock; + var shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBlocks.getECCodewordsPerBlock(); // The last elements of result may be 1 element longer; // first fill out as many elements as all of them have var rawCodewordsOffset = 0; diff --git a/src/databr.js b/src/databr.js index 0abd9eb..9eeca58 100644 --- a/src/databr.js +++ b/src/databr.js @@ -264,7 +264,7 @@ function QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode) return intData; } - this.__defineGetter__("DataByte", function() + this.getDataByte = function() { var output = new Array(); var MODE_NUMBER = 1; @@ -332,5 +332,5 @@ function QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode) } while (true); return output; - }); + }; } diff --git a/src/decoder.js b/src/decoder.js index d0c1ed5..001b95b 100644 --- a/src/decoder.js +++ b/src/decoder.js @@ -58,7 +58,7 @@ Decoder.decode=function(bits) { var parser = new BitMatrixParser(bits); var version = parser.readVersion(); - var ecLevel = parser.readFormatInformation().ErrorCorrectionLevel; + var ecLevel = parser.readFormatInformation().getErrorCorrectionLevel(); // Read codewords var codewords = parser.readCodewords(); @@ -70,7 +70,7 @@ Decoder.decode=function(bits) var totalBytes = 0; for (var i = 0; i < dataBlocks.length; i++) { - totalBytes += dataBlocks[i].NumDataCodewords; + totalBytes += dataBlocks[i].getNumDataCodewords(); } var resultBytes = new Array(totalBytes); var resultOffset = 0; @@ -79,8 +79,8 @@ Decoder.decode=function(bits) for (var j = 0; j < dataBlocks.length; j++) { var dataBlock = dataBlocks[j]; - var codewordBytes = dataBlock.Codewords; - var numDataCodewords = dataBlock.NumDataCodewords; + var codewordBytes = dataBlock.getCodewords(); + var numDataCodewords = dataBlock.getNumDataCodewords(); Decoder.correctErrors(codewordBytes, numDataCodewords); for (var i = 0; i < numDataCodewords; i++) { @@ -89,7 +89,7 @@ Decoder.decode=function(bits) } // Decode the contents of that stream of bytes - var reader = new QRCodeDataBlockReader(resultBytes, version.VersionNumber, ecLevel.Bits); + var reader = new QRCodeDataBlockReader(resultBytes, version.getVersionNumber(), ecLevel.getBits()); return reader; //return DecodedBitStreamParser.decode(resultBytes, version, ecLevel); } diff --git a/src/detector.js b/src/detector.js index e201a3c..d8bf070 100644 --- a/src/detector.js +++ b/src/detector.js @@ -83,8 +83,8 @@ function PerspectiveTransform( a11, a21, a31, a12, a22, a32, a13, a23, a PerspectiveTransform.quadrilateralToQuadrilateral=function( x0, y0, x1, y1, x2, y2, x3, y3, x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p) { - var qToS = this.quadrilateralToSquare(x0, y0, x1, y1, x2, y2, x3, y3); - var sToQ = this.squareToQuadrilateral(x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p); + var qToS = PerspectiveTransform.quadrilateralToSquare(x0, y0, x1, y1, x2, y2, x3, y3); + var sToQ = PerspectiveTransform.squareToQuadrilateral(x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p); return sToQ.times(qToS); } @@ -112,7 +112,7 @@ PerspectiveTransform.squareToQuadrilateral=function( x0, y0, x1, y1, x2, y2 PerspectiveTransform.quadrilateralToSquare=function( x0, y0, x1, y1, x2, y2, x3, y3) { // Here, the adjoint serves as the inverse: - return this.squareToQuadrilateral(x0, y0, x1, y1, x2, y2, x3, y3).buildAdjoint(); + return PerspectiveTransform.squareToQuadrilateral(x0, y0, x1, y1, x2, y2, x3, y3).buildAdjoint(); } function DetectorResult(bits, points) @@ -234,8 +234,8 @@ function Detector(image) this.calculateModuleSizeOneWay=function( pattern, otherPattern) { - var moduleSizeEst1 = this.sizeOfBlackWhiteBlackRunBothWays(Math.floor( pattern.X), Math.floor( pattern.Y), Math.floor( otherPattern.X), Math.floor(otherPattern.Y)); - var moduleSizeEst2 = this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(otherPattern.X), Math.floor(otherPattern.Y), Math.floor( pattern.X), Math.floor(pattern.Y)); + var moduleSizeEst1 = this.sizeOfBlackWhiteBlackRunBothWays(Math.floor( pattern.getX()), Math.floor( pattern.getY()), Math.floor( otherPattern.getX()), Math.floor(otherPattern.getY())); + var moduleSizeEst2 = this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(otherPattern.getX()), Math.floor(otherPattern.getY()), Math.floor( pattern.getX()), Math.floor(pattern.getY())); if (isNaN(moduleSizeEst1)) { return moduleSizeEst2 / 7.0; @@ -258,8 +258,8 @@ function Detector(image) this.distance=function( pattern1, pattern2) { - var xDiff = pattern1.X - pattern2.X; - var yDiff = pattern1.Y - pattern2.Y; + var xDiff = pattern1.getX() - pattern2.getX(); + var yDiff = pattern1.getY() - pattern2.getY(); return Math.sqrt( (xDiff * xDiff + yDiff * yDiff)); } this.computeDimension=function( topLeft, topRight, bottomLeft, moduleSize) @@ -315,19 +315,19 @@ function Detector(image) var sourceBottomRightY; if (alignmentPattern != null) { - bottomRightX = alignmentPattern.X; - bottomRightY = alignmentPattern.Y; + bottomRightX = alignmentPattern.getX(); + bottomRightY = alignmentPattern.getY(); sourceBottomRightX = sourceBottomRightY = dimMinusThree - 3.0; } else { // Don't have an alignment pattern, just make up the bottom-right point - bottomRightX = (topRight.X - topLeft.X) + bottomLeft.X; - bottomRightY = (topRight.Y - topLeft.Y) + bottomLeft.Y; + bottomRightX = (topRight.getX() - topLeft.getX()) + bottomLeft.getX(); + bottomRightY = (topRight.getY() - topLeft.getY()) + bottomLeft.getY(); sourceBottomRightX = sourceBottomRightY = dimMinusThree; } - 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); + var transform = PerspectiveTransform.quadrilateralToQuadrilateral(3.5, 3.5, dimMinusThree, 3.5, sourceBottomRightX, sourceBottomRightY, 3.5, dimMinusThree, topLeft.getX(), topLeft.getY(), topRight.getX(), topRight.getY(), bottomRightX, bottomRightY, bottomLeft.getX(), bottomLeft.getY()); return transform; } @@ -342,9 +342,9 @@ function Detector(image) this.processFinderPatternInfo = function( info) { - var topLeft = info.TopLeft; - var topRight = info.TopRight; - var bottomLeft = info.BottomLeft; + var topLeft = info.getTopLeft(); + var topRight = info.getTopRight(); + var bottomLeft = info.getBottomLeft(); var moduleSize = this.calculateModuleSize(topLeft, topRight, bottomLeft); if (moduleSize < 1.0) @@ -353,22 +353,22 @@ function Detector(image) } var dimension = this.computeDimension(topLeft, topRight, bottomLeft, moduleSize); var provisionalVersion = Version.getProvisionalVersionForDimension(dimension); - var modulesBetweenFPCenters = provisionalVersion.DimensionForVersion - 7; + var modulesBetweenFPCenters = provisionalVersion.getDimensionForVersion() - 7; var alignmentPattern = null; // Anything above version 1 has an alignment pattern - if (provisionalVersion.AlignmentPatternCenters.length > 0) + if (provisionalVersion.getAlignmentPatternCenters().length > 0) { // Guess where a "bottom right" finder pattern would have been - var bottomRightX = topRight.X - topLeft.X + bottomLeft.X; - var bottomRightY = topRight.Y - topLeft.Y + bottomLeft.Y; + var bottomRightX = topRight.getX() - topLeft.getX() + bottomLeft.getX(); + var bottomRightY = topRight.getY() - topLeft.getY() + bottomLeft.getY(); // Estimate that alignment pattern is closer by 3 modules // from "bottom right" to known top left location var correctionToTopLeft = 1.0 - 3.0 / modulesBetweenFPCenters; - var estAlignmentX = Math.floor (topLeft.X + correctionToTopLeft * (bottomRightX - topLeft.X)); - var estAlignmentY = Math.floor (topLeft.Y + correctionToTopLeft * (bottomRightY - topLeft.Y)); + var estAlignmentX = Math.floor (topLeft.getX() + correctionToTopLeft * (bottomRightX - topLeft.getX())); + var estAlignmentY = Math.floor (topLeft.getY() + correctionToTopLeft * (bottomRightY - topLeft.getY())); // Kind of arbitrary -- expand search radius before giving up for (var i = 4; i <= 16; i <<= 1) diff --git a/src/errorlevel.js b/src/errorlevel.js index 4bb60b3..4ec05a7 100644 --- a/src/errorlevel.js +++ b/src/errorlevel.js @@ -28,14 +28,14 @@ function ErrorCorrectionLevel(ordinal, bits, name) this.ordinal_Renamed_Field = ordinal; this.bits = bits; this.name = name; - this.__defineGetter__("Bits", function() + this.getBits = function() { return this.bits; - }); - this.__defineGetter__("Name", function() + }; + this.getName = function() { return this.name; - }); + }; this.ordinal=function() { return this.ordinal_Renamed_Field; diff --git a/src/findpat.js b/src/findpat.js index 8d4c1bc..f09089c 100644 --- a/src/findpat.js +++ b/src/findpat.js @@ -32,8 +32,8 @@ qrcode.orderBestPatterns=function(patterns) function distance( pattern1, pattern2) { - var xDiff = pattern1.X - pattern2.X; - var yDiff = pattern1.Y - pattern2.Y; + var xDiff = pattern1.getX() - pattern2.getX(); + var yDiff = pattern1.getY() - pattern2.getY(); return Math.sqrt( (xDiff * xDiff + yDiff * yDiff)); } @@ -96,22 +96,22 @@ function FinderPattern(posX, posY, estimatedModuleSize) this.count = 1; this.estimatedModuleSize = estimatedModuleSize; - this.__defineGetter__("EstimatedModuleSize", function() + this.getEstimatedModuleSize = function() { return this.estimatedModuleSize; - }); - this.__defineGetter__("Count", function() + }; + this.getCount = function() { return this.count; - }); - this.__defineGetter__("X", function() + }; + this.getX = function() { return this.x; - }); - this.__defineGetter__("Y", function() + }; + this.getY = function() { return this.y; - }); + }; this.incrementCount = function() { this.count++; @@ -133,18 +133,18 @@ function FinderPatternInfo(patternCenters) this.bottomLeft = patternCenters[0]; this.topLeft = patternCenters[1]; this.topRight = patternCenters[2]; - this.__defineGetter__("BottomLeft", function() + this.getBottomLeft = function() { return this.bottomLeft; - }); - this.__defineGetter__("TopLeft", function() + }; + this.getTopLeft = function() { return this.topLeft; - }); - this.__defineGetter__("TopRight", function() + }; + this.getTopRight = function() { return this.topRight; - }); + }; } /** @@ -162,7 +162,7 @@ function FinderPatternFinder() this.crossCheckStateCount = new Array(0,0,0,0,0); this.resultPointCallback = null; - this.__defineGetter__("CrossCheckStateCount", function() + this.getCrossCheckStateCount = function() { this.crossCheckStateCount[0] = 0; this.crossCheckStateCount[1] = 0; @@ -170,7 +170,7 @@ function FinderPatternFinder() this.crossCheckStateCount[3] = 0; this.crossCheckStateCount[4] = 0; return this.crossCheckStateCount; - }); + }; this.foundPatternCross=function( stateCount) { @@ -206,7 +206,7 @@ function FinderPatternFinder() var image = this.image; var maxI = qrcode.height; - var stateCount = this.CrossCheckStateCount; + var stateCount = this.getCrossCheckStateCount(); // Start counting up from center var i = startI; @@ -284,7 +284,7 @@ function FinderPatternFinder() var image = this.image; var maxJ = qrcode.width; - var stateCount = this.CrossCheckStateCount; + var stateCount = this.getCrossCheckStateCount(); var j = startJ; while (j >= 0 && image[j+ centerI*qrcode.width]) @@ -412,15 +412,15 @@ function FinderPatternFinder() var square = 0.0; for (var i = 0; i < startSize; i++) { - //totalModuleSize += this.possibleCenters[i].EstimatedModuleSize; - var centerValue=this.possibleCenters[i].EstimatedModuleSize; + //totalModuleSize += this.possibleCenters[i].getEstimatedModuleSize(); + var centerValue=this.possibleCenters[i].getEstimatedModuleSize(); totalModuleSize += centerValue; square += (centerValue * centerValue); } var average = totalModuleSize / startSize; this.possibleCenters.sort(function(center1,center2) { - var dA=Math.abs(center2.EstimatedModuleSize - average); - var dB=Math.abs(center1.EstimatedModuleSize - average); + var dA=Math.abs(center2.getEstimatedModuleSize() - average); + var dB=Math.abs(center1.getEstimatedModuleSize() - average); if (dA < dB) { return (-1); } else if (dA == dB) { @@ -436,8 +436,8 @@ function FinderPatternFinder() for (var i = this.possibleCenters.length - 1; i >= 0 ; i--) { var pattern = this.possibleCenters[i]; - //if (Math.abs(pattern.EstimatedModuleSize - average) > 0.2 * average) - if (Math.abs(pattern.EstimatedModuleSize - average) > limit) + //if (Math.abs(pattern.getEstimatedModuleSize() - average) > 0.2 * average) + if (Math.abs(pattern.getEstimatedModuleSize() - average) > limit) { //this.possibleCenters.remove(i); this.possibleCenters.splice(i,1); @@ -470,7 +470,7 @@ function FinderPatternFinder() for (var i = 0; i < max; i++) { var center = this.possibleCenters[i]; - if (center.Count >= CENTER_QUORUM) + if (center.getCount() >= CENTER_QUORUM) { if (firstConfirmedCenter == null) { @@ -484,7 +484,7 @@ function FinderPatternFinder() // difference in the x / y coordinates of the two centers. // This is the case where you find top left last. this.hasSkipped = true; - return Math.floor ((Math.abs(firstConfirmedCenter.X - center.X) - Math.abs(firstConfirmedCenter.Y - center.Y)) / 2); + return Math.floor ((Math.abs(firstConfirmedCenter.getX() - center.getX()) - Math.abs(firstConfirmedCenter.getY() - center.getY())) / 2); } } } @@ -499,10 +499,10 @@ function FinderPatternFinder() for (var i = 0; i < max; i++) { var pattern = this.possibleCenters[i]; - if (pattern.Count >= CENTER_QUORUM) + if (pattern.getCount() >= CENTER_QUORUM) { confirmedCount++; - totalModuleSize += pattern.EstimatedModuleSize; + totalModuleSize += pattern.getEstimatedModuleSize(); } } if (confirmedCount < 3) @@ -518,7 +518,7 @@ function FinderPatternFinder() for (var i = 0; i < max; i++) { pattern = this.possibleCenters[i]; - totalDeviation += Math.abs(pattern.EstimatedModuleSize - average); + totalDeviation += Math.abs(pattern.getEstimatedModuleSize() - average); } return totalDeviation <= 0.05 * totalModuleSize; } diff --git a/src/formatinf.js b/src/formatinf.js index 62266a4..1373f59 100644 --- a/src/formatinf.js +++ b/src/formatinf.js @@ -33,14 +33,14 @@ function FormatInformation(formatInfo) this.errorCorrectionLevel = ErrorCorrectionLevel.forBits((formatInfo >> 3) & 0x03); this.dataMask = (formatInfo & 0x07); - this.__defineGetter__("ErrorCorrectionLevel", function() + this.getErrorCorrectionLevel = function() { return this.errorCorrectionLevel; - }); - this.__defineGetter__("DataMask", function() + }; + this.getDataMask = function() { return this.dataMask; - }); + }; this.GetHashCode=function() { return (this.errorCorrectionLevel.ordinal() << 3) | this.dataMask; @@ -85,7 +85,7 @@ FormatInformation.doDecodeFormatInformation=function( maskedFormatInfo) // Found an exact match return new FormatInformation(decodeInfo[1]); } - var bitsDifference = this.numBitsDiffering(maskedFormatInfo, targetInfo); + var bitsDifference = FormatInformation.numBitsDiffering(maskedFormatInfo, targetInfo); if (bitsDifference < bestDifference) { bestFormatInfo = decodeInfo[1]; diff --git a/src/gf256.js b/src/gf256.js index fe89d3f..89538c1 100644 --- a/src/gf256.js +++ b/src/gf256.js @@ -47,14 +47,14 @@ function GF256( primitive) var at1=new Array(1);at1[0]=1; this.one = new GF256Poly(this, new Array(at1)); - this.__defineGetter__("Zero", function() + this.getZero = function() { return this.zero; - }); - this.__defineGetter__("One", function() + }; + this.getOne = function() { return this.one; - }); + }; this.buildMonomial=function( degree, coefficient) { if (degree < 0) diff --git a/src/gf256poly.js b/src/gf256poly.js index 0e1fd89..ce5ccdf 100644 --- a/src/gf256poly.js +++ b/src/gf256poly.js @@ -41,7 +41,7 @@ function GF256Poly(field, coefficients) } if (firstNonZero == coefficientsLength) { - this.coefficients = field.Zero.coefficients; + this.coefficients = field.getZero().coefficients; } else { @@ -56,18 +56,18 @@ function GF256Poly(field, coefficients) this.coefficients = coefficients; } - this.__defineGetter__("Zero", function() + this.getZero = function() { return this.coefficients[0] == 0; - }); - this.__defineGetter__("Degree", function() + }; + this.getDegree = function() { return this.coefficients.length - 1; - }); - this.__defineGetter__("Coefficients", function() + }; + this.getCoefficients = function() { return this.coefficients; - }); + }; this.getCoefficient=function( degree) { @@ -106,11 +106,11 @@ function GF256Poly(field, coefficients) { throw new Error("QR Error: GF256Polys do not have same GF256 field"); } - if (this.Zero) + if (this.getZero()) { return other; } - if (other.Zero) + if (other.getZero()) { return this; } @@ -142,9 +142,9 @@ function GF256Poly(field, coefficients) { throw new Error("QR Error: GF256Polys do not have same GF256 field"); } - if (this.Zero || other.Zero) + if (this.getZero() || other.getZero()) { - return this.field.Zero; + return this.field.getZero(); } var aCoefficients = this.coefficients; var aLength = aCoefficients.length; @@ -165,7 +165,7 @@ function GF256Poly(field, coefficients) { if (scalar == 0) { - return this.field.Zero; + return this.field.getZero(); } if (scalar == 1) { @@ -187,7 +187,7 @@ function GF256Poly(field, coefficients) } if (coefficient == 0) { - return this.field.Zero; + return this.field.getZero(); } var size = this.coefficients.length; var product = new Array(size + degree); @@ -204,21 +204,21 @@ function GF256Poly(field, coefficients) { throw new Error("QR Error: GF256Polys do not have same GF256 field"); } - if (other.Zero) + if (other.getZero()) { throw new Error("QR Error: Divide by 0"); } - var quotient = this.field.Zero; + var quotient = this.field.getZero(); var remainder = this; - var denominatorLeadingTerm = other.getCoefficient(other.Degree); + var denominatorLeadingTerm = other.getCoefficient(other.getDegree()); var inverseDenominatorLeadingTerm = this.field.inverse(denominatorLeadingTerm); - while (remainder.Degree >= other.Degree && !remainder.Zero) + while (remainder.getDegree() >= other.getDegree() && !remainder.getZero()) { - var degreeDifference = remainder.Degree - other.Degree; - var scale = this.field.multiply(remainder.getCoefficient(remainder.Degree), inverseDenominatorLeadingTerm); + var degreeDifference = remainder.getDegree() - other.getDegree(); + var scale = this.field.multiply(remainder.getCoefficient(remainder.getDegree()), inverseDenominatorLeadingTerm); var term = other.multiplyByMonomial(degreeDifference, scale); var iterationQuotient = this.field.buildMonomial(degreeDifference, scale); quotient = quotient.addOrSubtract(iterationQuotient); diff --git a/src/prefix.js b/src/prefix.js deleted file mode 100644 index 7410c62..0000000 --- a/src/prefix.js +++ /dev/null @@ -1 +0,0 @@ -(function() { \ No newline at end of file diff --git a/src/qrcode.js b/src/qrcode.js index 6def9dc..197d6c5 100644 --- a/src/qrcode.js +++ b/src/qrcode.js @@ -116,8 +116,8 @@ qrcode.process = function(){ var qRCodeMatrix = detector.detect(); // throws if no qr code was found if (qrcode.debug) { - for (var y = 0; y < qRCodeMatrix.bits.Height; y++) { - for (var x = 0; x < qRCodeMatrix.bits.Width; x++) { + for (var y = 0; y < qRCodeMatrix.bits.getHeight(); y++) { + for (var x = 0; x < qRCodeMatrix.bits.getWidth(); x++) { var point = (x * 4 * 2) + (y * 2 * qrcode.width * 4); var isSet = qRCodeMatrix.bits.get_Renamed(x, y) debugImage.data[point] = isSet ? 0 : 255; @@ -135,7 +135,7 @@ qrcode.process = function(){ var reader = Decoder.decode(qRCodeMatrix.bits); - var data = reader.DataByte; + var data = reader.getDataByte(); var str=""; for(var i=0;i= b's - if (a.Degree < b.Degree) + if (a.getDegree() < b.getDegree()) { var temp = a; a = b; @@ -76,13 +76,13 @@ function ReedSolomonDecoder(field) var rLast = a; var r = b; - var sLast = this.field.One; - var s = this.field.Zero; - var tLast = this.field.Zero; - var t = this.field.One; + var sLast = this.field.getOne(); + var s = this.field.getZero(); + var tLast = this.field.getZero(); + var t = this.field.getOne(); // Run Euclidean algorithm until r's degree is less than R/2 - while (r.Degree >= Math.floor(R / 2)) + while (r.getDegree() >= Math.floor(R / 2)) { var rLastLast = rLast; var sLastLast = sLast; @@ -92,19 +92,19 @@ function ReedSolomonDecoder(field) tLast = t; // Divide rLastLast by rLast, with quotient in q and remainder in r - if (rLast.Zero) + if (rLast.getZero()) { // Oops, Euclidean algorithm already terminated? throw new Error("QR Error: r_{i-1} was zero"); } r = rLastLast; - var q = this.field.Zero; - var denominatorLeadingTerm = rLast.getCoefficient(rLast.Degree); + var q = this.field.getZero(); + var denominatorLeadingTerm = rLast.getCoefficient(rLast.getDegree()); var dltInverse = this.field.inverse(denominatorLeadingTerm); - while (r.Degree >= rLast.Degree && !r.Zero) + while (r.getDegree() >= rLast.getDegree() && !r.getZero()) { - var degreeDiff = r.Degree - rLast.Degree; - var scale = this.field.multiply(r.getCoefficient(r.Degree), dltInverse); + var degreeDiff = r.getDegree() - rLast.getDegree(); + var scale = this.field.multiply(r.getCoefficient(r.getDegree()), dltInverse); q = q.addOrSubtract(this.field.buildMonomial(degreeDiff, scale)); r = r.addOrSubtract(rLast.multiplyByMonomial(degreeDiff, scale)); //r.EXE(); @@ -128,7 +128,7 @@ function ReedSolomonDecoder(field) this.findErrorLocations=function( errorLocator) { // This is a direct application of Chien's search - var numErrors = errorLocator.Degree; + var numErrors = errorLocator.getDegree(); if (numErrors == 1) { // shortcut diff --git a/src/suffix.js b/src/suffix.js deleted file mode 100644 index 158693a..0000000 --- a/src/suffix.js +++ /dev/null @@ -1 +0,0 @@ -})(); \ No newline at end of file diff --git a/src/version.js b/src/version.js index fd073f1..a2720a3 100644 --- a/src/version.js +++ b/src/version.js @@ -29,14 +29,14 @@ function ECB(count, dataCodewords) this.count = count; this.dataCodewords = dataCodewords; - this.__defineGetter__("Count", function() + this.getCount = function() { return this.count; - }); - this.__defineGetter__("DataCodewords", function() + }; + this.getDataCodewords = function() { return this.dataCodewords; - }); + }; } function ECBlocks( ecCodewordsPerBlock, ecBlocks1, ecBlocks2) @@ -47,17 +47,17 @@ function ECBlocks( ecCodewordsPerBlock, ecBlocks1, ecBlocks2) else this.ecBlocks = new Array(ecBlocks1); - this.__defineGetter__("ECCodewordsPerBlock", function() + this.getECCodewordsPerBlock = function() { return this.ecCodewordsPerBlock; - }); + }; - this.__defineGetter__("TotalECCodewords", function() + this.getTotalECCodewords = function() { - return this.ecCodewordsPerBlock * this.NumBlocks; - }); + return this.ecCodewordsPerBlock * this.getNumBlocks(); + }; - this.__defineGetter__("NumBlocks", function() + this.getNumBlocks = function() { var total = 0; for (var i = 0; i < this.ecBlocks.length; i++) @@ -65,7 +65,7 @@ function ECBlocks( ecCodewordsPerBlock, ecBlocks1, ecBlocks2) total += this.ecBlocks[i].length; } return total; - }); + }; this.getECBlocks=function() { @@ -80,36 +80,36 @@ function Version( versionNumber, alignmentPatternCenters, ecBlocks1, ecBlocks this.ecBlocks = new Array(ecBlocks1, ecBlocks2, ecBlocks3, ecBlocks4); var total = 0; - var ecCodewords = ecBlocks1.ECCodewordsPerBlock; + var ecCodewords = ecBlocks1.getECCodewordsPerBlock(); var ecbArray = ecBlocks1.getECBlocks(); for (var i = 0; i < ecbArray.length; i++) { var ecBlock = ecbArray[i]; - total += ecBlock.Count * (ecBlock.DataCodewords + ecCodewords); + total += ecBlock.getCount() * (ecBlock.getDataCodewords() + ecCodewords); } this.totalCodewords = total; - this.__defineGetter__("VersionNumber", function() + this.getVersionNumber = function() { return this.versionNumber; - }); + }; - this.__defineGetter__("AlignmentPatternCenters", function() + this.getAlignmentPatternCenters = function() { return this.alignmentPatternCenters; - }); - this.__defineGetter__("TotalCodewords", function() + }; + this.getTotalCodewords = function() { return this.totalCodewords; - }); - this.__defineGetter__("DimensionForVersion", function() + }; + this.getDimensionForVersion = function() { return 17 + 4 * this.versionNumber; - }); + }; this.buildFunctionPattern=function() { - var dimension = this.DimensionForVersion; + var dimension = this.getDimensionForVersion(); var bitMatrix = new BitMatrix(dimension); // Top left finder pattern + separator + format @@ -195,7 +195,7 @@ Version.decodeVersionInformation=function( versionBits) // Do the version info bits match exactly? done. if (targetVersion == versionBits) { - return this.getVersionForNumber(i + 7); + return Version.getVersionForNumber(i + 7); } // Otherwise see if this is the closest to a real version info bit string // we have seen so far @@ -210,7 +210,7 @@ Version.decodeVersionInformation=function( versionBits) // differ in less than 4 bits. if (bestDifference <= 3) { - return this.getVersionForNumber(bestVersion); + return Version.getVersionForNumber(bestVersion); } // If we didn't find a close enough match, fail return null;