Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow easier access to neighboring pixels in Dynamic module #201

Closed
jywarren opened this issue Mar 12, 2018 · 12 comments
Closed

Allow easier access to neighboring pixels in Dynamic module #201

jywarren opened this issue Mar 12, 2018 · 12 comments

Comments

@jywarren
Copy link
Member

Currently the Dynamic module runs on each pixel, one by one:

function changePixel(r, g, b, a) {
var combined = (r + g + b) / 3.000;
return [
options.red_function( r, g, b, a),
options.green_function(r, g, b, a),
options.blue_function( r, g, b, a),
options.alpha_function(r, g, b, a),
];
}

It has read access to the existing pixel, and uses that data to generate a new pixel color.

But to do some activities, it's helpful to be able to access neighboring pixels. This can become computationally intensive, but also useful for some operations. We could make a neighbor(x,y) pixel available to specify pixels x, y away from the current pixel.

@jywarren
Copy link
Member Author

GitMate.io thinks the contributor most likely able to help you is @ccpandhare.

Possibly related issues are #108 (Math Module), #146 (Monochrome "fallback" on Dynamic module not working), #112 (Scale module), #5 (image cropping module), and #75 (Pixel Manipulation and GIFs).

@tech4GT
Copy link
Member

tech4GT commented Mar 13, 2018

@jywarren should we make a function to do this in the dynamic module?

function neighbour(x,y){
/*Some Definition*/
}

@jywarren
Copy link
Member Author

jywarren commented Mar 13, 2018 via email

@ccpandhare
Copy link
Collaborator

ccpandhare commented Mar 14, 2018 via email

@tech4GT
Copy link
Member

tech4GT commented Mar 14, 2018

@ccpandhare actually the neighbor function is supposed to be generic only, it will yield the pixel at x,y distance from the current pixel, as @jywarren was saying, will it be fine then?

@ccpandhare
Copy link
Collaborator

ccpandhare commented Mar 14, 2018 via email

@tech4GT
Copy link
Member

tech4GT commented Mar 22, 2018

@jywarren i have made this work but i have a doubt, should we put the logic to get neighboring pixels in PixelManipulation itself and pass it to changePixel so that other modules can also use it if need be?
What i mean is that changePixel can be defined like this

function changePixel(r,g,b,a,neighbour){
/*some code*/
neighbour(x,y) gives the neighbouring pixel
/*some other code*/
}

since neighbour is last parameter, its not required hence other modules which do not use neighbors would need no change

function changePixel(r,g,b,a){
/*function definition*/
}

or we can define the logic in dynamic module and pass it to PixelManipulation which will in turn pass it to module's changePixel ?

tech4GT added a commit to tech4GT/image-sequencer that referenced this issue Mar 22, 2018
Signed-off-by: tech4GT <varun.gupta1798@gmail.com>
@jywarren
Copy link
Member Author

I think it's possible we could expose access to neighbor() without passing it as a parameter, if we pass it using a closure -- my brain bends a bit thinking about it, but can't we allow changePixel() access? Ugh, it's been too long since I did this...

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures

Otherwise, i like your passing neighbor() as the 5th parameter. Thanks for thinking this through!!!

@tech4GT
Copy link
Member

tech4GT commented Mar 23, 2018

@jywarren actually the thing is that the pixels object is not available in the module.js so even if we define the logic there there is no way that we get access to pixels there so we have to pass it to pixelmanipulation, only way this can work is if we bind the neighbour function to an object inside module.js and access that object directly in changepixel, would that be fine

Var obj={}
Obj.fun=getneighbor(){}
Changepixel uses obj.fun

@tech4GT
Copy link
Member

tech4GT commented Mar 23, 2018

This obj is passed to pixelmanipulation

@tech4GT
Copy link
Member

tech4GT commented Mar 23, 2018

#204 @jywarren done without extra parameter🎉

@tech4GT
Copy link
Member

tech4GT commented Mar 31, 2018

closed in #207

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants