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

Function blur

plugins/plugin-blur/src/index.ts:46–172  ·  view source on GitHub ↗

* A fast blur algorithm that produces similar effect to a Gaussian blur - but MUCH quicker * @param r the pixel radius of the blur * @example * ```ts * import { Jimp } from "jimp"; * * const image = await Jimp.read("test/image.png"); * * image.blur(5); * ```

(image: I, r: number)

Source from the content-addressed store, hash-verified

44 * ```
45 */
46 blur<I extends JimpClass>(image: I, r: number) {
47 if (typeof r !== "number") {
48 throw new Error("r must be a number");
49 }
50
51 if (r < 1) {
52 throw new Error("r must be greater than 0");
53 }
54
55 let rsum: number;
56 let gsum: number;
57 let bsum: number;
58 let asum: number;
59 let x: number;
60 let y: number;
61 let i: number;
62 let p: number;
63 let p1: number;
64 let p2: number;
65 let yp: number;
66 let yi: number;
67 let yw: number;
68
69 const wm = image.bitmap.width - 1;
70 const hm = image.bitmap.height - 1;
71 // const wh = image.bitmap.width * image.bitmap.height;
72 const rad1 = r + 1;
73
74 const mulSum = mulTable[r]!;
75 const shgSum = shgTable[r]!;
76
77 const red = [];
78 const green = [];
79 const blue = [];
80 const alpha = [];
81
82 const vmin = [];
83 const vmax = [];
84
85 let iterations = 2;
86
87 while (iterations-- > 0) {
88 yi = 0;
89 yw = 0;
90
91 for (y = 0; y < image.bitmap.height; y++) {
92 rsum = image.bitmap.data[yw]! * rad1;
93 gsum = image.bitmap.data[yw + 1]! * rad1;
94 bsum = image.bitmap.data[yw + 2]! * rad1;
95 asum = image.bitmap.data[yw + 3]! * rad1;
96
97 for (i = 1; i <= r; i++) {
98 p = yw + ((i > wm ? wm : i) << 2);
99 rsum += image.bitmap.data[p++]!;
100 gsum += image.bitmap.data[p++]!;
101 bsum += image.bitmap.data[p++]!;
102 asum += image.bitmap.data[p]!;
103 }

Callers

nothing calls this directly

Calls 1

limit255Function · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…