@loaders.gl/polyfills 3.3.0-alpha.10 → 3.3.0-alpha.12

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.
@@ -9,38 +9,29 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
9
9
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
11
  var _getPixels = _interopRequireDefault(require("get-pixels"));
12
- var _assert = require("../../utils/assert");
13
- var _util = _interopRequireDefault(require("util"));
14
12
  function parseImageNode(_x, _x2) {
15
13
  return _parseImageNode.apply(this, arguments);
16
14
  }
17
15
  function _parseImageNode() {
18
16
  _parseImageNode = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(arrayBuffer, mimeType) {
19
- var getPixelsAsync, buffer, ndarray, shape, layers, data;
17
+ var buffer, ndarray;
20
18
  return _regenerator.default.wrap(function _callee$(_context) {
21
19
  while (1) {
22
20
  switch (_context.prev = _context.next) {
23
21
  case 0:
24
- (0, _assert.assert)(mimeType, 'MIMEType is required to parse image under Node.js');
25
-
26
- getPixelsAsync = _util.default.promisify(_getPixels.default);
22
+ if (mimeType) {
23
+ _context.next = 2;
24
+ break;
25
+ }
26
+ throw new Error('MIMEType is required to parse image under Node.js');
27
+ case 2:
27
28
  buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);
28
29
  _context.next = 5;
29
30
  return getPixelsAsync(buffer, mimeType);
30
31
  case 5:
31
32
  ndarray = _context.sent;
32
- shape = (0, _toConsumableArray2.default)(ndarray.shape);
33
- layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
34
- data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;
35
- return _context.abrupt("return", {
36
- shape: shape,
37
- data: data,
38
- width: ndarray.shape[0],
39
- height: ndarray.shape[1],
40
- components: ndarray.shape[2],
41
- layers: layers
42
- });
43
- case 10:
33
+ return _context.abrupt("return", ndarray);
34
+ case 7:
44
35
  case "end":
45
36
  return _context.stop();
46
37
  }
@@ -49,4 +40,25 @@ function _parseImageNode() {
49
40
  }));
50
41
  return _parseImageNode.apply(this, arguments);
51
42
  }
43
+ function getPixelsAsync(buffer, mimeType) {
44
+ return new Promise(function (resolve) {
45
+ return (0, _getPixels.default)(buffer, mimeType, function (err, ndarray) {
46
+ if (err) {
47
+ throw err;
48
+ }
49
+ var shape = (0, _toConsumableArray2.default)(ndarray.shape);
50
+ var layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
51
+ var data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;
52
+
53
+ resolve({
54
+ shape: shape,
55
+ data: data,
56
+ width: ndarray.shape[0],
57
+ height: ndarray.shape[1],
58
+ components: ndarray.shape[2],
59
+ layers: layers ? [layers] : []
60
+ });
61
+ });
62
+ });
63
+ }
52
64
  //# sourceMappingURL=parse-image.node.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-image.node.js","names":["parseImageNode","arrayBuffer","mimeType","assert","getPixelsAsync","util","promisify","getPixels","buffer","Buffer","from","ndarray","shape","layers","length","shift","data","Uint8Array","width","height","components"],"sources":["../../../../src/node/images/parse-image.node.ts"],"sourcesContent":["import getPixels from 'get-pixels';\nimport {assert} from '../../utils/assert';\nimport util from 'util';\n\n// Note: These types are also defined in @loaders.gl/images and need to be kept in sync\ntype NDArray = {\n shape: number[];\n data: Uint8Array;\n width: number;\n height: number;\n components: number;\n layers: number[];\n};\n\nexport async function parseImageNode(arrayBuffer: ArrayBuffer, mimeType: string): Promise<NDArray> {\n assert(mimeType, 'MIMEType is required to parse image under Node.js');\n\n // TODO - check if getPixels callback is asynchronous if provided with buffer input\n // if not, parseImage can be a sync function\n const getPixelsAsync = util.promisify(getPixels);\n\n const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);\n\n const ndarray = await getPixelsAsync(buffer, mimeType);\n\n const shape = [...ndarray.shape];\n const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;\n const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;\n\n // extract width/height etc\n return {\n shape,\n data,\n width: ndarray.shape[0],\n height: ndarray.shape[1],\n components: ndarray.shape[2],\n layers\n };\n}\n"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AAAwB,SAYFA,cAAc;EAAA;AAAA;AAAA;EAAA,4EAA7B,iBAA8BC,WAAwB,EAAEC,QAAgB;IAAA;IAAA;MAAA;QAAA;UAAA;YAC7E,IAAAC,cAAM,EAACD,QAAQ,EAAE,mDAAmD,CAAC;;YAI/DE,cAAc,GAAGC,aAAI,CAACC,SAAS,CAACC,kBAAS,CAAC;YAE1CC,MAAM,GAAGP,WAAW,YAAYQ,MAAM,GAAGR,WAAW,GAAGQ,MAAM,CAACC,IAAI,CAACT,WAAW,CAAC;YAAA;YAAA,OAE/DG,cAAc,CAACI,MAAM,EAAEN,QAAQ,CAAC;UAAA;YAAhDS,OAAO;YAEPC,KAAK,oCAAOD,OAAO,CAACC,KAAK;YACzBC,MAAM,GAAGF,OAAO,CAACC,KAAK,CAACE,MAAM,KAAK,CAAC,GAAGH,OAAO,CAACC,KAAK,CAACG,KAAK,EAAE,GAAG,CAAC;YAC/DC,IAAI,GAAGL,OAAO,CAACK,IAAI,YAAYP,MAAM,GAAG,IAAIQ,UAAU,CAACN,OAAO,CAACK,IAAI,CAAC,GAAGL,OAAO,CAACK,IAAI;YAAA,iCAGlF;cACLJ,KAAK,EAALA,KAAK;cACLI,IAAI,EAAJA,IAAI;cACJE,KAAK,EAAEP,OAAO,CAACC,KAAK,CAAC,CAAC,CAAC;cACvBO,MAAM,EAAER,OAAO,CAACC,KAAK,CAAC,CAAC,CAAC;cACxBQ,UAAU,EAAET,OAAO,CAACC,KAAK,CAAC,CAAC,CAAC;cAC5BC,MAAM,EAANA;YACF,CAAC;UAAA;UAAA;YAAA;QAAA;MAAA;IAAA;EAAA,CACF;EAAA;AAAA"}
1
+ {"version":3,"file":"parse-image.node.js","names":["parseImageNode","arrayBuffer","mimeType","Error","buffer","Buffer","from","getPixelsAsync","ndarray","Promise","resolve","getPixels","err","shape","layers","length","shift","data","Uint8Array","width","height","components"],"sources":["../../../../src/node/images/parse-image.node.ts"],"sourcesContent":["import getPixels from 'get-pixels';\n\n// Note: These types are also defined in @loaders.gl/images and need to be kept in sync\ntype NDArray = {\n shape: number[];\n data: Uint8Array;\n width: number;\n height: number;\n components: number;\n layers: number[];\n};\n\nexport async function parseImageNode(arrayBuffer: ArrayBuffer, mimeType: string): Promise<NDArray> {\n if (!mimeType) {\n throw new Error('MIMEType is required to parse image under Node.js');\n }\n\n const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);\n\n const ndarray = await getPixelsAsync(buffer, mimeType);\n\n return ndarray;\n}\n\n// TODO - check if getPixels callback is asynchronous if provided with buffer input\n// if not, parseImage can be a sync function\nfunction getPixelsAsync(buffer: Buffer, mimeType: string): Promise<NDArray> {\n return new Promise<NDArray>((resolve) =>\n getPixels(buffer, mimeType, (err, ndarray) => {\n if (err) {\n throw err;\n }\n\n const shape = [...ndarray.shape];\n const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;\n const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;\n\n // extract width/height etc\n resolve({\n shape,\n data,\n width: ndarray.shape[0],\n height: ndarray.shape[1],\n components: ndarray.shape[2],\n // TODO - error\n layers: layers ? [layers] : []\n });\n })\n );\n}\n"],"mappings":";;;;;;;;;;AAAA;AAAmC,SAYbA,cAAc;EAAA;AAAA;AAAA;EAAA,4EAA7B,iBAA8BC,WAAwB,EAAEC,QAAgB;IAAA;IAAA;MAAA;QAAA;UAAA;YAAA,IACxEA,QAAQ;cAAA;cAAA;YAAA;YAAA,MACL,IAAIC,KAAK,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ert } from '../../utils/assert';
3
- import util from 'util';
4
2
 
5
3
  export async function parseImageNode(arrayBuffer, mimeType) {
6
- assert(mimeType, 'MIMEType is required to parse image under Node.js');
7
-
8
- const getPixelsAsync = util.promisify(getPixels);
4
+ if (!mimeType) {
5
+ throw new Error('MIMEType is required to parse image under Node.js');
6
+ }
9
7
  const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);
10
8
  const ndarray = await getPixelsAsync(buffer, mimeType);
11
- const shape = [...ndarray.shape];
12
- const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
13
- const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;
9
+ return ndarray;
10
+ }
11
+
12
+ function getPixelsAsync(buffer, mimeType) {
13
+ return new Promise(resolve => getPixels(buffer, mimeType, (err, ndarray) => {
14
+ if (err) {
15
+ throw err;
16
+ }
17
+ const shape = [...ndarray.shape];
18
+ const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
19
+ const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;
14
20
 
15
- return {
16
- shape,
17
- data,
18
- width: ndarray.shape[0],
19
- height: ndarray.shape[1],
20
- components: ndarray.shape[2],
21
- layers
22
- };
21
+ resolve({
22
+ shape,
23
+ data,
24
+ width: ndarray.shape[0],
25
+ height: ndarray.shape[1],
26
+ components: ndarray.shape[2],
27
+ layers: layers ? [layers] : []
28
+ });
29
+ }));
23
30
  }
24
31
  //# sourceMappingURL=parse-image.node.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-image.node.js","names":["getPixels","assert","util","parseImageNode","arrayBuffer","mimeType","getPixelsAsync","promisify","buffer","Buffer","from","ndarray","shape","layers","length","shift","data","Uint8Array","width","height","components"],"sources":["../../../../src/node/images/parse-image.node.ts"],"sourcesContent":["import getPixels from 'get-pixels';\nimport {assert} from '../../utils/assert';\nimport util from 'util';\n\n// Note: These types are also defined in @loaders.gl/images and need to be kept in sync\ntype NDArray = {\n shape: number[];\n data: Uint8Array;\n width: number;\n height: number;\n components: number;\n layers: number[];\n};\n\nexport async function parseImageNode(arrayBuffer: ArrayBuffer, mimeType: string): Promise<NDArray> {\n assert(mimeType, 'MIMEType is required to parse image under Node.js');\n\n // TODO - check if getPixels callback is asynchronous if provided with buffer input\n // if not, parseImage can be a sync function\n const getPixelsAsync = util.promisify(getPixels);\n\n const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);\n\n const ndarray = await getPixelsAsync(buffer, mimeType);\n\n const shape = [...ndarray.shape];\n const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;\n const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;\n\n // extract width/height etc\n return {\n shape,\n data,\n width: ndarray.shape[0],\n height: ndarray.shape[1],\n components: ndarray.shape[2],\n layers\n };\n}\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,YAAY;AAClC,SAAQC,MAAM,QAAO,oBAAoB;AACzC,OAAOC,IAAI,MAAM,MAAM;;AAYvB,OAAO,eAAeC,cAAc,CAACC,WAAwB,EAAEC,QAAgB,EAAoB;EACjGJ,MAAM,CAACI,QAAQ,EAAE,mDAAmD,CAAC;;EAIrE,MAAMC,cAAc,GAAGJ,IAAI,CAACK,SAAS,CAACP,SAAS,CAAC;EAEhD,MAAMQ,MAAM,GAAGJ,WAAW,YAAYK,MAAM,GAAGL,WAAW,GAAGK,MAAM,CAACC,IAAI,CAACN,WAAW,CAAC;EAErF,MAAMO,OAAO,GAAG,MAAML,cAAc,CAACE,MAAM,EAAEH,QAAQ,CAAC;EAEtD,MAAMO,KAAK,GAAG,CAAC,GAAGD,OAAO,CAACC,KAAK,CAAC;EAChC,MAAMC,MAAM,GAAGF,OAAO,CAACC,KAAK,CAACE,MAAM,KAAK,CAAC,GAAGH,OAAO,CAACC,KAAK,CAACG,KAAK,EAAE,GAAG,CAAC;EACrE,MAAMC,IAAI,GAAGL,OAAO,CAACK,IAAI,YAAYP,MAAM,GAAG,IAAIQ,UAAU,CAACN,OAAO,CAACK,IAAI,CAAC,GAAGL,OAAO,CAACK,IAAI;;EAGzF,OAAO;IACLJ,KAAK;IACLI,IAAI;IACJE,KAAK,EAAEP,OAAO,CAACC,KAAK,CAAC,CAAC,CAAC;IACvBO,MAAM,EAAER,OAAO,CAACC,KAAK,CAAC,CAAC,CAAC;IACxBQ,UAAU,EAAET,OAAO,CAACC,KAAK,CAAC,CAAC,CAAC;IAC5BC;EACF,CAAC;AACH"}
1
+ {"version":3,"file":"parse-image.node.js","names":["getPixels","parseImageNode","arrayBuffer","mimeType","Error","buffer","Buffer","from","ndarray","getPixelsAsync","Promise","resolve","err","shape","layers","length","shift","data","Uint8Array","width","height","components"],"sources":["../../../../src/node/images/parse-image.node.ts"],"sourcesContent":["import getPixels from 'get-pixels';\n\n// Note: These types are also defined in @loaders.gl/images and need to be kept in sync\ntype NDArray = {\n shape: number[];\n data: Uint8Array;\n width: number;\n height: number;\n components: number;\n layers: number[];\n};\n\nexport async function parseImageNode(arrayBuffer: ArrayBuffer, mimeType: string): Promise<NDArray> {\n if (!mimeType) {\n throw new Error('MIMEType is required to parse image under Node.js');\n }\n\n const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);\n\n const ndarray = await getPixelsAsync(buffer, mimeType);\n\n return ndarray;\n}\n\n// TODO - check if getPixels callback is asynchronous if provided with buffer input\n// if not, parseImage can be a sync function\nfunction getPixelsAsync(buffer: Buffer, mimeType: string): Promise<NDArray> {\n return new Promise<NDArray>((resolve) =>\n getPixels(buffer, mimeType, (err, ndarray) => {\n if (err) {\n throw err;\n }\n\n const shape = [...ndarray.shape];\n const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;\n const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;\n\n // extract width/height etc\n resolve({\n shape,\n data,\n width: ndarray.shape[0],\n height: ndarray.shape[1],\n components: ndarray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A,MAAM,CAAC,GAAG;IAC9B,CAAC,CAAC;EACJ,CAAC,CAAC,CACH;AACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"parse-image.node.d.ts","sourceRoot":"","sources":["../../../src/node/images/parse-image.node.ts"],"names":[],"mappings":"AAKA,KAAK,OAAO,GAAG;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,wBAAsB,cAAc,CAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAwBjG"}
1
+ {"version":3,"file":"parse-image.node.d.ts","sourceRoot":"","sources":["../../../src/node/images/parse-image.node.ts"],"names":[],"mappings":"AAGA,KAAK,OAAO,GAAG;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,wBAAsB,cAAc,CAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAUjG"}
@@ -5,26 +5,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.parseImageNode = void 0;
7
7
  const get_pixels_1 = __importDefault(require("get-pixels"));
8
- const assert_1 = require("../../utils/assert");
9
- const util_1 = __importDefault(require("util"));
10
8
  async function parseImageNode(arrayBuffer, mimeType) {
11
- (0, assert_1.assert)(mimeType, 'MIMEType is required to parse image under Node.js');
12
- // TODO - check if getPixels callback is asynchronous if provided with buffer input
13
- // if not, parseImage can be a sync function
14
- const getPixelsAsync = util_1.default.promisify(get_pixels_1.default);
9
+ if (!mimeType) {
10
+ throw new Error('MIMEType is required to parse image under Node.js');
11
+ }
15
12
  const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);
16
13
  const ndarray = await getPixelsAsync(buffer, mimeType);
17
- const shape = [...ndarray.shape];
18
- const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
19
- const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;
20
- // extract width/height etc
21
- return {
22
- shape,
23
- data,
24
- width: ndarray.shape[0],
25
- height: ndarray.shape[1],
26
- components: ndarray.shape[2],
27
- layers
28
- };
14
+ return ndarray;
29
15
  }
30
16
  exports.parseImageNode = parseImageNode;
17
+ // TODO - check if getPixels callback is asynchronous if provided with buffer input
18
+ // if not, parseImage can be a sync function
19
+ function getPixelsAsync(buffer, mimeType) {
20
+ return new Promise((resolve) => (0, get_pixels_1.default)(buffer, mimeType, (err, ndarray) => {
21
+ if (err) {
22
+ throw err;
23
+ }
24
+ const shape = [...ndarray.shape];
25
+ const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
26
+ const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;
27
+ // extract width/height etc
28
+ resolve({
29
+ shape,
30
+ data,
31
+ width: ndarray.shape[0],
32
+ height: ndarray.shape[1],
33
+ components: ndarray.shape[2],
34
+ // TODO - error
35
+ layers: layers ? [layers] : []
36
+ });
37
+ }));
38
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/polyfills",
3
- "version": "3.3.0-alpha.10",
3
+ "version": "3.3.0-alpha.12",
4
4
  "description": "Polyfills for TextEncoder/TextDecoder",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -105,5 +105,5 @@
105
105
  "through": "^2.3.8",
106
106
  "web-streams-polyfill": "^3.0.0"
107
107
  },
108
- "gitHead": "53bc8d3f18fbc3445a00f8509038479119895c78"
108
+ "gitHead": "e807cde8f2fcb3503fa01ae3ac6b148ff5326649"
109
109
  }
@@ -1,6 +1,4 @@
1
1
  import getPixels from 'get-pixels';
2
- import {assert} from '../../utils/assert';
3
- import util from 'util';
4
2
 
5
3
  // Note: These types are also defined in @loaders.gl/images and need to be kept in sync
6
4
  type NDArray = {
@@ -13,27 +11,40 @@ type NDArray = {
13
11
  };
14
12
 
15
13
  export async function parseImageNode(arrayBuffer: ArrayBuffer, mimeType: string): Promise<NDArray> {
16
- assert(mimeType, 'MIMEType is required to parse image under Node.js');
17
-
18
- // TODO - check if getPixels callback is asynchronous if provided with buffer input
19
- // if not, parseImage can be a sync function
20
- const getPixelsAsync = util.promisify(getPixels);
14
+ if (!mimeType) {
15
+ throw new Error('MIMEType is required to parse image under Node.js');
16
+ }
21
17
 
22
18
  const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);
23
19
 
24
20
  const ndarray = await getPixelsAsync(buffer, mimeType);
25
21
 
26
- const shape = [...ndarray.shape];
27
- const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
28
- const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;
29
-
30
- // extract width/height etc
31
- return {
32
- shape,
33
- data,
34
- width: ndarray.shape[0],
35
- height: ndarray.shape[1],
36
- components: ndarray.shape[2],
37
- layers
38
- };
22
+ return ndarray;
23
+ }
24
+
25
+ // TODO - check if getPixels callback is asynchronous if provided with buffer input
26
+ // if not, parseImage can be a sync function
27
+ function getPixelsAsync(buffer: Buffer, mimeType: string): Promise<NDArray> {
28
+ return new Promise<NDArray>((resolve) =>
29
+ getPixels(buffer, mimeType, (err, ndarray) => {
30
+ if (err) {
31
+ throw err;
32
+ }
33
+
34
+ const shape = [...ndarray.shape];
35
+ const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
36
+ const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;
37
+
38
+ // extract width/height etc
39
+ resolve({
40
+ shape,
41
+ data,
42
+ width: ndarray.shape[0],
43
+ height: ndarray.shape[1],
44
+ components: ndarray.shape[2],
45
+ // TODO - error
46
+ layers: layers ? [layers] : []
47
+ });
48
+ })
49
+ );
39
50
  }