@babylonjs/ktx2decoder 7.11.4 → 7.13.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,6 +29,11 @@ export class MSCTranscoder extends Transcoder {
29
29
  script.setAttribute("type", "text/javascript");
30
30
  script.setAttribute("src", Transcoder.GetWasmUrl(MSCTranscoder.JSModuleURL));
31
31
  script.onload = () => {
32
+ // defensive
33
+ if (typeof MSC_TRANSCODER === "undefined") {
34
+ reject("MSC_TRANSCODER script loaded but MSC_TRANSCODER is not defined.");
35
+ return;
36
+ }
32
37
  MSC_TRANSCODER({ wasmBinary }).then((basisModule) => {
33
38
  basisModule.initTranscoders();
34
39
  this._mscBasisModule = basisModule;
@@ -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;gBACh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G,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;;AAjKD;;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 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 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"]}
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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,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}\r\n"]}
package/ktx2FileReader.js CHANGED
@@ -9,6 +9,30 @@ export var SupercompressionScheme;
9
9
  SupercompressionScheme[SupercompressionScheme["ZStandard"] = 2] = "ZStandard";
10
10
  SupercompressionScheme[SupercompressionScheme["ZLib"] = 3] = "ZLib";
11
11
  })(SupercompressionScheme || (SupercompressionScheme = {}));
12
+ var DFDModel;
13
+ (function (DFDModel) {
14
+ DFDModel[DFDModel["ETC1S"] = 163] = "ETC1S";
15
+ DFDModel[DFDModel["UASTC"] = 166] = "UASTC";
16
+ })(DFDModel || (DFDModel = {}));
17
+ var DFDChannel_ETC1S;
18
+ (function (DFDChannel_ETC1S) {
19
+ DFDChannel_ETC1S[DFDChannel_ETC1S["RGB"] = 0] = "RGB";
20
+ DFDChannel_ETC1S[DFDChannel_ETC1S["RRR"] = 3] = "RRR";
21
+ DFDChannel_ETC1S[DFDChannel_ETC1S["GGG"] = 4] = "GGG";
22
+ DFDChannel_ETC1S[DFDChannel_ETC1S["AAA"] = 15] = "AAA";
23
+ })(DFDChannel_ETC1S || (DFDChannel_ETC1S = {}));
24
+ var DFDChannel_UASTC;
25
+ (function (DFDChannel_UASTC) {
26
+ DFDChannel_UASTC[DFDChannel_UASTC["RGB"] = 0] = "RGB";
27
+ DFDChannel_UASTC[DFDChannel_UASTC["RGBA"] = 3] = "RGBA";
28
+ DFDChannel_UASTC[DFDChannel_UASTC["RRR"] = 4] = "RRR";
29
+ DFDChannel_UASTC[DFDChannel_UASTC["RRRG"] = 5] = "RRRG";
30
+ })(DFDChannel_UASTC || (DFDChannel_UASTC = {}));
31
+ var DFDTransferFunction;
32
+ (function (DFDTransferFunction) {
33
+ DFDTransferFunction[DFDTransferFunction["linear"] = 1] = "linear";
34
+ DFDTransferFunction[DFDTransferFunction["sRGB"] = 2] = "sRGB";
35
+ })(DFDTransferFunction || (DFDTransferFunction = {}));
12
36
  export class KTX2FileReader {
13
37
  /**
14
38
  * Will throw an exception if the file can't be parsed
@@ -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;AA2GD,MAAM,OAAO,cAAc;IAOvB;;;OAGG;IACH,YAAY,IAAgB;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACtB,CAAC;IAED,IAAW,IAAI;QACX,OAAO,IAAI,CAAC,KAAK,CAAC;IAC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AAE,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/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AmB,CAAC,QAAQ;gBAClC,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,kCAA0B,CAAC;SAC9E;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,IAAW,eAAe;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC,sBAAsB,KAAK,sBAAsB,CAAC,SAAS,CAAC;IACpF,CAAC;IAED,IAAW,cAAc;QACrB,OAAO,IAAI,CAAC,SAAS,CAAC,gBAAgB,qCAA6B,CAAC;IACxE,CAAC;IAEM,MAAM,CAAC,OAAO,CAAC,IAAqB;QACvC,IAAI,IAAI,CAAC,UAAU,IAAI,EAAE,EAAE;YACvB,mEAAmE;YACnE,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,EAAE,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonjs/ktx2decoder",
3
- "version": "7.11.4",
3
+ "version": "7.13.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.11.4",
22
+ "@babylonjs/core": "^7.13.0",
23
23
  "@dev/build-tools": "^1.0.0",
24
24
  "@tools/ktx2decoder": "^1.0.0"
25
25
  },
@@ -5,7 +5,7 @@ const DecisionTree = {
5
5
  option: "forceRGBA",
6
6
  yes: {
7
7
  transcodeFormat: KTX2.TranscodeTarget.RGBA32,
8
- engineFormat: KTX2.EngineFormat.RGBA8Format,
8
+ engineFormat: 32856 /* KTX2.EngineFormat.RGBA8Format */,
9
9
  roundToMultiple4: false,
10
10
  },
11
11
  no: {
@@ -14,11 +14,11 @@ const DecisionTree = {
14
14
  alpha: true,
15
15
  yes: {
16
16
  transcodeFormat: KTX2.TranscodeTarget.ETC2_RGBA,
17
- engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA8_ETC2_EAC,
17
+ engineFormat: 37496 /* KTX2.EngineFormat.COMPRESSED_RGBA8_ETC2_EAC */,
18
18
  },
19
19
  no: {
20
20
  transcodeFormat: KTX2.TranscodeTarget.ETC1_RGB,
21
- engineFormat: KTX2.EngineFormat.COMPRESSED_RGB8_ETC2,
21
+ engineFormat: 37492 /* KTX2.EngineFormat.COMPRESSED_RGB8_ETC2 */,
22
22
  },
23
23
  },
24
24
  no: {
@@ -26,13 +26,13 @@ const DecisionTree = {
26
26
  alpha: false,
27
27
  yes: {
28
28
  transcodeFormat: KTX2.TranscodeTarget.ETC1_RGB,
29
- engineFormat: KTX2.EngineFormat.COMPRESSED_RGB_ETC1_WEBGL,
29
+ engineFormat: 36196 /* KTX2.EngineFormat.COMPRESSED_RGB_ETC1_WEBGL */,
30
30
  },
31
31
  no: {
32
32
  cap: "bptc",
33
33
  yes: {
34
34
  transcodeFormat: KTX2.TranscodeTarget.BC7_RGBA,
35
- engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_BPTC_UNORM_EXT,
35
+ engineFormat: 36492 /* KTX2.EngineFormat.COMPRESSED_RGBA_BPTC_UNORM_EXT */,
36
36
  },
37
37
  no: {
38
38
  cap: "s3tc",
@@ -40,11 +40,11 @@ const DecisionTree = {
40
40
  alpha: true,
41
41
  yes: {
42
42
  transcodeFormat: KTX2.TranscodeTarget.BC3_RGBA,
43
- engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_S3TC_DXT5_EXT,
43
+ engineFormat: 33779 /* KTX2.EngineFormat.COMPRESSED_RGBA_S3TC_DXT5_EXT */,
44
44
  },
45
45
  no: {
46
46
  transcodeFormat: KTX2.TranscodeTarget.BC1_RGB,
47
- engineFormat: KTX2.EngineFormat.COMPRESSED_RGB_S3TC_DXT1_EXT,
47
+ engineFormat: 33776 /* KTX2.EngineFormat.COMPRESSED_RGB_S3TC_DXT1_EXT */,
48
48
  },
49
49
  },
50
50
  no: {
@@ -54,16 +54,16 @@ const DecisionTree = {
54
54
  alpha: true,
55
55
  yes: {
56
56
  transcodeFormat: KTX2.TranscodeTarget.PVRTC1_4_RGBA,
57
- engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
57
+ engineFormat: 35842 /* KTX2.EngineFormat.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG */,
58
58
  },
59
59
  no: {
60
60
  transcodeFormat: KTX2.TranscodeTarget.PVRTC1_4_RGB,
61
- engineFormat: KTX2.EngineFormat.COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
61
+ engineFormat: 35840 /* KTX2.EngineFormat.COMPRESSED_RGB_PVRTC_4BPPV1_IMG */,
62
62
  },
63
63
  },
64
64
  no: {
65
65
  transcodeFormat: KTX2.TranscodeTarget.RGBA32,
66
- engineFormat: KTX2.EngineFormat.RGBA8Format,
66
+ engineFormat: 32856 /* KTX2.EngineFormat.RGBA8Format */,
67
67
  roundToMultiple4: false,
68
68
  },
69
69
  },
@@ -76,40 +76,40 @@ const DecisionTree = {
76
76
  option: "forceRGBA",
77
77
  yes: {
78
78
  transcodeFormat: KTX2.TranscodeTarget.RGBA32,
79
- engineFormat: KTX2.EngineFormat.RGBA8Format,
79
+ engineFormat: 32856 /* KTX2.EngineFormat.RGBA8Format */,
80
80
  roundToMultiple4: false,
81
81
  },
82
82
  no: {
83
83
  option: "forceR8",
84
84
  yes: {
85
85
  transcodeFormat: KTX2.TranscodeTarget.R8,
86
- engineFormat: KTX2.EngineFormat.R8Format,
86
+ engineFormat: 33321 /* KTX2.EngineFormat.R8Format */,
87
87
  roundToMultiple4: false,
88
88
  },
89
89
  no: {
90
90
  option: "forceRG8",
91
91
  yes: {
92
92
  transcodeFormat: KTX2.TranscodeTarget.RG8,
93
- engineFormat: KTX2.EngineFormat.RG8Format,
93
+ engineFormat: 33323 /* KTX2.EngineFormat.RG8Format */,
94
94
  roundToMultiple4: false,
95
95
  },
96
96
  no: {
97
97
  cap: "astc",
98
98
  yes: {
99
99
  transcodeFormat: KTX2.TranscodeTarget.ASTC_4X4_RGBA,
100
- engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_ASTC_4X4_KHR,
100
+ engineFormat: 37808 /* KTX2.EngineFormat.COMPRESSED_RGBA_ASTC_4X4_KHR */,
101
101
  },
102
102
  no: {
103
103
  cap: "bptc",
104
104
  yes: {
105
105
  transcodeFormat: KTX2.TranscodeTarget.BC7_RGBA,
106
- engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_BPTC_UNORM_EXT,
106
+ engineFormat: 36492 /* KTX2.EngineFormat.COMPRESSED_RGBA_BPTC_UNORM_EXT */,
107
107
  },
108
108
  no: {
109
109
  option: "useRGBAIfASTCBC7NotAvailableWhenUASTC",
110
110
  yes: {
111
111
  transcodeFormat: KTX2.TranscodeTarget.RGBA32,
112
- engineFormat: KTX2.EngineFormat.RGBA8Format,
112
+ engineFormat: 32856 /* KTX2.EngineFormat.RGBA8Format */,
113
113
  roundToMultiple4: false,
114
114
  },
115
115
  no: {
@@ -118,18 +118,18 @@ const DecisionTree = {
118
118
  alpha: true,
119
119
  yes: {
120
120
  transcodeFormat: KTX2.TranscodeTarget.ETC2_RGBA,
121
- engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA8_ETC2_EAC,
121
+ engineFormat: 37496 /* KTX2.EngineFormat.COMPRESSED_RGBA8_ETC2_EAC */,
122
122
  },
123
123
  no: {
124
124
  transcodeFormat: KTX2.TranscodeTarget.ETC1_RGB,
125
- engineFormat: KTX2.EngineFormat.COMPRESSED_RGB8_ETC2,
125
+ engineFormat: 37492 /* KTX2.EngineFormat.COMPRESSED_RGB8_ETC2 */,
126
126
  },
127
127
  },
128
128
  no: {
129
129
  cap: "etc1",
130
130
  yes: {
131
131
  transcodeFormat: KTX2.TranscodeTarget.ETC1_RGB,
132
- engineFormat: KTX2.EngineFormat.COMPRESSED_RGB_ETC1_WEBGL,
132
+ engineFormat: 36196 /* KTX2.EngineFormat.COMPRESSED_RGB_ETC1_WEBGL */,
133
133
  },
134
134
  no: {
135
135
  cap: "s3tc",
@@ -137,11 +137,11 @@ const DecisionTree = {
137
137
  alpha: true,
138
138
  yes: {
139
139
  transcodeFormat: KTX2.TranscodeTarget.BC3_RGBA,
140
- engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_S3TC_DXT5_EXT,
140
+ engineFormat: 33779 /* KTX2.EngineFormat.COMPRESSED_RGBA_S3TC_DXT5_EXT */,
141
141
  },
142
142
  no: {
143
143
  transcodeFormat: KTX2.TranscodeTarget.BC1_RGB,
144
- engineFormat: KTX2.EngineFormat.COMPRESSED_RGB_S3TC_DXT1_EXT,
144
+ engineFormat: 33776 /* KTX2.EngineFormat.COMPRESSED_RGB_S3TC_DXT1_EXT */,
145
145
  },
146
146
  },
147
147
  no: {
@@ -151,16 +151,16 @@ const DecisionTree = {
151
151
  alpha: true,
152
152
  yes: {
153
153
  transcodeFormat: KTX2.TranscodeTarget.PVRTC1_4_RGBA,
154
- engineFormat: KTX2.EngineFormat.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
154
+ engineFormat: 35842 /* KTX2.EngineFormat.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG */,
155
155
  },
156
156
  no: {
157
157
  transcodeFormat: KTX2.TranscodeTarget.PVRTC1_4_RGB,
158
- engineFormat: KTX2.EngineFormat.COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
158
+ engineFormat: 35840 /* KTX2.EngineFormat.COMPRESSED_RGB_PVRTC_4BPPV1_IMG */,
159
159
  },
160
160
  },
161
161
  no: {
162
162
  transcodeFormat: KTX2.TranscodeTarget.RGBA32,
163
- engineFormat: KTX2.EngineFormat.RGBA8Format,
163
+ engineFormat: 32856 /* KTX2.EngineFormat.RGBA8Format */,
164
164
  roundToMultiple4: false,
165
165
  },
166
166
  },
@@ -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,EAAE,IAAI,CAAC,YAAY,CAAC,WAAW;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,eAAe,CAAC,SAAS;oBAC/C,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,yBAAyB;iBAC5D;gBACD,EAAE,EAAE;oBACA,eAAe,EAAE,IAAI,CAAC,eAAe,CAAC,QAAQ;oBAC9C,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,oBAAoB;iBACvD;aACJ;YACD,EAAE,EAAE;gBACA,GAAG,EAAE,MAAM;gBACX,KAAK,EAAE,KAAK;gBACZ,GAAG,EAAE;oBACD,eAAe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L,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":["../../../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,eAAe,CAAC,SAAS;oBAC/C,YAAY,yDAA6C;iBAC5D;gBACD,EAAE,EAAE;oBACA,eAAe,EAAE,IAAI,CAAC,eAAe,CAAC,QAAQ;oBAC9C,YAAY,oDAAwC;iBACvD;aACJ;YACD,EAAE,EAAE;gBACA,GAAG,EAAE,MAAM;gBACX,KAAK,EAAE,KAAK;gBACZ,GAAG,EAAE;oBACD,eAAe,EAAE,IAAI,CAAC,eAAe,CAAC,QAAQ;oBAC9C,YAAY,yDAA6C;iBAC5D;gBACD,EAAE,EAAE;oBACA,GAAG,EAAE,MAAM;oBACX,GAAG,EAAE;wBACD,eAAe,EAAE,IAAI,CAAC,eAAe,CAAC,QAAQ;wBAC9C,YAAY,8DAAk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AAI,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"]}