From ae6c70fb17086532ccc5a4fbbf61ff1a5d2b7dfa Mon Sep 17 00:00:00 2001 From: Brian Beck Date: Wed, 9 Oct 2024 20:07:30 -0700 Subject: [PATCH] Update README --- README.md | 21 +++++++++++++++++++++ src/index.ts | 17 +++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/README.md b/README.md index 7c8a4a5..a2fd5d9 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,18 @@ converted from arbitrary color to Turbo. The alpha channel is copied as-is. | ---------- | ---------- | | `convertColorBufferToTurbo` | `(buffer: ArrayBufferLike, targetBuffer?: ArrayBufferLike, options?: { cache: Map; }) => ArrayBufferLike` | +Parameters: + +* `buffer`: A buffer containing RGBA intensities, such as one backing +an ImageData instance. +* `targetBuffer`: A same-sized buffer to write converted RGBA intensities +to. If not provided, one will automatically be created. You can pass the +same buffer provided as input to convert in-place. +* `options.cache`: A Map to use as a lookup cache, to avoid repeated +nearest-neighbor searches. If not provided, a temporary one will be used +for each function call. + + ### :gear: convertGrayscaleBufferToTurbo Given an ArrayBuffer-like `buffer` containing RGBA intensities, return a new @@ -182,6 +194,15 @@ converted from grayscale to Turbo. The alpha channel is copied as-is. | ---------- | ---------- | | `convertGrayscaleBufferToTurbo` | `(buffer: ArrayBufferLike, targetBuffer?: ArrayBufferLike) => ArrayBufferLike` | +Parameters: + +* `buffer`: A buffer containing RGBA intensities, such as one backing +an ImageData instance. +* `targetBuffer`: A same-sized buffer to write converted RGBA intensities +to. If not provided, one will automatically be created. You can pass the +same buffer provided as input to convert in-place. + + ## :wrench: Constants diff --git a/src/index.ts b/src/index.ts index 0ae67c4..79c5283 100644 --- a/src/index.ts +++ b/src/index.ts @@ -228,6 +228,8 @@ export function grayscaleToTurbo(gray: Color) { /** * Convert a float in the range 0-1 to an integer in the range 0-255. This is * not specific to Turbo. + * + * @param value - A number in the range 0-1. */ function normalizedToIntensity(value: number): number { return Math.floor(value * 255); @@ -270,6 +272,15 @@ export function convertTurboBufferToGrayscale( * Given an ArrayBuffer-like `buffer` containing RGBA intensities, return a new * ArrayBuffer (or the provided `targetBuffer`) with the RGB pixel values * converted from arbitrary color to Turbo. The alpha channel is copied as-is. + * + * @param buffer A buffer containing RGBA intensities, such as one backing + * an ImageData instance. + * @param targetBuffer A same-sized buffer to write converted RGBA intensities + * to. If not provided, one will automatically be created. You can pass the + * same buffer provided as input to convert in-place. + * @param options.cache A Map to use as a lookup cache, to avoid repeated + * nearest-neighbor searches. If not provided, a temporary one will be used + * for each function call. */ export function convertColorBufferToTurbo( buffer: ArrayBufferLike, @@ -294,6 +305,12 @@ export function convertColorBufferToTurbo( * Given an ArrayBuffer-like `buffer` containing RGBA intensities, return a new * ArrayBuffer (or the provided `targetBuffer`) with the RGB pixel values * converted from grayscale to Turbo. The alpha channel is copied as-is. + * + * @param buffer A buffer containing RGBA intensities, such as one backing + * an ImageData instance. + * @param targetBuffer A same-sized buffer to write converted RGBA intensities + * to. If not provided, one will automatically be created. You can pass the + * same buffer provided as input to convert in-place. */ export function convertGrayscaleBufferToTurbo( buffer: ArrayBufferLike,