mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Ensure clahe op uses random read, simplify validation
This commit is contained in:
parent
6c61ad256f
commit
0063df4d4f
@ -357,9 +357,9 @@ This will, in general, enhance the clarity of the image by bringing out darker d
|
|||||||
| Param | Type | Default | Description |
|
| Param | Type | Default | Description |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| options | <code>Object</code> | | |
|
| options | <code>Object</code> | | |
|
||||||
| options.width | <code>number</code> | | integer width of the region in pixels. |
|
| options.width | <code>number</code> | | Integral width of the search window, in pixels. |
|
||||||
| options.height | <code>number</code> | | integer height of the region in pixels. |
|
| options.height | <code>number</code> | | Integral height of the search window, 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.maxSlope] | <code>number</code> | <code>3</code> | Integral level of brightening, between 0 and 100, where 0 disables contrast limiting. |
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
|
@ -512,34 +512,33 @@ function normalize (normalize) {
|
|||||||
* .toBuffer();
|
* .toBuffer();
|
||||||
*
|
*
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @param {number} options.width - integer width of the region in pixels.
|
* @param {number} options.width - Integral width of the search window, in pixels.
|
||||||
* @param {number} options.height - integer height of the region in pixels.
|
* @param {number} options.height - Integral height of the search window, in pixels.
|
||||||
* @param {number} [options.maxSlope=3] - maximum value for the slope of the
|
* @param {number} [options.maxSlope=3] - Integral level of brightening, between 0 and 100, where 0 disables contrast limiting.
|
||||||
* cumulative histogram. A value of 0 disables contrast limiting. Valid values
|
|
||||||
* are integers in the range 0-100 (inclusive)
|
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
function clahe (options) {
|
function clahe (options) {
|
||||||
if (!is.plainObject(options)) {
|
if (is.plainObject(options)) {
|
||||||
throw is.invalidParameterError('options', 'plain object', options);
|
if (is.integer(options.width) && options.width > 0) {
|
||||||
}
|
|
||||||
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;
|
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 {
|
} else {
|
||||||
|
throw is.invalidParameterError('width', 'integer greater than zero', options.width);
|
||||||
|
}
|
||||||
|
if (is.integer(options.height) && options.height > 0) {
|
||||||
this.options.claheHeight = options.height;
|
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 {
|
} 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;
|
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);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -1659,6 +1659,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
baton->rotationAngle != 0.0 ||
|
baton->rotationAngle != 0.0 ||
|
||||||
baton->tileAngle != 0 ||
|
baton->tileAngle != 0 ||
|
||||||
baton->useExifOrientation ||
|
baton->useExifOrientation ||
|
||||||
|
baton->claheWidth != 0 ||
|
||||||
!baton->affineMatrix.empty()
|
!baton->affineMatrix.empty()
|
||||||
) {
|
) {
|
||||||
baton->input->access = VIPS_ACCESS_RANDOM;
|
baton->input->access = VIPS_ACCESS_RANDOM;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user