@loaders.gl/geotiff 3.1.0-beta.7 → 3.1.0

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.
@@ -1,14 +1,18 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
6
8
  exports.getOmePixelSourceMeta = getOmePixelSourceMeta;
7
9
  exports.DTYPE_LOOKUP = void 0;
8
10
 
11
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
12
+
9
13
  var _utils = require("./utils");
10
14
 
11
- const DTYPE_LOOKUP = {
15
+ var DTYPE_LOOKUP = {
12
16
  uint8: 'Uint8',
13
17
  uint16: 'Uint16',
14
18
  uint32: 'Uint32',
@@ -20,12 +24,11 @@ const DTYPE_LOOKUP = {
20
24
  };
21
25
  exports.DTYPE_LOOKUP = DTYPE_LOOKUP;
22
26
 
23
- function getOmePixelSourceMeta({
24
- Pixels
25
- }) {
26
- const labels = (0, _utils.getLabels)(Pixels.DimensionOrder);
27
- const dims = (0, _utils.getDims)(labels);
28
- const shape = Array(labels.length).fill(0);
27
+ function getOmePixelSourceMeta(_ref) {
28
+ var Pixels = _ref.Pixels;
29
+ var labels = (0, _utils.getLabels)(Pixels.DimensionOrder);
30
+ var dims = (0, _utils.getDims)(labels);
31
+ var shape = Array(labels.length).fill(0);
29
32
  shape[dims('t')] = Pixels.SizeT;
30
33
  shape[dims('c')] = Pixels.SizeC;
31
34
  shape[dims('z')] = Pixels.SizeZ;
@@ -35,8 +38,8 @@ function getOmePixelSourceMeta({
35
38
  shape.push(3);
36
39
  }
37
40
 
38
- const getShape = level => {
39
- const s = [...shape];
41
+ var getShape = function getShape(level) {
42
+ var s = (0, _toConsumableArray2.default)(shape);
40
43
  s[dims('x')] = Pixels.SizeX >> level;
41
44
  s[dims('y')] = Pixels.SizeY >> level;
42
45
  return s;
@@ -46,10 +49,10 @@ function getOmePixelSourceMeta({
46
49
  throw Error("Pixel type ".concat(Pixels.Type, " not supported."));
47
50
  }
48
51
 
49
- const dtype = DTYPE_LOOKUP[Pixels.Type];
52
+ var dtype = DTYPE_LOOKUP[Pixels.Type];
50
53
 
51
54
  if (Pixels.PhysicalSizeX && Pixels.PhysicalSizeY) {
52
- const physicalSizes = {
55
+ var physicalSizes = {
53
56
  x: {
54
57
  size: Pixels.PhysicalSizeX,
55
58
  unit: Pixels.PhysicalSizeXUnit
@@ -68,17 +71,17 @@ function getOmePixelSourceMeta({
68
71
  }
69
72
 
70
73
  return {
71
- labels,
72
- getShape,
73
- physicalSizes,
74
- dtype
74
+ labels: labels,
75
+ getShape: getShape,
76
+ physicalSizes: physicalSizes,
77
+ dtype: dtype
75
78
  };
76
79
  }
77
80
 
78
81
  return {
79
- labels,
80
- getShape,
81
- dtype
82
+ labels: labels,
83
+ getShape: getShape,
84
+ dtype: dtype
82
85
  };
83
86
  }
84
87
  //# sourceMappingURL=ome-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/ome/ome-utils.ts"],"names":["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;;AAGO,MAAMA,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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AAM,CAACkB,IAAR,CAA1B;;AACA,MAAIlB,MAAM,CAACqB,aAAP,IAAwBrB,MAAM,CAACsB,aAAnC,EAAkD;AAChD,UAAMC,aAEL,GAAG;AACFC,MAAAA,CAAC,EAAE;AACDC,QAAAA,IAAI,EAAEzB,MAAM,CAACqB,aADZ;AAEDK,QAAAA,IAAI,EAAE1B,MAAM,CAAC2B;AAFZ,OADD;AAKFC,MAAAA,CAAC,EAAE;AACDH,QAAAA,IAAI,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"}
1
+ {"version":3,"sources":["../../../../src/lib/ome/ome-utils.ts"],"names":["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;;AAGO,IAAMA,YAAY,GAAG;AAC1BC,EAAAA,KAAK,EAAE,OADmB;AAE1BC,EAAAA,MAAM,EAAE,QAFkB;AAG1BC,EAAAA,MAAM,EAAE,QAHkB;AAI1BC,EA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AAK,sBAAenB,MAAM,CAACkB,IAAtB,qBAAX;AACD;;AAED,MAAME,KAAK,GAAG9B,YAAY,CAACU,MAAM,CAACkB,IAAR,CAA1B;;AACA,MAAIlB,MAAM,CAACqB,aAAP,IAAwBrB,MAAM,CAACsB,aAAnC,EAAkD;AAChD,QAAMC,aAEL,GAAG;AACFC,MAAAA,CAAC,EAAE;AACDC,QAAAA,IAAI,EAAEzB,MAAM,CAACqB,aADZ;AAEDK,QAAAA,IAAI,EAAE1B,MAAM,CAAC2B;AAFZ,OADD;AAKFC,MAAAA,CAAC,EAAE;AACDH,QAAAA,IAAI,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,MAAM,EAANA,MAAD;AAASY,MAAAA,QAAQ,EAARA,QAAT;AAAmBU,MAAAA,aAAa,EAAbA,aAAnB;AAAkCH,MAAAA,KAAK,EAALA;AAAlC,KAAP;AACD;;AAED,SAAO;AAACnB,IAAAA,MAAM,EAANA,MAAD;AAASY,IAAAA,QAAQ,EAARA,QAAT;AAAmBO,IAAAA,KAAK,EAALA;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"}
@@ -7,11 +7,17 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.fromString = fromString;
9
9
 
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
10
12
  var _fastXmlParser = _interopRequireDefault(require("fast-xml-parser"));
11
13
 
12
14
  var _tiffUtils = require("../utils/tiff-utils");
13
15
 
14
- const PARSER_OPTIONS = {
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
17
+
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
19
+
20
+ var PARSER_OPTIONS = {
15
21
  attributeNamePrefix: '',
16
22
  attrNodeName: 'attr',
17
23
  parseNodeValue: true,
@@ -19,46 +25,46 @@ const PARSER_OPTIONS = {
19
25
  ignoreAttributes: false
20
26
  };
21
27
 
22
- const parse = str => _fastXmlParser.default.parse(str, PARSER_OPTIONS);
28
+ var parse = function parse(str) {
29
+ return _fastXmlParser.default.parse(str, PARSER_OPTIONS);
30
+ };
23
31
 
24
32
  function fromString(str) {
25
- const res = parse(str);
33
+ var res = parse(str);
26
34
 
27
35
  if (!res.OME) {
28
36
  throw Error('Failed to parse OME-XML metadata.');
29
37
  }
30
38
 
31
- return (0, _tiffUtils.ensureArray)(res.OME.Image).map(img => {
32
- const Channels = (0, _tiffUtils.ensureArray)(img.Pixels.Channel).map(c => {
39
+ return (0, _tiffUtils.ensureArray)(res.OME.Image).map(function (img) {
40
+ var Channels = (0, _tiffUtils.ensureArray)(img.Pixels.Channel).map(function (c) {
33
41
  if ('Color' in c.attr) {
34
- return { ...c.attr,
42
+ return _objectSpread(_objectSpread({}, c.attr), {}, {
35
43
  Color: (0, _tiffUtils.intToRgba)(c.attr.Color)
36
- };
44
+ });
37
45
  }
38
46
 
39
- return { ...c.attr
40
- };
47
+ return _objectSpread({}, c.attr);
48
+ });
49
+ var _img$AquisitionDate = img.AquisitionDate,
50
+ AquisitionDate = _img$AquisitionDate === void 0 ? '' : _img$AquisitionDate,
51
+ _img$Description = img.Description,
52
+ Description = _img$Description === void 0 ? '' : _img$Description;
53
+
54
+ var image = _objectSpread(_objectSpread({}, img.attr), {}, {
55
+ AquisitionDate: AquisitionDate,
56
+ Description: Description,
57
+ Pixels: _objectSpread(_objectSpread({}, img.Pixels.attr), {}, {
58
+ Channels: Channels
59
+ })
41
60
  });
42
- const {
43
- AquisitionDate = '',
44
- Description = ''
45
- } = img;
46
- const image = { ...img.attr,
47
- AquisitionDate,
48
- Description,
49
- Pixels: { ...img.Pixels.attr,
50
- Channels
51
- }
52
- };
53
- return { ...image,
54
61
 
55
- format() {
56
- const {
57
- Pixels
58
- } = image;
59
- const sizes = ['X', 'Y', 'Z'].map(name => {
60
- const size = Pixels["PhysicalSize".concat(name)];
61
- const unit = Pixels["PhysicalSize".concat(name, "Unit")];
62
+ return _objectSpread(_objectSpread({}, image), {}, {
63
+ format: function format() {
64
+ var Pixels = image.Pixels;
65
+ var sizes = ['X', 'Y', 'Z'].map(function (name) {
66
+ var size = Pixels["PhysicalSize".concat(name)];
67
+ var unit = Pixels["PhysicalSize".concat(name, "Unit")];
62
68
  return size && unit ? "".concat(size, " ").concat(unit) : '-';
63
69
  }).join(' x ');
64
70
  return {
@@ -70,8 +76,7 @@ function fromString(str) {
70
76
  Channels: Pixels.SizeC
71
77
  };
72
78
  }
73
-
74
- };
79
+ });
75
80
  });
76
81
  }
77
82
  //# sourceMappingURL=omexml.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/ome/omexml.ts"],"names":["PARSER_OPTIONS","attributeNamePrefix","attrNodeName","parseNodeValue","parseAttributeValue","ignoreAttributes","parse","str","parser","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"],"mappings":";;;;;;;;;AAAA;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AGQ,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"}
1
+ {"version":3,"sources":["../../../../src/lib/ome/omexml.ts"],"names":["PARSER_OPTIONS","attributeNamePrefix","attrNodeName","parseNodeValue","parseAttributeValue","ignoreAttributes","parse","str","parser","fromString","res","OME","Error","Image","map","img","Channels","Pixels","Channel","c","attr","Color","AquisitionDate","Description","image","format","sizes","name","size","unit","join","S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,MAAAA,WAAW,EAAXA,WAHS;AAITN,MAAAA,MAAM,kCACDF,GAAG,CAACE,MAAJ,CAAWG,IADV;AAEJJ,QAAAA,QAAQ,EAARA;AAFI;AAJG,MAAX;;AASA,2CACKQ,KADL;AAEEC,MAAAA,MAFF,oBAEW;AACP,YAAOR,MAAP,GAAiBO,KAAjB,CAAOP,MAAP;AAEA,YAAMS,KAAK,GAAI,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,CAAD,CACXZ,GADW,CACP,UAACa,IAAD,EAAU;AACb,cAAMC,IAAI,GAAGX,MAAM,uBAAgBU,IAAhB,EAAnB;AACA,cAAME,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;AArBH;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"}
@@ -11,14 +11,16 @@ function getLabels(dimOrder) {
11
11
  }
12
12
 
13
13
  function getDims(labels) {
14
- const lookup = new Map(labels.map((name, i) => [name, i]));
14
+ var lookup = new Map(labels.map(function (name, i) {
15
+ return [name, i];
16
+ }));
15
17
 
16
18
  if (lookup.size !== labels.length) {
17
19
  throw Error('Labels must be unique, found duplicated label.');
18
20
  }
19
21
 
20
- return name => {
21
- const index = lookup.get(name);
22
+ return function (name) {
23
+ var index = lookup.get(name);
22
24
 
23
25
  if (index === undefined) {
24
26
  throw Error('Invalid dimension.');
@@ -1 +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":";;;;;;;;AAaO,SAASA,SAAT,CAAmBC,QAAnB,EAAoE;AACzE,SAAOA,QAAQ,CAACC,WAAT,GAAuBC,KAAvB,CAA6B,EAA7B,EAAiCC,OAAjC,EAAP;AACD;;AAWM,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
+ {"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":";;;;;;;;AAaO,SAASA,SAAT,CAAmBC,QAAnB,EAAoE;AACzE,SAAOA,QAAQ,CAACC,WAAT,GAAuBC,KAAvB,CAA6B,EAA7B,EAAiCC,OAAjC,EAAP;AACD;;AAWM,SAASC,OAAT,CAAmCC,MAAnC,EAAgD;AACrD,MAAMC,MAAM,GAAG,IAAIC,GAAJ,CAAQF,MAAM,CAACG,GAAP,CAAW,UAACC,IAAD,EAAOC,CAAP;AAAA,WAAa,CAACD,IAAD,EAAOC,CAAP,CAAb;AAAA,GAAX,CAAR,CAAf;;AACA,MAAIJ,MAAM,CAACK,IAAP,KAAgBN,MAAM,CAACO,MAA3B,EAAmC;AACjC,UAAMC,KAAK,CAAC,gDAAD,CAAX;AACD;;AACD,SAAO,UAACJ,IAAD,EAAa;AAClB,QAAMK,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"}
@@ -7,12 +7,25 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
 
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
+
14
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
+
16
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
+
10
18
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
19
 
12
20
  var _tiffUtils = require("./utils/tiff-utils");
13
21
 
14
- class TiffPixelSource {
15
- constructor(indexer, dtype, tileSize, shape, labels, meta) {
22
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
23
+
24
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
25
+
26
+ var TiffPixelSource = function () {
27
+ function TiffPixelSource(indexer, dtype, tileSize, shape, labels, meta) {
28
+ (0, _classCallCheck2.default)(this, TiffPixelSource);
16
29
  (0, _defineProperty2.default)(this, "dtype", void 0);
17
30
  (0, _defineProperty2.default)(this, "tileSize", void 0);
18
31
  (0, _defineProperty2.default)(this, "shape", void 0);
@@ -27,89 +40,162 @@ class TiffPixelSource {
27
40
  this.meta = meta;
28
41
  }
29
42
 
30
- async getRaster({
31
- selection,
32
- signal
33
- }) {
34
- const image = await this._indexer(selection);
35
- return this._readRasters(image, {
36
- signal
37
- });
38
- }
39
-
40
- async getTile({
41
- x,
42
- y,
43
- selection,
44
- signal
45
- }) {
46
- const {
47
- height,
48
- width
49
- } = this._getTileExtent(x, y);
50
-
51
- const x0 = x * this.tileSize;
52
- const y0 = y * this.tileSize;
53
- const window = [x0, y0, x0 + width, y0 + height];
54
- const image = await this._indexer(selection);
55
- return this._readRasters(image, {
56
- window,
57
- width,
58
- height,
59
- signal
60
- });
61
- }
62
-
63
- async _readRasters(image, props) {
64
- var _props$signal;
65
-
66
- const interleave = (0, _tiffUtils.isInterleaved)(this.shape);
67
- const raster = await image.readRasters({
68
- interleave,
69
- ...props
70
- });
71
-
72
- if (props !== null && props !== void 0 && (_props$signal = props.signal) !== null && _props$signal !== void 0 && _props$signal.aborted) {
73
- throw _tiffUtils.SIGNAL_ABORTED;
74
- }
75
-
76
- const data = interleave ? raster : raster[0];
77
- return {
78
- data,
79
- width: raster.width,
80
- height: raster.height
81
- };
82
- }
83
-
84
- _getTileExtent(x, y) {
85
- const {
86
- height: zoomLevelHeight,
87
- width: zoomLevelWidth
88
- } = (0, _tiffUtils.getImageSize)(this);
89
- let height = this.tileSize;
90
- let width = this.tileSize;
91
- const maxXTileCoord = Math.floor(zoomLevelWidth / this.tileSize);
92
- const maxYTileCoord = Math.floor(zoomLevelHeight / this.tileSize);
93
-
94
- if (x === maxXTileCoord) {
95
- width = zoomLevelWidth % this.tileSize;
43
+ (0, _createClass2.default)(TiffPixelSource, [{
44
+ key: "getRaster",
45
+ value: function () {
46
+ var _getRaster = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(_ref) {
47
+ var selection, signal, image;
48
+ return _regenerator.default.wrap(function _callee$(_context) {
49
+ while (1) {
50
+ switch (_context.prev = _context.next) {
51
+ case 0:
52
+ selection = _ref.selection, signal = _ref.signal;
53
+ _context.next = 3;
54
+ return this._indexer(selection);
55
+
56
+ case 3:
57
+ image = _context.sent;
58
+ return _context.abrupt("return", this._readRasters(image, {
59
+ signal: signal
60
+ }));
61
+
62
+ case 5:
63
+ case "end":
64
+ return _context.stop();
65
+ }
66
+ }
67
+ }, _callee, this);
68
+ }));
69
+
70
+ function getRaster(_x) {
71
+ return _getRaster.apply(this, arguments);
72
+ }
73
+
74
+ return getRaster;
75
+ }()
76
+ }, {
77
+ key: "getTile",
78
+ value: function () {
79
+ var _getTile = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(_ref2) {
80
+ var x, y, selection, signal, _this$_getTileExtent, height, width, x0, y0, window, image;
81
+
82
+ return _regenerator.default.wrap(function _callee2$(_context2) {
83
+ while (1) {
84
+ switch (_context2.prev = _context2.next) {
85
+ case 0:
86
+ x = _ref2.x, y = _ref2.y, selection = _ref2.selection, signal = _ref2.signal;
87
+ _this$_getTileExtent = this._getTileExtent(x, y), height = _this$_getTileExtent.height, width = _this$_getTileExtent.width;
88
+ x0 = x * this.tileSize;
89
+ y0 = y * this.tileSize;
90
+ window = [x0, y0, x0 + width, y0 + height];
91
+ _context2.next = 7;
92
+ return this._indexer(selection);
93
+
94
+ case 7:
95
+ image = _context2.sent;
96
+ return _context2.abrupt("return", this._readRasters(image, {
97
+ window: window,
98
+ width: width,
99
+ height: height,
100
+ signal: signal
101
+ }));
102
+
103
+ case 9:
104
+ case "end":
105
+ return _context2.stop();
106
+ }
107
+ }
108
+ }, _callee2, this);
109
+ }));
110
+
111
+ function getTile(_x2) {
112
+ return _getTile.apply(this, arguments);
113
+ }
114
+
115
+ return getTile;
116
+ }()
117
+ }, {
118
+ key: "_readRasters",
119
+ value: function () {
120
+ var _readRasters2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(image, props) {
121
+ var _props$signal;
122
+
123
+ var interleave, raster, data;
124
+ return _regenerator.default.wrap(function _callee3$(_context3) {
125
+ while (1) {
126
+ switch (_context3.prev = _context3.next) {
127
+ case 0:
128
+ interleave = (0, _tiffUtils.isInterleaved)(this.shape);
129
+ _context3.next = 3;
130
+ return image.readRasters(_objectSpread({
131
+ interleave: interleave
132
+ }, props));
133
+
134
+ case 3:
135
+ raster = _context3.sent;
136
+
137
+ if (!(props !== null && props !== void 0 && (_props$signal = props.signal) !== null && _props$signal !== void 0 && _props$signal.aborted)) {
138
+ _context3.next = 6;
139
+ break;
140
+ }
141
+
142
+ throw _tiffUtils.SIGNAL_ABORTED;
143
+
144
+ case 6:
145
+ data = interleave ? raster : raster[0];
146
+ return _context3.abrupt("return", {
147
+ data: data,
148
+ width: raster.width,
149
+ height: raster.height
150
+ });
151
+
152
+ case 8:
153
+ case "end":
154
+ return _context3.stop();
155
+ }
156
+ }
157
+ }, _callee3, this);
158
+ }));
159
+
160
+ function _readRasters(_x3, _x4) {
161
+ return _readRasters2.apply(this, arguments);
162
+ }
163
+
164
+ return _readRasters;
165
+ }()
166
+ }, {
167
+ key: "_getTileExtent",
168
+ value: function _getTileExtent(x, y) {
169
+ var _getImageSize = (0, _tiffUtils.getImageSize)(this),
170
+ zoomLevelHeight = _getImageSize.height,
171
+ zoomLevelWidth = _getImageSize.width;
172
+
173
+ var height = this.tileSize;
174
+ var width = this.tileSize;
175
+ var maxXTileCoord = Math.floor(zoomLevelWidth / this.tileSize);
176
+ var maxYTileCoord = Math.floor(zoomLevelHeight / this.tileSize);
177
+
178
+ if (x === maxXTileCoord) {
179
+ width = zoomLevelWidth % this.tileSize;
180
+ }
181
+
182
+ if (y === maxYTileCoord) {
183
+ height = zoomLevelHeight % this.tileSize;
184
+ }
185
+
186
+ return {
187
+ height: height,
188
+ width: width
189
+ };
96
190
  }
97
-
98
- if (y === maxYTileCoord) {
99
- height = zoomLevelHeight % this.tileSize;
191
+ }, {
192
+ key: "onTileError",
193
+ value: function onTileError(err) {
194
+ console.error(err);
100
195
  }
101
-
102
- return {
103
- height,
104
- width
105
- };
106
- }
107
-
108
- onTileError(err) {
109
- console.error(err);
110
- }
111
-
112
- }
196
+ }]);
197
+ return TiffPixelSource;
198
+ }();
113
199
 
114
200
  var _default = TiffPixelSource;
115
201
  exports.default = _default;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/tiff-pixel-source.ts"],"names":["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","SIGNAL_ABORTED","data","zoomLevelHeight","zoomLevelWidth","maxXTileCoord","Math","floor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,KAAK1B,QAAhC;AACD;;AACD,WAAO;AAACa,MAAAA,MAAD;AAASC,MAAAA;AAAT,KAAP;AACD;;AAEDkB,EAAAA,WAAW,CAACC,GAAD,EAAa;AACtBC,IAAAA,OAAO,CAACC,KAAR,CAAcF,GAAd;AACD;;AAhFiE;;eAmFrDrC,e","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"}
1
+ {"version":3,"sources":["../../../src/lib/tiff-pixel-source.ts"],"names":["TiffPixelSource","indexer","dtype","tileSize","shape","labels","meta","_indexer","selection","signal","image","_readRasters","x","y","_getTileExtent","height","width","x0","y0","window","props","interleave","readRasters","raster","aborted","SIGNAL_ABORTED","data","zoomLevelHeight","zoomLevelWidth","maxXTileCoord","Math","floor","maxYTileCoord","err","console","error"],"mappings":";;;;;;;;;;;;;;;;;;;AACA;;;;;;IAcMA,e;AASJ,2BACEC,OADF,EAEEC,KAFF,EAGEC,QAHF,EAIEC,KAJF,EAKEC,MALF,EAMEC,IANF,EAOE;AAAA;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;;;;;iFAED;AAAA;AAAA;AAAA;AAAA;AAAA;AAAiBE,gBAAAA,SAAjB,QAAiBA,SAAjB,EAA4BC,MAA5B,Q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ACD;;;WAED,qBAAYiB,GAAZ,EAAwB;AACtBC,MAAAA,OAAO,CAACC,KAAR,CAAcF,GAAd;AACD;;;;;eAGYjC,e","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"}