/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import e from"../../core/Error.js";import{throwIfAborted as t}from"../../core/promiseUtils.js";async function r(r,a,i){let o;try{o=await n(r,i)}catch(s){throw new e("request:server",`Unable to load ${a}`,{url:a,error:s})}return t(i),o}async function a(r,a,i,o,s){let c;try{c=await n(r,s)}catch(m){throw new e("request:server",`Unable to load tile ${a}/${i}/${o}`,{error:m,level:a,row:i,col:o})}return t(s),c}async function n(e,t){const r=await createImageBitmap(e,{imageOrientation:t?.imageOrientation??"none"}),a=t?.type??(e instanceof Blob?e.type.startsWith("image/")?e.type:t?.allowDeriveTypeFromData?await i(await e.bytes()):void 0:void 0);return new o(r,a)}async function i(e){return e.byteLength<2?"unknown":137===e[0]&&80===e[1]?"image/png":71===e[0]&&73===e[1]?"image/gif":66===e[0]&&77===e[1]?"image/bmp":255===e[0]&&216===e[1]?"image/jpeg":"unknown"}class o{constructor(e,t){this.bitmap=e,this.type=t}get isOpaque(){return"image/jpeg"===this.type}}export{o as CreateBitmapResult,r as createBitmap,n as createBitmapResult,a as createTileBitmap};
