@developmentseed/deck.gl-geotiff 0.1.0-beta.5 → 0.1.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 (70) hide show
  1. package/dist/cog-layer.d.ts +107 -9
  2. package/dist/cog-layer.d.ts.map +1 -1
  3. package/dist/cog-layer.js +122 -95
  4. package/dist/cog-layer.js.map +1 -1
  5. package/dist/cog-tile-matrix-set.d.ts +2 -1
  6. package/dist/cog-tile-matrix-set.d.ts.map +1 -1
  7. package/dist/cog-tile-matrix-set.js +20 -23
  8. package/dist/cog-tile-matrix-set.js.map +1 -1
  9. package/dist/ellipsoids.d.ts +1 -1
  10. package/dist/ellipsoids.js +1 -1
  11. package/dist/geotiff/geotiff.d.ts +59 -0
  12. package/dist/geotiff/geotiff.d.ts.map +1 -0
  13. package/dist/geotiff/geotiff.js +146 -0
  14. package/dist/geotiff/geotiff.js.map +1 -0
  15. package/dist/geotiff/index.d.ts +1 -0
  16. package/dist/geotiff/index.d.ts.map +1 -0
  17. package/dist/geotiff/index.js +2 -0
  18. package/dist/geotiff/index.js.map +1 -0
  19. package/dist/geotiff/render-pipeline.d.ts +13 -0
  20. package/dist/geotiff/render-pipeline.d.ts.map +1 -0
  21. package/dist/geotiff/render-pipeline.js +149 -0
  22. package/dist/geotiff/render-pipeline.js.map +1 -0
  23. package/dist/geotiff/texture.d.ts +14 -0
  24. package/dist/geotiff/texture.d.ts.map +1 -0
  25. package/dist/geotiff/texture.js +134 -0
  26. package/dist/geotiff/texture.js.map +1 -0
  27. package/dist/geotiff/types.d.ts +34 -0
  28. package/dist/geotiff/types.d.ts.map +1 -0
  29. package/dist/geotiff/types.js +18 -0
  30. package/dist/geotiff/types.js.map +1 -0
  31. package/dist/geotiff-layer.d.ts +42 -3
  32. package/dist/geotiff-layer.d.ts.map +1 -1
  33. package/dist/geotiff-layer.js +21 -7
  34. package/dist/geotiff-layer.js.map +1 -1
  35. package/dist/geotiff-reprojection.d.ts +5 -11
  36. package/dist/geotiff-reprojection.d.ts.map +1 -1
  37. package/dist/geotiff-reprojection.js +8 -37
  38. package/dist/geotiff-reprojection.js.map +1 -1
  39. package/dist/index.d.ts +6 -4
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +4 -2
  42. package/dist/index.js.map +1 -1
  43. package/dist/proj.d.ts +24 -0
  44. package/dist/proj.d.ts.map +1 -0
  45. package/dist/proj.js +46 -0
  46. package/dist/proj.js.map +1 -0
  47. package/package.json +10 -15
  48. package/dist/geotiff.d.ts +0 -31
  49. package/dist/geotiff.d.ts.map +0 -1
  50. package/dist/geotiff.js +0 -70
  51. package/dist/geotiff.js.map +0 -1
  52. package/dist/index.cjs +0 -181
  53. package/dist/index.cjs.map +0 -1
  54. package/dist/pool.d.ts +0 -1
  55. package/dist/pool.d.ts.map +0 -1
  56. package/dist/pool.js +0 -2
  57. package/dist/pool.js.map +0 -1
  58. package/dist/src/geotiff-reprojection.d.ts +0 -10
  59. package/dist/src/geotiff-reprojection.d.ts.map +0 -1
  60. package/dist/src/geotiff-reprojection.js +0 -159
  61. package/dist/src/geotiff-reprojection.js.map +0 -1
  62. package/dist/src/index.d.ts +0 -2
  63. package/dist/src/index.d.ts.map +0 -1
  64. package/dist/src/index.js +0 -2
  65. package/dist/src/index.js.map +0 -1
  66. package/dist/tests/placeholder.test.d.ts +0 -2
  67. package/dist/tests/placeholder.test.d.ts.map +0 -1
  68. package/dist/tests/placeholder.test.js +0 -7
  69. package/dist/tests/placeholder.test.js.map +0 -1
  70. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,59 @@
1
+ import type { GeoTIFF, GeoTIFFImage, TypedArrayWithDimensions } from "geotiff";
2
+ import { BaseClient, Pool } from "geotiff";
3
+ import type { Converter } from "proj4";
4
+ /**
5
+ * Options that may be passed when reading image data from geotiff.js
6
+ */
7
+ type ReadRasterOptions = {
8
+ /** the subset to read data from in pixels. */
9
+ window?: [number, number, number, number];
10
+ /** The optional decoder pool to use. */
11
+ pool?: Pool;
12
+ /** An AbortSignal that may be signalled if the request is to be aborted */
13
+ signal?: AbortSignal;
14
+ };
15
+ /**
16
+ * Retrieve the default geotiff.js decoder Pool.
17
+ *
18
+ * If a Pool has not yet been created, it will be created on first call.
19
+ *
20
+ * The Pool will be shared between all COGLayer and GeoTIFFLayer instances.
21
+ */
22
+ export declare function defaultPool(): Pool;
23
+ /**
24
+ * Load an RGBA image from a GeoTIFFImage.
25
+ */
26
+ export declare function loadRgbImage(image: GeoTIFFImage, options?: ReadRasterOptions): Promise<{
27
+ texture: ImageData;
28
+ height: number;
29
+ width: number;
30
+ }>;
31
+ /**
32
+ * Add an alpha channel to an RGB image array.
33
+ *
34
+ * Only supports input arrays with 3 (RGB) or 4 (RGBA) channels. If the input is
35
+ * already RGBA, it is returned unchanged.
36
+ */
37
+ export declare function addAlphaChannel(rgbImage: TypedArrayWithDimensions): ImageData;
38
+ /**
39
+ * Parse the GeoTIFF `ColorMap` tag into an ImageData.
40
+ *
41
+ * @param {Uint16Array} cmap The colormap array from the GeoTIFF `ColorMap` tag.
42
+ *
43
+ * @return {ImageData} The parsed colormap as an ImageData object.
44
+ */
45
+ export declare function parseColormap(cmap: Uint16Array): ImageData;
46
+ export declare function fetchGeoTIFF(input: GeoTIFF | string | ArrayBuffer | Blob | BaseClient): Promise<GeoTIFF>;
47
+ /**
48
+ * Calculate the WGS84 bounding box of a GeoTIFF image
49
+ */
50
+ export declare function getGeographicBounds(image: GeoTIFFImage, converter: Converter): {
51
+ west: number;
52
+ south: number;
53
+ east: number;
54
+ north: number;
55
+ };
56
+ /** Parse the GDAL_NODATA TIFF tag into a number. */
57
+ export declare function parseGDALNoData(GDAL_NODATA: string | undefined): number | null;
58
+ export {};
59
+ //# sourceMappingURL=geotiff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geotiff.d.ts","sourceRoot":"","sources":["../../src/geotiff/geotiff.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EA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AACpD,wBAAgB,eAAe,CAC7B,WAAW,EAAE,MAAM,GAAG,SAAS,GAC9B,MAAM,GAAG,IAAI,CAYf"}
@@ -0,0 +1,146 @@
1
+ // Utilities for interacting with geotiff.js.
2
+ import { BaseClient, fromArrayBuffer, fromBlob, fromCustomClient, fromUrl, Pool, } from "geotiff";
3
+ /**
4
+ * A default geotiff.js decoder pool instance.
5
+ *
6
+ * It will be created on first call of `defaultPool`.
7
+ */
8
+ let DEFAULT_POOL = null;
9
+ /**
10
+ * Retrieve the default geotiff.js decoder Pool.
11
+ *
12
+ * If a Pool has not yet been created, it will be created on first call.
13
+ *
14
+ * The Pool will be shared between all COGLayer and GeoTIFFLayer instances.
15
+ */
16
+ export function defaultPool() {
17
+ if (DEFAULT_POOL === null) {
18
+ DEFAULT_POOL = new Pool();
19
+ }
20
+ return DEFAULT_POOL;
21
+ }
22
+ /**
23
+ * Load an RGBA image from a GeoTIFFImage.
24
+ */
25
+ export async function loadRgbImage(image, options) {
26
+ const mergedOptions = {
27
+ ...options,
28
+ interleave: true,
29
+ enableAlpha: true,
30
+ };
31
+ // Since we set interleave: true, the result is a single array with all
32
+ // samples, so we cast to TypedArrayWithDimensions
33
+ // https://github.com/geotiffjs/geotiff.js/issues/486
34
+ const rgbImage = (await image.readRGB(mergedOptions));
35
+ const imageData = addAlphaChannel(rgbImage);
36
+ return {
37
+ texture: imageData,
38
+ height: rgbImage.height,
39
+ width: rgbImage.width,
40
+ };
41
+ }
42
+ /**
43
+ * Add an alpha channel to an RGB image array.
44
+ *
45
+ * Only supports input arrays with 3 (RGB) or 4 (RGBA) channels. If the input is
46
+ * already RGBA, it is returned unchanged.
47
+ */
48
+ export function addAlphaChannel(rgbImage) {
49
+ const { height, width } = rgbImage;
50
+ if (rgbImage.length === height * width * 4) {
51
+ // Already has alpha channel
52
+ return new ImageData(new Uint8ClampedArray(rgbImage), width, height);
53
+ }
54
+ else if (rgbImage.length === height * width * 3) {
55
+ // Need to add alpha channel
56
+ const rgbaLength = (rgbImage.length / 3) * 4;
57
+ const rgbaArray = new Uint8ClampedArray(rgbaLength);
58
+ for (let i = 0; i < rgbImage.length / 3; ++i) {
59
+ rgbaArray[i * 4] = rgbImage[i * 3];
60
+ rgbaArray[i * 4 + 1] = rgbImage[i * 3 + 1];
61
+ rgbaArray[i * 4 + 2] = rgbImage[i * 3 + 2];
62
+ rgbaArray[i * 4 + 3] = 255;
63
+ }
64
+ return new ImageData(rgbaArray, width, height);
65
+ }
66
+ else {
67
+ throw new Error(`Unexpected number of channels in raster data: ${rgbImage.length / (height * width)}`);
68
+ }
69
+ }
70
+ /**
71
+ * Parse the GeoTIFF `ColorMap` tag into an ImageData.
72
+ *
73
+ * @param {Uint16Array} cmap The colormap array from the GeoTIFF `ColorMap` tag.
74
+ *
75
+ * @return {ImageData} The parsed colormap as an ImageData object.
76
+ */
77
+ export function parseColormap(cmap) {
78
+ // TODO: test colormap handling on a 16-bit image with 2^16 entries?
79
+ const size = cmap.length / 3;
80
+ const rgba = new Uint8ClampedArray(size * 4);
81
+ const rOffset = 0;
82
+ const gOffset = size;
83
+ const bOffset = size * 2;
84
+ // Note: >> 8 is needed to convert from 16-bit to 8-bit color values
85
+ // It just divides by 256 and floors to nearest integer
86
+ for (let i = 0; i < size; i++) {
87
+ rgba[4 * i + 0] = cmap[rOffset + i] >> 8;
88
+ rgba[4 * i + 1] = cmap[gOffset + i] >> 8;
89
+ rgba[4 * i + 2] = cmap[bOffset + i] >> 8;
90
+ // Full opacity
91
+ rgba[4 * i + 3] = 255;
92
+ }
93
+ return new ImageData(rgba, size, 1);
94
+ }
95
+ export async function fetchGeoTIFF(input) {
96
+ if (typeof input === "string") {
97
+ return fromUrl(input);
98
+ }
99
+ if (input instanceof ArrayBuffer) {
100
+ return fromArrayBuffer(input);
101
+ }
102
+ if (input instanceof Blob) {
103
+ return fromBlob(input);
104
+ }
105
+ // TODO: instanceof may fail here if multiple versions of geotiff.js are
106
+ // present
107
+ if (input instanceof BaseClient) {
108
+ return fromCustomClient(input);
109
+ }
110
+ return input;
111
+ }
112
+ /**
113
+ * Calculate the WGS84 bounding box of a GeoTIFF image
114
+ */
115
+ export function getGeographicBounds(image, converter) {
116
+ const projectedBbox = image.getBoundingBox();
117
+ // Reproject all four corners to handle rotation/skew
118
+ const [minX, minY, maxX, maxY] = projectedBbox;
119
+ const corners = [
120
+ converter.forward([minX, minY]), // bottom-left
121
+ converter.forward([maxX, minY]), // bottom-right
122
+ converter.forward([maxX, maxY]), // top-right
123
+ converter.forward([minX, maxY]), // top-left
124
+ ];
125
+ // Find the bounding box that encompasses all reprojected corners
126
+ const lons = corners.map((c) => c[0]);
127
+ const lats = corners.map((c) => c[1]);
128
+ const west = Math.min(...lons);
129
+ const south = Math.min(...lats);
130
+ const east = Math.max(...lons);
131
+ const north = Math.max(...lats);
132
+ // Return bounds in MapLibre format: [[west, south], [east, north]]
133
+ return { west, south, east, north };
134
+ }
135
+ /** Parse the GDAL_NODATA TIFF tag into a number. */
136
+ export function parseGDALNoData(GDAL_NODATA) {
137
+ if (!GDAL_NODATA) {
138
+ return null;
139
+ }
140
+ // Remove trailing null character if present
141
+ const noDataString = GDAL_NODATA?.[GDAL_NODATA?.length - 1] === "\x00"
142
+ ? GDAL_NODATA.slice(0, -1)
143
+ : GDAL_NODATA;
144
+ return noDataString?.length > 0 ? parseFloat(noDataString) : null;
145
+ }
146
+ //# sourceMappingURL=geotiff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geotiff.js","sourceRoot":"","sources":["../../src/geotiff/geotiff.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAG7C,OAAO,EACL,UAAU,EACV,eAAe,EACf,QAAQ,EACR,gBAAgB,EAChB,OAAO,EACP,IAAI,GACL,MAAM,SAAS,CAAC;AAiBjB;;;;GAIG;AACH,IAAI,YAAY,GAAgB,IAAI,CAAC;AAErC;;;;;;GAMG;AACH,MAAM,UAAU,WAAW;IACzB,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;QA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OAAO,YAAY,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACpE,CAAC"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/geotiff/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/geotiff/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ import type { Device, Texture } from "@luma.gl/core";
2
+ import type { COGLayerProps } from "../cog-layer";
3
+ import type { ImageFileDirectory } from "./types";
4
+ export type TextureDataT = {
5
+ height: number;
6
+ width: number;
7
+ texture: Texture;
8
+ };
9
+ export declare function inferRenderPipeline(ifd: ImageFileDirectory, device: Device): {
10
+ getTileData: COGLayerProps<TextureDataT>["getTileData"];
11
+ renderTile: COGLayerProps<TextureDataT>["renderTile"];
12
+ };
13
+ //# sourceMappingURL=render-pipeline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-pipeline.d.ts","sourceRoot":"","sources":["../../src/geotiff/render-pipeline.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,MAAM,EAAgB,OAAO,EAAE,MAAM,eAAe,CAAC;AAEnE,OAAO,KAAK,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AAGtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGlD,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAqBF,wBAAgB,mBAAmB,CAEjC,GAAG,EAAE,kBAAkB,EACvB,MAAM,EAAE,MAAM,GACb;IACD,WAAW,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC,aAAa,CAAC,CAAC;IACxD,UAAU,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC,YAAY,CAAC,CAAC;CACvD,CAYA"}
@@ -0,0 +1,149 @@
1
+ import { CMYKToRGB, Colormap, CreateTexture, cieLabToRGB, FilterNoDataVal, YCbCrToRGB, } from "@developmentseed/deck.gl-raster/gpu-modules";
2
+ import { addAlphaChannel, parseColormap, parseGDALNoData } from "./geotiff";
3
+ import { inferTextureFormat } from "./texture";
4
+ import { PhotometricInterpretationT } from "./types";
5
+ export function inferRenderPipeline(
6
+ // TODO: narrow type to only used fields
7
+ ifd, device) {
8
+ const { SampleFormat } = ifd;
9
+ switch (SampleFormat[0]) {
10
+ // Unsigned integers
11
+ case 1:
12
+ return createUnormPipeline(ifd, device);
13
+ }
14
+ throw new Error(`Inferring render pipeline for non-unsigned integers not yet supported. Found SampleFormat: ${SampleFormat}`);
15
+ }
16
+ /**
17
+ * Create pipeline for visualizing unsigned-integer data.
18
+ */
19
+ function createUnormPipeline(ifd, device) {
20
+ const { BitsPerSample, ColorMap, GDAL_NODATA, PhotometricInterpretation, SampleFormat, SamplesPerPixel, } = ifd;
21
+ const renderPipeline = [
22
+ {
23
+ module: CreateTexture,
24
+ props: {
25
+ textureName: (data) => data.texture,
26
+ },
27
+ },
28
+ ];
29
+ // Add NoData filtering if GDAL_NODATA is defined
30
+ const noDataVal = parseGDALNoData(GDAL_NODATA);
31
+ if (noDataVal !== null) {
32
+ // Since values are 0-1 for unorm textures,
33
+ const noDataScaled = noDataVal / 255.0;
34
+ renderPipeline.push({
35
+ module: FilterNoDataVal,
36
+ props: { value: noDataScaled },
37
+ });
38
+ }
39
+ const toRGBModule = photometricInterpretationToRGB(PhotometricInterpretation, device, ColorMap);
40
+ if (toRGBModule) {
41
+ renderPipeline.push(toRGBModule);
42
+ }
43
+ // For palette images, use nearest-neighbor sampling
44
+ const samplerOptions = PhotometricInterpretation === PhotometricInterpretationT.Palette
45
+ ? {
46
+ magFilter: "nearest",
47
+ minFilter: "nearest",
48
+ }
49
+ : {
50
+ magFilter: "linear",
51
+ minFilter: "linear",
52
+ };
53
+ const getTileData = async (image, options) => {
54
+ const { device } = options;
55
+ const mergedOptions = {
56
+ ...options,
57
+ interleave: true,
58
+ };
59
+ let data = (await image.readRasters(mergedOptions));
60
+ let numSamples = SamplesPerPixel;
61
+ if (SamplesPerPixel === 3) {
62
+ // WebGL2 doesn't have an RGB-only texture format; it requires RGBA.
63
+ data = addAlphaChannel(data);
64
+ numSamples = 4;
65
+ }
66
+ const textureFormat = inferTextureFormat(
67
+ // Add one sample for added alpha channel
68
+ numSamples, BitsPerSample, SampleFormat);
69
+ const texture = device.createTexture({
70
+ data,
71
+ format: textureFormat,
72
+ width: data.width,
73
+ height: data.height,
74
+ sampler: samplerOptions,
75
+ });
76
+ return {
77
+ texture,
78
+ height: data.height,
79
+ width: data.width,
80
+ };
81
+ };
82
+ const renderTile = (tileData) => {
83
+ return renderPipeline.map((m, _i) => resolveModule(m, tileData));
84
+ };
85
+ return { getTileData, renderTile };
86
+ }
87
+ function photometricInterpretationToRGB(PhotometricInterpretation, device, ColorMap) {
88
+ switch (PhotometricInterpretation) {
89
+ case PhotometricInterpretationT.RGB:
90
+ return null;
91
+ case PhotometricInterpretationT.Palette: {
92
+ if (!ColorMap) {
93
+ throw new Error("ColorMap is required for PhotometricInterpretation Palette");
94
+ }
95
+ const { data, width, height } = parseColormap(ColorMap);
96
+ const cmapTexture = device.createTexture({
97
+ data,
98
+ format: "rgba8unorm",
99
+ width,
100
+ height,
101
+ sampler: {
102
+ minFilter: "nearest",
103
+ magFilter: "nearest",
104
+ addressModeU: "clamp-to-edge",
105
+ addressModeV: "clamp-to-edge",
106
+ },
107
+ });
108
+ return {
109
+ module: Colormap,
110
+ props: {
111
+ colormapTexture: cmapTexture,
112
+ },
113
+ };
114
+ }
115
+ case PhotometricInterpretationT.CMYK:
116
+ return {
117
+ module: CMYKToRGB,
118
+ };
119
+ case PhotometricInterpretationT.YCbCr:
120
+ return {
121
+ module: YCbCrToRGB,
122
+ };
123
+ case PhotometricInterpretationT.CIELab:
124
+ return {
125
+ module: cieLabToRGB,
126
+ };
127
+ default:
128
+ throw new Error(`Unsupported PhotometricInterpretation ${PhotometricInterpretation}`);
129
+ }
130
+ }
131
+ /**
132
+ * If any prop of any module is a function, replace that prop value with the
133
+ * result of that function
134
+ */
135
+ function resolveModule(m, data) {
136
+ const { module, props } = m;
137
+ if (!props) {
138
+ return { module };
139
+ }
140
+ const resolvedProps = {};
141
+ for (const [key, value] of Object.entries(props)) {
142
+ const newValue = typeof value === "function" ? value(data) : value;
143
+ if (newValue !== undefined) {
144
+ resolvedProps[key] = newValue;
145
+ }
146
+ }
147
+ return { module, props: resolvedProps };
148
+ }
149
+ //# sourceMappingURL=render-pipeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-pipeline.js","sourceRoot":"","sources":["../../src/geotiff/render-pipeline.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,QAAQ,EACR,aAAa,EACb,WAAW,EACX,eAAe,EACf,UAAU,GACX,MAAM,6CAA6C,CAAC;AAIrD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AA2BrD,MAAM,UAAU,mBAAmB;AACjC,wCAAwC;AACxC,GAAuB,EACvB,MAAc;IAKd,MAAM,EAAE,YAAY,EAAE,GAAG,GAAG,CAAC;IAE7B,QAAQ,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;QACxB,oBAAoB;QACpB,KAAK,CAAC;YACJ,OAAO,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,IAAI,KAAK,CACb,8FAA8F,YAAY,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AAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACnE,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,aAAa,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;QAChC,CAAC;IACH,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { TextureFormat, TextureProps } from "@luma.gl/core";
2
+ import type { GeoTIFFImage, TypedArray } from "geotiff";
3
+ /**
4
+ * Infers texture properties from a GeoTIFF image and its associated data.
5
+ */
6
+ export declare function createTextureProps(image: GeoTIFFImage, data: TypedArray, options: {
7
+ width: number;
8
+ height: number;
9
+ }): TextureProps;
10
+ /**
11
+ * Infer the TextureFormat given values from GeoTIFF tags.
12
+ */
13
+ export declare function inferTextureFormat(samplesPerPixel: number, bitsPerSample: Uint16Array, sampleFormat: Uint16Array): TextureFormat;
14
+ //# sourceMappingURL=texture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"texture.d.ts","sourceRoot":"","sources":["../../src/geotiff/texture.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGxD;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACzC,YAAY,CAgBd;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,eAAe,EAAE,MAAM,EACvB,aAAa,EAAE,WAAW,EAC1B,YAAY,EAAE,WAAW,GACxB,aAAa,CAef"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Infers texture properties from a GeoTIFF image and its associated data.
3
+ */
4
+ export function createTextureProps(image, data, options) {
5
+ const ifd = image.getFileDirectory();
6
+ const samplesPerPixel = ifd.SamplesPerPixel;
7
+ const textureFormat = inferTextureFormat(samplesPerPixel, ifd.BitsPerSample, ifd.SampleFormat);
8
+ return {
9
+ data,
10
+ format: textureFormat,
11
+ width: options.width,
12
+ height: options.height,
13
+ };
14
+ }
15
+ /**
16
+ * Infer the TextureFormat given values from GeoTIFF tags.
17
+ */
18
+ export function inferTextureFormat(samplesPerPixel, bitsPerSample, sampleFormat) {
19
+ const channelCount = verifySamplesPerPixel(samplesPerPixel);
20
+ const bitWidth = verifyIdenticalBitsPerSample(bitsPerSample);
21
+ const scalarKind = inferScalarKind(sampleFormat);
22
+ const formatKey = `${channelCount}:${scalarKind}:${bitWidth}`;
23
+ const format = FORMAT_TABLE[formatKey];
24
+ if (!format) {
25
+ throw new Error(`Unsupported texture format for SamplesPerPixel=${samplesPerPixel}, BitsPerSample=${bitsPerSample}, SampleFormat=${sampleFormat}`);
26
+ }
27
+ return format;
28
+ }
29
+ function verifySamplesPerPixel(samplesPerPixel) {
30
+ if (samplesPerPixel === 1 ||
31
+ samplesPerPixel === 2 ||
32
+ samplesPerPixel === 3 ||
33
+ samplesPerPixel === 4) {
34
+ return samplesPerPixel;
35
+ }
36
+ throw new Error(`Unsupported SamplesPerPixel ${samplesPerPixel}. Only 1, 2, 3, or 4 are supported.`);
37
+ }
38
+ function verifyIdenticalBitsPerSample(bitsPerSample) {
39
+ // bitsPerSamples is non-empty
40
+ const first = bitsPerSample[0];
41
+ for (let i = 1; i < bitsPerSample.length; i++) {
42
+ if (bitsPerSample[i] !== first) {
43
+ throw new Error(`Unsupported varying BitsPerSample ${bitsPerSample}. All samples must have the same bit width.`);
44
+ }
45
+ }
46
+ if (first !== 8 && first !== 16 && first !== 32) {
47
+ throw new Error(`Unsupported BitsPerSample ${first}. Only 8, 16, or 32 are supported.`);
48
+ }
49
+ return first;
50
+ }
51
+ /**
52
+ * Map the geotiff tag SampleFormat to known kinds of scalars
53
+ */
54
+ function inferScalarKind(sampleFormat) {
55
+ // Only support identical SampleFormats for all samples
56
+ const first = sampleFormat[0];
57
+ for (let i = 1; i < sampleFormat.length; i++) {
58
+ if (sampleFormat[i] !== first) {
59
+ throw new Error(`Unsupported varying SampleFormat ${sampleFormat}. All samples must have the same format.`);
60
+ }
61
+ }
62
+ switch (first) {
63
+ case 1:
64
+ return "unorm";
65
+ case 2:
66
+ return "sint";
67
+ case 3:
68
+ return "float";
69
+ default:
70
+ throw new Error(`Unsupported SampleFormat ${sampleFormat}`);
71
+ }
72
+ }
73
+ /**
74
+ * A mapping of our texture format "key" to allowed TextureFormats defined by
75
+ * luma.gl.
76
+ *
77
+ * See https://luma.gl/docs/api-reference/core/texture-formats for details on
78
+ * texture formats.
79
+ *
80
+ * You can use `device.isTextureFormatSupported(format)` check if it is possible
81
+ * to create and sample textures with a specific texture format on your current
82
+ * device.
83
+ *
84
+ * This explicit mapping ensures that Typescript can verify that all keys
85
+ * correspond to valid TextureFormats.
86
+ */
87
+ const FORMAT_TABLE = {
88
+ // 1 byte per pixel
89
+ "1:sint:8": "r8sint",
90
+ "1:uint:8": "r8uint",
91
+ "1:unorm:8": "r8unorm",
92
+ // 2 bytes per pixel (one channel)
93
+ "1:float:16": "r16float",
94
+ "1:sint:16": "r16sint",
95
+ "1:uint:16": "r16uint",
96
+ "1:unorm:16": "r16unorm",
97
+ // 2 bytes per pixel (two channels)
98
+ "2:sint:8": "rg8sint",
99
+ "2:uint:8": "rg8uint",
100
+ "2:unorm:8": "rg8unorm",
101
+ // 4 bytes per pixel (one channel)
102
+ "1:float:32": "r32float",
103
+ "1:sint:32": "r32sint",
104
+ "1:uint:32": "r32uint",
105
+ // 4 bytes per pixel (two channels)
106
+ "2:float:16": "rg16float",
107
+ "2:sint:16": "rg16sint",
108
+ "2:uint:16": "rg16uint",
109
+ "2:unorm:16": "rg16unorm",
110
+ // 4 bytes per pixel (four channels)
111
+ "4:sint:8": "rgba8sint",
112
+ "4:uint:8": "rgba8uint",
113
+ "4:unorm:8": "rgba8unorm",
114
+ // 6 bytes per pixel (three channels)
115
+ // Note: this is supported on WebGL2 but not supported on WebGPU
116
+ // I expect actual switch to WebGPU to be quite a ways off still
117
+ "3:uint:16": "rgb16unorm-webgl",
118
+ // 8 bytes per pixel (two channels)
119
+ "2:float:32": "rg32float",
120
+ "2:sint:32": "rg32sint",
121
+ "2:uint:32": "rg32uint",
122
+ // 8 bytes per pixel (four channels)
123
+ "4:float:16": "rgba16float",
124
+ "4:sint:16": "rgba16sint",
125
+ "4:uint:16": "rgba16uint",
126
+ "4:unorm:16": "rgba16unorm",
127
+ // 12 bytes per pixel (three channels)
128
+ "3:float:32": "rgb32float-webgl",
129
+ // 16 bytes per pixel (four channels)
130
+ "4:float:32": "rgba32float",
131
+ "4:sint:32": "rgba32sint",
132
+ "4:uint:32": "rgba32uint",
133
+ };
134
+ //# sourceMappingURL=texture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"texture.js","sourceRoot":"","sources":["../../src/geotiff/texture.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAAmB,EACnB,IAAgB,EAChB,OAA0C;IAE1C,MAAM,GAAG,GAAG,KAAK,CAAC,gBAAgB,EAAwB,CAAC;IAC3D,MAAM,eAAe,GAAG,GAAG,CAAC,eAAe,CAAC;IAE5C,MAAM,aAAa,GAAG,kBAAkB,CACtC,eAAe,EACf,GAAG,CAAC,aAAa,EACjB,GAAG,CAAC,YAAY,CACjB,CAAC;IAEF,OAAO;QACL,IAAI;QACJ,MAAM,EAAE,aAAa;QACrB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAChC,eAAuB,EACvB,aAA0B,EAC1B,YAAyB;IAEzB,MAAM,YAAY,GAAG,qBAAqB,CAAC,eAAe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,EAAE,YAAY;IAEzB,qCAAqC;IACrC,gEAAgE;IAChE,gEAAgE;IAChE,WAAW,EAAE,kBAAkB;IAE/B,mCAAmC;IACnC,YAAY,EAAE,WAAW;IACzB,WAAW,EAAE,UAAU;IACvB,WAAW,EAAE,UAAU;IAEvB,oCAAoC;IACpC,YAAY,EAAE,aAAa;IAC3B,WAAW,EAAE,YAAY;IACzB,WAAW,EAAE,YAAY;IACzB,YAAY,EAAE,aAAa;IAE3B,sCAAsC;IACtC,YAAY,EAAE,kBAAkB;IAEhC,qCAAqC;IACrC,YAAY,EAAE,aAAa;IAC3B,WAAW,EAAE,YAAY;IACzB,WAAW,EAAE,YAAY;CAC1B,CAAC"}
@@ -0,0 +1,34 @@
1
+ export declare enum PhotometricInterpretationT {
2
+ WhiteIsZero = 0,
3
+ BlackIsZero = 1,
4
+ RGB = 2,
5
+ Palette = 3,
6
+ TransparencyMask = 4,
7
+ CMYK = 5,
8
+ YCbCr = 6,
9
+ CIELab = 8,
10
+ ICCLab = 9
11
+ }
12
+ export declare enum PlanarConfigurationT {
13
+ Chunky = 1,
14
+ Planar = 2
15
+ }
16
+ /** Improved typing for IFD. */
17
+ export type ImageFileDirectory = {
18
+ BitsPerSample: Uint16Array;
19
+ ColorMap?: Uint16Array;
20
+ Compression: number;
21
+ /** GDAL NoData value as string.
22
+ * <https://gdal.org/en/stable/drivers/raster/gtiff.html#nodata-value>
23
+ */
24
+ GDAL_NODATA?: string;
25
+ ImageLength: number;
26
+ ImageWidth: number;
27
+ PhotometricInterpretation: PhotometricInterpretationT;
28
+ /** Strip or tiled */
29
+ PlanarConfiguration: PlanarConfigurationT;
30
+ SampleFormat: Uint16Array;
31
+ /** Number of bands */
32
+ SamplesPerPixel: number;
33
+ };
34
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/geotiff/types.ts"],"names":[],"mappings":"AAAA,oBAAY,0BAA0B;IACpC,WAAW,IAAI;IACf,WAAW,IAAI;IACf,GAAG,IAAI;IACP,OAAO,IAAI;IACX,gBAAgB,IAAI;IACpB,IAAI,IAAI;IACR,KAAK,IAAI;IACT,MAAM,IAAI;IACV,MAAM,IAAI;CACX;AAED,oBAAY,oBAAoB;IAC9B,MAAM,IAAI;IACV,MAAM,IAAI;CACX;AAED,+BAA+B;AAC/B,MAAM,MAAM,kBAAkB,GAAG;IAC/B,aAAa,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,yBAAyB,EAAE,0BAA0B,CAAC;IACtD,qBAAqB;IACrB,mBAAmB,EAAE,oBAAoB,CAAC;IAC1C,YAAY,EAAE,WAAW,CAAC;IAC1B,sBAAsB;IACtB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC"}
@@ -0,0 +1,18 @@
1
+ export var PhotometricInterpretationT;
2
+ (function (PhotometricInterpretationT) {
3
+ PhotometricInterpretationT[PhotometricInterpretationT["WhiteIsZero"] = 0] = "WhiteIsZero";
4
+ PhotometricInterpretationT[PhotometricInterpretationT["BlackIsZero"] = 1] = "BlackIsZero";
5
+ PhotometricInterpretationT[PhotometricInterpretationT["RGB"] = 2] = "RGB";
6
+ PhotometricInterpretationT[PhotometricInterpretationT["Palette"] = 3] = "Palette";
7
+ PhotometricInterpretationT[PhotometricInterpretationT["TransparencyMask"] = 4] = "TransparencyMask";
8
+ PhotometricInterpretationT[PhotometricInterpretationT["CMYK"] = 5] = "CMYK";
9
+ PhotometricInterpretationT[PhotometricInterpretationT["YCbCr"] = 6] = "YCbCr";
10
+ PhotometricInterpretationT[PhotometricInterpretationT["CIELab"] = 8] = "CIELab";
11
+ PhotometricInterpretationT[PhotometricInterpretationT["ICCLab"] = 9] = "ICCLab";
12
+ })(PhotometricInterpretationT || (PhotometricInterpretationT = {}));
13
+ export var PlanarConfigurationT;
14
+ (function (PlanarConfigurationT) {
15
+ PlanarConfigurationT[PlanarConfigurationT["Chunky"] = 1] = "Chunky";
16
+ PlanarConfigurationT[PlanarConfigurationT["Planar"] = 2] = "Planar";
17
+ })(PlanarConfigurationT || (PlanarConfigurationT = {}));
18
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/geotiff/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,0BAUX;AAVD,WAAY,0BAA0B;IACpC,yFAAe,CAAA;IACf,yFAAe,CAAA;IACf,yEAAO,CAAA;IACP,iFAAW,CAAA;IACX,mGAAoB,CAAA;IACpB,2EAAQ,CAAA;IACR,6EAAS,CAAA;IACT,+EAAU,CAAA;IACV,+EAAU,CAAA;AACZ,CAAC,EAVW,0BAA0B,KAA1B,0BAA0B,QAUrC;AAED,MAAM,CAAN,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,mEAAU,CAAA;IACV,mEAAU,CAAA;AACZ,CAAC,EAHW,oBAAoB,KAApB,oBAAoB,QAG/B"}