Socket
Socket
Sign inDemoInstall

ktx-parse

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ktx-parse - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

2

dist/ktx-parse.js

@@ -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];(t=exports.KTX2SupercompressionScheme||(exports.KTX2SupercompressionScheme={}))[t.NONE=0]="NONE",t[t.BASISLZ=1]="BASISLZ",t[t.ZSTD=2]="ZSTD",t[t.ZLIB=3]="ZLIB",(e=exports.KTX2DescriptorType||(exports.KTX2DescriptorType={}))[e.BASICFORMAT=0]="BASICFORMAT",(n=exports.KTX2Model||(exports.KTX2Model={}))[n.UNSPECIFIED=0]="UNSPECIFIED",n[n.ETC1S=163]="ETC1S",n[n.UASTC=166]="UASTC",(i=exports.KTX2Primaries||(exports.KTX2Primaries={}))[i.UNSPECIFIED=0]="UNSPECIFIED",i[i.SRGB=1]="SRGB",(r=exports.KTX2Transfer||(exports.KTX2Transfer={}))[r.UNSPECIFIED=0]="UNSPECIFIED",r[r.LINEAR=1]="LINEAR",r[r.SRGB=2]="SRGB",r[r.ITU=3]="ITU",r[r.NTSC=4]="NTSC",r[r.SLOG=5]="SLOG",r[r.SLOG2=6]="SLOG2",(a=exports.KTX2Flags||(exports.KTX2Flags={}))[a.ALPHA_STRAIGHT=0]="ALPHA_STRAIGHT",a[a.ALPHA_PREMULTIPLIED=1]="ALPHA_PREMULTIPLIED",(s=exports.KTX2ChannelETC1S||(exports.KTX2ChannelETC1S={}))[s.RGB=0]="RGB",s[s.RRR=3]="RRR",s[s.GGG=4]="GGG",s[s.AAA=15]="AAA",(o=exports.KTX2ChannelUASTC||(exports.KTX2ChannelUASTC={}))[o.RGB=0]="RGB",o[o.RGBA=3]="RGBA",o[o.RRR=4]="RRR",o[o.RRRG=5]="RRRG";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=exports.KTX2SupercompressionScheme.NONE,this.levels=[],this.dataFormatDescriptor=[{vendorId:0,descriptorType:exports.KTX2DescriptorType.BASICFORMAT,versionNumber:2,descriptorBlockSize:40,colorModel:exports.KTX2Model.UNSPECIFIED,colorPrimaries:exports.KTX2Primaries.SRGB,transferFunction:exports.KTX2Primaries.SRGB,flags:exports.KTX2Flags.ALPHA_STRAIGHT,texelBlockDimension:{x:4,y:4,z:1,w:1},bytesPlane:[],samples:[]}],this.keyValue={},this.globalData=null},p=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 h(){return(h=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 c(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 x(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 c(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)?c(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 u(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){for(var e,n=0,i=x(t);!(e=i()).done;)n+=e.value.byteLength;for(var r,a=new Uint8Array(n),s=0,o=x(t);!(r=o()).done;){var l=r.value;a.set(new Uint8Array(l),s),s+=l.byteLength}return a}var y={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 p(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(),h=r._nextUint32(),c=r._nextUint64(),x=r._nextUint64(),u=new p(t,f.length+i,3*a*8,!0),g=0;g<a;g++)n.levels.push({levelData:new Uint8Array(t.buffer,t.byteOffset+u._nextUint64(),u._nextUint64()),uncompressedByteLength:u._nextUint64()});for(var y=new p(t,s,o,!0),d={vendorId:y._skip(4)._nextUint16(),descriptorType:y._nextUint16(),versionNumber:y._nextUint16(),descriptorBlockSize:y._nextUint16(),colorModel:y._nextUint8(),colorPrimaries:y._nextUint8(),transferFunction:y._nextUint8(),flags:y._nextUint8(),texelBlockDimension:{x:y._nextUint8()+1,y:y._nextUint8()+1,z:y._nextUint8()+1,w:y._nextUint8()+1},bytesPlane:[y._nextUint8(),y._nextUint8(),y._nextUint8(),y._nextUint8(),y._nextUint8(),y._nextUint8(),y._nextUint8(),y._nextUint8()],samples:[]},b=(d.descriptorBlockSize/4-6)/4,D=0;D<b;D++)d.samples[D]={bitOffset:y._nextUint16(),bitLength:y._nextUint8(),channelID:y._nextUint8(),samplePosition:[y._nextUint8(),y._nextUint8(),y._nextUint8(),y._nextUint8()],sampleLower:y._nextUint32(),sampleUpper:y._nextUint32()};n.dataFormatDescriptor.length=0,n.dataFormatDescriptor.push(d);for(var m=new p(t,l,h,!0);m._offset<h;){var v=m._nextUint32(),S=m._scan(v),T=_(S),A=m._scan(v-S.byteLength);n.keyValue[T]=T.match(/^ktx/i)?_(A):A,m._offset%4&&m._skip(4-m._offset%4)}if(x<=0)return n;for(var w=new p(t,c,x,!0),B=w._nextUint16(),L=w._nextUint16(),I=w._nextUint32(),R=w._nextUint32(),E=w._nextUint32(),C=w._nextUint32(),P=[],O=0;O<a;O++)P.push({imageFlags:w._nextUint32(),rgbSliceByteOffset:w._nextUint32(),rgbSliceByteLength:w._nextUint32(),alphaSliceByteOffset:w._nextUint32(),alphaSliceByteLength:w._nextUint32()});var F=c+w._offset,G=F+I,K=G+R,X=K+E,k=new Uint8Array(t.buffer,t.byteOffset+F,I),N=new Uint8Array(t.buffer,t.byteOffset+G,R),V=new Uint8Array(t.buffer,t.byteOffset+K,E),M=new Uint8Array(t.buffer,t.byteOffset+X,C);return n.globalData={endpointCount:B,selectorCount:L,imageDescs:P,endpointsData:k,selectorsData:N,tablesData:V,extendedData:M},n},exports.write=function(t,e){void 0===e&&(e={}),e=h({},y,e);var n=new ArrayBuffer(0);if(t.globalData){var i=new ArrayBuffer(20+5*t.globalData.imageDescs.length*4),r=new DataView(i);r.setUint16(0,t.globalData.endpointCount,!0),r.setUint16(2,t.globalData.selectorCount,!0),r.setUint32(4,t.globalData.endpointsData.byteLength,!0),r.setUint32(8,t.globalData.selectorsData.byteLength,!0),r.setUint32(12,t.globalData.tablesData.byteLength,!0),r.setUint32(16,t.globalData.extendedData.byteLength,!0);for(var a=0;a<t.globalData.imageDescs.length;a++){var s=t.globalData.imageDescs[a];r.setUint32(20+5*a*4+0,s.imageFlags,!0),r.setUint32(20+5*a*4+4,s.rgbSliceByteOffset,!0),r.setUint32(20+5*a*4+8,s.rgbSliceByteLength,!0),r.setUint32(20+5*a*4+12,s.alphaSliceByteOffset,!0),r.setUint32(20+5*a*4+16,s.alphaSliceByteLength,!0)}n=g([i,t.globalData.endpointsData,t.globalData.selectorsData,t.globalData.tablesData,t.globalData.extendedData])}var o=[],U=t.keyValue;for(var p in e.keepWriter||(U=h({},t.keyValue,{KTXwriter:"KTX-Parse v0.2.1"})),U){var c=U[p],x=u(p),_="string"==typeof c?u(c):c,d=x.byteLength+1+_.byteLength+1,b=d%4?4-d%4:0;o.push(g([new Uint32Array([d]),x,l,_,l,new Uint8Array(b).fill(0)]))}var D=g(o),m=new ArrayBuffer(44),v=new DataView(m);if(1!==t.dataFormatDescriptor.length||t.dataFormatDescriptor[0].descriptorType!==exports.KTX2DescriptorType.BASICFORMAT)throw new Error("Only BASICFORMAT Data Format Descriptor output supported.");var S=t.dataFormatDescriptor[0];v.setUint32(0,44,!0),v.setUint16(4,S.vendorId,!0),v.setUint16(6,S.descriptorType,!0),v.setUint16(8,S.versionNumber,!0),v.setUint16(10,S.descriptorBlockSize,!0),v.setUint8(12,S.colorModel),v.setUint8(13,S.colorPrimaries),v.setUint8(14,S.transferFunction),v.setUint8(15,S.flags),v.setUint8(16,S.texelBlockDimension.x-1),v.setUint8(17,S.texelBlockDimension.y-1),v.setUint8(18,S.texelBlockDimension.z-1),v.setUint8(19,S.texelBlockDimension.w-1);for(var T=0;T<8;T++)v.setUint8(20+T,S.bytesPlane[T]);for(var A=0;A<S.samples.length;A++){var w=S.samples[A],B=28+16*A;v.setUint16(B+0,w.bitOffset,!0),v.setUint8(B+2,w.bitLength),v.setUint8(B+3,w.channelID),v.setUint8(B+4,w.samplePosition[0]),v.setUint8(B+5,w.samplePosition[1]),v.setUint8(B+6,w.samplePosition[2]),v.setUint8(B+7,w.samplePosition[3]),v.setUint32(B+8,w.sampleLower,!0),v.setUint32(B+12,w.sampleUpper,!0)}var L=f.length+68+3*t.levels.length*8,I=L+m.byteLength,R=I+D.byteLength;R%8&&(R+=8-R%8);for(var E=[],C=new DataView(new ArrayBuffer(3*t.levels.length*8)),P=R+n.byteLength,O=0;O<t.levels.length;O++){var F=t.levels[O];E.push(F.levelData),C.setBigUint64(24*O+0,BigInt(P),!0),C.setBigUint64(24*O+8,BigInt(F.levelData.byteLength),!0),C.setBigUint64(24*O+16,BigInt(F.uncompressedByteLength),!0),P+=F.levelData.byteLength}var G=new ArrayBuffer(68),K=new DataView(G);return K.setUint32(0,t.vkFormat,!0),K.setUint32(4,t.typeSize,!0),K.setUint32(8,t.pixelWidth,!0),K.setUint32(12,t.pixelHeight,!0),K.setUint32(16,t.pixelDepth,!0),K.setUint32(20,t.layerCount,!0),K.setUint32(24,t.faceCount,!0),K.setUint32(28,t.levels.length,!0),K.setUint32(32,t.supercompressionScheme,!0),K.setUint32(36,L,!0),K.setUint32(40,m.byteLength,!0),K.setUint32(44,I,!0),K.setUint32(48,D.byteLength,!0),K.setBigUint64(52,BigInt(R),!0),K.setBigUint64(60,BigInt(n.byteLength),!0),new Uint8Array(g([new Uint8Array(f).buffer,G,C.buffer,m,D,new ArrayBuffer(R-(I+D.byteLength)),n].concat(E)))};
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];(t=exports.KTX2SupercompressionScheme||(exports.KTX2SupercompressionScheme={}))[t.NONE=0]="NONE",t[t.BASISLZ=1]="BASISLZ",t[t.ZSTD=2]="ZSTD",t[t.ZLIB=3]="ZLIB",(e=exports.KTX2DescriptorType||(exports.KTX2DescriptorType={}))[e.BASICFORMAT=0]="BASICFORMAT",(n=exports.KTX2Model||(exports.KTX2Model={}))[n.UNSPECIFIED=0]="UNSPECIFIED",n[n.ETC1S=163]="ETC1S",n[n.UASTC=166]="UASTC",(i=exports.KTX2Primaries||(exports.KTX2Primaries={}))[i.UNSPECIFIED=0]="UNSPECIFIED",i[i.SRGB=1]="SRGB",(r=exports.KTX2Transfer||(exports.KTX2Transfer={}))[r.UNSPECIFIED=0]="UNSPECIFIED",r[r.LINEAR=1]="LINEAR",r[r.SRGB=2]="SRGB",r[r.ITU=3]="ITU",r[r.NTSC=4]="NTSC",r[r.SLOG=5]="SLOG",r[r.SLOG2=6]="SLOG2",(a=exports.KTX2Flags||(exports.KTX2Flags={}))[a.ALPHA_STRAIGHT=0]="ALPHA_STRAIGHT",a[a.ALPHA_PREMULTIPLIED=1]="ALPHA_PREMULTIPLIED",(s=exports.KTX2ChannelETC1S||(exports.KTX2ChannelETC1S={}))[s.RGB=0]="RGB",s[s.RRR=3]="RRR",s[s.GGG=4]="GGG",s[s.AAA=15]="AAA",(o=exports.KTX2ChannelUASTC||(exports.KTX2ChannelUASTC={}))[o.RGB=0]="RGB",o[o.RGBA=3]="RGBA",o[o.RRR=4]="RRR",o[o.RRRG=5]="RRRG";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=exports.KTX2SupercompressionScheme.NONE,this.levels=[],this.dataFormatDescriptor=[{vendorId:0,descriptorType:exports.KTX2DescriptorType.BASICFORMAT,versionNumber:2,descriptorBlockSize:40,colorModel:exports.KTX2Model.UNSPECIFIED,colorPrimaries:exports.KTX2Primaries.SRGB,transferFunction:exports.KTX2Primaries.SRGB,flags:exports.KTX2Flags.ALPHA_STRAIGHT,texelBlockDimension:{x:4,y:4,z:1,w:1},bytesPlane:[],samples:[]}],this.keyValue={},this.globalData=null},p=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 h(){return(h=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 c(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 x(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 c(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)?c(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 u(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){for(var e,n=0,i=x(t);!(e=i()).done;)n+=e.value.byteLength;for(var r,a=new Uint8Array(n),s=0,o=x(t);!(r=o()).done;){var l=r.value;a.set(new Uint8Array(l),s),s+=l.byteLength}return a}var y={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 p(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(),h=r._nextUint32(),c=r._nextUint64(),x=r._nextUint64(),u=new p(t,f.length+i,3*a*8,!0),g=0;g<a;g++)n.levels.push({levelData:new Uint8Array(t.buffer,t.byteOffset+u._nextUint64(),u._nextUint64()),uncompressedByteLength:u._nextUint64()});for(var y=new p(t,s,o,!0),d={vendorId:y._skip(4)._nextUint16(),descriptorType:y._nextUint16(),versionNumber:y._nextUint16(),descriptorBlockSize:y._nextUint16(),colorModel:y._nextUint8(),colorPrimaries:y._nextUint8(),transferFunction:y._nextUint8(),flags:y._nextUint8(),texelBlockDimension:{x:y._nextUint8()+1,y:y._nextUint8()+1,z:y._nextUint8()+1,w:y._nextUint8()+1},bytesPlane:[y._nextUint8(),y._nextUint8(),y._nextUint8(),y._nextUint8(),y._nextUint8(),y._nextUint8(),y._nextUint8(),y._nextUint8()],samples:[]},b=(d.descriptorBlockSize/4-6)/4,D=0;D<b;D++)d.samples[D]={bitOffset:y._nextUint16(),bitLength:y._nextUint8(),channelID:y._nextUint8(),samplePosition:[y._nextUint8(),y._nextUint8(),y._nextUint8(),y._nextUint8()],sampleLower:y._nextUint32(),sampleUpper:y._nextUint32()};n.dataFormatDescriptor.length=0,n.dataFormatDescriptor.push(d);for(var m=new p(t,l,h,!0);m._offset<h;){var v=m._nextUint32(),S=m._scan(v),T=_(S),A=m._scan(v-S.byteLength);n.keyValue[T]=T.match(/^ktx/i)?_(A):A,m._offset%4&&m._skip(4-m._offset%4)}if(x<=0)return n;for(var w=new p(t,c,x,!0),B=w._nextUint16(),L=w._nextUint16(),I=w._nextUint32(),R=w._nextUint32(),E=w._nextUint32(),C=w._nextUint32(),P=[],O=0;O<a;O++)P.push({imageFlags:w._nextUint32(),rgbSliceByteOffset:w._nextUint32(),rgbSliceByteLength:w._nextUint32(),alphaSliceByteOffset:w._nextUint32(),alphaSliceByteLength:w._nextUint32()});var F=c+w._offset,G=F+I,K=G+R,X=K+E,k=new Uint8Array(t.buffer,t.byteOffset+F,I),N=new Uint8Array(t.buffer,t.byteOffset+G,R),V=new Uint8Array(t.buffer,t.byteOffset+K,E),M=new Uint8Array(t.buffer,t.byteOffset+X,C);return n.globalData={endpointCount:B,selectorCount:L,imageDescs:P,endpointsData:k,selectorsData:N,tablesData:V,extendedData:M},n},exports.write=function(t,e){void 0===e&&(e={}),e=h({},y,e);var n=new ArrayBuffer(0);if(t.globalData){var i=new ArrayBuffer(20+5*t.globalData.imageDescs.length*4),r=new DataView(i);r.setUint16(0,t.globalData.endpointCount,!0),r.setUint16(2,t.globalData.selectorCount,!0),r.setUint32(4,t.globalData.endpointsData.byteLength,!0),r.setUint32(8,t.globalData.selectorsData.byteLength,!0),r.setUint32(12,t.globalData.tablesData.byteLength,!0),r.setUint32(16,t.globalData.extendedData.byteLength,!0);for(var a=0;a<t.globalData.imageDescs.length;a++){var s=t.globalData.imageDescs[a];r.setUint32(20+5*a*4+0,s.imageFlags,!0),r.setUint32(20+5*a*4+4,s.rgbSliceByteOffset,!0),r.setUint32(20+5*a*4+8,s.rgbSliceByteLength,!0),r.setUint32(20+5*a*4+12,s.alphaSliceByteOffset,!0),r.setUint32(20+5*a*4+16,s.alphaSliceByteLength,!0)}n=g([i,t.globalData.endpointsData,t.globalData.selectorsData,t.globalData.tablesData,t.globalData.extendedData])}var o=[],U=t.keyValue;for(var p in e.keepWriter||(U=h({},t.keyValue,{KTXwriter:"KTX-Parse v0.2.2"})),U){var c=U[p],x=u(p),_="string"==typeof c?u(c):c,d=x.byteLength+1+_.byteLength+1,b=d%4?4-d%4:0;o.push(g([new Uint32Array([d]),x,l,_,l,new Uint8Array(b).fill(0)]))}var D=g(o);if(1!==t.dataFormatDescriptor.length||t.dataFormatDescriptor[0].descriptorType!==exports.KTX2DescriptorType.BASICFORMAT)throw new Error("Only BASICFORMAT Data Format Descriptor output supported.");var m=t.dataFormatDescriptor[0],v=new ArrayBuffer(28+16*m.samples.length),S=new DataView(v);S.setUint32(0,v.byteLength,!0),S.setUint16(4,m.vendorId,!0),S.setUint16(6,m.descriptorType,!0),S.setUint16(8,m.versionNumber,!0),S.setUint16(10,m.descriptorBlockSize,!0),S.setUint8(12,m.colorModel),S.setUint8(13,m.colorPrimaries),S.setUint8(14,m.transferFunction),S.setUint8(15,m.flags),S.setUint8(16,m.texelBlockDimension.x-1),S.setUint8(17,m.texelBlockDimension.y-1),S.setUint8(18,m.texelBlockDimension.z-1),S.setUint8(19,m.texelBlockDimension.w-1);for(var T=0;T<8;T++)S.setUint8(20+T,m.bytesPlane[T]);for(var A=0;A<m.samples.length;A++){var w=m.samples[A],B=28+16*A;S.setUint16(B+0,w.bitOffset,!0),S.setUint8(B+2,w.bitLength),S.setUint8(B+3,w.channelID),S.setUint8(B+4,w.samplePosition[0]),S.setUint8(B+5,w.samplePosition[1]),S.setUint8(B+6,w.samplePosition[2]),S.setUint8(B+7,w.samplePosition[3]),S.setUint32(B+8,w.sampleLower,!0),S.setUint32(B+12,w.sampleUpper,!0)}var L=f.length+68+3*t.levels.length*8,I=L+v.byteLength,R=I+D.byteLength;R%8&&(R+=8-R%8);for(var E=[],C=new DataView(new ArrayBuffer(3*t.levels.length*8)),P=R+n.byteLength,O=0;O<t.levels.length;O++){var F=t.levels[O];E.push(F.levelData),C.setBigUint64(24*O+0,BigInt(P),!0),C.setBigUint64(24*O+8,BigInt(F.levelData.byteLength),!0),C.setBigUint64(24*O+16,BigInt(F.uncompressedByteLength),!0),P+=F.levelData.byteLength}var G=new ArrayBuffer(68),K=new DataView(G);return K.setUint32(0,t.vkFormat,!0),K.setUint32(4,t.typeSize,!0),K.setUint32(8,t.pixelWidth,!0),K.setUint32(12,t.pixelHeight,!0),K.setUint32(16,t.pixelDepth,!0),K.setUint32(20,t.layerCount,!0),K.setUint32(24,t.faceCount,!0),K.setUint32(28,t.levels.length,!0),K.setUint32(32,t.supercompressionScheme,!0),K.setUint32(36,L,!0),K.setUint32(40,v.byteLength,!0),K.setUint32(44,I,!0),K.setUint32(48,D.byteLength,!0),K.setBigUint64(52,BigInt(R),!0),K.setBigUint64(60,BigInt(n.byteLength),!0),new Uint8Array(g([new Uint8Array(f).buffer,G,C.buffer,v,D,new ArrayBuffer(R-(I+D.byteLength)),n].concat(E)))};
//# 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,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.2.1"}));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{l as KTX2ChannelETC1S,f as KTX2ChannelUASTC,U as KTX2Container,i as KTX2DescriptorType,o as KTX2Flags,s as KTX2Model,a as KTX2Primaries,n as KTX2SupercompressionScheme,r as KTX2Transfer,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.2.2"}));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);if(1!==n.dataFormatDescriptor.length||n.dataFormatDescriptor[0].descriptorType!==i.BASICFORMAT)throw new Error("Only BASICFORMAT Data Format Descriptor output supported.");const f=n.dataFormatDescriptor[0],U=new ArrayBuffer(28+16*f.samples.length),c=new DataView(U);c.setUint32(0,U.byteLength,!0),c.setUint16(4,f.vendorId,!0),c.setUint16(6,f.descriptorType,!0),c.setUint16(8,f.versionNumber,!0),c.setUint16(10,f.descriptorBlockSize,!0),c.setUint8(12,f.colorModel),c.setUint8(13,f.colorPrimaries),c.setUint8(14,f.transferFunction),c.setUint8(15,f.flags),c.setUint8(16,f.texelBlockDimension.x-1),c.setUint8(17,f.texelBlockDimension.y-1),c.setUint8(18,f.texelBlockDimension.z-1),c.setUint8(19,f.texelBlockDimension.w-1);for(let t=0;t<8;t++)c.setUint8(20+t,f.bytesPlane[t]);for(let t=0;t<f.samples.length;t++){const e=f.samples[t],n=28+16*t;c.setUint16(n+0,e.bitOffset,!0),c.setUint8(n+2,e.bitLength),c.setUint8(n+3,e.channelID),c.setUint8(n+4,e.samplePosition[0]),c.setUint8(n+5,e.samplePosition[1]),c.setUint8(n+6,e.samplePosition[2]),c.setUint8(n+7,e.samplePosition[3]),c.setUint32(n+8,e.sampleLower,!0),c.setUint32(n+12,e.sampleUpper,!0)}const _=e.length+68+3*n.levels.length*8,p=_+U.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,U.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,U,l,new ArrayBuffer(y-(p+l.byteLength)),a,...D]))}export{l as KTX2ChannelETC1S,f as KTX2ChannelUASTC,U as KTX2Container,i as KTX2DescriptorType,o as KTX2Flags,s as KTX2Model,a as KTX2Primaries,n as KTX2SupercompressionScheme,r as KTX2Transfer,p as read,y as write};
//# sourceMappingURL=ktx-parse.modern.js.map
{
"name": "ktx-parse",
"version": "0.2.1",
"version": "0.2.2",
"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/3c95c2e/src/read.ts#L13)*
*Defined in [src/read.ts:13](https://github.com/donmccurdy/KTX-Parse/blob/fe08af2/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:21](https://github.com/donmccurdy/KTX-Parse/blob/3c95c2e/src/write.ts#L21)*
*Defined in [src/write.ts:21](https://github.com/donmccurdy/KTX-Parse/blob/fe08af2/src/write.ts#L21)*

@@ -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:48](https://github.com/donmccurdy/KTX-Parse/blob/3c95c2e/src/container.ts#L48)*
*Defined in [src/container.ts:48](https://github.com/donmccurdy/KTX-Parse/blob/fe08af2/src/container.ts#L48)*

@@ -143,3 +143,3 @@ Data Format Descriptor.

*Defined in [src/container.ts:39](https://github.com/donmccurdy/KTX-Parse/blob/3c95c2e/src/container.ts#L39)*
*Defined in [src/container.ts:39](https://github.com/donmccurdy/KTX-Parse/blob/fe08af2/src/container.ts#L39)*

@@ -156,3 +156,3 @@ Number of cubemap faces. For cubemaps and cubemap arrays, `faceCount` must be 6. For all

*Defined in [src/container.ts:66](https://github.com/donmccurdy/KTX-Parse/blob/3c95c2e/src/container.ts#L66)*
*Defined in [src/container.ts:66](https://github.com/donmccurdy/KTX-Parse/blob/fe08af2/src/container.ts#L66)*

@@ -167,3 +167,3 @@ Supercompression Global Data.

*Defined in [src/container.ts:63](https://github.com/donmccurdy/KTX-Parse/blob/3c95c2e/src/container.ts#L63)*
*Defined in [src/container.ts:63](https://github.com/donmccurdy/KTX-Parse/blob/fe08af2/src/container.ts#L63)*

@@ -178,3 +178,3 @@ Key/Value Data.

*Defined in [src/container.ts:32](https://github.com/donmccurdy/KTX-Parse/blob/3c95c2e/src/container.ts#L32)*
*Defined in [src/container.ts:32](https://github.com/donmccurdy/KTX-Parse/blob/fe08af2/src/container.ts#L32)*

@@ -189,3 +189,3 @@ Number of array elements (array textures only).

*Defined in [src/container.ts:45](https://github.com/donmccurdy/KTX-Parse/blob/3c95c2e/src/container.ts#L45)*
*Defined in [src/container.ts:45](https://github.com/donmccurdy/KTX-Parse/blob/fe08af2/src/container.ts#L45)*

@@ -200,3 +200,3 @@ Mip levels, ordered largest (original) to smallest (~1px).

*Defined in [src/container.ts:29](https://github.com/donmccurdy/KTX-Parse/blob/3c95c2e/src/container.ts#L29)*
*Defined in [src/container.ts:29](https://github.com/donmccurdy/KTX-Parse/blob/fe08af2/src/container.ts#L29)*

@@ -211,3 +211,3 @@ Depth of the texture image for level 0, in pixels (3D textures only).

*Defined in [src/container.ts:26](https://github.com/donmccurdy/KTX-Parse/blob/3c95c2e/src/container.ts#L26)*
*Defined in [src/container.ts:26](https://github.com/donmccurdy/KTX-Parse/blob/fe08af2/src/container.ts#L26)*

@@ -222,3 +222,3 @@ Height of the texture image for level 0, in pixels.

*Defined in [src/container.ts:23](https://github.com/donmccurdy/KTX-Parse/blob/3c95c2e/src/container.ts#L23)*
*Defined in [src/container.ts:23](https://github.com/donmccurdy/KTX-Parse/blob/fe08af2/src/container.ts#L23)*

@@ -233,3 +233,3 @@ Width of the texture image for level 0, in pixels.

*Defined in [src/container.ts:42](https://github.com/donmccurdy/KTX-Parse/blob/3c95c2e/src/container.ts#L42)*
*Defined in [src/container.ts:42](https://github.com/donmccurdy/KTX-Parse/blob/fe08af2/src/container.ts#L42)*

@@ -244,3 +244,3 @@ Indicates which supercompression scheme has been applied to mip level images, if any.

*Defined in [src/container.ts:20](https://github.com/donmccurdy/KTX-Parse/blob/3c95c2e/src/container.ts#L20)*
*Defined in [src/container.ts:20](https://github.com/donmccurdy/KTX-Parse/blob/fe08af2/src/container.ts#L20)*

@@ -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:14](https://github.com/donmccurdy/KTX-Parse/blob/3c95c2e/src/container.ts#L14)*
*Defined in [src/container.ts:14](https://github.com/donmccurdy/KTX-Parse/blob/fe08af2/src/container.ts#L14)*

@@ -259,0 +259,0 @@ Specifies the image format using Vulkan VkFormat enum values. When using Basis Universal

@@ -92,5 +92,2 @@ import { HEADER_BYTE_LENGTH, KTX2_ID, KTX_WRITER, NUL } from './constants';

const dfdBuffer = new ArrayBuffer(44);
const dfdView = new DataView(dfdBuffer);
if (container.dataFormatDescriptor.length !== 1

@@ -103,3 +100,6 @@ || container.dataFormatDescriptor[0].descriptorType !== KTX2DescriptorType.BASICFORMAT) {

dfdView.setUint32(0, 44, true);
const dfdBuffer = new ArrayBuffer(28 + dfd.samples.length * 16);
const dfdView = new DataView(dfdBuffer);
dfdView.setUint32(0, dfdBuffer.byteLength, true);
dfdView.setUint16(4, dfd.vendorId, true);

@@ -106,0 +106,0 @@ dfdView.setUint16(6, dfd.descriptorType, true);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc