Comparing version 0.0.4 to 0.0.5
@@ -1,2 +0,2 @@ | ||
var t,e,n,i,r,a,s,o,l=new Uint8Array([0]),f=[171,75,84,88,32,50,48,187,13,10,26,10];!function(t){t[t.NONE=0]="NONE",t[t.BASISLZ=1]="BASISLZ",t[t.ZSTD=2]="ZSTD",t[t.ZLIB=3]="ZLIB"}(t||(t={})),function(t){t[t.BASICFORMAT=0]="BASICFORMAT"}(e||(e={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.ETC1S=163]="ETC1S",t[t.UASTC=166]="UASTC"}(n||(n={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.SRGB=1]="SRGB"}(i||(i={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.LINEAR=1]="LINEAR",t[t.SRGB=2]="SRGB",t[t.ITU=3]="ITU",t[t.NTSC=4]="NTSC",t[t.SLOG=5]="SLOG",t[t.SLOG2=6]="SLOG2"}(r||(r={})),function(t){t[t.ALPHA_STRAIGHT=0]="ALPHA_STRAIGHT",t[t.ALPHA_PREMULTIPLIED=1]="ALPHA_PREMULTIPLIED"}(a||(a={})),function(t){t[t.RGB=0]="RGB",t[t.RRR=3]="RRR",t[t.GGG=4]="GGG",t[t.AAA=15]="AAA"}(s||(s={})),function(t){t[t.RGB=0]="RGB",t[t.RGBA=3]="RGBA",t[t.RRR=4]="RRR",t[t.RRRG=5]="RRRG"}(o||(o={}));var U=function(){this.vkFormat=0,this.typeSize=1,this.pixelWidth=0,this.pixelHeight=0,this.pixelDepth=0,this.layerCount=0,this.faceCount=1,this.supercompressionScheme=t.NONE,this.levels=[],this.dataFormatDescriptor=[{vendorId:0,descriptorType:e.BASICFORMAT,versionNumber:2,descriptorBlockSize:40,colorModel:n.UNSPECIFIED,colorPrimaries:i.SRGB,transferFunction:i.SRGB,flags:a.ALPHA_STRAIGHT,texelBlockDimension:{x:4,y:4,z:1,w:1},bytesPlane:[],samples:[]}],this.keyValue={},this.globalData=null},h=function(){function t(t,e,n,i){this._dataView=new DataView(t.buffer,t.byteOffset+e,n),this._littleEndian=i,this._offset=0}var e=t.prototype;return e._nextUint8=function(){var t=this._dataView.getUint8(this._offset);return this._offset+=1,t},e._nextUint16=function(){var t=this._dataView.getUint16(this._offset,this._littleEndian);return this._offset+=2,t},e._nextUint32=function(){var t=this._dataView.getUint32(this._offset,this._littleEndian);return this._offset+=4,t},e._nextUint64=function(){var t=this._dataView.getUint32(this._offset,this._littleEndian),e=this._dataView.getUint32(this._offset+4,this._littleEndian),n=t+Math.pow(2,32)*e;return this._offset+=8,n},e._skip=function(t){return this._offset+=t,this},e._scan=function(t,e){void 0===e&&(e=0);for(var n=this._offset,i=0;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)},t}();function c(){return(c=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}function u(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function _(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return u(t,void 0);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?u(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=t[Symbol.iterator]()).next.bind(n)}function p(t){return"undefined"!=typeof TextEncoder?(new TextEncoder).encode(t):Buffer.from(t)}function g(t){return"undefined"!=typeof TextDecoder?(new TextDecoder).decode(t):Buffer.from(t).toString("utf8")}function y(t){for(var e,n=0,i=_(t);!(e=i()).done;)n+=e.value.byteLength;for(var r,a=new Uint8Array(n),s=0,o=_(t);!(r=o()).done;){var l=r.value;a.set(new Uint8Array(l),s),s+=l.byteLength}return a}var x={keepWriter:!1};exports.KTX2Container=U,exports.read=function(t){var e=new Uint8Array(t.buffer,t.byteOffset,f.length);if(e[0]!==f[0]||e[1]!==f[1]||e[2]!==f[2]||e[3]!==f[3]||e[4]!==f[4]||e[5]!==f[5]||e[6]!==f[6]||e[7]!==f[7]||e[8]!==f[8]||e[9]!==f[9]||e[10]!==f[10]||e[11]!==f[11])throw new Error("Missing KTX 2.0 identifier.");var n=new U,i=17*Uint32Array.BYTES_PER_ELEMENT,r=new h(t,f.length,i,!0);n.vkFormat=r._nextUint32(),n.typeSize=r._nextUint32(),n.pixelWidth=r._nextUint32(),n.pixelHeight=r._nextUint32(),n.pixelDepth=r._nextUint32(),n.layerCount=r._nextUint32(),n.faceCount=r._nextUint32();var a=r._nextUint32();n.supercompressionScheme=r._nextUint32();for(var s=r._nextUint32(),o=r._nextUint32(),l=r._nextUint32(),c=r._nextUint32(),u=r._nextUint64(),_=r._nextUint64(),p=new h(t,f.length+i,3*a*8,!0),y=0;y<a;y++)n.levels.push({levelData:new Uint8Array(t.buffer,t.byteOffset+p._nextUint64(),p._nextUint64()),uncompressedByteLength:p._nextUint64()});for(var x=new h(t,s,o,!0),b={vendorId:x._skip(4)._nextUint16(),descriptorType:x._nextUint16(),versionNumber:x._nextUint16(),descriptorBlockSize:x._nextUint16(),colorModel:x._nextUint8(),colorPrimaries:x._nextUint8(),transferFunction:x._nextUint8(),flags:x._nextUint8(),texelBlockDimension:{x:x._nextUint8()+1,y:x._nextUint8()+1,z:x._nextUint8()+1,w:x._nextUint8()+1},bytesPlane:[x._nextUint8(),x._nextUint8(),x._nextUint8(),x._nextUint8(),x._nextUint8(),x._nextUint8(),x._nextUint8(),x._nextUint8()],samples:[]},d=(b.descriptorBlockSize/4-6)/4,v=0;v<d;v++)b.samples[v]={bitOffset:x._nextUint16(),bitLength:x._nextUint8(),channelID:x._nextUint8(),samplePosition:[x._nextUint8(),x._nextUint8(),x._nextUint8(),x._nextUint8()],sampleLower:x._nextUint32(),sampleUpper:x._nextUint32()};n.dataFormatDescriptor.length=0,n.dataFormatDescriptor.push(b);for(var D=new h(t,l,c,!0);D._offset<c;){var m=D._nextUint32(),A=D._scan(m),w=g(A),S=D._scan(m-A.byteLength);n.keyValue[w]=w.match(/^ktx/i)?g(S):S,m%4&&D._skip(4-m%4)}if(_<=0)return n;for(var B=new h(t,u,_,!0),L=B._nextUint16(),I=B._nextUint16(),R=B._nextUint32(),E=B._nextUint32(),T=B._nextUint32(),O=B._nextUint32(),C=[],P=0;P<a;P++)C.push({imageFlags:B._nextUint32(),rgbSliceByteOffset:B._nextUint32(),rgbSliceByteLength:B._nextUint32(),alphaSliceByteOffset:B._nextUint32(),alphaSliceByteLength:B._nextUint32()});var F=u+B._offset,G=F+R,k=G+E,N=k+T,V=new Uint8Array(t.buffer,t.byteOffset+F,R),M=new Uint8Array(t.buffer,t.byteOffset+G,E),H=new Uint8Array(t.buffer,t.byteOffset+k,T),z=new Uint8Array(t.buffer,t.byteOffset+N,O);return n.globalData={endpointCount:L,selectorCount:I,imageDescs:C,endpointsData:V,selectorsData:M,tablesData:H,extendedData:z},n},exports.write=function(t,n){void 0===n&&(n={}),n=c({},x,n);var i=new ArrayBuffer(0);if(t.globalData){var r=new ArrayBuffer(20+5*t.globalData.imageDescs.length*4),a=new DataView(r);a.setUint16(0,t.globalData.endpointCount,!0),a.setUint16(2,t.globalData.selectorCount,!0),a.setUint32(4,t.globalData.endpointsData.byteLength,!0),a.setUint32(8,t.globalData.selectorsData.byteLength,!0),a.setUint32(12,t.globalData.tablesData.byteLength,!0),a.setUint32(16,t.globalData.extendedData.byteLength,!0);for(var s=0;s<t.globalData.imageDescs.length;s++){var o=t.globalData.imageDescs[s];a.setUint32(20+5*s*4+0,o.imageFlags,!0),a.setUint32(20+5*s*4+4,o.rgbSliceByteOffset,!0),a.setUint32(20+5*s*4+8,o.rgbSliceByteLength,!0),a.setUint32(20+5*s*4+12,o.alphaSliceByteOffset,!0),a.setUint32(20+5*s*4+16,o.alphaSliceByteLength,!0)}i=y([r,t.globalData.endpointsData,t.globalData.selectorsData,t.globalData.tablesData,t.globalData.extendedData])}var U=[],h=t.keyValue;for(var u in n.keepWriter||(h=c({},t.keyValue,{KTXwriter:"KTX-Parse v0.0.4"})),h){var _=h[u],g=p(u),b="string"==typeof _?p(_):_,d=g.byteLength+1+b.byteLength+1,v=d%4?4-d%4:0;U.push(y([new Uint32Array([d]),g,l,b,l,new Uint8Array(v).fill(0)]))}var D=y(U),m=new ArrayBuffer(44),A=new DataView(m);if(1!==t.dataFormatDescriptor.length||t.dataFormatDescriptor[0].descriptorType!==e.BASICFORMAT)throw new Error("Only BASICFORMAT Data Format Descriptor output supported.");var w=t.dataFormatDescriptor[0];A.setUint32(0,44,!0),A.setUint16(4,w.vendorId,!0),A.setUint16(6,w.descriptorType,!0),A.setUint16(8,w.versionNumber,!0),A.setUint16(10,w.descriptorBlockSize,!0),A.setUint8(12,w.colorModel),A.setUint8(13,w.colorPrimaries),A.setUint8(14,w.transferFunction),A.setUint8(15,w.flags),A.setUint8(16,w.texelBlockDimension.x-1),A.setUint8(17,w.texelBlockDimension.y-1),A.setUint8(18,w.texelBlockDimension.z-1),A.setUint8(19,w.texelBlockDimension.w-1);for(var S=0;S<8;S++)A.setUint8(20+S,w.bytesPlane[S]);for(var B=0;B<w.samples.length;B++){var L=w.samples[B],I=28+16*B;A.setUint16(I+0,L.bitOffset,!0),A.setUint8(I+2,L.bitLength),A.setUint8(I+3,L.channelID),A.setUint8(I+4,L.samplePosition[0]),A.setUint8(I+5,L.samplePosition[1]),A.setUint8(I+6,L.samplePosition[2]),A.setUint8(I+7,L.samplePosition[3]),A.setUint32(I+8,L.sampleLower,!0),A.setUint32(I+12,L.sampleUpper,!0)}var R=f.length+68+3*t.levels.length*8,E=R+m.byteLength,T=E+D.byteLength;T%8&&(T+=8-T%8);for(var O=[],C=new DataView(new ArrayBuffer(3*t.levels.length*8)),P=T+i.byteLength,F=0;F<t.levels.length;F++){var G=t.levels[F];O.push(G.levelData),C.setBigUint64(24*F+0,BigInt(P),!0),C.setBigUint64(24*F+8,BigInt(G.levelData.byteLength),!0),C.setBigUint64(24*F+16,BigInt(G.uncompressedByteLength),!0),P+=G.levelData.byteLength}var k=new ArrayBuffer(68),N=new DataView(k);return N.setUint32(0,t.vkFormat,!0),N.setUint32(4,t.typeSize,!0),N.setUint32(8,t.pixelWidth,!0),N.setUint32(12,t.pixelHeight,!0),N.setUint32(16,t.pixelDepth,!0),N.setUint32(20,t.layerCount,!0),N.setUint32(24,t.faceCount,!0),N.setUint32(28,t.levels.length,!0),N.setUint32(32,t.supercompressionScheme,!0),N.setUint32(36,R,!0),N.setUint32(40,m.byteLength,!0),N.setUint32(44,E,!0),N.setUint32(48,D.byteLength,!0),N.setBigUint64(52,BigInt(T),!0),N.setBigUint64(60,BigInt(i.byteLength),!0),new Uint8Array(y([new Uint8Array(f).buffer,k,C.buffer,m,D,new ArrayBuffer(T-(E+D.byteLength)),i].concat(O)))}; | ||
var t,e,n,i,r,a,s,o,l=new Uint8Array([0]),f=[171,75,84,88,32,50,48,187,13,10,26,10];!function(t){t[t.NONE=0]="NONE",t[t.BASISLZ=1]="BASISLZ",t[t.ZSTD=2]="ZSTD",t[t.ZLIB=3]="ZLIB"}(t||(t={})),function(t){t[t.BASICFORMAT=0]="BASICFORMAT"}(e||(e={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.ETC1S=163]="ETC1S",t[t.UASTC=166]="UASTC"}(n||(n={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.SRGB=1]="SRGB"}(i||(i={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.LINEAR=1]="LINEAR",t[t.SRGB=2]="SRGB",t[t.ITU=3]="ITU",t[t.NTSC=4]="NTSC",t[t.SLOG=5]="SLOG",t[t.SLOG2=6]="SLOG2"}(r||(r={})),function(t){t[t.ALPHA_STRAIGHT=0]="ALPHA_STRAIGHT",t[t.ALPHA_PREMULTIPLIED=1]="ALPHA_PREMULTIPLIED"}(a||(a={})),function(t){t[t.RGB=0]="RGB",t[t.RRR=3]="RRR",t[t.GGG=4]="GGG",t[t.AAA=15]="AAA"}(s||(s={})),function(t){t[t.RGB=0]="RGB",t[t.RGBA=3]="RGBA",t[t.RRR=4]="RRR",t[t.RRRG=5]="RRRG"}(o||(o={}));var U=function(){this.vkFormat=0,this.typeSize=1,this.pixelWidth=0,this.pixelHeight=0,this.pixelDepth=0,this.layerCount=0,this.faceCount=1,this.supercompressionScheme=t.NONE,this.levels=[],this.dataFormatDescriptor=[{vendorId:0,descriptorType:e.BASICFORMAT,versionNumber:2,descriptorBlockSize:40,colorModel:n.UNSPECIFIED,colorPrimaries:i.SRGB,transferFunction:i.SRGB,flags:a.ALPHA_STRAIGHT,texelBlockDimension:{x:4,y:4,z:1,w:1},bytesPlane:[],samples:[]}],this.keyValue={},this.globalData=null},h=function(){function t(t,e,n,i){this._dataView=new DataView(t.buffer,t.byteOffset+e,n),this._littleEndian=i,this._offset=0}var e=t.prototype;return e._nextUint8=function(){var t=this._dataView.getUint8(this._offset);return this._offset+=1,t},e._nextUint16=function(){var t=this._dataView.getUint16(this._offset,this._littleEndian);return this._offset+=2,t},e._nextUint32=function(){var t=this._dataView.getUint32(this._offset,this._littleEndian);return this._offset+=4,t},e._nextUint64=function(){var t=this._dataView.getUint32(this._offset,this._littleEndian),e=this._dataView.getUint32(this._offset+4,this._littleEndian),n=t+Math.pow(2,32)*e;return this._offset+=8,n},e._skip=function(t){return this._offset+=t,this},e._scan=function(t,e){void 0===e&&(e=0);for(var n=this._offset,i=0;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)},t}();function c(){return(c=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}function u(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function _(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return u(t,void 0);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?u(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=t[Symbol.iterator]()).next.bind(n)}function p(t){return"undefined"!=typeof TextEncoder?(new TextEncoder).encode(t):Buffer.from(t)}function g(t){return"undefined"!=typeof TextDecoder?(new TextDecoder).decode(t):Buffer.from(t).toString("utf8")}function y(t){for(var e,n=0,i=_(t);!(e=i()).done;)n+=e.value.byteLength;for(var r,a=new Uint8Array(n),s=0,o=_(t);!(r=o()).done;){var l=r.value;a.set(new Uint8Array(l),s),s+=l.byteLength}return a}var x={keepWriter:!1};exports.KTX2Container=U,exports.read=function(t){var e=new Uint8Array(t.buffer,t.byteOffset,f.length);if(e[0]!==f[0]||e[1]!==f[1]||e[2]!==f[2]||e[3]!==f[3]||e[4]!==f[4]||e[5]!==f[5]||e[6]!==f[6]||e[7]!==f[7]||e[8]!==f[8]||e[9]!==f[9]||e[10]!==f[10]||e[11]!==f[11])throw new Error("Missing KTX 2.0 identifier.");var n=new U,i=17*Uint32Array.BYTES_PER_ELEMENT,r=new h(t,f.length,i,!0);n.vkFormat=r._nextUint32(),n.typeSize=r._nextUint32(),n.pixelWidth=r._nextUint32(),n.pixelHeight=r._nextUint32(),n.pixelDepth=r._nextUint32(),n.layerCount=r._nextUint32(),n.faceCount=r._nextUint32();var a=r._nextUint32();n.supercompressionScheme=r._nextUint32();for(var s=r._nextUint32(),o=r._nextUint32(),l=r._nextUint32(),c=r._nextUint32(),u=r._nextUint64(),_=r._nextUint64(),p=new h(t,f.length+i,3*a*8,!0),y=0;y<a;y++)n.levels.push({levelData:new Uint8Array(t.buffer,t.byteOffset+p._nextUint64(),p._nextUint64()),uncompressedByteLength:p._nextUint64()});for(var x=new h(t,s,o,!0),b={vendorId:x._skip(4)._nextUint16(),descriptorType:x._nextUint16(),versionNumber:x._nextUint16(),descriptorBlockSize:x._nextUint16(),colorModel:x._nextUint8(),colorPrimaries:x._nextUint8(),transferFunction:x._nextUint8(),flags:x._nextUint8(),texelBlockDimension:{x:x._nextUint8()+1,y:x._nextUint8()+1,z:x._nextUint8()+1,w:x._nextUint8()+1},bytesPlane:[x._nextUint8(),x._nextUint8(),x._nextUint8(),x._nextUint8(),x._nextUint8(),x._nextUint8(),x._nextUint8(),x._nextUint8()],samples:[]},d=(b.descriptorBlockSize/4-6)/4,v=0;v<d;v++)b.samples[v]={bitOffset:x._nextUint16(),bitLength:x._nextUint8(),channelID:x._nextUint8(),samplePosition:[x._nextUint8(),x._nextUint8(),x._nextUint8(),x._nextUint8()],sampleLower:x._nextUint32(),sampleUpper:x._nextUint32()};n.dataFormatDescriptor.length=0,n.dataFormatDescriptor.push(b);for(var D=new h(t,l,c,!0);D._offset<c;){var m=D._nextUint32(),A=D._scan(m),w=g(A),S=D._scan(m-A.byteLength);n.keyValue[w]=w.match(/^ktx/i)?g(S):S,D._offset%4&&D._skip(4-D._offset%4)}if(_<=0)return n;for(var B=new h(t,u,_,!0),L=B._nextUint16(),I=B._nextUint16(),R=B._nextUint32(),E=B._nextUint32(),T=B._nextUint32(),O=B._nextUint32(),C=[],P=0;P<a;P++)C.push({imageFlags:B._nextUint32(),rgbSliceByteOffset:B._nextUint32(),rgbSliceByteLength:B._nextUint32(),alphaSliceByteOffset:B._nextUint32(),alphaSliceByteLength:B._nextUint32()});var F=u+B._offset,G=F+R,k=G+E,N=k+T,V=new Uint8Array(t.buffer,t.byteOffset+F,R),M=new Uint8Array(t.buffer,t.byteOffset+G,E),H=new Uint8Array(t.buffer,t.byteOffset+k,T),z=new Uint8Array(t.buffer,t.byteOffset+N,O);return n.globalData={endpointCount:L,selectorCount:I,imageDescs:C,endpointsData:V,selectorsData:M,tablesData:H,extendedData:z},n},exports.write=function(t,n){void 0===n&&(n={}),n=c({},x,n);var i=new ArrayBuffer(0);if(t.globalData){var r=new ArrayBuffer(20+5*t.globalData.imageDescs.length*4),a=new DataView(r);a.setUint16(0,t.globalData.endpointCount,!0),a.setUint16(2,t.globalData.selectorCount,!0),a.setUint32(4,t.globalData.endpointsData.byteLength,!0),a.setUint32(8,t.globalData.selectorsData.byteLength,!0),a.setUint32(12,t.globalData.tablesData.byteLength,!0),a.setUint32(16,t.globalData.extendedData.byteLength,!0);for(var s=0;s<t.globalData.imageDescs.length;s++){var o=t.globalData.imageDescs[s];a.setUint32(20+5*s*4+0,o.imageFlags,!0),a.setUint32(20+5*s*4+4,o.rgbSliceByteOffset,!0),a.setUint32(20+5*s*4+8,o.rgbSliceByteLength,!0),a.setUint32(20+5*s*4+12,o.alphaSliceByteOffset,!0),a.setUint32(20+5*s*4+16,o.alphaSliceByteLength,!0)}i=y([r,t.globalData.endpointsData,t.globalData.selectorsData,t.globalData.tablesData,t.globalData.extendedData])}var U=[],h=t.keyValue;for(var u in n.keepWriter||(h=c({},t.keyValue,{KTXwriter:"KTX-Parse v0.0.5"})),h){var _=h[u],g=p(u),b="string"==typeof _?p(_):_,d=g.byteLength+1+b.byteLength+1,v=d%4?4-d%4:0;U.push(y([new Uint32Array([d]),g,l,b,l,new Uint8Array(v).fill(0)]))}var D=y(U),m=new ArrayBuffer(44),A=new DataView(m);if(1!==t.dataFormatDescriptor.length||t.dataFormatDescriptor[0].descriptorType!==e.BASICFORMAT)throw new Error("Only BASICFORMAT Data Format Descriptor output supported.");var w=t.dataFormatDescriptor[0];A.setUint32(0,44,!0),A.setUint16(4,w.vendorId,!0),A.setUint16(6,w.descriptorType,!0),A.setUint16(8,w.versionNumber,!0),A.setUint16(10,w.descriptorBlockSize,!0),A.setUint8(12,w.colorModel),A.setUint8(13,w.colorPrimaries),A.setUint8(14,w.transferFunction),A.setUint8(15,w.flags),A.setUint8(16,w.texelBlockDimension.x-1),A.setUint8(17,w.texelBlockDimension.y-1),A.setUint8(18,w.texelBlockDimension.z-1),A.setUint8(19,w.texelBlockDimension.w-1);for(var S=0;S<8;S++)A.setUint8(20+S,w.bytesPlane[S]);for(var B=0;B<w.samples.length;B++){var L=w.samples[B],I=28+16*B;A.setUint16(I+0,L.bitOffset,!0),A.setUint8(I+2,L.bitLength),A.setUint8(I+3,L.channelID),A.setUint8(I+4,L.samplePosition[0]),A.setUint8(I+5,L.samplePosition[1]),A.setUint8(I+6,L.samplePosition[2]),A.setUint8(I+7,L.samplePosition[3]),A.setUint32(I+8,L.sampleLower,!0),A.setUint32(I+12,L.sampleUpper,!0)}var R=f.length+68+3*t.levels.length*8,E=R+m.byteLength,T=E+D.byteLength;T%8&&(T+=8-T%8);for(var O=[],C=new DataView(new ArrayBuffer(3*t.levels.length*8)),P=T+i.byteLength,F=0;F<t.levels.length;F++){var G=t.levels[F];O.push(G.levelData),C.setBigUint64(24*F+0,BigInt(P),!0),C.setBigUint64(24*F+8,BigInt(G.levelData.byteLength),!0),C.setBigUint64(24*F+16,BigInt(G.uncompressedByteLength),!0),P+=G.levelData.byteLength}var k=new ArrayBuffer(68),N=new DataView(k);return N.setUint32(0,t.vkFormat,!0),N.setUint32(4,t.typeSize,!0),N.setUint32(8,t.pixelWidth,!0),N.setUint32(12,t.pixelHeight,!0),N.setUint32(16,t.pixelDepth,!0),N.setUint32(20,t.layerCount,!0),N.setUint32(24,t.faceCount,!0),N.setUint32(28,t.levels.length,!0),N.setUint32(32,t.supercompressionScheme,!0),N.setUint32(36,R,!0),N.setUint32(40,m.byteLength,!0),N.setUint32(44,E,!0),N.setUint32(48,D.byteLength,!0),N.setBigUint64(52,BigInt(T),!0),N.setBigUint64(60,BigInt(i.byteLength),!0),new Uint8Array(y([new Uint8Array(f).buffer,k,C.buffer,m,D,new ArrayBuffer(T-(E+D.byteLength)),i].concat(O)))}; | ||
//# sourceMappingURL=ktx-parse.js.map |
@@ -1,2 +0,2 @@ | ||
const t=new Uint8Array([0]),e=[171,75,84,88,32,50,48,187,13,10,26,10];var n,i,s,a,r,o,l,f;!function(t){t[t.NONE=0]="NONE",t[t.BASISLZ=1]="BASISLZ",t[t.ZSTD=2]="ZSTD",t[t.ZLIB=3]="ZLIB"}(n||(n={})),function(t){t[t.BASICFORMAT=0]="BASICFORMAT"}(i||(i={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.ETC1S=163]="ETC1S",t[t.UASTC=166]="UASTC"}(s||(s={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.SRGB=1]="SRGB"}(a||(a={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.LINEAR=1]="LINEAR",t[t.SRGB=2]="SRGB",t[t.ITU=3]="ITU",t[t.NTSC=4]="NTSC",t[t.SLOG=5]="SLOG",t[t.SLOG2=6]="SLOG2"}(r||(r={})),function(t){t[t.ALPHA_STRAIGHT=0]="ALPHA_STRAIGHT",t[t.ALPHA_PREMULTIPLIED=1]="ALPHA_PREMULTIPLIED"}(o||(o={})),function(t){t[t.RGB=0]="RGB",t[t.RRR=3]="RRR",t[t.GGG=4]="GGG",t[t.AAA=15]="AAA"}(l||(l={})),function(t){t[t.RGB=0]="RGB",t[t.RGBA=3]="RGBA",t[t.RRR=4]="RRR",t[t.RRRG=5]="RRRG"}(f||(f={}));class U{constructor(){this.vkFormat=0,this.typeSize=1,this.pixelWidth=0,this.pixelHeight=0,this.pixelDepth=0,this.layerCount=0,this.faceCount=1,this.supercompressionScheme=n.NONE,this.levels=[],this.dataFormatDescriptor=[{vendorId:0,descriptorType:i.BASICFORMAT,versionNumber:2,descriptorBlockSize:40,colorModel:s.UNSPECIFIED,colorPrimaries:a.SRGB,transferFunction:a.SRGB,flags:o.ALPHA_STRAIGHT,texelBlockDimension:{x:4,y:4,z:1,w:1},bytesPlane:[],samples:[]}],this.keyValue={},this.globalData=null}}class c{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}_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)}}function h(t){return"undefined"!=typeof TextEncoder?(new TextEncoder).encode(t):Buffer.from(t)}function _(t){return"undefined"!=typeof TextDecoder?(new TextDecoder).decode(t):Buffer.from(t).toString("utf8")}function g(t){let e=0;for(const n of t)e+=n.byteLength;const n=new Uint8Array(e);let i=0;for(const e of t)n.set(new Uint8Array(e),i),i+=e.byteLength;return n}function p(t){const n=new Uint8Array(t.buffer,t.byteOffset,e.length);if(n[0]!==e[0]||n[1]!==e[1]||n[2]!==e[2]||n[3]!==e[3]||n[4]!==e[4]||n[5]!==e[5]||n[6]!==e[6]||n[7]!==e[7]||n[8]!==e[8]||n[9]!==e[9]||n[10]!==e[10]||n[11]!==e[11])throw new Error("Missing KTX 2.0 identifier.");const i=new U,s=17*Uint32Array.BYTES_PER_ELEMENT,a=new c(t,e.length,s,!0);i.vkFormat=a._nextUint32(),i.typeSize=a._nextUint32(),i.pixelWidth=a._nextUint32(),i.pixelHeight=a._nextUint32(),i.pixelDepth=a._nextUint32(),i.layerCount=a._nextUint32(),i.faceCount=a._nextUint32();const r=a._nextUint32();i.supercompressionScheme=a._nextUint32();const o=a._nextUint32(),l=a._nextUint32(),f=a._nextUint32(),h=a._nextUint32(),g=a._nextUint64(),p=a._nextUint64(),x=new c(t,e.length+s,3*r*8,!0);for(let e=0;e<r;e++)i.levels.push({levelData:new Uint8Array(t.buffer,t.byteOffset+x._nextUint64(),x._nextUint64()),uncompressedByteLength:x._nextUint64()});const u=new c(t,o,l,!0),y={vendorId:u._skip(4)._nextUint16(),descriptorType:u._nextUint16(),versionNumber:u._nextUint16(),descriptorBlockSize:u._nextUint16(),colorModel:u._nextUint8(),colorPrimaries:u._nextUint8(),transferFunction:u._nextUint8(),flags:u._nextUint8(),texelBlockDimension:{x:u._nextUint8()+1,y:u._nextUint8()+1,z:u._nextUint8()+1,w:u._nextUint8()+1},bytesPlane:[u._nextUint8(),u._nextUint8(),u._nextUint8(),u._nextUint8(),u._nextUint8(),u._nextUint8(),u._nextUint8(),u._nextUint8()],samples:[]},D=(y.descriptorBlockSize/4-6)/4;for(let t=0;t<D;t++)y.samples[t]={bitOffset:u._nextUint16(),bitLength:u._nextUint8(),channelID:u._nextUint8(),samplePosition:[u._nextUint8(),u._nextUint8(),u._nextUint8(),u._nextUint8()],sampleLower:u._nextUint32(),sampleUpper:u._nextUint32()};i.dataFormatDescriptor.length=0,i.dataFormatDescriptor.push(y);const b=new c(t,f,h,!0);for(;b._offset<h;){const t=b._nextUint32(),e=b._scan(t),n=_(e),s=b._scan(t-e.byteLength);i.keyValue[n]=n.match(/^ktx/i)?_(s):s,t%4&&b._skip(4-t%4)}if(p<=0)return i;const d=new c(t,g,p,!0),B=d._nextUint16(),w=d._nextUint16(),A=d._nextUint32(),S=d._nextUint32(),m=d._nextUint32(),L=d._nextUint32(),I=[];for(let t=0;t<r;t++)I.push({imageFlags:d._nextUint32(),rgbSliceByteOffset:d._nextUint32(),rgbSliceByteLength:d._nextUint32(),alphaSliceByteOffset:d._nextUint32(),alphaSliceByteLength:d._nextUint32()});const R=g+d._offset,E=R+A,T=E+S,O=T+m,P=new Uint8Array(t.buffer,t.byteOffset+R,A),C=new Uint8Array(t.buffer,t.byteOffset+E,S),F=new Uint8Array(t.buffer,t.byteOffset+T,m),G=new Uint8Array(t.buffer,t.byteOffset+O,L);return i.globalData={endpointCount:B,selectorCount:w,imageDescs:I,endpointsData:P,selectorsData:C,tablesData:F,extendedData:G},i}function x(){return(x=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}const u={keepWriter:!1};function y(n,s={}){s=x({},u,s);let a=new ArrayBuffer(0);if(n.globalData){const t=new ArrayBuffer(20+5*n.globalData.imageDescs.length*4),e=new DataView(t);e.setUint16(0,n.globalData.endpointCount,!0),e.setUint16(2,n.globalData.selectorCount,!0),e.setUint32(4,n.globalData.endpointsData.byteLength,!0),e.setUint32(8,n.globalData.selectorsData.byteLength,!0),e.setUint32(12,n.globalData.tablesData.byteLength,!0),e.setUint32(16,n.globalData.extendedData.byteLength,!0);for(let t=0;t<n.globalData.imageDescs.length;t++){const i=n.globalData.imageDescs[t];e.setUint32(20+5*t*4+0,i.imageFlags,!0),e.setUint32(20+5*t*4+4,i.rgbSliceByteOffset,!0),e.setUint32(20+5*t*4+8,i.rgbSliceByteLength,!0),e.setUint32(20+5*t*4+12,i.alphaSliceByteOffset,!0),e.setUint32(20+5*t*4+16,i.alphaSliceByteLength,!0)}a=g([t,n.globalData.endpointsData,n.globalData.selectorsData,n.globalData.tablesData,n.globalData.extendedData])}const r=[];let o=n.keyValue;s.keepWriter||(o=x({},n.keyValue,{KTXwriter:"KTX-Parse v0.0.4"}));for(const e in o){const n=o[e],i=h(e),s="string"==typeof n?h(n):n,a=i.byteLength+1+s.byteLength+1,l=a%4?4-a%4:0;r.push(g([new Uint32Array([a]),i,t,s,t,new Uint8Array(l).fill(0)]))}const l=g(r),f=new ArrayBuffer(44),U=new DataView(f);if(1!==n.dataFormatDescriptor.length||n.dataFormatDescriptor[0].descriptorType!==i.BASICFORMAT)throw new Error("Only BASICFORMAT Data Format Descriptor output supported.");const c=n.dataFormatDescriptor[0];U.setUint32(0,44,!0),U.setUint16(4,c.vendorId,!0),U.setUint16(6,c.descriptorType,!0),U.setUint16(8,c.versionNumber,!0),U.setUint16(10,c.descriptorBlockSize,!0),U.setUint8(12,c.colorModel),U.setUint8(13,c.colorPrimaries),U.setUint8(14,c.transferFunction),U.setUint8(15,c.flags),U.setUint8(16,c.texelBlockDimension.x-1),U.setUint8(17,c.texelBlockDimension.y-1),U.setUint8(18,c.texelBlockDimension.z-1),U.setUint8(19,c.texelBlockDimension.w-1);for(let t=0;t<8;t++)U.setUint8(20+t,c.bytesPlane[t]);for(let t=0;t<c.samples.length;t++){const e=c.samples[t],n=28+16*t;U.setUint16(n+0,e.bitOffset,!0),U.setUint8(n+2,e.bitLength),U.setUint8(n+3,e.channelID),U.setUint8(n+4,e.samplePosition[0]),U.setUint8(n+5,e.samplePosition[1]),U.setUint8(n+6,e.samplePosition[2]),U.setUint8(n+7,e.samplePosition[3]),U.setUint32(n+8,e.sampleLower,!0),U.setUint32(n+12,e.sampleUpper,!0)}const _=e.length+68+3*n.levels.length*8,p=_+f.byteLength;let y=p+l.byteLength;y%8&&(y+=8-y%8);const D=[],b=new DataView(new ArrayBuffer(3*n.levels.length*8));let d=y+a.byteLength;for(let t=0;t<n.levels.length;t++){const e=n.levels[t];D.push(e.levelData),b.setBigUint64(24*t+0,BigInt(d),!0),b.setBigUint64(24*t+8,BigInt(e.levelData.byteLength),!0),b.setBigUint64(24*t+16,BigInt(e.uncompressedByteLength),!0),d+=e.levelData.byteLength}const B=new ArrayBuffer(68),w=new DataView(B);return w.setUint32(0,n.vkFormat,!0),w.setUint32(4,n.typeSize,!0),w.setUint32(8,n.pixelWidth,!0),w.setUint32(12,n.pixelHeight,!0),w.setUint32(16,n.pixelDepth,!0),w.setUint32(20,n.layerCount,!0),w.setUint32(24,n.faceCount,!0),w.setUint32(28,n.levels.length,!0),w.setUint32(32,n.supercompressionScheme,!0),w.setUint32(36,_,!0),w.setUint32(40,f.byteLength,!0),w.setUint32(44,p,!0),w.setUint32(48,l.byteLength,!0),w.setBigUint64(52,BigInt(y),!0),w.setBigUint64(60,BigInt(a.byteLength),!0),new Uint8Array(g([new Uint8Array(e).buffer,B,b.buffer,f,l,new ArrayBuffer(y-(p+l.byteLength)),a,...D]))}export{U as KTX2Container,p as read,y as write}; | ||
const t=new Uint8Array([0]),e=[171,75,84,88,32,50,48,187,13,10,26,10];var n,i,s,a,r,o,l,f;!function(t){t[t.NONE=0]="NONE",t[t.BASISLZ=1]="BASISLZ",t[t.ZSTD=2]="ZSTD",t[t.ZLIB=3]="ZLIB"}(n||(n={})),function(t){t[t.BASICFORMAT=0]="BASICFORMAT"}(i||(i={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.ETC1S=163]="ETC1S",t[t.UASTC=166]="UASTC"}(s||(s={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.SRGB=1]="SRGB"}(a||(a={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.LINEAR=1]="LINEAR",t[t.SRGB=2]="SRGB",t[t.ITU=3]="ITU",t[t.NTSC=4]="NTSC",t[t.SLOG=5]="SLOG",t[t.SLOG2=6]="SLOG2"}(r||(r={})),function(t){t[t.ALPHA_STRAIGHT=0]="ALPHA_STRAIGHT",t[t.ALPHA_PREMULTIPLIED=1]="ALPHA_PREMULTIPLIED"}(o||(o={})),function(t){t[t.RGB=0]="RGB",t[t.RRR=3]="RRR",t[t.GGG=4]="GGG",t[t.AAA=15]="AAA"}(l||(l={})),function(t){t[t.RGB=0]="RGB",t[t.RGBA=3]="RGBA",t[t.RRR=4]="RRR",t[t.RRRG=5]="RRRG"}(f||(f={}));class U{constructor(){this.vkFormat=0,this.typeSize=1,this.pixelWidth=0,this.pixelHeight=0,this.pixelDepth=0,this.layerCount=0,this.faceCount=1,this.supercompressionScheme=n.NONE,this.levels=[],this.dataFormatDescriptor=[{vendorId:0,descriptorType:i.BASICFORMAT,versionNumber:2,descriptorBlockSize:40,colorModel:s.UNSPECIFIED,colorPrimaries:a.SRGB,transferFunction:a.SRGB,flags:o.ALPHA_STRAIGHT,texelBlockDimension:{x:4,y:4,z:1,w:1},bytesPlane:[],samples:[]}],this.keyValue={},this.globalData=null}}class c{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}_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)}}function h(t){return"undefined"!=typeof TextEncoder?(new TextEncoder).encode(t):Buffer.from(t)}function _(t){return"undefined"!=typeof TextDecoder?(new TextDecoder).decode(t):Buffer.from(t).toString("utf8")}function g(t){let e=0;for(const n of t)e+=n.byteLength;const n=new Uint8Array(e);let i=0;for(const e of t)n.set(new Uint8Array(e),i),i+=e.byteLength;return n}function p(t){const n=new Uint8Array(t.buffer,t.byteOffset,e.length);if(n[0]!==e[0]||n[1]!==e[1]||n[2]!==e[2]||n[3]!==e[3]||n[4]!==e[4]||n[5]!==e[5]||n[6]!==e[6]||n[7]!==e[7]||n[8]!==e[8]||n[9]!==e[9]||n[10]!==e[10]||n[11]!==e[11])throw new Error("Missing KTX 2.0 identifier.");const i=new U,s=17*Uint32Array.BYTES_PER_ELEMENT,a=new c(t,e.length,s,!0);i.vkFormat=a._nextUint32(),i.typeSize=a._nextUint32(),i.pixelWidth=a._nextUint32(),i.pixelHeight=a._nextUint32(),i.pixelDepth=a._nextUint32(),i.layerCount=a._nextUint32(),i.faceCount=a._nextUint32();const r=a._nextUint32();i.supercompressionScheme=a._nextUint32();const o=a._nextUint32(),l=a._nextUint32(),f=a._nextUint32(),h=a._nextUint32(),g=a._nextUint64(),p=a._nextUint64(),x=new c(t,e.length+s,3*r*8,!0);for(let e=0;e<r;e++)i.levels.push({levelData:new Uint8Array(t.buffer,t.byteOffset+x._nextUint64(),x._nextUint64()),uncompressedByteLength:x._nextUint64()});const u=new c(t,o,l,!0),y={vendorId:u._skip(4)._nextUint16(),descriptorType:u._nextUint16(),versionNumber:u._nextUint16(),descriptorBlockSize:u._nextUint16(),colorModel:u._nextUint8(),colorPrimaries:u._nextUint8(),transferFunction:u._nextUint8(),flags:u._nextUint8(),texelBlockDimension:{x:u._nextUint8()+1,y:u._nextUint8()+1,z:u._nextUint8()+1,w:u._nextUint8()+1},bytesPlane:[u._nextUint8(),u._nextUint8(),u._nextUint8(),u._nextUint8(),u._nextUint8(),u._nextUint8(),u._nextUint8(),u._nextUint8()],samples:[]},D=(y.descriptorBlockSize/4-6)/4;for(let t=0;t<D;t++)y.samples[t]={bitOffset:u._nextUint16(),bitLength:u._nextUint8(),channelID:u._nextUint8(),samplePosition:[u._nextUint8(),u._nextUint8(),u._nextUint8(),u._nextUint8()],sampleLower:u._nextUint32(),sampleUpper:u._nextUint32()};i.dataFormatDescriptor.length=0,i.dataFormatDescriptor.push(y);const b=new c(t,f,h,!0);for(;b._offset<h;){const t=b._nextUint32(),e=b._scan(t),n=_(e),s=b._scan(t-e.byteLength);i.keyValue[n]=n.match(/^ktx/i)?_(s):s,b._offset%4&&b._skip(4-b._offset%4)}if(p<=0)return i;const d=new c(t,g,p,!0),B=d._nextUint16(),w=d._nextUint16(),A=d._nextUint32(),S=d._nextUint32(),m=d._nextUint32(),L=d._nextUint32(),I=[];for(let t=0;t<r;t++)I.push({imageFlags:d._nextUint32(),rgbSliceByteOffset:d._nextUint32(),rgbSliceByteLength:d._nextUint32(),alphaSliceByteOffset:d._nextUint32(),alphaSliceByteLength:d._nextUint32()});const R=g+d._offset,E=R+A,T=E+S,O=T+m,P=new Uint8Array(t.buffer,t.byteOffset+R,A),C=new Uint8Array(t.buffer,t.byteOffset+E,S),F=new Uint8Array(t.buffer,t.byteOffset+T,m),G=new Uint8Array(t.buffer,t.byteOffset+O,L);return i.globalData={endpointCount:B,selectorCount:w,imageDescs:I,endpointsData:P,selectorsData:C,tablesData:F,extendedData:G},i}function x(){return(x=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}const u={keepWriter:!1};function y(n,s={}){s=x({},u,s);let a=new ArrayBuffer(0);if(n.globalData){const t=new ArrayBuffer(20+5*n.globalData.imageDescs.length*4),e=new DataView(t);e.setUint16(0,n.globalData.endpointCount,!0),e.setUint16(2,n.globalData.selectorCount,!0),e.setUint32(4,n.globalData.endpointsData.byteLength,!0),e.setUint32(8,n.globalData.selectorsData.byteLength,!0),e.setUint32(12,n.globalData.tablesData.byteLength,!0),e.setUint32(16,n.globalData.extendedData.byteLength,!0);for(let t=0;t<n.globalData.imageDescs.length;t++){const i=n.globalData.imageDescs[t];e.setUint32(20+5*t*4+0,i.imageFlags,!0),e.setUint32(20+5*t*4+4,i.rgbSliceByteOffset,!0),e.setUint32(20+5*t*4+8,i.rgbSliceByteLength,!0),e.setUint32(20+5*t*4+12,i.alphaSliceByteOffset,!0),e.setUint32(20+5*t*4+16,i.alphaSliceByteLength,!0)}a=g([t,n.globalData.endpointsData,n.globalData.selectorsData,n.globalData.tablesData,n.globalData.extendedData])}const r=[];let o=n.keyValue;s.keepWriter||(o=x({},n.keyValue,{KTXwriter:"KTX-Parse v0.0.5"}));for(const e in o){const n=o[e],i=h(e),s="string"==typeof n?h(n):n,a=i.byteLength+1+s.byteLength+1,l=a%4?4-a%4:0;r.push(g([new Uint32Array([a]),i,t,s,t,new Uint8Array(l).fill(0)]))}const l=g(r),f=new ArrayBuffer(44),U=new DataView(f);if(1!==n.dataFormatDescriptor.length||n.dataFormatDescriptor[0].descriptorType!==i.BASICFORMAT)throw new Error("Only BASICFORMAT Data Format Descriptor output supported.");const c=n.dataFormatDescriptor[0];U.setUint32(0,44,!0),U.setUint16(4,c.vendorId,!0),U.setUint16(6,c.descriptorType,!0),U.setUint16(8,c.versionNumber,!0),U.setUint16(10,c.descriptorBlockSize,!0),U.setUint8(12,c.colorModel),U.setUint8(13,c.colorPrimaries),U.setUint8(14,c.transferFunction),U.setUint8(15,c.flags),U.setUint8(16,c.texelBlockDimension.x-1),U.setUint8(17,c.texelBlockDimension.y-1),U.setUint8(18,c.texelBlockDimension.z-1),U.setUint8(19,c.texelBlockDimension.w-1);for(let t=0;t<8;t++)U.setUint8(20+t,c.bytesPlane[t]);for(let t=0;t<c.samples.length;t++){const e=c.samples[t],n=28+16*t;U.setUint16(n+0,e.bitOffset,!0),U.setUint8(n+2,e.bitLength),U.setUint8(n+3,e.channelID),U.setUint8(n+4,e.samplePosition[0]),U.setUint8(n+5,e.samplePosition[1]),U.setUint8(n+6,e.samplePosition[2]),U.setUint8(n+7,e.samplePosition[3]),U.setUint32(n+8,e.sampleLower,!0),U.setUint32(n+12,e.sampleUpper,!0)}const _=e.length+68+3*n.levels.length*8,p=_+f.byteLength;let y=p+l.byteLength;y%8&&(y+=8-y%8);const D=[],b=new DataView(new ArrayBuffer(3*n.levels.length*8));let d=y+a.byteLength;for(let t=0;t<n.levels.length;t++){const e=n.levels[t];D.push(e.levelData),b.setBigUint64(24*t+0,BigInt(d),!0),b.setBigUint64(24*t+8,BigInt(e.levelData.byteLength),!0),b.setBigUint64(24*t+16,BigInt(e.uncompressedByteLength),!0),d+=e.levelData.byteLength}const B=new ArrayBuffer(68),w=new DataView(B);return w.setUint32(0,n.vkFormat,!0),w.setUint32(4,n.typeSize,!0),w.setUint32(8,n.pixelWidth,!0),w.setUint32(12,n.pixelHeight,!0),w.setUint32(16,n.pixelDepth,!0),w.setUint32(20,n.layerCount,!0),w.setUint32(24,n.faceCount,!0),w.setUint32(28,n.levels.length,!0),w.setUint32(32,n.supercompressionScheme,!0),w.setUint32(36,_,!0),w.setUint32(40,f.byteLength,!0),w.setUint32(44,p,!0),w.setUint32(48,l.byteLength,!0),w.setBigUint64(52,BigInt(y),!0),w.setBigUint64(60,BigInt(a.byteLength),!0),new Uint8Array(g([new Uint8Array(e).buffer,B,b.buffer,f,l,new ArrayBuffer(y-(p+l.byteLength)),a,...D]))}export{U as KTX2Container,p as read,y as write}; | ||
//# sourceMappingURL=ktx-parse.modern.js.map |
{ | ||
"name": "ktx-parse", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "KTX 2.0 (.ktx2) parser and serializer.", | ||
@@ -5,0 +5,0 @@ "source": "src/index.ts", |
@@ -72,3 +72,3 @@ # ktx-parse | ||
*Defined in [src/read.ts:13](https://github.com/donmccurdy/KTX-Parse/blob/bfff943/src/read.ts#L13)* | ||
*Defined in [src/read.ts:13](https://github.com/donmccurdy/KTX-Parse/blob/b599bf4/src/read.ts#L13)* | ||
@@ -96,3 +96,3 @@ Parses a KTX 2.0 file, returning an unpacked `KTX2Container` instance with all associated | ||
*Defined in [src/write.ts:20](https://github.com/donmccurdy/KTX-Parse/blob/bfff943/src/write.ts#L20)* | ||
*Defined in [src/write.ts:20](https://github.com/donmccurdy/KTX-Parse/blob/b599bf4/src/write.ts#L20)* | ||
@@ -132,3 +132,3 @@ Serializes a `KTX2Container` instance to a KTX 2.0 file. Mip levels and other binary data | ||
*Defined in [src/container.ts:47](https://github.com/donmccurdy/KTX-Parse/blob/bfff943/src/container.ts#L47)* | ||
*Defined in [src/container.ts:47](https://github.com/donmccurdy/KTX-Parse/blob/b599bf4/src/container.ts#L47)* | ||
@@ -143,3 +143,3 @@ Data Format Descriptor. | ||
*Defined in [src/container.ts:38](https://github.com/donmccurdy/KTX-Parse/blob/bfff943/src/container.ts#L38)* | ||
*Defined in [src/container.ts:38](https://github.com/donmccurdy/KTX-Parse/blob/b599bf4/src/container.ts#L38)* | ||
@@ -156,3 +156,3 @@ Number of cubemap faces. For cubemaps and cubemap arrays, `faceCount` must be 6. For all | ||
*Defined in [src/container.ts:65](https://github.com/donmccurdy/KTX-Parse/blob/bfff943/src/container.ts#L65)* | ||
*Defined in [src/container.ts:65](https://github.com/donmccurdy/KTX-Parse/blob/b599bf4/src/container.ts#L65)* | ||
@@ -167,3 +167,3 @@ Supercompression Global Data. | ||
*Defined in [src/container.ts:62](https://github.com/donmccurdy/KTX-Parse/blob/bfff943/src/container.ts#L62)* | ||
*Defined in [src/container.ts:62](https://github.com/donmccurdy/KTX-Parse/blob/b599bf4/src/container.ts#L62)* | ||
@@ -178,3 +178,3 @@ Key/Value Data. | ||
*Defined in [src/container.ts:31](https://github.com/donmccurdy/KTX-Parse/blob/bfff943/src/container.ts#L31)* | ||
*Defined in [src/container.ts:31](https://github.com/donmccurdy/KTX-Parse/blob/b599bf4/src/container.ts#L31)* | ||
@@ -189,3 +189,3 @@ Number of array elements (array textures only). | ||
*Defined in [src/container.ts:44](https://github.com/donmccurdy/KTX-Parse/blob/bfff943/src/container.ts#L44)* | ||
*Defined in [src/container.ts:44](https://github.com/donmccurdy/KTX-Parse/blob/b599bf4/src/container.ts#L44)* | ||
@@ -200,3 +200,3 @@ Mip levels, ordered largest (original) to smallest (~1px). | ||
*Defined in [src/container.ts:28](https://github.com/donmccurdy/KTX-Parse/blob/bfff943/src/container.ts#L28)* | ||
*Defined in [src/container.ts:28](https://github.com/donmccurdy/KTX-Parse/blob/b599bf4/src/container.ts#L28)* | ||
@@ -211,3 +211,3 @@ Depth of the texture image for level 0, in pixels (3D textures only). | ||
*Defined in [src/container.ts:25](https://github.com/donmccurdy/KTX-Parse/blob/bfff943/src/container.ts#L25)* | ||
*Defined in [src/container.ts:25](https://github.com/donmccurdy/KTX-Parse/blob/b599bf4/src/container.ts#L25)* | ||
@@ -222,3 +222,3 @@ Height of the texture image for level 0, in pixels. | ||
*Defined in [src/container.ts:22](https://github.com/donmccurdy/KTX-Parse/blob/bfff943/src/container.ts#L22)* | ||
*Defined in [src/container.ts:22](https://github.com/donmccurdy/KTX-Parse/blob/b599bf4/src/container.ts#L22)* | ||
@@ -233,3 +233,3 @@ Width of the texture image for level 0, in pixels. | ||
*Defined in [src/container.ts:41](https://github.com/donmccurdy/KTX-Parse/blob/bfff943/src/container.ts#L41)* | ||
*Defined in [src/container.ts:41](https://github.com/donmccurdy/KTX-Parse/blob/b599bf4/src/container.ts#L41)* | ||
@@ -244,3 +244,3 @@ Indicates which supercompression scheme has been applied to mip level images, if any. | ||
*Defined in [src/container.ts:19](https://github.com/donmccurdy/KTX-Parse/blob/bfff943/src/container.ts#L19)* | ||
*Defined in [src/container.ts:19](https://github.com/donmccurdy/KTX-Parse/blob/b599bf4/src/container.ts#L19)* | ||
@@ -256,3 +256,3 @@ Size of the data type in bytes used to upload the data to a graphics API. When `vkFormat` is | ||
*Defined in [src/container.ts:13](https://github.com/donmccurdy/KTX-Parse/blob/bfff943/src/container.ts#L13)* | ||
*Defined in [src/container.ts:13](https://github.com/donmccurdy/KTX-Parse/blob/b599bf4/src/container.ts#L13)* | ||
@@ -259,0 +259,0 @@ Specifies the image format using Vulkan VkFormat enum values. When using Basis Universal |
@@ -147,2 +147,3 @@ import { BufferReader } from './buffer-reader'; | ||
const key = decodeText(keyData); | ||
const valueData = kvdReader._scan(keyValueByteLength - keyData.byteLength); | ||
@@ -152,3 +153,3 @@ container.keyValue[key] = key.match(/^ktx/i) ? decodeText(valueData) : valueData; | ||
// 4-byte alignment. | ||
if (keyValueByteLength % 4) kvdReader._skip(4 - (keyValueByteLength % 4)); | ||
if (kvdReader._offset % 4) kvdReader._skip(4 - (kvdReader._offset % 4)); | ||
} | ||
@@ -155,0 +156,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
176624