/* The MIT License (MIT) Copyright (c) 2014 Scott Laufer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. QR Code is registered trademark of DENSO WAVE INCORPORATED. */ function QR__apush(e,t){for(var n=0;n=0;i--){n[i]=e&r?true:false;r=r<<1}return n}function QR__pi2ba(e,t,n){var r=1;var i=e.length;for(var s=e.length+n-1;s>=i;s--){e[s]=t&r?true:false;r=r<<1}}function QR__ba2i(e,t,n){var r=0;for(var i=t;i=0&&e=7){for(var e=0;e<6;e++){for(var t=0;t<3;t++){this.setReserveBit(e,this.dim-9-t);this.setBit(e,this.dim-9-t,false);this.setReserveBit(this.dim-9-t,e);this.setBit(this.dim-9-t,e,false)}}}}function QR__drawBitstream(){var e=this.generateBitstream(this.data);var t=this.dim-1;var n=this.dim-1;var r=0;var i=-1;for(var s=0;1;s++){this.setBit(n-r,t,e[s]);if(s==e.length){break}do{if(r==1){r=0;t+=i;if(t==-1||t==this.dim){i=-i;t=i==1?0:this.dim-1;n=n-(n==8?3:2)}}else{r=1}}while(this.getReserveBit(n-r,t))}}function QR__drawFormat(){for(var e=0;e<6;e++){this.setBit(8,e,QR__FormatString[this.ec][this.mask][14-e]);this.setBit(e,8,QR__FormatString[this.ec][this.mask][e])}this.setBit(8,7,QR__FormatString[this.ec][this.mask][8]);this.setBit(8,8,QR__FormatString[this.ec][this.mask][7]);this.setBit(7,8,QR__FormatString[this.ec][this.mask][6]);for(var e=0;e<8;e++){this.setBit(this.dim-8+e,8,QR__FormatString[this.ec][this.mask][e+7])}for(var e=0;e<7;e++){this.setBit(8,this.dim-1-e,QR__FormatString[this.ec][this.mask][e])}if(this.ver>=7){for(var e=0;e<3;e++){for(var t=0;t<6;t++){this.setBit(t,this.dim-11+e,QR__Ver[this.ver].vi[17-(t*3+e)]);this.setBit(this.dim-11+e,t,QR__Ver[this.ver].vi[17-(t*3+e)])}}}}function QR__drawSymbol(){if(this.ver==null&&!this.autover){throw new Error("QR version not set")}if(this.data==null){throw new Error("Data not set")}if(this.autover){this.ver=null;for(var e=1;e40){throw new Error("Invalid QR Version")}if(t!=QR__EC.L&&t!=QR__EC.M&&t!=QR__EC.Q&&t!=QR__EC.H){throw new Error("Bad error correction level")}if(e==0){this.ver=null;this.autover=true}else{this.ver=e;this.autover=false}this.dim=QR__Ver[e].dim;this.ec=t}function QR__setData(e){this.data=e}function QR__generateMessage(e){var t=[];for(var n=0;nr){throw new Error("Message too long")}for(var n=0;(n<4||t.length%8!=0)&&t.length=t;o-=8){s[s.length]=QR__ba2i(e,o,8)}for(var o=s.length-1;o>=i;){var u=QR__GF256R[s[s.length-1]];var t=s.length-QR__GenPoly[i].length;for(var a=QR__GenPoly[i].length-1;a>-1;a--){var f=QR__GenPoly[i][a]+u;if(f>255){f%=255}f=QR__GF256[f];s[a+t]^=f}while(s[s.length-1]==0){s.pop();o--}}for(var o=s.length-1;o>-1;o--){QR__pi2ba(r,s[o],8)}return r}function QR__generateBitstream(e){var t=this.generateMessage(e);var n=[];var r=[0];var i=[0];var s=0;var o=0;for(var u=0,a=0;uo){o=QR__Ver[this.ver].ec[this.ec].groups[u].ecwords}if(QR__Ver[this.ver].ec[this.ec].groups[u].codewords-QR__Ver[this.ver].ec[this.ec].groups[u].ecwords>s){s=QR__Ver[this.ver].ec[this.ec].groups[u].codewords-QR__Ver[this.ver].ec[this.ec].groups[u].ecwords}for(var c=0;cr[c]+p){QR__apushr(h,t,r[c]+p,8)}}p+=8}var p=0;for(var u=0;ui[c]+p){QR__apushr(h,n,i[c]+p,8)}}p+=8}for(var u=0;u0){modules-=(Math.pow(QR__Ver[i].align.length,2)-3)*25-5*(QR__Ver[i].align.length-2)*2}if(i>=7){modules-=36}if(i<=9){QR__Ver[i].cci=QR__cci0}else if(i<=26){QR__Ver[i].cci=QR__cci1}else{QR__Ver[i].cci=QR__cci2}QR__Ver[i].dim=dim;QR__Ver[i].codewords=Math.floor(modules/8);QR__Ver[i].rem=modules%8}var QR__Mode={term:0,num:1,alNum:2,append:3,eightBit:4,FNC11:5,ECI:7,kanji:8,FNC12:9,smart:10};var QR__EC={L:"L",M:"M",Q:"Q",H:"H"};var QR__EncAlNumVals=["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"," ","$","%","*","+","-",".","/",":"];QR__EncAlNumKeys={};for(var i=0;i255){QR__GF256[i]^=285}}var QR__GF256R=[null];for(var i=QR__GF256.length-1;i>=0;i--){QR__GF256R[QR__GF256[i]]=i}var QR__GenPoly=[[],[0,0]];for(var i=2;i<=68;i++){var mul=[i-1,0];var output=[];for(var j=0;j255){alpha%=255}if(output.length=5){n[r]+=a-2}o+=a}}for(var o=0;o=5){n[r]+=a-2}s+=a}}}for(var r=0;r57){throw new Error("Bad data for numeric encoding")}}for(var r=0;rQR__UTF8_Breakpoints[u];u++);i+=u+1;if(u){var a=a=5*u+6;var f=QR__i2ba(o,a);var l;for(l=0;lQR__UTF8_Breakpoints[s];s++);n+=8*s+8}return n};QR__Encode[QR__Mode.ECI]=function(e,t,n){QR__pi2ba(e,QR__Mode.ECI,4);if(t<0||t>999999){throw new Error("ECI Assignment Number out of range")}if(t<128){QR__apush(e,[false]);QR__pi2ba(e,t,7)}else if(t<16384){QR__apush(e,[true,false]);QR__pi2ba(e,t,14)}else{QR__apush(e,[true,true,false]);QR__pi2ba(e,t,21)}};QR__EncodeLen[QR__Mode.ECI]=function(e,t){if(e<128){return 12}else if(e<16384){return 20}else{return 28}};QR__Encode[QR__Mode.FNC11]=function(e,t,n){QR__apush(e,[false,true,false,true])};QR__EncodeLen[QR__Mode.FNC11]=function(e,t){return 4};QR__Encode[QR__Mode.FNC12]=function(e,t,n){QR__apush(e,[true,false,false,true]);QR__pi2ba(e,t,8)};QR__EncodeLen[QR__Mode.FNC12]=function(e,t){return 12};QR__Encode[QR__Mode.smart]=function(e,t,n){var r=0;var i=QR__Mode.num;while(r"57"){i=QR__Mode.alNum;break}r++}while(r"57"){r=QR__Mode.alNum;break}n++}while(n