@loaders.gl/images 4.0.0-alpha.5 → 4.0.0-alpha.7
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/dist.min.js +1 -1
- package/dist/dist.min.js.map +3 -3
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/image-loader.js +33 -0
- package/dist/es5/image-loader.js.map +1 -0
- package/dist/es5/image-writer.js +24 -0
- package/dist/es5/image-writer.js.map +1 -0
- package/dist/es5/index.js +85 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/category-api/binary-image-api.js +113 -0
- package/dist/es5/lib/category-api/binary-image-api.js.map +1 -0
- package/dist/es5/lib/category-api/image-format.js +181 -0
- package/dist/es5/lib/category-api/image-format.js.map +1 -0
- package/dist/es5/lib/category-api/image-type.js +40 -0
- package/dist/es5/lib/category-api/image-type.js.map +1 -0
- package/dist/es5/lib/category-api/parse-isobmff-binary.js +50 -0
- package/dist/es5/lib/category-api/parse-isobmff-binary.js.map +1 -0
- package/dist/es5/lib/category-api/parsed-image-api.js +65 -0
- package/dist/es5/lib/category-api/parsed-image-api.js.map +1 -0
- package/dist/es5/lib/encoders/encode-image.js +101 -0
- package/dist/es5/lib/encoders/encode-image.js.map +1 -0
- package/dist/es5/lib/parsers/parse-image.js +76 -0
- package/dist/es5/lib/parsers/parse-image.js.map +1 -0
- package/dist/es5/lib/parsers/parse-to-image-bitmap.js +97 -0
- package/dist/es5/lib/parsers/parse-to-image-bitmap.js.map +1 -0
- package/dist/es5/lib/parsers/parse-to-image.js +86 -0
- package/dist/es5/lib/parsers/parse-to-image.js.map +1 -0
- package/dist/es5/lib/parsers/parse-to-node-image.js +36 -0
- package/dist/es5/lib/parsers/parse-to-node-image.js.map +1 -0
- package/dist/es5/lib/parsers/svg-utils.js +36 -0
- package/dist/es5/lib/parsers/svg-utils.js.map +1 -0
- package/dist/es5/lib/texture-api/async-deep-map.js +156 -0
- package/dist/es5/lib/texture-api/async-deep-map.js.map +1 -0
- package/dist/es5/lib/texture-api/deep-load.js +63 -0
- package/dist/es5/lib/texture-api/deep-load.js.map +1 -0
- package/dist/es5/lib/texture-api/generate-url.js +24 -0
- package/dist/es5/lib/texture-api/generate-url.js.map +1 -0
- package/dist/es5/lib/texture-api/load-image.js +132 -0
- package/dist/es5/lib/texture-api/load-image.js.map +1 -0
- package/dist/es5/lib/utils/version.js +9 -0
- package/dist/es5/lib/utils/version.js.map +1 -0
- package/dist/es5/types.js +2 -0
- package/dist/es5/types.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/image-loader.js +23 -0
- package/dist/esm/image-loader.js.map +1 -0
- package/dist/esm/image-writer.js +17 -0
- package/dist/esm/image-writer.js.map +1 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/category-api/binary-image-api.js +107 -0
- package/dist/esm/lib/category-api/binary-image-api.js.map +1 -0
- package/dist/esm/lib/category-api/image-format.js +67 -0
- package/dist/esm/lib/category-api/image-format.js.map +1 -0
- package/dist/esm/lib/category-api/image-type.js +35 -0
- package/dist/esm/lib/category-api/image-type.js.map +1 -0
- package/dist/esm/lib/category-api/parse-isobmff-binary.js +39 -0
- package/dist/esm/lib/category-api/parse-isobmff-binary.js.map +1 -0
- package/dist/esm/lib/category-api/parsed-image-api.js +53 -0
- package/dist/esm/lib/category-api/parsed-image-api.js.map +1 -0
- package/dist/esm/lib/encoders/encode-image.js +62 -0
- package/dist/esm/lib/encoders/encode-image.js.map +1 -0
- package/dist/esm/lib/parsers/parse-image.js +44 -0
- package/dist/esm/lib/parsers/parse-image.js.map +1 -0
- package/dist/esm/lib/parsers/parse-to-image-bitmap.js +37 -0
- package/dist/esm/lib/parsers/parse-to-image-bitmap.js.map +1 -0
- package/dist/esm/lib/parsers/parse-to-image.js +30 -0
- package/dist/esm/lib/parsers/parse-to-image.js.map +1 -0
- package/dist/esm/lib/parsers/parse-to-node-image.js +11 -0
- package/dist/esm/lib/parsers/parse-to-node-image.js.map +1 -0
- package/dist/esm/lib/parsers/svg-utils.js +28 -0
- package/dist/esm/lib/parsers/svg-utils.js.map +1 -0
- package/dist/esm/lib/texture-api/async-deep-map.js +34 -0
- package/dist/esm/lib/texture-api/async-deep-map.js.map +1 -0
- package/dist/esm/lib/texture-api/deep-load.js +10 -0
- package/dist/esm/lib/texture-api/deep-load.js.map +1 -0
- package/dist/esm/lib/texture-api/generate-url.js +19 -0
- package/dist/esm/lib/texture-api/generate-url.js.map +1 -0
- package/dist/esm/lib/texture-api/load-image.js +51 -0
- package/dist/esm/lib/texture-api/load-image.js.map +1 -0
- package/dist/esm/lib/utils/version.js +2 -0
- package/dist/esm/lib/utils/version.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/image-loader.d.ts +3 -14
- package/dist/image-loader.d.ts.map +1 -1
- package/dist/image-loader.js +41 -21
- package/dist/image-writer.d.ts +8 -13
- package/dist/image-writer.d.ts.map +1 -1
- package/dist/image-writer.js +20 -16
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -8
- package/dist/lib/category-api/binary-image-api.d.ts +3 -7
- package/dist/lib/category-api/binary-image-api.d.ts.map +1 -1
- package/dist/lib/category-api/binary-image-api.js +145 -102
- package/dist/lib/category-api/image-format.d.ts +4 -2
- package/dist/lib/category-api/image-format.d.ts.map +1 -1
- package/dist/lib/category-api/image-format.js +107 -41
- package/dist/lib/category-api/image-type.js +44 -38
- package/dist/lib/category-api/parse-isobmff-binary.d.ts +19 -0
- package/dist/lib/category-api/parse-isobmff-binary.d.ts.map +1 -0
- package/dist/lib/category-api/parse-isobmff-binary.js +94 -0
- package/dist/lib/category-api/parsed-image-api.js +62 -57
- package/dist/lib/encoders/encode-image.d.ts +2 -1
- package/dist/lib/encoders/encode-image.d.ts.map +1 -1
- package/dist/lib/encoders/encode-image.js +72 -60
- package/dist/lib/parsers/parse-image.js +54 -49
- package/dist/lib/parsers/parse-to-image-bitmap.js +53 -35
- package/dist/lib/parsers/parse-to-image.js +43 -30
- package/dist/lib/parsers/parse-to-node-image.js +13 -10
- package/dist/lib/parsers/svg-utils.js +36 -26
- package/dist/lib/texture-api/async-deep-map.js +49 -32
- package/dist/lib/texture-api/deep-load.js +13 -8
- package/dist/lib/texture-api/generate-url.js +19 -21
- package/dist/lib/texture-api/load-image.js +42 -47
- package/dist/lib/utils/version.js +7 -2
- package/dist/types.d.ts +3 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -2
- package/package.json +8 -5
- package/src/image-loader.ts +5 -4
- package/src/image-writer.ts +13 -2
- package/src/index.ts +3 -2
- package/src/lib/category-api/binary-image-api.ts +25 -6
- package/src/lib/category-api/image-format.ts +92 -39
- package/src/lib/category-api/parse-isobmff-binary.ts +105 -0
- package/src/lib/encoders/encode-image.ts +2 -1
- package/src/types.ts +1 -1
- package/dist/bundle.js.map +0 -1
- package/dist/image-loader.js.map +0 -1
- package/dist/image-writer.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/category-api/binary-image-api.js.map +0 -1
- package/dist/lib/category-api/image-format.js.map +0 -1
- package/dist/lib/category-api/image-type.js.map +0 -1
- package/dist/lib/category-api/parsed-image-api.js.map +0 -1
- package/dist/lib/encoders/encode-image.js.map +0 -1
- package/dist/lib/parsers/parse-image.js.map +0 -1
- package/dist/lib/parsers/parse-to-image-bitmap.js.map +0 -1
- package/dist/lib/parsers/parse-to-image.js.map +0 -1
- package/dist/lib/parsers/parse-to-node-image.js.map +0 -1
- package/dist/lib/parsers/svg-utils.js.map +0 -1
- package/dist/lib/texture-api/async-deep-map.js.map +0 -1
- package/dist/lib/texture-api/deep-load.js.map +0 -1
- package/dist/lib/texture-api/generate-url.js.map +0 -1
- package/dist/lib/texture-api/load-image.js.map +0 -1
- package/dist/lib/utils/version.js.map +0 -1
- package/dist/types.js.map +0 -1
package/dist/image-writer.d.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
extensions: string[];
|
|
8
|
-
options: {
|
|
9
|
-
image: {
|
|
10
|
-
mimeType: string;
|
|
11
|
-
jpegQuality: null;
|
|
12
|
-
};
|
|
1
|
+
import type { Writer, WriterOptions } from '@loaders.gl/loader-utils';
|
|
2
|
+
import type { ImageDataType } from './types';
|
|
3
|
+
export type ImageWriterOptions = WriterOptions & {
|
|
4
|
+
image: {
|
|
5
|
+
mimeType: 'image/png';
|
|
6
|
+
jpegQuality: null;
|
|
13
7
|
};
|
|
14
|
-
encode: typeof encodeImage;
|
|
15
8
|
};
|
|
9
|
+
/** Writer for image data */
|
|
10
|
+
export declare const ImageWriter: Writer<ImageDataType, never, ImageWriterOptions>;
|
|
16
11
|
//# sourceMappingURL=image-writer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-writer.d.ts","sourceRoot":"","sources":["../src/image-writer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"image-writer.d.ts","sourceRoot":"","sources":["../src/image-writer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAI3C,MAAM,MAAM,kBAAkB,GAAG,aAAa,GAAG;IAC/C,KAAK,EAAE;QACL,QAAQ,EAAE,WAAW,CAAC;QACtB,WAAW,EAAE,IAAI,CAAC;KACnB,CAAC;CACH,CAAC;AAEF,4BAA4B;AAC5B,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,aAAa,EAAE,KAAK,EAAE,kBAAkB,CAaxE,CAAC"}
|
package/dist/image-writer.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// loaders.gl, MIT license
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ImageWriter = void 0;
|
|
5
|
+
const version_1 = require("./lib/utils/version");
|
|
6
|
+
const encode_image_1 = require("./lib/encoders/encode-image");
|
|
7
|
+
/** Writer for image data */
|
|
8
|
+
exports.ImageWriter = {
|
|
9
|
+
name: 'Images',
|
|
10
|
+
id: 'image',
|
|
11
|
+
module: 'images',
|
|
12
|
+
version: version_1.VERSION,
|
|
13
|
+
extensions: ['jpeg'],
|
|
14
|
+
options: {
|
|
15
|
+
image: {
|
|
16
|
+
mimeType: 'image/png',
|
|
17
|
+
jpegQuality: null
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
encode: encode_image_1.encodeImage
|
|
16
21
|
};
|
|
17
|
-
//# sourceMappingURL=image-writer.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { ImageWriter } from './image-writer';
|
|
|
5
5
|
export { getBinaryImageMetadata } from './lib/category-api/binary-image-api';
|
|
6
6
|
export { isImageTypeSupported, getDefaultImageType } from './lib/category-api/image-type';
|
|
7
7
|
export { isImage, getImageType, getImageSize, getImageData } from './lib/category-api/parsed-image-api';
|
|
8
|
-
export {
|
|
8
|
+
export { getSupportedImageFormats } from './lib/category-api/image-format';
|
|
9
|
+
export { isImageFormatSupported } from './lib/category-api/image-format';
|
|
9
10
|
export { loadImage } from './lib/texture-api/load-image';
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAC,aAAa,EAAE,SAAS,EAAE,aAAa,EAAC,MAAM,SAAS,CAAC;AACrE,YAAY,EAAC,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AAGvD,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAK3C,OAAO,EAAC,sBAAsB,EAAC,MAAM,qCAAqC,CAAC;AAG3E,OAAO,EAAC,oBAAoB,EAAE,mBAAmB,EAAC,MAAM,+BAA+B,CAAC;AAExF,OAAO,EACL,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,YAAY,EACb,MAAM,qCAAqC,CAAC;AAG7C,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAC,aAAa,EAAE,SAAS,EAAE,aAAa,EAAC,MAAM,SAAS,CAAC;AACrE,YAAY,EAAC,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AAGvD,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAK3C,OAAO,EAAC,sBAAsB,EAAC,MAAM,qCAAqC,CAAC;AAG3E,OAAO,EAAC,oBAAoB,EAAE,mBAAmB,EAAC,MAAM,+BAA+B,CAAC;AAExF,OAAO,EACL,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,YAAY,EACb,MAAM,qCAAqC,CAAC;AAG7C,OAAO,EAAC,wBAAwB,EAAC,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAC,sBAAsB,EAAC,MAAM,iCAAiC,CAAC;AAGvE,OAAO,EAAC,SAAS,EAAC,MAAM,8BAA8B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadImage = exports.isImageFormatSupported = exports.getSupportedImageFormats = exports.getImageData = exports.getImageSize = exports.getImageType = exports.isImage = exports.getDefaultImageType = exports.isImageTypeSupported = exports.getBinaryImageMetadata = exports.ImageWriter = exports.ImageLoader = void 0;
|
|
4
|
+
// LOADERS AND WRITERS
|
|
5
|
+
var image_loader_1 = require("./image-loader");
|
|
6
|
+
Object.defineProperty(exports, "ImageLoader", { enumerable: true, get: function () { return image_loader_1.ImageLoader; } });
|
|
7
|
+
var image_writer_1 = require("./image-writer");
|
|
8
|
+
Object.defineProperty(exports, "ImageWriter", { enumerable: true, get: function () { return image_writer_1.ImageWriter; } });
|
|
9
|
+
// IMAGE CATEGORY API
|
|
10
|
+
// Binary Image API
|
|
11
|
+
var binary_image_api_1 = require("./lib/category-api/binary-image-api");
|
|
12
|
+
Object.defineProperty(exports, "getBinaryImageMetadata", { enumerable: true, get: function () { return binary_image_api_1.getBinaryImageMetadata; } });
|
|
13
|
+
// Parsed Image API
|
|
14
|
+
var image_type_1 = require("./lib/category-api/image-type");
|
|
15
|
+
Object.defineProperty(exports, "isImageTypeSupported", { enumerable: true, get: function () { return image_type_1.isImageTypeSupported; } });
|
|
16
|
+
Object.defineProperty(exports, "getDefaultImageType", { enumerable: true, get: function () { return image_type_1.getDefaultImageType; } });
|
|
17
|
+
var parsed_image_api_1 = require("./lib/category-api/parsed-image-api");
|
|
18
|
+
Object.defineProperty(exports, "isImage", { enumerable: true, get: function () { return parsed_image_api_1.isImage; } });
|
|
19
|
+
Object.defineProperty(exports, "getImageType", { enumerable: true, get: function () { return parsed_image_api_1.getImageType; } });
|
|
20
|
+
Object.defineProperty(exports, "getImageSize", { enumerable: true, get: function () { return parsed_image_api_1.getImageSize; } });
|
|
21
|
+
Object.defineProperty(exports, "getImageData", { enumerable: true, get: function () { return parsed_image_api_1.getImageData; } });
|
|
22
|
+
// EXPERIMENTAL
|
|
23
|
+
var image_format_1 = require("./lib/category-api/image-format");
|
|
24
|
+
Object.defineProperty(exports, "getSupportedImageFormats", { enumerable: true, get: function () { return image_format_1.getSupportedImageFormats; } });
|
|
25
|
+
var image_format_2 = require("./lib/category-api/image-format");
|
|
26
|
+
Object.defineProperty(exports, "isImageFormatSupported", { enumerable: true, get: function () { return image_format_2.isImageFormatSupported; } });
|
|
27
|
+
// DEPRECATED - Remove in V4 (fix dependency in luma.gl)
|
|
28
|
+
var load_image_1 = require("./lib/texture-api/load-image");
|
|
29
|
+
Object.defineProperty(exports, "loadImage", { enumerable: true, get: function () { return load_image_1.loadImage; } });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** MIME type, width and height extracted from binary compressed image data */
|
|
2
|
-
export
|
|
2
|
+
export type BinaryImageMetadata = {
|
|
3
3
|
mimeType: string;
|
|
4
4
|
width: number;
|
|
5
5
|
height: number;
|
|
@@ -7,13 +7,9 @@ export declare type BinaryImageMetadata = {
|
|
|
7
7
|
/**
|
|
8
8
|
* Extracts `{mimeType, width and height}` from a memory buffer containing a known image format
|
|
9
9
|
* Currently supports `image/png`, `image/jpeg`, `image/bmp` and `image/gif`.
|
|
10
|
-
* @param binaryData image file memory to parse
|
|
10
|
+
* @param binaryData: DataView | ArrayBuffer image file memory to parse
|
|
11
11
|
* @returns metadata or null if memory is not a valid image file format layout.
|
|
12
12
|
*/
|
|
13
13
|
export declare function getBinaryImageMetadata(binaryData: DataView | ArrayBuffer): BinaryImageMetadata | null;
|
|
14
|
-
export declare function getBmpMetadata(binaryData:
|
|
15
|
-
mimeType: string;
|
|
16
|
-
width: number;
|
|
17
|
-
height: number;
|
|
18
|
-
} | null;
|
|
14
|
+
export declare function getBmpMetadata(binaryData: DataView | ArrayBuffer): BinaryImageMetadata | null;
|
|
19
15
|
//# sourceMappingURL=binary-image-api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binary-image-api.d.ts","sourceRoot":"","sources":["../../../src/lib/category-api/binary-image-api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"binary-image-api.d.ts","sourceRoot":"","sources":["../../../src/lib/category-api/binary-image-api.ts"],"names":[],"mappings":"AAUA,8EAA8E;AAC9E,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAKF;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,QAAQ,GAAG,WAAW,GACjC,mBAAmB,GAAG,IAAI,CAS5B;AA2DD,wBAAgB,cAAc,CAAC,UAAU,EAAE,QAAQ,GAAG,WAAW,GAAG,mBAAmB,GAAG,IAAI,CAmB7F"}
|
|
@@ -1,118 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Attributions
|
|
3
|
+
// * Based on binary-gltf-utils under MIT license: Copyright (c) 2016-17 Karl Cheng
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.getBmpMetadata = exports.getBinaryImageMetadata = void 0;
|
|
6
|
+
// TODO: make these functions work for Node.js buffers?
|
|
7
|
+
// Quarantine references to Buffer to prevent bundler from adding big polyfills
|
|
8
|
+
// import {bufferToArrayBuffer} from '../node/buffer-to-array-buffer.js';
|
|
9
|
+
// TODO - this should be handled in @loaders.gl/polyfills
|
|
10
|
+
const parse_isobmff_binary_1 = require("./parse-isobmff-binary");
|
|
1
11
|
const BIG_ENDIAN = false;
|
|
2
12
|
const LITTLE_ENDIAN = true;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Extracts `{mimeType, width and height}` from a memory buffer containing a known image format
|
|
15
|
+
* Currently supports `image/png`, `image/jpeg`, `image/bmp` and `image/gif`.
|
|
16
|
+
* @param binaryData: DataView | ArrayBuffer image file memory to parse
|
|
17
|
+
* @returns metadata or null if memory is not a valid image file format layout.
|
|
18
|
+
*/
|
|
19
|
+
function getBinaryImageMetadata(binaryData) {
|
|
20
|
+
const dataView = toDataView(binaryData);
|
|
21
|
+
return (getPngMetadata(dataView) ||
|
|
22
|
+
getJpegMetadata(dataView) ||
|
|
23
|
+
getGifMetadata(dataView) ||
|
|
24
|
+
getBmpMetadata(dataView) ||
|
|
25
|
+
getISOBMFFMetadata(dataView));
|
|
6
26
|
}
|
|
7
|
-
|
|
27
|
+
exports.getBinaryImageMetadata = getBinaryImageMetadata;
|
|
28
|
+
// ISOBMFF
|
|
29
|
+
function getISOBMFFMetadata(binaryData) {
|
|
30
|
+
const buffer = new Uint8Array(binaryData instanceof DataView ? binaryData.buffer : binaryData);
|
|
31
|
+
const mediaType = (0, parse_isobmff_binary_1.getISOBMFFMediaType)(buffer);
|
|
32
|
+
if (!mediaType) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
mimeType: mediaType.mimeType,
|
|
37
|
+
// TODO - decode width and height
|
|
38
|
+
width: 0,
|
|
39
|
+
height: 0
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// PNG
|
|
8
43
|
function getPngMetadata(binaryData) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
44
|
+
const dataView = toDataView(binaryData);
|
|
45
|
+
// Check file contains the first 4 bytes of the PNG signature.
|
|
46
|
+
const isPng = dataView.byteLength >= 24 && dataView.getUint32(0, BIG_ENDIAN) === 0x89504e47;
|
|
47
|
+
if (!isPng) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
// Extract size from a binary PNG file
|
|
51
|
+
return {
|
|
52
|
+
mimeType: 'image/png',
|
|
53
|
+
width: dataView.getUint32(16, BIG_ENDIAN),
|
|
54
|
+
height: dataView.getUint32(20, BIG_ENDIAN)
|
|
55
|
+
};
|
|
21
56
|
}
|
|
22
|
-
|
|
57
|
+
// GIF
|
|
58
|
+
// Extract size from a binary GIF file
|
|
59
|
+
// TODO: GIF is not this simple
|
|
23
60
|
function getGifMetadata(binaryData) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
61
|
+
const dataView = toDataView(binaryData);
|
|
62
|
+
// Check first 4 bytes of the GIF signature ("GIF8").
|
|
63
|
+
const isGif = dataView.byteLength >= 10 && dataView.getUint32(0, BIG_ENDIAN) === 0x47494638;
|
|
64
|
+
if (!isGif) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
// GIF is little endian.
|
|
68
|
+
return {
|
|
69
|
+
mimeType: 'image/gif',
|
|
70
|
+
width: dataView.getUint16(6, LITTLE_ENDIAN),
|
|
71
|
+
height: dataView.getUint16(8, LITTLE_ENDIAN)
|
|
72
|
+
};
|
|
36
73
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
74
|
+
// BMP
|
|
75
|
+
// TODO: BMP is not this simple
|
|
76
|
+
function getBmpMetadata(binaryData) {
|
|
77
|
+
const dataView = toDataView(binaryData);
|
|
78
|
+
// Check magic number is valid (first 2 characters should be "BM").
|
|
79
|
+
// The mandatory bitmap file header is 14 bytes long.
|
|
80
|
+
const isBmp = dataView.byteLength >= 14 &&
|
|
81
|
+
dataView.getUint16(0, BIG_ENDIAN) === 0x424d &&
|
|
82
|
+
dataView.getUint32(2, LITTLE_ENDIAN) === dataView.byteLength;
|
|
83
|
+
if (!isBmp) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
// BMP is little endian.
|
|
87
|
+
return {
|
|
88
|
+
mimeType: 'image/bmp',
|
|
89
|
+
width: dataView.getUint32(18, LITTLE_ENDIAN),
|
|
90
|
+
height: dataView.getUint32(22, LITTLE_ENDIAN)
|
|
91
|
+
};
|
|
51
92
|
}
|
|
52
|
-
|
|
93
|
+
exports.getBmpMetadata = getBmpMetadata;
|
|
94
|
+
// JPEG
|
|
95
|
+
// Extract width and height from a binary JPEG file
|
|
53
96
|
function getJpegMetadata(binaryData) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
};
|
|
97
|
+
const dataView = toDataView(binaryData);
|
|
98
|
+
// Check file contains the JPEG "start of image" (SOI) marker
|
|
99
|
+
// followed by another marker.
|
|
100
|
+
const isJpeg = dataView.byteLength >= 3 &&
|
|
101
|
+
dataView.getUint16(0, BIG_ENDIAN) === 0xffd8 &&
|
|
102
|
+
dataView.getUint8(2) === 0xff;
|
|
103
|
+
if (!isJpeg) {
|
|
104
|
+
return null;
|
|
76
105
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
106
|
+
const { tableMarkers, sofMarkers } = getJpegMarkers();
|
|
107
|
+
// Exclude the two byte SOI marker.
|
|
108
|
+
let i = 2;
|
|
109
|
+
while (i + 9 < dataView.byteLength) {
|
|
110
|
+
const marker = dataView.getUint16(i, BIG_ENDIAN);
|
|
111
|
+
// The frame that contains the width and height of the JPEG image.
|
|
112
|
+
if (sofMarkers.has(marker)) {
|
|
113
|
+
return {
|
|
114
|
+
mimeType: 'image/jpeg',
|
|
115
|
+
height: dataView.getUint16(i + 5, BIG_ENDIAN),
|
|
116
|
+
width: dataView.getUint16(i + 7, BIG_ENDIAN) // Number of pixels per line
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
// Miscellaneous tables/data preceding the frame header.
|
|
120
|
+
if (!tableMarkers.has(marker)) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
// Length includes size of length parameter but not the two byte header.
|
|
124
|
+
i += 2;
|
|
125
|
+
i += dataView.getUint16(i, BIG_ENDIAN);
|
|
80
126
|
}
|
|
81
|
-
|
|
82
|
-
i += 2;
|
|
83
|
-
i += dataView.getUint16(i, BIG_ENDIAN);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return null;
|
|
127
|
+
return null;
|
|
87
128
|
}
|
|
88
|
-
|
|
89
129
|
function getJpegMarkers() {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
130
|
+
// Tables/misc header markers.
|
|
131
|
+
// DQT, DHT, DAC, DRI, COM, APP_n
|
|
132
|
+
const tableMarkers = new Set([0xffdb, 0xffc4, 0xffcc, 0xffdd, 0xfffe]);
|
|
133
|
+
for (let i = 0xffe0; i < 0xfff0; ++i) {
|
|
134
|
+
tableMarkers.add(i);
|
|
135
|
+
}
|
|
136
|
+
// SOF markers and DHP marker.
|
|
137
|
+
// These markers are after tables/misc data.
|
|
138
|
+
const sofMarkers = new Set([
|
|
139
|
+
0xffc0, 0xffc1, 0xffc2, 0xffc3, 0xffc5, 0xffc6, 0xffc7, 0xffc9, 0xffca, 0xffcb, 0xffcd, 0xffce,
|
|
140
|
+
0xffcf, 0xffde
|
|
141
|
+
]);
|
|
142
|
+
return { tableMarkers, sofMarkers };
|
|
101
143
|
}
|
|
102
|
-
|
|
144
|
+
// TODO - move into image module?
|
|
103
145
|
function toDataView(data) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
146
|
+
if (data instanceof DataView) {
|
|
147
|
+
return data;
|
|
148
|
+
}
|
|
149
|
+
if (ArrayBuffer.isView(data)) {
|
|
150
|
+
return new DataView(data.buffer);
|
|
151
|
+
}
|
|
152
|
+
// TODO: make these functions work for Node.js buffers?
|
|
153
|
+
// if (bufferToArrayBuffer) {
|
|
154
|
+
// data = bufferToArrayBuffer(data);
|
|
155
|
+
// }
|
|
156
|
+
// Careful - Node Buffers will look like ArrayBuffers (keep after isBuffer)
|
|
157
|
+
if (data instanceof ArrayBuffer) {
|
|
158
|
+
return new DataView(data);
|
|
159
|
+
}
|
|
160
|
+
throw new Error('toDataView');
|
|
117
161
|
}
|
|
118
|
-
//# sourceMappingURL=binary-image-api.js.map
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/** Run-time browser detection of file formats requires async tests for most precise results */
|
|
2
|
+
export declare function getSupportedImageFormats(): Promise<Set<string>>;
|
|
1
3
|
/**
|
|
2
|
-
* Check if image MIME type is supported. Result is cached.
|
|
4
|
+
* Check if image MIME type is supported. Result is cached to avoid repeated tests.
|
|
3
5
|
*/
|
|
4
|
-
export declare function
|
|
6
|
+
export declare function isImageFormatSupported(mimeType: string): boolean;
|
|
5
7
|
//# sourceMappingURL=image-format.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-format.d.ts","sourceRoot":"","sources":["../../../src/lib/category-api/image-format.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"image-format.d.ts","sourceRoot":"","sources":["../../../src/lib/category-api/image-format.ts"],"names":[],"mappings":"AAqBA,+FAA+F;AAC/F,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAgBrE;AAKD;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAQhE"}
|
|
@@ -1,44 +1,110 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// loaders.gl, MIT license
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.isImageFormatSupported = exports.getSupportedImageFormats = void 0;
|
|
5
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
6
|
+
const MIME_TYPES = [
|
|
7
|
+
'image/png',
|
|
8
|
+
'image/jpeg',
|
|
9
|
+
'image/gif',
|
|
10
|
+
'image/webp',
|
|
11
|
+
'image/avif',
|
|
12
|
+
'image/tiff',
|
|
13
|
+
// TODO - what is the correct type for SVG
|
|
14
|
+
'image/svg',
|
|
15
|
+
'image/svg+xml',
|
|
16
|
+
'image/bmp',
|
|
17
|
+
'image/vnd.microsoft.icon'
|
|
18
|
+
];
|
|
19
|
+
/** Only one round of tests is performed */
|
|
20
|
+
const mimeTypeSupportedPromise = null;
|
|
21
|
+
/** Run-time browser detection of file formats requires async tests for most precise results */
|
|
22
|
+
async function getSupportedImageFormats() {
|
|
23
|
+
if (mimeTypeSupportedPromise) {
|
|
24
|
+
return await mimeTypeSupportedPromise;
|
|
25
|
+
}
|
|
26
|
+
const supportedMimeTypes = new Set();
|
|
27
|
+
for (const mimeType of MIME_TYPES) {
|
|
28
|
+
const supported = loader_utils_1.isBrowser
|
|
29
|
+
? await checkBrowserImageFormatSupportAsync(mimeType)
|
|
30
|
+
: checkNodeImageFormatSupport(mimeType);
|
|
31
|
+
if (supported) {
|
|
32
|
+
supportedMimeTypes.add(mimeType);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return supportedMimeTypes;
|
|
10
36
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return Boolean(_parseImageNode) && NODE_FORMAT_SUPPORT.includes(mimeType);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
37
|
+
exports.getSupportedImageFormats = getSupportedImageFormats;
|
|
38
|
+
/** Cache sync values for speed */
|
|
39
|
+
const mimeTypeSupportedSync = {};
|
|
40
|
+
/**
|
|
41
|
+
* Check if image MIME type is supported. Result is cached to avoid repeated tests.
|
|
42
|
+
*/
|
|
43
|
+
function isImageFormatSupported(mimeType) {
|
|
44
|
+
if (mimeTypeSupportedSync[mimeType] === undefined) {
|
|
45
|
+
const supported = loader_utils_1.isBrowser
|
|
46
|
+
? checkBrowserImageFormatSupport(mimeType)
|
|
47
|
+
: checkNodeImageFormatSupport(mimeType);
|
|
48
|
+
mimeTypeSupportedSync[mimeType] = supported;
|
|
49
|
+
}
|
|
50
|
+
return mimeTypeSupportedSync[mimeType];
|
|
30
51
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return
|
|
42
|
-
|
|
52
|
+
exports.isImageFormatSupported = isImageFormatSupported;
|
|
53
|
+
/**
|
|
54
|
+
* Checks that polyfills are installed and that mimeType is supported by polyfills
|
|
55
|
+
* @todo Ideally polyfills should declare what formats they support, instead of storing that data here.
|
|
56
|
+
*/
|
|
57
|
+
function checkNodeImageFormatSupport(mimeType) {
|
|
58
|
+
/** @deprecated Remove these in 4.0 and rely on polyfills to inject them */
|
|
59
|
+
const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
const { _parseImageNode, _imageFormatsNode = NODE_FORMAT_SUPPORT } = globalThis;
|
|
62
|
+
return Boolean(_parseImageNode) && _imageFormatsNode.includes(mimeType);
|
|
63
|
+
}
|
|
64
|
+
/** Checks image format support synchronously.
|
|
65
|
+
* @note Unreliable, fails on AVIF
|
|
66
|
+
*/
|
|
67
|
+
function checkBrowserImageFormatSupport(mimeType) {
|
|
68
|
+
switch (mimeType) {
|
|
69
|
+
case 'image/avif': // Will fail
|
|
70
|
+
case 'image/webp':
|
|
71
|
+
return testBrowserImageFormatSupport(mimeType);
|
|
72
|
+
default:
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const TEST_IMAGE = {
|
|
77
|
+
'image/avif': 'data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=',
|
|
78
|
+
// Lossy test image. Support for lossy images doesn't guarantee support for all WebP images.
|
|
79
|
+
'image/webp': 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA'
|
|
80
|
+
};
|
|
81
|
+
/** Checks WebP and AVIF support asynchronously */
|
|
82
|
+
async function checkBrowserImageFormatSupportAsync(mimeType) {
|
|
83
|
+
const dataURL = TEST_IMAGE[mimeType];
|
|
84
|
+
return dataURL ? await testBrowserImageFormatSupportAsync(dataURL) : true;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Checks browser synchronously
|
|
88
|
+
* Checks if toDataURL supports the mimeType.
|
|
89
|
+
* @note Imperfect testOn Chrome this is true for WebP but not for AVIF
|
|
90
|
+
*/
|
|
91
|
+
function testBrowserImageFormatSupport(mimeType) {
|
|
92
|
+
try {
|
|
93
|
+
const element = document.createElement('canvas');
|
|
94
|
+
const dataURL = element.toDataURL(mimeType);
|
|
95
|
+
return dataURL.indexOf(`data:${mimeType}`) === 0;
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// Probably Safari...
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Check WebPSupport asynchronously
|
|
103
|
+
async function testBrowserImageFormatSupportAsync(testImageDataURL) {
|
|
104
|
+
return new Promise((resolve) => {
|
|
105
|
+
const image = new Image();
|
|
106
|
+
image.src = testImageDataURL;
|
|
107
|
+
image.onload = () => resolve(image.height > 0);
|
|
108
|
+
image.onerror = () => resolve(false);
|
|
109
|
+
});
|
|
43
110
|
}
|
|
44
|
-
//# sourceMappingURL=image-format.js.map
|