Skip to content

Commit

Permalink
Ensure clahe op uses random read, simplify validation
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Feb 28, 2023
1 parent 6c61ad2 commit 0063df4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions docs/api-operation.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,9 @@ This will, in general, enhance the clarity of the image by bringing out darker d
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| options | <code>Object</code> | | |
| options.width | <code>number</code> | | integer width of the region in pixels. |
| options.height | <code>number</code> | | integer height of the region in pixels. |
| [options.maxSlope] | <code>number</code> | <code>3</code> | 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 | <code>number</code> | | Integral width of the search window, in pixels. |
| options.height | <code>number</code> | | Integral height of the search window, in pixels. |
| [options.maxSlope] | <code>number</code> | <code>3</code> | Integral level of brightening, between 0 and 100, where 0 disables contrast limiting. |

**Example**
```js
Expand Down
45 changes: 22 additions & 23 deletions lib/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,34 +512,33 @@ 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)) {
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);
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 {
this.options.claheMaxSlope = options.maxSlope;
throw is.invalidParameterError('options', 'plain object', options);
}
return this;
}
Expand Down
1 change: 1 addition & 0 deletions src/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0063df4

Please sign in to comment.