-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add convolve operation for kernel-based convolution (#479)
- Loading branch information
Showing
12 changed files
with
202 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
'use strict'; | ||
|
||
var assert = require('assert'); | ||
|
||
var sharp = require('../../index'); | ||
var fixtures = require('../fixtures'); | ||
|
||
describe('Convolve', function() { | ||
|
||
it('specific convolution kernel 1', function(done) { | ||
sharp(fixtures.inputPngStripesV) | ||
.resize(320, 240) | ||
.convolve( | ||
{ | ||
'width': 3, | ||
'height': 3, | ||
'scale': 50, | ||
'offset': 0, | ||
'kernel': [ 10, 20, 10, | ||
0, 0, 0, | ||
10, 20, 10 ] | ||
}) | ||
.toBuffer(function(err, data, info) { | ||
assert.strictEqual('png', info.format); | ||
assert.strictEqual(320, info.width); | ||
assert.strictEqual(240, info.height); | ||
fixtures.assertSimilar(fixtures.expected('conv-1.png'), data, done); | ||
}); | ||
}); | ||
|
||
it('specific convolution kernel 2', function(done) { | ||
sharp(fixtures.inputPngStripesH) | ||
.resize(320, 240) | ||
.convolve( | ||
{ | ||
'width': 3, | ||
'height': 3, | ||
'kernel': [ 1, 0, 1, | ||
2, 0, 2, | ||
1, 0, 1 ] | ||
}) | ||
.toBuffer(function(err, data, info) { | ||
assert.strictEqual('png', info.format); | ||
assert.strictEqual(320, info.width); | ||
assert.strictEqual(240, info.height); | ||
fixtures.assertSimilar(fixtures.expected('conv-2.png'), data, done); | ||
}); | ||
}); | ||
|
||
it('invalid kernel specification: no data', function() { | ||
assert.throws(function() { | ||
sharp(fixtures.inputJpg).convolve( | ||
{ | ||
'width': 3, | ||
'height': 3, | ||
'kernel': [] | ||
}); | ||
}); | ||
}); | ||
|
||
it('invalid kernel specification: bad data format', function() { | ||
assert.throws(function() { | ||
sharp(fixtures.inputJpg).convolve( | ||
{ | ||
'width': 3, | ||
'height': 3, | ||
'kernel': [[1, 2, 3], [4, 5, 6], [7, 8, 9]] | ||
}); | ||
}); | ||
}); | ||
|
||
it('invalid kernel specification: wrong width', function() { | ||
assert.throws(function() { | ||
sharp(fixtures.inputJpg).convolve( | ||
{ | ||
'width': 3, | ||
'height': 4, | ||
'kernel': [1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
}); | ||
}); | ||
}); | ||
}); |