This commit is contained in:
Chinmay Pandhare
2017-07-04 21:31:12 +05:30
parent ef2d315089
commit b5a6b416fe
4 changed files with 26 additions and 11 deletions

View File

@@ -2,10 +2,10 @@ console.log('\x1b[31m%s\x1b[0m',"This is the output of the module");
require('./src/ImageSequencer');
sequencer = ImageSequencer();
sequencer.loadImages({images:{red:'examples/red.jpg'},callback:function(){
sequencer.addSteps(['do-nothing-pix','ndvi-red','invert']);
sequencer.addSteps(['ndvi-red','do-nothing','do-nothing']);
sequencer.removeSteps(1);
sequencer.insertSteps({
red: [{index: -1, name: 'do-nothing', o:{}}]
red: [{index: -1, name: 'do-nothing-pix', o:{}}]
});
sequencer.run();
}});

View File

@@ -1,7 +1,7 @@
function AddStep(ref, image, name, o) {
function addStep(image, name, o_) {
ref.log('\x1b[36m%s\x1b[0m','adding step \"' + name + '\" to \"' + image + '\".');
ref.clog('\x1b[36m%s\x1b[0m','adding step \"' + name + '\" to \"' + image + '\".');
o = {};
o.id = ref.options.sequencerCounter++; //Gives a Unique ID to each step

View File

@@ -12,7 +12,7 @@ ImageSequencer = function ImageSequencer(options) {
return Object.prototype.toString.call(object).split(" ")[1].slice(0,-1)
}
function log(color,msg) {
function clog(color,msg) {
if(options.ui!="none") {
if(arguments.length==1) console.log(arguments[0]);
else if(arguments.length==2) console.log(color,msg);
@@ -41,7 +41,8 @@ ImageSequencer = function ImageSequencer(options) {
var image,
steps = [],
modules = require('./Modules'),
images = {};
images = {},
log = [];
// if in browser, prompt for an image
// if (options.imageSelect || options.inBrowser) addStep('image-select');
@@ -52,6 +53,7 @@ ImageSequencer = function ImageSequencer(options) {
json_q = {};
for(arg in arguments){args.push(copy(arguments[arg]));}
json_q = formatInput.call(this,args,"+");
log.push({method:"addSteps", json_q:copy(json_q)});
for (i in json_q)
for (j in json_q[i])
require("./AddStep")(this,i,json_q[i][j].name,json_q[i][j].o);
@@ -60,7 +62,7 @@ ImageSequencer = function ImageSequencer(options) {
function removeStep(image,index) {
//remove the step from images[image].steps and redraw remaining images
if(index>0) {
log('\x1b[31m%s\x1b[0m',"Removing "+index+" from "+image);
clog('\x1b[31m%s\x1b[0m',"Removing "+index+" from "+image);
images[image].steps.splice(index,1);
}
//tell the UI a step has been removed
@@ -71,6 +73,7 @@ ImageSequencer = function ImageSequencer(options) {
args = [];
for(arg in arguments) args.push(copy(arguments[arg]));
json_q = formatInput.call(this,args,"-");
log.push({method:"removeSteps", json_q:copy(json_q)});
for (img in json_q) {
indices = json_q[img].sort(function(a,b){return b-a});
@@ -88,6 +91,7 @@ ImageSequencer = function ImageSequencer(options) {
for (arg in arguments) args.push(arguments[arg]);
json_q = formatInput.call(this,args,"^");
log.push({method:"insertSteps", json_q:copy(json_q)});
for (img in json_q) {
var details = json_q[img];
@@ -100,7 +104,7 @@ ImageSequencer = function ImageSequencer(options) {
}
function run(t_image,t_from) {
log('\x1b[32m%s\x1b[0m',"Running the Sequencer!");
clog('\x1b[32m%s\x1b[0m',"Running the Sequencer!");
this_ = this;
args = [];
for (var arg in arguments) args.push(copy(arguments[arg]));
@@ -118,11 +122,20 @@ ImageSequencer = function ImageSequencer(options) {
args = [];
for (arg in arguments) args.push(copy(arguments[arg]));
json_q = formatInput.call(this,args,"l");
json_q_push = copy(json_q);
delete json_q_push.callback;
log.push({method:"loadImages", json_q:json_q_push});
for (i in json_q.images)
require('./LoadImage')(this,i,json_q.images[i])
json_q.callback();
if (json_q.callback) json_q.callback();
}
function runLog() {
for(i in sequencer.log)
eval("sequencer."+sequencer.log[i].method).call(sequencer,sequencer.log[i].json_q);
return true
}
return {
@@ -132,12 +145,14 @@ ImageSequencer = function ImageSequencer(options) {
removeSteps: removeSteps,
insertSteps: insertSteps,
run: run,
log: log,
modules: modules,
images: images,
ui: options.ui,
log: log,
clog: clog,
objTypeOf: objTypeOf,
copy: copy
copy: copy,
runLog: runLog
}
}

View File

@@ -1,7 +1,7 @@
function InsertStep(ref, image, index, name, o) {
function insertStep(image, index, name, o) {
ref.log('\x1b[36m%s\x1b[0m','inserting step \"' + name + '\" to \"' + image + '\" at \"'+index+'\".');
ref.clog('\x1b[36m%s\x1b[0m','inserting step \"' + name + '\" to \"' + image + '\" at \"'+index+'\".');
o = o || {};
o.id = ref.options.sequencerCounter++; //Gives a Unique ID to each step