UNPKG

voluptasquisquam

Version:

Image processing and manipulation in JavaScript

24 lines (22 loc) 646 B
/** * Allows to generate an array of points for a binary image (bit depth = 1) * @memberof Image * @instance * @return {Array<Array<number>>} - an array of [x,y] corresponding to the set pixels in the binary image */ export default function points() { this.checkProcessable('points', { bitDepth: [1] }); let pixels = new Array(this.size); let counter = 0; for (let x = 0; x < this.width; x++) { for (let y = 0; y < this.height; y++) { if (this.getBitXY(x, y) === 1) { pixels[counter++] = [x, y]; } } } pixels.length = counter; return pixels; }