geotiff 3.0.4-beta.2 → 3.0.4

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 (43) hide show
  1. package/dist-browser/geotiff.js +1 -1
  2. package/dist-browser/geotiff.js.map +1 -1
  3. package/dist-module/geotiffimage.js +3 -3
  4. package/dist-module/geotiffimage.js.map +1 -1
  5. package/dist-module/globals.d.ts +60 -19
  6. package/dist-module/globals.d.ts.map +1 -1
  7. package/dist-module/globals.js +22 -13
  8. package/dist-module/globals.js.map +1 -1
  9. package/dist-module/imagefiledirectory.d.ts +4 -4
  10. package/dist-module/imagefiledirectory.d.ts.map +1 -1
  11. package/dist-module/imagefiledirectory.js +4 -4
  12. package/dist-module/imagefiledirectory.js.map +1 -1
  13. package/dist-module/pool.d.ts +1 -0
  14. package/dist-module/pool.d.ts.map +1 -1
  15. package/dist-module/pool.js +8 -2
  16. package/dist-module/pool.js.map +1 -1
  17. package/dist-module/worker/create.js +1 -1
  18. package/dist-module/worker/decoder.js +2 -2
  19. package/dist-module/worker/decoder.js.map +1 -1
  20. package/dist-node/geotiffimage.js +3 -3
  21. package/dist-node/geotiffimage.js.map +1 -1
  22. package/dist-node/globals.d.ts +60 -19
  23. package/dist-node/globals.d.ts.map +1 -1
  24. package/dist-node/globals.js +22 -13
  25. package/dist-node/globals.js.map +1 -1
  26. package/dist-node/imagefiledirectory.d.ts +4 -4
  27. package/dist-node/imagefiledirectory.d.ts.map +1 -1
  28. package/dist-node/imagefiledirectory.js +4 -4
  29. package/dist-node/imagefiledirectory.js.map +1 -1
  30. package/dist-node/pool.d.ts +1 -0
  31. package/dist-node/pool.d.ts.map +1 -1
  32. package/dist-node/pool.js +8 -2
  33. package/dist-node/pool.js.map +1 -1
  34. package/dist-node/worker/create.js +1 -1
  35. package/dist-node/worker/create.js.map +1 -1
  36. package/dist-node/worker/decoder.js +2 -2
  37. package/dist-node/worker/decoder.js.map +1 -1
  38. package/package.json +1 -1
  39. package/src/geotiffimage.js +3 -3
  40. package/src/globals.js +22 -13
  41. package/src/imagefiledirectory.js +4 -4
  42. package/src/pool.js +7 -2
  43. package/src/worker/decoder.js +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../../dist-module/worker/create.js"],"names":[],"mappings":";;;;;AAEA,yBAKC;AAPD,4DAAgC;AAEhC,SAAwB,MAAM;IAC5B,MAAM,MAAM,GAAG,k7/OAAk7/O,CAAC;IACl8/O,OAAO,IAAI,oBAAM,CAAC,OAAO,MAAM,KAAK,WAAW;QAC7C,CAAC,CAAC,qCAAqC,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC1F,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,wBAAwB,EAAE,CAAC,CAAC,CAAC,CAAC;AACnF,CAAC"}
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../../dist-module/worker/create.js"],"names":[],"mappings":";;;;;AAEA,yBAKC;AAPD,4DAAgC;AAEhC,SAAwB,MAAM;IAC5B,MAAM,MAAM,GAAG,4hgPAA4hgP,CAAC;IAC5igP,OAAO,IAAI,oBAAM,CAAC,OAAO,MAAM,KAAK,WAAW;QAC7C,CAAC,CAAC,qCAAqC,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC1F,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,wBAAwB,EAAE,CAAC,CAAC,CAAC,CAAC;AACnF,CAAC"}
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  /* global globalThis */
4
4
  /* eslint-disable import/no-mutable-exports */
5
5
  const index_js_1 = require("../compression/index.js");
6
- const worker = globalThis;
6
+ const worker = /** @type {Worker} */ ( /** @type {unknown} */(globalThis));
7
7
  worker.addEventListener('message', async (e) => {
8
8
  const { compression, decoderParameters, buffer, ...extra } = e.data;
9
9
  try {
10
10
  const decoder = await (0, index_js_1.getDecoder)(compression, decoderParameters);
11
11
  const decoded = await decoder.decode(buffer);
12
- worker.postMessage({ decoded, ...extra }, { transfer: [decoded] });
12
+ worker.postMessage({ decoded, ...extra }, [decoded]);
13
13
  }
14
14
  catch (error) {
15
15
  if (error instanceof Error) {
@@ -1 +1 @@
1
- {"version":3,"file":"decoder.js","sourceRoot":"","sources":["../../dist-module/worker/decoder.js"],"names":[],"mappings":";;AAAA,uBAAuB;AACvB,8CAA8C;AAC9C,sDAAqD;AACrD,MAAM,MAAM,GAAG,UAAU,CAAC;AAC1B,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAC3C,MAAM,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC;IACpE,IAAI,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,IAAA,qBAAU,EAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;QACjE,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7C,MAAM,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,KAAK,EAAE,CAAC;QACX,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YACzB,MAAM,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;QAC3D,CAAC;aACI,CAAC;YACF,MAAM,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;QAC3D,CAAC;IACL,CAAC;AACL,CAAC,CAAC,CAAC;AACH,mCAAmC"}
1
+ {"version":3,"file":"decoder.js","sourceRoot":"","sources":["../../dist-module/worker/decoder.js"],"names":[],"mappings":";;AAAA,uBAAuB;AACvB,8CAA8C;AAC9C,sDAAqD;AACrD,MAAM,MAAM,GAAG,qBAAqB,CAAC,EAAE,sBAAsB,CAAC,UAAU,CAAC,CAAC,CAAC;AAC3E,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAC3C,MAAM,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC;IACpE,IAAI,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,IAAA,qBAAU,EAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;QACjE,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7C,MAAM,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,KAAK,EAAE,CAAC;QACX,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YACzB,MAAM,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;QAC3D,CAAC;aACI,CAAC;YACF,MAAM,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;QAC3D,CAAC;IACL,CAAC;AACL,CAAC,CAAC,CAAC;AACH,mCAAmC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geotiff",
3
- "version": "3.0.4-beta.2",
3
+ "version": "3.0.4",
4
4
  "description": "GeoTIFF image decoding in JavaScript",
5
5
  "repository": {
6
6
  "type": "git",
@@ -253,7 +253,7 @@ class GeoTIFFImage {
253
253
  * @returns {Number} the number of samples per pixel
254
254
  */
255
255
  getSamplesPerPixel() {
256
- return this.fileDirectory.getValue('SamplesPerPixel') || 1;
256
+ return this.fileDirectory.hasTag('SamplesPerPixel') ? this.fileDirectory.getValue('SamplesPerPixel') : 1;
257
257
  }
258
258
 
259
259
  /**
@@ -272,7 +272,7 @@ class GeoTIFFImage {
272
272
  if (this.isTiled) {
273
273
  return this.fileDirectory.getValue('TileLength') || 0;
274
274
  }
275
- const rowsPerStrip = this.fileDirectory.getValue('RowsPerStrip');
275
+ const rowsPerStrip = this.fileDirectory.hasTag('RowsPerStrip') && this.fileDirectory.getValue('RowsPerStrip');
276
276
  if (rowsPerStrip) {
277
277
  return Math.min(rowsPerStrip, this.getHeight());
278
278
  }
@@ -936,7 +936,7 @@ class GeoTIFFImage {
936
936
  * @returns {number|null}
937
937
  */
938
938
  getGDALNoData() {
939
- const string = this.fileDirectory.getValue('GDAL_NODATA');
939
+ const string = this.fileDirectory.hasTag('GDAL_NODATA') && this.fileDirectory.getValue('GDAL_NODATA');
940
940
  if (!string) {
941
941
  return null;
942
942
  }
package/src/globals.js CHANGED
@@ -71,13 +71,13 @@ export function getFieldTypeSize(fieldType) {
71
71
  */
72
72
 
73
73
  export const tagDictionary = /** @type {const} */ ({
74
- NewSubfileType: { tag: 254, type: fieldTypes.LONG },
75
- SubfileType: { tag: 255, type: fieldTypes.SHORT },
76
- ImageWidth: { tag: 256, type: fieldTypes.SHORT },
77
- ImageLength: { tag: 257, type: fieldTypes.SHORT },
74
+ NewSubfileType: { tag: 254, type: fieldTypes.LONG, eager: true },
75
+ SubfileType: { tag: 255, type: fieldTypes.SHORT, eager: true },
76
+ ImageWidth: { tag: 256, type: fieldTypes.SHORT, eager: true },
77
+ ImageLength: { tag: 257, type: fieldTypes.SHORT, eager: true },
78
78
  BitsPerSample: { tag: 258, type: fieldTypes.SHORT, isArray: true, eager: true },
79
- Compression: { tag: 259, type: fieldTypes.SHORT },
80
- PhotometricInterpretation: { tag: 262, type: fieldTypes.SHORT },
79
+ Compression: { tag: 259, type: fieldTypes.SHORT, eager: true },
80
+ PhotometricInterpretation: { tag: 262, type: fieldTypes.SHORT, eager: true },
81
81
  Threshholding: { tag: 263, type: fieldTypes.SHORT },
82
82
  CellWidth: { tag: 264, type: fieldTypes.SHORT },
83
83
  CellLength: { tag: 265, type: fieldTypes.SHORT },
@@ -88,14 +88,14 @@ export const tagDictionary = /** @type {const} */ ({
88
88
  Model: { tag: 272, type: fieldTypes.ASCII },
89
89
  StripOffsets: { tag: 273, type: fieldTypes.SHORT, isArray: true },
90
90
  Orientation: { tag: 274, type: fieldTypes.SHORT },
91
- SamplesPerPixel: { tag: 277, type: fieldTypes.SHORT },
92
- RowsPerStrip: { tag: 278, type: fieldTypes.SHORT },
91
+ SamplesPerPixel: { tag: 277, type: fieldTypes.SHORT, eager: true },
92
+ RowsPerStrip: { tag: 278, type: fieldTypes.SHORT, eager: true },
93
93
  StripByteCounts: { tag: 279, type: fieldTypes.LONG, isArray: true },
94
94
  MinSampleValue: { tag: 280, type: fieldTypes.SHORT, isArray: true },
95
95
  MaxSampleValue: { tag: 281, type: fieldTypes.SHORT, isArray: true },
96
96
  XResolution: { tag: 282, type: fieldTypes.RATIONAL },
97
97
  YResolution: { tag: 283, type: fieldTypes.RATIONAL },
98
- PlanarConfiguration: { tag: 284, type: fieldTypes.SHORT },
98
+ PlanarConfiguration: { tag: 284, type: fieldTypes.SHORT, eager: true },
99
99
  PageName: { tag: 285, type: fieldTypes.ASCII },
100
100
  XPosition: { tag: 286, type: fieldTypes.RATIONAL },
101
101
  YPosition: { tag: 287, type: fieldTypes.RATIONAL },
@@ -117,8 +117,8 @@ export const tagDictionary = /** @type {const} */ ({
117
117
  PrimaryChromaticities: { tag: 319, type: fieldTypes.RATIONAL, isArray: true },
118
118
  ColorMap: { tag: 320, type: fieldTypes.SHORT, isArray: true },
119
119
  HalftoneHints: { tag: 321, type: fieldTypes.SHORT, isArray: true },
120
- TileWidth: { tag: 322, type: fieldTypes.SHORT },
121
- TileLength: { tag: 323, type: fieldTypes.SHORT },
120
+ TileWidth: { tag: 322, type: fieldTypes.SHORT, eager: true },
121
+ TileLength: { tag: 323, type: fieldTypes.SHORT, eager: true },
122
122
  TileOffsets: { tag: 324, type: fieldTypes.LONG, isArray: true },
123
123
  TileByteCounts: { tag: 325, type: fieldTypes.SHORT, isArray: true },
124
124
  InkSet: { tag: 332, type: fieldTypes.SHORT },
@@ -126,7 +126,7 @@ export const tagDictionary = /** @type {const} */ ({
126
126
  NumberOfInks: { tag: 334, type: fieldTypes.SHORT },
127
127
  DotRange: { tag: 336, type: fieldTypes.BYTE, isArray: true },
128
128
  TargetPrinter: { tag: 337, type: fieldTypes.ASCII },
129
- ExtraSamples: { tag: 338, type: fieldTypes.BYTE, isArray: true },
129
+ ExtraSamples: { tag: 338, type: fieldTypes.BYTE, isArray: true, eager: true },
130
130
  SampleFormat: { tag: 339, type: fieldTypes.SHORT, isArray: true, eager: true },
131
131
  SMinSampleValue: { tag: 340, isArray: true },
132
132
  SMaxSampleValue: { tag: 341, isArray: true },
@@ -178,7 +178,7 @@ export const tagDictionary = /** @type {const} */ ({
178
178
  ICCProfile: { tag: 34675, name: 'ICC Profile' },
179
179
  XMP: { tag: 700 },
180
180
  GDAL_METADATA: { tag: 42112 },
181
- GDAL_NODATA: { tag: 42113, type: fieldTypes.ASCII },
181
+ GDAL_NODATA: { tag: 42113, type: fieldTypes.ASCII, eager: true },
182
182
  Photoshop: { tag: 34377 },
183
183
  ModelPixelScale: { tag: 33550, type: fieldTypes.DOUBLE, isArray: true, eager: true },
184
184
  ModelTiepoint: { tag: 33922, type: fieldTypes.DOUBLE, isArray: true, eager: true },
@@ -191,6 +191,15 @@ export const tagDictionary = /** @type {const} */ ({
191
191
 
192
192
  /** @typedef {keyof typeof tagDictionary} TagName */
193
193
  /** @typedef {typeof tagDictionary[keyof typeof tagDictionary]['tag']} Tag */
194
+ /**
195
+ * @typedef {Extract<keyof typeof tagDictionary,
196
+ * { [K in keyof typeof tagDictionary]: (typeof tagDictionary)[K] extends { eager: true }
197
+ * ? K : never }[keyof typeof tagDictionary]>} EagerTagName
198
+ */
199
+ /**
200
+ * @typedef {Extract<Tag, { [K in keyof typeof tagDictionary]: (typeof tagDictionary)[K] extends { eager: true }
201
+ * ? (typeof tagDictionary)[K]['tag'] : never }[keyof typeof tagDictionary]>} EagerTag
202
+ */
194
203
  /** @typedef {Extract<typeof tagDictionary[keyof typeof tagDictionary], {type: any}>['type']} TagType */
195
204
 
196
205
  /**
@@ -306,9 +306,9 @@ export class ImageFileDirectory {
306
306
 
307
307
  /**
308
308
  * Synchronously retrieves the value for a given tag. If it is deferred, an error is thrown.
309
- * @template {import('./globals.js').TagName} [T=any]
310
- * @param {T|number} tagIdentifier The field tag ID or name
311
- * @returns {T extends import('./globals.js').TagName ? (import('./globals.js').TagValue<T> | undefined) : unknown}
309
+ * @template {import('./globals.js').EagerTagName | import('./globals.js').EagerTag} [T=any]
310
+ * @param {T} tagIdentifier The field tag ID or name
311
+ * @returns {T extends import('./globals.js').TagName ? (import('./globals.js').TagValue<T> | undefined) : any}
312
312
  * the field value,
313
313
  * or undefined if it does not exist
314
314
  * @throws {Error} If the tag is deferred and requires asynchronous loading
@@ -414,7 +414,7 @@ export class ImageFileDirectory {
414
414
  const geoKeyDirectory = {};
415
415
  for (let i = 4; i <= rawGeoKeyDirectory[3] * 4; i += 4) {
416
416
  const key = (/** @type {Record<number, import('./globals.js').GeoKeyName>} */ (geoKeyNames))[rawGeoKeyDirectory[i]];
417
- const location = rawGeoKeyDirectory[i + 1] || null;
417
+ const location = /** @type {import('./globals.js').EagerTag} */ (rawGeoKeyDirectory[i + 1]) || null;
418
418
  const count = rawGeoKeyDirectory[i + 2];
419
419
  const offset = rawGeoKeyDirectory[i + 3];
420
420
 
package/src/pool.js CHANGED
@@ -15,6 +15,7 @@ class WorkerWrapper {
15
15
  * @param {Worker} worker the worker to wrap
16
16
  */
17
17
  constructor(worker) {
18
+ /** @type {Worker} */
18
19
  this.worker = worker;
19
20
  this.worker.addEventListener('message', (e) => this._onWorkerMessage(e));
20
21
  this.jobIdCounter = 0;
@@ -57,7 +58,7 @@ class WorkerWrapper {
57
58
  * @returns {Promise<{decoded: ArrayBuffer}>} a promise that gets resolved/rejected when a message with the same jobId is
58
59
  * received from the worker.
59
60
  */
60
- submitJob(message, transferables = undefined) {
61
+ submitJob(message, transferables) {
61
62
  const jobId = this.newJobId();
62
63
  let resolve;
63
64
  let reject;
@@ -68,7 +69,11 @@ class WorkerWrapper {
68
69
  });
69
70
 
70
71
  this.jobs.set(jobId, { resolve, reject });
71
- this.worker.postMessage({ ...message, jobId }, { transfer: transferables });
72
+ if (transferables) {
73
+ this.worker.postMessage({ ...message, jobId }, transferables);
74
+ } else {
75
+ this.worker.postMessage({ ...message, jobId });
76
+ }
72
77
  return promise;
73
78
  }
74
79
 
@@ -2,14 +2,14 @@
2
2
  /* eslint-disable import/no-mutable-exports */
3
3
  import { getDecoder } from '../compression/index.js';
4
4
 
5
- const worker = globalThis;
5
+ const worker = /** @type {Worker} */ (/** @type {unknown} */ (globalThis));
6
6
 
7
7
  worker.addEventListener('message', async (e) => {
8
8
  const { compression, decoderParameters, buffer, ...extra } = e.data;
9
9
  try {
10
10
  const decoder = await getDecoder(compression, decoderParameters);
11
11
  const decoded = await decoder.decode(buffer);
12
- worker.postMessage({ decoded, ...extra }, { transfer: [decoded] });
12
+ worker.postMessage({ decoded, ...extra }, [decoded]);
13
13
  } catch (error) {
14
14
  if (error instanceof Error) {
15
15
  worker.postMessage({ error: error.message, ...extra });