10 lines
12 KiB
JavaScript
10 lines
12 KiB
JavaScript
|
// [qr.js](http://neocotic.com/qr.js) 1.0.3
|
||
|
// (c) 2011 Alasdair Mercer
|
||
|
// Freely distributable under the MIT license.
|
||
|
// Based on jsqrencode
|
||
|
// (c) 2010 tz@execpc.com
|
||
|
// Licensed under the GPL Version 3 license.
|
||
|
// For all details and documentation:
|
||
|
// http://neocotic.com/qr.js
|
||
|
(function(a){function Q(a){var c,h,i,j,k,m,n,u;k=a.length;C=0;do{C++;i=(r-1)*4+(C-1)*16;z=d[i++];A=d[i++];o=d[i++];p=d[i];i=o*(z+A)+A-3+(C<=9);if(k<=i)break}while(C<40);D=17+4*C;m=o+(o+p)*(z+A)+A;for(k=0;k<m;k++)q[k]=0;B=a.slice(0);for(k=0;k<D*D;k++)s[k]=0;for(k=0;k<(D*(D+1)+1)/2;k++)t[k]=0;for(k=0;k<3;k++){i=0;u=0;if(k===1)i=D-7;if(k===2)u=D-7;s[u+3+D*(i+3)]=1;for(n=0;n<6;n++){s[u+n+D*i]=1;s[u+D*(i+n+1)]=1;s[u+6+D*(i+n)]=1;s[u+n+1+D*(i+6)]=1}for(n=1;n<5;n++){I(u+n,i+1);I(u+1,i+n+1);I(u+5,i+n);I(u+n+1,i+5)}for(n=2;n<4;n++){s[u+n+D*(i+2)]=1;s[u+2+D*(i+n+1)]=1;s[u+4+D*(i+n)]=1;s[u+n+1+D*(i+4)]=1}}if(C>1){k=b[C];u=D-7;for(;;){n=D-7;while(n>k-3){J(n,u);if(n<k)break;n-=k}if(u<=k+9)break;u-=k;J(6,u);J(u,6)}}s[8+D*(D-8)]=1;for(u=0;u<7;u++){I(7,u);I(D-8,u);I(7,u+D-7)}for(n=0;n<8;n++){I(n,7);I(n+D-8,7);I(n,D-8)}for(n=0;n<9;n++)I(n,8);for(n=0;n<8;n++){I(n+D-8,8);I(8,n)}for(u=0;u<7;u++)I(8,u+D-7);for(n=0;n<D-14;n++){if(n&1){I(8+n,6);I(6,8+n)}else{s[8+n+D*6]=1;s[6+D*(8+n)]=1}}if(C>6){k=l[C-7];i=17;for(n=0;n<6;n++){for(u=0;u<3;u++,i--){if(1&(i>11?C>>i-12:k>>i)){s[5-n+D*(2-u+D-11)]=1;s[2-u+D-11+D*(5-n)]=1}else{I(5-n,2-u+D-11);I(2-u+D-11,5-n)}}}}for(u=0;u<D;u++){for(n=0;n<=u;n++){if(s[n+D*u])I(n,u)}}m=B.length;for(c=0;c<m;c++)q[c]=B.charCodeAt(c);B=q.slice(0);n=o*(z+A)+A;if(m>=n-2){m=n-2;if(C>9)m--}c=m;if(C>9){B[c+2]=0;B[c+3]=0;while(c--){k=B[c];B[c+3]|=255&k<<4;B[c+2]=k>>4}B[2]|=255&m<<4;B[1]=m>>4;B[0]=64|m>>12}else{B[c+1]=0;B[c+2]=0;while(c--){k=B[c];B[c+2]|=255&k<<4;B[c+1]=k>>4}B[1]|=255&m<<4;B[0]=64|m>>4}c=m+3-(C<10);while(c<n){B[c++]=236;B[c++]=17}x[0]=1;for(c=0;c<p;c++){x[c+1]=1;for(h=c;h>0;h--){x[h]=x[h]?x[h-1]^f[K(g[x[h]]+c)]:x[h-1]}x[0]=f[K(g[x[0]]+c)]}for(c=0;c<=p;c++)x[c]=g[x[c]];i=n;u=0;for(c=0;c<z;c++){L(u,o,i,p);u+=o;i+=p}for(c=0;c<A;c++){L(u,o+1,i,p);u+=o+1;i+=p}u=0;for(c=0;c<o;c++){for(h=0;h<z;h++){q[u++]=B[c+h*o]}for(h=0;h<A;h++){q[u++]=B[z*o+c+h*(o+1)]}}for(h=0;h<A;h++){q[u++]=B[z*o+c+h*(o+1)]}for(c=0;c<p;c++){for(h=0;h<z+A;h++){q[u++]=B[n+c+h*p]}}B=q;n=u=D-1;i=m=1;j=(o+p)*(z+A)+A;for(c=0;c<j;c++){k=B[c];for(h=0;h<8;h++,k<<=1){if(128&k)s[n+D*u]=1;do{if(m){n--}else{n++;if(i){if(u!==0){u--}else{n-=2;i=!i;if(n===6){n--;u=9}}}else{if(u!==D-1){u++}else{n-=2;i=!i;if(n===6){n--;u-=8}}}}m=!m}while(M(n,u))}}B=s.slice(0);k=0;u=3e4;for(i=0;i<8;i++){N(i);n=P();if(n<u){u=n;k=i}if(k===7)break;s=B.slice(0)}if(k!==i)N(k);u=e[k+(r-1<<3)];for(i=0;i<8;i++,u>>=1){if(u&1){s[D-1-i+D*8]=1;if(i<6){s[8+D*i]=1}else{s[8+D*(i+1)]=1}}}for(i=0;i<7;i++,u>>=1){if(u&1){s[8+D*(D-7+i)]=1;if(i){s[6-i+D*8]=1}else{s[7+D*8]=1}}}return s}function P(){var a,b,c,d,e,f,g=0,h=0,j=0;for(f=0;f<D-1;f++){for(e=0;e<D-1;e++){if(s[e+D*f]&&s[e+1+D*f]&&s[e+D*(f+1)]&&s[e+1+D*(f+1)]||!(s[e+D*f]||s[e+1+D*f]||s[e+D*(f+1)]||s[e+1+D*(f+1)])){g+=i}}}for(f=0;f<D;f++){m[0]=0;for(d=a=e=0;e<D;e++){if((b=s[e+D*f])===a){m[d]++}else{m[++d]=1}a=b;h+=a?1:-1}g+=O(d)}if(h<0)h=-h;c=h;c+=c<<2;c<<=1;while(c>D*D){c-=D*D;j++}g+=j*k;for(e=0;e<D;e++){m[0]=0;for(d=a=f=0;f<D;f++){if((b=s[e+D*f])===a){m[d]++}else{m[++d]=1}a=b}g+=O(d)}return g}function O(a){var b=0,c;for(c=0;c<=a;c++){if(m[c]>=5)b+=h+m[c]-5}for(c=3;c<a-1;c+=2){if(m[c-2]===m[c+2]&&m[c+2]===m[c-1]&&m[c-1]===m[c+1]&&m[c-1]*3===m[c]&&(m[c-3]===0||c+3>a||m[c-3]*3>=m[c]*4||m[c+3]*3>=m[c]*4)){b+=j}}return b}function N(a){var b,c,d,e;switch(a){case 0:for(c=0;c<D;c++){for(b=0;b<D;b++){if(!(b+c&1)&&!M(b,c)){s[b+c*D]^=1}}}break;case 1:for(c=0;c<D;c++){for(b=0;b<D;b++){if(!(c&1)&&!M(b,c))s[b+c*D]^=1}}break;case 2:for(c=0;c<D;c++){for(d=0,b=0;b<D;b++,d++){if(d===3)d=0;if(!d&&!M(b,c))s[b+c*D]^=1}}break;case 3:for(e=0,c=0;c<D;c++,e++){if(e===3)e=0;for(d=e,b=0;b<D;b++,d++){if(d===3)d=0;if(!d&&!M(b,c))s[b+c*D]^=1}}break;case 4:for(c=0;c<D;c++){for(d=0,e=c>>1&1,b=0;b<D;b++,d++){if(d===3){d=0;e=!e}if(!e&&!M(b,c))s[b+c*D]^=1}}break;case 5:for(e=0,c=0;c<D;c++,e++){if(e===3)e=0;for(d=0,b=0;b<D;b++,d++){if(d===3)d=0;if(!((b&c&1)+!(!d|!e))&&!M(b,c)){s[b+c*D]^=1}}}break;case 6:for(e=0,c=0;c<D;c++,e++){if(e===3)e=0;for(d=0,b=0;b<D;b++,d++){if(d===3)d=0;if(!((b&c&1)+(d&&d===e)&1)&&!M(b,c)){s[b+c*D]^=1}}}break;case 7:for(e=0,c=0;c<D;c++,e++){if(e===3)e=0;for
|