@@ -185,40 +185,105 @@ function affine (matrix, options) {
185185 * When a `sigma` is provided, performs a slower, more accurate sharpen of the L channel in the LAB colour space.
186186 * Separate control over the level of sharpening in "flat" and "jagged" areas is available.
187187 *
188- * @param {number } [sigma] - the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
189- * @param {number } [flat=1.0] - the level of sharpening to apply to "flat" areas.
190- * @param {number } [jagged=2.0] - the level of sharpening to apply to "jagged" areas.
188+ * See {@link https://www.libvips.org/API/current/libvips-convolution.html#vips-sharpen|libvips sharpen} operation.
189+ *
190+ * @example
191+ * const data = await sharp(input).sharpen().toBuffer();
192+ *
193+ * @example
194+ * const data = await sharp(input).sharpen({ sigma: 2 }).toBuffer();
195+ *
196+ * @example
197+ * const data = await sharp(input)
198+ * .sharpen({
199+ * sigma: 2,
200+ * m1: 0
201+ * m2: 3,
202+ * x1: 3,
203+ * y2: 15,
204+ * y3: 15,
205+ * })
206+ * .toBuffer();
207+ *
208+ * @param {Object } [options] - if present, is an Object with optional attributes.
209+ * @param {number } [options.sigma] - the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
210+ * @param {number } [options.m1=1.0] - the level of sharpening to apply to "flat" areas.
211+ * @param {number } [options.m2=2.0] - the level of sharpening to apply to "jagged" areas.
212+ * @param {number } [options.x1=2.0] - threshold between "flat" and "jagged"
213+ * @param {number } [options.y2=10.0] - maximum amount of brightening.
214+ * @param {number } [options.y3=20.0] - maximum amount of darkening.
191215 * @returns {Sharp }
192216 * @throws {Error } Invalid parameters
193217 */
194- function sharpen ( sigma , flat , jagged ) {
195- if ( ! is . defined ( sigma ) ) {
218+ function sharpen ( options ) {
219+ if ( ! is . defined ( options ) ) {
196220 // No arguments: default to mild sharpen
197221 this . options . sharpenSigma = - 1 ;
198- } else if ( is . bool ( sigma ) ) {
199- // Boolean argument: apply mild sharpen?
200- this . options . sharpenSigma = sigma ? - 1 : 0 ;
201- } else if ( is . number ( sigma ) && is . inRange ( sigma , 0.01 , 10000 ) ) {
202- // Numeric argument: specific sigma
203- this . options . sharpenSigma = sigma ;
204- // Control over flat areas
205- if ( is . defined ( flat ) ) {
206- if ( is . number ( flat ) && is . inRange ( flat , 0 , 10000 ) ) {
207- this . options . sharpenFlat = flat ;
222+ } else if ( is . bool ( options ) ) {
223+ // Deprecated boolean argument: apply mild sharpen?
224+ this . options . sharpenSigma = options ? - 1 : 0 ;
225+ } else if ( is . number ( options ) && is . inRange ( options , 0.01 , 10000 ) ) {
226+ // Deprecated numeric argument: specific sigma
227+ this . options . sharpenSigma = options ;
228+ // Deprecated control over flat areas
229+ if ( is . defined ( arguments [ 1 ] ) ) {
230+ if ( is . number ( arguments [ 1 ] ) && is . inRange ( arguments [ 1 ] , 0 , 10000 ) ) {
231+ this . options . sharpenM1 = arguments [ 1 ] ;
232+ } else {
233+ throw is . invalidParameterError ( 'flat' , 'number between 0 and 10000' , arguments [ 1 ] ) ;
234+ }
235+ }
236+ // Deprecated control over jagged areas
237+ if ( is . defined ( arguments [ 2 ] ) ) {
238+ if ( is . number ( arguments [ 2 ] ) && is . inRange ( arguments [ 2 ] , 0 , 10000 ) ) {
239+ this . options . sharpenM2 = arguments [ 2 ] ;
240+ } else {
241+ throw is . invalidParameterError ( 'jagged' , 'number between 0 and 10000' , arguments [ 2 ] ) ;
242+ }
243+ }
244+ } else if ( is . plainObject ( options ) ) {
245+ if ( is . number ( options . sigma ) && is . inRange ( options . sigma , 0.01 , 10000 ) ) {
246+ this . options . sharpenSigma = options . sigma ;
247+ } else {
248+ throw is . invalidParameterError ( 'options.sigma' , 'number between 0.01 and 10000' , options . sigma ) ;
249+ }
250+ if ( is . defined ( options . m1 ) ) {
251+ if ( is . number ( options . m1 ) && is . inRange ( options . m1 , 0 , 10000 ) ) {
252+ this . options . sharpenM1 = options . m1 ;
253+ } else {
254+ throw is . invalidParameterError ( 'options.m1' , 'number between 0 and 10000' , options . m1 ) ;
255+ }
256+ }
257+ if ( is . defined ( options . m2 ) ) {
258+ if ( is . number ( options . m2 ) && is . inRange ( options . m2 , 0 , 10000 ) ) {
259+ this . options . sharpenM2 = options . m2 ;
260+ } else {
261+ throw is . invalidParameterError ( 'options.m2' , 'number between 0 and 10000' , options . m2 ) ;
262+ }
263+ }
264+ if ( is . defined ( options . x1 ) ) {
265+ if ( is . number ( options . x1 ) && is . inRange ( options . x1 , 0 , 10000 ) ) {
266+ this . options . sharpenX1 = options . x1 ;
267+ } else {
268+ throw is . invalidParameterError ( 'options.x1' , 'number between 0 and 10000' , options . x1 ) ;
269+ }
270+ }
271+ if ( is . defined ( options . y2 ) ) {
272+ if ( is . number ( options . y2 ) && is . inRange ( options . y2 , 0 , 10000 ) ) {
273+ this . options . sharpenY2 = options . y2 ;
208274 } else {
209- throw is . invalidParameterError ( 'flat ' , 'number between 0 and 10000' , flat ) ;
275+ throw is . invalidParameterError ( 'options.y2 ' , 'number between 0 and 10000' , options . y2 ) ;
210276 }
211277 }
212- // Control over jagged areas
213- if ( is . defined ( jagged ) ) {
214- if ( is . number ( jagged ) && is . inRange ( jagged , 0 , 10000 ) ) {
215- this . options . sharpenJagged = jagged ;
278+ if ( is . defined ( options . y3 ) ) {
279+ if ( is . number ( options . y3 ) && is . inRange ( options . y3 , 0 , 10000 ) ) {
280+ this . options . sharpenY3 = options . y3 ;
216281 } else {
217- throw is . invalidParameterError ( 'jagged ' , 'number between 0 and 10000' , jagged ) ;
282+ throw is . invalidParameterError ( 'options.y3 ' , 'number between 0 and 10000' , options . y3 ) ;
218283 }
219284 }
220285 } else {
221- throw is . invalidParameterError ( 'sigma' , 'number between 0.01 and 10000' , sigma ) ;
286+ throw is . invalidParameterError ( 'sigma' , 'number between 0.01 and 10000' , options ) ;
222287 }
223288 return this ;
224289}
0 commit comments