mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-12 11:20:02 +01:00
Dynamic fix as fun (#207)
getNeighborPixel(x, y) method for Dynamic module
This commit is contained in:
committed by
Jeffrey Warren
parent
0ceb36ffde
commit
fba80bb151
@@ -35,15 +35,30 @@ module.exports = function Dynamic(options,UI) {
|
||||
});
|
||||
|
||||
function changePixel(r, g, b, a) {
|
||||
|
||||
/* neighbourpixels can be calculated by
|
||||
this.getNeighbourPixel.fun(x,y) or this.getNeighborPixel.fun(x,y)
|
||||
*/
|
||||
var combined = (r + g + b) / 3.000;
|
||||
return [
|
||||
options.red_function( r, g, b, a),
|
||||
options.red_function(r, g, b, a),
|
||||
options.green_function(r, g, b, a),
|
||||
options.blue_function( r, g, b, a),
|
||||
options.blue_function(r, g, b, a),
|
||||
options.alpha_function(r, g, b, a),
|
||||
];
|
||||
}
|
||||
|
||||
/* Functions to get the neighbouring pixel by position (x,y) */
|
||||
function getNeighbourPixel(pixels,curX,curY,distX,distY){
|
||||
return [
|
||||
pixels.get(curX+distX,curY+distY,0)
|
||||
,pixels.get(curX+distX,curY+distY,1)
|
||||
,pixels.get(curX+distX,curY+distY,2)
|
||||
,pixels.get(curX+distX,curY+distY,3)
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
function output(image,datauri,mimetype){
|
||||
|
||||
// This output is accessible by Image Sequencer
|
||||
@@ -59,6 +74,8 @@ module.exports = function Dynamic(options,UI) {
|
||||
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||
output: output,
|
||||
changePixel: changePixel,
|
||||
getNeighbourPixel: getNeighbourPixel,
|
||||
getNeighborPixel: getNeighbourPixel,
|
||||
format: input.format,
|
||||
image: options.image,
|
||||
inBrowser: options.inBrowser,
|
||||
|
||||
@@ -22,6 +22,12 @@ module.exports = function PixelManipulation(image, options) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(options.getNeighbourPixel){
|
||||
options.getNeighbourPixel.fun = function (distX,distY) {
|
||||
return options.getNeighbourPixel(pixels,x,y,distX,distY);
|
||||
};
|
||||
}
|
||||
|
||||
// iterate through pixels;
|
||||
// this could possibly be more efficient; see
|
||||
// https://github.com/p-v-o-s/infragram-js/blob/master/public/infragram.js#L173-L181
|
||||
@@ -33,11 +39,11 @@ module.exports = function PixelManipulation(image, options) {
|
||||
for(var y = 0; y < pixels.shape[1]; y++) {
|
||||
|
||||
var pixel = options.changePixel(
|
||||
pixels.get(x, y, 0),
|
||||
pixels.get(x, y, 1),
|
||||
pixels.get(x, y, 2),
|
||||
pixels.get(x, y, 3)
|
||||
);
|
||||
pixels.get(x, y, 0),
|
||||
pixels.get(x, y, 1),
|
||||
pixels.get(x, y, 2),
|
||||
pixels.get(x, y, 3)
|
||||
);
|
||||
|
||||
pixels.set(x, y, 0, pixel[0]);
|
||||
pixels.set(x, y, 1, pixel[1]);
|
||||
@@ -50,7 +56,7 @@ module.exports = function PixelManipulation(image, options) {
|
||||
}
|
||||
|
||||
if(options.extraManipulation)
|
||||
pixels = options.extraManipulation(pixels)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user