@loaders.gl/images 4.0.0-alpha.9 → 4.0.0-beta.1
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 +1 -1
- package/dist/dist.min.js.map +2 -2
- package/dist/es5/image-loader.js +2 -3
- package/dist/es5/image-loader.js.map +1 -1
- package/dist/es5/image-writer.js.map +1 -1
- package/dist/es5/lib/parsers/parse-image.js +7 -7
- package/dist/es5/lib/parsers/parse-image.js.map +1 -1
- package/dist/es5/lib/parsers/parse-to-image-bitmap.js +3 -3
- package/dist/es5/lib/parsers/parse-to-image-bitmap.js.map +1 -1
- package/dist/es5/lib/parsers/parse-to-image.js +1 -1
- package/dist/es5/lib/parsers/parse-to-image.js.map +1 -1
- package/dist/es5/lib/parsers/parse-to-node-image.js +1 -1
- package/dist/es5/lib/parsers/parse-to-node-image.js.map +1 -1
- package/dist/es5/lib/texture-api/deep-load.js.map +1 -1
- package/dist/es5/lib/texture-api/load-image.js +3 -3
- package/dist/es5/lib/texture-api/load-image.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/es5/lib/utils/version.js.map +1 -1
- package/dist/esm/image-loader.js +1 -1
- package/dist/esm/image-loader.js.map +1 -1
- package/dist/esm/image-writer.js.map +1 -1
- package/dist/esm/lib/parsers/parse-image.js +4 -4
- package/dist/esm/lib/parsers/parse-image.js.map +1 -1
- package/dist/esm/lib/parsers/parse-to-image-bitmap.js +2 -2
- package/dist/esm/lib/parsers/parse-to-image-bitmap.js.map +1 -1
- package/dist/esm/lib/parsers/parse-to-image.js +1 -1
- package/dist/esm/lib/parsers/parse-to-image.js.map +1 -1
- package/dist/esm/lib/parsers/parse-to-node-image.js +1 -1
- package/dist/esm/lib/parsers/parse-to-node-image.js.map +1 -1
- package/dist/esm/lib/texture-api/deep-load.js.map +1 -1
- package/dist/esm/lib/texture-api/load-image.js +1 -1
- package/dist/esm/lib/texture-api/load-image.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/esm/lib/utils/version.js.map +1 -1
- package/dist/image-writer.d.ts +3 -3
- package/dist/image-writer.d.ts.map +1 -1
- package/dist/lib/parsers/parse-image.d.ts +1 -1
- package/dist/lib/parsers/parse-image.d.ts.map +1 -1
- package/dist/lib/parsers/parse-to-image-bitmap.d.ts +1 -1
- package/dist/lib/parsers/parse-to-image-bitmap.d.ts.map +1 -1
- package/dist/lib/parsers/parse-to-image.d.ts +1 -1
- package/dist/lib/parsers/parse-to-image.d.ts.map +1 -1
- package/dist/lib/parsers/parse-to-node-image.d.ts +1 -1
- package/dist/lib/parsers/parse-to-node-image.d.ts.map +1 -1
- package/dist/lib/texture-api/deep-load.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/image-loader.ts +1 -1
- package/src/image-writer.ts +3 -3
- package/src/lib/parsers/parse-image.ts +4 -4
- package/src/lib/parsers/parse-to-image-bitmap.ts +2 -2
- package/src/lib/parsers/parse-to-image.ts +1 -1
- package/src/lib/parsers/parse-to-node-image.ts +1 -1
- package/src/lib/texture-api/deep-load.ts +0 -1
- package/src/lib/texture-api/load-image.ts +1 -1
- package/dist/bundle.js +0 -5
- package/dist/image-loader.js +0 -44
- 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 -57
- package/dist/lib/parsers/parse-to-image-bitmap.js +0 -61
- package/dist/lib/parsers/parse-to-image.js +0 -47
- package/dist/lib/parsers/parse-to-node-image.js +0 -14
- 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 -15
- package/dist/lib/texture-api/generate-url.js +0 -20
- package/dist/lib/texture-api/load-image.js +0 -47
- package/dist/lib/utils/version.js +0 -7
- package/dist/types.js +0 -2
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
7
|
-
const image_type_1 = require("../category-api/image-type");
|
|
8
|
-
const parsed_image_api_1 = require("../category-api/parsed-image-api");
|
|
9
|
-
const parse_to_image_1 = __importDefault(require("./parse-to-image"));
|
|
10
|
-
const parse_to_image_bitmap_1 = __importDefault(require("./parse-to-image-bitmap"));
|
|
11
|
-
const parse_to_node_image_1 = __importDefault(require("./parse-to-node-image"));
|
|
12
|
-
// Parse to platform defined image type (data on node, ImageBitmap or HTMLImage on browser)
|
|
13
|
-
// eslint-disable-next-line complexity
|
|
14
|
-
async function parseImage(arrayBuffer, options, context) {
|
|
15
|
-
options = options || {};
|
|
16
|
-
const imageOptions = options.image || {};
|
|
17
|
-
// The user can request a specific output format via `options.image.type`
|
|
18
|
-
const imageType = imageOptions.type || 'auto';
|
|
19
|
-
const { url } = context || {};
|
|
20
|
-
// Note: For options.image.type === `data`, we may still need to load as `image` or `imagebitmap`
|
|
21
|
-
const loadType = getLoadableImageType(imageType);
|
|
22
|
-
let image;
|
|
23
|
-
switch (loadType) {
|
|
24
|
-
case 'imagebitmap':
|
|
25
|
-
image = await (0, parse_to_image_bitmap_1.default)(arrayBuffer, options, url);
|
|
26
|
-
break;
|
|
27
|
-
case 'image':
|
|
28
|
-
image = await (0, parse_to_image_1.default)(arrayBuffer, options, url);
|
|
29
|
-
break;
|
|
30
|
-
case 'data':
|
|
31
|
-
// Node.js loads imagedata directly
|
|
32
|
-
image = await (0, parse_to_node_image_1.default)(arrayBuffer, options);
|
|
33
|
-
break;
|
|
34
|
-
default:
|
|
35
|
-
(0, loader_utils_1.assert)(false);
|
|
36
|
-
}
|
|
37
|
-
// Browser: if options.image.type === 'data', we can now extract data from the loaded image
|
|
38
|
-
if (imageType === 'data') {
|
|
39
|
-
image = (0, parsed_image_api_1.getImageData)(image);
|
|
40
|
-
}
|
|
41
|
-
return image;
|
|
42
|
-
}
|
|
43
|
-
exports.default = parseImage;
|
|
44
|
-
// Get a loadable image type from image type
|
|
45
|
-
function getLoadableImageType(type) {
|
|
46
|
-
switch (type) {
|
|
47
|
-
case 'auto':
|
|
48
|
-
case 'data':
|
|
49
|
-
// Browser: For image data we need still need to load using an image format
|
|
50
|
-
// Node: the default image type is `data`.
|
|
51
|
-
return (0, image_type_1.getDefaultImageType)();
|
|
52
|
-
default:
|
|
53
|
-
// Throw an error if not supported
|
|
54
|
-
(0, image_type_1.isImageTypeSupported)(type);
|
|
55
|
-
return type;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const svg_utils_1 = require("./svg-utils");
|
|
7
|
-
const parse_to_image_1 = __importDefault(require("./parse-to-image"));
|
|
8
|
-
const EMPTY_OBJECT = {};
|
|
9
|
-
let imagebitmapOptionsSupported = true;
|
|
10
|
-
/**
|
|
11
|
-
* Asynchronously parses an array buffer into an ImageBitmap - this contains the decoded data
|
|
12
|
-
* ImageBitmaps are supported on worker threads, but not supported on Edge, IE11 and Safari
|
|
13
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap#Browser_compatibility
|
|
14
|
-
*
|
|
15
|
-
* TODO - createImageBitmap supports source rect (5 param overload), pass through?
|
|
16
|
-
*/
|
|
17
|
-
async function parseToImageBitmap(arrayBuffer, options, url) {
|
|
18
|
-
let blob;
|
|
19
|
-
// Cannot parse SVG directly to ImageBitmap, parse to Image first
|
|
20
|
-
if ((0, svg_utils_1.isSVG)(url)) {
|
|
21
|
-
// Note: this only works on main thread
|
|
22
|
-
const image = await (0, parse_to_image_1.default)(arrayBuffer, options, url);
|
|
23
|
-
blob = image;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
// Create blob from the array buffer
|
|
27
|
-
blob = (0, svg_utils_1.getBlob)(arrayBuffer, url);
|
|
28
|
-
}
|
|
29
|
-
const imagebitmapOptions = options && options.imagebitmap;
|
|
30
|
-
return await safeCreateImageBitmap(blob, imagebitmapOptions);
|
|
31
|
-
}
|
|
32
|
-
exports.default = parseToImageBitmap;
|
|
33
|
-
/**
|
|
34
|
-
* Safely creates an imageBitmap with options
|
|
35
|
-
* *
|
|
36
|
-
* Firefox crashes if imagebitmapOptions is supplied
|
|
37
|
-
* Avoid supplying if not provided or supported, remember if not supported
|
|
38
|
-
*/
|
|
39
|
-
async function safeCreateImageBitmap(blob, imagebitmapOptions = null) {
|
|
40
|
-
if (isEmptyObject(imagebitmapOptions) || !imagebitmapOptionsSupported) {
|
|
41
|
-
imagebitmapOptions = null;
|
|
42
|
-
}
|
|
43
|
-
if (imagebitmapOptions) {
|
|
44
|
-
try {
|
|
45
|
-
// @ts-ignore Options
|
|
46
|
-
return await createImageBitmap(blob, imagebitmapOptions);
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
console.warn(error); // eslint-disable-line
|
|
50
|
-
imagebitmapOptionsSupported = false;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return await createImageBitmap(blob);
|
|
54
|
-
}
|
|
55
|
-
function isEmptyObject(object) {
|
|
56
|
-
// @ts-ignore
|
|
57
|
-
for (const key in object || EMPTY_OBJECT) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadToImage = 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.default = 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,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
4
|
-
const binary_image_api_1 = require("../category-api/binary-image-api");
|
|
5
|
-
// Use polyfills if installed to parsed image using get-pixels
|
|
6
|
-
async function parseToNodeImage(arrayBuffer, options) {
|
|
7
|
-
const { mimeType } = (0, binary_image_api_1.getBinaryImageMetadata)(arrayBuffer) || {};
|
|
8
|
-
// @ts-ignore
|
|
9
|
-
const _parseImageNode = globalThis._parseImageNode;
|
|
10
|
-
(0, loader_utils_1.assert)(_parseImageNode); // '@loaders.gl/polyfills not installed'
|
|
11
|
-
// @ts-expect-error TODO should we throw error in this case?
|
|
12
|
-
return await _parseImageNode(arrayBuffer, mimeType);
|
|
13
|
-
}
|
|
14
|
-
exports.default = 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,15 +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
|
-
// console.error('loading', url);
|
|
11
|
-
const response = await fetch(url, options.fetch);
|
|
12
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
13
|
-
return await load(arrayBuffer, options);
|
|
14
|
-
}
|
|
15
|
-
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,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getMipLevels = exports.getImageUrls = exports.loadImage = void 0;
|
|
7
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
8
|
-
const parse_image_1 = __importDefault(require("../parsers/parse-image"));
|
|
9
|
-
const parsed_image_api_1 = require("../category-api/parsed-image-api");
|
|
10
|
-
const generate_url_1 = require("./generate-url");
|
|
11
|
-
const deep_load_1 = require("./deep-load");
|
|
12
|
-
async function loadImage(getUrl, options = {}) {
|
|
13
|
-
const imageUrls = await getImageUrls(getUrl, options);
|
|
14
|
-
return await (0, deep_load_1.deepLoad)(imageUrls, parse_image_1.default, options);
|
|
15
|
-
}
|
|
16
|
-
exports.loadImage = loadImage;
|
|
17
|
-
async function getImageUrls(getUrl, options, urlOptions = {}) {
|
|
18
|
-
const mipLevels = (options && options.image && options.image.mipLevels) || 0;
|
|
19
|
-
return mipLevels !== 0
|
|
20
|
-
? await getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions)
|
|
21
|
-
: (0, generate_url_1.generateUrl)(getUrl, options, urlOptions);
|
|
22
|
-
}
|
|
23
|
-
exports.getImageUrls = getImageUrls;
|
|
24
|
-
async function getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions) {
|
|
25
|
-
const urls = [];
|
|
26
|
-
// If no mip levels supplied, we need to load the level 0 image and calculate based on size
|
|
27
|
-
if (mipLevels === 'auto') {
|
|
28
|
-
const url = (0, generate_url_1.generateUrl)(getUrl, options, { ...urlOptions, lod: 0 });
|
|
29
|
-
const image = await (0, deep_load_1.shallowLoad)(url, parse_image_1.default, options);
|
|
30
|
-
const { width, height } = (0, parsed_image_api_1.getImageSize)(image);
|
|
31
|
-
mipLevels = getMipLevels({ width, height });
|
|
32
|
-
// TODO - push image and make `deepLoad` pass through non-url values, avoid loading twice?
|
|
33
|
-
urls.push(url);
|
|
34
|
-
}
|
|
35
|
-
// We now know how many mipLevels we need, remaining image urls can now be constructed
|
|
36
|
-
(0, loader_utils_1.assert)(mipLevels > 0);
|
|
37
|
-
for (let mipLevel = urls.length; mipLevel < mipLevels; ++mipLevel) {
|
|
38
|
-
const url = (0, generate_url_1.generateUrl)(getUrl, options, { ...urlOptions, lod: mipLevel });
|
|
39
|
-
urls.push(url);
|
|
40
|
-
}
|
|
41
|
-
return urls;
|
|
42
|
-
}
|
|
43
|
-
// Calculates number of mipmaps based on texture size (log2)
|
|
44
|
-
function getMipLevels({ width, height }) {
|
|
45
|
-
return 1 + Math.floor(Math.log2(Math.max(width, height)));
|
|
46
|
-
}
|
|
47
|
-
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