var e=`https://staticimgly.com/@imgly/background-removal-data/1.7.0/dist/`,t=`/models/isnet_quint8`,n=`isnet_quint8_1.7.0`,r=[`https://huggingface.co/briaai/RMBG-2.0/resolve/main/onnx/model_int8.onnx`,`https://huggingface.co/kn4666/bria-rmbg-2.0-web/resolve/main/onnx/model_uint8.onnx`],i=`rmbg2_int8_bria`,a=1024,o=[128,128,128],s=[256,256,256],c=[.485,.456,.406],l=[.229,.224,.225],u=1800,d=.86,f=`xyxp_matting_model_kind`,p=`rmbg2_int8`,m={isnet_quint8:`IS-Net quint8`,rmbg2_int8:`RMBG-2.0 INT8`},h={isnet_quint8:`约 44MB，速度快，适合低配环境`,rmbg2_int8:`约 366MB，抠图质量更好（CC BY-NC 4.0 非商用）`},g=[`rmbg2_int8`,`isnet_quint8`];async function _(){let e=(await chrome.storage.local.get(f))[f];return e===`isnet_quint8`||e===`rmbg2_int8`?e:p}async function v(e){await chrome.storage.local.set({[f]:e})}function y(e,t,n=u){let r=Math.max(e,t),i=r>n?n/r:1;return{width:Math.max(1,Math.round(e*i)),height:Math.max(1,Math.round(t*i)),scale:i}}async function b(e,t=u){let n=await(await fetch(e)).blob(),r;try{r=await createImageBitmap(n)}catch{throw Error(`图片解码失败`)}try{let{width:e,height:n}=y(r.width,r.height,t),i=document.createElement(`canvas`);i.width=e,i.height=n;let a=i.getContext(`2d`,{willReadFrequently:!0});if(!a)throw Error(`无法创建画布`);return a.fillStyle=`#ffffff`,a.fillRect(0,0,e,n),a.imageSmoothingEnabled=!0,a.imageSmoothingQuality=`high`,a.drawImage(r,0,0,e,n),{data:a.getImageData(0,0,e,n).data,width:e,height:n}}finally{r.close()}}function x(e){let{width:t,height:n,data:r}=e,i=t*n,a=new Float32Array(3*i);for(let e=0,t=0;e<r.length;e+=4,t+=1)a[t]=(r[e]-o[0])/s[0],a[t+i]=(r[e+1]-o[1])/s[1],a[t+i+i]=(r[e+2]-o[2])/s[2];return{data:a,dims:[1,3,n,t]}}function S(e){let{width:t,height:n,data:r}=e.width===1024&&e.height===1024?e:C(e,a,a),i=t*n,o=new Float32Array(3*i);for(let e=0,t=0;e<r.length;e+=4,t+=1){let n=r[e]/255,a=r[e+1]/255,s=r[e+2]/255;o[t]=(n-c[0])/l[0],o[t+i]=(a-c[1])/l[1],o[t+i+i]=(s-c[2])/l[2]}return{data:o,dims:[1,3,n,t]}}function C(e,t,n){let{width:r,height:i,data:a}=e,o=new Uint8ClampedArray(t*n*4),s=r/t,c=i/n;for(let e=0;e<n;e++)for(let n=0;n<t;n++){let l=n*s,u=e*c,d=Math.max(Math.floor(l),0),f=Math.min(Math.ceil(l),r-1),p=Math.max(Math.floor(u),0),m=Math.min(Math.ceil(u),i-1),h=l-d,g=u-p,_=(e*t+n)*4;for(let e=0;e<4;e++){let t=a[(p*r+d)*4+e],n=a[(p*r+f)*4+e],i=a[(m*r+d)*4+e],s=a[(m*r+f)*4+e],c=(1-h)*(1-g)*t+h*(1-g)*n+(1-h)*g*i+h*g*s;o[_+e]=Math.round(c)}}return{data:o,width:t,height:n}}function w(e,t=245,n=.52){let{width:r,height:i,data:a}=e,o=Math.max(1,Math.floor(r*i/4096)),s=0,c=0;for(let e=0;e<r*i;e+=o){let n=e*4,r=a[n],i=a[n+1],o=a[n+2];r>=t&&i>=t&&o>=t&&s++,c++}return c>0&&s/c>=n}function T(e,t=248){let{width:n,height:r,data:i}=e,a=new Uint8ClampedArray(n*r);for(let e=0;e<n*r;e++){let n=e*4,r=i[n],o=i[n+1],s=i[n+2];a[e]=r>=t&&o>=t&&s>=t?0:255}return a}export{a as _,x as a,i as b,h as c,_ as d,v as f,u as g,e as h,C as i,m as l,t as m,w as n,S as o,n as p,b as r,p as s,T as t,g as u,d as v,r as y};