@loaders.gl/images 3.1.0-alpha.2 → 3.1.0-beta.1

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 (180) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +4 -6
  4. package/dist/dist.min.js +2 -2
  5. package/dist/dist.min.js.map +7 -1
  6. package/dist/es5/bundle.js +7 -0
  7. package/dist/es5/bundle.js.map +1 -0
  8. package/dist/es5/image-loader.js +38 -0
  9. package/dist/es5/image-loader.js.map +1 -0
  10. package/dist/es5/image-writer.js +27 -0
  11. package/dist/es5/image-writer.js.map +1 -0
  12. package/dist/es5/index.js +86 -0
  13. package/dist/es5/index.js.map +1 -0
  14. package/dist/es5/lib/category-api/binary-image-api.js +126 -0
  15. package/dist/es5/lib/category-api/binary-image-api.js.map +1 -0
  16. package/dist/es5/lib/category-api/image-format.js +53 -0
  17. package/dist/es5/lib/category-api/image-format.js.map +1 -0
  18. package/dist/es5/lib/category-api/image-type.js +53 -0
  19. package/dist/es5/lib/category-api/image-type.js.map +1 -0
  20. package/dist/es5/lib/category-api/parsed-image-api.js +79 -0
  21. package/dist/es5/lib/category-api/parsed-image-api.js.map +1 -0
  22. package/dist/es5/lib/encoders/encode-image.js +79 -0
  23. package/dist/es5/lib/encoders/encode-image.js.map +1 -0
  24. package/dist/es5/lib/parsers/parse-image.js +67 -0
  25. package/dist/es5/lib/parsers/parse-image.js.map +1 -0
  26. package/dist/es5/lib/parsers/parse-to-image-bitmap.js +55 -0
  27. package/dist/es5/lib/parsers/parse-to-image-bitmap.js.map +1 -0
  28. package/dist/es5/lib/parsers/parse-to-image.js +44 -0
  29. package/dist/es5/lib/parsers/parse-to-image.js.map +1 -0
  30. package/dist/es5/lib/parsers/parse-to-node-image.js +20 -0
  31. package/dist/es5/lib/parsers/parse-to-node-image.js.map +1 -0
  32. package/dist/es5/lib/parsers/svg-utils.js +43 -0
  33. package/dist/es5/lib/parsers/svg-utils.js.map +1 -0
  34. package/dist/es5/lib/texture-api/async-deep-map.js +48 -0
  35. package/dist/es5/lib/texture-api/async-deep-map.js.map +1 -0
  36. package/dist/es5/lib/texture-api/deep-load.js +20 -0
  37. package/dist/es5/lib/texture-api/deep-load.js.map +1 -0
  38. package/dist/es5/lib/texture-api/generate-url.js +30 -0
  39. package/dist/es5/lib/texture-api/generate-url.js.map +1 -0
  40. package/dist/es5/lib/texture-api/load-image.js +69 -0
  41. package/dist/es5/lib/texture-api/load-image.js.map +1 -0
  42. package/dist/es5/lib/utils/version.js +9 -0
  43. package/dist/es5/lib/utils/version.js.map +1 -0
  44. package/dist/es5/types.js +2 -0
  45. package/dist/{types.js.map → es5/types.js.map} +0 -0
  46. package/dist/esm/bundle.js +5 -0
  47. package/dist/esm/bundle.js.map +1 -0
  48. package/dist/esm/image-loader.js +24 -0
  49. package/dist/esm/image-loader.js.map +1 -0
  50. package/dist/esm/image-writer.js +17 -0
  51. package/dist/esm/image-writer.js.map +1 -0
  52. package/dist/esm/index.js +8 -0
  53. package/dist/esm/index.js.map +1 -0
  54. package/dist/esm/lib/category-api/binary-image-api.js +118 -0
  55. package/dist/esm/lib/category-api/binary-image-api.js.map +1 -0
  56. package/dist/esm/lib/category-api/image-format.js +44 -0
  57. package/dist/esm/lib/category-api/image-format.js.map +1 -0
  58. package/dist/esm/lib/category-api/image-type.js +42 -0
  59. package/dist/esm/lib/category-api/image-type.js.map +1 -0
  60. package/dist/esm/lib/category-api/parsed-image-api.js +64 -0
  61. package/dist/esm/lib/category-api/parsed-image-api.js.map +1 -0
  62. package/dist/esm/lib/encoders/encode-image.js +69 -0
  63. package/dist/esm/lib/encoders/encode-image.js.map +1 -0
  64. package/dist/esm/lib/parsers/parse-image.js +52 -0
  65. package/dist/esm/lib/parsers/parse-image.js.map +1 -0
  66. package/dist/esm/lib/parsers/parse-to-image-bitmap.js +43 -0
  67. package/dist/esm/lib/parsers/parse-to-image-bitmap.js.map +1 -0
  68. package/dist/esm/lib/parsers/parse-to-image.js +34 -0
  69. package/dist/esm/lib/parsers/parse-to-image.js.map +1 -0
  70. package/dist/esm/lib/parsers/parse-to-node-image.js +11 -0
  71. package/dist/esm/lib/parsers/parse-to-node-image.js.map +1 -0
  72. package/dist/esm/lib/parsers/svg-utils.js +32 -0
  73. package/dist/esm/lib/parsers/svg-utils.js.map +1 -0
  74. package/dist/esm/lib/texture-api/async-deep-map.js +39 -0
  75. package/dist/esm/lib/texture-api/async-deep-map.js.map +1 -0
  76. package/dist/esm/lib/texture-api/deep-load.js +10 -0
  77. package/dist/esm/lib/texture-api/deep-load.js.map +1 -0
  78. package/dist/esm/lib/texture-api/generate-url.js +22 -0
  79. package/dist/esm/lib/texture-api/generate-url.js.map +1 -0
  80. package/dist/esm/lib/texture-api/load-image.js +52 -0
  81. package/dist/esm/lib/texture-api/load-image.js.map +1 -0
  82. package/dist/esm/lib/utils/version.js +2 -0
  83. package/dist/esm/lib/utils/version.js.map +1 -0
  84. package/dist/esm/types.js +2 -0
  85. package/dist/esm/types.js.map +1 -0
  86. package/dist/image-loader.d.ts +26 -0
  87. package/dist/image-loader.d.ts.map +1 -0
  88. package/dist/image-loader.js +39 -19
  89. package/dist/image-writer.d.ts +16 -0
  90. package/dist/image-writer.d.ts.map +1 -0
  91. package/dist/image-writer.js +19 -16
  92. package/dist/index.d.ts +10 -0
  93. package/dist/index.d.ts.map +1 -0
  94. package/dist/index.js +27 -7
  95. package/dist/lib/category-api/binary-image-api.d.ts +19 -0
  96. package/dist/lib/category-api/binary-image-api.d.ts.map +1 -0
  97. package/dist/lib/category-api/binary-image-api.js +125 -102
  98. package/dist/lib/category-api/image-format.d.ts +5 -0
  99. package/dist/lib/category-api/image-format.d.ts.map +1 -0
  100. package/dist/lib/category-api/image-format.js +63 -0
  101. package/dist/lib/category-api/image-type.d.ts +12 -0
  102. package/dist/lib/category-api/image-type.d.ts.map +1 -0
  103. package/dist/lib/category-api/image-type.js +44 -38
  104. package/dist/lib/category-api/parsed-image-api.d.ts +10 -0
  105. package/dist/lib/category-api/parsed-image-api.d.ts.map +1 -0
  106. package/dist/lib/category-api/parsed-image-api.js +62 -57
  107. package/dist/lib/encoders/encode-image.d.ts +12 -0
  108. package/dist/lib/encoders/encode-image.d.ts.map +1 -0
  109. package/dist/lib/encoders/encode-image.js +73 -61
  110. package/dist/lib/parsers/parse-image.d.ts +5 -0
  111. package/dist/lib/parsers/parse-image.d.ts.map +1 -0
  112. package/dist/lib/parsers/parse-image.js +54 -49
  113. package/dist/lib/parsers/parse-to-image-bitmap.d.ts +10 -0
  114. package/dist/lib/parsers/parse-to-image-bitmap.d.ts.map +1 -0
  115. package/dist/lib/parsers/parse-to-image-bitmap.js +53 -35
  116. package/dist/lib/parsers/parse-to-image.d.ts +4 -0
  117. package/dist/lib/parsers/parse-to-image.d.ts.map +1 -0
  118. package/dist/lib/parsers/parse-to-image.js +43 -30
  119. package/dist/lib/parsers/parse-to-node-image.d.ts +4 -0
  120. package/dist/lib/parsers/parse-to-node-image.d.ts.map +1 -0
  121. package/dist/lib/parsers/parse-to-node-image.js +13 -13
  122. package/dist/lib/parsers/svg-utils.d.ts +4 -0
  123. package/dist/lib/parsers/svg-utils.d.ts.map +1 -0
  124. package/dist/lib/parsers/svg-utils.js +36 -26
  125. package/dist/lib/texture-api/async-deep-map.d.ts +3 -0
  126. package/dist/lib/texture-api/async-deep-map.d.ts.map +1 -0
  127. package/dist/lib/texture-api/async-deep-map.js +49 -32
  128. package/dist/lib/texture-api/deep-load.d.ts +3 -0
  129. package/dist/lib/texture-api/deep-load.d.ts.map +1 -0
  130. package/dist/lib/texture-api/deep-load.js +13 -8
  131. package/dist/lib/texture-api/generate-url.d.ts +2 -0
  132. package/dist/lib/texture-api/generate-url.d.ts.map +1 -0
  133. package/dist/lib/texture-api/generate-url.js +19 -22
  134. package/dist/lib/texture-api/load-image.d.ts +7 -0
  135. package/dist/lib/texture-api/load-image.d.ts.map +1 -0
  136. package/dist/lib/texture-api/load-image.js +42 -47
  137. package/dist/lib/utils/version.d.ts +2 -0
  138. package/dist/lib/utils/version.d.ts.map +1 -0
  139. package/dist/lib/utils/version.js +7 -2
  140. package/dist/types.d.ts +18 -0
  141. package/dist/types.d.ts.map +1 -0
  142. package/dist/types.js +2 -2
  143. package/package.json +7 -8
  144. package/src/bundle.ts +2 -3
  145. package/src/image-loader.ts +18 -8
  146. package/src/index.ts +4 -0
  147. package/src/lib/category-api/image-format.ts +66 -0
  148. package/src/lib/category-api/image-type.ts +2 -2
  149. package/src/lib/encoders/encode-image.ts +1 -2
  150. package/src/lib/parsers/parse-image.ts +9 -2
  151. package/src/lib/parsers/parse-to-image-bitmap.ts +10 -2
  152. package/src/lib/parsers/parse-to-image.ts +7 -2
  153. package/src/lib/parsers/parse-to-node-image.ts +24 -6
  154. package/src/lib/parsers/svg-utils.ts +2 -2
  155. package/src/lib/texture-api/generate-url.ts +1 -2
  156. package/src/lib/texture-api/load-image.ts +1 -1
  157. package/dist/bundle.js.map +0 -1
  158. package/dist/image-loader.js.map +0 -1
  159. package/dist/image-writer.js.map +0 -1
  160. package/dist/index.js.map +0 -1
  161. package/dist/lib/category-api/binary-image-api.js.map +0 -1
  162. package/dist/lib/category-api/image-type.js.map +0 -1
  163. package/dist/lib/category-api/parsed-image-api.js.map +0 -1
  164. package/dist/lib/encoders/encode-image.js.map +0 -1
  165. package/dist/lib/parsers/parse-image.js.map +0 -1
  166. package/dist/lib/parsers/parse-to-image-bitmap.js.map +0 -1
  167. package/dist/lib/parsers/parse-to-image.js.map +0 -1
  168. package/dist/lib/parsers/parse-to-node-image.js.map +0 -1
  169. package/dist/lib/parsers/svg-utils.js.map +0 -1
  170. package/dist/lib/texture-api/async-deep-map.js.map +0 -1
  171. package/dist/lib/texture-api/deep-load.js.map +0 -1
  172. package/dist/lib/texture-api/generate-url.js.map +0 -1
  173. package/dist/lib/texture-api/load-image.js.map +0 -1
  174. package/dist/lib/utils/assert.js +0 -6
  175. package/dist/lib/utils/assert.js.map +0 -1
  176. package/dist/lib/utils/globals.js +0 -16
  177. package/dist/lib/utils/globals.js.map +0 -1
  178. package/dist/lib/utils/version.js.map +0 -1
  179. package/src/lib/utils/assert.js +0 -5
  180. package/src/lib/utils/globals.ts +0 -48
@@ -1,23 +1,43 @@
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';
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports._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");
4
10
  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'];
6
- export const ImageLoader = {
7
- id: 'image',
8
- module: 'images',
9
- name: 'Images',
10
- version: VERSION,
11
- mimeTypes: MIME_TYPES,
12
- extensions: EXTENSIONS,
13
- parse: parseImage,
14
- tests: [arrayBuffer => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer)))],
15
- options: {
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
+ ];
20
+ const DEFAULT_IMAGE_LOADER_OPTIONS = {
16
21
  image: {
17
- type: 'auto',
18
- decode: true
22
+ type: 'auto',
23
+ decode: true // if format is HTML
19
24
  }
20
- }
25
+ // imagebitmap: {} - passes (platform dependent) parameters to ImageBitmap constructor
26
+ };
27
+ /**
28
+ * Loads a platform-specific image type
29
+ * Note: This type can be used as input data to WebGL texture creation
30
+ */
31
+ exports.ImageLoader = {
32
+ id: 'image',
33
+ module: 'images',
34
+ name: 'Images',
35
+ version: version_1.VERSION,
36
+ mimeTypes: MIME_TYPES,
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
21
42
  };
22
- export const _typecheckImageLoader = ImageLoader;
23
- //# sourceMappingURL=image-loader.js.map
43
+ exports._typecheckImageLoader = exports.ImageLoader;
@@ -0,0 +1,16 @@
1
+ import { encodeImage } from './lib/encoders/encode-image';
2
+ export declare const ImageWriter: {
3
+ name: string;
4
+ id: string;
5
+ module: string;
6
+ version: any;
7
+ extensions: string[];
8
+ options: {
9
+ image: {
10
+ mimeType: string;
11
+ jpegQuality: null;
12
+ };
13
+ };
14
+ encode: typeof encodeImage;
15
+ };
16
+ //# sourceMappingURL=image-writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-writer.d.ts","sourceRoot":"","sources":["../src/image-writer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAC;AAExD,eAAO,MAAM,WAAW;;;;;;;;;;;;;CAavB,CAAC"}
@@ -1,17 +1,20 @@
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
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImageWriter = void 0;
4
+ // import type {Writer} from '@loaders.gl/loader-utils';
5
+ const version_1 = require("./lib/utils/version");
6
+ const encode_image_1 = require("./lib/encoders/encode-image");
7
+ exports.ImageWriter = {
8
+ name: 'Images',
9
+ id: 'image',
10
+ module: 'images',
11
+ version: version_1.VERSION,
12
+ extensions: ['jpeg'],
13
+ options: {
14
+ image: {
15
+ mimeType: 'image/png',
16
+ jpegQuality: null
17
+ }
18
+ },
19
+ encode: encode_image_1.encodeImage
16
20
  };
17
- //# sourceMappingURL=image-writer.js.map
@@ -0,0 +1,10 @@
1
+ export type { ImageDataType, ImageType, ImageTypeEnum } from './types';
2
+ export type { ImageLoaderOptions } from './image-loader';
3
+ export { ImageLoader } from './image-loader';
4
+ export { ImageWriter } from './image-writer';
5
+ export { getBinaryImageMetadata } from './lib/category-api/binary-image-api';
6
+ export { isImageTypeSupported, getDefaultImageType } from './lib/category-api/image-type';
7
+ export { isImage, getImageType, getImageSize, getImageData } from './lib/category-api/parsed-image-api';
8
+ export { _isImageFormatSupported } from './lib/category-api/image-format';
9
+ export { loadImage } from './lib/texture-api/load-image';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,uBAAuB,EAAC,MAAM,iCAAiC,CAAC;AAGxE,OAAO,EAAC,SAAS,EAAC,MAAM,8BAA8B,CAAC"}
package/dist/index.js CHANGED
@@ -1,7 +1,27 @@
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 { loadImage } from './lib/texture-api/load-image';
7
- //# sourceMappingURL=index.js.map
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadImage = exports._isImageFormatSupported = 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, "_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; } });
@@ -0,0 +1,19 @@
1
+ /** MIME type, width and height extracted from binary compressed image data */
2
+ export declare type BinaryImageMetadata = {
3
+ mimeType: string;
4
+ width: number;
5
+ height: number;
6
+ };
7
+ /**
8
+ * Extracts `{mimeType, width and height}` from a memory buffer containing a known image format
9
+ * Currently supports `image/png`, `image/jpeg`, `image/bmp` and `image/gif`.
10
+ * @param binaryData image file memory to parse
11
+ * @returns metadata or null if memory is not a valid image file format layout.
12
+ */
13
+ export declare function getBinaryImageMetadata(binaryData: DataView | ArrayBuffer): BinaryImageMetadata | null;
14
+ export declare function getBmpMetadata(binaryData: any): {
15
+ mimeType: string;
16
+ width: number;
17
+ height: number;
18
+ } | null;
19
+ //# sourceMappingURL=binary-image-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binary-image-api.d.ts","sourceRoot":"","sources":["../../../src/lib/category-api/binary-image-api.ts"],"names":[],"mappings":"AAQA,8EAA8E;AAC9E,oBAAY,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,CAQ5B;AA2CD,wBAAgB,cAAc,CAAC,UAAU,KAAA;;;;SAmBxC"}
@@ -1,118 +1,141 @@
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;
1
6
  const BIG_ENDIAN = false;
2
7
  const LITTLE_ENDIAN = true;
3
- export function getBinaryImageMetadata(binaryData) {
4
- const dataView = toDataView(binaryData);
5
- return getPngMetadata(dataView) || getJpegMetadata(dataView) || getGifMetadata(dataView) || getBmpMetadata(dataView);
8
+ /**
9
+ * Extracts `{mimeType, width and height}` from a memory buffer containing a known image format
10
+ * Currently supports `image/png`, `image/jpeg`, `image/bmp` and `image/gif`.
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));
6
20
  }
7
-
21
+ exports.getBinaryImageMetadata = getBinaryImageMetadata;
22
+ // PNG
8
23
  function getPngMetadata(binaryData) {
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
- };
24
+ const dataView = toDataView(binaryData);
25
+ // Check file contains the first 4 bytes of the PNG signature.
26
+ const isPng = dataView.byteLength >= 24 && dataView.getUint32(0, BIG_ENDIAN) === 0x89504e47;
27
+ if (!isPng) {
28
+ return null;
29
+ }
30
+ // Extract size from a binary PNG file
31
+ return {
32
+ mimeType: 'image/png',
33
+ width: dataView.getUint32(16, BIG_ENDIAN),
34
+ height: dataView.getUint32(20, BIG_ENDIAN)
35
+ };
21
36
  }
22
-
37
+ // GIF
38
+ // Extract size from a binary GIF file
39
+ // TODO: GIF is not this simple
23
40
  function getGifMetadata(binaryData) {
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
- };
41
+ const dataView = toDataView(binaryData);
42
+ // Check first 4 bytes of the GIF signature ("GIF8").
43
+ const isGif = dataView.byteLength >= 10 && dataView.getUint32(0, BIG_ENDIAN) === 0x47494638;
44
+ if (!isGif) {
45
+ return null;
46
+ }
47
+ // GIF is little endian.
48
+ return {
49
+ mimeType: 'image/gif',
50
+ width: dataView.getUint16(6, LITTLE_ENDIAN),
51
+ height: dataView.getUint16(8, LITTLE_ENDIAN)
52
+ };
36
53
  }
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
- };
54
+ // BMP
55
+ // TODO: BMP is not this simple
56
+ function getBmpMetadata(binaryData) {
57
+ const dataView = toDataView(binaryData);
58
+ // Check magic number is valid (first 2 characters should be "BM").
59
+ // The mandatory bitmap file header is 14 bytes long.
60
+ const isBmp = dataView.byteLength >= 14 &&
61
+ dataView.getUint16(0, BIG_ENDIAN) === 0x424d &&
62
+ dataView.getUint32(2, LITTLE_ENDIAN) === dataView.byteLength;
63
+ if (!isBmp) {
64
+ return null;
65
+ }
66
+ // BMP is little endian.
67
+ return {
68
+ mimeType: 'image/bmp',
69
+ width: dataView.getUint32(18, LITTLE_ENDIAN),
70
+ height: dataView.getUint32(22, LITTLE_ENDIAN)
71
+ };
51
72
  }
52
-
73
+ exports.getBmpMetadata = getBmpMetadata;
74
+ // JPEG
75
+ // Extract width and height from a binary JPEG file
53
76
  function getJpegMetadata(binaryData) {
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
- };
77
+ const dataView = toDataView(binaryData);
78
+ // Check file contains the JPEG "start of image" (SOI) marker
79
+ // followed by another marker.
80
+ const isJpeg = dataView.byteLength >= 3 &&
81
+ dataView.getUint16(0, BIG_ENDIAN) === 0xffd8 &&
82
+ dataView.getUint8(2) === 0xff;
83
+ if (!isJpeg) {
84
+ return null;
76
85
  }
77
-
78
- if (!tableMarkers.has(marker)) {
79
- return null;
86
+ const { tableMarkers, sofMarkers } = getJpegMarkers();
87
+ // Exclude the two byte SOI marker.
88
+ let i = 2;
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);
80
106
  }
81
-
82
- i += 2;
83
- i += dataView.getUint16(i, BIG_ENDIAN);
84
- }
85
-
86
- return null;
107
+ return null;
87
108
  }
88
-
89
109
  function getJpegMarkers() {
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
- };
110
+ // Tables/misc header markers.
111
+ // DQT, DHT, DAC, DRI, COM, APP_n
112
+ const tableMarkers = new Set([0xffdb, 0xffc4, 0xffcc, 0xffdd, 0xfffe]);
113
+ for (let i = 0xffe0; i < 0xfff0; ++i) {
114
+ tableMarkers.add(i);
115
+ }
116
+ // SOF markers and DHP marker.
117
+ // These markers are after tables/misc data.
118
+ const sofMarkers = new Set([
119
+ 0xffc0, 0xffc1, 0xffc2, 0xffc3, 0xffc5, 0xffc6, 0xffc7, 0xffc9, 0xffca, 0xffcb, 0xffcd, 0xffce,
120
+ 0xffcf, 0xffde
121
+ ]);
122
+ return { tableMarkers, sofMarkers };
101
123
  }
102
-
124
+ // TODO - move into image module?
103
125
  function toDataView(data) {
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');
126
+ if (data instanceof DataView) {
127
+ return data;
128
+ }
129
+ if (ArrayBuffer.isView(data)) {
130
+ return new DataView(data.buffer);
131
+ }
132
+ // TODO: make these functions work for Node.js buffers?
133
+ // if (bufferToArrayBuffer) {
134
+ // data = bufferToArrayBuffer(data);
135
+ // }
136
+ // Careful - Node Buffers will look like ArrayBuffers (keep after isBuffer)
137
+ if (data instanceof ArrayBuffer) {
138
+ return new DataView(data);
139
+ }
140
+ throw new Error('toDataView');
117
141
  }
118
- //# sourceMappingURL=binary-image-api.js.map
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Check if image MIME type is supported. Result is cached.
3
+ */
4
+ export declare function _isImageFormatSupported(mimeType: string): boolean;
5
+ //# sourceMappingURL=image-format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-format.d.ts","sourceRoot":"","sources":["../../../src/lib/category-api/image-format.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAKjE"}
@@ -0,0 +1,63 @@
1
+ "use strict";
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
6
+ const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];
7
+ /** Cache values for speed */
8
+ const mimeTypeSupported = {};
9
+ /**
10
+ * Check if image MIME type is supported. Result is cached.
11
+ */
12
+ function _isImageFormatSupported(mimeType) {
13
+ if (mimeTypeSupported[mimeType] === undefined) {
14
+ mimeTypeSupported[mimeType] = checkFormatSupport(mimeType);
15
+ }
16
+ return mimeTypeSupported[mimeType];
17
+ }
18
+ exports._isImageFormatSupported = _isImageFormatSupported;
19
+ /**
20
+ * Check if image MIME type is supported.
21
+ */
22
+ function checkFormatSupport(mimeType) {
23
+ switch (mimeType) {
24
+ case 'image/webp':
25
+ return checkWebPSupport();
26
+ case 'image/svg':
27
+ return loader_utils_1.isBrowser;
28
+ default:
29
+ if (!loader_utils_1.isBrowser) {
30
+ // @ts-ignore
31
+ const { _parseImageNode } = globalThis;
32
+ return Boolean(_parseImageNode) && NODE_FORMAT_SUPPORT.includes(mimeType);
33
+ }
34
+ return true;
35
+ }
36
+ }
37
+ /** Check WebPSupport synchronously */
38
+ function checkWebPSupport() {
39
+ if (!loader_utils_1.isBrowser) {
40
+ return false;
41
+ }
42
+ try {
43
+ const element = document.createElement('canvas');
44
+ return element.toDataURL('image/webp').indexOf('data:image/webp') === 0;
45
+ }
46
+ catch {
47
+ // Probably Safari...
48
+ return false;
49
+ }
50
+ }
51
+ // Note: better test but asynchronous
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
+ // }
@@ -0,0 +1,12 @@
1
+ import type { ImageTypeEnum } from '../../types';
2
+ /**
3
+ * Checks if a loaders.gl image type is supported
4
+ * @param type image type string
5
+ */
6
+ export declare function isImageTypeSupported(type: string): boolean;
7
+ /**
8
+ * Returns the "most performant" supported image type on this platform
9
+ * @returns image type string
10
+ */
11
+ export declare function getDefaultImageType(): ImageTypeEnum;
12
+ //# sourceMappingURL=image-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-type.d.ts","sourceRoot":"","sources":["../../../src/lib/category-api/image-type.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAU/C;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAgB1D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,aAAa,CAanD"}
@@ -1,42 +1,48 @@
1
- import { global, isBrowser } from '../utils/globals';
2
- const {
3
- _parseImageNode
4
- } = global;
5
- const IMAGE_SUPPORTED = typeof Image !== 'undefined';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDefaultImageType = exports.isImageTypeSupported = void 0;
4
+ const loader_utils_1 = require("@loaders.gl/loader-utils");
5
+ // @ts-ignore TS2339: Property does not exist on type
6
+ const { _parseImageNode } = globalThis;
7
+ const IMAGE_SUPPORTED = typeof Image !== 'undefined'; // NOTE: "false" positives if jsdom is installed
6
8
  const IMAGE_BITMAP_SUPPORTED = typeof ImageBitmap !== 'undefined';
7
9
  const NODE_IMAGE_SUPPORTED = Boolean(_parseImageNode);
8
- const DATA_SUPPORTED = isBrowser ? true : NODE_IMAGE_SUPPORTED;
9
- export function isImageTypeSupported(type) {
10
- switch (type) {
11
- case 'auto':
12
- return IMAGE_BITMAP_SUPPORTED || IMAGE_SUPPORTED || DATA_SUPPORTED;
13
-
14
- case 'imagebitmap':
15
- return IMAGE_BITMAP_SUPPORTED;
16
-
17
- case 'image':
18
- return IMAGE_SUPPORTED;
19
-
20
- case 'data':
21
- return DATA_SUPPORTED;
22
-
23
- default:
24
- throw new Error(`@loaders.gl/images: image ${type} not supported in this environment`);
25
- }
10
+ const DATA_SUPPORTED = loader_utils_1.isBrowser ? true : NODE_IMAGE_SUPPORTED;
11
+ /**
12
+ * Checks if a loaders.gl image type is supported
13
+ * @param type image type string
14
+ */
15
+ function isImageTypeSupported(type) {
16
+ switch (type) {
17
+ case 'auto':
18
+ // Should only ever be false in Node.js, if polyfills have not been installed...
19
+ return IMAGE_BITMAP_SUPPORTED || IMAGE_SUPPORTED || DATA_SUPPORTED;
20
+ case 'imagebitmap':
21
+ return IMAGE_BITMAP_SUPPORTED;
22
+ case 'image':
23
+ return IMAGE_SUPPORTED;
24
+ case 'data':
25
+ return DATA_SUPPORTED;
26
+ default:
27
+ throw new Error(`@loaders.gl/images: image ${type} not supported in this environment`);
28
+ }
26
29
  }
27
- export function getDefaultImageType() {
28
- if (IMAGE_BITMAP_SUPPORTED) {
29
- return 'imagebitmap';
30
- }
31
-
32
- if (IMAGE_SUPPORTED) {
33
- return 'image';
34
- }
35
-
36
- if (DATA_SUPPORTED) {
37
- return 'data';
38
- }
39
-
40
- throw new Error('Install \'@loaders.gl/polyfills\' to parse images under Node.js');
30
+ exports.isImageTypeSupported = isImageTypeSupported;
31
+ /**
32
+ * Returns the "most performant" supported image type on this platform
33
+ * @returns image type string
34
+ */
35
+ function getDefaultImageType() {
36
+ if (IMAGE_BITMAP_SUPPORTED) {
37
+ return 'imagebitmap';
38
+ }
39
+ if (IMAGE_SUPPORTED) {
40
+ return 'image';
41
+ }
42
+ if (DATA_SUPPORTED) {
43
+ return 'data';
44
+ }
45
+ // This should only happen in Node.js
46
+ throw new Error('Install \'@loaders.gl/polyfills\' to parse images under Node.js');
41
47
  }
42
- //# sourceMappingURL=image-type.js.map
48
+ exports.getDefaultImageType = getDefaultImageType;
@@ -0,0 +1,10 @@
1
+ import type { ImageType, ImageTypeEnum, ImageDataType } from '../../types';
2
+ export declare function isImage(image: ImageType): boolean;
3
+ export declare function deleteImage(image: ImageType): void;
4
+ export declare function getImageType(image: ImageType): ImageTypeEnum;
5
+ export declare function getImageSize(image: ImageType): {
6
+ width: number;
7
+ height: number;
8
+ };
9
+ export declare function getImageData(image: ImageType): ImageDataType | ImageData;
10
+ //# sourceMappingURL=parsed-image-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parsed-image-api.d.ts","sourceRoot":"","sources":["../../../src/lib/category-api/parsed-image-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,SAAS,EAAE,aAAa,EAAE,aAAa,EAAC,MAAM,aAAa,CAAC;AAEzE,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAEjD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAQlD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,aAAa,CAM5D;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,CAE9E;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,aAAa,GAAG,SAAS,CA0BxE"}