@loaders.gl/geotiff 3.1.0-alpha.4 → 3.1.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +26 -0
  4. package/dist/es5/bundle.js +2 -4
  5. package/dist/es5/bundle.js.map +1 -1
  6. package/dist/es5/index.js +2 -2
  7. package/dist/es5/lib/load-geotiff.js +27 -85
  8. package/dist/es5/lib/load-geotiff.js.map +1 -1
  9. package/dist/es5/lib/ome/load-ome-tiff.js +45 -62
  10. package/dist/es5/lib/ome/load-ome-tiff.js.map +1 -1
  11. package/dist/es5/lib/ome/ome-indexers.js +75 -117
  12. package/dist/es5/lib/ome/ome-indexers.js.map +1 -1
  13. package/dist/es5/lib/ome/ome-utils.js +18 -21
  14. package/dist/es5/lib/ome/ome-utils.js.map +1 -1
  15. package/dist/es5/lib/ome/omexml.js +30 -35
  16. package/dist/es5/lib/ome/omexml.js.map +1 -1
  17. package/dist/es5/lib/ome/utils.js +3 -5
  18. package/dist/es5/lib/ome/utils.js.map +1 -1
  19. package/dist/es5/lib/tiff-pixel-source.js +83 -169
  20. package/dist/es5/lib/tiff-pixel-source.js.map +1 -1
  21. package/dist/es5/lib/utils/Pool.js +53 -141
  22. package/dist/es5/lib/utils/Pool.js.map +1 -1
  23. package/dist/es5/lib/utils/proxies.js +13 -22
  24. package/dist/es5/lib/utils/proxies.js.map +1 -1
  25. package/dist/es5/lib/utils/tiff-utils.js +9 -18
  26. package/dist/es5/lib/utils/tiff-utils.js.map +1 -1
  27. package/dist/esm/lib/ome/ome-indexers.js +2 -2
  28. package/dist/esm/lib/ome/ome-indexers.js.map +1 -1
  29. package/dist/esm/lib/ome/ome-utils.js +1 -1
  30. package/dist/esm/lib/ome/ome-utils.js.map +1 -1
  31. package/dist/esm/lib/ome/omexml.js +5 -5
  32. package/dist/esm/lib/ome/omexml.js.map +1 -1
  33. package/dist/esm/lib/utils/proxies.js +2 -2
  34. package/dist/esm/lib/utils/proxies.js.map +1 -1
  35. package/dist/index.d.ts +3 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +10 -0
  38. package/dist/lib/load-geotiff.d.ts +28 -0
  39. package/dist/lib/load-geotiff.d.ts.map +1 -0
  40. package/dist/lib/load-geotiff.js +57 -0
  41. package/dist/lib/ome/load-ome-tiff.d.ts +50 -0
  42. package/dist/lib/ome/load-ome-tiff.d.ts.map +1 -0
  43. package/dist/lib/ome/load-ome-tiff.js +46 -0
  44. package/dist/lib/ome/ome-indexers.d.ts +11 -0
  45. package/dist/lib/ome/ome-indexers.d.ts.map +1 -0
  46. package/dist/lib/ome/ome-indexers.js +108 -0
  47. package/dist/lib/ome/ome-utils.d.ts +28 -0
  48. package/dist/lib/ome/ome-utils.d.ts.map +1 -0
  49. package/dist/lib/ome/ome-utils.js +63 -0
  50. package/dist/lib/ome/omexml.d.ts +49 -0
  51. package/dist/lib/ome/omexml.d.ts.map +1 -0
  52. package/dist/lib/ome/omexml.js +66 -0
  53. package/dist/lib/ome/utils.d.ts +5 -0
  54. package/dist/lib/ome/utils.d.ts.map +1 -0
  55. package/dist/lib/ome/utils.js +30 -0
  56. package/dist/lib/tiff-pixel-source.d.ts +18 -0
  57. package/dist/lib/tiff-pixel-source.d.ts.map +1 -0
  58. package/dist/lib/tiff-pixel-source.js +64 -0
  59. package/dist/lib/utils/Pool.d.ts +29 -0
  60. package/dist/lib/utils/Pool.d.ts.map +1 -0
  61. package/dist/lib/utils/Pool.js +83 -0
  62. package/dist/lib/utils/proxies.d.ts +6 -0
  63. package/dist/lib/utils/proxies.d.ts.map +1 -0
  64. package/dist/lib/utils/proxies.js +86 -0
  65. package/dist/lib/utils/tiff-utils.d.ts +10 -0
  66. package/dist/lib/utils/tiff-utils.d.ts.map +1 -0
  67. package/dist/lib/utils/tiff-utils.js +44 -0
  68. package/dist/types.d.ts +47 -0
  69. package/dist/types.d.ts.map +1 -0
  70. package/dist/types.js +2 -0
  71. package/dist/typings/geotiff.d.ts +60 -0
  72. package/dist/typings/geotiff.d.ts.map +1 -0
  73. package/dist/typings/geotiff.js +1 -0
  74. package/package.json +5 -5
  75. package/dist/dist.min.js +0 -13
  76. package/dist/dist.min.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/ome/omexml.ts"],"names":["parser","ensureArray","intToRgba","PARSER_OPTIONS","attributeNamePrefix","attrNodeName","parseNodeValue","parseAttributeValue","ignoreAttributes","parse","str","fromString","res","OME","Error","Image","map","img","Channels","Pixels","Channel","c","attr","Color","AquisitionDate","Description","image","format","sizes","name","size","unit","join","SizeX","SizeY","Type","SizeZ","SizeT","SizeC"],"mappings":"AAAA,OAAOA,MAAP,MAAmB,iBAAnB;AACA,SAAQC,WAAR,EAAqBC,SAArB,QAAqC,qBAArC;AAGA,MAAMC,cAAc,GAAG;AAErBC,EAAAA,mBAAmB,EAAE,EAFA;AAGrBC,EAAAA,YAAY,EAAE,MAHO;AAMrBC,EAAAA,cAAc,EAAE,IANK;AAOrBC,EAAAA,mBAAmB,EAAE,IAPA;AAUrBC,EAAAA,gBAAgB,EAAE;AAVG,CAAvB;;AAaA,MAAMC,KAAK,GAAIC,GAAD,IAAuBV,MAAM,CAACS,KAAP,CAAaC,GAAb,EAAkBP,cAAlB,CAArC;;AAEA,OAAO,SAASQ,UAAT,CAAoBD,GAApB,EAAiC;AACtC,QAAME,GAAG,GAAGH,KAAK,CAACC,GAAD,CAAjB;;AACA,MAAI,CAACE,GAAG,CAACC,GAAT,EAAc;AACZ,UAAMC,KAAK,CAAC,mCAAD,CAAX;AACD;;AACD,SAAOb,WAAW,CAACW,GAAG,CAACC,GAAJ,CAAQE,KAAT,CAAX,CAA2BC,GAA3B,CAAgCC,GAAD,IAAS;AAC7C,UAAMC,QAAQ,GAAGjB,WAAW,CAACgB,GAAG,CAACE,MAAJ,CAAWC,OAAZ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AM,CAACiB,KAAM,MAAKjB,MAAM,CAACkB,KAAM,EALtD;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","ensureArray","intToRgba","PARSER_OPTIONS","attributeNamePrefix","attrNodeName","parseNodeValue","parseAttributeValue","ignoreAttributes","parse","str","fromString","res","OME","Error","Image","map","img","Channels","Pixels","Channel","c","attr","Color","AquisitionDate","Description","image","format","sizes","name","size","unit","join","SizeX","SizeY","Type","SizeZ","SizeT","SizeC"],"mappings":"AAAA,OAAOA,MAAP,MAAmB,iBAAnB;AACA,SAAQC,WAAR,EAAqBC,SAArB,QAAqC,qBAArC;AAGA,MAAMC,cAAc,GAAG;AAErBC,EAAAA,mBAAmB,EAAE,EAFA;AAGrBC,EAAAA,YAAY,EAAE,MAHO;AAMrBC,EAAAA,cAAc,EAAE,IANK;AAOrBC,EAAAA,mBAAmB,EAAE,IAPA;AAUrBC,EAAAA,gBAAgB,EAAE;AAVG,CAAvB;;AAaA,MAAMC,KAAK,GAAIC,GAAD,IAAuBV,MAAM,CAACS,KAAP,CAAaC,GAAb,EAAkBP,cAAlB,CAArC;;AAEA,OAAO,SAASQ,UAAT,CAAoBD,GAApB,EAAiC;AACtC,QAAME,GAAG,GAAGH,KAAK,CAACC,GAAD,CAAjB;;AACA,MAAI,CAACE,GAAG,CAACC,GAAT,EAAc;AACZ,UAAMC,KAAK,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BN,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,6 +1,6 @@
1
1
  const VIV_PROXY_KEY = '__viv';
2
- const OFFSETS_PROXY_KEY = `${VIV_PROXY_KEY}-offsets`;
3
- const POOL_PROXY_KEY = `${VIV_PROXY_KEY}-decoder-pool`;
2
+ const OFFSETS_PROXY_KEY = "".concat(VIV_PROXY_KEY, "-offsets");
3
+ const POOL_PROXY_KEY = "".concat(VIV_PROXY_KEY, "-decoder-pool");
4
4
  export function checkProxies(tiff) {
5
5
  if (!isProxy(tiff, OFFSETS_PROXY_KEY)) {
6
6
  console.warn('GeoTIFF source is missing offsets proxy.');
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/utils/proxies.ts"],"names":["VIV_PROXY_KEY","OFFSETS_PROXY_KEY","POOL_PROXY_KEY","checkProxies","tiff","isProxy","console","warn","proxyFlag","createOffsetsProxy","offsets","get","target","key","index","ifdRequests","offset","parseFileDirectoryAt","getImage","Reflect","Proxy","createPoolProxy","pool","options","readRasters"],"mappings":"AAGA,MAAMA,aAAa,GAAG,OAAt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SAASU,eAAT,CAAyBjB,IAAzB,EAAwCkB,IAAxC,EAAoD;AACzD,QAAMX,GAAG,GAAG,CAACC,MAAD,EAAkBC,GAAlB,KAA+B;AAEzC,QAAIA,GAAG,KAAK,aAAZ,EAA2B;AACzB,aAAQU,OAAD,IAAoD;AAGzD,eAAOX,MAAM,CAACY,WAAP,CAAmB,EAAC,GAAGD,OAAJ;AAAaD,UAAAA;AAAb,SAAnB,CAAP;AACD,OAJD;AAKD;;AAGD,QAAIT,GAAG,KAAKX,cAAZ,EAA4B;AAC1B,aAAO,IAAP;AACD;;AAED,WAAOiB,OAAO,CAACR,GAAR,CAAYC,MAAZ,EAAoBC,GAApB,CAAP;AACD,GAhBD;;AAiBA,SAAO,IAAIO,KAAJ,CAAUhB,IAAV,EAAgB;AAACO,IAAAA;AAAD,GAAhB,CAAP;AACD","sourcesContent":["import type {GeoTIFF} from 'geotiff';\nimport type Pool from './Pool';\n\nconst VIV_PROXY_KEY = '__viv';\nconst OFFSETS_PROXY_KEY = `${VIV_PROXY_KEY}-offsets` as const;\nconst POOL_PROXY_KEY = `${VIV_PROXY_KEY}-decoder-pool` as const;\n\n/*\n * Inspect if the GeoTIFF source is wrapped in our proxies,\n * and warn if missing.\n */\nexport function checkProxies(tiff: GeoTIFF) {\n if (!isProxy(tiff, OFFSETS_PROXY_KEY)) {\n console.warn('GeoTIFF source is missing offsets proxy.'); // eslint-disable-line no-console\n }\n\n if (!isProxy(tiff, POOL_PROXY_KEY)) {\n console.warn('GeoTIFF source is missing decoder-pool proxy.'); // eslint-disable-line no-console\n }\n}\n\n/*\n * > isProxy(tiff, POOL_PROXY_KEY) === true; // false\n * > tiff = createPoolProxy(tiff, new Pool());\n * > isProxy(tiff, POOL_PROXY_KEY) === true; // true\n */\nfunction isProxy(tiff: GeoTIFF, proxyFlag: string) {\n return (tiff as any)[proxyFlag] as boolean;\n}\n\n/*\n * Creates an ES6 Proxy that wraps a GeoTIFF object. The proxy\n * handler intercepts calls to `tiff.getImage` and uses our custom\n * pre-computed offsets to pre-fetch the correct file directory.\n *\n * This is a bit of a hack. Internally GeoTIFF inspects `this.ifdRequests`\n * to see which fileDirectories need to be traversed. By adding the\n * ifdRequest for an 'index' manually, GeoTIFF will await that request\n * rather than traversing the file system remotely.\n */\nexport function createOffsetsProxy(tiff: GeoTIFF, offsets: number[]) {\n const get = (target: GeoTIFF, key: any) => {\n // Intercept `tiff.getImage`\n if (key === 'getImage') {\n return (index: number) => {\n // Manually add ifdRequest to tiff if missing and we have an offset.\n if (!(index in target.ifdRequests) && index in offsets) {\n const offset = offsets[index];\n target.ifdRequests[index] = target.parseFileDirectoryAt(offset);\n }\n return target.getImage(index);\n };\n }\n\n // tiff['__viv-offsets'] === true\n if (key === OFFSETS_PROXY_KEY) {\n return true;\n }\n\n return Reflect.get(target, key);\n };\n return new Proxy(tiff, {get});\n}\n\n/*\n * Creates an ES6 Proxy that wraps a GeoTIFF object. The proxy\n * handler intercepts calls to `tiff.readRasters` and injects\n * a pool argument to every call. This means our TiffPixelSource\n * doesn't need to be aware of whether a decoder pool is in use.\n *\n * > tiff.readRasters({ window }) -> tiff.readRasters({ window, pool });\n */\nexport function createPoolProxy(tiff: GeoTIFF, pool: Pool) {\n const get = (target: GeoTIFF, key: any) => {\n // Intercept calls to `image.readRasters`\n if (key === 'readRasters') {\n return (options: Parameters<typeof target.readRasters>) => {\n // Inject `pool` argument with other raster options.\n // @ts-ignore\n return target.readRasters({...options, pool});\n };\n }\n\n // tiff['__viv-decoder-pool'] === true\n if (key === POOL_PROXY_KEY) {\n return true;\n }\n\n return Reflect.get(target, key);\n };\n return new Proxy(tiff, {get});\n}\n"],"file":"proxies.js"}
1
+ {"version":3,"sources":["../../../../src/lib/utils/proxies.ts"],"names":["VIV_PROXY_KEY","OFFSETS_PROXY_KEY","POOL_PROXY_KEY","checkProxies","tiff","isProxy","console","warn","proxyFlag","createOffsetsProxy","offsets","get","target","key","index","ifdRequests","offset","parseFileDirectoryAt","getImage","Reflect","Pro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gB;AAACO,IAAAA;AAAD,GAAhB,CAAP;AACD;AAUD,OAAO,SAASU,eAAT,CAAyBjB,IAAzB,EAAwCkB,IAAxC,EAAoD;AACzD,QAAMX,GAAG,GAAG,CAACC,MAAD,EAAkBC,GAAlB,KAA+B;AAEzC,QAAIA,GAAG,KAAK,aAAZ,EAA2B;AACzB,aAAQU,OAAD,IAAoD;AAGzD,eAAOX,MAAM,CAACY,WAAP,CAAmB,EAAC,GAAGD,OAAJ;AAAaD,UAAAA;AAAb,SAAnB,CAAP;AACD,OAJD;AAKD;;AAGD,QAAIT,GAAG,KAAKX,cAAZ,EAA4B;AAC1B,aAAO,IAAP;AACD;;AAED,WAAOiB,OAAO,CAACR,GAAR,CAAYC,MAAZ,EAAoBC,GAApB,CAAP;AACD,GAhBD;;AAiBA,SAAO,IAAIO,KAAJ,CAAUhB,IAAV,EAAgB;AAACO,IAAAA;AAAD,GAAhB,CAAP;AACD","sourcesContent":["import type {GeoTIFF} from 'geotiff';\nimport type Pool from './Pool';\n\nconst VIV_PROXY_KEY = '__viv';\nconst OFFSETS_PROXY_KEY = `${VIV_PROXY_KEY}-offsets` as const;\nconst POOL_PROXY_KEY = `${VIV_PROXY_KEY}-decoder-pool` as const;\n\n/*\n * Inspect if the GeoTIFF source is wrapped in our proxies,\n * and warn if missing.\n */\nexport function checkProxies(tiff: GeoTIFF) {\n if (!isProxy(tiff, OFFSETS_PROXY_KEY)) {\n console.warn('GeoTIFF source is missing offsets proxy.'); // eslint-disable-line no-console\n }\n\n if (!isProxy(tiff, POOL_PROXY_KEY)) {\n console.warn('GeoTIFF source is missing decoder-pool proxy.'); // eslint-disable-line no-console\n }\n}\n\n/*\n * > isProxy(tiff, POOL_PROXY_KEY) === true; // false\n * > tiff = createPoolProxy(tiff, new Pool());\n * > isProxy(tiff, POOL_PROXY_KEY) === true; // true\n */\nfunction isProxy(tiff: GeoTIFF, proxyFlag: string) {\n return (tiff as any)[proxyFlag] as boolean;\n}\n\n/*\n * Creates an ES6 Proxy that wraps a GeoTIFF object. The proxy\n * handler intercepts calls to `tiff.getImage` and uses our custom\n * pre-computed offsets to pre-fetch the correct file directory.\n *\n * This is a bit of a hack. Internally GeoTIFF inspects `this.ifdRequests`\n * to see which fileDirectories need to be traversed. By adding the\n * ifdRequest for an 'index' manually, GeoTIFF will await that request\n * rather than traversing the file system remotely.\n */\nexport function createOffsetsProxy(tiff: GeoTIFF, offsets: number[]) {\n const get = (target: GeoTIFF, key: any) => {\n // Intercept `tiff.getImage`\n if (key === 'getImage') {\n return (index: number) => {\n // Manually add ifdRequest to tiff if missing and we have an offset.\n if (!(index in target.ifdRequests) && index in offsets) {\n const offset = offsets[index];\n target.ifdRequests[index] = target.parseFileDirectoryAt(offset);\n }\n return target.getImage(index);\n };\n }\n\n // tiff['__viv-offsets'] === true\n if (key === OFFSETS_PROXY_KEY) {\n return true;\n }\n\n return Reflect.get(target, key);\n };\n return new Proxy(tiff, {get});\n}\n\n/*\n * Creates an ES6 Proxy that wraps a GeoTIFF object. The proxy\n * handler intercepts calls to `tiff.readRasters` and injects\n * a pool argument to every call. This means our TiffPixelSource\n * doesn't need to be aware of whether a decoder pool is in use.\n *\n * > tiff.readRasters({ window }) -> tiff.readRasters({ window, pool });\n */\nexport function createPoolProxy(tiff: GeoTIFF, pool: Pool) {\n const get = (target: GeoTIFF, key: any) => {\n // Intercept calls to `image.readRasters`\n if (key === 'readRasters') {\n return (options: Parameters<typeof target.readRasters>) => {\n // Inject `pool` argument with other raster options.\n // @ts-ignore\n return target.readRasters({...options, pool});\n };\n }\n\n // tiff['__viv-decoder-pool'] === true\n if (key === POOL_PROXY_KEY) {\n return true;\n }\n\n return Reflect.get(target, key);\n };\n return new Proxy(tiff, {get});\n}\n"],"file":"proxies.js"}
@@ -0,0 +1,3 @@
1
+ export { loadGeoTiff } from './lib/load-geotiff';
2
+ export { default as TiffPixelSource } from './lib/tiff-pixel-source';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,yBAAyB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
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; } });
@@ -0,0 +1,28 @@
1
+ import { GeoTIFF } from 'geotiff';
2
+ import type TiffPixelSource from './tiff-pixel-source';
3
+ /** Options for initializing a tiff pixel source. */
4
+ interface GeoTIFFOptions {
5
+ /** Headers passed to each underlying request. */
6
+ headers?: Record<string, unknown>;
7
+ /** Performance enhancment to index the remote tiff source using pre-computed byte-offsets. Generated via https://github.com/ilan-gold/generate-tiff-offsets */
8
+ offsets?: number[];
9
+ /** Indicates whether a multi-threaded pool of image decoders should be used to decode tiles. */
10
+ pool?: boolean;
11
+ }
12
+ interface GeoTIFFData {
13
+ data: TiffPixelSource<string[]>[];
14
+ metadata: Record<string, unknown>;
15
+ }
16
+ /**
17
+ * Opens an OME-TIFF via URL and returns data source and associated metadata for first image.
18
+ *
19
+ * @param source url string, File/Blob object, or GeoTIFF object
20
+ * @param opts options for initializing a tiff pixel source.
21
+ * - `opts.headers` are passed to each underlying fetch request.
22
+ * - `opts.offsets` are a performance enhancment to index the remote tiff source using pre-computed byte-offsets.
23
+ * - `opts.pool` indicates whether a multi-threaded pool of image decoders should be used to decode tiles (default = true).
24
+ * @return data source and associated OME-Zarr metadata.
25
+ */
26
+ export declare function loadGeoTiff(source: string | Blob | GeoTIFF, opts?: GeoTIFFOptions): Promise<GeoTIFFData>;
27
+ export {};
28
+ //# sourceMappingURL=load-geotiff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-geotiff.d.ts","sourceRoot":"","sources":["../../src/lib/load-geotiff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,OAAO,EAAC,MAAM,SAAS,CAAC;AAUnD,OAAO,KAAK,eAAe,MAAM,qBAAqB,CAAC;AAEvD,oDAAoD;AACpD,UAAU,cAAc;IACtB,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,+JAA+J;IAC/J,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,gGAAgG;IAChG,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,UAAU,WAAW;IACnB,IAAI,EAAE,eAAe,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC;IAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,EAC/B,IAAI,GAAE,cAAmB,GACxB,OAAO,CAAC,WAAW,CAAC,CA2CtB"}
@@ -0,0 +1,57 @@
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;
@@ -0,0 +1,50 @@
1
+ import type { GeoTIFF, GeoTIFFImage } from 'geotiff';
2
+ import TiffPixelSource from '../tiff-pixel-source';
3
+ export declare const isOmeTiff: (img: GeoTIFFImage) => boolean;
4
+ export declare function loadOmeTiff(tiff: GeoTIFF, firstImage: GeoTIFFImage): Promise<{
5
+ data: TiffPixelSource<["t", "c", "z"] | ["c", "t", "z"] | ["z", "t", "c"] | ["t", "z", "c"] | ["z", "c", "t"] | ["c", "z", "t"]>[];
6
+ metadata: {
7
+ format(): {
8
+ 'Acquisition Date': string;
9
+ 'Dimensions (XY)': string;
10
+ 'Pixels Type': "uint8" | "uint16" | "uint32" | "float" | "double" | "int8" | "int16" | "int32" | "bit" | "complex" | "double-complex";
11
+ 'Pixels Size (XYZ)': string;
12
+ 'Z-sections/Timepoints': string;
13
+ Channels: number;
14
+ };
15
+ AquisitionDate: string;
16
+ Description: string;
17
+ Pixels: {
18
+ Channels: ({
19
+ Color: [number, number, number, number];
20
+ ID: string;
21
+ SamplesPerPixel: number;
22
+ Name?: string | undefined;
23
+ } | {
24
+ ID: string;
25
+ SamplesPerPixel: number;
26
+ Name?: string | undefined;
27
+ })[];
28
+ PhysicalSizeX: number;
29
+ PhysicalSizeY: number;
30
+ PhysicalSizeZ: number;
31
+ SignificantBits: number;
32
+ SizeX: number;
33
+ SizeY: number;
34
+ SizeZ: number;
35
+ SizeT: number;
36
+ SizeC: number;
37
+ PhysicalSizeXUnit: import("./omexml").UnitsLength;
38
+ PhysicalSizeYUnit: import("./omexml").UnitsLength;
39
+ PhysicalSizeZUnit: import("./omexml").UnitsLength;
40
+ BigEndian: boolean;
41
+ Interleaved: boolean;
42
+ ID: string;
43
+ DimensionOrder: import("./omexml").DimensionOrder;
44
+ Type: "uint8" | "uint16" | "uint32" | "float" | "double" | "int8" | "int16" | "int32" | "bit" | "complex" | "double-complex";
45
+ };
46
+ ID: string;
47
+ Name: string;
48
+ };
49
+ }>;
50
+ //# sourceMappingURL=load-ome-tiff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-ome-tiff.d.ts","sourceRoot":"","sources":["../../../src/lib/ome/load-ome-tiff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAE,YAAY,EAAC,MAAM,SAAS,CAAC;AAEnD,OAAO,eAAe,MAAM,sBAAsB,CAAC;AAMnD,eAAO,MAAM,SAAS,QAAS,YAAY,YAAwD,CAAC;AAEpG,wBAAsB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCxE"}
@@ -0,0 +1,46 @@
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;
@@ -0,0 +1,11 @@
1
+ import type { GeoTIFFImage, GeoTIFF } from 'geotiff';
2
+ import type { OMEXML } from '../ome/omexml';
3
+ export declare type OmeTiffSelection = {
4
+ t: number;
5
+ c: number;
6
+ z: number;
7
+ };
8
+ export declare type OmeTiffIndexer = (sel: OmeTiffSelection, z: number) => Promise<GeoTIFFImage>;
9
+ export declare function getOmeLegacyIndexer(tiff: GeoTIFF, rootMeta: OMEXML): OmeTiffIndexer;
10
+ export declare function getOmeSubIFDIndexer(tiff: GeoTIFF, rootMeta: OMEXML): OmeTiffIndexer;
11
+ //# sourceMappingURL=ome-indexers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ome-indexers.d.ts","sourceRoot":"","sources":["../../../src/lib/ome/ome-indexers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAE,OAAO,EAAqB,MAAM,SAAS,CAAC;AACvE,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAE1C,oBAAY,gBAAgB,GAAG;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC;AACjE,oBAAY,cAAc,GAAG,CAAC,GAAG,EAAE,gBAAgB,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;AAqBzF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,CAanF;AAgBD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,CAuCnF"}
@@ -0,0 +1,108 @@
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
+ }
@@ -0,0 +1,28 @@
1
+ import type { OMEXML, UnitsLength } from './omexml';
2
+ export declare const DTYPE_LOOKUP: {
3
+ readonly uint8: "Uint8";
4
+ readonly uint16: "Uint16";
5
+ readonly uint32: "Uint32";
6
+ readonly float: "Float32";
7
+ readonly double: "Float64";
8
+ readonly int8: "Int8";
9
+ readonly int16: "Int16";
10
+ readonly int32: "Int32";
11
+ };
12
+ export declare function getOmePixelSourceMeta({ Pixels }: OMEXML[0]): {
13
+ labels: import("../../types").Labels<["t", "c", "z"] | ["c", "t", "z"] | ["z", "t", "c"] | ["t", "z", "c"] | ["z", "c", "t"] | ["c", "z", "t"]>;
14
+ getShape: (level: number) => number[];
15
+ physicalSizes: {
16
+ [k: string]: {
17
+ size: number;
18
+ unit: UnitsLength;
19
+ };
20
+ };
21
+ dtype: "Uint8" | "Uint16" | "Uint32" | "Float32" | "Float64" | "Int8" | "Int16" | "Int32";
22
+ } | {
23
+ labels: import("../../types").Labels<["t", "c", "z"] | ["c", "t", "z"] | ["z", "t", "c"] | ["t", "z", "c"] | ["z", "c", "t"] | ["c", "z", "t"]>;
24
+ getShape: (level: number) => number[];
25
+ dtype: "Uint8" | "Uint16" | "Uint32" | "Float32" | "Float64" | "Int8" | "Int16" | "Int32";
26
+ physicalSizes?: undefined;
27
+ };
28
+ //# sourceMappingURL=ome-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ome-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/ome/ome-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,EAAE,WAAW,EAAC,MAAM,UAAU,CAAC;AAElD,eAAO,MAAM,YAAY;;;;;;;;;CASf,CAAC;AAEX,wBAAgB,qBAAqB,CAAC,EAAC,MAAM,EAAC,EAAE,MAAM,CAAC,CAAC,CAAC;;sBAoB9B,MAAM;;;kBAcP,MAAM;kBAAQ,WAAW;;;;;;sBAdxB,MAAM;;;EAmChC"}
@@ -0,0 +1,63 @@
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;
@@ -0,0 +1,49 @@
1
+ export declare function fromString(str: string): {
2
+ format(): {
3
+ 'Acquisition Date': string;
4
+ 'Dimensions (XY)': string;
5
+ 'Pixels Type': PixelType;
6
+ 'Pixels Size (XYZ)': string;
7
+ 'Z-sections/Timepoints': string;
8
+ Channels: number;
9
+ };
10
+ AquisitionDate: string;
11
+ Description: string;
12
+ Pixels: {
13
+ Channels: ({
14
+ Color: [number, number, number, number];
15
+ ID: string;
16
+ SamplesPerPixel: number;
17
+ Name?: string | undefined;
18
+ } | {
19
+ ID: string;
20
+ SamplesPerPixel: number;
21
+ Name?: string | undefined;
22
+ })[];
23
+ PhysicalSizeX: number;
24
+ PhysicalSizeY: number;
25
+ PhysicalSizeZ: number;
26
+ SignificantBits: number;
27
+ SizeX: number;
28
+ SizeY: number;
29
+ SizeZ: number;
30
+ SizeT: number;
31
+ SizeC: number;
32
+ PhysicalSizeXUnit: UnitsLength;
33
+ PhysicalSizeYUnit: UnitsLength;
34
+ PhysicalSizeZUnit: UnitsLength;
35
+ BigEndian: boolean;
36
+ Interleaved: boolean;
37
+ ID: string;
38
+ DimensionOrder: DimensionOrder;
39
+ Type: PixelType;
40
+ };
41
+ ID: string;
42
+ Name: string;
43
+ }[];
44
+ export declare type OMEXML = ReturnType<typeof fromString>;
45
+ export declare type DimensionOrder = 'XYZCT' | 'XYZTC' | 'XYCTZ' | 'XYCZT' | 'XYTCZ' | 'XYTZC';
46
+ declare type PixelType = 'int8' | 'int16' | 'int32' | 'uint8' | 'uint16' | 'uint32' | 'float' | 'bit' | 'double' | 'complex' | 'double-complex';
47
+ export declare type UnitsLength = 'Ym' | 'Zm' | 'Em' | 'Pm' | 'Tm' | 'Gm' | 'Mm' | 'km' | 'hm' | 'dam' | 'm' | 'dm' | 'cm' | 'mm' | 'µm' | 'nm' | 'pm' | 'fm' | 'am' | 'zm' | 'ym' | 'Å' | 'thou' | 'li' | 'in' | 'ft' | 'yd' | 'mi' | 'ua' | 'ly' | 'pc' | 'pt' | 'pixel' | 'reference frame';
48
+ export {};
49
+ //# sourceMappingURL=omexml.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"omexml.d.ts","sourceRoot":"","sources":["../../../src/lib/ome/omexml.ts"],"names":[],"mappings":"AAmBA,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA8CrC;AAED,oBAAY,MAAM,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;AACnD,oBAAY,cAAc,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAuBvF,aAAK,SAAS,GACV,MAAM,GACN,OAAO,GACP,OAAO,GACP,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,KAAK,GACL,QAAQ,GACR,SAAS,GACT,gBAAgB,CAAC;AAErB,oBAAY,WAAW,GACnB,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,KAAK,GACL,GAAG,GACH,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,GAAG,GACH,MAAM,GACN,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,OAAO,GACP,iBAAiB,CAAC"}
@@ -0,0 +1,66 @@
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;
@@ -0,0 +1,5 @@
1
+ import type { OMEXML } from '../ome/omexml';
2
+ import type { Labels } from '../../types';
3
+ export declare function getLabels(dimOrder: OMEXML[0]['Pixels']['DimensionOrder']): Labels<["t", "c", "z"] | ["c", "t", "z"] | ["z", "t", "c"] | ["t", "z", "c"] | ["z", "c", "t"] | ["c", "z", "t"]>;
4
+ export declare function getDims<S extends string>(labels: S[]): (name: S) => number;
5
+ //# sourceMappingURL=utils.d.ts.map