start to average module (#249)

* start to average module

* completed average module

* added average module, version bump
This commit is contained in:
Jeffrey Warren
2018-05-09 09:39:33 -04:00
committed by GitHub
parent cbbfbff4bc
commit 991e9bb29c
7 changed files with 257 additions and 59 deletions

View File

@@ -8,7 +8,9 @@ module.exports = function PixelManipulation(image, options) {
options.changePixel = options.changePixel || function changePixel(r, g, b, a) {
return [r, g, b, a];
};
options.extraManipulation = options.extraManipulation||function extraManipulation(pixels){
//
options.extraManipulation = options.extraManipulation || function extraManipulation(pixels){
return pixels;
}
@@ -23,26 +25,25 @@ module.exports = function PixelManipulation(image, options) {
}
if(options.getNeighbourPixel){
options.getNeighbourPixel.fun = function (distX,distY) {
options.getNeighbourPixel.fun = function getNeighborPixel(distX,distY) {
return options.getNeighbourPixel(pixels,x,y,distX,distY);
};
}
// iterate through pixels;
// this could possibly be more efficient; see
// TODO: this could possibly be more efficient; see
// https://github.com/p-v-o-s/infragram-js/blob/master/public/infragram.js#L173-L181
if(!options.inBrowser){
try{
if (!options.inBrowser) {
try {
var pace = require('pace')((pixels.shape[0] * pixels.shape[1]));
}
catch(e){
} catch(e){
options.inBrowser = true;
}
}
for(var x = 0; x < pixels.shape[0]; x++) {
for(var y = 0; y < pixels.shape[1]; y++) {
for (var x = 0; x < pixels.shape[0]; x++) {
for (var y = 0; y < pixels.shape[1]; y++) {
var pixel = options.changePixel(
pixels.get(x, y, 0),
@@ -60,9 +61,10 @@ module.exports = function PixelManipulation(image, options) {
pace.op()
}
}
if(options.extraManipulation)
pixels = options.extraManipulation(pixels)
// perform any extra operations on the entire array:
if (options.extraManipulation)
pixels = options.extraManipulation(pixels);
// there may be a more efficient means to encode an image object,
// but node modules and their documentation are essentially arcane on this point