Test/node_modules/pica/lib/mathlib.js
2026-04-09 22:54:00 +07:00

57 lines
1.1 KiB
JavaScript

// Collection of math functions
//
// 1. Combine components together
// 2. Has async init to load wasm modules
//
'use strict';
const inherits = require('inherits');
const Multimath = require('multimath');
const mm_unsharp_mask = require('./mm_unsharp_mask');
const mm_resize = require('./mm_resize');
function MathLib(requested_features) {
const __requested_features = requested_features || [];
let features = {
js: __requested_features.indexOf('js') >= 0,
wasm: __requested_features.indexOf('wasm') >= 0
};
Multimath.call(this, features);
this.features = {
js: features.js,
wasm: features.wasm && this.has_wasm()
};
this.use(mm_unsharp_mask);
this.use(mm_resize);
}
inherits(MathLib, Multimath);
MathLib.prototype.resizeAndUnsharp = function resizeAndUnsharp(options, cache) {
let result = this.resize(options, cache);
if (options.unsharpAmount) {
this.unsharp_mask(
result,
options.toWidth,
options.toHeight,
options.unsharpAmount,
options.unsharpRadius,
options.unsharpThreshold
);
}
return result;
};
module.exports = MathLib;