MCPcopy
hub / github.com/jimp-dev/jimp / dither

Function dither

plugins/plugin-dither/src/index.ts:15–36  ·  view source on GitHub ↗

* Apply a ordered dithering effect. * @example * ```ts * import { Jimp } from "jimp"; * * const image = await Jimp.read("test/image.png"); * * image.dither(); * ```

(image: I)

Source from the content-addressed store, hash-verified

13 * ```
14 */
15 dither<I extends JimpClass>(image: I) {
16 const rgb565Matrix = [
17 1, 9, 3, 11, 13, 5, 15, 7, 4, 12, 2, 10, 16, 8, 14, 6,
18 ];
19
20 image.scan((x, y, idx) => {
21 const thresholdId = ((y & 3) << 2) + (x % 4);
22 const dither = rgb565Matrix[thresholdId]!;
23
24 image.bitmap.data[idx] = Math.min(image.bitmap.data[idx]! + dither, 0xff);
25 image.bitmap.data[idx + 1] = Math.min(
26 image.bitmap.data[idx + 1]! + dither,
27 0xff,
28 );
29 image.bitmap.data[idx + 2] = Math.min(
30 image.bitmap.data[idx + 2]! + dither,
31 0xff,
32 );
33 });
34
35 return image;
36 },
37};

Callers

nothing calls this directly

Calls 1

scanMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…