angular2-qrscanner
Version:
QrScanner will scan for a QRCode from your Web-cam and return its string representation by drawing the captured image onto a 2D Canvas and use [@LazarSoft/jsqrcode](https://github.com/LazarSoft/jsqrcode) to check for a valid QRCode every *Xms*
1 lines • 52.7 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("rxjs"),require("@angular/common")):"function"==typeof define&&define.amd?define("angular2-qrscanner",["exports","@angular/core","rxjs","@angular/common"],t):t(e["angular2-qrscanner"]={},e.ng.core,e.rxjs,e.ng.common)}(this,function(e,t,n,r){"use strict";var f=function(){function e(e,t,n){this.count=1,this.incrementCount=function(){this.count++},this.aboutEquals=function(e,t,n){if(Math.abs(t-this.y)<=e&&Math.abs(n-this.x)<=e){var r=Math.abs(e-this.estimatedModuleSize);return r<=1||r/this.estimatedModuleSize<=1}return!1},this.x=e,this.y=t,this.estimatedModuleSize=n}return Object.defineProperty(e.prototype,"EstimatedModuleSize",{get:function(){return this.estimatedModuleSize},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"Count",{get:function(){return this.count},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"X",{get:function(){return Math.floor(this.x)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"Y",{get:function(){return Math.floor(this.y)},enumerable:!0,configurable:!0}),e}(),u=function(e,t,n,r,i,o,a,s,h){this.possibleCenters=new Array,this.crossCheckStateCount=new Array(0,0,0),this.centerFromEnd=function(e,t){return t-e[2]-e[1]/2},this.foundPatternCross=function(e){for(var t=this.moduleSize,n=t/2,r=0;r<3;r++)if(Math.abs(t-e[r])>=n)return!1;return!0},this.crossCheckVertical=function(e,t,n,r){var i=this.image,o=this.imageHeight,a=this.crossCheckStateCount;a[0]=0,a[1]=0,a[2]=0;for(var s=e;0<=s&&i[t+s*this.imageWidth]&&a[1]<=n;)a[1]++,s--;if(s<0||a[1]>n)return NaN;for(;0<=s&&!i[t+s*this.imageWidth]&&a[0]<=n;)a[0]++,s--;if(a[0]>n)return NaN;for(s=e+1;s<o&&i[t+s*this.imageWidth]&&a[1]<=n;)a[1]++,s++;if(s==o||a[1]>n)return NaN;for(;s<o&&!i[t+s*this.imageWidth]&&a[2]<=n;)a[2]++,s++;if(a[2]>n)return NaN;var h=a[0]+a[1]+a[2];return 5*Math.abs(h-r)>=2*r?NaN:this.foundPatternCross(a)?this.centerFromEnd(a,s):NaN},this.handlePossibleCenter=function(e,t,n){var r=e[0]+e[1]+e[2],i=this.centerFromEnd(e,n),o=this.crossCheckVertical(t,Math.floor(i),2*e[1],r);if(!isNaN(o)){for(var a=(e[0]+e[1]+e[2])/3,s=this.possibleCenters.length,h=0;h<s;h++)if(this.possibleCenters[h].aboutEquals(a,o,i))return new f(i,o,a);var u=new f(i,o,a);this.possibleCenters.push(u),null!=this.resultPointCallback&&this.resultPointCallback.foundPossibleResultPoint(u)}return null},this.find=function(){for(var e=this.startX,t=this.height,n=e+this.width,r=this.startY+(t>>1),i=new Array(0,0,0),o=0;o<t;o++){var a=r+(0==(1&o)?o+1>>1:-(o+1>>1));i[0]=0,i[1]=0,i[2]=0;for(var s=e;s<n&&!this.image[s+this.imageWidth*a];)s++;for(var h=0;s<n;){if(this.image[s+a*this.imageWidth])if(1==h)i[h]++;else if(2==h){var u;if(this.foundPatternCross(i)&&null!=(u=this.handlePossibleCenter(i,a,s)))return u;i[0]=i[2],i[1]=1,i[2]=0,h=1}else i[++h]++;else 1==h&&h++,i[h]++;s++}if(this.foundPatternCross(i)&&null!=(u=this.handlePossibleCenter(i,a,n)))return u}if(0!=this.possibleCenters.length)return this.possibleCenters[0];throw"Couldn't find enough alignment patterns"},this.image=e,this.startX=t,this.startY=n,this.width=r,this.height=i,this.moduleSize=o,this.resultPointCallback=h,this.imageWidth=a,this.imageHeight=s},v=function(){function m(e,t,n,r,i,o,a,s,h){this.transformPoints1=function(e){for(var t=e.length,n=this.a11,r=this.a12,i=this.a13,o=this.a21,a=this.a22,s=this.a23,h=this.a31,u=this.a32,f=this.a33,w=0;w<t;w+=2){var c=e[w],l=e[w+1],d=i*c+s*l+f;e[w]=(n*c+o*l+h)/d,e[w+1]=(r*c+a*l+u)/d}},this.transformPoints2=function(e,t){for(var n=e.length,r=0;r<n;r++){var i=e[r],o=t[r],a=this.a13*i+this.a23*o+this.a33;e[r]=(this.a11*i+this.a21*o+this.a31)/a,t[r]=(this.a12*i+this.a22*o+this.a32)/a}},this.buildAdjoint=function(){return new m(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)},this.times=function(e){return new m(this.a11*e.a11+this.a21*e.a12+this.a31*e.a13,this.a11*e.a21+this.a21*e.a22+this.a31*e.a23,this.a11*e.a31+this.a21*e.a32+this.a31*e.a33,this.a12*e.a11+this.a22*e.a12+this.a32*e.a13,this.a12*e.a21+this.a22*e.a22+this.a32*e.a23,this.a12*e.a31+this.a22*e.a32+this.a32*e.a33,this.a13*e.a11+this.a23*e.a12+this.a33*e.a13,this.a13*e.a21+this.a23*e.a22+this.a33*e.a23,this.a13*e.a31+this.a23*e.a32+this.a33*e.a33)},this.a11=e,this.a12=r,this.a13=a,this.a21=t,this.a22=i,this.a23=s,this.a31=n,this.a32=o,this.a33=h}return m.quadrilateralToQuadrilateral=function(e,t,n,r,i,o,a,s,h,u,f,w,c,l,d,p){var g=this.quadrilateralToSquare(e,t,n,r,i,o,a,s);return this.squareToQuadrilateral(h,u,f,w,c,l,d,p).times(g)},m.squareToQuadrilateral=function(e,t,n,r,i,o,a,s){var h=s-o,u=t-r+o-s;if(0==h&&0==u)return new m(n-e,i-n,e,r-t,o-r,t,0,0,1);var f=n-i,w=a-i,c=e-n+i-a,l=r-o,d=f*h-w*l,p=(c*h-w*u)/d,g=(f*u-c*l)/d;return new m(n-e+p*n,a-e+g*a,e,r-t+p*r,s-t+g*s,t,p,g,1)},m.quadrilateralToSquare=function(e,t,n,r,i,o,a,s){return this.squareToQuadrilateral(e,t,n,r,i,o,a,s).buildAdjoint()},m}(),l=function(){function e(e,t){if(t||(t=e),e<1||t<1)throw"Both dimensions must be greater than 0";this.width=e,this.height=t,this.rowSize=e>>5,0!=(31&e)&&this.rowSize++,this.bits=new Array(this.rowSize*t);for(var n=0;n<this.bits.length;n++)this.bits[n]=0}return Object.defineProperty(e.prototype,"Width",{get:function(){return this.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"Height",{get:function(){return this.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"Dimension",{get:function(){if(this.width!=this.height)throw"Can't call getDimension() on a non-square matrix";return this.width},enumerable:!0,configurable:!0}),e.prototype.URShift=function(e,t){return 0<=e?e>>t:(e>>t)+(2<<~t)},e.prototype.get_Renamed=function(e,t){var n=t*this.rowSize+(e>>5);return 0!=(1&this.URShift(this.bits[n],31&e))},e.prototype.set_Renamed=function(e,t){var n=t*this.rowSize+(e>>5);this.bits[n]|=1<<(31&e)},e.prototype.flip=function(e,t){var n=t*this.rowSize+(e>>5);this.bits[n]^=1<<(31&e)},e.prototype.clear=function(){for(var e=this.bits.length,t=0;t<e;t++)this.bits[t]=0},e.prototype.setRegion=function(e,t,n,r){if(t<0||e<0)throw"Left and top must be nonnegative";if(r<1||n<1)throw"Height and width must be at least 1";var i=e+n,o=t+r;if(o>this.height||i>this.width)throw"The region must fit inside the matrix";for(var a=t;a<o;a++)for(var s=a*this.rowSize,h=e;h<i;h++)this.bits[s+(h>>5)]|=1<<(31&h)},e}(),i=function(){function e(e,t){this.width=e,this.height=t}return e.prototype.checkAndNudgePoints=function(e,t){for(var n=this.width,r=this.height,i=!0,o=0;o<t.length&&i;o+=2){var a=Math.floor(t[o]),s=Math.floor(t[o+1]);if(a<-1||n<a||s<-1||r<s)throw"Error.checkAndNudgePoints ";i=!1,-1==a?i=!(t[o]=0):a==n&&(t[o]=n-1,i=!0),-1==s?i=!(t[o+1]=0):s==r&&(t[o+1]=r-1,i=!0)}i=!0;for(o=t.length-2;0<=o&&i;o-=2){a=Math.floor(t[o]),s=Math.floor(t[o+1]);if(a<-1||n<a||s<-1||r<s)throw"Error.checkAndNudgePoints ";i=!1,-1==a?i=!(t[o]=0):a==n&&(t[o]=n-1,i=!0),-1==s?i=!(t[o+1]=0):s==r&&(t[o+1]=r-1,i=!0)}},e.prototype.sampleGrid3=function(e,t,n,r){for(var i=new l(n,n),o=new Array(n<<1),a=0;a<n;a++){for(var s=o.length,h=a+.5,u=0;u<s;u+=2)o[u]=.5+(u>>1),o[u+1]=h;r.transformPoints1(o),this.checkAndNudgePoints(e,o);try{for(u=0;u<s;u+=2){var f=4*Math.floor(o[u])+Math.floor(o[u+1])*this.width*4,w=e[Math.floor(o[u])+this.width*Math.floor(o[u+1])];t.data[f]=w?255:0,t.data[f+1]=w?255:0,t.data[f+2]=0,t.data[f+3]=255,w&&i.set_Renamed(u>>1,a)}}catch(c){throw"Error.checkAndNudgePoints"}}return i},e.prototype.sampleGridx=function(e,t,n,r,i,o,a,s,h,u,f,w,c,l,d,p,g,m){var y=v.quadrilateralToQuadrilateral(n,r,i,o,a,s,h,u,f,w,c,l,d,p,g,m);return this.sampleGrid3(e,{},t,y)},e}(),o=function(){function e(e,t,n){this.ordinal_Renamed_Field=e,this.bits=t,this.name=n}return e.forBits=function(e){if(e<0||e>=this.FOR_BITS.length)throw"ArgumentException";return this.FOR_BITS[e]},Object.defineProperty(e.prototype,"Bits",{get:function(){return this.bits},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"Name",{get:function(){return this.name},enumerable:!0,configurable:!0}),e.prototype.ordinal=function(){return this.ordinal_Renamed_Field},e}();o.L=new o(0,1,"L"),o.M=new o(1,0,"M"),o.Q=new o(2,3,"Q"),o.H=new o(3,2,"H"),o.FOR_BITS=new Array(o.M,o.L,o.H,o.Q);var s=function(){function s(e){this.Equals=function(e){var t=e;return this.errorCorrectionLevel==t.errorCorrectionLevel&&this.dataMask==t.dataMask},this.errorCorrectionLevel=o.forBits(e>>3&3),this.dataMask=7&e}return Object.defineProperty(s.prototype,"ErrorCorrectionLevel",{get:function(){return this.errorCorrectionLevel},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"DataMask",{get:function(){return this.dataMask},enumerable:!0,configurable:!0}),s.prototype.GetHashCode=function(){return this.errorCorrectionLevel.ordinal()<<3|this.dataMask},s.URShift=function(e,t){return 0<=e?e>>t:(e>>t)+(2<<~t)},s.numBitsDiffering=function(e,t){return s.BITS_SET_IN_HALF_BYTE[15&(e^=t)]+s.BITS_SET_IN_HALF_BYTE[15&this.URShift(e,4)]+s.BITS_SET_IN_HALF_BYTE[15&this.URShift(e,8)]+s.BITS_SET_IN_HALF_BYTE[15&this.URShift(e,12)]+s.BITS_SET_IN_HALF_BYTE[15&this.URShift(e,16)]+s.BITS_SET_IN_HALF_BYTE[15&this.URShift(e,20)]+s.BITS_SET_IN_HALF_BYTE[15&this.URShift(e,24)]+s.BITS_SET_IN_HALF_BYTE[15&this.URShift(e,28)]},s.decodeFormatInformation=function(e){var t=this.doDecodeFormatInformation(e);return null!=t?t:this.doDecodeFormatInformation(e^s.FORMAT_INFO_MASK_QR)},s.doDecodeFormatInformation=function(e){for(var t=4294967295,n=0,r=0;r<s.FORMAT_INFO_DECODE_LOOKUP.length;r++){var i=s.FORMAT_INFO_DECODE_LOOKUP[r],o=i[0];if(o==e)return new s(i[1]);var a=s.numBitsDiffering(e,o);a<t&&(n=i[1],t=a)}return t<=3?new s(n):null},s.forBits=function(e){if(e<0||e>=s.FOR_BITS.length)throw"ArgumentException";return s.FOR_BITS[e]},s}();s.FORMAT_INFO_MASK_QR=21522,s.FORMAT_INFO_DECODE_LOOKUP=new Array(new Array(21522,0),new Array(20773,1),new Array(24188,2),new Array(23371,3),new Array(17913,4),new Array(16590,5),new Array(20375,6),new Array(19104,7),new Array(30660,8),new Array(29427,9),new Array(32170,10),new Array(30877,11),new Array(26159,12),new Array(25368,13),new Array(27713,14),new Array(26998,15),new Array(5769,16),new Array(5054,17),new Array(7399,18),new Array(6608,19),new Array(1890,20),new Array(597,21),new Array(3340,22),new Array(2107,23),new Array(13663,24),new Array(12392,25),new Array(16177,26),new Array(14854,27),new Array(9396,28),new Array(8579,29),new Array(11994,30),new Array(11245,31)),s.BITS_SET_IN_HALF_BYTE=new Array(0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4),s.L=new o(0,1,"L"),s.M=new o(1,0,"M"),s.Q=new o(2,3,"Q"),s.H=new o(3,2,"H"),s.FOR_BITS=new Array(s.M,s.L,s.H,s.Q);var h=function(){function e(e,t){this.count=e,this.dataCodewords=t}return Object.defineProperty(e.prototype,"Count",{get:function(){return this.count},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"DataCodewords",{get:function(){return this.dataCodewords},enumerable:!0,configurable:!0}),e}(),w=function(){function e(e,t,n){this.getECBlocks=function(){return this.ecBlocks},this.ecCodewordsPerBlock=e,this.ecBlocks=n?new Array(t,n):new Array(t)}return Object.defineProperty(e.prototype,"ECCodewordsPerBlock",{get:function(){return this.ecCodewordsPerBlock},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"TotalECCodewords",{get:function(){return this.ecCodewordsPerBlock*this.NumBlocks},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"NumBlocks",{get:function(){for(var e=0,t=0;t<this.ecBlocks.length;t++)e+=this.ecBlocks[t].length;return e},enumerable:!0,configurable:!0}),e}(),y=function(){function a(e,t,n,r,i,o){this.buildFunctionPattern=function(){var e=this.DimensionForVersion,t=new l(e);t.setRegion(0,0,9,9),t.setRegion(e-8,0,8,9),t.setRegion(0,e-8,9,8);for(var n=this.alignmentPatternCenters.length,r=0;r<n;r++)for(var i=this.alignmentPatternCenters[r]-2,o=0;o<n;o++)0==r&&(0==o||o==n-1)||r==n-1&&0==o||t.setRegion(this.alignmentPatternCenters[o]-2,i,5,5);return t.setRegion(6,9,1,e-17),t.setRegion(9,6,e-17,1),6<this.versionNumber&&(t.setRegion(e-11,0,3,6),t.setRegion(0,e-11,6,3)),t},this.getECBlocksForLevel=function(e){return this.ecBlocks[e.ordinal()]},this.versionNumber=e,this.alignmentPatternCenters=t,this.ecBlocks=new Array(n,r,i,o);for(var a=0,s=n.ECCodewordsPerBlock,h=n.getECBlocks(),u=0;u<h.length;u++){var f=h[u];a+=f.Count*(f.DataCodewords+s)}this.totalCodewords=a}return Object.defineProperty(a.prototype,"VersionNumber",{get:function(){return this.versionNumber},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"AlignmentPatternCenters",{get:function(){return this.alignmentPatternCenters},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"TotalCodewords",{get:function(){return this.totalCodewords},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"DimensionForVersion",{get:function(){return 17+4*this.versionNumber},enumerable:!0,configurable:!0}),a.getVersionForNumber=function(e){if(e<1||40<e)throw"ArgumentException";return a.VERSIONS[e-1]},a.getProvisionalVersionForDimension=function(e){if(e%4!=1)throw"Error getProvisionalVersionForDimension";try{return a.getVersionForNumber(e-17>>2)}catch(t){throw"Error getVersionForNumber"}},a.decodeVersionInformation=function(e){for(var t=4294967295,n=0,r=0;r<a.VERSION_DECODE_INFO.length;r++){var i=a.VERSION_DECODE_INFO[r];if(i==e)return this.getVersionForNumber(r+7);var o=s.numBitsDiffering(e,i);o<t&&(n=r+7,t=o)}return t<=3?this.getVersionForNumber(n):null},a.buildVersions=function(){return new Array(new a(1,new Array,new w(7,new h(1,19)),new w(10,new h(1,16)),new w(13,new h(1,13)),new w(17,new h(1,9))),new a(2,new Array(6,18),new w(10,new h(1,34)),new w(16,new h(1,28)),new w(22,new h(1,22)),new w(28,new h(1,16))),new a(3,new Array(6,22),new w(15,new h(1,55)),new w(26,new h(1,44)),new w(18,new h(2,17)),new w(22,new h(2,13))),new a(4,new Array(6,26),new w(20,new h(1,80)),new w(18,new h(2,32)),new w(26,new h(2,24)),new w(16,new h(4,9))),new a(5,new Array(6,30),new w(26,new h(1,108)),new w(24,new h(2,43)),new w(18,new h(2,15),new h(2,16)),new w(22,new h(2,11),new h(2,12))),new a(6,new Array(6,34),new w(18,new h(2,68)),new w(16,new h(4,27)),new w(24,new h(4,19)),new w(28,new h(4,15))),new a(7,new Array(6,22,38),new w(20,new h(2,78)),new w(18,new h(4,31)),new w(18,new h(2,14),new h(4,15)),new w(26,new h(4,13),new h(1,14))),new a(8,new Array(6,24,42),new w(24,new h(2,97)),new w(22,new h(2,38),new h(2,39)),new w(22,new h(4,18),new h(2,19)),new w(26,new h(4,14),new h(2,15))),new a(9,new Array(6,26,46),new w(30,new h(2,116)),new w(22,new h(3,36),new h(2,37)),new w(20,new h(4,16),new h(4,17)),new w(24,new h(4,12),new h(4,13))),new a(10,new Array(6,28,50),new w(18,new h(2,68),new h(2,69)),new w(26,new h(4,43),new h(1,44)),new w(24,new h(6,19),new h(2,20)),new w(28,new h(6,15),new h(2,16))),new a(11,new Array(6,30,54),new w(20,new h(4,81)),new w(30,new h(1,50),new h(4,51)),new w(28,new h(4,22),new h(4,23)),new w(24,new h(3,12),new h(8,13))),new a(12,new Array(6,32,58),new w(24,new h(2,92),new h(2,93)),new w(22,new h(6,36),new h(2,37)),new w(26,new h(4,20),new h(6,21)),new w(28,new h(7,14),new h(4,15))),new a(13,new Array(6,34,62),new w(26,new h(4,107)),new w(22,new h(8,37),new h(1,38)),new w(24,new h(8,20),new h(4,21)),new w(22,new h(12,11),new h(4,12))),new a(14,new Array(6,26,46,66),new w(30,new h(3,115),new h(1,116)),new w(24,new h(4,40),new h(5,41)),new w(20,new h(11,16),new h(5,17)),new w(24,new h(11,12),new h(5,13))),new a(15,new Array(6,26,48,70),new w(22,new h(5,87),new h(1,88)),new w(24,new h(5,41),new h(5,42)),new w(30,new h(5,24),new h(7,25)),new w(24,new h(11,12),new h(7,13))),new a(16,new Array(6,26,50,74),new w(24,new h(5,98),new h(1,99)),new w(28,new h(7,45),new h(3,46)),new w(24,new h(15,19),new h(2,20)),new w(30,new h(3,15),new h(13,16))),new a(17,new Array(6,30,54,78),new w(28,new h(1,107),new h(5,108)),new w(28,new h(10,46),new h(1,47)),new w(28,new h(1,22),new h(15,23)),new w(28,new h(2,14),new h(17,15))),new a(18,new Array(6,30,56,82),new w(30,new h(5,120),new h(1,121)),new w(26,new h(9,43),new h(4,44)),new w(28,new h(17,22),new h(1,23)),new w(28,new h(2,14),new h(19,15))),new a(19,new Array(6,30,58,86),new w(28,new h(3,113),new h(4,114)),new w(26,new h(3,44),new h(11,45)),new w(26,new h(17,21),new h(4,22)),new w(26,new h(9,13),new h(16,14))),new a(20,new Array(6,34,62,90),new w(28,new h(3,107),new h(5,108)),new w(26,new h(3,41),new h(13,42)),new w(30,new h(15,24),new h(5,25)),new w(28,new h(15,15),new h(10,16))),new a(21,new Array(6,28,50,72,94),new w(28,new h(4,116),new h(4,117)),new w(26,new h(17,42)),new w(28,new h(17,22),new h(6,23)),new w(30,new h(19,16),new h(6,17))),new a(22,new Array(6,26,50,74,98),new w(28,new h(2,111),new h(7,112)),new w(28,new h(17,46)),new w(30,new h(7,24),new h(16,25)),new w(24,new h(34,13))),new a(23,new Array(6,30,54,74,102),new w(30,new h(4,121),new h(5,122)),new w(28,new h(4,47),new h(14,48)),new w(30,new h(11,24),new h(14,25)),new w(30,new h(16,15),new h(14,16))),new a(24,new Array(6,28,54,80,106),new w(30,new h(6,117),new h(4,118)),new w(28,new h(6,45),new h(14,46)),new w(30,new h(11,24),new h(16,25)),new w(30,new h(30,16),new h(2,17))),new a(25,new Array(6,32,58,84,110),new w(26,new h(8,106),new h(4,107)),new w(28,new h(8,47),new h(13,48)),new w(30,new h(7,24),new h(22,25)),new w(30,new h(22,15),new h(13,16))),new a(26,new Array(6,30,58,86,114),new w(28,new h(10,114),new h(2,115)),new w(28,new h(19,46),new h(4,47)),new w(28,new h(28,22),new h(6,23)),new w(30,new h(33,16),new h(4,17))),new a(27,new Array(6,34,62,90,118),new w(30,new h(8,122),new h(4,123)),new w(28,new h(22,45),new h(3,46)),new w(30,new h(8,23),new h(26,24)),new w(30,new h(12,15),new h(28,16))),new a(28,new Array(6,26,50,74,98,122),new w(30,new h(3,117),new h(10,118)),new w(28,new h(3,45),new h(23,46)),new w(30,new h(4,24),new h(31,25)),new w(30,new h(11,15),new h(31,16))),new a(29,new Array(6,30,54,78,102,126),new w(30,new h(7,116),new h(7,117)),new w(28,new h(21,45),new h(7,46)),new w(30,new h(1,23),new h(37,24)),new w(30,new h(19,15),new h(26,16))),new a(30,new Array(6,26,52,78,104,130),new w(30,new h(5,115),new h(10,116)),new w(28,new h(19,47),new h(10,48)),new w(30,new h(15,24),new h(25,25)),new w(30,new h(23,15),new h(25,16))),new a(31,new Array(6,30,56,82,108,134),new w(30,new h(13,115),new h(3,116)),new w(28,new h(2,46),new h(29,47)),new w(30,new h(42,24),new h(1,25)),new w(30,new h(23,15),new h(28,16))),new a(32,new Array(6,34,60,86,112,138),new w(30,new h(17,115)),new w(28,new h(10,46),new h(23,47)),new w(30,new h(10,24),new h(35,25)),new w(30,new h(19,15),new h(35,16))),new a(33,new Array(6,30,58,86,114,142),new w(30,new h(17,115),new h(1,116)),new w(28,new h(14,46),new h(21,47)),new w(30,new h(29,24),new h(19,25)),new w(30,new h(11,15),new h(46,16))),new a(34,new Array(6,34,62,90,118,146),new w(30,new h(13,115),new h(6,116)),new w(28,new h(14,46),new h(23,47)),new w(30,new h(44,24),new h(7,25)),new w(30,new h(59,16),new h(1,17))),new a(35,new Array(6,30,54,78,102,126,150),new w(30,new h(12,121),new h(7,122)),new w(28,new h(12,47),new h(26,48)),new w(30,new h(39,24),new h(14,25)),new w(30,new h(22,15),new h(41,16))),new a(36,new Array(6,24,50,76,102,128,154),new w(30,new h(6,121),new h(14,122)),new w(28,new h(6,47),new h(34,48)),new w(30,new h(46,24),new h(10,25)),new w(30,new h(2,15),new h(64,16))),new a(37,new Array(6,28,54,80,106,132,158),new w(30,new h(17,122),new h(4,123)),new w(28,new h(29,46),new h(14,47)),new w(30,new h(49,24),new h(10,25)),new w(30,new h(24,15),new h(46,16))),new a(38,new Array(6,32,58,84,110,136,162),new w(30,new h(4,122),new h(18,123)),new w(28,new h(13,46),new h(32,47)),new w(30,new h(48,24),new h(14,25)),new w(30,new h(42,15),new h(32,16))),new a(39,new Array(6,26,54,82,110,138,166),new w(30,new h(20,117),new h(4,118)),new w(28,new h(40,47),new h(7,48)),new w(30,new h(43,24),new h(22,25)),new w(30,new h(10,15),new h(67,16))),new a(40,new Array(6,30,58,86,114,142,170),new w(30,new h(19,118),new h(6,119)),new w(28,new h(18,47),new h(31,48)),new w(30,new h(34,24),new h(34,25)),new w(30,new h(20,15),new h(61,16))))},a}();y.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),y.VERSIONS=y.buildVersions(),Array.prototype.remove||(Array.prototype.remove=function(e){var t=this.slice(e+1||this.length);return this.length=e<0?this.length+e:e,this.push.apply(this,t)});var c=function(){function e(e,t,n){this.incrementCount=function(){this.count++},this.aboutEquals=function(e,t,n){if(Math.abs(t-this.y)<=e&&Math.abs(n-this.x)<=e){var r=Math.abs(e-this.estimatedModuleSize);return r<=1||r/this.estimatedModuleSize<=1}return!1},this.x=e,this.y=t,this.count=1,this.estimatedModuleSize=n}return Object.defineProperty(e.prototype,"EstimatedModuleSize",{get:function(){return this.estimatedModuleSize},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"Count",{get:function(){return this.count},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"X",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"Y",{get:function(){return this.y},enumerable:!0,configurable:!0}),e}();c.MIN_SKIP=3,c.MAX_MODULES=57,c.INTEGER_MATH_SHIFT=8,c.CENTER_QUORUM=2;var d=function(){function e(e){this.bottomLeft=e[0],this.topLeft=e[1],this.topRight=e[2]}return Object.defineProperty(e.prototype,"BottomLeft",{get:function(){return this.bottomLeft},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"TopLeft",{get:function(){return this.topLeft},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"TopRight",{get:function(){return this.topRight},enumerable:!0,configurable:!0}),e}(),a=function(){function e(e,t){this.possibleCenters=new Array,this.hasSkipped=!1,this.crossCheckStateCount=new Array(0,0,0,0,0),this.orderBestPatterns=function(e){function t(e,t){var n=e.X-t.X,r=e.Y-t.Y;return Math.sqrt(n*n+r*r)}var n,r,i,o,a,s,h,u,f=t(e[0],e[1]),w=t(e[1],e[2]),c=t(e[0],e[2]);if(f<=w&&c<=w?(r=e[0],n=e[1],i=e[2]):w<=c&&f<=c?(r=e[1],n=e[0],i=e[2]):(r=e[2],n=e[0],i=e[1]),o=n,s=i,h=(a=r).x,u=a.y,(s.x-h)*(o.y-u)-(s.y-u)*(o.x-h)<0){var l=n;n=i,i=l}e[0]=n,e[1]=r,e[2]=i},this.foundPatternCross=function(e){for(var t=0,n=0;n<5;n++){var r=e[n];if(0==r)return!1;t+=r}if(t<7)return!1;var i=Math.floor((t<<c.INTEGER_MATH_SHIFT)/7),o=Math.floor(i/2);return Math.abs(i-(e[0]<<c.INTEGER_MATH_SHIFT))<o&&Math.abs(i-(e[1]<<c.INTEGER_MATH_SHIFT))<o&&Math.abs(3*i-(e[2]<<c.INTEGER_MATH_SHIFT))<3*o&&Math.abs(i-(e[3]<<c.INTEGER_MATH_SHIFT))<o&&Math.abs(i-(e[4]<<c.INTEGER_MATH_SHIFT))<o},this.centerFromEnd=function(e,t){return t-e[4]-e[3]-e[2]/2},this.crossCheckVertical=function(e,t,n,r){for(var i=this.image,o=this.height,a=this.CrossCheckStateCount,s=e;0<=s&&i[t+s*this.width];)a[2]++,s--;if(s<0)return NaN;for(;0<=s&&!i[t+s*this.width]&&a[1]<=n;)a[1]++,s--;if(s<0||a[1]>n)return NaN;for(;0<=s&&i[t+s*this.width]&&a[0]<=n;)a[0]++,s--;if(a[0]>n)return NaN;for(s=e+1;s<o&&i[t+s*this.width];)a[2]++,s++;if(s==o)return NaN;for(;s<o&&!i[t+s*this.width]&&a[3]<n;)a[3]++,s++;if(s==o||a[3]>=n)return NaN;for(;s<o&&i[t+s*this.width]&&a[4]<n;)a[4]++,s++;if(a[4]>=n)return NaN;var h=a[0]+a[1]+a[2]+a[3]+a[4];return 5*Math.abs(h-r)>=2*r?NaN:this.foundPatternCross(a)?this.centerFromEnd(a,s):NaN},this.crossCheckHorizontal=function(e,t,n,r){for(var i=this.image,o=this.width,a=this.CrossCheckStateCount,s=e;0<=s&&i[s+t*this.width];)a[2]++,s--;if(s<0)return NaN;for(;0<=s&&!i[s+t*this.width]&&a[1]<=n;)a[1]++,s--;if(s<0||a[1]>n)return NaN;for(;0<=s&&i[s+t*this.width]&&a[0]<=n;)a[0]++,s--;if(a[0]>n)return NaN;for(s=e+1;s<o&&i[s+t*this.width];)a[2]++,s++;if(s==o)return NaN;for(;s<o&&!i[s+t*this.width]&&a[3]<n;)a[3]++,s++;if(s==o||a[3]>=n)return NaN;for(;s<o&&i[s+t*this.width]&&a[4]<n;)a[4]++,s++;if(a[4]>=n)return NaN;var h=a[0]+a[1]+a[2]+a[3]+a[4];return 5*Math.abs(h-r)>=r?NaN:this.foundPatternCross(a)?this.centerFromEnd(a,s):NaN},this.handlePossibleCenter=function(e,t,n){var r=e[0]+e[1]+e[2]+e[3]+e[4],i=this.centerFromEnd(e,n),o=this.crossCheckVertical(t,Math.floor(i),e[2],r);if(!isNaN(o)&&(i=this.crossCheckHorizontal(Math.floor(i),Math.floor(o),e[2],r),!isNaN(i))){for(var a=r/7,s=!1,h=this.possibleCenters.length,u=0;u<h;u++){var f=this.possibleCenters[u];if(f.aboutEquals(a,o,i)){f.incrementCount(),s=!0;break}}if(!s){var w=new c(i,o,a);this.possibleCenters.push(w),null!=this.resultPointCallback&&this.resultPointCallback.foundPossibleResultPoint(w)}return!0}return!1},this.selectBestPatterns=function(){var e=this.possibleCenters.length;if(e<3)throw"Couldn't find enough finder patterns (found: "+e+")";if(3<e){for(var t=0,n=0,r=0;r<e;r++){var i=this.possibleCenters[r].EstimatedModuleSize;t+=i,n+=i*i}var o=t/e;this.possibleCenters.sort(function(e,t){var n=Math.abs(t.EstimatedModuleSize-o),r=Math.abs(e.EstimatedModuleSize-o);return n<r?-1:n==r?0:1});var a=Math.sqrt(n/e-o*o),s=Math.max(.2*o,a);for(r=this.possibleCenters.length-1;0<=r;r--){var h=this.possibleCenters[r];Math.abs(h.EstimatedModuleSize-o)>s&&this.possibleCenters.remove(r)}}return 3<this.possibleCenters.length&&this.possibleCenters.sort(function(e,t){return e.count>t.count?-1:e.count<t.count?1:0}),new Array(this.possibleCenters[0],this.possibleCenters[1],this.possibleCenters[2])},this.findRowSkip=function(){var e=this.possibleCenters.length;if(e<=1)return 0;for(var t=null,n=0;n<e;n++){var r=this.possibleCenters[n];if(r.Count>=c.CENTER_QUORUM){if(null!=t)return this.hasSkipped=!0,Math.floor((Math.abs(t.X-r.X)-Math.abs(t.Y-r.Y))/2);t=r}}return 0},this.haveMultiplyConfirmedCenters=function(){for(var e=0,t=0,n=this.possibleCenters.length,r=0;r<n;r++){var i=this.possibleCenters[r];i.Count>=c.CENTER_QUORUM&&(e++,t+=i.EstimatedModuleSize)}if(e<3)return!1;var o=t/n,a=0;for(r=0;r<n;r++)i=this.possibleCenters[r],a+=Math.abs(i.EstimatedModuleSize-o);return a<=.05*t},this.findFinderPattern=function(e){this.image=e;var t=this.height,n=this.width,r=Math.floor(3*t/(4*c.MAX_MODULES));r<c.MIN_SKIP&&(r=c.MIN_SKIP);for(var i=!1,o=new Array(5),a=r-1;a<t&&!i;a+=r){o[0]=0,o[1]=0,o[2]=0,o[3]=0;for(var s=o[4]=0,h=0;h<n;h++)if(e[h+a*this.width])1==(1&s)&&s++,o[s]++;else if(0==(1&s))if(4==s)if(this.foundPatternCross(o)){if(this.handlePossibleCenter(o,a,h))if(r=2,this.hasSkipped)i=this.haveMultiplyConfirmedCenters();else{var u=this.findRowSkip();u>o[2]&&(a+=u-o[2]-r,h=n-1)}else{for(;++h<n&&!e[h+a*this.width];);h--}o[s=0]=0,o[1]=0,o[2]=0,o[3]=0,o[4]=0}else o[0]=o[2],o[1]=o[3],o[2]=o[4],o[3]=1,o[4]=0,s=3;else o[++s]++;else o[s]++;if(this.foundPatternCross(o))this.handlePossibleCenter(o,a,n)&&(r=o[0],this.hasSkipped&&(i=this.haveMultiplyConfirmedCenters()))}var f=this.selectBestPatterns();return this.orderBestPatterns(f),new d(f)},this.width=e,this.height=t}return Object.defineProperty(e.prototype,"CrossCheckStateCount",{get:function(){return this.crossCheckStateCount[0]=0,this.crossCheckStateCount[1]=0,this.crossCheckStateCount[2]=0,this.crossCheckStateCount[3]=0,this.crossCheckStateCount[4]=0,this.crossCheckStateCount},enumerable:!0,configurable:!0}),e}(),b=function(e,t){this.bits=e,this.points=t},p=function(){function e(e,t,n,r){this.calculateModuleSizeOneWay=function(e,t){var n=this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(e.X),Math.floor(e.Y),Math.floor(t.X),Math.floor(t.Y)),r=this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(t.X),Math.floor(t.Y),Math.floor(e.X),Math.floor(e.Y));return isNaN(n)?r/7:isNaN(r)?n/7:(n+r)/14},this.calculateModuleSize=function(e,t,n){return(this.calculateModuleSizeOneWay(e,t)+this.calculateModuleSizeOneWay(e,n))/2},this.distance=function(e,t){var n=e.X-t.X,r=e.Y-t.Y;return Math.sqrt(n*n+r*r)},this.computeDimension=function(e,t,n,r){var i=7+(Math.round(this.distance(e,t)/r)+Math.round(this.distance(e,n)/r)>>1);switch(3&i){case 0:i++;break;case 2:i--;break;case 3:throw"Error"}return i},this.findAlignmentInRegion=function(e,t,n,r){var i=Math.floor(r*e),o=Math.max(0,t-i),a=Math.min(this.width-1,t+i);if(a-o<3*e)throw"Error";var s=Math.max(0,n-i),h=Math.min(this.height-1,n+i);return new u(this.image,o,s,a-o,h-s,e,this.width,this.height,this.resultPointCallback).find()},this.createTransform=function(e,t,n,r,i){var o,a,s,h,u=i-3.5;return null!=r?(o=r.X,a=r.Y,s=h=u-3):(o=t.X-e.X+n.X,a=t.Y-e.Y+n.Y,s=h=u),v.quadrilateralToQuadrilateral(3.5,3.5,u,3.5,s,h,3.5,u,e.X,e.Y,t.X,t.Y,o,a,n.X,n.Y)},this.sampleGrid=function(e,t,n){return new i(this.width,this.height).sampleGrid3(e,this.rawImage,n,t)},this.detect=function(){var e=new a(this.width,this.height).findFinderPattern(this.image);return this.processFinderPatternInfo(e)},this.image=e,this.rawImage=t,this.height=r,this.width=n}return e.prototype.sizeOfBlackWhiteBlackRun=function(e,t,n,r){var i=Math.abs(r-t)>Math.abs(n-e);if(i){var o=e;e=t,t=o,o=n,n=r,r=o}for(var a=Math.abs(n-e),s=Math.abs(r-t),h=-a>>1,u=t<r?1:-1,f=e<n?1:-1,w=0,c=e,l=t;c!=n;c+=f){var d=i?l:c,p=i?c:l;if(1==w?this.image[d+p*this.width]&&w++:this.image[d+p*this.width]||w++,3==w){var g=c-e,m=l-t;return Math.sqrt(g*g+m*m)}if(0<(h+=s)){if(l==r)break;l+=u,h-=a}}var y=n-e,v=r-t;return Math.sqrt(y*y+v*v)},e.prototype.sizeOfBlackWhiteBlackRunBothWays=function(e,t,n,r){var i=this.sizeOfBlackWhiteBlackRun(e,t,n,r),o=1,a=e-(n-e);a<0?(o=e/(e-a),a=0):a>=this.width&&(o=(this.width-1-e)/(a-e),a=this.width-1);var s=Math.floor(t-(r-t)*o);return o=1,s<0?(o=t/(t-s),s=0):s>=this.height&&(o=(this.height-1-t)/(s-t),s=this.height-1),a=Math.floor(e+(a-e)*o),(i+=this.sizeOfBlackWhiteBlackRun(e,t,a,s))-1},e.prototype.processFinderPatternInfo=function(e){var t=e.TopLeft,n=e.TopRight,r=e.BottomLeft,i=this.calculateModuleSize(t,n,r);if(i<1)throw"Error";var o=this.computeDimension(t,n,r,i),a=y.getProvisionalVersionForDimension(o),s=a.DimensionForVersion-7,h=null;if(0<a.AlignmentPatternCenters.length)for(var u=n.X-t.X+r.X,f=n.Y-t.Y+r.Y,w=1-3/s,c=Math.floor(t.X+w*(u-t.X)),l=Math.floor(t.Y+w*(f-t.Y)),d=4;d<=16;d<<=1){h=this.findAlignmentInRegion(i,c,l,d);break}var p,g=this.createTransform(t,n,r,h,o),m=this.sampleGrid(this.image,g,o);return p=null==h?new Array(r,t,n):new Array(r,t,n,h),new b(m,p)},e}(),g=function(){function u(e,t){if(this.divide=function(e){if(this.field!=e.field)throw"GF256Polys do not have same GF256 field";if(e.Zero)throw"Divide by 0";for(var t=this.field.Zero,n=this,r=e.getCoefficient(e.Degree),i=this.field.inverse(r);n.Degree>=e.Degree&&!n.Zero;){var o=n.Degree-e.Degree,a=this.field.multiply(n.getCoefficient(n.Degree),i),s=e.multiplyByMonomial(o,a),h=this.field.buildMonomial(o,a);t=t.addOrSubtract(h),n=n.addOrSubtract(s)}return new Array(t,n)},null==t||0==t.length)throw"System.ArgumentException";this.field=e;var n=t.length;if(1<n&&0==t[0]){for(var r=1;r<n&&0==t[r];)r++;if(r==n)this.coefficients=e.Zero.coefficients;else{this.coefficients=new Array(n-r);for(var i=0;i<this.coefficients.length;i++)this.coefficients[i]=0;for(var o=0;o<this.coefficients.length;o++)this.coefficients[o]=t[r+o]}}else this.coefficients=t}return Object.defineProperty(u.prototype,"Zero",{get:function(){return 0==this.coefficients[0]},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"Degree",{get:function(){return this.coefficients.length-1},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"Coefficients",{get:function(){return this.coefficients},enumerable:!0,configurable:!0}),u.prototype.getCoefficient=function(e){return this.coefficients[this.coefficients.length-1-e]},u.prototype.evaluateAt=function(e){if(0==e)return this.getCoefficient(0);var t=this.coefficients.length;if(1==e){for(var n=0,r=0;r<t;r++)n=m.addOrSubtract(n,this.coefficients[r]);return n}var i=this.coefficients[0];for(r=1;r<t;r++)i=m.addOrSubtract(this.field.multiply(e,i),this.coefficients[r]);return i},u.prototype.addOrSubtract=function(e){if(this.field!=e.field)throw"GF256Polys do not have same GF256 field";if(this.Zero)return e;if(e.Zero)return this;var t=this.coefficients,n=e.coefficients;if(t.length>n.length){var r=t;t=n,n=r}for(var i=new Array(n.length),o=n.length-t.length,a=0;a<o;a++)i[a]=n[a];for(var s=o;s<n.length;s++)i[s]=m.addOrSubtract(t[s-o],n[s]);return new u(this.field,i)},u.prototype.multiply1=function(e){if(this.field!=e.field)throw"GF256Polys do not have same GF256 field";if(this.Zero||e.Zero)return this.field.Zero;for(var t=this.coefficients,n=t.length,r=e.coefficients,i=r.length,o=new Array(n+i-1),a=0;a<n;a++)for(var s=t[a],h=0;h<i;h++)o[a+h]=m.addOrSubtract(o[a+h],this.field.multiply(s,r[h]));return new u(this.field,o)},u.prototype.multiply2=function(e){if(0==e)return this.field.Zero;if(1==e)return this;for(var t=this.coefficients.length,n=new Array(t),r=0;r<t;r++)n[r]=this.field.multiply(this.coefficients[r],e);return new u(this.field,n)},u.prototype.multiplyByMonomial=function(e,t){if(e<0)throw"System.ArgumentException";if(0==t)return this.field.Zero;for(var n=this.coefficients.length,r=new Array(n+e),i=0;i<r.length;i++)r[i]=0;for(i=0;i<n;i++)r[i]=this.field.multiply(this.coefficients[i],t);return new u(this.field,r)},u}(),m=function(){function e(e){this.expTable=new Array(256),this.logTable=new Array(256);for(var t=1,n=0;n<256;n++)this.expTable[n]=t,256<=(t<<=1)&&(t^=e);for(n=0;n<255;n++)this.logTable[this.expTable[n]]=n;var r=new Array(1);r[0]=0,this.zero=new g(this,new Array(r));var i=new Array(1);i[0]=1,this.one=new g(this,new Array(i))}return Object.defineProperty(e.prototype,"Zero",{get:function(){return this.zero},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"One",{get:function(){return this.one},enumerable:!0,configurable:!0}),e.prototype.buildMonomial=function(e,t){if(e<0)throw"System.ArgumentException";if(0==t)return this.zero;for(var n=new Array(e+1),r=0;r<n.length;r++)n[r]=0;return n[0]=t,new g(this,n)},e.prototype.exp=function(e){return this.expTable[e]},e.prototype.log=function(e){if(0==e)throw"System.ArgumentException";return this.logTable[e]},e.prototype.inverse=function(e){if(0==e)throw"System.ArithmeticException";return this.expTable[255-this.logTable[e]]},e.prototype.multiply=function(e,t){return 0==e||0==t?0:1==e?t:1==t?e:this.expTable[(this.logTable[e]+this.logTable[t])%255]},e.addOrSubtract=function(e,t){return e^t},e}();m.QR_CODE_FIELD=new m(285),m.DATA_MATRIX_FIELD=new m(301);var C=function(){function e(e){this.field=e}return e.prototype.decode=function(e,t){for(var n=new g(this.field,e),r=new Array(t),i=0;i<r.length;i++)r[i]=0;var o=!0;for(i=0;i<t;i++){var a=n.evaluateAt(this.field.exp(i));0!=(r[r.length-1-i]=a)&&(o=!1)}if(!o){var s=new g(this.field,r),h=this.runEuclideanAlgorithm(this.field.buildMonomial(t,1),s,t),u=h[0],f=h[1],w=this.findErrorLocations(u),c=this.findErrorMagnitudes(f,w,!1);for(i=0;i<w.length;i++){var l=e.length-1-this.field.log(w[i]);if(l<0)throw"ReedSolomonException Bad error location";e[l]=m.addOrSubtract(e[l],c[i])}}},e.prototype.runEuclideanAlgorithm=function(e,t,n){if(e.Degree<t.Degree){var r=e;e=t,t=r}for(var i=e,o=t,a=this.field.One,s=this.field.Zero,h=this.field.Zero,u=this.field.One;o.Degree>=Math.floor(n/2);){var f=i,w=a,c=h;if(a=s,h=u,(i=o).Zero)throw"r_{i-1} was zero";o=f;for(var l=this.field.Zero,d=i.getCoefficient(i.Degree),p=this.field.inverse(d);o.Degree>=i.Degree&&!o.Zero;){var g=o.Degree-i.Degree,m=this.field.multiply(o.getCoefficient(o.Degree),p);l=l.addOrSubtract(this.field.buildMonomial(g,m)),o=o.addOrSubtract(i.multiplyByMonomial(g,m))}s=l.multiply1(a).addOrSubtract(w),u=l.multiply1(h).addOrSubtract(c)}var y=u.getCoefficient(0);if(0==y)throw"ReedSolomonException sigmaTilde(0) was zero";var v=this.field.inverse(y),b=u.multiply2(v),C=o.multiply2(v);return new Array(b,C)},e.prototype.findErrorLocations=function(e){var t=e.Degree;if(1==t)return new Array(e.getCoefficient(1));for(var n=new Array(t),r=0,i=1;i<256&&r<t;i++)0==e.evaluateAt(i)&&(n[r]=this.field.inverse(i),r++);if(r!=t)throw"Error locator degree does not match number of roots";return n},e.prototype.findErrorMagnitudes=function(e,t,n){for(var r=t.length,i=new Array(r),o=0;o<r;o++){for(var a=this.field.inverse(t[o]),s=1,h=0;h<r;h++)o!=h&&(s=this.field.multiply(s,m.addOrSubtract(1,this.field.multiply(t[h],a))));i[o]=this.field.multiply(e.evaluateAt(a),this.field.inverse(s)),n&&(i[o]=this.field.multiply(i[o],a))}return i},e}(),A=function(){function e(){this.isMasked=function(e,t){return 0==(e+t&1)}}return e.prototype.unmaskBitMatrix=function(e,t){for(var n=0;n<t;n++)for(var r=0;r<t;r++)this.isMasked(n,r)&&e.flip(r,n)},e}(),M=function(){function e(){this.isMasked=function(e,t){return 0==(1&e)}}return e.prototype.unmaskBitMatrix=function(e,t){for(var n=0;n<t;n++)for(var r=0;r<t;r++)this.isMasked(n,r)&&e.flip(r,n)},e}(),S=function(){function e(){this.isMasked=function(e,t){return t%3==0}}return e.prototype.unmaskBitMatrix=function(e,t){for(var n=0;n<t;n++)for(var r=0;r<t;r++)this.isMasked(n,r)&&e.flip(r,n)},e}(),P=function(){function e(){this.isMasked=function(e,t){return(e+t)%3==0}}return e.prototype.unmaskBitMatrix=function(e,t){for(var n=0;n<t;n++)for(var r=0;r<t;r++)this.isMasked(n,r)&&e.flip(r,n)},e}(),E=function(){function e(){this.isMasked=function(e,t){return 0==(this.URShift(e,1)+t/3&1)}}return e.prototype.unmaskBitMatrix=function(e,t){for(var n=0;n<t;n++)for(var r=0;r<t;r++)this.isMasked(n,r)&&e.flip(r,n)},e.prototype.URShift=function(e,t){return 0<=e?e>>t:(e>>t)+(2<<~t)},e}(),k=function(){function e(){this.isMasked=function(e,t){var n=e*t;return(1&n)+n%3==0}}return e.prototype.unmaskBitMatrix=function(e,t){for(var n=0;n<t;n++)for(var r=0;r<t;r++)this.isMasked(n,r)&&e.flip(r,n)},e}(),N=function(){function e(){this.isMasked=function(e,t){var n=e*t;return 0==((1&n)+n%3&1)}}return e.prototype.unmaskBitMatrix=function(e,t){for(var n=0;n<t;n++)for(var r=0;r<t;r++)this.isMasked(n,r)&&e.flip(r,n)},e}(),T=function(){function e(){this.isMasked=function(e,t){return 0==((e+t&1)+e*t%3&1)}}return e.prototype.unmaskBitMatrix=function(e,t){for(var n=0;n<t;n++)for(var r=0;r<t;r++)this.isMasked(n,r)&&e.flip(r,n)},e}(),B=function(){function t(){}return t.forReference=function(e){if(e<0||7<e)throw"System.ArgumentException";return t.DATA_MASKS[e]},t}();B.DATA_MASKS=new Array(new A,new M,new S,new P,new E,new k,new N,new T);var O=function(){function e(e){var t=e.Dimension;if(t<21||1!=(3&t))throw"Error BitMatrixParser";this.bitMatrix=e}return e.prototype.copyBit=function(e,t,n){return this.bitMatrix.get_Renamed(e,t)?n<<1|1:n<<1},e.prototype.readFormatInformation=function(){if(null!=this.parsedFormatInfo)return this.parsedFormatInfo;for(var e=0,t=0;t<6;t++)e=this.copyBit(t,8,e);e=this.copyBit(7,8,e),e=this.copyBit(8,8,e),e=this.copyBit(8,7,e);for(var n=5;0<=n;n--)e=this.copyBit(8,n,e);if(this.parsedFormatInfo=s.decodeFormatInformation(e),null!=this.parsedFormatInfo)return this.parsedFormatInfo;var r=this.bitMatrix.Dimension;e=0;var i=r-8;for(t=r-1;i<=t;t--)e=this.copyBit(t,8,e);for(n=r-7;n<r;n++)e=this.copyBit(8,n,e);if(this.parsedFormatInfo=s.decodeFormatInformation(e),null!=this.parsedFormatInfo)return this.parsedFormatInfo;throw"Error readFormatInformation"},e.prototype.readVersion=function(){if(null!=this.parsedVersion)return this.parsedVersion;var e=this.bitMatrix.Dimension,t=e-17>>2;if(t<=6)return y.getVersionForNumber(t);for(var n=0,r=e-11,i=5;0<=i;i--)for(var o=e-9;r<=o;o--)n=this.copyBit(o,i,n);if(this.parsedVersion=y.decodeVersionInformation(n),null!=this.parsedVersion&&this.parsedVersion.DimensionForVersion==e)return this.parsedVersion;n=0;for(o=5;0<=o;o--)for(i=e-9;r<=i;i--)n=this.copyBit(o,i,n);if(this.parsedVersion=y.decodeVersionInformation(n),null!=this.parsedVersion&&this.parsedVersion.DimensionForVersion==e)return this.parsedVersion;throw"Error readVersion"},e.prototype.readCodewords=function(){var e=this.readFormatInformation(),t=this.readVersion(),n=B.forReference(e.DataMask),r=this.bitMatrix.Dimension;n.unmaskBitMatrix(this.bitMatrix,r);for(var i=t.buildFunctionPattern(),o=!0,a=new Array(t.TotalCodewords),s=0,h=0,u=0,f=r-1;0<f;f-=2){6==f&&f--;for(var w=0;w<r;w++)for(var c=o?r-1-w:w,l=0;l<2;l++)i.get_Renamed(f-l,c)||(u++,h<<=1,this.bitMatrix.get_Renamed(f-l,c)&&(h|=1),8==u&&(a[s++]=h,h=u=0));o=!o}if(s!=t.TotalCodewords)throw"Error readCodewords";return a},e}(),I=function(){function v(e,t){this.numDataCodewords=e,this.codewords=t}return Object.defineProperty(v.prototype,"NumDataCodewords",{get:function(){return this.numDataCodewords},enumerable:!0,configurable:!0}),Object.defineProperty(v.prototype,"Codewords",{get:function(){return this.codewords},enumerable:!0,configurable:!0}),v.getDataBlocks=function(e,t,n){if(e.length!=t.TotalCodewords)throw"ArgumentException";for(var r=t.getECBlocksForLevel(n),i=0,o=r.getECBlocks(),a=0;a<o.length;a++)i+=o[a].Count;for(var s=new Array(i),h=0,u=0;u<o.length;u++){var f=o[u];for(a=0;a<f.Count;a++){var w=f.DataCodewords,c=r.ECCodewordsPerBlock+w;s[h++]=new v(w,new Array(c))}}for(var l=s[0].codewords.length,d=s.length-1;0<=d;){if(s[d].codewords.length==l)break;d--}d++;var p=l-r.ECCodewordsPerBlock,g=0;for(a=0;a<p;a++)for(u=0;u<h;u++)s[u].codewords[a]=e[g++];for(u=d;u<h;u++)s[u].codewords[p]=e[g++];var m=s[0].codewords.length;for(a=p;a<m;a++)for(u=0;u<h;u++){var y=u<d?a:a+1;s[u].codewords[y]=e[g++]}return s},v}(),_=function(){function n(e,t,n){this.blockPointer=0,this.bitPointer=7,this.dataLength=0,this.blocks=e,this.numErrorCorrectionCode=n,t<=9?this.dataLengthMode=0:10<=t&&t<=26?this.dataLengthMode=1:27<=t&&t<=40&&(this.dataLengthMode=2)}return n.prototype.getNextBits=function(e){var t=0;if(e<this.bitPointer+1){for(var n=0,r=0;r<e;r++)n+=1<<r;return n<<=this.bitPointer-e+1,t=(this.blocks[this.blockPointer]&n)>>this.bitPointer-e+1,this.bitPointer-=e,t}if(e<this.bitPointer+1+8){var i=0;for(r=0;r<this.bitPointer+1;r++)i+=1<<r;return t=(this.blocks[this.blockPointer]&i)<<e-(this.bitPointer+1),this.blockPointer++,t+=this.blocks[this.blockPointer]>>8-(e-(this.bitPointer+1)),this.bitPointer=this.bitPointer-e%8,this.bitPointer<0&&(this.bitPointer=8+this.bitPointer),t}if(e<this.bitPointer+1+16){i=0;var o=0;for(r=0;r<this.bitPointer+1;r++)i+=1<<r;var a=(this.blocks[this.blockPointer]&i)<<e-(this.bitPointer+1);this.blockPointer++;var s=this.blocks[this.blockPointer]<<e-(this.bitPointer+1+8);this.blockPointer++;for(r=0;r<e-(this.bitPointer+1+8);r++)o+=1<<r;return o<<=8-(e-(this.bitPointer+1+8)),t=a+s+((this.blocks[this.blockPointer]&o)>>8-(e-(this.bitPointer+1+8))),this.bitPointer=this.bitPointer-(e-8)%8,this.bitPointer<0&&(this.bitPointer=8+this.bitPointer),t}return 0},n.prototype.NextMode=function(){return this.blockPointer>this.blocks.length-this.numErrorCorrectionCode-2?0:this.getNextBits(4)},n.prototype.getDataLength=function(e){for(var t=0;e>>t!=1;)t++;return this.getNextBits(n.sizeOfDataLengthInfo[this.dataLengthMode][t])},n.prototype.getRomanAndFigureString=function(e){var t=e,n=0,r="",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(1<t){var o=(n=this.getNextBits(11))%45;r+=i[Math.floor(n/45)],r+=i[o],t-=2}else 1==t&&(r+=i[n=this.getNextBits(6)],t-=1)}while(0<t);return r},n.prototype.getFigureString=function(e){for(var t=e,n=0,r="";3<=t?((n=this.getNextBits(10))<100&&(r+="0"),n<10&&(r+="0"),t-=3):2==t?((n=this.getNextBits(7))<10&&(r+="0"),t-=2):1==t&&(n=this.getNextBits(4),t-=1),r+=n,0<t;);return r},n.prototype.get8bitByteArray=function(e){for(var t=e,n=0,r=new Array;n=this.getNextBits(8),r.push(n),0<--t;);return r},n.prototype.getKanjiString=function(e){var t=e,n=0,r="";do{var i=((n=this.getNextBits(13))/192<<8)+n%192,o=0;o=i+33088<=40956?i+33088:i+49472,r+=String.fromCharCode(o),t--}while(0<t);return r},Object.defineProperty(n.prototype,"DataByte",{get:function(){for(var e=new Array;;){var t=this.NextMode();if(0==t){if(0<e.length)break;throw"Empty data block"}if(1!=t&&2!=t&&4!=t&&8!=t)throw"Invalid mode: "+t+" in (block:"+this.blockPointer+" bit:"+this.bitPointer+")";var n=this.getDataLength(t);if(n<1)throw"Invalid data length: "+n;switch(t){case 1:for(var r=this.getFigureString(n),i=new Array(r.length),o=0;o<r.length;o++)i[o]=r.charCodeAt(o);e.push(i);break;case 2:for(r=this.getRomanAndFigureString(n),i=new Array(r.length),o=0;o<r.length;o++)i[o]=r.charCodeAt(o);e.push(i);break;case 4:var a=this.get8bitByteArray(n);e.push(a);break;case 8:r=this.getKanjiString(n);e.push(r)}}return e},enumerable:!0,configurable:!0}),n}();_.sizeOfDataLengthInfo=[[10,9,8,8],[12,11,16,10],[14,13,16,12]];var D=function(){function e(){this.rsDecoder=new C(m.QR_CODE_FIELD),this.decode=function(e){for(var t=new O(e),n=t.readVersion(),r=t.readFormatInformation().ErrorCorrectionLevel,i=t.readCodewords(),o=I.getDataBlocks(i,n,r),a=0,s=0;s<o.length;s++)a+=o[s].NumDataCodewords;for(var h=new Array(a),u=0,f=0;f<o.length;f++){var w=o[f],c=w.Codewords,l=w.NumDataCodewords;this.correctErrors(c,l);for(s=0;s<l;s++)h[u++]=c[s]}return new _(h,n.VersionNumber,r.Bits)}}return e.prototype.correctErrors=function(e,t){for(var n=e.length,r=new Array(n),i=0;i<n;i++)r[i]=255&e[i];var o=e.length-t;try{this.rsDecoder.decode(r,o)}catch(a){throw a}for(i=0;i<t;i++)e[i]=r[i]},e}(),F=function(){function e(){this.debug=!1,this.maxImgSize=1048576,this.sizeOfDataLengthInfo=[[10,9,8,8],[12,11,16,10],[14,13,16,12]]}return e.prototype.decode=function(e){var t=e.getContext("2d");return this.width=e.width,this.height=e.height,this.imagedata=t.getImageData(0,0,this.width,this.height),this.result=this.process(t),null!=this.myCallback&&this.myCallback(this.result),this.result},e.prototype.process=function(e){var t=(new Date).getTime(),n=this.grayScaleToBitmap(this.grayscale());if(this.debug){for(var r=0;r<this.height;r++)for(var i=0;i<this.width;i++){var o=4*i+r*this.width*4;this.imagedata.data[o]=(n[i+r*this.width],0),this.imagedata.data[o+1]=(n[i+r*this.width],0),this.imagedata.data[o+2]=n[i+r*this.width]?255:0}e.putImageData(this.imagedata,0,0)}var a=new p(n,this.imagedata,this.width,this.height).detect();this.debug&&e.putImageData(this.imagedata,0,0);for(var s=(new D).decode(a.bits).DataByte,h="",u=0;u<s.length;u++)for(var f=0;f<s[u].length;f++)h+=String.fromCharCode(s[u][f]);var w=(new Date).getTime()-t;return console.log(w),h},e.prototype.grayScaleToBitmap=function(e){for(var t=this.getMiddleBrightnessPerArea(e),n=t.length,r=Math.floor(this.width/n),i=Math.floor(this.height/n),o=new Array(this.height*this.width),a=0;a<n;a++)for(var s=0;s<n;s++)for(var h=0;h<i;h++)for(var u=0;u<r;u++)o[r*s+u+(i*a+h)*this.width]=e[r*s+u+(i*a+h)*this.width]<t[s][a];return o},e.prototype.grayscale=function(){for(var e=new Array(this.width*this.height),t=0;t<this.height;t++)for(var n=0;n<this.width;n++){var r=this.getPixel(n,t);e[n+t*this.width]=r}return e},e.prototype.getPixel=function(e,t){if(this.width<e)throw"point error";if(this.height<t)throw"point error";var n=4*e+t*this.width*4;return(33*this.imagedata.data[n]+34*this.imagedata.data[n+1]+33*this.imagedata.data[n+2])/100},e.prototype.getMiddleBrightnessPerArea=function(e){for(var t=Math.floor(this.width/4),n=Math.floor(this.height/4),r=new Array(4),i=0;i<4;i++){r[i]=new Array(4);for(var o=0;o<4;o++)r[i][o]=new Array(0,0)}for(var a=0;a<4;a++)for(var s=0;s<4;s++){r[s][a][0]=255;for(var h=0;h<n;h++)for(var u=0;u<t;u++){var f=e[t*s+u+(n*a+h)*this.width];f<r[s][a][0]&&(r[s][a][0]=f),f>r[s][a][1]&&(r[s][a][1]=f)}}for(var w=new Array(4),c=0;c<4;c++)w[c]=new Array(4);for(a=0;a<4;a++)for(s=0;s<4;s++)w[s][a]=Math.floor((r[s][a][0]+r[s][a][1])/2);return w},e}(),R=function(){function e(e){this.renderer=e,this.canvasWidth=640,this.canvasHeight=480,this.debug=!1,this.stopAfterScan=!0,this.updateTime=500,this.capturedQr=new t.EventEmitter,this.foundCameras=new t.EventEmitter,this.chooseCamera=new n.Subject,this.canvasHidden=!0}return Object.defineProperty(e.prototype,"isCanvasSupported",{get:function(){var e=this.renderer.createElement("canvas");return!(!e.getContext||!e.getContext("2d"))},enumerable:!0,configurable:!0}),e.prototype.ngOnInit=function(){},e.prototype.ngOnDestroy=function(){this.chooseCamera$.unsubscribe(),this.stopScanning()},e.prototype.ngAfterViewInit=function(){var t=this;this.debug&&console.log("[QrScanner] ViewInit, isSupported: ",this.isCanvasSupported),this.isCanvasSupported&&(this.gCtx=this.qrCanvas.nativeElement.getContext("2d"),this.gCtx.clearRect(0,0,this.canvasWidth,this.canvasHeight),this.qrCode=new F,this.debug&&(this.qrCode.debug=!0),this.qrCode.myCallback=function(e){return t.QrDecodeCallback(e)}),this.chooseCamera$=this.chooseCamera.subscribe(function(e){return t.useDevice(e)}),this.getMediaDevices().then(function(e){return t.foundCameras.next(e)})},e.prototype.startScanning=function(e){this.useDevice(e)},e.prototype.stopScanning=function(){this.captureTimeout&&(clearTimeout(this.captureTimeout),this.captureTimeout=0),this.canvasHidden=!1;var e=this.stream&&this.stream.getTracks().length&&this.stream;e&&(e.getTracks().forEach(function(e){return e.enabled&&e.stop()}),this.stream=null)},e.prototype.getMediaDevices=function(){var t=this;return navigator.mediaDevices&&navigator.mediaDevices.enumerateDevices?navigator.mediaDevices.enumerateDevices().then(function(e){return e})["catch"](function(e){return t.debug&&console.warn("Error",e),[]}):Promise.resolve([])},e.prototype.QrDecodeCallback=function(e){var t=this;this.stopAfterScan?(this.stopScanning(),this.capturedQr.next(e)):(this.capturedQr.next(e),this.captureTimeout=setTimeout(function(){return t.captureToCanvas()},this.updateTime))},e.prototype.captureToCanvas=function(){var e=this;try{this.gCtx.drawImage(this.videoElement,0,0,this.canvasWidth,this.canvasHeight),this.qrCode.decode(this.qrCanvas.nativeElement)}catch(t){if(this.debug&&consol