* Apply a ordered dithering effect. * @example * ```ts * import { Jimp } from "jimp"; * * const image = await Jimp.read("test/image.png"); * * image.dither(); * ```
(image: I)
| 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 | }; |
nothing calls this directly
no test coverage detected
searching dependent graphs…