mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Allow separate parameters for gamma encoding and decoding (#1439)
This commit is contained in:
@@ -189,12 +189,13 @@ function flatten (options) {
|
||||
* then increasing the encoding (brighten) post-resize at a factor of `gamma`.
|
||||
* This can improve the perceived brightness of a resized image in non-linear colour spaces.
|
||||
* JPEG and WebP input images will not take advantage of the shrink-on-load performance optimisation
|
||||
* when applying a gamma correction.
|
||||
* when applying a gamma correction. Supply a second argument to use a different output gamma value, otherwise the first value is used in both cases.
|
||||
* @param {Number} [gamma=2.2] value between 1.0 and 3.0.
|
||||
* @param {Number} [gammaOut] value between 1.0 and 3.0. Defaults to same as gamma.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function gamma (gamma) {
|
||||
function gamma (gamma, gammaOut) {
|
||||
if (!is.defined(gamma)) {
|
||||
// Default gamma correction of 2.2 (sRGB)
|
||||
this.options.gamma = 2.2;
|
||||
@@ -203,6 +204,14 @@ function gamma (gamma) {
|
||||
} else {
|
||||
throw new Error('Invalid gamma correction (1.0 to 3.0) ' + gamma);
|
||||
}
|
||||
if (!is.defined(gammaOut)) {
|
||||
// Default gamma correction for output is same as input
|
||||
this.options.gammaOut = this.options.gamma;
|
||||
} else if (is.number(gammaOut) && is.inRange(gammaOut, 1, 3)) {
|
||||
this.options.gammaOut = gammaOut;
|
||||
} else {
|
||||
throw new Error('Invalid post gamma correction (1.0 to 3.0) ' + gammaOut);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user