@loaders.gl/geotiff 4.0.0-alpha.1 → 4.0.0-alpha.11
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.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +28 -2
- package/dist/es5/bundle.js +9 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +21 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/load-geotiff.js +76 -0
- package/dist/es5/lib/load-geotiff.js.map +1 -0
- package/dist/es5/lib/ome/load-ome-tiff.js +66 -0
- package/dist/es5/lib/ome/load-ome-tiff.js.map +1 -0
- package/dist/es5/lib/ome/ome-indexers.js +140 -0
- package/dist/es5/lib/ome/ome-indexers.js.map +1 -0
- package/dist/es5/lib/ome/ome-utils.js +74 -0
- package/dist/es5/lib/ome/ome-utils.js.map +1 -0
- package/dist/es5/lib/ome/omexml.js +68 -0
- package/dist/es5/lib/ome/omexml.js.map +1 -0
- package/dist/es5/lib/ome/utils.js +26 -0
- package/dist/es5/lib/ome/utils.js.map +1 -0
- package/dist/es5/lib/tiff-pixel-source.js +163 -0
- package/dist/es5/lib/tiff-pixel-source.js.map +1 -0
- package/dist/es5/lib/utils/Pool.js +136 -0
- package/dist/es5/lib/utils/Pool.js.map +1 -0
- package/dist/es5/lib/utils/proxies.js +65 -0
- package/dist/es5/lib/utils/proxies.js.map +1 -0
- package/dist/es5/lib/utils/tiff-utils.js +43 -0
- package/dist/es5/lib/utils/tiff-utils.js.map +1 -0
- package/dist/es5/types.js +2 -0
- package/dist/es5/types.js.map +1 -0
- package/dist/es5/typings/geotiff.js +2 -0
- package/dist/es5/typings/geotiff.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/load-geotiff.js +28 -0
- package/dist/esm/lib/load-geotiff.js.map +1 -0
- package/dist/esm/lib/ome/load-ome-tiff.js +47 -0
- package/dist/esm/lib/ome/load-ome-tiff.js.map +1 -0
- package/dist/esm/lib/ome/ome-indexers.js +120 -0
- package/dist/esm/lib/ome/ome-indexers.js.map +1 -0
- package/dist/esm/lib/ome/ome-utils.js +66 -0
- package/dist/esm/lib/ome/ome-utils.js.map +1 -0
- package/dist/esm/lib/ome/omexml.js +64 -0
- package/dist/esm/lib/ome/omexml.js.map +1 -0
- package/dist/esm/lib/ome/utils.js +17 -0
- package/dist/esm/lib/ome/utils.js.map +1 -0
- package/dist/esm/lib/tiff-pixel-source.js +92 -0
- package/dist/esm/lib/tiff-pixel-source.js.map +1 -0
- package/dist/esm/lib/utils/Pool.js +61 -0
- package/dist/esm/lib/utils/Pool.js.map +1 -0
- package/dist/esm/lib/utils/decoder.worker.ts.disabled +21 -0
- package/dist/esm/lib/utils/proxies.js +54 -0
- package/dist/esm/lib/utils/proxies.js.map +1 -0
- package/dist/esm/lib/utils/tiff-utils.js +27 -0
- package/dist/esm/lib/utils/tiff-utils.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/typings/geotiff.js +2 -0
- package/dist/esm/typings/geotiff.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -3
- package/dist/lib/load-geotiff.d.ts +28 -0
- package/dist/lib/load-geotiff.d.ts.map +1 -0
- package/dist/lib/load-geotiff.js +56 -31
- package/dist/lib/ome/load-ome-tiff.d.ts +50 -0
- package/dist/lib/ome/load-ome-tiff.d.ts.map +1 -0
- package/dist/lib/ome/load-ome-tiff.js +45 -50
- package/dist/lib/ome/ome-indexers.d.ts +11 -0
- package/dist/lib/ome/ome-indexers.d.ts.map +1 -0
- package/dist/lib/ome/ome-indexers.js +104 -112
- package/dist/lib/ome/ome-utils.d.ts +28 -0
- package/dist/lib/ome/ome-utils.d.ts.map +1 -0
- package/dist/lib/ome/ome-utils.js +59 -69
- package/dist/lib/ome/omexml.d.ts +49 -0
- package/dist/lib/ome/omexml.d.ts.map +1 -0
- package/dist/lib/ome/omexml.js +60 -60
- package/dist/lib/ome/utils.d.ts +5 -0
- package/dist/lib/ome/utils.d.ts.map +1 -0
- package/dist/lib/ome/utils.js +27 -18
- package/dist/lib/tiff-pixel-source.d.ts +18 -0
- package/dist/lib/tiff-pixel-source.d.ts.map +1 -0
- package/dist/lib/tiff-pixel-source.js +59 -106
- package/dist/lib/utils/Pool.d.ts +29 -0
- package/dist/lib/utils/Pool.d.ts.map +1 -0
- package/dist/lib/utils/Pool.js +78 -72
- package/dist/lib/utils/proxies.d.ts +6 -0
- package/dist/lib/utils/proxies.d.ts.map +1 -0
- package/dist/lib/utils/proxies.js +79 -56
- package/dist/lib/utils/tiff-utils.d.ts +10 -0
- package/dist/lib/utils/tiff-utils.d.ts.map +1 -0
- package/dist/lib/utils/tiff-utils.js +40 -24
- package/dist/types.d.ts +47 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -2
- package/dist/typings/geotiff.d.ts +60 -0
- package/dist/typings/geotiff.d.ts.map +1 -0
- package/dist/typings/geotiff.js +1 -2
- package/package.json +7 -7
- package/dist/bundle.js.map +0 -1
- package/dist/dist.min.js +0 -13
- package/dist/dist.min.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/load-geotiff.js.map +0 -1
- package/dist/lib/ome/load-ome-tiff.js.map +0 -1
- package/dist/lib/ome/ome-indexers.js.map +0 -1
- package/dist/lib/ome/ome-utils.js.map +0 -1
- package/dist/lib/ome/omexml.js.map +0 -1
- package/dist/lib/ome/utils.js.map +0 -1
- package/dist/lib/tiff-pixel-source.js.map +0 -1
- package/dist/lib/utils/Pool.js.map +0 -1
- package/dist/lib/utils/proxies.js.map +0 -1
- package/dist/lib/utils/tiff-utils.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/typings/geotiff.js.map +0 -1
- /package/dist/{lib → es5/lib}/utils/decoder.worker.ts.disabled +0 -0
|
@@ -1,73 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOmePixelSourceMeta = exports.DTYPE_LOOKUP = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
exports.DTYPE_LOOKUP = {
|
|
6
|
+
uint8: 'Uint8',
|
|
7
|
+
uint16: 'Uint16',
|
|
8
|
+
uint32: 'Uint32',
|
|
9
|
+
float: 'Float32',
|
|
10
|
+
double: 'Float64',
|
|
11
|
+
int8: 'Int8',
|
|
12
|
+
int16: 'Int16',
|
|
13
|
+
int32: 'Int32'
|
|
11
14
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const getShape = level => {
|
|
28
|
-
const s = [...shape];
|
|
29
|
-
s[dims('x')] = Pixels.SizeX >> level;
|
|
30
|
-
s[dims('y')] = Pixels.SizeY >> level;
|
|
31
|
-
return s;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
if (!(Pixels.Type in DTYPE_LOOKUP)) {
|
|
35
|
-
throw Error("Pixel type ".concat(Pixels.Type, " not supported."));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const dtype = DTYPE_LOOKUP[Pixels.Type];
|
|
39
|
-
|
|
40
|
-
if (Pixels.PhysicalSizeX && Pixels.PhysicalSizeY) {
|
|
41
|
-
const physicalSizes = {
|
|
42
|
-
x: {
|
|
43
|
-
size: Pixels.PhysicalSizeX,
|
|
44
|
-
unit: Pixels.PhysicalSizeXUnit
|
|
45
|
-
},
|
|
46
|
-
y: {
|
|
47
|
-
size: Pixels.PhysicalSizeY,
|
|
48
|
-
unit: Pixels.PhysicalSizeYUnit
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
if (Pixels.PhysicalSizeZ) {
|
|
53
|
-
physicalSizes.z = {
|
|
54
|
-
size: Pixels.PhysicalSizeZ,
|
|
55
|
-
unit: Pixels.PhysicalSizeZUnit
|
|
56
|
-
};
|
|
15
|
+
function getOmePixelSourceMeta({ Pixels }) {
|
|
16
|
+
// e.g. 'XYZCT' -> ['t', 'c', 'z', 'y', 'x']
|
|
17
|
+
const labels = (0, utils_1.getLabels)(Pixels.DimensionOrder);
|
|
18
|
+
// Compute "shape" of image
|
|
19
|
+
const dims = (0, utils_1.getDims)(labels);
|
|
20
|
+
const shape = Array(labels.length).fill(0);
|
|
21
|
+
shape[dims('t')] = Pixels.SizeT;
|
|
22
|
+
shape[dims('c')] = Pixels.SizeC;
|
|
23
|
+
shape[dims('z')] = Pixels.SizeZ;
|
|
24
|
+
// Push extra dimension if data are interleaved.
|
|
25
|
+
if (Pixels.Interleaved) {
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
labels.push('_c');
|
|
28
|
+
shape.push(3);
|
|
57
29
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
30
|
+
// Creates a new shape for different level of pyramid.
|
|
31
|
+
// Assumes factor-of-two downsampling.
|
|
32
|
+
const getShape = (level) => {
|
|
33
|
+
const s = [...shape];
|
|
34
|
+
s[dims('x')] = Pixels.SizeX >> level;
|
|
35
|
+
s[dims('y')] = Pixels.SizeY >> level;
|
|
36
|
+
return s;
|
|
64
37
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
38
|
+
if (!(Pixels.Type in exports.DTYPE_LOOKUP)) {
|
|
39
|
+
throw Error(`Pixel type ${Pixels.Type} not supported.`);
|
|
40
|
+
}
|
|
41
|
+
const dtype = exports.DTYPE_LOOKUP[Pixels.Type];
|
|
42
|
+
if (Pixels.PhysicalSizeX && Pixels.PhysicalSizeY) {
|
|
43
|
+
const physicalSizes = {
|
|
44
|
+
x: {
|
|
45
|
+
size: Pixels.PhysicalSizeX,
|
|
46
|
+
unit: Pixels.PhysicalSizeXUnit
|
|
47
|
+
},
|
|
48
|
+
y: {
|
|
49
|
+
size: Pixels.PhysicalSizeY,
|
|
50
|
+
unit: Pixels.PhysicalSizeYUnit
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
if (Pixels.PhysicalSizeZ) {
|
|
54
|
+
physicalSizes.z = {
|
|
55
|
+
size: Pixels.PhysicalSizeZ,
|
|
56
|
+
unit: Pixels.PhysicalSizeZUnit
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return { labels, getShape, physicalSizes, dtype };
|
|
60
|
+
}
|
|
61
|
+
return { labels, getShape, dtype };
|
|
72
62
|
}
|
|
73
|
-
|
|
63
|
+
exports.getOmePixelSourceMeta = getOmePixelSourceMeta;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export declare function fromString(str: string): {
|
|
2
|
+
format(): {
|
|
3
|
+
'Acquisition Date': string;
|
|
4
|
+
'Dimensions (XY)': string;
|
|
5
|
+
'Pixels Type': PixelType;
|
|
6
|
+
'Pixels Size (XYZ)': string;
|
|
7
|
+
'Z-sections/Timepoints': string;
|
|
8
|
+
Channels: number;
|
|
9
|
+
};
|
|
10
|
+
AquisitionDate: string;
|
|
11
|
+
Description: string;
|
|
12
|
+
Pixels: {
|
|
13
|
+
Channels: ({
|
|
14
|
+
Color: [number, number, number, number];
|
|
15
|
+
ID: string;
|
|
16
|
+
SamplesPerPixel: number;
|
|
17
|
+
Name?: string | undefined;
|
|
18
|
+
} | {
|
|
19
|
+
ID: string;
|
|
20
|
+
SamplesPerPixel: number;
|
|
21
|
+
Name?: string | undefined;
|
|
22
|
+
})[];
|
|
23
|
+
PhysicalSizeX: number;
|
|
24
|
+
PhysicalSizeY: number;
|
|
25
|
+
PhysicalSizeZ: number;
|
|
26
|
+
SignificantBits: number;
|
|
27
|
+
SizeX: number;
|
|
28
|
+
SizeY: number;
|
|
29
|
+
SizeZ: number;
|
|
30
|
+
SizeT: number;
|
|
31
|
+
SizeC: number;
|
|
32
|
+
PhysicalSizeXUnit: UnitsLength;
|
|
33
|
+
PhysicalSizeYUnit: UnitsLength;
|
|
34
|
+
PhysicalSizeZUnit: UnitsLength;
|
|
35
|
+
BigEndian: boolean;
|
|
36
|
+
Interleaved: boolean;
|
|
37
|
+
ID: string;
|
|
38
|
+
DimensionOrder: DimensionOrder;
|
|
39
|
+
Type: PixelType;
|
|
40
|
+
};
|
|
41
|
+
ID: string;
|
|
42
|
+
Name: string;
|
|
43
|
+
}[];
|
|
44
|
+
export type OMEXML = ReturnType<typeof fromString>;
|
|
45
|
+
export type DimensionOrder = 'XYZCT' | 'XYZTC' | 'XYCTZ' | 'XYCZT' | 'XYTCZ' | 'XYTZC';
|
|
46
|
+
type PixelType = 'int8' | 'int16' | 'int32' | 'uint8' | 'uint16' | 'uint32' | 'float' | 'bit' | 'double' | 'complex' | 'double-complex';
|
|
47
|
+
export type UnitsLength = 'Ym' | 'Zm' | 'Em' | 'Pm' | 'Tm' | 'Gm' | 'Mm' | 'km' | 'hm' | 'dam' | 'm' | 'dm' | 'cm' | 'mm' | 'µm' | 'nm' | 'pm' | 'fm' | 'am' | 'zm' | 'ym' | 'Å' | 'thou' | 'li' | 'in' | 'ft' | 'yd' | 'mi' | 'ua' | 'ly' | 'pc' | 'pt' | 'pixel' | 'reference frame';
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=omexml.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"omexml.d.ts","sourceRoot":"","sources":["../../../src/lib/ome/omexml.ts"],"names":[],"mappings":"AAmBA,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA8CrC;AAED,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;AACnD,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAuBvF,KAAK,SAAS,GACV,MAAM,GACN,OAAO,GACP,OAAO,GACP,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,KAAK,GACL,QAAQ,GACR,SAAS,GACT,gBAAgB,CAAC;AAErB,MAAM,MAAM,WAAW,GACnB,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,KAAK,GACL,GAAG,GACH,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,GAAG,GACH,MAAM,GACN,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,OAAO,GACP,iBAAiB,CAAC"}
|
package/dist/lib/ome/omexml.js
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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.fromString = void 0;
|
|
7
|
+
const fast_xml_parser_1 = __importDefault(require("fast-xml-parser"));
|
|
8
|
+
const tiff_utils_1 = require("../utils/tiff-utils");
|
|
9
|
+
// WARNING: Changes to the parser options _will_ effect the types in types/omexml.d.ts.
|
|
3
10
|
const PARSER_OPTIONS = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
// Nests attributes withtout prefix under 'attr' key for each node
|
|
12
|
+
attributeNamePrefix: '',
|
|
13
|
+
attrNodeName: 'attr',
|
|
14
|
+
// Parses numbers for both attributes and nodes
|
|
15
|
+
parseNodeValue: true,
|
|
16
|
+
parseAttributeValue: true,
|
|
17
|
+
// Forces attributes to be parsed
|
|
18
|
+
ignoreAttributes: false
|
|
9
19
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const parse = (str) => fast_xml_parser_1.default.parse(str, PARSER_OPTIONS);
|
|
21
|
+
function fromString(str) {
|
|
22
|
+
const res = parse(str);
|
|
23
|
+
if (!res.OME) {
|
|
24
|
+
throw Error('Failed to parse OME-XML metadata.');
|
|
25
|
+
}
|
|
26
|
+
return (0, tiff_utils_1.ensureArray)(res.OME.Image).map((img) => {
|
|
27
|
+
const Channels = (0, tiff_utils_1.ensureArray)(img.Pixels.Channel).map((c) => {
|
|
28
|
+
if ('Color' in c.attr) {
|
|
29
|
+
return { ...c.attr, Color: (0, tiff_utils_1.intToRgba)(c.attr.Color) };
|
|
30
|
+
}
|
|
31
|
+
return { ...c.attr };
|
|
32
|
+
});
|
|
33
|
+
const { AquisitionDate = '', Description = '' } = img;
|
|
34
|
+
const image = {
|
|
35
|
+
...img.attr,
|
|
36
|
+
AquisitionDate,
|
|
37
|
+
Description,
|
|
38
|
+
Pixels: {
|
|
39
|
+
...img.Pixels.attr,
|
|
40
|
+
Channels
|
|
41
|
+
}
|
|
25
42
|
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return { ...c.attr
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
const {
|
|
32
|
-
AquisitionDate = '',
|
|
33
|
-
Description = ''
|
|
34
|
-
} = img;
|
|
35
|
-
const image = { ...img.attr,
|
|
36
|
-
AquisitionDate,
|
|
37
|
-
Description,
|
|
38
|
-
Pixels: { ...img.Pixels.attr,
|
|
39
|
-
Channels
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
return { ...image,
|
|
43
|
-
|
|
44
|
-
format() {
|
|
45
|
-
const {
|
|
46
|
-
Pixels
|
|
47
|
-
} = image;
|
|
48
|
-
const sizes = ['X', 'Y', 'Z'].map(name => {
|
|
49
|
-
const size = Pixels["PhysicalSize".concat(name)];
|
|
50
|
-
const unit = Pixels["PhysicalSize".concat(name, "Unit")];
|
|
51
|
-
return size && unit ? "".concat(size, " ").concat(unit) : '-';
|
|
52
|
-
}).join(' x ');
|
|
53
43
|
return {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
44
|
+
...image,
|
|
45
|
+
format() {
|
|
46
|
+
const { Pixels } = image;
|
|
47
|
+
const sizes = ['X', 'Y', 'Z']
|
|
48
|
+
.map((name) => {
|
|
49
|
+
const size = Pixels[`PhysicalSize${name}`];
|
|
50
|
+
const unit = Pixels[`PhysicalSize${name}Unit`];
|
|
51
|
+
return size && unit ? `${size} ${unit}` : '-';
|
|
52
|
+
})
|
|
53
|
+
.join(' x ');
|
|
54
|
+
return {
|
|
55
|
+
'Acquisition Date': image.AquisitionDate,
|
|
56
|
+
'Dimensions (XY)': `${Pixels.SizeX} x ${Pixels.SizeY}`,
|
|
57
|
+
'Pixels Type': Pixels.Type,
|
|
58
|
+
'Pixels Size (XYZ)': sizes,
|
|
59
|
+
'Z-sections/Timepoints': `${Pixels.SizeZ} x ${Pixels.SizeT}`,
|
|
60
|
+
Channels: Pixels.SizeC
|
|
61
|
+
};
|
|
62
|
+
}
|
|
60
63
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
};
|
|
64
|
-
});
|
|
64
|
+
});
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
exports.fromString = fromString;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { OMEXML } from '../ome/omexml';
|
|
2
|
+
import type { Labels } from '../../types';
|
|
3
|
+
export declare function getLabels(dimOrder: OMEXML[0]['Pixels']['DimensionOrder']): Labels<["t", "c", "z"] | ["c", "t", "z"] | ["z", "t", "c"] | ["t", "z", "c"] | ["z", "c", "t"] | ["c", "z", "t"]>;
|
|
4
|
+
export declare function getDims<S extends string>(labels: S[]): (name: S) => number;
|
|
5
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/ome/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAYxC,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,gBAAgB,CAAC,qHAExE;AAWD,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,UAKrC,CAAC,YAOhB"}
|
package/dist/lib/ome/utils.js
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDims = exports.getLabels = void 0;
|
|
4
|
+
function getLabels(dimOrder) {
|
|
5
|
+
return dimOrder.toLowerCase().split('').reverse();
|
|
3
6
|
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
exports.getLabels = getLabels;
|
|
8
|
+
/*
|
|
9
|
+
* Creates an ES6 map of 'label' -> index
|
|
10
|
+
* > const labels = ['a', 'b', 'c', 'd'];
|
|
11
|
+
* > const dims = getDims(labels);
|
|
12
|
+
* > dims('a') === 0;
|
|
13
|
+
* > dims('b') === 1;
|
|
14
|
+
* > dims('c') === 2;
|
|
15
|
+
* > dims('hi!'); // throws
|
|
16
|
+
*/
|
|
17
|
+
function getDims(labels) {
|
|
18
|
+
const lookup = new Map(labels.map((name, i) => [name, i]));
|
|
19
|
+
if (lookup.size !== labels.length) {
|
|
20
|
+
throw Error('Labels must be unique, found duplicated label.');
|
|
16
21
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
return (name) => {
|
|
23
|
+
const index = lookup.get(name);
|
|
24
|
+
if (index === undefined) {
|
|
25
|
+
throw Error('Invalid dimension.');
|
|
26
|
+
}
|
|
27
|
+
return index;
|
|
28
|
+
};
|
|
20
29
|
}
|
|
21
|
-
|
|
30
|
+
exports.getDims = getDims;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { GeoTIFFImage } from 'geotiff';
|
|
2
|
+
import type { PixelSource, PixelSourceSelection, PixelSourceMeta, Dtype, Labels, RasterSelection, TileSelection, PixelData } from '../types';
|
|
3
|
+
declare class TiffPixelSource<S extends string[]> implements PixelSource<S> {
|
|
4
|
+
dtype: Dtype;
|
|
5
|
+
tileSize: number;
|
|
6
|
+
shape: number[];
|
|
7
|
+
labels: Labels<S>;
|
|
8
|
+
meta: PixelSourceMeta | undefined;
|
|
9
|
+
private _indexer;
|
|
10
|
+
constructor(indexer: (sel: PixelSourceSelection<S>) => Promise<GeoTIFFImage>, dtype: Dtype, tileSize: number, shape: number[], labels: Labels<S>, meta?: PixelSourceMeta);
|
|
11
|
+
getRaster({ selection, signal }: RasterSelection<S>): Promise<PixelData>;
|
|
12
|
+
getTile({ x, y, selection, signal }: TileSelection<S>): Promise<PixelData>;
|
|
13
|
+
private _readRasters;
|
|
14
|
+
private _getTileExtent;
|
|
15
|
+
onTileError(err: Error): void;
|
|
16
|
+
}
|
|
17
|
+
export default TiffPixelSource;
|
|
18
|
+
//# sourceMappingURL=tiff-pixel-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiff-pixel-source.d.ts","sourceRoot":"","sources":["../../src/lib/tiff-pixel-source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAgB,MAAM,SAAS,CAAC;AAGzD,OAAO,KAAK,EACV,WAAW,EACX,oBAAoB,EACpB,eAAe,EACf,KAAK,EACL,MAAM,EACN,eAAe,EACf,aAAa,EACb,SAAS,EAEV,MAAM,UAAU,CAAC;AAElB,cAAM,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;IAC1D,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAClB,IAAI,EAAE,eAAe,GAAG,SAAS,CAAC;IACzC,OAAO,CAAC,QAAQ,CAA0D;gBAIxE,OAAO,EAAE,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,YAAY,CAAC,EAChE,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,IAAI,CAAC,EAAE,eAAe;IAUlB,SAAS,CAAC,EAAC,SAAS,EAAE,MAAM,EAAC,EAAE,eAAe,CAAC,CAAC,CAAC;IAKjD,OAAO,CAAC,EAAC,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,EAAC,EAAE,aAAa,CAAC,CAAC,CAAC;YAU3C,YAAY;IAuB1B,OAAO,CAAC,cAAc;IAetB,WAAW,CAAC,GAAG,EAAE,KAAK;CAGvB;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -1,111 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tiff_utils_1 = require("./utils/tiff-utils");
|
|
4
4
|
class TiffPixelSource {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
_defineProperty(this, "meta", void 0);
|
|
15
|
-
|
|
16
|
-
_defineProperty(this, "_indexer", void 0);
|
|
17
|
-
|
|
18
|
-
this._indexer = indexer;
|
|
19
|
-
this.dtype = dtype;
|
|
20
|
-
this.tileSize = tileSize;
|
|
21
|
-
this.shape = shape;
|
|
22
|
-
this.labels = labels;
|
|
23
|
-
this.meta = meta;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async getRaster({
|
|
27
|
-
selection,
|
|
28
|
-
signal
|
|
29
|
-
}) {
|
|
30
|
-
const image = await this._indexer(selection);
|
|
31
|
-
return this._readRasters(image, {
|
|
32
|
-
signal
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async getTile({
|
|
37
|
-
x,
|
|
38
|
-
y,
|
|
39
|
-
selection,
|
|
40
|
-
signal
|
|
41
|
-
}) {
|
|
42
|
-
const {
|
|
43
|
-
height,
|
|
44
|
-
width
|
|
45
|
-
} = this._getTileExtent(x, y);
|
|
46
|
-
|
|
47
|
-
const x0 = x * this.tileSize;
|
|
48
|
-
const y0 = y * this.tileSize;
|
|
49
|
-
const window = [x0, y0, x0 + width, y0 + height];
|
|
50
|
-
const image = await this._indexer(selection);
|
|
51
|
-
return this._readRasters(image, {
|
|
52
|
-
window,
|
|
53
|
-
width,
|
|
54
|
-
height,
|
|
55
|
-
signal
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async _readRasters(image, props) {
|
|
60
|
-
var _props$signal;
|
|
61
|
-
|
|
62
|
-
const interleave = isInterleaved(this.shape);
|
|
63
|
-
const raster = await image.readRasters({
|
|
64
|
-
interleave,
|
|
65
|
-
...props
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
if (props !== null && props !== void 0 && (_props$signal = props.signal) !== null && _props$signal !== void 0 && _props$signal.aborted) {
|
|
69
|
-
throw SIGNAL_ABORTED;
|
|
5
|
+
// eslint-disable-next-line max-params
|
|
6
|
+
constructor(indexer, dtype, tileSize, shape, labels, meta) {
|
|
7
|
+
this._indexer = indexer;
|
|
8
|
+
this.dtype = dtype;
|
|
9
|
+
this.tileSize = tileSize;
|
|
10
|
+
this.shape = shape;
|
|
11
|
+
this.labels = labels;
|
|
12
|
+
this.meta = meta;
|
|
70
13
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
data,
|
|
75
|
-
width: raster.width,
|
|
76
|
-
height: raster.height
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
_getTileExtent(x, y) {
|
|
81
|
-
const {
|
|
82
|
-
height: zoomLevelHeight,
|
|
83
|
-
width: zoomLevelWidth
|
|
84
|
-
} = getImageSize(this);
|
|
85
|
-
let height = this.tileSize;
|
|
86
|
-
let width = this.tileSize;
|
|
87
|
-
const maxXTileCoord = Math.floor(zoomLevelWidth / this.tileSize);
|
|
88
|
-
const maxYTileCoord = Math.floor(zoomLevelHeight / this.tileSize);
|
|
89
|
-
|
|
90
|
-
if (x === maxXTileCoord) {
|
|
91
|
-
width = zoomLevelWidth % this.tileSize;
|
|
14
|
+
async getRaster({ selection, signal }) {
|
|
15
|
+
const image = await this._indexer(selection);
|
|
16
|
+
return this._readRasters(image, { signal });
|
|
92
17
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
18
|
+
async getTile({ x, y, selection, signal }) {
|
|
19
|
+
const { height, width } = this._getTileExtent(x, y);
|
|
20
|
+
const x0 = x * this.tileSize;
|
|
21
|
+
const y0 = y * this.tileSize;
|
|
22
|
+
const window = [x0, y0, x0 + width, y0 + height];
|
|
23
|
+
const image = await this._indexer(selection);
|
|
24
|
+
return this._readRasters(image, { window, width, height, signal });
|
|
25
|
+
}
|
|
26
|
+
async _readRasters(image, props) {
|
|
27
|
+
const interleave = (0, tiff_utils_1.isInterleaved)(this.shape);
|
|
28
|
+
const raster = await image.readRasters({ interleave, ...props });
|
|
29
|
+
if (props?.signal?.aborted) {
|
|
30
|
+
throw tiff_utils_1.SIGNAL_ABORTED;
|
|
31
|
+
}
|
|
32
|
+
/*
|
|
33
|
+
* geotiff.js returns objects with different structure
|
|
34
|
+
* depending on `interleave`. It's weird, but this seems to work.
|
|
35
|
+
*/
|
|
36
|
+
const data = (interleave ? raster : raster[0]);
|
|
37
|
+
return {
|
|
38
|
+
data,
|
|
39
|
+
width: raster.width,
|
|
40
|
+
height: raster.height
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/*
|
|
44
|
+
* Computes tile size given x, y coord.
|
|
45
|
+
*/
|
|
46
|
+
_getTileExtent(x, y) {
|
|
47
|
+
const { height: zoomLevelHeight, width: zoomLevelWidth } = (0, tiff_utils_1.getImageSize)(this);
|
|
48
|
+
let height = this.tileSize;
|
|
49
|
+
let width = this.tileSize;
|
|
50
|
+
const maxXTileCoord = Math.floor(zoomLevelWidth / this.tileSize);
|
|
51
|
+
const maxYTileCoord = Math.floor(zoomLevelHeight / this.tileSize);
|
|
52
|
+
if (x === maxXTileCoord) {
|
|
53
|
+
width = zoomLevelWidth % this.tileSize;
|
|
54
|
+
}
|
|
55
|
+
if (y === maxYTileCoord) {
|
|
56
|
+
height = zoomLevelHeight % this.tileSize;
|
|
57
|
+
}
|
|
58
|
+
return { height, width };
|
|
59
|
+
}
|
|
60
|
+
onTileError(err) {
|
|
61
|
+
console.error(err); // eslint-disable-line no-console
|
|
96
62
|
}
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
height,
|
|
100
|
-
width
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
onTileError(err) {
|
|
105
|
-
console.error(err);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
63
|
}
|
|
109
|
-
|
|
110
|
-
export default TiffPixelSource;
|
|
111
|
-
//# sourceMappingURL=tiff-pixel-source.js.map
|
|
64
|
+
exports.default = TiffPixelSource;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** eslint-disable */
|
|
2
|
+
import type { FileDirectory } from 'geotiff';
|
|
3
|
+
/**
|
|
4
|
+
* Pool for workers to decode chunks of the images.
|
|
5
|
+
* This is a line-for-line copy of GeoTIFFs old implementation: https://github.com/geotiffjs/geotiff.js/blob/v1.0.0-beta.6/src/pool.js
|
|
6
|
+
*/
|
|
7
|
+
export default class Pool {
|
|
8
|
+
workers: Worker[];
|
|
9
|
+
idleWorkers: Worker[];
|
|
10
|
+
waitQueue: any[];
|
|
11
|
+
decoder: null;
|
|
12
|
+
/**
|
|
13
|
+
* @constructor
|
|
14
|
+
* @param {Number} size The size of the pool. Defaults to the number of CPUs
|
|
15
|
+
* available. When this parameter is `null` or 0, then the
|
|
16
|
+
* decoding will be done in the main thread.
|
|
17
|
+
*/
|
|
18
|
+
constructor(size?: number);
|
|
19
|
+
/**
|
|
20
|
+
* Decode the given block of bytes with the set compression method.
|
|
21
|
+
* @param {ArrayBuffer} buffer the array buffer of bytes to decode.
|
|
22
|
+
* @returns {Promise.<ArrayBuffer>} the decoded result as a `Promise`
|
|
23
|
+
*/
|
|
24
|
+
decode(fileDirectory: FileDirectory, buffer: ArrayBuffer): Promise<unknown>;
|
|
25
|
+
waitForWorker(): Promise<Worker>;
|
|
26
|
+
finishTask(currentWorker: Worker): Promise<void>;
|
|
27
|
+
destroy(): void;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=Pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Pool.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/Pool.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAU3C;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,IAAI;IACvB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,EAAE,GAAG,EAAE,CAAC;IACjB,OAAO,EAAE,IAAI,CAAC;IAEd;;;;;OAKG;gBACS,IAAI,SAAkB;IAclC;;;;OAIG;IACG,MAAM,CAAC,aAAa,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW;IAmBxD,aAAa;IAcb,UAAU,CAAC,aAAa,EAAE,MAAM;IAStC,OAAO;CAMR"}
|