-
Notifications
You must be signed in to change notification settings - Fork 3
/
qrcode_kazuhikoarase.js
32 lines (32 loc) · 15.6 KB
/
qrcode_kazuhikoarase.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var qrcode=function(){function x(g,k){if("undefined"==typeof g.length)throw Error(g.length+"/"+k);var f=function(){for(var b=0;b<g.length&&0==g[b];)b+=1;for(var a=Array(g.length-b+k),c=0;c<g.length-b;c+=1)a[c]=g[c+b];return a}(),a={getAt:function(b){return f[b]},getLength:function(){return f.length},multiply:function(b){for(var e=Array(a.getLength()+b.getLength()-1),c=0;c<a.getLength();c+=1)for(var d=0;d<b.getLength();d+=1)e[c+d]^=t.gexp(t.glog(a.getAt(c))+t.glog(b.getAt(d)));return x(e,0)},mod:function(b){if(0>
a.getLength()-b.getLength())return a;for(var e=t.glog(a.getAt(0))-t.glog(b.getAt(0)),c=Array(a.getLength()),d=0;d<a.getLength();d+=1)c[d]=a.getAt(d);for(d=0;d<b.getLength();d+=1)c[d]^=t.gexp(t.glog(b.getAt(d))+e);return x(c,0).mod(b)}};return a}var A=function(g,k){var f=w[k],a=null,b=0,e=null,c=[],d={},r=function(d,k){for(var m=b=4*g+17,l=Array(m),h=0;h<m;h+=1){l[h]=Array(m);for(var p=0;p<m;p+=1)l[h][p]=null}a=l;z(0,0);z(b-7,0);z(0,b-7);m=y.getPatternPosition(g);for(l=0;l<m.length;l+=1)for(h=0;h<
m.length;h+=1){var p=m[l],r=m[h];if(null==a[p][r])for(var u=-2;2>=u;u+=1)for(var n=-2;2>=n;n+=1)a[p+u][r+n]=-2==u||2==u||-2==n||2==n||0==u&&0==n?!0:!1}for(m=8;m<b-8;m+=1)null==a[m][6]&&(a[m][6]=0==m%2);for(m=8;m<b-8;m+=1)null==a[6][m]&&(a[6][m]=0==m%2);m=y.getBCHTypeInfo(f<<3|k);for(l=0;15>l;l+=1)h=!d&&1==(m>>l&1),6>l?a[l][8]=h:8>l?a[l+1][8]=h:a[b-15+l][8]=h;for(l=0;15>l;l+=1)h=!d&&1==(m>>l&1),8>l?a[8][b-l-1]=h:9>l?a[8][15-l-1+1]=h:a[8][15-l-1]=h;a[b-8][8]=!d;if(7<=g){m=y.getBCHTypeNumber(g);for(l=
0;18>l;l+=1)h=!d&&1==(m>>l&1),a[Math.floor(l/3)][l%3+b-8-3]=h;for(l=0;18>l;l+=1)h=!d&&1==(m>>l&1),a[l%3+b-8-3][Math.floor(l/3)]=h}if(null==e){m=C.getRSBlocks(g,f);l=D();for(h=0;h<c.length;h+=1)p=c[h],l.put(p.getMode(),4),l.put(p.getLength(),y.getLengthInBits(p.getMode(),g)),p.write(l);for(h=p=0;h<m.length;h+=1)p+=m[h].dataCount;if(l.getLengthInBits()>8*p)throw Error("code length overflow. ("+l.getLengthInBits()+">"+8*p+")");for(l.getLengthInBits()+4<=8*p&&l.put(0,4);0!=l.getLengthInBits()%8;)l.putBit(!1);
for(;!(l.getLengthInBits()>=8*p);){l.put(236,8);if(l.getLengthInBits()>=8*p)break;l.put(17,8)}for(var v=0,p=h=0,r=Array(m.length),u=Array(m.length),n=0;n<m.length;n+=1){var t=m[n].dataCount,w=m[n].totalCount-t,h=Math.max(h,t),p=Math.max(p,w);r[n]=Array(t);for(var q=0;q<r[n].length;q+=1)r[n][q]=255&l.getBuffer()[q+v];v+=t;q=y.getErrorCorrectPolynomial(w);t=x(r[n],q.getLength()-1).mod(q);u[n]=Array(q.getLength()-1);for(q=0;q<u[n].length;q+=1)w=q+t.getLength()-u[n].length,u[n][q]=0<=w?t.getAt(w):0}for(q=
l=0;q<m.length;q+=1)l+=m[q].totalCount;l=Array(l);for(q=v=0;q<h;q+=1)for(n=0;n<m.length;n+=1)q<r[n].length&&(l[v]=r[n][q],v+=1);for(q=0;q<p;q+=1)for(n=0;n<m.length;n+=1)q<u[n].length&&(l[v]=u[n][q],v+=1);e=l}m=e;l=-1;h=b-1;p=7;r=0;u=y.getMaskFunction(k);for(n=b-1;0<n;n-=2)for(6==n&&--n;;){for(q=0;2>q;q+=1)null==a[h][n-q]&&(v=!1,r<m.length&&(v=1==(m[r]>>>p&1)),u(h,n-q)&&(v=!v),a[h][n-q]=v,--p,-1==p&&(r+=1,p=7));h+=l;if(0>h||b<=h){h-=l;l=-l;break}}},z=function(c,e){for(var d=-1;7>=d;d+=1)if(!(-1>=c+
d||b<=c+d))for(var h=-1;7>=h;h+=1)-1>=e+h||b<=e+h||(a[c+d][e+h]=0<=d&&6>=d&&(0==h||6==h)||0<=h&&6>=h&&(0==d||6==d)||2<=d&&4>=d&&2<=h&&4>=h?!0:!1)};d.addData=function(b){b=E(b);c.push(b);e=null};d.isDark=function(c,e){if(0>c||b<=c||0>e||b<=e)throw Error(c+","+e);return a[c][e]};d.getModuleCount=function(){return b};d.make=function(){for(var b=0,a=0,c=0;8>c;c+=1){r(!0,c);var e=y.getLostPoint(d);if(0==c||b>e)b=e,a=c}r(!1,a)};d.createTableTag=function(b,a){b=b||2;var c;c='<table style=" border-width: 0px; border-style: none; border-collapse: collapse;'+
(" padding: 0px; margin: "+("undefined"==typeof a?4*b:a)+"px;")+'"><tbody>';for(var e=0;e<d.getModuleCount();e+=1){c+="<tr>";for(var h=0;h<d.getModuleCount();h+=1)c+='<td style="',c+=" border-width: 0px; border-style: none;",c+=" border-collapse: collapse;",c+=" padding: 0px; margin: 0px;",c+=" width: "+b+"px;",c+=" height: "+b+"px;",c+=" background-color: ",c+=d.isDark(e,h)?"#000000":"#ffffff",c+=";",c+='"/>';c+="</tr>"}return c+"</tbody></table>"};d.createSvgTag=function(b,c){b=b||2;c="undefined"==
typeof c?4*b:c;var a=d.getModuleCount()*b+2*c,e,f,h,g,k;k="l"+b+",0 0,"+b+" -"+b+",0 0,-"+b+"z ";g="<svg"+(' width="'+a+'px"')+(' height="'+a+'px"')+' xmlns="http://www.w3.org/2000/svg">';g+='<path d="';for(f=0;f<d.getModuleCount();f+=1)for(h=f*b+c,a=0;a<d.getModuleCount();a+=1)d.isDark(f,a)&&(e=a*b+c,g+="M"+e+","+h+k);g+='" stroke="transparent" fill="black"/>';return g+="</svg>"};d.createImgTag=function(b,c){b=b||2;c="undefined"==typeof c?4*b:c;var a=d.getModuleCount()*b+2*c,e=c,f=a-c;return F(a,
a,function(c,a){return e<=c&&c<f&&e<=a&&a<f?d.isDark(Math.floor((a-e)/b),Math.floor((c-e)/b))?0:1:1})};return d};A.stringToBytes=function(g){for(var k=[],f=0;f<g.length;f+=1){var a=g.charCodeAt(f);k.push(a&255)}return k};A.createStringToBytes=function(g,k){var f=function(){for(var a=G(g),b=function(){var b=a.read();if(-1==b)throw Error();return b},e=0,c={};;){var d=a.read();if(-1==d)break;var f=b(),z=b(),h=b(),d=String.fromCharCode(d<<8|f);c[d]=z<<8|h;e+=1}if(e!=k)throw Error(e+" != "+k);return c}();
return function(a){for(var b=[],e=0;e<a.length;e+=1){var c=a.charCodeAt(e);128>c?b.push(c):(c=f[a.charAt(e)],"number"==typeof c?(c&255)==c?b.push(c):(b.push(c>>>8),b.push(c&255)):b.push(63))}return b}};var w={L:1,M:0,Q:3,H:2},y=function(){var g=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,
80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],k={},f=function(a){for(var b=0;0!=a;)b+=1,a>>>=1;return b};k.getBCHTypeInfo=function(a){for(var b=a<<10;0<=f(b)-f(1335);)b^=1335<<f(b)-f(1335);return(a<<
10|b)^21522};k.getBCHTypeNumber=function(a){for(var b=a<<12;0<=f(b)-f(7973);)b^=7973<<f(b)-f(7973);return a<<12|b};k.getPatternPosition=function(a){return g[a-1]};k.getMaskFunction=function(a){switch(a){case 0:return function(b,a){return 0==(b+a)%2};case 1:return function(b,a){return 0==b%2};case 2:return function(b,a){return 0==a%3};case 3:return function(b,a){return 0==(b+a)%3};case 4:return function(b,a){return 0==(Math.floor(b/2)+Math.floor(a/3))%2};case 5:return function(b,a){return 0==b*a%2+
b*a%3};case 6:return function(b,a){return 0==(b*a%2+b*a%3)%2};case 7:return function(b,a){return 0==(b*a%3+(b+a)%2)%2};default:throw Error("bad maskPattern:"+a);}};k.getErrorCorrectPolynomial=function(a){for(var b=x([1],0),e=0;e<a;e+=1)b=b.multiply(x([1,t.gexp(e)],0));return b};k.getLengthInBits=function(a,b){if(1<=b&&10>b)switch(a){case 1:return 10;case 2:return 9;case 4:return 8;case 8:return 8;default:throw Error("mode:"+a);}else if(27>b)switch(a){case 1:return 12;case 2:return 11;case 4:return 16;
case 8:return 10;default:throw Error("mode:"+a);}else if(41>b)switch(a){case 1:return 14;case 2:return 13;case 4:return 16;case 8:return 12;default:throw Error("mode:"+a);}else throw Error("type:"+b);};k.getLostPoint=function(a){for(var b=a.getModuleCount(),e=0,c=0;c<b;c+=1)for(var d=0;d<b;d+=1){for(var f=0,g=a.isDark(c,d),h=-1;1>=h;h+=1)if(!(0>c+h||b<=c+h))for(var k=-1;1>=k;k+=1)0>d+k||b<=d+k||0==h&&0==k||g!=a.isDark(c+h,d+k)||(f+=1);5<f&&(e+=3+f-5)}for(c=0;c<b-1;c+=1)for(d=0;d<b-1;d+=1)if(f=0,a.isDark(c,
d)&&(f+=1),a.isDark(c+1,d)&&(f+=1),a.isDark(c,d+1)&&(f+=1),a.isDark(c+1,d+1)&&(f+=1),0==f||4==f)e+=3;for(c=0;c<b;c+=1)for(d=0;d<b-6;d+=1)a.isDark(c,d)&&!a.isDark(c,d+1)&&a.isDark(c,d+2)&&a.isDark(c,d+3)&&a.isDark(c,d+4)&&!a.isDark(c,d+5)&&a.isDark(c,d+6)&&(e+=40);for(d=0;d<b;d+=1)for(c=0;c<b-6;c+=1)a.isDark(c,d)&&!a.isDark(c+1,d)&&a.isDark(c+2,d)&&a.isDark(c+3,d)&&a.isDark(c+4,d)&&!a.isDark(c+5,d)&&a.isDark(c+6,d)&&(e+=40);for(d=f=0;d<b;d+=1)for(c=0;c<b;c+=1)a.isDark(c,d)&&(f+=1);return e+Math.abs(100*
f/b/b-50)/5*10};return k}(),t=function(){for(var g=Array(256),k=Array(256),f=0;8>f;f+=1)g[f]=1<<f;for(f=8;256>f;f+=1)g[f]=g[f-4]^g[f-5]^g[f-6]^g[f-8];for(f=0;255>f;f+=1)k[g[f]]=f;return{glog:function(a){if(1>a)throw Error("glog("+a+")");return k[a]},gexp:function(a){for(;0>a;)a+=255;for(;256<=a;)a-=255;return g[a]}}}(),C=function(){var g=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,
134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],
[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12,7,37,13],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],
[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,
74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,
35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],
[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]],k=function(b,a){var c={};c.totalCount=b;c.dataCount=a;return c},f={},a=function(a,e){switch(e){case w.L:return g[4*(a-1)+0];case w.M:return g[4*(a-1)+1];case w.Q:return g[4*(a-1)+2];case w.H:return g[4*(a-1)+3]}};f.getRSBlocks=function(b,e){var c=a(b,e);if("undefined"==typeof c)throw Error("bad rs block @ typeNumber:"+
b+"/errorCorrectionLevel:"+e);for(var d=c.length/3,f=[],g=0;g<d;g+=1)for(var h=c[3*g+0],p=c[3*g+1],m=c[3*g+2],l=0;l<h;l+=1)f.push(k(p,m));return f};return f}(),D=function(){var g=[],k=0,f={getBuffer:function(){return g},getAt:function(a){return 1==(g[Math.floor(a/8)]>>>7-a%8&1)},put:function(a,b){for(var e=0;e<b;e+=1)f.putBit(1==(a>>>b-e-1&1))},getLengthInBits:function(){return k},putBit:function(a){var b=Math.floor(k/8);g.length<=b&&g.push(0);a&&(g[b]|=128>>>k%8);k+=1}};return f},E=function(g){var k=
A.stringToBytes(g);return{getMode:function(){return 4},getLength:function(f){return k.length},write:function(f){for(var a=0;a<k.length;a+=1)f.put(k[a],8)}}},B=function(){var g=[],k={writeByte:function(f){g.push(f&255)},writeShort:function(f){k.writeByte(f);k.writeByte(f>>>8)},writeBytes:function(f,a,b){a=a||0;b=b||f.length;for(var e=0;e<b;e+=1)k.writeByte(f[e+a])},writeString:function(f){for(var a=0;a<f.length;a+=1)k.writeByte(f.charCodeAt(a))},toByteArray:function(){return g},toString:function(){var f;
f="[";for(var a=0;a<g.length;a+=1)0<a&&(f+=","),f+=g[a];return f+"]"}};return k},H=function(){var g=0,k=0,f=0,a="",b={},e=function(a){if(!(0>a)){if(26>a)return 65+a;if(52>a)return 97+(a-26);if(62>a)return 48+(a-52);if(62==a)return 43;if(63==a)return 47}throw Error("n:"+a);};b.writeByte=function(b){g=g<<8|b&255;k+=8;for(f+=1;6<=k;)a+=String.fromCharCode(e(g>>>k-6&63)),k-=6};b.flush=function(){0<k&&(a+=String.fromCharCode(e(g<<6-k&63)),k=g=0);if(0!=f%3)for(var b=3-f%3,d=0;d<b;d+=1)a+="="};b.toString=
function(){return a};return b},G=function(g){var k=0,f=0,a=0,b=function(a){if(65<=a&&90>=a)return a-65;if(97<=a&&122>=a)return a-97+26;if(48<=a&&57>=a)return a-48+52;if(43==a)return 62;if(47==a)return 63;throw Error("c:"+a);};return{read:function(){for(;8>a;){if(k>=g.length){if(0==a)return-1;throw Error("unexpected end of file./"+a);}var e=g.charAt(k);k+=1;if("="==e)return a=0,-1;e.match(/^\s$/)||(f=f<<6|b(e.charCodeAt(0)),a+=6)}e=f>>>a-8&255;a-=8;return e}}},I=function(g,k){var f=Array(g*k),a=function(a){var b=
0,d=0;return{write:function(c,e){if(0!=c>>>e)throw Error("length over");for(;8<=b+e;)a.writeByte(255&(c<<b|d)),e-=8-b,c>>>=8-b,b=d=0;d|=c<<b;b+=e},flush:function(){0<b&&a.writeByte(d)}}},b=function(){var a={},b=0,d={add:function(c){if(d.contains(c))throw Error("dup key:"+c);a[c]=b;b+=1},size:function(){return b},indexOf:function(b){return a[b]},contains:function(b){return"undefined"!=typeof a[b]}};return d};return{setPixel:function(a,b,d){f[b*g+a]=d},write:function(e){e.writeString("GIF87a");e.writeShort(g);
e.writeShort(k);e.writeByte(128);e.writeByte(0);e.writeByte(0);e.writeByte(0);e.writeByte(0);e.writeByte(0);e.writeByte(255);e.writeByte(255);e.writeByte(255);e.writeString(",");e.writeShort(0);e.writeShort(0);e.writeShort(g);e.writeShort(k);e.writeByte(0);var c;c=3;for(var d=b(),r=0;4>r;r+=1)d.add(String.fromCharCode(r));d.add(String.fromCharCode(4));d.add(String.fromCharCode(5));var r=B(),t=a(r);t.write(4,c);for(var h=0,p=String.fromCharCode(f[h]),h=h+1;h<f.length;){var m=String.fromCharCode(f[h]),
h=h+1;d.contains(p+m)?p+=m:(t.write(d.indexOf(p),c),4095>d.size()&&(d.size()==1<<c&&(c+=1),d.add(p+m)),p=m)}t.write(d.indexOf(p),c);t.write(5,c);t.flush();c=r.toByteArray();e.writeByte(2);for(d=0;255<c.length-d;)e.writeByte(255),e.writeBytes(c,d,255),d+=255;e.writeByte(c.length-d);e.writeBytes(c,d,c.length-d);e.writeByte(0);e.writeString(";")}}},F=function(g,k,f,a){for(var b=I(g,k),e=0;e<k;e+=1)for(var c=0;c<g;c+=1)b.setPixel(c,e,f(c,e));f=B();b.write(f);b=H();f=f.toByteArray();for(e=0;e<f.length;e+=1)b.writeByte(f[e]);b.flush();b='<img src="data:image/gif;base64,'+b+'" width="';b+=g;b+='"';b+=' height="';b+=k;b+='"';a&&(b+=' alt="',b+=a,b+='"');return b+="/>"};return A}();(function(x){"function"===typeof define&&define.amd?define([],x):"object"===typeof exports&&(module.exports=x())})(function(){return qrcode});
// append UTF8 handling: originated from kazuhikoarase's qrcode_UTF8.js
!function(e){e.stringToBytes=function(d){for(var b=[],c=0;c<d.length;c++){var a=d.charCodeAt(c);128>a?b.push(a):2048>a?b.push(192|a>>6,128|a&63):55296>a||57344<=a?b.push(224|a>>12,128|a>>6&63,128|a&63):(c++,a=65536+((a&1023)<<10|d.charCodeAt(c)&1023),b.push(240|a>>18,128|a>>12&63,128|a>>6&63,128|a&63))}return b}}(qrcode);