@loaders.gl/geotiff 4.0.0-beta.2 → 4.0.0-beta.3
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/dist.dev.js +13292 -0
- package/dist/index.cjs +398 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/{esm/lib → lib}/load-geotiff.js +2 -2
- package/dist/lib/load-geotiff.js.map +1 -0
- package/dist/{esm/lib → lib}/ome/load-ome-tiff.js +4 -4
- package/dist/lib/ome/load-ome-tiff.js.map +1 -0
- package/dist/{esm/lib → lib}/ome/ome-indexers.js +2 -2
- package/dist/lib/ome/ome-indexers.js.map +1 -0
- package/dist/{esm/lib → lib}/ome/ome-utils.js +2 -2
- package/dist/lib/ome/ome-utils.js.map +1 -0
- package/dist/{esm/lib → lib}/ome/omexml.js +6 -6
- package/dist/lib/ome/omexml.js.map +1 -0
- package/dist/lib/ome/utils.js.map +1 -0
- package/dist/{esm/lib → lib}/tiff-pixel-source.js +7 -8
- package/dist/lib/tiff-pixel-source.js.map +1 -0
- package/dist/{esm/lib → lib}/utils/Pool.js +4 -5
- package/dist/lib/utils/Pool.js.map +1 -0
- package/dist/{esm/lib → lib}/utils/proxies.js +2 -2
- package/dist/lib/utils/proxies.js.map +1 -0
- package/dist/lib/utils/tiff-utils.js.map +1 -0
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -0
- package/dist/typings/geotiff.js.map +1 -0
- package/package.json +14 -6
- package/src/types.ts +2 -2
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/es5/bundle.js +0 -9
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/index.js +0 -21
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/load-geotiff.js +0 -76
- package/dist/es5/lib/load-geotiff.js.map +0 -1
- package/dist/es5/lib/ome/load-ome-tiff.js +0 -66
- package/dist/es5/lib/ome/load-ome-tiff.js.map +0 -1
- package/dist/es5/lib/ome/ome-indexers.js +0 -140
- package/dist/es5/lib/ome/ome-indexers.js.map +0 -1
- package/dist/es5/lib/ome/ome-utils.js +0 -74
- package/dist/es5/lib/ome/ome-utils.js.map +0 -1
- package/dist/es5/lib/ome/omexml.js +0 -68
- package/dist/es5/lib/ome/omexml.js.map +0 -1
- package/dist/es5/lib/ome/utils.js +0 -26
- package/dist/es5/lib/ome/utils.js.map +0 -1
- package/dist/es5/lib/tiff-pixel-source.js +0 -163
- package/dist/es5/lib/tiff-pixel-source.js.map +0 -1
- package/dist/es5/lib/utils/Pool.js +0 -136
- package/dist/es5/lib/utils/Pool.js.map +0 -1
- package/dist/es5/lib/utils/proxies.js +0 -65
- package/dist/es5/lib/utils/proxies.js.map +0 -1
- package/dist/es5/lib/utils/tiff-utils.js +0 -43
- package/dist/es5/lib/utils/tiff-utils.js.map +0 -1
- package/dist/es5/types.js +0 -2
- package/dist/es5/types.js.map +0 -1
- package/dist/es5/typings/geotiff.js +0 -2
- package/dist/es5/typings/geotiff.js.map +0 -1
- package/dist/esm/bundle.js +0 -4
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/index.js +0 -3
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/load-geotiff.js.map +0 -1
- package/dist/esm/lib/ome/load-ome-tiff.js.map +0 -1
- package/dist/esm/lib/ome/ome-indexers.js.map +0 -1
- package/dist/esm/lib/ome/ome-utils.js.map +0 -1
- package/dist/esm/lib/ome/omexml.js.map +0 -1
- package/dist/esm/lib/ome/utils.js.map +0 -1
- package/dist/esm/lib/tiff-pixel-source.js.map +0 -1
- package/dist/esm/lib/utils/Pool.js.map +0 -1
- package/dist/esm/lib/utils/decoder.worker.ts.disabled +0 -21
- package/dist/esm/lib/utils/proxies.js.map +0 -1
- package/dist/esm/lib/utils/tiff-utils.js.map +0 -1
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/typings/geotiff.js.map +0 -1
- package/src/bundle.ts +0 -5
- /package/dist/{esm/lib → lib}/ome/utils.js +0 -0
- /package/dist/{es5/lib → lib}/utils/decoder.worker.ts.disabled +0 -0
- /package/dist/{esm/lib → lib}/utils/tiff-utils.js +0 -0
- /package/dist/{esm/types.js → types.js} +0 -0
- /package/dist/{esm/typings → typings}/geotiff.js +0 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
TiffPixelSource: () => tiff_pixel_source_default,
|
|
24
|
+
loadGeoTiff: () => loadGeoTiff
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(src_exports);
|
|
27
|
+
|
|
28
|
+
// src/lib/load-geotiff.ts
|
|
29
|
+
var import_geotiff = require("geotiff");
|
|
30
|
+
|
|
31
|
+
// src/lib/utils/proxies.ts
|
|
32
|
+
var VIV_PROXY_KEY = "__viv";
|
|
33
|
+
var OFFSETS_PROXY_KEY = `${VIV_PROXY_KEY}-offsets`;
|
|
34
|
+
var POOL_PROXY_KEY = `${VIV_PROXY_KEY}-decoder-pool`;
|
|
35
|
+
function checkProxies(tiff) {
|
|
36
|
+
if (!isProxy(tiff, OFFSETS_PROXY_KEY)) {
|
|
37
|
+
console.warn("GeoTIFF source is missing offsets proxy.");
|
|
38
|
+
}
|
|
39
|
+
if (!isProxy(tiff, POOL_PROXY_KEY)) {
|
|
40
|
+
console.warn("GeoTIFF source is missing decoder-pool proxy.");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function isProxy(tiff, proxyFlag) {
|
|
44
|
+
return tiff[proxyFlag];
|
|
45
|
+
}
|
|
46
|
+
function createOffsetsProxy(tiff, offsets) {
|
|
47
|
+
const get = (target, key) => {
|
|
48
|
+
if (key === "getImage") {
|
|
49
|
+
return (index) => {
|
|
50
|
+
if (!(index in target.ifdRequests) && index in offsets) {
|
|
51
|
+
const offset = offsets[index];
|
|
52
|
+
target.ifdRequests[index] = target.parseFileDirectoryAt(offset);
|
|
53
|
+
}
|
|
54
|
+
return target.getImage(index);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (key === OFFSETS_PROXY_KEY) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
return Reflect.get(target, key);
|
|
61
|
+
};
|
|
62
|
+
return new Proxy(tiff, { get });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/lib/utils/tiff-utils.ts
|
|
66
|
+
function ensureArray(x) {
|
|
67
|
+
return Array.isArray(x) ? x : [x];
|
|
68
|
+
}
|
|
69
|
+
function intToRgba(int) {
|
|
70
|
+
if (!Number.isInteger(int)) {
|
|
71
|
+
throw Error("Not an integer.");
|
|
72
|
+
}
|
|
73
|
+
const buffer = new ArrayBuffer(4);
|
|
74
|
+
const view = new DataView(buffer);
|
|
75
|
+
view.setInt32(0, int, false);
|
|
76
|
+
const bytes = new Uint8Array(buffer);
|
|
77
|
+
return Array.from(bytes);
|
|
78
|
+
}
|
|
79
|
+
function isInterleaved(shape) {
|
|
80
|
+
const lastDimSize = shape[shape.length - 1];
|
|
81
|
+
return lastDimSize === 3 || lastDimSize === 4;
|
|
82
|
+
}
|
|
83
|
+
function getImageSize(source) {
|
|
84
|
+
const interleaved = isInterleaved(source.shape);
|
|
85
|
+
const [height, width] = source.shape.slice(interleaved ? -3 : -2);
|
|
86
|
+
return { height, width };
|
|
87
|
+
}
|
|
88
|
+
var SIGNAL_ABORTED = "__vivSignalAborted";
|
|
89
|
+
|
|
90
|
+
// src/lib/tiff-pixel-source.ts
|
|
91
|
+
var TiffPixelSource = class {
|
|
92
|
+
// eslint-disable-next-line max-params
|
|
93
|
+
constructor(indexer, dtype, tileSize, shape, labels, meta) {
|
|
94
|
+
this._indexer = indexer;
|
|
95
|
+
this.dtype = dtype;
|
|
96
|
+
this.tileSize = tileSize;
|
|
97
|
+
this.shape = shape;
|
|
98
|
+
this.labels = labels;
|
|
99
|
+
this.meta = meta;
|
|
100
|
+
}
|
|
101
|
+
async getRaster({ selection, signal }) {
|
|
102
|
+
const image = await this._indexer(selection);
|
|
103
|
+
return this._readRasters(image, { signal });
|
|
104
|
+
}
|
|
105
|
+
async getTile({ x, y, selection, signal }) {
|
|
106
|
+
const { height, width } = this._getTileExtent(x, y);
|
|
107
|
+
const x0 = x * this.tileSize;
|
|
108
|
+
const y0 = y * this.tileSize;
|
|
109
|
+
const window = [x0, y0, x0 + width, y0 + height];
|
|
110
|
+
const image = await this._indexer(selection);
|
|
111
|
+
return this._readRasters(image, { window, width, height, signal });
|
|
112
|
+
}
|
|
113
|
+
async _readRasters(image, props) {
|
|
114
|
+
var _a;
|
|
115
|
+
const interleave = isInterleaved(this.shape);
|
|
116
|
+
const raster = await image.readRasters({ interleave, ...props });
|
|
117
|
+
if ((_a = props == null ? void 0 : props.signal) == null ? void 0 : _a.aborted) {
|
|
118
|
+
throw SIGNAL_ABORTED;
|
|
119
|
+
}
|
|
120
|
+
const data = interleave ? raster : raster[0];
|
|
121
|
+
return {
|
|
122
|
+
data,
|
|
123
|
+
width: raster.width,
|
|
124
|
+
height: raster.height
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/*
|
|
128
|
+
* Computes tile size given x, y coord.
|
|
129
|
+
*/
|
|
130
|
+
_getTileExtent(x, y) {
|
|
131
|
+
const { height: zoomLevelHeight, width: zoomLevelWidth } = getImageSize(this);
|
|
132
|
+
let height = this.tileSize;
|
|
133
|
+
let width = this.tileSize;
|
|
134
|
+
const maxXTileCoord = Math.floor(zoomLevelWidth / this.tileSize);
|
|
135
|
+
const maxYTileCoord = Math.floor(zoomLevelHeight / this.tileSize);
|
|
136
|
+
if (x === maxXTileCoord) {
|
|
137
|
+
width = zoomLevelWidth % this.tileSize;
|
|
138
|
+
}
|
|
139
|
+
if (y === maxYTileCoord) {
|
|
140
|
+
height = zoomLevelHeight % this.tileSize;
|
|
141
|
+
}
|
|
142
|
+
return { height, width };
|
|
143
|
+
}
|
|
144
|
+
onTileError(err) {
|
|
145
|
+
console.error(err);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
var tiff_pixel_source_default = TiffPixelSource;
|
|
149
|
+
|
|
150
|
+
// src/lib/ome/ome-indexers.ts
|
|
151
|
+
function getOmeLegacyIndexer(tiff, rootMeta) {
|
|
152
|
+
const imgMeta = rootMeta[0];
|
|
153
|
+
const { SizeT, SizeC, SizeZ } = imgMeta.Pixels;
|
|
154
|
+
const ifdIndexer = getOmeIFDIndexer(imgMeta);
|
|
155
|
+
return (sel, pyramidLevel) => {
|
|
156
|
+
const index = ifdIndexer(sel);
|
|
157
|
+
const pyramidIndex = pyramidLevel * SizeZ * SizeT * SizeC;
|
|
158
|
+
return tiff.getImage(index + pyramidIndex);
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function getOmeSubIFDIndexer(tiff, rootMeta) {
|
|
162
|
+
const imgMeta = rootMeta[0];
|
|
163
|
+
const ifdIndexer = getOmeIFDIndexer(imgMeta);
|
|
164
|
+
const ifdCache = /* @__PURE__ */ new Map();
|
|
165
|
+
return async (sel, pyramidLevel) => {
|
|
166
|
+
const index = ifdIndexer(sel);
|
|
167
|
+
const baseImage = await tiff.getImage(index);
|
|
168
|
+
if (pyramidLevel === 0) {
|
|
169
|
+
return baseImage;
|
|
170
|
+
}
|
|
171
|
+
const { SubIFDs } = baseImage.fileDirectory;
|
|
172
|
+
if (!SubIFDs) {
|
|
173
|
+
throw Error("Indexing Error: OME-TIFF is missing SubIFDs.");
|
|
174
|
+
}
|
|
175
|
+
const key = `${sel.t}-${sel.c}-${sel.z}-${pyramidLevel}`;
|
|
176
|
+
if (!ifdCache.has(key)) {
|
|
177
|
+
const subIfdOffset = SubIFDs[pyramidLevel - 1];
|
|
178
|
+
ifdCache.set(key, tiff.parseFileDirectoryAt(subIfdOffset));
|
|
179
|
+
}
|
|
180
|
+
const ifd = await ifdCache.get(key);
|
|
181
|
+
return new baseImage.constructor(
|
|
182
|
+
ifd.fileDirectory,
|
|
183
|
+
ifd.geoKeyDirectory,
|
|
184
|
+
tiff.dataView,
|
|
185
|
+
tiff.littleEndian,
|
|
186
|
+
tiff.cache,
|
|
187
|
+
tiff.source
|
|
188
|
+
);
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function getOmeIFDIndexer(imgMeta) {
|
|
192
|
+
const { SizeC, SizeZ, SizeT, DimensionOrder } = imgMeta.Pixels;
|
|
193
|
+
switch (DimensionOrder) {
|
|
194
|
+
case "XYZCT": {
|
|
195
|
+
return ({ t, c, z }) => t * SizeZ * SizeC + c * SizeZ + z;
|
|
196
|
+
}
|
|
197
|
+
case "XYZTC": {
|
|
198
|
+
return ({ t, c, z }) => c * SizeZ * SizeT + t * SizeZ + z;
|
|
199
|
+
}
|
|
200
|
+
case "XYCTZ": {
|
|
201
|
+
return ({ t, c, z }) => z * SizeC * SizeT + t * SizeC + c;
|
|
202
|
+
}
|
|
203
|
+
case "XYCZT": {
|
|
204
|
+
return ({ t, c, z }) => t * SizeC * SizeZ + z * SizeC + c;
|
|
205
|
+
}
|
|
206
|
+
case "XYTCZ": {
|
|
207
|
+
return ({ t, c, z }) => z * SizeT * SizeC + c * SizeT + t;
|
|
208
|
+
}
|
|
209
|
+
case "XYTZC": {
|
|
210
|
+
return ({ t, c, z }) => c * SizeT * SizeZ + z * SizeT + t;
|
|
211
|
+
}
|
|
212
|
+
default: {
|
|
213
|
+
throw new Error(`Invalid OME-XML DimensionOrder, got ${DimensionOrder}.`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// src/lib/ome/utils.ts
|
|
219
|
+
function getLabels(dimOrder) {
|
|
220
|
+
return dimOrder.toLowerCase().split("").reverse();
|
|
221
|
+
}
|
|
222
|
+
function getDims(labels) {
|
|
223
|
+
const lookup = new Map(labels.map((name, i) => [name, i]));
|
|
224
|
+
if (lookup.size !== labels.length) {
|
|
225
|
+
throw Error("Labels must be unique, found duplicated label.");
|
|
226
|
+
}
|
|
227
|
+
return (name) => {
|
|
228
|
+
const index = lookup.get(name);
|
|
229
|
+
if (index === void 0) {
|
|
230
|
+
throw Error("Invalid dimension.");
|
|
231
|
+
}
|
|
232
|
+
return index;
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// src/lib/ome/ome-utils.ts
|
|
237
|
+
var DTYPE_LOOKUP = {
|
|
238
|
+
uint8: "Uint8",
|
|
239
|
+
uint16: "Uint16",
|
|
240
|
+
uint32: "Uint32",
|
|
241
|
+
float: "Float32",
|
|
242
|
+
double: "Float64",
|
|
243
|
+
int8: "Int8",
|
|
244
|
+
int16: "Int16",
|
|
245
|
+
int32: "Int32"
|
|
246
|
+
};
|
|
247
|
+
function getOmePixelSourceMeta({ Pixels }) {
|
|
248
|
+
const labels = getLabels(Pixels.DimensionOrder);
|
|
249
|
+
const dims = getDims(labels);
|
|
250
|
+
const shape = Array(labels.length).fill(0);
|
|
251
|
+
shape[dims("t")] = Pixels.SizeT;
|
|
252
|
+
shape[dims("c")] = Pixels.SizeC;
|
|
253
|
+
shape[dims("z")] = Pixels.SizeZ;
|
|
254
|
+
if (Pixels.Interleaved) {
|
|
255
|
+
labels.push("_c");
|
|
256
|
+
shape.push(3);
|
|
257
|
+
}
|
|
258
|
+
const getShape = (level) => {
|
|
259
|
+
const s = [...shape];
|
|
260
|
+
s[dims("x")] = Pixels.SizeX >> level;
|
|
261
|
+
s[dims("y")] = Pixels.SizeY >> level;
|
|
262
|
+
return s;
|
|
263
|
+
};
|
|
264
|
+
if (!(Pixels.Type in DTYPE_LOOKUP)) {
|
|
265
|
+
throw Error(`Pixel type ${Pixels.Type} not supported.`);
|
|
266
|
+
}
|
|
267
|
+
const dtype = DTYPE_LOOKUP[Pixels.Type];
|
|
268
|
+
if (Pixels.PhysicalSizeX && Pixels.PhysicalSizeY) {
|
|
269
|
+
const physicalSizes = {
|
|
270
|
+
x: {
|
|
271
|
+
size: Pixels.PhysicalSizeX,
|
|
272
|
+
unit: Pixels.PhysicalSizeXUnit
|
|
273
|
+
},
|
|
274
|
+
y: {
|
|
275
|
+
size: Pixels.PhysicalSizeY,
|
|
276
|
+
unit: Pixels.PhysicalSizeYUnit
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
if (Pixels.PhysicalSizeZ) {
|
|
280
|
+
physicalSizes.z = {
|
|
281
|
+
size: Pixels.PhysicalSizeZ,
|
|
282
|
+
unit: Pixels.PhysicalSizeZUnit
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
return { labels, getShape, physicalSizes, dtype };
|
|
286
|
+
}
|
|
287
|
+
return { labels, getShape, dtype };
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// src/lib/ome/omexml.ts
|
|
291
|
+
var import_fast_xml_parser = require("fast-xml-parser");
|
|
292
|
+
var xmlParser = new import_fast_xml_parser.XMLParser({
|
|
293
|
+
// Nests attributes withtout prefix under 'attr' key for each node
|
|
294
|
+
attributeNamePrefix: "",
|
|
295
|
+
attributesGroupName: "attr",
|
|
296
|
+
// Parses numbers for both attributes and nodes
|
|
297
|
+
parseTagValue: true,
|
|
298
|
+
parseAttributeValue: true,
|
|
299
|
+
// Forces attributes to be parsed
|
|
300
|
+
ignoreAttributes: false
|
|
301
|
+
});
|
|
302
|
+
var parse = (str) => xmlParser.parse(str);
|
|
303
|
+
function fromString(str) {
|
|
304
|
+
const res = parse(str);
|
|
305
|
+
if (!res.OME) {
|
|
306
|
+
throw Error("Failed to parse OME-XML metadata.");
|
|
307
|
+
}
|
|
308
|
+
return ensureArray(res.OME.Image).map((img) => {
|
|
309
|
+
const Channels = ensureArray(img.Pixels.Channel).map((c) => {
|
|
310
|
+
if ("Color" in c.attr) {
|
|
311
|
+
return { ...c.attr, Color: intToRgba(c.attr.Color) };
|
|
312
|
+
}
|
|
313
|
+
return { ...c.attr };
|
|
314
|
+
});
|
|
315
|
+
const { AquisitionDate = "", Description = "" } = img;
|
|
316
|
+
const image = {
|
|
317
|
+
...img.attr,
|
|
318
|
+
AquisitionDate,
|
|
319
|
+
Description,
|
|
320
|
+
Pixels: {
|
|
321
|
+
...img.Pixels.attr,
|
|
322
|
+
Channels
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
return {
|
|
326
|
+
...image,
|
|
327
|
+
format() {
|
|
328
|
+
const { Pixels } = image;
|
|
329
|
+
const sizes = ["X", "Y", "Z"].map((name) => {
|
|
330
|
+
const size = Pixels[`PhysicalSize${name}`];
|
|
331
|
+
const unit = Pixels[`PhysicalSize${name}Unit`];
|
|
332
|
+
return size && unit ? `${size} ${unit}` : "-";
|
|
333
|
+
}).join(" x ");
|
|
334
|
+
return {
|
|
335
|
+
"Acquisition Date": image.AquisitionDate,
|
|
336
|
+
"Dimensions (XY)": `${Pixels.SizeX} x ${Pixels.SizeY}`,
|
|
337
|
+
"Pixels Type": Pixels.Type,
|
|
338
|
+
"Pixels Size (XYZ)": sizes,
|
|
339
|
+
"Z-sections/Timepoints": `${Pixels.SizeZ} x ${Pixels.SizeT}`,
|
|
340
|
+
Channels: Pixels.SizeC
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// src/lib/ome/load-ome-tiff.ts
|
|
348
|
+
var isOmeTiff = (img) => img.fileDirectory.ImageDescription.includes("<OME");
|
|
349
|
+
async function loadOmeTiff(tiff, firstImage) {
|
|
350
|
+
const {
|
|
351
|
+
ImageDescription,
|
|
352
|
+
SubIFDs,
|
|
353
|
+
PhotometricInterpretation: photometricInterpretation
|
|
354
|
+
} = firstImage.fileDirectory;
|
|
355
|
+
const omexml = fromString(ImageDescription);
|
|
356
|
+
let levels;
|
|
357
|
+
let pyramidIndexer;
|
|
358
|
+
if (SubIFDs) {
|
|
359
|
+
levels = SubIFDs.length + 1;
|
|
360
|
+
pyramidIndexer = getOmeSubIFDIndexer(tiff, omexml);
|
|
361
|
+
} else {
|
|
362
|
+
levels = omexml.length;
|
|
363
|
+
pyramidIndexer = getOmeLegacyIndexer(tiff, omexml);
|
|
364
|
+
}
|
|
365
|
+
const imgMeta = omexml[0];
|
|
366
|
+
const { labels, getShape, physicalSizes, dtype } = getOmePixelSourceMeta(imgMeta);
|
|
367
|
+
const tileSize = firstImage.getTileWidth();
|
|
368
|
+
const meta = { photometricInterpretation, physicalSizes };
|
|
369
|
+
const data = Array.from({ length: levels }).map((_, resolution) => {
|
|
370
|
+
const shape = getShape(resolution);
|
|
371
|
+
const indexer = (sel) => pyramidIndexer(sel, resolution);
|
|
372
|
+
const source = new tiff_pixel_source_default(indexer, dtype, tileSize, shape, labels, meta);
|
|
373
|
+
return source;
|
|
374
|
+
});
|
|
375
|
+
return { data, metadata: imgMeta };
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// src/lib/load-geotiff.ts
|
|
379
|
+
async function loadGeoTiff(source, opts = {}) {
|
|
380
|
+
const { headers, offsets } = opts;
|
|
381
|
+
let tiff;
|
|
382
|
+
if (source instanceof import_geotiff.GeoTIFF) {
|
|
383
|
+
tiff = source;
|
|
384
|
+
} else if (typeof source === "string") {
|
|
385
|
+
tiff = await (0, import_geotiff.fromUrl)(source, headers);
|
|
386
|
+
} else {
|
|
387
|
+
tiff = await (0, import_geotiff.fromBlob)(source);
|
|
388
|
+
}
|
|
389
|
+
if (offsets) {
|
|
390
|
+
tiff = createOffsetsProxy(tiff, offsets);
|
|
391
|
+
}
|
|
392
|
+
checkProxies(tiff);
|
|
393
|
+
const firstImage = await tiff.getImage(0);
|
|
394
|
+
if (isOmeTiff(firstImage)) {
|
|
395
|
+
return loadOmeTiff(tiff, firstImage);
|
|
396
|
+
}
|
|
397
|
+
throw new Error("GeoTIFF not recognized.");
|
|
398
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["loadGeoTiff","default","TiffPixelSource"],"sources":["../src/index.ts"],"sourcesContent":["export {loadGeoTiff} from './lib/load-geotiff';\nexport {default as TiffPixelSource} from './lib/tiff-pixel-source';\n"],"mappings":"SAAQA,WAAW;AAAA,SACXC,OAAO,IAAIC,eAAe"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { fromUrl, fromBlob, GeoTIFF } from 'geotiff';
|
|
2
|
-
import { createOffsetsProxy, checkProxies } from
|
|
3
|
-
import { loadOmeTiff, isOmeTiff } from
|
|
2
|
+
import { createOffsetsProxy, checkProxies } from "./utils/proxies.js";
|
|
3
|
+
import { loadOmeTiff, isOmeTiff } from "./ome/load-ome-tiff.js";
|
|
4
4
|
export async function loadGeoTiff(source) {
|
|
5
5
|
let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
6
6
|
const {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-geotiff.js","names":["fromUrl","fromBlob","GeoTIFF","createOffsetsProxy","checkProxies","loadOmeTiff","isOmeTiff","loadGeoTiff","source","opts","arguments","length","undefined","headers","offsets","tiff","firstImage","getImage","Error"],"sources":["../../src/lib/load-geotiff.ts"],"sourcesContent":["import {fromUrl, fromBlob, GeoTIFF} from 'geotiff';\n\nimport {\n // createPoolProxy,\n createOffsetsProxy,\n checkProxies\n} from './utils/proxies';\n// import Pool from './lib/Pool';\n\nimport {loadOmeTiff, isOmeTiff} from './ome/load-ome-tiff';\nimport type TiffPixelSource from './tiff-pixel-source';\n\n/** Options for initializing a tiff pixel source. */\ninterface GeoTIFFOptions {\n /** Headers passed to each underlying request. */\n headers?: Record<string, unknown>;\n /** Performance enhancment to index the remote tiff source using pre-computed byte-offsets. Generated via https://github.com/ilan-gold/generate-tiff-offsets */\n offsets?: number[];\n /** Indicates whether a multi-threaded pool of image decoders should be used to decode tiles. */\n pool?: boolean;\n}\n\ninterface GeoTIFFData {\n data: TiffPixelSource<string[]>[];\n metadata: Record<string, unknown>;\n}\n\n/**\n * Opens an OME-TIFF via URL and returns data source and associated metadata for first image.\n *\n * @param source url string, File/Blob object, or GeoTIFF object\n * @param opts options for initializing a tiff pixel source.\n * - `opts.headers` are passed to each underlying fetch request.\n * - `opts.offsets` are a performance enhancment to index the remote tiff source using pre-computed byte-offsets.\n * - `opts.pool` indicates whether a multi-threaded pool of image decoders should be used to decode tiles (default = true).\n * @return data source and associated OME-Zarr metadata.\n */\nexport async function loadGeoTiff(\n source: string | Blob | GeoTIFF,\n opts: GeoTIFFOptions = {}\n): Promise<GeoTIFFData> {\n const {headers, offsets} = opts;\n\n // Create tiff source\n let tiff: GeoTIFF;\n if (source instanceof GeoTIFF) {\n tiff = source;\n } else if (typeof source === 'string') {\n tiff = await fromUrl(source, headers);\n } else {\n tiff = await fromBlob(source);\n }\n\n // if (pool) {\n /*\n * Creates a worker pool to decode tiff tiles. Wraps tiff\n * in a Proxy that injects 'pool' into `tiff.readRasters`.\n */\n // tiff = createPoolProxy(tiff, new Pool());\n // }\n\n if (offsets) {\n /*\n * Performance enhancement. If offsets are provided, we\n * create a proxy that intercepts calls to `tiff.getImage`\n * and injects the pre-computed offsets.\n */\n tiff = createOffsetsProxy(tiff, offsets);\n }\n\n /*\n * Inspect tiff source for our performance enhancing proxies.\n * Prints warnings to console if `offsets` or `pool` are missing.\n */\n checkProxies(tiff);\n\n const firstImage = await tiff.getImage(0);\n\n if (isOmeTiff(firstImage)) {\n return loadOmeTiff(tiff, firstImage);\n }\n\n throw new Error('GeoTIFF not recognized.');\n}\n"],"mappings":"AAAA,SAAQA,OAAO,EAAEC,QAAQ,EAAEC,OAAO,QAAO,SAAS;AAAC,SAIjDC,kBAAkB,EAClBC,YAAY;AAAA,SAINC,WAAW,EAAEC,SAAS;AA4B9B,OAAO,eAAeC,WAAWA,CAC/BC,MAA+B,EAET;EAAA,IADtBC,IAAoB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAEzB,MAAM;IAACG,OAAO;IAAEC;EAAO,CAAC,GAAGL,IAAI;EAG/B,IAAIM,IAAa;EACjB,IAAIP,MAAM,YAAYN,OAAO,EAAE;IAC7Ba,IAAI,GAAGP,MAAM;EACf,CAAC,MAAM,IAAI,OAAOA,MAAM,KAAK,QAAQ,EAAE;IACrCO,IAAI,GAAG,MAAMf,OAAO,CAACQ,MAAM,EAAEK,OAAO,CAAC;EACvC,CAAC,MAAM;IACLE,IAAI,GAAG,MAAMd,QAAQ,CAACO,MAAM,CAAC;EAC/B;EAUA,IAAIM,OAAO,EAAE;IAMXC,IAAI,GAAGZ,kBAAkB,CAACY,IAAI,EAAED,OAAO,CAAC;EAC1C;EAMAV,YAAY,CAACW,IAAI,CAAC;EAElB,MAAMC,UAAU,GAAG,MAAMD,IAAI,CAACE,QAAQ,CAAC,CAAC,CAAC;EAEzC,IAAIX,SAAS,CAACU,UAAU,CAAC,EAAE;IACzB,OAAOX,WAAW,CAACU,IAAI,EAAEC,UAAU,CAAC;EACtC;EAEA,MAAM,IAAIE,KAAK,CAAC,yBAAyB,CAAC;AAC5C"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import TiffPixelSource from
|
|
2
|
-
import { getOmeLegacyIndexer, getOmeSubIFDIndexer } from
|
|
3
|
-
import { getOmePixelSourceMeta } from
|
|
4
|
-
import { fromString } from
|
|
1
|
+
import TiffPixelSource from "../tiff-pixel-source.js";
|
|
2
|
+
import { getOmeLegacyIndexer, getOmeSubIFDIndexer } from "./ome-indexers.js";
|
|
3
|
+
import { getOmePixelSourceMeta } from "./ome-utils.js";
|
|
4
|
+
import { fromString } from "./omexml.js";
|
|
5
5
|
export const isOmeTiff = img => img.fileDirectory.ImageDescription.includes('<OME');
|
|
6
6
|
export async function loadOmeTiff(tiff, firstImage) {
|
|
7
7
|
const {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-ome-tiff.js","names":["TiffPixelSource","getOmeLegacyIndexer","getOmeSubIFDIndexer","getOmePixelSourceMeta","fromString","isOmeTiff","img","fileDirectory","ImageDescription","includes","loadOmeTiff","tiff","firstImage","SubIFDs","PhotometricInterpretation","photometricInterpretation","omexml","levels","pyramidIndexer","length","imgMeta","labels","getShape","physicalSizes","dtype","tileSize","getTileWidth","meta","data","Array","from","map","_","resolution","shape","indexer","sel","source","metadata"],"sources":["../../../src/lib/ome/load-ome-tiff.ts"],"sourcesContent":["import type {GeoTIFF, GeoTIFFImage} from 'geotiff';\n\nimport TiffPixelSource from '../tiff-pixel-source';\nimport {getOmeLegacyIndexer, getOmeSubIFDIndexer, OmeTiffIndexer} from './ome-indexers';\nimport {getOmePixelSourceMeta} from './ome-utils';\nimport {fromString} from './omexml';\nimport type {OmeTiffSelection} from './ome-indexers';\n\nexport const isOmeTiff = (img: GeoTIFFImage) => img.fileDirectory.ImageDescription.includes('<OME');\n\nexport async function loadOmeTiff(tiff: GeoTIFF, firstImage: GeoTIFFImage) {\n // Get first image from tiff and inspect OME-XML metadata\n const {\n ImageDescription,\n SubIFDs,\n PhotometricInterpretation: photometricInterpretation\n } = firstImage.fileDirectory;\n const omexml = fromString(ImageDescription);\n\n /*\n * Image pyramids are stored differently between versions of Bioformats.\n * Thus we need a different indexer depending on which format we have.\n */\n let levels: number;\n let pyramidIndexer: OmeTiffIndexer;\n\n if (SubIFDs) {\n // Image is >= Bioformats 6.0 and resolutions are stored using SubIFDs.\n levels = SubIFDs.length + 1;\n pyramidIndexer = getOmeSubIFDIndexer(tiff, omexml);\n } else {\n // Image is legacy format; resolutions are stored as separate images.\n levels = omexml.length;\n pyramidIndexer = getOmeLegacyIndexer(tiff, omexml);\n }\n\n // TODO: The OmeTIFF loader only works for the _first_ image in the metadata.\n const imgMeta = omexml[0];\n const {labels, getShape, physicalSizes, dtype} = getOmePixelSourceMeta(imgMeta);\n const tileSize = firstImage.getTileWidth();\n const meta = {photometricInterpretation, physicalSizes};\n\n const data = Array.from({length: levels}).map((_, resolution) => {\n const shape = getShape(resolution);\n const indexer = (sel: OmeTiffSelection) => pyramidIndexer(sel, resolution);\n const source = new TiffPixelSource(indexer, dtype, tileSize, shape, labels, meta);\n return source;\n });\n\n return {data, metadata: imgMeta};\n}\n"],"mappings":"OAEOA,eAAe;AAAA,SACdC,mBAAmB,EAAEC,mBAAmB;AAAA,SACxCC,qBAAqB;AAAA,SACrBC,UAAU;AAGlB,OAAO,MAAMC,SAAS,GAAIC,GAAiB,IAAKA,GAAG,CAACC,aAAa,CAACC,gBAAgB,CAACC,QAAQ,CAAC,MAAM,CAAC;AAEnG,OAAO,eAAeC,WAAWA,CAACC,IAAa,EAAEC,UAAwB,EAAE;EAEzE,MAAM;IACJJ,gBAAgB;IAChBK,OAAO;IACPC,yBAAyB,EAAEC;EAC7B,CAAC,GAAGH,UAAU,CAACL,aAAa;EAC5B,MAAMS,MAAM,GAAGZ,UAAU,CAACI,gBAAgB,CAAC;EAM3C,IAAIS,MAAc;EAClB,IAAIC,cAA8B;EAElC,IAAIL,OAAO,EAAE;IAEXI,MAAM,GAAGJ,OAAO,CAACM,MAAM,GAAG,CAAC;IAC3BD,cAAc,GAAGhB,mBAAmB,CAACS,IAAI,EAAEK,MAAM,CAAC;EACpD,CAAC,MAAM;IAELC,MAAM,GAAGD,MAAM,CAACG,MAAM;IACtBD,cAAc,GAAGjB,mBAAmB,CAACU,IAAI,EAAEK,MAAM,CAAC;EACpD;EAGA,MAAMI,OAAO,GAAGJ,MAAM,CAAC,CAAC,CAAC;EACzB,MAAM;IAACK,MAAM;IAAEC,QAAQ;IAAEC,aAAa;IAAEC;EAAK,CAAC,GAAGrB,qBAAqB,CAACiB,OAAO,CAAC;EAC/E,MAAMK,QAAQ,GAAGb,UAAU,CAACc,YAAY,CAAC,CAAC;EAC1C,MAAMC,IAAI,GAAG;IAACZ,yBAAyB;IAAEQ;EAAa,CAAC;EAEvD,MAAMK,IAAI,GAAGC,KAAK,CAACC,IAAI,CAAC;IAACX,MAAM,EAAEF;EAAM,CAAC,CAAC,CAACc,GAAG,CAAC,CAACC,CAAC,EAAEC,UAAU,KAAK;IAC/D,MAAMC,KAAK,GAAGZ,QAAQ,CAACW,UAAU,CAAC;IAClC,MAAME,OAAO,GAAIC,GAAqB,IAAKlB,cAAc,CAACkB,GAAG,EAAEH,UAAU,CAAC;IAC1E,MAAMI,MAAM,GAAG,IAAIrC,eAAe,CAACmC,OAAO,EAAEX,KAAK,EAAEC,QAAQ,EAAES,KAAK,EAAEb,MAAM,EAAEM,IAAI,CAAC;IACjF,OAAOU,MAAM;EACf,CAAC,CAAC;EAEF,OAAO;IAACT,IAAI;IAAEU,QAAQ,EAAElB;EAAO,CAAC;AAClC"}
|
|
@@ -28,7 +28,7 @@ export function getOmeSubIFDIndexer(tiff, rootMeta) {
|
|
|
28
28
|
if (!SubIFDs) {
|
|
29
29
|
throw Error('Indexing Error: OME-TIFF is missing SubIFDs.');
|
|
30
30
|
}
|
|
31
|
-
const key =
|
|
31
|
+
const key = `${sel.t}-${sel.c}-${sel.z}-${pyramidLevel}`;
|
|
32
32
|
if (!ifdCache.has(key)) {
|
|
33
33
|
const subIfdOffset = SubIFDs[pyramidLevel - 1];
|
|
34
34
|
ifdCache.set(key, tiff.parseFileDirectoryAt(subIfdOffset));
|
|
@@ -113,7 +113,7 @@ function getOmeIFDIndexer(imgMeta) {
|
|
|
113
113
|
}
|
|
114
114
|
default:
|
|
115
115
|
{
|
|
116
|
-
throw new Error(
|
|
116
|
+
throw new Error(`Invalid OME-XML DimensionOrder, got ${DimensionOrder}.`);
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ome-indexers.js","names":["getOmeLegacyIndexer","tiff","rootMeta","imgMeta","SizeT","SizeC","SizeZ","Pixels","ifdIndexer","getOmeIFDIndexer","sel","pyramidLevel","index","pyramidIndex","getImage","getOmeSubIFDIndexer","ifdCache","Map","baseImage","SubIFDs","fileDirectory","Error","key","t","c","z","has","subIfdOffset","set","parseFileDirectoryAt","ifd","get","constructor","geoKeyDirectory","dataView","littleEndian","cache","source","DimensionOrder","_ref","_ref2","_ref3","_ref4","_ref5","_ref6"],"sources":["../../../src/lib/ome/ome-indexers.ts"],"sourcesContent":["import type {GeoTIFFImage, GeoTIFF, ImageFileDirectory} from 'geotiff';\nimport type {OMEXML} from '../ome/omexml';\n\nexport type OmeTiffSelection = {t: number; c: number; z: number};\nexport type OmeTiffIndexer = (sel: OmeTiffSelection, z: number) => Promise<GeoTIFFImage>;\n\n/*\n * An \"indexer\" for a GeoTIFF-based source is a function that takes a\n * \"selection\" (e.g. { z, t, c }) and returns a Promise for the GeoTIFFImage\n * object corresponding to that selection.\n *\n * For OME-TIFF images, the \"selection\" object is the same regardless of\n * the format version. However, modern version of Bioformats have a different\n * memory layout for pyramidal resolutions. Thus, we have two different \"indexers\"\n * depending on which format version is detected.\n *\n * TODO: We currently only support indexing the first image in the OME-TIFF with\n * our indexers. There can be multiple images in an OME-TIFF, so supporting these\n * images will require extending these indexers or creating new methods.\n */\n\n/*\n * Returns an indexer for legacy Bioformats images. This assumes that\n * downsampled resolutions are stored sequentially in the OME-TIFF.\n */\nexport function getOmeLegacyIndexer(tiff: GeoTIFF, rootMeta: OMEXML): OmeTiffIndexer {\n const imgMeta = rootMeta[0];\n const {SizeT, SizeC, SizeZ} = imgMeta.Pixels;\n const ifdIndexer = getOmeIFDIndexer(imgMeta);\n\n return (sel: OmeTiffSelection, pyramidLevel: number) => {\n // Get IFD index at base pyramid level\n const index = ifdIndexer(sel);\n // Get index of first image at pyramidal level\n const pyramidIndex = pyramidLevel * SizeZ * SizeT * SizeC;\n // Return image at IFD index for pyramidal level\n return tiff.getImage(index + pyramidIndex);\n };\n}\n\n/*\n * Returns an indexer for modern Bioforamts images that store multiscale\n * resolutions using SubIFDs.\n *\n * The ifdIndexer returns the 'index' to the base resolution for a\n * particular 'selection'. The SubIFDs to the downsampled resolutions\n * of the 'selection' are stored within the `baseImage.fileDirectory`.\n * We use the SubIFDs to get the IFD for the corresponding sub-resolution.\n *\n * NOTE: This function create a custom IFD cache rather than mutating\n * `GeoTIFF.ifdRequests` with a random offset. The IFDs are cached in\n * an ES6 Map that maps a string key that identifies the selection uniquely\n * to the corresponding IFD.\n */\nexport function getOmeSubIFDIndexer(tiff: GeoTIFF, rootMeta: OMEXML): OmeTiffIndexer {\n const imgMeta = rootMeta[0];\n const ifdIndexer = getOmeIFDIndexer(imgMeta);\n const ifdCache: Map<string, Promise<ImageFileDirectory>> = new Map();\n\n return async (sel: OmeTiffSelection, pyramidLevel: number) => {\n const index = ifdIndexer(sel);\n const baseImage = await tiff.getImage(index);\n\n // It's the highest resolution, no need to look up SubIFDs.\n if (pyramidLevel === 0) {\n return baseImage;\n }\n\n const {SubIFDs} = baseImage.fileDirectory;\n if (!SubIFDs) {\n throw Error('Indexing Error: OME-TIFF is missing SubIFDs.');\n }\n\n // Get IFD for the selection at the pyramidal level\n const key = `${sel.t}-${sel.c}-${sel.z}-${pyramidLevel}`;\n if (!ifdCache.has(key)) {\n // Only create a new request if we don't have the key.\n const subIfdOffset = SubIFDs[pyramidLevel - 1];\n ifdCache.set(key, tiff.parseFileDirectoryAt(subIfdOffset));\n }\n const ifd = (await ifdCache.get(key)) as ImageFileDirectory;\n\n // Create a new image object manually from IFD\n // https://github.com/geotiffjs/geotiff.js/blob/8ef472f41b51d18074aece2300b6a8ad91a21ae1/src/geotiff.js#L447-L453\n return new (baseImage.constructor as any)(\n ifd.fileDirectory,\n ifd.geoKeyDirectory,\n tiff.dataView,\n tiff.littleEndian,\n tiff.cache,\n tiff.source\n ) as GeoTIFFImage;\n };\n}\n\n/*\n * Returns a function that computes the image index based on the dimension\n * order and dimension sizes.\n */\nfunction getOmeIFDIndexer(imgMeta: OMEXML[0]): (sel: OmeTiffSelection) => number {\n const {SizeC, SizeZ, SizeT, DimensionOrder} = imgMeta.Pixels;\n switch (DimensionOrder) {\n case 'XYZCT': {\n return ({t, c, z}) => t * SizeZ * SizeC + c * SizeZ + z;\n }\n case 'XYZTC': {\n return ({t, c, z}) => c * SizeZ * SizeT + t * SizeZ + z;\n }\n case 'XYCTZ': {\n return ({t, c, z}) => z * SizeC * SizeT + t * SizeC + c;\n }\n case 'XYCZT': {\n return ({t, c, z}) => t * SizeC * SizeZ + z * SizeC + c;\n }\n case 'XYTCZ': {\n return ({t, c, z}) => z * SizeT * SizeC + c * SizeT + t;\n }\n case 'XYTZC': {\n return ({t, c, z}) => c * SizeT * SizeZ + z * SizeT + t;\n }\n default: {\n throw new Error(`Invalid OME-XML DimensionOrder, got ${DimensionOrder}.`);\n }\n }\n}\n"],"mappings":"AAyBA,OAAO,SAASA,mBAAmBA,CAACC,IAAa,EAAEC,QAAgB,EAAkB;EACnF,MAAMC,OAAO,GAAGD,QAAQ,CAAC,CAAC,CAAC;EAC3B,MAAM;IAACE,KAAK;IAAEC,KAAK;IAAEC;EAAK,CAAC,GAAGH,OAAO,CAACI,MAAM;EAC5C,MAAMC,UA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,OAAKnB,CAAC,GAAGlB,KAAK,GAAGC,KAAK,GAAGmB,CAAC,GAAGpB,KAAK,GAAGmB,CAAC;QAAA;MACzD;IACA,KAAK,OAAO;MAAE;QACZ,OAAOmB,KAAA;UAAA,IAAC;YAACpB,CAAC;YAAEC,CAAC;YAAEC;UAAC,CAAC,GAAAkB,KAAA;UAAA,OAAKlB,CAAC,GAAGrB,KAAK,GAAGC,KAAK,GAAGmB,CAAC,GAAGpB,KAAK,GAAGmB,CAAC;QAAA;MACzD;IACA,KAAK,OAAO;MAAE;QACZ,OAAOqB,KAAA;UAAA,IAAC;YAACrB,CAAC;YAAEC,CAAC;YAAEC;UAAC,CAAC,GAAAmB,KAAA;UAAA,OAAKpB,CAAC,GAAGpB,KAAK,GAAGE,KAAK,GAAGmB,CAAC,GAAGrB,KAAK,GAAGmB,CAAC;QAAA;MACzD;IACA;MAAS;QACP,MAAM,IAAIF,KAAK,CAAE,uCAAsCiB,cAAe,GAAE,CAAC;MAC3E;EACF;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getDims, getLabels } from
|
|
1
|
+
import { getDims, getLabels } from "./utils.js";
|
|
2
2
|
export const DTYPE_LOOKUP = {
|
|
3
3
|
uint8: 'Uint8',
|
|
4
4
|
uint16: 'Uint16',
|
|
@@ -30,7 +30,7 @@ export function getOmePixelSourceMeta(_ref) {
|
|
|
30
30
|
return s;
|
|
31
31
|
};
|
|
32
32
|
if (!(Pixels.Type in DTYPE_LOOKUP)) {
|
|
33
|
-
throw Error(
|
|
33
|
+
throw Error(`Pixel type ${Pixels.Type} not supported.`);
|
|
34
34
|
}
|
|
35
35
|
const dtype = DTYPE_LOOKUP[Pixels.Type];
|
|
36
36
|
if (Pixels.PhysicalSizeX && Pixels.PhysicalSizeY) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ome-utils.js","names":["getDims","getLabels","DTYPE_LOOKUP","uint8","uint16","uint32","float","double","int8","int16","int32","getOmePixelSourceMeta","_ref","Pixels","labels","DimensionOrder","dims","shape","Array","length","fill","SizeT","SizeC","SizeZ","Interleaved","push","getShape","level","s","SizeX","SizeY","Type","Error","dtype","PhysicalSizeX","PhysicalSizeY","physicalSizes","x","size","unit","PhysicalSizeXUnit","y","PhysicalSizeYUnit","PhysicalSizeZ","z","PhysicalSizeZUnit"],"sources":["../../../src/lib/ome/ome-utils.ts"],"sourcesContent":["import {getDims, getLabels} from './utils';\nimport type {OMEXML, UnitsLength} from './omexml';\n\nexport const DTYPE_LOOKUP = {\n uint8: 'Uint8',\n uint16: 'Uint16',\n uint32: 'Uint32',\n float: 'Float32',\n double: 'Float64',\n int8: 'Int8',\n int16: 'Int16',\n int32: 'Int32'\n} as const;\n\nexport function getOmePixelSourceMeta({Pixels}: OMEXML[0]) {\n // e.g. 'XYZCT' -> ['t', 'c', 'z', 'y', 'x']\n const labels = getLabels(Pixels.DimensionOrder);\n\n // Compute \"shape\" of image\n const dims = getDims(labels);\n const shape: number[] = Array(labels.length).fill(0);\n shape[dims('t')] = Pixels.SizeT;\n shape[dims('c')] = Pixels.SizeC;\n shape[dims('z')] = Pixels.SizeZ;\n\n // Push extra dimension if data are interleaved.\n if (Pixels.Interleaved) {\n // @ts-ignore\n labels.push('_c');\n shape.push(3);\n }\n\n // Creates a new shape for different level of pyramid.\n // Assumes factor-of-two downsampling.\n const getShape = (level: number) => {\n const s = [...shape];\n s[dims('x')] = Pixels.SizeX >> level;\n s[dims('y')] = Pixels.SizeY >> level;\n return s;\n };\n\n if (!(Pixels.Type in DTYPE_LOOKUP)) {\n throw Error(`Pixel type ${Pixels.Type} not supported.`);\n }\n\n const dtype = DTYPE_LOOKUP[Pixels.Type as keyof typeof DTYPE_LOOKUP];\n if (Pixels.PhysicalSizeX && Pixels.PhysicalSizeY) {\n const physicalSizes: {\n [k: string]: {size: number; unit: UnitsLength};\n } = {\n x: {\n size: Pixels.PhysicalSizeX,\n unit: Pixels.PhysicalSizeXUnit\n },\n y: {\n size: Pixels.PhysicalSizeY,\n unit: Pixels.PhysicalSizeYUnit\n }\n };\n if (Pixels.PhysicalSizeZ) {\n physicalSizes.z = {\n size: Pixels.PhysicalSizeZ,\n unit: Pixels.PhysicalSizeZUnit\n };\n }\n return {labels, getShape, physicalSizes, dtype};\n }\n\n return {labels, getShape, dtype};\n}\n"],"mappings":"SAAQA,OAAO,EAAEC,SAAS;AAG1B,OAAO,MAAMC,YAAY,GAAG;EAC1BC,KAAK,EAAE,OAAO;EACdC,MAAM,EAAE,QAAQ;EAChBC,MAAM,EAAE,QAAQ;EAChBC,KAAK,EAAE,SAAS;EAChBC,MAAM,EAAE,SAAS;EACjBC,IAAI,EAAE,MAAM;EACZC,KAAK,EAAE,OAAO;EACdC,KAAK,EAAE;AACT,CAAU;AAEV,OAAO,SAASC,qBAAqBA,CAAAC,IAAA,EAAsB;EAAA,IAArB;IAACC;EAAiB,CAAC,GAAAD,IAAA;EAEvD,MAAME,MAAM,GAAGb,SAAS,CAACY,MAAM,CAACE,cAAc,CAAC;EAG/C,MAAMC,IAAI,GAAGhB,OAAO,CAACc,MAAM,CAAC;EAC5B,MAAMG,KAAe,GAAGC,KAAK,CAACJ,MAAM,CAACK,MAAM,CAAC,CAACC,IAAI,CAAC,CAAC,CAAC;EACpDH,KAAK,CAACD,IAAI,CAAC,GAAG,CAAC,CAAC,GAAGH,MAAM,CAACQ,KAAK;EAC/BJ,KAAK,CAACD,IAAI,CAAC,GAAG,CAAC,CAAC,GAAGH,MAAM,CAACS,KAAK;EAC/BL,KAAK,CAACD,IAAI,CAAC,GAAG,CAAC,CAAC,GAAGH,MAAM,CAACU,KAAK;EAG/B,IAAIV,MAAM,CAACW,WAAW,EAAE;IAEtBV,MAAM,CAACW,IAAI,CAAC,IAAI,CAAC;IACjBR,KAAK,CAACQ,IAAI,CAAC,CAAC,CAAC;EACf;EAIA,MAAMC,QAAQ,GAAIC,KAAa,IAAK;IAClC,MAAMC,CAAC,GAAG,CAAC,GAAGX,KAAK,CAAC;IACpBW,CAAC,CAACZ,IAAI,CAAC,GAAG,CAAC,CAAC,GAAGH,MAAM,CAACgB,KAAK,IAAIF,KAAK;IACpCC,CAAC,CAACZ,IAAI,CAAC,GAAG,CAAC,CAAC,GAAGH,MAAM,CAACiB,KAAK,IAAIH,KAAK;IACpC,OAAOC,CAAC;EACV,CAAC;EAED,IAAI,EAAEf,MAAM,CAACkB,IAAI,IAAI7B,YAAY,CAAC,EAAE;IAClC,MAAM8B,KAAK,CAAE,cAAanB,MAAM,CAACkB,IAAK,iBAAgB,CAAC;EACzD;EAEA,MAAME,KAAK,GAAG/B,YAAY,CAACW,MAAM,CAACkB,IAAI,CAA8B;EACpE,IAAIlB,MAAM,CAACqB,aAAa,IAAIrB,MAAM,CAACsB,aAAa,EAAE;IAChD,MAAMC,aAEL,GAAG;MACFC,CAAC,EAAE;QACDC,IAAI,EAAEzB,MAAM,CAACqB,aAAa;QAC1BK,IAAI,EAAE1B,MAAM,CAAC2B;MACf,CAAC;MACDC,CAAC,EAAE;QACDH,IAAI,EAAEzB,MAAM,CAACsB,aAAa;QAC1BI,IAAI,EAAE1B,MAAM,CAAC6B;MACf;IACF,CAAC;IACD,IAAI7B,MAAM,CAAC8B,aAAa,EAAE;MACxBP,aAAa,CAACQ,CAAC,GAAG;QAChBN,IAAI,EAAEzB,MAAM,CAAC8B,aAAa;QAC1BJ,IAAI,EAAE1B,MAAM,CAACgC;MACf,CAAC;IACH;IACA,OAAO;MAAC/B,MAAM;MAAEY,QAAQ;MAAEU,aAAa;MAAEH;IAAK,CAAC;EACjD;EAEA,OAAO;IAACnB,MAAM;IAAEY,QAAQ;IAAEO;EAAK,CAAC;AAClC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { XMLParser } from 'fast-xml-parser';
|
|
2
|
-
import { ensureArray, intToRgba } from
|
|
2
|
+
import { ensureArray, intToRgba } from "../utils/tiff-utils.js";
|
|
3
3
|
const xmlParser = new XMLParser({
|
|
4
4
|
attributeNamePrefix: '',
|
|
5
5
|
attributesGroupName: 'attr',
|
|
@@ -45,16 +45,16 @@ export function fromString(str) {
|
|
|
45
45
|
Pixels
|
|
46
46
|
} = image;
|
|
47
47
|
const sizes = ['X', 'Y', 'Z'].map(name => {
|
|
48
|
-
const size = Pixels[
|
|
49
|
-
const unit = Pixels[
|
|
50
|
-
return size && unit ?
|
|
48
|
+
const size = Pixels[`PhysicalSize${name}`];
|
|
49
|
+
const unit = Pixels[`PhysicalSize${name}Unit`];
|
|
50
|
+
return size && unit ? `${size} ${unit}` : '-';
|
|
51
51
|
}).join(' x ');
|
|
52
52
|
return {
|
|
53
53
|
'Acquisition Date': image.AquisitionDate,
|
|
54
|
-
'Dimensions (XY)':
|
|
54
|
+
'Dimensions (XY)': `${Pixels.SizeX} x ${Pixels.SizeY}`,
|
|
55
55
|
'Pixels Type': Pixels.Type,
|
|
56
56
|
'Pixels Size (XYZ)': sizes,
|
|
57
|
-
'Z-sections/Timepoints':
|
|
57
|
+
'Z-sections/Timepoints': `${Pixels.SizeZ} x ${Pixels.SizeT}`,
|
|
58
58
|
Channels: Pixels.SizeC
|
|
59
59
|
};
|
|
60
60
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"omexml.js","names":["XMLParser","ensureArray","intToRgba","xmlParser","attributeNamePrefix","attributesGroupName","parseTagValue","parseAttributeValue","ignoreAttributes","parse","str","fromString","res","OME","Error","Image","map","img","Channels","Pixels","Channel","c","attr","Color","AquisitionDate","Description","image","format","sizes","name","size","unit","join","SizeX","SizeY","Type","SizeZ","SizeT","SizeC"],"sources":["../../../src/lib/ome/omexml.ts"],"sourcesContent":["import {XMLParser} from 'fast-xml-parser';\nimport {ensureArray, intToRgba} from '../utils/tiff-utils';\n\n// WARNING: Changes to the parser options _will_ effect the types in types/omexml.d.ts.\nconst xmlParser = new XMLParser({\n // Nests attributes withtout prefix under 'attr' key for each node\n attributeNamePrefix: '',\n attributesGroupName: 'attr',\n\n // Parses numbers for both attributes and nodes\n parseTagValue: true,\n parseAttributeValue: true,\n\n // Forces attributes to be parsed\n ignoreAttributes: false\n});\n\nconst parse = (str: string): Root => xmlParser.parse(str);\n\nexport function fromString(str: string) {\n const res = parse(str);\n if (!res.OME) {\n throw Error('Failed to parse OME-XML metadata.');\n }\n return ensureArray(res.OME.Image).map((img) => {\n const Channels = ensureArray(img.Pixels.Channel).map((c) => {\n if ('Color' in c.attr) {\n return {...c.attr, Color: intToRgba(c.attr.Color)};\n }\n return {...c.attr};\n });\n const {AquisitionDate = '', Description = ''} = img;\n const image = {\n ...img.attr,\n AquisitionDate,\n Description,\n Pixels: {\n ...img.Pixels.attr,\n Channels\n }\n };\n return {\n ...image,\n format() {\n const {Pixels} = image;\n\n const sizes = (['X', 'Y', 'Z'] as const)\n .map((name) => {\n const size = Pixels[`PhysicalSize${name}` as const];\n const unit = Pixels[`PhysicalSize${name}Unit` as const];\n return size && unit ? `${size} ${unit}` : '-';\n })\n .join(' x ');\n\n return {\n 'Acquisition Date': image.AquisitionDate,\n 'Dimensions (XY)': `${Pixels.SizeX} x ${Pixels.SizeY}`,\n 'Pixels Type': Pixels.Type,\n 'Pixels Size (XYZ)': sizes,\n 'Z-sections/Timepoints': `${Pixels.SizeZ} x ${Pixels.SizeT}`,\n Channels: Pixels.SizeC\n };\n }\n };\n });\n}\n\nexport type OMEXML = ReturnType<typeof fromString>;\nexport type DimensionOrder = 'XYZCT' | 'XYZTC' | 'XYCTZ' | 'XYCZT' | 'XYTCZ' | 'XYTZC';\n\n// Structure of node is determined by the PARSER_OPTIONS.\ntype Node<T, A> = T & {attr: A};\ntype Attrs<Fields extends string, T = string> = {[K in Fields]: T};\n\ntype OMEAttrs = Attrs<'xmlns' | 'xmlns:xsi' | 'xsi:schemaLocation'>;\ntype OME = Node<{Insturment: Insturment; Image: Image | Image[]}, OMEAttrs>;\n\ntype Insturment = Node<\n {Objective: Node<{}, Attrs<'ID' | 'Model' | 'NominalMagnification'>>},\n Attrs<'ID'>\n>;\n\ninterface ImageNodes {\n AquisitionDate?: string;\n Description?: string;\n Pixels: Pixels;\n InstrumentRef: Node<{}, {ID: string}>;\n ObjectiveSettings: Node<{}, {ID: string}>;\n}\ntype Image = Node<ImageNodes, Attrs<'ID' | 'Name'>>;\n\ntype PixelType =\n | 'int8'\n | 'int16'\n | 'int32'\n | 'uint8'\n | 'uint16'\n | 'uint32'\n | 'float'\n | 'bit'\n | 'double'\n | 'complex'\n | 'double-complex';\n\nexport type UnitsLength =\n | 'Ym'\n | 'Zm'\n | 'Em'\n | 'Pm'\n | 'Tm'\n | 'Gm'\n | 'Mm'\n | 'km'\n | 'hm'\n | 'dam'\n | 'm'\n | 'dm'\n | 'cm'\n | 'mm'\n | 'µm'\n | 'nm'\n | 'pm'\n | 'fm'\n | 'am'\n | 'zm'\n | 'ym'\n | 'Å'\n | 'thou'\n | 'li'\n | 'in'\n | 'ft'\n | 'yd'\n | 'mi'\n | 'ua'\n | 'ly'\n | 'pc'\n | 'pt'\n | 'pixel'\n | 'reference frame';\n\ntype PhysicalSize<Name extends string> = `PhysicalSize${Name}`;\ntype PhysicalSizeUnit<Name extends string> = `PhysicalSize${Name}Unit`;\ntype Size<Names extends string> = `Size${Names}`;\n\ntype PixelAttrs = Attrs<\n PhysicalSize<'X' | 'Y' | 'Z'> | 'SignificantBits' | Size<'T' | 'C' | 'Z' | 'Y' | 'X'>,\n number\n> &\n Attrs<PhysicalSizeUnit<'X' | 'Y' | 'Z'>, UnitsLength> &\n Attrs<'BigEndian' | 'Interleaved', boolean> & {\n ID: string;\n DimensionOrder: DimensionOrder;\n Type: PixelType;\n };\n\ntype Pixels = Node<\n {\n Channel: Channel | Channel[];\n TiffData: Node<{}, Attrs<'IFD' | 'PlaneCount'>>;\n },\n PixelAttrs\n>;\n\ntype ChannelAttrs =\n | {\n ID: string;\n SamplesPerPixel: number;\n Name?: string;\n }\n | {\n ID: string;\n SamplesPerPixel: number;\n Name?: string;\n Color: number;\n };\n\ntype Channel = Node<{},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ClBJ;MACF;IACF,CAAC;IACD,OAAO;MACL,GAAGQ,KAAK;MACRC,MAAMA,CAAA,EAAG;QACP,MAAM;UAACR;QAAM,CAAC,GAAGO,KAAK;QAEtB,MAAME,KAAK,GAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAC3BZ,GAAG,CAAEa,IAAI,IAAK;UACb,MAAMC,IAAI,GAAGX,MAAM,CAAE,eAAcU,IAAK,EAAC,CAAU;UACnD,MAAME,IAAI,GAAGZ,MAAM,CAAE,eAAcU,IAAK,MAAK,CAAU;UACvD,OAAOC,IAAI,IAAIC,IAAI,GAAI,GAAED,IAAK,IAAGC,IAAK,EAAC,GAAG,GAAG;QAC/C,CAAC,CAAC,CACDC,IAAI,CAAC,KAAK,CAAC;QAEd,OAAO;UACL,kBAAkB,EAAEN,KAAK,CAACF,cAAc;UACxC,iBAAiB,EAAG,GAAEL,MAAM,CAACc,KAAM,MAAKd,MAAM,CAACe,KAAM,EAAC;UACtD,aAAa,EAAEf,MAAM,CAACgB,IAAI;UAC1B,mBAAmB,EAAEP,KAAK;UAC1B,uBAAuB,EAAG,GAAET,MAAM,CAACiB,KAAM,MAAKjB,MAAM,CAACkB,KAAM,EAAC;UAC5DnB,QAAQ,EAAEC,MAAM,CAACmB;QACnB,CAAC;MACH;IACF,CAAC;EACH,CAAC,CAAC;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":["getLabels","dimOrder","toLowerCase","split","reverse","getDims","labels","lookup","Map","map","name","i","size","length","Error","index","get","undefined"],"sources":["../../../src/lib/ome/utils.ts"],"sourcesContent":["import type {OMEXML} from '../ome/omexml';\nimport type {Labels} from '../../types';\n\n/*\n * Creates typed labels from DimensionOrder.\n * > imgMeta.Pixels.DimensionOrder === 'XYCZT'\n * > getLabels(imgMeta.Pixels) === ['t', 'z', 'c', 'y', 'x']\n */\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ntype Sel<Dim extends string> = Dim extends `${infer Z}${infer X}${infer A}${infer B}${infer C}`\n ? [C, B, A]\n : 'error';\nexport function getLabels(dimOrder: OMEXML[0]['Pixels']['DimensionOrder']) {\n return dimOrder.toLowerCase().split('').reverse() as Labels<Sel<Lowercase<typeof dimOrder>>>;\n}\n\n/*\n * Creates an ES6 map of 'label' -> index\n * > const labels = ['a', 'b', 'c', 'd'];\n * > const dims = getDims(labels);\n * > dims('a') === 0;\n * > dims('b') === 1;\n * > dims('c') === 2;\n * > dims('hi!'); // throws\n */\nexport function getDims<S extends string>(labels: S[]) {\n const lookup = new Map(labels.map((name, i) => [name, i]));\n if (lookup.size !== labels.length) {\n throw Error('Labels must be unique, found duplicated label.');\n }\n return (name: S) => {\n const index = lookup.get(name);\n if (index === undefined) {\n throw Error('Invalid dimension.');\n }\n return index;\n };\n}\n"],"mappings":"AAaA,OAAO,SAASA,SAASA,CAACC,QAA+C,EAAE;EACzE,OAAOA,QAAQ,CAACC,WAAW,CAAC,CAAC,CAACC,KAAK,CAAC,EAAE,CAAC,CAACC,OAAO,CAAC,CAAC;AACnD;AAWA,OAAO,SAASC,OAAOA,CAAmBC,MAAW,EAAE;EACrD,MAAMC,MAAM,GAAG,IAAIC,GAAG,CAACF,MAAM,CAACG,GAAG,CAAC,CAACC,IAAI,EAAEC,CAAC,KAAK,CAACD,IAAI,EAAEC,CAAC,CAAC,CAAC,CAAC;EAC1D,IAAIJ,MAAM,CAACK,IAAI,KAAKN,MAAM,CAACO,MAAM,EAAE;IACjC,MAAMC,KAAK,CAAC,gDAAgD,CAAC;EAC/D;EACA,OAAQJ,IAAO,IAAK;IAClB,MAAMK,KAAK,GAAGR,MAAM,CAACS,GAAG,CAACN,IAAI,CAAC;IAC9B,IAAIK,KAAK,KAAKE,SAAS,EAAE;MACvB,MAAMH,KAAK,CAAC,oBAAoB,CAAC;IACnC;IACA,OAAOC,KAAK;EACd,CAAC;AACH"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getImageSize, isInterleaved, SIGNAL_ABORTED } from './utils/tiff-utils';
|
|
1
|
+
import { getImageSize, isInterleaved, SIGNAL_ABORTED } from "./utils/tiff-utils.js";
|
|
3
2
|
class TiffPixelSource {
|
|
4
3
|
constructor(indexer, dtype, tileSize, shape, labels, meta) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
this.dtype = void 0;
|
|
5
|
+
this.tileSize = void 0;
|
|
6
|
+
this.shape = void 0;
|
|
7
|
+
this.labels = void 0;
|
|
8
|
+
this.meta = void 0;
|
|
9
|
+
this._indexer = void 0;
|
|
11
10
|
this._indexer = indexer;
|
|
12
11
|
this.dtype = dtype;
|
|
13
12
|
this.tileSize = tileSize;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiff-pixel-source.js","names":["getImageSize","isInterleaved","SIGNAL_ABORTED","TiffPixelSource","constructor","indexer","dtype","tileSize","shape","labels","meta","_indexer","getRaster","_ref","selection","signal","image","_readRasters","getTile","_ref2","x","y","height","width","_getTileExtent","x0","y0","window","props","_props$signal","interleave","raster","readRasters","aborted","data","zoomLevelHeight","zoomLevelWidth","maxXTileCoord","Math","floor","maxYTileCoord","onTileError","err","console","error"],"sources":["../../src/lib/tiff-pixel-source.ts"],"sourcesContent":["import type {GeoTIFFImage, RasterOptions} from 'geotiff';\nimport {getImageSize, isInterleaved, SIGNAL_ABORTED} from './utils/tiff-utils';\n\nimport type {\n PixelSource,\n PixelSourceSelection,\n PixelSourceMeta,\n Dtype,\n Labels,\n RasterSelection,\n TileSelection,\n PixelData,\n TypedArray\n} from '../types';\n\nclass TiffPixelSource<S extends string[]> implements PixelSource<S> {\n public dtype: Dtype;\n public tileSize: number;\n public shape: number[];\n public labels: Labels<S>;\n public meta: PixelSourceMeta | undefined;\n private _indexer: (sel: PixelSourceSelection<S>) => Promise<GeoTIFFImage>;\n\n // eslint-disable-next-line max-params\n constructor(\n indexer: (sel: PixelSourceSelection<S>) => Promise<GeoTIFFImage>,\n dtype: Dtype,\n tileSize: number,\n shape: number[],\n labels: Labels<S>,\n meta?: PixelSourceMeta\n ) {\n this._indexer = indexer;\n this.dtype = dtype;\n this.tileSize = tileSize;\n this.shape = shape;\n this.labels = labels;\n this.meta = meta;\n }\n\n async getRaster({selection, signal}: RasterSelection<S>) {\n const image = await this._indexer(selection);\n return this._readRasters(image, {signal});\n }\n\n async getTile({x, y, selection, signal}: TileSelection<S>) {\n const {height, width} = this._getTileExtent(x, y);\n const x0 = x * this.tileSize;\n const y0 = y * this.tileSize;\n const window = [x0, y0, x0 + width, y0 + height];\n\n const image = await this._indexer(selection);\n return this._readRasters(image, {window, width, height, signal});\n }\n\n private async _readRasters(image: GeoTIFFImage, props?: RasterOptions) {\n const interleave = isInterleaved(this.shape);\n const raster = await image.readRasters({interleave, ...props});\n\n if (props?.signal?.aborted) {\n throw SIGNAL_ABORTED;\n }\n\n /*\n * geotiff.js returns objects with different structure\n * depending on `interleave`. It's weird, but this seems to work.\n */\n const data = (interleave ? raster : raster[0]) as TypedArray;\n return {\n data,\n width: raster.width,\n height: raster.height\n } as PixelData;\n }\n\n /*\n * Computes tile size given x, y coord.\n */\n private _getTileExtent(x: number, y: number) {\n const {height: zoomLevelHeight, width: zoomLevelWidth} = getImageSize(this);\n let height = this.tileSize;\n let width = this.tileSize;\n const maxXTileCoord = Math.floor(zoomLevelWidth / this.tileSize);\n const maxYTileCoord = Math.floor(zoomLevelHeight / this.tileSize);\n if (x === maxXTileCoord) {\n width = zoomLevelWidth % this.tileSize;\n }\n if (y === maxYTileCoord) {\n height = zoomLevelHeight % this.tileSize;\n }\n return {height, width};\n }\n\n onTileError(err: Error) {\n console.error(err); // eslint-disable-line no-console\n }\n}\n\nexport default TiffPixelSource;\n"],"mappings":"SACQA,YAAY,EAAEC,aAAa,EAAEC,cAAc;AAcnD,MAAMC,eAAe,CAA+C;EASlEC,WAAWA,CACTC,OAAgE,EA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,MAAM,GAAGa,eAAe,GAAG,IAAI,CAAC5B,QAAQ;IAC1C;IACA,OAAO;MAACe,MAAM;MAAEC;IAAK,CAAC;EACxB;EAEAkB,WAAWA,CAACC,GAAU,EAAE;IACtBC,OAAO,CAACC,KAAK,CAACF,GAAG,CAAC;EACpB;AACF;AAEA,eAAevC,eAAe"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
1
|
var _globalThis$navigator, _globalThis$navigator2;
|
|
3
2
|
const defaultPoolSize = (_globalThis$navigator = globalThis === null || globalThis === void 0 ? void 0 : (_globalThis$navigator2 = globalThis.navigator) === null || _globalThis$navigator2 === void 0 ? void 0 : _globalThis$navigator2.hardwareConcurrency) !== null && _globalThis$navigator !== void 0 ? _globalThis$navigator : 4;
|
|
4
3
|
export default class Pool {
|
|
5
4
|
constructor() {
|
|
6
5
|
let size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultPoolSize;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
this.workers = void 0;
|
|
7
|
+
this.idleWorkers = void 0;
|
|
8
|
+
this.waitQueue = void 0;
|
|
9
|
+
this.decoder = void 0;
|
|
11
10
|
this.workers = [];
|
|
12
11
|
this.idleWorkers = [];
|
|
13
12
|
this.waitQueue = [];
|