@thi.ng/pixel-io-geotiff 0.1.147 → 0.2.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.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 211 standalone projects, maintained as part
10
+ > This is one of 213 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
@@ -66,11 +66,12 @@ For Node.js REPL:
66
66
  const geo = await import("@thi.ng/pixel-io-geotiff");
67
67
  ```
68
68
 
69
- Package sizes (brotli'd, pre-treeshake): ESM: 399 bytes
69
+ Package sizes (brotli'd, pre-treeshake): ESM: 474 bytes
70
70
 
71
71
  ## Dependencies
72
72
 
73
73
  - [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)
74
+ - [@thi.ng/math](https://github.com/thi-ng/umbrella/tree/develop/packages/math)
74
75
  - [@thi.ng/pixel](https://github.com/thi-ng/umbrella/tree/develop/packages/pixel)
75
76
  - [geotiff](https://github.com/geotiffjs/geotiff.js)
76
77
 
@@ -126,4 +127,4 @@ If this project contributes to an academic publication, please cite it as:
126
127
 
127
128
  ## License
128
129
 
129
- © 2023 - 2025 Karsten Schmidt // Apache License 2.0
130
+ © 2023 - 2026 Karsten Schmidt // Apache License 2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/pixel-io-geotiff",
3
- "version": "0.1.147",
3
+ "version": "0.2.0",
4
4
  "description": "GeoTIFF reader support for @thi.ng/pixel",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -39,8 +39,9 @@
39
39
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@thi.ng/api": "^8.12.10",
43
- "@thi.ng/pixel": "^7.5.19",
42
+ "@thi.ng/api": "^8.12.12",
43
+ "@thi.ng/math": "^5.15.1",
44
+ "@thi.ng/pixel": "^7.5.21",
44
45
  "geotiff": "2.1.4-beta.1"
45
46
  },
46
47
  "devDependencies": {
@@ -90,5 +91,5 @@
90
91
  "year": 2023,
91
92
  "screenshot": "pixel-io-geotiff/20230109-n45w121-crop-1280.jpg"
92
93
  },
93
- "gitHead": "824bf9047b5a10f777c5c5b4aeecf0c750a22c75\n"
94
+ "gitHead": "deb511294f7a120091b654af0ff7e8a399a465b3\n"
94
95
  }
package/read.d.ts CHANGED
@@ -8,10 +8,16 @@ export interface GeoTiffOpts {
8
8
  */
9
9
  channel: number;
10
10
  /**
11
- * Min/max elevation range to configure image pixel format. If omitted, the
12
- * range will be auto-computed.
11
+ * `[min,max]` elevation range to configure image pixel format. If omitted,
12
+ * the range will be auto-computed. Also see {@link GeoTiffOpts.clamp}.
13
13
  */
14
14
  range: [number, number];
15
+ /**
16
+ * If given, elevations will be pre-clamped to given `[min,max]` range, and
17
+ * {@link GeoTiffOpts.range} will be auto-computed (if enabled) using these
18
+ * clamped values.
19
+ */
20
+ clamp: [number, number];
15
21
  /**
16
22
  * Optionally enable geotiff.js worker pool to speed up processing. Disabled
17
23
  * by default.
package/read.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { typedArrayType } from "@thi.ng/api";
2
+ import { clamp } from "@thi.ng/math/interval";
2
3
  import { FLOAT_GRAY_RANGE, floatBuffer } from "@thi.ng/pixel";
3
4
  import { Pool, fromArrayBuffer } from "geotiff";
4
5
  const readGeoTiff = async (src, opts = {}) => {
@@ -6,8 +7,13 @@ const readGeoTiff = async (src, opts = {}) => {
6
7
  const tiffImg = await tiff.getImage();
7
8
  const width = tiffImg.getWidth();
8
9
  const height = tiffImg.getHeight();
9
- const pool = opts.pool instanceof Pool ? opts.pool : opts.pool ? new Pool() : void 0;
10
+ const pool = opts.pool instanceof Pool ? opts.pool : opts.pool ? new Pool(typeof opts.pool === "number" ? opts.pool : void 0) : void 0;
10
11
  const data = (await tiffImg.readRasters({ pool, samples: [opts.channel || 0] }))[0];
12
+ if (opts.clamp) {
13
+ const [min2, max2] = opts.clamp;
14
+ for (let i = 0, n = data.length; i < n; i++)
15
+ data[i] = clamp(data[i], min2, max2);
16
+ }
11
17
  const type = typedArrayType(data);
12
18
  const [min, max] = opts.range ? opts.range : data.reduce(
13
19
  (acc, x) => {