* Apply a posterize effect * @param n the amount to adjust the contrast, minimum threshold is two * @example * ```ts * import { Jimp } from "jimp"; * * const image = await Jimp.read("test/image.png"); * * image.posterize(5); * ```
(image: I, n: number)
| 411 | * ``` |
| 412 | */ |
| 413 | posterize<I extends JimpClass>(image: I, n: number) { |
| 414 | if (typeof n !== "number") { |
| 415 | throw new Error("n must be numbers"); |
| 416 | } |
| 417 | |
| 418 | // minimum of 2 levels |
| 419 | if (n < 2) { |
| 420 | n = 2; |
| 421 | } |
| 422 | |
| 423 | image.scan((_, __, idx) => { |
| 424 | const r = image.bitmap.data[idx]!; |
| 425 | const g = image.bitmap.data[idx + 1]!; |
| 426 | const b = image.bitmap.data[idx + 2]!; |
| 427 | |
| 428 | image.bitmap.data[idx] = |
| 429 | (Math.floor((r / 255) * (n - 1)) / (n - 1)) * 255; |
| 430 | image.bitmap.data[idx + 1] = |
| 431 | (Math.floor((g / 255) * (n - 1)) / (n - 1)) * 255; |
| 432 | image.bitmap.data[idx + 2] = |
| 433 | (Math.floor((b / 255) * (n - 1)) / (n - 1)) * 255; |
| 434 | }); |
| 435 | |
| 436 | return image; |
| 437 | }, |
| 438 | |
| 439 | /** |
| 440 | * Removes colour from the image using ITU Rec 709 luminance values |
nothing calls this directly
no test coverage detected
searching dependent graphs…