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

Function convolute

plugins/plugin-color/src/index.ts:751–775  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

cloneFunction · 0.90
scanFunction · 0.90
limit255Function · 0.90
applyKernelFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…