Skip to content

Commit

Permalink
fix(filters): ISSUE-6072 convolution filter is off by one (#6088)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfinck authored and asturur committed Jan 12, 2020
1 parent 3f10839 commit f8e4529
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/filters/convolute_filter.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
scx = x + cx - halfSide;

// eslint-disable-next-line max-depth
if (scy < 0 || scy > sh || scx < 0 || scx > sw) {
if (scy < 0 || scy >= sh || scx < 0 || scx >= sw) {
continue;
}

Expand Down
34 changes: 34 additions & 0 deletions test/unit/image_filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,40 @@
assert.ok(typeof filter.applyTo2d === 'function');
});

QUnit.test('applyTo2d values', function(assert) {
var filter = new fabric.Image.filters.Convolute({
matrix: [
0, 1, 0,
1, 2, 1,
0, 1, 0,
]
});
var pixelData = new Uint8Array([ // eslint-disable-line no-undef
0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255,
0, 0, 0, 255, 1, 2, 3, 255, 0, 0, 0, 255,
0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255,
]);
var expected = new Uint8Array([ // eslint-disable-line no-undef
0, 0, 0, 255, 1, 2, 3, 255, 0, 0, 0, 255,
1, 2, 3, 255, 2, 4, 6, 255, 1, 2, 3, 255,
0, 0, 0, 255, 1, 2, 3, 255, 0, 0, 0, 255,
]);
var imageData = context.createImageData(3, 3);
pixelData.forEach(function(el, i) {
imageData.data[i] = el;
});
var outCanvas = fabric.document.createElement('canvas');
var options = {
imageData: imageData,
ctx: outCanvas.getContext('2d'),
};
filter.applyTo2d(options);
var data = options.imageData.data;
data.forEach(function(el, i) {
assert.equal(el, expected[i]);
});
});

QUnit.test('toObject', function(assert) {
var filter = new fabric.Image.filters.Convolute({opaque: 1});
assert.ok(typeof filter.toObject === 'function');
Expand Down

0 comments on commit f8e4529

Please sign in to comment.