-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPixelatedLoader.min.js
5 lines (5 loc) · 2.46 KB
/
PixelatedLoader.min.js
1
2
3
4
5
var PixelatedLoader=function(){function B(b){for(var d="",a=0;a<b.length;a++)d+=String.fromCharCode(b.charCodeAt(a)&255);return d}function H(b){b=B(b);for(var d=[];b.length>=l;){for(var a=0,r=l-1;0<=r;r--)a*=256,a+=b.charCodeAt(r);d.push(a);b=b.substr(l)}return d}var J=function(){var b=[],d={};return{add:function(a){b.push(a)},execute:function(a){for(d[a]=!0;0<b.length&&d[b[0]];)a=b.shift(),delete d[a],a()}}},l=4;return{load:function(b,d){var a,r,m,C,u,D,t=b.getContext("2d"),v=document.createElement("canvas"),
y=v.getContext("2d"),c=0,E=0,I=J(),e=new XMLHttpRequest;e.open("get",d,!0);e.responseType="text";e.overrideMimeType("text/plain; charset=x-user-defined");var h=0,A=[function(){var F=3*l;if(!e.response||e.response.length<c+F)return!1;var G=H(e.response.substr(c,F));a=G[0];r=G[1];m=G[2];C=a*Math.pow(2,m-1);u=r*Math.pow(2,m-1);b.width=C;b.height=u;c+=F;return!0},function(){var b=l*m;if(e.response.length<c+b)return!1;D=H(e.response.substr(c,b));c+=b;return!0},function(){var b=D[0];if(e.response.length<
c+b)return!1;var a=new Image;a.onload=function(){v.width=a.width;v.height=a.height;y.drawImage(a,0,0);for(var b=y.getImageData(0,0,a.width,a.height).data,c=u/a.height,e=0;e<a.width;e++)for(var z=0;z<a.height;z++){t.beginPath();t.rect(e*c,z*c,c,c);for(var f=4*(e+z*a.width),d=t,f=(65536*b[f]+256*b[f+1]+b[f+2]).toString(16);6>f.length;)f="0"+f;d.fillStyle="#"+f;t.fill()}};a.src="data:image/jpeg;base64,"+window.btoa(B(e.response.substr(c,b)));c+=b;E=1;return!0},function(){function a(){v.width=p.width;
v.height=p.height;y.drawImage(p,0,0);for(var c=y.getImageData(0,0,p.width,p.height).data,e=t.getImageData(0,0,C,u),d=e.data,f=u/p.height,q=f/2,r=p.width/3,k=0,h=0;h<p.height;h++)for(var l=0;l<r;l++){var m=c[k++],w=c[k++],x=c[k++];k++;for(var n=0;n<q;n++)for(var g=4*(l*f+q+(h*f+n)*b.width),s=0;s<q;s++)d[g++]=m,d[g++]=w,d[g++]=x,g++;m=c[k++];w=c[k++];x=c[k++];k++;for(n=0;n<q;n++)for(g=4*(l*f+(h*f+q+n)*b.width),s=0;s<q;s++)d[g++]=m,d[g++]=w,d[g++]=x,g++;m=c[k++];w=c[k++];x=c[k++];k++;for(n=0;n<q;n++)for(g=
4*(l*f+q+(h*f+q+n)*b.width),s=0;s<q;s++)d[g++]=m,d[g++]=w,d[g++]=x,g++}t.putImageData(e,0,0)}var d=D[E];if(e.response.length<c+d)return!1;var p=new Image;I.add(a);p.onload=function(){I.execute(a)};p.src="data:image/jpeg;base64,"+window.btoa(B(e.response.substr(c,d)));c+=d;return++E>=m}];e.addEventListener("progress",function(a){for(;h<A.length&&A[h]();)h++});e.onload=function(){intervalID=setInterval(function(){h<A.length?A[h]()&&h++:clearInterval(intervalID)},50)};e.send()}}}();