@loaders.gl/images 4.0.0-alpha.9 → 4.0.0-beta.2
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
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.ImageLoader = void 0;
|
|
7
|
-
// import type { ImageType } from '@loaders.gl/schema';
|
|
8
|
-
const version_1 = require("./lib/utils/version");
|
|
9
|
-
const parse_image_1 = __importDefault(require("./lib/parsers/parse-image"));
|
|
10
|
-
const binary_image_api_1 = require("./lib/category-api/binary-image-api");
|
|
11
|
-
const EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'ico', 'svg', 'avif'];
|
|
12
|
-
const MIME_TYPES = [
|
|
13
|
-
'image/png',
|
|
14
|
-
'image/jpeg',
|
|
15
|
-
'image/gif',
|
|
16
|
-
'image/webp',
|
|
17
|
-
'image/avif',
|
|
18
|
-
'image/bmp',
|
|
19
|
-
'image/vnd.microsoft.icon',
|
|
20
|
-
'image/svg+xml'
|
|
21
|
-
];
|
|
22
|
-
const DEFAULT_IMAGE_LOADER_OPTIONS = {
|
|
23
|
-
image: {
|
|
24
|
-
type: 'auto',
|
|
25
|
-
decode: true // if format is HTML
|
|
26
|
-
}
|
|
27
|
-
// imagebitmap: {} - passes (platform dependent) parameters to ImageBitmap constructor
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Loads a platform-specific image type
|
|
31
|
-
* Note: This type can be used as input data to WebGL texture creation
|
|
32
|
-
*/
|
|
33
|
-
exports.ImageLoader = {
|
|
34
|
-
id: 'image',
|
|
35
|
-
module: 'images',
|
|
36
|
-
name: 'Images',
|
|
37
|
-
version: version_1.VERSION,
|
|
38
|
-
mimeTypes: MIME_TYPES,
|
|
39
|
-
extensions: EXTENSIONS,
|
|
40
|
-
parse: parse_image_1.default,
|
|
41
|
-
// TODO: byteOffset, byteLength;
|
|
42
|
-
tests: [(arrayBuffer) => Boolean((0, binary_image_api_1.getBinaryImageMetadata)(new DataView(arrayBuffer)))],
|
|
43
|
-
options: DEFAULT_IMAGE_LOADER_OPTIONS
|
|
44
|
-
};
|
package/dist/image-writer.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.ImageWriter = void 0;
|
|
5
|
-
const version_1 = require("./lib/utils/version");
|
|
6
|
-
const encode_image_1 = require("./lib/encoders/encode-image");
|
|
7
|
-
/** Writer for image data */
|
|
8
|
-
exports.ImageWriter = {
|
|
9
|
-
name: 'Images',
|
|
10
|
-
id: 'image',
|
|
11
|
-
module: 'images',
|
|
12
|
-
version: version_1.VERSION,
|
|
13
|
-
extensions: ['jpeg'],
|
|
14
|
-
options: {
|
|
15
|
-
image: {
|
|
16
|
-
mimeType: 'image/png',
|
|
17
|
-
jpegQuality: null
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
encode: encode_image_1.encodeImage
|
|
21
|
-
};
|
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,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeImage = void 0;
|
|
4
|
-
const parsed_image_api_1 = require("../category-api/parsed-image-api");
|
|
5
|
-
// @ts-ignore TS2339: Property does not exist on type
|
|
6
|
-
const { _encodeImageNode } = globalThis;
|
|
7
|
-
/**
|
|
8
|
-
* Returns data bytes representing a compressed image in PNG or JPG format,
|
|
9
|
-
* This data can be saved using file system (f) methods or used in a request.
|
|
10
|
-
* @param image - ImageBitmap Image or Canvas
|
|
11
|
-
* @param options
|
|
12
|
-
* param opt.type='png' - png, jpg or image/png, image/jpg are valid
|
|
13
|
-
* param mimeType= - Whether to include a data URI header
|
|
14
|
-
*/
|
|
15
|
-
async function encodeImage(image, options) {
|
|
16
|
-
options = options || {};
|
|
17
|
-
options.image = options.image || {};
|
|
18
|
-
return _encodeImageNode
|
|
19
|
-
? _encodeImageNode(image, { type: options.image.mimeType })
|
|
20
|
-
: encodeImageInBrowser(image, options);
|
|
21
|
-
}
|
|
22
|
-
exports.encodeImage = encodeImage;
|
|
23
|
-
// In case we get exceptions from canvas.toBlob(resolve, type, quality)
|
|
24
|
-
let qualityParamSupported = true;
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
27
|
-
* @param image
|
|
28
|
-
* @param options
|
|
29
|
-
* @note Based on canvas.toBlob
|
|
30
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob
|
|
31
|
-
*/
|
|
32
|
-
async function encodeImageInBrowser(image, options) {
|
|
33
|
-
const { mimeType, jpegQuality } = options.image;
|
|
34
|
-
const { width, height } = (0, parsed_image_api_1.getImageSize)(image);
|
|
35
|
-
// create a canvas and resize it to the size of our image
|
|
36
|
-
const canvas = document.createElement('canvas');
|
|
37
|
-
canvas.width = width;
|
|
38
|
-
canvas.height = height;
|
|
39
|
-
drawImageToCanvas(image, canvas);
|
|
40
|
-
// The actual encoding is done asynchronously with `canvas.toBlob()`
|
|
41
|
-
const blob = await new Promise((resolve) => {
|
|
42
|
-
// get it back as a Blob
|
|
43
|
-
if (jpegQuality && qualityParamSupported) {
|
|
44
|
-
try {
|
|
45
|
-
canvas.toBlob(resolve, mimeType, jpegQuality);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
qualityParamSupported = false;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
canvas.toBlob(resolve, mimeType);
|
|
53
|
-
});
|
|
54
|
-
if (!blob) {
|
|
55
|
-
throw new Error('image encoding failed');
|
|
56
|
-
}
|
|
57
|
-
return await blob.arrayBuffer();
|
|
58
|
-
}
|
|
59
|
-
function drawImageToCanvas(image, canvas, x = 0, y = 0) {
|
|
60
|
-
// Try optimized path for ImageBitmaps via bitmaprenderer context
|
|
61
|
-
if (x === 0 && y === 0 && typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
|
|
62
|
-
const context = canvas.getContext('bitmaprenderer');
|
|
63
|
-
if (context) {
|
|
64
|
-
// transfer the ImageBitmap to it
|
|
65
|
-
context.transferFromImageBitmap(image);
|
|
66
|
-
return canvas;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// Available on most platforms, except IE11 and Andriod WebViews...
|
|
70
|
-
const context = canvas.getContext('2d');
|
|
71
|
-
if (image.data) {
|
|
72
|
-
// ImageData constructor expects clamped array even though getImageData does not return a clamped array...
|
|
73
|
-
const clampedArray = new Uint8ClampedArray(image.data);
|
|
74
|
-
const imageData = new ImageData(clampedArray, image.width, image.height);
|
|
75
|
-
context.putImageData(imageData, 0, 0);
|
|
76
|
-
return canvas;
|
|
77
|
-
}
|
|
78
|
-
// Fall back to generic image/image bitmap rendering path
|
|
79
|
-
context.drawImage(image, 0, 0);
|
|
80
|
-
return canvas;
|
|
81
|
-
}
|