import{L as A}from"./index-6jOCfdig.js";import"./index-Ds2meNS5.js";import"./svelte/svelte_svelte.js";import"./svelte/svelte_animate.js";import"./svelte/svelte_attachments.js";import"./svelte/svelte_easing.js";import"./svelte/svelte_internal_client.js";import"./svelte/svelte_internal_flags_async.js";import"./svelte/svelte_internal_flags_legacy.js";import"./svelte/svelte_internal_flags_tracing.js";import"./svelte/svelte_internal_server.js";import"./svelte/svelte_legacy.js";import"./svelte/svelte_motion.js";import"./svelte/svelte_reactivity.js";import"./svelte/svelte_reactivity_window.js";import"./svelte/svelte_server.js";import"./svelte/svelte_store.js";import"./svelte/svelte_transition.js";import"./svelte/svelte_events.js";const U=1,d=2,N=3,L=9,O=10,Y=11,k=48,z=4,P=0,B=1,C=2,M=3;function G(o){let r=0;return{id_length:o[r++],colormap_type:o[r++],image_type:o[r++],colormap_index:o[r++]|o[r++]<<8,colormap_length:o[r++]|o[r++]<<8,colormap_size:o[r++],origin:[o[r++]|o[r++]<<8,o[r++]|o[r++]<<8],width:o[r++]|o[r++]<<8,height:o[r++]|o[r++]<<8,pixel_size:o[r++],flags:o[r++]}}function R(o,r){if(r.length<19){A.Error("Unable to load TGA file - Not enough data to contain header");return}let c=18;const s=G(r);if(s.id_length+c>r.length){A.Error("Unable to load TGA file - Not enough data");return}c+=s.id_length;let _=!1,f=!1,u=!1;switch(s.image_type){case L:_=!0;case U:f=!0;break;case O:_=!0;case d:break;case Y:_=!0;case N:u=!0;break}let p;const m=s.pixel_size>>3,g=s.width*s.height*m;let n;if(f&&(n=r.subarray(c,c+=s.colormap_length*(s.colormap_size>>3))),_){p=new Uint8Array(g);let I,y,w,b=0;const T=new Uint8Array(m);for(;c<g&&b<g;)if(I=r[c++],y=(I&127)+1,I&128){for(w=0;w<m;++w)T[w]=r[c++];for(w=0;w<y;++w)p.set(T,b+w*m);b+=m*y}else{for(y*=m,w=0;w<y;++w)p[b+w]=r[c++];b+=y}}else p=r.subarray(c,c+=f?s.width*s.height:g);let h,a,i,t,e,l;switch((s.flags&k)>>z){default:case C:h=0,i=1,l=s.width,a=0,t=1,e=s.height;break;case P:h=0,i=1,l=s.width,a=s.height-1,t=-1,e=-1;break;case M:h=s.width-1,i=-1,l=-1,a=0,t=1,e=s.height;break;case B:h=s.width-1,i=-1,l=-1,a=s.height-1,t=-1,e=-1;break}const x="_getImageData"+(u?"Grey":"")+s.pixel_size+"bits",D=j[x](s,n,p,a,t,e,h,i,l);o.getEngine()._uploadDataToTextureDirectly(o,D)}function H(o,r,c,s,_,f,u,p,m){const g=c,n=r,h=o.width,a=o.height;let i,t=0,e,l;const x=new Uint8Array(h*a*4);for(l=s;l!==f;l+=_)for(e=u;e!==m;e+=p,t++)i=g[t],x[(e+h*l)*4+3]=255,x[(e+h*l)*4+2]=n[i*3+0],x[(e+h*l)*4+1]=n[i*3+1],x[(e+h*l)*4+0]=n[i*3+2];return x}function S(o,r,c,s,_,f,u,p,m){const g=c,n=o.width,h=o.height;let a,i=0,t,e;const l=new Uint8Array(n*h*4);for(e=s;e!==f;e+=_)for(t=u;t!==m;t+=p,i+=2){a=g[i+0]+(g[i+1]<<8);const x=((a&31744)>>10)*255/31|0,D=((a&992)>>5)*255/31|0,E=(a&31)*255/31|0;l[(t+n*e)*4+0]=x,l[(t+n*e)*4+1]=D,l[(t+n*e)*4+2]=E,l[(t+n*e)*4+3]=a&32768?0:255}return l}function X(o,r,c,s,_,f,u,p,m){const g=c,n=o.width,h=o.height;let a=0,i,t;const e=new Uint8Array(n*h*4);for(t=s;t!==f;t+=_)for(i=u;i!==m;i+=p,a+=3)e[(i+n*t)*4+3]=255,e[(i+n*t)*4+2]=g[a+0],e[(i+n*t)*4+1]=g[a+1],e[(i+n*t)*4+0]=g[a+2];return e}function v(o,r,c,s,_,f,u,p,m){const g=c,n=o.width,h=o.height;let a=0,i,t;const e=new Uint8Array(n*h*4);for(t=s;t!==f;t+=_)for(i=u;i!==m;i+=p,a+=4)e[(i+n*t)*4+2]=g[a+0],e[(i+n*t)*4+1]=g[a+1],e[(i+n*t)*4+0]=g[a+2],e[(i+n*t)*4+3]=g[a+3];return e}function F(o,r,c,s,_,f,u,p,m){const g=c,n=o.width,h=o.height;let a,i=0,t,e;const l=new Uint8Array(n*h*4);for(e=s;e!==f;e+=_)for(t=u;t!==m;t+=p,i++)a=g[i],l[(t+n*e)*4+0]=a,l[(t+n*e)*4+1]=a,l[(t+n*e)*4+2]=a,l[(t+n*e)*4+3]=255;return l}function K(o,r,c,s,_,f,u,p,m){const g=c,n=o.width,h=o.height;let a=0,i,t;const e=new Uint8Array(n*h*4);for(t=s;t!==f;t+=_)for(i=u;i!==m;i+=p,a+=2)e[(i+n*t)*4+0]=g[a+0],e[(i+n*t)*4+1]=g[a+0],e[(i+n*t)*4+2]=g[a+0],e[(i+n*t)*4+3]=g[a+1];return e}const j={GetTGAHeader:G,UploadContent:R,_getImageData8bits:H,_getImageData16bits:S,_getImageData24bits:X,_getImageData32bits:v,_getImageDataGrey8bits:F,_getImageDataGrey16bits:K};class _t{constructor(){this.supportCascades=!1}loadCubeData(){throw".env not supported in Cube."}loadData(r,c,s){const _=new Uint8Array(r.buffer,r.byteOffset,r.byteLength),f=G(_);s(f.width,f.height,c.generateMipMaps,!1,()=>{R(c,_)})}}export{_t as _TGATextureLoader};
