Files
Foundry-VTT-Docker/resources/app/node_modules/@pixi/basis/lib/loader/BasisParser.mjs.map

1 line
20 KiB
Plaintext
Raw Normal View History

2025-01-04 00:34:03 +01:00
{"version":3,"file":"BasisParser.mjs","sources":["../../src/loader/BasisParser.ts"],"sourcesContent":["import { CompressedTextureResource } from '@pixi/compressed-textures';\nimport { BufferResource, settings, TYPES } from '@pixi/core';\nimport {\n BASIS_FORMAT_TO_INTERNAL_FORMAT,\n BASIS_FORMATS,\n BASIS_FORMATS_ALPHA,\n INTERNAL_FORMAT_TO_BASIS_FORMAT,\n} from '../Basis';\nimport { TranscoderWorker } from '../TranscoderWorker';\n\nimport type { CompressedLevelBuffer, INTERNAL_FORMATS } from '@pixi/compressed-textures';\nimport type { BasisBinding, BasisTextureExtensions } from '../Basis';\n\nexport type TranscodedResourcesArray = (Array<CompressedTextureResource> | Array<BufferResource>) & {\n basisFormat: BASIS_FORMATS\n};\n\n/**\n * Loader plugin for handling BASIS supercompressed texture files.\n *\n * To use this loader, you must bind the basis_universal WebAssembly transcoder. There are two ways of\n * doing this:\n *\n * 1. Adding a &lt;script&gt; tag to your HTML page to the transcoder bundle in this package, and serving\n * the WASM binary from the same location.\n *\n * ```html\n * <!-- Copy ./node_modules/@pixi/basis/assets/basis_.wasm into your assets directory\n * as well, so it is served from the same folder as the JavaScript! -->\n * <script src=\"./node_modules/@pixi/basis/assets/basis_transcoder.js\"></script>\n * ```\n *\n * NOTE: `basis_transcoder.js` expects the WebAssembly binary to be named `basis_transcoder.wasm`.\n * NOTE-2: This method supports transcoding on the main-thread. Only use this if you have 1 or 2 *.basis\n * files.\n *\n * 2. Loading the transcoder source from a URL.\n *\n * ```js\n * // Use this if you to use the default CDN url for @pixi/basis\n * BasisParser.loadTranscoder();\n *\n * // Use this if you want to serve the transcoder on your own\n * BasisParser.loadTranscoder('./basis_transcoder.js', './basis_transcoder.wasm');\n * ```\n *\n * NOTE: This can only be used with web-workers.\n * @class\n * @memberof PIXI\n * @implements {PIXI.ILoaderPlugin}\n */\nexport class BasisParser\n{\n public static basisBinding: BasisBinding;\n private static defaultRGBFormat: { basisFormat: BASIS_FORMATS, textureFormat: INTERNAL_FORMATS | TYPES };\n private static defaultRGBAFormat: { basisFormat: BASIS_FORMATS, textureFormat: INTERNAL_FORMATS | TYPES };\n private static fallbackMode = false;\n private static workerPool: TranscoderWorker[] = [];\n\n /**\n * Runs transcoding and populates imageArray. It will run the transcoding in a web worker\n * if they are available.\n * @private\n */\n public static async transcode(arrayBuffer: ArrayBuffer): Promise<TranscodedResourcesArray>\n {\n let resources: TranscodedResourcesArray;\n\n if (typeof Worker !== 'undefined' && BasisParser.TranscoderWorker.wasmSource)\n {\n resources = await BasisParser.transcodeAsync(arrayBuffer);\n }\n else\n {\n resources = BasisParser.transcodeSync(arrayBuffer);\n }\n\n return resources;\n }\n\n /**\n * Finds a suitable worker for transcoding and sends a transcoding request\n * @private\n * @async\n */\n public static async transcodeAsync(arrayBuffer: ArrayBuffer): Promise<TranscodedResourcesArray>\n {\n if (!BasisParser.defaultRGBAFormat && !BasisParser.defaultRGBFormat)\n {\n BasisParser.autoDetectFormats();\n }\n\n const workerPool = BasisParser.workerPool;\n\n let leastLoad = 0x10000000;\n let worker = null;\n\n for (let i = 0, j = workerPool.length; i < j; i++)\n {\n if (workerPool[i].load < leastLoad)\n {\n worker = workerPool[i];\n leastLoad = worker.load;\n }\n }\n\n if (!worker)\n {\n /* eslint-disable-next-line no-use-before-define */\n worker = new TranscoderWorker();\n\n workerPool.push(worker);\n }\n\n // Wait until worker is ready\n await work