diff --git a/README.md b/README.md index 964aa3a..ff2392b 100644 --- a/README.md +++ b/README.md @@ -49,8 +49,8 @@ This library has helpers for performing these tasks and more. ## :toolbox: Functions - [intensityToTurbo](#gear-intensitytoturbo) -- [snapToTurbo](#gear-snaptoturbo) -- [snapToIntensity](#gear-snaptointensity) +- [snapColorToTurbo](#gear-snapcolortoturbo) +- [snapColorToIntensity](#gear-snapcolortointensity) - [snapNormalizedToTurbo](#gear-snapnormalizedtoturbo) - [interpolateNormalizedToTurbo](#gear-interpolatenormalizedtoturbo) - [grayscaleToTurbo](#gear-grayscaletoturbo) @@ -67,7 +67,7 @@ simple lookup by array index. | ---------- | ---------- | | `intensityToTurbo` | `(value: number) => Color` | -### :gear: snapToTurbo +### :gear: snapColorToTurbo Accepts an arbitrary RGB triplet and returns the nearest color (by Euclidian distance) in the Turbo colormap. There is no interpolation; one of the 256 @@ -78,9 +78,9 @@ nearest-neighbor search. | Function | Type | | ---------- | ---------- | -| `snapToTurbo` | `(rgbColor: Color, cache?: Map or undefined) => Uint8ClampedArray` | +| `snapColorToTurbo` | `(rgbColor: Color, cache?: Map or undefined) => Uint8ClampedArray` | -### :gear: snapToIntensity +### :gear: snapColorToIntensity Accepts an arbitrary RGB triplet and returns the index (0-255) of the nearest Turbo color. This index can also be used directly as a grayscale intensity @@ -88,7 +88,7 @@ value. | Function | Type | | ---------- | ---------- | -| `snapToIntensity` | `(rgbColor: Color, cache?: Map or undefined) => number` | +| `snapColorToIntensity` | `(rgbColor: Color, cache?: Map or undefined) => number` | ### :gear: snapNormalizedToTurbo diff --git a/src/index.ts b/src/index.ts index c8759e5..c409ca9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -148,8 +148,8 @@ export function intensityToTurbo(value: number): Color { * For performance, this uses a pre-initialized k-d tree to perform * nearest-neighbor search. */ -export function snapToTurbo(rgbColor: Color, cache?: Map) { - const index = snapToIntensity(rgbColor, cache); +export function snapColorToTurbo(rgbColor: Color, cache?: Map) { + const index = snapColorToIntensity(rgbColor, cache); return rgbColormap[index]; } @@ -158,7 +158,7 @@ export function snapToTurbo(rgbColor: Color, cache?: Map) { * Turbo color. This index can also be used directly as a grayscale intensity * value. */ -export function snapToIntensity( +export function snapColorToIntensity( rgbColor: Color, cache?: Map ): number { @@ -226,7 +226,8 @@ export function grayscaleToTurbo(gray: Color) { } /** - * Convert a float in the range 0-1 to an integer in the range 0-255. + * Convert a float in the range 0-1 to an integer in the range 0-255. This is + * not specific to Turbo. */ function normalizedToIntensity(value: number): number { return Math.floor(value * 255); @@ -247,7 +248,7 @@ export function convertTurboBufferToGrayscale( const targetArray = new Uint8ClampedArray(targetBuffer); for (let i = 0; i < len; i += 4) { const color = new Uint8ClampedArray(buffer, i, 4); - const intensity = snapToIntensity(color, cache); + const intensity = snapColorToIntensity(color, cache); targetArray[i] = intensity; targetArray[i + 1] = intensity; targetArray[i + 2] = intensity; @@ -269,7 +270,7 @@ export function convertColorBufferToTurbo( const targetArray = new Uint8ClampedArray(targetBuffer); for (let i = 0; i < len; i += 4) { const color = new Uint8ClampedArray(buffer, i, 4); - const turboColor = snapToTurbo(color); + const turboColor = snapColorToTurbo(color); targetArray[i] = turboColor[0]; targetArray[i + 1] = turboColor[1]; targetArray[i + 2] = turboColor[2];