From 0063df4d4f345471a73a8e08cd73be18d432cfbb Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Tue, 28 Feb 2023 21:59:31 +0000 Subject: [PATCH] Ensure clahe op uses random read, simplify validation --- docs/api-operation.md | 6 +++--- lib/operation.js | 45 +++++++++++++++++++++---------------------- src/pipeline.cc | 1 + 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/docs/api-operation.md b/docs/api-operation.md index bfff981c..3f66ad67 100644 --- a/docs/api-operation.md +++ b/docs/api-operation.md @@ -357,9 +357,9 @@ This will, in general, enhance the clarity of the image by bringing out darker d | Param | Type | Default | Description | | --- | --- | --- | --- | | options | Object | | | -| options.width | number | | integer width of the region in pixels. | -| options.height | number | | integer height of the region in pixels. | -| [options.maxSlope] | number | 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) | +| options.width | number | | Integral width of the search window, in pixels. | +| options.height | number | | Integral height of the search window, in pixels. | +| [options.maxSlope] | number | 3 | Integral level of brightening, between 0 and 100, where 0 disables contrast limiting. | **Example** ```js diff --git a/lib/operation.js b/lib/operation.js index e14bd641..b94dd470 100644 --- a/lib/operation.js +++ b/lib/operation.js @@ -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; } diff --git a/src/pipeline.cc b/src/pipeline.cc index 63d2b982..7c0b3cd3 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -1659,6 +1659,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) { baton->rotationAngle != 0.0 || baton->tileAngle != 0 || baton->useExifOrientation || + baton->claheWidth != 0 || !baton->affineMatrix.empty() ) { baton->input->access = VIPS_ACCESS_RANDOM;