lwip-pixels
Version:
Get a matrix of pixels from a lwip image object.
30 lines (25 loc) • 683 B
JavaScript
;
var Pixel = require("pixel-class");
/**
* getPixels
* Builts a pixel matrix from the input `lwip` object.
*
* @name getPixels
* @function
* @param {lwip} image The `lwip` object.
* @return {Array} An array of arrays of [`Pixel`](https://github.com/IonicaBizau/pixel-class) instances.
*/
module.exports = function getPixels(image) {
var pixels = [],
height = image.height(),
width = image.width(),
cRow = [];
for (var y = 0; y < height; ++y) {
for (var x = 0; x < width; ++x) {
cRow.push(new Pixel(image.getPixel(x, y)));
}
pixels.push(cRow);
cRow = [];
}
return pixels;
};