-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tiler-sharp): support uint32 and uint8 source datasets for color…
…-ramp (#3391) ### Motivation We are getting datasets that have other datatypes than float32 that need to be expanded into 4 band RGBA so basemaps can render them. A common type is a one band `uint8` which is generally a grey scale dataset which can be directly band expanded from `0` to `r:0, g:0, b:0, alpha: 255` and `255` to `r:255, g:255, b:255, alpha: 255` ### Modifications Added support for `uint8` and `uint32` with the tiler piplines TODO: it would be nicer to handle the datatypes more generically, to hopefully avoid giant switch case statements, we should in theory be able to trust that lerc gives us the correct typed array for instance. ### Verification Added unit tests and rendered it locally ![image](https://github.com/user-attachments/assets/f8788700-b9d3-470c-a7d7-9aabe8067f0f)
- Loading branch information
Showing
5 changed files
with
148 additions
and
17 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
packages/tiler-sharp/src/pipeline/__tests__/pipeline.color.ramp.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import assert from 'node:assert'; | ||
import { describe, it } from 'node:test'; | ||
|
||
import { Tiff } from '@basemaps/shared'; | ||
import { CompositionTiff } from '@basemaps/tiler'; | ||
|
||
import { DecompressedInterleaved } from '../decompressor.js'; | ||
import { PipelineColorRamp } from '../pipeline.color.ramp.js'; | ||
|
||
const FakeTiff = { images: [{ noData: -9999, resolution: [0.1, -0.1] }] } as unknown as Tiff; | ||
const FakeComp = { asset: FakeTiff, source: { x: 0, y: 0, imageId: 0 } } as CompositionTiff; | ||
|
||
describe('pipeline.color-ramp', () => { | ||
it('should color-ramp a float32 DEM with default ramp', async () => { | ||
const bytes: DecompressedInterleaved = { | ||
pixels: new Float32Array([-9999, 0, 100]), | ||
depth: 'float32', | ||
channels: 1, | ||
width: 3, | ||
height: 1, | ||
}; | ||
|
||
const output = await PipelineColorRamp.process(FakeComp, bytes); | ||
|
||
assert.equal(output.channels, 4); | ||
|
||
assert.equal(String(output.pixels.slice(0, 4)), '0,0,0,0'); | ||
assert.equal(String(output.pixels.slice(4, 8)), '167,205,228,255'); | ||
}); | ||
|
||
it('should color-ramp a uint8', async () => { | ||
const bytes: DecompressedInterleaved = { | ||
pixels: new Uint8Array([0, 128, 255]), | ||
depth: 'uint8', | ||
channels: 1, | ||
width: 3, | ||
height: 1, | ||
}; | ||
|
||
const output = await PipelineColorRamp.process(FakeComp, bytes); | ||
|
||
assert.equal(output.channels, 4); | ||
|
||
assert.equal(String(output.pixels.slice(0, 4)), '0,0,0,255'); | ||
assert.equal(String(output.pixels.slice(4, 8)), '128,128,128,255'); | ||
assert.equal(String(output.pixels.slice(8, 12)), '255,255,255,255'); | ||
}); | ||
|
||
it('should color-ramp a uint32', async () => { | ||
const bytes: DecompressedInterleaved = { | ||
pixels: new Uint32Array([0, 2 ** 31, 2 ** 32 - 1]), | ||
depth: 'uint32', | ||
channels: 1, | ||
width: 3, | ||
height: 1, | ||
}; | ||
|
||
const output = await PipelineColorRamp.process(FakeComp, bytes); | ||
|
||
assert.equal(output.channels, 4); | ||
|
||
assert.equal(String(output.pixels.slice(0, 4)), '0,0,0,255'); | ||
assert.equal(String(output.pixels.slice(4, 8)), '128,128,128,255'); | ||
assert.equal(String(output.pixels.slice(8, 12)), '255,255,255,255'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters