geolibre-wasm 1.8.2 → 1.8.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.
package/README.md CHANGED
@@ -169,9 +169,13 @@ user-defined projection strings that cannot be written as EPSG metadata, such as
169
169
  the NLCD sample, default to `bbox_crs` output so GIS viewers can place the
170
170
  result. Outputs are Deflate-compressed by default. `nodata` overrides the output
171
171
  nodata metadata and is used to fill pixels introduced during reprojection.
172
- The subset writer preserves the source sample type for supported COG types
173
- (`uint8`, `float32`, and `float64`); palette-indexed `uint8` rasters retain
174
- their source ColorMap.
172
+ The subset writer preserves the source sample type for 8-, 16-, and 32-bit
173
+ integers (signed and unsigned), `float32`, and `float64`, so 16-bit imagery such
174
+ as Landsat and Sentinel-2 stays 16-bit. If `nodata` does not fit an integer
175
+ source type (e.g. `-9999` on `uint16`), the output is widened to `float32` (or
176
+ `float64` for 32-bit integers) so the nodata value is stored as given. Any other
177
+ type is written as `float64`.
178
+ Palette-indexed `uint8` rasters retain their source ColorMap.
175
179
 
176
180
  ## API
177
181
 
@@ -454,6 +454,7 @@ Used by:
454
454
  - static_assertions 1.1.0 (https://github.com/nvzqz/static-assertions-rs) by Nikolai Vazquez
455
455
  - utf8_iter 1.0.4 (https://github.com/hsivonen/utf8_iter) by Henri Sivonen <hsivonen@hsivonen.fi>
456
456
  - zeroize 1.9.0 (https://github.com/RustCrypto/utils) by The RustCrypto Project Developers
457
+ - zeroize_derive 1.5.0 (https://github.com/RustCrypto/utils) by The RustCrypto Project Developers
457
458
 
458
459
 
459
460
  Apache License
@@ -6880,7 +6881,7 @@ Used by:
6880
6881
  - equivalent 1.0.2 (https://github.com/indexmap-rs/equivalent)
6881
6882
  - errno 0.3.14 (https://github.com/lambda-fairy/rust-errno) by Chris Wong <lambda.fairy@gmail.com>, Dan Gohman <dev@sunfishcode.online>
6882
6883
  - filetime 0.2.29 (https://github.com/alexcrichton/filetime) by Alex Crichton <alex@alexcrichton.com>
6883
- - flate2 1.1.10 (https://github.com/rust-lang/flate2-rs) by Alex Crichton <alex@alexcrichton.com>, Josh Triplett <josh@joshtriplett.org>
6884
+ - flate2 1.1.11 (https://github.com/rust-lang/flate2-rs) by Alex Crichton <alex@alexcrichton.com>, Josh Triplett <josh@joshtriplett.org>
6884
6885
  - fnv 1.0.7 (https://github.com/servo/rust-fnv) by Alex Crichton <alex@alexcrichton.com>
6885
6886
  - form_urlencoded 1.2.2 (https://github.com/servo/rust-url) by The rust-url developers
6886
6887
  - futures-cpupool 0.1.8 (https://github.com/alexcrichton/futures-rs) by Alex Crichton <alex@alexcrichton.com>
@@ -9100,6 +9101,7 @@ Used by:
9100
9101
  - wbvector 0.1.4 (https://github.com/jblindsay/whitebox_next_gen) by John Lindsay, Whitebox Geospatial Inc.
9101
9102
  - allocator-api2 0.2.21 (https://github.com/zakarumych/allocator-api2) by Zakarum <zaq.dev@icloud.com>
9102
9103
  - anyhow 1.0.102 (https://github.com/dtolnay/anyhow) by David Tolnay <dtolnay@gmail.com>
9104
+ - constant_time_eq 0.6.1 (https://codeberg.org/cesarb/constant_time_eq) by Cesar Eduardo Barros <cesarb@cesarb.eti.br>
9103
9105
  - deku 0.15.1 (https://github.com/sharksforarms/deku) by sharks <sharks@sharks>
9104
9106
  - deku_derive 0.15.1 (https://github.com/sharksforarms/deku) by sharks <sharks@sharks>
9105
9107
  - erased-serde 0.4.10 (https://github.com/dtolnay/erased-serde) by David Tolnay <dtolnay@gmail.com>
@@ -11484,7 +11486,7 @@ DEALINGS IN THE SOFTWARE.
11484
11486
  MIT License (MIT)
11485
11487
 
11486
11488
  Used by:
11487
- - bytes 1.12.1 (https://github.com/tokio-rs/bytes) by Carl Lerche <me@carllerche.com>, Sean McArthur <sean@seanmonstar.com>
11489
+ - bytes 1.12.2 (https://github.com/tokio-rs/bytes) by Carl Lerche <me@carllerche.com>, Sean McArthur <sean@seanmonstar.com>
11488
11490
 
11489
11491
  Copyright (c) 2018 Carl Lerche
11490
11492
 
@@ -12228,10 +12230,10 @@ MIT License (MIT)
12228
12230
 
12229
12231
  Used by:
12230
12232
  - freestiler-core 0.1.0 (https://github.com/walkerke/freestiler)
12231
- - geolibre-cli 1.8.2 (https://github.com/opengeos/geolibre-rust)
12232
- - geolibre-pmtiles 1.8.2 (https://github.com/opengeos/geolibre-rust)
12233
- - geolibre-tools 1.8.2 (https://github.com/opengeos/geolibre-rust)
12234
- - geolibre-wasm 1.8.2 (https://github.com/opengeos/geolibre-rust)
12233
+ - geolibre-cli 1.8.4 (https://github.com/opengeos/geolibre-rust)
12234
+ - geolibre-pmtiles 1.8.4 (https://github.com/opengeos/geolibre-rust)
12235
+ - geolibre-tools 1.8.4 (https://github.com/opengeos/geolibre-rust)
12236
+ - geolibre-wasm 1.8.4 (https://github.com/opengeos/geolibre-rust)
12235
12237
  - i_key_sort 0.10.3 (https://github.com/iShape-Rust/iKeySort) by Nail Sharipov <nailxsharipov@gmail.com>
12236
12238
  - libm 0.2.16 (https://github.com/rust-lang/compiler-builtins) by Alex Crichton <alex@alexcrichton.com>, Amanieu d'Antras <amanieu@gmail.com>, Jorge Aparicio <japaricious@gmail.com>, Trevor Gross <tg@trevorgross.com>
12237
12239
  - simd_helpers 0.1.0 (https://github.com/lu-zero/simd_helpers) by Luca Barbato <lu_zero@gentoo.org>
@@ -12474,7 +12476,7 @@ MIT License (MIT)
12474
12476
  Used by:
12475
12477
  - tracing-core 0.1.36 (https://github.com/tokio-rs/tracing) by Tokio Contributors <team@tokio.rs>
12476
12478
  - zip 8.6.0 (https://github.com/zip-rs/zip2) by Mathijs van de Nes <git@mathijs.vd-nes.nl>, Marli Frost <marli@frost.red>, Ryan Levick <ryan.levick@gmail.com>, Chris Hennick <hennickc@amazon.com>
12477
- - zip 9.3.0 (https://github.com/zip-rs/zip2) by Mathijs van de Nes <git@mathijs.vd-nes.nl>, Marli Frost <marli@frost.red>, Ryan Levick <ryan.levick@gmail.com>, Chris Hennick <hennickc@amazon.com>
12479
+ - zip 9.7.2 (https://github.com/zip-rs/zip2) by Mathijs van de Nes <git@mathijs.vd-nes.nl>, Marli Frost <marli@frost.red>, Ryan Levick <ryan.levick@gmail.com>, Chris Hennick <hennickc@amazon.com>
12478
12480
 
12479
12481
  The MIT License (MIT)
12480
12482
 
@@ -12715,7 +12717,7 @@ IN THE SOFTWARE.
12715
12717
  MIT License (MIT)
12716
12718
 
12717
12719
  Used by:
12718
- - calamine 0.36.1 (https://github.com/tafia/calamine) by Johann Tuffe <tafia973@gmail.com>
12720
+ - calamine 0.38.0 (https://github.com/tafia/calamine) by Johann Tuffe <tafia973@gmail.com>
12719
12721
  - quick-xml 0.42.0 (https://github.com/tafia/quick-xml)
12720
12722
 
12721
12723
  The MIT License (MIT)
@@ -12847,37 +12849,6 @@ The above copyright notice and this permission notice shall be included in all c
12847
12849
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12848
12850
 
12849
12851
 
12850
- ================================================================================
12851
- MIT License (MIT)
12852
-
12853
- Used by:
12854
- - quick-xml 0.41.0 (https://github.com/tafia/quick-xml)
12855
-
12856
- The MIT License (MIT)
12857
-
12858
- Copyright (c) 2016 Johann Tuffe
12859
-
12860
- Permission is hereby granted, free of charge, to any person obtaining a copy
12861
- of this software and associated documentation files (the "Software"), to deal
12862
- in the Software without restriction, including without limitation the rights
12863
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12864
- copies of the Software, and to permit persons to whom the Software is
12865
- furnished to do so, subject to the following conditions:
12866
-
12867
-
12868
- The above copyright notice and this permission notice shall be included in
12869
- all copies or substantial portions of the Software.
12870
-
12871
-
12872
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12873
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12874
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
12875
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
12876
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
12877
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
12878
- THE SOFTWARE.
12879
-
12880
-
12881
12852
  ================================================================================
12882
12853
  MIT License (MIT)
12883
12854
 
@@ -13431,7 +13402,7 @@ Used by:
13431
13402
  zlib License (Zlib)
13432
13403
 
13433
13404
  Used by:
13434
- - zlib-rs 0.6.3 (https://github.com/trifectatechfoundation/zlib-rs)
13405
+ - zlib-rs 0.6.8 (https://github.com/trifectatechfoundation/zlib-rs)
13435
13406
 
13436
13407
  (C) 2024 Trifecta Tech Foundation
13437
13408
 
package/geolibre-cli.wasm CHANGED
Binary file
@@ -64,6 +64,26 @@ export class CogBuilder {
64
64
  * Encode `f64` pixel data to a COG. `Uint8Array`.
65
65
  */
66
66
  write_f64(data: Float64Array | number[]): Uint8Array;
67
+ /**
68
+ * Encode `i16` pixel data (`Int16Array`) to a COG. `Uint8Array`.
69
+ */
70
+ write_i16(data: Int16Array | number[]): Uint8Array;
71
+ /**
72
+ * Encode `i32` pixel data (`Int32Array`) to a COG. `Uint8Array`.
73
+ */
74
+ write_i32(data: Int32Array | number[]): Uint8Array;
75
+ /**
76
+ * Encode `i8` pixel data (`Int8Array`) to a COG. `Uint8Array`.
77
+ */
78
+ write_i8(data: Int8Array | number[]): Uint8Array;
79
+ /**
80
+ * Encode `u16` pixel data (`Uint16Array`) to a COG. `Uint8Array`.
81
+ */
82
+ write_u16(data: Uint16Array | number[]): Uint8Array;
83
+ /**
84
+ * Encode `u32` pixel data (`Uint32Array`) to a COG. `Uint8Array`.
85
+ */
86
+ write_u32(data: Uint32Array | number[]): Uint8Array;
67
87
  /**
68
88
  * Encode `u8` pixel data to a COG. `Uint8Array`.
69
89
  */
@@ -616,6 +636,11 @@ export interface InitOutput {
616
636
  readonly cogbuilder_set_tile_size: (a: number, b: number) => void;
617
637
  readonly cogbuilder_write_f32: (a: number, b: number, c: number, d: number) => void;
618
638
  readonly cogbuilder_write_f64: (a: number, b: number, c: number, d: number) => void;
639
+ readonly cogbuilder_write_i16: (a: number, b: number, c: number, d: number) => void;
640
+ readonly cogbuilder_write_i32: (a: number, b: number, c: number, d: number) => void;
641
+ readonly cogbuilder_write_i8: (a: number, b: number, c: number, d: number) => void;
642
+ readonly cogbuilder_write_u16: (a: number, b: number, c: number, d: number) => void;
643
+ readonly cogbuilder_write_u32: (a: number, b: number, c: number, d: number) => void;
619
644
  readonly cogbuilder_write_u8: (a: number, b: number, c: number, d: number) => void;
620
645
  readonly cogstream_bbox_to_dataset_crs: (a: number, b: number, c: number, d: number, e: number) => void;
621
646
  readonly cogstream_bounding_box: (a: number, b: number) => void;
package/geolibre_wasm.js CHANGED
@@ -188,6 +188,131 @@ export class CogBuilder {
188
188
  wasm.__wbindgen_add_to_stack_pointer(16);
189
189
  }
190
190
  }
191
+ /**
192
+ * Encode `i16` pixel data (`Int16Array`) to a COG. `Uint8Array`.
193
+ * @param {Int16Array | number[]} data
194
+ * @returns {Uint8Array}
195
+ */
196
+ write_i16(data) {
197
+ try {
198
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
199
+ const ptr0 = passArray16ToWasm0(data, wasm.__wbindgen_export2);
200
+ const len0 = WASM_VECTOR_LEN;
201
+ wasm.cogbuilder_write_i16(retptr, this.__wbg_ptr, ptr0, len0);
202
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
203
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
204
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
205
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
206
+ if (r3) {
207
+ throw takeFromExternrefTable0(r2);
208
+ }
209
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
210
+ wasm.__wbindgen_export(r0, r1 * 1, 1);
211
+ return v2;
212
+ } finally {
213
+ wasm.__wbindgen_add_to_stack_pointer(16);
214
+ }
215
+ }
216
+ /**
217
+ * Encode `i32` pixel data (`Int32Array`) to a COG. `Uint8Array`.
218
+ * @param {Int32Array | number[]} data
219
+ * @returns {Uint8Array}
220
+ */
221
+ write_i32(data) {
222
+ try {
223
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
224
+ const ptr0 = passArray32ToWasm0(data, wasm.__wbindgen_export2);
225
+ const len0 = WASM_VECTOR_LEN;
226
+ wasm.cogbuilder_write_i32(retptr, this.__wbg_ptr, ptr0, len0);
227
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
228
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
229
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
230
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
231
+ if (r3) {
232
+ throw takeFromExternrefTable0(r2);
233
+ }
234
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
235
+ wasm.__wbindgen_export(r0, r1 * 1, 1);
236
+ return v2;
237
+ } finally {
238
+ wasm.__wbindgen_add_to_stack_pointer(16);
239
+ }
240
+ }
241
+ /**
242
+ * Encode `i8` pixel data (`Int8Array`) to a COG. `Uint8Array`.
243
+ * @param {Int8Array | number[]} data
244
+ * @returns {Uint8Array}
245
+ */
246
+ write_i8(data) {
247
+ try {
248
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
249
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export2);
250
+ const len0 = WASM_VECTOR_LEN;
251
+ wasm.cogbuilder_write_i8(retptr, this.__wbg_ptr, ptr0, len0);
252
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
253
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
254
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
255
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
256
+ if (r3) {
257
+ throw takeFromExternrefTable0(r2);
258
+ }
259
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
260
+ wasm.__wbindgen_export(r0, r1 * 1, 1);
261
+ return v2;
262
+ } finally {
263
+ wasm.__wbindgen_add_to_stack_pointer(16);
264
+ }
265
+ }
266
+ /**
267
+ * Encode `u16` pixel data (`Uint16Array`) to a COG. `Uint8Array`.
268
+ * @param {Uint16Array | number[]} data
269
+ * @returns {Uint8Array}
270
+ */
271
+ write_u16(data) {
272
+ try {
273
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
274
+ const ptr0 = passArray16ToWasm0(data, wasm.__wbindgen_export2);
275
+ const len0 = WASM_VECTOR_LEN;
276
+ wasm.cogbuilder_write_u16(retptr, this.__wbg_ptr, ptr0, len0);
277
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
278
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
279
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
280
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
281
+ if (r3) {
282
+ throw takeFromExternrefTable0(r2);
283
+ }
284
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
285
+ wasm.__wbindgen_export(r0, r1 * 1, 1);
286
+ return v2;
287
+ } finally {
288
+ wasm.__wbindgen_add_to_stack_pointer(16);
289
+ }
290
+ }
291
+ /**
292
+ * Encode `u32` pixel data (`Uint32Array`) to a COG. `Uint8Array`.
293
+ * @param {Uint32Array | number[]} data
294
+ * @returns {Uint8Array}
295
+ */
296
+ write_u32(data) {
297
+ try {
298
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
299
+ const ptr0 = passArray32ToWasm0(data, wasm.__wbindgen_export2);
300
+ const len0 = WASM_VECTOR_LEN;
301
+ wasm.cogbuilder_write_u32(retptr, this.__wbg_ptr, ptr0, len0);
302
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
303
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
304
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
305
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
306
+ if (r3) {
307
+ throw takeFromExternrefTable0(r2);
308
+ }
309
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
310
+ wasm.__wbindgen_export(r0, r1 * 1, 1);
311
+ return v2;
312
+ } finally {
313
+ wasm.__wbindgen_add_to_stack_pointer(16);
314
+ }
315
+ }
191
316
  /**
192
317
  * Encode `u8` pixel data to a COG. `Uint8Array`.
193
318
  * @param {Uint8Array | number[]} data
@@ -2689,6 +2814,13 @@ function getUint8ArrayMemory0() {
2689
2814
  return cachedUint8ArrayMemory0;
2690
2815
  }
2691
2816
 
2817
+ function passArray16ToWasm0(arg, malloc) {
2818
+ const ptr = malloc(arg.length * 2, 2) >>> 0;
2819
+ getUint16ArrayMemory0().set(arg, ptr / 2);
2820
+ WASM_VECTOR_LEN = arg.length;
2821
+ return ptr;
2822
+ }
2823
+
2692
2824
  function passArray32ToWasm0(arg, malloc) {
2693
2825
  const ptr = malloc(arg.length * 4, 4) >>> 0;
2694
2826
  getUint32ArrayMemory0().set(arg, ptr / 4);
Binary file
@@ -19,6 +19,11 @@ export const cogbuilder_set_proj_string: (a: number, b: number, c: number, d: nu
19
19
  export const cogbuilder_set_tile_size: (a: number, b: number) => void;
20
20
  export const cogbuilder_write_f32: (a: number, b: number, c: number, d: number) => void;
21
21
  export const cogbuilder_write_f64: (a: number, b: number, c: number, d: number) => void;
22
+ export const cogbuilder_write_i16: (a: number, b: number, c: number, d: number) => void;
23
+ export const cogbuilder_write_i32: (a: number, b: number, c: number, d: number) => void;
24
+ export const cogbuilder_write_i8: (a: number, b: number, c: number, d: number) => void;
25
+ export const cogbuilder_write_u16: (a: number, b: number, c: number, d: number) => void;
26
+ export const cogbuilder_write_u32: (a: number, b: number, c: number, d: number) => void;
22
27
  export const cogbuilder_write_u8: (a: number, b: number, c: number, d: number) => void;
23
28
  export const cogstream_bbox_to_dataset_crs: (a: number, b: number, c: number, d: number, e: number) => void;
24
29
  export const cogstream_bounding_box: (a: number, b: number) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "geolibre-wasm",
3
3
  "type": "module",
4
- "version": "1.8.2",
4
+ "version": "1.8.4",
5
5
  "description": "Pure-Rust geospatial toolkit (whitebox_next_gen) compiled to WebAssembly (WASI) for GeoLibre's in-browser tool execution",
6
6
  "license": "MIT",
7
7
  "repository": {
package/tools.mjs CHANGED
@@ -973,29 +973,53 @@ function readGeotiffInterleaved(reader) {
973
973
  return out;
974
974
  }
975
975
 
976
+ // Integer sample types the COG writer can preserve, keyed "format/bits":
977
+ // the typed array to fill, its value range, and the CogBuilder method.
978
+ const INTEGER_COG_WRITERS = {
979
+ "uint/8": { Array: Uint8Array, min: 0, max: 255, write: "write_u8" },
980
+ "int/8": { Array: Int8Array, min: -128, max: 127, write: "write_i8" },
981
+ "uint/16": { Array: Uint16Array, min: 0, max: 65535, write: "write_u16" },
982
+ "int/16": { Array: Int16Array, min: -32768, max: 32767, write: "write_i16" },
983
+ "uint/32": { Array: Uint32Array, min: 0, max: 4294967295, write: "write_u32" },
984
+ "int/32": { Array: Int32Array, min: -2147483648, max: 2147483647, write: "write_i32" },
985
+ };
986
+
976
987
  function writeTypedCog({ data, width, height, bands, sampleFormat, bitsPerSample, geoTransform, epsg, nodata, palette }) {
977
988
  const builder = new CogBuilder(width, height, bands);
978
989
  builder.set_geo_transform(geoTransform);
979
990
  builder.set_compression("deflate");
980
991
  if (epsg != null) builder.set_epsg(epsg);
981
992
  if (nodata != null) builder.set_nodata(nodata);
982
- if (sampleFormat === "uint" && bitsPerSample === 8) {
983
- const u8 = new Uint8Array(data.length);
984
- const fill = nodata == null ? 0 : Math.max(0, Math.min(255, Math.round(nodata)));
985
- for (let i = 0; i < data.length; i++) {
986
- const v = data[i];
987
- u8[i] = Number.isFinite(v) ? Math.max(0, Math.min(255, Math.round(v))) : fill;
993
+ const integer = INTEGER_COG_WRITERS[`${sampleFormat}/${bitsPerSample}`];
994
+ if (integer) {
995
+ const { Array: Typed, min, max, write } = integer;
996
+ if (nodata == null || (Number.isInteger(nodata) && nodata >= min && nodata <= max)) {
997
+ const clamp = (v) => Math.max(min, Math.min(max, Math.round(v)));
998
+ const out = new Typed(data.length);
999
+ const fill = nodata ?? 0;
1000
+ for (let i = 0; i < data.length; i++) {
1001
+ const v = data[i];
1002
+ out[i] = Number.isFinite(v) ? clamp(v) : fill;
1003
+ }
1004
+ const bytes = builder[write](out);
1005
+ return bitsPerSample === 8 && sampleFormat === "uint" && bands === 1 && palette
1006
+ ? patchTiffPalette(bytes, palette)
1007
+ : bytes;
988
1008
  }
989
- const bytes = builder.write_u8(u8);
990
- return bands === 1 && palette ? patchTiffPalette(bytes, palette) : bytes;
1009
+ // The requested nodata (e.g. -9999 on uint16) does not fit the integer
1010
+ // type, so widen to a float type that holds every source value exactly
1011
+ // and store nodata as given, keeping pixels and metadata in agreement.
1012
+ const out = (bitsPerSample <= 16 ? Float32Array : Float64Array).from(data, (v) =>
1013
+ Number.isFinite(v) ? v : nodata,
1014
+ );
1015
+ return bitsPerSample <= 16 ? builder.write_f32(out) : builder.write_f64(out);
991
1016
  }
992
1017
  if (sampleFormat === "ieeefloat" && bitsPerSample === 32) {
993
1018
  return builder.write_f32(Float32Array.from(data));
994
1019
  }
995
- if (sampleFormat === "ieeefloat" && bitsPerSample === 64) {
996
- return builder.write_f64(data);
997
- }
998
- throw new Error(`preserving source sample type is not yet supported for ${sampleFormat}/${bitsPerSample}-bit rasters`);
1020
+ // float64 and any other type (e.g. 64-bit integers) are written as float64,
1021
+ // so the extract still succeeds.
1022
+ return builder.write_f64(data instanceof Float64Array ? data : Float64Array.from(data));
999
1023
  }
1000
1024
 
1001
1025
  function windowFromBbox(gt, baseLevel, level, bbox) {