diff --git a/packages/plugin-color/src/index.js b/packages/plugin-color/src/index.js index 82489caa0..451bf2ce8 100644 --- a/packages/plugin-color/src/index.js +++ b/packages/plugin-color/src/index.js @@ -583,7 +583,7 @@ export default () => ({ * @param {number} w (optional) the width of the region to apply convolution to * @param {number} h (optional) the height of the region to apply convolution to * @param {function(Error, Jimp)} cb (optional) a callback for when complete - * @returns {Jimp }this for chaining of methods + * @returns {Jimp} this for chaining of methods */ convolute(kernel, x, y, w, h, cb) { if (!Array.isArray(kernel)) @@ -613,10 +613,8 @@ export default () => ({ } } - const ksize = (kernel.length - 1) / 2; - - x = isDef(x) ? x : ksize; - y = isDef(y) ? y : ksize; + x = isDef(x) ? x : 0; + y = isDef(y) ? y : 0; w = isDef(w) ? w : this.bitmap.width - x; h = isDef(h) ? h : this.bitmap.height - y; diff --git a/packages/plugin-color/test/convolution.test.js b/packages/plugin-color/test/convolution.test.js index 428ae52f3..e7abca10b 100644 --- a/packages/plugin-color/test/convolution.test.js +++ b/packages/plugin-color/test/convolution.test.js @@ -57,6 +57,12 @@ describe("Convolution", function () { [0, 1, 1], ]; + const blurM = [ + [1 / 9, 1 / 9, 1 / 9], + [1 / 9, 1 / 9, 1 / 9], + [1 / 9, 1 / 9, 1 / 9], + ]; + it("3x3 sharp matrix on EDGE_EXTEND", (done) => { expectToBeJGD( imgMid.clone().convolution(sharpM).getJGDSync(), @@ -150,6 +156,16 @@ describe("Convolution", function () { done(); }); + it("3x3 box blur matrix using convolute", async () => { + const expectedImg = await jimp.read( + getTestDir(__dirname) + "/images/tiles-blurred.png" + ); + + const image = await jimp.read(getTestDir(__dirname) + "/images/tiles.jpg"); + + expect(image.convolute(blurM).bitmap.data).toEqual(expectedImg.bitmap.data); + }); + it("new pixel value is greater than 255", async () => { const expectedImg = await jimp.read( getTestDir(__dirname) + "/images/qr-convoluted.png" diff --git a/packages/plugin-color/test/images/tiles-blurred.png b/packages/plugin-color/test/images/tiles-blurred.png new file mode 100644 index 000000000..5b3da9b69 Binary files /dev/null and b/packages/plugin-color/test/images/tiles-blurred.png differ diff --git a/packages/plugin-color/test/images/tiles.jpg b/packages/plugin-color/test/images/tiles.jpg new file mode 100644 index 000000000..538c77e45 Binary files /dev/null and b/packages/plugin-color/test/images/tiles.jpg differ