@loaders.gl/images 3.4.0-alpha.2 → 3.4.0-alpha.4
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/image-loader.js +0 -1
- package/dist/es5/image-loader.js.map +1 -1
- package/dist/es5/image-writer.js +0 -1
- package/dist/es5/image-writer.js.map +1 -1
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/category-api/binary-image-api.js +0 -17
- package/dist/es5/lib/category-api/binary-image-api.js.map +1 -1
- package/dist/es5/lib/category-api/image-format.js +90 -104
- package/dist/es5/lib/category-api/image-format.js.map +1 -1
- package/dist/es5/lib/category-api/image-type.js +0 -3
- package/dist/es5/lib/category-api/image-type.js.map +1 -1
- package/dist/es5/lib/category-api/parse-isobmff-binary.js +0 -5
- package/dist/es5/lib/category-api/parse-isobmff-binary.js.map +1 -1
- package/dist/es5/lib/category-api/parsed-image-api.js +0 -2
- package/dist/es5/lib/category-api/parsed-image-api.js.map +1 -1
- package/dist/es5/lib/encoders/encode-image.js +43 -53
- package/dist/es5/lib/encoders/encode-image.js.map +1 -1
- package/dist/es5/lib/parsers/parse-image.js +38 -40
- package/dist/es5/lib/parsers/parse-image.js.map +1 -1
- package/dist/es5/lib/parsers/parse-to-image-bitmap.js +51 -56
- package/dist/es5/lib/parsers/parse-to-image-bitmap.js.map +1 -1
- package/dist/es5/lib/parsers/parse-to-image.js +49 -54
- package/dist/es5/lib/parsers/parse-to-image.js.map +1 -1
- package/dist/es5/lib/parsers/parse-to-node-image.js +12 -15
- package/dist/es5/lib/parsers/parse-to-node-image.js.map +1 -1
- package/dist/es5/lib/parsers/svg-utils.js +0 -1
- package/dist/es5/lib/parsers/svg-utils.js.map +1 -1
- package/dist/es5/lib/texture-api/async-deep-map.js +93 -85
- package/dist/es5/lib/texture-api/async-deep-map.js.map +1 -1
- package/dist/es5/lib/texture-api/deep-load.js +28 -32
- package/dist/es5/lib/texture-api/deep-load.js.map +1 -1
- package/dist/es5/lib/texture-api/generate-url.js +0 -1
- package/dist/es5/lib/texture-api/generate-url.js.map +1 -1
- package/dist/es5/lib/texture-api/load-image.js +65 -72
- 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/bundle.js +0 -1
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/image-loader.js +0 -1
- package/dist/esm/image-loader.js.map +1 -1
- package/dist/esm/image-writer.js +0 -1
- package/dist/esm/image-writer.js.map +1 -1
- package/dist/esm/index.js +0 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/category-api/binary-image-api.js +0 -19
- package/dist/esm/lib/category-api/binary-image-api.js.map +1 -1
- package/dist/esm/lib/category-api/image-format.js +1 -13
- package/dist/esm/lib/category-api/image-format.js.map +1 -1
- package/dist/esm/lib/category-api/image-type.js +0 -3
- package/dist/esm/lib/category-api/image-type.js.map +1 -1
- package/dist/esm/lib/category-api/parse-isobmff-binary.js +0 -6
- package/dist/esm/lib/category-api/parse-isobmff-binary.js.map +1 -1
- package/dist/esm/lib/category-api/parsed-image-api.js +0 -2
- package/dist/esm/lib/category-api/parsed-image-api.js.map +1 -1
- package/dist/esm/lib/encoders/encode-image.js +0 -9
- package/dist/esm/lib/encoders/encode-image.js.map +1 -1
- package/dist/esm/lib/parsers/parse-image.js +0 -5
- package/dist/esm/lib/parsers/parse-image.js.map +1 -1
- package/dist/esm/lib/parsers/parse-to-image-bitmap.js +0 -3
- package/dist/esm/lib/parsers/parse-to-image-bitmap.js.map +1 -1
- package/dist/esm/lib/parsers/parse-to-image.js +0 -4
- package/dist/esm/lib/parsers/parse-to-image.js.map +1 -1
- package/dist/esm/lib/parsers/parse-to-node-image.js +0 -3
- package/dist/esm/lib/parsers/parse-to-node-image.js.map +1 -1
- package/dist/esm/lib/parsers/svg-utils.js +0 -2
- package/dist/esm/lib/parsers/svg-utils.js.map +1 -1
- package/dist/esm/lib/texture-api/async-deep-map.js +0 -5
- package/dist/esm/lib/texture-api/async-deep-map.js.map +1 -1
- package/dist/esm/lib/texture-api/deep-load.js.map +1 -1
- package/dist/esm/lib/texture-api/generate-url.js +0 -2
- package/dist/esm/lib/texture-api/generate-url.js.map +1 -1
- package/dist/esm/lib/texture-api/load-image.js +0 -4
- package/dist/esm/lib/texture-api/load-image.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -2
- package/dist/esm/lib/utils/version.js.map +1 -1
- package/dist/lib/category-api/binary-image-api.js +1 -1
- package/package.json +3 -3
|
@@ -26,22 +26,20 @@ function _loadImage() {
|
|
|
26
26
|
imageUrls,
|
|
27
27
|
_args = arguments;
|
|
28
28
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
29
|
-
while (1) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return _context.stop();
|
|
44
|
-
}
|
|
29
|
+
while (1) switch (_context.prev = _context.next) {
|
|
30
|
+
case 0:
|
|
31
|
+
options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
|
|
32
|
+
_context.next = 3;
|
|
33
|
+
return getImageUrls(getUrl, options);
|
|
34
|
+
case 3:
|
|
35
|
+
imageUrls = _context.sent;
|
|
36
|
+
_context.next = 6;
|
|
37
|
+
return (0, _deepLoad.deepLoad)(imageUrls, _parseImage.default, options);
|
|
38
|
+
case 6:
|
|
39
|
+
return _context.abrupt("return", _context.sent);
|
|
40
|
+
case 7:
|
|
41
|
+
case "end":
|
|
42
|
+
return _context.stop();
|
|
45
43
|
}
|
|
46
44
|
}, _callee);
|
|
47
45
|
}));
|
|
@@ -56,29 +54,27 @@ function _getImageUrls() {
|
|
|
56
54
|
mipLevels,
|
|
57
55
|
_args2 = arguments;
|
|
58
56
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
59
|
-
while (1) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
_context2.next = 8;
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
_context2.next = 5;
|
|
69
|
-
return getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions);
|
|
70
|
-
case 5:
|
|
71
|
-
_context2.t0 = _context2.sent;
|
|
72
|
-
_context2.next = 9;
|
|
57
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
58
|
+
case 0:
|
|
59
|
+
urlOptions = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
|
|
60
|
+
mipLevels = options && options.image && options.image.mipLevels || 0;
|
|
61
|
+
if (!(mipLevels !== 0)) {
|
|
62
|
+
_context2.next = 8;
|
|
73
63
|
break;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
64
|
+
}
|
|
65
|
+
_context2.next = 5;
|
|
66
|
+
return getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions);
|
|
67
|
+
case 5:
|
|
68
|
+
_context2.t0 = _context2.sent;
|
|
69
|
+
_context2.next = 9;
|
|
70
|
+
break;
|
|
71
|
+
case 8:
|
|
72
|
+
_context2.t0 = (0, _generateUrl.generateUrl)(getUrl, options, urlOptions);
|
|
73
|
+
case 9:
|
|
74
|
+
return _context2.abrupt("return", _context2.t0);
|
|
75
|
+
case 10:
|
|
76
|
+
case "end":
|
|
77
|
+
return _context2.stop();
|
|
82
78
|
}
|
|
83
79
|
}, _callee2);
|
|
84
80
|
}));
|
|
@@ -91,41 +87,38 @@ function _getMipmappedImageUrls() {
|
|
|
91
87
|
_getMipmappedImageUrls = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(getUrl, mipLevels, options, urlOptions) {
|
|
92
88
|
var urls, url, image, _getImageSize, width, height, mipLevel, _url;
|
|
93
89
|
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
94
|
-
while (1) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
90
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
91
|
+
case 0:
|
|
92
|
+
urls = [];
|
|
93
|
+
if (!(mipLevels === 'auto')) {
|
|
94
|
+
_context3.next = 9;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
url = (0, _generateUrl.generateUrl)(getUrl, options, _objectSpread(_objectSpread({}, urlOptions), {}, {
|
|
98
|
+
lod: 0
|
|
99
|
+
}));
|
|
100
|
+
_context3.next = 5;
|
|
101
|
+
return (0, _deepLoad.shallowLoad)(url, _parseImage.default, options);
|
|
102
|
+
case 5:
|
|
103
|
+
image = _context3.sent;
|
|
104
|
+
_getImageSize = (0, _parsedImageApi.getImageSize)(image), width = _getImageSize.width, height = _getImageSize.height;
|
|
105
|
+
mipLevels = getMipLevels({
|
|
106
|
+
width: width,
|
|
107
|
+
height: height
|
|
108
|
+
});
|
|
109
|
+
urls.push(url);
|
|
110
|
+
case 9:
|
|
111
|
+
(0, _loaderUtils.assert)(mipLevels > 0);
|
|
112
|
+
for (mipLevel = urls.length; mipLevel < mipLevels; ++mipLevel) {
|
|
113
|
+
_url = (0, _generateUrl.generateUrl)(getUrl, options, _objectSpread(_objectSpread({}, urlOptions), {}, {
|
|
114
|
+
lod: mipLevel
|
|
104
115
|
}));
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
width: width,
|
|
112
|
-
height: height
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
urls.push(url);
|
|
116
|
-
case 9:
|
|
117
|
-
(0, _loaderUtils.assert)(mipLevels > 0);
|
|
118
|
-
for (mipLevel = urls.length; mipLevel < mipLevels; ++mipLevel) {
|
|
119
|
-
_url = (0, _generateUrl.generateUrl)(getUrl, options, _objectSpread(_objectSpread({}, urlOptions), {}, {
|
|
120
|
-
lod: mipLevel
|
|
121
|
-
}));
|
|
122
|
-
urls.push(_url);
|
|
123
|
-
}
|
|
124
|
-
return _context3.abrupt("return", urls);
|
|
125
|
-
case 12:
|
|
126
|
-
case "end":
|
|
127
|
-
return _context3.stop();
|
|
128
|
-
}
|
|
116
|
+
urls.push(_url);
|
|
117
|
+
}
|
|
118
|
+
return _context3.abrupt("return", urls);
|
|
119
|
+
case 12:
|
|
120
|
+
case "end":
|
|
121
|
+
return _context3.stop();
|
|
129
122
|
}
|
|
130
123
|
}, _callee3);
|
|
131
124
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-image.js","names":["loadImage","getUrl","options","getImageUrls","
|
|
1
|
+
{"version":3,"file":"load-image.js","names":["_loaderUtils","require","_parseImage","_interopRequireDefault","_parsedImageApi","_generateUrl","_deepLoad","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","loadImage","_x","_loadImage","_asyncToGenerator2","_regenerator","mark","_callee","getUrl","options","imageUrls","_args","wrap","_callee$","_context","prev","next","undefined","getImageUrls","sent","deepLoad","parseImage","abrupt","stop","_x2","_x3","_getImageUrls","_callee2","urlOptions","mipLevels","_args2","_callee2$","_context2","image","getMipmappedImageUrls","t0","generateUrl","_x4","_x5","_x6","_x7","_getMipmappedImageUrls","_callee3","urls","url","_getImageSize","width","height","mipLevel","_url","_callee3$","_context3","lod","shallowLoad","getImageSize","getMipLevels","assert","_ref","Math","floor","log2","max"],"sources":["../../../../src/lib/texture-api/load-image.ts"],"sourcesContent":["import {assert} from '@loaders.gl/loader-utils';\nimport parseImage from '../parsers/parse-image';\nimport {getImageSize} from '../category-api/parsed-image-api';\nimport {generateUrl} from './generate-url';\nimport {deepLoad, shallowLoad} from './deep-load';\n\nexport async function loadImage(getUrl, options = {}) {\n const imageUrls = await getImageUrls(getUrl, options);\n return await deepLoad(imageUrls, parseImage, options);\n}\n\nexport async function getImageUrls(getUrl, options, urlOptions = {}) {\n const mipLevels = (options && options.image && options.image.mipLevels) || 0;\n return mipLevels !== 0\n ? await getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions)\n : generateUrl(getUrl, options, urlOptions);\n}\n\nasync function getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions) {\n const urls: string[] = [];\n\n // If no mip levels supplied, we need to load the level 0 image and calculate based on size\n if (mipLevels === 'auto') {\n const url = generateUrl(getUrl, options, {...urlOptions, lod: 0});\n const image = await shallowLoad(url, parseImage, options);\n\n const {width, height} = getImageSize(image);\n mipLevels = getMipLevels({width, height});\n\n // TODO - push image and make `deepLoad` pass through non-url values, avoid loading twice?\n urls.push(url);\n }\n\n // We now know how many mipLevels we need, remaining image urls can now be constructed\n assert(mipLevels > 0);\n\n for (let mipLevel = urls.length; mipLevel < mipLevels; ++mipLevel) {\n const url = generateUrl(getUrl, options, {...urlOptions, lod: mipLevel});\n urls.push(url);\n }\n\n return urls;\n}\n\n// Calculates number of mipmaps based on texture size (log2)\nexport function getMipLevels({width, height}) {\n return 1 + Math.floor(Math.log2(Math.max(width, height)));\n}\n"],"mappings":";;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AAAkD,SAAAM,QAAAC,MAAA,EAAAC,cAAA,QAAAC,IAAA,GAAAC,MAAA,CAAAD,IAAA,CAAAF,MAAA,OAAAG,MAAA,CAAAC,qBAAA,QAAAC,OAAA,GAAAF,MAAA,CAAAC,qBAAA,CAAAJ,M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;EACzC,OAAO,CAAC,GAAGW,IAAI,CAACC,KAAK,CAACD,IAAI,CAACE,IAAI,CAACF,IAAI,CAACG,GAAG,CAACf,KAAK,EAAEC,MAAM,CAAC,CAAC,CAAC;AAC3D"}
|
|
@@ -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.0-alpha.
|
|
7
|
+
var VERSION = typeof "3.4.0-alpha.4" !== 'undefined' ? "3.4.0-alpha.4" : 'latest';
|
|
8
8
|
exports.VERSION = VERSION;
|
|
9
9
|
//# sourceMappingURL=version.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":["VERSION"],"sources":["../../../../src/lib/utils/version.ts"],"sourcesContent":["// Version constant cannot be imported, it needs to correspond to the build version of **this** module.\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nexport const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n"],"mappings":";;;;;;AAGO,IAAMA,OAAO,GAAG,sBAAkB,KAAK,WAAW,qBAAiB,QAAQ;
|
|
1
|
+
{"version":3,"file":"version.js","names":["VERSION","exports"],"sources":["../../../../src/lib/utils/version.ts"],"sourcesContent":["// Version constant cannot be imported, it needs to correspond to the build version of **this** module.\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nexport const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n"],"mappings":";;;;;;AAGO,IAAMA,OAAO,GAAG,sBAAkB,KAAK,WAAW,qBAAiB,QAAQ;AAACC,OAAA,CAAAD,OAAA,GAAAA,OAAA"}
|
package/dist/esm/bundle.js
CHANGED
package/dist/esm/bundle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.js","names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"sources":["../../src/bundle.ts"],"sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"bundle.js","names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"sources":["../../src/bundle.ts"],"sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"mappings":"AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAS,CAAC;AACxCC,UAAU,CAACC,OAAO,GAAGD,UAAU,CAACC,OAAO,IAAI,CAAC,CAAC;AAC7CC,MAAM,CAACC,OAAO,GAAGC,MAAM,CAACC,MAAM,CAACL,UAAU,CAACC,OAAO,EAAEH,aAAa,CAAC"}
|
package/dist/esm/image-loader.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-loader.js","names":["VERSION","parseImage","getBinaryImageMetadata","EXTENSIONS","MIME_TYPES","DEFAULT_IMAGE_LOADER_OPTIONS","image","type","decode","ImageLoader","id","module","name","version","mimeTypes","extensions","parse","tests","arrayBuffer","Boolean","DataView","options","_typecheckImageLoader"],"sources":["../../src/image-loader.ts"],"sourcesContent":["import type {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport {VERSION} from './lib/utils/version';\nimport parseImage from './lib/parsers/parse-image';\nimport {getBinaryImageMetadata} from './lib/category-api/binary-image-api';\n\nconst EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'ico', 'svg', 'avif'];\nconst MIME_TYPES = [\n 'image/png',\n 'image/jpeg',\n 'image/gif',\n 'image/webp',\n 'image/avif',\n 'image/bmp',\n 'image/vnd.microsoft.icon',\n 'image/svg+xml'\n];\n\nexport type ImageLoaderOptions = LoaderOptions & {\n image?: {\n type?: 'auto' | 'data' | 'imagebitmap' | 'image';\n decode?: boolean;\n };\n imagebitmap?: ImageBitmapOptions;\n};\n\nconst DEFAULT_IMAGE_LOADER_OPTIONS: ImageLoaderOptions = {\n image: {\n type: 'auto',\n decode: true // if format is HTML\n }\n // imagebitmap: {} - passes (platform dependent) parameters to ImageBitmap constructor\n};\n\n/**\n * Loads a platform-specific image type\n * Note: This type can be used as input data to WebGL texture creation\n */\nexport const ImageLoader = {\n id: 'image',\n module: 'images',\n name: 'Images',\n version: VERSION,\n mimeTypes: MIME_TYPES,\n extensions: EXTENSIONS,\n parse: parseImage,\n // TODO: byteOffset, byteLength;\n tests: [(arrayBuffer) => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer)))],\n options: DEFAULT_IMAGE_LOADER_OPTIONS\n};\n\nexport const _typecheckImageLoader: LoaderWithParser = ImageLoader;\n"],"mappings":"AACA,SAAQA,OAAO,QAAO,qBAAqB;AAC3C,OAAOC,UAAU,MAAM,2BAA2B;AAClD,SAAQC,sBAAsB,QAAO,qCAAqC;AAE1E,MAAMC,UAAU,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC;AACrF,MAAMC,UAAU,GAAG,CACjB,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,0BAA0B,EAC1B,eAAe,CAChB;AAUD,MAAMC,4BAAgD,GAAG;EACvDC,KAAK,EAAE;IACLC,IAAI,EAAE,MAAM;IACZC,MAAM,EAAE;EACV;AAEF,CAAC
|
|
1
|
+
{"version":3,"file":"image-loader.js","names":["VERSION","parseImage","getBinaryImageMetadata","EXTENSIONS","MIME_TYPES","DEFAULT_IMAGE_LOADER_OPTIONS","image","type","decode","ImageLoader","id","module","name","version","mimeTypes","extensions","parse","tests","arrayBuffer","Boolean","DataView","options","_typecheckImageLoader"],"sources":["../../src/image-loader.ts"],"sourcesContent":["import type {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport {VERSION} from './lib/utils/version';\nimport parseImage from './lib/parsers/parse-image';\nimport {getBinaryImageMetadata} from './lib/category-api/binary-image-api';\n\nconst EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'ico', 'svg', 'avif'];\nconst MIME_TYPES = [\n 'image/png',\n 'image/jpeg',\n 'image/gif',\n 'image/webp',\n 'image/avif',\n 'image/bmp',\n 'image/vnd.microsoft.icon',\n 'image/svg+xml'\n];\n\nexport type ImageLoaderOptions = LoaderOptions & {\n image?: {\n type?: 'auto' | 'data' | 'imagebitmap' | 'image';\n decode?: boolean;\n };\n imagebitmap?: ImageBitmapOptions;\n};\n\nconst DEFAULT_IMAGE_LOADER_OPTIONS: ImageLoaderOptions = {\n image: {\n type: 'auto',\n decode: true // if format is HTML\n }\n // imagebitmap: {} - passes (platform dependent) parameters to ImageBitmap constructor\n};\n\n/**\n * Loads a platform-specific image type\n * Note: This type can be used as input data to WebGL texture creation\n */\nexport const ImageLoader = {\n id: 'image',\n module: 'images',\n name: 'Images',\n version: VERSION,\n mimeTypes: MIME_TYPES,\n extensions: EXTENSIONS,\n parse: parseImage,\n // TODO: byteOffset, byteLength;\n tests: [(arrayBuffer) => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer)))],\n options: DEFAULT_IMAGE_LOADER_OPTIONS\n};\n\nexport const _typecheckImageLoader: LoaderWithParser = ImageLoader;\n"],"mappings":"AACA,SAAQA,OAAO,QAAO,qBAAqB;AAC3C,OAAOC,UAAU,MAAM,2BAA2B;AAClD,SAAQC,sBAAsB,QAAO,qCAAqC;AAE1E,MAAMC,UAAU,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC;AACrF,MAAMC,UAAU,GAAG,CACjB,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,0BAA0B,EAC1B,eAAe,CAChB;AAUD,MAAMC,4BAAgD,GAAG;EACvDC,KAAK,EAAE;IACLC,IAAI,EAAE,MAAM;IACZC,MAAM,EAAE;EACV;AAEF,CAAC;AAMD,OAAO,MAAMC,WAAW,GAAG;EACzBC,EAAE,EAAE,OAAO;EACXC,MAAM,EAAE,QAAQ;EAChBC,IAAI,EAAE,QAAQ;EACdC,OAAO,EAAEb,OAAO;EAChBc,SAAS,EAAEV,UAAU;EACrBW,UAAU,EAAEZ,UAAU;EACtBa,KAAK,EAAEf,UAAU;EAEjBgB,KAAK,EAAE,CAAEC,WAAW,IAAKC,OAAO,CAACjB,sBAAsB,CAAC,IAAIkB,QAAQ,CAACF,WAAW,CAAC,CAAC,CAAC,CAAC;EACpFG,OAAO,EAAEhB;AACX,CAAC;AAED,OAAO,MAAMiB,qBAAuC,GAAGb,WAAW"}
|
package/dist/esm/image-writer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-writer.js","names":["VERSION","encodeImage","ImageWriter","name","id","module","version","extensions","options","image","mimeType","jpegQuality","encode"],"sources":["../../src/image-writer.ts"],"sourcesContent":["// import type {Writer} from '@loaders.gl/loader-utils';\nimport {VERSION} from './lib/utils/version';\nimport {encodeImage} from './lib/encoders/encode-image';\n\nexport const ImageWriter = {\n name: 'Images',\n id: 'image',\n module: 'images',\n version: VERSION,\n extensions: ['jpeg'],\n options: {\n image: {\n mimeType: 'image/png',\n jpegQuality: null\n }\n },\n encode: encodeImage\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"image-writer.js","names":["VERSION","encodeImage","ImageWriter","name","id","module","version","extensions","options","image","mimeType","jpegQuality","encode"],"sources":["../../src/image-writer.ts"],"sourcesContent":["// import type {Writer} from '@loaders.gl/loader-utils';\nimport {VERSION} from './lib/utils/version';\nimport {encodeImage} from './lib/encoders/encode-image';\n\nexport const ImageWriter = {\n name: 'Images',\n id: 'image',\n module: 'images',\n version: VERSION,\n extensions: ['jpeg'],\n options: {\n image: {\n mimeType: 'image/png',\n jpegQuality: null\n }\n },\n encode: encodeImage\n};\n"],"mappings":"AACA,SAAQA,OAAO,QAAO,qBAAqB;AAC3C,SAAQC,WAAW,QAAO,6BAA6B;AAEvD,OAAO,MAAMC,WAAW,GAAG;EACzBC,IAAI,EAAE,QAAQ;EACdC,EAAE,EAAE,OAAO;EACXC,MAAM,EAAE,QAAQ;EAChBC,OAAO,EAAEN,OAAO;EAChBO,UAAU,EAAE,CAAC,MAAM,CAAC;EACpBC,OAAO,EAAE;IACPC,KAAK,EAAE;MACLC,QAAQ,EAAE,WAAW;MACrBC,WAAW,EAAE;IACf;EACF,CAAC;EACDC,MAAM,EAAEX;AACV,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
1
|
export { ImageLoader } from './image-loader';
|
|
4
2
|
export { ImageWriter } from './image-writer';
|
|
5
|
-
|
|
6
3
|
export { getBinaryImageMetadata } from './lib/category-api/binary-image-api';
|
|
7
|
-
|
|
8
4
|
export { isImageTypeSupported, getDefaultImageType } from './lib/category-api/image-type';
|
|
9
5
|
export { isImage, getImageType, getImageSize, getImageData } from './lib/category-api/parsed-image-api';
|
|
10
|
-
|
|
11
6
|
export { getSupportedImageFormats } from './lib/category-api/image-format';
|
|
12
7
|
export { isImageFormatSupported } from './lib/category-api/image-format';
|
|
13
|
-
|
|
14
8
|
export { loadImage } from './lib/texture-api/load-image';
|
|
15
9
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["ImageLoader","ImageWriter","getBinaryImageMetadata","isImageTypeSupported","getDefaultImageType","isImage","getImageType","getImageSize","getImageData","getSupportedImageFormats","isImageFormatSupported","loadImage"],"sources":["../../src/index.ts"],"sourcesContent":["// TYPES\nexport type {ImageDataType, ImageType, ImageTypeEnum} from './types';\nexport type {ImageLoaderOptions} from './image-loader';\n\n// LOADERS AND WRITERS\nexport {ImageLoader} from './image-loader';\nexport {ImageWriter} from './image-writer';\n\n// IMAGE CATEGORY API\n\n// Binary Image API\nexport {getBinaryImageMetadata} from './lib/category-api/binary-image-api';\n\n// Parsed Image API\nexport {isImageTypeSupported, getDefaultImageType} from './lib/category-api/image-type';\n\nexport {\n isImage,\n getImageType,\n getImageSize,\n getImageData\n} from './lib/category-api/parsed-image-api';\n\n// EXPERIMENTAL\nexport {getSupportedImageFormats} from './lib/category-api/image-format';\nexport {isImageFormatSupported} from './lib/category-api/image-format';\n\n// DEPRECATED - Remove in V4 (fix dependency in luma.gl)\nexport {loadImage} from './lib/texture-api/load-image';\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["ImageLoader","ImageWriter","getBinaryImageMetadata","isImageTypeSupported","getDefaultImageType","isImage","getImageType","getImageSize","getImageData","getSupportedImageFormats","isImageFormatSupported","loadImage"],"sources":["../../src/index.ts"],"sourcesContent":["// TYPES\nexport type {ImageDataType, ImageType, ImageTypeEnum} from './types';\nexport type {ImageLoaderOptions} from './image-loader';\n\n// LOADERS AND WRITERS\nexport {ImageLoader} from './image-loader';\nexport {ImageWriter} from './image-writer';\n\n// IMAGE CATEGORY API\n\n// Binary Image API\nexport {getBinaryImageMetadata} from './lib/category-api/binary-image-api';\n\n// Parsed Image API\nexport {isImageTypeSupported, getDefaultImageType} from './lib/category-api/image-type';\n\nexport {\n isImage,\n getImageType,\n getImageSize,\n getImageData\n} from './lib/category-api/parsed-image-api';\n\n// EXPERIMENTAL\nexport {getSupportedImageFormats} from './lib/category-api/image-format';\nexport {isImageFormatSupported} from './lib/category-api/image-format';\n\n// DEPRECATED - Remove in V4 (fix dependency in luma.gl)\nexport {loadImage} from './lib/texture-api/load-image';\n"],"mappings":"AAKA,SAAQA,WAAW,QAAO,gBAAgB;AAC1C,SAAQC,WAAW,QAAO,gBAAgB;AAK1C,SAAQC,sBAAsB,QAAO,qCAAqC;AAG1E,SAAQC,oBAAoB,EAAEC,mBAAmB,QAAO,+BAA+B;AAEvF,SACEC,OAAO,EACPC,YAAY,EACZC,YAAY,EACZC,YAAY,QACP,qCAAqC;AAG5C,SAAQC,wBAAwB,QAAO,iCAAiC;AACxE,SAAQC,sBAAsB,QAAO,iCAAiC;AAGtE,SAAQC,SAAS,QAAO,8BAA8B"}
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
1
|
import { getISOBMFFMediaType } from './parse-isobmff-binary';
|
|
4
|
-
|
|
5
2
|
const BIG_ENDIAN = false;
|
|
6
3
|
const LITTLE_ENDIAN = true;
|
|
7
|
-
|
|
8
4
|
export function getBinaryImageMetadata(binaryData) {
|
|
9
5
|
const dataView = toDataView(binaryData);
|
|
10
6
|
return getPngMetadata(dataView) || getJpegMetadata(dataView) || getGifMetadata(dataView) || getBmpMetadata(dataView) || getISOBMFFMetadata(dataView);
|
|
11
7
|
}
|
|
12
|
-
|
|
13
8
|
function getISOBMFFMetadata(binaryData) {
|
|
14
9
|
const buffer = new Uint8Array(binaryData instanceof DataView ? binaryData.buffer : binaryData);
|
|
15
10
|
const mediaType = getISOBMFFMediaType(buffer);
|
|
@@ -22,49 +17,42 @@ function getISOBMFFMetadata(binaryData) {
|
|
|
22
17
|
height: 0
|
|
23
18
|
};
|
|
24
19
|
}
|
|
25
|
-
|
|
26
20
|
function getPngMetadata(binaryData) {
|
|
27
21
|
const dataView = toDataView(binaryData);
|
|
28
22
|
const isPng = dataView.byteLength >= 24 && dataView.getUint32(0, BIG_ENDIAN) === 0x89504e47;
|
|
29
23
|
if (!isPng) {
|
|
30
24
|
return null;
|
|
31
25
|
}
|
|
32
|
-
|
|
33
26
|
return {
|
|
34
27
|
mimeType: 'image/png',
|
|
35
28
|
width: dataView.getUint32(16, BIG_ENDIAN),
|
|
36
29
|
height: dataView.getUint32(20, BIG_ENDIAN)
|
|
37
30
|
};
|
|
38
31
|
}
|
|
39
|
-
|
|
40
32
|
function getGifMetadata(binaryData) {
|
|
41
33
|
const dataView = toDataView(binaryData);
|
|
42
34
|
const isGif = dataView.byteLength >= 10 && dataView.getUint32(0, BIG_ENDIAN) === 0x47494638;
|
|
43
35
|
if (!isGif) {
|
|
44
36
|
return null;
|
|
45
37
|
}
|
|
46
|
-
|
|
47
38
|
return {
|
|
48
39
|
mimeType: 'image/gif',
|
|
49
40
|
width: dataView.getUint16(6, LITTLE_ENDIAN),
|
|
50
41
|
height: dataView.getUint16(8, LITTLE_ENDIAN)
|
|
51
42
|
};
|
|
52
43
|
}
|
|
53
|
-
|
|
54
44
|
export function getBmpMetadata(binaryData) {
|
|
55
45
|
const dataView = toDataView(binaryData);
|
|
56
46
|
const isBmp = dataView.byteLength >= 14 && dataView.getUint16(0, BIG_ENDIAN) === 0x424d && dataView.getUint32(2, LITTLE_ENDIAN) === dataView.byteLength;
|
|
57
47
|
if (!isBmp) {
|
|
58
48
|
return null;
|
|
59
49
|
}
|
|
60
|
-
|
|
61
50
|
return {
|
|
62
51
|
mimeType: 'image/bmp',
|
|
63
52
|
width: dataView.getUint32(18, LITTLE_ENDIAN),
|
|
64
53
|
height: dataView.getUint32(22, LITTLE_ENDIAN)
|
|
65
54
|
};
|
|
66
55
|
}
|
|
67
|
-
|
|
68
56
|
function getJpegMetadata(binaryData) {
|
|
69
57
|
const dataView = toDataView(binaryData);
|
|
70
58
|
const isJpeg = dataView.byteLength >= 3 && dataView.getUint16(0, BIG_ENDIAN) === 0xffd8 && dataView.getUint8(2) === 0xff;
|
|
@@ -75,11 +63,9 @@ function getJpegMetadata(binaryData) {
|
|
|
75
63
|
tableMarkers,
|
|
76
64
|
sofMarkers
|
|
77
65
|
} = getJpegMarkers();
|
|
78
|
-
|
|
79
66
|
let i = 2;
|
|
80
67
|
while (i + 9 < dataView.byteLength) {
|
|
81
68
|
const marker = dataView.getUint16(i, BIG_ENDIAN);
|
|
82
|
-
|
|
83
69
|
if (sofMarkers.has(marker)) {
|
|
84
70
|
return {
|
|
85
71
|
mimeType: 'image/jpeg',
|
|
@@ -87,11 +73,9 @@ function getJpegMetadata(binaryData) {
|
|
|
87
73
|
width: dataView.getUint16(i + 7, BIG_ENDIAN)
|
|
88
74
|
};
|
|
89
75
|
}
|
|
90
|
-
|
|
91
76
|
if (!tableMarkers.has(marker)) {
|
|
92
77
|
return null;
|
|
93
78
|
}
|
|
94
|
-
|
|
95
79
|
i += 2;
|
|
96
80
|
i += dataView.getUint16(i, BIG_ENDIAN);
|
|
97
81
|
}
|
|
@@ -102,14 +86,12 @@ function getJpegMarkers() {
|
|
|
102
86
|
for (let i = 0xffe0; i < 0xfff0; ++i) {
|
|
103
87
|
tableMarkers.add(i);
|
|
104
88
|
}
|
|
105
|
-
|
|
106
89
|
const sofMarkers = new Set([0xffc0, 0xffc1, 0xffc2, 0xffc3, 0xffc5, 0xffc6, 0xffc7, 0xffc9, 0xffca, 0xffcb, 0xffcd, 0xffce, 0xffcf, 0xffde]);
|
|
107
90
|
return {
|
|
108
91
|
tableMarkers,
|
|
109
92
|
sofMarkers
|
|
110
93
|
};
|
|
111
94
|
}
|
|
112
|
-
|
|
113
95
|
function toDataView(data) {
|
|
114
96
|
if (data instanceof DataView) {
|
|
115
97
|
return data;
|
|
@@ -117,7 +99,6 @@ function toDataView(data) {
|
|
|
117
99
|
if (ArrayBuffer.isView(data)) {
|
|
118
100
|
return new DataView(data.buffer);
|
|
119
101
|
}
|
|
120
|
-
|
|
121
102
|
if (data instanceof ArrayBuffer) {
|
|
122
103
|
return new DataView(data);
|
|
123
104
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binary-image-api.js","names":["getISOBMFFMediaType","BIG_ENDIAN","LITTLE_ENDIAN","getBinaryImageMetadata","binaryData","dataView","toDataView","getPngMetadata","getJpegMetadata","getGifMetadata","getBmpMetadata","getISOBMFFMetadata","buffer","Uint8Array","DataView","mediaType","mimeType","width","height","isPng","byteLength","getUint32","isGif","getUint16","isBmp","isJpeg","getUint8","tableMarkers","sofMarkers","getJpegMarkers","i","marker","has","Set","add","data","ArrayBuffer","isView","Error"],"sources":["../../../../src/lib/category-api/binary-image-api.ts"],"sourcesContent":["// Attributions\n// * Based on binary-gltf-utils under MIT license: Copyright (c) 2016-17 Karl Cheng\n\n// TODO: make these functions work for Node.js buffers?\n// Quarantine references to Buffer to prevent bundler from adding big polyfills\n// import {bufferToArrayBuffer} from '../node/buffer-to-array-buffer';\n// TODO - this should be handled in @loaders.gl/polyfills\n\nimport {getISOBMFFMediaType} from './parse-isobmff-binary';\n\n/** MIME type, width and height extracted from binary compressed image data */\nexport type BinaryImageMetadata = {\n mimeType: string;\n width: number;\n height: number;\n};\n\nconst BIG_ENDIAN = false;\nconst LITTLE_ENDIAN = true;\n\n/**\n * Extracts `{mimeType, width and height}` from a memory buffer containing a known image format\n * Currently supports `image/png`, `image/jpeg`, `image/bmp` and `image/gif`.\n * @param binaryData: DataView | ArrayBuffer image file memory to parse\n * @returns metadata or null if memory is not a valid image file format layout.\n */\nexport function getBinaryImageMetadata(\n binaryData: DataView | ArrayBuffer\n): BinaryImageMetadata | null {\n const dataView = toDataView(binaryData);\n return (\n getPngMetadata(dataView) ||\n getJpegMetadata(dataView) ||\n getGifMetadata(dataView) ||\n getBmpMetadata(dataView) ||\n getISOBMFFMetadata(dataView)\n );\n}\n\n// ISOBMFF\n\nfunction getISOBMFFMetadata(binaryData: DataView | ArrayBuffer): BinaryImageMetadata | null {\n const buffer = new Uint8Array(binaryData instanceof DataView ? binaryData.buffer : binaryData);\n const mediaType = getISOBMFFMediaType(buffer);\n if (!mediaType) {\n return null;\n }\n return {\n mimeType: mediaType.mimeType,\n // TODO - decode width and height\n width: 0,\n height: 0\n };\n}\n\n// PNG\n\nfunction getPngMetadata(binaryData: DataView | ArrayBuffer): BinaryImageMetadata | null {\n const dataView = toDataView(binaryData);\n // Check file contains the first 4 bytes of the PNG signature.\n const isPng = dataView.byteLength >= 24 && dataView.getUint32(0, BIG_ENDIAN) === 0x89504e47;\n if (!isPng) {\n return null;\n }\n\n // Extract size from a binary PNG file\n return {\n mimeType: 'image/png',\n width: dataView.getUint32(16, BIG_ENDIAN),\n height: dataView.getUint32(20, BIG_ENDIAN)\n };\n}\n\n// GIF\n\n// Extract size from a binary GIF file\n// TODO: GIF is not this simple\nfunction getGifMetadata(binaryData: DataView | ArrayBuffer): BinaryImageMetadata | null {\n const dataView = toDataView(binaryData);\n // Check first 4 bytes of the GIF signature (\"GIF8\").\n const isGif = dataView.byteLength >= 10 && dataView.getUint32(0, BIG_ENDIAN) === 0x47494638;\n if (!isGif) {\n return null;\n }\n\n // GIF is little endian.\n return {\n mimeType: 'image/gif',\n width: dataView.getUint16(6, LITTLE_ENDIAN),\n height: dataView.getUint16(8, LITTLE_ENDIAN)\n };\n}\n\n// BMP\n\n// TODO: BMP is not this simple\nexport function getBmpMetadata(binaryData: DataView | ArrayBuffer): BinaryImageMetadata | null {\n const dataView = toDataView(binaryData);\n // Check magic number is valid (first 2 characters should be \"BM\").\n // The mandatory bitmap file header is 14 bytes long.\n const isBmp =\n dataView.byteLength >= 14 &&\n dataView.getUint16(0, BIG_ENDIAN) === 0x424d &&\n dataView.getUint32(2, LITTLE_ENDIAN) === dataView.byteLength;\n\n if (!isBmp) {\n return null;\n }\n\n // BMP is little endian.\n return {\n mimeType: 'image/bmp',\n width: dataView.getUint32(18, LITTLE_ENDIAN),\n height: dataView.getUint32(22, LITTLE_ENDIAN)\n };\n}\n\n// JPEG\n\n// Extract width and height from a binary JPEG file\nfunction getJpegMetadata(binaryData: DataView | ArrayBuffer): BinaryImageMetadata | null {\n const dataView = toDataView(binaryData);\n // Check file contains the JPEG \"start of image\" (SOI) marker\n // followed by another marker.\n const isJpeg =\n dataView.byteLength >= 3 &&\n dataView.getUint16(0, BIG_ENDIAN) === 0xffd8 &&\n dataView.getUint8(2) === 0xff;\n\n if (!isJpeg) {\n return null;\n }\n\n const {tableMarkers, sofMarkers} = getJpegMarkers();\n\n // Exclude the two byte SOI marker.\n let i = 2;\n while (i + 9 < dataView.byteLength) {\n const marker = dataView.getUint16(i, BIG_ENDIAN);\n\n // The frame that contains the width and height of the JPEG image.\n if (sofMarkers.has(marker)) {\n return {\n mimeType: 'image/jpeg',\n height: dataView.getUint16(i + 5, BIG_ENDIAN), // Number of lines\n width: dataView.getUint16(i + 7, BIG_ENDIAN) // Number of pixels per line\n };\n }\n\n // Miscellaneous tables/data preceding the frame header.\n if (!tableMarkers.has(marker)) {\n return null;\n }\n\n // Length includes size of length parameter but not the two byte header.\n i += 2;\n i += dataView.getUint16(i, BIG_ENDIAN);\n }\n\n return null;\n}\n\nfunction getJpegMarkers() {\n // Tables/misc header markers.\n // DQT, DHT, DAC, DRI, COM, APP_n\n const tableMarkers = new Set([0xffdb, 0xffc4, 0xffcc, 0xffdd, 0xfffe]);\n for (let i = 0xffe0; i < 0xfff0; ++i) {\n tableMarkers.add(i);\n }\n\n // SOF markers and DHP marker.\n // These markers are after tables/misc data.\n const sofMarkers = new Set([\n 0xffc0, 0xffc1, 0xffc2, 0xffc3, 0xffc5, 0xffc6, 0xffc7, 0xffc9, 0xffca, 0xffcb, 0xffcd, 0xffce,\n 0xffcf, 0xffde\n ]);\n\n return {tableMarkers, sofMarkers};\n}\n\n// TODO - move into image module?\nfunction toDataView(data) {\n if (data instanceof DataView) {\n return data;\n }\n if (ArrayBuffer.isView(data)) {\n return new DataView(data.buffer);\n }\n\n // TODO: make these functions work for Node.js buffers?\n // if (bufferToArrayBuffer) {\n // data = bufferToArrayBuffer(data);\n // }\n\n // Careful - Node Buffers will look like ArrayBuffers (keep after isBuffer)\n if (data instanceof ArrayBuffer) {\n return new DataView(data);\n }\n throw new Error('toDataView');\n}\n"],"mappings":";;AAQA,SAAQA,mBAAmB,QAAO,wBAAwB;;AAS1D,MAAMC,UAAU,GAAG,KAAK;AACxB,MAAMC,aAAa,GAAG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E,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAC9F,MAAM,EAAE,MAAM,CACf,CAAC;EAEF,OAAO;IAACN,YAAY;IAAEC;EAAU,CAAC;AACnC;;AAGA,SAAStB,UAAU,CAAC6B,IAAI,EAAE;EACxB,IAAIA,IAAI,YAAYrB,QAAQ,EAAE;IAC5B,OAAOqB,IAAI;EACb;EACA,IAAIC,WAAW,CAACC,MAAM,CAACF,IAAI,CAAC,EAAE;IAC5B,OAAO,IAAIrB,QAAQ,CAACqB,IAAI,CAACvB,MAAM,CAAC;EAClC;;EAQA,IAAIuB,IAAI,YAAYC,WAAW,EAAE;IAC/B,OAAO,IAAItB,QAAQ,CAACqB,IAAI,CAAC;EAC3B;EACA,MAAM,IAAIG,KAAK,CAAC,YAAY,CAAC;AAC/B"}
|
|
1
|
+
{"version":3,"file":"binary-image-api.js","names":["getISOBMFFMediaType","BIG_ENDIAN","LITTLE_ENDIAN","getBinaryImageMetadata","binaryData","dataView","toDataView","getPngMetadata","getJpegMetadata","getGifMetadata","getBmpMetadata","getISOBMFFMetadata","buffer","Uint8Array","DataView","mediaType","mimeType","width","height","isPng","byteLength","getUint32","isGif","getUint16","isBmp","isJpeg","getUint8","tableMarkers","sofMarkers","getJpegMarkers","i","marker","has","Set","add","data","ArrayBuffer","isView","Error"],"sources":["../../../../src/lib/category-api/binary-image-api.ts"],"sourcesContent":["// Attributions\n// * Based on binary-gltf-utils under MIT license: Copyright (c) 2016-17 Karl Cheng\n\n// TODO: make these functions work for Node.js buffers?\n// Quarantine references to Buffer to prevent bundler from adding big polyfills\n// import {bufferToArrayBuffer} from '../node/buffer-to-array-buffer';\n// TODO - this should be handled in @loaders.gl/polyfills\n\nimport {getISOBMFFMediaType} from './parse-isobmff-binary';\n\n/** MIME type, width and height extracted from binary compressed image data */\nexport type BinaryImageMetadata = {\n mimeType: string;\n width: number;\n height: number;\n};\n\nconst BIG_ENDIAN = false;\nconst LITTLE_ENDIAN = true;\n\n/**\n * Extracts `{mimeType, width and height}` from a memory buffer containing a known image format\n * Currently supports `image/png`, `image/jpeg`, `image/bmp` and `image/gif`.\n * @param binaryData: DataView | ArrayBuffer image file memory to parse\n * @returns metadata or null if memory is not a valid image file format layout.\n */\nexport function getBinaryImageMetadata(\n binaryData: DataView | ArrayBuffer\n): BinaryImageMetadata | null {\n const dataView = toDataView(binaryData);\n return (\n getPngMetadata(dataView) ||\n getJpegMetadata(dataView) ||\n getGifMetadata(dataView) ||\n getBmpMetadata(dataView) ||\n getISOBMFFMetadata(dataView)\n );\n}\n\n// ISOBMFF\n\nfunction getISOBMFFMetadata(binaryData: DataView | ArrayBuffer): BinaryImageMetadata | null {\n const buffer = new Uint8Array(binaryData instanceof DataView ? binaryData.buffer : binaryData);\n const mediaType = getISOBMFFMediaType(buffer);\n if (!mediaType) {\n return null;\n }\n return {\n mimeType: mediaType.mimeType,\n // TODO - decode width and height\n width: 0,\n height: 0\n };\n}\n\n// PNG\n\nfunction getPngMetadata(binaryData: DataView | ArrayBuffer): BinaryImageMetadata | null {\n const dataView = toDataView(binaryData);\n // Check file contains the first 4 bytes of the PNG signature.\n const isPng = dataView.byteLength >= 24 && dataView.getUint32(0, BIG_ENDIAN) === 0x89504e47;\n if (!isPng) {\n return null;\n }\n\n // Extract size from a binary PNG file\n return {\n mimeType: 'image/png',\n width: dataView.getUint32(16, BIG_ENDIAN),\n height: dataView.getUint32(20, BIG_ENDIAN)\n };\n}\n\n// GIF\n\n// Extract size from a binary GIF file\n// TODO: GIF is not this simple\nfunction getGifMetadata(binaryData: DataView | ArrayBuffer): BinaryImageMetadata | null {\n const dataView = toDataView(binaryData);\n // Check first 4 bytes of the GIF signature (\"GIF8\").\n const isGif = dataView.byteLength >= 10 && dataView.getUint32(0, BIG_ENDIAN) === 0x47494638;\n if (!isGif) {\n return null;\n }\n\n // GIF is little endian.\n return {\n mimeType: 'image/gif',\n width: dataView.getUint16(6, LITTLE_ENDIAN),\n height: dataView.getUint16(8, LITTLE_ENDIAN)\n };\n}\n\n// BMP\n\n// TODO: BMP is not this simple\nexport function getBmpMetadata(binaryData: DataView | ArrayBuffer): BinaryImageMetadata | null {\n const dataView = toDataView(binaryData);\n // Check magic number is valid (first 2 characters should be \"BM\").\n // The mandatory bitmap file header is 14 bytes long.\n const isBmp =\n dataView.byteLength >= 14 &&\n dataView.getUint16(0, BIG_ENDIAN) === 0x424d &&\n dataView.getUint32(2, LITTLE_ENDIAN) === dataView.byteLength;\n\n if (!isBmp) {\n return null;\n }\n\n // BMP is little endian.\n return {\n mimeType: 'image/bmp',\n width: dataView.getUint32(18, LITTLE_ENDIAN),\n height: dataView.getUint32(22, LITTLE_ENDIAN)\n };\n}\n\n// JPEG\n\n// Extract width and height from a binary JPEG file\nfunction getJpegMetadata(binaryData: DataView | ArrayBuffer): BinaryImageMetadata | null {\n const dataView = toDataView(binaryData);\n // Check file contains the JPEG \"start of image\" (SOI) marker\n // followed by another marker.\n const isJpeg =\n dataView.byteLength >= 3 &&\n dataView.getUint16(0, BIG_ENDIAN) === 0xffd8 &&\n dataView.getUint8(2) === 0xff;\n\n if (!isJpeg) {\n return null;\n }\n\n const {tableMarkers, sofMarkers} = getJpegMarkers();\n\n // Exclude the two byte SOI marker.\n let i = 2;\n while (i + 9 < dataView.byteLength) {\n const marker = dataView.getUint16(i, BIG_ENDIAN);\n\n // The frame that contains the width and height of the JPEG image.\n if (sofMarkers.has(marker)) {\n return {\n mimeType: 'image/jpeg',\n height: dataView.getUint16(i + 5, BIG_ENDIAN), // Number of lines\n width: dataView.getUint16(i + 7, BIG_ENDIAN) // Number of pixels per line\n };\n }\n\n // Miscellaneous tables/data preceding the frame header.\n if (!tableMarkers.has(marker)) {\n return null;\n }\n\n // Length includes size of length parameter but not the two byte header.\n i += 2;\n i += dataView.getUint16(i, BIG_ENDIAN);\n }\n\n return null;\n}\n\nfunction getJpegMarkers() {\n // Tables/misc header markers.\n // DQT, DHT, DAC, DRI, COM, APP_n\n const tableMarkers = new Set([0xffdb, 0xffc4, 0xffcc, 0xffdd, 0xfffe]);\n for (let i = 0xffe0; i < 0xfff0; ++i) {\n tableMarkers.add(i);\n }\n\n // SOF markers and DHP marker.\n // These markers are after tables/misc data.\n const sofMarkers = new Set([\n 0xffc0, 0xffc1, 0xffc2, 0xffc3, 0xffc5, 0xffc6, 0xffc7, 0xffc9, 0xffca, 0xffcb, 0xffcd, 0xffce,\n 0xffcf, 0xffde\n ]);\n\n return {tableMarkers, sofMarkers};\n}\n\n// TODO - move into image module?\nfunction toDataView(data) {\n if (data instanceof DataView) {\n return data;\n }\n if (ArrayBuffer.isView(data)) {\n return new DataView(data.buffer);\n }\n\n // TODO: make these functions work for Node.js buffers?\n // if (bufferToArrayBuffer) {\n // data = bufferToArrayBuffer(data);\n // }\n\n // Careful - Node Buffers will look like ArrayBuffers (keep after isBuffer)\n if (data instanceof ArrayBuffer) {\n return new DataView(data);\n }\n throw new Error('toDataView');\n}\n"],"mappings":"AAQA,SAAQA,mBAAmB,QAAO,wBAAwB;AAS1D,MAAMC,UAAU,GAAG,KAAK;AACxB,MAAMC,aAAa,GAAG,IAAI;AAQ1B,OAAO,SAASC,sBAAsBA,CACpCC,UAAkC,EACN;EAC5B,MAAMC,QAAQ,GAAGC,UAAU,CAACF,UAAU,CAAC;EACvC,OACEG,cAAc,CAACF,QAAQ,CAAC,IACxBG,eAAe,CAACH,QAAQ,CAAC,IACzBI,cAAc,CAACJ,QAAQ,CAAC,IACxBK,cAAc,CAACL,QAAQ,CAAC,IACxBM,kBAAkB,CAACN,QAAQ,CAAC;AAEhC;AAIA,SAASM,kBAAkBA,CAACP,UAAkC,EAA8B;EAC1F,MAAMQ,MAAM,GAAG,IAAIC,UAAU,CAACT,UAAU,YAAYU,QAAQ,GAAGV,UAAU,CAACQ,MAAM,GAAGR,UAAU,CAAC;EAC9F,MAAMW,SAAS,GAAGf,mBAAmB,CAACY,MAAM,CAAC;EAC7C,IAAI,CAACG,SAAS,EAAE;IACd,OAAO,IAAI;EACb;E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
2
|
-
|
|
3
1
|
import { isBrowser } from '@loaders.gl/loader-utils';
|
|
4
|
-
const MIME_TYPES = ['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/avif', 'image/tiff',
|
|
5
|
-
'image/svg', 'image/svg+xml', 'image/bmp', 'image/vnd.microsoft.icon'];
|
|
6
|
-
|
|
2
|
+
const MIME_TYPES = ['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/avif', 'image/tiff', 'image/svg', 'image/svg+xml', 'image/bmp', 'image/vnd.microsoft.icon'];
|
|
7
3
|
const mimeTypeSupportedPromise = null;
|
|
8
|
-
|
|
9
4
|
export async function getSupportedImageFormats() {
|
|
10
5
|
if (mimeTypeSupportedPromise) {
|
|
11
6
|
return await mimeTypeSupportedPromise;
|
|
@@ -19,9 +14,7 @@ export async function getSupportedImageFormats() {
|
|
|
19
14
|
}
|
|
20
15
|
return supportedMimeTypes;
|
|
21
16
|
}
|
|
22
|
-
|
|
23
17
|
const mimeTypeSupportedSync = {};
|
|
24
|
-
|
|
25
18
|
export function isImageFormatSupported(mimeType) {
|
|
26
19
|
if (mimeTypeSupportedSync[mimeType] === undefined) {
|
|
27
20
|
const supported = isBrowser ? checkBrowserImageFormatSupport(mimeType) : checkNodeImageFormatSupport(mimeType);
|
|
@@ -29,7 +22,6 @@ export function isImageFormatSupported(mimeType) {
|
|
|
29
22
|
}
|
|
30
23
|
return mimeTypeSupportedSync[mimeType];
|
|
31
24
|
}
|
|
32
|
-
|
|
33
25
|
function checkNodeImageFormatSupport(mimeType) {
|
|
34
26
|
const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];
|
|
35
27
|
const {
|
|
@@ -38,7 +30,6 @@ function checkNodeImageFormatSupport(mimeType) {
|
|
|
38
30
|
} = globalThis;
|
|
39
31
|
return Boolean(_parseImageNode) && _imageFormatsNode.includes(mimeType);
|
|
40
32
|
}
|
|
41
|
-
|
|
42
33
|
function checkBrowserImageFormatSupport(mimeType) {
|
|
43
34
|
switch (mimeType) {
|
|
44
35
|
case 'image/avif':
|
|
@@ -52,12 +43,10 @@ const TEST_IMAGE = {
|
|
|
52
43
|
'image/avif': 'data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=',
|
|
53
44
|
'image/webp': 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA'
|
|
54
45
|
};
|
|
55
|
-
|
|
56
46
|
async function checkBrowserImageFormatSupportAsync(mimeType) {
|
|
57
47
|
const dataURL = TEST_IMAGE[mimeType];
|
|
58
48
|
return dataURL ? await testBrowserImageFormatSupportAsync(dataURL) : true;
|
|
59
49
|
}
|
|
60
|
-
|
|
61
50
|
function testBrowserImageFormatSupport(mimeType) {
|
|
62
51
|
try {
|
|
63
52
|
const element = document.createElement('canvas');
|
|
@@ -67,7 +56,6 @@ function testBrowserImageFormatSupport(mimeType) {
|
|
|
67
56
|
return false;
|
|
68
57
|
}
|
|
69
58
|
}
|
|
70
|
-
|
|
71
59
|
async function testBrowserImageFormatSupportAsync(testImageDataURL) {
|
|
72
60
|
return new Promise(resolve => {
|
|
73
61
|
const image = new Image();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-format.js","names":["isBrowser","MIME_TYPES","mimeTypeSupportedPromise","getSupportedImageFormats","supportedMimeTypes","Set","mimeType","supported","checkBrowserImageFormatSupportAsync","checkNodeImageFormatSupport","add","mimeTypeSupportedSync","isImageFormatSupported","undefined","checkBrowserImageFormatSupport","NODE_FORMAT_SUPPORT","_parseImageNode","_imageFormatsNode","globalThis","Boolean","includes","testBrowserImageFormatSupport","TEST_IMAGE","dataURL","testBrowserImageFormatSupportAsync","element","document","createElement","toDataURL","indexOf","testImageDataURL","Promise","resolve","image","Image","src","onload","height","onerror"],"sources":["../../../../src/lib/category-api/image-format.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport {isBrowser} from '@loaders.gl/loader-utils';\n\nconst MIME_TYPES = [\n 'image/png',\n 'image/jpeg',\n 'image/gif',\n 'image/webp',\n 'image/avif',\n 'image/tiff',\n // TODO - what is the correct type for SVG\n 'image/svg',\n 'image/svg+xml',\n 'image/bmp',\n 'image/vnd.microsoft.icon'\n];\n\n/** Only one round of tests is performed */\nconst mimeTypeSupportedPromise: Promise<Set<string>> | null = null;\n\n/** Run-time browser detection of file formats requires async tests for most precise results */\nexport async function getSupportedImageFormats(): Promise<Set<string>> {\n if (mimeTypeSupportedPromise) {\n return await mimeTypeSupportedPromise;\n }\n\n const supportedMimeTypes = new Set<string>();\n for (const mimeType of MIME_TYPES) {\n const supported = isBrowser\n ? await checkBrowserImageFormatSupportAsync(mimeType)\n : checkNodeImageFormatSupport(mimeType);\n if (supported) {\n supportedMimeTypes.add(mimeType);\n }\n }\n\n return supportedMimeTypes;\n}\n\n/** Cache sync values for speed */\nconst mimeTypeSupportedSync: {[mimeType: string]: boolean} = {};\n\n/**\n * Check if image MIME type is supported. Result is cached to avoid repeated tests.\n */\nexport function isImageFormatSupported(mimeType: string): boolean {\n if (mimeTypeSupportedSync[mimeType] === undefined) {\n const supported = isBrowser\n ? checkBrowserImageFormatSupport(mimeType)\n : checkNodeImageFormatSupport(mimeType);\n mimeTypeSupportedSync[mimeType] = supported;\n }\n return mimeTypeSupportedSync[mimeType];\n}\n\n/**\n * Checks that polyfills are installed and that mimeType is supported by polyfills\n * @todo Ideally polyfills should declare what formats they support, instead of storing that data here.\n */\nfunction checkNodeImageFormatSupport(mimeType: string): boolean {\n /** @deprecated Remove these in 4.0 and rely on polyfills to inject them */\n const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];\n // @ts-ignore\n const {_parseImageNode, _imageFormatsNode = NODE_FORMAT_SUPPORT} = globalThis;\n return Boolean(_parseImageNode) && _imageFormatsNode.includes(mimeType);\n}\n\n/** Checks image format support synchronously.\n * @note Unreliable, fails on AVIF\n */\nfunction checkBrowserImageFormatSupport(mimeType: string): boolean {\n switch (mimeType) {\n case 'image/avif': // Will fail\n case 'image/webp':\n return testBrowserImageFormatSupport(mimeType);\n default:\n return true;\n }\n}\n\nconst TEST_IMAGE = {\n 'image/avif':\n 'data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=',\n // Lossy test image. Support for lossy images doesn't guarantee support for all WebP images.\n 'image/webp': 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA'\n};\n\n/** Checks WebP and AVIF support asynchronously */\nasync function checkBrowserImageFormatSupportAsync(mimeType: string): Promise<boolean> {\n const dataURL = TEST_IMAGE[mimeType];\n return dataURL ? await testBrowserImageFormatSupportAsync(dataURL) : true;\n}\n\n/**\n * Checks browser synchronously\n * Checks if toDataURL supports the mimeType.\n * @note Imperfect testOn Chrome this is true for WebP but not for AVIF\n */\nfunction testBrowserImageFormatSupport(mimeType: string): boolean {\n try {\n const element = document.createElement('canvas');\n const dataURL = element.toDataURL(mimeType);\n return dataURL.indexOf(`data:${mimeType}`) === 0;\n } catch {\n // Probably Safari...\n return false;\n }\n}\n\n// Check WebPSupport asynchronously\nasync function testBrowserImageFormatSupportAsync(testImageDataURL: string): Promise<boolean> {\n return new Promise((resolve) => {\n const image = new Image();\n image.src = testImageDataURL;\n image.onload = () => resolve(image.height > 0);\n image.onerror = () => resolve(false);\n });\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"image-format.js","names":["isBrowser","MIME_TYPES","mimeTypeSupportedPromise","getSupportedImageFormats","supportedMimeTypes","Set","mimeType","supported","checkBrowserImageFormatSupportAsync","checkNodeImageFormatSupport","add","mimeTypeSupportedSync","isImageFormatSupported","undefined","checkBrowserImageFormatSupport","NODE_FORMAT_SUPPORT","_parseImageNode","_imageFormatsNode","globalThis","Boolean","includes","testBrowserImageFormatSupport","TEST_IMAGE","dataURL","testBrowserImageFormatSupportAsync","element","document","createElement","toDataURL","indexOf","concat","testImageDataURL","Promise","resolve","image","Image","src","onload","height","onerror"],"sources":["../../../../src/lib/category-api/image-format.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport {isBrowser} from '@loaders.gl/loader-utils';\n\nconst MIME_TYPES = [\n 'image/png',\n 'image/jpeg',\n 'image/gif',\n 'image/webp',\n 'image/avif',\n 'image/tiff',\n // TODO - what is the correct type for SVG\n 'image/svg',\n 'image/svg+xml',\n 'image/bmp',\n 'image/vnd.microsoft.icon'\n];\n\n/** Only one round of tests is performed */\nconst mimeTypeSupportedPromise: Promise<Set<string>> | null = null;\n\n/** Run-time browser detection of file formats requires async tests for most precise results */\nexport async function getSupportedImageFormats(): Promise<Set<string>> {\n if (mimeTypeSupportedPromise) {\n return await mimeTypeSupportedPromise;\n }\n\n const supportedMimeTypes = new Set<string>();\n for (const mimeType of MIME_TYPES) {\n const supported = isBrowser\n ? await checkBrowserImageFormatSupportAsync(mimeType)\n : checkNodeImageFormatSupport(mimeType);\n if (supported) {\n supportedMimeTypes.add(mimeType);\n }\n }\n\n return supportedMimeTypes;\n}\n\n/** Cache sync values for speed */\nconst mimeTypeSupportedSync: {[mimeType: string]: boolean} = {};\n\n/**\n * Check if image MIME type is supported. Result is cached to avoid repeated tests.\n */\nexport function isImageFormatSupported(mimeType: string): boolean {\n if (mimeTypeSupportedSync[mimeType] === undefined) {\n const supported = isBrowser\n ? checkBrowserImageFormatSupport(mimeType)\n : checkNodeImageFormatSupport(mimeType);\n mimeTypeSupportedSync[mimeType] = supported;\n }\n return mimeTypeSupportedSync[mimeType];\n}\n\n/**\n * Checks that polyfills are installed and that mimeType is supported by polyfills\n * @todo Ideally polyfills should declare what formats they support, instead of storing that data here.\n */\nfunction checkNodeImageFormatSupport(mimeType: string): boolean {\n /** @deprecated Remove these in 4.0 and rely on polyfills to inject them */\n const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];\n // @ts-ignore\n const {_parseImageNode, _imageFormatsNode = NODE_FORMAT_SUPPORT} = globalThis;\n return Boolean(_parseImageNode) && _imageFormatsNode.includes(mimeType);\n}\n\n/** Checks image format support synchronously.\n * @note Unreliable, fails on AVIF\n */\nfunction checkBrowserImageFormatSupport(mimeType: string): boolean {\n switch (mimeType) {\n case 'image/avif': // Will fail\n case 'image/webp':\n return testBrowserImageFormatSupport(mimeType);\n default:\n return true;\n }\n}\n\nconst TEST_IMAGE = {\n 'image/avif':\n 'data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=',\n // Lossy test image. Support for lossy images doesn't guarantee support for all WebP images.\n 'image/webp': 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA'\n};\n\n/** Checks WebP and AVIF support asynchronously */\nasync function checkBrowserImageFormatSupportAsync(mimeType: string): Promise<boolean> {\n const dataURL = TEST_IMAGE[mimeType];\n return dataURL ? await testBrowserImageFormatSupportAsync(dataURL) : true;\n}\n\n/**\n * Checks browser synchronously\n * Checks if toDataURL supports the mimeType.\n * @note Imperfect testOn Chrome this is true for WebP but not for AVIF\n */\nfunction testBrowserImageFormatSupport(mimeType: string): boolean {\n try {\n const element = document.createElement('canvas');\n const dataURL = element.toDataURL(mimeType);\n return dataURL.indexOf(`data:${mimeType}`) === 0;\n } catch {\n // Probably Safari...\n return false;\n }\n}\n\n// Check WebPSupport asynchronously\nasync function testBrowserImageFormatSupportAsync(testImageDataURL: string): Promise<boolean> {\n return new Promise((resolve) => {\n const image = new Image();\n image.src = testImageDataURL;\n image.onload = () => resolve(image.height > 0);\n image.onerror = () => resolve(false);\n });\n}\n"],"mappings":"AAEA,SAAQA,SAAS,QAAO,0BAA0B;AAElD,MAAMC,UAAU,GAAG,CACjB,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,YAAY,EAEZ,WAAW,EACX,eAAe,EACf,WAAW,EACX,0BAA0B,CAC3B;AAGD,MA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O,IAAI;EACf;AACF;AAEA,MAAMgB,UAAU,GAAG;EACjB,YAAY,EACV,ybAAyb;EAE3b,YAAY,EAAE;AAChB,CAAC;AAGD,eAAed,mCAAmCA,CAACF,QAAgB,EAAoB;EACrF,MAAMiB,OAAO,GAAGD,UAAU,CAAChB,QAAQ,CAAC;EACpC,OAAOiB,OAAO,GAAG,MAAMC,kCAAkC,CAACD,OAAO,CAAC,GAAG,IAAI;AAC3E;AAOA,SAASF,6BAA6BA,CAACf,QAAgB,EAAW;EAChE,IAAI;IACF,MAAMmB,OAAO,GAAGC,QAAQ,CAACC,aAAa,CAAC,QAAQ,CAAC;IAChD,MAAMJ,OAAO,GAAGE,OAAO,CAACG,SAAS,CAACtB,QAAQ,CAAC;IAC3C,OAAOiB,OAAO,CAACM,OAAO,SAAAC,MAAA,CAASxB,QAAQ,CAAE,CAAC,KAAK,CAAC;EAClD,CAAC,CAAC,MAAM;IAEN,OAAO,KAAK;EACd;AACF;AAGA,eAAekB,kCAAkCA,CAACO,gBAAwB,EAAoB;EAC5F,OAAO,IAAIC,OAAO,CAAEC,OAAO,IAAK;IAC9B,MAAMC,KAAK,GAAG,IAAIC,KAAK,CAAC,CAAC;IACzBD,KAAK,CAACE,GAAG,GAAGL,gBAAgB;IAC5BG,KAAK,CAACG,MAAM,GAAG,MAAMJ,OAAO,CAACC,KAAK,CAACI,MAAM,GAAG,CAAC,CAAC;IAC9CJ,KAAK,CAACK,OAAO,GAAG,MAAMN,OAAO,CAAC,KAAK,CAAC;EACtC,CAAC,CAAC;AACJ"}
|
|
@@ -6,7 +6,6 @@ const IMAGE_SUPPORTED = typeof Image !== 'undefined';
|
|
|
6
6
|
const IMAGE_BITMAP_SUPPORTED = typeof ImageBitmap !== 'undefined';
|
|
7
7
|
const NODE_IMAGE_SUPPORTED = Boolean(_parseImageNode);
|
|
8
8
|
const DATA_SUPPORTED = isBrowser ? true : NODE_IMAGE_SUPPORTED;
|
|
9
|
-
|
|
10
9
|
export function isImageTypeSupported(type) {
|
|
11
10
|
switch (type) {
|
|
12
11
|
case 'auto':
|
|
@@ -21,7 +20,6 @@ export function isImageTypeSupported(type) {
|
|
|
21
20
|
throw new Error("@loaders.gl/images: image ".concat(type, " not supported in this environment"));
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
|
-
|
|
25
23
|
export function getDefaultImageType() {
|
|
26
24
|
if (IMAGE_BITMAP_SUPPORTED) {
|
|
27
25
|
return 'imagebitmap';
|
|
@@ -32,7 +30,6 @@ export function getDefaultImageType() {
|
|
|
32
30
|
if (DATA_SUPPORTED) {
|
|
33
31
|
return 'data';
|
|
34
32
|
}
|
|
35
|
-
|
|
36
33
|
throw new Error('Install \'@loaders.gl/polyfills\' to parse images under Node.js');
|
|
37
34
|
}
|
|
38
35
|
//# sourceMappingURL=image-type.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-type.js","names":["isBrowser","_parseImageNode","globalThis","IMAGE_SUPPORTED","Image","IMAGE_BITMAP_SUPPORTED","ImageBitmap","NODE_IMAGE_SUPPORTED","Boolean","DATA_SUPPORTED","isImageTypeSupported","type","Error","getDefaultImageType"],"sources":["../../../../src/lib/category-api/image-type.ts"],"sourcesContent":["import {isBrowser} from '@loaders.gl/loader-utils';\nimport type {ImageTypeEnum} from '../../types';\n\n// @ts-ignore TS2339: Property does not exist on type\nconst {_parseImageNode} = globalThis;\n\nconst IMAGE_SUPPORTED = typeof Image !== 'undefined'; // NOTE: \"false\" positives if jsdom is installed\nconst IMAGE_BITMAP_SUPPORTED = typeof ImageBitmap !== 'undefined';\nconst NODE_IMAGE_SUPPORTED = Boolean(_parseImageNode);\nconst DATA_SUPPORTED = isBrowser ? true : NODE_IMAGE_SUPPORTED;\n\n/**\n * Checks if a loaders.gl image type is supported\n * @param type image type string\n */\nexport function isImageTypeSupported(type: string): boolean {\n switch (type) {\n case 'auto':\n // Should only ever be false in Node.js, if polyfills have not been installed...\n return IMAGE_BITMAP_SUPPORTED || IMAGE_SUPPORTED || DATA_SUPPORTED;\n\n case 'imagebitmap':\n return IMAGE_BITMAP_SUPPORTED;\n case 'image':\n return IMAGE_SUPPORTED;\n case 'data':\n return DATA_SUPPORTED;\n\n default:\n throw new Error(`@loaders.gl/images: image ${type} not supported in this environment`);\n }\n}\n\n/**\n * Returns the \"most performant\" supported image type on this platform\n * @returns image type string\n */\nexport function getDefaultImageType(): ImageTypeEnum {\n if (IMAGE_BITMAP_SUPPORTED) {\n return 'imagebitmap';\n }\n if (IMAGE_SUPPORTED) {\n return 'image';\n }\n if (DATA_SUPPORTED) {\n return 'data';\n }\n\n // This should only happen in Node.js\n throw new Error('Install \\'@loaders.gl/polyfills\\' to parse images under Node.js');\n}\n"],"mappings":"AAAA,SAAQA,SAAS,QAAO,0BAA0B;AAIlD,MAAM;EAACC;AAAe,CAAC,GAAGC,UAAU;AAEpC,MAAMC,eAAe,GAAG,OAAOC,KAAK,KAAK,WAAW;AACpD,MAAMC,sBAAsB,GAAG,OAAOC,WAAW,KAAK,WAAW;AACjE,MAAMC,oBAAoB,GAAGC,OAAO,CAACP,eAAe,CAAC;AACrD,MAAMQ,cAAc,GAAGT,SAAS,GAAG,IAAI,GAAGO,oBAAoB
|
|
1
|
+
{"version":3,"file":"image-type.js","names":["isBrowser","_parseImageNode","globalThis","IMAGE_SUPPORTED","Image","IMAGE_BITMAP_SUPPORTED","ImageBitmap","NODE_IMAGE_SUPPORTED","Boolean","DATA_SUPPORTED","isImageTypeSupported","type","Error","concat","getDefaultImageType"],"sources":["../../../../src/lib/category-api/image-type.ts"],"sourcesContent":["import {isBrowser} from '@loaders.gl/loader-utils';\nimport type {ImageTypeEnum} from '../../types';\n\n// @ts-ignore TS2339: Property does not exist on type\nconst {_parseImageNode} = globalThis;\n\nconst IMAGE_SUPPORTED = typeof Image !== 'undefined'; // NOTE: \"false\" positives if jsdom is installed\nconst IMAGE_BITMAP_SUPPORTED = typeof ImageBitmap !== 'undefined';\nconst NODE_IMAGE_SUPPORTED = Boolean(_parseImageNode);\nconst DATA_SUPPORTED = isBrowser ? true : NODE_IMAGE_SUPPORTED;\n\n/**\n * Checks if a loaders.gl image type is supported\n * @param type image type string\n */\nexport function isImageTypeSupported(type: string): boolean {\n switch (type) {\n case 'auto':\n // Should only ever be false in Node.js, if polyfills have not been installed...\n return IMAGE_BITMAP_SUPPORTED || IMAGE_SUPPORTED || DATA_SUPPORTED;\n\n case 'imagebitmap':\n return IMAGE_BITMAP_SUPPORTED;\n case 'image':\n return IMAGE_SUPPORTED;\n case 'data':\n return DATA_SUPPORTED;\n\n default:\n throw new Error(`@loaders.gl/images: image ${type} not supported in this environment`);\n }\n}\n\n/**\n * Returns the \"most performant\" supported image type on this platform\n * @returns image type string\n */\nexport function getDefaultImageType(): ImageTypeEnum {\n if (IMAGE_BITMAP_SUPPORTED) {\n return 'imagebitmap';\n }\n if (IMAGE_SUPPORTED) {\n return 'image';\n }\n if (DATA_SUPPORTED) {\n return 'data';\n }\n\n // This should only happen in Node.js\n throw new Error('Install \\'@loaders.gl/polyfills\\' to parse images under Node.js');\n}\n"],"mappings":"AAAA,SAAQA,SAAS,QAAO,0BAA0B;AAIlD,MAAM;EAACC;AAAe,CAAC,GAAGC,UAAU;AAEpC,MAAMC,eAAe,GAAG,OAAOC,KAAK,KAAK,WAAW;AACpD,MAAMC,sBAAsB,GAAG,OAAOC,WAAW,KAAK,WAAW;AACjE,MAAMC,oBAAoB,GAAGC,OAAO,CAACP,eAAe,CAAC;AACrD,MAAMQ,cAAc,GAAGT,SAAS,GAAG,IAAI,GAAGO,oBAAoB;AAM9D,OAAO,SAASG,oBAAoBA,CAACC,IAAY,EAAW;EAC1D,QAAQA,IAAI;IACV,KAAK,MAAM;MAET,OAAON,sBAAsB,IAAIF,eAAe,IAAIM,cAAc;IAEpE,KAAK,aAAa;MAChB,OAAOJ,sBAAsB;IAC/B,KAAK,OAAO;MACV,OAAOF,eAAe;IACxB,KAAK,MAAM;MACT,OAAOM,cAAc;IAEvB;MACE,MAAM,IAAIG,KAAK,8BAAAC,MAAA,CAA8BF,IAAI,uCAAoC,CAAC;EAC1F;AACF;AAMA,OAAO,SAASG,mBAAmBA,CAAA,EAAkB;EACnD,IAAIT,sBAAsB,EAAE;IAC1B,OAAO,aAAa;EACtB;EACA,IAAIF,eAAe,EAAE;IACnB,OAAO,OAAO;EAChB;EACA,IAAIM,cAAc,EAAE;IAClB,OAAO,MAAM;EACf;EAGA,MAAM,IAAIG,KAAK,CAAC,iEAAiE,CAAC;AACpF"}
|