geotiff 3.0.2 → 3.0.4-beta.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 (279) hide show
  1. package/dist-browser/geotiff.js +3 -3
  2. package/dist-browser/geotiff.js.map +1 -1
  3. package/dist-module/compression/basedecoder.d.ts +30 -4
  4. package/dist-module/compression/basedecoder.d.ts.map +1 -1
  5. package/dist-module/compression/basedecoder.js +22 -1
  6. package/dist-module/compression/basedecoder.js.map +1 -0
  7. package/dist-module/compression/deflate.d.ts +2 -1
  8. package/dist-module/compression/deflate.d.ts.map +1 -1
  9. package/dist-module/compression/deflate.js +2 -0
  10. package/dist-module/compression/deflate.js.map +1 -0
  11. package/dist-module/compression/index.d.ts +14 -22
  12. package/dist-module/compression/index.d.ts.map +1 -1
  13. package/dist-module/compression/index.js +36 -25
  14. package/dist-module/compression/index.js.map +1 -0
  15. package/dist-module/compression/jpeg.d.ts +55 -15
  16. package/dist-module/compression/jpeg.d.ts.map +1 -1
  17. package/dist-module/compression/jpeg.js +187 -16
  18. package/dist-module/compression/jpeg.js.map +1 -0
  19. package/dist-module/compression/lerc.d.ts +11 -1
  20. package/dist-module/compression/lerc.d.ts.map +1 -1
  21. package/dist-module/compression/lerc.js +16 -4
  22. package/dist-module/compression/lerc.js.map +1 -0
  23. package/dist-module/compression/lzw.d.ts +2 -1
  24. package/dist-module/compression/lzw.d.ts.map +1 -1
  25. package/dist-module/compression/lzw.js +29 -1
  26. package/dist-module/compression/lzw.js.map +1 -0
  27. package/dist-module/compression/packbits.d.ts +2 -1
  28. package/dist-module/compression/packbits.d.ts.map +1 -1
  29. package/dist-module/compression/packbits.js +2 -0
  30. package/dist-module/compression/packbits.js.map +1 -0
  31. package/dist-module/compression/raw.d.ts +2 -1
  32. package/dist-module/compression/raw.d.ts.map +1 -1
  33. package/dist-module/compression/raw.js +2 -0
  34. package/dist-module/compression/raw.js.map +1 -0
  35. package/dist-module/compression/webimage.d.ts +2 -1
  36. package/dist-module/compression/webimage.d.ts.map +1 -1
  37. package/dist-module/compression/webimage.js +5 -0
  38. package/dist-module/compression/webimage.js.map +1 -0
  39. package/dist-module/compression/zstd.d.ts +4 -2
  40. package/dist-module/compression/zstd.d.ts.map +1 -1
  41. package/dist-module/compression/zstd.js +3 -1
  42. package/dist-module/compression/zstd.js.map +1 -0
  43. package/dist-module/dataslice.d.ts +78 -22
  44. package/dist-module/dataslice.d.ts.map +1 -1
  45. package/dist-module/dataslice.js +57 -1
  46. package/dist-module/dataslice.js.map +1 -0
  47. package/dist-module/dataview64.d.ts +71 -14
  48. package/dist-module/dataview64.d.ts.map +1 -1
  49. package/dist-module/dataview64.js +58 -1
  50. package/dist-module/dataview64.js.map +1 -0
  51. package/dist-module/geotiff.d.ts +61 -12
  52. package/dist-module/geotiff.d.ts.map +1 -1
  53. package/dist-module/geotiff.js +73 -14
  54. package/dist-module/geotiff.js.map +1 -0
  55. package/dist-module/geotiffimage.d.ts +41 -15
  56. package/dist-module/geotiffimage.d.ts.map +1 -1
  57. package/dist-module/geotiffimage.js +132 -52
  58. package/dist-module/geotiffimage.js.map +1 -0
  59. package/dist-module/geotiffwriter.d.ts +28 -1
  60. package/dist-module/geotiffwriter.d.ts.map +1 -1
  61. package/dist-module/geotiffwriter.js +206 -84
  62. package/dist-module/geotiffwriter.js.map +1 -0
  63. package/dist-module/globals.d.ts +912 -92
  64. package/dist-module/globals.d.ts.map +1 -1
  65. package/dist-module/globals.js +201 -227
  66. package/dist-module/globals.js.map +1 -0
  67. package/dist-module/imagefiledirectory.d.ts +72 -19
  68. package/dist-module/imagefiledirectory.d.ts.map +1 -1
  69. package/dist-module/imagefiledirectory.js +51 -26
  70. package/dist-module/imagefiledirectory.js.map +1 -0
  71. package/dist-module/logging.d.ts +36 -10
  72. package/dist-module/logging.d.ts.map +1 -1
  73. package/dist-module/logging.js +16 -2
  74. package/dist-module/logging.js.map +1 -0
  75. package/dist-module/pool.d.ts +15 -8
  76. package/dist-module/pool.d.ts.map +1 -1
  77. package/dist-module/pool.js +11 -3
  78. package/dist-module/pool.js.map +1 -0
  79. package/dist-module/predictor.d.ts +10 -1
  80. package/dist-module/predictor.d.ts.map +1 -1
  81. package/dist-module/predictor.js +19 -0
  82. package/dist-module/predictor.js.map +1 -0
  83. package/dist-module/resample.d.ts.map +1 -1
  84. package/dist-module/resample.js +12 -0
  85. package/dist-module/resample.js.map +1 -0
  86. package/dist-module/rgb.js +1 -0
  87. package/dist-module/rgb.js.map +1 -0
  88. package/dist-module/source/arraybuffer.d.ts +7 -4
  89. package/dist-module/source/arraybuffer.d.ts.map +1 -1
  90. package/dist-module/source/arraybuffer.js +15 -1
  91. package/dist-module/source/arraybuffer.js.map +1 -0
  92. package/dist-module/source/basesource.d.ts +11 -6
  93. package/dist-module/source/basesource.d.ts.map +1 -1
  94. package/dist-module/source/basesource.js +7 -4
  95. package/dist-module/source/basesource.js.map +1 -0
  96. package/dist-module/source/blockedsource.d.ts +2 -2
  97. package/dist-module/source/blockedsource.d.ts.map +1 -1
  98. package/dist-module/source/blockedsource.js +8 -5
  99. package/dist-module/source/blockedsource.js.map +1 -0
  100. package/dist-module/source/client/base.d.ts +8 -7
  101. package/dist-module/source/client/base.d.ts.map +1 -1
  102. package/dist-module/source/client/base.js +7 -5
  103. package/dist-module/source/client/base.js.map +1 -0
  104. package/dist-module/source/client/fetch.d.ts +6 -2
  105. package/dist-module/source/client/fetch.d.ts.map +1 -1
  106. package/dist-module/source/client/fetch.js +7 -2
  107. package/dist-module/source/client/fetch.js.map +1 -0
  108. package/dist-module/source/client/http.d.ts +27 -5
  109. package/dist-module/source/client/http.d.ts.map +1 -1
  110. package/dist-module/source/client/http.js +16 -2
  111. package/dist-module/source/client/http.js.map +1 -0
  112. package/dist-module/source/client/xhr.d.ts +22 -3
  113. package/dist-module/source/client/xhr.d.ts.map +1 -1
  114. package/dist-module/source/client/xhr.js +12 -2
  115. package/dist-module/source/client/xhr.js.map +1 -0
  116. package/dist-module/source/file.d.ts +8 -5
  117. package/dist-module/source/file.d.ts.map +1 -1
  118. package/dist-module/source/file.js +40 -8
  119. package/dist-module/source/file.js.map +1 -0
  120. package/dist-module/source/filereader.d.ts +12 -4
  121. package/dist-module/source/filereader.d.ts.map +1 -1
  122. package/dist-module/source/filereader.js +15 -2
  123. package/dist-module/source/filereader.js.map +1 -0
  124. package/dist-module/source/httputils.d.ts +16 -9
  125. package/dist-module/source/httputils.d.ts.map +1 -1
  126. package/dist-module/source/httputils.js +19 -12
  127. package/dist-module/source/httputils.js.map +1 -0
  128. package/dist-module/source/remote.d.ts.map +1 -1
  129. package/dist-module/source/remote.js +19 -7
  130. package/dist-module/source/remote.js.map +1 -0
  131. package/dist-module/utils.d.ts +36 -41
  132. package/dist-module/utils.d.ts.map +1 -1
  133. package/dist-module/utils.js +17 -12
  134. package/dist-module/utils.js.map +1 -0
  135. package/dist-module/worker/create.js +1 -1
  136. package/dist-module/worker/create.js.map +1 -0
  137. package/dist-module/worker/decoder.d.ts +2 -0
  138. package/dist-module/worker/decoder.d.ts.map +1 -0
  139. package/dist-module/worker/decoder.js +21 -0
  140. package/dist-module/worker/decoder.js.map +1 -0
  141. package/dist-node/compression/basedecoder.d.ts +30 -4
  142. package/dist-node/compression/basedecoder.d.ts.map +1 -1
  143. package/dist-node/compression/basedecoder.js +22 -1
  144. package/dist-node/compression/basedecoder.js.map +1 -1
  145. package/dist-node/compression/deflate.d.ts +2 -1
  146. package/dist-node/compression/deflate.d.ts.map +1 -1
  147. package/dist-node/compression/deflate.js +2 -0
  148. package/dist-node/compression/deflate.js.map +1 -1
  149. package/dist-node/compression/index.d.ts +14 -22
  150. package/dist-node/compression/index.d.ts.map +1 -1
  151. package/dist-node/compression/index.js +36 -25
  152. package/dist-node/compression/index.js.map +1 -1
  153. package/dist-node/compression/jpeg.d.ts +55 -16
  154. package/dist-node/compression/jpeg.d.ts.map +1 -1
  155. package/dist-node/compression/jpeg.js +187 -16
  156. package/dist-node/compression/jpeg.js.map +1 -1
  157. package/dist-node/compression/lerc.d.ts +11 -1
  158. package/dist-node/compression/lerc.d.ts.map +1 -1
  159. package/dist-node/compression/lerc.js +16 -4
  160. package/dist-node/compression/lerc.js.map +1 -1
  161. package/dist-node/compression/lzw.d.ts +2 -1
  162. package/dist-node/compression/lzw.d.ts.map +1 -1
  163. package/dist-node/compression/lzw.js +29 -1
  164. package/dist-node/compression/lzw.js.map +1 -1
  165. package/dist-node/compression/packbits.d.ts +2 -1
  166. package/dist-node/compression/packbits.d.ts.map +1 -1
  167. package/dist-node/compression/packbits.js +2 -0
  168. package/dist-node/compression/packbits.js.map +1 -1
  169. package/dist-node/compression/raw.d.ts +2 -1
  170. package/dist-node/compression/raw.d.ts.map +1 -1
  171. package/dist-node/compression/raw.js +2 -0
  172. package/dist-node/compression/raw.js.map +1 -1
  173. package/dist-node/compression/webimage.d.ts +2 -2
  174. package/dist-node/compression/webimage.d.ts.map +1 -1
  175. package/dist-node/compression/webimage.js +5 -0
  176. package/dist-node/compression/webimage.js.map +1 -1
  177. package/dist-node/compression/zstd.d.ts +2 -1
  178. package/dist-node/compression/zstd.d.ts.map +1 -1
  179. package/dist-node/compression/zstd.js +3 -1
  180. package/dist-node/compression/zstd.js.map +1 -1
  181. package/dist-node/dataslice.d.ts +78 -22
  182. package/dist-node/dataslice.d.ts.map +1 -1
  183. package/dist-node/dataslice.js +57 -1
  184. package/dist-node/dataslice.js.map +1 -1
  185. package/dist-node/dataview64.d.ts +71 -14
  186. package/dist-node/dataview64.d.ts.map +1 -1
  187. package/dist-node/dataview64.js +58 -1
  188. package/dist-node/dataview64.js.map +1 -1
  189. package/dist-node/geotiff.d.ts +61 -12
  190. package/dist-node/geotiff.d.ts.map +1 -1
  191. package/dist-node/geotiff.js +75 -15
  192. package/dist-node/geotiff.js.map +1 -1
  193. package/dist-node/geotiffimage.d.ts +41 -15
  194. package/dist-node/geotiffimage.d.ts.map +1 -1
  195. package/dist-node/geotiffimage.js +132 -52
  196. package/dist-node/geotiffimage.js.map +1 -1
  197. package/dist-node/geotiffwriter.d.ts +28 -1
  198. package/dist-node/geotiffwriter.d.ts.map +1 -1
  199. package/dist-node/geotiffwriter.js +206 -84
  200. package/dist-node/geotiffwriter.js.map +1 -1
  201. package/dist-node/globals.d.ts +910 -90
  202. package/dist-node/globals.d.ts.map +1 -1
  203. package/dist-node/globals.js +202 -228
  204. package/dist-node/globals.js.map +1 -1
  205. package/dist-node/imagefiledirectory.d.ts +72 -19
  206. package/dist-node/imagefiledirectory.d.ts.map +1 -1
  207. package/dist-node/imagefiledirectory.js +51 -26
  208. package/dist-node/imagefiledirectory.js.map +1 -1
  209. package/dist-node/logging.d.ts +36 -10
  210. package/dist-node/logging.d.ts.map +1 -1
  211. package/dist-node/logging.js +16 -2
  212. package/dist-node/logging.js.map +1 -1
  213. package/dist-node/pool.d.ts +15 -8
  214. package/dist-node/pool.d.ts.map +1 -1
  215. package/dist-node/pool.js +11 -3
  216. package/dist-node/pool.js.map +1 -1
  217. package/dist-node/predictor.d.ts +10 -1
  218. package/dist-node/predictor.d.ts.map +1 -1
  219. package/dist-node/predictor.js +19 -0
  220. package/dist-node/predictor.js.map +1 -1
  221. package/dist-node/resample.d.ts.map +1 -1
  222. package/dist-node/resample.js +12 -0
  223. package/dist-node/resample.js.map +1 -1
  224. package/dist-node/rgb.js +1 -0
  225. package/dist-node/rgb.js.map +1 -1
  226. package/dist-node/source/arraybuffer.d.ts +7 -4
  227. package/dist-node/source/arraybuffer.d.ts.map +1 -1
  228. package/dist-node/source/arraybuffer.js +15 -1
  229. package/dist-node/source/arraybuffer.js.map +1 -1
  230. package/dist-node/source/basesource.d.ts +11 -6
  231. package/dist-node/source/basesource.d.ts.map +1 -1
  232. package/dist-node/source/basesource.js +7 -4
  233. package/dist-node/source/basesource.js.map +1 -1
  234. package/dist-node/source/blockedsource.d.ts +2 -2
  235. package/dist-node/source/blockedsource.d.ts.map +1 -1
  236. package/dist-node/source/blockedsource.js +8 -5
  237. package/dist-node/source/blockedsource.js.map +1 -1
  238. package/dist-node/source/client/base.d.ts +8 -7
  239. package/dist-node/source/client/base.d.ts.map +1 -1
  240. package/dist-node/source/client/base.js +7 -5
  241. package/dist-node/source/client/base.js.map +1 -1
  242. package/dist-node/source/client/fetch.d.ts +5 -2
  243. package/dist-node/source/client/fetch.d.ts.map +1 -1
  244. package/dist-node/source/client/fetch.js +7 -2
  245. package/dist-node/source/client/fetch.js.map +1 -1
  246. package/dist-node/source/client/http.d.ts +22 -4
  247. package/dist-node/source/client/http.d.ts.map +1 -1
  248. package/dist-node/source/client/http.js +16 -2
  249. package/dist-node/source/client/http.js.map +1 -1
  250. package/dist-node/source/client/xhr.d.ts +23 -3
  251. package/dist-node/source/client/xhr.d.ts.map +1 -1
  252. package/dist-node/source/client/xhr.js +12 -2
  253. package/dist-node/source/client/xhr.js.map +1 -1
  254. package/dist-node/source/file.d.ts +8 -5
  255. package/dist-node/source/file.d.ts.map +1 -1
  256. package/dist-node/source/file.js +40 -8
  257. package/dist-node/source/file.js.map +1 -1
  258. package/dist-node/source/filereader.d.ts +12 -4
  259. package/dist-node/source/filereader.d.ts.map +1 -1
  260. package/dist-node/source/filereader.js +15 -2
  261. package/dist-node/source/filereader.js.map +1 -1
  262. package/dist-node/source/httputils.d.ts +16 -9
  263. package/dist-node/source/httputils.d.ts.map +1 -1
  264. package/dist-node/source/httputils.js +19 -12
  265. package/dist-node/source/httputils.js.map +1 -1
  266. package/dist-node/source/remote.d.ts.map +1 -1
  267. package/dist-node/source/remote.js +19 -7
  268. package/dist-node/source/remote.js.map +1 -1
  269. package/dist-node/utils.d.ts +9 -8
  270. package/dist-node/utils.d.ts.map +1 -1
  271. package/dist-node/utils.js +17 -12
  272. package/dist-node/utils.js.map +1 -1
  273. package/dist-node/worker/create.js +1 -1
  274. package/dist-node/worker/create.js.map +1 -1
  275. package/dist-node/worker/decoder.d.ts +2 -0
  276. package/dist-node/worker/decoder.d.ts.map +1 -0
  277. package/dist-node/worker/decoder.js +24 -0
  278. package/dist-node/worker/decoder.js.map +1 -0
  279. package/package.json +5 -3
@@ -13,7 +13,8 @@ declare class GeoTIFFImage {
13
13
  constructor(fileDirectory: import("./imagefiledirectory").ImageFileDirectory, littleEndian: boolean, cache: boolean, source: import("./source/basesource.js").BaseSource);
14
14
  fileDirectory: import("./imagefiledirectory").ImageFileDirectory;
15
15
  littleEndian: boolean;
16
- tiles: {} | null;
16
+ /** @type {Array<Promise<ArrayBufferLike>>|null} */
17
+ tiles: Array<Promise<ArrayBufferLike>> | null;
17
18
  isTiled: boolean;
18
19
  /** @type {1 | 2} */
19
20
  planarConfiguration: 1 | 2;
@@ -54,18 +55,35 @@ declare class GeoTIFFImage {
54
55
  */
55
56
  getTileHeight(): number;
56
57
  getBlockWidth(): number;
57
- getBlockHeight(y: any): number;
58
+ /**
59
+ * @param {number} y
60
+ * @returns {number}
61
+ */
62
+ getBlockHeight(y: number): number;
58
63
  /**
59
64
  * Calculates the number of bytes for each pixel across all samples. Only full
60
65
  * bytes are supported, an exception is thrown when this is not the case.
61
66
  * @returns {Number} the bytes per pixel
62
67
  */
63
68
  getBytesPerPixel(): number;
64
- getSampleByteSize(i: any): number;
65
- getReaderForSample(sampleIndex: any): (byteOffset: number, littleEndian?: boolean) => number;
66
- getSampleFormat(sampleIndex?: number): any;
67
- getBitsPerSample(sampleIndex?: number): any;
68
- getArrayForSample(sampleIndex: any, size: any): Uint8Array<any> | Uint16Array<any> | Uint32Array<any> | Int8Array<any> | Int16Array<any> | Int32Array<any> | Float32Array<any> | Float64Array<any>;
69
+ /**
70
+ * @param {number} i
71
+ * @returns {number}
72
+ */
73
+ getSampleByteSize(i: number): number;
74
+ /**
75
+ * @param {number} sampleIndex
76
+ * @returns {(this: DataView, byteOffset: number, littleEndian: boolean) => number}
77
+ */
78
+ getReaderForSample(sampleIndex: number): (this: DataView, byteOffset: number, littleEndian: boolean) => number;
79
+ getSampleFormat(sampleIndex?: number): number;
80
+ getBitsPerSample(sampleIndex?: number): number;
81
+ /**
82
+ * @param {number} sampleIndex
83
+ * @param {number|ArrayBufferLike} sizeOrData
84
+ * @returns {TypedArray}
85
+ */
86
+ getArrayForSample(sampleIndex: number, sizeOrData: number | ArrayBufferLike): TypedArray;
69
87
  /**
70
88
  * Returns the decoded strip or tile.
71
89
  * @param {Number} x the strip or tile x-offset
@@ -74,19 +92,19 @@ declare class GeoTIFFImage {
74
92
  * @param {DecoderWorker|import("./geotiff").BaseDecoder} poolOrDecoder the decoder or decoder pool
75
93
  * @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
76
94
  * to be aborted
77
- * @returns {Promise.<{x: number, y: number, sample: number, data: ArrayBuffer}>} the decoded strip or tile
95
+ * @returns {Promise.<{x: number, y: number, sample: number, data: ArrayBufferLike}>} the decoded strip or tile
78
96
  */
79
97
  getTileOrStrip(x: number, y: number, sample: number, poolOrDecoder: DecoderWorker | import("./geotiff").BaseDecoder, signal?: AbortSignal): Promise<{
80
98
  x: number;
81
99
  y: number;
82
100
  sample: number;
83
- data: ArrayBuffer;
101
+ data: ArrayBufferLike;
84
102
  }>;
85
103
  /**
86
104
  * Internal read function.
87
105
  * @private
88
- * @param {Array} imageWindow The image window in pixel coordinates
89
- * @param {Array} samples The selected samples (0-based indices)
106
+ * @param {Array<number>} imageWindow The image window in pixel coordinates
107
+ * @param {Array<number>} samples The selected samples (0-based indices)
90
108
  * @param {TypedArray|TypedArray[]} valueArrays The array(s) to write into
91
109
  * @param {boolean|undefined} interleave Whether or not to write in an interleaved manner
92
110
  * @param {DecoderWorker|import("./geotiff").BaseDecoder} poolOrDecoder the decoder or decoder pool
@@ -160,9 +178,16 @@ declare class GeoTIFFImage {
160
178
  readRGB(options?: ReadRGBOptions | undefined): Promise<import("./geotiff").TypedArrayArrayWithDimensions>;
161
179
  /**
162
180
  * Returns an array of tiepoints.
163
- * @returns {Promise<Object[]>}
181
+ * @returns {Promise<Array<{i: number, j: number, k: number, x: number, y: number, z: number}>>} the tiepoints
164
182
  */
165
- getTiePoints(): Promise<any[]>;
183
+ getTiePoints(): Promise<Array<{
184
+ i: number;
185
+ j: number;
186
+ k: number;
187
+ x: number;
188
+ y: number;
189
+ z: number;
190
+ }>>;
166
191
  /**
167
192
  * Returns the parsed GDAL metadata items.
168
193
  *
@@ -170,9 +195,9 @@ declare class GeoTIFFImage {
170
195
  * Otherwise only metadata specific to the provided sample will be returned.
171
196
  *
172
197
  * @param {number|null} [sample=null] The sample index.
173
- * @returns {Promise<Object>}
198
+ * @returns {Promise<Record<string, unknown>|null>} The GDAL metadata items
174
199
  */
175
- getGDALMetadata(sample?: number | null): Promise<any>;
200
+ getGDALMetadata(sample?: number | null): Promise<Record<string, unknown> | null>;
176
201
  /**
177
202
  * Returns the GDAL nodata value
178
203
  * @returns {number|null}
@@ -208,6 +233,7 @@ declare class GeoTIFFImage {
208
233
  */
209
234
  getBoundingBox(tilegrid?: boolean): Array<number>;
210
235
  }
236
+ import type { TypedArray } from "./geotiff";
211
237
  import type { DecoderWorker } from "./geotiff";
212
238
  import type { ReadRastersOptions } from "./geotiff";
213
239
  import type { ReadRasterResult } from "./geotiff";
@@ -1 +1 @@
1
- {"version":3,"file":"geotiffimage.d.ts","sourceRoot":"","sources":["../dist-module/geotiffimage.js"],"names":[],"mappings":";AAkJA;;GAEG;AACH;IACI;;;;;;OAMG;IACH,2BALW,OAAO,sBAAsB,EAAE,kBAAkB,iDAGjD,OAAO,wBAAwB,EAAE,UAAU,EAcrD;IAXG,iEAAkC;IAClC,sBAAgC;IAChC,iBAA8B;IAC9B,iBAAoD;IAKpD,oBAAoB;IACpB,qBADW,CAAC,GAAG,CAAC,CAC8B;IAC9C,oDAAoB;IAExB;;;OAGG;IACH,oBAFa,OAAO,sBAAsB,EAAE,kBAAkB,CAI7D;IACD;;;OAGG;IACH,cAFa,OAAO,CAAC,MAAM,CAAC,OAAO,cAAc,EAAE,UAAU,EAAE,GAAC,CAAC,CAAC,GAAC,IAAI,CAItE;IACD;;;OAGG;IACH,mBAEC;IACD;;;OAGG;IACH,oBAEC;IACD;;;OAGG;IACH,6BAGC;IACD;;;OAGG;IACH,uBAEC;IACD;;;OAGG;IACH,wBAQC;IACD,wBAEC;IACD,+BAOC;IACD;;;;OAIG;IACH,2BAOC;IACD,kCAMC;IACD,6FA6CC;IACD,2CAGC;IACD,4CAEC;IACD,mMAIC;IACD;;;;;;;;;OASG;IACH,oEALW,aAAa,GAAC,OAAO,WAAW,EAAE,WAAW,WAC7C,WAAW,GAET,OAAO,CAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,WAAW,CAAA;KAAC,CAAC,CA0D/E;IACD;;;;;;;;;;;;;;OAcG;IACH,oBAgGC;;;;;;IAEE,qBACQ,kBAAkB,GAAG;QAAC,UAAU,EAAE,IAAI,CAAA;KAAC,GACrC,OAAO,CAAC,OAAO,WAAW,EAAE,wBAAwB,CAAC,CACjE;;;;;;IAEE,qBACQ,kBAAkB,GAAG;QAAC,UAAU,EAAE,KAAK,CAAA;KAAC,GACtC,OAAO,CAAC,OAAO,WAAW,EAAE,6BAA6B,CAAC,CACtE;;;;;;IAEE,qBACQ,kBAAkB,GAAG;QAAC,UAAU,EAAE,OAAO,CAAA;KAAC,GACxC,OAAO,CAAC,gBAAgB,CAAC,CACrC;;;;;;IAEE,uDAEU,OAAO,CAAC,OAAO,WAAW,EAAE,6BAA6B,CAAC,CACtE;;;;;;IAsEE,iBACQ,cAAc,GAAG;QAAC,UAAU,EAAE,IAAI,CAAA;KAAC,GACjC,OAAO,CAAC,OAAO,WAAW,EAAE,wBAAwB,CAAC,CACjE;;;;;;IAEE,iBACQ,cAAc,GAAG;QAAC,UAAU,EAAE,KAAK,CAAA;KAAC,GAClC,OAAO,CAAC,OAAO,WAAW,EAAE,6BAA6B,CAAC,CACtE;;;;;;IAEE,iBACQ,cAAc,GAAG;QAAC,UAAU,EAAE,OAAO,CAAA;KAAC,GACpC,OAAO,CAAC,gBAAgB,CAAC,CACrC;;;;;;IAEE,+CAEU,OAAO,CAAC,OAAO,WAAW,EAAE,6BAA6B,CAAC,CACtE;IA+GD;;;OAGG;IACH,gBAFa,OAAO,CAAC,KAAQ,CAAC,CAmB7B;IACD;;;;;;;;OAQG;IACH,yBAHW,MAAM,GAAC,IAAI,GACT,OAAO,KAAQ,CAoB3B;IACD;;;OAGG;IACH,iBAFa,MAAM,GAAC,IAAI,CAQvB;IACD;;;;OAIG;IACH,aAFa,KAAK,CAAC,MAAM,CAAC,CAoBzB;IACD;;;;;;;OAOG;IACH,+BALW,YAAY,GAAC,IAAI,GAGf,KAAK,CAAC,MAAM,CAAC,CAqCzB;IACD;;;OAGG;IACH,uBAEC;IACD;;;;;;;OAOG;IACH,0BAJW,OAAO,GAEL,KAAK,CAAC,MAAM,CAAC,CAyCzB;CACJ;mCAx3B4C,WAAW;wCAElB,WAAW;sCADb,WAAW;oCAEb,WAAW"}
1
+ {"version":3,"file":"geotiffimage.d.ts","sourceRoot":"","sources":["../dist-module/geotiffimage.js"],"names":[],"mappings":";AA0LA;;GAEG;AACH;IACI;;;;;;OAMG;IACH,2BALW,OAAO,sBAAsB,EAAE,kBAAkB,iDAGjD,OAAO,wBAAwB,EAAE,UAAU,EAerD;IAZG,iEAAkC;IAClC,sBAAgC;IAChC,mDAAmD;IACnD,OADW,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,GAAC,IAAI,CACjB;IAC9B,iBAAoD;IAKpD,oBAAoB;IACpB,qBADW,CAAC,GAAG,CAAC,CAC8B;IAC9C,oDAAoB;IAExB;;;OAGG;IACH,oBAFa,OAAO,sBAAsB,EAAE,kBAAkB,CAI7D;IACD;;;OAGG;IACH,cAFa,OAAO,CAAC,MAAM,CAAC,OAAO,cAAc,EAAE,UAAU,EAAE,GAAC,CAAC,CAAC,GAAC,IAAI,CAItE;IACD;;;OAGG;IACH,mBAEC;IACD;;;OAGG;IACH,oBAEC;IACD;;;OAGG;IACH,6BAEC;IACD;;;OAGG;IACH,uBAEC;IACD;;;OAGG;IACH,wBASC;IACD,wBAEC;IACD;;;OAGG;IACH,kBAHW,MAAM,GACJ,MAAM,CASlB;IACD;;;;OAIG;IACH,2BAQC;IACD;;;OAGG;IACH,qBAHW,MAAM,GACJ,MAAM,CAQlB;IACD;;;OAGG;IACH,gCAHW,MAAM,GACJ,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,KAAK,MAAM,CAgDjF;IACD,8CAGC;IACD,+CAGC;IACD;;;;OAIG;IACH,+BAJW,MAAM,cACN,MAAM,GAAC,eAAe,GACpB,UAAU,CAMtB;IACD;;;;;;;;;OASG;IACH,oEALW,aAAa,GAAC,OAAO,WAAW,EAAE,WAAW,WAC7C,WAAW,GAET,OAAO,CAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,eAAe,CAAA;KAAC,CAAC,CA0DnF;IACD;;;;;;;;;;;;;;OAcG;IACH,oBAsGC;;;;;;IAEE,qBACQ,kBAAkB,GAAG;QAAC,UAAU,EAAE,IAAI,CAAA;KAAC,GACrC,OAAO,CAAC,OAAO,WAAW,EAAE,wBAAwB,CAAC,CACjE;;;;;;IAEE,qBACQ,kBAAkB,GAAG;QAAC,UAAU,EAAE,KAAK,CAAA;KAAC,GACtC,OAAO,CAAC,OAAO,WAAW,EAAE,6BAA6B,CAAC,CACtE;;;;;;IAEE,qBACQ,kBAAkB,GAAG;QAAC,UAAU,EAAE,OAAO,CAAA;KAAC,GACxC,OAAO,CAAC,gBAAgB,CAAC,CACrC;;;;;;IAEE,uDAEU,OAAO,CAAC,OAAO,WAAW,EAAE,6BAA6B,CAAC,CACtE;;;;;;IA2EE,iBACQ,cAAc,GAAG;QAAC,UAAU,EAAE,IAAI,CAAA;KAAC,GACjC,OAAO,CAAC,OAAO,WAAW,EAAE,wBAAwB,CAAC,CACjE;;;;;;IAEE,iBACQ,cAAc,GAAG;QAAC,UAAU,EAAE,KAAK,CAAA;KAAC,GAClC,OAAO,CAAC,OAAO,WAAW,EAAE,6BAA6B,CAAC,CACtE;;;;;;IAEE,iBACQ,cAAc,GAAG;QAAC,UAAU,EAAE,OAAO,CAAA;KAAC,GACpC,OAAO,CAAC,gBAAgB,CAAC,CACrC;;;;;;IAEE,+CAEU,OAAO,CAAC,OAAO,WAAW,EAAE,6BAA6B,CAAC,CACtE;IAiHD;;;OAGG;IACH,gBAFa,OAAO,CAAC,KAAK,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,CAAC,CAAC,CAsB9F;IACD;;;;;;;;OAQG;IACH,yBAHW,MAAM,GAAC,IAAI,GACT,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAC,IAAI,CAAC,CAsBjD;IACD;;;OAGG;IACH,iBAFa,MAAM,GAAC,IAAI,CAQvB;IACD;;;;OAIG;IACH,aAFa,KAAK,CAAC,MAAM,CAAC,CAoBzB;IACD;;;;;;;OAOG;IACH,+BALW,YAAY,GAAC,IAAI,GAGf,KAAK,CAAC,MAAM,CAAC,CAqCzB;IACD;;;OAGG;IACH,uBAEC;IACD;;;;;;;OAOG;IACH,0BAJW,OAAO,GAEL,KAAK,CAAC,MAAM,CAAC,CAyCzB;CACJ;gCAr8B4C,WAAW;mCAAX,WAAW;wCAElB,WAAW;sCADb,WAAW;oCAEb,WAAW"}
@@ -5,7 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  /** @module geotiffimage */
7
7
  const float16_1 = require("@petamoriken/float16");
8
+ // @ts-expect-error
8
9
  const get_attribute_1 = __importDefault(require("xml-utils/get-attribute")); // eslint-disable-line import/extensions
10
+ // @ts-expect-error
9
11
  const find_tags_by_name_1 = __importDefault(require("xml-utils/find-tags-by-name")); // eslint-disable-line import/extensions
10
12
  const globals_js_1 = require("./globals.js");
11
13
  const rgb_js_1 = require("./rgb.js");
@@ -15,6 +17,12 @@ const resample_js_1 = require("./resample.js");
15
17
  /** @import {ReadRasterResult} from "./geotiff" */
16
18
  /** @import {ReadRastersOptions} from "./geotiff" */
17
19
  /** @import {ReadRGBOptions} from "./geotiff" */
20
+ /**
21
+ * @param {Array<number>|TypedArray} array
22
+ * @param {number} start
23
+ * @param {number} end
24
+ * @returns {number}
25
+ */
18
26
  function sum(array, start, end) {
19
27
  let s = 0;
20
28
  for (let i = start; i < end; ++i) {
@@ -22,37 +30,46 @@ function sum(array, start, end) {
22
30
  }
23
31
  return s;
24
32
  }
25
- function arrayForType(format, bitsPerSample, size) {
33
+ /**
34
+ * @param {1|2|3} format
35
+ * @param {number} bitsPerSample
36
+ * @param {number|ArrayBufferLike} sizeOrData
37
+ * @returns {TypedArray}
38
+ */
39
+ function arrayForType(format, bitsPerSample, sizeOrData) {
40
+ let TypedArrayConstructor;
26
41
  switch (format) {
27
42
  case 1: // unsigned integer data
28
43
  if (bitsPerSample <= 8) {
29
- return new Uint8Array(size);
44
+ TypedArrayConstructor = Uint8Array;
30
45
  }
31
46
  else if (bitsPerSample <= 16) {
32
- return new Uint16Array(size);
47
+ TypedArrayConstructor = Uint16Array;
33
48
  }
34
49
  else if (bitsPerSample <= 32) {
35
- return new Uint32Array(size);
50
+ TypedArrayConstructor = Uint32Array;
36
51
  }
37
52
  break;
38
53
  case 2: // twos complement signed integer data
39
54
  if (bitsPerSample === 8) {
40
- return new Int8Array(size);
55
+ TypedArrayConstructor = Int8Array;
41
56
  }
42
57
  else if (bitsPerSample === 16) {
43
- return new Int16Array(size);
58
+ TypedArrayConstructor = Int16Array;
44
59
  }
45
60
  else if (bitsPerSample === 32) {
46
- return new Int32Array(size);
61
+ TypedArrayConstructor = Int32Array;
47
62
  }
48
63
  break;
49
64
  case 3: // floating point data
50
65
  switch (bitsPerSample) {
51
66
  case 16:
52
67
  case 32:
53
- return new Float32Array(size);
68
+ TypedArrayConstructor = Float32Array;
69
+ break;
54
70
  case 64:
55
- return new Float64Array(size);
71
+ TypedArrayConstructor = Float64Array;
72
+ break;
56
73
  default:
57
74
  break;
58
75
  }
@@ -60,8 +77,21 @@ function arrayForType(format, bitsPerSample, size) {
60
77
  default:
61
78
  break;
62
79
  }
80
+ if (TypedArrayConstructor) {
81
+ if (typeof sizeOrData === 'number') {
82
+ return new TypedArrayConstructor(sizeOrData);
83
+ }
84
+ else if (sizeOrData instanceof ArrayBuffer) {
85
+ return new TypedArrayConstructor(sizeOrData);
86
+ }
87
+ }
63
88
  throw Error('Unsupported data format/bitsPerSample');
64
89
  }
90
+ /**
91
+ * @param {1|2|3} format
92
+ * @param {number} bitsPerSample
93
+ * @returns {boolean}
94
+ */
65
95
  function needsNormalization(format, bitsPerSample) {
66
96
  if ((format === 1 || format === 2) && bitsPerSample <= 32 && bitsPerSample % 8 === 0) {
67
97
  return false;
@@ -71,6 +101,16 @@ function needsNormalization(format, bitsPerSample) {
71
101
  }
72
102
  return true;
73
103
  }
104
+ /**
105
+ * @param {ArrayBufferLike} inBuffer
106
+ * @param {1|2|3} format
107
+ * @param {1|2} planarConfiguration
108
+ * @param {number} samplesPerPixel
109
+ * @param {number} bitsPerSample
110
+ * @param {number} tileWidth
111
+ * @param {number} tileHeight
112
+ * @returns {ArrayBufferLike}
113
+ */
74
114
  function normalizeArray(inBuffer, format, planarConfiguration, samplesPerPixel, bitsPerSample, tileWidth, tileHeight) {
75
115
  // const inByteArray = new Uint8Array(inBuffer);
76
116
  const view = new DataView(inBuffer);
@@ -163,7 +203,8 @@ class GeoTIFFImage {
163
203
  constructor(fileDirectory, littleEndian, cache, source) {
164
204
  this.fileDirectory = fileDirectory;
165
205
  this.littleEndian = littleEndian;
166
- this.tiles = cache ? {} : null;
206
+ /** @type {Array<Promise<ArrayBufferLike>>|null} */
207
+ this.tiles = cache ? [] : null;
167
208
  this.isTiled = !fileDirectory.hasTag('StripOffsets');
168
209
  const planarConfiguration = fileDirectory.getValue('PlanarConfiguration') ?? 1;
169
210
  if (planarConfiguration !== 1 && planarConfiguration !== 2) {
@@ -192,29 +233,28 @@ class GeoTIFFImage {
192
233
  * @returns {Number} the width of the image
193
234
  */
194
235
  getWidth() {
195
- return this.fileDirectory.getValue('ImageWidth');
236
+ return this.fileDirectory.getValue('ImageWidth') || 0;
196
237
  }
197
238
  /**
198
239
  * Returns the height of the image.
199
240
  * @returns {Number} the height of the image
200
241
  */
201
242
  getHeight() {
202
- return this.fileDirectory.getValue('ImageLength');
243
+ return this.fileDirectory.getValue('ImageLength') || 0;
203
244
  }
204
245
  /**
205
246
  * Returns the number of samples per pixel.
206
247
  * @returns {Number} the number of samples per pixel
207
248
  */
208
249
  getSamplesPerPixel() {
209
- return this.fileDirectory.hasTag('SamplesPerPixel')
210
- ? this.fileDirectory.getValue('SamplesPerPixel') : 1;
250
+ return this.fileDirectory.getValue('SamplesPerPixel') || 1;
211
251
  }
212
252
  /**
213
253
  * Returns the width of each tile.
214
254
  * @returns {Number} the width of each tile
215
255
  */
216
256
  getTileWidth() {
217
- return this.isTiled ? this.fileDirectory.getValue('TileWidth') : this.getWidth();
257
+ return this.isTiled ? (this.fileDirectory.getValue('TileWidth') || 0) : this.getWidth();
218
258
  }
219
259
  /**
220
260
  * Returns the height of each tile.
@@ -222,16 +262,21 @@ class GeoTIFFImage {
222
262
  */
223
263
  getTileHeight() {
224
264
  if (this.isTiled) {
225
- return this.fileDirectory.getValue('TileLength');
265
+ return this.fileDirectory.getValue('TileLength') || 0;
226
266
  }
227
- if (this.fileDirectory.hasTag('RowsPerStrip')) {
228
- return Math.min(this.fileDirectory.getValue('RowsPerStrip'), this.getHeight());
267
+ const rowsPerStrip = this.fileDirectory.getValue('RowsPerStrip');
268
+ if (rowsPerStrip) {
269
+ return Math.min(rowsPerStrip, this.getHeight());
229
270
  }
230
271
  return this.getHeight();
231
272
  }
232
273
  getBlockWidth() {
233
274
  return this.getTileWidth();
234
275
  }
276
+ /**
277
+ * @param {number} y
278
+ * @returns {number}
279
+ */
235
280
  getBlockHeight(y) {
236
281
  if (this.isTiled || (y + 1) * this.getTileHeight() <= this.getHeight()) {
237
282
  return this.getTileHeight();
@@ -248,22 +293,32 @@ class GeoTIFFImage {
248
293
  getBytesPerPixel() {
249
294
  let bytes = 0;
250
295
  // this is a short list, so we assume this is already loaded
251
- for (let i = 0; i < this.fileDirectory.getValue('BitsPerSample').length; ++i) {
296
+ const bitsPerSample = this.fileDirectory.getValue('BitsPerSample') || [];
297
+ for (let i = 0; i < bitsPerSample.length; ++i) {
252
298
  bytes += this.getSampleByteSize(i);
253
299
  }
254
300
  return bytes;
255
301
  }
302
+ /**
303
+ * @param {number} i
304
+ * @returns {number}
305
+ */
256
306
  getSampleByteSize(i) {
257
- const bitsPerSample = this.fileDirectory.getValue('BitsPerSample');
307
+ const bitsPerSample = this.fileDirectory.getValue('BitsPerSample') || [];
258
308
  if (i >= bitsPerSample.length) {
259
309
  throw new RangeError(`Sample index ${i} is out of range.`);
260
310
  }
261
311
  return Math.ceil(bitsPerSample[i] / 8);
262
312
  }
313
+ /**
314
+ * @param {number} sampleIndex
315
+ * @returns {(this: DataView, byteOffset: number, littleEndian: boolean) => number}
316
+ */
263
317
  getReaderForSample(sampleIndex) {
264
- const format = this.fileDirectory.hasTag('SampleFormat')
265
- ? this.fileDirectory.getValue('SampleFormat')[sampleIndex] : 1;
266
- const bitsPerSample = this.fileDirectory.getValue('BitsPerSample')[sampleIndex];
318
+ const sampleFormat = this.fileDirectory.getValue('SampleFormat');
319
+ const format = sampleFormat
320
+ ? sampleFormat[sampleIndex] : 1;
321
+ const bitsPerSample = (this.fileDirectory.getValue('BitsPerSample') || [])[sampleIndex];
267
322
  switch (format) {
268
323
  case 1: // unsigned integer data
269
324
  if (bitsPerSample <= 8) {
@@ -307,16 +362,22 @@ class GeoTIFFImage {
307
362
  throw Error('Unsupported data format/bitsPerSample');
308
363
  }
309
364
  getSampleFormat(sampleIndex = 0) {
310
- return this.fileDirectory.hasTag('SampleFormat')
311
- ? this.fileDirectory.getValue('SampleFormat')[sampleIndex] : 1;
365
+ const sampleFormat = this.fileDirectory.getValue('SampleFormat');
366
+ return sampleFormat ? sampleFormat[sampleIndex] : 1;
312
367
  }
313
368
  getBitsPerSample(sampleIndex = 0) {
314
- return this.fileDirectory.getValue('BitsPerSample')[sampleIndex];
369
+ const bitsPerSample = this.fileDirectory.getValue('BitsPerSample');
370
+ return bitsPerSample ? bitsPerSample[sampleIndex] : 0;
315
371
  }
316
- getArrayForSample(sampleIndex, size) {
317
- const format = this.getSampleFormat(sampleIndex);
372
+ /**
373
+ * @param {number} sampleIndex
374
+ * @param {number|ArrayBufferLike} sizeOrData
375
+ * @returns {TypedArray}
376
+ */
377
+ getArrayForSample(sampleIndex, sizeOrData) {
378
+ const format = /** @type {1|2|3} */ (this.getSampleFormat(sampleIndex));
318
379
  const bitsPerSample = this.getBitsPerSample(sampleIndex);
319
- return arrayForType(format, bitsPerSample, size);
380
+ return arrayForType(format, bitsPerSample, sizeOrData);
320
381
  }
321
382
  /**
322
383
  * Returns the decoded strip or tile.
@@ -326,7 +387,7 @@ class GeoTIFFImage {
326
387
  * @param {DecoderWorker|import("./geotiff").BaseDecoder} poolOrDecoder the decoder or decoder pool
327
388
  * @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
328
389
  * to be aborted
329
- * @returns {Promise.<{x: number, y: number, sample: number, data: ArrayBuffer}>} the decoded strip or tile
390
+ * @returns {Promise.<{x: number, y: number, sample: number, data: ArrayBufferLike}>} the decoded strip or tile
330
391
  */
331
392
  async getTileOrStrip(x, y, sample, poolOrDecoder, signal) {
332
393
  const numTilesPerRow = Math.ceil(this.getWidth() / this.getTileWidth());
@@ -345,12 +406,12 @@ class GeoTIFFImage {
345
406
  let offset;
346
407
  let byteCount;
347
408
  if (this.isTiled) {
348
- offset = await this.fileDirectory.loadValueIndexed('TileOffsets', index);
349
- byteCount = await this.fileDirectory.loadValueIndexed('TileByteCounts', index);
409
+ offset = Number(await this.fileDirectory.loadValueIndexed('TileOffsets', index));
410
+ byteCount = Number(await this.fileDirectory.loadValueIndexed('TileByteCounts', index));
350
411
  }
351
412
  else {
352
- offset = await this.fileDirectory.loadValueIndexed('StripOffsets', index);
353
- byteCount = await this.fileDirectory.loadValueIndexed('StripByteCounts', index);
413
+ offset = Number(await this.fileDirectory.loadValueIndexed('StripOffsets', index));
414
+ byteCount = Number(await this.fileDirectory.loadValueIndexed('StripByteCounts', index));
354
415
  }
355
416
  if (byteCount === 0) {
356
417
  const nPixels = this.getBlockHeight(y) * this.getTileWidth();
@@ -366,7 +427,7 @@ class GeoTIFFImage {
366
427
  // resolve each request by potentially applying array normalization
367
428
  request = (async () => {
368
429
  let data = await poolOrDecoder.decode(slice);
369
- const sampleFormat = this.getSampleFormat();
430
+ const sampleFormat = /** @type {1|2|3} */ (this.getSampleFormat());
370
431
  const bitsPerSample = this.getBitsPerSample();
371
432
  if (needsNormalization(sampleFormat, bitsPerSample)) {
372
433
  data = normalizeArray(data, sampleFormat, this.planarConfiguration, this.getSamplesPerPixel(), bitsPerSample, this.getTileWidth(), this.getBlockHeight(y));
@@ -388,8 +449,8 @@ class GeoTIFFImage {
388
449
  /**
389
450
  * Internal read function.
390
451
  * @private
391
- * @param {Array} imageWindow The image window in pixel coordinates
392
- * @param {Array} samples The selected samples (0-based indices)
452
+ * @param {Array<number>} imageWindow The image window in pixel coordinates
453
+ * @param {Array<number>} samples The selected samples (0-based indices)
393
454
  * @param {TypedArray|TypedArray[]} valueArrays The array(s) to write into
394
455
  * @param {boolean|undefined} interleave Whether or not to write in an interleaved manner
395
456
  * @param {DecoderWorker|import("./geotiff").BaseDecoder} poolOrDecoder the decoder or decoder pool
@@ -411,11 +472,17 @@ class GeoTIFFImage {
411
472
  const maxYTile = Math.min(Math.ceil(imageWindow[3] / tileHeight), Math.ceil(imageHeight / tileHeight));
412
473
  const windowWidth = imageWindow[2] - imageWindow[0];
413
474
  let bytesPerPixel = this.getBytesPerPixel();
475
+ /** @type {Array<number>} */
414
476
  const srcSampleOffsets = [];
477
+ /** @type {Array<(this: DataView, byteOffset: number, littleEndian: boolean) => number>} */
415
478
  const sampleReaders = [];
416
479
  for (let i = 0; i < samples.length; ++i) {
417
480
  if (this.planarConfiguration === 1) {
418
- srcSampleOffsets.push(sum(await this.fileDirectory.loadValue('BitsPerSample'), 0, samples[i]) / 8);
481
+ const bitsPerSample = await this.fileDirectory.loadValue('BitsPerSample');
482
+ if (typeof bitsPerSample !== 'object') {
483
+ throw new Error('Expected BitsPerSample to be an array or typed array.');
484
+ }
485
+ srcSampleOffsets.push(sum(bitsPerSample, 0, samples[i]) / 8);
419
486
  }
420
487
  else {
421
488
  srcSampleOffsets.push(0);
@@ -464,7 +531,7 @@ class GeoTIFFImage {
464
531
  }
465
532
  else {
466
533
  windowCoordinate = ((y + firstLine - imageWindow[1]) * windowWidth) + x + firstCol - imageWindow[0];
467
- valueArrays[si][windowCoordinate] = value;
534
+ /** @type {TypedArray} */ (valueArrays[si])[windowCoordinate] = value;
468
535
  }
469
536
  }
470
537
  }
@@ -553,9 +620,14 @@ class GeoTIFFImage {
553
620
  /** @type {TypedArray|TypedArray[]} */
554
621
  let valueArrays;
555
622
  if (interleave) {
556
- const format = this.fileDirectory.hasTag('SampleFormat')
557
- ? Math.max.apply(null, this.fileDirectory.getValue('SampleFormat')) : 1;
558
- const bitsPerSample = Math.max.apply(null, this.fileDirectory.getValue('BitsPerSample'));
623
+ const { fileDirectory } = this;
624
+ const format = fileDirectory.hasTag('SampleFormat')
625
+ ? Math.max.apply(null, Array.from(fileDirectory.getValue('SampleFormat'))) : 1;
626
+ if (format !== 1 && format !== 2 && format !== 3) {
627
+ throw new Error('Unsupported sample format for interleaved data. Must be 1, 2, or 3.');
628
+ }
629
+ const bitsPerSample = fileDirectory.hasTag('BitsPerSample')
630
+ ? Math.max.apply(null, Array.from(fileDirectory.getValue('BitsPerSample'))) : 8;
559
631
  valueArrays = arrayForType(format, bitsPerSample, numPixels * samples.length);
560
632
  if (fillValue) {
561
633
  if (Array.isArray(fillValue)) {
@@ -626,9 +698,11 @@ class GeoTIFFImage {
626
698
  const pi = this.fileDirectory.getValue('PhotometricInterpretation');
627
699
  if (pi === globals_js_1.photometricInterpretations.RGB) {
628
700
  let s = [0, 1, 2];
629
- if ((!(this.fileDirectory.getValue('ExtraSamples') === globals_js_1.ExtraSamplesValues.Unspecified)) && enableAlpha) {
701
+ const extraSamples = this.fileDirectory.getValue('ExtraSamples');
702
+ if (extraSamples && extraSamples[0] !== globals_js_1.ExtraSamplesValues.Unspecified && enableAlpha) {
630
703
  s = [];
631
- for (let i = 0; i < this.fileDirectory.getValue('BitsPerSample').length; i += 1) {
704
+ const bitsPerSample = this.fileDirectory.getValue('BitsPerSample') || [];
705
+ for (let i = 0; i < bitsPerSample.length; i += 1) {
632
706
  s.push(i);
633
707
  }
634
708
  }
@@ -683,7 +757,7 @@ class GeoTIFFImage {
683
757
  data = (0, rgb_js_1.fromBlackIsZero)(raster, max);
684
758
  break;
685
759
  case globals_js_1.photometricInterpretations.Palette:
686
- data = (0, rgb_js_1.fromPalette)(raster, await fileDirectory.loadValue('ColorMap'));
760
+ data = (0, rgb_js_1.fromPalette)(raster, /** @type {Uint16Array} */ (await fileDirectory.loadValue('ColorMap')));
687
761
  break;
688
762
  case globals_js_1.photometricInterpretations.CMYK:
689
763
  data = (0, rgb_js_1.fromCMYK)(raster);
@@ -717,13 +791,16 @@ class GeoTIFFImage {
717
791
  }
718
792
  /**
719
793
  * Returns an array of tiepoints.
720
- * @returns {Promise<Object[]>}
794
+ * @returns {Promise<Array<{i: number, j: number, k: number, x: number, y: number, z: number}>>} the tiepoints
721
795
  */
722
796
  async getTiePoints() {
723
797
  if (!this.fileDirectory.hasTag('ModelTiepoint')) {
724
798
  return [];
725
799
  }
726
800
  const modelTiePoint = await this.fileDirectory.loadValue('ModelTiepoint');
801
+ if (typeof modelTiePoint !== 'object') {
802
+ throw new Error('Expected ModelTiepoint to be an array or typed array.');
803
+ }
727
804
  const tiePoints = [];
728
805
  for (let i = 0; i < modelTiePoint.length; i += 6) {
729
806
  tiePoints.push({
@@ -744,14 +821,16 @@ class GeoTIFFImage {
744
821
  * Otherwise only metadata specific to the provided sample will be returned.
745
822
  *
746
823
  * @param {number|null} [sample=null] The sample index.
747
- * @returns {Promise<Object>}
824
+ * @returns {Promise<Record<string, unknown>|null>} The GDAL metadata items
748
825
  */
749
826
  async getGDALMetadata(sample = null) {
827
+ /** @type {Record<string, unknown>} */
750
828
  const metadata = {};
751
829
  if (!this.fileDirectory.hasTag('GDAL_METADATA')) {
752
830
  return null;
753
831
  }
754
832
  const string = await this.fileDirectory.loadValue('GDAL_METADATA');
833
+ /** @type {Array<{inner: unknown}>} */
755
834
  let items = (0, find_tags_by_name_1.default)(string, 'Item');
756
835
  if (sample === null) {
757
836
  items = items.filter((item) => (0, get_attribute_1.default)(item, 'sample') === undefined);
@@ -770,10 +849,10 @@ class GeoTIFFImage {
770
849
  * @returns {number|null}
771
850
  */
772
851
  getGDALNoData() {
773
- if (!this.fileDirectory.hasTag('GDAL_NODATA')) {
852
+ const string = this.fileDirectory.getValue('GDAL_NODATA');
853
+ if (!string) {
774
854
  return null;
775
855
  }
776
- const string = this.fileDirectory.getValue('GDAL_NODATA');
777
856
  return Number(string.substring(0, string.length - 1));
778
857
  }
779
858
  /**
@@ -862,9 +941,9 @@ class GeoTIFFImage {
862
941
  getBoundingBox(tilegrid = false) {
863
942
  const height = this.getHeight();
864
943
  const width = this.getWidth();
865
- if (this.fileDirectory.hasTag('ModelTransformation') && !tilegrid) {
866
- // eslint-disable-next-line no-unused-vars
867
- const [a, b, c, d, e, f, g, h] = this.fileDirectory.getValue('ModelTransformation');
944
+ const modelTransformation = this.fileDirectory.getValue('ModelTransformation');
945
+ if (modelTransformation && !tilegrid) {
946
+ const [a, b, , d, e, f, , h] = modelTransformation;
868
947
  const corners = [
869
948
  [0, 0],
870
949
  [0, height],
@@ -901,4 +980,5 @@ class GeoTIFFImage {
901
980
  }
902
981
  }
903
982
  exports.default = GeoTIFFImage;
983
+ //# sourceMappingURL=geotiffimage.js.map
904
984
  //# sourceMappingURL=geotiffimage.js.map