-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathgify.min.js
1 lines (1 loc) · 2.5 KB
/
gify.min.js
1
var gify=function(){"use strict";var t=100;function e(t){return 3*Math.pow(2,1+t.slice(5,8).reduce(function(t,e){return 2*t+e},0))}function i(t){for(var e=[],i=7;i>=0;i--)e.push(t&1<<i?1:0);return e}function a(t,e,i){for(var a={data:"",size:0};;){var r=t.getUint8(e+a.size,!0);if(0===r){a.size++;break}i&&(a.data+=t.getString(r,e+a.size+1)),a.size+=r+1}return a}function r(r,n){var o=0,l=0,s={valid:!1,globalPalette:!1,globalPaletteSize:0,globalPaletteColorsRGB:[],loopCount:-1,height:0,width:0,animated:!1,images:[],isBrowserDuration:!1,duration:0,durationIE:0,durationSafari:0,durationFirefox:0,durationChrome:0,durationOpera:0},g=new jDataView(r);if(r.byteLength<10)return s;if(18249!=g.getUint16(0)||17976!=g.getUint16(2))return s;if(s.width=g.getUint16(6,!0),s.height=g.getUint16(8,!0),s.valid=!0,(w=i(g.getUint8(10,!0)))[0]){var u=e(w);s.globalPalette=!0,s.globalPaletteSize=u/3,o+=u;for(var d=0;d<s.globalPaletteSize;d++){var c=13+3*d,f=g.getUint8(c,!0),h=g.getUint8(c+1,!0),U=g.getUint8(c+2,!0);s.globalPaletteColorsRGB.push({r:f,g:h,b:U})}}o+=13;for(var v={identifier:"0",localPalette:!1,localPaletteSize:0,interlace:!1,comments:[],text:"",left:0,top:0,width:0,height:0,delay:0,disposal:0};;){try{switch(g.getUint8(o,!0)){case 33:var b=g.getUint8(o+1,!0);if(249===b){if(4===g.getUint8(o+2)){var m=g.getUint16(o+4,!0)/100*1e3;m<60&&!s.isBrowserDuration&&(s.isBrowserDuration=!0),v.delay=m,s.duration+=m,s.durationIE+=m<60?t:m,s.durationSafari+=m<20?t:m,s.durationChrome+=m<20?t:m,s.durationFirefox+=m<20?t:m,s.durationOpera+=m<20?t:m;var p=(w=i(g.getUint8(o+3))).slice(3,6).join("");v.disposal=parseInt(p,2),o+=8}else o++}else{var P=a(g,o+=2,!0);switch(b){case 255:"NETSCAPE"===g.getString(8,o+1)&&(s.loopCount=g.getUint8(o+14,!0));break;case 206:v.identifier=P.data;break;case 254:v.comments.push(P.data);break;case 1:v.text=P.data}o+=P.size}break;case 44:var w;if(v.left=g.getUint16(o+1,!0),v.top=g.getUint16(o+3,!0),v.width=g.getUint16(o+5,!0),v.height=g.getUint16(o+7,!0),(w=i(g.getUint8(o+9,!0)))[0]){var z=e(w);v.localPalette=!0,v.localPaletteSize=z/3,o+=z}if(w[1]&&(v.interlace=!0),s.images.push(v),(v={identifier:"0",localPalette:!1,localPaletteSize:0,interlace:!1,comments:[],text:"",left:0,top:0,width:0,height:0,delay:0,disposal:0}).identifier=(++l).toString(),s.images.length>1&&!s.animated&&(s.animated=!0,n))return s;o+=11,o+=(P=a(g,o,!1)).size;break;case 59:return s;default:o++}}catch(t){return s.valid=!1,s}if(o>=r.byteLength)return s}return s}return{isAnimated:function(t){return r(t,!0).animated},getInfo:function(t){return r(t,!1)}}}();