UNPKG

@3846masa/bmp

Version:

Create a BMP (w/ alpha channel) binary from RGBA raw bytes like ImageData.

2 lines (1 loc) 1.09 kB
const A=URL.createObjectURL(new Blob([`(${()=>{const A=Uint8Array.from(atob("Qk0AAAAAAAAAAHoAAABsAAAAAAAAAAAAAAABACAAAwAAAAAAAADDDgAAww4AAAAAAAAAAAAA/wAAAAD/AAAAAP8AAAAA/0JHUnM"),(A=>A.charCodeAt(0))),t=122,e="navigator"in globalThis&&/Trident|Edge/.test(navigator.userAgent);onmessage=({data:[a,n,s,r,o]})=>{try{const i=(({width:a,height:n,data:s},r)=>{const o=Object.assign({strict:!1},r),i=s.byteLength,g=t+i,w=new Uint8Array(g),c=new DataView(w.buffer),d=(A,t)=>c.setUint32(A,t,!0);if(w.set(A),d(2,g),d(18,a),d(22,-n),d(34,i),w.set(s,t),o.strict||e){d(54,16711680),d(62,255);for(let A=0;A<i;A+=4)w[t+A]=s[A+2],w[124+A]=s[A]}return w})({width:n,height:s,data:new Uint8Array(r)},o);postMessage([a,i.buffer],[i.buffer])}catch(A){postMessage([a,void 0,A])}}}})()`])),t=new Worker(A),e=new Map;t.onmessage=({data:[A,t,a]})=>{const[n,s]=e.get(A);e.delete(A),t?n(new Uint8Array(t)):s(Object.assign(new Error,a))};const a=({width:A,height:a,data:n},s)=>new Promise(((r,o)=>{const i=""+Date.now()+Math.random();e.set(i,[r,o]),t.postMessage([i,A,a,n.buffer,s],[n.buffer])}));export{a as convert};