@loaders.gl/textures
Advanced tools
Comparing version 4.2.0-alpha.4 to 4.2.0-alpha.5
@@ -0,26 +1,34 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { VERSION } from "./lib/utils/version.js"; | ||
import parseBasis from "./lib/parsers/parse-basis.js"; | ||
/** | ||
* Worker loader for Basis super compressed textures | ||
*/ | ||
export const BasisWorkerLoader = { | ||
name: 'Basis', | ||
id: 'basis', | ||
module: 'textures', | ||
version: VERSION, | ||
worker: true, | ||
extensions: ['basis', 'ktx2'], | ||
mimeTypes: ['application/octet-stream', 'image/ktx2'], | ||
tests: ['sB'], | ||
binary: true, | ||
options: { | ||
basis: { | ||
format: 'auto', | ||
libraryPath: 'libs/', | ||
containerFormat: 'auto', | ||
module: 'transcoder' | ||
name: 'Basis', | ||
id: 'basis', | ||
module: 'textures', | ||
version: VERSION, | ||
worker: true, | ||
extensions: ['basis', 'ktx2'], | ||
mimeTypes: ['application/octet-stream', 'image/ktx2'], | ||
tests: ['sB'], | ||
binary: true, | ||
options: { | ||
basis: { | ||
format: 'auto', // gl context doesn't exist on a worker thread | ||
libraryPath: 'libs/', | ||
containerFormat: 'auto', // 'basis' || 'ktx2' || 'auto' | ||
module: 'transcoder' // 'transcoder' || 'encoder' | ||
} | ||
} | ||
} | ||
}; | ||
/** | ||
* Loader for Basis super compressed textures | ||
*/ | ||
export const BasisLoader = { | ||
...BasisWorkerLoader, | ||
parse: parseBasis | ||
...BasisWorkerLoader, | ||
parse: parseBasis | ||
}; | ||
//# sourceMappingURL=basis-loader.js.map |
@@ -0,40 +1,60 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { VERSION } from "./lib/utils/version.js"; | ||
import { parseCompressedTexture } from "./lib/parsers/parse-compressed-texture.js"; | ||
import parseBasis from "./lib/parsers/parse-basis.js"; | ||
/** | ||
* Worker Loader for KTX, DDS, and PVR texture container formats | ||
*/ | ||
export const CompressedTextureWorkerLoader = { | ||
name: 'Texture Containers', | ||
id: 'compressed-texture', | ||
module: 'textures', | ||
version: VERSION, | ||
worker: true, | ||
extensions: ['ktx', 'ktx2', 'dds', 'pvr'], | ||
mimeTypes: ['image/ktx2', 'image/ktx', 'image/vnd-ms.dds', 'image/x-dds', 'application/octet-stream'], | ||
binary: true, | ||
options: { | ||
'compressed-texture': { | ||
libraryPath: 'libs/', | ||
useBasis: false | ||
name: 'Texture Containers', | ||
id: 'compressed-texture', | ||
module: 'textures', | ||
version: VERSION, | ||
worker: true, | ||
extensions: [ | ||
'ktx', | ||
'ktx2', | ||
'dds', // WEBGL_compressed_texture_s3tc, WEBGL_compressed_texture_atc | ||
'pvr' // WEBGL_compressed_texture_pvrtc | ||
], | ||
mimeTypes: [ | ||
'image/ktx2', | ||
'image/ktx', | ||
'image/vnd-ms.dds', | ||
'image/x-dds', | ||
'application/octet-stream' | ||
], | ||
binary: true, | ||
options: { | ||
'compressed-texture': { | ||
libraryPath: 'libs/', | ||
useBasis: false | ||
} | ||
} | ||
} | ||
}; | ||
/** | ||
* Loader for KTX, DDS, and PVR texture container formats | ||
*/ | ||
export const CompressedTextureLoader = { | ||
...CompressedTextureWorkerLoader, | ||
parse: async (arrayBuffer, options) => { | ||
var _options$compressedT; | ||
if (options !== null && options !== void 0 && (_options$compressedT = options['compressed-texture']) !== null && _options$compressedT !== void 0 && _options$compressedT.useBasis) { | ||
options.basis = { | ||
format: { | ||
alpha: 'BC3', | ||
noAlpha: 'BC1' | ||
}, | ||
...options.basis, | ||
containerFormat: 'ktx2', | ||
module: 'encoder' | ||
}; | ||
const result = await parseBasis(arrayBuffer, options); | ||
return result[0]; | ||
...CompressedTextureWorkerLoader, | ||
parse: async (arrayBuffer, options) => { | ||
if (options?.['compressed-texture']?.useBasis) { | ||
// @ts-expect-error TODO not allowed to modify inputs | ||
options.basis = { | ||
format: { | ||
alpha: 'BC3', | ||
noAlpha: 'BC1' | ||
}, | ||
// @ts-expect-error TODO not allowed to modify inputs | ||
...options.basis, | ||
containerFormat: 'ktx2', | ||
module: 'encoder' | ||
}; | ||
const result = await parseBasis(arrayBuffer, options); | ||
return result[0]; | ||
} | ||
return parseCompressedTexture(arrayBuffer); | ||
} | ||
return parseCompressedTexture(arrayBuffer); | ||
} | ||
}; | ||
//# sourceMappingURL=compressed-texture-loader.js.map |
@@ -0,24 +1,37 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { VERSION } from "./lib/utils/version.js"; | ||
import { encodeImageURLToCompressedTextureURL } from "./lib/encoders/encode-texture.js"; | ||
/** | ||
* DDS Texture Container Exporter | ||
*/ | ||
export const CompressedTextureWriter = { | ||
name: 'DDS Texture Container', | ||
id: 'dds', | ||
module: 'textures', | ||
version: VERSION, | ||
extensions: ['dds'], | ||
options: { | ||
texture: { | ||
format: 'auto', | ||
compression: 'auto', | ||
quality: 'auto', | ||
mipmap: false, | ||
flipY: false, | ||
toolFlags: '' | ||
name: 'DDS Texture Container', | ||
id: 'dds', | ||
module: 'textures', | ||
version: VERSION, | ||
extensions: ['dds'], | ||
options: { | ||
texture: { | ||
format: 'auto', | ||
compression: 'auto', | ||
quality: 'auto', | ||
mipmap: false, | ||
flipY: false, | ||
toolFlags: '' | ||
} | ||
}, | ||
encodeURLtoURL: encodeImageURLToCompressedTextureURL, | ||
encode() { | ||
throw new Error('Not implemented'); | ||
} | ||
}, | ||
encodeURLtoURL: encodeImageURLToCompressedTextureURL, | ||
encode() { | ||
throw new Error('Not implemented'); | ||
} | ||
}; | ||
//# sourceMappingURL=compressed-texture-writer.js.map | ||
// TYPE TESTS - TODO find a better way than exporting junk | ||
// export const _TypecheckCompressedTextureWriter: typeof CompressedTextureWriter & { | ||
// encodeURLtoURL: ( | ||
// inputUrl: string, | ||
// outputUrl: string, | ||
// options?: CompressedTextureWriterOptions | ||
// ) => Promise<string>; | ||
// } = CompressedTextureWriter; |
@@ -0,17 +1,23 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { VERSION } from "./lib/utils/version.js"; | ||
/** | ||
* Worker loader for the Crunch compressed texture container format | ||
* @note We avoid bundling crunch - it is a rare format and large lib, so we only offer worker loader | ||
*/ | ||
export const CrunchLoader = { | ||
id: 'crunch', | ||
name: 'Crunch', | ||
module: 'textures', | ||
version: VERSION, | ||
worker: true, | ||
extensions: ['crn'], | ||
mimeTypes: ['image/crn', 'image/x-crn', 'application/octet-stream'], | ||
binary: true, | ||
options: { | ||
crunch: { | ||
libraryPath: 'libs/' | ||
id: 'crunch', | ||
name: 'Crunch', | ||
module: 'textures', | ||
version: VERSION, | ||
worker: true, | ||
extensions: ['crn'], | ||
mimeTypes: ['image/crn', 'image/x-crn', 'application/octet-stream'], | ||
binary: true, | ||
options: { | ||
crunch: { | ||
libraryPath: 'libs/' | ||
} | ||
} | ||
} | ||
}; | ||
//# sourceMappingURL=crunch-loader.js.map |
export type { GPUTextureFormat } from '@loaders.gl/schema'; | ||
export type { TextureLoaderOptions } from './compressed-texture-loader'; | ||
export { BasisLoader, BasisWorkerLoader } from './basis-loader'; | ||
export { CompressedTextureLoader, CompressedTextureWorkerLoader } from './compressed-texture-loader'; | ||
export { CrunchLoader } from './crunch-loader'; | ||
export { NPYLoader, NPYWorkerLoader } from './npy-loader'; | ||
export { BASIS_EXTERNAL_LIBRARIES } from './lib/parsers/basis-module-loader'; | ||
export { CRUNCH_EXTERNAL_LIBRARIES } from './lib/parsers/crunch-module-loader'; | ||
export { CompressedTextureWriter } from './compressed-texture-writer'; | ||
export { KTX2BasisWriter } from './ktx2-basis-writer'; | ||
export type { TextureLoaderOptions } from "./compressed-texture-loader.js"; | ||
export { BasisLoader, BasisWorkerLoader } from "./basis-loader.js"; | ||
export { CompressedTextureLoader, CompressedTextureWorkerLoader } from "./compressed-texture-loader.js"; | ||
export { CrunchLoader } from "./crunch-loader.js"; | ||
export { NPYLoader, NPYWorkerLoader } from "./npy-loader.js"; | ||
export { BASIS_EXTERNAL_LIBRARIES } from "./lib/parsers/basis-module-loader.js"; | ||
export { CRUNCH_EXTERNAL_LIBRARIES } from "./lib/parsers/crunch-module-loader.js"; | ||
export { CompressedTextureWriter } from "./compressed-texture-writer.js"; | ||
export { KTX2BasisWriter } from "./ktx2-basis-writer.js"; | ||
export declare const KTX2BasisWriterWorker: { | ||
@@ -25,9 +25,9 @@ name: string; | ||
}; | ||
export { loadImageTexture } from './lib/texture-api/load-image'; | ||
export { loadImageTextureArray } from './lib/texture-api/load-image-array'; | ||
export { loadImageTextureCube } from './lib/texture-api/load-image-cube'; | ||
export { GL_EXTENSIONS_CONSTANTS } from './lib/gl-extensions'; | ||
export { selectSupportedBasisFormat } from './lib/parsers/parse-basis'; | ||
export { getSupportedGPUTextureFormats } from './lib/utils/texture-formats'; | ||
export { CrunchLoader as CrunchWorkerLoader } from './crunch-loader'; | ||
export { loadImageTexture } from "./lib/texture-api/load-image.js"; | ||
export { loadImageTextureArray } from "./lib/texture-api/load-image-array.js"; | ||
export { loadImageTextureCube } from "./lib/texture-api/load-image-cube.js"; | ||
export { GL_EXTENSIONS_CONSTANTS } from "./lib/gl-extensions.js"; | ||
export { selectSupportedBasisFormat } from "./lib/parsers/parse-basis.js"; | ||
export { getSupportedGPUTextureFormats } from "./lib/utils/texture-formats.js"; | ||
export { CrunchLoader as CrunchWorkerLoader } from "./crunch-loader.js"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -0,2 +1,6 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { VERSION } from "./lib/utils/version.js"; | ||
// Loaders | ||
export { BasisLoader, BasisWorkerLoader } from "./basis-loader.js"; | ||
@@ -6,27 +10,31 @@ export { CompressedTextureLoader, CompressedTextureWorkerLoader } from "./compressed-texture-loader.js"; | ||
export { NPYLoader, NPYWorkerLoader } from "./npy-loader.js"; | ||
// Module constants | ||
export { BASIS_EXTERNAL_LIBRARIES } from "./lib/parsers/basis-module-loader.js"; | ||
export { CRUNCH_EXTERNAL_LIBRARIES } from "./lib/parsers/crunch-module-loader.js"; | ||
// Writers | ||
export { CompressedTextureWriter } from "./compressed-texture-writer.js"; | ||
export { KTX2BasisWriter } from "./ktx2-basis-writer.js"; | ||
export const KTX2BasisWriterWorker = { | ||
name: 'Basis Universal Supercompressed GPU Texture', | ||
id: 'ktx2-basis-writer', | ||
module: 'textures', | ||
version: VERSION, | ||
extensions: ['ktx2'], | ||
worker: true, | ||
options: { | ||
useSRGB: false, | ||
qualityLevel: 10, | ||
encodeUASTC: false, | ||
mipmaps: false | ||
} | ||
name: 'Basis Universal Supercompressed GPU Texture', | ||
id: 'ktx2-basis-writer', | ||
module: 'textures', | ||
version: VERSION, | ||
extensions: ['ktx2'], | ||
worker: true, | ||
options: { | ||
useSRGB: false, | ||
qualityLevel: 10, | ||
encodeUASTC: false, | ||
mipmaps: false | ||
} | ||
}; | ||
// Texture Loading API | ||
export { loadImageTexture } from "./lib/texture-api/load-image.js"; | ||
export { loadImageTextureArray } from "./lib/texture-api/load-image-array.js"; | ||
export { loadImageTextureCube } from "./lib/texture-api/load-image-cube.js"; | ||
// Utilities | ||
export { GL_EXTENSIONS_CONSTANTS } from "./lib/gl-extensions.js"; | ||
export { selectSupportedBasisFormat } from "./lib/parsers/parse-basis.js"; | ||
export { getSupportedGPUTextureFormats } from "./lib/utils/texture-formats.js"; | ||
// DEPRECATED | ||
export { CrunchLoader as CrunchWorkerLoader } from "./crunch-loader.js"; | ||
//# sourceMappingURL=index.js.map |
@@ -0,19 +1,25 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { VERSION } from "./lib/utils/version.js"; | ||
import { encodeKTX2BasisTexture } from "./lib/encoders/encode-ktx2-basis-texture.js"; | ||
/** | ||
* Basis Universal Supercompressed GPU Texture. | ||
* Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.8/textureSetDefinitionFormat.cmn.md | ||
*/ | ||
export const KTX2BasisWriter = { | ||
name: 'Basis Universal Supercompressed GPU Texture', | ||
id: 'ktx2-basis-writer', | ||
module: 'textures', | ||
version: VERSION, | ||
extensions: ['ktx2'], | ||
options: { | ||
['ktx2-basis-writer']: { | ||
useSRGB: false, | ||
qualityLevel: 10, | ||
encodeUASTC: false, | ||
mipmaps: false | ||
} | ||
}, | ||
encode: encodeKTX2BasisTexture | ||
name: 'Basis Universal Supercompressed GPU Texture', | ||
id: 'ktx2-basis-writer', | ||
module: 'textures', | ||
version: VERSION, | ||
extensions: ['ktx2'], | ||
options: { | ||
['ktx2-basis-writer']: { | ||
useSRGB: false, | ||
qualityLevel: 10, | ||
encodeUASTC: false, | ||
mipmaps: false | ||
} | ||
}, | ||
encode: encodeKTX2BasisTexture | ||
}; | ||
//# sourceMappingURL=ktx2-basis-writer.js.map |
@@ -0,6 +1,9 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { read } from 'ktx-parse'; | ||
export function encodeKTX(texture) { | ||
const ktx = read(texture); | ||
return ktx; | ||
const ktx = read(texture); | ||
// post process | ||
return ktx; | ||
} | ||
//# sourceMappingURL=encode-ktx.js.map |
@@ -0,35 +1,40 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { loadBasisEncoderModule } from "../parsers/basis-module-loader.js"; | ||
export async function encodeKTX2BasisTexture(image) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
const { | ||
useSRGB = false, | ||
qualityLevel = 10, | ||
encodeUASTC = false, | ||
mipmaps = false | ||
} = (options === null || options === void 0 ? void 0 : options['ktx2-basis-writer']) || {}; | ||
const { | ||
BasisEncoder | ||
} = await loadBasisEncoderModule(options); | ||
const basisEncoder = new BasisEncoder(); | ||
try { | ||
const basisFileData = new Uint8Array(image.width * image.height * 4); | ||
basisEncoder.setCreateKTX2File(true); | ||
basisEncoder.setKTX2UASTCSupercompression(true); | ||
basisEncoder.setKTX2SRGBTransferFunc(true); | ||
basisEncoder.setSliceSourceImage(0, image.data, image.width, image.height, false); | ||
basisEncoder.setPerceptual(useSRGB); | ||
basisEncoder.setMipSRGB(useSRGB); | ||
basisEncoder.setQualityLevel(qualityLevel); | ||
basisEncoder.setUASTC(encodeUASTC); | ||
basisEncoder.setMipGen(mipmaps); | ||
const numOutputBytes = basisEncoder.encode(basisFileData); | ||
const actualKTX2FileData = basisFileData.subarray(0, numOutputBytes).buffer; | ||
return actualKTX2FileData; | ||
} catch (error) { | ||
console.error('Basis Universal Supercompressed GPU Texture encoder Error: ', error); | ||
throw error; | ||
} finally { | ||
basisEncoder.delete(); | ||
} | ||
/** | ||
* Encodes image to Basis Universal Supercompressed GPU Texture. | ||
* Code example is taken from here - https://github.com/BinomialLLC/basis_universal/blob/master/webgl/ktx2_encode_test/index.html#L279 | ||
* BasisEncoder API - https://github.com/BinomialLLC/basis_universal/blob/master/webgl/transcoder/basis_wrappers.cpp#L1712 | ||
* @param image | ||
* @param options | ||
*/ | ||
export async function encodeKTX2BasisTexture(image, options = {}) { | ||
// TODO remove default values after writer options will be normalized like it done in load module. | ||
const { useSRGB = false, qualityLevel = 10, encodeUASTC = false, mipmaps = false } = options?.['ktx2-basis-writer'] || {}; | ||
const { BasisEncoder } = await loadBasisEncoderModule(options); | ||
const basisEncoder = new BasisEncoder(); | ||
try { | ||
const basisFileData = new Uint8Array(image.width * image.height * 4); | ||
basisEncoder.setCreateKTX2File(true); | ||
basisEncoder.setKTX2UASTCSupercompression(true); | ||
basisEncoder.setKTX2SRGBTransferFunc(true); | ||
basisEncoder.setSliceSourceImage(0, image.data, image.width, image.height, false); | ||
basisEncoder.setPerceptual(useSRGB); | ||
basisEncoder.setMipSRGB(useSRGB); | ||
basisEncoder.setQualityLevel(qualityLevel); | ||
basisEncoder.setUASTC(encodeUASTC); | ||
basisEncoder.setMipGen(mipmaps); | ||
const numOutputBytes = basisEncoder.encode(basisFileData); | ||
const actualKTX2FileData = basisFileData.subarray(0, numOutputBytes).buffer; | ||
return actualKTX2FileData; | ||
} | ||
catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.error('Basis Universal Supercompressed GPU Texture encoder Error: ', error); | ||
throw error; | ||
} | ||
finally { | ||
basisEncoder.delete(); | ||
} | ||
} | ||
//# sourceMappingURL=encode-ktx2-basis-texture.js.map |
@@ -1,3 +0,3 @@ | ||
import { CompressedTextureWriterOptions } from '../../compressed-texture-writer'; | ||
import { CompressedTextureWriterOptions } from "../../compressed-texture-writer.js"; | ||
export declare function encodeImageURLToCompressedTextureURL(inputUrl: string, outputUrl: string, options?: CompressedTextureWriterOptions): Promise<string>; | ||
//# sourceMappingURL=encode-texture.d.ts.map |
@@ -0,12 +1,26 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { ChildProcessProxy } from '@loaders.gl/worker-utils'; | ||
/* | ||
* @see https://github.com/TimvanScherpenzeel/texture-compressor | ||
*/ | ||
export async function encodeImageURLToCompressedTextureURL(inputUrl, outputUrl, options) { | ||
const args = ['texture-compressor', '--type', 's3tc', '--compression', 'DXT1', '--quality', 'normal', '--input', inputUrl, '--output', outputUrl]; | ||
const childProcess = new ChildProcessProxy(); | ||
await childProcess.start({ | ||
command: 'npx', | ||
arguments: args, | ||
spawn: options | ||
}); | ||
return outputUrl; | ||
// prettier-ignore | ||
const args = [ | ||
// Note: our actual executable is `npx`, so `texture-compressor` is an argument | ||
'texture-compressor', | ||
'--type', 's3tc', | ||
'--compression', 'DXT1', | ||
'--quality', 'normal', | ||
'--input', inputUrl, | ||
'--output', outputUrl | ||
]; | ||
const childProcess = new ChildProcessProxy(); | ||
await childProcess.start({ | ||
command: 'npx', | ||
arguments: args, | ||
spawn: options | ||
}); | ||
return outputUrl; | ||
} | ||
//# sourceMappingURL=encode-texture.js.map |
@@ -0,61 +1,72 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
/* eslint-disable camelcase */ | ||
export const GL_EXTENSIONS_CONSTANTS = { | ||
COMPRESSED_RGB_S3TC_DXT1_EXT: 0x83f0, | ||
COMPRESSED_RGBA_S3TC_DXT1_EXT: 0x83f1, | ||
COMPRESSED_RGBA_S3TC_DXT3_EXT: 0x83f2, | ||
COMPRESSED_RGBA_S3TC_DXT5_EXT: 0x83f3, | ||
COMPRESSED_R11_EAC: 0x9270, | ||
COMPRESSED_SIGNED_R11_EAC: 0x9271, | ||
COMPRESSED_RG11_EAC: 0x9272, | ||
COMPRESSED_SIGNED_RG11_EAC: 0x9273, | ||
COMPRESSED_RGB8_ETC2: 0x9274, | ||
COMPRESSED_RGBA8_ETC2_EAC: 0x9275, | ||
COMPRESSED_SRGB8_ETC2: 0x9276, | ||
COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 0x9277, | ||
COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: 0x9278, | ||
COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 0x9279, | ||
COMPRESSED_RGB_PVRTC_4BPPV1_IMG: 0x8c00, | ||
COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: 0x8c02, | ||
COMPRESSED_RGB_PVRTC_2BPPV1_IMG: 0x8c01, | ||
COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: 0x8c03, | ||
COMPRESSED_RGB_ETC1_WEBGL: 0x8d64, | ||
COMPRESSED_RGB_ATC_WEBGL: 0x8c92, | ||
COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL: 0x8c93, | ||
COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL: 0x87ee, | ||
COMPRESSED_RGBA_ASTC_4X4_KHR: 0x93b0, | ||
COMPRESSED_RGBA_ASTC_5X4_KHR: 0x93b1, | ||
COMPRESSED_RGBA_ASTC_5X5_KHR: 0x93b2, | ||
COMPRESSED_RGBA_ASTC_6X5_KHR: 0x93b3, | ||
COMPRESSED_RGBA_ASTC_6X6_KHR: 0x93b4, | ||
COMPRESSED_RGBA_ASTC_8X5_KHR: 0x93b5, | ||
COMPRESSED_RGBA_ASTC_8X6_KHR: 0x93b6, | ||
COMPRESSED_RGBA_ASTC_8X8_KHR: 0x93b7, | ||
COMPRESSED_RGBA_ASTC_10X5_KHR: 0x93b8, | ||
COMPRESSED_RGBA_ASTC_10X6_KHR: 0x93b9, | ||
COMPRESSED_RGBA_ASTC_10X8_KHR: 0x93ba, | ||
COMPRESSED_RGBA_ASTC_10X10_KHR: 0x93bb, | ||
COMPRESSED_RGBA_ASTC_12X10_KHR: 0x93bc, | ||
COMPRESSED_RGBA_ASTC_12X12_KHR: 0x93bd, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR: 0x93d0, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR: 0x93d1, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR: 0x93d2, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR: 0x93d3, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR: 0x93d4, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR: 0x93d5, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR: 0x93d6, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR: 0x93d7, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR: 0x93d8, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR: 0x93d9, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR: 0x93da, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR: 0x93db, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR: 0x93dc, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR: 0x93dd, | ||
COMPRESSED_RED_RGTC1_EXT: 0x8dbb, | ||
COMPRESSED_SIGNED_RED_RGTC1_EXT: 0x8dbc, | ||
COMPRESSED_RED_GREEN_RGTC2_EXT: 0x8dbd, | ||
COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT: 0x8dbe, | ||
COMPRESSED_SRGB_S3TC_DXT1_EXT: 0x8c4c, | ||
COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 0x8c4d, | ||
COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 0x8c4e, | ||
COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 0x8c4f | ||
// WEBGL_compressed_texture_s3tc | ||
COMPRESSED_RGB_S3TC_DXT1_EXT: 0x83f0, | ||
COMPRESSED_RGBA_S3TC_DXT1_EXT: 0x83f1, | ||
COMPRESSED_RGBA_S3TC_DXT3_EXT: 0x83f2, | ||
COMPRESSED_RGBA_S3TC_DXT5_EXT: 0x83f3, | ||
// WEBGL_compressed_texture_es3 | ||
COMPRESSED_R11_EAC: 0x9270, | ||
COMPRESSED_SIGNED_R11_EAC: 0x9271, | ||
COMPRESSED_RG11_EAC: 0x9272, | ||
COMPRESSED_SIGNED_RG11_EAC: 0x9273, | ||
COMPRESSED_RGB8_ETC2: 0x9274, | ||
COMPRESSED_RGBA8_ETC2_EAC: 0x9275, | ||
COMPRESSED_SRGB8_ETC2: 0x9276, | ||
COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 0x9277, | ||
COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: 0x9278, | ||
COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 0x9279, | ||
// WEBGL_compressed_texture_pvrtc | ||
COMPRESSED_RGB_PVRTC_4BPPV1_IMG: 0x8c00, | ||
COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: 0x8c02, | ||
COMPRESSED_RGB_PVRTC_2BPPV1_IMG: 0x8c01, | ||
COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: 0x8c03, | ||
// WEBGL_compressed_texture_etc1 | ||
COMPRESSED_RGB_ETC1_WEBGL: 0x8d64, | ||
// WEBGL_compressed_texture_atc | ||
COMPRESSED_RGB_ATC_WEBGL: 0x8c92, | ||
COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL: 0x8c93, | ||
COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL: 0x87ee, | ||
// WEBGL_compressed_texture_astc | ||
COMPRESSED_RGBA_ASTC_4X4_KHR: 0x93b0, | ||
COMPRESSED_RGBA_ASTC_5X4_KHR: 0x93b1, | ||
COMPRESSED_RGBA_ASTC_5X5_KHR: 0x93b2, | ||
COMPRESSED_RGBA_ASTC_6X5_KHR: 0x93b3, | ||
COMPRESSED_RGBA_ASTC_6X6_KHR: 0x93b4, | ||
COMPRESSED_RGBA_ASTC_8X5_KHR: 0x93b5, | ||
COMPRESSED_RGBA_ASTC_8X6_KHR: 0x93b6, | ||
COMPRESSED_RGBA_ASTC_8X8_KHR: 0x93b7, | ||
COMPRESSED_RGBA_ASTC_10X5_KHR: 0x93b8, | ||
COMPRESSED_RGBA_ASTC_10X6_KHR: 0x93b9, | ||
COMPRESSED_RGBA_ASTC_10X8_KHR: 0x93ba, | ||
COMPRESSED_RGBA_ASTC_10X10_KHR: 0x93bb, | ||
COMPRESSED_RGBA_ASTC_12X10_KHR: 0x93bc, | ||
COMPRESSED_RGBA_ASTC_12X12_KHR: 0x93bd, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR: 0x93d0, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR: 0x93d1, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR: 0x93d2, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR: 0x93d3, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR: 0x93d4, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR: 0x93d5, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR: 0x93d6, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR: 0x93d7, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR: 0x93d8, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR: 0x93d9, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR: 0x93da, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR: 0x93db, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR: 0x93dc, | ||
COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR: 0x93dd, | ||
// EXT_texture_compression_rgtc | ||
COMPRESSED_RED_RGTC1_EXT: 0x8dbb, | ||
COMPRESSED_SIGNED_RED_RGTC1_EXT: 0x8dbc, | ||
COMPRESSED_RED_GREEN_RGTC2_EXT: 0x8dbd, | ||
COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT: 0x8dbe, | ||
// WEBGL_compressed_texture_s3tc_srgb | ||
COMPRESSED_SRGB_S3TC_DXT1_EXT: 0x8c4c, | ||
COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 0x8c4d, | ||
COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 0x8c4e, | ||
COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 0x8c4f | ||
}; | ||
//# sourceMappingURL=gl-extensions.js.map |
@@ -0,80 +1,116 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { loadLibrary } from '@loaders.gl/worker-utils'; | ||
export const BASIS_EXTERNAL_LIBRARIES = { | ||
TRANSCODER: 'basis_transcoder.js', | ||
TRANSCODER_WASM: 'basis_transcoder.wasm', | ||
ENCODER: 'basis_encoder.js', | ||
ENCODER_WASM: 'basis_encoder.wasm' | ||
/** Basis transcoder, javascript wrapper part */ | ||
TRANSCODER: 'basis_transcoder.js', | ||
/** Basis transcoder, compiled web assembly part */ | ||
TRANSCODER_WASM: 'basis_transcoder.wasm', | ||
/** Basis encoder, javascript wrapper part */ | ||
ENCODER: 'basis_encoder.js', | ||
/** Basis encoder, compiled web assembly part */ | ||
ENCODER_WASM: 'basis_encoder.wasm' | ||
}; | ||
let loadBasisTranscoderPromise; | ||
/** | ||
* Loads wasm transcoder module | ||
* @param options | ||
* @returns {BasisFile} promise | ||
*/ | ||
export async function loadBasisTranscoderModule(options) { | ||
const modules = options.modules || {}; | ||
if (modules.basis) { | ||
return modules.basis; | ||
} | ||
loadBasisTranscoderPromise = loadBasisTranscoderPromise || loadBasisTranscoder(options); | ||
return await loadBasisTranscoderPromise; | ||
const modules = options.modules || {}; | ||
if (modules.basis) { | ||
return modules.basis; | ||
} | ||
loadBasisTranscoderPromise = loadBasisTranscoderPromise || loadBasisTranscoder(options); | ||
return await loadBasisTranscoderPromise; | ||
} | ||
/** | ||
* Loads wasm transcoder module | ||
* @param options | ||
* @returns {BasisFile} promise | ||
*/ | ||
async function loadBasisTranscoder(options) { | ||
let BASIS = null; | ||
let wasmBinary = null; | ||
[BASIS, wasmBinary] = await Promise.all([await loadLibrary(BASIS_EXTERNAL_LIBRARIES.TRANSCODER, 'textures', options), await loadLibrary(BASIS_EXTERNAL_LIBRARIES.TRANSCODER_WASM, 'textures', options)]); | ||
BASIS = BASIS || globalThis.BASIS; | ||
return await initializeBasisTranscoderModule(BASIS, wasmBinary); | ||
let BASIS = null; | ||
let wasmBinary = null; | ||
[BASIS, wasmBinary] = await Promise.all([ | ||
await loadLibrary(BASIS_EXTERNAL_LIBRARIES.TRANSCODER, 'textures', options), | ||
await loadLibrary(BASIS_EXTERNAL_LIBRARIES.TRANSCODER_WASM, 'textures', options) | ||
]); | ||
// Depends on how import happened... | ||
// @ts-ignore TS2339: Property does not exist on type | ||
BASIS = BASIS || globalThis.BASIS; | ||
return await initializeBasisTranscoderModule(BASIS, wasmBinary); | ||
} | ||
/** | ||
* Initialize wasm transcoder module | ||
* @param BasisModule - js part of the module | ||
* @param wasmBinary - wasm part of the module | ||
* @returns {BasisFile} promise | ||
*/ | ||
function initializeBasisTranscoderModule(BasisModule, wasmBinary) { | ||
const options = {}; | ||
if (wasmBinary) { | ||
options.wasmBinary = wasmBinary; | ||
} | ||
return new Promise(resolve => { | ||
BasisModule(options).then(module => { | ||
const { | ||
BasisFile, | ||
initializeBasis | ||
} = module; | ||
initializeBasis(); | ||
resolve({ | ||
BasisFile | ||
}); | ||
const options = {}; | ||
if (wasmBinary) { | ||
options.wasmBinary = wasmBinary; | ||
} | ||
return new Promise((resolve) => { | ||
// if you try to return BasisModule the browser crashes! | ||
BasisModule(options).then((module) => { | ||
const { BasisFile, initializeBasis } = module; | ||
initializeBasis(); | ||
resolve({ BasisFile }); | ||
}); | ||
}); | ||
}); | ||
} | ||
let loadBasisEncoderPromise; | ||
/** | ||
* Loads wasm encoder module | ||
* @param options | ||
* @returns {BasisFile, KTX2File} promise | ||
*/ | ||
export async function loadBasisEncoderModule(options) { | ||
const modules = options.modules || {}; | ||
if (modules.basisEncoder) { | ||
return modules.basisEncoder; | ||
} | ||
loadBasisEncoderPromise = loadBasisEncoderPromise || loadBasisEncoder(options); | ||
return await loadBasisEncoderPromise; | ||
const modules = options.modules || {}; | ||
if (modules.basisEncoder) { | ||
return modules.basisEncoder; | ||
} | ||
loadBasisEncoderPromise = loadBasisEncoderPromise || loadBasisEncoder(options); | ||
return await loadBasisEncoderPromise; | ||
} | ||
/** | ||
* Loads wasm encoder module | ||
* @param options | ||
* @returns {BasisFile, KTX2File} promise | ||
*/ | ||
async function loadBasisEncoder(options) { | ||
let BASIS_ENCODER = null; | ||
let wasmBinary = null; | ||
[BASIS_ENCODER, wasmBinary] = await Promise.all([await loadLibrary(BASIS_EXTERNAL_LIBRARIES.ENCODER, 'textures', options), await loadLibrary(BASIS_EXTERNAL_LIBRARIES.ENCODER_WASM, 'textures', options)]); | ||
BASIS_ENCODER = BASIS_ENCODER || globalThis.BASIS; | ||
return await initializeBasisEncoderModule(BASIS_ENCODER, wasmBinary); | ||
let BASIS_ENCODER = null; | ||
let wasmBinary = null; | ||
[BASIS_ENCODER, wasmBinary] = await Promise.all([ | ||
await loadLibrary(BASIS_EXTERNAL_LIBRARIES.ENCODER, 'textures', options), | ||
await loadLibrary(BASIS_EXTERNAL_LIBRARIES.ENCODER_WASM, 'textures', options) | ||
]); | ||
// Depends on how import happened... | ||
// @ts-ignore TS2339: Property does not exist on type | ||
BASIS_ENCODER = BASIS_ENCODER || globalThis.BASIS; | ||
return await initializeBasisEncoderModule(BASIS_ENCODER, wasmBinary); | ||
} | ||
/** | ||
* Initialize wasm transcoder module | ||
* @param BasisEncoderModule - js part of the module | ||
* @param wasmBinary - wasm part of the module | ||
* @returns {BasisFile, KTX2File} promise | ||
*/ | ||
function initializeBasisEncoderModule(BasisEncoderModule, wasmBinary) { | ||
const options = {}; | ||
if (wasmBinary) { | ||
options.wasmBinary = wasmBinary; | ||
} | ||
return new Promise(resolve => { | ||
BasisEncoderModule(options).then(module => { | ||
const { | ||
BasisFile, | ||
KTX2File, | ||
initializeBasis, | ||
BasisEncoder | ||
} = module; | ||
initializeBasis(); | ||
resolve({ | ||
BasisFile, | ||
KTX2File, | ||
BasisEncoder | ||
}); | ||
const options = {}; | ||
if (wasmBinary) { | ||
options.wasmBinary = wasmBinary; | ||
} | ||
return new Promise((resolve) => { | ||
// if you try to return BasisModule the browser crashes! | ||
BasisEncoderModule(options).then((module) => { | ||
const { BasisFile, KTX2File, initializeBasis, BasisEncoder } = module; | ||
initializeBasis(); | ||
resolve({ BasisFile, KTX2File, BasisEncoder }); | ||
}); | ||
}); | ||
}); | ||
} | ||
//# sourceMappingURL=basis-module-loader.js.map |
@@ -0,22 +1,38 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
// @ts-nocheck | ||
import { loadLibrary } from '@loaders.gl/worker-utils'; | ||
export const CRUNCH_EXTERNAL_LIBRARIES = { | ||
DECODER: 'crunch.js' | ||
/** Crunch decoder library. It is used as dynamically imported script */ | ||
DECODER: 'crunch.js' | ||
}; | ||
/** | ||
* Load crunch decoder module | ||
* @param options - loader options | ||
* @returns Promise of module object | ||
*/ | ||
export async function loadCrunchModule(options) { | ||
const modules = options.modules || {}; | ||
if (modules.crunch) { | ||
return modules.crunch; | ||
} | ||
return loadCrunch(options); | ||
const modules = options.modules || {}; | ||
if (modules.crunch) { | ||
return modules.crunch; | ||
} | ||
return loadCrunch(options); | ||
} | ||
let crunchModule; | ||
/** | ||
* Load crunch decoder module | ||
* @param {any} options - Loader options | ||
* @returns {Promise<any>} Promise of Module object | ||
*/ | ||
async function loadCrunch(options) { | ||
if (crunchModule) { | ||
if (crunchModule) { | ||
return crunchModule; | ||
} | ||
let loadCrunchDecoder = await loadLibrary(CRUNCH_EXTERNAL_LIBRARIES.DECODER, 'textures', options); | ||
// Depends on how import happened... | ||
// @ts-ignore TS2339: Property does not exist on type | ||
loadCrunchDecoder = loadCrunchDecoder || globalThis.LoadCrunchDecoder; | ||
crunchModule = loadCrunchDecoder(); | ||
return crunchModule; | ||
} | ||
let loadCrunchDecoder = await loadLibrary(CRUNCH_EXTERNAL_LIBRARIES.DECODER, 'textures', options); | ||
loadCrunchDecoder = loadCrunchDecoder || globalThis.LoadCrunchDecoder; | ||
crunchModule = loadCrunchDecoder(); | ||
return crunchModule; | ||
} | ||
//# sourceMappingURL=crunch-module-loader.js.map |
@@ -0,1 +1,4 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { loadBasisEncoderModule, loadBasisTranscoderModule } from "./basis-module-loader.js"; | ||
@@ -6,227 +9,236 @@ import { GL_EXTENSIONS_CONSTANTS } from "../gl-extensions.js"; | ||
const OutputFormat = { | ||
etc1: { | ||
basisFormat: 0, | ||
compressed: true, | ||
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL | ||
}, | ||
etc2: { | ||
basisFormat: 1, | ||
compressed: true | ||
}, | ||
bc1: { | ||
basisFormat: 2, | ||
compressed: true, | ||
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT | ||
}, | ||
bc3: { | ||
basisFormat: 3, | ||
compressed: true, | ||
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT | ||
}, | ||
bc4: { | ||
basisFormat: 4, | ||
compressed: true | ||
}, | ||
bc5: { | ||
basisFormat: 5, | ||
compressed: true | ||
}, | ||
'bc7-m6-opaque-only': { | ||
basisFormat: 6, | ||
compressed: true | ||
}, | ||
'bc7-m5': { | ||
basisFormat: 7, | ||
compressed: true | ||
}, | ||
'pvrtc1-4-rgb': { | ||
basisFormat: 8, | ||
compressed: true, | ||
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG | ||
}, | ||
'pvrtc1-4-rgba': { | ||
basisFormat: 9, | ||
compressed: true, | ||
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG | ||
}, | ||
'astc-4x4': { | ||
basisFormat: 10, | ||
compressed: true, | ||
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR | ||
}, | ||
'atc-rgb': { | ||
basisFormat: 11, | ||
compressed: true | ||
}, | ||
'atc-rgba-interpolated-alpha': { | ||
basisFormat: 12, | ||
compressed: true | ||
}, | ||
rgba32: { | ||
basisFormat: 13, | ||
compressed: false | ||
}, | ||
rgb565: { | ||
basisFormat: 14, | ||
compressed: false | ||
}, | ||
bgr565: { | ||
basisFormat: 15, | ||
compressed: false | ||
}, | ||
rgba4444: { | ||
basisFormat: 16, | ||
compressed: false | ||
} | ||
etc1: { | ||
basisFormat: 0, | ||
compressed: true, | ||
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL | ||
}, | ||
etc2: { basisFormat: 1, compressed: true }, | ||
bc1: { | ||
basisFormat: 2, | ||
compressed: true, | ||
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT | ||
}, | ||
bc3: { | ||
basisFormat: 3, | ||
compressed: true, | ||
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT | ||
}, | ||
bc4: { basisFormat: 4, compressed: true }, | ||
bc5: { basisFormat: 5, compressed: true }, | ||
'bc7-m6-opaque-only': { basisFormat: 6, compressed: true }, | ||
'bc7-m5': { basisFormat: 7, compressed: true }, | ||
'pvrtc1-4-rgb': { | ||
basisFormat: 8, | ||
compressed: true, | ||
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG | ||
}, | ||
'pvrtc1-4-rgba': { | ||
basisFormat: 9, | ||
compressed: true, | ||
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG | ||
}, | ||
'astc-4x4': { | ||
basisFormat: 10, | ||
compressed: true, | ||
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR | ||
}, | ||
'atc-rgb': { basisFormat: 11, compressed: true }, | ||
'atc-rgba-interpolated-alpha': { basisFormat: 12, compressed: true }, | ||
rgba32: { basisFormat: 13, compressed: false }, | ||
rgb565: { basisFormat: 14, compressed: false }, | ||
bgr565: { basisFormat: 15, compressed: false }, | ||
rgba4444: { basisFormat: 16, compressed: false } | ||
}; | ||
/** | ||
* parse data with a Binomial Basis_Universal module | ||
* @param data | ||
* @param options | ||
* @returns compressed texture data | ||
*/ | ||
export default async function parseBasis(data, options) { | ||
if (options.basis.containerFormat === 'auto') { | ||
if (isKTX(data)) { | ||
const fileConstructors = await loadBasisEncoderModule(options); | ||
return parseKTX2File(fileConstructors.KTX2File, data, options); | ||
if (options.basis.containerFormat === 'auto') { | ||
if (isKTX(data)) { | ||
const fileConstructors = await loadBasisEncoderModule(options); | ||
return parseKTX2File(fileConstructors.KTX2File, data, options); | ||
} | ||
const { BasisFile } = await loadBasisTranscoderModule(options); | ||
return parseBasisFile(BasisFile, data, options); | ||
} | ||
const { | ||
BasisFile | ||
} = await loadBasisTranscoderModule(options); | ||
return parseBasisFile(BasisFile, data, options); | ||
} | ||
switch (options.basis.module) { | ||
case 'encoder': | ||
const fileConstructors = await loadBasisEncoderModule(options); | ||
switch (options.basis.containerFormat) { | ||
case 'ktx2': | ||
return parseKTX2File(fileConstructors.KTX2File, data, options); | ||
case 'basis': | ||
switch (options.basis.module) { | ||
case 'encoder': | ||
const fileConstructors = await loadBasisEncoderModule(options); | ||
switch (options.basis.containerFormat) { | ||
case 'ktx2': | ||
return parseKTX2File(fileConstructors.KTX2File, data, options); | ||
case 'basis': | ||
default: | ||
return parseBasisFile(fileConstructors.BasisFile, data, options); | ||
} | ||
case 'transcoder': | ||
default: | ||
return parseBasisFile(fileConstructors.BasisFile, data, options); | ||
} | ||
case 'transcoder': | ||
default: | ||
const { | ||
BasisFile | ||
} = await loadBasisTranscoderModule(options); | ||
return parseBasisFile(BasisFile, data, options); | ||
} | ||
const { BasisFile } = await loadBasisTranscoderModule(options); | ||
return parseBasisFile(BasisFile, data, options); | ||
} | ||
} | ||
/** | ||
* Parse *.basis file data | ||
* @param BasisFile - initialized transcoder module | ||
* @param data | ||
* @param options | ||
* @returns compressed texture data | ||
*/ | ||
function parseBasisFile(BasisFile, data, options) { | ||
const basisFile = new BasisFile(new Uint8Array(data)); | ||
try { | ||
if (!basisFile.startTranscoding()) { | ||
throw new Error('Failed to start basis transcoding'); | ||
const basisFile = new BasisFile(new Uint8Array(data)); | ||
try { | ||
if (!basisFile.startTranscoding()) { | ||
throw new Error('Failed to start basis transcoding'); | ||
} | ||
const imageCount = basisFile.getNumImages(); | ||
const images = []; | ||
for (let imageIndex = 0; imageIndex < imageCount; imageIndex++) { | ||
const levelsCount = basisFile.getNumLevels(imageIndex); | ||
const levels = []; | ||
for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) { | ||
levels.push(transcodeImage(basisFile, imageIndex, levelIndex, options)); | ||
} | ||
images.push(levels); | ||
} | ||
return images; | ||
} | ||
const imageCount = basisFile.getNumImages(); | ||
const images = []; | ||
for (let imageIndex = 0; imageIndex < imageCount; imageIndex++) { | ||
const levelsCount = basisFile.getNumLevels(imageIndex); | ||
const levels = []; | ||
for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) { | ||
levels.push(transcodeImage(basisFile, imageIndex, levelIndex, options)); | ||
} | ||
images.push(levels); | ||
finally { | ||
basisFile.close(); | ||
basisFile.delete(); | ||
} | ||
return images; | ||
} finally { | ||
basisFile.close(); | ||
basisFile.delete(); | ||
} | ||
} | ||
/** | ||
* Parse the particular level image of a basis file | ||
* @param basisFile | ||
* @param imageIndex | ||
* @param levelIndex | ||
* @param options | ||
* @returns compressed texture data | ||
*/ | ||
function transcodeImage(basisFile, imageIndex, levelIndex, options) { | ||
const width = basisFile.getImageWidth(imageIndex, levelIndex); | ||
const height = basisFile.getImageHeight(imageIndex, levelIndex); | ||
const hasAlpha = basisFile.getHasAlpha(); | ||
const { | ||
compressed, | ||
format, | ||
basisFormat | ||
} = getBasisOptions(options, hasAlpha); | ||
const decodedSize = basisFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, basisFormat); | ||
const decodedData = new Uint8Array(decodedSize); | ||
if (!basisFile.transcodeImage(decodedData, imageIndex, levelIndex, basisFormat, 0, 0)) { | ||
throw new Error('failed to start Basis transcoding'); | ||
} | ||
return { | ||
width, | ||
height, | ||
data: decodedData, | ||
compressed, | ||
format, | ||
hasAlpha | ||
}; | ||
const width = basisFile.getImageWidth(imageIndex, levelIndex); | ||
const height = basisFile.getImageHeight(imageIndex, levelIndex); | ||
// See https://github.com/BinomialLLC/basis_universal/pull/83 | ||
const hasAlpha = basisFile.getHasAlpha( /* imageIndex, levelIndex */); | ||
// Check options for output format etc | ||
const { compressed, format, basisFormat } = getBasisOptions(options, hasAlpha); | ||
const decodedSize = basisFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, basisFormat); | ||
const decodedData = new Uint8Array(decodedSize); | ||
if (!basisFile.transcodeImage(decodedData, imageIndex, levelIndex, basisFormat, 0, 0)) { | ||
throw new Error('failed to start Basis transcoding'); | ||
} | ||
return { | ||
// standard loaders.gl image category payload | ||
width, | ||
height, | ||
data: decodedData, | ||
compressed, | ||
format, | ||
// Additional fields | ||
// Add levelSize field. | ||
hasAlpha | ||
}; | ||
} | ||
/** | ||
* Parse *.ktx2 file data | ||
* @param KTX2File | ||
* @param data | ||
* @param options | ||
* @returns compressed texture data | ||
*/ | ||
function parseKTX2File(KTX2File, data, options) { | ||
const ktx2File = new KTX2File(new Uint8Array(data)); | ||
try { | ||
if (!ktx2File.startTranscoding()) { | ||
throw new Error('failed to start KTX2 transcoding'); | ||
const ktx2File = new KTX2File(new Uint8Array(data)); | ||
try { | ||
if (!ktx2File.startTranscoding()) { | ||
throw new Error('failed to start KTX2 transcoding'); | ||
} | ||
const levelsCount = ktx2File.getLevels(); | ||
const levels = []; | ||
for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) { | ||
levels.push(transcodeKTX2Image(ktx2File, levelIndex, options)); | ||
break; // texture app can only show one level for some reason | ||
} | ||
return [levels]; | ||
} | ||
const levelsCount = ktx2File.getLevels(); | ||
const levels = []; | ||
for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) { | ||
levels.push(transcodeKTX2Image(ktx2File, levelIndex, options)); | ||
break; | ||
finally { | ||
ktx2File.close(); | ||
ktx2File.delete(); | ||
} | ||
return [levels]; | ||
} finally { | ||
ktx2File.close(); | ||
ktx2File.delete(); | ||
} | ||
} | ||
/** | ||
* Parse the particular level image of a ktx2 file | ||
* @param ktx2File | ||
* @param levelIndex | ||
* @param options | ||
* @returns | ||
*/ | ||
function transcodeKTX2Image(ktx2File, levelIndex, options) { | ||
const { | ||
alphaFlag, | ||
height, | ||
width | ||
} = ktx2File.getImageLevelInfo(levelIndex, 0, 0); | ||
const { | ||
compressed, | ||
format, | ||
basisFormat | ||
} = getBasisOptions(options, alphaFlag); | ||
const decodedSize = ktx2File.getImageTranscodedSizeInBytes(levelIndex, 0, 0, basisFormat); | ||
const decodedData = new Uint8Array(decodedSize); | ||
if (!ktx2File.transcodeImage(decodedData, levelIndex, 0, 0, basisFormat, 0, -1, -1)) { | ||
throw new Error('Failed to transcode KTX2 image'); | ||
} | ||
return { | ||
width, | ||
height, | ||
data: decodedData, | ||
compressed, | ||
levelSize: decodedSize, | ||
hasAlpha: alphaFlag, | ||
format | ||
}; | ||
const { alphaFlag, height, width } = ktx2File.getImageLevelInfo(levelIndex, 0, 0); | ||
// Check options for output format etc | ||
const { compressed, format, basisFormat } = getBasisOptions(options, alphaFlag); | ||
const decodedSize = ktx2File.getImageTranscodedSizeInBytes(levelIndex, 0 /* layerIndex */, 0 /* faceIndex */, basisFormat); | ||
const decodedData = new Uint8Array(decodedSize); | ||
if (!ktx2File.transcodeImage(decodedData, levelIndex, 0 /* layerIndex */, 0 /* faceIndex */, basisFormat, 0, -1 /* channel0 */, -1 /* channel1 */)) { | ||
throw new Error('Failed to transcode KTX2 image'); | ||
} | ||
return { | ||
// standard loaders.gl image category payload | ||
width, | ||
height, | ||
data: decodedData, | ||
compressed, | ||
// Additional fields | ||
levelSize: decodedSize, | ||
hasAlpha: alphaFlag, | ||
format | ||
}; | ||
} | ||
/** | ||
* Get BasisFormat by loader format option | ||
* @param options | ||
* @param hasAlpha | ||
* @returns BasisFormat data | ||
*/ | ||
function getBasisOptions(options, hasAlpha) { | ||
let format = options && options.basis && options.basis.format; | ||
if (format === 'auto') { | ||
format = selectSupportedBasisFormat(); | ||
} | ||
if (typeof format === 'object') { | ||
format = hasAlpha ? format.alpha : format.noAlpha; | ||
} | ||
format = format.toLowerCase(); | ||
return OutputFormat[format]; | ||
let format = options && options.basis && options.basis.format; | ||
if (format === 'auto') { | ||
format = selectSupportedBasisFormat(); | ||
} | ||
if (typeof format === 'object') { | ||
format = hasAlpha ? format.alpha : format.noAlpha; | ||
} | ||
format = format.toLowerCase(); | ||
return OutputFormat[format]; | ||
} | ||
/** | ||
* Select transcode format from the list of supported formats | ||
* @returns key for OutputFormat map | ||
*/ | ||
export function selectSupportedBasisFormat() { | ||
const supportedFormats = getSupportedGPUTextureFormats(); | ||
if (supportedFormats.has('astc')) { | ||
return 'astc-4x4'; | ||
} else if (supportedFormats.has('dxt')) { | ||
return { | ||
alpha: 'bc3', | ||
noAlpha: 'bc1' | ||
}; | ||
} else if (supportedFormats.has('pvrtc')) { | ||
return { | ||
alpha: 'pvrtc1-4-rgba', | ||
noAlpha: 'pvrtc1-4-rgb' | ||
}; | ||
} else if (supportedFormats.has('etc1')) { | ||
return 'etc1'; | ||
} else if (supportedFormats.has('etc2')) { | ||
return 'etc2'; | ||
} | ||
return 'rgb565'; | ||
const supportedFormats = getSupportedGPUTextureFormats(); | ||
if (supportedFormats.has('astc')) { | ||
return 'astc-4x4'; | ||
} | ||
else if (supportedFormats.has('dxt')) { | ||
return { | ||
alpha: 'bc3', | ||
noAlpha: 'bc1' | ||
}; | ||
} | ||
else if (supportedFormats.has('pvrtc')) { | ||
return { | ||
alpha: 'pvrtc1-4-rgba', | ||
noAlpha: 'pvrtc1-4-rgb' | ||
}; | ||
} | ||
else if (supportedFormats.has('etc1')) { | ||
return 'etc1'; | ||
} | ||
else if (supportedFormats.has('etc2')) { | ||
return 'etc2'; | ||
} | ||
return 'rgb565'; | ||
} | ||
//# sourceMappingURL=parse-basis.js.map |
@@ -0,16 +1,25 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { isKTX, parseKTX } from "./parse-ktx.js"; | ||
import { isDDS, parseDDS } from "./parse-dds.js"; | ||
import { isPVR, parsePVR } from "./parse-pvr.js"; | ||
/** | ||
* Deduces format and parses compressed texture loaded in ArrayBuffer | ||
* @param data - binary data of compressed texture | ||
* @returns Array of the texture levels | ||
*/ | ||
export function parseCompressedTexture(data) { | ||
if (isKTX(data)) { | ||
return parseKTX(data); | ||
} | ||
if (isDDS(data)) { | ||
return parseDDS(data); | ||
} | ||
if (isPVR(data)) { | ||
return parsePVR(data); | ||
} | ||
throw new Error('Texture container format not recognized'); | ||
if (isKTX(data)) { | ||
// TODO: remove @ts-ignore when `parseKTX` output is normalized to loaders.gl texture format | ||
// @ts-ignore | ||
return parseKTX(data); | ||
} | ||
if (isDDS(data)) { | ||
return parseDDS(data); | ||
} | ||
if (isPVR(data)) { | ||
return parsePVR(data); | ||
} | ||
throw new Error('Texture container format not recognized'); | ||
} | ||
//# sourceMappingURL=parse-compressed-texture.js.map |
@@ -0,1 +1,4 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { loadCrunchModule } from "./crunch-module-loader.js"; | ||
@@ -6,71 +9,98 @@ import { GL_EXTENSIONS_CONSTANTS } from "../gl-extensions.js"; | ||
import { extractMipmapImages } from "../utils/extract-mipmap-images.js"; | ||
// Taken from crnlib.h | ||
const CRN_FORMAT = { | ||
cCRNFmtInvalid: -1, | ||
cCRNFmtDXT1: 0, | ||
cCRNFmtDXT3: 1, | ||
cCRNFmtDXT5: 2 | ||
cCRNFmtInvalid: -1, | ||
cCRNFmtDXT1: 0, | ||
// cCRNFmtDXT3 is not currently supported when writing to CRN - only DDS. | ||
cCRNFmtDXT3: 1, | ||
cCRNFmtDXT5: 2 | ||
// Crunch supports more formats than this. | ||
}; | ||
/** Mapping of Crunch formats to DXT formats. */ | ||
const DXT_FORMAT_MAP = { | ||
[CRN_FORMAT.cCRNFmtDXT1]: { | ||
pixelFormat: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT, | ||
sizeFunction: getDxt1LevelSize | ||
}, | ||
[CRN_FORMAT.cCRNFmtDXT3]: { | ||
pixelFormat: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT, | ||
sizeFunction: getDxtXLevelSize | ||
}, | ||
[CRN_FORMAT.cCRNFmtDXT5]: { | ||
pixelFormat: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT, | ||
sizeFunction: getDxtXLevelSize | ||
} | ||
[CRN_FORMAT.cCRNFmtDXT1]: { | ||
pixelFormat: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT, | ||
sizeFunction: getDxt1LevelSize | ||
}, | ||
[CRN_FORMAT.cCRNFmtDXT3]: { | ||
pixelFormat: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT, | ||
sizeFunction: getDxtXLevelSize | ||
}, | ||
[CRN_FORMAT.cCRNFmtDXT5]: { | ||
pixelFormat: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT, | ||
sizeFunction: getDxtXLevelSize | ||
} | ||
}; | ||
let cachedDstSize = 0; | ||
let dst; | ||
/** | ||
* Parse texture data as "CRN" format. | ||
* Function is "async" as emscriptified decoder module is loaded asyncronously | ||
* @param data - binary data of compressed texture | ||
* @returns Promise of Array of the texture levels | ||
*/ | ||
export async function parseCrunch(data, options) { | ||
const crunchModule = await loadCrunchModule(options); | ||
const srcSize = data.byteLength; | ||
const bytes = new Uint8Array(data); | ||
const src = crunchModule._malloc(srcSize); | ||
arrayBufferCopy(bytes, crunchModule.HEAPU8, src, srcSize); | ||
const format = crunchModule._crn_get_dxt_format(src, srcSize); | ||
assert(Boolean(DXT_FORMAT_MAP[format]), 'Unsupported format'); | ||
const mipMapLevels = crunchModule._crn_get_levels(src, srcSize); | ||
const width = crunchModule._crn_get_width(src, srcSize); | ||
const height = crunchModule._crn_get_height(src, srcSize); | ||
const sizeFunction = DXT_FORMAT_MAP[format].sizeFunction; | ||
let dstSize = 0; | ||
for (let i = 0; i < mipMapLevels; ++i) { | ||
dstSize += sizeFunction(width >> i, height >> i); | ||
} | ||
if (cachedDstSize < dstSize) { | ||
if (dst) { | ||
crunchModule._free(dst); | ||
const crunchModule = await loadCrunchModule(options); | ||
// Copy the contents of the arrayBuffer into emscriptens heap. | ||
const srcSize = data.byteLength; | ||
const bytes = new Uint8Array(data); | ||
const src = crunchModule._malloc(srcSize); | ||
arrayBufferCopy(bytes, crunchModule.HEAPU8, src, srcSize); | ||
// Determine what type of compressed data the file contains. | ||
const format = crunchModule._crn_get_dxt_format(src, srcSize); | ||
assert(Boolean(DXT_FORMAT_MAP[format]), 'Unsupported format'); | ||
// Gather basic metrics about the DXT data. | ||
const mipMapLevels = crunchModule._crn_get_levels(src, srcSize); | ||
const width = crunchModule._crn_get_width(src, srcSize); | ||
const height = crunchModule._crn_get_height(src, srcSize); | ||
// const bytesPerBlock = crunchModule._crn_get_bytes_per_block(src, srcSize); | ||
// Determine the size of the decoded DXT data. | ||
const sizeFunction = DXT_FORMAT_MAP[format].sizeFunction; | ||
let dstSize = 0; | ||
for (let i = 0; i < mipMapLevels; ++i) { | ||
dstSize += sizeFunction(width >> i, height >> i); | ||
} | ||
dst = crunchModule._malloc(dstSize); | ||
cachedDstSize = dstSize; | ||
} | ||
crunchModule._crn_decompress(src, srcSize, dst, dstSize, 0, mipMapLevels); | ||
crunchModule._free(src); | ||
const image = new Uint8Array(crunchModule.HEAPU8.buffer, dst, dstSize).slice(); | ||
return extractMipmapImages(image, { | ||
mipMapLevels, | ||
width, | ||
height, | ||
sizeFunction, | ||
internalFormat: DXT_FORMAT_MAP[format].pixelFormat | ||
}); | ||
// Allocate enough space on the emscripten heap to hold the decoded DXT data | ||
// or reuse the existing allocation if a previous call to this function has | ||
// already acquired a large enough buffer. | ||
if (cachedDstSize < dstSize) { | ||
if (dst) { | ||
crunchModule._free(dst); | ||
} | ||
dst = crunchModule._malloc(dstSize); | ||
cachedDstSize = dstSize; | ||
} | ||
// Decompress the DXT data from the Crunch file into the allocated space. | ||
crunchModule._crn_decompress(src, srcSize, dst, dstSize, 0, mipMapLevels); | ||
// Release the crunch file data from the emscripten heap. | ||
crunchModule._free(src); | ||
const image = new Uint8Array(crunchModule.HEAPU8.buffer, dst, dstSize).slice(); | ||
return extractMipmapImages(image, { | ||
mipMapLevels, | ||
width, | ||
height, | ||
sizeFunction, | ||
internalFormat: DXT_FORMAT_MAP[format].pixelFormat | ||
}); | ||
} | ||
/** | ||
* Copy an array of bytes into or out of the emscripten heap | ||
* @param {Uint8Array} srcData - Source data array | ||
* @param {Uint8Array} dstData - Destination data array | ||
* @param {number} dstByteOffset - Destination data offset | ||
* @param {number} numBytes - number of bytes to copy | ||
* @returns {void} | ||
*/ | ||
function arrayBufferCopy(srcData, dstData, dstByteOffset, numBytes) { | ||
let i; | ||
const dst32Offset = dstByteOffset / 4; | ||
const tail = numBytes % 4; | ||
const src32 = new Uint32Array(srcData.buffer, 0, (numBytes - tail) / 4); | ||
const dst32 = new Uint32Array(dstData.buffer); | ||
for (i = 0; i < src32.length; i++) { | ||
dst32[dst32Offset + i] = src32[i]; | ||
} | ||
for (i = numBytes - tail; i < numBytes; i++) { | ||
dstData[dstByteOffset + i] = srcData[i]; | ||
} | ||
let i; | ||
const dst32Offset = dstByteOffset / 4; | ||
const tail = numBytes % 4; | ||
const src32 = new Uint32Array(srcData.buffer, 0, (numBytes - tail) / 4); | ||
const dst32 = new Uint32Array(dstData.buffer); | ||
for (i = 0; i < src32.length; i++) { | ||
dst32[dst32Offset + i] = src32[i]; | ||
} | ||
for (i = numBytes - tail; i < numBytes; i++) { | ||
dstData[dstByteOffset + i] = srcData[i]; | ||
} | ||
} | ||
//# sourceMappingURL=parse-crunch.js.map |
@@ -0,1 +1,4 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { assert } from '@loaders.gl/loader-utils'; | ||
@@ -5,22 +8,22 @@ import { GL_EXTENSIONS_CONSTANTS } from "../gl-extensions.js"; | ||
const DDS_CONSTANTS = { | ||
MAGIC_NUMBER: 0x20534444, | ||
HEADER_LENGTH: 31, | ||
MAGIC_NUMBER_INDEX: 0, | ||
HEADER_SIZE_INDEX: 1, | ||
HEADER_FLAGS_INDEX: 2, | ||
HEADER_HEIGHT_INDEX: 3, | ||
HEADER_WIDTH_INDEX: 4, | ||
MIPMAPCOUNT_INDEX: 7, | ||
HEADER_PF_FLAGS_INDEX: 20, | ||
HEADER_PF_FOURCC_INDEX: 21, | ||
DDSD_MIPMAPCOUNT: 0x20000, | ||
DDPF_FOURCC: 0x4 | ||
MAGIC_NUMBER: 0x20534444, | ||
HEADER_LENGTH: 31, | ||
MAGIC_NUMBER_INDEX: 0, | ||
HEADER_SIZE_INDEX: 1, | ||
HEADER_FLAGS_INDEX: 2, | ||
HEADER_HEIGHT_INDEX: 3, | ||
HEADER_WIDTH_INDEX: 4, | ||
MIPMAPCOUNT_INDEX: 7, | ||
HEADER_PF_FLAGS_INDEX: 20, | ||
HEADER_PF_FOURCC_INDEX: 21, | ||
DDSD_MIPMAPCOUNT: 0x20000, | ||
DDPF_FOURCC: 0x4 | ||
}; | ||
const DDS_PIXEL_FORMATS = { | ||
DXT1: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT, | ||
DXT3: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT, | ||
DXT5: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT, | ||
'ATC ': GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ATC_WEBGL, | ||
ATCA: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL, | ||
ATCI: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL | ||
DXT1: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT, | ||
DXT3: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT, | ||
DXT5: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT, | ||
'ATC ': GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ATC_WEBGL, | ||
ATCA: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL, | ||
ATCI: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL | ||
}; | ||
@@ -31,47 +34,73 @@ const getATCLevelSize = getDxt1LevelSize; | ||
const DDS_SIZE_FUNCTIONS = { | ||
DXT1: getDxt1LevelSize, | ||
DXT3: getDxtXLevelSize, | ||
DXT5: getDxtXLevelSize, | ||
'ATC ': getATCLevelSize, | ||
ATCA: getATCALevelSize, | ||
ATCI: getATCILevelSize | ||
DXT1: getDxt1LevelSize, | ||
DXT3: getDxtXLevelSize, | ||
DXT5: getDxtXLevelSize, | ||
'ATC ': getATCLevelSize, | ||
ATCA: getATCALevelSize, | ||
ATCI: getATCILevelSize | ||
}; | ||
/** | ||
* Check if data is in "DDS" format by its magic number | ||
* @param data - binary data of compressed texture | ||
* @returns true - data in "DDS" format, else - false | ||
*/ | ||
export function isDDS(data) { | ||
const header = new Uint32Array(data, 0, DDS_CONSTANTS.HEADER_LENGTH); | ||
const magic = header[DDS_CONSTANTS.MAGIC_NUMBER_INDEX]; | ||
return magic === DDS_CONSTANTS.MAGIC_NUMBER; | ||
const header = new Uint32Array(data, 0, DDS_CONSTANTS.HEADER_LENGTH); | ||
const magic = header[DDS_CONSTANTS.MAGIC_NUMBER_INDEX]; | ||
return magic === DDS_CONSTANTS.MAGIC_NUMBER; | ||
} | ||
/** | ||
* Parse texture data as "DDS" format | ||
* @param data - binary data of compressed texture | ||
* @returns Array of the texture levels | ||
*/ | ||
export function parseDDS(data) { | ||
const header = new Int32Array(data, 0, DDS_CONSTANTS.HEADER_LENGTH); | ||
const pixelFormatNumber = header[DDS_CONSTANTS.HEADER_PF_FOURCC_INDEX]; | ||
assert(Boolean(header[DDS_CONSTANTS.HEADER_PF_FLAGS_INDEX] & DDS_CONSTANTS.DDPF_FOURCC), 'DDS: Unsupported format, must contain a FourCC code'); | ||
const fourCC = int32ToFourCC(pixelFormatNumber); | ||
const internalFormat = DDS_PIXEL_FORMATS[fourCC]; | ||
const sizeFunction = DDS_SIZE_FUNCTIONS[fourCC]; | ||
assert(internalFormat && sizeFunction, `DDS: Unknown pixel format ${pixelFormatNumber}`); | ||
let mipMapLevels = 1; | ||
if (header[DDS_CONSTANTS.HEADER_FLAGS_INDEX] & DDS_CONSTANTS.DDSD_MIPMAPCOUNT) { | ||
mipMapLevels = Math.max(1, header[DDS_CONSTANTS.MIPMAPCOUNT_INDEX]); | ||
} | ||
const width = header[DDS_CONSTANTS.HEADER_WIDTH_INDEX]; | ||
const height = header[DDS_CONSTANTS.HEADER_HEIGHT_INDEX]; | ||
const dataOffset = header[DDS_CONSTANTS.HEADER_SIZE_INDEX] + 4; | ||
const image = new Uint8Array(data, dataOffset); | ||
return extractMipmapImages(image, { | ||
mipMapLevels, | ||
width, | ||
height, | ||
sizeFunction, | ||
internalFormat | ||
}); | ||
const header = new Int32Array(data, 0, DDS_CONSTANTS.HEADER_LENGTH); | ||
const pixelFormatNumber = header[DDS_CONSTANTS.HEADER_PF_FOURCC_INDEX]; | ||
assert(Boolean(header[DDS_CONSTANTS.HEADER_PF_FLAGS_INDEX] & DDS_CONSTANTS.DDPF_FOURCC), 'DDS: Unsupported format, must contain a FourCC code'); | ||
const fourCC = int32ToFourCC(pixelFormatNumber); | ||
const internalFormat = DDS_PIXEL_FORMATS[fourCC]; | ||
const sizeFunction = DDS_SIZE_FUNCTIONS[fourCC]; | ||
assert(internalFormat && sizeFunction, `DDS: Unknown pixel format ${pixelFormatNumber}`); | ||
let mipMapLevels = 1; | ||
if (header[DDS_CONSTANTS.HEADER_FLAGS_INDEX] & DDS_CONSTANTS.DDSD_MIPMAPCOUNT) { | ||
mipMapLevels = Math.max(1, header[DDS_CONSTANTS.MIPMAPCOUNT_INDEX]); | ||
} | ||
const width = header[DDS_CONSTANTS.HEADER_WIDTH_INDEX]; | ||
const height = header[DDS_CONSTANTS.HEADER_HEIGHT_INDEX]; | ||
const dataOffset = header[DDS_CONSTANTS.HEADER_SIZE_INDEX] + 4; | ||
const image = new Uint8Array(data, dataOffset); | ||
return extractMipmapImages(image, { | ||
mipMapLevels, | ||
width, | ||
height, | ||
sizeFunction, | ||
internalFormat | ||
}); | ||
} | ||
/** | ||
* DXT1 applicable function to calculate level size | ||
* @param width - level width | ||
* @param height - level height | ||
* @returns level size in bytes | ||
*/ | ||
export function getDxt1LevelSize(width, height) { | ||
return (width + 3 >> 2) * (height + 3 >> 2) * 8; | ||
return ((width + 3) >> 2) * ((height + 3) >> 2) * 8; | ||
} | ||
/** | ||
* DXT3 & DXT5 applicable function to calculate level size | ||
* @param width - level width | ||
* @param height - level height | ||
* @returns level size in bytes | ||
*/ | ||
export function getDxtXLevelSize(width, height) { | ||
return (width + 3 >> 2) * (height + 3 >> 2) * 16; | ||
return ((width + 3) >> 2) * ((height + 3) >> 2) * 16; | ||
} | ||
/** | ||
* Convert every byte of Int32 value to char | ||
* @param value - Int32 number | ||
* @returns string of 4 characters | ||
*/ | ||
function int32ToFourCC(value) { | ||
return String.fromCharCode(value & 0xff, value >> 8 & 0xff, value >> 16 & 0xff, value >> 24 & 0xff); | ||
return String.fromCharCode(value & 0xff, (value >> 8) & 0xff, (value >> 16) & 0xff, (value >> 24) & 0xff); | ||
} | ||
//# sourceMappingURL=parse-dds.js.map |
@@ -0,25 +1,44 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { read } from 'ktx-parse'; | ||
import { extractMipmapImages } from "../utils/extract-mipmap-images.js"; | ||
import { mapVkFormatToWebGL } from "../utils/ktx-format-helper.js"; | ||
const KTX2_ID = [0xab, 0x4b, 0x54, 0x58, 0x20, 0x32, 0x30, 0xbb, 0x0d, 0x0a, 0x1a, 0x0a]; | ||
const KTX2_ID = [ | ||
// '´', 'K', 'T', 'X', '2', '0', 'ª', '\r', '\n', '\x1A', '\n' | ||
0xab, 0x4b, 0x54, 0x58, 0x20, 0x32, 0x30, 0xbb, 0x0d, 0x0a, 0x1a, 0x0a | ||
]; | ||
// eslint-disable-next-line complexity | ||
export function isKTX(data) { | ||
const id = new Uint8Array(data); | ||
const notKTX = id.byteLength < KTX2_ID.length || id[0] !== KTX2_ID[0] || id[1] !== KTX2_ID[1] || id[2] !== KTX2_ID[2] || id[3] !== KTX2_ID[3] || id[4] !== KTX2_ID[4] || id[5] !== KTX2_ID[5] || id[6] !== KTX2_ID[6] || id[7] !== KTX2_ID[7] || id[8] !== KTX2_ID[8] || id[9] !== KTX2_ID[9] || id[10] !== KTX2_ID[10] || id[11] !== KTX2_ID[11]; | ||
return !notKTX; | ||
// const id = new Uint8Array(data.buffer, data.byteOffset, data.byteLength); | ||
const id = new Uint8Array(data); | ||
const notKTX = id.byteLength < KTX2_ID.length || | ||
id[0] !== KTX2_ID[0] || // '´' | ||
id[1] !== KTX2_ID[1] || // 'K' | ||
id[2] !== KTX2_ID[2] || // 'T' | ||
id[3] !== KTX2_ID[3] || // 'X' | ||
id[4] !== KTX2_ID[4] || // ' ' | ||
id[5] !== KTX2_ID[5] || // '2' | ||
id[6] !== KTX2_ID[6] || // '0' | ||
id[7] !== KTX2_ID[7] || // 'ª' | ||
id[8] !== KTX2_ID[8] || // '\r' | ||
id[9] !== KTX2_ID[9] || // '\n' | ||
id[10] !== KTX2_ID[10] || // '\x1A' | ||
id[11] !== KTX2_ID[11]; // '\n' | ||
return !notKTX; | ||
} | ||
export function parseKTX(arrayBuffer) { | ||
const uint8Array = new Uint8Array(arrayBuffer); | ||
const ktx = read(uint8Array); | ||
const mipMapLevels = Math.max(1, ktx.levels.length); | ||
const width = ktx.pixelWidth; | ||
const height = ktx.pixelHeight; | ||
const internalFormat = mapVkFormatToWebGL(ktx.vkFormat); | ||
return extractMipmapImages(ktx.levels, { | ||
mipMapLevels, | ||
width, | ||
height, | ||
sizeFunction: level => level.uncompressedByteLength, | ||
internalFormat | ||
}); | ||
const uint8Array = new Uint8Array(arrayBuffer); | ||
const ktx = read(uint8Array); | ||
const mipMapLevels = Math.max(1, ktx.levels.length); | ||
const width = ktx.pixelWidth; | ||
const height = ktx.pixelHeight; | ||
const internalFormat = mapVkFormatToWebGL(ktx.vkFormat); | ||
return extractMipmapImages(ktx.levels, { | ||
mipMapLevels, | ||
width, | ||
height, | ||
sizeFunction: (level) => level.uncompressedByteLength, | ||
internalFormat | ||
}); | ||
} | ||
//# sourceMappingURL=parse-ktx.js.map |
@@ -0,1 +1,4 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
const a = new Uint32Array([0x12345678]); | ||
@@ -5,60 +8,74 @@ const b = new Uint8Array(a.buffer, a.byteOffset, a.byteLength); | ||
const LITTLE_ENDIAN_OS = isLittleEndian; | ||
/** | ||
* The basic string format consists of 3 characters: | ||
* 1. a character describing the byteorder of the data (<: little-endian, >: big-endian, |: not-relevant) | ||
* 2. a character code giving the basic type of the array | ||
* 3. an integer providing the number of bytes the type uses. | ||
* https://numpy.org/doc/stable/reference/arrays.interface.html | ||
* | ||
* Here I only include the second and third characters, and check endianness separately | ||
*/ | ||
const DTYPES = { | ||
u1: Uint8Array, | ||
i1: Int8Array, | ||
u2: Uint16Array, | ||
i2: Int16Array, | ||
u4: Uint32Array, | ||
i4: Int32Array, | ||
f4: Float32Array, | ||
f8: Float64Array | ||
u1: Uint8Array, | ||
i1: Int8Array, | ||
u2: Uint16Array, | ||
i2: Int16Array, | ||
u4: Uint32Array, | ||
i4: Int32Array, | ||
f4: Float32Array, | ||
f8: Float64Array | ||
}; | ||
export function parseNPY(arrayBuffer, options) { | ||
var _header$shape; | ||
const view = new DataView(arrayBuffer); | ||
const { | ||
header, | ||
headerEndOffset | ||
} = parseHeader(view); | ||
const numpyType = header.descr; | ||
const ArrayType = DTYPES[numpyType.slice(1, 3)]; | ||
if (!ArrayType) { | ||
throw new Error(`Unimplemented type ${numpyType}`); | ||
} | ||
const nArrayElements = (_header$shape = header.shape) === null || _header$shape === void 0 ? void 0 : _header$shape.reduce((a, b) => a * b); | ||
const arrayByteLength = nArrayElements * ArrayType.BYTES_PER_ELEMENT; | ||
if (arrayBuffer.byteLength < headerEndOffset + arrayByteLength) { | ||
throw new Error('Buffer overflow'); | ||
} | ||
const data = new ArrayType(arrayBuffer.slice(headerEndOffset, headerEndOffset + arrayByteLength)); | ||
if (numpyType[0] === '>' && LITTLE_ENDIAN_OS || numpyType[0] === '<' && !LITTLE_ENDIAN_OS) { | ||
throw new Error('Incorrect endianness'); | ||
} | ||
return { | ||
data, | ||
header | ||
}; | ||
const view = new DataView(arrayBuffer); | ||
const { header, headerEndOffset } = parseHeader(view); | ||
const numpyType = header.descr; | ||
const ArrayType = DTYPES[numpyType.slice(1, 3)]; | ||
if (!ArrayType) { | ||
throw new Error(`Unimplemented type ${numpyType}`); | ||
} | ||
const nArrayElements = header.shape?.reduce((a, b) => a * b); | ||
const arrayByteLength = nArrayElements * ArrayType.BYTES_PER_ELEMENT; | ||
if (arrayBuffer.byteLength < headerEndOffset + arrayByteLength) { | ||
throw new Error('Buffer overflow'); | ||
} | ||
const data = new ArrayType(arrayBuffer.slice(headerEndOffset, headerEndOffset + arrayByteLength)); | ||
// Swap endianness if needed | ||
if ((numpyType[0] === '>' && LITTLE_ENDIAN_OS) || (numpyType[0] === '<' && !LITTLE_ENDIAN_OS)) { | ||
throw new Error('Incorrect endianness'); | ||
} | ||
return { | ||
data, | ||
header | ||
}; | ||
} | ||
/** | ||
* Parse NPY header | ||
* | ||
* @param view | ||
* @return | ||
*/ | ||
function parseHeader(view) { | ||
const majorVersion = view.getUint8(6); | ||
let offset = 8; | ||
let headerLength; | ||
if (majorVersion >= 2) { | ||
headerLength = view.getUint32(offset, true); | ||
offset += 4; | ||
} else { | ||
headerLength = view.getUint16(offset, true); | ||
offset += 2; | ||
} | ||
const encoding = majorVersion <= 2 ? 'latin1' : 'utf-8'; | ||
const decoder = new TextDecoder(encoding); | ||
const headerArray = new Uint8Array(view.buffer, offset, headerLength); | ||
const headerText = decoder.decode(headerArray); | ||
offset += headerLength; | ||
const header = JSON.parse(headerText.replace(/'/g, '"').replace('False', 'false').replace('(', '[').replace(/,*\),*/g, ']')); | ||
return { | ||
header, | ||
headerEndOffset: offset | ||
}; | ||
const majorVersion = view.getUint8(6); | ||
// const minorVersion = view.getUint8(7); | ||
let offset = 8; | ||
let headerLength; | ||
if (majorVersion >= 2) { | ||
headerLength = view.getUint32(offset, true); | ||
offset += 4; | ||
} | ||
else { | ||
headerLength = view.getUint16(offset, true); | ||
offset += 2; | ||
} | ||
const encoding = majorVersion <= 2 ? 'latin1' : 'utf-8'; | ||
const decoder = new TextDecoder(encoding); | ||
const headerArray = new Uint8Array(view.buffer, offset, headerLength); | ||
const headerText = decoder.decode(headerArray); | ||
offset += headerLength; | ||
const header = JSON.parse(headerText | ||
.replace(/'/g, '"') | ||
.replace('False', 'false') | ||
.replace('(', '[') | ||
.replace(/,*\),*/g, ']')); | ||
return { header, headerEndOffset: offset }; | ||
} | ||
//# sourceMappingURL=parse-npy.js.map |
@@ -0,154 +1,245 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { GL_EXTENSIONS_CONSTANTS } from "../gl-extensions.js"; | ||
import { extractMipmapImages } from "../utils/extract-mipmap-images.js"; | ||
const PVR_CONSTANTS = { | ||
MAGIC_NUMBER: 0x03525650, | ||
MAGIC_NUMBER_EXTRA: 0x50565203, | ||
HEADER_LENGTH: 13, | ||
HEADER_SIZE: 52, | ||
MAGIC_NUMBER_INDEX: 0, | ||
PIXEL_FORMAT_INDEX: 2, | ||
COLOUR_SPACE_INDEX: 4, | ||
HEIGHT_INDEX: 6, | ||
WIDTH_INDEX: 7, | ||
MIPMAPCOUNT_INDEX: 11, | ||
METADATA_SIZE_INDEX: 12 | ||
MAGIC_NUMBER: 0x03525650, | ||
MAGIC_NUMBER_EXTRA: 0x50565203, | ||
HEADER_LENGTH: 13, | ||
HEADER_SIZE: 52, | ||
MAGIC_NUMBER_INDEX: 0, | ||
PIXEL_FORMAT_INDEX: 2, | ||
COLOUR_SPACE_INDEX: 4, | ||
HEIGHT_INDEX: 6, | ||
WIDTH_INDEX: 7, | ||
MIPMAPCOUNT_INDEX: 11, | ||
METADATA_SIZE_INDEX: 12 | ||
}; | ||
const PVR_PIXEL_FORMATS = { | ||
0: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_2BPPV1_IMG], | ||
1: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG], | ||
2: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG], | ||
3: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG], | ||
6: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL], | ||
7: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT], | ||
9: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT], | ||
11: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT], | ||
22: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_ETC2], | ||
23: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA8_ETC2_EAC], | ||
24: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2], | ||
25: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_R11_EAC], | ||
26: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RG11_EAC], | ||
27: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR, GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR], | ||
28: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X4_KHR, GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR], | ||
29: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X5_KHR, GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR], | ||
30: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X5_KHR, GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR], | ||
31: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X6_KHR, GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR], | ||
32: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X5_KHR, GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR], | ||
33: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X6_KHR, GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR], | ||
34: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X8_KHR, GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR], | ||
35: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X5_KHR, GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR], | ||
36: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X6_KHR, GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR], | ||
37: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X8_KHR, GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR], | ||
38: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X10_KHR, GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR], | ||
39: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X10_KHR, GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR], | ||
40: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X12_KHR, GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR] | ||
0: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_2BPPV1_IMG], | ||
1: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG], | ||
2: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG], | ||
3: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG], | ||
6: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL], | ||
7: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT], | ||
9: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT], | ||
11: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT], | ||
22: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_ETC2], | ||
23: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA8_ETC2_EAC], | ||
24: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2], | ||
25: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_R11_EAC], | ||
26: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RG11_EAC], | ||
27: [ | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR, | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR | ||
], | ||
28: [ | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X4_KHR, | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR | ||
], | ||
29: [ | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X5_KHR, | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR | ||
], | ||
30: [ | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X5_KHR, | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR | ||
], | ||
31: [ | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X6_KHR, | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR | ||
], | ||
32: [ | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X5_KHR, | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR | ||
], | ||
33: [ | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X6_KHR, | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR | ||
], | ||
34: [ | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X8_KHR, | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR | ||
], | ||
35: [ | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X5_KHR, | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR | ||
], | ||
36: [ | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X6_KHR, | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR | ||
], | ||
37: [ | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X8_KHR, | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR | ||
], | ||
38: [ | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X10_KHR, | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR | ||
], | ||
39: [ | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X10_KHR, | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR | ||
], | ||
40: [ | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X12_KHR, | ||
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR | ||
] | ||
}; | ||
const PVR_SIZE_FUNCTIONS = { | ||
0: pvrtc2bppSize, | ||
1: pvrtc2bppSize, | ||
2: pvrtc4bppSize, | ||
3: pvrtc4bppSize, | ||
6: dxtEtcSmallSize, | ||
7: dxtEtcSmallSize, | ||
9: dxtEtcAstcBigSize, | ||
11: dxtEtcAstcBigSize, | ||
22: dxtEtcSmallSize, | ||
23: dxtEtcAstcBigSize, | ||
24: dxtEtcSmallSize, | ||
25: dxtEtcSmallSize, | ||
26: dxtEtcAstcBigSize, | ||
27: dxtEtcAstcBigSize, | ||
28: atc5x4Size, | ||
29: atc5x5Size, | ||
30: atc6x5Size, | ||
31: atc6x6Size, | ||
32: atc8x5Size, | ||
33: atc8x6Size, | ||
34: atc8x8Size, | ||
35: atc10x5Size, | ||
36: atc10x6Size, | ||
37: atc10x8Size, | ||
38: atc10x10Size, | ||
39: atc12x10Size, | ||
40: atc12x12Size | ||
0: pvrtc2bppSize, | ||
1: pvrtc2bppSize, | ||
2: pvrtc4bppSize, | ||
3: pvrtc4bppSize, | ||
6: dxtEtcSmallSize, | ||
7: dxtEtcSmallSize, | ||
9: dxtEtcAstcBigSize, | ||
11: dxtEtcAstcBigSize, | ||
22: dxtEtcSmallSize, | ||
23: dxtEtcAstcBigSize, | ||
24: dxtEtcSmallSize, | ||
25: dxtEtcSmallSize, | ||
26: dxtEtcAstcBigSize, | ||
27: dxtEtcAstcBigSize, | ||
28: atc5x4Size, | ||
29: atc5x5Size, | ||
30: atc6x5Size, | ||
31: atc6x6Size, | ||
32: atc8x5Size, | ||
33: atc8x6Size, | ||
34: atc8x8Size, | ||
35: atc10x5Size, | ||
36: atc10x6Size, | ||
37: atc10x8Size, | ||
38: atc10x10Size, | ||
39: atc12x10Size, | ||
40: atc12x12Size | ||
}; | ||
/** | ||
* Check if data is in "PVR" format by its magic number | ||
* @param data - binary data of compressed texture | ||
* @returns true - data in "PVR" format, else - false | ||
*/ | ||
export function isPVR(data) { | ||
const header = new Uint32Array(data, 0, PVR_CONSTANTS.HEADER_LENGTH); | ||
const version = header[PVR_CONSTANTS.MAGIC_NUMBER_INDEX]; | ||
return version === PVR_CONSTANTS.MAGIC_NUMBER || version === PVR_CONSTANTS.MAGIC_NUMBER_EXTRA; | ||
const header = new Uint32Array(data, 0, PVR_CONSTANTS.HEADER_LENGTH); | ||
const version = header[PVR_CONSTANTS.MAGIC_NUMBER_INDEX]; | ||
return version === PVR_CONSTANTS.MAGIC_NUMBER || version === PVR_CONSTANTS.MAGIC_NUMBER_EXTRA; | ||
} | ||
/** | ||
* Parse texture data as "PVR" format | ||
* @param data - binary data of compressed texture | ||
* @returns Array of the texture levels | ||
* @see http://cdn.imgtec.com/sdk-documentation/PVR+File+Format.Specification.pdf | ||
*/ | ||
export function parsePVR(data) { | ||
const header = new Uint32Array(data, 0, PVR_CONSTANTS.HEADER_LENGTH); | ||
const pvrFormat = header[PVR_CONSTANTS.PIXEL_FORMAT_INDEX]; | ||
const colourSpace = header[PVR_CONSTANTS.COLOUR_SPACE_INDEX]; | ||
const pixelFormats = PVR_PIXEL_FORMATS[pvrFormat] || []; | ||
const internalFormat = pixelFormats.length > 1 && colourSpace ? pixelFormats[1] : pixelFormats[0]; | ||
const sizeFunction = PVR_SIZE_FUNCTIONS[pvrFormat]; | ||
const mipMapLevels = header[PVR_CONSTANTS.MIPMAPCOUNT_INDEX]; | ||
const width = header[PVR_CONSTANTS.WIDTH_INDEX]; | ||
const height = header[PVR_CONSTANTS.HEIGHT_INDEX]; | ||
const dataOffset = PVR_CONSTANTS.HEADER_SIZE + header[PVR_CONSTANTS.METADATA_SIZE_INDEX]; | ||
const image = new Uint8Array(data, dataOffset); | ||
return extractMipmapImages(image, { | ||
mipMapLevels, | ||
width, | ||
height, | ||
sizeFunction, | ||
internalFormat | ||
}); | ||
const header = new Uint32Array(data, 0, PVR_CONSTANTS.HEADER_LENGTH); | ||
const pvrFormat = header[PVR_CONSTANTS.PIXEL_FORMAT_INDEX]; | ||
const colourSpace = header[PVR_CONSTANTS.COLOUR_SPACE_INDEX]; | ||
const pixelFormats = PVR_PIXEL_FORMATS[pvrFormat] || []; | ||
const internalFormat = pixelFormats.length > 1 && colourSpace ? pixelFormats[1] : pixelFormats[0]; | ||
const sizeFunction = PVR_SIZE_FUNCTIONS[pvrFormat]; | ||
const mipMapLevels = header[PVR_CONSTANTS.MIPMAPCOUNT_INDEX]; | ||
const width = header[PVR_CONSTANTS.WIDTH_INDEX]; | ||
const height = header[PVR_CONSTANTS.HEIGHT_INDEX]; | ||
const dataOffset = PVR_CONSTANTS.HEADER_SIZE + header[PVR_CONSTANTS.METADATA_SIZE_INDEX]; | ||
const image = new Uint8Array(data, dataOffset); | ||
return extractMipmapImages(image, { | ||
mipMapLevels, | ||
width, | ||
height, | ||
sizeFunction, | ||
internalFormat | ||
}); | ||
} | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_pvrtc/ | ||
function pvrtc2bppSize(width, height) { | ||
width = Math.max(width, 16); | ||
height = Math.max(height, 8); | ||
return width * height / 4; | ||
width = Math.max(width, 16); | ||
height = Math.max(height, 8); | ||
return (width * height) / 4; | ||
} | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_pvrtc/ | ||
function pvrtc4bppSize(width, height) { | ||
width = Math.max(width, 8); | ||
height = Math.max(height, 8); | ||
return width * height / 2; | ||
width = Math.max(width, 8); | ||
height = Math.max(height, 8); | ||
return (width * height) / 2; | ||
} | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_s3tc/ | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_etc/ | ||
// Size for: | ||
// COMPRESSED_RGB_S3TC_DXT1_EXT | ||
// COMPRESSED_R11_EAC | ||
// COMPRESSED_SIGNED_R11_EAC | ||
// COMPRESSED_RGB8_ETC2 | ||
// COMPRESSED_SRGB8_ETC2 | ||
// COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 | ||
// COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 | ||
function dxtEtcSmallSize(width, height) { | ||
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 8; | ||
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 8; | ||
} | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_s3tc/ | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_etc/ | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/ | ||
// Size for: | ||
// COMPRESSED_RGBA_S3TC_DXT3_EXT | ||
// COMPRESSED_RGBA_S3TC_DXT5_EXT | ||
// COMPRESSED_RG11_EAC | ||
// COMPRESSED_SIGNED_RG11_EAC | ||
// COMPRESSED_RGBA8_ETC2_EAC | ||
// COMPRESSED_SRGB8_ALPHA8_ETC2_EAC | ||
// COMPRESSED_RGBA_ASTC_4x4_KHR | ||
function dxtEtcAstcBigSize(width, height) { | ||
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 16; | ||
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 16; | ||
} | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/ | ||
function atc5x4Size(width, height) { | ||
return Math.floor((width + 4) / 5) * Math.floor((height + 3) / 4) * 16; | ||
return Math.floor((width + 4) / 5) * Math.floor((height + 3) / 4) * 16; | ||
} | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/ | ||
function atc5x5Size(width, height) { | ||
return Math.floor((width + 4) / 5) * Math.floor((height + 4) / 5) * 16; | ||
return Math.floor((width + 4) / 5) * Math.floor((height + 4) / 5) * 16; | ||
} | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/ | ||
function atc6x5Size(width, height) { | ||
return Math.floor((width + 5) / 6) * Math.floor((height + 4) / 5) * 16; | ||
return Math.floor((width + 5) / 6) * Math.floor((height + 4) / 5) * 16; | ||
} | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/ | ||
function atc6x6Size(width, height) { | ||
return Math.floor((width + 5) / 6) * Math.floor((height + 5) / 6) * 16; | ||
return Math.floor((width + 5) / 6) * Math.floor((height + 5) / 6) * 16; | ||
} | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/ | ||
function atc8x5Size(width, height) { | ||
return Math.floor((width + 7) / 8) * Math.floor((height + 4) / 5) * 16; | ||
return Math.floor((width + 7) / 8) * Math.floor((height + 4) / 5) * 16; | ||
} | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/ | ||
function atc8x6Size(width, height) { | ||
return Math.floor((width + 7) / 8) * Math.floor((height + 5) / 6) * 16; | ||
return Math.floor((width + 7) / 8) * Math.floor((height + 5) / 6) * 16; | ||
} | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/ | ||
function atc8x8Size(width, height) { | ||
return Math.floor((width + 7) / 8) * Math.floor((height + 7) / 8) * 16; | ||
return Math.floor((width + 7) / 8) * Math.floor((height + 7) / 8) * 16; | ||
} | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/ | ||
function atc10x5Size(width, height) { | ||
return Math.floor((width + 9) / 10) * Math.floor((height + 4) / 5) * 16; | ||
return Math.floor((width + 9) / 10) * Math.floor((height + 4) / 5) * 16; | ||
} | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/ | ||
function atc10x6Size(width, height) { | ||
return Math.floor((width + 9) / 10) * Math.floor((height + 5) / 6) * 16; | ||
return Math.floor((width + 9) / 10) * Math.floor((height + 5) / 6) * 16; | ||
} | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/ | ||
function atc10x8Size(width, height) { | ||
return Math.floor((width + 9) / 10) * Math.floor((height + 7) / 8) * 16; | ||
return Math.floor((width + 9) / 10) * Math.floor((height + 7) / 8) * 16; | ||
} | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/ | ||
function atc10x10Size(width, height) { | ||
return Math.floor((width + 9) / 10) * Math.floor((height + 9) / 10) * 16; | ||
return Math.floor((width + 9) / 10) * Math.floor((height + 9) / 10) * 16; | ||
} | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/ | ||
function atc12x10Size(width, height) { | ||
return Math.floor((width + 11) / 12) * Math.floor((height + 9) / 10) * 16; | ||
return Math.floor((width + 11) / 12) * Math.floor((height + 9) / 10) * 16; | ||
} | ||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/ | ||
function atc12x12Size(width, height) { | ||
return Math.floor((width + 11) / 12) * Math.floor((height + 11) / 12) * 16; | ||
return Math.floor((width + 11) / 12) * Math.floor((height + 11) / 12) * 16; | ||
} | ||
//# sourceMappingURL=parse-pvr.js.map |
@@ -1,34 +0,39 @@ | ||
const isObject = value => value && typeof value === 'object'; | ||
export async function asyncDeepMap(tree, func) { | ||
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
return await mapSubtree(tree, func, options); | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
const isObject = (value) => value && typeof value === 'object'; | ||
// Loads a deep structure of urls (objects and arrays of urls) | ||
// Returns an object with six key-value pairs containing the images (or image mip arrays) | ||
// for each cube face | ||
export async function asyncDeepMap(tree, func, options = {}) { | ||
return await mapSubtree(tree, func, options); | ||
} | ||
export async function mapSubtree(object, func, options) { | ||
if (Array.isArray(object)) { | ||
return await mapArray(object, func, options); | ||
} | ||
if (isObject(object)) { | ||
return await mapObject(object, func, options); | ||
} | ||
const url = object; | ||
return await func(url, options); | ||
if (Array.isArray(object)) { | ||
return await mapArray(object, func, options); | ||
} | ||
if (isObject(object)) { | ||
return await mapObject(object, func, options); | ||
} | ||
// TODO - ignore non-urls, non-arraybuffers? | ||
const url = object; | ||
return await func(url, options); | ||
} | ||
// HELPERS | ||
async function mapObject(object, func, options) { | ||
const promises = []; | ||
const values = {}; | ||
for (const key in object) { | ||
const url = object[key]; | ||
const promise = mapSubtree(url, func, options).then(value => { | ||
values[key] = value; | ||
}); | ||
promises.push(promise); | ||
} | ||
await Promise.all(promises); | ||
return values; | ||
const promises = []; | ||
const values = {}; | ||
for (const key in object) { | ||
const url = object[key]; | ||
const promise = mapSubtree(url, func, options).then((value) => { | ||
values[key] = value; | ||
}); | ||
promises.push(promise); | ||
} | ||
await Promise.all(promises); | ||
return values; | ||
} | ||
async function mapArray(urlArray, func) { | ||
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
const promises = urlArray.map(url => mapSubtree(url, func, options)); | ||
return await Promise.all(promises); | ||
async function mapArray(urlArray, func, options = {}) { | ||
const promises = urlArray.map((url) => mapSubtree(url, func, options)); | ||
return await Promise.all(promises); | ||
} | ||
//# sourceMappingURL=async-deep-map.js.map |
@@ -0,10 +1,12 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { asyncDeepMap } from "./async-deep-map.js"; | ||
export async function deepLoad(urlTree, load, options) { | ||
return await asyncDeepMap(urlTree, url => shallowLoad(url, load, options)); | ||
return await asyncDeepMap(urlTree, (url) => shallowLoad(url, load, options)); | ||
} | ||
export async function shallowLoad(url, load, options) { | ||
const response = await fetch(url, options.fetch); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
return await load(arrayBuffer, options); | ||
const response = await fetch(url, options.fetch); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
return await load(arrayBuffer, options); | ||
} | ||
//# sourceMappingURL=deep-load.js.map |
@@ -1,3 +0,3 @@ | ||
import type { GetUrl, UrlOptions } from './texture-api-types'; | ||
import type { GetUrl, UrlOptions } from "./texture-api-types.js"; | ||
export declare function generateUrl(getUrl: string | GetUrl, options: UrlOptions, urlOptions: Record<string, any>): string; | ||
//# sourceMappingURL=generate-url.d.ts.map |
@@ -0,13 +1,15 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { resolvePath } from '@loaders.gl/loader-utils'; | ||
// Generate a url by calling getUrl with mix of options, applying options.baseUrl | ||
export function generateUrl(getUrl, options, urlOptions) { | ||
let url = typeof getUrl === 'function' ? getUrl({ | ||
...options, | ||
...urlOptions | ||
}) : getUrl; | ||
const baseUrl = options.baseUrl; | ||
if (baseUrl) { | ||
url = baseUrl[baseUrl.length - 1] === '/' ? `${baseUrl}${url}` : `${baseUrl}/${url}`; | ||
} | ||
return resolvePath(url); | ||
// Get url | ||
let url = typeof getUrl === 'function' ? getUrl({ ...options, ...urlOptions }) : getUrl; | ||
// Apply options.baseUrl | ||
const baseUrl = options.baseUrl; | ||
if (baseUrl) { | ||
url = baseUrl[baseUrl.length - 1] === '/' ? `${baseUrl}${url}` : `${baseUrl}/${url}`; | ||
} | ||
return resolvePath(url); | ||
} | ||
//# sourceMappingURL=generate-url.js.map |
@@ -1,4 +0,4 @@ | ||
import type { GetUrl } from './texture-api-types'; | ||
import type { GetUrl } from "./texture-api-types.js"; | ||
export declare function loadImageTextureArray(count: number, getUrl: GetUrl, options?: {}): Promise<any>; | ||
export declare function getImageArrayUrls(count: number, getUrl: GetUrl, options?: {}): Promise<any>; | ||
//# sourceMappingURL=load-image-array.d.ts.map |
@@ -0,20 +1,18 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { ImageLoader } from '@loaders.gl/images'; | ||
import { getImageUrls } from "./load-image.js"; | ||
import { deepLoad } from "./deep-load.js"; | ||
export async function loadImageTextureArray(count, getUrl) { | ||
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
const imageUrls = await getImageArrayUrls(count, getUrl, options); | ||
return await deepLoad(imageUrls, ImageLoader.parse, options); | ||
export async function loadImageTextureArray(count, getUrl, options = {}) { | ||
const imageUrls = await getImageArrayUrls(count, getUrl, options); | ||
return await deepLoad(imageUrls, ImageLoader.parse, options); | ||
} | ||
export async function getImageArrayUrls(count, getUrl) { | ||
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
const promises = []; | ||
for (let index = 0; index < count; index++) { | ||
const promise = getImageUrls(getUrl, options, { | ||
index | ||
}); | ||
promises.push(promise); | ||
} | ||
return await Promise.all(promises); | ||
export async function getImageArrayUrls(count, getUrl, options = {}) { | ||
const promises = []; | ||
for (let index = 0; index < count; index++) { | ||
const promise = getImageUrls(getUrl, options, { index }); | ||
promises.push(promise); | ||
} | ||
return await Promise.all(promises); | ||
} | ||
//# sourceMappingURL=load-image-array.js.map |
@@ -1,2 +0,2 @@ | ||
import type { GetUrl, UrlOptions } from './texture-api-types'; | ||
import type { GetUrl, UrlOptions } from "./texture-api-types.js"; | ||
export type ImageCubeTexture = { | ||
@@ -3,0 +3,0 @@ GL_TEXTURE_CUBE_MAP_POSITIVE_X: any; |
@@ -0,4 +1,8 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { ImageLoader } from '@loaders.gl/images'; | ||
import { getImageUrls } from "./load-image.js"; | ||
import { deepLoad } from "./deep-load.js"; | ||
// Returned map will be have keys corresponding to GL cubemap constants | ||
const GL_TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515; | ||
@@ -10,55 +14,32 @@ const GL_TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516; | ||
const GL_TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851a; | ||
const CUBE_FACES = [{ | ||
face: GL_TEXTURE_CUBE_MAP_POSITIVE_X, | ||
direction: 'right', | ||
axis: 'x', | ||
sign: 'positive' | ||
}, { | ||
face: GL_TEXTURE_CUBE_MAP_NEGATIVE_X, | ||
direction: 'left', | ||
axis: 'x', | ||
sign: 'negative' | ||
}, { | ||
face: GL_TEXTURE_CUBE_MAP_POSITIVE_Y, | ||
direction: 'top', | ||
axis: 'y', | ||
sign: 'positive' | ||
}, { | ||
face: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, | ||
direction: 'bottom', | ||
axis: 'y', | ||
sign: 'negative' | ||
}, { | ||
face: GL_TEXTURE_CUBE_MAP_POSITIVE_Z, | ||
direction: 'front', | ||
axis: 'z', | ||
sign: 'positive' | ||
}, { | ||
face: GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, | ||
direction: 'back', | ||
axis: 'z', | ||
sign: 'negative' | ||
}]; | ||
const CUBE_FACES = [ | ||
{ face: GL_TEXTURE_CUBE_MAP_POSITIVE_X, direction: 'right', axis: 'x', sign: 'positive' }, | ||
{ face: GL_TEXTURE_CUBE_MAP_NEGATIVE_X, direction: 'left', axis: 'x', sign: 'negative' }, | ||
{ face: GL_TEXTURE_CUBE_MAP_POSITIVE_Y, direction: 'top', axis: 'y', sign: 'positive' }, | ||
{ face: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, direction: 'bottom', axis: 'y', sign: 'negative' }, | ||
{ face: GL_TEXTURE_CUBE_MAP_POSITIVE_Z, direction: 'front', axis: 'z', sign: 'positive' }, | ||
{ face: GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, direction: 'back', axis: 'z', sign: 'negative' } | ||
]; | ||
// Returns an object with six key-value pairs containing the urls (or url mip arrays) | ||
// for each cube face | ||
export async function getImageCubeUrls(getUrl, options) { | ||
const urls = {}; | ||
const promises = []; | ||
let index = 0; | ||
for (let i = 0; i < CUBE_FACES.length; ++i) { | ||
const face = CUBE_FACES[index]; | ||
const promise = getImageUrls(getUrl, options, { | ||
...face, | ||
index: index++ | ||
}).then(url => { | ||
urls[face.face] = url; | ||
}); | ||
promises.push(promise); | ||
} | ||
await Promise.all(promises); | ||
return urls; | ||
// Calculate URLs | ||
const urls = {}; | ||
const promises = []; | ||
let index = 0; | ||
for (let i = 0; i < CUBE_FACES.length; ++i) { | ||
const face = CUBE_FACES[index]; | ||
const promise = getImageUrls(getUrl, options, { ...face, index: index++ }).then((url) => { | ||
urls[face.face] = url; | ||
}); | ||
promises.push(promise); | ||
} | ||
await Promise.all(promises); | ||
return urls; | ||
} | ||
export async function loadImageTextureCube(getUrl) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
const urls = await getImageCubeUrls(getUrl, options); | ||
return await deepLoad(urls, ImageLoader.parse, options); | ||
// Returns an object with six key-value pairs containing the images (or image mip arrays) | ||
// for each cube face | ||
export async function loadImageTextureCube(getUrl, options = {}) { | ||
const urls = await getImageCubeUrls(getUrl, options); | ||
return (await deepLoad(urls, ImageLoader.parse, options)); | ||
} | ||
//# sourceMappingURL=load-image-cube.js.map |
@@ -1,2 +0,2 @@ | ||
import type { GetUrl, UrlOptions } from './texture-api-types'; | ||
import type { GetUrl, UrlOptions } from "./texture-api-types.js"; | ||
export declare function loadImageTexture(getUrl: string | GetUrl, options?: {}): Promise<any>; | ||
@@ -3,0 +3,0 @@ export declare function getImageUrls(getUrl: string | GetUrl, options: any, urlOptions?: UrlOptions): Promise<any>; |
@@ -0,1 +1,4 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { assert } from '@loaders.gl/loader-utils'; | ||
@@ -5,43 +8,34 @@ import { ImageLoader, getImageSize } from '@loaders.gl/images'; | ||
import { deepLoad, shallowLoad } from "./deep-load.js"; | ||
export async function loadImageTexture(getUrl) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
const imageUrls = await getImageUrls(getUrl, options); | ||
return await deepLoad(imageUrls, ImageLoader.parse, options); | ||
export async function loadImageTexture(getUrl, options = {}) { | ||
const imageUrls = await getImageUrls(getUrl, options); | ||
return await deepLoad(imageUrls, ImageLoader.parse, options); | ||
} | ||
export async function getImageUrls(getUrl, options) { | ||
let urlOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
const mipLevels = options && options.image && options.image.mipLevels || 0; | ||
return mipLevels !== 0 ? await getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions) : generateUrl(getUrl, options, urlOptions); | ||
export async function getImageUrls(getUrl, options, urlOptions = {}) { | ||
const mipLevels = (options && options.image && options.image.mipLevels) || 0; | ||
return mipLevels !== 0 | ||
? await getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions) | ||
: generateUrl(getUrl, options, urlOptions); | ||
} | ||
async function getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions) { | ||
const urls = []; | ||
if (mipLevels === 'auto') { | ||
const url = generateUrl(getUrl, options, { | ||
...urlOptions, | ||
lod: 0 | ||
}); | ||
const image = await shallowLoad(url, ImageLoader.parse, options); | ||
const { | ||
width, | ||
height | ||
} = getImageSize(image); | ||
mipLevels = getMipLevels({ | ||
width, | ||
height | ||
}); | ||
urls.push(url); | ||
} | ||
assert(mipLevels > 0); | ||
for (let mipLevel = urls.length; mipLevel < mipLevels; ++mipLevel) { | ||
const url = generateUrl(getUrl, options, { | ||
...urlOptions, | ||
lod: mipLevel | ||
}); | ||
urls.push(url); | ||
} | ||
return urls; | ||
const urls = []; | ||
// If no mip levels supplied, we need to load the level 0 image and calculate based on size | ||
if (mipLevels === 'auto') { | ||
const url = generateUrl(getUrl, options, { ...urlOptions, lod: 0 }); | ||
const image = await shallowLoad(url, ImageLoader.parse, options); | ||
const { width, height } = getImageSize(image); | ||
mipLevels = getMipLevels({ width, height }); | ||
// TODO - push image and make `deepLoad` pass through non-url values, avoid loading twice? | ||
urls.push(url); | ||
} | ||
// We now know how many mipLevels we need, remaining image urls can now be constructed | ||
assert(mipLevels > 0); | ||
for (let mipLevel = urls.length; mipLevel < mipLevels; ++mipLevel) { | ||
const url = generateUrl(getUrl, options, { ...urlOptions, lod: mipLevel }); | ||
urls.push(url); | ||
} | ||
return urls; | ||
} | ||
// Calculates number of mipmaps based on texture size (log2) | ||
export function getMipLevels(size) { | ||
return 1 + Math.floor(Math.log2(Math.max(size.width, size.height))); | ||
return 1 + Math.floor(Math.log2(Math.max(size.width, size.height))); | ||
} | ||
//# sourceMappingURL=load-image.js.map |
@@ -0,2 +1,4 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
export {}; | ||
//# sourceMappingURL=texture-api-types.js.map |
@@ -0,35 +1,49 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
/** | ||
* Extract mipmap images from compressed texture buffer | ||
* @param data - binary data of compressed texture or Array of level objects | ||
* @param options.mipMapLevels - number of mipmap level inside image | ||
* @param options.width - width of 0 - level | ||
* @param options.height - height of 0 - level | ||
* @param options.sizeFunction - format-related function to calculate level size in bytes | ||
* @param options.internalFormat - WebGL compatible format code | ||
* @returns Array of the texture levels | ||
*/ | ||
export function extractMipmapImages(data, options) { | ||
const images = new Array(options.mipMapLevels); | ||
let levelWidth = options.width; | ||
let levelHeight = options.height; | ||
let offset = 0; | ||
for (let i = 0; i < options.mipMapLevels; ++i) { | ||
const levelSize = getLevelSize(options, levelWidth, levelHeight, data, i); | ||
const levelData = getLevelData(data, i, offset, levelSize); | ||
images[i] = { | ||
compressed: true, | ||
format: options.internalFormat, | ||
data: levelData, | ||
width: levelWidth, | ||
height: levelHeight, | ||
levelSize | ||
}; | ||
levelWidth = Math.max(1, levelWidth >> 1); | ||
levelHeight = Math.max(1, levelHeight >> 1); | ||
offset += levelSize; | ||
} | ||
return images; | ||
const images = new Array(options.mipMapLevels); | ||
let levelWidth = options.width; | ||
let levelHeight = options.height; | ||
let offset = 0; | ||
for (let i = 0; i < options.mipMapLevels; ++i) { | ||
// @ts-expect-error | ||
const levelSize = getLevelSize(options, levelWidth, levelHeight, data, i); | ||
// @ts-expect-error | ||
const levelData = getLevelData(data, i, offset, levelSize); | ||
images[i] = { | ||
compressed: true, | ||
format: options.internalFormat, | ||
data: levelData, | ||
width: levelWidth, | ||
height: levelHeight, | ||
levelSize | ||
}; | ||
levelWidth = Math.max(1, levelWidth >> 1); | ||
levelHeight = Math.max(1, levelHeight >> 1); | ||
offset += levelSize; | ||
} | ||
return images; | ||
} | ||
function getLevelData(data, index, offset, levelSize) { | ||
if (!Array.isArray(data)) { | ||
return new Uint8Array(data.buffer, data.byteOffset + offset, levelSize); | ||
} | ||
return data[index].levelData; | ||
if (!Array.isArray(data)) { | ||
return new Uint8Array(data.buffer, data.byteOffset + offset, levelSize); | ||
} | ||
return data[index].levelData; | ||
} | ||
function getLevelSize(options, levelWidth, levelHeight, data, index) { | ||
if (!Array.isArray(data)) { | ||
return options.sizeFunction(levelWidth, levelHeight); | ||
} | ||
return options.sizeFunction(data[index]); | ||
if (!Array.isArray(data)) { | ||
return options.sizeFunction(levelWidth, levelHeight); | ||
} | ||
return options.sizeFunction(data[index]); | ||
} | ||
//# sourceMappingURL=extract-mipmap-images.js.map |
@@ -0,73 +1,124 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { GL_EXTENSIONS_CONSTANTS } from "../gl-extensions.js"; | ||
const VULKAN_TO_WEBGL_FORMAT_MAP = { | ||
131: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT, | ||
132: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB_S3TC_DXT1_EXT, | ||
133: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT1_EXT, | ||
134: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, | ||
135: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT, | ||
136: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, | ||
137: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT, | ||
138: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, | ||
139: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RED_RGTC1_EXT, | ||
140: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SIGNED_RED_RGTC1_EXT, | ||
141: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RED_GREEN_RGTC2_EXT, | ||
142: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT, | ||
147: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_ETC2, | ||
148: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ETC2, | ||
149: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, | ||
150: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, | ||
151: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA8_ETC2_EAC, | ||
152: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, | ||
153: GL_EXTENSIONS_CONSTANTS.COMPRESSED_R11_EAC, | ||
154: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SIGNED_R11_EAC, | ||
155: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RG11_EAC, | ||
156: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SIGNED_RG11_EAC, | ||
157: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4x4_KHR, | ||
158: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, | ||
159: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5x4_KHR, | ||
160: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR, | ||
161: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5x5_KHR, | ||
162: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, | ||
163: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6x5_KHR, | ||
164: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, | ||
165: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6x6_KHR, | ||
166: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, | ||
167: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x5_KHR, | ||
168: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, | ||
169: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x6_KHR, | ||
170: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, | ||
171: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x8_KHR, | ||
172: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, | ||
173: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x5_KHR, | ||
174: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, | ||
175: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x6_KHR, | ||
176: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, | ||
177: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x8_KHR, | ||
178: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, | ||
179: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x10_KHR, | ||
180: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, | ||
181: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12x10_KHR, | ||
182: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, | ||
183: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12x12_KHR, | ||
184: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, | ||
1000054000: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, | ||
1000054001: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, | ||
1000066000: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4x4_KHR, | ||
1000066001: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5x4_KHR, | ||
1000066002: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5x5_KHR, | ||
1000066003: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6x5_KHR, | ||
1000066004: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6x6_KHR, | ||
1000066005: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x5_KHR, | ||
1000066006: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x6_KHR, | ||
1000066007: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x8_KHR, | ||
1000066008: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x5_KHR, | ||
1000066009: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x6_KHR, | ||
1000066010: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x8_KHR, | ||
1000066011: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x10_KHR, | ||
1000066012: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12x10_KHR, | ||
1000066013: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12x12_KHR | ||
131: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT, | ||
132: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB_S3TC_DXT1_EXT, | ||
133: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT1_EXT, | ||
134: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, | ||
135: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT, | ||
136: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, | ||
137: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT, | ||
138: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, | ||
139: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RED_RGTC1_EXT, | ||
140: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SIGNED_RED_RGTC1_EXT, | ||
141: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RED_GREEN_RGTC2_EXT, | ||
142: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT, | ||
147: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_ETC2, | ||
148: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ETC2, | ||
149: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, | ||
150: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, | ||
151: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA8_ETC2_EAC, | ||
152: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, | ||
153: GL_EXTENSIONS_CONSTANTS.COMPRESSED_R11_EAC, | ||
154: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SIGNED_R11_EAC, | ||
155: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RG11_EAC, | ||
156: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SIGNED_RG11_EAC, | ||
// @ts-ignore | ||
157: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4x4_KHR, | ||
// @ts-ignore | ||
158: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, | ||
// @ts-ignore | ||
159: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5x4_KHR, | ||
// @ts-ignore | ||
160: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR, | ||
// @ts-ignore | ||
161: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5x5_KHR, | ||
// @ts-ignore | ||
162: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, | ||
// @ts-ignore | ||
163: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6x5_KHR, | ||
// @ts-ignore | ||
164: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, | ||
// @ts-ignore | ||
165: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6x6_KHR, | ||
// @ts-ignore | ||
166: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, | ||
// @ts-ignore | ||
167: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x5_KHR, | ||
// @ts-ignore | ||
168: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, | ||
// @ts-ignore | ||
169: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x6_KHR, | ||
// @ts-ignore | ||
170: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, | ||
// @ts-ignore | ||
171: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x8_KHR, | ||
// @ts-ignore | ||
172: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, | ||
// @ts-ignore | ||
173: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x5_KHR, | ||
// @ts-ignore | ||
174: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, | ||
// @ts-ignore | ||
175: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x6_KHR, | ||
// @ts-ignore | ||
176: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, | ||
// @ts-ignore | ||
177: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x8_KHR, | ||
// @ts-ignore | ||
178: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, | ||
// @ts-ignore | ||
179: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x10_KHR, | ||
// @ts-ignore | ||
180: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, | ||
// @ts-ignore | ||
181: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12x10_KHR, | ||
// @ts-ignore | ||
182: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, | ||
// @ts-ignore | ||
183: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12x12_KHR, | ||
// @ts-ignore | ||
184: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, | ||
1000054000: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, | ||
1000054001: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, | ||
// @ts-ignore | ||
1000066000: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4x4_KHR, | ||
// @ts-ignore | ||
1000066001: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5x4_KHR, | ||
// @ts-ignore | ||
1000066002: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5x5_KHR, | ||
// @ts-ignore | ||
1000066003: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6x5_KHR, | ||
// @ts-ignore | ||
1000066004: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6x6_KHR, | ||
// @ts-ignore | ||
1000066005: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x5_KHR, | ||
// @ts-ignore | ||
1000066006: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x6_KHR, | ||
// @ts-ignore | ||
1000066007: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x8_KHR, | ||
// @ts-ignore | ||
1000066008: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x5_KHR, | ||
// @ts-ignore | ||
1000066009: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x6_KHR, | ||
// @ts-ignore | ||
1000066010: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x8_KHR, | ||
// @ts-ignore | ||
1000066011: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x10_KHR, | ||
// @ts-ignore | ||
1000066012: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12x10_KHR, | ||
// @ts-ignore | ||
1000066013: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12x12_KHR | ||
}; | ||
/** | ||
* Returns WebGl format based on Vulkan format | ||
* Vulkan to WebGl format mapping provided here http://github.khronos.org/KTX-Specification/#formatMapping | ||
* Vulkan name to format number mapping provided here: https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkFormat.html | ||
* @param vkFormat | ||
* @returns WebGL / OpenGL constant | ||
*/ | ||
export function mapVkFormatToWebGL(vkFormat) { | ||
return VULKAN_TO_WEBGL_FORMAT_MAP[vkFormat]; | ||
return VULKAN_TO_WEBGL_FORMAT_MAP[vkFormat]; | ||
} | ||
//# sourceMappingURL=ktx-format-helper.js.map |
@@ -0,36 +1,50 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
const BROWSER_PREFIXES = ['', 'WEBKIT_', 'MOZ_']; | ||
const WEBGL_EXTENSIONS = { | ||
WEBGL_compressed_texture_s3tc: 'dxt', | ||
WEBGL_compressed_texture_s3tc_srgb: 'dxt-srgb', | ||
WEBGL_compressed_texture_etc1: 'etc1', | ||
WEBGL_compressed_texture_etc: 'etc2', | ||
WEBGL_compressed_texture_pvrtc: 'pvrtc', | ||
WEBGL_compressed_texture_atc: 'atc', | ||
WEBGL_compressed_texture_astc: 'astc', | ||
EXT_texture_compression_rgtc: 'rgtc' | ||
/* eslint-disable camelcase */ | ||
WEBGL_compressed_texture_s3tc: 'dxt', | ||
WEBGL_compressed_texture_s3tc_srgb: 'dxt-srgb', | ||
WEBGL_compressed_texture_etc1: 'etc1', | ||
WEBGL_compressed_texture_etc: 'etc2', | ||
WEBGL_compressed_texture_pvrtc: 'pvrtc', | ||
WEBGL_compressed_texture_atc: 'atc', | ||
WEBGL_compressed_texture_astc: 'astc', | ||
EXT_texture_compression_rgtc: 'rgtc' | ||
/* eslint-enable camelcase */ | ||
}; | ||
let formats = null; | ||
/** | ||
* Returns a list of formats. | ||
* Creates a temporary WebGLRenderingContext if none is provided. | ||
* | ||
* @param gl - Optional context. | ||
*/ | ||
export function getSupportedGPUTextureFormats(gl) { | ||
if (!formats) { | ||
gl = gl || getWebGLContext() || undefined; | ||
formats = new Set(); | ||
for (const prefix of BROWSER_PREFIXES) { | ||
for (const extension in WEBGL_EXTENSIONS) { | ||
if (gl && gl.getExtension(`${prefix}${extension}`)) { | ||
const gpuTextureFormat = WEBGL_EXTENSIONS[extension]; | ||
formats.add(gpuTextureFormat); | ||
if (!formats) { | ||
gl = gl || getWebGLContext() || undefined; | ||
formats = new Set(); | ||
for (const prefix of BROWSER_PREFIXES) { | ||
for (const extension in WEBGL_EXTENSIONS) { | ||
if (gl && gl.getExtension(`${prefix}${extension}`)) { | ||
const gpuTextureFormat = WEBGL_EXTENSIONS[extension]; | ||
formats.add(gpuTextureFormat); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return formats; | ||
return formats; | ||
} | ||
/** | ||
* @returns {WebGLRenderingContext?} | ||
*/ | ||
function getWebGLContext() { | ||
try { | ||
const canvas = document.createElement('canvas'); | ||
return canvas.getContext('webgl'); | ||
} catch (error) { | ||
return null; | ||
} | ||
try { | ||
const canvas = document.createElement('canvas'); | ||
return canvas.getContext('webgl'); | ||
} | ||
catch (error) { | ||
return null; | ||
} | ||
} | ||
//# sourceMappingURL=texture-formats.js.map |
@@ -0,2 +1,7 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
// Version constant cannot be imported, it needs to correspond to the build version of **this** module. | ||
// __VERSION__ is injected by babel-plugin-version-inline | ||
// @ts-ignore TS2304: Cannot find name '__VERSION__'. | ||
export const VERSION = typeof "4.2.0-alpha.4" !== 'undefined' ? "4.2.0-alpha.4" : 'latest'; | ||
//# sourceMappingURL=version.js.map |
import type { Loader, LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils'; | ||
import { NPYTile } from './lib/parsers/parse-npy'; | ||
import { NPYTile } from "./lib/parsers/parse-npy.js"; | ||
export type NPYLoaderOptions = LoaderOptions & { | ||
@@ -4,0 +4,0 @@ npy?: {}; |
@@ -0,22 +1,31 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { VERSION } from "./lib/utils/version.js"; | ||
import { parseNPY } from "./lib/parsers/parse-npy.js"; | ||
// \x93NUMPY | ||
const NPY_MAGIC_NUMBER = new Uint8Array([147, 78, 85, 77, 80, 89]); | ||
/** | ||
* Worker loader for numpy "tiles" | ||
*/ | ||
export const NPYWorkerLoader = { | ||
name: 'NPY', | ||
id: 'npy', | ||
module: 'textures', | ||
version: VERSION, | ||
worker: true, | ||
extensions: ['npy'], | ||
mimeTypes: [], | ||
tests: [NPY_MAGIC_NUMBER.buffer], | ||
options: { | ||
npy: {} | ||
} | ||
name: 'NPY', | ||
id: 'npy', | ||
module: 'textures', | ||
version: VERSION, | ||
worker: true, | ||
extensions: ['npy'], | ||
mimeTypes: [], | ||
tests: [NPY_MAGIC_NUMBER.buffer], | ||
options: { | ||
npy: {} | ||
} | ||
}; | ||
/** | ||
* Loader for numpy "tiles" | ||
*/ | ||
export const NPYLoader = { | ||
...NPYWorkerLoader, | ||
parseSync: parseNPY, | ||
parse: async (arrayBuffer, options) => parseNPY(arrayBuffer, options) | ||
...NPYWorkerLoader, | ||
parseSync: parseNPY, | ||
parse: async (arrayBuffer, options) => parseNPY(arrayBuffer, options) | ||
}; | ||
//# sourceMappingURL=npy-loader.js.map |
@@ -0,1 +1,5 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
// Polyfills increases the bundle size significantly. Use it for NodeJS worker only | ||
import '@loaders.gl/polyfills'; | ||
@@ -5,2 +9,1 @@ import { createLoaderWorker } from '@loaders.gl/loader-utils'; | ||
createLoaderWorker(BasisLoader); | ||
//# sourceMappingURL=basis-worker-node.js.map |
@@ -0,4 +1,6 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { createLoaderWorker } from '@loaders.gl/loader-utils'; | ||
import { BasisLoader } from "../basis-loader.js"; | ||
createLoaderWorker(BasisLoader); | ||
//# sourceMappingURL=basis-worker.js.map |
@@ -0,4 +1,7 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { createLoaderWorker } from '@loaders.gl/loader-utils'; | ||
import { CompressedTextureLoader } from "../compressed-texture-loader.js"; | ||
// @ts-expect-error | ||
createLoaderWorker(CompressedTextureLoader); | ||
//# sourceMappingURL=compressed-texture-worker.js.map |
@@ -1,2 +0,2 @@ | ||
import { parseCrunch } from '../lib/parsers/parse-crunch'; | ||
import { parseCrunch } from "../lib/parsers/parse-crunch.js"; | ||
/** | ||
@@ -3,0 +3,0 @@ * Loader for the Crunch compressed texture container format |
@@ -0,9 +1,14 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { createLoaderWorker } from '@loaders.gl/loader-utils'; | ||
import { CrunchLoader } from "../crunch-loader.js"; | ||
import { parseCrunch } from "../lib/parsers/parse-crunch.js"; | ||
/** | ||
* Loader for the Crunch compressed texture container format | ||
*/ | ||
export const CrunchLoaderWithParser = { | ||
...CrunchLoader, | ||
parse: parseCrunch | ||
...CrunchLoader, | ||
parse: parseCrunch | ||
}; | ||
createLoaderWorker(CrunchLoaderWithParser); | ||
//# sourceMappingURL=crunch-worker.js.map |
@@ -0,1 +1,5 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
// Polyfills increases the bundle size significantly. Use it for NodeJS worker only | ||
import '@loaders.gl/polyfills'; | ||
@@ -5,29 +9,22 @@ import { WorkerBody } from '@loaders.gl/worker-utils'; | ||
(async () => { | ||
if (!(await WorkerBody.inWorkerThread())) { | ||
return; | ||
} | ||
WorkerBody.onmessage = async (type, payload) => { | ||
switch (type) { | ||
case 'process': | ||
try { | ||
var _KTX2BasisWriter$enco; | ||
const { | ||
input, | ||
options | ||
} = payload; | ||
const result = await ((_KTX2BasisWriter$enco = KTX2BasisWriter.encode) === null || _KTX2BasisWriter$enco === void 0 ? void 0 : _KTX2BasisWriter$enco.call(KTX2BasisWriter, input, options)); | ||
WorkerBody.postMessage('done', { | ||
result | ||
}); | ||
} catch (error) { | ||
const message = error instanceof Error ? error.message : ''; | ||
WorkerBody.postMessage('error', { | ||
error: message | ||
}); | ||
// Check that we are actually in a worker thread | ||
if (!(await WorkerBody.inWorkerThread())) { | ||
return; | ||
} | ||
WorkerBody.onmessage = async (type, payload) => { | ||
switch (type) { | ||
case 'process': | ||
try { | ||
const { input, options } = payload; | ||
const result = await KTX2BasisWriter.encode?.(input, options); | ||
WorkerBody.postMessage('done', { result }); | ||
} | ||
catch (error) { | ||
const message = error instanceof Error ? error.message : ''; | ||
WorkerBody.postMessage('error', { error: message }); | ||
} | ||
break; | ||
default: | ||
} | ||
break; | ||
default: | ||
} | ||
}; | ||
}; | ||
})(); | ||
//# sourceMappingURL=ktx2-basis-writer-worker-node.js.map |
@@ -0,31 +1,27 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { WorkerBody } from '@loaders.gl/worker-utils'; | ||
import { KTX2BasisWriter } from "../ktx2-basis-writer.js"; | ||
(async () => { | ||
if (!(await WorkerBody.inWorkerThread())) { | ||
return; | ||
} | ||
WorkerBody.onmessage = async (type, payload) => { | ||
switch (type) { | ||
case 'process': | ||
try { | ||
var _KTX2BasisWriter$enco; | ||
const { | ||
input, | ||
options | ||
} = payload; | ||
const result = await ((_KTX2BasisWriter$enco = KTX2BasisWriter.encode) === null || _KTX2BasisWriter$enco === void 0 ? void 0 : _KTX2BasisWriter$enco.call(KTX2BasisWriter, input, options)); | ||
WorkerBody.postMessage('done', { | ||
result | ||
}); | ||
} catch (error) { | ||
const message = error instanceof Error ? error.message : ''; | ||
WorkerBody.postMessage('error', { | ||
error: message | ||
}); | ||
// Check that we are actually in a worker thread | ||
if (!(await WorkerBody.inWorkerThread())) { | ||
return; | ||
} | ||
WorkerBody.onmessage = async (type, payload) => { | ||
switch (type) { | ||
case 'process': | ||
try { | ||
const { input, options } = payload; | ||
const result = await KTX2BasisWriter.encode?.(input, options); | ||
WorkerBody.postMessage('done', { result }); | ||
} | ||
catch (error) { | ||
const message = error instanceof Error ? error.message : ''; | ||
WorkerBody.postMessage('error', { error: message }); | ||
} | ||
break; | ||
default: | ||
} | ||
break; | ||
default: | ||
} | ||
}; | ||
}; | ||
})(); | ||
//# sourceMappingURL=ktx2-basis-writer-worker.js.map |
@@ -0,4 +1,6 @@ | ||
// loaders.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { NPYLoader } from "../npy-loader.js"; | ||
import { createLoaderWorker } from '@loaders.gl/loader-utils'; | ||
createLoaderWorker(NPYLoader); | ||
//# sourceMappingURL=npy-worker.js.map |
{ | ||
"name": "@loaders.gl/textures", | ||
"version": "4.2.0-alpha.4", | ||
"version": "4.2.0-alpha.5", | ||
"description": "Framework-independent loaders for compressed and super compressed (basis) textures ", | ||
@@ -43,5 +43,6 @@ "license": "MIT", | ||
"scripts": { | ||
"pre-build": "npm run copy-libs && npm run build-bundle && npm run build-bundle -- --env=dev && npm run build-workers", | ||
"pre-build": "npm run copy-libs && npm run build-bundle && npm run build-bundle-dev && npm run build-workers", | ||
"copy-libs": "cp -rf ./src/libs ./dist/libs", | ||
"build-bundle": "ocular-bundle ./src/index.ts", | ||
"build-bundle": "ocular-bundle ./bundle.ts --output=dist/dist.min.js", | ||
"build-bundle-dev": "ocular-bundle ./bundle.ts --env=dev --output=dist/dist.dev.js", | ||
"build-workers": "npm run build-basis-worker && npm run build-basis-worker-node && npm run build-npy-worker && npm run build-compressed-texture-worker && npm run build-crunch-worker && npm run build-ktx2-basis-writer-worker && npm run build-ktx2-basis-writer-worker-node", | ||
@@ -57,6 +58,6 @@ "build-basis-worker": "esbuild src/workers/basis-worker.ts --outfile=dist/basis-worker.js --target=esnext --bundle --define:__VERSION__=\\\"$npm_package_version\\\"", | ||
"dependencies": { | ||
"@loaders.gl/images": "4.2.0-alpha.4", | ||
"@loaders.gl/loader-utils": "4.2.0-alpha.4", | ||
"@loaders.gl/schema": "4.2.0-alpha.4", | ||
"@loaders.gl/worker-utils": "4.2.0-alpha.4", | ||
"@loaders.gl/images": "4.2.0-alpha.5", | ||
"@loaders.gl/loader-utils": "4.2.0-alpha.5", | ||
"@loaders.gl/schema": "4.2.0-alpha.5", | ||
"@loaders.gl/worker-utils": "4.2.0-alpha.5", | ||
"ktx-parse": "^0.0.4", | ||
@@ -66,5 +67,8 @@ "texture-compressor": "^1.0.2" | ||
"devDependencies": { | ||
"@loaders.gl/polyfills": "4.2.0-alpha.4" | ||
"@loaders.gl/polyfills": "4.2.0-alpha.5" | ||
}, | ||
"gitHead": "6c52dee5c3f005648a394cc4aee7fc37005c8e83" | ||
"peerDependencies": { | ||
"@loaders.gl/core": "^4.0.0" | ||
}, | ||
"gitHead": "32d95a81971f104e4dfeb88ab57065f05321a76a" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
5
8
50
9273841
7
178
145213
+ Added@loaders.gl/core@4.2.1(transitive)
+ Added@loaders.gl/images@4.2.0-alpha.5(transitive)
+ Added@loaders.gl/loader-utils@4.2.0-alpha.54.2.1(transitive)
+ Added@loaders.gl/schema@4.2.0-alpha.54.2.1(transitive)
+ Added@loaders.gl/worker-utils@4.2.0-alpha.54.2.1(transitive)
+ Added@probe.gl/env@4.0.9(transitive)
+ Added@probe.gl/log@4.0.9(transitive)
- Removed@babel/runtime@7.24.5(transitive)
- Removed@loaders.gl/images@4.2.0-alpha.4(transitive)
- Removed@loaders.gl/loader-utils@4.2.0-alpha.4(transitive)
- Removed@loaders.gl/schema@4.2.0-alpha.4(transitive)
- Removed@loaders.gl/worker-utils@4.2.0-alpha.4(transitive)
- Removedregenerator-runtime@0.14.1(transitive)