forked from jywarren/image-sequencer
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configurable parameter for blend module to chose image (#424)
* Add configurable parameter for blend module to chose image * Made minor changes * Edit test to work with new parameter * blend offset test added * blend offset test added * fixed blend offset test
- Loading branch information
Showing
3 changed files
with
70 additions
and
48 deletions.
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