From b5a6b416feb9fe76a1181658fd58547d65c60823 Mon Sep 17 00:00:00 2001 From: Chinmay Pandhare Date: Tue, 4 Jul 2017 21:31:12 +0530 Subject: [PATCH 1/2] log --- index.js | 4 ++-- src/AddStep.js | 2 +- src/ImageSequencer.js | 29 ++++++++++++++++++++++------- src/InsertStep.js | 2 +- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 9e2cf4da78..16a026400c 100644 --- a/index.js +++ b/index.js @@ -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(); }}); diff --git a/src/AddStep.js b/src/AddStep.js index 4b3f21ea90..32f00e2f53 100644 --- a/src/AddStep.js +++ b/src/AddStep.js @@ -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 diff --git a/src/ImageSequencer.js b/src/ImageSequencer.js index 4d0c1a851c..895ae45f9a 100644 --- a/src/ImageSequencer.js +++ b/src/ImageSequencer.js @@ -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 } } diff --git a/src/InsertStep.js b/src/InsertStep.js index 5546f542eb..49c82a07a1 100644 --- a/src/InsertStep.js +++ b/src/InsertStep.js @@ -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 From a067336ecfd2e95226646d40dfb89745819f96fb Mon Sep 17 00:00:00 2001 From: Chinmay Pandhare Date: Tue, 4 Jul 2017 21:39:14 +0530 Subject: [PATCH 2/2] Basic Log Function --- dist/image-sequencer.js | 38 ++++++++++++++++++++++++-------------- index.js | 2 +- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/dist/image-sequencer.js b/dist/image-sequencer.js index 25261b683a..981f32c49e 100644 --- a/dist/image-sequencer.js +++ b/dist/image-sequencer.js @@ -34236,7 +34236,7 @@ function hasOwnProperty(obj, prop) { 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 @@ -34436,7 +34436,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); @@ -34465,7 +34465,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'); @@ -34476,6 +34477,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); @@ -34484,7 +34486,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 @@ -34495,6 +34497,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}); @@ -34512,6 +34515,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]; @@ -34524,7 +34528,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])); @@ -34542,11 +34546,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 { @@ -34556,12 +34569,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 } } @@ -34572,7 +34587,7 @@ module.exports = ImageSequencer; 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 @@ -34918,9 +34933,7 @@ module.exports = function PixelManipulation(image, options) { // there may be a more efficient means to encode an image object, // but node modules and their documentation are essentially arcane on this point - // w = base64.encode(); w = base64.encode(); - // var w = require('fs').createWriteStream('output.png'); var r = savePixels(pixels, options.format); r.pipe(w).on('finish',function(){ data = w.read().toString(); @@ -34929,9 +34942,6 @@ module.exports = function PixelManipulation(image, options) { if (options.callback) options.callback(); }); - - - }); } diff --git a/index.js b/index.js index 16a026400c..23b0f83ea2 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ 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(['ndvi-red','do-nothing','do-nothing']); + sequencer.addSteps(['do-nothing-pix','ndvi-red','invert']); sequencer.removeSteps(1); sequencer.insertSteps({ red: [{index: -1, name: 'do-nothing-pix', o:{}}]