@loaders.gl/images 3.1.3 → 4.0.0-alpha.5
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/bundle.js +2 -2
- package/dist/bundle.js.map +1 -0
- package/dist/image-loader.js +20 -39
- package/dist/image-loader.js.map +1 -0
- package/dist/image-writer.js +16 -19
- package/dist/image-writer.js.map +1 -0
- package/dist/index.js +8 -27
- package/dist/index.js.map +1 -0
- package/dist/lib/category-api/binary-image-api.js +102 -125
- package/dist/lib/category-api/binary-image-api.js.map +1 -0
- package/dist/lib/category-api/image-format.js +37 -56
- package/dist/lib/category-api/image-format.js.map +1 -0
- package/dist/lib/category-api/image-type.js +38 -44
- package/dist/lib/category-api/image-type.js.map +1 -0
- package/dist/lib/category-api/parsed-image-api.js +57 -62
- package/dist/lib/category-api/parsed-image-api.js.map +1 -0
- package/dist/lib/encoders/encode-image.js +60 -73
- package/dist/lib/encoders/encode-image.js.map +1 -0
- package/dist/lib/parsers/parse-image.js +49 -54
- package/dist/lib/parsers/parse-image.js.map +1 -0
- package/dist/lib/parsers/parse-to-image-bitmap.js +35 -53
- package/dist/lib/parsers/parse-to-image-bitmap.js.map +1 -0
- package/dist/lib/parsers/parse-to-image.js +30 -43
- package/dist/lib/parsers/parse-to-image.js.map +1 -0
- package/dist/lib/parsers/parse-to-node-image.js +10 -13
- package/dist/lib/parsers/parse-to-node-image.js.map +1 -0
- package/dist/lib/parsers/svg-utils.js +26 -36
- package/dist/lib/parsers/svg-utils.js.map +1 -0
- package/dist/lib/texture-api/async-deep-map.js +32 -49
- package/dist/lib/texture-api/async-deep-map.js.map +1 -0
- package/dist/lib/texture-api/deep-load.js +8 -13
- package/dist/lib/texture-api/deep-load.js.map +1 -0
- package/dist/lib/texture-api/generate-url.js +21 -19
- package/dist/lib/texture-api/generate-url.js.map +1 -0
- package/dist/lib/texture-api/load-image.js +47 -42
- package/dist/lib/texture-api/load-image.js.map +1 -0
- package/dist/lib/utils/version.js +2 -7
- package/dist/lib/utils/version.js.map +1 -0
- package/dist/types.js +2 -2
- package/dist/{es5/types.js.map → types.js.map} +0 -0
- package/package.json +5 -5
- package/dist/es5/bundle.js +0 -7
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/image-loader.js +0 -40
- package/dist/es5/image-loader.js.map +0 -1
- package/dist/es5/image-writer.js +0 -27
- package/dist/es5/image-writer.js.map +0 -1
- package/dist/es5/index.js +0 -86
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/category-api/binary-image-api.js +0 -126
- package/dist/es5/lib/category-api/binary-image-api.js.map +0 -1
- package/dist/es5/lib/category-api/image-format.js +0 -51
- package/dist/es5/lib/category-api/image-format.js.map +0 -1
- package/dist/es5/lib/category-api/image-type.js +0 -51
- package/dist/es5/lib/category-api/image-type.js.map +0 -1
- package/dist/es5/lib/category-api/parsed-image-api.js +0 -83
- package/dist/es5/lib/category-api/parsed-image-api.js.map +0 -1
- package/dist/es5/lib/encoders/encode-image.js +0 -131
- package/dist/es5/lib/encoders/encode-image.js.map +0 -1
- package/dist/es5/lib/parsers/parse-image.js +0 -102
- package/dist/es5/lib/parsers/parse-image.js.map +0 -1
- package/dist/es5/lib/parsers/parse-to-image-bitmap.js +0 -127
- package/dist/es5/lib/parsers/parse-to-image-bitmap.js.map +0 -1
- package/dist/es5/lib/parsers/parse-to-image.js +0 -110
- package/dist/es5/lib/parsers/parse-to-image.js.map +0 -1
- package/dist/es5/lib/parsers/parse-to-node-image.js +0 -48
- package/dist/es5/lib/parsers/parse-to-node-image.js.map +0 -1
- package/dist/es5/lib/parsers/svg-utils.js +0 -43
- package/dist/es5/lib/parsers/svg-utils.js.map +0 -1
- package/dist/es5/lib/texture-api/async-deep-map.js +0 -177
- package/dist/es5/lib/texture-api/async-deep-map.js.map +0 -1
- package/dist/es5/lib/texture-api/deep-load.js +0 -81
- package/dist/es5/lib/texture-api/deep-load.js.map +0 -1
- package/dist/es5/lib/texture-api/generate-url.js +0 -34
- package/dist/es5/lib/texture-api/generate-url.js.map +0 -1
- package/dist/es5/lib/texture-api/load-image.js +0 -173
- package/dist/es5/lib/texture-api/load-image.js.map +0 -1
- package/dist/es5/lib/utils/version.js +0 -9
- package/dist/es5/lib/utils/version.js.map +0 -1
- package/dist/es5/types.js +0 -2
- package/dist/esm/bundle.js +0 -5
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/image-loader.js +0 -24
- package/dist/esm/image-loader.js.map +0 -1
- package/dist/esm/image-writer.js +0 -17
- package/dist/esm/image-writer.js.map +0 -1
- package/dist/esm/index.js +0 -8
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/category-api/binary-image-api.js +0 -118
- package/dist/esm/lib/category-api/binary-image-api.js.map +0 -1
- package/dist/esm/lib/category-api/image-format.js +0 -44
- package/dist/esm/lib/category-api/image-format.js.map +0 -1
- package/dist/esm/lib/category-api/image-type.js +0 -42
- package/dist/esm/lib/category-api/image-type.js.map +0 -1
- package/dist/esm/lib/category-api/parsed-image-api.js +0 -64
- package/dist/esm/lib/category-api/parsed-image-api.js.map +0 -1
- package/dist/esm/lib/encoders/encode-image.js +0 -69
- package/dist/esm/lib/encoders/encode-image.js.map +0 -1
- package/dist/esm/lib/parsers/parse-image.js +0 -52
- package/dist/esm/lib/parsers/parse-image.js.map +0 -1
- package/dist/esm/lib/parsers/parse-to-image-bitmap.js +0 -43
- package/dist/esm/lib/parsers/parse-to-image-bitmap.js.map +0 -1
- package/dist/esm/lib/parsers/parse-to-image.js +0 -34
- package/dist/esm/lib/parsers/parse-to-image.js.map +0 -1
- package/dist/esm/lib/parsers/parse-to-node-image.js +0 -11
- package/dist/esm/lib/parsers/parse-to-node-image.js.map +0 -1
- package/dist/esm/lib/parsers/svg-utils.js +0 -32
- package/dist/esm/lib/parsers/svg-utils.js.map +0 -1
- package/dist/esm/lib/texture-api/async-deep-map.js +0 -39
- package/dist/esm/lib/texture-api/async-deep-map.js.map +0 -1
- package/dist/esm/lib/texture-api/deep-load.js +0 -10
- package/dist/esm/lib/texture-api/deep-load.js.map +0 -1
- package/dist/esm/lib/texture-api/generate-url.js +0 -22
- package/dist/esm/lib/texture-api/generate-url.js.map +0 -1
- package/dist/esm/lib/texture-api/load-image.js +0 -52
- package/dist/esm/lib/texture-api/load-image.js.map +0 -1
- package/dist/esm/lib/utils/version.js +0 -2
- package/dist/esm/lib/utils/version.js.map +0 -1
- package/dist/esm/types.js +0 -2
- package/dist/esm/types.js.map +0 -1
package/dist/bundle.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":"AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,OAAX,GAAqBD,UAAU,CAACC,OAAX,IAAsB,EAA3C;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,OAAzB,EAAkCH,aAAlC,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"file":"bundle.js"}
|
package/dist/image-loader.js
CHANGED
|
@@ -1,43 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports._typecheckImageLoader = exports.ImageLoader = void 0;
|
|
7
|
-
const version_1 = require("./lib/utils/version");
|
|
8
|
-
const parse_image_1 = __importDefault(require("./lib/parsers/parse-image"));
|
|
9
|
-
const binary_image_api_1 = require("./lib/category-api/binary-image-api");
|
|
1
|
+
import { VERSION } from './lib/utils/version';
|
|
2
|
+
import parseImage from './lib/parsers/parse-image';
|
|
3
|
+
import { getBinaryImageMetadata } from './lib/category-api/binary-image-api';
|
|
10
4
|
const EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'ico', 'svg'];
|
|
11
|
-
const MIME_TYPES = [
|
|
12
|
-
'image/png',
|
|
13
|
-
'image/jpeg',
|
|
14
|
-
'image/gif',
|
|
15
|
-
'image/webp',
|
|
16
|
-
'image/bmp',
|
|
17
|
-
'image/vnd.microsoft.icon',
|
|
18
|
-
'image/svg+xml'
|
|
19
|
-
];
|
|
5
|
+
const MIME_TYPES = ['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/bmp', 'image/vnd.microsoft.icon', 'image/svg+xml'];
|
|
20
6
|
const DEFAULT_IMAGE_LOADER_OPTIONS = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// imagebitmap: {} - passes (platform dependent) parameters to ImageBitmap constructor
|
|
7
|
+
image: {
|
|
8
|
+
type: 'auto',
|
|
9
|
+
decode: true
|
|
10
|
+
}
|
|
26
11
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
extensions: EXTENSIONS,
|
|
38
|
-
parse: parse_image_1.default,
|
|
39
|
-
// TODO: byteOffset, byteLength;
|
|
40
|
-
tests: [(arrayBuffer) => Boolean((0, binary_image_api_1.getBinaryImageMetadata)(new DataView(arrayBuffer)))],
|
|
41
|
-
options: DEFAULT_IMAGE_LOADER_OPTIONS
|
|
12
|
+
export const ImageLoader = {
|
|
13
|
+
id: 'image',
|
|
14
|
+
module: 'images',
|
|
15
|
+
name: 'Images',
|
|
16
|
+
version: VERSION,
|
|
17
|
+
mimeTypes: MIME_TYPES,
|
|
18
|
+
extensions: EXTENSIONS,
|
|
19
|
+
parse: parseImage,
|
|
20
|
+
tests: [arrayBuffer => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer)))],
|
|
21
|
+
options: DEFAULT_IMAGE_LOADER_OPTIONS
|
|
42
22
|
};
|
|
43
|
-
|
|
23
|
+
export const _typecheckImageLoader = ImageLoader;
|
|
24
|
+
//# sourceMappingURL=image-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/image-loader.ts"],"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"],"mappings":"AACA,SAAQA,OAAR,QAAsB,qBAAtB;AACA,OAAOC,UAAP,MAAuB,2BAAvB;AACA,SAAQC,sBAAR,QAAqC,qCAArC;AAEA,MAAMC,UAAU,GAAG,CAAC,KAAD,EAAQ,KAAR,EAAe,MAAf,EAAuB,KAAvB,EAA8B,MAA9B,EAAsC,KAAtC,EAA6C,KAA7C,EAAoD,KAApD,CAAnB;AACA,MAAMC,UAAU,GAAG,CACjB,WADiB,EAEjB,YAFiB,EAGjB,WAHiB,EAIjB,YAJiB,EAKjB,WALiB,EAMjB,0BANiB,EAOjB,eAPiB,CAAnB;AAkBA,MAAMC,4BAAgD,GAAG;AACvDC,EAAAA,KAAK,EAAE;AACLC,IAAAA,IAAI,EAAE,MADD;AAELC,IAAAA,MAAM,EAAE;AAFH;AADgD,CAAzD;AAYA,OAAO,MAAMC,WAAW,GAAG;AACzBC,EAAAA,EAAE,EAAE,OADqB;AAEzBC,EAAAA,MAAM,EAAE,QAFiB;AAGzBC,EAAAA,IAAI,EAAE,QAHmB;AAIzBC,EAAAA,OAAO,EAAEb,OAJgB;AAKzBc,EAAAA,SAAS,EAAEV,UALc;AAMzBW,EAAAA,UAAU,EAAEZ,UANa;AAOzBa,EAAAA,KAAK,EAAEf,UAPkB;AASzBgB,EAAAA,KAAK,EAAE,CAAEC,WAAD,IAAiBC,OAAO,CAACjB,sBAAsB,CAAC,IAAIkB,QAAJ,CAAaF,WAAb,CAAD,CAAvB,CAAzB,CATkB;AAUzBG,EAAAA,OAAO,EAAEhB;AAVgB,CAApB;AAaP,OAAO,MAAMiB,qBAAuC,GAAGb,WAAhD","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"],"file":"image-loader.js"}
|
package/dist/image-writer.js
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
jpegQuality: null
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
encode: encode_image_1.encodeImage
|
|
1
|
+
import { VERSION } from './lib/utils/version';
|
|
2
|
+
import { encodeImage } from './lib/encoders/encode-image';
|
|
3
|
+
export const ImageWriter = {
|
|
4
|
+
name: 'Images',
|
|
5
|
+
id: 'image',
|
|
6
|
+
module: 'images',
|
|
7
|
+
version: VERSION,
|
|
8
|
+
extensions: ['jpeg'],
|
|
9
|
+
options: {
|
|
10
|
+
image: {
|
|
11
|
+
mimeType: 'image/png',
|
|
12
|
+
jpegQuality: null
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
encode: encodeImage
|
|
20
16
|
};
|
|
17
|
+
//# sourceMappingURL=image-writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/image-writer.ts"],"names":["VERSION","encodeImage","ImageWriter","name","id","module","version","extensions","options","image","mimeType","jpegQuality","encode"],"mappings":"AACA,SAAQA,OAAR,QAAsB,qBAAtB;AACA,SAAQC,WAAR,QAA0B,6BAA1B;AAEA,OAAO,MAAMC,WAAW,GAAG;AACzBC,EAAAA,IAAI,EAAE,QADmB;AAEzBC,EAAAA,EAAE,EAAE,OAFqB;AAGzBC,EAAAA,MAAM,EAAE,QAHiB;AAIzBC,EAAAA,OAAO,EAAEN,OAJgB;AAKzBO,EAAAA,UAAU,EAAE,CAAC,MAAD,CALa;AAMzBC,EAAAA,OAAO,EAAE;AACPC,IAAAA,KAAK,EAAE;AACLC,MAAAA,QAAQ,EAAE,WADL;AAELC,MAAAA,WAAW,EAAE;AAFR;AADA,GANgB;AAYzBC,EAAAA,MAAM,EAAEX;AAZiB,CAApB","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"],"file":"image-writer.js"}
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// IMAGE CATEGORY API
|
|
10
|
-
// Binary Image API
|
|
11
|
-
var binary_image_api_1 = require("./lib/category-api/binary-image-api");
|
|
12
|
-
Object.defineProperty(exports, "getBinaryImageMetadata", { enumerable: true, get: function () { return binary_image_api_1.getBinaryImageMetadata; } });
|
|
13
|
-
// Parsed Image API
|
|
14
|
-
var image_type_1 = require("./lib/category-api/image-type");
|
|
15
|
-
Object.defineProperty(exports, "isImageTypeSupported", { enumerable: true, get: function () { return image_type_1.isImageTypeSupported; } });
|
|
16
|
-
Object.defineProperty(exports, "getDefaultImageType", { enumerable: true, get: function () { return image_type_1.getDefaultImageType; } });
|
|
17
|
-
var parsed_image_api_1 = require("./lib/category-api/parsed-image-api");
|
|
18
|
-
Object.defineProperty(exports, "isImage", { enumerable: true, get: function () { return parsed_image_api_1.isImage; } });
|
|
19
|
-
Object.defineProperty(exports, "getImageType", { enumerable: true, get: function () { return parsed_image_api_1.getImageType; } });
|
|
20
|
-
Object.defineProperty(exports, "getImageSize", { enumerable: true, get: function () { return parsed_image_api_1.getImageSize; } });
|
|
21
|
-
Object.defineProperty(exports, "getImageData", { enumerable: true, get: function () { return parsed_image_api_1.getImageData; } });
|
|
22
|
-
// EXPERIMENTAL
|
|
23
|
-
var image_format_1 = require("./lib/category-api/image-format");
|
|
24
|
-
Object.defineProperty(exports, "_isImageFormatSupported", { enumerable: true, get: function () { return image_format_1._isImageFormatSupported; } });
|
|
25
|
-
// DEPRECATED - Remove in V3 (fix dependency in luma.gl)
|
|
26
|
-
var load_image_1 = require("./lib/texture-api/load-image");
|
|
27
|
-
Object.defineProperty(exports, "loadImage", { enumerable: true, get: function () { return load_image_1.loadImage; } });
|
|
1
|
+
export { ImageLoader } from './image-loader';
|
|
2
|
+
export { ImageWriter } from './image-writer';
|
|
3
|
+
export { getBinaryImageMetadata } from './lib/category-api/binary-image-api';
|
|
4
|
+
export { isImageTypeSupported, getDefaultImageType } from './lib/category-api/image-type';
|
|
5
|
+
export { isImage, getImageType, getImageSize, getImageData } from './lib/category-api/parsed-image-api';
|
|
6
|
+
export { _isImageFormatSupported } from './lib/category-api/image-format';
|
|
7
|
+
export { loadImage } from './lib/texture-api/load-image';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["ImageLoader","ImageWriter","getBinaryImageMetadata","isImageTypeSupported","getDefaultImageType","isImage","getImageType","getImageSize","getImageData","_isImageFormatSupported","loadImage"],"mappings":"AAKA,SAAQA,WAAR,QAA0B,gBAA1B;AACA,SAAQC,WAAR,QAA0B,gBAA1B;AAKA,SAAQC,sBAAR,QAAqC,qCAArC;AAGA,SAAQC,oBAAR,EAA8BC,mBAA9B,QAAwD,+BAAxD;AAEA,SACEC,OADF,EAEEC,YAFF,EAGEC,YAHF,EAIEC,YAJF,QAKO,qCALP;AAQA,SAAQC,uBAAR,QAAsC,iCAAtC;AAGA,SAAQC,SAAR,QAAwB,8BAAxB","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"],"file":"index.js"}
|
|
@@ -1,141 +1,118 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Attributions
|
|
3
|
-
// * Based on binary-gltf-utils under MIT license: Copyright (c) 2016-17 Karl Cheng
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.getBmpMetadata = exports.getBinaryImageMetadata = void 0;
|
|
6
1
|
const BIG_ENDIAN = false;
|
|
7
2
|
const LITTLE_ENDIAN = true;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* @param binaryData image file memory to parse
|
|
12
|
-
* @returns metadata or null if memory is not a valid image file format layout.
|
|
13
|
-
*/
|
|
14
|
-
function getBinaryImageMetadata(binaryData) {
|
|
15
|
-
const dataView = toDataView(binaryData);
|
|
16
|
-
return (getPngMetadata(dataView) ||
|
|
17
|
-
getJpegMetadata(dataView) ||
|
|
18
|
-
getGifMetadata(dataView) ||
|
|
19
|
-
getBmpMetadata(dataView));
|
|
3
|
+
export function getBinaryImageMetadata(binaryData) {
|
|
4
|
+
const dataView = toDataView(binaryData);
|
|
5
|
+
return getPngMetadata(dataView) || getJpegMetadata(dataView) || getGifMetadata(dataView) || getBmpMetadata(dataView);
|
|
20
6
|
}
|
|
21
|
-
|
|
22
|
-
// PNG
|
|
7
|
+
|
|
23
8
|
function getPngMetadata(binaryData) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
9
|
+
const dataView = toDataView(binaryData);
|
|
10
|
+
const isPng = dataView.byteLength >= 24 && dataView.getUint32(0, BIG_ENDIAN) === 0x89504e47;
|
|
11
|
+
|
|
12
|
+
if (!isPng) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
mimeType: 'image/png',
|
|
18
|
+
width: dataView.getUint32(16, BIG_ENDIAN),
|
|
19
|
+
height: dataView.getUint32(20, BIG_ENDIAN)
|
|
20
|
+
};
|
|
36
21
|
}
|
|
37
|
-
|
|
38
|
-
// Extract size from a binary GIF file
|
|
39
|
-
// TODO: GIF is not this simple
|
|
22
|
+
|
|
40
23
|
function getGifMetadata(binaryData) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
24
|
+
const dataView = toDataView(binaryData);
|
|
25
|
+
const isGif = dataView.byteLength >= 10 && dataView.getUint32(0, BIG_ENDIAN) === 0x47494638;
|
|
26
|
+
|
|
27
|
+
if (!isGif) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
mimeType: 'image/gif',
|
|
33
|
+
width: dataView.getUint16(6, LITTLE_ENDIAN),
|
|
34
|
+
height: dataView.getUint16(8, LITTLE_ENDIAN)
|
|
35
|
+
};
|
|
53
36
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
mimeType: 'image/bmp',
|
|
69
|
-
width: dataView.getUint32(18, LITTLE_ENDIAN),
|
|
70
|
-
height: dataView.getUint32(22, LITTLE_ENDIAN)
|
|
71
|
-
};
|
|
37
|
+
|
|
38
|
+
export function getBmpMetadata(binaryData) {
|
|
39
|
+
const dataView = toDataView(binaryData);
|
|
40
|
+
const isBmp = dataView.byteLength >= 14 && dataView.getUint16(0, BIG_ENDIAN) === 0x424d && dataView.getUint32(2, LITTLE_ENDIAN) === dataView.byteLength;
|
|
41
|
+
|
|
42
|
+
if (!isBmp) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
mimeType: 'image/bmp',
|
|
48
|
+
width: dataView.getUint32(18, LITTLE_ENDIAN),
|
|
49
|
+
height: dataView.getUint32(22, LITTLE_ENDIAN)
|
|
50
|
+
};
|
|
72
51
|
}
|
|
73
|
-
|
|
74
|
-
// JPEG
|
|
75
|
-
// Extract width and height from a binary JPEG file
|
|
52
|
+
|
|
76
53
|
function getJpegMetadata(binaryData) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
54
|
+
const dataView = toDataView(binaryData);
|
|
55
|
+
const isJpeg = dataView.byteLength >= 3 && dataView.getUint16(0, BIG_ENDIAN) === 0xffd8 && dataView.getUint8(2) === 0xff;
|
|
56
|
+
|
|
57
|
+
if (!isJpeg) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const {
|
|
62
|
+
tableMarkers,
|
|
63
|
+
sofMarkers
|
|
64
|
+
} = getJpegMarkers();
|
|
65
|
+
let i = 2;
|
|
66
|
+
|
|
67
|
+
while (i + 9 < dataView.byteLength) {
|
|
68
|
+
const marker = dataView.getUint16(i, BIG_ENDIAN);
|
|
69
|
+
|
|
70
|
+
if (sofMarkers.has(marker)) {
|
|
71
|
+
return {
|
|
72
|
+
mimeType: 'image/jpeg',
|
|
73
|
+
height: dataView.getUint16(i + 5, BIG_ENDIAN),
|
|
74
|
+
width: dataView.getUint16(i + 7, BIG_ENDIAN)
|
|
75
|
+
};
|
|
85
76
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
while (i + 9 < dataView.byteLength) {
|
|
90
|
-
const marker = dataView.getUint16(i, BIG_ENDIAN);
|
|
91
|
-
// The frame that contains the width and height of the JPEG image.
|
|
92
|
-
if (sofMarkers.has(marker)) {
|
|
93
|
-
return {
|
|
94
|
-
mimeType: 'image/jpeg',
|
|
95
|
-
height: dataView.getUint16(i + 5, BIG_ENDIAN),
|
|
96
|
-
width: dataView.getUint16(i + 7, BIG_ENDIAN) // Number of pixels per line
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
// Miscellaneous tables/data preceding the frame header.
|
|
100
|
-
if (!tableMarkers.has(marker)) {
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
// Length includes size of length parameter but not the two byte header.
|
|
104
|
-
i += 2;
|
|
105
|
-
i += dataView.getUint16(i, BIG_ENDIAN);
|
|
77
|
+
|
|
78
|
+
if (!tableMarkers.has(marker)) {
|
|
79
|
+
return null;
|
|
106
80
|
}
|
|
107
|
-
|
|
81
|
+
|
|
82
|
+
i += 2;
|
|
83
|
+
i += dataView.getUint16(i, BIG_ENDIAN);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return null;
|
|
108
87
|
}
|
|
88
|
+
|
|
109
89
|
function getJpegMarkers() {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
]);
|
|
122
|
-
return { tableMarkers, sofMarkers };
|
|
90
|
+
const tableMarkers = new Set([0xffdb, 0xffc4, 0xffcc, 0xffdd, 0xfffe]);
|
|
91
|
+
|
|
92
|
+
for (let i = 0xffe0; i < 0xfff0; ++i) {
|
|
93
|
+
tableMarkers.add(i);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const sofMarkers = new Set([0xffc0, 0xffc1, 0xffc2, 0xffc3, 0xffc5, 0xffc6, 0xffc7, 0xffc9, 0xffca, 0xffcb, 0xffcd, 0xffce, 0xffcf, 0xffde]);
|
|
97
|
+
return {
|
|
98
|
+
tableMarkers,
|
|
99
|
+
sofMarkers
|
|
100
|
+
};
|
|
123
101
|
}
|
|
124
|
-
|
|
102
|
+
|
|
125
103
|
function toDataView(data) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
throw new Error('toDataView');
|
|
104
|
+
if (data instanceof DataView) {
|
|
105
|
+
return data;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (ArrayBuffer.isView(data)) {
|
|
109
|
+
return new DataView(data.buffer);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (data instanceof ArrayBuffer) {
|
|
113
|
+
return new DataView(data);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
throw new Error('toDataView');
|
|
141
117
|
}
|
|
118
|
+
//# sourceMappingURL=binary-image-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/category-api/binary-image-api.ts"],"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"],"mappings":"AAeA,MAAMA,UAAU,GAAG,KAAnB;AACA,MAAMC,aAAa,GAAG,IAAtB;AAQA,OAAO,SAASC,sBAAT,CACLC,UADK,EAEuB;AAC5B,QAAMC,QAAQ,GAAGC,UAAU,CAACF,UAAD,CAA3B;AACA,SACEG,cAAc,CAACF,QAAD,CAAd,IACAG,eAAe,CAACH,QAAD,CADf,IAEAI,cAAc,CAACJ,QAAD,CAFd,IAGAK,cAAc,CAACL,QAAD,CAJhB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M,IAAIK,KAAJ,CAAU,YAAV,CAAN;AACD","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"],"file":"binary-image-api.js"}
|
|
@@ -1,63 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._isImageFormatSupported = void 0;
|
|
4
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
-
// The following formats are supported by loaders.gl polyfills
|
|
1
|
+
import { isBrowser } from '@loaders.gl/loader-utils';
|
|
6
2
|
const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];
|
|
7
|
-
/** Cache values for speed */
|
|
8
3
|
const mimeTypeSupported = {};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
return mimeTypeSupported[mimeType];
|
|
4
|
+
export function _isImageFormatSupported(mimeType) {
|
|
5
|
+
if (mimeTypeSupported[mimeType] === undefined) {
|
|
6
|
+
mimeTypeSupported[mimeType] = checkFormatSupport(mimeType);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return mimeTypeSupported[mimeType];
|
|
17
10
|
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Check if image MIME type is supported.
|
|
21
|
-
*/
|
|
11
|
+
|
|
22
12
|
function checkFormatSupport(mimeType) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
13
|
+
switch (mimeType) {
|
|
14
|
+
case 'image/webp':
|
|
15
|
+
return checkWebPSupport();
|
|
16
|
+
|
|
17
|
+
case 'image/svg':
|
|
18
|
+
return isBrowser;
|
|
19
|
+
|
|
20
|
+
default:
|
|
21
|
+
if (!isBrowser) {
|
|
22
|
+
const {
|
|
23
|
+
_parseImageNode
|
|
24
|
+
} = globalThis;
|
|
25
|
+
return Boolean(_parseImageNode) && NODE_FORMAT_SUPPORT.includes(mimeType);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
36
30
|
}
|
|
37
|
-
|
|
31
|
+
|
|
38
32
|
function checkWebPSupport() {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
33
|
+
if (!isBrowser) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const element = document.createElement('canvas');
|
|
39
|
+
return element.toDataURL('image/webp').indexOf('data:image/webp') === 0;
|
|
40
|
+
} catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
50
43
|
}
|
|
51
|
-
|
|
52
|
-
// Lossy test image. Support for lossy images doesn't guarantee support for all WebP images.
|
|
53
|
-
// https://stackoverflow.com/questions/5573096/detecting-webp-support
|
|
54
|
-
// const WEBP_TEST_IMAGE = 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA';
|
|
55
|
-
// Check WebPSupport asynchronously
|
|
56
|
-
// async function isWebPSupported() {
|
|
57
|
-
// return new Promise( resolve => {
|
|
58
|
-
// const image = new Image();
|
|
59
|
-
// image.src = WEBP_TEST_IMAGE;
|
|
60
|
-
// image.onload = image.onerror = function () {
|
|
61
|
-
// resolve( image.height === 1 );
|
|
62
|
-
// }
|
|
63
|
-
// }
|
|
44
|
+
//# sourceMappingURL=image-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/category-api/image-format.ts"],"names":["isBrowser","NODE_FORMAT_SUPPORT","mimeTypeSupported","_isImageFormatSupported","mimeType","undefined","checkFormatSupport","checkWebPSupport","_parseImageNode","globalThis","Boolean","includes","element","document","createElement","toDataURL","indexOf"],"mappings":"AAAA,SAAQA,SAAR,QAAwB,0BAAxB;AAGA,MAAMC,mBAAmB,GAAG,CAAC,WAAD,EAAc,YAAd,EAA4B,WAA5B,CAA5B;AAGA,MAAMC,iBAAgD,GAAG,EAAzD;AAKA,OAAO,SAASC,uBAAT,CAAiCC,QAAjC,EAA4D;AACjE,MAAIF,iBAAiB,CAACE,QAAD,CAAjB,KAAgCC,SAApC,EAA+C;AAC7CH,IAAAA,iBAAiB,CAACE,QAAD,CAAjB,GAA8BE,kBAAkB,CAACF,QAAD,CAAhD;AACD;;AACD,SAAOF,iBAAiB,CAACE,QAAD,CAAxB;AACD;;AAKD,SAASE,kBAAT,CAA4BF,QAA5B,EAAuD;AACrD,UAAQA,QAAR;AACE,SAAK,YAAL;AACE,aAAOG,gBAAgB,EAAvB;;AACF,SAAK,WAAL;AACE,aAAOP,SAAP;;AACF;AACE,UAAI,CAACA,SAAL,EAAgB;AAEd,cAAM;AAACQ,UAAAA;AAAD,YAAoBC,UAA1B;AACA,eAAOC,OAAO,CAACF,eAAD,CAAP,IAA4BP,mBAAmB,CAACU,QAApB,CAA6BP,QAA7B,CAAnC;AACD;;AACD,aAAO,IAAP;AAXJ;AAaD;;AAGD,SAASG,gBAAT,GAA4B;AAC1B,MAAI,CAACP,SAAL,EAAgB;AACd,WAAO,KAAP;AACD;;AACD,MAAI;AACF,UAAMY,OAAO,GAAGC,QAAQ,CAACC,aAAT,CAAuB,QAAvB,CAAhB;AACA,WAAOF,OAAO,CAACG,SAAR,CAAkB,YAAlB,EAAgCC,OAAhC,CAAwC,iBAAxC,MAA+D,CAAtE;AACD,GAHD,CAGE,MAAM;AAEN,WAAO,KAAP;AACD;AACF","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"],"file":"image-format.js"}
|