import{L as A}from"./index-CDrXokXW.js";import"./index-DWyDLubb.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 n=0;return{id_length:o[n++],colormap_type:o[n++],image_type:o[n++],colormap_index:o[n++]|o[n++]<<8,colormap_length:o[n++]|o[n++]<<8,colormap_size:o[n++],origin:[o[n++]|o[n++]<<8,o[n++]|o[n++]<<8],width:o[n++]|o[n++]<<8,height:o[n++]|o[n++]<<8,pixel_size:o[n++],flags:o[n++]}}function R(o,n){if(n.length<19){A.Error("Unable to load TGA file - Not enough data to contain header");return}let c=18;const r=G(n);if(r.id_length+c>n.length){A.Error("Unable to load TGA file - Not enough data");return}c+=r.id_length;let _=!1,f=!1,p=!1;switch(r.image_type){case L:_=!0;case U:f=!0;break;case O:_=!0;case d:break;case Y:_=!0;case N:p=!0;break}let m;const u=r.pixel_size>>3,g=r.width*r.height*u;let s;if(f&&(s=n.subarray(c,c+=r.colormap_length*(r.colormap_size>>3))),_){m=new Uint8Array(g);let I,y,w,b=0;const T=new Uint8Array(u);for(;c<g&&b<g;)if(I=n[c++],y=(I&127)+1,I&128){for(w=0;w<u;++w)T[w]=n[c++];for(w=0;w<y;++w)m.set(T,b+w*u);b+=u*y}else{for(y*=u,w=0;w<y;++w)m[b+w]=n[c++];b+=y}}else m=n.subarray(c,c+=f?r.width*r.height:g);let h,a,i,t,e,l;switch((r.flags&k)>>z){default:case C:h=0,i=1,l=r.width,a=0,t=1,e=r.height;break;case P:h=0,i=1,l=r.width,a=r.height-1,t=-1,e=-1;break;case M:h=r.width-1,i=-1,l=-1,a=0,t=1,e=r.height;break;case B:h=r.width-1,i=-1,l=-1,a=r.height-1,t=-1,e=-1;break}const x="_getImageData"+(p?"Grey":"")+r.pixel_size+"bits",D=j[x](r,s,m,a,t,e,h,i,l);o.getEngine()._uploadDataToTextureDirectly(o,D)}function H(o,n,c,r,_,f,p,m,u){const g=c,s=n,h=o.width,a=o.height;let i,t=0,e,l;const x=new Uint8Array(h*a*4);for(l=r;l!==f;l+=_)for(e=p;e!==u;e+=m,t++)i=g[t],x[(e+h*l)*4+3]=255,x[(e+h*l)*4+2]=s[i*3+0],x[(e+h*l)*4+1]=s[i*3+1],x[(e+h*l)*4+0]=s[i*3+2];return x}function S(o,n,c,r,_,f,p,m,u){const g=c,s=o.width,h=o.height;let a,i=0,t,e;const l=new Uint8Array(s*h*4);for(e=r;e!==f;e+=_)for(t=p;t!==u;t+=m,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+s*e)*4+0]=x,l[(t+s*e)*4+1]=D,l[(t+s*e)*4+2]=E,l[(t+s*e)*4+3]=a&32768?0:255}return l}function X(o,n,c,r,_,f,p,m,u){const g=c,s=o.width,h=o.height;let a=0,i,t;const e=new Uint8Array(s*h*4);for(t=r;t!==f;t+=_)for(i=p;i!==u;i+=m,a+=3)e[(i+s*t)*4+3]=255,e[(i+s*t)*4+2]=g[a+0],e[(i+s*t)*4+1]=g[a+1],e[(i+s*t)*4+0]=g[a+2];return e}function v(o,n,c,r,_,f,p,m,u){const g=c,s=o.width,h=o.height;let a=0,i,t;const e=new Uint8Array(s*h*4);for(t=r;t!==f;t+=_)for(i=p;i!==u;i+=m,a+=4)e[(i+s*t)*4+2]=g[a+0],e[(i+s*t)*4+1]=g[a+1],e[(i+s*t)*4+0]=g[a+2],e[(i+s*t)*4+3]=g[a+3];return e}function F(o,n,c,r,_,f,p,m,u){const g=c,s=o.width,h=o.height;let a,i=0,t,e;const l=new Uint8Array(s*h*4);for(e=r;e!==f;e+=_)for(t=p;t!==u;t+=m,i++)a=g[i],l[(t+s*e)*4+0]=a,l[(t+s*e)*4+1]=a,l[(t+s*e)*4+2]=a,l[(t+s*e)*4+3]=255;return l}function K(o,n,c,r,_,f,p,m,u){const g=c,s=o.width,h=o.height;let a=0,i,t;const e=new Uint8Array(s*h*4);for(t=r;t!==f;t+=_)for(i=p;i!==u;i+=m,a+=2)e[(i+s*t)*4+0]=g[a+0],e[(i+s*t)*4+1]=g[a+0],e[(i+s*t)*4+2]=g[a+0],e[(i+s*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 Q{constructor(){this.supportCascades=!1}loadCubeData(){throw".env not supported in Cube."}loadData(n,c,r){const _=new Uint8Array(n.buffer,n.byteOffset,n.byteLength),f=G(_);r(f.width,f.height,c.generateMipMaps,!1,()=>{R(c,_)})}}export{Q as _TGATextureLoader};
