UNPKG

image-js

Version:

Image processing and manipulation in JavaScript

28 lines (27 loc) 788 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = min; var _newArray = _interopRequireDefault(require("new-array")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** * Returns an array with the minimal value of each channel * @memberof Image * @instance * @return {number[]} Array having has size the number of channels */ function min() { this.checkProcessable('min', { bitDepth: [8, 16, 32] }); let result = (0, _newArray.default)(this.channels, +Infinity); for (let i = 0; i < this.data.length; i += this.channels) { for (let c = 0; c < this.channels; c++) { if (this.data[i + c] < result[c]) { result[c] = this.data[i + c]; } } } return result; }