forked from jywarren/image-sequencer
-
Notifications
You must be signed in to change notification settings - Fork 210
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
Add configurable parameter for blend module to chose image #424
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5c5e7b9
Add configurable parameter for blend module to chose image
5c86743
Made minor changes
62ed7ef
Edit test to work with new parameter
24ba2ae
blend offset test added
b21884c
blend offset test added
3ee1a65
fixed blend offset test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,67 @@ | ||
module.exports = function Dynamic(options, UI, util) { | ||
|
||
options.func = options.func || "function(r1, g1, b1, a1, r2, g2, b2, a2) { return [ r1, g2, b2, a2 ] }"; | ||
options.func = options.func || "function(r1, g1, b1, a1, r2, g2, b2, a2) { return [ r1, g2, b2, a2 ] }"; | ||
options.offset = options.offset || -2; | ||
|
||
var output; | ||
var output; | ||
|
||
// This function is called on every draw. | ||
function draw(input, callback, progressObj) { | ||
// This function is called on every draw. | ||
function draw(input, callback, progressObj) { | ||
|
||
progressObj.stop(true); | ||
progressObj.overrideFlag = true; | ||
progressObj.stop(true); | ||
progressObj.overrideFlag = true; | ||
|
||
var step = this; | ||
var step = this; | ||
|
||
// convert to runnable code: | ||
if (typeof options.func === "string") eval('options.func = ' + options.func); | ||
// convert to runnable code: | ||
if (typeof options.func === "string") eval('options.func = ' + options.func); | ||
|
||
var getPixels = require('get-pixels'); | ||
var getPixels = require('get-pixels'); | ||
|
||
// save first image's pixels | ||
var priorStep = this.getStep(-2); | ||
// convert offset as string to int | ||
if(typeof options.offset === "string") options.offset = parseInt(options.offset); | ||
|
||
getPixels(priorStep.output.src, function(err, pixels) { | ||
options.firstImagePixels = pixels; | ||
// save first image's pixels | ||
var priorStep = this.getStep(options.offset); | ||
|
||
function changePixel(r2, g2, b2, a2, x, y) { | ||
// blend! | ||
var p = options.firstImagePixels; | ||
return options.func( | ||
r2, g2, b2, a2, | ||
p.get(x, y, 0), | ||
p.get(x, y, 1), | ||
p.get(x, y, 2), | ||
p.get(x, y, 3) | ||
) | ||
} | ||
getPixels(priorStep.output.src, function(err, pixels) { | ||
options.firstImagePixels = pixels; | ||
|
||
function output(image, datauri, mimetype) { | ||
function changePixel(r2, g2, b2, a2, x, y) { | ||
// blend! | ||
var p = options.firstImagePixels; | ||
return options.func( | ||
r2, g2, b2, a2, | ||
p.get(x, y, 0), | ||
p.get(x, y, 1), | ||
p.get(x, y, 2), | ||
p.get(x, y, 3) | ||
) | ||
} | ||
|
||
// This output is accessible by Image Sequencer | ||
step.output = { src: datauri, format: mimetype }; | ||
function output(image, datauri, mimetype) { | ||
|
||
} | ||
// This output is accessible by Image Sequencer | ||
step.output = { src: datauri, format: mimetype }; | ||
|
||
// run PixelManipulatin on second image's pixels | ||
return require('../_nomodule/PixelManipulation.js')(input, { | ||
} | ||
|
||
// run PixelManipulatin on second image's pixels | ||
return require('../_nomodule/PixelManipulation.js')(input, { | ||
output: output, | ||
changePixel: changePixel, | ||
format: input.format, | ||
image: options.image, | ||
inBrowser: options.inBrowser, | ||
callback: callback | ||
}); | ||
}); | ||
} | ||
|
||
return { | ||
options: options, | ||
draw: draw, | ||
output: output, | ||
changePixel: changePixel, | ||
format: input.format, | ||
image: options.image, | ||
inBrowser: options.inBrowser, | ||
callback: callback | ||
}); | ||
}); | ||
} | ||
|
||
return { | ||
options: options, | ||
draw: draw, | ||
output: output, | ||
UI: UI | ||
} | ||
UI: UI | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, perhaps we should introduce a new test for offsets, and we could do a test demonstrating that the default offset and
-3
don't return the same result. You can run a sequence that inverts repeatedly a few times, then does blend, and this kind of test should work. You could say-3
isn't the same as-2
, but-4
is the same, you know? And create a new test specifically for this functionality.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll think about it and try to add new test soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some kind of documentation on how to do tests? It's time consuming by doing a lot of trials, espiecially when I can't run it locally, and each time I have to run in on Travis Ci, becouse there are some errors on the windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, have you had trouble running tests locally? I think you should be able to with
npm test
-- but if you did something like:Docs are here: https://github.com/substack/tape
Tutorial: https://ponyfoo.com/articles/testing-javascript-modules-with-tape
But you're right, we should add these to a
Testing
section of the README -- would you be interested in adding a section like that? Otherwise I can open an issue for someone new to try it out.Thanks @KusioDev !! This is going to be awesome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to write test that invert twice first, and then blend.
It saves the first output to variable, change the offset to -3, and re-run drawing the blend.
However, when I run
sequencer.run()
after changing the offset, the outuput is set to undefined, and so the test is not correct, becouse I can't read property of.output.src
if output is not set.