cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
2 lines (1 loc) • 5.04 kB
JavaScript
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class t{constructor(){this.vkFormat=0,this.typeSize=1,this.pixelWidth=0,this.pixelHeight=0,this.pixelDepth=0,this.layerCount=0,this.faceCount=1,this.supercompressionScheme=0,this.levels=[],this.dataFormatDescriptor=[{vendorId:0,descriptorType:0,descriptorBlockSize:0,versionNumber:2,colorModel:0,colorPrimaries:1,transferFunction:2,flags:0,texelBlockDimension:[0,0,0,0],bytesPlane:[0,0,0,0,0,0,0,0],samples:[]}],this.keyValue={},this.globalData=null}}class e{constructor(t,e,n,i){this._dataView=new DataView(t.buffer,t.byteOffset+e,n),this._littleEndian=i,this._offset=0}_nextUint8(){const t=this._dataView.getUint8(this._offset);return this._offset+=1,t}_nextUint16(){const t=this._dataView.getUint16(this._offset,this._littleEndian);return this._offset+=2,t}_nextUint32(){const t=this._dataView.getUint32(this._offset,this._littleEndian);return this._offset+=4,t}_nextUint64(){const t=this._dataView.getUint32(this._offset,this._littleEndian)+2**32*this._dataView.getUint32(this._offset+4,this._littleEndian);return this._offset+=8,t}_nextInt32(){const t=this._dataView.getInt32(this._offset,this._littleEndian);return this._offset+=4,t}_skip(t){return this._offset+=t,this}_scan(t,e=0){const n=this._offset;let i=0;for(;this._dataView.getUint8(this._offset)!==e&&i<t;)i++,this._offset++;return i<t&&this._offset++,new Uint8Array(this._dataView.buffer,this._dataView.byteOffset+n,i)}}const n=[171,75,84,88,32,50,48,187,13,10,26,10];function i(t){return"undefined"!=typeof TextDecoder?(new TextDecoder).decode(t):Buffer.from(t).toString("utf8")}exports.KHR_DF_FLAG_ALPHA_PREMULTIPLIED=1,exports.KHR_DF_TRANSFER_SRGB=2,exports.KHR_SUPERCOMPRESSION_NONE=0,exports.KHR_SUPERCOMPRESSION_ZSTD=2,exports.KTX2Container=t,exports.VK_FORMAT_R16G16B16A16_SFLOAT=97,exports.VK_FORMAT_R16G16_SFLOAT=83,exports.VK_FORMAT_R16_SFLOAT=76,exports.VK_FORMAT_R32G32B32A32_SFLOAT=109,exports.VK_FORMAT_R32G32_SFLOAT=103,exports.VK_FORMAT_R32_SFLOAT=100,exports.VK_FORMAT_R8G8B8A8_SRGB=43,exports.VK_FORMAT_R8G8B8A8_UNORM=37,exports.VK_FORMAT_R8G8_SRGB=22,exports.VK_FORMAT_R8G8_UNORM=16,exports.VK_FORMAT_R8_SRGB=15,exports.VK_FORMAT_R8_UNORM=9,exports.VK_FORMAT_UNDEFINED=0,exports.read=function(s){const _=new Uint8Array(s.buffer,s.byteOffset,n.length);if(_[0]!==n[0]||_[1]!==n[1]||_[2]!==n[2]||_[3]!==n[3]||_[4]!==n[4]||_[5]!==n[5]||_[6]!==n[6]||_[7]!==n[7]||_[8]!==n[8]||_[9]!==n[9]||_[10]!==n[10]||_[11]!==n[11])throw new Error("Missing KTX 2.0 identifier.");const r=new t,o=17*Uint32Array.BYTES_PER_ELEMENT,a=new e(s,n.length,o,!0);r.vkFormat=a._nextUint32(),r.typeSize=a._nextUint32(),r.pixelWidth=a._nextUint32(),r.pixelHeight=a._nextUint32(),r.pixelDepth=a._nextUint32(),r.layerCount=a._nextUint32(),r.faceCount=a._nextUint32();const f=a._nextUint32();r.supercompressionScheme=a._nextUint32();const x=a._nextUint32(),l=a._nextUint32(),U=a._nextUint32(),p=a._nextUint32(),h=a._nextUint64(),c=a._nextUint64(),u=new e(s,n.length+o,3*f*8,!0);for(let t=0;t<f;t++)r.levels.push({levelData:new Uint8Array(s.buffer,s.byteOffset+u._nextUint64(),u._nextUint64()),uncompressedByteLength:u._nextUint64()});const d=new e(s,x,l,!0),R={vendorId:d._skip(4)._nextUint16(),descriptorType:d._nextUint16(),versionNumber:d._nextUint16(),descriptorBlockSize:d._nextUint16(),colorModel:d._nextUint8(),colorPrimaries:d._nextUint8(),transferFunction:d._nextUint8(),flags:d._nextUint8(),texelBlockDimension:[d._nextUint8(),d._nextUint8(),d._nextUint8(),d._nextUint8()],bytesPlane:[d._nextUint8(),d._nextUint8(),d._nextUint8(),d._nextUint8(),d._nextUint8(),d._nextUint8(),d._nextUint8(),d._nextUint8()],samples:[]},O=(R.descriptorBlockSize/4-6)/4;for(let t=0;t<O;t++){const e={bitOffset:d._nextUint16(),bitLength:d._nextUint8(),channelType:d._nextUint8(),samplePosition:[d._nextUint8(),d._nextUint8(),d._nextUint8(),d._nextUint8()],sampleLower:-1/0,sampleUpper:1/0};64&e.channelType?(e.sampleLower=d._nextInt32(),e.sampleUpper=d._nextInt32()):(e.sampleLower=d._nextUint32(),e.sampleUpper=d._nextUint32()),R.samples[t]=e}r.dataFormatDescriptor.length=0,r.dataFormatDescriptor.push(R);const y=new e(s,U,p,!0);for(;y._offset<p;){const t=y._nextUint32(),e=y._scan(t),n=i(e),s=y._scan(t-e.byteLength);r.keyValue[n]=n.match(/^ktx/i)?i(s):s,y._offset%4&&y._skip(4-y._offset%4)}if(c<=0)return r;const A=new e(s,h,c,!0),S=A._nextUint16(),T=A._nextUint16(),F=A._nextUint32(),g=A._nextUint32(),m=A._nextUint32(),w=A._nextUint32(),b=[];for(let t=0;t<f;t++)b.push({imageFlags:A._nextUint32(),rgbSliceByteOffset:A._nextUint32(),rgbSliceByteLength:A._nextUint32(),alphaSliceByteOffset:A._nextUint32(),alphaSliceByteLength:A._nextUint32()});const V=h+A._offset,M=V+F,D=M+g,E=D+m,B=new Uint8Array(s.buffer,s.byteOffset+V,F),K=new Uint8Array(s.buffer,s.byteOffset+M,g),L=new Uint8Array(s.buffer,s.byteOffset+D,m),P=new Uint8Array(s.buffer,s.byteOffset+E,w);return r.globalData={endpointCount:S,selectorCount:T,imageDescs:b,endpointsData:B,selectorsData:K,tablesData:L,extendedData:P},r};