@loaders.gl/images 3.4.11 → 3.4.13
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/es5/lib/utils/version.js +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/package.json +3 -3
- package/dist/bundle.js +0 -5
- package/dist/image-loader.js +0 -44
- package/dist/image-writer.js +0 -20
- 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 -82
- 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
|
@@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.VERSION = void 0;
|
|
7
|
-
var VERSION = typeof "3.4.
|
|
7
|
+
var VERSION = typeof "3.4.13" !== 'undefined' ? "3.4.13" : 'latest';
|
|
8
8
|
exports.VERSION = VERSION;
|
|
9
9
|
//# sourceMappingURL=version.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = typeof "3.4.
|
|
1
|
+
export const VERSION = typeof "3.4.13" !== 'undefined' ? "3.4.13" : 'latest';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/images",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.13",
|
|
4
4
|
"description": "Framework-independent loaders and writers for images (PNG, JPG, ...)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"build-bundle": "esbuild src/bundle.ts --outfile=dist/dist.min.js --bundle --minify --sourcemap"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@loaders.gl/loader-utils": "3.4.
|
|
35
|
+
"@loaders.gl/loader-utils": "3.4.13"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "be8849c02972ce541e01720d29b976f830d6af92",
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/get-pixels": "^3.3.2"
|
|
40
40
|
}
|
package/dist/bundle.js
DELETED
package/dist/image-loader.js
DELETED
|
@@ -1,44 +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._typecheckImageLoader = exports.ImageLoader = void 0;
|
|
7
|
-
const version_1 = require("./lib/utils/version");
|
|
8
|
-
const parse_image_1 = __importDefault(require("./lib/parsers/parse-image"));
|
|
9
|
-
const binary_image_api_1 = require("./lib/category-api/binary-image-api");
|
|
10
|
-
const EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'ico', 'svg', 'avif'];
|
|
11
|
-
const MIME_TYPES = [
|
|
12
|
-
'image/png',
|
|
13
|
-
'image/jpeg',
|
|
14
|
-
'image/gif',
|
|
15
|
-
'image/webp',
|
|
16
|
-
'image/avif',
|
|
17
|
-
'image/bmp',
|
|
18
|
-
'image/vnd.microsoft.icon',
|
|
19
|
-
'image/svg+xml'
|
|
20
|
-
];
|
|
21
|
-
const DEFAULT_IMAGE_LOADER_OPTIONS = {
|
|
22
|
-
image: {
|
|
23
|
-
type: 'auto',
|
|
24
|
-
decode: true // if format is HTML
|
|
25
|
-
}
|
|
26
|
-
// imagebitmap: {} - passes (platform dependent) parameters to ImageBitmap constructor
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Loads a platform-specific image type
|
|
30
|
-
* Note: This type can be used as input data to WebGL texture creation
|
|
31
|
-
*/
|
|
32
|
-
exports.ImageLoader = {
|
|
33
|
-
id: 'image',
|
|
34
|
-
module: 'images',
|
|
35
|
-
name: 'Images',
|
|
36
|
-
version: version_1.VERSION,
|
|
37
|
-
mimeTypes: MIME_TYPES,
|
|
38
|
-
extensions: EXTENSIONS,
|
|
39
|
-
parse: parse_image_1.default,
|
|
40
|
-
// TODO: byteOffset, byteLength;
|
|
41
|
-
tests: [(arrayBuffer) => Boolean((0, binary_image_api_1.getBinaryImageMetadata)(new DataView(arrayBuffer)))],
|
|
42
|
-
options: DEFAULT_IMAGE_LOADER_OPTIONS
|
|
43
|
-
};
|
|
44
|
-
exports._typecheckImageLoader = exports.ImageLoader;
|
package/dist/image-writer.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImageWriter = void 0;
|
|
4
|
-
// import type {Writer} from '@loaders.gl/loader-utils';
|
|
5
|
-
const version_1 = require("./lib/utils/version");
|
|
6
|
-
const encode_image_1 = require("./lib/encoders/encode-image");
|
|
7
|
-
exports.ImageWriter = {
|
|
8
|
-
name: 'Images',
|
|
9
|
-
id: 'image',
|
|
10
|
-
module: 'images',
|
|
11
|
-
version: version_1.VERSION,
|
|
12
|
-
extensions: ['jpeg'],
|
|
13
|
-
options: {
|
|
14
|
-
image: {
|
|
15
|
-
mimeType: 'image/png',
|
|
16
|
-
jpegQuality: null
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
encode: encode_image_1.encodeImage
|
|
20
|
-
};
|
package/dist/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadImage = exports.isImageFormatSupported = exports.getSupportedImageFormats = exports.getImageData = exports.getImageSize = exports.getImageType = exports.isImage = exports.getDefaultImageType = exports.isImageTypeSupported = exports.getBinaryImageMetadata = exports.ImageWriter = exports.ImageLoader = void 0;
|
|
4
|
-
// LOADERS AND WRITERS
|
|
5
|
-
var image_loader_1 = require("./image-loader");
|
|
6
|
-
Object.defineProperty(exports, "ImageLoader", { enumerable: true, get: function () { return image_loader_1.ImageLoader; } });
|
|
7
|
-
var image_writer_1 = require("./image-writer");
|
|
8
|
-
Object.defineProperty(exports, "ImageWriter", { enumerable: true, get: function () { return image_writer_1.ImageWriter; } });
|
|
9
|
-
// IMAGE CATEGORY API
|
|
10
|
-
// Binary Image API
|
|
11
|
-
var binary_image_api_1 = require("./lib/category-api/binary-image-api");
|
|
12
|
-
Object.defineProperty(exports, "getBinaryImageMetadata", { enumerable: true, get: function () { return binary_image_api_1.getBinaryImageMetadata; } });
|
|
13
|
-
// Parsed Image API
|
|
14
|
-
var image_type_1 = require("./lib/category-api/image-type");
|
|
15
|
-
Object.defineProperty(exports, "isImageTypeSupported", { enumerable: true, get: function () { return image_type_1.isImageTypeSupported; } });
|
|
16
|
-
Object.defineProperty(exports, "getDefaultImageType", { enumerable: true, get: function () { return image_type_1.getDefaultImageType; } });
|
|
17
|
-
var parsed_image_api_1 = require("./lib/category-api/parsed-image-api");
|
|
18
|
-
Object.defineProperty(exports, "isImage", { enumerable: true, get: function () { return parsed_image_api_1.isImage; } });
|
|
19
|
-
Object.defineProperty(exports, "getImageType", { enumerable: true, get: function () { return parsed_image_api_1.getImageType; } });
|
|
20
|
-
Object.defineProperty(exports, "getImageSize", { enumerable: true, get: function () { return parsed_image_api_1.getImageSize; } });
|
|
21
|
-
Object.defineProperty(exports, "getImageData", { enumerable: true, get: function () { return parsed_image_api_1.getImageData; } });
|
|
22
|
-
// EXPERIMENTAL
|
|
23
|
-
var image_format_1 = require("./lib/category-api/image-format");
|
|
24
|
-
Object.defineProperty(exports, "getSupportedImageFormats", { enumerable: true, get: function () { return image_format_1.getSupportedImageFormats; } });
|
|
25
|
-
var image_format_2 = require("./lib/category-api/image-format");
|
|
26
|
-
Object.defineProperty(exports, "isImageFormatSupported", { enumerable: true, get: function () { return image_format_2.isImageFormatSupported; } });
|
|
27
|
-
// DEPRECATED - Remove in V4 (fix dependency in luma.gl)
|
|
28
|
-
var load_image_1 = require("./lib/texture-api/load-image");
|
|
29
|
-
Object.defineProperty(exports, "loadImage", { enumerable: true, get: function () { return load_image_1.loadImage; } });
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Attributions
|
|
3
|
-
// * Based on binary-gltf-utils under MIT license: Copyright (c) 2016-17 Karl Cheng
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.getBmpMetadata = exports.getBinaryImageMetadata = void 0;
|
|
6
|
-
// TODO: make these functions work for Node.js buffers?
|
|
7
|
-
// Quarantine references to Buffer to prevent bundler from adding big polyfills
|
|
8
|
-
// import {bufferToArrayBuffer} from '../node/buffer-to-array-buffer';
|
|
9
|
-
// TODO - this should be handled in @loaders.gl/polyfills
|
|
10
|
-
const parse_isobmff_binary_1 = require("./parse-isobmff-binary");
|
|
11
|
-
const BIG_ENDIAN = false;
|
|
12
|
-
const LITTLE_ENDIAN = true;
|
|
13
|
-
/**
|
|
14
|
-
* Extracts `{mimeType, width and height}` from a memory buffer containing a known image format
|
|
15
|
-
* Currently supports `image/png`, `image/jpeg`, `image/bmp` and `image/gif`.
|
|
16
|
-
* @param binaryData: DataView | ArrayBuffer image file memory to parse
|
|
17
|
-
* @returns metadata or null if memory is not a valid image file format layout.
|
|
18
|
-
*/
|
|
19
|
-
function getBinaryImageMetadata(binaryData) {
|
|
20
|
-
const dataView = toDataView(binaryData);
|
|
21
|
-
return (getPngMetadata(dataView) ||
|
|
22
|
-
getJpegMetadata(dataView) ||
|
|
23
|
-
getGifMetadata(dataView) ||
|
|
24
|
-
getBmpMetadata(dataView) ||
|
|
25
|
-
getISOBMFFMetadata(dataView));
|
|
26
|
-
}
|
|
27
|
-
exports.getBinaryImageMetadata = getBinaryImageMetadata;
|
|
28
|
-
// ISOBMFF
|
|
29
|
-
function getISOBMFFMetadata(binaryData) {
|
|
30
|
-
const buffer = new Uint8Array(binaryData instanceof DataView ? binaryData.buffer : binaryData);
|
|
31
|
-
const mediaType = (0, parse_isobmff_binary_1.getISOBMFFMediaType)(buffer);
|
|
32
|
-
if (!mediaType) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
mimeType: mediaType.mimeType,
|
|
37
|
-
// TODO - decode width and height
|
|
38
|
-
width: 0,
|
|
39
|
-
height: 0
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
// PNG
|
|
43
|
-
function getPngMetadata(binaryData) {
|
|
44
|
-
const dataView = toDataView(binaryData);
|
|
45
|
-
// Check file contains the first 4 bytes of the PNG signature.
|
|
46
|
-
const isPng = dataView.byteLength >= 24 && dataView.getUint32(0, BIG_ENDIAN) === 0x89504e47;
|
|
47
|
-
if (!isPng) {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
// Extract size from a binary PNG file
|
|
51
|
-
return {
|
|
52
|
-
mimeType: 'image/png',
|
|
53
|
-
width: dataView.getUint32(16, BIG_ENDIAN),
|
|
54
|
-
height: dataView.getUint32(20, BIG_ENDIAN)
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
// GIF
|
|
58
|
-
// Extract size from a binary GIF file
|
|
59
|
-
// TODO: GIF is not this simple
|
|
60
|
-
function getGifMetadata(binaryData) {
|
|
61
|
-
const dataView = toDataView(binaryData);
|
|
62
|
-
// Check first 4 bytes of the GIF signature ("GIF8").
|
|
63
|
-
const isGif = dataView.byteLength >= 10 && dataView.getUint32(0, BIG_ENDIAN) === 0x47494638;
|
|
64
|
-
if (!isGif) {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
// GIF is little endian.
|
|
68
|
-
return {
|
|
69
|
-
mimeType: 'image/gif',
|
|
70
|
-
width: dataView.getUint16(6, LITTLE_ENDIAN),
|
|
71
|
-
height: dataView.getUint16(8, LITTLE_ENDIAN)
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
// BMP
|
|
75
|
-
// TODO: BMP is not this simple
|
|
76
|
-
function getBmpMetadata(binaryData) {
|
|
77
|
-
const dataView = toDataView(binaryData);
|
|
78
|
-
// Check magic number is valid (first 2 characters should be "BM").
|
|
79
|
-
// The mandatory bitmap file header is 14 bytes long.
|
|
80
|
-
const isBmp = dataView.byteLength >= 14 &&
|
|
81
|
-
dataView.getUint16(0, BIG_ENDIAN) === 0x424d &&
|
|
82
|
-
dataView.getUint32(2, LITTLE_ENDIAN) === dataView.byteLength;
|
|
83
|
-
if (!isBmp) {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
// BMP is little endian.
|
|
87
|
-
return {
|
|
88
|
-
mimeType: 'image/bmp',
|
|
89
|
-
width: dataView.getUint32(18, LITTLE_ENDIAN),
|
|
90
|
-
height: dataView.getUint32(22, LITTLE_ENDIAN)
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
exports.getBmpMetadata = getBmpMetadata;
|
|
94
|
-
// JPEG
|
|
95
|
-
// Extract width and height from a binary JPEG file
|
|
96
|
-
function getJpegMetadata(binaryData) {
|
|
97
|
-
const dataView = toDataView(binaryData);
|
|
98
|
-
// Check file contains the JPEG "start of image" (SOI) marker
|
|
99
|
-
// followed by another marker.
|
|
100
|
-
const isJpeg = dataView.byteLength >= 3 &&
|
|
101
|
-
dataView.getUint16(0, BIG_ENDIAN) === 0xffd8 &&
|
|
102
|
-
dataView.getUint8(2) === 0xff;
|
|
103
|
-
if (!isJpeg) {
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
const { tableMarkers, sofMarkers } = getJpegMarkers();
|
|
107
|
-
// Exclude the two byte SOI marker.
|
|
108
|
-
let i = 2;
|
|
109
|
-
while (i + 9 < dataView.byteLength) {
|
|
110
|
-
const marker = dataView.getUint16(i, BIG_ENDIAN);
|
|
111
|
-
// The frame that contains the width and height of the JPEG image.
|
|
112
|
-
if (sofMarkers.has(marker)) {
|
|
113
|
-
return {
|
|
114
|
-
mimeType: 'image/jpeg',
|
|
115
|
-
height: dataView.getUint16(i + 5, BIG_ENDIAN),
|
|
116
|
-
width: dataView.getUint16(i + 7, BIG_ENDIAN) // Number of pixels per line
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
// Miscellaneous tables/data preceding the frame header.
|
|
120
|
-
if (!tableMarkers.has(marker)) {
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
// Length includes size of length parameter but not the two byte header.
|
|
124
|
-
i += 2;
|
|
125
|
-
i += dataView.getUint16(i, BIG_ENDIAN);
|
|
126
|
-
}
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
function getJpegMarkers() {
|
|
130
|
-
// Tables/misc header markers.
|
|
131
|
-
// DQT, DHT, DAC, DRI, COM, APP_n
|
|
132
|
-
const tableMarkers = new Set([0xffdb, 0xffc4, 0xffcc, 0xffdd, 0xfffe]);
|
|
133
|
-
for (let i = 0xffe0; i < 0xfff0; ++i) {
|
|
134
|
-
tableMarkers.add(i);
|
|
135
|
-
}
|
|
136
|
-
// SOF markers and DHP marker.
|
|
137
|
-
// These markers are after tables/misc data.
|
|
138
|
-
const sofMarkers = new Set([
|
|
139
|
-
0xffc0, 0xffc1, 0xffc2, 0xffc3, 0xffc5, 0xffc6, 0xffc7, 0xffc9, 0xffca, 0xffcb, 0xffcd, 0xffce,
|
|
140
|
-
0xffcf, 0xffde
|
|
141
|
-
]);
|
|
142
|
-
return { tableMarkers, sofMarkers };
|
|
143
|
-
}
|
|
144
|
-
// TODO - move into image module?
|
|
145
|
-
function toDataView(data) {
|
|
146
|
-
if (data instanceof DataView) {
|
|
147
|
-
return data;
|
|
148
|
-
}
|
|
149
|
-
if (ArrayBuffer.isView(data)) {
|
|
150
|
-
return new DataView(data.buffer);
|
|
151
|
-
}
|
|
152
|
-
// TODO: make these functions work for Node.js buffers?
|
|
153
|
-
// if (bufferToArrayBuffer) {
|
|
154
|
-
// data = bufferToArrayBuffer(data);
|
|
155
|
-
// }
|
|
156
|
-
// Careful - Node Buffers will look like ArrayBuffers (keep after isBuffer)
|
|
157
|
-
if (data instanceof ArrayBuffer) {
|
|
158
|
-
return new DataView(data);
|
|
159
|
-
}
|
|
160
|
-
throw new Error('toDataView');
|
|
161
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.isImageFormatSupported = exports.getSupportedImageFormats = void 0;
|
|
5
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
6
|
-
const MIME_TYPES = [
|
|
7
|
-
'image/png',
|
|
8
|
-
'image/jpeg',
|
|
9
|
-
'image/gif',
|
|
10
|
-
'image/webp',
|
|
11
|
-
'image/avif',
|
|
12
|
-
'image/tiff',
|
|
13
|
-
// TODO - what is the correct type for SVG
|
|
14
|
-
'image/svg',
|
|
15
|
-
'image/svg+xml',
|
|
16
|
-
'image/bmp',
|
|
17
|
-
'image/vnd.microsoft.icon'
|
|
18
|
-
];
|
|
19
|
-
/** Only one round of tests is performed */
|
|
20
|
-
const mimeTypeSupportedPromise = null;
|
|
21
|
-
/** Run-time browser detection of file formats requires async tests for most precise results */
|
|
22
|
-
async function getSupportedImageFormats() {
|
|
23
|
-
if (mimeTypeSupportedPromise) {
|
|
24
|
-
return await mimeTypeSupportedPromise;
|
|
25
|
-
}
|
|
26
|
-
const supportedMimeTypes = new Set();
|
|
27
|
-
for (const mimeType of MIME_TYPES) {
|
|
28
|
-
const supported = loader_utils_1.isBrowser
|
|
29
|
-
? await checkBrowserImageFormatSupportAsync(mimeType)
|
|
30
|
-
: checkNodeImageFormatSupport(mimeType);
|
|
31
|
-
if (supported) {
|
|
32
|
-
supportedMimeTypes.add(mimeType);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return supportedMimeTypes;
|
|
36
|
-
}
|
|
37
|
-
exports.getSupportedImageFormats = getSupportedImageFormats;
|
|
38
|
-
/** Cache sync values for speed */
|
|
39
|
-
const mimeTypeSupportedSync = {};
|
|
40
|
-
/**
|
|
41
|
-
* Check if image MIME type is supported. Result is cached to avoid repeated tests.
|
|
42
|
-
*/
|
|
43
|
-
function isImageFormatSupported(mimeType) {
|
|
44
|
-
if (mimeTypeSupportedSync[mimeType] === undefined) {
|
|
45
|
-
const supported = loader_utils_1.isBrowser
|
|
46
|
-
? checkBrowserImageFormatSupport(mimeType)
|
|
47
|
-
: checkNodeImageFormatSupport(mimeType);
|
|
48
|
-
mimeTypeSupportedSync[mimeType] = supported;
|
|
49
|
-
}
|
|
50
|
-
return mimeTypeSupportedSync[mimeType];
|
|
51
|
-
}
|
|
52
|
-
exports.isImageFormatSupported = isImageFormatSupported;
|
|
53
|
-
/**
|
|
54
|
-
* Checks that polyfills are installed and that mimeType is supported by polyfills
|
|
55
|
-
* @todo Ideally polyfills should declare what formats they support, instead of storing that data here.
|
|
56
|
-
*/
|
|
57
|
-
function checkNodeImageFormatSupport(mimeType) {
|
|
58
|
-
/** @deprecated Remove these in 4.0 and rely on polyfills to inject them */
|
|
59
|
-
const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];
|
|
60
|
-
// @ts-ignore
|
|
61
|
-
const { _parseImageNode, _imageFormatsNode = NODE_FORMAT_SUPPORT } = globalThis;
|
|
62
|
-
return Boolean(_parseImageNode) && _imageFormatsNode.includes(mimeType);
|
|
63
|
-
}
|
|
64
|
-
/** Checks image format support synchronously.
|
|
65
|
-
* @note Unreliable, fails on AVIF
|
|
66
|
-
*/
|
|
67
|
-
function checkBrowserImageFormatSupport(mimeType) {
|
|
68
|
-
switch (mimeType) {
|
|
69
|
-
case 'image/avif': // Will fail
|
|
70
|
-
case 'image/webp':
|
|
71
|
-
return testBrowserImageFormatSupport(mimeType);
|
|
72
|
-
default:
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
const TEST_IMAGE = {
|
|
77
|
-
'image/avif': 'data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=',
|
|
78
|
-
// Lossy test image. Support for lossy images doesn't guarantee support for all WebP images.
|
|
79
|
-
'image/webp': 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA'
|
|
80
|
-
};
|
|
81
|
-
/** Checks WebP and AVIF support asynchronously */
|
|
82
|
-
async function checkBrowserImageFormatSupportAsync(mimeType) {
|
|
83
|
-
const dataURL = TEST_IMAGE[mimeType];
|
|
84
|
-
return dataURL ? await testBrowserImageFormatSupportAsync(dataURL) : true;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Checks browser synchronously
|
|
88
|
-
* Checks if toDataURL supports the mimeType.
|
|
89
|
-
* @note Imperfect testOn Chrome this is true for WebP but not for AVIF
|
|
90
|
-
*/
|
|
91
|
-
function testBrowserImageFormatSupport(mimeType) {
|
|
92
|
-
try {
|
|
93
|
-
const element = document.createElement('canvas');
|
|
94
|
-
const dataURL = element.toDataURL(mimeType);
|
|
95
|
-
return dataURL.indexOf(`data:${mimeType}`) === 0;
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
// Probably Safari...
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
// Check WebPSupport asynchronously
|
|
103
|
-
async function testBrowserImageFormatSupportAsync(testImageDataURL) {
|
|
104
|
-
return new Promise((resolve) => {
|
|
105
|
-
const image = new Image();
|
|
106
|
-
image.src = testImageDataURL;
|
|
107
|
-
image.onload = () => resolve(image.height > 0);
|
|
108
|
-
image.onerror = () => resolve(false);
|
|
109
|
-
});
|
|
110
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDefaultImageType = exports.isImageTypeSupported = void 0;
|
|
4
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
-
// @ts-ignore TS2339: Property does not exist on type
|
|
6
|
-
const { _parseImageNode } = globalThis;
|
|
7
|
-
const IMAGE_SUPPORTED = typeof Image !== 'undefined'; // NOTE: "false" positives if jsdom is installed
|
|
8
|
-
const IMAGE_BITMAP_SUPPORTED = typeof ImageBitmap !== 'undefined';
|
|
9
|
-
const NODE_IMAGE_SUPPORTED = Boolean(_parseImageNode);
|
|
10
|
-
const DATA_SUPPORTED = loader_utils_1.isBrowser ? true : NODE_IMAGE_SUPPORTED;
|
|
11
|
-
/**
|
|
12
|
-
* Checks if a loaders.gl image type is supported
|
|
13
|
-
* @param type image type string
|
|
14
|
-
*/
|
|
15
|
-
function isImageTypeSupported(type) {
|
|
16
|
-
switch (type) {
|
|
17
|
-
case 'auto':
|
|
18
|
-
// Should only ever be false in Node.js, if polyfills have not been installed...
|
|
19
|
-
return IMAGE_BITMAP_SUPPORTED || IMAGE_SUPPORTED || DATA_SUPPORTED;
|
|
20
|
-
case 'imagebitmap':
|
|
21
|
-
return IMAGE_BITMAP_SUPPORTED;
|
|
22
|
-
case 'image':
|
|
23
|
-
return IMAGE_SUPPORTED;
|
|
24
|
-
case 'data':
|
|
25
|
-
return DATA_SUPPORTED;
|
|
26
|
-
default:
|
|
27
|
-
throw new Error(`@loaders.gl/images: image ${type} not supported in this environment`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.isImageTypeSupported = isImageTypeSupported;
|
|
31
|
-
/**
|
|
32
|
-
* Returns the "most performant" supported image type on this platform
|
|
33
|
-
* @returns image type string
|
|
34
|
-
*/
|
|
35
|
-
function getDefaultImageType() {
|
|
36
|
-
if (IMAGE_BITMAP_SUPPORTED) {
|
|
37
|
-
return 'imagebitmap';
|
|
38
|
-
}
|
|
39
|
-
if (IMAGE_SUPPORTED) {
|
|
40
|
-
return 'image';
|
|
41
|
-
}
|
|
42
|
-
if (DATA_SUPPORTED) {
|
|
43
|
-
return 'data';
|
|
44
|
-
}
|
|
45
|
-
// This should only happen in Node.js
|
|
46
|
-
throw new Error('Install \'@loaders.gl/polyfills\' to parse images under Node.js');
|
|
47
|
-
}
|
|
48
|
-
exports.getDefaultImageType = getDefaultImageType;
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
// code adapted from https://github.com/sindresorhus/file-type under MIT license
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.decodeMajorBrand = exports.getISOBMFFMediaType = void 0;
|
|
6
|
-
/**
|
|
7
|
-
* Tests if a buffer is in ISO base media file format (ISOBMFF) @see https://en.wikipedia.org/wiki/ISO_base_media_file_format
|
|
8
|
-
* (ISOBMFF is a media container standard based on the Apple QuickTime container format)
|
|
9
|
-
*/
|
|
10
|
-
function getISOBMFFMediaType(buffer) {
|
|
11
|
-
// Almost all ISO base media files start with `ftyp` box. (It's not required to be first, but it's recommended to be.)
|
|
12
|
-
if (!checkString(buffer, 'ftyp', 4)) {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
// Extra check: test for 8859-1 printable characters (for simplicity, it's a mask which also catches one non-printable character).
|
|
16
|
-
if ((buffer[8] & 0x60) === 0x00) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
// `ftyp` box must contain a brand major identifier, which must consist of ISO 8859-1 printable characters.
|
|
20
|
-
return decodeMajorBrand(buffer);
|
|
21
|
-
}
|
|
22
|
-
exports.getISOBMFFMediaType = getISOBMFFMediaType;
|
|
23
|
-
/**
|
|
24
|
-
* brands explained @see https://github.com/strukturag/libheif/issues/83
|
|
25
|
-
* code adapted from @see https://github.com/sindresorhus/file-type/blob/main/core.js#L489-L492
|
|
26
|
-
*/
|
|
27
|
-
function decodeMajorBrand(buffer) {
|
|
28
|
-
const brandMajor = getUTF8String(buffer, 8, 12).replace('\0', ' ').trim();
|
|
29
|
-
switch (brandMajor) {
|
|
30
|
-
case 'avif':
|
|
31
|
-
case 'avis':
|
|
32
|
-
return { extension: 'avif', mimeType: 'image/avif' };
|
|
33
|
-
default:
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
// We don't need these now, but they are easy to add
|
|
37
|
-
// case 'mif1':
|
|
38
|
-
// return {extension: 'heic', mimeType: 'image/heif'};
|
|
39
|
-
// case 'msf1':
|
|
40
|
-
// return {extension: 'heic', mimeType: 'image/heif-sequence'};
|
|
41
|
-
// case 'heic':
|
|
42
|
-
// case 'heix':
|
|
43
|
-
// return {extension: 'heic', mimeType: 'image/heic'};
|
|
44
|
-
// case 'hevc':
|
|
45
|
-
// case 'hevx':
|
|
46
|
-
// return {extension: 'heic', mimeType: 'image/heic-sequence'};
|
|
47
|
-
// case 'qt':
|
|
48
|
-
// return {ext: 'mov', mime: 'video/quicktime'};
|
|
49
|
-
// case 'M4V':
|
|
50
|
-
// case 'M4VH':
|
|
51
|
-
// case 'M4VP':
|
|
52
|
-
// return {ext: 'm4v', mime: 'video/x-m4v'};
|
|
53
|
-
// case 'M4P':
|
|
54
|
-
// return {ext: 'm4p', mime: 'video/mp4'};
|
|
55
|
-
// case 'M4B':
|
|
56
|
-
// return {ext: 'm4b', mime: 'audio/mp4'};
|
|
57
|
-
// case 'M4A':
|
|
58
|
-
// return {ext: 'm4a', mime: 'audio/x-m4a'};
|
|
59
|
-
// case 'F4V':
|
|
60
|
-
// return {ext: 'f4v', mime: 'video/mp4'};
|
|
61
|
-
// case 'F4P':
|
|
62
|
-
// return {ext: 'f4p', mime: 'video/mp4'};
|
|
63
|
-
// case 'F4A':
|
|
64
|
-
// return {ext: 'f4a', mime: 'audio/mp4'};
|
|
65
|
-
// case 'F4B':
|
|
66
|
-
// return {ext: 'f4b', mime: 'audio/mp4'};
|
|
67
|
-
// case 'crx':
|
|
68
|
-
// return {ext: 'cr3', mime: 'image/x-canon-cr3'};
|
|
69
|
-
// default:
|
|
70
|
-
// if (brandMajor.startsWith('3g')) {
|
|
71
|
-
// if (brandMajor.startsWith('3g2')) {
|
|
72
|
-
// return {ext: '3g2', mime: 'video/3gpp2'};
|
|
73
|
-
// }
|
|
74
|
-
// return {ext: '3gp', mime: 'video/3gpp'};
|
|
75
|
-
// }
|
|
76
|
-
// return {ext: 'mp4', mime: 'video/mp4'};
|
|
77
|
-
}
|
|
78
|
-
exports.decodeMajorBrand = decodeMajorBrand;
|
|
79
|
-
/** Interpret a chunk of bytes as a UTF8 string */
|
|
80
|
-
function getUTF8String(array, start, end) {
|
|
81
|
-
return String.fromCharCode(...array.slice(start, end));
|
|
82
|
-
}
|
|
83
|
-
function stringToBytes(string) {
|
|
84
|
-
return [...string].map((character) => character.charCodeAt(0));
|
|
85
|
-
}
|
|
86
|
-
function checkString(buffer, header, offset = 0) {
|
|
87
|
-
const headerBytes = stringToBytes(header);
|
|
88
|
-
for (let i = 0; i < headerBytes.length; ++i) {
|
|
89
|
-
if (headerBytes[i] !== buffer[i + offset]) {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getImageData = exports.getImageSize = exports.getImageType = exports.deleteImage = exports.isImage = void 0;
|
|
4
|
-
function isImage(image) {
|
|
5
|
-
return Boolean(getImageTypeOrNull(image));
|
|
6
|
-
}
|
|
7
|
-
exports.isImage = isImage;
|
|
8
|
-
function deleteImage(image) {
|
|
9
|
-
switch (getImageType(image)) {
|
|
10
|
-
case 'imagebitmap':
|
|
11
|
-
image.close();
|
|
12
|
-
break;
|
|
13
|
-
default:
|
|
14
|
-
// Nothing to do for images and image data objects
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.deleteImage = deleteImage;
|
|
18
|
-
function getImageType(image) {
|
|
19
|
-
const format = getImageTypeOrNull(image);
|
|
20
|
-
if (!format) {
|
|
21
|
-
throw new Error('Not an image');
|
|
22
|
-
}
|
|
23
|
-
return format;
|
|
24
|
-
}
|
|
25
|
-
exports.getImageType = getImageType;
|
|
26
|
-
function getImageSize(image) {
|
|
27
|
-
return getImageData(image);
|
|
28
|
-
}
|
|
29
|
-
exports.getImageSize = getImageSize;
|
|
30
|
-
function getImageData(image) {
|
|
31
|
-
switch (getImageType(image)) {
|
|
32
|
-
case 'data':
|
|
33
|
-
return image;
|
|
34
|
-
case 'image':
|
|
35
|
-
case 'imagebitmap':
|
|
36
|
-
// Extract the image data from the image via a canvas
|
|
37
|
-
const canvas = document.createElement('canvas');
|
|
38
|
-
// TODO - reuse the canvas?
|
|
39
|
-
const context = canvas.getContext('2d');
|
|
40
|
-
if (!context) {
|
|
41
|
-
throw new Error('getImageData');
|
|
42
|
-
}
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
canvas.width = image.width;
|
|
45
|
-
// @ts-ignore
|
|
46
|
-
canvas.height = image.height;
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
context.drawImage(image, 0, 0);
|
|
49
|
-
// @ts-ignore
|
|
50
|
-
return context.getImageData(0, 0, image.width, image.height);
|
|
51
|
-
default:
|
|
52
|
-
throw new Error('getImageData');
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.getImageData = getImageData;
|
|
56
|
-
// PRIVATE
|
|
57
|
-
// eslint-disable-next-line complexity
|
|
58
|
-
function getImageTypeOrNull(image) {
|
|
59
|
-
if (typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
|
|
60
|
-
return 'imagebitmap';
|
|
61
|
-
}
|
|
62
|
-
if (typeof Image !== 'undefined' && image instanceof Image) {
|
|
63
|
-
return 'image';
|
|
64
|
-
}
|
|
65
|
-
if (image && typeof image === 'object' && image.data && image.width && image.height) {
|
|
66
|
-
return 'data';
|
|
67
|
-
}
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeImage = void 0;
|
|
4
|
-
// Image loading/saving for browser and Node.js
|
|
5
|
-
const parsed_image_api_1 = require("../category-api/parsed-image-api");
|
|
6
|
-
// @ts-ignore TS2339: Property does not exist on type
|
|
7
|
-
const { _encodeImageNode } = globalThis;
|
|
8
|
-
/**
|
|
9
|
-
* Returns data bytes representing a compressed image in PNG or JPG format,
|
|
10
|
-
* This data can be saved using file system (f) methods or used in a request.
|
|
11
|
-
* @param image - ImageBitmap Image or Canvas
|
|
12
|
-
* @param options
|
|
13
|
-
* param opt.type='png' - png, jpg or image/png, image/jpg are valid
|
|
14
|
-
* param mimeType= - Whether to include a data URI header
|
|
15
|
-
*/
|
|
16
|
-
async function encodeImage(image, options) {
|
|
17
|
-
options = options || {};
|
|
18
|
-
options.image = options.image || {};
|
|
19
|
-
return _encodeImageNode
|
|
20
|
-
? _encodeImageNode(image, { type: options.image.mimeType })
|
|
21
|
-
: encodeImageInBrowser(image, options);
|
|
22
|
-
}
|
|
23
|
-
exports.encodeImage = encodeImage;
|
|
24
|
-
// In case we get exceptions from canvas.toBlob(resolve, type, quality)
|
|
25
|
-
let qualityParamSupported = true;
|
|
26
|
-
/**
|
|
27
|
-
*
|
|
28
|
-
* @param image
|
|
29
|
-
* @param options
|
|
30
|
-
* @note Based on canvas.toBlob
|
|
31
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob
|
|
32
|
-
*/
|
|
33
|
-
async function encodeImageInBrowser(image, options) {
|
|
34
|
-
const { mimeType, jpegQuality } = options.image;
|
|
35
|
-
const { width, height } = (0, parsed_image_api_1.getImageSize)(image);
|
|
36
|
-
// create a canvas and resize it to the size of our image
|
|
37
|
-
const canvas = document.createElement('canvas');
|
|
38
|
-
canvas.width = width;
|
|
39
|
-
canvas.height = height;
|
|
40
|
-
drawImageToCanvas(image, canvas);
|
|
41
|
-
// The actual encoding is done asynchronously with `canvas.toBlob()`
|
|
42
|
-
const blob = await new Promise((resolve) => {
|
|
43
|
-
// get it back as a Blob
|
|
44
|
-
if (jpegQuality && qualityParamSupported) {
|
|
45
|
-
try {
|
|
46
|
-
canvas.toBlob(resolve, mimeType, jpegQuality);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
qualityParamSupported = false;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
canvas.toBlob(resolve, mimeType);
|
|
54
|
-
});
|
|
55
|
-
if (!blob) {
|
|
56
|
-
throw new Error('image encoding failed');
|
|
57
|
-
}
|
|
58
|
-
return await blob.arrayBuffer();
|
|
59
|
-
}
|
|
60
|
-
function drawImageToCanvas(image, canvas, x = 0, y = 0) {
|
|
61
|
-
// Try optimized path for ImageBitmaps via bitmaprenderer context
|
|
62
|
-
if (x === 0 && y === 0 && typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
|
|
63
|
-
const context = canvas.getContext('bitmaprenderer');
|
|
64
|
-
if (context) {
|
|
65
|
-
// transfer the ImageBitmap to it
|
|
66
|
-
context.transferFromImageBitmap(image);
|
|
67
|
-
return canvas;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
// Available on most platforms, except IE11 and Andriod WebViews...
|
|
71
|
-
const context = canvas.getContext('2d');
|
|
72
|
-
if (image.data) {
|
|
73
|
-
// ImageData constructor expects clamped array even though getImageData does not return a clamped array...
|
|
74
|
-
const clampedArray = new Uint8ClampedArray(image.data);
|
|
75
|
-
const imageData = new ImageData(clampedArray, image.width, image.height);
|
|
76
|
-
context.putImageData(imageData, 0, 0);
|
|
77
|
-
return canvas;
|
|
78
|
-
}
|
|
79
|
-
// Fall back to generic image/image bitmap rendering path
|
|
80
|
-
context.drawImage(image, 0, 0);
|
|
81
|
-
return canvas;
|
|
82
|
-
}
|
|
@@ -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