image-js
Version:
Image processing and manipulation in JavaScript
30 lines (29 loc) • 735 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = abs;
var _getOutputImage = require("../internal/getOutputImage");
/**
* Calculate the absolute values of an image.
* Only works on 32-bit images.
* @memberof Image
* @instance
* @param {object} [options]
* @param {boolean} [options.inPlace=false]
* @param {Image} [options.out]
* @return {Image}
*/
function abs(options = {}) {
this.checkProcessable('abs', {
bitDepth: [32]
});
const out = (0, _getOutputImage.getOutputImageOrInPlace)(this, options);
absolute(this, out);
return out;
}
function absolute(image, out) {
for (let i = 0; i < image.data.length; i++) {
out.data[i] = Math.abs(image.data[i]);
}
}