@loaders.gl/images 4.0.0-alpha.23 → 4.0.0-alpha.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.min.js.map +1 -1
- package/dist/es5/image-writer.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/esm/image-writer.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/image-writer.d.ts +3 -3
- package/dist/image-writer.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/image-writer.ts +3 -3
- package/dist/bundle.js +0 -5
- package/dist/image-loader.js +0 -41
- package/dist/image-writer.js +0 -21
- package/dist/index.js +0 -29
- package/dist/lib/category-api/binary-image-api.js +0 -161
- package/dist/lib/category-api/image-format.js +0 -110
- package/dist/lib/category-api/image-type.js +0 -48
- package/dist/lib/category-api/parse-isobmff-binary.js +0 -94
- package/dist/lib/category-api/parsed-image-api.js +0 -69
- package/dist/lib/encoders/encode-image.js +0 -81
- package/dist/lib/parsers/parse-image.js +0 -55
- package/dist/lib/parsers/parse-to-image-bitmap.js +0 -59
- package/dist/lib/parsers/parse-to-image.js +0 -47
- package/dist/lib/parsers/parse-to-node-image.js +0 -15
- package/dist/lib/parsers/svg-utils.js +0 -42
- package/dist/lib/texture-api/async-deep-map.js +0 -56
- package/dist/lib/texture-api/deep-load.js +0 -14
- package/dist/lib/texture-api/generate-url.js +0 -20
- package/dist/lib/texture-api/load-image.js +0 -44
- package/dist/lib/utils/version.js +0 -7
- package/dist/types.js +0 -2
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadToImage = exports.parseToImage = void 0;
|
|
4
|
-
const svg_utils_1 = require("./svg-utils");
|
|
5
|
-
// Parses html image from array buffer
|
|
6
|
-
async function parseToImage(arrayBuffer, options, url) {
|
|
7
|
-
// Note: image parsing requires conversion to Blob (for createObjectURL).
|
|
8
|
-
// Potentially inefficient for not using `response.blob()` (and for File / Blob inputs)...
|
|
9
|
-
// But presumably not worth adding 'blob' flag to loader objects?
|
|
10
|
-
const blobOrDataUrl = (0, svg_utils_1.getBlobOrSVGDataUrl)(arrayBuffer, url);
|
|
11
|
-
const URL = self.URL || self.webkitURL;
|
|
12
|
-
const objectUrl = typeof blobOrDataUrl !== 'string' && URL.createObjectURL(blobOrDataUrl);
|
|
13
|
-
try {
|
|
14
|
-
return await loadToImage(objectUrl || blobOrDataUrl, options);
|
|
15
|
-
}
|
|
16
|
-
finally {
|
|
17
|
-
if (objectUrl) {
|
|
18
|
-
URL.revokeObjectURL(objectUrl);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.parseToImage = parseToImage;
|
|
23
|
-
async function loadToImage(url, options) {
|
|
24
|
-
const image = new Image();
|
|
25
|
-
image.src = url;
|
|
26
|
-
// The `image.onload()` callback does not guarantee that the image has been decoded
|
|
27
|
-
// so a main thread "freeze" can be incurred when using the image for the first time.
|
|
28
|
-
// `Image.decode()` returns a promise that completes when image is decoded.
|
|
29
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decode
|
|
30
|
-
// Note: When calling `img.decode()`, we do not need to wait for `img.onload()`
|
|
31
|
-
// Note: `HTMLImageElement.decode()` is not available in Edge and IE11
|
|
32
|
-
if (options.image && options.image.decode && image.decode) {
|
|
33
|
-
await image.decode();
|
|
34
|
-
return image;
|
|
35
|
-
}
|
|
36
|
-
// Create a promise that tracks onload/onerror callbacks
|
|
37
|
-
return await new Promise((resolve, reject) => {
|
|
38
|
-
try {
|
|
39
|
-
image.onload = () => resolve(image);
|
|
40
|
-
image.onerror = (err) => reject(new Error(`Could not load image ${url}: ${err}`));
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
reject(error);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
exports.loadToImage = loadToImage;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseToNodeImage = void 0;
|
|
4
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
-
const binary_image_api_1 = require("../category-api/binary-image-api");
|
|
6
|
-
// Use polyfills if installed to parsed image using get-pixels
|
|
7
|
-
async function parseToNodeImage(arrayBuffer, options) {
|
|
8
|
-
const { mimeType } = (0, binary_image_api_1.getBinaryImageMetadata)(arrayBuffer) || {};
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
const _parseImageNode = globalThis._parseImageNode;
|
|
11
|
-
(0, loader_utils_1.assert)(_parseImageNode); // '@loaders.gl/polyfills not installed'
|
|
12
|
-
// @ts-expect-error TODO should we throw error in this case?
|
|
13
|
-
return await _parseImageNode(arrayBuffer, mimeType);
|
|
14
|
-
}
|
|
15
|
-
exports.parseToNodeImage = parseToNodeImage;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// SVG parsing has limitations, e.g:
|
|
3
|
-
// https://bugs.chromium.org/p/chromium/issues/detail?id=606319
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.getBlob = exports.getBlobOrSVGDataUrl = exports.isSVG = void 0;
|
|
6
|
-
const SVG_DATA_URL_PATTERN = /^data:image\/svg\+xml/;
|
|
7
|
-
const SVG_URL_PATTERN = /\.svg((\?|#).*)?$/;
|
|
8
|
-
function isSVG(url) {
|
|
9
|
-
return url && (SVG_DATA_URL_PATTERN.test(url) || SVG_URL_PATTERN.test(url));
|
|
10
|
-
}
|
|
11
|
-
exports.isSVG = isSVG;
|
|
12
|
-
function getBlobOrSVGDataUrl(arrayBuffer, url) {
|
|
13
|
-
if (isSVG(url)) {
|
|
14
|
-
// Prepare a properly tagged data URL, and load using normal mechanism
|
|
15
|
-
const textDecoder = new TextDecoder();
|
|
16
|
-
let xmlText = textDecoder.decode(arrayBuffer);
|
|
17
|
-
// TODO Escape in browser to support e.g. Chinese characters
|
|
18
|
-
try {
|
|
19
|
-
if (typeof unescape === 'function' && typeof encodeURIComponent === 'function') {
|
|
20
|
-
xmlText = unescape(encodeURIComponent(xmlText));
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
throw new Error(error.message);
|
|
25
|
-
}
|
|
26
|
-
// base64 encoding is safer. utf-8 fails in some browsers
|
|
27
|
-
const src = `data:image/svg+xml;base64,${btoa(xmlText)}`;
|
|
28
|
-
return src;
|
|
29
|
-
}
|
|
30
|
-
return getBlob(arrayBuffer, url);
|
|
31
|
-
}
|
|
32
|
-
exports.getBlobOrSVGDataUrl = getBlobOrSVGDataUrl;
|
|
33
|
-
function getBlob(arrayBuffer, url) {
|
|
34
|
-
if (isSVG(url)) {
|
|
35
|
-
// https://bugs.chromium.org/p/chromium/issues/detail?id=606319
|
|
36
|
-
// return new Blob([new Uint8Array(arrayBuffer)], {type: 'image/svg+xml'});
|
|
37
|
-
throw new Error('SVG cannot be parsed directly to imagebitmap');
|
|
38
|
-
}
|
|
39
|
-
// TODO - how to determine mime type? Param? Sniff here?
|
|
40
|
-
return new Blob([new Uint8Array(arrayBuffer)]); // MIME type not needed?
|
|
41
|
-
}
|
|
42
|
-
exports.getBlob = getBlob;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Asynchronously maps a deep structure of values (e.g. objects and arrays of urls).
|
|
4
|
-
|
|
5
|
-
E.g. a mipmapped cubemap
|
|
6
|
-
{
|
|
7
|
-
[CUBE_FACE_FRONT]: [
|
|
8
|
-
"image-front-0.jpg",
|
|
9
|
-
"image-front-1.jpg",
|
|
10
|
-
"image-front-2.jpg",
|
|
11
|
-
],
|
|
12
|
-
[CUBE_MAP_BACK]: [
|
|
13
|
-
...
|
|
14
|
-
]
|
|
15
|
-
}
|
|
16
|
-
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.mapSubtree = exports.asyncDeepMap = void 0;
|
|
19
|
-
const isObject = (value) => value && typeof value === 'object';
|
|
20
|
-
// Loads a deep structure of urls (objects and arrays of urls)
|
|
21
|
-
// Returns an object with six key-value pairs containing the images (or image mip arrays)
|
|
22
|
-
// for each cube face
|
|
23
|
-
async function asyncDeepMap(tree, func, options = {}) {
|
|
24
|
-
return await mapSubtree(tree, func, options);
|
|
25
|
-
}
|
|
26
|
-
exports.asyncDeepMap = asyncDeepMap;
|
|
27
|
-
async function mapSubtree(object, func, options) {
|
|
28
|
-
if (Array.isArray(object)) {
|
|
29
|
-
return await mapArray(object, func, options);
|
|
30
|
-
}
|
|
31
|
-
if (isObject(object)) {
|
|
32
|
-
return await mapObject(object, func, options);
|
|
33
|
-
}
|
|
34
|
-
// TODO - ignore non-urls, non-arraybuffers?
|
|
35
|
-
const url = object;
|
|
36
|
-
return await func(url, options);
|
|
37
|
-
}
|
|
38
|
-
exports.mapSubtree = mapSubtree;
|
|
39
|
-
// HELPERS
|
|
40
|
-
async function mapObject(object, func, options) {
|
|
41
|
-
const promises = [];
|
|
42
|
-
const values = {};
|
|
43
|
-
for (const key in object) {
|
|
44
|
-
const url = object[key];
|
|
45
|
-
const promise = mapSubtree(url, func, options).then((value) => {
|
|
46
|
-
values[key] = value;
|
|
47
|
-
});
|
|
48
|
-
promises.push(promise);
|
|
49
|
-
}
|
|
50
|
-
await Promise.all(promises);
|
|
51
|
-
return values;
|
|
52
|
-
}
|
|
53
|
-
async function mapArray(urlArray, func, options = {}) {
|
|
54
|
-
const promises = urlArray.map((url) => mapSubtree(url, func, options));
|
|
55
|
-
return await Promise.all(promises);
|
|
56
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.shallowLoad = exports.deepLoad = void 0;
|
|
4
|
-
const async_deep_map_1 = require("./async-deep-map");
|
|
5
|
-
async function deepLoad(urlTree, load, options) {
|
|
6
|
-
return await (0, async_deep_map_1.asyncDeepMap)(urlTree, (url) => shallowLoad(url, load, options));
|
|
7
|
-
}
|
|
8
|
-
exports.deepLoad = deepLoad;
|
|
9
|
-
async function shallowLoad(url, load, options) {
|
|
10
|
-
const response = await fetch(url, options.fetch);
|
|
11
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
12
|
-
return await load(arrayBuffer, options);
|
|
13
|
-
}
|
|
14
|
-
exports.shallowLoad = shallowLoad;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateUrl = void 0;
|
|
4
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
-
// Generate a url by calling getUrl with mix of options, applying options.baseUrl
|
|
6
|
-
function generateUrl(getUrl, options, urlOptions) {
|
|
7
|
-
// Get url
|
|
8
|
-
let url = getUrl;
|
|
9
|
-
if (typeof getUrl === 'function') {
|
|
10
|
-
url = getUrl({ ...options, ...urlOptions });
|
|
11
|
-
}
|
|
12
|
-
(0, loader_utils_1.assert)(typeof url === 'string');
|
|
13
|
-
// Apply options.baseUrl
|
|
14
|
-
const { baseUrl } = options;
|
|
15
|
-
if (baseUrl) {
|
|
16
|
-
url = baseUrl[baseUrl.length - 1] === '/' ? `${baseUrl}${url}` : `${baseUrl}/${url}`;
|
|
17
|
-
}
|
|
18
|
-
return (0, loader_utils_1.resolvePath)(url);
|
|
19
|
-
}
|
|
20
|
-
exports.generateUrl = generateUrl;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMipLevels = exports.getImageUrls = exports.loadImage = void 0;
|
|
4
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
-
const parse_image_1 = require("../parsers/parse-image");
|
|
6
|
-
const parsed_image_api_1 = require("../category-api/parsed-image-api");
|
|
7
|
-
const generate_url_1 = require("./generate-url");
|
|
8
|
-
const deep_load_1 = require("./deep-load");
|
|
9
|
-
async function loadImage(getUrl, options = {}) {
|
|
10
|
-
const imageUrls = await getImageUrls(getUrl, options);
|
|
11
|
-
return await (0, deep_load_1.deepLoad)(imageUrls, parse_image_1.parseImage, options);
|
|
12
|
-
}
|
|
13
|
-
exports.loadImage = loadImage;
|
|
14
|
-
async function getImageUrls(getUrl, options, urlOptions = {}) {
|
|
15
|
-
const mipLevels = (options && options.image && options.image.mipLevels) || 0;
|
|
16
|
-
return mipLevels !== 0
|
|
17
|
-
? await getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions)
|
|
18
|
-
: (0, generate_url_1.generateUrl)(getUrl, options, urlOptions);
|
|
19
|
-
}
|
|
20
|
-
exports.getImageUrls = getImageUrls;
|
|
21
|
-
async function getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions) {
|
|
22
|
-
const urls = [];
|
|
23
|
-
// If no mip levels supplied, we need to load the level 0 image and calculate based on size
|
|
24
|
-
if (mipLevels === 'auto') {
|
|
25
|
-
const url = (0, generate_url_1.generateUrl)(getUrl, options, { ...urlOptions, lod: 0 });
|
|
26
|
-
const image = await (0, deep_load_1.shallowLoad)(url, parse_image_1.parseImage, options);
|
|
27
|
-
const { width, height } = (0, parsed_image_api_1.getImageSize)(image);
|
|
28
|
-
mipLevels = getMipLevels({ width, height });
|
|
29
|
-
// TODO - push image and make `deepLoad` pass through non-url values, avoid loading twice?
|
|
30
|
-
urls.push(url);
|
|
31
|
-
}
|
|
32
|
-
// We now know how many mipLevels we need, remaining image urls can now be constructed
|
|
33
|
-
(0, loader_utils_1.assert)(mipLevels > 0);
|
|
34
|
-
for (let mipLevel = urls.length; mipLevel < mipLevels; ++mipLevel) {
|
|
35
|
-
const url = (0, generate_url_1.generateUrl)(getUrl, options, { ...urlOptions, lod: mipLevel });
|
|
36
|
-
urls.push(url);
|
|
37
|
-
}
|
|
38
|
-
return urls;
|
|
39
|
-
}
|
|
40
|
-
// Calculates number of mipmaps based on texture size (log2)
|
|
41
|
-
function getMipLevels({ width, height }) {
|
|
42
|
-
return 1 + Math.floor(Math.log2(Math.max(width, height)));
|
|
43
|
-
}
|
|
44
|
-
exports.getMipLevels = getMipLevels;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VERSION = void 0;
|
|
4
|
-
// Version constant cannot be imported, it needs to correspond to the build version of **this** module.
|
|
5
|
-
// __VERSION__ is injected by babel-plugin-version-inline
|
|
6
|
-
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
7
|
-
exports.VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
package/dist/types.js
DELETED