@babylonjs/ktx2decoder 7.34.3 → 7.35.0
Sign up to get free protection for your applications and to get access to all the features.
- package/Misc/dataReader.js.map +1 -1
- package/Transcoders/liteTranscoder.js.map +1 -1
- package/Transcoders/mscTranscoder.js.map +1 -1
- package/ktx2Decoder.js.map +1 -1
- package/ktx2FileReader.js.map +1 -1
- package/legacy/legacy.js.map +1 -1
- package/package.json +2 -2
- package/transcodeDecisionTree.js.map +1 -1
- package/transcoder.js.map +1 -1
- package/transcoderManager.js.map +1 -1
- package/wasmMemoryManager.js.map +1 -1
- package/zstddec.js.map +1 -1
package/Misc/dataReader.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"dataReader.js","sourceRoot":"","sources":["../../../../tools/ktx2Decoder/src/Misc/dataReader.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,UAAU;IACnB;;OAEG;IACH,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;IAKD;;;;;OAKG;IACH,YAAY,MAAqC,EAAE,UAAmB,EAAE,UAAmB;QACvF,IAAK,MAA0B,CAAC,MAAM,EAAE;
|
1
|
+
{"version":3,"file":"dataReader.js","sourceRoot":"","sources":["../../../../tools/ktx2Decoder/src/Misc/dataReader.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,UAAU;IACnB;;OAEG;IACH,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;IAKD;;;;;OAKG;IACH,YAAY,MAAqC,EAAE,UAAmB,EAAE,UAAmB;QACvF,IAAK,MAA0B,CAAC,MAAM,EAAE,CAAC;YACrC,IAAI,CAAC,SAAS,GAAG,IAAI,QAAQ,CACxB,MAA0B,CAAC,MAAM,EACjC,MAA0B,CAAC,UAAU,GAAG,CAAC,UAAU,IAAI,CAAC,CAAC,EAC1D,UAAU,IAAK,MAA0B,CAAC,UAAU,CACvD,CAAC;QACN,CAAC;aAAM,CAAC;YACJ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AAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;QAClE,IAAI,CAAC,eAAe,IAAI,CAAC,CAAC;QAC1B,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;;OAGG;IACI,UAAU;QACb,qDAAqD;QACrD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;QAClE,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,eAAe,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;QAEvE,gCAAgC;QAChC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC,oGAAoG;QAE7I;;WAEG;QAEH,IAAI,CAAC,eAAe,IAAI,CAAC,CAAC;QAC1B,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED;;;;OAIG;IACI,cAAc,CAAC,UAAkB;QACpC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,GAAG,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;QAClH,IAAI,CAAC,eAAe,IAAI,UAAU,CAAC;QACnC,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,UAAkB;QAC/B,IAAI,CAAC,eAAe,IAAI,UAAU,CAAC;QACnC,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ","sourcesContent":["/**\r\n * Utility class for reading from a data buffer\r\n */\r\nexport class DataReader {\r\n /**\r\n * The current byte offset from the beginning of the data buffer.\r\n */\r\n public get byteOffset() {\r\n return this._dataByteOffset;\r\n }\r\n\r\n private _dataView: DataView;\r\n private _dataByteOffset: number;\r\n\r\n /**\r\n * Constructor\r\n * @param buffer The buffer to set\r\n * @param byteOffset The starting offset in the buffer\r\n * @param byteLength The byte length of the buffer\r\n */\r\n constructor(buffer: ArrayBuffer | ArrayBufferView, byteOffset?: number, byteLength?: number) {\r\n if ((buffer as ArrayBufferView).buffer) {\r\n this._dataView = new DataView(\r\n (buffer as ArrayBufferView).buffer,\r\n (buffer as ArrayBufferView).byteOffset + (byteOffset ?? 0),\r\n byteLength ?? (buffer as ArrayBufferView).byteLength\r\n );\r\n } else {\r\n this._dataView = new DataView(buffer as ArrayBuffer, byteOffset ?? 0, byteLength ?? (buffer as ArrayBuffer).byteLength);\r\n }\r\n\r\n this._dataByteOffset = 0;\r\n }\r\n\r\n /**\r\n * Read a unsigned 8-bit integer from the currently loaded data range.\r\n * @returns The 8-bit integer read\r\n */\r\n public readUint8(): number {\r\n const value = this._dataView.getUint8(this._dataByteOffset);\r\n this._dataByteOffset += 1;\r\n return value;\r\n }\r\n\r\n /**\r\n * Read a signed 8-bit integer from the currently loaded data range.\r\n * @returns The 8-bit integer read\r\n */\r\n public readInt8(): number {\r\n const value = this._dataView.getInt8(this._dataByteOffset);\r\n this._dataByteOffset += 1;\r\n return value;\r\n }\r\n\r\n /**\r\n * Read a unsigned 16-bit integer from the currently loaded data range.\r\n * @returns The 16-bit integer read\r\n */\r\n public readUint16(): number {\r\n const value = this._dataView.getUint16(this._dataByteOffset, true);\r\n this._dataByteOffset += 2;\r\n return value;\r\n }\r\n\r\n /**\r\n * Read a signed 16-bit integer from the currently loaded data range.\r\n * @returns The 16-bit integer read\r\n */\r\n public readInt16(): number {\r\n const value = this._dataView.getInt16(this._dataByteOffset, true);\r\n this._dataByteOffset += 2;\r\n return value;\r\n }\r\n\r\n /**\r\n * Read a unsigned 32-bit integer from the currently loaded data range.\r\n * @returns The 32-bit integer read\r\n */\r\n public readUint32(): number {\r\n const value = this._dataView.getUint32(this._dataByteOffset, true);\r\n this._dataByteOffset += 4;\r\n return value;\r\n }\r\n\r\n /**\r\n * Read a signed 32-bit integer from the currently loaded data range.\r\n * @returns The 32-bit integer read\r\n */\r\n public readInt32(): number {\r\n const value = this._dataView.getInt32(this._dataByteOffset, true);\r\n this._dataByteOffset += 4;\r\n return value;\r\n }\r\n\r\n /**\r\n * Read a unsigned 32-bit integer from the currently loaded data range.\r\n * @returns The 32-bit integer read\r\n */\r\n public readUint64(): number {\r\n // split 64-bit number into two 32-bit (4-byte) parts\r\n const left = this._dataView.getUint32(this._dataByteOffset, true);\r\n const right = this._dataView.getUint32(this._dataByteOffset + 4, true);\r\n\r\n // combine the two 32-bit values\r\n const combined = left + 2 ** 32 * right; // That was weird..Keeping it for posterity: true ? left + 2 ** 32 * right : 2 ** 32 * left + right;\r\n\r\n /*if (!Number.isSafeInteger(combined)) {\r\n console.warn('DataReader: ' + combined + ' exceeds MAX_SAFE_INTEGER. Precision may be lost.');\r\n }*/\r\n\r\n this._dataByteOffset += 8;\r\n return combined;\r\n }\r\n\r\n /**\r\n * Read a byte array from the currently loaded data range.\r\n * @param byteLength The byte length to read\r\n * @returns The byte array read\r\n */\r\n public readUint8Array(byteLength: number): Uint8Array {\r\n const value = new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + this._dataByteOffset, byteLength);\r\n this._dataByteOffset += byteLength;\r\n return value;\r\n }\r\n\r\n /**\r\n * Skips the given byte length the currently loaded data range.\r\n * @param byteLength The byte length to skip\r\n * @returns This instance\r\n */\r\n public skipBytes(byteLength: number) {\r\n this._dataByteOffset += byteLength;\r\n return this;\r\n }\r\n}\r\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"liteTranscoder.js","sourceRoot":"","sources":["../../../../tools/ktx2Decoder/src/Transcoders/liteTranscoder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGzD;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,UAAU;IAA9C;;QAEY,gBAAW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AM,WAAW,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,cAAc,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,CAAC,CAAC;QAE1F,MAAM,uBAAuB,GAAG,IAAI,CAAC,iBAAiB;YAClD,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,IAAI,UAAU,CACV,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,MAAM,EACrC,KAAK,GAAG,OAAO,GAAG,EAAE,EACpB,yBAAyB,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,GAAG,MAAM,GAAG,yBAAyB,CAAC,CAAC,CAAC,sBAAsB,CAChH,CAAC;QAER,WAAW,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAE7B,OAAO,CAAC,WAAW,EAAE,uBAAuB,EAAE,OAAO,CAAC,CAAC;IAC3D,CAAC;CACJ","sourcesContent":["import type * as KTX2 from \"core/Materials/Textures/ktx2decoderTypes\";\r\n\r\nimport { Transcoder } from \"../transcoder\";\r\nimport { WASMMemoryManager } from \"../wasmMemoryManager\";\r\nimport type { KTX2FileReader, IKTX2_ImageDesc } from \"../ktx2FileReader\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class LiteTranscoder extends Transcoder {\r\n private _modulePath: string;\r\n private _wasmBinary: ArrayBuffer | null = null;\r\n private _modulePromise: Promise<{ module: any }>;\r\n private _memoryManager: WASMMemoryManager;\r\n protected _transcodeInPlace: boolean;\r\n\r\n private _instantiateWebAssembly(wasmBinary: ArrayBuffer): Promise<{ module: any }> {\r\n return WebAssembly.instantiate(wasmBinary as ArrayBuffer, { env: { memory: this._memoryManager.wasmMemory } }).then((moduleWrapper) => {\r\n return { module: moduleWrapper.instance.exports };\r\n });\r\n }\r\n\r\n protected _loadModule(wasmBinary: ArrayBuffer | null = this._wasmBinary): Promise<{ module: any }> {\r\n this._modulePromise =\r\n this._modulePromise ||\r\n (wasmBinary ? Promise.resolve(wasmBinary) : WASMMemoryManager.LoadWASM(this._modulePath)).then((wasmBinary) => {\r\n return this._instantiateWebAssembly(wasmBinary);\r\n });\r\n return this._modulePromise;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected get memoryManager(): WASMMemoryManager {\r\n return this._memoryManager;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected setModulePath(modulePath: string, wasmBinary: ArrayBuffer | null): void {\r\n this._modulePath = Transcoder.GetWasmUrl(modulePath);\r\n this._wasmBinary = wasmBinary;\r\n }\r\n\r\n public override initialize(): void {\r\n this._transcodeInPlace = true;\r\n }\r\n\r\n public override needMemoryManager(): boolean {\r\n return true;\r\n }\r\n\r\n public override setMemoryManager(memoryMgr: WASMMemoryManager): void {\r\n this._memoryManager = memoryMgr;\r\n }\r\n\r\n public override transcode(\r\n src: KTX2.SourceTextureFormat,\r\n dst: KTX2.TranscodeTarget,\r\n level: number,\r\n width: number,\r\n height: number,\r\n uncompressedByteLength: number,\r\n ktx2Reader: KTX2FileReader,\r\n imageDesc: IKTX2_ImageDesc | null,\r\n encodedData: Uint8Array\r\n ): Promise<Uint8Array | null> {\r\n return this._loadModule().then((moduleWrapper: any) => {\r\n const transcoder: any = moduleWrapper.module;\r\n const [textureView, uncompressedTextureView, nBlocks] = this._prepareTranscoding(width, height, uncompressedByteLength, encodedData);\r\n\r\n return transcoder.transcode(nBlocks) === 0 ? (this._transcodeInPlace ? textureView.slice() : uncompressedTextureView!.slice()) : null;\r\n });\r\n }\r\n\r\n protected _prepareTranscoding(\r\n width: number,\r\n height: number,\r\n uncompressedByteLength: number,\r\n encodedData: Uint8Array,\r\n uncompressedNumComponents?: number\r\n ): [Uint8Array, Uint8Array | null, number] {\r\n const nBlocks = ((width + 3) >> 2) * ((height + 3) >> 2);\r\n\r\n if (uncompressedNumComponents !== undefined) {\r\n uncompressedByteLength = width * ((height + 3) >> 2) * 4 * uncompressedNumComponents;\r\n }\r\n\r\n const texMemoryPages = ((nBlocks * 16 + 65535 + (this._transcodeInPlace ? 0 : uncompressedByteLength)) >> 16) + 1;\r\n\r\n const textureView = this.memoryManager.getMemoryView(texMemoryPages, 65536, nBlocks * 16);\r\n\r\n const uncompressedTextureView = this._transcodeInPlace\r\n ? null\r\n : new Uint8Array(\r\n this._memoryManager.wasmMemory.buffer,\r\n 65536 + nBlocks * 16,\r\n uncompressedNumComponents !== undefined ? width * height * uncompressedNumComponents : uncompressedByteLength\r\n );\r\n\r\n textureView.set(encodedData);\r\n\r\n return [textureView, uncompressedTextureView, nBlocks];\r\n }\r\n}\r\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mscTranscoder.js","sourceRoot":"","sources":["../../../../tools/ktx2Decoder/src/Transcoders/mscTranscoder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,+DAAiD;AAEjE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAMzD;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,UAAU;IAwBzB,OAAO;QACnB,OAAO,aAAa,CAAC,IAAI,CAAC;IAC9B,CAAC;IAKO,sBAAsB;QAC1B,IAAI,IAAI,CAAC,0BAA0B,EAAE;YACjC,OAAO,IAAI,CAAC,0BAA0B,CAAC;SAC1C;QAED,IAAI,CAAC,0BAA0B,GAAG,CAC9B,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CACxJ,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE;YAClB,IAAI,aAAa,CAAC,QAAQ,IAAI,OAAO,cAAc,KAAK,WAAW,EAAE;gBACjE,iJAAiJ;gBAChJ,UAAkB,CAAC,cAAc,GAAG,aAAa,CAAC,QAAQ,CAAC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SAAS,CAAC,aAAa,GAAG,CAAC,CAAC;oBAC5B,SAAS,CAAC,aAAa,GAAG,sBAAsB,CAAC;oBACjD,SAAS,CAAC,eAAe,GAAG,CAAC,CAAC;oBAC9B,SAAS,CAAC,eAAe,GAAG,CAAC,CAAC;oBAE9B,MAAM,GAAG,UAAU,CAAC,cAAc,CAAC,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;iBAC7G;aACJ;oBAAS;gBACN,IAAI,UAAU,EAAE;oBACZ,UAAU,CAAC,MAAM,EAAE,CAAC;iBACvB;gBAED,IAAI,SAAS,EAAE;oBACX,SAAS,CAAC,MAAM,EAAE,CAAC;iBACtB;gBAED,IAAI,MAAM,IAAI,MAAM,CAAC,eAAe,EAAE;oBAClC,WAAW,GAAG,MAAM,CAAC,eAAe,CAAC,qBAAqB,EAAE,CAAC,KAAK,EAAE,CAAC;oBACrE,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC;iBACnC;aACJ;YAED,OAAO,WAAW,CAAC;QACvB,CAAC,CAAC,CAAC;IACP,CAAC;;AAvKD;;GAEG;AACW,yBAAW,GAAG,qEAAqE,CAAC;AAClG;;GAEG;AACW,2BAAa,GAAG,uEAAuE,CAAC;AAEtG;;GAEG;AACW,wBAAU,GAAuB,IAAI,CAAC;AAEpD;;GAEG;AACW,sBAAQ,GAAQ,IAAI,CAAC;AAErB,iCAAmB,GAAG,IAAI,CAAC;AAElB,kBAAI,GAAG,eAAe,CAAC","sourcesContent":["import * as KTX2 from \"core/Materials/Textures/ktx2decoderTypes\";\r\n\r\nimport { Transcoder } from \"../transcoder\";\r\nimport type { KTX2FileReader, IKTX2_ImageDesc } from \"../ktx2FileReader\";\r\nimport { WASMMemoryManager } from \"../wasmMemoryManager\";\r\n\r\ndeclare let MSC_TRANSCODER: any;\r\n\r\ndeclare function importScripts(...urls: string[]): void;\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class MSCTranscoder extends Transcoder {\r\n /**\r\n * URL to use when loading the MSC transcoder\r\n */\r\n public static JSModuleURL = \"https://cdn.babylonjs.com/ktx2Transcoders/1/msc_basis_transcoder.js\";\r\n /**\r\n * URL to use when loading the wasm module for the transcoder\r\n */\r\n public static WasmModuleURL = \"https://cdn.babylonjs.com/ktx2Transcoders/1/msc_basis_transcoder.wasm\";\r\n\r\n /**\r\n * Binary data of the wasm module\r\n */\r\n public static WasmBinary: ArrayBuffer | null = null;\r\n\r\n /**\r\n * MSC transcoder module, if provided externally\r\n */\r\n public static JSModule: any = null;\r\n\r\n public static UseFromWorkerThread = true;\r\n\r\n public static override Name = \"MSCTranscoder\";\r\n\r\n public override getName(): string {\r\n return MSCTranscoder.Name;\r\n }\r\n\r\n private _mscBasisTranscoderPromise: Promise<void>;\r\n private _mscBasisModule: any;\r\n\r\n private _getMSCBasisTranscoder(): Promise<void> {\r\n if (this._mscBasisTranscoderPromise) {\r\n return this._mscBasisTranscoderPromise;\r\n }\r\n\r\n this._mscBasisTranscoderPromise = (\r\n MSCTranscoder.WasmBinary ? Promise.resolve(MSCTranscoder.WasmBinary) : WASMMemoryManager.LoadWASM(Transcoder.GetWasmUrl(MSCTranscoder.WasmModuleURL))\r\n ).then((wasmBinary) => {\r\n if (MSCTranscoder.JSModule && typeof MSC_TRANSCODER === \"undefined\") {\r\n // this must be set on the global scope for the MSC transcoder to work. Mainly due to back-compat with the old way of loading the MSC transcoder.\r\n (globalThis as any).MSC_TRANSCODER = MSCTranscoder.JSModule;\r\n } else {\r\n if (MSCTranscoder.UseFromWorkerThread) {\r\n importScripts(Transcoder.GetWasmUrl(MSCTranscoder.JSModuleURL));\r\n }\r\n // Worker Number = 0 and MSC_TRANSCODER has not been loaded yet.\r\n else if (typeof MSC_TRANSCODER === \"undefined\") {\r\n return new Promise((resolve, reject) => {\r\n const head = document.getElementsByTagName(\"head\")[0];\r\n const script = document.createElement(\"script\");\r\n script.setAttribute(\"type\", \"text/javascript\");\r\n script.setAttribute(\"src\", Transcoder.GetWasmUrl(MSCTranscoder.JSModuleURL));\r\n\r\n script.onload = () => {\r\n // defensive\r\n if (typeof MSC_TRANSCODER === \"undefined\") {\r\n reject(\"MSC_TRANSCODER script loaded but MSC_TRANSCODER is not defined.\");\r\n return;\r\n }\r\n\r\n (MSC_TRANSCODER as any)({ wasmBinary }).then((basisModule: any) => {\r\n basisModule.initTranscoders();\r\n this._mscBasisModule = basisModule;\r\n resolve();\r\n });\r\n };\r\n\r\n script.onerror = () => {\r\n reject(\"Can not load MSC_TRANSCODER script.\");\r\n };\r\n\r\n head.appendChild(script);\r\n });\r\n }\r\n }\r\n\r\n return new Promise((resolve) => {\r\n MSC_TRANSCODER({ wasmBinary }).then((basisModule: any) => {\r\n basisModule.initTranscoders();\r\n this._mscBasisModule = basisModule;\r\n resolve();\r\n });\r\n });\r\n });\r\n\r\n return this._mscBasisTranscoderPromise;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static override CanTranscode(src: KTX2.SourceTextureFormat, dst: KTX2.TranscodeTarget, isInGammaSpace: boolean): boolean {\r\n return true;\r\n }\r\n\r\n public override transcode(\r\n src: KTX2.SourceTextureFormat,\r\n dst: KTX2.TranscodeTarget,\r\n level: number,\r\n width: number,\r\n height: number,\r\n uncompressedByteLength: number,\r\n ktx2Reader: KTX2FileReader,\r\n imageDesc: IKTX2_ImageDesc | null,\r\n encodedData: Uint8Array\r\n ): Promise<Uint8Array | null> {\r\n const isVideo = false;\r\n\r\n return this._getMSCBasisTranscoder().then(() => {\r\n const basisModule = this._mscBasisModule;\r\n\r\n let transcoder: any;\r\n let imageInfo: any;\r\n let result: any;\r\n let textureData: any = null;\r\n\r\n try {\r\n transcoder = src === KTX2.SourceTextureFormat.UASTC4x4 ? new basisModule.UastcImageTranscoder() : new basisModule.BasisLzEtc1sImageTranscoder();\r\n const texFormat = src === KTX2.SourceTextureFormat.UASTC4x4 ? basisModule.TextureFormat.UASTC4x4 : basisModule.TextureFormat.ETC1S;\r\n\r\n imageInfo = new basisModule.ImageInfo(texFormat, width, height, level);\r\n\r\n const targetFormat = basisModule.TranscodeTarget[KTX2.TranscodeTarget[dst]]; // works because the labels of the sourceTextureFormat enum are the same as the property names used in TranscodeTarget!\r\n\r\n if (!basisModule.isFormatSupported(targetFormat, texFormat)) {\r\n throw new Error(\r\n `MSCTranscoder: Transcoding from \"${KTX2.SourceTextureFormat[src]}\" to \"${KTX2.TranscodeTarget[dst]}\" not supported by current transcoder build.`\r\n );\r\n }\r\n\r\n if (src === KTX2.SourceTextureFormat.ETC1S) {\r\n const sgd = ktx2Reader.supercompressionGlobalData;\r\n\r\n transcoder.decodePalettes(sgd.endpointCount, sgd.endpointsData, sgd.selectorCount, sgd.selectorsData);\r\n transcoder.decodeTables(sgd.tablesData);\r\n\r\n imageInfo.flags = imageDesc!.imageFlags;\r\n imageInfo.rgbByteOffset = 0;\r\n imageInfo.rgbByteLength = imageDesc!.rgbSliceByteLength;\r\n imageInfo.alphaByteOffset = imageDesc!.alphaSliceByteOffset > 0 ? imageDesc!.rgbSliceByteLength : 0;\r\n imageInfo.alphaByteLength = imageDesc!.alphaSliceByteLength;\r\n\r\n result = transcoder.transcodeImage(targetFormat, encodedData, imageInfo, 0, isVideo);\r\n } else {\r\n imageInfo.flags = 0;\r\n imageInfo.rgbByteOffset = 0;\r\n imageInfo.rgbByteLength = uncompressedByteLength;\r\n imageInfo.alphaByteOffset = 0;\r\n imageInfo.alphaByteLength = 0;\r\n\r\n result = transcoder.transcodeImage(targetFormat, encodedData, imageInfo, 0, ktx2Reader.hasAlpha, isVideo);\r\n }\r\n } finally {\r\n if (transcoder) {\r\n transcoder.delete();\r\n }\r\n\r\n if (imageInfo) {\r\n imageInfo.delete();\r\n }\r\n\r\n if (result && result.transcodedImage) {\r\n textureData = result.transcodedImage.get_typed_memory_view().slice();\r\n result.transcodedImage.delete();\r\n }\r\n }\r\n\r\n return textureData;\r\n });\r\n }\r\n}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S,EAAE,CAAC,EAAE,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;gBAC9G,CAAC;YACL,CAAC;oBAAS,CAAC;gBACP,IAAI,UAAU,EAAE,CAAC;oBACb,UAAU,CAAC,MAAM,EAAE,CAAC;gBACxB,CAAC;gBAED,IAAI,SAAS,EAAE,CAAC;oBACZ,SAAS,CAAC,MAAM,EAAE,CAAC;gBACvB,CAAC;gBAED,IAAI,MAAM,IAAI,MAAM,CAAC,eAAe,EAAE,CAAC;oBACnC,WAAW,GAAG,MAAM,CAAC,eAAe,CAAC,qBAAqB,EAAE,CAAC,KAAK,EAAE,CAAC;oBACrE,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC;gBACpC,CAAC;YACL,CAAC;YAED,OAAO,WAAW,CAAC;QACvB,CAAC,CAAC,CAAC;IACP,CAAC;;AAvKD;;GAEG;AACW,yBAAW,GAAG,qEAAqE,CAAC;AAClG;;GAEG;AACW,2BAAa,GAAG,uEAAuE,CAAC;AAEtG;;GAEG;AACW,wBAAU,GAAuB,IAAI,CAAC;AAEpD;;GAEG;AACW,sBAAQ,GAAQ,IAAI,CAAC;AAErB,iCAAmB,GAAG,IAAI,CAAC;AAElB,kBAAI,GAAG,eAAe,CAAC","sourcesContent":["import * as KTX2 from \"core/Materials/Textures/ktx2decoderTypes\";\r\n\r\nimport { Transcoder } from \"../transcoder\";\r\nimport type { KTX2FileReader, IKTX2_ImageDesc } from \"../ktx2FileReader\";\r\nimport { WASMMemoryManager } from \"../wasmMemoryManager\";\r\n\r\ndeclare let MSC_TRANSCODER: any;\r\n\r\ndeclare function importScripts(...urls: string[]): void;\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class MSCTranscoder extends Transcoder {\r\n /**\r\n * URL to use when loading the MSC transcoder\r\n */\r\n public static JSModuleURL = \"https://cdn.babylonjs.com/ktx2Transcoders/1/msc_basis_transcoder.js\";\r\n /**\r\n * URL to use when loading the wasm module for the transcoder\r\n */\r\n public static WasmModuleURL = \"https://cdn.babylonjs.com/ktx2Transcoders/1/msc_basis_transcoder.wasm\";\r\n\r\n /**\r\n * Binary data of the wasm module\r\n */\r\n public static WasmBinary: ArrayBuffer | null = null;\r\n\r\n /**\r\n * MSC transcoder module, if provided externally\r\n */\r\n public static JSModule: any = null;\r\n\r\n public static UseFromWorkerThread = true;\r\n\r\n public static override Name = \"MSCTranscoder\";\r\n\r\n public override getName(): string {\r\n return MSCTranscoder.Name;\r\n }\r\n\r\n private _mscBasisTranscoderPromise: Promise<void>;\r\n private _mscBasisModule: any;\r\n\r\n private _getMSCBasisTranscoder(): Promise<void> {\r\n if (this._mscBasisTranscoderPromise) {\r\n return this._mscBasisTranscoderPromise;\r\n }\r\n\r\n this._mscBasisTranscoderPromise = (\r\n MSCTranscoder.WasmBinary ? Promise.resolve(MSCTranscoder.WasmBinary) : WASMMemoryManager.LoadWASM(Transcoder.GetWasmUrl(MSCTranscoder.WasmModuleURL))\r\n ).then((wasmBinary) => {\r\n if (MSCTranscoder.JSModule && typeof MSC_TRANSCODER === \"undefined\") {\r\n // this must be set on the global scope for the MSC transcoder to work. Mainly due to back-compat with the old way of loading the MSC transcoder.\r\n (globalThis as any).MSC_TRANSCODER = MSCTranscoder.JSModule;\r\n } else {\r\n if (MSCTranscoder.UseFromWorkerThread) {\r\n importScripts(Transcoder.GetWasmUrl(MSCTranscoder.JSModuleURL));\r\n }\r\n // Worker Number = 0 and MSC_TRANSCODER has not been loaded yet.\r\n else if (typeof MSC_TRANSCODER === \"undefined\") {\r\n return new Promise((resolve, reject) => {\r\n const head = document.getElementsByTagName(\"head\")[0];\r\n const script = document.createElement(\"script\");\r\n script.setAttribute(\"type\", \"text/javascript\");\r\n script.setAttribute(\"src\", Transcoder.GetWasmUrl(MSCTranscoder.JSModuleURL));\r\n\r\n script.onload = () => {\r\n // defensive\r\n if (typeof MSC_TRANSCODER === \"undefined\") {\r\n reject(\"MSC_TRANSCODER script loaded but MSC_TRANSCODER is not defined.\");\r\n return;\r\n }\r\n\r\n (MSC_TRANSCODER as any)({ wasmBinary }).then((basisModule: any) => {\r\n basisModule.initTranscoders();\r\n this._mscBasisModule = basisModule;\r\n resolve();\r\n });\r\n };\r\n\r\n script.onerror = () => {\r\n reject(\"Can not load MSC_TRANSCODER script.\");\r\n };\r\n\r\n head.appendChild(script);\r\n });\r\n }\r\n }\r\n\r\n return new Promise((resolve) => {\r\n MSC_TRANSCODER({ wasmBinary }).then((basisModule: any) => {\r\n basisModule.initTranscoders();\r\n this._mscBasisModule = basisModule;\r\n resolve();\r\n });\r\n });\r\n });\r\n\r\n return this._mscBasisTranscoderPromise;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static override CanTranscode(src: KTX2.SourceTextureFormat, dst: KTX2.TranscodeTarget, isInGammaSpace: boolean): boolean {\r\n return true;\r\n }\r\n\r\n public override transcode(\r\n src: KTX2.SourceTextureFormat,\r\n dst: KTX2.TranscodeTarget,\r\n level: number,\r\n width: number,\r\n height: number,\r\n uncompressedByteLength: number,\r\n ktx2Reader: KTX2FileReader,\r\n imageDesc: IKTX2_ImageDesc | null,\r\n encodedData: Uint8Array\r\n ): Promise<Uint8Array | null> {\r\n const isVideo = false;\r\n\r\n return this._getMSCBasisTranscoder().then(() => {\r\n const basisModule = this._mscBasisModule;\r\n\r\n let transcoder: any;\r\n let imageInfo: any;\r\n let result: any;\r\n let textureData: any = null;\r\n\r\n try {\r\n transcoder = src === KTX2.SourceTextureFormat.UASTC4x4 ? new basisModule.UastcImageTranscoder() : new basisModule.BasisLzEtc1sImageTranscoder();\r\n const texFormat = src === KTX2.SourceTextureFormat.UASTC4x4 ? basisModule.TextureFormat.UASTC4x4 : basisModule.TextureFormat.ETC1S;\r\n\r\n imageInfo = new basisModule.ImageInfo(texFormat, width, height, level);\r\n\r\n const targetFormat = basisModule.TranscodeTarget[KTX2.TranscodeTarget[dst]]; // works because the labels of the sourceTextureFormat enum are the same as the property names used in TranscodeTarget!\r\n\r\n if (!basisModule.isFormatSupported(targetFormat, texFormat)) {\r\n throw new Error(\r\n `MSCTranscoder: Transcoding from \"${KTX2.SourceTextureFormat[src]}\" to \"${KTX2.TranscodeTarget[dst]}\" not supported by current transcoder build.`\r\n );\r\n }\r\n\r\n if (src === KTX2.SourceTextureFormat.ETC1S) {\r\n const sgd = ktx2Reader.supercompressionGlobalData;\r\n\r\n transcoder.decodePalettes(sgd.endpointCount, sgd.endpointsData, sgd.selectorCount, sgd.selectorsData);\r\n transcoder.decodeTables(sgd.tablesData);\r\n\r\n imageInfo.flags = imageDesc!.imageFlags;\r\n imageInfo.rgbByteOffset = 0;\r\n imageInfo.rgbByteLength = imageDesc!.rgbSliceByteLength;\r\n imageInfo.alphaByteOffset = imageDesc!.alphaSliceByteOffset > 0 ? imageDesc!.rgbSliceByteLength : 0;\r\n imageInfo.alphaByteLength = imageDesc!.alphaSliceByteLength;\r\n\r\n result = transcoder.transcodeImage(targetFormat, encodedData, imageInfo, 0, isVideo);\r\n } else {\r\n imageInfo.flags = 0;\r\n imageInfo.rgbByteOffset = 0;\r\n imageInfo.rgbByteLength = uncompressedByteLength;\r\n imageInfo.alphaByteOffset = 0;\r\n imageInfo.alphaByteLength = 0;\r\n\r\n result = transcoder.transcodeImage(targetFormat, encodedData, imageInfo, 0, ktx2Reader.hasAlpha, isVideo);\r\n }\r\n } finally {\r\n if (transcoder) {\r\n transcoder.delete();\r\n }\r\n\r\n if (imageInfo) {\r\n imageInfo.delete();\r\n }\r\n\r\n if (result && result.transcodedImage) {\r\n textureData = result.transcodedImage.get_typed_memory_view().slice();\r\n result.transcodedImage.delete();\r\n }\r\n }\r\n\r\n return textureData;\r\n });\r\n }\r\n}\r\n"]}
|
package/ktx2Decoder.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ktx2Decoder.js","sourceRoot":"","sources":["../../../tools/ktx2Decoder/src/ktx2Decoder.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,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AC,CAAC,CAAC;gBAEP,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;gBAElC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;aACxB;SACJ;QAED,OAAO,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;YACvC,OAAO,WAAW,CAAC;QACvB,CAAC,CAAC,CAAC;IACP,CAAC;;AA1Ia,iCAAqB,GAA6B,EAAE,CAAC;AA6IvE,mEAAmE;AACnE,iBAAiB,CAAC,kBAAkB,CAAC,yBAAyB,CAAC,CAAC;AAChE,iBAAiB,CAAC,kBAAkB,CAAC,wBAAwB,CAAC,CAAC;AAC/D,iBAAiB,CAAC,kBAAkB,CAAC,+BAA+B,CAAC,CAAC;AACtE,iBAAiB,CAAC,kBAAkB,CAAC,8BAA8B,CAAC,CAAC;AACrE,iBAAiB,CAAC,kBAAkB,CAAC,6BAA6B,CAAC,CAAC;AACpE,iBAAiB,CAAC,kBAAkB,CAAC,8BAA8B,CAAC,CAAC;AACrE,iBAAiB,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAC,CAAC,+EAA+E","sourcesContent":["/**\r\n * Resources used for the implementation:\r\n * - 3js KTX2 loader: https://github.com/mrdoob/three.js/blob/dfb5c23ce126ec845e4aa240599915fef5375797/examples/jsm/loaders/KTX2Loader.js\r\n * - Universal Texture Transcoders: https://github.com/KhronosGroup/Universal-Texture-Transcoders\r\n * - KTX2 specification: http://github.khronos.org/KTX-Specification/\r\n * - KTX2 binaries to convert files: https://github.com/KhronosGroup/KTX-Software/releases\r\n * - KTX specification: https://www.khronos.org/registry/DataFormat/specs/1.3/dataformat.1.3.html\r\n * - KTX-Software: https://github.com/KhronosGroup/KTX-Software\r\n */\r\nimport * as KTX2 from \"core/Materials/Textures/ktx2decoderTypes\";\r\n\r\nimport type { IKTX2_ImageDesc } from \"./ktx2FileReader\";\r\nimport { KTX2FileReader, SupercompressionScheme } from \"./ktx2FileReader\";\r\nimport { TranscoderManager } from \"./transcoderManager\";\r\nimport { LiteTranscoder_UASTC_ASTC } from \"./Transcoders/liteTranscoder_UASTC_ASTC\";\r\nimport { LiteTranscoder_UASTC_BC7 } from \"./Transcoders/liteTranscoder_UASTC_BC7\";\r\nimport { LiteTranscoder_UASTC_RGBA_UNORM } from \"./Transcoders/liteTranscoder_UASTC_RGBA_UNORM\";\r\nimport { LiteTranscoder_UASTC_RGBA_SRGB } from \"./Transcoders/liteTranscoder_UASTC_RGBA_SRGB\";\r\nimport { LiteTranscoder_UASTC_R8_UNORM } from \"./Transcoders/liteTranscoder_UASTC_R8_UNORM\";\r\nimport { LiteTranscoder_UASTC_RG8_UNORM } from \"./Transcoders/liteTranscoder_UASTC_RG8_UNORM\";\r\nimport { MSCTranscoder } from \"./Transcoders/mscTranscoder\";\r\nimport { ZSTDDecoder } from \"./zstddec\";\r\nimport { TranscodeDecisionTree } from \"./transcodeDecisionTree\";\r\n\r\nconst isPowerOfTwo = (value: number) => {\r\n return (value & (value - 1)) === 0 && value !== 0;\r\n};\r\n\r\n/**\r\n * Class for decoding KTX2 files\r\n *\r\n */\r\nexport class KTX2Decoder {\r\n private _transcoderMgr: TranscoderManager;\r\n private _zstdDecoder: ZSTDDecoder;\r\n\r\n public static DefaultDecoderOptions: KTX2.IKTX2DecoderOptions = {};\r\n\r\n constructor() {\r\n this._transcoderMgr = new TranscoderManager();\r\n }\r\n\r\n public decode(data: Uint8Array, caps: KTX2.ICompressedFormatCapabilities, options?: KTX2.IKTX2DecoderOptions): Promise<KTX2.IDecodedData> {\r\n const finalOptions = { ...options, ...KTX2Decoder.DefaultDecoderOptions };\r\n\r\n return Promise.resolve().then(() => {\r\n const kfr = new KTX2FileReader(data);\r\n\r\n if (!kfr.isValid()) {\r\n throw new Error(\"Invalid KT2 file: wrong signature\");\r\n }\r\n\r\n kfr.parse();\r\n\r\n if (kfr.needZSTDDecoder) {\r\n if (!this._zstdDecoder) {\r\n this._zstdDecoder = new ZSTDDecoder();\r\n }\r\n\r\n return this._zstdDecoder.init().then(() => {\r\n return this._decodeData(kfr, caps, finalOptions);\r\n });\r\n }\r\n\r\n return this._decodeData(kfr, caps, finalOptions);\r\n });\r\n }\r\n\r\n private _decodeData(kfr: KTX2FileReader, caps: KTX2.ICompressedFormatCapabilities, options?: KTX2.IKTX2DecoderOptions): Promise<KTX2.IDecodedData> {\r\n const width = kfr.header.pixelWidth;\r\n const height = kfr.header.pixelHeight;\r\n const srcTexFormat = kfr.textureFormat;\r\n\r\n const decisionTree = new TranscodeDecisionTree(srcTexFormat, kfr.hasAlpha, isPowerOfTwo(width) && isPowerOfTwo(height), caps, options);\r\n\r\n if (options?.transcodeFormatDecisionTree) {\r\n decisionTree.parseTree(options?.transcodeFormatDecisionTree);\r\n }\r\n\r\n const transcodeFormat = decisionTree.transcodeFormat;\r\n const engineFormat = decisionTree.engineFormat;\r\n const roundToMultiple4 = decisionTree.roundToMultiple4;\r\n\r\n const transcoder = this._transcoderMgr.findTranscoder(srcTexFormat, transcodeFormat, kfr.isInGammaSpace, options?.bypassTranscoders);\r\n\r\n if (transcoder === null) {\r\n throw new Error(\r\n `no transcoder found to transcode source texture format \"${KTX2.SourceTextureFormat[srcTexFormat]}\" to format \"${KTX2.TranscodeTarget[transcodeFormat]}\"`\r\n );\r\n }\r\n\r\n const mipmaps: Array<KTX2.IMipmap> = [];\r\n const dataPromises: Array<Promise<Uint8Array | null>> = [];\r\n const decodedData: KTX2.IDecodedData = {\r\n width: 0,\r\n height: 0,\r\n transcodedFormat: engineFormat,\r\n mipmaps,\r\n isInGammaSpace: kfr.isInGammaSpace,\r\n hasAlpha: kfr.hasAlpha,\r\n transcoderName: transcoder.getName(),\r\n };\r\n\r\n let firstImageDescIndex = 0;\r\n\r\n for (let level = 0; level < kfr.header.levelCount; level++) {\r\n if (level > 0) {\r\n firstImageDescIndex += Math.max(kfr.header.layerCount, 1) * kfr.header.faceCount * Math.max(kfr.header.pixelDepth >> (level - 1), 1);\r\n }\r\n\r\n const levelWidth = Math.floor(width / (1 << level)) || 1;\r\n const levelHeight = Math.floor(height / (1 << level)) || 1;\r\n\r\n const numImagesInLevel = kfr.header.faceCount; // note that cubemap are not supported yet (see KTX2FileReader), so faceCount == 1\r\n const levelImageByteLength = ((levelWidth + 3) >> 2) * ((levelHeight + 3) >> 2) * kfr.dfdBlock.bytesPlane[0];\r\n\r\n const levelUncompressedByteLength = kfr.levels[level].uncompressedByteLength;\r\n\r\n let levelDataBuffer = kfr.data.buffer;\r\n\r\n let levelDataOffset = kfr.levels[level].byteOffset + kfr.data.byteOffset;\r\n let imageOffsetInLevel = 0;\r\n\r\n if (kfr.header.supercompressionScheme === SupercompressionScheme.ZStandard) {\r\n levelDataBuffer = this._zstdDecoder.decode(new Uint8Array(levelDataBuffer, levelDataOffset, kfr.levels[level].byteLength), levelUncompressedByteLength);\r\n levelDataOffset = 0;\r\n }\r\n\r\n if (level === 0) {\r\n decodedData.width = roundToMultiple4 ? (levelWidth + 3) & ~3 : levelWidth;\r\n decodedData.height = roundToMultiple4 ? (levelHeight + 3) & ~3 : levelHeight;\r\n }\r\n\r\n for (let imageIndex = 0; imageIndex < numImagesInLevel; imageIndex++) {\r\n let encodedData: Uint8Array;\r\n let imageDesc: IKTX2_ImageDesc | null = null;\r\n\r\n if (kfr.header.supercompressionScheme === SupercompressionScheme.BasisLZ) {\r\n imageDesc = kfr.supercompressionGlobalData.imageDescs![firstImageDescIndex + imageIndex];\r\n\r\n encodedData = new Uint8Array(levelDataBuffer, levelDataOffset + imageDesc.rgbSliceByteOffset, imageDesc.rgbSliceByteLength + imageDesc.alphaSliceByteLength);\r\n } else {\r\n encodedData = new Uint8Array(levelDataBuffer, levelDataOffset + imageOffsetInLevel, levelImageByteLength);\r\n\r\n imageOffsetInLevel += levelImageByteLength;\r\n }\r\n\r\n const mipmap: KTX2.IMipmap = {\r\n data: null,\r\n width: levelWidth,\r\n height: levelHeight,\r\n };\r\n\r\n const transcodedData = transcoder\r\n .transcode(srcTexFormat, transcodeFormat, level, levelWidth, levelHeight, levelUncompressedByteLength, kfr, imageDesc, encodedData)\r\n .then((data) => {\r\n mipmap.data = data;\r\n return data;\r\n })\r\n .catch((reason) => {\r\n decodedData.errors = decodedData.errors ?? \"\";\r\n decodedData.errors += reason + \"\\n\" + reason.stack + \"\\n\";\r\n return null;\r\n });\r\n\r\n dataPromises.push(transcodedData);\r\n\r\n mipmaps.push(mipmap);\r\n }\r\n }\r\n\r\n return Promise.all(dataPromises).then(() => {\r\n return decodedData;\r\n });\r\n }\r\n}\r\n\r\n// Put in the order you want the transcoders to be used in priority\r\nTranscoderManager.RegisterTranscoder(LiteTranscoder_UASTC_ASTC);\r\nTranscoderManager.RegisterTranscoder(LiteTranscoder_UASTC_BC7);\r\nTranscoderManager.RegisterTranscoder(LiteTranscoder_UASTC_RGBA_UNORM);\r\nTranscoderManager.RegisterTranscoder(LiteTranscoder_UASTC_RGBA_SRGB);\r\nTranscoderManager.RegisterTranscoder(LiteTranscoder_UASTC_R8_UNORM);\r\nTranscoderManager.RegisterTranscoder(LiteTranscoder_UASTC_RG8_UNORM);\r\nTranscoderManager.RegisterTranscoder(MSCTranscoder); // catch all transcoder - will throw an error if the format can't be transcoded\r\n"]}
|
1
|
+
{"version":3,"file":"ktx2Decoder.js","sourceRoot":"","sources":["../../../tools/ktx2Decoder/src/ktx2Decoder.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,IAAI,+DAAiD;AAGjE,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAClF,OAAO,EAAE,+BAA+B,EAAE,MAAM,+CAA+C,CAAC;AAChG,OAAO,EAAE,8BAA8B,EAAE,MA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AC,GAAG,EAAE;YACvC,OAAO,WAAW,CAAC;QACvB,CAAC,CAAC,CAAC;IACP,CAAC;;AA1Ia,iCAAqB,GAA6B,EAAE,CAAC;AA6IvE,mEAAmE;AACnE,iBAAiB,CAAC,kBAAkB,CAAC,yBAAyB,CAAC,CAAC;AAChE,iBAAiB,CAAC,kBAAkB,CAAC,wBAAwB,CAAC,CAAC;AAC/D,iBAAiB,CAAC,kBAAkB,CAAC,+BAA+B,CAAC,CAAC;AACtE,iBAAiB,CAAC,kBAAkB,CAAC,8BAA8B,CAAC,CAAC;AACrE,iBAAiB,CAAC,kBAAkB,CAAC,6BAA6B,CAAC,CAAC;AACpE,iBAAiB,CAAC,kBAAkB,CAAC,8BAA8B,CAAC,CAAC;AACrE,iBAAiB,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAC,CAAC,+EAA+E","sourcesContent":["/**\r\n * Resources used for the implementation:\r\n * - 3js KTX2 loader: https://github.com/mrdoob/three.js/blob/dfb5c23ce126ec845e4aa240599915fef5375797/examples/jsm/loaders/KTX2Loader.js\r\n * - Universal Texture Transcoders: https://github.com/KhronosGroup/Universal-Texture-Transcoders\r\n * - KTX2 specification: http://github.khronos.org/KTX-Specification/\r\n * - KTX2 binaries to convert files: https://github.com/KhronosGroup/KTX-Software/releases\r\n * - KTX specification: https://www.khronos.org/registry/DataFormat/specs/1.3/dataformat.1.3.html\r\n * - KTX-Software: https://github.com/KhronosGroup/KTX-Software\r\n */\r\nimport * as KTX2 from \"core/Materials/Textures/ktx2decoderTypes\";\r\n\r\nimport type { IKTX2_ImageDesc } from \"./ktx2FileReader\";\r\nimport { KTX2FileReader, SupercompressionScheme } from \"./ktx2FileReader\";\r\nimport { TranscoderManager } from \"./transcoderManager\";\r\nimport { LiteTranscoder_UASTC_ASTC } from \"./Transcoders/liteTranscoder_UASTC_ASTC\";\r\nimport { LiteTranscoder_UASTC_BC7 } from \"./Transcoders/liteTranscoder_UASTC_BC7\";\r\nimport { LiteTranscoder_UASTC_RGBA_UNORM } from \"./Transcoders/liteTranscoder_UASTC_RGBA_UNORM\";\r\nimport { LiteTranscoder_UASTC_RGBA_SRGB } from \"./Transcoders/liteTranscoder_UASTC_RGBA_SRGB\";\r\nimport { LiteTranscoder_UASTC_R8_UNORM } from \"./Transcoders/liteTranscoder_UASTC_R8_UNORM\";\r\nimport { LiteTranscoder_UASTC_RG8_UNORM } from \"./Transcoders/liteTranscoder_UASTC_RG8_UNORM\";\r\nimport { MSCTranscoder } from \"./Transcoders/mscTranscoder\";\r\nimport { ZSTDDecoder } from \"./zstddec\";\r\nimport { TranscodeDecisionTree } from \"./transcodeDecisionTree\";\r\n\r\nconst isPowerOfTwo = (value: number) => {\r\n return (value & (value - 1)) === 0 && value !== 0;\r\n};\r\n\r\n/**\r\n * Class for decoding KTX2 files\r\n *\r\n */\r\nexport class KTX2Decoder {\r\n private _transcoderMgr: TranscoderManager;\r\n private _zstdDecoder: ZSTDDecoder;\r\n\r\n public static DefaultDecoderOptions: KTX2.IKTX2DecoderOptions = {};\r\n\r\n constructor() {\r\n this._transcoderMgr = new TranscoderManager();\r\n }\r\n\r\n public decode(data: Uint8Array, caps: KTX2.ICompressedFormatCapabilities, options?: KTX2.IKTX2DecoderOptions): Promise<KTX2.IDecodedData> {\r\n const finalOptions = { ...options, ...KTX2Decoder.DefaultDecoderOptions };\r\n\r\n return Promise.resolve().then(() => {\r\n const kfr = new KTX2FileReader(data);\r\n\r\n if (!kfr.isValid()) {\r\n throw new Error(\"Invalid KT2 file: wrong signature\");\r\n }\r\n\r\n kfr.parse();\r\n\r\n if (kfr.needZSTDDecoder) {\r\n if (!this._zstdDecoder) {\r\n this._zstdDecoder = new ZSTDDecoder();\r\n }\r\n\r\n return this._zstdDecoder.init().then(() => {\r\n return this._decodeData(kfr, caps, finalOptions);\r\n });\r\n }\r\n\r\n return this._decodeData(kfr, caps, finalOptions);\r\n });\r\n }\r\n\r\n private _decodeData(kfr: KTX2FileReader, caps: KTX2.ICompressedFormatCapabilities, options?: KTX2.IKTX2DecoderOptions): Promise<KTX2.IDecodedData> {\r\n const width = kfr.header.pixelWidth;\r\n const height = kfr.header.pixelHeight;\r\n const srcTexFormat = kfr.textureFormat;\r\n\r\n const decisionTree = new TranscodeDecisionTree(srcTexFormat, kfr.hasAlpha, isPowerOfTwo(width) && isPowerOfTwo(height), caps, options);\r\n\r\n if (options?.transcodeFormatDecisionTree) {\r\n decisionTree.parseTree(options?.transcodeFormatDecisionTree);\r\n }\r\n\r\n const transcodeFormat = decisionTree.transcodeFormat;\r\n const engineFormat = decisionTree.engineFormat;\r\n const roundToMultiple4 = decisionTree.roundToMultiple4;\r\n\r\n const transcoder = this._transcoderMgr.findTranscoder(srcTexFormat, transcodeFormat, kfr.isInGammaSpace, options?.bypassTranscoders);\r\n\r\n if (transcoder === null) {\r\n throw new Error(\r\n `no transcoder found to transcode source texture format \"${KTX2.SourceTextureFormat[srcTexFormat]}\" to format \"${KTX2.TranscodeTarget[transcodeFormat]}\"`\r\n );\r\n }\r\n\r\n const mipmaps: Array<KTX2.IMipmap> = [];\r\n const dataPromises: Array<Promise<Uint8Array | null>> = [];\r\n const decodedData: KTX2.IDecodedData = {\r\n width: 0,\r\n height: 0,\r\n transcodedFormat: engineFormat,\r\n mipmaps,\r\n isInGammaSpace: kfr.isInGammaSpace,\r\n hasAlpha: kfr.hasAlpha,\r\n transcoderName: transcoder.getName(),\r\n };\r\n\r\n let firstImageDescIndex = 0;\r\n\r\n for (let level = 0; level < kfr.header.levelCount; level++) {\r\n if (level > 0) {\r\n firstImageDescIndex += Math.max(kfr.header.layerCount, 1) * kfr.header.faceCount * Math.max(kfr.header.pixelDepth >> (level - 1), 1);\r\n }\r\n\r\n const levelWidth = Math.floor(width / (1 << level)) || 1;\r\n const levelHeight = Math.floor(height / (1 << level)) || 1;\r\n\r\n const numImagesInLevel = kfr.header.faceCount; // note that cubemap are not supported yet (see KTX2FileReader), so faceCount == 1\r\n const levelImageByteLength = ((levelWidth + 3) >> 2) * ((levelHeight + 3) >> 2) * kfr.dfdBlock.bytesPlane[0];\r\n\r\n const levelUncompressedByteLength = kfr.levels[level].uncompressedByteLength;\r\n\r\n let levelDataBuffer = kfr.data.buffer;\r\n\r\n let levelDataOffset = kfr.levels[level].byteOffset + kfr.data.byteOffset;\r\n let imageOffsetInLevel = 0;\r\n\r\n if (kfr.header.supercompressionScheme === SupercompressionScheme.ZStandard) {\r\n levelDataBuffer = this._zstdDecoder.decode(new Uint8Array(levelDataBuffer, levelDataOffset, kfr.levels[level].byteLength), levelUncompressedByteLength);\r\n levelDataOffset = 0;\r\n }\r\n\r\n if (level === 0) {\r\n decodedData.width = roundToMultiple4 ? (levelWidth + 3) & ~3 : levelWidth;\r\n decodedData.height = roundToMultiple4 ? (levelHeight + 3) & ~3 : levelHeight;\r\n }\r\n\r\n for (let imageIndex = 0; imageIndex < numImagesInLevel; imageIndex++) {\r\n let encodedData: Uint8Array;\r\n let imageDesc: IKTX2_ImageDesc | null = null;\r\n\r\n if (kfr.header.supercompressionScheme === SupercompressionScheme.BasisLZ) {\r\n imageDesc = kfr.supercompressionGlobalData.imageDescs![firstImageDescIndex + imageIndex];\r\n\r\n encodedData = new Uint8Array(levelDataBuffer, levelDataOffset + imageDesc.rgbSliceByteOffset, imageDesc.rgbSliceByteLength + imageDesc.alphaSliceByteLength);\r\n } else {\r\n encodedData = new Uint8Array(levelDataBuffer, levelDataOffset + imageOffsetInLevel, levelImageByteLength);\r\n\r\n imageOffsetInLevel += levelImageByteLength;\r\n }\r\n\r\n const mipmap: KTX2.IMipmap = {\r\n data: null,\r\n width: levelWidth,\r\n height: levelHeight,\r\n };\r\n\r\n const transcodedData = transcoder\r\n .transcode(srcTexFormat, transcodeFormat, level, levelWidth, levelHeight, levelUncompressedByteLength, kfr, imageDesc, encodedData)\r\n .then((data) => {\r\n mipmap.data = data;\r\n return data;\r\n })\r\n .catch((reason) => {\r\n decodedData.errors = decodedData.errors ?? \"\";\r\n decodedData.errors += reason + \"\\n\" + reason.stack + \"\\n\";\r\n return null;\r\n });\r\n\r\n dataPromises.push(transcodedData);\r\n\r\n mipmaps.push(mipmap);\r\n }\r\n }\r\n\r\n return Promise.all(dataPromises).then(() => {\r\n return decodedData;\r\n });\r\n }\r\n}\r\n\r\n// Put in the order you want the transcoders to be used in priority\r\nTranscoderManager.RegisterTranscoder(LiteTranscoder_UASTC_ASTC);\r\nTranscoderManager.RegisterTranscoder(LiteTranscoder_UASTC_BC7);\r\nTranscoderManager.RegisterTranscoder(LiteTranscoder_UASTC_RGBA_UNORM);\r\nTranscoderManager.RegisterTranscoder(LiteTranscoder_UASTC_RGBA_SRGB);\r\nTranscoderManager.RegisterTranscoder(LiteTranscoder_UASTC_R8_UNORM);\r\nTranscoderManager.RegisterTranscoder(LiteTranscoder_UASTC_RG8_UNORM);\r\nTranscoderManager.RegisterTranscoder(MSCTranscoder); // catch all transcoder - will throw an error if the format can't be transcoded\r\n"]}
|
package/ktx2FileReader.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ktx2FileReader.js","sourceRoot":"","sources":["../../../tools/ktx2Decoder/src/ktx2FileReader.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,OAAO,KAAK,IAAI,+DAAiD;AAEjE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,gBAAgB;AAChB,MAAM,CAAN,IAAY,sBAKX;AALD,WAAY,sBAAsB;IAC9B,mEAAQ,CAAA;IACR,yEAAW,CAAA;IACX,6EAAa,CAAA;IACb,mEAAQ,CAAA;AACZ,CAAC,EALW,sBAAsB,KAAtB,sBAAsB,QAKjC;AAED,IAAW,QAGV;AAHD,WAAW,QAAQ;IACf,2CAAW,CAAA;IACX,2CAAW,CAAA;AACf,CAAC,EAHU,QAAQ,KAAR,QAAQ,QAGlB;AAED,IAAW,gBAKV;AALD,WAAW,gBAAgB;IACvB,qDAAO,CAAA;IACP,qDAAO,CAAA;IACP,qDAAO,CAAA;IACP,sDAA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,CAAC,CAAC;YACpE,IACI,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,EAAE,CAAC,KAAK,IAAI;gBACvB,UAAU,CAAC,EAAE,CAAC,KAAK,IAAI,EACzB;gBACE,OAAO,IAAI,CAAC;aACf;SACJ;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport * as KTX2 from \"core/Materials/Textures/ktx2decoderTypes\";\r\n\r\nimport { DataReader } from \"./Misc/dataReader\";\r\n\r\n/** @internal */\r\nexport enum SupercompressionScheme {\r\n None = 0,\r\n BasisLZ = 1,\r\n ZStandard = 2,\r\n ZLib = 3,\r\n}\r\n\r\nconst enum DFDModel {\r\n ETC1S = 163,\r\n UASTC = 166,\r\n}\r\n\r\nconst enum DFDChannel_ETC1S {\r\n RGB = 0,\r\n RRR = 3,\r\n GGG = 4,\r\n AAA = 15,\r\n}\r\n\r\nconst enum DFDChannel_UASTC {\r\n RGB = 0,\r\n RGBA = 3,\r\n RRR = 4,\r\n RRRG = 5,\r\n}\r\n\r\nconst enum DFDTransferFunction {\r\n linear = 1,\r\n sRGB = 2,\r\n}\r\n\r\n/** @internal */\r\nexport interface IKTX2_Header {\r\n vkFormat: number;\r\n typeSize: number;\r\n pixelWidth: number;\r\n pixelHeight: number;\r\n pixelDepth: number;\r\n layerCount: number;\r\n faceCount: number;\r\n levelCount: number;\r\n supercompressionScheme: number;\r\n dfdByteOffset: number;\r\n dfdByteLength: number;\r\n kvdByteOffset: number;\r\n kvdByteLength: number;\r\n sgdByteOffset: number;\r\n sgdByteLength: number;\r\n}\r\n\r\n/** @internal */\r\nexport interface IKTX2_Level {\r\n byteOffset: number;\r\n byteLength: number;\r\n uncompressedByteLength: number;\r\n}\r\n\r\ninterface IKTX2_Sample {\r\n bitOffset: number;\r\n bitLength: number;\r\n channelType: number;\r\n channelFlags: number;\r\n samplePosition: number[];\r\n sampleLower: number;\r\n sampleUpper: number;\r\n}\r\n\r\n/** @internal */\r\nexport interface IKTX2_DFD {\r\n vendorId: number;\r\n descriptorType: number;\r\n versionNumber: number;\r\n descriptorBlockSize: number;\r\n colorModel: number;\r\n colorPrimaries: number;\r\n transferFunction: number;\r\n flags: number;\r\n texelBlockDimension: {\r\n x: number;\r\n y: number;\r\n z: number;\r\n w: number;\r\n };\r\n bytesPlane: Array<number>;\r\n numSamples: number;\r\n samples: Array<IKTX2_Sample>;\r\n}\r\n\r\n/** @internal */\r\nexport interface IKTX2_ImageDesc {\r\n imageFlags: number;\r\n rgbSliceByteOffset: number;\r\n rgbSliceByteLength: number;\r\n alphaSliceByteOffset: number;\r\n alphaSliceByteLength: number;\r\n}\r\n\r\n/** @internal */\r\nexport interface IKTX2_SupercompressionGlobalData {\r\n endpointCount?: number;\r\n selectorCount?: number;\r\n endpointsByteLength?: number;\r\n selectorsByteLength?: number;\r\n tablesByteLength?: number;\r\n extendedByteLength?: number;\r\n imageDescs?: Array<IKTX2_ImageDesc>;\r\n endpointsData?: Uint8Array;\r\n selectorsData?: Uint8Array;\r\n tablesData?: Uint8Array;\r\n extendedData?: Uint8Array;\r\n}\r\n\r\nexport class KTX2FileReader {\r\n private _data: Uint8Array;\r\n private _header: IKTX2_Header;\r\n private _levels: Array<IKTX2_Level>;\r\n private _dfdBlock: IKTX2_DFD;\r\n private _supercompressionGlobalData: IKTX2_SupercompressionGlobalData;\r\n\r\n /**\r\n * Will throw an exception if the file can't be parsed\r\n * @param data\r\n */\r\n constructor(data: Uint8Array) {\r\n this._data = data;\r\n }\r\n\r\n public get data(): Uint8Array {\r\n return this._data;\r\n }\r\n\r\n public get header(): IKTX2_Header {\r\n return this._header;\r\n }\r\n\r\n public get levels(): Array<IKTX2_Level> {\r\n return this._levels;\r\n }\r\n\r\n public get dfdBlock(): IKTX2_DFD {\r\n return this._dfdBlock;\r\n }\r\n\r\n public get supercompressionGlobalData(): IKTX2_SupercompressionGlobalData {\r\n return this._supercompressionGlobalData;\r\n }\r\n\r\n public isValid() {\r\n return KTX2FileReader.IsValid(this._data);\r\n }\r\n\r\n public parse() {\r\n let offsetInFile = 12; // skip the header\r\n\r\n /**\r\n * Get the header\r\n */\r\n const hdrReader = new DataReader(this._data, offsetInFile, 17 * 4);\r\n\r\n const header = (this._header = {\r\n vkFormat: hdrReader.readUint32(),\r\n typeSize: hdrReader.readUint32(),\r\n pixelWidth: hdrReader.readUint32(),\r\n pixelHeight: hdrReader.readUint32(),\r\n pixelDepth: hdrReader.readUint32(),\r\n layerCount: hdrReader.readUint32(),\r\n faceCount: hdrReader.readUint32(),\r\n levelCount: hdrReader.readUint32(),\r\n supercompressionScheme: hdrReader.readUint32(),\r\n\r\n dfdByteOffset: hdrReader.readUint32(),\r\n dfdByteLength: hdrReader.readUint32(),\r\n kvdByteOffset: hdrReader.readUint32(),\r\n kvdByteLength: hdrReader.readUint32(),\r\n sgdByteOffset: hdrReader.readUint64(),\r\n sgdByteLength: hdrReader.readUint64(),\r\n });\r\n\r\n if (header.pixelDepth > 0) {\r\n throw new Error(`Failed to parse KTX2 file - Only 2D textures are currently supported.`);\r\n }\r\n\r\n if (header.layerCount > 1) {\r\n throw new Error(`Failed to parse KTX2 file - Array textures are not currently supported.`);\r\n }\r\n\r\n if (header.faceCount > 1) {\r\n throw new Error(`Failed to parse KTX2 file - Cube textures are not currently supported.`);\r\n }\r\n\r\n offsetInFile += hdrReader.byteOffset;\r\n\r\n /**\r\n * Get the levels\r\n */\r\n let levelCount = Math.max(1, header.levelCount);\r\n\r\n const levelReader = new DataReader(this._data, offsetInFile, levelCount * 3 * (2 * 4));\r\n\r\n const levels: Array<IKTX2_Level> = (this._levels = []);\r\n\r\n while (levelCount--) {\r\n levels.push({\r\n byteOffset: levelReader.readUint64(),\r\n byteLength: levelReader.readUint64(),\r\n uncompressedByteLength: levelReader.readUint64(),\r\n });\r\n }\r\n\r\n offsetInFile += levelReader.byteOffset;\r\n\r\n /**\r\n * Get the data format descriptor (DFD) blocks\r\n */\r\n const dfdReader = new DataReader(this._data, header.dfdByteOffset, header.dfdByteLength);\r\n\r\n const dfdBlock = (this._dfdBlock = {\r\n vendorId: dfdReader.skipBytes(4 /* skip totalSize */).readUint16(),\r\n descriptorType: dfdReader.readUint16(),\r\n versionNumber: dfdReader.readUint16(),\r\n descriptorBlockSize: dfdReader.readUint16(),\r\n colorModel: dfdReader.readUint8(),\r\n colorPrimaries: dfdReader.readUint8(),\r\n transferFunction: dfdReader.readUint8(),\r\n flags: dfdReader.readUint8(),\r\n texelBlockDimension: {\r\n x: dfdReader.readUint8() + 1,\r\n y: dfdReader.readUint8() + 1,\r\n z: dfdReader.readUint8() + 1,\r\n w: dfdReader.readUint8() + 1,\r\n },\r\n bytesPlane: [\r\n dfdReader.readUint8() /* bytesPlane0 */,\r\n dfdReader.readUint8() /* bytesPlane1 */,\r\n dfdReader.readUint8() /* bytesPlane2 */,\r\n dfdReader.readUint8() /* bytesPlane3 */,\r\n dfdReader.readUint8() /* bytesPlane4 */,\r\n dfdReader.readUint8() /* bytesPlane5 */,\r\n dfdReader.readUint8() /* bytesPlane6 */,\r\n dfdReader.readUint8() /* bytesPlane7 */,\r\n ],\r\n numSamples: 0,\r\n samples: new Array<IKTX2_Sample>(),\r\n });\r\n\r\n dfdBlock.numSamples = (dfdBlock.descriptorBlockSize - 24) / 16;\r\n\r\n for (let i = 0; i < dfdBlock.numSamples; i++) {\r\n const sample = {\r\n bitOffset: dfdReader.readUint16(),\r\n bitLength: dfdReader.readUint8() + 1,\r\n channelType: dfdReader.readUint8(),\r\n channelFlags: 0,\r\n samplePosition: [\r\n dfdReader.readUint8() /* samplePosition0 */,\r\n dfdReader.readUint8() /* samplePosition1 */,\r\n dfdReader.readUint8() /* samplePosition2 */,\r\n dfdReader.readUint8() /* samplePosition3 */,\r\n ],\r\n sampleLower: dfdReader.readUint32(),\r\n sampleUpper: dfdReader.readUint32(),\r\n };\r\n\r\n sample.channelFlags = (sample.channelType & 0xf0) >> 4;\r\n sample.channelType = sample.channelType & 0x0f;\r\n\r\n dfdBlock.samples.push(sample);\r\n }\r\n\r\n /**\r\n * Get the Supercompression Global Data (sgd)\r\n */\r\n const sgd: IKTX2_SupercompressionGlobalData = (this._supercompressionGlobalData = {});\r\n\r\n if (header.sgdByteLength > 0) {\r\n const sgdReader = new DataReader(this._data, header.sgdByteOffset, header.sgdByteLength);\r\n\r\n sgd.endpointCount = sgdReader.readUint16();\r\n sgd.selectorCount = sgdReader.readUint16();\r\n sgd.endpointsByteLength = sgdReader.readUint32();\r\n sgd.selectorsByteLength = sgdReader.readUint32();\r\n sgd.tablesByteLength = sgdReader.readUint32();\r\n sgd.extendedByteLength = sgdReader.readUint32();\r\n sgd.imageDescs = [];\r\n\r\n const imageCount = this._getImageCount();\r\n\r\n for (let i = 0; i < imageCount; i++) {\r\n sgd.imageDescs.push({\r\n imageFlags: sgdReader.readUint32(),\r\n rgbSliceByteOffset: sgdReader.readUint32(),\r\n rgbSliceByteLength: sgdReader.readUint32(),\r\n alphaSliceByteOffset: sgdReader.readUint32(),\r\n alphaSliceByteLength: sgdReader.readUint32(),\r\n });\r\n }\r\n\r\n const endpointsByteOffset = header.sgdByteOffset + sgdReader.byteOffset;\r\n const selectorsByteOffset = endpointsByteOffset + sgd.endpointsByteLength;\r\n const tablesByteOffset = selectorsByteOffset + sgd.selectorsByteLength;\r\n const extendedByteOffset = tablesByteOffset + sgd.tablesByteLength;\r\n\r\n sgd.endpointsData = new Uint8Array(this._data.buffer, this._data.byteOffset + endpointsByteOffset, sgd.endpointsByteLength);\r\n sgd.selectorsData = new Uint8Array(this._data.buffer, this._data.byteOffset + selectorsByteOffset, sgd.selectorsByteLength);\r\n sgd.tablesData = new Uint8Array(this._data.buffer, this._data.byteOffset + tablesByteOffset, sgd.tablesByteLength);\r\n sgd.extendedData = new Uint8Array(this._data.buffer, this._data.byteOffset + extendedByteOffset, sgd.extendedByteLength);\r\n }\r\n }\r\n\r\n private _getImageCount(): number {\r\n let layerPixelDepth = Math.max(this._header.pixelDepth, 1);\r\n for (let i = 1; i < this._header.levelCount; i++) {\r\n layerPixelDepth += Math.max(this._header.pixelDepth >> i, 1);\r\n }\r\n\r\n return Math.max(this._header.layerCount, 1) * this._header.faceCount * layerPixelDepth;\r\n }\r\n\r\n public get textureFormat(): KTX2.SourceTextureFormat {\r\n return this._dfdBlock.colorModel === DFDModel.UASTC ? KTX2.SourceTextureFormat.UASTC4x4 : KTX2.SourceTextureFormat.ETC1S;\r\n }\r\n\r\n public get hasAlpha(): boolean {\r\n const tformat = this.textureFormat;\r\n\r\n switch (tformat) {\r\n case KTX2.SourceTextureFormat.ETC1S:\r\n return (\r\n this._dfdBlock.numSamples === 2 &&\r\n (this._dfdBlock.samples[0].channelType === DFDChannel_ETC1S.AAA || this._dfdBlock.samples[1].channelType === DFDChannel_ETC1S.AAA)\r\n );\r\n\r\n case KTX2.SourceTextureFormat.UASTC4x4:\r\n return this._dfdBlock.samples[0].channelType === DFDChannel_UASTC.RGBA;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n public get needZSTDDecoder(): boolean {\r\n return this._header.supercompressionScheme === SupercompressionScheme.ZStandard;\r\n }\r\n\r\n public get isInGammaSpace(): boolean {\r\n return this._dfdBlock.transferFunction === DFDTransferFunction.sRGB;\r\n }\r\n\r\n public static IsValid(data: ArrayBufferView): boolean {\r\n if (data.byteLength >= 12) {\r\n // '«', 'K', 'T', 'X', ' ', '2', '0', '»', '\\r', '\\n', '\\x1A', '\\n'\r\n const identifier = new Uint8Array(data.buffer, data.byteOffset, 12);\r\n if (\r\n identifier[0] === 0xab &&\r\n identifier[1] === 0x4b &&\r\n identifier[2] === 0x54 &&\r\n identifier[3] === 0x58 &&\r\n identifier[4] === 0x20 &&\r\n identifier[5] === 0x32 &&\r\n identifier[6] === 0x30 &&\r\n identifier[7] === 0xbb &&\r\n identifier[8] === 0x0d &&\r\n identifier[9] === 0x0a &&\r\n identifier[10] === 0x1a &&\r\n identifier[11] === 0x0a\r\n ) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n}\r\n"]}
|
1
|
+
{"version":3,"file":"ktx2FileReader.js","sourceRoot":"","sources":["../../../tools/ktx2Decoder/src/ktx2FileReader.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,OAAO,KAAK,IAAI,+DAAiD;AAEjE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,gBAAgB;AAChB,MAAM,CAAN,IAAY,sBAKX;AALD,WAAY,sBAAsB;IAC9B,mEAAQ,CAAA;IACR,yEAAW,CAAA;IACX,6EAAa,CAAA;IACb,mEAAQ,CAAA;AACZ,CAAC,EALW,sBAAsB,KAAtB,sBAAsB,QAKjC;AAED,IAAW,QAGV;AAHD,WAAW,QAAQ;IACf,2CAAW,CAAA;IACX,2CAAW,CAAA;AACf,CAAC,EAHU,QAAQ,KAAR,QAAQ,QAGlB;AAED,IAAW,gBAKV;AALD,WAAW,gBAAgB;IACvB,qDAAO,CAAA;IACP,qDAAO,CAAA;IACP,qDAAO,CAAA;IACP,sDAAQ,CAAA;AACZ,CAAC,EALU,gBAAgB,KAAhB,gBAAgB,QAK1B;AAED,IAAW,gBAKV;AALD,WAAW,gBAAgB;IACvB,qDAAO,CAAA;IACP,uDAAQ,CAAA;IACR,qDAAO,CAAA;IACP,uDAAQ,CAAA;AACZ,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ACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,EAAE,CAAC,KAAK,IAAI;gBACvB,UAAU,CAAC,EAAE,CAAC,KAAK,IAAI,EACzB,CAAC;gBACC,OAAO,IAAI,CAAC;YAChB,CAAC;QACL,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport * as KTX2 from \"core/Materials/Textures/ktx2decoderTypes\";\r\n\r\nimport { DataReader } from \"./Misc/dataReader\";\r\n\r\n/** @internal */\r\nexport enum SupercompressionScheme {\r\n None = 0,\r\n BasisLZ = 1,\r\n ZStandard = 2,\r\n ZLib = 3,\r\n}\r\n\r\nconst enum DFDModel {\r\n ETC1S = 163,\r\n UASTC = 166,\r\n}\r\n\r\nconst enum DFDChannel_ETC1S {\r\n RGB = 0,\r\n RRR = 3,\r\n GGG = 4,\r\n AAA = 15,\r\n}\r\n\r\nconst enum DFDChannel_UASTC {\r\n RGB = 0,\r\n RGBA = 3,\r\n RRR = 4,\r\n RRRG = 5,\r\n}\r\n\r\nconst enum DFDTransferFunction {\r\n linear = 1,\r\n sRGB = 2,\r\n}\r\n\r\n/** @internal */\r\nexport interface IKTX2_Header {\r\n vkFormat: number;\r\n typeSize: number;\r\n pixelWidth: number;\r\n pixelHeight: number;\r\n pixelDepth: number;\r\n layerCount: number;\r\n faceCount: number;\r\n levelCount: number;\r\n supercompressionScheme: number;\r\n dfdByteOffset: number;\r\n dfdByteLength: number;\r\n kvdByteOffset: number;\r\n kvdByteLength: number;\r\n sgdByteOffset: number;\r\n sgdByteLength: number;\r\n}\r\n\r\n/** @internal */\r\nexport interface IKTX2_Level {\r\n byteOffset: number;\r\n byteLength: number;\r\n uncompressedByteLength: number;\r\n}\r\n\r\ninterface IKTX2_Sample {\r\n bitOffset: number;\r\n bitLength: number;\r\n channelType: number;\r\n channelFlags: number;\r\n samplePosition: number[];\r\n sampleLower: number;\r\n sampleUpper: number;\r\n}\r\n\r\n/** @internal */\r\nexport interface IKTX2_DFD {\r\n vendorId: number;\r\n descriptorType: number;\r\n versionNumber: number;\r\n descriptorBlockSize: number;\r\n colorModel: number;\r\n colorPrimaries: number;\r\n transferFunction: number;\r\n flags: number;\r\n texelBlockDimension: {\r\n x: number;\r\n y: number;\r\n z: number;\r\n w: number;\r\n };\r\n bytesPlane: Array<number>;\r\n numSamples: number;\r\n samples: Array<IKTX2_Sample>;\r\n}\r\n\r\n/** @internal */\r\nexport interface IKTX2_ImageDesc {\r\n imageFlags: number;\r\n rgbSliceByteOffset: number;\r\n rgbSliceByteLength: number;\r\n alphaSliceByteOffset: number;\r\n alphaSliceByteLength: number;\r\n}\r\n\r\n/** @internal */\r\nexport interface IKTX2_SupercompressionGlobalData {\r\n endpointCount?: number;\r\n selectorCount?: number;\r\n endpointsByteLength?: number;\r\n selectorsByteLength?: number;\r\n tablesByteLength?: number;\r\n extendedByteLength?: number;\r\n imageDescs?: Array<IKTX2_ImageDesc>;\r\n endpointsData?: Uint8Array;\r\n selectorsData?: Uint8Array;\r\n tablesData?: Uint8Array;\r\n extendedData?: Uint8Array;\r\n}\r\n\r\nexport class KTX2FileReader {\r\n private _data: Uint8Array;\r\n private _header: IKTX2_Header;\r\n private _levels: Array<IKTX2_Level>;\r\n private _dfdBlock: IKTX2_DFD;\r\n private _supercompressionGlobalData: IKTX2_SupercompressionGlobalData;\r\n\r\n /**\r\n * Will throw an exception if the file can't be parsed\r\n * @param data\r\n */\r\n constructor(data: Uint8Array) {\r\n this._data = data;\r\n }\r\n\r\n public get data(): Uint8Array {\r\n return this._data;\r\n }\r\n\r\n public get header(): IKTX2_Header {\r\n return this._header;\r\n }\r\n\r\n public get levels(): Array<IKTX2_Level> {\r\n return this._levels;\r\n }\r\n\r\n public get dfdBlock(): IKTX2_DFD {\r\n return this._dfdBlock;\r\n }\r\n\r\n public get supercompressionGlobalData(): IKTX2_SupercompressionGlobalData {\r\n return this._supercompressionGlobalData;\r\n }\r\n\r\n public isValid() {\r\n return KTX2FileReader.IsValid(this._data);\r\n }\r\n\r\n public parse() {\r\n let offsetInFile = 12; // skip the header\r\n\r\n /**\r\n * Get the header\r\n */\r\n const hdrReader = new DataReader(this._data, offsetInFile, 17 * 4);\r\n\r\n const header = (this._header = {\r\n vkFormat: hdrReader.readUint32(),\r\n typeSize: hdrReader.readUint32(),\r\n pixelWidth: hdrReader.readUint32(),\r\n pixelHeight: hdrReader.readUint32(),\r\n pixelDepth: hdrReader.readUint32(),\r\n layerCount: hdrReader.readUint32(),\r\n faceCount: hdrReader.readUint32(),\r\n levelCount: hdrReader.readUint32(),\r\n supercompressionScheme: hdrReader.readUint32(),\r\n\r\n dfdByteOffset: hdrReader.readUint32(),\r\n dfdByteLength: hdrReader.readUint32(),\r\n kvdByteOffset: hdrReader.readUint32(),\r\n kvdByteLength: hdrReader.readUint32(),\r\n sgdByteOffset: hdrReader.readUint64(),\r\n sgdByteLength: hdrReader.readUint64(),\r\n });\r\n\r\n if (header.pixelDepth > 0) {\r\n throw new Error(`Failed to parse KTX2 file - Only 2D textures are currently supported.`);\r\n }\r\n\r\n if (header.layerCount > 1) {\r\n throw new Error(`Failed to parse KTX2 file - Array textures are not currently supported.`);\r\n }\r\n\r\n if (header.faceCount > 1) {\r\n throw new Error(`Failed to parse KTX2 file - Cube textures are not currently supported.`);\r\n }\r\n\r\n offsetInFile += hdrReader.byteOffset;\r\n\r\n /**\r\n * Get the levels\r\n */\r\n let levelCount = Math.max(1, header.levelCount);\r\n\r\n const levelReader = new DataReader(this._data, offsetInFile, levelCount * 3 * (2 * 4));\r\n\r\n const levels: Array<IKTX2_Level> = (this._levels = []);\r\n\r\n while (levelCount--) {\r\n levels.push({\r\n byteOffset: levelReader.readUint64(),\r\n byteLength: levelReader.readUint64(),\r\n uncompressedByteLength: levelReader.readUint64(),\r\n });\r\n }\r\n\r\n offsetInFile += levelReader.byteOffset;\r\n\r\n /**\r\n * Get the data format descriptor (DFD) blocks\r\n */\r\n const dfdReader = new DataReader(this._data, header.dfdByteOffset, header.dfdByteLength);\r\n\r\n const dfdBlock = (this._dfdBlock = {\r\n vendorId: dfdReader.skipBytes(4 /* skip totalSize */).readUint16(),\r\n descriptorType: dfdReader.readUint16(),\r\n versionNumber: dfdReader.readUint16(),\r\n descriptorBlockSize: dfdReader.readUint16(),\r\n colorModel: dfdReader.readUint8(),\r\n colorPrimaries: dfdReader.readUint8(),\r\n transferFunction: dfdReader.readUint8(),\r\n flags: dfdReader.readUint8(),\r\n texelBlockDimension: {\r\n x: dfdReader.readUint8() + 1,\r\n y: dfdReader.readUint8() + 1,\r\n z: dfdReader.readUint8() + 1,\r\n w: dfdReader.readUint8() + 1,\r\n },\r\n bytesPlane: [\r\n dfdReader.readUint8() /* bytesPlane0 */,\r\n dfdReader.readUint8() /* bytesPlane1 */,\r\n dfdReader.readUint8() /* bytesPlane2 */,\r\n dfdReader.readUint8() /* bytesPlane3 */,\r\n dfdReader.readUint8() /* bytesPlane4 */,\r\n dfdReader.readUint8() /* bytesPlane5 */,\r\n dfdReader.readUint8() /* bytesPlane6 */,\r\n dfdReader.readUint8() /* bytesPlane7 */,\r\n ],\r\n numSamples: 0,\r\n samples: new Array<IKTX2_Sample>(),\r\n });\r\n\r\n dfdBlock.numSamples = (dfdBlock.descriptorBlockSize - 24) / 16;\r\n\r\n for (let i = 0; i < dfdBlock.numSamples; i++) {\r\n const sample = {\r\n bitOffset: dfdReader.readUint16(),\r\n bitLength: dfdReader.readUint8() + 1,\r\n channelType: dfdReader.readUint8(),\r\n channelFlags: 0,\r\n samplePosition: [\r\n dfdReader.readUint8() /* samplePosition0 */,\r\n dfdReader.readUint8() /* samplePosition1 */,\r\n dfdReader.readUint8() /* samplePosition2 */,\r\n dfdReader.readUint8() /* samplePosition3 */,\r\n ],\r\n sampleLower: dfdReader.readUint32(),\r\n sampleUpper: dfdReader.readUint32(),\r\n };\r\n\r\n sample.channelFlags = (sample.channelType & 0xf0) >> 4;\r\n sample.channelType = sample.channelType & 0x0f;\r\n\r\n dfdBlock.samples.push(sample);\r\n }\r\n\r\n /**\r\n * Get the Supercompression Global Data (sgd)\r\n */\r\n const sgd: IKTX2_SupercompressionGlobalData = (this._supercompressionGlobalData = {});\r\n\r\n if (header.sgdByteLength > 0) {\r\n const sgdReader = new DataReader(this._data, header.sgdByteOffset, header.sgdByteLength);\r\n\r\n sgd.endpointCount = sgdReader.readUint16();\r\n sgd.selectorCount = sgdReader.readUint16();\r\n sgd.endpointsByteLength = sgdReader.readUint32();\r\n sgd.selectorsByteLength = sgdReader.readUint32();\r\n sgd.tablesByteLength = sgdReader.readUint32();\r\n sgd.extendedByteLength = sgdReader.readUint32();\r\n sgd.imageDescs = [];\r\n\r\n const imageCount = this._getImageCount();\r\n\r\n for (let i = 0; i < imageCount; i++) {\r\n sgd.imageDescs.push({\r\n imageFlags: sgdReader.readUint32(),\r\n rgbSliceByteOffset: sgdReader.readUint32(),\r\n rgbSliceByteLength: sgdReader.readUint32(),\r\n alphaSliceByteOffset: sgdReader.readUint32(),\r\n alphaSliceByteLength: sgdReader.readUint32(),\r\n });\r\n }\r\n\r\n const endpointsByteOffset = header.sgdByteOffset + sgdReader.byteOffset;\r\n const selectorsByteOffset = endpointsByteOffset + sgd.endpointsByteLength;\r\n const tablesByteOffset = selectorsByteOffset + sgd.selectorsByteLength;\r\n const extendedByteOffset = tablesByteOffset + sgd.tablesByteLength;\r\n\r\n sgd.endpointsData = new Uint8Array(this._data.buffer, this._data.byteOffset + endpointsByteOffset, sgd.endpointsByteLength);\r\n sgd.selectorsData = new Uint8Array(this._data.buffer, this._data.byteOffset + selectorsByteOffset, sgd.selectorsByteLength);\r\n sgd.tablesData = new Uint8Array(this._data.buffer, this._data.byteOffset + tablesByteOffset, sgd.tablesByteLength);\r\n sgd.extendedData = new Uint8Array(this._data.buffer, this._data.byteOffset + extendedByteOffset, sgd.extendedByteLength);\r\n }\r\n }\r\n\r\n private _getImageCount(): number {\r\n let layerPixelDepth = Math.max(this._header.pixelDepth, 1);\r\n for (let i = 1; i < this._header.levelCount; i++) {\r\n layerPixelDepth += Math.max(this._header.pixelDepth >> i, 1);\r\n }\r\n\r\n return Math.max(this._header.layerCount, 1) * this._header.faceCount * layerPixelDepth;\r\n }\r\n\r\n public get textureFormat(): KTX2.SourceTextureFormat {\r\n return this._dfdBlock.colorModel === DFDModel.UASTC ? KTX2.SourceTextureFormat.UASTC4x4 : KTX2.SourceTextureFormat.ETC1S;\r\n }\r\n\r\n public get hasAlpha(): boolean {\r\n const tformat = this.textureFormat;\r\n\r\n switch (tformat) {\r\n case KTX2.SourceTextureFormat.ETC1S:\r\n return (\r\n this._dfdBlock.numSamples === 2 &&\r\n (this._dfdBlock.samples[0].channelType === DFDChannel_ETC1S.AAA || this._dfdBlock.samples[1].channelType === DFDChannel_ETC1S.AAA)\r\n );\r\n\r\n case KTX2.SourceTextureFormat.UASTC4x4:\r\n return this._dfdBlock.samples[0].channelType === DFDChannel_UASTC.RGBA;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n public get needZSTDDecoder(): boolean {\r\n return this._header.supercompressionScheme === SupercompressionScheme.ZStandard;\r\n }\r\n\r\n public get isInGammaSpace(): boolean {\r\n return this._dfdBlock.transferFunction === DFDTransferFunction.sRGB;\r\n }\r\n\r\n public static IsValid(data: ArrayBufferView): boolean {\r\n if (data.byteLength >= 12) {\r\n // '«', 'K', 'T', 'X', ' ', '2', '0', '»', '\\r', '\\n', '\\x1A', '\\n'\r\n const identifier = new Uint8Array(data.buffer, data.byteOffset, 12);\r\n if (\r\n identifier[0] === 0xab &&\r\n identifier[1] === 0x4b &&\r\n identifier[2] === 0x54 &&\r\n identifier[3] === 0x58 &&\r\n identifier[4] === 0x20 &&\r\n identifier[5] === 0x32 &&\r\n identifier[6] === 0x30 &&\r\n identifier[7] === 0xbb &&\r\n identifier[8] === 0x0d &&\r\n identifier[9] === 0x0a &&\r\n identifier[10] === 0x1a &&\r\n identifier[11] === 0x0a\r\n ) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n}\r\n"]}
|
package/legacy/legacy.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"legacy.js","sourceRoot":"","sources":["../../../../tools/ktx2Decoder/src/legacy/legacy.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,YAAY,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACjH,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE;
|
1
|
+
{"version":3,"file":"legacy.js","sourceRoot":"","sources":["../../../../tools/ktx2Decoder/src/legacy/legacy.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,YAAY,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACjH,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE,CAAC;IAChC,YAAa,CAAC,WAAW,GAAG,WAAW,CAAC;AAClD,CAAC;AAED,cAAc,UAAU,CAAC","sourcesContent":["/* eslint-disable import/no-internal-modules */\r\nimport { KTX2Decoder } from \"../index\";\r\n\r\nconst globalObject = typeof global !== \"undefined\" ? global : typeof window !== \"undefined\" ? window : undefined;\r\nif (typeof globalObject !== \"undefined\") {\r\n (<any>globalObject).KTX2DECODER = KTX2Decoder;\r\n}\r\n\r\nexport * from \"../index\";\r\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@babylonjs/ktx2decoder",
|
3
|
-
"version": "7.
|
3
|
+
"version": "7.35.0",
|
4
4
|
"main": "index.js",
|
5
5
|
"module": "index.js",
|
6
6
|
"types": "index.d.ts",
|
@@ -19,7 +19,7 @@
|
|
19
19
|
"postcompile": "build-tools -c add-js-to-es6 && build-tools -c cp -f \"../../../tools/babylonServer/public/ktx2Transcoders/1\" -t ./wasm"
|
20
20
|
},
|
21
21
|
"devDependencies": {
|
22
|
-
"@babylonjs/core": "^7.
|
22
|
+
"@babylonjs/core": "^7.35.0",
|
23
23
|
"@dev/build-tools": "^1.0.0",
|
24
24
|
"@tools/ktx2decoder": "^1.0.0"
|
25
25
|
},
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transcodeDecisionTree.js","sourceRoot":"","sources":["../../../tools/ktx2Decoder/src/transcodeDecisionTree.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,OAAO,KAAK,IAAI,+DAAiD;AAEjE,MAAM,YAAY,GAAuB;IACrC,KAAK,EAAE;QACH,MAAM,EAAE,WAAW;QACnB,GAAG,EAAE;YACD,eAAe,EAAE,IAAI,CAAC,eAAe,CAAC,MAAM;YAC5C,YAAY,2CAA+B;YAC3C,gBAAgB,EAAE,KAAK;SAC1B;QACD,EAAE,EAAE;YACA,GAAG,EAAE,MAAM;YACX,GAAG,EAAE;gBACD,KAAK,EAAE,IAAI;gBACX,GAAG,EAAE;oBACD,eAAe,EAAE,IAAI,CAAC,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KAAK,SAAS,EAAE;gBAC3B,SAAS,GAAG,SAAS,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAoC,CAAC,CAAC;aACvF;YACD,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;gBAC1B,SAAS,GAAG,SAAS,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,KAAK,CAAC;aAC1D;YACD,IAAI,IAAI,CAAC,eAAe,KAAK,SAAS,EAAE;gBACpC,SAAS,GAAG,SAAS,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI,CAAC,eAAe,CAAC;aACxE;YACD,IAAI,IAAI,CAAC,eAAe,KAAK,SAAS,EAAE;gBACpC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE;oBACrC,SAAS,GAAG,SAAS,IAAI,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC;iBACvF;qBAAM;oBACH,SAAS,GAAG,SAAS,IAAI,IAAI,CAAC,eAAe,KAAK,IAAI,CAAC,gBAAgB,CAAC;iBAC3E;aACJ;YAED,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAI,CAAC,CAAC,CAAC,IAAI,CAAC,EAAG,CAAC,CAAC;SACrD;IACL,CAAC;CACJ","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport * as KTX2 from \"core/Materials/Textures/ktx2decoderTypes\";\r\n\r\nconst DecisionTree: KTX2.IDecisionTree = {\r\n ETC1S: {\r\n option: \"forceRGBA\",\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.RGBA32,\r\n engineFormat: KTX2.EngineFormat.RGBA8Format,\r\n roundToMultiple4: false,\r\n },\r\n no: {\r\n cap: \"etc2\",\r\n yes: {\r\n alpha: true,\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.ETC2_RGBA,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA8_ETC2_EAC,\r\n },\r\n no: {\r\n transcodeFormat: KTX2.TranscodeTarget.ETC1_RGB,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGB8_ETC2,\r\n },\r\n },\r\n no: {\r\n cap: \"etc1\",\r\n alpha: false,\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.ETC1_RGB,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGB_ETC1_WEBGL,\r\n },\r\n no: {\r\n cap: \"bptc\",\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.BC7_RGBA,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_BPTC_UNORM_EXT,\r\n },\r\n no: {\r\n cap: \"s3tc\",\r\n yes: {\r\n alpha: true,\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.BC3_RGBA,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_S3TC_DXT5_EXT,\r\n },\r\n no: {\r\n transcodeFormat: KTX2.TranscodeTarget.BC1_RGB,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGB_S3TC_DXT1_EXT,\r\n },\r\n },\r\n no: {\r\n cap: \"pvrtc\",\r\n needsPowerOfTwo: true,\r\n yes: {\r\n alpha: true,\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.PVRTC1_4_RGBA,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,\r\n },\r\n no: {\r\n transcodeFormat: KTX2.TranscodeTarget.PVRTC1_4_RGB,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGB_PVRTC_4BPPV1_IMG,\r\n },\r\n },\r\n no: {\r\n transcodeFormat: KTX2.TranscodeTarget.RGBA32,\r\n engineFormat: KTX2.EngineFormat.RGBA8Format,\r\n roundToMultiple4: false,\r\n },\r\n },\r\n },\r\n },\r\n },\r\n },\r\n },\r\n\r\n UASTC: {\r\n option: \"forceRGBA\",\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.RGBA32,\r\n engineFormat: KTX2.EngineFormat.RGBA8Format,\r\n roundToMultiple4: false,\r\n },\r\n no: {\r\n option: \"forceR8\",\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.R8,\r\n engineFormat: KTX2.EngineFormat.R8Format,\r\n roundToMultiple4: false,\r\n },\r\n no: {\r\n option: \"forceRG8\",\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.RG8,\r\n engineFormat: KTX2.EngineFormat.RG8Format,\r\n roundToMultiple4: false,\r\n },\r\n no: {\r\n cap: \"astc\",\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.ASTC_4X4_RGBA,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_ASTC_4X4_KHR,\r\n },\r\n no: {\r\n cap: \"bptc\",\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.BC7_RGBA,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_BPTC_UNORM_EXT,\r\n },\r\n no: {\r\n option: \"useRGBAIfASTCBC7NotAvailableWhenUASTC\",\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.RGBA32,\r\n engineFormat: KTX2.EngineFormat.RGBA8Format,\r\n roundToMultiple4: false,\r\n },\r\n no: {\r\n cap: \"etc2\",\r\n yes: {\r\n alpha: true,\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.ETC2_RGBA,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA8_ETC2_EAC,\r\n },\r\n no: {\r\n transcodeFormat: KTX2.TranscodeTarget.ETC1_RGB,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGB8_ETC2,\r\n },\r\n },\r\n no: {\r\n cap: \"etc1\",\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.ETC1_RGB,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGB_ETC1_WEBGL,\r\n },\r\n no: {\r\n cap: \"s3tc\",\r\n yes: {\r\n alpha: true,\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.BC3_RGBA,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_S3TC_DXT5_EXT,\r\n },\r\n no: {\r\n transcodeFormat: KTX2.TranscodeTarget.BC1_RGB,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGB_S3TC_DXT1_EXT,\r\n },\r\n },\r\n no: {\r\n cap: \"pvrtc\",\r\n needsPowerOfTwo: true,\r\n yes: {\r\n alpha: true,\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.PVRTC1_4_RGBA,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,\r\n },\r\n no: {\r\n transcodeFormat: KTX2.TranscodeTarget.PVRTC1_4_RGB,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGB_PVRTC_4BPPV1_IMG,\r\n },\r\n },\r\n no: {\r\n transcodeFormat: KTX2.TranscodeTarget.RGBA32,\r\n engineFormat: KTX2.EngineFormat.RGBA8Format,\r\n roundToMultiple4: false,\r\n },\r\n },\r\n },\r\n },\r\n },\r\n },\r\n },\r\n },\r\n },\r\n },\r\n },\r\n};\r\n\r\nexport class TranscodeDecisionTree {\r\n private static _IsLeafNode(node: KTX2.INode | KTX2.ILeaf): node is KTX2.ILeaf {\r\n return (node as KTX2.ILeaf).engineFormat !== undefined;\r\n }\r\n\r\n private _textureFormat: KTX2.SourceTextureFormat;\r\n private _hasAlpha: boolean;\r\n private _isPowerOfTwo: boolean;\r\n private _caps: KTX2.ICompressedFormatCapabilities;\r\n private _options: KTX2.IKTX2DecoderOptions;\r\n private _transcodeFormat: number;\r\n private _engineFormat: number;\r\n private _roundToMultiple4: boolean;\r\n\r\n public get transcodeFormat() {\r\n return this._transcodeFormat;\r\n }\r\n\r\n public get engineFormat() {\r\n return this._engineFormat;\r\n }\r\n\r\n public get roundToMultiple4() {\r\n return this._roundToMultiple4;\r\n }\r\n\r\n constructor(textureFormat: KTX2.SourceTextureFormat, hasAlpha: boolean, isPowerOfTwo: boolean, caps: KTX2.ICompressedFormatCapabilities, options?: KTX2.IKTX2DecoderOptions) {\r\n this._textureFormat = textureFormat;\r\n this._hasAlpha = hasAlpha;\r\n this._isPowerOfTwo = isPowerOfTwo;\r\n this._caps = caps;\r\n this._options = options ?? {};\r\n\r\n this.parseTree(DecisionTree);\r\n }\r\n\r\n public parseTree(tree: KTX2.IDecisionTree): boolean {\r\n const node = this._textureFormat === KTX2.SourceTextureFormat.UASTC4x4 ? tree.UASTC : tree.ETC1S;\r\n if (node) {\r\n this._parseNode(node);\r\n }\r\n return node !== undefined;\r\n }\r\n\r\n private _parseNode(node: KTX2.INode | KTX2.ILeaf | undefined): void {\r\n if (!node) {\r\n return;\r\n }\r\n\r\n if (TranscodeDecisionTree._IsLeafNode(node)) {\r\n this._transcodeFormat = node.transcodeFormat;\r\n this._engineFormat = node.engineFormat;\r\n this._roundToMultiple4 = node.roundToMultiple4 ?? true;\r\n } else {\r\n let condition = true;\r\n\r\n if (node.cap !== undefined) {\r\n condition = condition && !!this._caps[node.cap as keyof typeof this._caps];\r\n }\r\n if (node.option !== undefined) {\r\n condition = condition && !!this._options[node.option as keyof typeof this._options];\r\n }\r\n if (node.alpha !== undefined) {\r\n condition = condition && this._hasAlpha === node.alpha;\r\n }\r\n if (node.needsPowerOfTwo !== undefined) {\r\n condition = condition && this._isPowerOfTwo === node.needsPowerOfTwo;\r\n }\r\n if (node.transcodeFormat !== undefined) {\r\n if (Array.isArray(node.transcodeFormat)) {\r\n condition = condition && node.transcodeFormat.indexOf(this._transcodeFormat) !== -1;\r\n } else {\r\n condition = condition && node.transcodeFormat === this._transcodeFormat;\r\n }\r\n }\r\n\r\n this._parseNode(condition ? node.yes! : node.no!);\r\n }\r\n }\r\n}\r\n"]}
|
1
|
+
{"version":3,"file":"transcodeDecisionTree.js","sourceRoot":"","sources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AAI,CAAC,gBAAgB,CAAC;gBAC5E,CAAC;YACL,CAAC;YAED,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAI,CAAC,CAAC,CAAC,IAAI,CAAC,EAAG,CAAC,CAAC;QACtD,CAAC;IACL,CAAC;CACJ","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport * as KTX2 from \"core/Materials/Textures/ktx2decoderTypes\";\r\n\r\nconst DecisionTree: KTX2.IDecisionTree = {\r\n ETC1S: {\r\n option: \"forceRGBA\",\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.RGBA32,\r\n engineFormat: KTX2.EngineFormat.RGBA8Format,\r\n roundToMultiple4: false,\r\n },\r\n no: {\r\n cap: \"etc2\",\r\n yes: {\r\n alpha: true,\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.ETC2_RGBA,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA8_ETC2_EAC,\r\n },\r\n no: {\r\n transcodeFormat: KTX2.TranscodeTarget.ETC1_RGB,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGB8_ETC2,\r\n },\r\n },\r\n no: {\r\n cap: \"etc1\",\r\n alpha: false,\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.ETC1_RGB,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGB_ETC1_WEBGL,\r\n },\r\n no: {\r\n cap: \"bptc\",\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.BC7_RGBA,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_BPTC_UNORM_EXT,\r\n },\r\n no: {\r\n cap: \"s3tc\",\r\n yes: {\r\n alpha: true,\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.BC3_RGBA,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_S3TC_DXT5_EXT,\r\n },\r\n no: {\r\n transcodeFormat: KTX2.TranscodeTarget.BC1_RGB,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGB_S3TC_DXT1_EXT,\r\n },\r\n },\r\n no: {\r\n cap: \"pvrtc\",\r\n needsPowerOfTwo: true,\r\n yes: {\r\n alpha: true,\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.PVRTC1_4_RGBA,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,\r\n },\r\n no: {\r\n transcodeFormat: KTX2.TranscodeTarget.PVRTC1_4_RGB,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGB_PVRTC_4BPPV1_IMG,\r\n },\r\n },\r\n no: {\r\n transcodeFormat: KTX2.TranscodeTarget.RGBA32,\r\n engineFormat: KTX2.EngineFormat.RGBA8Format,\r\n roundToMultiple4: false,\r\n },\r\n },\r\n },\r\n },\r\n },\r\n },\r\n },\r\n\r\n UASTC: {\r\n option: \"forceRGBA\",\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.RGBA32,\r\n engineFormat: KTX2.EngineFormat.RGBA8Format,\r\n roundToMultiple4: false,\r\n },\r\n no: {\r\n option: \"forceR8\",\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.R8,\r\n engineFormat: KTX2.EngineFormat.R8Format,\r\n roundToMultiple4: false,\r\n },\r\n no: {\r\n option: \"forceRG8\",\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.RG8,\r\n engineFormat: KTX2.EngineFormat.RG8Format,\r\n roundToMultiple4: false,\r\n },\r\n no: {\r\n cap: \"astc\",\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.ASTC_4X4_RGBA,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_ASTC_4X4_KHR,\r\n },\r\n no: {\r\n cap: \"bptc\",\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.BC7_RGBA,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_BPTC_UNORM_EXT,\r\n },\r\n no: {\r\n option: \"useRGBAIfASTCBC7NotAvailableWhenUASTC\",\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.RGBA32,\r\n engineFormat: KTX2.EngineFormat.RGBA8Format,\r\n roundToMultiple4: false,\r\n },\r\n no: {\r\n cap: \"etc2\",\r\n yes: {\r\n alpha: true,\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.ETC2_RGBA,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA8_ETC2_EAC,\r\n },\r\n no: {\r\n transcodeFormat: KTX2.TranscodeTarget.ETC1_RGB,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGB8_ETC2,\r\n },\r\n },\r\n no: {\r\n cap: \"etc1\",\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.ETC1_RGB,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGB_ETC1_WEBGL,\r\n },\r\n no: {\r\n cap: \"s3tc\",\r\n yes: {\r\n alpha: true,\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.BC3_RGBA,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_S3TC_DXT5_EXT,\r\n },\r\n no: {\r\n transcodeFormat: KTX2.TranscodeTarget.BC1_RGB,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGB_S3TC_DXT1_EXT,\r\n },\r\n },\r\n no: {\r\n cap: \"pvrtc\",\r\n needsPowerOfTwo: true,\r\n yes: {\r\n alpha: true,\r\n yes: {\r\n transcodeFormat: KTX2.TranscodeTarget.PVRTC1_4_RGBA,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,\r\n },\r\n no: {\r\n transcodeFormat: KTX2.TranscodeTarget.PVRTC1_4_RGB,\r\n engineFormat: KTX2.EngineFormat.COMPRESSED_RGB_PVRTC_4BPPV1_IMG,\r\n },\r\n },\r\n no: {\r\n transcodeFormat: KTX2.TranscodeTarget.RGBA32,\r\n engineFormat: KTX2.EngineFormat.RGBA8Format,\r\n roundToMultiple4: false,\r\n },\r\n },\r\n },\r\n },\r\n },\r\n },\r\n },\r\n },\r\n },\r\n },\r\n },\r\n};\r\n\r\nexport class TranscodeDecisionTree {\r\n private static _IsLeafNode(node: KTX2.INode | KTX2.ILeaf): node is KTX2.ILeaf {\r\n return (node as KTX2.ILeaf).engineFormat !== undefined;\r\n }\r\n\r\n private _textureFormat: KTX2.SourceTextureFormat;\r\n private _hasAlpha: boolean;\r\n private _isPowerOfTwo: boolean;\r\n private _caps: KTX2.ICompressedFormatCapabilities;\r\n private _options: KTX2.IKTX2DecoderOptions;\r\n private _transcodeFormat: number;\r\n private _engineFormat: number;\r\n private _roundToMultiple4: boolean;\r\n\r\n public get transcodeFormat() {\r\n return this._transcodeFormat;\r\n }\r\n\r\n public get engineFormat() {\r\n return this._engineFormat;\r\n }\r\n\r\n public get roundToMultiple4() {\r\n return this._roundToMultiple4;\r\n }\r\n\r\n constructor(textureFormat: KTX2.SourceTextureFormat, hasAlpha: boolean, isPowerOfTwo: boolean, caps: KTX2.ICompressedFormatCapabilities, options?: KTX2.IKTX2DecoderOptions) {\r\n this._textureFormat = textureFormat;\r\n this._hasAlpha = hasAlpha;\r\n this._isPowerOfTwo = isPowerOfTwo;\r\n this._caps = caps;\r\n this._options = options ?? {};\r\n\r\n this.parseTree(DecisionTree);\r\n }\r\n\r\n public parseTree(tree: KTX2.IDecisionTree): boolean {\r\n const node = this._textureFormat === KTX2.SourceTextureFormat.UASTC4x4 ? tree.UASTC : tree.ETC1S;\r\n if (node) {\r\n this._parseNode(node);\r\n }\r\n return node !== undefined;\r\n }\r\n\r\n private _parseNode(node: KTX2.INode | KTX2.ILeaf | undefined): void {\r\n if (!node) {\r\n return;\r\n }\r\n\r\n if (TranscodeDecisionTree._IsLeafNode(node)) {\r\n this._transcodeFormat = node.transcodeFormat;\r\n this._engineFormat = node.engineFormat;\r\n this._roundToMultiple4 = node.roundToMultiple4 ?? true;\r\n } else {\r\n let condition = true;\r\n\r\n if (node.cap !== undefined) {\r\n condition = condition && !!this._caps[node.cap as keyof typeof this._caps];\r\n }\r\n if (node.option !== undefined) {\r\n condition = condition && !!this._options[node.option as keyof typeof this._options];\r\n }\r\n if (node.alpha !== undefined) {\r\n condition = condition && this._hasAlpha === node.alpha;\r\n }\r\n if (node.needsPowerOfTwo !== undefined) {\r\n condition = condition && this._isPowerOfTwo === node.needsPowerOfTwo;\r\n }\r\n if (node.transcodeFormat !== undefined) {\r\n if (Array.isArray(node.transcodeFormat)) {\r\n condition = condition && node.transcodeFormat.indexOf(this._transcodeFormat) !== -1;\r\n } else {\r\n condition = condition && node.transcodeFormat === this._transcodeFormat;\r\n }\r\n }\r\n\r\n this._parseNode(condition ? node.yes! : node.no!);\r\n }\r\n }\r\n}\r\n"]}
|
package/transcoder.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transcoder.js","sourceRoot":"","sources":["../../../tools/ktx2Decoder/src/transcoder.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,OAAO,UAAU;IACZ,MAAM,CAAC,YAAY,CAAC,GAA6B,EAAE,GAAyB,EAAE,cAAuB;QACxG,OAAO,KAAK,CAAC;IACjB,CAAC;IAMM,MAAM,CAAC,UAAU,CAAC,OAAe;QACpC,IAAI,UAAU,CAAC,WAAW,IAAI,OAAO,CAAC,UAAU,CAAC,4BAA4B,CAAC,EAAE;
|
1
|
+
{"version":3,"file":"transcoder.js","sourceRoot":"","sources":["../../../tools/ktx2Decoder/src/transcoder.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,OAAO,UAAU;IACZ,MAAM,CAAC,YAAY,CAAC,GAA6B,EAAE,GAAyB,EAAE,cAAuB;QACxG,OAAO,KAAK,CAAC;IACjB,CAAC;IAMM,MAAM,CAAC,UAAU,CAAC,OAAe;QACpC,IAAI,UAAU,CAAC,WAAW,IAAI,OAAO,CAAC,UAAU,CAAC,4BAA4B,CAAC,EAAE,CAAC;YAC7E,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,4BAA4B,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;QACpF,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;IAEM,OAAO;QACV,OAAO,UAAU,CAAC,IAAI,CAAC;IAC3B,CAAC;IAEM,UAAU,KAAU,CAAC;IAErB,iBAAiB;QACpB,OAAO,KAAK,CAAC;IACjB,CAAC;IAEM,gBAAgB,CAAC,SAA4B,IAAS,CAAC;IAEvD,SAAS,CACZ,GAA6B,EAC7B,GAAyB,EACzB,KAAa,EACb,KAAa,EACb,MAAc,EACd,sBAA8B,EAC9B,UAA0B,EAC1B,SAAiC,EACjC,WAAuB;QAEvB,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;;AAnCa,eAAI,GAAG,YAAY,CAAC;AAEpB,sBAAW,GAAG,EAAE,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\r\n/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type * as KTX2 from \"core/Materials/Textures/ktx2decoderTypes\";\r\n\r\nimport type { WASMMemoryManager } from \"./wasmMemoryManager\";\r\nimport type { KTX2FileReader, IKTX2_ImageDesc } from \"./ktx2FileReader\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class Transcoder {\r\n public static CanTranscode(src: KTX2.SourceTextureFormat, dst: KTX2.TranscodeTarget, isInGammaSpace: boolean): boolean {\r\n return false;\r\n }\r\n\r\n public static Name = \"Transcoder\";\r\n\r\n public static WasmBaseUrl = \"\";\r\n\r\n public static GetWasmUrl(wasmUrl: string) {\r\n if (Transcoder.WasmBaseUrl && wasmUrl.startsWith(\"https://cdn.babylonjs.com/\")) {\r\n wasmUrl = wasmUrl.replace(\"https://cdn.babylonjs.com/\", Transcoder.WasmBaseUrl);\r\n }\r\n return wasmUrl;\r\n }\r\n\r\n public getName(): string {\r\n return Transcoder.Name;\r\n }\r\n\r\n public initialize(): void {}\r\n\r\n public needMemoryManager(): boolean {\r\n return false;\r\n }\r\n\r\n public setMemoryManager(memoryMgr: WASMMemoryManager): void {}\r\n\r\n public transcode(\r\n src: KTX2.SourceTextureFormat,\r\n dst: KTX2.TranscodeTarget,\r\n level: number,\r\n width: number,\r\n height: number,\r\n uncompressedByteLength: number,\r\n ktx2Reader: KTX2FileReader,\r\n imageDesc: IKTX2_ImageDesc | null,\r\n encodedData: Uint8Array\r\n ): Promise<Uint8Array | null> {\r\n return Promise.resolve(null);\r\n }\r\n}\r\n"]}
|
package/transcoderManager.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transcoderManager.js","sourceRoot":"","sources":["../../../tools/ktx2Decoder/src/transcoderManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,+DAAiD;AAGjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAGnB,MAAM,CAAC,kBAAkB,CAAC,UAA6B;QAC1D,iBAAiB,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC;IAMM,cAAc,CAAC,GAA6B,EAAE,GAAyB,EAAE,cAAuB,EAAE,MAAiB;QACtH,IAAI,UAAU,GAAsB,IAAI,CAAC;QAEzC,MAAM,GAAG,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QAE5E,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,iBAAiB,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;
|
1
|
+
{"version":3,"file":"transcoderManager.js","sourceRoot":"","sources":["../../../tools/ktx2Decoder/src/transcoderManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,+DAAiD;AAGjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAA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AAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;oBAC1D,CAAC;oBACD,IAAI,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,GAAG,CAAC,EAAE,CAAC;wBAC/C,iBAAiB,CAAC,oBAAoB,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;oBACrD,CAAC;oBACD,iBAAiB,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;gBACjE,CAAC;gBACD,MAAM;YACV,CAAC;QACL,CAAC;QAED,OAAO,UAAU,CAAC;IACtB,CAAC;IAEO,sBAAsB,CAAC,GAAW,EAAE,cAAsB;QAC9D,MAAM,WAAW,GAAG,iBAAiB,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;QAEhE,IAAI,WAAW,EAAE,CAAC;YACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;gBAC1C,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;gBAClC,IAAI,cAAc,KAAK,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC;oBAC1C,OAAO,UAAU,CAAC;gBACtB,CAAC;YACL,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;;AApDa,8BAAY,GAA6B,EAAE,CAAC;AAM3C,sCAAoB,GAAyC,EAAE,CAAC","sourcesContent":["import * as KTX2 from \"core/Materials/Textures/ktx2decoderTypes\";\r\n\r\nimport type { Transcoder } from \"./transcoder\";\r\nimport { WASMMemoryManager } from \"./wasmMemoryManager\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class TranscoderManager {\r\n public static _Transcoders: Array<typeof Transcoder> = [];\r\n\r\n public static RegisterTranscoder(transcoder: typeof Transcoder) {\r\n TranscoderManager._Transcoders.push(transcoder);\r\n }\r\n\r\n private static _TranscoderInstances: { [key: string]: Array<Transcoder> } = {};\r\n\r\n private _wasmMemoryManager: WASMMemoryManager;\r\n\r\n public findTranscoder(src: KTX2.SourceTextureFormat, dst: KTX2.TranscodeTarget, isInGammaSpace: boolean, bypass?: string[]): Transcoder | null {\r\n let transcoder: Transcoder | null = null;\r\n\r\n const key = KTX2.SourceTextureFormat[src] + \"_\" + KTX2.TranscodeTarget[dst];\r\n\r\n for (let i = 0; i < TranscoderManager._Transcoders.length; ++i) {\r\n if (TranscoderManager._Transcoders[i].CanTranscode(src, dst, isInGammaSpace) && (!bypass || bypass.indexOf(TranscoderManager._Transcoders[i].Name) < 0)) {\r\n transcoder = this._getExistingTranscoder(key, TranscoderManager._Transcoders[i].Name);\r\n if (!transcoder) {\r\n transcoder = new TranscoderManager._Transcoders[i]();\r\n transcoder!.initialize();\r\n if (transcoder!.needMemoryManager()) {\r\n if (!this._wasmMemoryManager) {\r\n this._wasmMemoryManager = new WASMMemoryManager();\r\n }\r\n transcoder!.setMemoryManager(this._wasmMemoryManager);\r\n }\r\n if (!TranscoderManager._TranscoderInstances[key]) {\r\n TranscoderManager._TranscoderInstances[key] = [];\r\n }\r\n TranscoderManager._TranscoderInstances[key].push(transcoder);\r\n }\r\n break;\r\n }\r\n }\r\n\r\n return transcoder;\r\n }\r\n\r\n private _getExistingTranscoder(key: string, transcoderName: string): Transcoder | null {\r\n const transcoders = TranscoderManager._TranscoderInstances[key];\r\n\r\n if (transcoders) {\r\n for (let t = 0; t < transcoders.length; ++t) {\r\n const transcoder = transcoders[t];\r\n if (transcoderName === transcoder.getName()) {\r\n return transcoder;\r\n }\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n}\r\n"]}
|
package/wasmMemoryManager.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"wasmMemoryManager.js","sourceRoot":"","sources":["../../../tools/ktx2Decoder/src/wasmMemoryManager.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAMnB,MAAM,CAAC,QAAQ,CAAC,IAAY;QA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AI,CAAC,qBAAqB,GAAG,UAAU,CAAC;YACxC,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC;QACpC,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,WAAW,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;YAC3E,IAAI,CAAC,qBAAqB,GAAG,UAAU,CAAC;YACxC,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC;QACpC,CAAC;QAED,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;;AAzEa,+CAA6B,GAAG,IAAI,CAAC;AACrC,oCAAkB,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW;AAExD,4BAAU,GAAG,CAAC,CAAC","sourcesContent":["declare function postMessage(message: any, transfer?: any[]): void;\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class WASMMemoryManager {\r\n public static LoadBinariesFromCurrentThread = true;\r\n public static InitialMemoryPages = (1 * 1024 * 1024) >> 16; // 1 Mbytes\r\n\r\n private static _RequestId = 0;\r\n\r\n public static LoadWASM(path: string): Promise<ArrayBuffer> {\r\n if (this.LoadBinariesFromCurrentThread) {\r\n return new Promise((resolve, reject) => {\r\n fetch(path)\r\n .then((response) => {\r\n if (response.ok) {\r\n return response.arrayBuffer();\r\n }\r\n throw new Error(`Could not fetch the wasm component from \"${path}\": ${response.status} - ${response.statusText}`);\r\n })\r\n .then((wasmBinary) => resolve(wasmBinary))\r\n .catch((reason) => {\r\n reject(reason);\r\n });\r\n });\r\n }\r\n\r\n const id = this._RequestId++;\r\n\r\n return new Promise((resolve) => {\r\n const wasmLoadedHandler = (msg: any) => {\r\n if (msg.data.action === \"wasmLoaded\" && msg.data.id === id) {\r\n self.removeEventListener(\"message\", wasmLoadedHandler);\r\n resolve(msg.data.wasmBinary);\r\n }\r\n };\r\n\r\n self.addEventListener(\"message\", wasmLoadedHandler);\r\n\r\n postMessage({ action: \"loadWASM\", path: path, id: id });\r\n });\r\n }\r\n\r\n private _memory: WebAssembly.Memory;\r\n private _numPages: number;\r\n private _memoryView: Uint8Array;\r\n private _memoryViewByteLength: number;\r\n private _memoryViewOffset: number;\r\n\r\n constructor(initialMemoryPages: number = WASMMemoryManager.InitialMemoryPages) {\r\n this._numPages = initialMemoryPages;\r\n\r\n this._memory = new WebAssembly.Memory({ initial: this._numPages });\r\n this._memoryViewByteLength = this._numPages << 16;\r\n this._memoryViewOffset = 0;\r\n this._memoryView = new Uint8Array(this._memory.buffer, this._memoryViewOffset, this._memoryViewByteLength);\r\n }\r\n\r\n public get wasmMemory(): WebAssembly.Memory {\r\n return this._memory;\r\n }\r\n\r\n public getMemoryView(numPages: number, offset: number = 0, byteLength?: number): Uint8Array {\r\n byteLength = byteLength ?? numPages << 16;\r\n\r\n if (this._numPages < numPages) {\r\n this._memory.grow(numPages - this._numPages);\r\n this._numPages = numPages;\r\n this._memoryView = new Uint8Array(this._memory.buffer, offset, byteLength);\r\n this._memoryViewByteLength = byteLength;\r\n this._memoryViewOffset = offset;\r\n } else {\r\n this._memoryView = new Uint8Array(this._memory.buffer, offset, byteLength);\r\n this._memoryViewByteLength = byteLength;\r\n this._memoryViewOffset = offset;\r\n }\r\n\r\n return this._memoryView;\r\n }\r\n}\r\n"]}
|
package/zstddec.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"zstddec.js","sourceRoot":"","sources":["../../../tools/ktx2Decoder/src/zstddec.ts"],"names":[],"mappings":"AAAA,yDAAyD;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAc1C,IAAI,IAAmB,CAAC;AACxB,IAAI,QAAqC,CAAC;AAC1C,IAAI,IAAgB,CAAC;AAErB,MAAM,aAAa,GAAG;IAClB,GAAG,EAAE;QACD,+BAA+B,EAAE;YAC7B,IAAI,GAAG,IAAI,UAAU,CAAC,QAAQ,CAAC,OA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a,CAAC,CAAC;QACrC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAEvC,OAAO,GAAG,CAAC;IACf,CAAC;;AAvDa,yBAAa,GAAG,wCAAwC,CAAC;AA0D3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\n\r\nimport { Transcoder } from \"./transcoder\";\r\n\r\n/**\r\n * From https://github.com/donmccurdy/zstddec by Don McCurdy\r\n */\r\ninterface DecoderExports {\r\n memory: Uint8Array;\r\n\r\n ZSTD_findDecompressedSize: (compressedPtr: number, compressedSize: number) => number;\r\n ZSTD_decompress: (uncompressedPtr: number, uncompressedSize: number, compressedPtr: number, compressedSize: number) => number;\r\n malloc: (ptr: number) => number;\r\n free: (ptr: number) => void;\r\n}\r\n\r\nlet init: Promise<void>;\r\nlet instance: { exports: DecoderExports };\r\nlet heap: Uint8Array;\r\n\r\nconst IMPORT_OBJECT = {\r\n env: {\r\n emscripten_notify_memory_growth: function (): void {\r\n heap = new Uint8Array(instance.exports.memory.buffer);\r\n },\r\n },\r\n};\r\n\r\n/**\r\n * ZSTD (Zstandard) decoder.\r\n */\r\nexport class ZSTDDecoder {\r\n public static WasmModuleURL = \"https://cdn.babylonjs.com/zstddec.wasm\";\r\n\r\n init(): Promise<void> {\r\n if (init) {\r\n return init;\r\n }\r\n\r\n if (typeof fetch !== \"undefined\") {\r\n // Web.\r\n\r\n init = fetch(Transcoder.GetWasmUrl(ZSTDDecoder.WasmModuleURL))\r\n .then((response) => {\r\n if (response.ok) {\r\n return response.arrayBuffer();\r\n }\r\n throw new Error(`Could not fetch the wasm component for the Zstandard decompression lib: ${response.status} - ${response.statusText}`);\r\n })\r\n .then((arrayBuffer) => WebAssembly.instantiate(arrayBuffer, IMPORT_OBJECT))\r\n .then(this._init);\r\n } else {\r\n // Node.js.\r\n\r\n init = WebAssembly.instantiateStreaming(fetch(ZSTDDecoder.WasmModuleURL), IMPORT_OBJECT).then(this._init);\r\n }\r\n\r\n return init;\r\n }\r\n\r\n _init(result: WebAssembly.WebAssemblyInstantiatedSource): void {\r\n instance = result.instance as unknown as { exports: DecoderExports };\r\n\r\n IMPORT_OBJECT.env.emscripten_notify_memory_growth(); // initialize heap.\r\n }\r\n\r\n decode(array: Uint8Array, uncompressedSize = 0): Uint8Array {\r\n if (!instance) {\r\n throw new Error(`ZSTDDecoder: Await .init() before decoding.`);\r\n }\r\n\r\n // Write compressed data into WASM memory.\r\n const compressedSize = array.byteLength;\r\n const compressedPtr = instance.exports.malloc(compressedSize);\r\n heap.set(array, compressedPtr);\r\n\r\n // Decompress into WASM memory.\r\n uncompressedSize = uncompressedSize || Number(instance.exports.ZSTD_findDecompressedSize(compressedPtr, compressedSize));\r\n const uncompressedPtr = instance.exports.malloc(uncompressedSize);\r\n const actualSize = instance.exports.ZSTD_decompress(uncompressedPtr, uncompressedSize, compressedPtr, compressedSize);\r\n\r\n // Read decompressed data and free WASM memory.\r\n const dec = heap.slice(uncompressedPtr, uncompressedPtr + actualSize);\r\n instance.exports.free(compressedPtr);\r\n instance.exports.free(uncompressedPtr);\r\n\r\n return dec;\r\n }\r\n}\r\n\r\n/**\r\n * BSD License\r\n *\r\n * For Zstandard software\r\n *\r\n * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. All rights reserved.\r\n *\r\n * Redistribution and use in source and binary forms, with or without modification,\r\n * are permitted provided that the following conditions are met:\r\n *\r\n * * Redistributions of source code must retain the above copyright notice, this\r\n * list of conditions and the following disclaimer.\r\n *\r\n * * Redistributions in binary form must reproduce the above copyright notice,\r\n * this list of conditions and the following disclaimer in the documentation\r\n * and/or other materials provided with the distribution.\r\n *\r\n * * Neither the name Facebook nor the names of its contributors may be used to\r\n * endorse or promote products derived from this software without specific\r\n * prior written permission.\r\n *\r\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\r\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r\n * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\r\n * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r\n * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r\n * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\r\n * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r\n * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r\n */\r\n"]}
|