mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 15:25:07 +01:00
Expose linear transform feature of libvips (#1024)
This commit is contained in:
@@ -203,6 +203,8 @@ const Sharp = function (input, options) {
|
||||
tiffYres: 1.0,
|
||||
tileSize: 256,
|
||||
tileOverlap: 0,
|
||||
linearA: 1,
|
||||
linearB: 0,
|
||||
// Function to notify of libvips warnings
|
||||
debuglog: debuglog,
|
||||
// Function to notify of queue length changes
|
||||
|
||||
@@ -406,6 +406,33 @@ function boolean (operand, operator, options) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the linear formula a * input + b to the image (levels adjustment)
|
||||
* @param {Number} [a=1.0] multiplier
|
||||
* @param {Number} [b=0.0] offset
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function linear (a, b) {
|
||||
if (!is.defined(a)) {
|
||||
this.options.linearA = 1.0;
|
||||
} else if (is.number(a)) {
|
||||
this.options.linearA = a;
|
||||
} else {
|
||||
throw new Error('Invalid linear transform multiplier ' + a);
|
||||
}
|
||||
|
||||
if (!is.defined(b)) {
|
||||
this.options.linearB = 0.0;
|
||||
} else if (is.number(b)) {
|
||||
this.options.linearB = b;
|
||||
} else {
|
||||
throw new Error('Invalid linear transform offset ' + b);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorate the Sharp prototype with operation-related functions.
|
||||
* @private
|
||||
@@ -427,7 +454,8 @@ module.exports = function (Sharp) {
|
||||
normalize,
|
||||
convolve,
|
||||
threshold,
|
||||
boolean
|
||||
boolean,
|
||||
linear
|
||||
].forEach(function (f) {
|
||||
Sharp.prototype[f.name] = f;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user