@loaders.gl/geotiff 4.0.0-alpha.9 → 4.0.0-beta.1

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.
@@ -6,19 +6,19 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.fromString = fromString;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _fastXmlParser = _interopRequireDefault(require("fast-xml-parser"));
9
+ var _fastXmlParser = require("fast-xml-parser");
10
10
  var _tiffUtils = require("../utils/tiff-utils");
11
11
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
12
12
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
13
- var PARSER_OPTIONS = {
13
+ var xmlParser = new _fastXmlParser.XMLParser({
14
14
  attributeNamePrefix: '',
15
- attrNodeName: 'attr',
16
- parseNodeValue: true,
15
+ attributesGroupName: 'attr',
16
+ parseTagValue: true,
17
17
  parseAttributeValue: true,
18
18
  ignoreAttributes: false
19
- };
19
+ });
20
20
  var parse = function parse(str) {
21
- return _fastXmlParser.default.parse(str, PARSER_OPTIONS);
21
+ return xmlParser.parse(str);
22
22
  };
23
23
  function fromString(str) {
24
24
  var res = parse(str);
@@ -1 +1 @@
1
- {"version":3,"file":"omexml.js","names":["_fastXmlParser","_interopRequireDefault","require","_tiffUtils","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","PARSER_OPTIONS","attributeNamePrefix","attrNodeName","parseNodeValue","parseAttributeValue","ignoreAttributes","parse","str","parser","fromString","res","OME","Error","ensureArray","Image","map","img","Channels","Pixels","Channel","c","attr","Color","intToRgba","_img$AquisitionDate","AquisitionDate","_img$Description","Description","image","format","sizes","name","size","concat","unit","join","SizeX","SizeY","Type","SizeZ","SizeT","SizeC"],"sources":["../../../../src/lib/ome/omexml.ts"],"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"],"mappings":";;;;;;;;AAAA,IAAAA,cAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAA2D,SAAAE,QAAAC,MAAA,EAAAC,cAAA,QAAAC,IAAA,GAAAC,MAAA,CAAAD,IAAA,CAAAF,MAAA,OAAAG,MAAA,CAAAC,qBAAA,QAAAC,OAAA,GAAAF,MAAA,CAAAC,qBAAA,CAAAJ,MAAA,GAAAC,cAAA,KAAAI,OAAA,GAAAA,OAAA,CAAAC,MAAA,WAAAC,GAAA,WAAAJ,MAAA,CAAAK,wBAAA,CAAAR,MAAA,EAAAO,GAAA,EAAAE,UAAA,OAAAP,IAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,IAAA,EAAAG,OAAA,YAAAH,IAAA;AAAA,SAAAU,cAAAC,MAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAC,SAAA,CAAA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AO;UACL,kBAAkB,EAAEP,KAAK,CAACH,cAAc;UACxC,iBAAiB,KAAAQ,MAAA,CAAKf,MAAM,CAACkB,KAAK,SAAAH,MAAA,CAAMf,MAAM,CAACmB,KAAK,CAAE;UACtD,aAAa,EAAEnB,MAAM,CAACoB,IAAI;UAC1B,mBAAmB,EAAER,KAAK;UAC1B,uBAAuB,KAAAG,MAAA,CAAKf,MAAM,CAACqB,KAAK,SAAAN,MAAA,CAAMf,MAAM,CAACsB,KAAK,CAAE;UAC5DvB,QAAQ,EAAEC,MAAM,CAACuB;QACnB,CAAC;MACH;IAAC;EAEL,CAAC,CAAC;AACJ"}
1
+ {"version":3,"file":"omexml.js","names":["_fastXmlParser","require","_tiffUtils","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","xmlParser","XMLParser","attributeNamePrefix","attributesGroupName","parseTagValue","parseAttributeValue","ignoreAttributes","parse","str","fromString","res","OME","Error","ensureArray","Image","map","img","Channels","Pixels","Channel","c","attr","Color","intToRgba","_img$AquisitionDate","AquisitionDate","_img$Description","Description","image","format","sizes","name","size","concat","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<{}, ChannelAttrs>;\n\ntype Root = {OME: OME};\n"],"mappings":";;;;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAA2D,SAAAE,QAAAC,MAAA,EAAAC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ACP,IAAOX,MAAM,GAAIU,KAAK,CAAfV,MAAM;QAEb,IAAMY,KAAK,GAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAC3Bf,GAAG,CAAC,UAACgB,IAAI,EAAK;UACb,IAAMC,IAAI,GAAGd,MAAM,gBAAAe,MAAA,CAAgBF,IAAI,EAAY;UACnD,IAAMG,IAAI,GAAGhB,MAAM,gBAAAe,MAAA,CAAgBF,IAAI,UAAgB;UACvD,OAAOC,IAAI,IAAIE,IAAI,MAAAD,MAAA,CAAMD,IAAI,OAAAC,MAAA,CAAIC,IAAI,IAAK,GAAG;QAC/C,CAAC,CAAC,CACDC,IAAI,CAAC,KAAK,CAAC;QAEd,OAAO;UACL,kBAAkB,EAAEP,KAAK,CAACH,cAAc;UACxC,iBAAiB,KAAAQ,MAAA,CAAKf,MAAM,CAACkB,KAAK,SAAAH,MAAA,CAAMf,MAAM,CAACmB,KAAK,CAAE;UACtD,aAAa,EAAEnB,MAAM,CAACoB,IAAI;UAC1B,mBAAmB,EAAER,KAAK;UAC1B,uBAAuB,KAAAG,MAAA,CAAKf,MAAM,CAACqB,KAAK,SAAAN,MAAA,CAAMf,MAAM,CAACsB,KAAK,CAAE;UAC5DvB,QAAQ,EAAEC,MAAM,CAACuB;QACnB,CAAC;MACH;IAAC;EAEL,CAAC,CAAC;AACJ"}
@@ -1,13 +1,13 @@
1
- import parser from 'fast-xml-parser';
1
+ import { XMLParser } from 'fast-xml-parser';
2
2
  import { ensureArray, intToRgba } from '../utils/tiff-utils';
3
- const PARSER_OPTIONS = {
3
+ const xmlParser = new XMLParser({
4
4
  attributeNamePrefix: '',
5
- attrNodeName: 'attr',
6
- parseNodeValue: true,
5
+ attributesGroupName: 'attr',
6
+ parseTagValue: true,
7
7
  parseAttributeValue: true,
8
8
  ignoreAttributes: false
9
- };
10
- const parse = str => parser.parse(str, PARSER_OPTIONS);
9
+ });
10
+ const parse = str => xmlParser.parse(str);
11
11
  export function fromString(str) {
12
12
  const res = parse(str);
13
13
  if (!res.OME) {
@@ -1 +1 @@
1
- {"version":3,"file":"omexml.js","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","concat","unit","join","SizeX","SizeY","Type","SizeZ","SizeT","SizeC"],"sources":["../../../../src/lib/ome/omexml.ts"],"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"],"mappings":"AAAA,OAAOA,MAAM,MAAM,iBAAiB;AACpC,SAAQC,WAAW,EAAEC,SAAS,QAAO,qBAAqB;AAG1D,MAAMC,cAAc,GAAG;EAErBC,mBAAmB,EAAE,EAAE;EACvBC,YAAY,EAAE,MAAM;EAGpBC,cAAc,EAAE,IAAI;EACpBC,mBAAmB,EAAE,IAAI;EAGzBC,gBAAgB,EAAE;AACpB,CAAC;AAED,MAAMC,KAAK,GAAIC,GAAW,IAAWV,MAAM,CAACS,KAAK,CAACC,GAAG,EAAEP,cAAc,CAAC;AAEtE,OAAO,SAASQ,UAAUA,CAACD,GAAW,EAAE;EACtC,MAAME,GAAG,GAAGH,KAAK,CAACC,GAAG,CAAC;EACtB,IAAI,CAACE,GAAG,CAACC,GAAG,EAAE;IACZ,MAAMC,KAAK,CAAC,mCAAmC,CAAC;EAClD;EACA,OAAOb,WAAW,CAACW,GAAG,CAACC,GAAG,CAACE,KAAK,CAAC,CAACC,GAAG,CAAEC,GAAG,IAAK;IAC7C,MAAMC,QAAQ,GAAGjB,WAAW,CAAC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AC1B,mBAAmB,EAAER,KAAK;UAC1B,uBAAuB,KAAAG,MAAA,CAAKZ,MAAM,CAACkB,KAAK,SAAAN,MAAA,CAAMZ,MAAM,CAACmB,KAAK,CAAE;UAC5DpB,QAAQ,EAAEC,MAAM,CAACoB;QACnB,CAAC;MACH;IACF,CAAC;EACH,CAAC,CAAC;AACJ"}
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","concat","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<{}, ChannelAttrs>;\n\ntype Root = {OME: OME};\n"],"mappings":"AAAA,SAAQA,SAAS,QAAO,iBAAiB;AACzC,SAAQC,WAAW,EAAEC,SAAS,QAAO,qBAAqB;AAG1D,MAAMC,SAAS,GAAG,IAAIH,SAAS,CAAC;EAE9BI,mBAAmB,EAAE,EAAE;EACvBC,mBAAmB,EAAE,MAAM;EAG3BC,aAAa,EAAE,IAAI;EACnBC,mBAAmB,EAAE,IAAI;EAGzBC,gBAAgB,EAAE;AACpB,CAAC,CAAC;AAEF,MAAMC,KAAK,GAAIC,GAAW,IAAWP,SAAS,CAACM,KAAK,CAACC,GAAG,CAAC;AAEzD,OAAO,SAASC,UAAUA,CAACD,GAAW,EAAE;EACtC,MAAME,GAAG,GAAGH,KAAK,CAACC,GAAG,CAAC;EACtB,IAAI,CAACE,GAAG,CAACC,GAAG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AO;UACL,kBAAkB,EAAEP,KAAK,CAACF,cAAc;UACxC,iBAAiB,KAAAO,MAAA,CAAKZ,MAAM,CAACe,KAAK,SAAAH,MAAA,CAAMZ,MAAM,CAACgB,KAAK,CAAE;UACtD,aAAa,EAAEhB,MAAM,CAACiB,IAAI;UAC1B,mBAAmB,EAAER,KAAK;UAC1B,uBAAuB,KAAAG,MAAA,CAAKZ,MAAM,CAACkB,KAAK,SAAAN,MAAA,CAAMZ,MAAM,CAACmB,KAAK,CAAE;UAC5DpB,QAAQ,EAAEC,MAAM,CAACoB;QACnB,CAAC;MACH;IACF,CAAC;EACH,CAAC,CAAC;AACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/geotiff",
3
- "version": "4.0.0-alpha.9",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "Framework-independent loaders for tiff and geotiff",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -36,8 +36,8 @@
36
36
  "geotiff": "ilan-gold/geotiff.js#ilan-gold/viv_094"
37
37
  },
38
38
  "dependencies": {
39
- "fast-xml-parser": "^3.16.0",
39
+ "fast-xml-parser": "^4.2.5",
40
40
  "geotiff": "^1.0.4"
41
41
  },
42
- "gitHead": "03ff81ab468f20f3bddeec787aa88d477a7e1c72"
42
+ "gitHead": "35c625e67132b0784e597d9ddabae8aefea29ff2"
43
43
  }
@@ -1,21 +1,21 @@
1
- import parser from 'fast-xml-parser';
1
+ import {XMLParser} from 'fast-xml-parser';
2
2
  import {ensureArray, intToRgba} from '../utils/tiff-utils';
3
3
 
4
4
  // WARNING: Changes to the parser options _will_ effect the types in types/omexml.d.ts.
5
- const PARSER_OPTIONS = {
5
+ const xmlParser = new XMLParser({
6
6
  // Nests attributes withtout prefix under 'attr' key for each node
7
7
  attributeNamePrefix: '',
8
- attrNodeName: 'attr',
8
+ attributesGroupName: 'attr',
9
9
 
10
10
  // Parses numbers for both attributes and nodes
11
- parseNodeValue: true,
11
+ parseTagValue: true,
12
12
  parseAttributeValue: true,
13
13
 
14
14
  // Forces attributes to be parsed
15
15
  ignoreAttributes: false
16
- };
16
+ });
17
17
 
18
- const parse = (str: string): Root => parser.parse(str, PARSER_OPTIONS);
18
+ const parse = (str: string): Root => xmlParser.parse(str);
19
19
 
20
20
  export function fromString(str: string) {
21
21
  const res = parse(str);
package/dist/bundle.js DELETED
@@ -1,30 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const moduleExports = __importStar(require("./index"));
27
- // @ts-ignore
28
- globalThis.loaders = globalThis.loaders || {};
29
- // @ts-ignore
30
- module.exports = Object.assign(globalThis.loaders, moduleExports);
package/dist/index.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TiffPixelSource = exports.loadGeoTiff = void 0;
7
- var load_geotiff_1 = require("./lib/load-geotiff");
8
- Object.defineProperty(exports, "loadGeoTiff", { enumerable: true, get: function () { return load_geotiff_1.loadGeoTiff; } });
9
- var tiff_pixel_source_1 = require("./lib/tiff-pixel-source");
10
- Object.defineProperty(exports, "TiffPixelSource", { enumerable: true, get: function () { return __importDefault(tiff_pixel_source_1).default; } });
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadGeoTiff = void 0;
4
- const geotiff_1 = require("geotiff");
5
- const proxies_1 = require("./utils/proxies");
6
- // import Pool from './lib/Pool';
7
- const load_ome_tiff_1 = require("./ome/load-ome-tiff");
8
- /**
9
- * Opens an OME-TIFF via URL and returns data source and associated metadata for first image.
10
- *
11
- * @param source url string, File/Blob object, or GeoTIFF object
12
- * @param opts options for initializing a tiff pixel source.
13
- * - `opts.headers` are passed to each underlying fetch request.
14
- * - `opts.offsets` are a performance enhancment to index the remote tiff source using pre-computed byte-offsets.
15
- * - `opts.pool` indicates whether a multi-threaded pool of image decoders should be used to decode tiles (default = true).
16
- * @return data source and associated OME-Zarr metadata.
17
- */
18
- async function loadGeoTiff(source, opts = {}) {
19
- const { headers, offsets } = opts;
20
- // Create tiff source
21
- let tiff;
22
- if (source instanceof geotiff_1.GeoTIFF) {
23
- tiff = source;
24
- }
25
- else if (typeof source === 'string') {
26
- tiff = await (0, geotiff_1.fromUrl)(source, headers);
27
- }
28
- else {
29
- tiff = await (0, geotiff_1.fromBlob)(source);
30
- }
31
- // if (pool) {
32
- /*
33
- * Creates a worker pool to decode tiff tiles. Wraps tiff
34
- * in a Proxy that injects 'pool' into `tiff.readRasters`.
35
- */
36
- // tiff = createPoolProxy(tiff, new Pool());
37
- // }
38
- if (offsets) {
39
- /*
40
- * Performance enhancement. If offsets are provided, we
41
- * create a proxy that intercepts calls to `tiff.getImage`
42
- * and injects the pre-computed offsets.
43
- */
44
- tiff = (0, proxies_1.createOffsetsProxy)(tiff, offsets);
45
- }
46
- /*
47
- * Inspect tiff source for our performance enhancing proxies.
48
- * Prints warnings to console if `offsets` or `pool` are missing.
49
- */
50
- (0, proxies_1.checkProxies)(tiff);
51
- const firstImage = await tiff.getImage(0);
52
- if ((0, load_ome_tiff_1.isOmeTiff)(firstImage)) {
53
- return (0, load_ome_tiff_1.loadOmeTiff)(tiff, firstImage);
54
- }
55
- throw new Error('GeoTIFF not recognized.');
56
- }
57
- exports.loadGeoTiff = loadGeoTiff;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.loadOmeTiff = exports.isOmeTiff = void 0;
7
- const tiff_pixel_source_1 = __importDefault(require("../tiff-pixel-source"));
8
- const ome_indexers_1 = require("./ome-indexers");
9
- const ome_utils_1 = require("./ome-utils");
10
- const omexml_1 = require("./omexml");
11
- const isOmeTiff = (img) => img.fileDirectory.ImageDescription.includes('<OME');
12
- exports.isOmeTiff = isOmeTiff;
13
- async function loadOmeTiff(tiff, firstImage) {
14
- // Get first image from tiff and inspect OME-XML metadata
15
- const { ImageDescription, SubIFDs, PhotometricInterpretation: photometricInterpretation } = firstImage.fileDirectory;
16
- const omexml = (0, omexml_1.fromString)(ImageDescription);
17
- /*
18
- * Image pyramids are stored differently between versions of Bioformats.
19
- * Thus we need a different indexer depending on which format we have.
20
- */
21
- let levels;
22
- let pyramidIndexer;
23
- if (SubIFDs) {
24
- // Image is >= Bioformats 6.0 and resolutions are stored using SubIFDs.
25
- levels = SubIFDs.length + 1;
26
- pyramidIndexer = (0, ome_indexers_1.getOmeSubIFDIndexer)(tiff, omexml);
27
- }
28
- else {
29
- // Image is legacy format; resolutions are stored as separate images.
30
- levels = omexml.length;
31
- pyramidIndexer = (0, ome_indexers_1.getOmeLegacyIndexer)(tiff, omexml);
32
- }
33
- // TODO: The OmeTIFF loader only works for the _first_ image in the metadata.
34
- const imgMeta = omexml[0];
35
- const { labels, getShape, physicalSizes, dtype } = (0, ome_utils_1.getOmePixelSourceMeta)(imgMeta);
36
- const tileSize = firstImage.getTileWidth();
37
- const meta = { photometricInterpretation, physicalSizes };
38
- const data = Array.from({ length: levels }).map((_, resolution) => {
39
- const shape = getShape(resolution);
40
- const indexer = (sel) => pyramidIndexer(sel, resolution);
41
- const source = new tiff_pixel_source_1.default(indexer, dtype, tileSize, shape, labels, meta);
42
- return source;
43
- });
44
- return { data, metadata: imgMeta };
45
- }
46
- exports.loadOmeTiff = loadOmeTiff;
@@ -1,108 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getOmeSubIFDIndexer = exports.getOmeLegacyIndexer = void 0;
4
- /*
5
- * An "indexer" for a GeoTIFF-based source is a function that takes a
6
- * "selection" (e.g. { z, t, c }) and returns a Promise for the GeoTIFFImage
7
- * object corresponding to that selection.
8
- *
9
- * For OME-TIFF images, the "selection" object is the same regardless of
10
- * the format version. However, modern version of Bioformats have a different
11
- * memory layout for pyramidal resolutions. Thus, we have two different "indexers"
12
- * depending on which format version is detected.
13
- *
14
- * TODO: We currently only support indexing the first image in the OME-TIFF with
15
- * our indexers. There can be multiple images in an OME-TIFF, so supporting these
16
- * images will require extending these indexers or creating new methods.
17
- */
18
- /*
19
- * Returns an indexer for legacy Bioformats images. This assumes that
20
- * downsampled resolutions are stored sequentially in the OME-TIFF.
21
- */
22
- function getOmeLegacyIndexer(tiff, rootMeta) {
23
- const imgMeta = rootMeta[0];
24
- const { SizeT, SizeC, SizeZ } = imgMeta.Pixels;
25
- const ifdIndexer = getOmeIFDIndexer(imgMeta);
26
- return (sel, pyramidLevel) => {
27
- // Get IFD index at base pyramid level
28
- const index = ifdIndexer(sel);
29
- // Get index of first image at pyramidal level
30
- const pyramidIndex = pyramidLevel * SizeZ * SizeT * SizeC;
31
- // Return image at IFD index for pyramidal level
32
- return tiff.getImage(index + pyramidIndex);
33
- };
34
- }
35
- exports.getOmeLegacyIndexer = getOmeLegacyIndexer;
36
- /*
37
- * Returns an indexer for modern Bioforamts images that store multiscale
38
- * resolutions using SubIFDs.
39
- *
40
- * The ifdIndexer returns the 'index' to the base resolution for a
41
- * particular 'selection'. The SubIFDs to the downsampled resolutions
42
- * of the 'selection' are stored within the `baseImage.fileDirectory`.
43
- * We use the SubIFDs to get the IFD for the corresponding sub-resolution.
44
- *
45
- * NOTE: This function create a custom IFD cache rather than mutating
46
- * `GeoTIFF.ifdRequests` with a random offset. The IFDs are cached in
47
- * an ES6 Map that maps a string key that identifies the selection uniquely
48
- * to the corresponding IFD.
49
- */
50
- function getOmeSubIFDIndexer(tiff, rootMeta) {
51
- const imgMeta = rootMeta[0];
52
- const ifdIndexer = getOmeIFDIndexer(imgMeta);
53
- const ifdCache = new Map();
54
- return async (sel, pyramidLevel) => {
55
- const index = ifdIndexer(sel);
56
- const baseImage = await tiff.getImage(index);
57
- // It's the highest resolution, no need to look up SubIFDs.
58
- if (pyramidLevel === 0) {
59
- return baseImage;
60
- }
61
- const { SubIFDs } = baseImage.fileDirectory;
62
- if (!SubIFDs) {
63
- throw Error('Indexing Error: OME-TIFF is missing SubIFDs.');
64
- }
65
- // Get IFD for the selection at the pyramidal level
66
- const key = `${sel.t}-${sel.c}-${sel.z}-${pyramidLevel}`;
67
- if (!ifdCache.has(key)) {
68
- // Only create a new request if we don't have the key.
69
- const subIfdOffset = SubIFDs[pyramidLevel - 1];
70
- ifdCache.set(key, tiff.parseFileDirectoryAt(subIfdOffset));
71
- }
72
- const ifd = (await ifdCache.get(key));
73
- // Create a new image object manually from IFD
74
- // https://github.com/geotiffjs/geotiff.js/blob/8ef472f41b51d18074aece2300b6a8ad91a21ae1/src/geotiff.js#L447-L453
75
- return new baseImage.constructor(ifd.fileDirectory, ifd.geoKeyDirectory, tiff.dataView, tiff.littleEndian, tiff.cache, tiff.source);
76
- };
77
- }
78
- exports.getOmeSubIFDIndexer = getOmeSubIFDIndexer;
79
- /*
80
- * Returns a function that computes the image index based on the dimension
81
- * order and dimension sizes.
82
- */
83
- function getOmeIFDIndexer(imgMeta) {
84
- const { SizeC, SizeZ, SizeT, DimensionOrder } = imgMeta.Pixels;
85
- switch (DimensionOrder) {
86
- case 'XYZCT': {
87
- return ({ t, c, z }) => t * SizeZ * SizeC + c * SizeZ + z;
88
- }
89
- case 'XYZTC': {
90
- return ({ t, c, z }) => c * SizeZ * SizeT + t * SizeZ + z;
91
- }
92
- case 'XYCTZ': {
93
- return ({ t, c, z }) => z * SizeC * SizeT + t * SizeC + c;
94
- }
95
- case 'XYCZT': {
96
- return ({ t, c, z }) => t * SizeC * SizeZ + z * SizeC + c;
97
- }
98
- case 'XYTCZ': {
99
- return ({ t, c, z }) => z * SizeT * SizeC + c * SizeT + t;
100
- }
101
- case 'XYTZC': {
102
- return ({ t, c, z }) => c * SizeT * SizeZ + z * SizeT + t;
103
- }
104
- default: {
105
- throw new Error(`Invalid OME-XML DimensionOrder, got ${DimensionOrder}.`);
106
- }
107
- }
108
- }
@@ -1,63 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getOmePixelSourceMeta = exports.DTYPE_LOOKUP = void 0;
4
- const utils_1 = require("./utils");
5
- exports.DTYPE_LOOKUP = {
6
- uint8: 'Uint8',
7
- uint16: 'Uint16',
8
- uint32: 'Uint32',
9
- float: 'Float32',
10
- double: 'Float64',
11
- int8: 'Int8',
12
- int16: 'Int16',
13
- int32: 'Int32'
14
- };
15
- function getOmePixelSourceMeta({ Pixels }) {
16
- // e.g. 'XYZCT' -> ['t', 'c', 'z', 'y', 'x']
17
- const labels = (0, utils_1.getLabels)(Pixels.DimensionOrder);
18
- // Compute "shape" of image
19
- const dims = (0, utils_1.getDims)(labels);
20
- const shape = Array(labels.length).fill(0);
21
- shape[dims('t')] = Pixels.SizeT;
22
- shape[dims('c')] = Pixels.SizeC;
23
- shape[dims('z')] = Pixels.SizeZ;
24
- // Push extra dimension if data are interleaved.
25
- if (Pixels.Interleaved) {
26
- // @ts-ignore
27
- labels.push('_c');
28
- shape.push(3);
29
- }
30
- // Creates a new shape for different level of pyramid.
31
- // Assumes factor-of-two downsampling.
32
- const getShape = (level) => {
33
- const s = [...shape];
34
- s[dims('x')] = Pixels.SizeX >> level;
35
- s[dims('y')] = Pixels.SizeY >> level;
36
- return s;
37
- };
38
- if (!(Pixels.Type in exports.DTYPE_LOOKUP)) {
39
- throw Error(`Pixel type ${Pixels.Type} not supported.`);
40
- }
41
- const dtype = exports.DTYPE_LOOKUP[Pixels.Type];
42
- if (Pixels.PhysicalSizeX && Pixels.PhysicalSizeY) {
43
- const physicalSizes = {
44
- x: {
45
- size: Pixels.PhysicalSizeX,
46
- unit: Pixels.PhysicalSizeXUnit
47
- },
48
- y: {
49
- size: Pixels.PhysicalSizeY,
50
- unit: Pixels.PhysicalSizeYUnit
51
- }
52
- };
53
- if (Pixels.PhysicalSizeZ) {
54
- physicalSizes.z = {
55
- size: Pixels.PhysicalSizeZ,
56
- unit: Pixels.PhysicalSizeZUnit
57
- };
58
- }
59
- return { labels, getShape, physicalSizes, dtype };
60
- }
61
- return { labels, getShape, dtype };
62
- }
63
- exports.getOmePixelSourceMeta = getOmePixelSourceMeta;
@@ -1,66 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.fromString = void 0;
7
- const fast_xml_parser_1 = __importDefault(require("fast-xml-parser"));
8
- const tiff_utils_1 = require("../utils/tiff-utils");
9
- // WARNING: Changes to the parser options _will_ effect the types in types/omexml.d.ts.
10
- const PARSER_OPTIONS = {
11
- // Nests attributes withtout prefix under 'attr' key for each node
12
- attributeNamePrefix: '',
13
- attrNodeName: 'attr',
14
- // Parses numbers for both attributes and nodes
15
- parseNodeValue: true,
16
- parseAttributeValue: true,
17
- // Forces attributes to be parsed
18
- ignoreAttributes: false
19
- };
20
- const parse = (str) => fast_xml_parser_1.default.parse(str, PARSER_OPTIONS);
21
- function fromString(str) {
22
- const res = parse(str);
23
- if (!res.OME) {
24
- throw Error('Failed to parse OME-XML metadata.');
25
- }
26
- return (0, tiff_utils_1.ensureArray)(res.OME.Image).map((img) => {
27
- const Channels = (0, tiff_utils_1.ensureArray)(img.Pixels.Channel).map((c) => {
28
- if ('Color' in c.attr) {
29
- return { ...c.attr, Color: (0, tiff_utils_1.intToRgba)(c.attr.Color) };
30
- }
31
- return { ...c.attr };
32
- });
33
- const { AquisitionDate = '', Description = '' } = img;
34
- const image = {
35
- ...img.attr,
36
- AquisitionDate,
37
- Description,
38
- Pixels: {
39
- ...img.Pixels.attr,
40
- Channels
41
- }
42
- };
43
- return {
44
- ...image,
45
- format() {
46
- const { Pixels } = image;
47
- const sizes = ['X', 'Y', 'Z']
48
- .map((name) => {
49
- const size = Pixels[`PhysicalSize${name}`];
50
- const unit = Pixels[`PhysicalSize${name}Unit`];
51
- return size && unit ? `${size} ${unit}` : '-';
52
- })
53
- .join(' x ');
54
- return {
55
- 'Acquisition Date': image.AquisitionDate,
56
- 'Dimensions (XY)': `${Pixels.SizeX} x ${Pixels.SizeY}`,
57
- 'Pixels Type': Pixels.Type,
58
- 'Pixels Size (XYZ)': sizes,
59
- 'Z-sections/Timepoints': `${Pixels.SizeZ} x ${Pixels.SizeT}`,
60
- Channels: Pixels.SizeC
61
- };
62
- }
63
- };
64
- });
65
- }
66
- exports.fromString = fromString;
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDims = exports.getLabels = void 0;
4
- function getLabels(dimOrder) {
5
- return dimOrder.toLowerCase().split('').reverse();
6
- }
7
- exports.getLabels = getLabels;
8
- /*
9
- * Creates an ES6 map of 'label' -> index
10
- * > const labels = ['a', 'b', 'c', 'd'];
11
- * > const dims = getDims(labels);
12
- * > dims('a') === 0;
13
- * > dims('b') === 1;
14
- * > dims('c') === 2;
15
- * > dims('hi!'); // throws
16
- */
17
- function getDims(labels) {
18
- const lookup = new Map(labels.map((name, i) => [name, i]));
19
- if (lookup.size !== labels.length) {
20
- throw Error('Labels must be unique, found duplicated label.');
21
- }
22
- return (name) => {
23
- const index = lookup.get(name);
24
- if (index === undefined) {
25
- throw Error('Invalid dimension.');
26
- }
27
- return index;
28
- };
29
- }
30
- exports.getDims = getDims;
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tiff_utils_1 = require("./utils/tiff-utils");
4
- class TiffPixelSource {
5
- // eslint-disable-next-line max-params
6
- constructor(indexer, dtype, tileSize, shape, labels, meta) {
7
- this._indexer = indexer;
8
- this.dtype = dtype;
9
- this.tileSize = tileSize;
10
- this.shape = shape;
11
- this.labels = labels;
12
- this.meta = meta;
13
- }
14
- async getRaster({ selection, signal }) {
15
- const image = await this._indexer(selection);
16
- return this._readRasters(image, { signal });
17
- }
18
- async getTile({ x, y, selection, signal }) {
19
- const { height, width } = this._getTileExtent(x, y);
20
- const x0 = x * this.tileSize;
21
- const y0 = y * this.tileSize;
22
- const window = [x0, y0, x0 + width, y0 + height];
23
- const image = await this._indexer(selection);
24
- return this._readRasters(image, { window, width, height, signal });
25
- }
26
- async _readRasters(image, props) {
27
- const interleave = (0, tiff_utils_1.isInterleaved)(this.shape);
28
- const raster = await image.readRasters({ interleave, ...props });
29
- if (props?.signal?.aborted) {
30
- throw tiff_utils_1.SIGNAL_ABORTED;
31
- }
32
- /*
33
- * geotiff.js returns objects with different structure
34
- * depending on `interleave`. It's weird, but this seems to work.
35
- */
36
- const data = (interleave ? raster : raster[0]);
37
- return {
38
- data,
39
- width: raster.width,
40
- height: raster.height
41
- };
42
- }
43
- /*
44
- * Computes tile size given x, y coord.
45
- */
46
- _getTileExtent(x, y) {
47
- const { height: zoomLevelHeight, width: zoomLevelWidth } = (0, tiff_utils_1.getImageSize)(this);
48
- let height = this.tileSize;
49
- let width = this.tileSize;
50
- const maxXTileCoord = Math.floor(zoomLevelWidth / this.tileSize);
51
- const maxYTileCoord = Math.floor(zoomLevelHeight / this.tileSize);
52
- if (x === maxXTileCoord) {
53
- width = zoomLevelWidth % this.tileSize;
54
- }
55
- if (y === maxYTileCoord) {
56
- height = zoomLevelHeight % this.tileSize;
57
- }
58
- return { height, width };
59
- }
60
- onTileError(err) {
61
- console.error(err); // eslint-disable-line no-console
62
- }
63
- }
64
- exports.default = TiffPixelSource;
@@ -1,83 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // import Worker from 'web-worker:./decoder.worker.ts';
4
- // https://developer.mozilla.org/en-US/docs/Web/API/NavigatorConcurrentHardware/hardwareConcurrency
5
- // We need to give a different way of getting this for safari, so 4 is probably a safe bet
6
- // for parallel processing in the meantime. More can't really hurt since they'll just block
7
- // each other and not the UI thread, which is the real benefit.
8
- const defaultPoolSize = globalThis?.navigator?.hardwareConcurrency ?? 4;
9
- /**
10
- * Pool for workers to decode chunks of the images.
11
- * 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
12
- */
13
- class Pool {
14
- /**
15
- * @constructor
16
- * @param {Number} size The size of the pool. Defaults to the number of CPUs
17
- * available. When this parameter is `null` or 0, then the
18
- * decoding will be done in the main thread.
19
- */
20
- constructor(size = defaultPoolSize) {
21
- this.workers = [];
22
- this.idleWorkers = [];
23
- this.waitQueue = [];
24
- this.decoder = null;
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
- }
31
- }
32
- /**
33
- * Decode the given block of bytes with the set compression method.
34
- * @param {ArrayBuffer} buffer the array buffer of bytes to decode.
35
- * @returns {Promise.<ArrayBuffer>} the decoded result as a `Promise`
36
- */
37
- async decode(fileDirectory, buffer) {
38
- const currentWorker = await this.waitForWorker();
39
- return new Promise((resolve, reject) => {
40
- currentWorker.onmessage = (event) => {
41
- // this.workers.push(currentWorker);
42
- // eslint-disable-next-line
43
- this.finishTask(currentWorker);
44
- resolve(event.data[0]);
45
- };
46
- currentWorker.onerror = (error) => {
47
- // this.workers.push(currentWorker);
48
- // eslint-disable-next-line
49
- this.finishTask(currentWorker);
50
- reject(error);
51
- };
52
- currentWorker.postMessage(['decode', fileDirectory, buffer], [buffer]);
53
- });
54
- }
55
- async waitForWorker() {
56
- const idleWorker = this.idleWorkers.pop();
57
- if (idleWorker) {
58
- return idleWorker;
59
- }
60
- const waiter = {};
61
- const promise = new Promise((resolve) => {
62
- waiter.resolve = resolve;
63
- });
64
- this.waitQueue.push(waiter);
65
- return promise;
66
- }
67
- async finishTask(currentWorker) {
68
- const waiter = this.waitQueue.pop();
69
- if (waiter) {
70
- waiter.resolve(currentWorker);
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
- }
81
- }
82
- }
83
- exports.default = Pool;
@@ -1,86 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createPoolProxy = exports.createOffsetsProxy = exports.checkProxies = void 0;
4
- const VIV_PROXY_KEY = '__viv';
5
- const OFFSETS_PROXY_KEY = `${VIV_PROXY_KEY}-offsets`;
6
- const POOL_PROXY_KEY = `${VIV_PROXY_KEY}-decoder-pool`;
7
- /*
8
- * Inspect if the GeoTIFF source is wrapped in our proxies,
9
- * and warn if missing.
10
- */
11
- function checkProxies(tiff) {
12
- if (!isProxy(tiff, OFFSETS_PROXY_KEY)) {
13
- console.warn('GeoTIFF source is missing offsets proxy.'); // eslint-disable-line no-console
14
- }
15
- if (!isProxy(tiff, POOL_PROXY_KEY)) {
16
- console.warn('GeoTIFF source is missing decoder-pool proxy.'); // eslint-disable-line no-console
17
- }
18
- }
19
- exports.checkProxies = checkProxies;
20
- /*
21
- * > isProxy(tiff, POOL_PROXY_KEY) === true; // false
22
- * > tiff = createPoolProxy(tiff, new Pool());
23
- * > isProxy(tiff, POOL_PROXY_KEY) === true; // true
24
- */
25
- function isProxy(tiff, proxyFlag) {
26
- return tiff[proxyFlag];
27
- }
28
- /*
29
- * Creates an ES6 Proxy that wraps a GeoTIFF object. The proxy
30
- * handler intercepts calls to `tiff.getImage` and uses our custom
31
- * pre-computed offsets to pre-fetch the correct file directory.
32
- *
33
- * This is a bit of a hack. Internally GeoTIFF inspects `this.ifdRequests`
34
- * to see which fileDirectories need to be traversed. By adding the
35
- * ifdRequest for an 'index' manually, GeoTIFF will await that request
36
- * rather than traversing the file system remotely.
37
- */
38
- function createOffsetsProxy(tiff, offsets) {
39
- const get = (target, key) => {
40
- // Intercept `tiff.getImage`
41
- if (key === 'getImage') {
42
- return (index) => {
43
- // Manually add ifdRequest to tiff if missing and we have an offset.
44
- if (!(index in target.ifdRequests) && index in offsets) {
45
- const offset = offsets[index];
46
- target.ifdRequests[index] = target.parseFileDirectoryAt(offset);
47
- }
48
- return target.getImage(index);
49
- };
50
- }
51
- // tiff['__viv-offsets'] === true
52
- if (key === OFFSETS_PROXY_KEY) {
53
- return true;
54
- }
55
- return Reflect.get(target, key);
56
- };
57
- return new Proxy(tiff, { get });
58
- }
59
- exports.createOffsetsProxy = createOffsetsProxy;
60
- /*
61
- * Creates an ES6 Proxy that wraps a GeoTIFF object. The proxy
62
- * handler intercepts calls to `tiff.readRasters` and injects
63
- * a pool argument to every call. This means our TiffPixelSource
64
- * doesn't need to be aware of whether a decoder pool is in use.
65
- *
66
- * > tiff.readRasters({ window }) -> tiff.readRasters({ window, pool });
67
- */
68
- function createPoolProxy(tiff, pool) {
69
- const get = (target, key) => {
70
- // Intercept calls to `image.readRasters`
71
- if (key === 'readRasters') {
72
- return (options) => {
73
- // Inject `pool` argument with other raster options.
74
- // @ts-ignore
75
- return target.readRasters({ ...options, pool });
76
- };
77
- }
78
- // tiff['__viv-decoder-pool'] === true
79
- if (key === POOL_PROXY_KEY) {
80
- return true;
81
- }
82
- return Reflect.get(target, key);
83
- };
84
- return new Proxy(tiff, { get });
85
- }
86
- exports.createPoolProxy = createPoolProxy;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SIGNAL_ABORTED = exports.getImageSize = exports.isInterleaved = exports.intToRgba = exports.ensureArray = void 0;
4
- function ensureArray(x) {
5
- return Array.isArray(x) ? x : [x];
6
- }
7
- exports.ensureArray = ensureArray;
8
- /*
9
- * Converts 32-bit integer color representation to RGBA tuple.
10
- * Used to serialize colors from OME-XML metadata.
11
- *
12
- * > console.log(intToRgba(100100));
13
- * > // [0, 1, 135, 4]
14
- */
15
- function intToRgba(int) {
16
- if (!Number.isInteger(int)) {
17
- throw Error('Not an integer.');
18
- }
19
- // Write number to int32 representation (4 bytes).
20
- const buffer = new ArrayBuffer(4);
21
- const view = new DataView(buffer);
22
- view.setInt32(0, int, false); // offset === 0, littleEndian === false
23
- // Take u8 view and extract number for each byte (1 byte for R/G/B/A).
24
- const bytes = new Uint8Array(buffer);
25
- return Array.from(bytes);
26
- }
27
- exports.intToRgba = intToRgba;
28
- /*
29
- * Helper method to determine whether pixel data is interleaved or not.
30
- * > isInterleaved([1, 24, 24]) === false;
31
- * > isInterleaved([1, 24, 24, 3]) === true;
32
- */
33
- function isInterleaved(shape) {
34
- const lastDimSize = shape[shape.length - 1];
35
- return lastDimSize === 3 || lastDimSize === 4;
36
- }
37
- exports.isInterleaved = isInterleaved;
38
- function getImageSize(source) {
39
- const interleaved = isInterleaved(source.shape);
40
- const [height, width] = source.shape.slice(interleaved ? -3 : -2);
41
- return { height, width };
42
- }
43
- exports.getImageSize = getImageSize;
44
- exports.SIGNAL_ABORTED = '__vivSignalAborted';
package/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +0,0 @@
1
- "use strict";