@loaders.gl/geotiff 3.1.3 → 4.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +2 -24
- package/dist/bundle.js.map +1 -0
- package/dist/index.js +3 -10
- package/dist/index.js.map +1 -0
- package/dist/lib/load-geotiff.js +31 -56
- package/dist/lib/load-geotiff.js.map +1 -0
- package/dist/lib/ome/load-ome-tiff.js +50 -45
- package/dist/lib/ome/load-ome-tiff.js.map +1 -0
- package/dist/lib/ome/ome-indexers.js +112 -104
- package/dist/lib/ome/ome-indexers.js.map +1 -0
- package/dist/lib/ome/ome-utils.js +69 -59
- package/dist/lib/ome/ome-utils.js.map +1 -0
- package/dist/lib/ome/omexml.js +60 -60
- package/dist/lib/ome/omexml.js.map +1 -0
- package/dist/lib/ome/utils.js +18 -27
- package/dist/lib/ome/utils.js.map +1 -0
- package/dist/lib/tiff-pixel-source.js +106 -59
- package/dist/lib/tiff-pixel-source.js.map +1 -0
- package/dist/lib/utils/Pool.js +72 -78
- package/dist/lib/utils/Pool.js.map +1 -0
- package/dist/{es5/lib → lib}/utils/decoder.worker.ts.disabled +0 -0
- package/dist/lib/utils/proxies.js +56 -79
- package/dist/lib/utils/proxies.js.map +1 -0
- package/dist/lib/utils/tiff-utils.js +24 -40
- package/dist/lib/utils/tiff-utils.js.map +1 -0
- package/dist/types.js +2 -2
- package/dist/{es5/types.js.map → types.js.map} +0 -0
- package/dist/typings/geotiff.js +2 -1
- package/dist/{es5/typings → typings}/geotiff.js.map +0 -0
- package/package.json +4 -4
- package/dist/es5/bundle.js +0 -13
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/index.js +0 -24
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/load-geotiff.js +0 -100
- package/dist/es5/lib/load-geotiff.js.map +0 -1
- package/dist/es5/lib/ome/load-ome-tiff.js +0 -85
- package/dist/es5/lib/ome/load-ome-tiff.js.map +0 -1
- package/dist/es5/lib/ome/ome-indexers.js +0 -167
- package/dist/es5/lib/ome/ome-indexers.js.map +0 -1
- package/dist/es5/lib/ome/ome-utils.js +0 -87
- package/dist/es5/lib/ome/ome-utils.js.map +0 -1
- package/dist/es5/lib/ome/omexml.js +0 -82
- package/dist/es5/lib/ome/omexml.js.map +0 -1
- package/dist/es5/lib/ome/utils.js +0 -32
- package/dist/es5/lib/ome/utils.js.map +0 -1
- package/dist/es5/lib/tiff-pixel-source.js +0 -202
- package/dist/es5/lib/tiff-pixel-source.js.map +0 -1
- package/dist/es5/lib/utils/Pool.js +0 -173
- package/dist/es5/lib/utils/Pool.js.map +0 -1
- package/dist/es5/lib/utils/proxies.js +0 -82
- package/dist/es5/lib/utils/proxies.js.map +0 -1
- package/dist/es5/lib/utils/tiff-utils.js +0 -53
- package/dist/es5/lib/utils/tiff-utils.js.map +0 -1
- package/dist/es5/types.js +0 -2
- package/dist/es5/typings/geotiff.js +0 -2
- 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 +0 -32
- package/dist/esm/lib/load-geotiff.js.map +0 -1
- package/dist/esm/lib/ome/load-ome-tiff.js +0 -51
- package/dist/esm/lib/ome/load-ome-tiff.js.map +0 -1
- package/dist/esm/lib/ome/ome-indexers.js +0 -116
- package/dist/esm/lib/ome/ome-indexers.js.map +0 -1
- package/dist/esm/lib/ome/ome-utils.js +0 -73
- package/dist/esm/lib/ome/ome-utils.js.map +0 -1
- package/dist/esm/lib/ome/omexml.js +0 -66
- package/dist/esm/lib/ome/omexml.js.map +0 -1
- package/dist/esm/lib/ome/utils.js +0 -21
- package/dist/esm/lib/ome/utils.js.map +0 -1
- package/dist/esm/lib/tiff-pixel-source.js +0 -111
- package/dist/esm/lib/tiff-pixel-source.js.map +0 -1
- package/dist/esm/lib/utils/Pool.js +0 -77
- 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 +0 -63
- package/dist/esm/lib/utils/proxies.js.map +0 -1
- package/dist/esm/lib/utils/tiff-utils.js +0 -28
- package/dist/esm/lib/utils/tiff-utils.js.map +0 -1
- package/dist/esm/types.js +0 -2
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/typings/geotiff.js +0 -2
- package/dist/esm/typings/geotiff.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/ome/ome-utils.ts"],"names":["getDims","getLabels","DTYPE_LOOKUP","uint8","uint16","uint32","float","double","int8","int16","int32","getOmePixelSourceMeta","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"],"mappings":"AAAA,SAAQA,OAAR,EAAiBC,SAAjB,QAAiC,SAAjC;AAGA,OAAO,MAAMC,YAAY,GAAG;AAC1BC,EAAAA,KAAK,EAAE,OADmB;AAE1BC,EAAAA,MAAM,EAAE,QAFkB;AAG1BC,EAAAA,MAAM,EAAE,QAHkB;AAI1BC,EAAAA,KAAK,EAAE,SAJmB;AAK1BC,EAAAA,MAAM,EAAE,SALkB;AAM1BC,EAAAA,IAAI,EAAE,MANoB;AAO1BC,EAAAA,KAAK,EAAE,OAPmB;AAQ1BC,EAAAA,KAAK,EAAE;AARmB,CAArB;AAWP,OAAO,SAASC,qBAAT,CAA+B;AAACC,EAAAA;AAAD,CAA/B,EAAoD;AAEzD,QAAMC,MAAM,GAAGZ,SAAS,CAACW,MAAM,CAACE,cAAR,CAAxB;AAGA,QAAMC,IAAI,GAAGf,OAAO,CAACa,MAAD,CAApB;AACA,QAAMG,KAAe,GAAGC,KAAK,CA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AI,EAAEzB,MAAM,CAACsB,aADZ;AAEDI,QAAAA,IAAI,EAAE1B,MAAM,CAAC6B;AAFZ;AALD,KAFJ;;AAYA,QAAI7B,MAAM,CAAC8B,aAAX,EAA0B;AACxBP,MAAAA,aAAa,CAACQ,CAAd,GAAkB;AAChBN,QAAAA,IAAI,EAAEzB,MAAM,CAAC8B,aADG;AAEhBJ,QAAAA,IAAI,EAAE1B,MAAM,CAACgC;AAFG,OAAlB;AAID;;AACD,WAAO;AAAC/B,MAAAA,MAAD;AAASY,MAAAA,QAAT;AAAmBU,MAAAA,aAAnB;AAAkCH,MAAAA;AAAlC,KAAP;AACD;;AAED,SAAO;AAACnB,IAAAA,MAAD;AAASY,IAAAA,QAAT;AAAmBO,IAAAA;AAAnB,GAAP;AACD","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"],"file":"ome-utils.js"}
|
package/dist/lib/ome/omexml.js
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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.
|
|
1
|
+
import parser from 'fast-xml-parser';
|
|
2
|
+
import { ensureArray, intToRgba } from '../utils/tiff-utils';
|
|
10
3
|
const PARSER_OPTIONS = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
parseAttributeValue: true,
|
|
17
|
-
// Forces attributes to be parsed
|
|
18
|
-
ignoreAttributes: false
|
|
4
|
+
attributeNamePrefix: '',
|
|
5
|
+
attrNodeName: 'attr',
|
|
6
|
+
parseNodeValue: true,
|
|
7
|
+
parseAttributeValue: true,
|
|
8
|
+
ignoreAttributes: false
|
|
19
9
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
...img.attr,
|
|
36
|
-
AquisitionDate,
|
|
37
|
-
Description,
|
|
38
|
-
Pixels: {
|
|
39
|
-
...img.Pixels.attr,
|
|
40
|
-
Channels
|
|
41
|
-
}
|
|
10
|
+
|
|
11
|
+
const parse = str => parser.parse(str, PARSER_OPTIONS);
|
|
12
|
+
|
|
13
|
+
export function fromString(str) {
|
|
14
|
+
const res = parse(str);
|
|
15
|
+
|
|
16
|
+
if (!res.OME) {
|
|
17
|
+
throw Error('Failed to parse OME-XML metadata.');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return ensureArray(res.OME.Image).map(img => {
|
|
21
|
+
const Channels = ensureArray(img.Pixels.Channel).map(c => {
|
|
22
|
+
if ('Color' in c.attr) {
|
|
23
|
+
return { ...c.attr,
|
|
24
|
+
Color: intToRgba(c.attr.Color)
|
|
42
25
|
};
|
|
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 ');
|
|
43
53
|
return {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
}
|
|
54
|
+
'Acquisition Date': image.AquisitionDate,
|
|
55
|
+
'Dimensions (XY)': "".concat(Pixels.SizeX, " x ").concat(Pixels.SizeY),
|
|
56
|
+
'Pixels Type': Pixels.Type,
|
|
57
|
+
'Pixels Size (XYZ)': sizes,
|
|
58
|
+
'Z-sections/Timepoints': "".concat(Pixels.SizeZ, " x ").concat(Pixels.SizeT),
|
|
59
|
+
Channels: Pixels.SizeC
|
|
63
60
|
};
|
|
64
|
-
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
//# sourceMappingURL=omexml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/ome/omexml.ts"],"names":["parser","ensureArray","intToRgba","PARSER_OPTIONS","attributeNamePrefix","attrNodeName","parseNodeValue","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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FY;AAGZC,MAAAA,WAHY;AAIZN,MAAAA,MAAM,EAAE,EACN,GAAGF,GAAG,CAACE,MAAJ,CAAWG,IADR;AAENJ,QAAAA;AAFM;AAJI,KAAd;AASA,WAAO,EACL,GAAGQ,KADE;;AAELC,MAAAA,MAAM,GAAG;AACP,cAAM;AAACR,UAAAA;AAAD,YAAWO,KAAjB;AAEA,cAAME,KAAK,GAAI,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,CAAD,CACXZ,GADW,CACNa,IAAD,IAAU;AACb,gBAAMC,IAAI,GAAGX,MAAM,uBAAgBU,IAAhB,EAAnB;AACA,gBAAME,IAAI,GAAGZ,MAAM,uBAAgBU,IAAhB,UAAnB;AACA,iBAAOC,IAAI,IAAIC,IAAR,aAAkBD,IAAlB,cAA0BC,IAA1B,IAAmC,GAA1C;AACD,SALW,EAMXC,IANW,CAMN,KANM,CAAd;AAQA,eAAO;AACL,8BAAoBN,KAAK,CAACF,cADrB;AAEL,uCAAsBL,MAAM,CAACc,KAA7B,gBAAwCd,MAAM,CAACe,KAA/C,CAFK;AAGL,yBAAef,MAAM,CAACgB,IAHjB;AAIL,+BAAqBP,KAJhB;AAKL,6CAA4BT,MAAM,CAACiB,KAAnC,gBAA8CjB,MAAM,CAACkB,KAArD,CALK;AAMLnB,UAAAA,QAAQ,EAAEC,MAAM,CAACmB;AANZ,SAAP;AAQD;;AArBI,KAAP;AAuBD,GAxCM,CAAP;AAyCD","sourcesContent":["import parser 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 PARSER_OPTIONS = {\n // Nests attributes withtout prefix under 'attr' key for each node\n attributeNamePrefix: '',\n attrNodeName: 'attr',\n\n // Parses numbers for both attributes and nodes\n parseNodeValue: true,\n parseAttributeValue: true,\n\n // Forces attributes to be parsed\n ignoreAttributes: false\n};\n\nconst parse = (str: string): Root => parser.parse(str, PARSER_OPTIONS);\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<{}, ChannelAttrs>;\n\ntype Root = {OME: OME};\n"],"file":"omexml.js"}
|
package/dist/lib/ome/utils.js
CHANGED
|
@@ -1,30 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getDims = exports.getLabels = void 0;
|
|
4
|
-
function getLabels(dimOrder) {
|
|
5
|
-
return dimOrder.toLowerCase().split('').reverse();
|
|
1
|
+
export function getLabels(dimOrder) {
|
|
2
|
+
return dimOrder.toLowerCase().split('').reverse();
|
|
6
3
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (lookup.size !== labels.length) {
|
|
20
|
-
throw Error('Labels must be unique, found duplicated label.');
|
|
4
|
+
export function getDims(labels) {
|
|
5
|
+
const lookup = new Map(labels.map((name, i) => [name, i]));
|
|
6
|
+
|
|
7
|
+
if (lookup.size !== labels.length) {
|
|
8
|
+
throw Error('Labels must be unique, found duplicated label.');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return name => {
|
|
12
|
+
const index = lookup.get(name);
|
|
13
|
+
|
|
14
|
+
if (index === undefined) {
|
|
15
|
+
throw Error('Invalid dimension.');
|
|
21
16
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
throw Error('Invalid dimension.');
|
|
26
|
-
}
|
|
27
|
-
return index;
|
|
28
|
-
};
|
|
17
|
+
|
|
18
|
+
return index;
|
|
19
|
+
};
|
|
29
20
|
}
|
|
30
|
-
|
|
21
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/ome/utils.ts"],"names":["getLabels","dimOrder","toLowerCase","split","reverse","getDims","labels","lookup","Map","map","name","i","size","length","Error","index","get","undefined"],"mappings":"AAaA,OAAO,SAASA,SAAT,CAAmBC,QAAnB,EAAoE;AACzE,SAAOA,QAAQ,CAACC,WAAT,GAAuBC,KAAvB,CAA6B,EAA7B,EAAiCC,OAAjC,EAAP;AACD;AAWD,OAAO,SAASC,OAAT,CAAmCC,MAAnC,EAAgD;AACrD,QAAMC,MAAM,GAAG,IAAIC,GAAJ,CAAQF,MAAM,CAACG,GAAP,CAAW,CAACC,IAAD,EAAOC,CAAP,KAAa,CAACD,IAAD,EAAOC,CAAP,CAAxB,CAAR,CAAf;;AACA,MAAIJ,MAAM,CAACK,IAAP,KAAgBN,MAAM,CAACO,MAA3B,EAAmC;AACjC,UAAMC,KAAK,CAAC,gDAAD,CAAX;AACD;;AACD,SAAQJ,IAAD,IAAa;AAClB,UAAMK,KAAK,GAAGR,MAAM,CAACS,GAAP,CAAWN,IAAX,CAAd;;AACA,QAAIK,KAAK,KAAKE,SAAd,EAAyB;AACvB,YAAMH,KAAK,CAAC,oBAAD,CAAX;AACD;;AACD,WAAOC,KAAP;AACD,GAND;AAOD","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"],"file":"utils.js"}
|
|
@@ -1,64 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import { getImageSize, isInterleaved, SIGNAL_ABORTED } from './utils/tiff-utils';
|
|
3
|
+
|
|
4
4
|
class TiffPixelSource {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
constructor(indexer, dtype, tileSize, shape, labels, meta) {
|
|
6
|
+
_defineProperty(this, "dtype", void 0);
|
|
7
|
+
|
|
8
|
+
_defineProperty(this, "tileSize", void 0);
|
|
9
|
+
|
|
10
|
+
_defineProperty(this, "shape", void 0);
|
|
11
|
+
|
|
12
|
+
_defineProperty(this, "labels", void 0);
|
|
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;
|
|
13
70
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
71
|
+
|
|
72
|
+
const data = interleave ? raster : raster[0];
|
|
73
|
+
return {
|
|
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;
|
|
17
92
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
93
|
+
|
|
94
|
+
if (y === maxYTileCoord) {
|
|
95
|
+
height = zoomLevelHeight % this.tileSize;
|
|
62
96
|
}
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
height,
|
|
100
|
+
width
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
onTileError(err) {
|
|
105
|
+
console.error(err);
|
|
106
|
+
}
|
|
107
|
+
|
|
63
108
|
}
|
|
64
|
-
|
|
109
|
+
|
|
110
|
+
export default TiffPixelSource;
|
|
111
|
+
//# sourceMappingURL=tiff-pixel-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/tiff-pixel-source.ts"],"names":["getImageSize","isInterleaved","SIGNAL_ABORTED","TiffPixelSource","constructor","indexer","dtype","tileSize","shape","labels","meta","_indexer","getRaster","selection","signal","image","_readRasters","getTile","x","y","height","width","_getTileExtent","x0","y0","window","props","interleave","raster","readRasters","aborted","data","zoomLevelHeight","zoomLevelWidth","maxXTileCoord","Math","floor","maxYTileCoord","onTileError","err","console","error"],"mappings":";AACA,SAAQA,YAAR,EAAsBC,aAAtB,EAAqCC,cAArC,QAA0D,oBAA1D;;AAcA,MAAMC,eAAN,CAAoE;AASlEC,EAAAA,WAAW,CACTC,OADS,EAETC,KAFS,EAGTC,QAHS,EAITC,KAJS,EAKTC,MALS,EAMTC,IANS,EAOT;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AACA,SAAKC,QAAL,GAAgBN,OAAhB;AACA,SAAKC,KAAL,GAAaA,KAAb;AACA,SAAKC,QAAL,GAAgBA,QAAhB;AACA,SAAKC,KAAL,GAAaA,KAAb;AACA,SAAKC,MAAL,GAAcA,MAAd;AACA,SAAKC,IAAL,GAAYA,IAAZ;AACD;;AAEc,QAATE,SAAS,CAAC;AAACC,IAAAA,SAAD;AAAYC,IAAAA;AAAZ,GAAD,EAA0C;AACvD,UAAMC,KAAK,GAAG,MAAM,KAAKJ,QAAL,CAAcE,SAAd,CAApB;AACA,WAAO,KAAKG,YAAL,CAAkBD,KAAlB,EAAyB;AAACD,MAAAA;AAAD,KAAzB,CAAP;AACD;;AAEY,QAAPG,OAAO,CAAC;AAACC,IAAAA,CAAD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AZ,EAAuB;AAC3C,UAAM;AAACC,MAAAA,MAAM,EAAEY,eAAT;AAA0BX,MAAAA,KAAK,EAAEY;AAAjC,QAAmDjC,YAAY,CAAC,IAAD,CAArE;AACA,QAAIoB,MAAM,GAAG,KAAKb,QAAlB;AACA,QAAIc,KAAK,GAAG,KAAKd,QAAjB;AACA,UAAM2B,aAAa,GAAGC,IAAI,CAACC,KAAL,CAAWH,cAAc,GAAG,KAAK1B,QAAjC,CAAtB;AACA,UAAM8B,aAAa,GAAGF,IAAI,CAACC,KAAL,CAAWJ,eAAe,GAAG,KAAKzB,QAAlC,CAAtB;;AACA,QAAIW,CAAC,KAAKgB,aAAV,EAAyB;AACvBb,MAAAA,KAAK,GAAGY,cAAc,GAAG,KAAK1B,QAA9B;AACD;;AACD,QAAIY,CAAC,KAAKkB,aAAV,EAAyB;AACvBjB,MAAAA,MAAM,GAAGY,eAAe,GAAG,KAAKzB,QAAhC;AACD;;AACD,WAAO;AAACa,MAAAA,MAAD;AAASC,MAAAA;AAAT,KAAP;AACD;;AAEDiB,EAAAA,WAAW,CAACC,GAAD,EAAa;AACtBC,IAAAA,OAAO,CAACC,KAAR,CAAcF,GAAd;AACD;;AAhFiE;;AAmFpE,eAAepC,eAAf","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"],"file":"tiff-pixel-source.js"}
|
package/dist/lib/utils/Pool.js
CHANGED
|
@@ -1,83 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// eslint-disable-next-line no-plusplus
|
|
26
|
-
for (let i = 0; i < size; ++i) {
|
|
27
|
-
const w = new Worker('./decoder.worker');
|
|
28
|
-
this.workers.push(w);
|
|
29
|
-
this.idleWorkers.push(w);
|
|
30
|
-
}
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
|
|
3
|
+
var _globalThis$navigator, _globalThis$navigator2;
|
|
4
|
+
|
|
5
|
+
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;
|
|
6
|
+
export default class Pool {
|
|
7
|
+
constructor(size = defaultPoolSize) {
|
|
8
|
+
_defineProperty(this, "workers", void 0);
|
|
9
|
+
|
|
10
|
+
_defineProperty(this, "idleWorkers", void 0);
|
|
11
|
+
|
|
12
|
+
_defineProperty(this, "waitQueue", void 0);
|
|
13
|
+
|
|
14
|
+
_defineProperty(this, "decoder", void 0);
|
|
15
|
+
|
|
16
|
+
this.workers = [];
|
|
17
|
+
this.idleWorkers = [];
|
|
18
|
+
this.waitQueue = [];
|
|
19
|
+
this.decoder = null;
|
|
20
|
+
|
|
21
|
+
for (let i = 0; i < size; ++i) {
|
|
22
|
+
const w = new Worker('./decoder.worker');
|
|
23
|
+
this.workers.push(w);
|
|
24
|
+
this.idleWorkers.push(w);
|
|
31
25
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async decode(fileDirectory, buffer) {
|
|
29
|
+
const currentWorker = await this.waitForWorker();
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
currentWorker.onmessage = event => {
|
|
32
|
+
this.finishTask(currentWorker);
|
|
33
|
+
resolve(event.data[0]);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
currentWorker.onerror = error => {
|
|
37
|
+
this.finishTask(currentWorker);
|
|
38
|
+
reject(error);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
currentWorker.postMessage(['decode', fileDirectory, buffer], [buffer]);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async waitForWorker() {
|
|
46
|
+
const idleWorker = this.idleWorkers.pop();
|
|
47
|
+
|
|
48
|
+
if (idleWorker) {
|
|
49
|
+
return idleWorker;
|
|
54
50
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
51
|
+
|
|
52
|
+
const waiter = {};
|
|
53
|
+
const promise = new Promise(resolve => {
|
|
54
|
+
waiter.resolve = resolve;
|
|
55
|
+
});
|
|
56
|
+
this.waitQueue.push(waiter);
|
|
57
|
+
return promise;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async finishTask(currentWorker) {
|
|
61
|
+
const waiter = this.waitQueue.pop();
|
|
62
|
+
|
|
63
|
+
if (waiter) {
|
|
64
|
+
waiter.resolve(currentWorker);
|
|
65
|
+
} else {
|
|
66
|
+
this.idleWorkers.push(currentWorker);
|
|
66
67
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
else {
|
|
73
|
-
this.idleWorkers.push(currentWorker);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
destroy() {
|
|
77
|
-
// eslint-disable-next-line no-plusplus
|
|
78
|
-
for (let i = 0; i < this.workers.length; ++i) {
|
|
79
|
-
this.workers[i].terminate();
|
|
80
|
-
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
destroy() {
|
|
71
|
+
for (let i = 0; i < this.workers.length; ++i) {
|
|
72
|
+
this.workers[i].terminate();
|
|
81
73
|
}
|
|
74
|
+
}
|
|
75
|
+
|
|
82
76
|
}
|
|
83
|
-
|
|
77
|
+
//# sourceMappingURL=Pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/utils/Pool.ts"],"names":["defaultPoolSize","globalThis","navigator","hardwareConcurrency","Pool","constructor","size","workers","idleWorkers","waitQueue","decoder","i","w","Worker","push","decode","fileDirectory","buffer","currentWorker","waitForWorker","Promise","resolve","reject","onmessage","event","finishTask","data","onerror","error","postMessage","idleWorker","pop","waiter","promise","destroy","length","terminate"],"mappings":";;;;AASA,MAAMA,eAAe,4BAAGC,UAAH,aAAGA,UAAH,iDAAGA,UAAU,CAAEC,SAAf,2DAAG,uBAAuBC,mBAA1B,yEAAiD,CAAtE;AAMA,eAAe,MAAMC,IAAN,CAAW;AAYxBC,EAAAA,WAAW,CAACC,IAAI,GAAGN,eAAR,EAAyB;AAAA;;AAAA;;AAAA;;AAAA;;AAClC,SAAKO,OAAL,GAAe,EAAf;AACA,SAAKC,WAAL,GAAmB,EAAnB;AACA,SAAKC,SAAL,GAAiB,EAAjB;AACA,SAAKC,OAAL,GAAe,IAAf;;AAGA,SAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGL,IAApB,EAA0B,EAAEK,CAA5B,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L,CAAesB,GAAf,EAAf;;AACA,QAAIC,MAAJ,EAAY;AACVA,MAAAA,MAAM,CAACX,OAAP,CAAeH,aAAf;AACD,KAFD,MAEO;AACL,WAAKV,WAAL,CAAiBM,IAAjB,CAAsBI,aAAtB;AACD;AACF;;AAEDgB,EAAAA,OAAO,GAAG;AAER,SAAK,IAAIvB,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAG,KAAKJ,OAAL,CAAa4B,MAAjC,EAAyC,EAAExB,CAA3C,EAA8C;AAC5C,WAAKJ,OAAL,CAAaI,CAAb,EAAgByB,SAAhB;AACD;AACF;;AA9EuB","sourcesContent":["/** eslint-disable */\nimport type {FileDirectory} from 'geotiff';\n\n// import Worker from 'web-worker:./decoder.worker.ts';\n\n// https://developer.mozilla.org/en-US/docs/Web/API/NavigatorConcurrentHardware/hardwareConcurrency\n// We need to give a different way of getting this for safari, so 4 is probably a safe bet\n// for parallel processing in the meantime. More can't really hurt since they'll just block\n// each other and not the UI thread, which is the real benefit.\nconst defaultPoolSize = globalThis?.navigator?.hardwareConcurrency ?? 4;\n\n/**\n * Pool for workers to decode chunks of the images.\n * 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\n */\nexport default class Pool {\n workers: Worker[];\n idleWorkers: Worker[];\n waitQueue: any[];\n decoder: null;\n\n /**\n * @constructor\n * @param {Number} size The size of the pool. Defaults to the number of CPUs\n * available. When this parameter is `null` or 0, then the\n * decoding will be done in the main thread.\n */\n constructor(size = defaultPoolSize) {\n this.workers = [];\n this.idleWorkers = [];\n this.waitQueue = [];\n this.decoder = null;\n\n // eslint-disable-next-line no-plusplus\n for (let i = 0; i < size; ++i) {\n const w = new Worker('./decoder.worker');\n this.workers.push(w);\n this.idleWorkers.push(w);\n }\n }\n\n /**\n * Decode the given block of bytes with the set compression method.\n * @param {ArrayBuffer} buffer the array buffer of bytes to decode.\n * @returns {Promise.<ArrayBuffer>} the decoded result as a `Promise`\n */\n async decode(fileDirectory: FileDirectory, buffer: ArrayBuffer) {\n const currentWorker = await this.waitForWorker();\n return new Promise((resolve, reject) => {\n currentWorker.onmessage = (event) => {\n // this.workers.push(currentWorker);\n // eslint-disable-next-line\n this.finishTask(currentWorker);\n resolve(event.data[0]);\n };\n currentWorker.onerror = (error) => {\n // this.workers.push(currentWorker);\n // eslint-disable-next-line\n this.finishTask(currentWorker);\n reject(error);\n };\n currentWorker.postMessage(['decode', fileDirectory, buffer], [buffer]);\n });\n }\n\n async waitForWorker() {\n const idleWorker = this.idleWorkers.pop();\n if (idleWorker) {\n return idleWorker;\n }\n const waiter: any = {};\n const promise = new Promise((resolve) => {\n waiter.resolve = resolve;\n });\n\n this.waitQueue.push(waiter);\n return promise as Promise<Worker>;\n }\n\n async finishTask(currentWorker: Worker) {\n const waiter = this.waitQueue.pop();\n if (waiter) {\n waiter.resolve(currentWorker);\n } else {\n this.idleWorkers.push(currentWorker);\n }\n }\n\n destroy() {\n // eslint-disable-next-line no-plusplus\n for (let i = 0; i < this.workers.length; ++i) {\n this.workers[i].terminate();\n }\n }\n}\n"],"file":"Pool.js"}
|
|
File without changes
|