Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
exogen committed Oct 10, 2024
1 parent 48c89b7 commit aa11438
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -78,17 +78,17 @@ nearest-neighbor search.

| Function | Type |
| ---------- | ---------- |
| `snapToTurbo` | `(rgbColor: Color, cache?: Map<string, number> or undefined) => Uint8ClampedArray` |
| `snapColorToTurbo` | `(rgbColor: Color, cache?: Map<string, number> 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
value.

| Function | Type |
| ---------- | ---------- |
| `snapToIntensity` | `(rgbColor: Color, cache?: Map<string, number> or undefined) => number` |
| `snapColorToIntensity` | `(rgbColor: Color, cache?: Map<string, number> or undefined) => number` |

### :gear: snapNormalizedToTurbo

Expand Down
13 changes: 7 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number>) {
const index = snapToIntensity(rgbColor, cache);
export function snapColorToTurbo(rgbColor: Color, cache?: Map<string, number>) {
const index = snapColorToIntensity(rgbColor, cache);
return rgbColormap[index];
}

Expand All @@ -158,7 +158,7 @@ export function snapToTurbo(rgbColor: Color, cache?: Map<string, number>) {
* Turbo color. This index can also be used directly as a grayscale intensity
* value.
*/
export function snapToIntensity(
export function snapColorToIntensity(
rgbColor: Color,
cache?: Map<string, number>
): number {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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];
Expand Down

0 comments on commit aa11438

Please sign in to comment.