Path: blob/master/node_modules/@jimp/plugin-threshold/es/index.js
1126 views
"use strict";12Object.defineProperty(exports, "__esModule", {3value: true4});5exports["default"] = void 0;67var _utils = require("@jimp/utils");89/**10* Applies a minimum color threshold to a greyscale image. Converts image to greyscale by default11* @param {number} options object12* max: A number auto limited between 0 - 25513* replace: (optional) A number auto limited between 0 - 255 (default 255)14* autoGreyscale: (optional) A boolean whether to apply greyscale beforehand (default true)15* @param {number} cb (optional) a callback for when complete16* @return {this} this for chaining of methods17*/18var _default = function _default() {19return {20threshold: function threshold(_ref, cb) {21var _this = this;2223var max = _ref.max,24_ref$replace = _ref.replace,25replace = _ref$replace === void 0 ? 255 : _ref$replace,26_ref$autoGreyscale = _ref.autoGreyscale,27autoGreyscale = _ref$autoGreyscale === void 0 ? true : _ref$autoGreyscale;2829if (typeof max !== 'number') {30return _utils.throwError.call(this, 'max must be a number', cb);31}3233if (typeof replace !== 'number') {34return _utils.throwError.call(this, 'replace must be a number', cb);35}3637if (typeof autoGreyscale !== 'boolean') {38return _utils.throwError.call(this, 'autoGreyscale must be a boolean', cb);39}4041max = this.constructor.limit255(max);42replace = this.constructor.limit255(replace);4344if (autoGreyscale) {45this.greyscale();46}4748this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function (x, y, idx) {49var grey = _this.bitmap.data[idx] < max ? _this.bitmap.data[idx] : replace;50_this.bitmap.data[idx] = grey;51_this.bitmap.data[idx + 1] = grey;52_this.bitmap.data[idx + 2] = grey;53});5455if ((0, _utils.isNodePattern)(cb)) {56cb.call(this, null, this);57}5859return this;60}61};62};6364exports["default"] = _default;65//# sourceMappingURL=index.js.map6667