@cogeotiff/core 9.1.2 → 9.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/build/__benchmark__/cog.read.benchmark.d.ts +1 -0
  3. package/build/__benchmark__/cog.read.benchmark.d.ts.map +1 -0
  4. package/build/__benchmark__/cog.read.benchmark.js +4 -3
  5. package/build/__benchmark__/source.file.d.ts +5 -0
  6. package/build/__benchmark__/source.file.d.ts.map +1 -0
  7. package/build/__benchmark__/source.file.js +4 -13
  8. package/build/__benchmark__/source.memory.d.ts +1 -0
  9. package/build/__benchmark__/source.memory.d.ts.map +1 -0
  10. package/build/__benchmark__/source.memory.js +3 -19
  11. package/build/__test__/cog.image.test.d.ts +1 -0
  12. package/build/__test__/cog.image.test.d.ts.map +1 -0
  13. package/build/__test__/cog.image.test.js +0 -1
  14. package/build/__test__/cog.read.test.d.ts +1 -0
  15. package/build/__test__/cog.read.test.d.ts.map +1 -0
  16. package/build/__test__/cog.read.test.js +81 -2
  17. package/build/__test__/example.d.ts +1 -0
  18. package/build/__test__/example.d.ts.map +1 -0
  19. package/build/__test__/example.js +0 -1
  20. package/build/const/index.d.ts +1 -0
  21. package/build/const/index.d.ts.map +1 -0
  22. package/build/const/index.js +0 -1
  23. package/build/const/tiff.endian.d.ts +1 -0
  24. package/build/const/tiff.endian.d.ts.map +1 -0
  25. package/build/const/tiff.endian.js +0 -1
  26. package/build/const/tiff.mime.d.ts +1 -0
  27. package/build/const/tiff.mime.d.ts.map +1 -0
  28. package/build/const/tiff.mime.js +0 -1
  29. package/build/const/tiff.tag.id.d.ts +16 -8
  30. package/build/const/tiff.tag.id.d.ts.map +1 -0
  31. package/build/const/tiff.tag.id.js +10 -3
  32. package/build/const/tiff.tag.value.d.ts +1 -0
  33. package/build/const/tiff.tag.value.d.ts.map +1 -0
  34. package/build/const/tiff.tag.value.js +0 -1
  35. package/build/const/tiff.version.d.ts +1 -0
  36. package/build/const/tiff.version.d.ts.map +1 -0
  37. package/build/const/tiff.version.js +0 -1
  38. package/build/index.d.ts +4 -2
  39. package/build/index.d.ts.map +1 -0
  40. package/build/index.js +2 -4
  41. package/build/read/data.view.offset.d.ts +1 -0
  42. package/build/read/data.view.offset.d.ts.map +1 -0
  43. package/build/read/data.view.offset.js +0 -1
  44. package/build/read/endian.d.ts +2 -0
  45. package/build/read/endian.d.ts.map +1 -0
  46. package/build/read/endian.js +5 -0
  47. package/build/read/tiff.gdal.d.ts +1 -0
  48. package/build/read/tiff.gdal.d.ts.map +1 -0
  49. package/build/read/tiff.gdal.js +1 -9
  50. package/build/read/tiff.ifd.config.d.ts +1 -0
  51. package/build/read/tiff.ifd.config.d.ts.map +1 -0
  52. package/build/read/tiff.ifd.config.js +0 -1
  53. package/build/read/tiff.tag.d.ts +2 -1
  54. package/build/read/tiff.tag.d.ts.map +1 -0
  55. package/build/read/tiff.tag.factory.d.ts +15 -1
  56. package/build/read/tiff.tag.factory.d.ts.map +1 -0
  57. package/build/read/tiff.tag.factory.js +60 -4
  58. package/build/read/tiff.tag.js +0 -1
  59. package/build/read/tiff.value.reader.d.ts +1 -0
  60. package/build/read/tiff.value.reader.d.ts.map +1 -0
  61. package/build/read/tiff.value.reader.js +0 -1
  62. package/build/source.d.ts +4 -1
  63. package/build/source.d.ts.map +1 -0
  64. package/build/source.js +0 -1
  65. package/build/tiff.d.ts +12 -3
  66. package/build/tiff.d.ts.map +1 -0
  67. package/build/tiff.image.d.ts +11 -2
  68. package/build/tiff.image.d.ts.map +1 -0
  69. package/build/tiff.image.js +51 -69
  70. package/build/tiff.js +28 -74
  71. package/build/util/bytes.d.ts +1 -0
  72. package/build/util/bytes.d.ts.map +1 -0
  73. package/build/util/bytes.js +0 -1
  74. package/build/util/util.hex.d.ts +1 -0
  75. package/build/util/util.hex.d.ts.map +1 -0
  76. package/build/util/util.hex.js +0 -1
  77. package/build/vector.d.ts +1 -0
  78. package/build/vector.d.ts.map +1 -0
  79. package/build/vector.js +0 -1
  80. package/package.json +2 -2
  81. package/src/__benchmark__/cog.read.benchmark.ts +4 -2
  82. package/src/__benchmark__/source.file.ts +3 -1
  83. package/src/__benchmark__/source.memory.ts +2 -2
  84. package/src/__test__/cog.image.test.ts +1 -1
  85. package/src/__test__/cog.read.test.ts +107 -2
  86. package/src/const/tiff.tag.id.ts +16 -8
  87. package/src/index.ts +14 -11
  88. package/src/read/endian.ts +6 -0
  89. package/src/read/tiff.tag.factory.ts +73 -3
  90. package/src/read/tiff.tag.ts +1 -1
  91. package/src/source.ts +1 -1
  92. package/src/tiff.image.ts +40 -26
  93. package/src/tiff.ts +18 -4
  94. package/tsconfig.json +1 -2
  95. package/build/__benchmark__/cog.read.benchmark.js.map +0 -1
  96. package/build/__benchmark__/source.file.js.map +0 -1
  97. package/build/__benchmark__/source.memory.js.map +0 -1
  98. package/build/__test__/cog.image.test.js.map +0 -1
  99. package/build/__test__/cog.read.test.js.map +0 -1
  100. package/build/__test__/example.js.map +0 -1
  101. package/build/const/index.js.map +0 -1
  102. package/build/const/tiff.endian.js.map +0 -1
  103. package/build/const/tiff.mime.js.map +0 -1
  104. package/build/const/tiff.tag.id.js.map +0 -1
  105. package/build/const/tiff.tag.value.js.map +0 -1
  106. package/build/const/tiff.version.js.map +0 -1
  107. package/build/index.js.map +0 -1
  108. package/build/read/data.view.offset.js.map +0 -1
  109. package/build/read/tiff.gdal.js.map +0 -1
  110. package/build/read/tiff.ifd.config.js.map +0 -1
  111. package/build/read/tiff.tag.factory.js.map +0 -1
  112. package/build/read/tiff.tag.js.map +0 -1
  113. package/build/read/tiff.value.reader.js.map +0 -1
  114. package/build/source.js.map +0 -1
  115. package/build/tiff.image.js.map +0 -1
  116. package/build/tiff.js.map +0 -1
  117. package/build/util/bytes.js.map +0 -1
  118. package/build/util/util.hex.js.map +0 -1
  119. package/build/vector.js.map +0 -1
@@ -22,14 +22,7 @@ export var GhostOptionTileLeader;
22
22
  * this class represents the optimizations that GDAL has applied
23
23
  */
24
24
  export class TiffGhostOptions {
25
- constructor() {
26
- Object.defineProperty(this, "options", {
27
- enumerable: true,
28
- configurable: true,
29
- writable: true,
30
- value: new Map()
31
- });
32
- }
25
+ options = new Map();
33
26
  /**
34
27
  * Has GDAL optimized this tiff
35
28
  */
@@ -89,4 +82,3 @@ export class TiffGhostOptions {
89
82
  return this.options.get(GhostOption.MaskInterleavedWithImagery) === 'YES';
90
83
  }
91
84
  }
92
- //# sourceMappingURL=tiff.gdal.js.map
@@ -15,3 +15,4 @@ export declare const TiffIfdEntry: {
15
15
  43: TiffIfdConfig;
16
16
  42: TiffIfdConfig;
17
17
  };
18
+ //# sourceMappingURL=tiff.ifd.config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiff.ifd.config.d.ts","sourceRoot":"","sources":["../../src/read/tiff.ifd.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,eAAO,MAAM,aAAa,EAAE,aAY3B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,aAe9B,CAAC;AAEF,MAAM,WAAW,aAAa;IAC5B,gBAAgB;IAChB,OAAO,EAAE,WAAW,CAAC;IACrB,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,GAAG,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,YAAY;;;CAGxB,CAAC"}
@@ -32,4 +32,3 @@ export const TiffIfdEntry = {
32
32
  [TiffVersion.BigTiff]: TagTiffBigConfig,
33
33
  [TiffVersion.Tiff]: TagTiffConfig,
34
34
  };
35
- //# sourceMappingURL=tiff.ifd.config.js.map
@@ -33,7 +33,7 @@ export interface TagInline<T> extends TagBase {
33
33
  export interface TagOffset extends TagBase {
34
34
  type: 'offset';
35
35
  /** Values of the offsets this is a sparse array unless @see {TagOffset.isLoaded} is true */
36
- value: number[];
36
+ value: number[] | Uint32Array | Uint16Array;
37
37
  /** Have all the values been read */
38
38
  isLoaded: boolean;
39
39
  /** Raw buffer of the values for lazy decoding, as reading 100,000s of uint64s can take quite a long time */
@@ -41,3 +41,4 @@ export interface TagOffset extends TagBase {
41
41
  /** Where in the file the value is read from */
42
42
  dataOffset: number;
43
43
  }
44
+ //# sourceMappingURL=tiff.tag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiff.tag.d.ts","sourceRoot":"","sources":["../../src/read/tiff.tag.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,0BAA0B;AAC1B,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;AAErE,MAAM,WAAW,OAAO;IACtB,oBAAoB;IACpB,EAAE,EAAE,OAAO,CAAC;IACZ,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,uBAAuB;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,QAAQ,EAAE,gBAAgB,CAAC;CAC5B;AAED,2EAA2E;AAC3E,MAAM,WAAW,OAAO,CAAC,CAAC,CAAE,SAAQ,OAAO;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,KAAK,CAAC,EAAE,CAAC,CAAC;IACV,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,kEAAkE;AAClE,MAAM,WAAW,SAAS,CAAC,CAAC,CAAE,SAAQ,OAAO;IAC3C,IAAI,EAAE,QAAQ,CAAC;IACf,uBAAuB;IACvB,KAAK,EAAE,CAAC,CAAC;CACV;AAED,oEAAoE;AACpE,MAAM,WAAW,SAAU,SAAQ,OAAO;IACxC,IAAI,EAAE,QAAQ,CAAC;IACf,4FAA4F;IAC5F,KAAK,EAAE,MAAM,EAAE,GAAG,WAAW,GAAG,WAAW,CAAC;IAC5C,oCAAoC;IACpC,QAAQ,EAAE,OAAO,CAAC;IAClB,4GAA4G;IAC5G,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;CACpB"}
@@ -1,6 +1,18 @@
1
+ import { TiffTagValueType } from '../const/tiff.tag.value.js';
1
2
  import type { Tiff } from '../tiff.js';
2
3
  import type { DataViewOffset } from './data.view.offset.js';
3
4
  import type { Tag, TagLazy, TagOffset } from './tiff.tag.js';
5
+ /**
6
+ * Convert a tiff tag value to a typed array if the local endian matches the tiff endian
7
+ *
8
+ * @param tiff
9
+ * @param bytes
10
+ * @param offset Offset in the data view to read from
11
+ * @param length Number of bytes to read
12
+ * @param type type of tiff tag
13
+ * @returns the value if the type is a typed array and the endianness matches otherwise null
14
+ */
15
+ export declare function readTypedValue<T>(tiff: Tiff, bytes: DataView, offset: number, length: number, type: TiffTagValueType): T | null;
4
16
  /**
5
17
  * Determine if all the data for the tiff tag is loaded in and use that to create the specific CogTiffTag
6
18
  *
@@ -16,7 +28,9 @@ export declare function fetchLazy<T>(tag: TagLazy<T>, tiff: Tiff): Promise<T>;
16
28
  /**
17
29
  * Fetch all the values from a {@link TagOffset}
18
30
  */
19
- export declare function fetchAllOffsets(tiff: Tiff, tag: TagOffset): Promise<number[]>;
31
+ export declare function fetchAllOffsets(tiff: Tiff, tag: TagOffset): Promise<TagOffset['value']>;
20
32
  export declare function setBytes(tag: TagOffset, view: DataViewOffset): void;
21
33
  /** Partially fetch the values of a {@link TagOffset} and return the value for the offset */
22
34
  export declare function getValueAt(tiff: Tiff, tag: TagOffset, index: number): Promise<number>;
35
+ export declare function getValueAtSync(tiff: Tiff, tag: TagOffset, index: number): number | null;
36
+ //# sourceMappingURL=tiff.tag.factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiff.tag.factory.d.ts","sourceRoot":"","sources":["../../src/read/tiff.tag.factory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG5D,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAoD7D;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,gBAAgB,GACrB,CAAC,GAAG,IAAI,CAkBV;AAgDD;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,CAqDxF;AAED,iDAAiD;AACjD,wBAAsB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAQ1E;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAa7F;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI,CAKnE;AAED,4FAA4F;AAC5F,wBAAsB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAoB3F;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUvF"}
@@ -3,6 +3,7 @@ import { TiffTag, TiffTagConvertArray } from '../const/tiff.tag.id.js';
3
3
  import { TiffTagValueType } from '../const/tiff.tag.value.js';
4
4
  import { getUint, getUint64 } from '../util/bytes.js';
5
5
  import { hasBytes } from './data.view.offset.js';
6
+ import { isLittleEndian } from './endian.js';
6
7
  import { getTiffTagSize } from './tiff.value.reader.js';
7
8
  function readTagValue(fieldType, bytes, offset, isLittleEndian) {
8
9
  switch (fieldType) {
@@ -36,6 +37,31 @@ function readTagValue(fieldType, bytes, offset, isLittleEndian) {
36
37
  throw new Error(`Unknown read type "${fieldType}" "${TiffTagValueType[fieldType]}"`);
37
38
  }
38
39
  }
40
+ /**
41
+ * Convert a tiff tag value to a typed array if the local endian matches the tiff endian
42
+ *
43
+ * @param tiff
44
+ * @param bytes
45
+ * @param offset Offset in the data view to read from
46
+ * @param length Number of bytes to read
47
+ * @param type type of tiff tag
48
+ * @returns the value if the type is a typed array and the endianness matches otherwise null
49
+ */
50
+ export function readTypedValue(tiff, bytes, offset, length, type) {
51
+ switch (type) {
52
+ case TiffTagValueType.Uint8:
53
+ return new Uint8Array(bytes.buffer.slice(bytes.byteOffset + offset, bytes.byteOffset + offset + length));
54
+ case TiffTagValueType.Uint16:
55
+ if (tiff.isLittleEndian !== isLittleEndian)
56
+ return null;
57
+ return new Uint16Array(bytes.buffer.slice(bytes.byteOffset + offset, bytes.byteOffset + offset + length));
58
+ case TiffTagValueType.Uint32:
59
+ if (tiff.isLittleEndian !== isLittleEndian)
60
+ return null;
61
+ return new Uint32Array(bytes.buffer.slice(bytes.byteOffset + offset, bytes.byteOffset + offset + length));
62
+ }
63
+ return null;
64
+ }
39
65
  function readValue(tiff, tagId, bytes, offset, type, count) {
40
66
  const typeSize = getTiffTagSize(type);
41
67
  const dataLength = count * typeSize;
@@ -51,6 +77,15 @@ function readValue(tiff, tagId, bytes, offset, type, count) {
51
77
  case TiffTagValueType.Ascii:
52
78
  return String.fromCharCode.apply(null, new Uint8Array(bytes.buffer, offset, dataLength - 1));
53
79
  }
80
+ // TODO should we convert all tag values to typed arrays if possible?
81
+ if (tagId === TiffTag.TileOffsets ||
82
+ tagId === TiffTag.TileByteCounts ||
83
+ tagId === TiffTag.StripOffsets ||
84
+ tagId === TiffTag.StripByteCounts) {
85
+ const typedOutput = readTypedValue(tiff, bytes, offset, dataLength, type);
86
+ if (typedOutput)
87
+ return typedOutput;
88
+ }
54
89
  const output = [];
55
90
  for (let i = 0; i < dataLength; i += typeSize) {
56
91
  output.push(readTagValue(type, bytes, offset + i, tiff.isLittleEndian));
@@ -94,9 +129,16 @@ export function createTag(tiff, view, offset) {
94
129
  value: [],
95
130
  tagOffset: offset,
96
131
  };
97
- // Some offsets are quite long and don't need to read them often, so only read the tags we are interested in when we need to
98
- if (tagId === TiffTag.TileOffsets && hasBytes(view, dataOffset, dataLength))
99
- setBytes(tag, view);
132
+ if (hasBytes(view, dataOffset, dataLength)) {
133
+ const val = readTypedValue(tiff, view, dataOffset - view.sourceOffset, dataLength, dataType);
134
+ if (val) {
135
+ tag.value = val;
136
+ tag.isLoaded = true;
137
+ }
138
+ else {
139
+ setBytes(tag, view);
140
+ }
141
+ }
100
142
  return tag;
101
143
  }
102
144
  // If we already have the bytes in the view read them in
@@ -128,6 +170,7 @@ export async function fetchAllOffsets(tiff, tag) {
128
170
  tag.view.sourceOffset = tag.dataOffset;
129
171
  }
130
172
  tag.value = readValue(tiff, tag.id, tag.view, 0, tag.dataType, tag.count);
173
+ tag.view = undefined;
131
174
  tag.isLoaded = true;
132
175
  return tag.value;
133
176
  }
@@ -161,4 +204,17 @@ export async function getValueAt(tiff, tag, index) {
161
204
  tag.value[index] = value;
162
205
  return value;
163
206
  }
164
- //# sourceMappingURL=tiff.tag.factory.js.map
207
+ export function getValueAtSync(tiff, tag, index) {
208
+ if (index > tag.count || index < 0)
209
+ throw new Error('TagOffset: out of bounds :' + index);
210
+ if (tag.value[index] != null)
211
+ return tag.value[index];
212
+ if (tag.view == null)
213
+ return null;
214
+ const dataTypeSize = getTiffTagSize(tag.dataType);
215
+ const value = readValue(tiff, undefined, tag.view, index * dataTypeSize, tag.dataType, 1);
216
+ if (typeof value !== 'number')
217
+ throw new Error('Value is not a number');
218
+ tag.value[index] = value;
219
+ return value;
220
+ }
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=tiff.tag.js.map
@@ -1,3 +1,4 @@
1
1
  import { TiffTagValueType } from '../const/tiff.tag.value.js';
2
2
  import type { ByteSize } from '../util/bytes.js';
3
3
  export declare function getTiffTagSize(fieldType: TiffTagValueType): ByteSize;
4
+ //# sourceMappingURL=tiff.value.reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiff.value.reader.d.ts","sourceRoot":"","sources":["../../src/read/tiff.value.reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD,wBAAgB,cAAc,CAAC,SAAS,EAAE,gBAAgB,GAAG,QAAQ,CAyBpE"}
@@ -25,4 +25,3 @@ export function getTiffTagSize(fieldType) {
25
25
  throw new Error(`Invalid fieldType ${String(fieldType)}`);
26
26
  }
27
27
  }
28
- //# sourceMappingURL=tiff.value.reader.js.map
package/build/source.d.ts CHANGED
@@ -11,7 +11,10 @@ export interface Source {
11
11
  size?: number;
12
12
  };
13
13
  /** Fetch bytes from a source */
14
- fetch(offset: number, length?: number): Promise<ArrayBuffer>;
14
+ fetch(offset: number, length?: number, options?: {
15
+ signal?: AbortSignal;
16
+ }): Promise<ArrayBuffer>;
15
17
  /** Optionally close the source, useful for sources that have open connections of file descriptors */
16
18
  close?(): Promise<void>;
17
19
  }
20
+ //# sourceMappingURL=source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,kCAAkC;IAClC,GAAG,EAAE,GAAG,CAAC;IAET,iFAAiF;IACjF,QAAQ,CAAC,EAAE;QACT,2CAA2C;QAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IAEF,gCAAgC;IAChC,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAEjG,qGAAqG;IACrG,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB"}
package/build/source.js CHANGED
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=source.js.map
package/build/tiff.d.ts CHANGED
@@ -3,6 +3,10 @@ import { TiffGhostOptions } from './read/tiff.gdal.js';
3
3
  import type { TiffIfdConfig } from './read/tiff.ifd.config.js';
4
4
  import type { Source } from './source.js';
5
5
  import { TiffImage } from './tiff.image.js';
6
+ export interface TiffCreationOptions {
7
+ /** When initializing the tiff, read data in blocks of this size (in KB) */
8
+ defaultReadSize: number;
9
+ }
6
10
  export declare class Tiff {
7
11
  /** Read 16KB blocks at a time */
8
12
  static DefaultReadSize: number;
@@ -23,11 +27,15 @@ export declare class Tiff {
23
27
  /** Has init() been called */
24
28
  isInitialized: boolean;
25
29
  private _initPromise?;
26
- constructor(source: Source);
30
+ /** A Tiff constructed from a source will not be pre-initialized with {@link init}. */
31
+ constructor(source: Source, options?: TiffCreationOptions);
27
32
  /** Create a tiff and initialize it by reading the tiff headers */
28
- static create(source: Source): Promise<Tiff>;
33
+ static create(source: Source, options?: TiffCreationOptions): Promise<Tiff>;
29
34
  /**
30
- * Initialize the tiff loading in the header and all image headers
35
+ * Initialize the tiff loading in the header and all image headers.
36
+ *
37
+ * This is only required if the Tiff was created with the constructor, if you
38
+ * used {@link create} this will have already been called.
31
39
  */
32
40
  init(): Promise<Tiff>;
33
41
  /**
@@ -46,3 +54,4 @@ export declare class Tiff {
46
54
  */
47
55
  private readIfd;
48
56
  }
57
+ //# sourceMappingURL=tiff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiff.d.ts","sourceRoot":"","sources":["../src/tiff.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAItD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAG/D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,WAAW,mBAAmB;IAClC,2EAA2E;IAC3E,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,qBAAa,IAAI;IACf,iCAAiC;IACjC,MAAM,CAAC,eAAe,SAAa;IACnC,iCAAiC;IACjC,eAAe,SAAwB;IACvC,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,wBAAwB;IACxB,OAAO,cAAoB;IAC3B,0CAA0C;IAC1C,MAAM,EAAE,SAAS,EAAE,CAAM;IACzB,2BAA2B;IAC3B,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,4CAA4C;IAC5C,SAAS,EAAE,aAAa,CAAiB;IACzC,8CAA8C;IAC9C,cAAc,UAAS;IACvB,6BAA6B;IAC7B,aAAa,UAAS;IAEtB,OAAO,CAAC,YAAY,CAAC,CAAgB;IAErC,sFAAsF;gBAC1E,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,mBAA+D;IAKpG,kEAAkE;IAClE,MAAM,CAAC,MAAM,CACX,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,mBAA+D,GACvE,OAAO,CAAC,IAAI,CAAC;IAIhB;;;;;OAKG;IACH,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAMrB;;;;OAIG;IACH,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS;IAoBnD,qEAAqE;YACvD,UAAU;IAgExB;;;;;OAKG;IACH,OAAO,CAAC,OAAO;CAsBhB"}
@@ -17,6 +17,7 @@ export interface TiffImageTileCount {
17
17
  }
18
18
  /** Tags that are commonly accessed for geotiffs */
19
19
  export declare const ImportantTags: Set<TiffTag>;
20
+ export declare const ImportantGeoTags: Set<TiffTag>;
20
21
  /**
21
22
  * Size of a individual tile
22
23
  */
@@ -198,7 +199,9 @@ export declare class TiffImage {
198
199
  /** The jpeg header is stored in the IFD, read the JPEG header and adjust the byte array to include it */
199
200
  getJpegHeader(bytes: ArrayBuffer): ArrayBuffer;
200
201
  /** Read image bytes at the given offset */
201
- getBytes(offset: number, byteCount: number): Promise<{
202
+ getBytes(offset: number, byteCount: number, options?: {
203
+ signal?: AbortSignal;
204
+ }): Promise<{
202
205
  mimeType: TiffMimeType;
203
206
  bytes: ArrayBuffer;
204
207
  compression: Compression;
@@ -211,7 +214,9 @@ export declare class TiffImage {
211
214
  * @param x Tile x offset
212
215
  * @param y Tile y offset
213
216
  */
214
- getTile(x: number, y: number): Promise<{
217
+ getTile(x: number, y: number, options?: {
218
+ signal?: AbortSignal;
219
+ }): Promise<{
215
220
  mimeType: TiffMimeType;
216
221
  bytes: ArrayBuffer;
217
222
  compression: Compression;
@@ -230,6 +235,9 @@ export declare class TiffImage {
230
235
  hasTile(x: number, y: number): Promise<boolean>;
231
236
  /**
232
237
  * Load the offset and byteCount of a tile
238
+ *
239
+ * if the tiff is sparse, offset and byteCount will be zero if the tile is empty
240
+ *
233
241
  * @param index index in the tile array
234
242
  * @returns Offset and byteCount for the tile
235
243
  */
@@ -238,3 +246,4 @@ export declare class TiffImage {
238
246
  imageSize: number;
239
247
  }>;
240
248
  }
249
+ //# sourceMappingURL=tiff.image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiff.image.d.ts","sourceRoot":"","sources":["../src/tiff.image.ts"],"names":[],"mappings":"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"}
@@ -1,6 +1,6 @@
1
1
  import { getCompressionMimeType, TiffCompressionMimeType, TiffMimeType } from './const/tiff.mime.js';
2
2
  import { Compression, ModelTypeCode, SubFileType, TiffTag, TiffTagGeo } from './const/tiff.tag.id.js';
3
- import { fetchAllOffsets, fetchLazy, getValueAt } from './read/tiff.tag.factory.js';
3
+ import { fetchAllOffsets, fetchLazy, getValueAt, getValueAtSync } from './read/tiff.tag.factory.js';
4
4
  import { getUint } from './util/bytes.js';
5
5
  /** Invalid EPSG code */
6
6
  export const InvalidProjectionCode = 32767;
@@ -14,53 +14,25 @@ export const ImportantTags = new Set([
14
14
  TiffTag.ModelTransformation,
15
15
  TiffTag.TileHeight,
16
16
  TiffTag.TileWidth,
17
- TiffTag.GeoKeyDirectory,
18
- TiffTag.GeoAsciiParams,
19
- TiffTag.GeoDoubleParams,
20
- TiffTag.TileOffsets,
21
17
  ]);
18
+ export const ImportantGeoTags = new Set([TiffTag.GeoKeyDirectory, TiffTag.GeoAsciiParams, TiffTag.GeoDoubleParams]);
22
19
  export class TiffImage {
20
+ /**
21
+ * Id of the tif image, generally the image index inside the tif
22
+ * where 0 is the root image, and every sub image is +1
23
+ *
24
+ * @example 0, 1, 2
25
+ */
26
+ id;
27
+ /** Reference to the TIFF that owns this image */
28
+ tiff;
29
+ /** Has loadGeoTiffTags been called */
30
+ isGeoTagsLoaded = false;
31
+ /** Sub tags stored in TiffTag.GeoKeyDirectory */
32
+ tagsGeo = new Map();
33
+ /** All IFD tags that have been read for the image */
34
+ tags;
23
35
  constructor(tiff, id, tags) {
24
- /**
25
- * Id of the tif image, generally the image index inside the tif
26
- * where 0 is the root image, and every sub image is +1
27
- *
28
- * @example 0, 1, 2
29
- */
30
- Object.defineProperty(this, "id", {
31
- enumerable: true,
32
- configurable: true,
33
- writable: true,
34
- value: void 0
35
- });
36
- /** Reference to the TIFF that owns this image */
37
- Object.defineProperty(this, "tiff", {
38
- enumerable: true,
39
- configurable: true,
40
- writable: true,
41
- value: void 0
42
- });
43
- /** Has loadGeoTiffTags been called */
44
- Object.defineProperty(this, "isGeoTagsLoaded", {
45
- enumerable: true,
46
- configurable: true,
47
- writable: true,
48
- value: false
49
- });
50
- /** Sub tags stored in TiffTag.GeoKeyDirectory */
51
- Object.defineProperty(this, "tagsGeo", {
52
- enumerable: true,
53
- configurable: true,
54
- writable: true,
55
- value: new Map()
56
- });
57
- /** All IFD tags that have been read for the image */
58
- Object.defineProperty(this, "tags", {
59
- enumerable: true,
60
- configurable: true,
61
- writable: true,
62
- value: void 0
63
- });
64
36
  this.tiff = tiff;
65
37
  this.id = id;
66
38
  this.tags = tags;
@@ -71,20 +43,14 @@ export class TiffImage {
71
43
  * @param loadGeoTags Whether to load the GeoKeyDirectory and unpack it
72
44
  */
73
45
  async init(loadGeoTags = true) {
74
- const requiredTags = [
75
- this.fetch(TiffTag.Compression),
76
- this.fetch(TiffTag.ImageHeight),
77
- this.fetch(TiffTag.ImageWidth),
78
- this.fetch(TiffTag.ModelPixelScale),
79
- this.fetch(TiffTag.ModelTiePoint),
80
- this.fetch(TiffTag.ModelTransformation),
81
- this.fetch(TiffTag.TileHeight),
82
- this.fetch(TiffTag.TileWidth),
83
- ];
46
+ const requiredTags = [];
47
+ ImportantTags.forEach((tag) => {
48
+ requiredTags.push(this.fetch(tag));
49
+ });
84
50
  if (loadGeoTags) {
85
- requiredTags.push(this.fetch(TiffTag.GeoKeyDirectory));
86
- requiredTags.push(this.fetch(TiffTag.GeoAsciiParams));
87
- requiredTags.push(this.fetch(TiffTag.GeoDoubleParams));
51
+ ImportantGeoTags.forEach((tag) => {
52
+ requiredTags.push(this.fetch(tag));
53
+ });
88
54
  }
89
55
  await Promise.all(requiredTags);
90
56
  if (loadGeoTags)
@@ -457,13 +423,13 @@ export class TiffImage {
457
423
  const actualBytes = new Uint8Array(bytes.byteLength + tableData.length - 2);
458
424
  actualBytes.set(tableData, 0);
459
425
  actualBytes.set(new Uint8Array(bytes).slice(2), tableData.length);
460
- return actualBytes;
426
+ return actualBytes.buffer.slice(actualBytes.byteOffset, actualBytes.byteOffset + actualBytes.byteLength);
461
427
  }
462
428
  /** Read image bytes at the given offset */
463
- async getBytes(offset, byteCount) {
429
+ async getBytes(offset, byteCount, options) {
464
430
  if (byteCount === 0)
465
431
  return null;
466
- const bytes = await this.tiff.source.fetch(offset, byteCount);
432
+ const bytes = await this.tiff.source.fetch(offset, byteCount, options);
467
433
  if (bytes.byteLength < byteCount) {
468
434
  throw new Error(`Failed to fetch bytes from offset:${offset} wanted:${byteCount} got:${bytes.byteLength}`);
469
435
  }
@@ -483,7 +449,7 @@ export class TiffImage {
483
449
  * @param x Tile x offset
484
450
  * @param y Tile y offset
485
451
  */
486
- async getTile(x, y) {
452
+ async getTile(x, y, options) {
487
453
  const size = this.size;
488
454
  const tiles = this.tileSize;
489
455
  if (tiles == null)
@@ -499,7 +465,7 @@ export class TiffImage {
499
465
  if (idx >= totalTiles)
500
466
  throw new Error(`Tile index is outside of tile range: ${idx} >= ${totalTiles}`);
501
467
  const { offset, imageSize } = await this.getTileSize(idx);
502
- return this.getBytes(offset, imageSize);
468
+ return this.getBytes(offset, imageSize, options);
503
469
  }
504
470
  /**
505
471
  * Does this tile exist in the tiff and does it actually have a value
@@ -528,15 +494,25 @@ export class TiffImage {
528
494
  }
529
495
  /**
530
496
  * Load the offset and byteCount of a tile
497
+ *
498
+ * if the tiff is sparse, offset and byteCount will be zero if the tile is empty
499
+ *
531
500
  * @param index index in the tile array
532
501
  * @returns Offset and byteCount for the tile
533
502
  */
534
503
  async getTileSize(index) {
504
+ // If both the tile offset and tile byte counts are loaded,
505
+ // we can get the offset and byte count synchronously without needing to fetch any additional data
506
+ const byteCounts = this.tags.get(TiffTag.TileByteCounts);
507
+ const tileOffset = getOffsetSync(this.tiff, this.tileOffset, index);
508
+ const tileSize = getOffsetSync(this.tiff, byteCounts, index);
509
+ if (tileOffset != null && tileSize != null)
510
+ return { offset: tileOffset, imageSize: tileSize };
535
511
  // GDAL optimizes tiles by storing the size of the tile in
536
512
  // the few bytes leading up to the tile
537
513
  const leaderBytes = this.tiff.options?.tileLeaderByteSize;
538
514
  if (leaderBytes) {
539
- const offset = await getOffset(this.tiff, this.tileOffset, index);
515
+ const offset = tileOffset ?? (await getOffset(this.tiff, this.tileOffset, index));
540
516
  // Sparse tiff no data found
541
517
  if (offset === 0)
542
518
  return { offset: 0, imageSize: 0 };
@@ -545,17 +521,22 @@ export class TiffImage {
545
521
  const bytes = await this.tiff.source.fetch(offset - leaderBytes, leaderBytes);
546
522
  return { offset, imageSize: getUint(new DataView(bytes), 0, leaderBytes, this.tiff.isLittleEndian) };
547
523
  }
548
- const byteCounts = this.tags.get(TiffTag.TileByteCounts);
549
524
  if (byteCounts == null)
550
525
  throw new Error('No tile byte counts found');
551
526
  const [offset, imageSize] = await Promise.all([
552
- getOffset(this.tiff, this.tileOffset, index),
553
- getOffset(this.tiff, byteCounts, index),
527
+ tileOffset ?? getOffset(this.tiff, this.tileOffset, index),
528
+ tileSize ?? getOffset(this.tiff, byteCounts, index),
554
529
  ]);
555
530
  return { offset, imageSize };
556
531
  }
557
532
  }
558
533
  function getOffset(tiff, x, index) {
534
+ const val = getOffsetSync(tiff, x, index);
535
+ if (val != null)
536
+ return Promise.resolve(val);
537
+ return getValueAt(tiff, x, index);
538
+ }
539
+ function getOffsetSync(tiff, x, index) {
559
540
  if (index < 0) {
560
541
  throw new Error(`Tiff: ${tiff.source.url.href} out of bounds ${TiffTag[x.id]} index:${index} total:${x.count}`);
561
542
  }
@@ -564,6 +545,7 @@ function getOffset(tiff, x, index) {
564
545
  return 0;
565
546
  if (x.type === 'inline')
566
547
  return x.value[index];
567
- return getValueAt(tiff, x, index);
548
+ if (x.isLoaded)
549
+ return x.value[index];
550
+ return getValueAtSync(tiff, x, index);
568
551
  }
569
- //# sourceMappingURL=tiff.image.js.map
package/build/tiff.js CHANGED
@@ -8,77 +8,39 @@ import { TiffImage } from './tiff.image.js';
8
8
  import { getUint } from './util/bytes.js';
9
9
  import { toHex } from './util/util.hex.js';
10
10
  export class Tiff {
11
- constructor(source) {
12
- /** Read 16KB blocks at a time */
13
- Object.defineProperty(this, "defaultReadSize", {
14
- enumerable: true,
15
- configurable: true,
16
- writable: true,
17
- value: Tiff.DefaultReadSize
18
- });
19
- /** Where this cog is fetching its data from */
20
- Object.defineProperty(this, "source", {
21
- enumerable: true,
22
- configurable: true,
23
- writable: true,
24
- value: void 0
25
- });
26
- /** Big or small Tiff */
27
- Object.defineProperty(this, "version", {
28
- enumerable: true,
29
- configurable: true,
30
- writable: true,
31
- value: TiffVersion.Tiff
32
- });
33
- /** List of images, o is the base image */
34
- Object.defineProperty(this, "images", {
35
- enumerable: true,
36
- configurable: true,
37
- writable: true,
38
- value: []
39
- });
40
- /** Ghost header options */
41
- Object.defineProperty(this, "options", {
42
- enumerable: true,
43
- configurable: true,
44
- writable: true,
45
- value: void 0
46
- });
47
- /** Configuration for the size of the IFD */
48
- Object.defineProperty(this, "ifdConfig", {
49
- enumerable: true,
50
- configurable: true,
51
- writable: true,
52
- value: TagTiffConfig
53
- });
54
- /** Is the tiff being read is little Endian */
55
- Object.defineProperty(this, "isLittleEndian", {
56
- enumerable: true,
57
- configurable: true,
58
- writable: true,
59
- value: false
60
- });
61
- /** Has init() been called */
62
- Object.defineProperty(this, "isInitialized", {
63
- enumerable: true,
64
- configurable: true,
65
- writable: true,
66
- value: false
67
- });
68
- Object.defineProperty(this, "_initPromise", {
69
- enumerable: true,
70
- configurable: true,
71
- writable: true,
72
- value: void 0
73
- });
11
+ /** Read 16KB blocks at a time */
12
+ static DefaultReadSize = 16 * 1024;
13
+ /** Read 16KB blocks at a time */
14
+ defaultReadSize = Tiff.DefaultReadSize;
15
+ /** Where this cog is fetching its data from */
16
+ source;
17
+ /** Big or small Tiff */
18
+ version = TiffVersion.Tiff;
19
+ /** List of images, o is the base image */
20
+ images = [];
21
+ /** Ghost header options */
22
+ options;
23
+ /** Configuration for the size of the IFD */
24
+ ifdConfig = TagTiffConfig;
25
+ /** Is the tiff being read is little Endian */
26
+ isLittleEndian = false;
27
+ /** Has init() been called */
28
+ isInitialized = false;
29
+ _initPromise;
30
+ /** A Tiff constructed from a source will not be pre-initialized with {@link init}. */
31
+ constructor(source, options = { defaultReadSize: Tiff.DefaultReadSize }) {
74
32
  this.source = source;
33
+ this.defaultReadSize = options.defaultReadSize;
75
34
  }
76
35
  /** Create a tiff and initialize it by reading the tiff headers */
77
- static create(source) {
78
- return new Tiff(source).init();
36
+ static create(source, options = { defaultReadSize: Tiff.DefaultReadSize }) {
37
+ return new Tiff(source, options).init();
79
38
  }
80
39
  /**
81
- * Initialize the tiff loading in the header and all image headers
40
+ * Initialize the tiff loading in the header and all image headers.
41
+ *
42
+ * This is only required if the Tiff was created with the constructor, if you
43
+ * used {@link create} this will have already been called.
82
44
  */
83
45
  init() {
84
46
  if (this._initPromise)
@@ -190,13 +152,6 @@ export class Tiff {
190
152
  return getUint(view, startOffset + tagCount * ifdSize, this.ifdConfig.pointer, this.isLittleEndian);
191
153
  }
192
154
  }
193
- /** Read 16KB blocks at a time */
194
- Object.defineProperty(Tiff, "DefaultReadSize", {
195
- enumerable: true,
196
- configurable: true,
197
- writable: true,
198
- value: 16 * 1024
199
- });
200
155
  function getMaxLength(source, offset, length) {
201
156
  const size = source.metadata?.size;
202
157
  // max length is unknown, roll the dice and hope the chunk exists
@@ -207,4 +162,3 @@ function getMaxLength(source, offset, length) {
207
162
  return size - offset;
208
163
  return length;
209
164
  }
210
- //# sourceMappingURL=tiff.js.map