mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Ensure clahe op uses random read, simplify validation
This commit is contained in:
@@ -512,35 +512,34 @@ function normalize (normalize) {
|
||||
* .toBuffer();
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {number} options.width - integer width of the region in pixels.
|
||||
* @param {number} options.height - integer height of the region in pixels.
|
||||
* @param {number} [options.maxSlope=3] - maximum value for the slope of the
|
||||
* cumulative histogram. A value of 0 disables contrast limiting. Valid values
|
||||
* are integers in the range 0-100 (inclusive)
|
||||
* @param {number} options.width - Integral width of the search window, in pixels.
|
||||
* @param {number} options.height - Integral height of the search window, in pixels.
|
||||
* @param {number} [options.maxSlope=3] - Integral level of brightening, between 0 and 100, where 0 disables contrast limiting.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function clahe (options) {
|
||||
if (!is.plainObject(options)) {
|
||||
if (is.plainObject(options)) {
|
||||
if (is.integer(options.width) && options.width > 0) {
|
||||
this.options.claheWidth = options.width;
|
||||
} else {
|
||||
throw is.invalidParameterError('width', 'integer greater than zero', options.width);
|
||||
}
|
||||
if (is.integer(options.height) && options.height > 0) {
|
||||
this.options.claheHeight = options.height;
|
||||
} else {
|
||||
throw is.invalidParameterError('height', 'integer greater than zero', options.height);
|
||||
}
|
||||
if (is.defined(options.maxSlope)) {
|
||||
if (is.integer(options.maxSlope) && is.inRange(options.maxSlope, 0, 100)) {
|
||||
this.options.claheMaxSlope = options.maxSlope;
|
||||
} else {
|
||||
throw is.invalidParameterError('maxSlope', 'integer between 0 and 100', options.maxSlope);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw is.invalidParameterError('options', 'plain object', options);
|
||||
}
|
||||
if (!('width' in options) || !is.integer(options.width) || options.width <= 0) {
|
||||
throw is.invalidParameterError('width', 'integer above zero', options.width);
|
||||
} else {
|
||||
this.options.claheWidth = options.width;
|
||||
}
|
||||
if (!('height' in options) || !is.integer(options.height) || options.height <= 0) {
|
||||
throw is.invalidParameterError('height', 'integer above zero', options.height);
|
||||
} else {
|
||||
this.options.claheHeight = options.height;
|
||||
}
|
||||
if (!is.defined(options.maxSlope)) {
|
||||
this.options.claheMaxSlope = 3;
|
||||
} else if (!is.integer(options.maxSlope) || options.maxSlope < 0 || options.maxSlope > 100) {
|
||||
throw is.invalidParameterError('maxSlope', 'integer 0-100', options.maxSlope);
|
||||
} else {
|
||||
this.options.claheMaxSlope = options.maxSlope;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user