Add lightness option to modulate operation

This commit is contained in:
Tenpi
2021-08-16 22:50:17 -04:00
committed by Lovell Fuller
parent 104464c2e0
commit 4a9267ce12
10 changed files with 62 additions and 13 deletions

View File

@@ -570,14 +570,16 @@ function recomb (inputMatrix) {
}
/**
* Transforms the image using brightness, saturation and hue rotation.
* Transforms the image using brightness, saturation, hue rotation, and lightness.
* Brightness and lightness both operate on luminance, with the difference being that
* brightness is multiplicative whereas lightness is additive.
*
* @since 0.22.1
*
* @example
* sharp(input)
* .modulate({
* brightness: 2 // increase lightness by a factor of 2
* brightness: 2 // increase brightness by a factor of 2
* });
*
* sharp(input)
@@ -585,6 +587,11 @@ function recomb (inputMatrix) {
* hue: 180 // hue-rotate by 180 degrees
* });
*
* sharp(input)
* .modulate({
* lightness: 50 // increase lightness by +50
* });
*
* // decreate brightness and saturation while also hue-rotating by 90 degrees
* sharp(input)
* .modulate({
@@ -597,6 +604,7 @@ function recomb (inputMatrix) {
* @param {number} [options.brightness] Brightness multiplier
* @param {number} [options.saturation] Saturation multiplier
* @param {number} [options.hue] Degrees for hue rotation
* @param {number} [options.lightness] Lightness addend
* @returns {Sharp}
*/
function modulate (options) {
@@ -624,6 +632,13 @@ function modulate (options) {
throw is.invalidParameterError('hue', 'number', options.hue);
}
}
if ('lightness' in options) {
if (is.number(options.lightness)) {
this.options.lightness = options.lightness;
} else {
throw is.invalidParameterError('lightness', 'number', options.lightness);
}
}
return this;
}