@loaders.gl/images 3.4.0-alpha.1 → 3.4.0-alpha.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.
Files changed (44) hide show
  1. package/dist/dist.min.js +1 -1
  2. package/dist/dist.min.js.map +3 -3
  3. package/dist/es5/image-loader.js +2 -2
  4. package/dist/es5/image-loader.js.map +1 -1
  5. package/dist/es5/index.js +12 -6
  6. package/dist/es5/index.js.map +1 -1
  7. package/dist/es5/lib/category-api/binary-image-api.js +15 -1
  8. package/dist/es5/lib/category-api/binary-image-api.js.map +1 -1
  9. package/dist/es5/lib/category-api/image-format.js +170 -20
  10. package/dist/es5/lib/category-api/image-format.js.map +1 -1
  11. package/dist/es5/lib/category-api/parse-isobmff-binary.js +55 -0
  12. package/dist/es5/lib/category-api/parse-isobmff-binary.js.map +1 -0
  13. package/dist/es5/lib/utils/version.js +1 -1
  14. package/dist/esm/image-loader.js +2 -2
  15. package/dist/esm/image-loader.js.map +1 -1
  16. package/dist/esm/index.js +2 -1
  17. package/dist/esm/index.js.map +1 -1
  18. package/dist/esm/lib/category-api/binary-image-api.js +16 -1
  19. package/dist/esm/lib/category-api/binary-image-api.js.map +1 -1
  20. package/dist/esm/lib/category-api/image-format.js +58 -21
  21. package/dist/esm/lib/category-api/image-format.js.map +1 -1
  22. package/dist/esm/lib/category-api/parse-isobmff-binary.js +45 -0
  23. package/dist/esm/lib/category-api/parse-isobmff-binary.js.map +1 -0
  24. package/dist/esm/lib/utils/version.js +1 -1
  25. package/dist/image-loader.d.ts.map +1 -1
  26. package/dist/image-loader.js +2 -1
  27. package/dist/index.d.ts +2 -1
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +5 -3
  30. package/dist/lib/category-api/binary-image-api.d.ts +2 -6
  31. package/dist/lib/category-api/binary-image-api.d.ts.map +1 -1
  32. package/dist/lib/category-api/binary-image-api.js +22 -2
  33. package/dist/lib/category-api/image-format.d.ts +4 -2
  34. package/dist/lib/category-api/image-format.d.ts.map +1 -1
  35. package/dist/lib/category-api/image-format.js +86 -39
  36. package/dist/lib/category-api/parse-isobmff-binary.d.ts +19 -0
  37. package/dist/lib/category-api/parse-isobmff-binary.d.ts.map +1 -0
  38. package/dist/lib/category-api/parse-isobmff-binary.js +94 -0
  39. package/package.json +6 -3
  40. package/src/image-loader.ts +2 -1
  41. package/src/index.ts +3 -2
  42. package/src/lib/category-api/binary-image-api.ts +25 -6
  43. package/src/lib/category-api/image-format.ts +92 -39
  44. package/src/lib/category-api/parse-isobmff-binary.ts +105 -0
@@ -1,45 +1,195 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
- exports._isImageFormatSupported = _isImageFormatSupported;
7
+ exports.getSupportedImageFormats = getSupportedImageFormats;
8
+ exports.isImageFormatSupported = isImageFormatSupported;
9
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
10
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
7
11
  var _loaderUtils = require("@loaders.gl/loader-utils");
8
- var NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];
12
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
13
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
14
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
15
+ var MIME_TYPES = ['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/avif', 'image/tiff',
16
+ 'image/svg', 'image/svg+xml', 'image/bmp', 'image/vnd.microsoft.icon'];
9
17
 
10
- var mimeTypeSupported = {};
18
+ var mimeTypeSupportedPromise = null;
11
19
 
12
- function _isImageFormatSupported(mimeType) {
13
- if (mimeTypeSupported[mimeType] === undefined) {
14
- mimeTypeSupported[mimeType] = checkFormatSupport(mimeType);
20
+ function getSupportedImageFormats() {
21
+ return _getSupportedImageFormats.apply(this, arguments);
22
+ }
23
+ function _getSupportedImageFormats() {
24
+ _getSupportedImageFormats = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee() {
25
+ var supportedMimeTypes, _iterator, _step, _mimeType, supported;
26
+ return _regenerator.default.wrap(function _callee$(_context) {
27
+ while (1) {
28
+ switch (_context.prev = _context.next) {
29
+ case 0:
30
+ if (!mimeTypeSupportedPromise) {
31
+ _context.next = 4;
32
+ break;
33
+ }
34
+ _context.next = 3;
35
+ return mimeTypeSupportedPromise;
36
+ case 3:
37
+ return _context.abrupt("return", _context.sent);
38
+ case 4:
39
+ supportedMimeTypes = new Set();
40
+ _iterator = _createForOfIteratorHelper(MIME_TYPES);
41
+ _context.prev = 6;
42
+ _iterator.s();
43
+ case 8:
44
+ if ((_step = _iterator.n()).done) {
45
+ _context.next = 21;
46
+ break;
47
+ }
48
+ _mimeType = _step.value;
49
+ if (!_loaderUtils.isBrowser) {
50
+ _context.next = 16;
51
+ break;
52
+ }
53
+ _context.next = 13;
54
+ return checkBrowserImageFormatSupportAsync(_mimeType);
55
+ case 13:
56
+ _context.t0 = _context.sent;
57
+ _context.next = 17;
58
+ break;
59
+ case 16:
60
+ _context.t0 = checkNodeImageFormatSupport(_mimeType);
61
+ case 17:
62
+ supported = _context.t0;
63
+ if (supported) {
64
+ supportedMimeTypes.add(_mimeType);
65
+ }
66
+ case 19:
67
+ _context.next = 8;
68
+ break;
69
+ case 21:
70
+ _context.next = 26;
71
+ break;
72
+ case 23:
73
+ _context.prev = 23;
74
+ _context.t1 = _context["catch"](6);
75
+ _iterator.e(_context.t1);
76
+ case 26:
77
+ _context.prev = 26;
78
+ _iterator.f();
79
+ return _context.finish(26);
80
+ case 29:
81
+ return _context.abrupt("return", supportedMimeTypes);
82
+ case 30:
83
+ case "end":
84
+ return _context.stop();
85
+ }
86
+ }
87
+ }, _callee, null, [[6, 23, 26, 29]]);
88
+ }));
89
+ return _getSupportedImageFormats.apply(this, arguments);
90
+ }
91
+ var mimeTypeSupportedSync = {};
92
+
93
+ function isImageFormatSupported(mimeType) {
94
+ if (mimeTypeSupportedSync[mimeType] === undefined) {
95
+ var supported = _loaderUtils.isBrowser ? checkBrowserImageFormatSupport(mimeType) : checkNodeImageFormatSupport(mimeType);
96
+ mimeTypeSupportedSync[mimeType] = supported;
15
97
  }
16
- return mimeTypeSupported[mimeType];
98
+ return mimeTypeSupportedSync[mimeType];
17
99
  }
18
100
 
19
- function checkFormatSupport(mimeType) {
101
+ function checkNodeImageFormatSupport(mimeType) {
102
+ var NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];
103
+ var _parseImageNode = globalThis._parseImageNode,
104
+ _globalThis$_imageFor = globalThis._imageFormatsNode,
105
+ _imageFormatsNode = _globalThis$_imageFor === void 0 ? NODE_FORMAT_SUPPORT : _globalThis$_imageFor;
106
+ return Boolean(_parseImageNode) && _imageFormatsNode.includes(mimeType);
107
+ }
108
+
109
+ function checkBrowserImageFormatSupport(mimeType) {
20
110
  switch (mimeType) {
111
+ case 'image/avif':
21
112
  case 'image/webp':
22
- return checkWebPSupport();
23
- case 'image/svg':
24
- return _loaderUtils.isBrowser;
113
+ return testBrowserImageFormatSupport(mimeType);
25
114
  default:
26
- if (!_loaderUtils.isBrowser) {
27
- var _parseImageNode = globalThis._parseImageNode;
28
- return Boolean(_parseImageNode) && NODE_FORMAT_SUPPORT.includes(mimeType);
29
- }
30
115
  return true;
31
116
  }
32
117
  }
118
+ var TEST_IMAGE = {
119
+ 'image/avif': 'data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=',
120
+ 'image/webp': 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA'
121
+ };
33
122
 
34
- function checkWebPSupport() {
35
- if (!_loaderUtils.isBrowser) {
36
- return false;
37
- }
123
+ function checkBrowserImageFormatSupportAsync(_x) {
124
+ return _checkBrowserImageFormatSupportAsync.apply(this, arguments);
125
+ }
126
+ function _checkBrowserImageFormatSupportAsync() {
127
+ _checkBrowserImageFormatSupportAsync = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(mimeType) {
128
+ var dataURL;
129
+ return _regenerator.default.wrap(function _callee2$(_context2) {
130
+ while (1) {
131
+ switch (_context2.prev = _context2.next) {
132
+ case 0:
133
+ dataURL = TEST_IMAGE[mimeType];
134
+ if (!dataURL) {
135
+ _context2.next = 7;
136
+ break;
137
+ }
138
+ _context2.next = 4;
139
+ return testBrowserImageFormatSupportAsync(dataURL);
140
+ case 4:
141
+ _context2.t0 = _context2.sent;
142
+ _context2.next = 8;
143
+ break;
144
+ case 7:
145
+ _context2.t0 = true;
146
+ case 8:
147
+ return _context2.abrupt("return", _context2.t0);
148
+ case 9:
149
+ case "end":
150
+ return _context2.stop();
151
+ }
152
+ }
153
+ }, _callee2);
154
+ }));
155
+ return _checkBrowserImageFormatSupportAsync.apply(this, arguments);
156
+ }
157
+ function testBrowserImageFormatSupport(mimeType) {
38
158
  try {
39
159
  var element = document.createElement('canvas');
40
- return element.toDataURL('image/webp').indexOf('data:image/webp') === 0;
160
+ var dataURL = element.toDataURL(mimeType);
161
+ return dataURL.indexOf("data:".concat(mimeType)) === 0;
41
162
  } catch (_unused) {
42
163
  return false;
43
164
  }
44
165
  }
166
+
167
+ function testBrowserImageFormatSupportAsync(_x2) {
168
+ return _testBrowserImageFormatSupportAsync.apply(this, arguments);
169
+ }
170
+ function _testBrowserImageFormatSupportAsync() {
171
+ _testBrowserImageFormatSupportAsync = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(testImageDataURL) {
172
+ return _regenerator.default.wrap(function _callee3$(_context3) {
173
+ while (1) {
174
+ switch (_context3.prev = _context3.next) {
175
+ case 0:
176
+ return _context3.abrupt("return", new Promise(function (resolve) {
177
+ var image = new Image();
178
+ image.src = testImageDataURL;
179
+ image.onload = function () {
180
+ return resolve(image.height > 0);
181
+ };
182
+ image.onerror = function () {
183
+ return resolve(false);
184
+ };
185
+ }));
186
+ case 1:
187
+ case "end":
188
+ return _context3.stop();
189
+ }
190
+ }
191
+ }, _callee3);
192
+ }));
193
+ return _testBrowserImageFormatSupportAsync.apply(this, arguments);
194
+ }
45
195
  //# sourceMappingURL=image-format.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"image-format.js","names":["NODE_FORMAT_SUPPORT","mimeTypeSupported","_isImageFormatSupported","mimeType","undefined","checkFormatSupport","checkWebPSupport","isBrowser","_parseImageNode","globalThis","Boolean","includes","element","document","createElement","toDataURL","indexOf"],"sources":["../../../../src/lib/category-api/image-format.ts"],"sourcesContent":["import {isBrowser} from '@loaders.gl/loader-utils';\n\n// The following formats are supported by loaders.gl polyfills\nconst NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];\n\n/** Cache values for speed */\nconst mimeTypeSupported: {[mimeType: string]: boolean} = {};\n\n/**\n * Check if image MIME type is supported. Result is cached.\n */\nexport function _isImageFormatSupported(mimeType: string): boolean {\n if (mimeTypeSupported[mimeType] === undefined) {\n mimeTypeSupported[mimeType] = checkFormatSupport(mimeType);\n }\n return mimeTypeSupported[mimeType];\n}\n\n/**\n * Check if image MIME type is supported.\n */\nfunction checkFormatSupport(mimeType: string): boolean {\n switch (mimeType) {\n case 'image/webp':\n return checkWebPSupport();\n case 'image/svg':\n return isBrowser;\n default:\n if (!isBrowser) {\n // @ts-ignore\n const {_parseImageNode} = globalThis;\n return Boolean(_parseImageNode) && NODE_FORMAT_SUPPORT.includes(mimeType);\n }\n return true;\n }\n}\n\n/** Check WebPSupport synchronously */\nfunction checkWebPSupport() {\n if (!isBrowser) {\n return false;\n }\n try {\n const element = document.createElement('canvas');\n return element.toDataURL('image/webp').indexOf('data:image/webp') === 0;\n } catch {\n // Probably Safari...\n return false;\n }\n}\n\n// Note: better test but asynchronous\n\n// Lossy test image. Support for lossy images doesn't guarantee support for all WebP images.\n// https://stackoverflow.com/questions/5573096/detecting-webp-support\n// const WEBP_TEST_IMAGE = 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA';\n\n// Check WebPSupport asynchronously\n// async function isWebPSupported() {\n// return new Promise( resolve => {\n// const image = new Image();\n// image.src = WEBP_TEST_IMAGE;\n// image.onload = image.onerror = function () {\n// resolve( image.height === 1 );\n// }\n// }\n"],"mappings":";;;;;;AAAA;AAGA,IAAMA,mBAAmB,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,WAAW,CAAC;;AAGpE,IAAMC,iBAAgD,GAAG,CAAC,CAAC;;AAKpD,SAASC,uBAAuB,CAACC,QAAgB,EAAW;EACjE,IAAIF,iBAAiB,CAACE,QAAQ,CAAC,KAAKC,SAAS,EAAE;IAC7CH,iBAAiB,CAACE,QAAQ,CAAC,GAAGE,kBAAkB,CAACF,QAAQ,CAAC;EAC5D;EACA,OAAOF,iBAAiB,CAACE,QAAQ,CAAC;AACpC;;AAKA,SAASE,kBAAkB,CAACF,QAAgB,EAAW;EACrD,QAAQA,QAAQ;IACd,KAAK,YAAY;MACf,OAAOG,gBAAgB,EAAE;IAC3B,KAAK,WAAW;MACd,OAAOC,sBAAS;IAClB;MACE,IAAI,CAACA,sBAAS,EAAE;QAEd,IAAOC,eAAe,GAAIC,UAAU,CAA7BD,eAAe;QACtB,OAAOE,OAAO,CAACF,eAAe,CAAC,IAAIR,mBAAmB,CAACW,QAAQ,CAACR,QAAQ,CAAC;MAC3E;MACA,OAAO,IAAI;EAAC;AAElB;;AAGA,SAASG,gBAAgB,GAAG;EAC1B,IAAI,CAACC,sBAAS,EAAE;IACd,OAAO,KAAK;EACd;EACA,IAAI;IACF,IAAMK,OAAO,GAAGC,QAAQ,CAACC,aAAa,CAAC,QAAQ,CAAC;IAChD,OAAOF,OAAO,CAACG,SAAS,CAAC,YAAY,CAAC,CAACC,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC;EACzE,CAAC,CAAC,gBAAM;IAEN,OAAO,KAAK;EACd;AACF"}
1
+ {"version":3,"file":"image-format.js","names":["MIME_TYPES","mimeTypeSupportedPromise","getSupportedImageFormats","supportedMimeTypes","Set","mimeType","isBrowser","checkBrowserImageFormatSupportAsync","checkNodeImageFormatSupport","supported","add","mimeTypeSupportedSync","isImageFormatSupported","undefined","checkBrowserImageFormatSupport","NODE_FORMAT_SUPPORT","_parseImageNode","globalThis","_imageFormatsNode","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":";;;;;;;;;;AAEA;AAAmD;AAAA;AAAA;AAEnD,IAAMA,UAAU,GAAG,CACjB,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,YAAY;AAEZ,WAAW,EACX,eAAe,EACf,WAAW,EACX,0BAA0B,CAC3B;;AAGD,IAAMC,wBAAqD,GAAG,IAAI;;AAAC,SAG7CC,wBAAwB;EAAA;AAAA;AAAA;EAAA,sFAAvC;IAAA;IAAA;MAAA;QAAA;UAAA;YAAA,KACDD,wBAAwB;cAAA;cAAA;YAAA;YAAA;YAAA,OACbA,wBAAwB;UAAA;YAAA;UAAA;YAGjCE,kBAAkB,GAAG,IAAIC,GAAG,EAAU;YAAA,uCACrBJ,UAAU;YAAA;YAAA;UAAA;YAAA;cAAA;cAAA;YAAA;YAAtBK,SAAQ;YAAA,KACCC,sBAAS;cAAA;cAAA;YAAA;YAAA;YAAA,OACjBC,mCAAmC,CAACF,SAAQ,CAAC;UAAA;YAAA;YAAA;YAAA;UAAA;YAAA,cACnDG,2BAA2B,CAACH,SAAQ,CAAC;UAAA;YAFnCI,SAAS;YAGf,IAAIA,SAAS,EAAE;cACbN,kBAAkB,CAACO,GA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AAA;YAC3DkB,OAAO,GAAGD,UAAU,CAACjB,QAAQ,CAAC;YAAA,KAC7BkB,OAAO;cAAA;cAAA;YAAA;YAAA;YAAA,OAASC,kCAAkC,CAACD,OAAO,CAAC;UAAA;YAAA;YAAA;YAAA;UAAA;YAAA,eAAG,IAAI;UAAA;YAAA;UAAA;UAAA;YAAA;QAAA;MAAA;IAAA;EAAA,CAC1E;EAAA;AAAA;AAOD,SAASF,6BAA6B,CAAChB,QAAgB,EAAW;EAChE,IAAI;IACF,IAAMoB,OAAO,GAAGC,QAAQ,CAACC,aAAa,CAAC,QAAQ,CAAC;IAChD,IAAMJ,OAAO,GAAGE,OAAO,CAACG,SAAS,CAACvB,QAAQ,CAAC;IAC3C,OAAOkB,OAAO,CAACM,OAAO,gBAASxB,QAAQ,EAAG,KAAK,CAAC;EAClD,CAAC,CAAC,gBAAM;IAEN,OAAO,KAAK;EACd;AACF;;AAAC,SAGcmB,kCAAkC;EAAA;AAAA;AAAA;EAAA,gGAAjD,kBAAkDM,gBAAwB;IAAA;MAAA;QAAA;UAAA;YAAA,kCACjE,IAAIC,OAAO,CAAC,UAACC,OAAO,EAAK;cAC9B,IAAMC,KAAK,GAAG,IAAIC,KAAK,EAAE;cACzBD,KAAK,CAACE,GAAG,GAAGL,gBAAgB;cAC5BG,KAAK,CAACG,MAAM,GAAG;gBAAA,OAAMJ,OAAO,CAACC,KAAK,CAACI,MAAM,GAAG,CAAC,CAAC;cAAA;cAC9CJ,KAAK,CAACK,OAAO,GAAG;gBAAA,OAAMN,OAAO,CAAC,KAAK,CAAC;cAAA;YACtC,CAAC,CAAC;UAAA;UAAA;YAAA;QAAA;MAAA;IAAA;EAAA,CACH;EAAA;AAAA"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.decodeMajorBrand = decodeMajorBrand;
8
+ exports.getISOBMFFMediaType = getISOBMFFMediaType;
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
+
11
+ function getISOBMFFMediaType(buffer) {
12
+ if (!checkString(buffer, 'ftyp', 4)) {
13
+ return null;
14
+ }
15
+
16
+ if ((buffer[8] & 0x60) === 0x00) {
17
+ return null;
18
+ }
19
+
20
+ return decodeMajorBrand(buffer);
21
+ }
22
+
23
+ function decodeMajorBrand(buffer) {
24
+ var brandMajor = getUTF8String(buffer, 8, 12).replace('\0', ' ').trim();
25
+ switch (brandMajor) {
26
+ case 'avif':
27
+ case 'avis':
28
+ return {
29
+ extension: 'avif',
30
+ mimeType: 'image/avif'
31
+ };
32
+ default:
33
+ return null;
34
+ }
35
+ }
36
+
37
+ function getUTF8String(array, start, end) {
38
+ return String.fromCharCode.apply(String, (0, _toConsumableArray2.default)(array.slice(start, end)));
39
+ }
40
+ function stringToBytes(string) {
41
+ return (0, _toConsumableArray2.default)(string).map(function (character) {
42
+ return character.charCodeAt(0);
43
+ });
44
+ }
45
+ function checkString(buffer, header) {
46
+ var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
47
+ var headerBytes = stringToBytes(header);
48
+ for (var i = 0; i < headerBytes.length; ++i) {
49
+ if (headerBytes[i] !== buffer[i + offset]) {
50
+ return false;
51
+ }
52
+ }
53
+ return true;
54
+ }
55
+ //# sourceMappingURL=parse-isobmff-binary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-isobmff-binary.js","names":["getISOBMFFMediaType","buffer","checkString","decodeMajorBrand","brandMajor","getUTF8String","replace","trim","extension","mimeType","array","start","end","String","fromCharCode","slice","stringToBytes","string","map","character","charCodeAt","header","offset","headerBytes","i","length"],"sources":["../../../../src/lib/category-api/parse-isobmff-binary.ts"],"sourcesContent":["// loaders.gl, MIT license\n// code adapted from https://github.com/sindresorhus/file-type under MIT license\n\n/**\n * Box is a container format that can contain a variety of media related files,\n * so we want to return information about which type of file is actually contained inside\n */\nexport type BoxFileType = {extension: string; mimeType: string};\n\n/**\n * Tests if a buffer is in ISO base media file format (ISOBMFF) @see https://en.wikipedia.org/wiki/ISO_base_media_file_format\n * (ISOBMFF is a media container standard based on the Apple QuickTime container format)\n */\nexport function getISOBMFFMediaType(buffer: Uint8Array): BoxFileType | null {\n // Almost all ISO base media files start with `ftyp` box. (It's not required to be first, but it's recommended to be.)\n if (!checkString(buffer, 'ftyp', 4)) {\n return null;\n }\n\n // Extra check: test for 8859-1 printable characters (for simplicity, it's a mask which also catches one non-printable character).\n if ((buffer[8] & 0x60) === 0x00) {\n return null;\n }\n\n // `ftyp` box must contain a brand major identifier, which must consist of ISO 8859-1 printable characters.\n return decodeMajorBrand(buffer);\n}\n\n/**\n * brands explained @see https://github.com/strukturag/libheif/issues/83\n * code adapted from @see https://github.com/sindresorhus/file-type/blob/main/core.js#L489-L492\n */\nexport function decodeMajorBrand(buffer: Uint8Array): BoxFileType | null {\n const brandMajor = getUTF8String(buffer, 8, 12).replace('\\0', ' ').trim();\n\n switch (brandMajor) {\n case 'avif':\n case 'avis':\n return {extension: 'avif', mimeType: 'image/avif'};\n default:\n return null;\n }\n // We don't need these now, but they are easy to add\n // case 'mif1':\n // return {extension: 'heic', mimeType: 'image/heif'};\n // case 'msf1':\n // return {extension: 'heic', mimeType: 'image/heif-sequence'};\n // case 'heic':\n // case 'heix':\n // return {extension: 'heic', mimeType: 'image/heic'};\n // case 'hevc':\n // case 'hevx':\n // return {extension: 'heic', mimeType: 'image/heic-sequence'};\n // case 'qt':\n // return {ext: 'mov', mime: 'video/quicktime'};\n // case 'M4V':\n // case 'M4VH':\n // case 'M4VP':\n // return {ext: 'm4v', mime: 'video/x-m4v'};\n // case 'M4P':\n // return {ext: 'm4p', mime: 'video/mp4'};\n // case 'M4B':\n // return {ext: 'm4b', mime: 'audio/mp4'};\n // case 'M4A':\n // return {ext: 'm4a', mime: 'audio/x-m4a'};\n // case 'F4V':\n // return {ext: 'f4v', mime: 'video/mp4'};\n // case 'F4P':\n // return {ext: 'f4p', mime: 'video/mp4'};\n // case 'F4A':\n // return {ext: 'f4a', mime: 'audio/mp4'};\n // case 'F4B':\n // return {ext: 'f4b', mime: 'audio/mp4'};\n // case 'crx':\n // return {ext: 'cr3', mime: 'image/x-canon-cr3'};\n // default:\n // if (brandMajor.startsWith('3g')) {\n // if (brandMajor.startsWith('3g2')) {\n // return {ext: '3g2', mime: 'video/3gpp2'};\n // }\n // return {ext: '3gp', mime: 'video/3gpp'};\n // }\n // return {ext: 'mp4', mime: 'video/mp4'};\n}\n\n/** Interpret a chunk of bytes as a UTF8 string */\nfunction getUTF8String(array: Uint8Array, start: number, end: number): string {\n return String.fromCharCode(...array.slice(start, end));\n}\n\nfunction stringToBytes(string: string): number[] {\n return [...string].map((character) => character.charCodeAt(0));\n}\n\nfunction checkString(buffer: ArrayLike<number>, header: string, offset: number = 0): boolean {\n const headerBytes = stringToBytes(header);\n\n for (let i = 0; i < headerBytes.length; ++i) {\n if (headerBytes[i] !== buffer[i + offset]) {\n return false;\n }\n }\n\n return true;\n}\n"],"mappings":";;;;;;;;;;AAaO,SAASA,mBAAmB,CAACC,MAAkB,EAAsB;EAE1E,IAAI,CAACC,WAAW,CAACD,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE;IACnC,OAAO,IAAI;EACb;;EAGA,IAAI,CAACA,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,MAAM,IAAI,EAAE;IAC/B,OAAO,IAAI;EACb;;EAGA,OAAOE,gBAAgB,CAACF,MAAM,CAAC;AACjC;;AAMO,SAASE,gBAAgB,CAACF,MAAkB,EAAsB;EACvE,IAAMG,UAAU,GAAGC,aAAa,CAACJ,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,CAACK,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAACC,IAAI,EAAE;EAEzE,QAAQH,UAAU;IAChB,KAAK,MAAM;IACX,KAAK,MAAM;MACT,OAAO;QAACI,SAAS,EAAE,MAAM;QAAEC,QAAQ,EAAE;MAAY,CAAC;IACpD;MACE,OAAO,IAAI;EAAC;AA2ClB;;AAGA,SAASJ,aAAa,CAACK,KAAiB,EAAEC,KAAa,EAAEC,GAAW,EAAU;EAC5E,OAAOC,MAAM,CAACC,YAAY,OAAnBD,MAAM,mCAAiBH,KAAK,CAACK,KAAK,CAACJ,KAAK,EAAEC,GAAG,CAAC,EAAC;AACxD;AAEA,SAASI,aAAa,CAACC,MAAc,EAAY;EAC/C,OAAO,iCAAIA,MAAM,EAAEC,GAAG,CAAC,UAACC,SAAS;IAAA,OAAKA,SAAS,CAACC,UAAU,CAAC,CAAC,CAAC;EAAA,EAAC;AAChE;AAEA,SAASlB,WAAW,CAACD,MAAyB,EAAEoB,MAAc,EAA+B;EAAA,IAA7BC,MAAc,uEAAG,CAAC;EAChF,IAAMC,WAAW,GAAGP,aAAa,CAACK,MAAM,CAAC;EAEzC,KAAK,IAAIG,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGD,WAAW,CAACE,MAAM,EAAE,EAAED,CAAC,EAAE;IAC3C,IAAID,WAAW,CAACC,CAAC,CAAC,KAAKvB,MAAM,CAACuB,CAAC,GAAGF,MAAM,CAAC,EAAE;MACzC,OAAO,KAAK;IACd;EACF;EAEA,OAAO,IAAI;AACb"}
@@ -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.1" !== 'undefined' ? "3.4.0-alpha.1" : 'latest';
7
+ var VERSION = typeof "3.4.0-alpha.2" !== 'undefined' ? "3.4.0-alpha.2" : 'latest';
8
8
  exports.VERSION = VERSION;
9
9
  //# sourceMappingURL=version.js.map
@@ -1,8 +1,8 @@
1
1
  import { VERSION } from './lib/utils/version';
2
2
  import parseImage from './lib/parsers/parse-image';
3
3
  import { getBinaryImageMetadata } from './lib/category-api/binary-image-api';
4
- const EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'ico', 'svg'];
5
- const MIME_TYPES = ['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/bmp', 'image/vnd.microsoft.icon', 'image/svg+xml'];
4
+ const EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'ico', 'svg', 'avif'];
5
+ const MIME_TYPES = ['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/avif', 'image/bmp', 'image/vnd.microsoft.icon', 'image/svg+xml'];
6
6
  const DEFAULT_IMAGE_LOADER_OPTIONS = {
7
7
  image: {
8
8
  type: 'auto',
@@ -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'];\nconst MIME_TYPES = [\n 'image/png',\n 'image/jpeg',\n 'image/gif',\n 'image/webp',\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,CAAC;AAC7E,MAAMC,UAAU,GAAG,CACjB,WAAW,EACX,YAAY,EACZ,WAAW,EACX,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"}
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/index.js CHANGED
@@ -8,7 +8,8 @@ export { getBinaryImageMetadata } from './lib/category-api/binary-image-api';
8
8
  export { isImageTypeSupported, getDefaultImageType } from './lib/category-api/image-type';
9
9
  export { isImage, getImageType, getImageSize, getImageData } from './lib/category-api/parsed-image-api';
10
10
 
11
- export { _isImageFormatSupported } from './lib/category-api/image-format';
11
+ export { getSupportedImageFormats } from './lib/category-api/image-format';
12
+ export { isImageFormatSupported } from './lib/category-api/image-format';
12
13
 
13
14
  export { loadImage } from './lib/texture-api/load-image';
14
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["ImageLoader","ImageWriter","getBinaryImageMetadata","isImageTypeSupported","getDefaultImageType","isImage","getImageType","getImageSize","getImageData","_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 {_isImageFormatSupported} from './lib/category-api/image-format';\n\n// DEPRECATED - Remove in V3 (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,uBAAuB,QAAO,iCAAiC;;AAGvE,SAAQC,SAAS,QAAO,8BAA8B"}
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,11 +1,26 @@
1
1
 
2
2
 
3
+ import { getISOBMFFMediaType } from './parse-isobmff-binary';
4
+
3
5
  const BIG_ENDIAN = false;
4
6
  const LITTLE_ENDIAN = true;
5
7
 
6
8
  export function getBinaryImageMetadata(binaryData) {
7
9
  const dataView = toDataView(binaryData);
8
- return getPngMetadata(dataView) || getJpegMetadata(dataView) || getGifMetadata(dataView) || getBmpMetadata(dataView);
10
+ return getPngMetadata(dataView) || getJpegMetadata(dataView) || getGifMetadata(dataView) || getBmpMetadata(dataView) || getISOBMFFMetadata(dataView);
11
+ }
12
+
13
+ function getISOBMFFMetadata(binaryData) {
14
+ const buffer = new Uint8Array(binaryData instanceof DataView ? binaryData.buffer : binaryData);
15
+ const mediaType = getISOBMFFMediaType(buffer);
16
+ if (!mediaType) {
17
+ return null;
18
+ }
19
+ return {
20
+ mimeType: mediaType.mimeType,
21
+ width: 0,
22
+ height: 0
23
+ };
9
24
  }
10
25
 
11
26
  function getPngMetadata(binaryData) {
@@ -1 +1 @@
1
- {"version":3,"file":"binary-image-api.js","names":["BIG_ENDIAN","LITTLE_ENDIAN","getBinaryImageMetadata","binaryData","dataView","toDataView","getPngMetadata","getJpegMetadata","getGifMetadata","getBmpMetadata","isPng","byteLength","getUint32","mimeType","width","height","isGif","getUint16","isBmp","isJpeg","getUint8","tableMarkers","sofMarkers","getJpegMarkers","i","marker","has","Set","add","data","DataView","ArrayBuffer","isView","buffer","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\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 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 );\n}\n\n// PNG\n\nfunction getPngMetadata(binaryData) {\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) {\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) {\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) {\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":";;AAeA,MAAMA,UAAU,GAAG,KAAK;AACxB,MAAMC,aAAa,GAAG,IAAI;;AAQ1B,OAAO,SAASC,sBAAsB,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;AAE5B;;AAIA,SAASE,cAAc,CAACH,UAAU,EAAE;EAClC,MAAMC,QAAQ,GAAGC,UAAU,CAACF,UAAU,CAAC;EAEvC,MAAMO,KAAK,GA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SAASuB,cAAc,GAAG;EAGxB,MAAMF,YAAY,GAAG,IAAIM,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;EACtE,KAAK,IAAIH,CAAC,GAAG,MAAM,EAAEA,CAAC,GAAG,MAAM,EAAE,EAAEA,CAAC,EAAE;IACpCH,YAAY,CAACO,GAAG,CAACJ,CAAC,CAAC;EACrB;;EAIA,MAAMF,UAAU,GAAG,IAAIK,GAAG,CAAC,CACzB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAC9F,MAAM,EAAE,MAAM,CACf,CAAC;EAEF,OAAO;IAACN,YAAY;IAAEC;EAAU,CAAC;AACnC;;AAGA,SAASjB,UAAU,CAACwB,IAAI,EAAE;EACxB,IAAIA,IAAI,YAAYC,QAAQ,EAAE;IAC5B,OAAOD,IAAI;EACb;EACA,IAAIE,WAAW,CAACC,MAAM,CAACH,IAAI,CAAC,EAAE;IAC5B,OAAO,IAAIC,QAAQ,CAACD,IAAI,CAACI,MAAM,CAAC;EAClC;;EAQA,IAAIJ,IAAI,YAAYE,WAAW,EAAE;IAC/B,OAAO,IAAID,QAAQ,CAACD,IAAI,CAAC;EAC3B;EACA,MAAM,IAAIK,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,sBAAsB,CACpCC,UAAkC,EACN;EAC5B,MAAMC,QAAQ,GAAGC,UAAU,CAACF,UAAU,CAAC;EACvC,OACEG,cAAc,CAACF,QAAQ,CAA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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,42 +1,79 @@
1
+
2
+
1
3
  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'];
2
6
 
3
- const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];
7
+ const mimeTypeSupportedPromise = null;
4
8
 
5
- const mimeTypeSupported = {};
9
+ export async function getSupportedImageFormats() {
10
+ if (mimeTypeSupportedPromise) {
11
+ return await mimeTypeSupportedPromise;
12
+ }
13
+ const supportedMimeTypes = new Set();
14
+ for (const mimeType of MIME_TYPES) {
15
+ const supported = isBrowser ? await checkBrowserImageFormatSupportAsync(mimeType) : checkNodeImageFormatSupport(mimeType);
16
+ if (supported) {
17
+ supportedMimeTypes.add(mimeType);
18
+ }
19
+ }
20
+ return supportedMimeTypes;
21
+ }
22
+
23
+ const mimeTypeSupportedSync = {};
6
24
 
7
- export function _isImageFormatSupported(mimeType) {
8
- if (mimeTypeSupported[mimeType] === undefined) {
9
- mimeTypeSupported[mimeType] = checkFormatSupport(mimeType);
25
+ export function isImageFormatSupported(mimeType) {
26
+ if (mimeTypeSupportedSync[mimeType] === undefined) {
27
+ const supported = isBrowser ? checkBrowserImageFormatSupport(mimeType) : checkNodeImageFormatSupport(mimeType);
28
+ mimeTypeSupportedSync[mimeType] = supported;
10
29
  }
11
- return mimeTypeSupported[mimeType];
30
+ return mimeTypeSupportedSync[mimeType];
31
+ }
32
+
33
+ function checkNodeImageFormatSupport(mimeType) {
34
+ const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];
35
+ const {
36
+ _parseImageNode,
37
+ _imageFormatsNode = NODE_FORMAT_SUPPORT
38
+ } = globalThis;
39
+ return Boolean(_parseImageNode) && _imageFormatsNode.includes(mimeType);
12
40
  }
13
41
 
14
- function checkFormatSupport(mimeType) {
42
+ function checkBrowserImageFormatSupport(mimeType) {
15
43
  switch (mimeType) {
44
+ case 'image/avif':
16
45
  case 'image/webp':
17
- return checkWebPSupport();
18
- case 'image/svg':
19
- return isBrowser;
46
+ return testBrowserImageFormatSupport(mimeType);
20
47
  default:
21
- if (!isBrowser) {
22
- const {
23
- _parseImageNode
24
- } = globalThis;
25
- return Boolean(_parseImageNode) && NODE_FORMAT_SUPPORT.includes(mimeType);
26
- }
27
48
  return true;
28
49
  }
29
50
  }
51
+ const TEST_IMAGE = {
52
+ 'image/avif': 'data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=',
53
+ 'image/webp': 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA'
54
+ };
30
55
 
31
- function checkWebPSupport() {
32
- if (!isBrowser) {
33
- return false;
34
- }
56
+ async function checkBrowserImageFormatSupportAsync(mimeType) {
57
+ const dataURL = TEST_IMAGE[mimeType];
58
+ return dataURL ? await testBrowserImageFormatSupportAsync(dataURL) : true;
59
+ }
60
+
61
+ function testBrowserImageFormatSupport(mimeType) {
35
62
  try {
36
63
  const element = document.createElement('canvas');
37
- return element.toDataURL('image/webp').indexOf('data:image/webp') === 0;
64
+ const dataURL = element.toDataURL(mimeType);
65
+ return dataURL.indexOf("data:".concat(mimeType)) === 0;
38
66
  } catch {
39
67
  return false;
40
68
  }
41
69
  }
70
+
71
+ async function testBrowserImageFormatSupportAsync(testImageDataURL) {
72
+ return new Promise(resolve => {
73
+ const image = new Image();
74
+ image.src = testImageDataURL;
75
+ image.onload = () => resolve(image.height > 0);
76
+ image.onerror = () => resolve(false);
77
+ });
78
+ }
42
79
  //# sourceMappingURL=image-format.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"image-format.js","names":["isBrowser","NODE_FORMAT_SUPPORT","mimeTypeSupported","_isImageFormatSupported","mimeType","undefined","checkFormatSupport","checkWebPSupport","_parseImageNode","globalThis","Boolean","includes","element","document","createElement","toDataURL","indexOf"],"sources":["../../../../src/lib/category-api/image-format.ts"],"sourcesContent":["import {isBrowser} from '@loaders.gl/loader-utils';\n\n// The following formats are supported by loaders.gl polyfills\nconst NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];\n\n/** Cache values for speed */\nconst mimeTypeSupported: {[mimeType: string]: boolean} = {};\n\n/**\n * Check if image MIME type is supported. Result is cached.\n */\nexport function _isImageFormatSupported(mimeType: string): boolean {\n if (mimeTypeSupported[mimeType] === undefined) {\n mimeTypeSupported[mimeType] = checkFormatSupport(mimeType);\n }\n return mimeTypeSupported[mimeType];\n}\n\n/**\n * Check if image MIME type is supported.\n */\nfunction checkFormatSupport(mimeType: string): boolean {\n switch (mimeType) {\n case 'image/webp':\n return checkWebPSupport();\n case 'image/svg':\n return isBrowser;\n default:\n if (!isBrowser) {\n // @ts-ignore\n const {_parseImageNode} = globalThis;\n return Boolean(_parseImageNode) && NODE_FORMAT_SUPPORT.includes(mimeType);\n }\n return true;\n }\n}\n\n/** Check WebPSupport synchronously */\nfunction checkWebPSupport() {\n if (!isBrowser) {\n return false;\n }\n try {\n const element = document.createElement('canvas');\n return element.toDataURL('image/webp').indexOf('data:image/webp') === 0;\n } catch {\n // Probably Safari...\n return false;\n }\n}\n\n// Note: better test but asynchronous\n\n// Lossy test image. Support for lossy images doesn't guarantee support for all WebP images.\n// https://stackoverflow.com/questions/5573096/detecting-webp-support\n// const WEBP_TEST_IMAGE = 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA';\n\n// Check WebPSupport asynchronously\n// async function isWebPSupported() {\n// return new Promise( resolve => {\n// const image = new Image();\n// image.src = WEBP_TEST_IMAGE;\n// image.onload = image.onerror = function () {\n// resolve( image.height === 1 );\n// }\n// }\n"],"mappings":"AAAA,SAAQA,SAAS,QAAO,0BAA0B;;AAGlD,MAAMC,mBAAmB,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,WAAW,CAAC;;AAGpE,MAAMC,iBAAgD,GAAG,CAAC,CAAC;;AAK3D,OAAO,SAASC,uBAAuB,CAACC,QAAgB,EAAW;EACjE,IAAIF,iBAAiB,CAACE,QAAQ,CAAC,KAAKC,SAAS,EAAE;IAC7CH,iBAAiB,CAACE,QAAQ,CAAC,GAAGE,kBAAkB,CAACF,QAAQ,CAAC;EAC5D;EACA,OAAOF,iBAAiB,CAACE,QAAQ,CAAC;AACpC;;AAKA,SAASE,kBAAkB,CAACF,QAAgB,EAAW;EACrD,QAAQA,QAAQ;IACd,KAAK,YAAY;MACf,OAAOG,gBAAgB,EAAE;IAC3B,KAAK,WAAW;MACd,OAAOP,SAAS;IAClB;MACE,IAAI,CAACA,SAAS,EAAE;QAEd,MAAM;UAACQ;QAAe,CAAC,GAAGC,UAAU;QACpC,OAAOC,OAAO,CAACF,eAAe,CAAC,IAAIP,mBAAmB,CAACU,QAAQ,CAACP,QAAQ,CAAC;MAC3E;MACA,OAAO,IAAI;EAAC;AAElB;;AAGA,SAASG,gBAAgB,GAAG;EAC1B,IAAI,CAACP,SAAS,EAAE;IACd,OAAO,KAAK;EACd;EACA,IAAI;IACF,MAAMY,OAAO,GAAGC,QAAQ,CAACC,aAAa,CAAC,QAAQ,CAAC;IAChD,OAAOF,OAAO,CAACG,SAAS,CAAC,YAAY,CAAC,CAACC,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC;EACzE,CAAC,CAAC,MAAM;IAEN,OAAO,KAAK;EACd;AACF"}
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":";;AAEA,SAAQA,SAAS,QAAO,0BAA0B;AAElD,MAAMC,UAAU,GAAG,CACjB,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,YAAY;AAEZ,WAAW,EACX,eAAe,EACf,WAAW,EACX,0BAA0B,CAC3B;;AAGD,MAAMC,wBAAqD,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