Skip to content

Commit

Permalink
refactor: missing files clean up types
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha committed Jan 21, 2025
1 parent 76d8ad1 commit 5fc2994
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
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');
});
});
2 changes: 1 addition & 1 deletion packages/tiler-sharp/src/pipeline/pipeline.color.ramp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class ColorRamp {
export const Ramps: Record<DecompressedInterleaved['depth'], ColorRamp> = {
float32: new ColorRamp(DefaultColorRamp),
uint8: new ColorRamp(`0 0 0 0 255\n255 255 255 255 255`),
uint32: new ColorRamp(`0 0 0 0 255\n${2 ** 32} 255 255 255 255`),
uint32: new ColorRamp(`0 0 0 0 255\n${2 ** 32 - 1} 255 255 255 255`),
};

export const PipelineColorRamp: Pipeline = {
Expand Down
2 changes: 1 addition & 1 deletion packages/tiler-sharp/src/pipeline/pipeline.resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function resizeNearest(
return ret;
}

function getOutputBuffer(source: DecompressedInterleaved, target: Size & { scale: number }): DecompressedInterleaved {
function getOutputBuffer(source: DecompressedInterleaved, target: Size): DecompressedInterleaved {
switch (source.depth) {
case 'uint8':
return {
Expand Down

0 comments on commit 5fc2994

Please sign in to comment.