-
-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
28 changed files
with
257 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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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,125 @@ | ||
'use strict'; | ||
|
||
const sharp = require('../../'); | ||
const assert = require('assert'); | ||
const fixtures = require('../fixtures'); | ||
|
||
describe('Modulate', function () { | ||
describe('Invalid options', function () { | ||
[ | ||
null, | ||
undefined, | ||
10, | ||
{ brightness: -1 }, | ||
{ brightness: '50%' }, | ||
{ brightness: null }, | ||
{ saturation: -1 }, | ||
{ saturation: '50%' }, | ||
{ saturation: null }, | ||
{ hue: '50deg' }, | ||
{ hue: 1.5 }, | ||
{ hue: null } | ||
].forEach(function (options) { | ||
it('should throw', function () { | ||
assert.throws(function () { | ||
sharp(fixtures.inputJpg).modulate(options); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should be able to hue-rotate', function () { | ||
const base = 'modulate-hue-120.jpg'; | ||
const actual = fixtures.path('output.' + base); | ||
const expected = fixtures.expected(base); | ||
|
||
return sharp(fixtures.inputJpg) | ||
.modulate({ hue: 120 }) | ||
.toFile(actual) | ||
.then(function () { | ||
fixtures.assertMaxColourDistance(actual, expected, 25); | ||
}); | ||
}); | ||
|
||
it('should be able to brighten', function () { | ||
const base = 'modulate-brightness-2.jpg'; | ||
const actual = fixtures.path('output.' + base); | ||
const expected = fixtures.expected(base); | ||
|
||
return sharp(fixtures.inputJpg) | ||
.modulate({ brightness: 2 }) | ||
.toFile(actual) | ||
.then(function () { | ||
fixtures.assertMaxColourDistance(actual, expected, 25); | ||
}); | ||
}); | ||
|
||
it('should be able to unbrighten', function () { | ||
const base = 'modulate-brightness-0-5.jpg'; | ||
const actual = fixtures.path('output.' + base); | ||
const expected = fixtures.expected(base); | ||
|
||
return sharp(fixtures.inputJpg) | ||
.modulate({ brightness: 0.5 }) | ||
.toFile(actual) | ||
.then(function () { | ||
fixtures.assertMaxColourDistance(actual, expected, 25); | ||
}); | ||
}); | ||
|
||
it('should be able to saturate', function () { | ||
const base = 'modulate-saturation-2.jpg'; | ||
const actual = fixtures.path('output.' + base); | ||
const expected = fixtures.expected(base); | ||
|
||
return sharp(fixtures.inputJpg) | ||
.modulate({ saturation: 2 }) | ||
.toFile(actual) | ||
.then(function () { | ||
fixtures.assertMaxColourDistance(actual, expected, 30); | ||
}); | ||
}); | ||
|
||
it('should be able to desaturate', function () { | ||
const base = 'modulate-saturation-0.5.jpg'; | ||
const actual = fixtures.path('output.' + base); | ||
const expected = fixtures.expected(base); | ||
|
||
return sharp(fixtures.inputJpg) | ||
.modulate({ saturation: 0.5 }) | ||
.toFile(actual) | ||
.then(function () { | ||
fixtures.assertMaxColourDistance(actual, expected, 25); | ||
}); | ||
}); | ||
|
||
it('should be able to modulate all channels', function () { | ||
const base = 'modulate-all.jpg'; | ||
const actual = fixtures.path('output.' + base); | ||
const expected = fixtures.expected(base); | ||
|
||
return sharp(fixtures.inputJpg) | ||
.modulate({ brightness: 2, saturation: 0.5, hue: 180 }) | ||
.toFile(actual) | ||
.then(function () { | ||
fixtures.assertMaxColourDistance(actual, expected, 25); | ||
}); | ||
}); | ||
|
||
describe('hue-rotate', function (done) { | ||
[30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 360].forEach(function (angle) { | ||
it('should properly hue rotate by ' + angle + 'deg', function () { | ||
const base = 'modulate-hue-angle-' + angle + '.png'; | ||
const actual = fixtures.path('output.' + base); | ||
const expected = fixtures.expected(base); | ||
|
||
return sharp(fixtures.testPattern) | ||
.modulate({ hue: angle }) | ||
.toFile(actual) | ||
.then(function () { | ||
fixtures.assertMaxColourDistance(actual, expected, 25); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |