image-js
Version:
Image processing and manipulation in JavaScript
26 lines (25 loc) • 729 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = sum;
var _newArray = _interopRequireDefault(require("new-array"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* Returns an array with the sum of the values of each channel
* @memberof Image
* @instance
* @return {number[]} Array having has size the number of channels
*/
function sum() {
this.checkProcessable('sum', {
bitDepth: [8, 16]
});
let result = (0, _newArray.default)(this.channels, 0);
for (let i = 0; i < this.data.length; i += this.channels) {
for (let c = 0; c < this.channels; c++) {
result[c] += this.data[i + c];
}
}
return result;
}