geotiff 3.0.0 → 3.0.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.
Files changed (164) hide show
  1. package/dist-browser/geotiff.js +3 -2
  2. package/dist-browser/geotiff.js.map +1 -1
  3. package/dist-module/compression/basedecoder.d.ts +4 -0
  4. package/dist-module/compression/basedecoder.d.ts.map +1 -1
  5. package/dist-module/compression/basedecoder.js +6 -0
  6. package/dist-module/compression/index.d.ts +4 -4
  7. package/dist-module/compression/index.d.ts.map +1 -1
  8. package/dist-module/compression/index.js +4 -4
  9. package/dist-module/compression/jpeg.d.ts +6 -1
  10. package/dist-module/compression/jpeg.d.ts.map +1 -1
  11. package/dist-module/compression/jpeg.js +50 -5
  12. package/dist-module/compression/lzw.js +1 -1
  13. package/dist-module/compression/webimage.d.ts +1 -1
  14. package/dist-module/compression/webimage.d.ts.map +1 -1
  15. package/dist-module/compression/webimage.js +1 -1
  16. package/dist-module/dataslice.d.ts.map +1 -1
  17. package/dist-module/dataslice.js +2 -2
  18. package/dist-module/dataview64.d.ts +2 -2
  19. package/dist-module/dataview64.d.ts.map +1 -1
  20. package/dist-module/dataview64.js +4 -4
  21. package/dist-module/geotiff.d.ts +161 -45
  22. package/dist-module/geotiff.d.ts.map +1 -1
  23. package/dist-module/geotiff.js +111 -20
  24. package/dist-module/geotiffimage.d.ts +76 -110
  25. package/dist-module/geotiffimage.d.ts.map +1 -1
  26. package/dist-module/geotiffimage.js +98 -70
  27. package/dist-module/geotiffwriter.js +2 -2
  28. package/dist-module/globals.d.ts +48 -40
  29. package/dist-module/globals.d.ts.map +1 -1
  30. package/dist-module/globals.js +14 -10
  31. package/dist-module/imagefiledirectory.d.ts +2 -2
  32. package/dist-module/imagefiledirectory.d.ts.map +1 -1
  33. package/dist-module/imagefiledirectory.js +23 -12
  34. package/dist-module/logging.js +7 -7
  35. package/dist-module/pool.d.ts +2 -3
  36. package/dist-module/pool.d.ts.map +1 -1
  37. package/dist-module/pool.js +18 -16
  38. package/dist-module/predictor.js +1 -1
  39. package/dist-module/resample.d.ts +18 -18
  40. package/dist-module/resample.d.ts.map +1 -1
  41. package/dist-module/resample.js +12 -12
  42. package/dist-module/source/basesource.d.ts +7 -7
  43. package/dist-module/source/basesource.d.ts.map +1 -1
  44. package/dist-module/source/basesource.js +7 -7
  45. package/dist-module/source/blockedsource.d.ts +10 -10
  46. package/dist-module/source/blockedsource.d.ts.map +1 -1
  47. package/dist-module/source/blockedsource.js +12 -9
  48. package/dist-module/source/client/base.d.ts +8 -10
  49. package/dist-module/source/client/base.d.ts.map +1 -1
  50. package/dist-module/source/client/base.js +4 -3
  51. package/dist-module/source/client/fetch.d.ts +2 -7
  52. package/dist-module/source/client/fetch.d.ts.map +1 -1
  53. package/dist-module/source/client/fetch.js +7 -2
  54. package/dist-module/source/client/http.d.ts +4 -1
  55. package/dist-module/source/client/http.d.ts.map +1 -1
  56. package/dist-module/source/client/http.js +4 -4
  57. package/dist-module/source/client/xhr.d.ts +4 -1
  58. package/dist-module/source/client/xhr.d.ts.map +1 -1
  59. package/dist-module/source/client/xhr.js +1 -1
  60. package/dist-module/source/file.js +4 -4
  61. package/dist-module/source/filereader.js +1 -1
  62. package/dist-module/source/httputils.d.ts +14 -6
  63. package/dist-module/source/httputils.d.ts.map +1 -1
  64. package/dist-module/source/httputils.js +13 -12
  65. package/dist-module/source/remote.d.ts +31 -22
  66. package/dist-module/source/remote.d.ts.map +1 -1
  67. package/dist-module/source/remote.js +37 -13
  68. package/dist-module/utils.d.ts +7 -1
  69. package/dist-module/utils.d.ts.map +1 -1
  70. package/dist-module/utils.js +6 -0
  71. package/dist-module/worker/create.js +1 -1
  72. package/dist-node/compression/basedecoder.d.ts +4 -0
  73. package/dist-node/compression/basedecoder.d.ts.map +1 -1
  74. package/dist-node/compression/basedecoder.js +6 -0
  75. package/dist-node/compression/basedecoder.js.map +1 -1
  76. package/dist-node/compression/index.d.ts +4 -4
  77. package/dist-node/compression/index.d.ts.map +1 -1
  78. package/dist-node/compression/index.js +4 -4
  79. package/dist-node/compression/jpeg.d.ts +6 -1
  80. package/dist-node/compression/jpeg.d.ts.map +1 -1
  81. package/dist-node/compression/jpeg.js +50 -5
  82. package/dist-node/compression/jpeg.js.map +1 -1
  83. package/dist-node/compression/lzw.js +1 -1
  84. package/dist-node/compression/lzw.js.map +1 -1
  85. package/dist-node/compression/webimage.js +1 -1
  86. package/dist-node/compression/webimage.js.map +1 -1
  87. package/dist-node/dataslice.js +2 -2
  88. package/dist-node/dataslice.js.map +1 -1
  89. package/dist-node/dataview64.d.ts +2 -2
  90. package/dist-node/dataview64.d.ts.map +1 -1
  91. package/dist-node/dataview64.js +4 -4
  92. package/dist-node/dataview64.js.map +1 -1
  93. package/dist-node/geotiff.d.ts +161 -45
  94. package/dist-node/geotiff.d.ts.map +1 -1
  95. package/dist-node/geotiff.js +110 -20
  96. package/dist-node/geotiff.js.map +1 -1
  97. package/dist-node/geotiffimage.d.ts +77 -111
  98. package/dist-node/geotiffimage.d.ts.map +1 -1
  99. package/dist-node/geotiffimage.js +98 -70
  100. package/dist-node/geotiffimage.js.map +1 -1
  101. package/dist-node/geotiffwriter.js +2 -2
  102. package/dist-node/geotiffwriter.js.map +1 -1
  103. package/dist-node/globals.d.ts +48 -40
  104. package/dist-node/globals.d.ts.map +1 -1
  105. package/dist-node/globals.js +14 -10
  106. package/dist-node/globals.js.map +1 -1
  107. package/dist-node/imagefiledirectory.d.ts +2 -2
  108. package/dist-node/imagefiledirectory.d.ts.map +1 -1
  109. package/dist-node/imagefiledirectory.js +23 -12
  110. package/dist-node/imagefiledirectory.js.map +1 -1
  111. package/dist-node/logging.js +7 -7
  112. package/dist-node/logging.js.map +1 -1
  113. package/dist-node/pool.d.ts +2 -3
  114. package/dist-node/pool.d.ts.map +1 -1
  115. package/dist-node/pool.js +18 -16
  116. package/dist-node/pool.js.map +1 -1
  117. package/dist-node/predictor.js +1 -1
  118. package/dist-node/predictor.js.map +1 -1
  119. package/dist-node/resample.d.ts +18 -18
  120. package/dist-node/resample.d.ts.map +1 -1
  121. package/dist-node/resample.js +12 -12
  122. package/dist-node/source/basesource.d.ts +7 -7
  123. package/dist-node/source/basesource.d.ts.map +1 -1
  124. package/dist-node/source/basesource.js +7 -7
  125. package/dist-node/source/basesource.js.map +1 -1
  126. package/dist-node/source/blockedsource.d.ts +10 -10
  127. package/dist-node/source/blockedsource.d.ts.map +1 -1
  128. package/dist-node/source/blockedsource.js +12 -9
  129. package/dist-node/source/blockedsource.js.map +1 -1
  130. package/dist-node/source/client/base.d.ts +8 -10
  131. package/dist-node/source/client/base.d.ts.map +1 -1
  132. package/dist-node/source/client/base.js +4 -3
  133. package/dist-node/source/client/base.js.map +1 -1
  134. package/dist-node/source/client/fetch.d.ts +2 -6
  135. package/dist-node/source/client/fetch.d.ts.map +1 -1
  136. package/dist-node/source/client/fetch.js +7 -2
  137. package/dist-node/source/client/fetch.js.map +1 -1
  138. package/dist-node/source/client/http.d.ts +4 -1
  139. package/dist-node/source/client/http.d.ts.map +1 -1
  140. package/dist-node/source/client/http.js +4 -4
  141. package/dist-node/source/client/http.js.map +1 -1
  142. package/dist-node/source/client/xhr.d.ts +4 -1
  143. package/dist-node/source/client/xhr.d.ts.map +1 -1
  144. package/dist-node/source/client/xhr.js +1 -1
  145. package/dist-node/source/client/xhr.js.map +1 -1
  146. package/dist-node/source/file.js +4 -4
  147. package/dist-node/source/file.js.map +1 -1
  148. package/dist-node/source/filereader.js +1 -1
  149. package/dist-node/source/filereader.js.map +1 -1
  150. package/dist-node/source/httputils.d.ts +14 -6
  151. package/dist-node/source/httputils.d.ts.map +1 -1
  152. package/dist-node/source/httputils.js +13 -12
  153. package/dist-node/source/httputils.js.map +1 -1
  154. package/dist-node/source/remote.d.ts +31 -22
  155. package/dist-node/source/remote.d.ts.map +1 -1
  156. package/dist-node/source/remote.js +37 -13
  157. package/dist-node/source/remote.js.map +1 -1
  158. package/dist-node/utils.d.ts +7 -1
  159. package/dist-node/utils.d.ts.map +1 -1
  160. package/dist-node/utils.js +6 -0
  161. package/dist-node/utils.js.map +1 -1
  162. package/dist-node/worker/create.js +1 -1
  163. package/dist-node/worker/create.js.map +1 -1
  164. package/package.json +3 -54
@@ -1,6 +1,10 @@
1
1
  export default class BaseDecoder {
2
2
  constructor(parameters: any);
3
3
  parameters: any;
4
+ /**
5
+ * @abstract
6
+ */
7
+ decodeBlock(_buffer: any): void;
4
8
  decode(buffer: any): Promise<any>;
5
9
  }
6
10
  //# sourceMappingURL=basedecoder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"basedecoder.d.ts","sourceRoot":"","sources":["../../src/compression/basedecoder.js"],"names":[],"mappings":"AAEA;IACE,6BAEC;IADC,gBAA4B;IAG9B,kCAaC;CACF"}
1
+ {"version":3,"file":"basedecoder.d.ts","sourceRoot":"","sources":["../../src/compression/basedecoder.js"],"names":[],"mappings":"AAEA;IACE,6BAEC;IADC,gBAA4B;IAG9B;;OAEG;IACH,gCAEC;IAED,kCAaC;CACF"}
@@ -3,6 +3,12 @@ export default class BaseDecoder {
3
3
  constructor(parameters) {
4
4
  this.parameters = parameters;
5
5
  }
6
+ /**
7
+ * @abstract
8
+ */
9
+ decodeBlock(_buffer) {
10
+ throw new Error('decodeBlock not implemented');
11
+ }
6
12
  async decode(buffer) {
7
13
  const decoded = await this.decodeBlock(buffer);
8
14
  const { tileWidth, tileHeight, predictor, bitsPerSample, planarConfiguration, } = this.parameters;
@@ -6,10 +6,10 @@
6
6
  * Register a decoder for a specific compression method or a range of compressions
7
7
  * @param {(NumberOrUndefined|(NumberOrUndefined[]))} cases ids of the compression methods to register for
8
8
  * @param {function():Promise} importFn the function to import the decoder
9
- * @param {function():Promise} decoderParameterFn
9
+ * @param {function(import("../imagefiledirectory").ImageFileDirectory):Promise} decoderParameterFn
10
10
  * @param {boolean} preferWorker_ Whether to prefer running the decoder in a worker
11
11
  */
12
- export function addDecoder(cases: (NumberOrUndefined | (NumberOrUndefined[])), importFn: () => Promise<any>, decoderParameterFn?: () => Promise<any>, preferWorker_?: boolean): void;
12
+ export function addDecoder(cases: (NumberOrUndefined | (NumberOrUndefined[])), importFn: () => Promise<any>, decoderParameterFn?: (arg0: import("../imagefiledirectory").ImageFileDirectory) => Promise<any>, preferWorker_?: boolean): void;
13
13
  /**
14
14
  * Get the required decoder parameters for a specific compression method
15
15
  * @param {NumberOrUndefined} compression
@@ -25,10 +25,10 @@ export function getDecoderParameters(compression: NumberOrUndefined, fileDirecto
25
25
  export function getDecoder(compression: number, decoderParameters: DecoderParameters): Promise<import("./basedecoder.js").default>;
26
26
  /**
27
27
  * Whether to prefer running the decoder in a worker
28
- * @param {object} fileDirectory the file directory of the image
28
+ * @param {number|undefined} compression the compression method identifier
29
29
  * @returns {boolean}
30
30
  */
31
- export function preferWorker(compression: any): boolean;
31
+ export function preferWorker(compression: number | undefined): boolean;
32
32
  export type DecoderParameters = {
33
33
  tileWidth: number;
34
34
  tileHeight: number;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compression/index.js"],"names":[],"mappings":"AA6BA;;;GAGG;AAEH;;;;;;GAMG;AACH,kCALW,CAAC,iBAAiB,GAAC,CAAC,iBAAiB,EAAE,CAAC,CAAC,YACzC,kBAAkB,uBAClB,kBAAkB,kBAClB,OAAO,QASjB;AAED;;;;GAIG;AACH,kDAHW,iBAAiB,iBACjB,OAAO,0BAA0B,EAAE,kBAAkB,gBAQ/D;AAED;;;;;GAKG;AACH,wCAJW,MAAM,qBACN,iBAAiB,GACf,OAAO,CAAC,OAAO,kBAAkB,EAAE,OAAO,CAAC,CASvD;AAED;;;;GAIG;AACH,gDAFa,OAAO,CAOnB;;eApFa,MAAM;gBACN,MAAM;yBACN,MAAM;mBACN,MAAM;eACN,MAAM;;;;;gCAuBP,CAAC,MAAM,GAAC,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compression/index.js"],"names":[],"mappings":"AA6BA;;;GAGG;AAEH;;;;;;GAMG;AACH,kCALW,CAAC,iBAAiB,GAAC,CAAC,iBAAiB,EAAE,CAAC,CAAC,YACzC,kBAAkB,uBAClB,CAAS,IAAkD,EAAlD,OAAO,uBAAuB,EAAE,kBAAkB,iBAAS,kBACpE,OAAO,QASjB;AAED;;;;GAIG;AACH,kDAHW,iBAAiB,iBACjB,OAAO,0BAA0B,EAAE,kBAAkB,gBAQ/D;AAED;;;;;GAKG;AACH,wCAJW,MAAM,qBACN,iBAAiB,GACf,OAAO,CAAC,OAAO,kBAAkB,EAAE,OAAO,CAAC,CASvD;AAED;;;;GAIG;AACH,0CAHW,MAAM,GAAC,SAAS,GACd,OAAO,CAOnB;;eApFa,MAAM;gBACN,MAAM;yBACN,MAAM;mBACN,MAAM;eACN,MAAM;;;;;gCAuBP,CAAC,MAAM,GAAC,SAAS,CAAC"}
@@ -9,8 +9,8 @@ const registry = new Map();
9
9
  */
10
10
  /**
11
11
  * Default decoder parameter retrieval function
12
- * @param {import('../imagefiledirectory.js').ImageFileDirectory} fileDirectory
13
- * @returns {DecoderParameters}
12
+ * @param {import("../imagefiledirectory").ImageFileDirectory} fileDirectory
13
+ * @returns {Promise<DecoderParameters>}
14
14
  */
15
15
  async function defaultDecoderParameterFn(fileDirectory) {
16
16
  const isTiled = !fileDirectory.hasTag('StripOffsets');
@@ -30,7 +30,7 @@ async function defaultDecoderParameterFn(fileDirectory) {
30
30
  * Register a decoder for a specific compression method or a range of compressions
31
31
  * @param {(NumberOrUndefined|(NumberOrUndefined[]))} cases ids of the compression methods to register for
32
32
  * @param {function():Promise} importFn the function to import the decoder
33
- * @param {function():Promise} decoderParameterFn
33
+ * @param {function(import("../imagefiledirectory").ImageFileDirectory):Promise} decoderParameterFn
34
34
  * @param {boolean} preferWorker_ Whether to prefer running the decoder in a worker
35
35
  */
36
36
  export function addDecoder(cases, importFn, decoderParameterFn = defaultDecoderParameterFn, preferWorker_ = true) {
@@ -69,7 +69,7 @@ export async function getDecoder(compression, decoderParameters) {
69
69
  }
70
70
  /**
71
71
  * Whether to prefer running the decoder in a worker
72
- * @param {object} fileDirectory the file directory of the image
72
+ * @param {number|undefined} compression the compression method identifier
73
73
  * @returns {boolean}
74
74
  */
75
75
  export function preferWorker(compression) {
@@ -2,6 +2,11 @@ export default class JpegDecoder extends BaseDecoder {
2
2
  reader: JpegStreamReader;
3
3
  decodeBlock(buffer: any): ArrayBuffer;
4
4
  }
5
+ export type HuffmanNode = (number | HuffmanNode)[];
6
+ export type Code = {
7
+ children: HuffmanNode;
8
+ index: number;
9
+ };
5
10
  import BaseDecoder from './basedecoder.js';
6
11
  declare class JpegStreamReader {
7
12
  jfif: {
@@ -25,8 +30,8 @@ declare class JpegStreamReader {
25
30
  quantizationTables: any[];
26
31
  huffmanTablesAC: any[];
27
32
  huffmanTablesDC: any[];
33
+ frames: any[];
28
34
  resetFrames(): void;
29
- frames: any[] | undefined;
30
35
  parse(data: any): void;
31
36
  resetInterval: number | undefined;
32
37
  getResult(): Uint8Array<ArrayBuffer>;
@@ -1 +1 @@
1
- {"version":3,"file":"jpeg.d.ts","sourceRoot":"","sources":["../../src/compression/jpeg.js"],"names":[],"mappings":"AAk3BA;IAGI,yBAAoC;IAMtC,sCAIC;CACF;wBAh4BuB,kBAAkB;AAwjB1C;IAEI;;;;;;;;;;;aAAgB;IAChB;;;;;aAAiB;IAEjB,0BAA4B;IAC5B,uBAAyB;IACzB,uBAAyB;IAI3B,oBAEC;IADC,0BAAgB;IAGlB,uBA0PC;IA5CO,kCAAiC;IA8CzC,qCA4CC;CACF"}
1
+ {"version":3,"file":"jpeg.d.ts","sourceRoot":"","sources":["../../src/compression/jpeg.js"],"names":[],"mappings":"AAg6BA;IAGI,yBAAoC;IAMtC,sCAIC;CACF;0BA13Ba,CAAC,MAAM,GAAC,WAAW,CAAC,EAAE;mBACtB;IAAC,QAAQ,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC;wBArD5B,kBAAkB;AAqmB1C;IAEI;;;;;;;;;;;aAAgB;IAChB;;;;;aAAiB;IAEjB,0BAA4B;IAC5B,uBAAyB;IACzB,uBAAyB;IACzB,cAAgB;IAGlB,oBAEC;IAED,uBA2PC;IA5CO,kCAAiC;IA8CzC,qCA4CC;CACF"}
@@ -45,22 +45,38 @@ const dctCos6 = 1567; // cos(6*pi/16)
45
45
  const dctSin6 = 3784; // sin(6*pi/16)
46
46
  const dctSqrt2 = 5793; // sqrt(2)
47
47
  const dctSqrt1d2 = 2896; // sqrt(2) / 2
48
+ /** @typedef {(number|HuffmanNode)[]} HuffmanNode */
49
+ /** @typedef {{children: HuffmanNode, index: number}} Code */
50
+ /**
51
+ * @param {Uint8Array<ArrayBuffer>} codeLengths
52
+ * @param {Uint8Array<ArrayBuffer>} values
53
+ * @returns {HuffmanNode}
54
+ */
48
55
  function buildHuffmanTable(codeLengths, values) {
49
56
  let k = 0;
57
+ /** @type {Array<Code>} */
50
58
  const code = [];
51
59
  let length = 16;
52
60
  while (length > 0 && !codeLengths[length - 1]) {
53
61
  --length;
54
62
  }
55
63
  code.push({ children: [], index: 0 });
64
+ /** @type {Code|undefined} */
56
65
  let p = code[0];
66
+ /** @type {Code|undefined} */
57
67
  let q;
58
68
  for (let i = 0; i < length; i++) {
59
69
  for (let j = 0; j < codeLengths[i]; j++) {
60
70
  p = code.pop();
71
+ if (!p) {
72
+ throw new Error('buildHuffmanTable: codeLength mismatch');
73
+ }
61
74
  p.children[p.index] = values[k];
62
75
  while (p.index > 0) {
63
76
  p = code.pop();
77
+ if (!p) {
78
+ throw new Error('buildHuffmanTable: codeLength mismatch');
79
+ }
64
80
  }
65
81
  p.index++;
66
82
  code.push(p);
@@ -131,6 +147,9 @@ function decodeScan(data, initialOffset, frame, components, resetInterval, spect
131
147
  }
132
148
  function receiveAndExtend(length) {
133
149
  const n = receive(length);
150
+ if (n === undefined) {
151
+ return undefined;
152
+ }
134
153
  if (n >= 1 << (length - 1)) {
135
154
  return n;
136
155
  }
@@ -144,6 +163,9 @@ function decodeScan(data, initialOffset, frame, components, resetInterval, spect
144
163
  let k = 1;
145
164
  while (k < 64) {
146
165
  const rs = decodeHuffman(component.huffmanTableAC);
166
+ if (rs === null) {
167
+ throw new Error('Unexpected end of data in AC coefficient decoding');
168
+ }
147
169
  const s = rs & 15;
148
170
  const r = rs >> 4;
149
171
  if (s === 0) {
@@ -162,7 +184,11 @@ function decodeScan(data, initialOffset, frame, components, resetInterval, spect
162
184
  }
163
185
  function decodeDCFirst(component, zz) {
164
186
  const t = decodeHuffman(component.huffmanTableDC);
165
- const diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
187
+ const value = receiveAndExtend(t);
188
+ if (value === undefined) {
189
+ throw new Error('Unexpected end of data in DC coefficient decoding');
190
+ }
191
+ const diff = t === 0 ? 0 : (value << successive);
166
192
  component.pred += diff;
167
193
  zz[0] = component.pred;
168
194
  }
@@ -179,11 +205,18 @@ function decodeScan(data, initialOffset, frame, components, resetInterval, spect
179
205
  const e = spectralEnd;
180
206
  while (k <= e) {
181
207
  const rs = decodeHuffman(component.huffmanTableAC);
208
+ if (rs === null) {
209
+ throw new Error('Unexpected end of data in AC coefficient decoding');
210
+ }
182
211
  const s = rs & 15;
183
212
  const r = rs >> 4;
184
213
  if (s === 0) {
185
214
  if (r < 15) {
186
- eobrun = receive(r) + (1 << r) - 1;
215
+ const value = receive(r);
216
+ if (value === undefined) {
217
+ throw new Error('Unexpected end of data in AC coefficient decoding');
218
+ }
219
+ eobrun = value + (1 << r) - 1;
187
220
  break;
188
221
  }
189
222
  k += 16;
@@ -191,7 +224,11 @@ function decodeScan(data, initialOffset, frame, components, resetInterval, spect
191
224
  else {
192
225
  k += r;
193
226
  const z = dctZigZag[k];
194
- zz[z] = receiveAndExtend(s) * (1 << successive);
227
+ const value = receiveAndExtend(s);
228
+ if (value === undefined) {
229
+ throw new Error('Unexpected end of data in AC coefficient decoding');
230
+ }
231
+ zz[z] = value * (1 << successive);
195
232
  k++;
196
233
  }
197
234
  }
@@ -208,11 +245,18 @@ function decodeScan(data, initialOffset, frame, components, resetInterval, spect
208
245
  switch (successiveACState) {
209
246
  case 0: { // initial state
210
247
  const rs = decodeHuffman(component.huffmanTableAC);
248
+ if (rs === null) {
249
+ throw new Error('Unexpected end of data in AC coefficient decoding');
250
+ }
211
251
  const s = rs & 15;
212
252
  r = rs >> 4;
213
253
  if (s === 0) {
214
254
  if (r < 15) {
215
- eobrun = receive(r) + (1 << r);
255
+ const value = receive(r);
256
+ if (value === undefined) {
257
+ throw new Error('Unexpected end of data in AC coefficient decoding');
258
+ }
259
+ eobrun = value + (1 << r);
216
260
  successiveACState = 4;
217
261
  }
218
262
  else {
@@ -547,7 +591,7 @@ class JpegStreamReader {
547
591
  this.quantizationTables = [];
548
592
  this.huffmanTablesAC = [];
549
593
  this.huffmanTablesDC = [];
550
- this.resetFrames();
594
+ this.frames = [];
551
595
  }
552
596
  resetFrames() {
553
597
  this.frames = [];
@@ -699,6 +743,7 @@ class JpegStreamReader {
699
743
  scanLines: readUint16(),
700
744
  samplesPerLine: readUint16(),
701
745
  components: {},
746
+ /** @type {any[]} */
702
747
  componentsOrder: [],
703
748
  };
704
749
  const componentsCount = data[offset++];
@@ -122,6 +122,6 @@ function decompress(input) {
122
122
  }
123
123
  export default class LZWDecoder extends BaseDecoder {
124
124
  decodeBlock(buffer) {
125
- return decompress(buffer, false).buffer;
125
+ return decompress(buffer).buffer;
126
126
  }
127
127
  }
@@ -5,7 +5,7 @@
5
5
  * formats like WebP when supported.
6
6
  */
7
7
  export default class WebImageDecoder extends BaseDecoder {
8
- decodeBlock(buffer: any): Promise<any>;
8
+ decodeBlock(buffer: any): Promise<ArrayBuffer>;
9
9
  }
10
10
  import BaseDecoder from './basedecoder.js';
11
11
  //# sourceMappingURL=webimage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webimage.d.ts","sourceRoot":"","sources":["../../src/compression/webimage.js"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH;IAUE,uCAoCC;CACF;wBAvDuB,kBAAkB"}
1
+ {"version":3,"file":"webimage.d.ts","sourceRoot":"","sources":["../../src/compression/webimage.js"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH;IAUE,+CAoCC;CACF;wBAvDuB,kBAAkB"}
@@ -29,7 +29,7 @@ export default class WebImageDecoder extends BaseDecoder {
29
29
  }
30
30
  // Draw the image onto the canvas to extract the pixel data.
31
31
  // Note: createImageBitmap always returns RGBA data.
32
- const ctx = canvas.getContext('2d');
32
+ const ctx = /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
33
33
  ctx.drawImage(imageBitmap, 0, 0);
34
34
  const imageData = ctx.getImageData(0, 0, imageBitmap.width, imageBitmap.height).data;
35
35
  // Return the correct channels to the caller
@@ -1 +1 @@
1
- {"version":3,"file":"dataslice.d.ts","sourceRoot":"","sources":["../src/dataslice.js"],"names":[],"mappings":"AAAA;IACE,iFAKC;IAJC,yBAA0C;IAC1C,kBAA+B;IAC/B,mBAAiC;IACjC,cAAuB;IAGzB,uBAEC;IAED,oBAEC;IAED,wBAEC;IAED,mBAEC;IAED,kBAEC;IAED,0CAEC;IAED,+BAIC;IAED,8BAIC;IAED,gCAIC;IAED,+BAIC;IAED,gCAIC;IAED,+BAIC;IAED,iCAIC;IAED,iCAIC;IAED,gCAuBC;IAGD,+BAyBC;IAED,gCAKC;CACF"}
1
+ {"version":3,"file":"dataslice.d.ts","sourceRoot":"","sources":["../src/dataslice.js"],"names":[],"mappings":"AAAA;IACE,iFAKC;IAJC,yBAA0C;IAC1C,kBAA+B;IAC/B,mBAAiC;IACjC,cAAuB;IAGzB,uBAEC;IAED,oBAEC;IAED,wBAEC;IAED,mBAEC;IAED,kBAEC;IAED,0CAEC;IAED,+BAEC;IAED,8BAEC;IAED,gCAIC;IAED,+BAIC;IAED,gCAIC;IAED,+BAIC;IAED,iCAIC;IAED,iCAIC;IAED,gCAuBC;IAGD,+BAyBC;IAED,gCAKC;CACF"}
@@ -24,10 +24,10 @@ export default class DataSlice {
24
24
  return this.sliceOffset <= offset && this.sliceTop >= offset + length;
25
25
  }
26
26
  readUint8(offset) {
27
- return this._dataView.getUint8(offset - this._sliceOffset, this._littleEndian);
27
+ return this._dataView.getUint8(offset - this._sliceOffset);
28
28
  }
29
29
  readInt8(offset) {
30
- return this._dataView.getInt8(offset - this._sliceOffset, this._littleEndian);
30
+ return this._dataView.getInt8(offset - this._sliceOffset);
31
31
  }
32
32
  readUint16(offset) {
33
33
  return this._dataView.getUint16(offset - this._sliceOffset, this._littleEndian);
@@ -4,8 +4,8 @@ export default class DataView64 {
4
4
  get buffer(): any;
5
5
  getUint64(offset: any, littleEndian: any): number;
6
6
  getInt64(offset: any, littleEndian: any): number;
7
- getUint8(offset: any, littleEndian: any): number;
8
- getInt8(offset: any, littleEndian: any): number;
7
+ getUint8(offset: any): number;
8
+ getInt8(offset: any): number;
9
9
  getUint16(offset: any, littleEndian: any): number;
10
10
  getInt16(offset: any, littleEndian: any): number;
11
11
  getUint32(offset: any, littleEndian: any): number;
@@ -1 +1 @@
1
- {"version":3,"file":"dataview64.d.ts","sourceRoot":"","sources":["../src/dataview64.js"],"names":[],"mappings":"AAEA;IACE,8BAEC;IADC,yBAA0C;IAG5C,kBAEC;IAED,kDAuBC;IAGD,iDAsBC;IAED,iDAEC;IAED,gDAEC;IAED,kDAEC;IAED,iDAEC;IAED,kDAEC;IAED,iDAEC;IAED,mDAEC;IAED,mDAEC;IAED,mDAEC;CACF"}
1
+ {"version":3,"file":"dataview64.d.ts","sourceRoot":"","sources":["../src/dataview64.js"],"names":[],"mappings":"AAEA;IACE,8BAEC;IADC,yBAA0C;IAG5C,kBAEC;IAED,kDAuBC;IAGD,iDAsBC;IAED,8BAEC;IAED,6BAEC;IAED,kDAEC;IAED,iDAEC;IAED,kDAEC;IAED,iDAEC;IAED,mDAEC;IAED,mDAEC;IAED,mDAEC;CACF"}
@@ -50,11 +50,11 @@ export default class DataView64 {
50
50
  }
51
51
  return value;
52
52
  }
53
- getUint8(offset, littleEndian) {
54
- return this._dataView.getUint8(offset, littleEndian);
53
+ getUint8(offset) {
54
+ return this._dataView.getUint8(offset);
55
55
  }
56
- getInt8(offset, littleEndian) {
57
- return this._dataView.getInt8(offset, littleEndian);
56
+ getInt8(offset) {
57
+ return this._dataView.getInt8(offset);
58
58
  }
59
59
  getUint16(offset, littleEndian) {
60
60
  return this._dataView.getUint16(offset, littleEndian);
@@ -1,23 +1,23 @@
1
1
  /**
2
2
  * Creates a new GeoTIFF from a remote URL.
3
3
  * @param {string} url The URL to access the image from
4
- * @param {object} [options] Additional options to pass to the source.
4
+ * @param {RemoteSourceOptions} [options] Additional options to pass to the source.
5
5
  * See {@link makeRemoteSource} for details.
6
6
  * @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
7
7
  * to be aborted
8
8
  * @returns {Promise<GeoTIFF>} The resulting GeoTIFF file.
9
9
  */
10
- export function fromUrl(url: string, options?: object, signal?: AbortSignal): Promise<GeoTIFF>;
10
+ export function fromUrl(url: string, options?: RemoteSourceOptions, signal?: AbortSignal): Promise<GeoTIFF>;
11
11
  /**
12
12
  * Creates a new GeoTIFF from a custom {@link BaseClient}.
13
13
  * @param {BaseClient} client The client.
14
- * @param {object} [options] Additional options to pass to the source.
14
+ * @param {RemoteSourceOptions} [options] Additional options to pass to the source.
15
15
  * See {@link makeRemoteSource} for details.
16
16
  * @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
17
17
  * to be aborted
18
18
  * @returns {Promise<GeoTIFF>} The resulting GeoTIFF file.
19
19
  */
20
- export function fromCustomClient(client: BaseClient, options?: object, signal?: AbortSignal): Promise<GeoTIFF>;
20
+ export function fromCustomClient(client: BaseClient, options?: RemoteSourceOptions, signal?: AbortSignal): Promise<GeoTIFF>;
21
21
  /**
22
22
  * Construct a new GeoTIFF from an
23
23
  * [ArrayBuffer]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer}.
@@ -55,20 +55,21 @@ export function fromBlob(blob: Blob | File, signal?: AbortSignal): Promise<GeoTI
55
55
  * Construct a MultiGeoTIFF from the given URLs.
56
56
  * @param {string} mainUrl The URL for the main file.
57
57
  * @param {string[]} overviewUrls An array of URLs for the overview images.
58
- * @param {Object} [options] Additional options to pass to the source.
58
+ * @param {RemoteSourceOptions} [options] Additional options to pass to the source.
59
59
  * See [makeRemoteSource]{@link module:source.makeRemoteSource}
60
60
  * for details.
61
61
  * @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
62
62
  * to be aborted
63
63
  * @returns {Promise<MultiGeoTIFF>} The resulting MultiGeoTIFF file.
64
64
  */
65
- export function fromUrls(mainUrl: string, overviewUrls?: string[], options?: Object, signal?: AbortSignal): Promise<MultiGeoTIFF>;
65
+ export function fromUrls(mainUrl: string, overviewUrls?: string[], options?: RemoteSourceOptions, signal?: AbortSignal): Promise<MultiGeoTIFF>;
66
66
  /**
67
67
  * Main creating function for GeoTIFF files.
68
- * @param {(Array)} array of pixel values
69
- * @returns {metadata} metadata
68
+ * @param {Array} values of pixel values
69
+ * @param {Object} metadata
70
+ * @returns {ArrayBuffer}
70
71
  */
71
- export function writeArrayBuffer(values: any, metadata: any): any;
72
+ export function writeArrayBuffer(values: any[], metadata: Object): ArrayBuffer;
72
73
  export { default as BaseDecoder } from "./compression/basedecoder.js";
73
74
  export default GeoTIFF;
74
75
  export type TypedArray = Uint8Array | Int8Array | Uint16Array | Int16Array | Uint32Array | Int32Array | Float32Array | Float64Array;
@@ -94,6 +95,117 @@ export type TypedArrayArrayWithDimensions = TypedArray[] & Dimensions;
94
95
  * `(TypedArray | TypedArray[]) & { height: number; width: number}`
95
96
  */
96
97
  export type ReadRasterResult = TypedArrayWithDimensions | TypedArrayArrayWithDimensions;
98
+ export type ReadRastersOptions = {
99
+ /**
100
+ * the subset to read data from in pixels. Whole window if not specified.
101
+ */
102
+ window?: number[] | undefined;
103
+ /**
104
+ * the selection of samples to read from. Default is all samples.
105
+ * All samples if not specified.
106
+ */
107
+ samples?: number[] | undefined;
108
+ /**
109
+ * The optional decoder pool to use.
110
+ */
111
+ pool?: Pool | null | undefined;
112
+ /**
113
+ * The desired width of the output. When the width is not the
114
+ * same as the images, resampling will be performed.
115
+ */
116
+ width?: number | undefined;
117
+ /**
118
+ * The desired height of the output. When the width is not the
119
+ * same as the images, resampling will be performed.
120
+ */
121
+ height?: number | undefined;
122
+ /**
123
+ * The desired resampling method.
124
+ */
125
+ resampleMethod?: string | undefined;
126
+ /**
127
+ * An AbortSignal that may be signalled if the request is
128
+ * to be aborted
129
+ */
130
+ signal?: AbortSignal | undefined;
131
+ /**
132
+ * The value to use for parts of the image
133
+ * outside of the images extent. When multiple samples are requested and `interleave` is
134
+ * `false`, an array of fill values can be passed.
135
+ */
136
+ fillValue?: number | number[] | undefined;
137
+ /**
138
+ * whether the data shall be read
139
+ * in one single array or separate arrays.
140
+ */
141
+ interleave?: boolean | undefined;
142
+ };
143
+ export type ReadRGBOptions = {
144
+ /**
145
+ * the subset to read data from in pixels. Whole window if not specified.
146
+ */
147
+ window?: number[] | undefined;
148
+ /**
149
+ * The optional decoder pool to use.
150
+ */
151
+ pool?: Pool | null | undefined;
152
+ /**
153
+ * The desired width of the output. When the width is no the
154
+ * same as the images, resampling will be performed.
155
+ */
156
+ width?: number | undefined;
157
+ /**
158
+ * The desired height of the output. When the width is no the
159
+ * same as the images, resampling will be performed.
160
+ */
161
+ height?: number | undefined;
162
+ /**
163
+ * The desired resampling method.
164
+ */
165
+ resampleMethod?: string | undefined;
166
+ /**
167
+ * Enable reading alpha channel if present.
168
+ */
169
+ enableAlpha?: boolean | undefined;
170
+ /**
171
+ * An AbortSignal that may be signalled if the request is
172
+ * to be aborted
173
+ */
174
+ signal?: AbortSignal | undefined;
175
+ /**
176
+ * whether the data shall be read
177
+ * in one single array or separate arrays.
178
+ */
179
+ interleave?: boolean | undefined;
180
+ };
181
+ export type BlockedSourceOptions = {
182
+ /**
183
+ * Block size for a BlockedSource.
184
+ */
185
+ blockSize?: number | null | undefined;
186
+ /**
187
+ * The number of blocks to cache.
188
+ */
189
+ cacheSize?: number | undefined;
190
+ };
191
+ export type RemoteSourceOptions = {
192
+ /**
193
+ * Additional headers to add to each request
194
+ */
195
+ headers?: Object | undefined;
196
+ /**
197
+ * Maximum number of ranges to request in a single HTTP request. 0 means no multi-range requests.
198
+ */
199
+ maxRanges?: number | undefined;
200
+ /**
201
+ * Whether to allow full file responses when requesting ranges
202
+ */
203
+ allowFullFile?: boolean | undefined;
204
+ /**
205
+ * When the Fetch API would be used, force using XMLHttpRequest instead.
206
+ */
207
+ forceXHR?: boolean | undefined;
208
+ };
97
209
  export type GeoTIFFOptions = {
98
210
  /**
99
211
  * whether or not decoded tiles shall be cached.
@@ -106,51 +218,37 @@ export type GeoTIFFOptions = {
106
218
  */
107
219
  /**
108
220
  * The abstraction for a whole GeoTIFF file.
109
- * @augments GeoTIFFBase
110
221
  */
111
222
  export class GeoTIFF extends GeoTIFFBase {
112
223
  /**
113
224
  * Parse a (Geo)TIFF file from the given source.
114
225
  *
115
- * @param {*} source The source of data to parse from.
226
+ * @param {BaseSource} source The source of data to parse from.
116
227
  * @param {GeoTIFFOptions} [options] Additional options.
117
228
  * @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
118
229
  * to be aborted
119
230
  */
120
- static fromSource(source: any, options?: GeoTIFFOptions, signal?: AbortSignal): Promise<GeoTIFF>;
231
+ static fromSource(source: BaseSource, options?: GeoTIFFOptions, signal?: AbortSignal): Promise<GeoTIFF>;
121
232
  /**
122
233
  * @constructor
123
- * @param {*} source The datasource to read from.
234
+ * @param {BaseSource} source The datasource to read from.
124
235
  * @param {boolean} littleEndian Whether the image uses little endian.
125
236
  * @param {boolean} bigTiff Whether the image uses bigTIFF conventions.
126
237
  * @param {number} firstIFDOffset The numeric byte-offset from the start of the image
127
238
  * to the first IFD.
128
239
  * @param {GeoTIFFOptions} [options] further options.
129
240
  */
130
- constructor(source: any, littleEndian: boolean, bigTiff: boolean, firstIFDOffset: number, options?: GeoTIFFOptions);
131
- source: any;
241
+ constructor(source: BaseSource, littleEndian: boolean, bigTiff: boolean, firstIFDOffset: number, options?: GeoTIFFOptions);
242
+ source: BaseSource;
132
243
  parser: ImageFileDirectoryParser;
133
244
  littleEndian: boolean;
134
245
  bigTiff: boolean;
135
246
  firstIFDOffset: number;
136
247
  cache: boolean;
137
248
  ifdRequests: any[];
138
- ghostValues: {} | null;
249
+ ghostValues: Object;
139
250
  getSlice(offset: any, size: any): Promise<DataSlice>;
140
251
  requestIFD(index: any): Promise<any>;
141
- /**
142
- * Get the n-th internal subfile of an image. By default, the first is returned.
143
- *
144
- * @param {number} [index=0] the index of the image to return.
145
- * @returns {Promise<GeoTIFFImage>} the image at the given index
146
- */
147
- getImage(index?: number): Promise<GeoTIFFImage>;
148
- /**
149
- * Returns the count of the internal subfiles.
150
- *
151
- * @returns {Promise<number>} the number of internal subfile images
152
- */
153
- getImageCount(): Promise<number>;
154
252
  /**
155
253
  * Get the values of the COG ghost area as a parsed map.
156
254
  * See https://gdal.org/drivers/raster/cog.html#header-ghost-area for reference
@@ -162,7 +260,7 @@ export class GeoTIFF extends GeoTIFFBase {
162
260
  * N.B. After the GeoTIFF has been completely processed it needs
163
261
  * to be closed but only if it has been constructed from a file.
164
262
  */
165
- close(): any;
263
+ close(): false | Promise<void>;
166
264
  }
167
265
  import { BaseClient } from './source/client/base.js';
168
266
  /**
@@ -183,19 +281,6 @@ export class MultiGeoTIFF extends GeoTIFFBase {
183
281
  fileDirectoriesPerFileParsing: any;
184
282
  imageCount: number | null;
185
283
  parseFileDirectoriesPerFile(): Promise<import("./imagefiledirectory.js").ImageFileDirectory[]>;
186
- /**
187
- * Get the n-th internal subfile of an image. By default, the first is returned.
188
- *
189
- * @param {number} [index=0] the index of the image to return.
190
- * @returns {Promise<GeoTIFFImage>} the image at the given index
191
- */
192
- getImage(index?: number): Promise<GeoTIFFImage>;
193
- /**
194
- * Returns the count of the internal subfiles.
195
- *
196
- * @returns {Promise<number>} the number of internal subfile images
197
- */
198
- getImageCount(): Promise<number>;
199
284
  imageCounts: number[] | undefined;
200
285
  }
201
286
  import * as globals from './globals.js';
@@ -208,6 +293,22 @@ import Pool from './pool.js';
208
293
  import GeoTIFFImage from './geotiffimage.js';
209
294
  import { BaseResponse } from './source/client/base.js';
210
295
  declare class GeoTIFFBase {
296
+ /**
297
+ * @param {number} [_index=0] the index of the image to return.
298
+ * @returns {Promise<GeoTIFFImage>} the image at the given index
299
+ */
300
+ getImage(_index?: number): Promise<GeoTIFFImage>;
301
+ /**
302
+ * @returns {Promise<number>} the number of internal subfile images
303
+ */
304
+ getImageCount(): Promise<number>;
305
+ /**
306
+ * @typedef {Object} ReadRastersWindowOptions
307
+ * @property {number} [resX] desired Y resolution (world units per pixel)
308
+ * @property {number} [resY] desired X resolution (world units per pixel)
309
+ * @property {Array<number>} [bbox] the subset to read data from in
310
+ * geographical coordinates. Whole image if not specified.
311
+ */
211
312
  /**
212
313
  * (experimental) Reads raster data from the best fitting image. This function uses
213
314
  * the image with the lowest resolution that is still a higher resolution than the
@@ -217,11 +318,26 @@ declare class GeoTIFFBase {
217
318
  * Then, the [readRasters]{@link GeoTIFFImage#readRasters} method of the selected
218
319
  * image is called and the result returned.
219
320
  * @see GeoTIFFImage.readRasters
220
- * @param {import('./geotiffimage').ReadRasterOptions} [options={}] optional parameters
321
+ * @param {ReadRastersOptions & ReadRastersWindowOptions} options optional parameters
221
322
  * @returns {Promise<ReadRasterResult>} the decoded array(s), with `height` and `width`, as a promise
222
323
  */
223
- readRasters(options?: import("./geotiffimage").ReadRasterOptions): Promise<ReadRasterResult>;
324
+ readRasters(options?: ReadRastersOptions & {
325
+ /**
326
+ * desired Y resolution (world units per pixel)
327
+ */
328
+ resX?: number | undefined;
329
+ /**
330
+ * desired X resolution (world units per pixel)
331
+ */
332
+ resY?: number | undefined;
333
+ /**
334
+ * the subset to read data from in
335
+ * geographical coordinates. Whole image if not specified.
336
+ */
337
+ bbox?: number[] | undefined;
338
+ }): Promise<ReadRasterResult>;
224
339
  }
340
+ import type { BaseSource } from './source/basesource.js';
225
341
  import { ImageFileDirectoryParser } from './imagefiledirectory.js';
226
342
  import DataSlice from './dataslice.js';
227
343
  export { globals, registerTag, rgb, getDecoder, addDecoder, setLogger, Pool, GeoTIFFImage, BaseClient, BaseResponse };