@thi.ng/pixel-io-geotiff 0.1.49 → 0.1.51

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 (3) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/package.json +8 -6
  3. package/read.js +38 -38
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-12-03T12:13:31Z
3
+ - **Last updated**: 2023-12-11T10:07:09Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/pixel-io-geotiff",
3
- "version": "0.1.49",
3
+ "version": "0.1.51",
4
4
  "description": "GeoTIFF reader support for @thi.ng/pixel",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -24,7 +24,9 @@
24
24
  "author": "Karsten Schmidt (https://thi.ng)",
25
25
  "license": "Apache-2.0",
26
26
  "scripts": {
27
- "build": "yarn clean && tsc --declaration",
27
+ "build": "yarn build:esbuild && yarn build:decl",
28
+ "build:decl": "tsc --declaration --emitDeclarationOnly",
29
+ "build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
28
30
  "clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
29
31
  "doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
30
32
  "doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
@@ -33,13 +35,13 @@
33
35
  "test": "bun test"
34
36
  },
35
37
  "dependencies": {
36
- "@thi.ng/api": "^8.9.10",
37
- "@thi.ng/pixel": "^5.0.2",
38
+ "@thi.ng/api": "^8.9.12",
39
+ "@thi.ng/pixel": "^5.0.4",
38
40
  "geotiff": "2.0.7"
39
41
  },
40
42
  "devDependencies": {
41
43
  "@microsoft/api-extractor": "^7.38.3",
42
- "@thi.ng/testament": "^0.4.3",
44
+ "esbuild": "^0.19.8",
43
45
  "rimraf": "^5.0.5",
44
46
  "tools": "^0.0.1",
45
47
  "typedoc": "^0.25.4",
@@ -85,5 +87,5 @@
85
87
  "status": "alpha",
86
88
  "year": 2023
87
89
  },
88
- "gitHead": "04d1de79f256d7a53c6b5fd157b37f49bc88e11d\n"
90
+ "gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
89
91
  }
package/read.js CHANGED
@@ -1,42 +1,42 @@
1
1
  import { typedArrayType } from "@thi.ng/api";
2
2
  import { FLOAT_GRAY_RANGE, floatBuffer } from "@thi.ng/pixel";
3
3
  import { Pool, fromArrayBuffer } from "geotiff";
4
- export const readGeoTiff = async (src, opts = {}) => {
5
- const tiff = await fromArrayBuffer(src.buffer);
6
- const tiffImg = await tiff.getImage();
7
- const width = tiffImg.getWidth();
8
- const height = tiffImg.getHeight();
9
- const pool = opts.pool instanceof Pool
10
- ? opts.pool
11
- : opts.pool
12
- ? new Pool()
13
- : undefined;
14
- const data = ((await tiffImg.readRasters({ pool, samples: [opts.channel || 0] }))[0]);
15
- const type = typedArrayType(data);
16
- const [min, max] = opts.range
17
- ? opts.range
18
- : data.reduce((acc, x) => {
19
- acc[0] = Math.min(acc[0], x);
20
- acc[1] = Math.max(acc[1], x);
21
- return acc;
22
- }, [Infinity, -Infinity]);
23
- const fmt = FLOAT_GRAY_RANGE(min, max);
24
- let img;
25
- switch (type) {
26
- case "i8":
27
- case "u8":
28
- case "i16":
29
- case "u16":
30
- case "i32":
31
- case "u32":
32
- img = floatBuffer(width, height, fmt, new Float32Array(data));
33
- break;
34
- case "f32":
35
- img = floatBuffer(width, height, fmt, data);
36
- break;
37
- case "f64":
38
- img = floatBuffer(width, height, fmt, new Float32Array(data));
39
- break;
40
- }
41
- return { img: img, tiff: tiffImg };
4
+ const readGeoTiff = async (src, opts = {}) => {
5
+ const tiff = await fromArrayBuffer(src.buffer);
6
+ const tiffImg = await tiff.getImage();
7
+ const width = tiffImg.getWidth();
8
+ const height = tiffImg.getHeight();
9
+ const pool = opts.pool instanceof Pool ? opts.pool : opts.pool ? new Pool() : void 0;
10
+ const data = (await tiffImg.readRasters({ pool, samples: [opts.channel || 0] }))[0];
11
+ const type = typedArrayType(data);
12
+ const [min, max] = opts.range ? opts.range : data.reduce(
13
+ (acc, x) => {
14
+ acc[0] = Math.min(acc[0], x);
15
+ acc[1] = Math.max(acc[1], x);
16
+ return acc;
17
+ },
18
+ [Infinity, -Infinity]
19
+ );
20
+ const fmt = FLOAT_GRAY_RANGE(min, max);
21
+ let img;
22
+ switch (type) {
23
+ case "i8":
24
+ case "u8":
25
+ case "i16":
26
+ case "u16":
27
+ case "i32":
28
+ case "u32":
29
+ img = floatBuffer(width, height, fmt, new Float32Array(data));
30
+ break;
31
+ case "f32":
32
+ img = floatBuffer(width, height, fmt, data);
33
+ break;
34
+ case "f64":
35
+ img = floatBuffer(width, height, fmt, new Float32Array(data));
36
+ break;
37
+ }
38
+ return { img, tiff: tiffImg };
39
+ };
40
+ export {
41
+ readGeoTiff
42
42
  };