Image Processing
Image Methods
b8.Image.ditherOrdered(imageData, mapFn [,opts])
Ordered dithering (Bayer). Biases colour before quantising.
- imageData: ImageData (modified in-place)
- mapFn: (r,g,b) -> {r,g,b}
- opts:
- size: 2 | 4 | 8 (matrix size)
- strength: 0..1 (scales the bias)
- amplitude: number (max per-channel bias in 0..255)
Parameters
- imageData (ImageData): The ImageData to dither.
- mapFn (function): The function to map RGB values to the nearest palette color.
- [opts] (object): The options for dithering. (default: {})
Returns
- (ImageData): The dithered ImageData.
b8.Image.findClosestColorUsingLookup(r, g, b, palette)
Finds the closest color in the palette to the given RGB values.
Parameters
- r (number): The red component (0-255).
- g (number): The green component (0-255).
- b (number): The blue component (0-255).
- palette (string[]): The color palette (array of hex strings).
Returns
- (string): The closest color in hex format.
b8.Image.generateColorLookupTable(palette [,bucketSize])
Generates a color lookup table for the given palette.
Parameters
- palette (string[]): The color palette (array of hex strings).
- [bucketSize] (number): The size of the color buckets. (default: 4)
Returns
- (object): The color lookup table.
b8.Image.loadImageAsync(src) async
Loads an image asynchronously.
Parameters
- src (string): The source URL of the image.
Returns
- (Promise<HTMLImageElement>): A promise that resolves to the loaded image.
b8.Image.quantiseImageData(imageData, lookupTable)
Quantise an ImageData in-place to a palette (no dithering). Returns the same ImageData for chaining.
Parameters
- imageData (ImageData): The ImageData to quantise.
- lookupTable (object): The color lookup table.
Returns
- (ImageData): The quantised ImageData.