@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 1.34 kB
JavaScript
import{p as t}from"../../../../../chunks/index2.js";import{throwIfAborted as e}from"../../../../../core/promiseUtils.js";import{Milliseconds as o}from"../../../../../core/time.js";async function r(r,n){const i=t(r);if(i instanceof Error)throw i;await i.createImages(),e(n);const{frames:a,width:s,height:p}=i,c=document.createElement("canvas");c.width=s,c.height=p;const l=c.getContext("2d",{willReadFrequently:!0}),m=[],h=[];for(const t of a){h.push(o(t.delay||100));const e=t.imageElement;0===t.blendOp?l.globalCompositeOperation="copy":l.globalCompositeOperation="source-over";const r=2===t.disposeOp?l.getImageData(t.left,t.top,t.width,t.height):void 0;l.drawImage(e,t.left,t.top);const n=l.getImageData(0,0,s,p);m.push(n),0===t.disposeOp||(1===t.disposeOp?l.clearRect(t.left,t.top,t.width,t.height):2===t.disposeOp&&l.putImageData(r,t.left,t.top))}return{frameDurations:h,getFrame:t=>m[t],width:s,height:p}}const n=[137,80,78,71,13,10,26,10];function i(t){const e=new Uint8Array(t);return!n.some(((t,o)=>t!==e[o]))}function a(t){if(!i(t))return!1;const e=new DataView(t),o=new Uint8Array(t);let r,n=8;do{const t=e.getUint32(n);if(r=String.fromCharCode.apply(String,Array.prototype.slice.call(o.subarray(n+4,n+8))),"acTL"===r)return!0;n+=12+t}while("IEND"!==r&&n<o.length);return!1}export{a as isAnimatedPNG,i as isPNG,r as parseApng};