add steps api functions (#293)

* add steps api functions

Signed-off-by: tech4GT <varun.gupta1798@gmail.com>

* optimize getHeight and getWidth

Signed-off-by: tech4GT <varun.gupta1798@gmail.com>

* add tests

Signed-off-by: tech4GT <varun.gupta1798@gmail.com>

* update tests

Signed-off-by: tech4GT <varun.gupta1798@gmail.com>
This commit is contained in:
Varun Gupta
2018-07-25 23:30:54 +05:30
committed by Jeffrey Warren
parent 56feb4c546
commit 10e47656a3
6 changed files with 96 additions and 21 deletions

View File

@@ -48280,7 +48280,7 @@ module.exports = function Dynamic(options, UI, util) {
// save first image's pixels
var priorStep = this.getStep(-2);
getPixels(priorStep.output.src, function (err, pixels) {
getPixels(priorStep.output.src, function(err, pixels) {
options.firstImagePixels = pixels;
function changePixel(r2, g2, b2, a2, x, y) {
@@ -50236,21 +50236,52 @@ module.exports = function GetFormat(src) {
},{}],198:[function(require,module,exports){
module.exports = {
getPreviousStep : function () {
getPreviousStep: function() {
return this.getStep(-1);
},
getNextStep : function() {
getNextStep: function() {
return this.getStep(1);
},
getInput : function(offset){
if(offset + this.getIndex() === 0) offset++;
getInput: function(offset) {
if (offset + this.getIndex() === 0) offset++;
return this.getStep(offset - 1).output;
},
getOuput : function(offset){
getOutput: function(offset) {
return this.getStep(offset).output;
},
getOptions: function() {
return this.getStep(0).options;
},
setOptions: function(optionsObj) {
let options = this.getStep(0).options;
for (let key in optionsObj) {
if (options[key]) options[key] = optionsObj[key];
}
},
getFormat: function() {
return this.getStep(-1).output.format;
},
getHeight: function(callback) {
let img = new Image();
img.onload = function() {
callback(img.height);
};
img.src = this.getInput(0).src;
},
getWidth: function(callback) {
let img = new Image();
img.onload = function() {
callback(img.width);
};
img.src = this.getInput(0).src;
}
}
},{}]},{},[139]);

File diff suppressed because one or more lines are too long

View File

@@ -20,7 +20,7 @@ module.exports = function Dynamic(options, UI, util) {
// save first image's pixels
var priorStep = this.getStep(-2);
getPixels(priorStep.output.src, function (err, pixels) {
getPixels(priorStep.output.src, function(err, pixels) {
options.firstImagePixels = pixels;
function changePixel(r2, g2, b2, a2, x, y) {

View File

@@ -1,18 +1,49 @@
module.exports = {
getPreviousStep : function () {
getPreviousStep: function() {
return this.getStep(-1);
},
getNextStep : function() {
getNextStep: function() {
return this.getStep(1);
},
getInput : function(offset){
if(offset + this.getIndex() === 0) offset++;
getInput: function(offset) {
if (offset + this.getIndex() === 0) offset++;
return this.getStep(offset - 1).output;
},
getOuput : function(offset){
getOutput: function(offset) {
return this.getStep(offset).output;
},
getOptions: function() {
return this.getStep(0).options;
},
setOptions: function(optionsObj) {
let options = this.getStep(0).options;
for (let key in optionsObj) {
if (options[key]) options[key] = optionsObj[key];
}
},
getFormat: function() {
return this.getStep(-1).output.format;
},
getHeight: function(callback) {
let img = new Image();
img.onload = function() {
callback(img.height);
};
img.src = this.getInput(0).src;
},
getWidth: function(callback) {
let img = new Image();
img.onload = function() {
callback(img.width);
};
img.src = this.getInput(0).src;
}
}

View File

@@ -1,14 +1,27 @@
module.exports = function testModule(options, UI) {
module.exports = function Dynamic(options, UI, util) {
// Tests for functions that are available inside modules only
var output;
// This function is called on every draw.
function draw(input, callback) {
var output = function(input) {
return input;
var step = this;
if (this.getPreviousStep().options.name != "invert") throw new Error("getPreviousStep not working");
if (this.getNextStep().options.name != "invert") throw new Error("getNextStep not working");
if (this.getInput(0) != this.getOutput(-1)) throw new Error("getInput and getOuput now working")
if (this.getFormat() != "jpeg") throw new Error("getFormat not working");
if (this.getOptions().name != "test") throw new Error("getOptions not working");
this.setOptions({ name: "test-1" });
if (this.getOptions().name != "test-1") throw new Error("setOptions not working not working");
this.getHeight(((h) => { if (h != 16) throw new Error("getHeight not working") }));
this.getWidth((w) => { if (w != 16) throw new Error("getWidth not working") });
function output(image, datauri, mimetype) {
step.output = input;
}
this.output = output(input); // run the output and assign it to this.output
callback();
}
return {

View File

@@ -1,5 +1,5 @@
{
"name": "test",
"description": "Outputs the same image.",
"description": "Functions that are scoped inside modules are tested with this. This Module is dynamically loaded.",
"inputs": {}
}