* Applies a convolution kernel to the image or a region * @example * ```ts * import { Jimp } from "jimp"; * * const image = await Jimp.read("test/image.png"); * * // apply a convolution kernel to the whole image * image.convolution([ * [-1, -1, 0], * [-1, 1, 1],
(image: I, options: ConvoluteOptions)
| 749 | * ``` |
| 750 | */ |
| 751 | convolute<I extends JimpClass>(image: I, options: ConvoluteOptions) { |
| 752 | const parsed = ConvoluteOptionsSchema.parse(options); |
| 753 | const { |
| 754 | kernel, |
| 755 | x = 0, |
| 756 | y = 0, |
| 757 | w = image.bitmap.width - x, |
| 758 | h = image.bitmap.height - y, |
| 759 | } = "kernel" in parsed |
| 760 | ? parsed |
| 761 | : ({ kernel: parsed } as ConvoluteComplexOptions); |
| 762 | |
| 763 | const source = clone(image); |
| 764 | |
| 765 | scan(source, x, y, w, h, (xx, yx, idx) => { |
| 766 | const value = applyKernel(source, kernel, xx, yx); |
| 767 | |
| 768 | image.bitmap.data[idx] = limit255(value[0]!); |
| 769 | image.bitmap.data[idx + 1] = limit255(value[1]!); |
| 770 | image.bitmap.data[idx + 2] = limit255(value[2]!); |
| 771 | image.bitmap.data[idx + 3] = limit255(value[3]!); |
| 772 | }); |
| 773 | |
| 774 | return image; |
| 775 | }, |
| 776 | |
| 777 | /** |
| 778 | * Apply multiple color modification rules |
nothing calls this directly
no test coverage detected
searching dependent graphs…