securityos/public/System/Hexells/UPNG.min.js

2 lines
25 KiB
JavaScript
Raw Normal View History

2024-09-06 15:32:35 +00:00
var UPNG={toRGBA8:function(e){var r=e.width,t=e.height;if(null==e.tabs.acTL)return[UPNG.toRGBA8.decodeImage(e.data,r,t,e).buffer];var n=[];null==e.frames[0].data&&(e.frames[0].data=e.data);for(var a=r*t*4,i=new Uint8Array(a),f=new Uint8Array(a),o=new Uint8Array(a),l=0;l<e.frames.length;l++){var s=e.frames[l],c=s.rect.x,u=s.rect.y,d=s.rect.width,h=s.rect.height,v=UPNG.toRGBA8.decodeImage(s.data,d,h,e);if(0!=l)for(var U=0;U<a;U++)o[U]=i[U];if(0==s.blend?UPNG._copyTile(v,d,h,i,r,t,c,u,0):1==s.blend&&UPNG._copyTile(v,d,h,i,r,t,c,u,1),n.push(i.buffer.slice(0)),0==s.dispose);else if(1==s.dispose)UPNG._copyTile(f,d,h,i,r,t,c,u,0);else if(2==s.dispose)for(U=0;U<a;U++)i[U]=o[U]}return n}};UPNG.toRGBA8.decodeImage=function(e,r,t,n){var a=r*t,i=UPNG.decode._getBPP(n),f=Math.ceil(r*i/8),o=new Uint8Array(4*a),l=new Uint32Array(o.buffer),s=n.ctype,c=n.depth,u=UPNG._bin.readUshort;Date.now();if(6==s){var d=a<<2;if(8==c)for(var h=0;h<d;h+=4)o[h]=e[h],o[h+1]=e[h+1],o[h+2]=e[h+2],o[h+3]=e[h+3];if(16==c)for(h=0;h<d;h++)o[h]=e[h<<1]}else if(2==s){var v=n.tabs.tRNS;if(null==v){if(8==c)for(h=0;h<a;h++){var U=3*h;l[h]=255<<24|e[U+2]<<16|e[U+1]<<8|e[U]}if(16==c)for(h=0;h<a;h++){U=6*h;l[h]=255<<24|e[U+4]<<16|e[U+2]<<8|e[U]}}else{var g=v[0],N=v[1],P=v[2];if(8==c)for(h=0;h<a;h++){var p=h<<2;U=3*h;l[h]=255<<24|e[U+2]<<16|e[U+1]<<8|e[U],e[U]==g&&e[U+1]==N&&e[U+2]==P&&(o[p+3]=0)}if(16==c)for(h=0;h<a;h++){p=h<<2,U=6*h;l[h]=255<<24|e[U+4]<<16|e[U+2]<<8|e[U],u(e,U)==g&&u(e,U+2)==N&&u(e,U+4)==P&&(o[p+3]=0)}}}else if(3==s){var G=n.tabs.PLTE,b=n.tabs.tRNS,w=b?b.length:0;if(1==c)for(var y=0;y<t;y++){var m=y*f,A=y*r;for(h=0;h<r;h++){p=A+h<<2;var _=3*(H=e[m+(h>>3)]>>7-((7&h)<<0)&1);o[p]=G[_],o[p+1]=G[_+1],o[p+2]=G[_+2],o[p+3]=H<w?b[H]:255}}if(2==c)for(y=0;y<t;y++)for(m=y*f,A=y*r,h=0;h<r;h++){p=A+h<<2,_=3*(H=e[m+(h>>2)]>>6-((3&h)<<1)&3);o[p]=G[_],o[p+1]=G[_+1],o[p+2]=G[_+2],o[p+3]=H<w?b[H]:255}if(4==c)for(y=0;y<t;y++)for(m=y*f,A=y*r,h=0;h<r;h++){p=A+h<<2,_=3*(H=e[m+(h>>1)]>>4-((1&h)<<2)&15);o[p]=G[_],o[p+1]=G[_+1],o[p+2]=G[_+2],o[p+3]=H<w?b[H]:255}if(8==c)for(h=0;h<a;h++){var H;p=h<<2,_=3*(H=e[h]);o[p]=G[_],o[p+1]=G[_+1],o[p+2]=G[_+2],o[p+3]=H<w?b[H]:255}}else if(4==s){if(8==c)for(h=0;h<a;h++){p=h<<2;var I=e[M=h<<1];o[p]=I,o[p+1]=I,o[p+2]=I,o[p+3]=e[M+1]}if(16==c)for(h=0;h<a;h++){var M;p=h<<2,I=e[M=h<<2];o[p]=I,o[p+1]=I,o[p+2]=I,o[p+3]=e[M+2]}}else if(0==s)for(g=n.tabs.tRNS?n.tabs.tRNS:-1,y=0;y<t;y++){var q=y*f,R=y*r;if(1==c)for(var T=0;T<r;T++){var z=(I=255*(e[q+(T>>>3)]>>>7-(7&T)&1))==255*g?0:255;l[R+T]=z<<24|I<<16|I<<8|I}else if(2==c)for(T=0;T<r;T++){z=(I=85*(e[q+(T>>>2)]>>>6-((3&T)<<1)&3))==85*g?0:255;l[R+T]=z<<24|I<<16|I<<8|I}else if(4==c)for(T=0;T<r;T++){z=(I=17*(e[q+(T>>>1)]>>>4-((1&T)<<2)&15))==17*g?0:255;l[R+T]=z<<24|I<<16|I<<8|I}else if(8==c)for(T=0;T<r;T++){z=(I=e[q+T])==g?0:255;l[R+T]=z<<24|I<<16|I<<8|I}else if(16==c)for(T=0;T<r;T++){I=e[q+(T<<1)],z=u(e,q+(T<<1))==g?0:255;l[R+T]=z<<24|I<<16|I<<8|I}}return o},UPNG.decode=function(e){for(var r,t=new Uint8Array(e),n=8,a=UPNG._bin,i=a.readUshort,f=a.readUint,o={tabs:{},frames:[]},l=new Uint8Array(t.length),s=0,c=0,u=[137,80,78,71,13,10,26,10],d=0;d<8;d++)if(t[d]!=u[d])throw"The input is not a PNG file!";for(;n<t.length;){var h=a.readUint(t,n);n+=4;var v=a.readASCII(t,n,4);if(n+=4,"IHDR"==v)UPNG.decode._IHDR(t,n,o);else if("CgBI"==v)o.tabs[v]=t.slice(n,n+4);else if("IDAT"==v){for(d=0;d<h;d++)l[s+d]=t[n+d];s+=h}else if("acTL"==v)o.tabs[v]={num_frames:f(t,n),num_plays:f(t,n+4)},r=new Uint8Array(t.length);else if("fcTL"==v){var U;if(0!=c)(U=o.frames[o.frames.length-1]).data=UPNG.decode._decompress(o,r.slice(0,c),U.rect.width,U.rect.height),c=0;var g={x:f(t,n+12),y:f(t,n+16),width:f(t,n+4),height:f(t,n+8)},N=i(t,n+22);N=i(t,n+20)/(0==N?100:N);var P={rect:g,delay:Math.round(1e3*N),dispose:t[n+24],blend:t[n+25]};o.frames.push(P)}else if("fdAT"==v){for(d=0;d<h-4;d++)r[c+d]=t[n+d+4];c+=h-4}else if("pHYs"==v)o.tabs[v]=[a.readUint(t,n),a.readUint(t,n+4),t[n+8]];else if("cHRM"==v){o.tabs[v]=[];for(d=0;d<8;d++)o.tabs[v].push(a.readUint(t,n+4*d))}else if("tEXt"==v||"zTXt"==v){null==o.tabs[v]&&(o.tabs[v]={});var p=a