UNPKG

@animech-public/playcanvas

Version:
2 lines (1 loc) 1.9 kB
import{extends as r}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{ReadStream as e}from"../../../core/read-stream.js";import{ADDRESS_REPEAT as t,ADDRESS_CLAMP_TO_EDGE as s,FILTER_NEAREST as n,PIXELFORMAT_RGBA8 as a,TEXTURETYPE_RGBE as i}from"../../../platform/graphics/constants.js";import{Texture as l}from"../../../platform/graphics/texture.js";import{Asset as o}from"../../asset/asset.js";import{TextureParser as f}from"./texture.js";class u extends f{constructor(r){super(),this.maxRetries=0}load(r,e,t){o.fetchArrayBuffer(r.load,e,t,this.maxRetries)}open(e,o,f,u={}){const p=this.parse(o);if(!p)return null;const d=new l(f,r({name:e,addressU:t,addressV:s,minFilter:n,magFilter:n,width:p.width,height:p.height,levels:p.levels,format:a,type:i,mipmaps:!1},u));return d.upload(),d}parse(r){const t=new e(r);if(!t.readLine().startsWith("#?RADIANCE"))return null;const s={};for(;;){const r=t.readLine();if(0===r.length)break;{const e=r.split("=");2===e.length&&(s[e[0]]=e[1])}}if(!s.hasOwnProperty("FORMAT"))return null;const n=t.readLine().split(" ");if(4!==n.length)return null;const a=parseInt(n[1],10),i=parseInt(n[3],10),l=this._readPixels(t,i,a,"-Y"===n[0]);return l?{width:i,height:a,levels:[l]}:null}_readPixels(r,e,t,s){if(e<8||e>32767)return this._readPixelsFlat(r,e,t);const n=[0,0,0,0];if(r.readArray(n),2!==n[0]||2!==n[1]||128&n[2])return r.skip(-4),this._readPixelsFlat(r,e,t);const a=new ArrayBuffer(e*t*4),i=new Uint8Array(a);let l,o,f,u,p,d,m=s?0:4*e*(t-1);for(o=0;o<t;++o){if(o&&r.readArray(n),(n[2]<<8)+n[3]!==e)return null;for(u=0;u<4;++u)for(l=0;l<e;)if(p=r.readU8(),p>128){if(p-=128,l+p>e)return null;for(d=r.readU8(),f=0;f<p;++f)i[m+u+4*l++]=d}else{if(0===p||l+p>e)return null;for(f=0;f<p;++f)i[m+u+4*l++]=r.readU8()}m+=4*e*(s?1:-1)}return i}_readPixelsFlat(r,e,t){return r.remainingBytes===e*t*4?new Uint8Array(r.arraybuffer,r.offset):null}}export{u as HdrParser};