@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 1.69 kB
JavaScript
import{Milliseconds as t}from"../../../../../core/time.js";import{imageTypeToCanvas as e}from"../../../../../geometry/support/meshUtils/exporters/gltf/imageutils.js";import{p as i,d as s}from"../../../../../chunks/index3.js";async function n(n,a){const r=i(n),o=s(r,!0),{width:c,height:d}=r.lsd,m=document.createElement("canvas");m.width=c,m.height=d;const u=m.getContext("2d",{willReadFrequently:!0}),f=[],h=[];for(const i of o){h.push(t(i.delay||100));const s=new ImageData(i.patch,i.dims.width,i.dims.height),n=e(s),a=3===i.disposalType?u.getImageData(i.dims.left,i.dims.top,i.dims.width,i.dims.height):void 0;u.drawImage(n,i.dims.left,i.dims.top);const r=u.getImageData(0,0,c,d);f.push(r),1===i.disposalType||(2===i.disposalType?u.clearRect(i.dims.left,i.dims.top,i.dims.width,i.dims.height):3===i.disposalType&&u.putImageData(a,i.dims.left,i.dims.top))}return{frameDurations:h,getFrame:t=>f[t],width:c,height:d}}const a=[71,73,70];function r(t){const e=new Uint8Array(t);return!a.some(((t,i)=>t!==e[i]))}function o(t){if(!r(t))return!1;const e=new DataView(t),i=e.getUint8(10);let s=13+(128&i?3*2**(1+(7&i)):0),n=0,a=!1;for(;!a;){switch(e.getUint8(s++)){case 33:if(!o())return!1;break;case 44:c();break;case 59:a=!0;break;default:return!1}if(n>1)return!0}function o(){switch(e.getUint8(s++)){case 249:d();break;case 1:m();break;case 254:u();break;case 255:f();break;default:return!1}return!0}function c(){n++,s+=8;const t=e.getUint8(s++);s+=128&t?3*2**(1+(7&t)):0,s++,h()}function d(){s++,s+=4,h()}function m(){n++,s++,s+=12,h()}function u(){h()}function f(){s++,s+=8,s+=3,h()}function h(){let t;for(;t=e.getUint8(s++);)s+=t}return!1}export{o as isAnimatedGIF,r as isGIF,n as parseGif};