mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-13 20:00:05 +01:00
Rework UI Handling
This commit is contained in:
216
dist/image-sequencer.js
vendored
216
dist/image-sequencer.js
vendored
@@ -34391,18 +34391,14 @@ function AddStep(ref, image, name, o) {
|
|||||||
o.container = o_.container || ref.options.selector;
|
o.container = o_.container || ref.options.selector;
|
||||||
o.image = image;
|
o.image = image;
|
||||||
|
|
||||||
o.identity = {
|
o.step = {
|
||||||
stepName: o.name,
|
name: o.name,
|
||||||
stepID: o.number,
|
ID: o.number,
|
||||||
imageName: o.image
|
imageName: o.image,
|
||||||
|
inBrowser: ref.options.inBrowser,
|
||||||
|
ui: ref.options.ui
|
||||||
};
|
};
|
||||||
o.UIFs = ref.UI();
|
var UI = ref.events;
|
||||||
var UI = {
|
|
||||||
onSetup: function(){o.UIFs.onSetup(o.identity);},
|
|
||||||
onDraw: function(){o.UIFs.onSetup(o.identity);},
|
|
||||||
onComplete: function(out){o.UIFs.onSetup(o.identity,out);},
|
|
||||||
onRemove: function(){o.UIFs.onSetup(o.identity);},
|
|
||||||
}
|
|
||||||
var module = ref.modules[name](o,UI);
|
var module = ref.modules[name](o,UI);
|
||||||
ref.images[image].steps.push(module);
|
ref.images[image].steps.push(module);
|
||||||
|
|
||||||
@@ -34624,7 +34620,7 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
formatInput = require('./FormatInput'),
|
formatInput = require('./FormatInput'),
|
||||||
images = {},
|
images = {},
|
||||||
inputlog = [],
|
inputlog = [],
|
||||||
UI;
|
events;
|
||||||
|
|
||||||
setUI();
|
setUI();
|
||||||
|
|
||||||
@@ -34651,7 +34647,7 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
function removeStep(image,index) {
|
function removeStep(image,index) {
|
||||||
//remove the step from images[image].steps and redraw remaining images
|
//remove the step from images[image].steps and redraw remaining images
|
||||||
if(index>0) {
|
if(index>0) {
|
||||||
images[image].steps[index].UI.onRemove();
|
images[image].steps[index].UI.onRemove(images[image].steps[index].options.step);
|
||||||
images[image].steps.splice(index,1);
|
images[image].steps.splice(index,1);
|
||||||
}
|
}
|
||||||
//tell the UI a step has been removed
|
//tell the UI a step has been removed
|
||||||
@@ -34743,9 +34739,8 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
return require('./ReplaceImage')(this,selector,steps);
|
return require('./ReplaceImage')(this,selector,steps);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setUI(_UI) {
|
function setUI(UI) {
|
||||||
UI = require('./UserInterface')(_UI,options);
|
events = require('./UserInterface')(UI);
|
||||||
return UI;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -34755,7 +34750,7 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
inputlog: inputlog,
|
inputlog: inputlog,
|
||||||
modules: modules,
|
modules: modules,
|
||||||
images: images,
|
images: images,
|
||||||
UI: UI,
|
events: events,
|
||||||
|
|
||||||
//user functions
|
//user functions
|
||||||
loadImages: loadImages,
|
loadImages: loadImages,
|
||||||
@@ -34789,18 +34784,14 @@ function InsertStep(ref, image, index, name, o) {
|
|||||||
|
|
||||||
if(index==-1) index = ref.images[image].steps.length;
|
if(index==-1) index = ref.images[image].steps.length;
|
||||||
|
|
||||||
o.identity = {
|
o.step = {
|
||||||
stepName: o.name,
|
name: o.name,
|
||||||
stepID: o.number,
|
ID: o.number,
|
||||||
imageName: o.image
|
imageName: o.image,
|
||||||
|
inBrowser: ref.options.inBrowser,
|
||||||
|
ui: ref.options.ui
|
||||||
};
|
};
|
||||||
o.UIFs = ref.UI();
|
var UI = ref.events;
|
||||||
var UI = {
|
|
||||||
onSetup: function(){o.UIFs.onSetup(o.identity);},
|
|
||||||
onDraw: function(){o.UIFs.onSetup(o.identity);},
|
|
||||||
onComplete: function(out){o.UIFs.onSetup(o.identity,out);},
|
|
||||||
onRemove: function(){o.UIFs.onSetup(o.identity);},
|
|
||||||
}
|
|
||||||
var module = ref.modules[name](o,UI);
|
var module = ref.modules[name](o,UI);
|
||||||
ref.images[image].steps.splice(index,0,module);
|
ref.images[image].steps.splice(index,0,module);
|
||||||
|
|
||||||
@@ -34823,27 +34814,37 @@ function LoadImage(ref, name, src) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadImage(name, src) {
|
function loadImage(name, src) {
|
||||||
|
var step = {
|
||||||
|
name: "load-image",
|
||||||
|
ID: ref.options.sequencerCounter++,
|
||||||
|
imageName: name,
|
||||||
|
inBrowser: ref.options.inBrowser,
|
||||||
|
ui: ref.options.ui
|
||||||
|
};
|
||||||
|
|
||||||
var image = {
|
var image = {
|
||||||
src: src,
|
src: src,
|
||||||
steps: [{
|
steps: [{
|
||||||
options: {
|
options: {
|
||||||
id: ref.options.sequencerCounter++,
|
id: step.ID,
|
||||||
name: "load-image",
|
name: "load-image",
|
||||||
title: "Load Image"
|
title: "Load Image",
|
||||||
|
step: step
|
||||||
},
|
},
|
||||||
UI: ref.UI({
|
UI: ref.events,
|
||||||
stepName: "load-image",
|
|
||||||
stepID: ref.options.sequencerCounter++,
|
|
||||||
imageName: name
|
|
||||||
}),
|
|
||||||
draw: function() {
|
draw: function() {
|
||||||
|
UI.onDraw(options.step);
|
||||||
if(arguments.length==1){
|
if(arguments.length==1){
|
||||||
this.output = CImage(arguments[0]);
|
this.output = CImage(arguments[0]);
|
||||||
|
options.step.output = this.output;
|
||||||
|
UI.onComplete(options.step);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if(arguments.length==2) {
|
else if(arguments.length==2) {
|
||||||
this.output = CImage(arguments[0]);
|
this.output = CImage(arguments[0]);
|
||||||
|
options.step.output = this.output;
|
||||||
arguments[1]();
|
arguments[1]();
|
||||||
|
UI.onComplete(options.step);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -34852,9 +34853,11 @@ function LoadImage(ref, name, src) {
|
|||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
ref.images[name] = image;
|
ref.images[name] = image;
|
||||||
ref.images[name].steps[0].UI.onSetup();
|
loadImageStep = ref.images[name].steps[0];
|
||||||
ref.images[name].steps[0].UI.onDraw();
|
loadImageStep.options.step.output = loadImageStep.output.src;
|
||||||
ref.images[name].steps[0].UI.onComplete(image.steps[0].output.src);
|
loadImageStep.UI.onSetup(loadImageStep.options.step);
|
||||||
|
loadImageStep.UI.onDraw(loadImageStep.options.step);
|
||||||
|
loadImageStep.UI.onComplete(loadImageStep.options.step);
|
||||||
}
|
}
|
||||||
|
|
||||||
return loadImage(name,src);
|
return loadImage(name,src);
|
||||||
@@ -34964,79 +34967,29 @@ module.exports = Run;
|
|||||||
|
|
||||||
},{}],119:[function(require,module,exports){
|
},{}],119:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
* Default UI for each image-sequencer module
|
* User Interface Handling Module
|
||||||
*/
|
*/
|
||||||
module.exports = function UserInterface(newUI = {},options) {
|
|
||||||
|
|
||||||
var UI = newUI;
|
module.exports = function UserInterface(events = {}) {
|
||||||
|
|
||||||
return function userInterface(identity) {
|
|
||||||
|
|
||||||
identity.ui = options.ui;
|
|
||||||
identity.inBrowser = options.inBrowser;
|
|
||||||
|
|
||||||
UI.onSetup = UI.onSetup || function(identity) {
|
|
||||||
if(identity.ui == false) {
|
|
||||||
// No UI
|
|
||||||
}
|
|
||||||
else if(identity.inBrowser) {
|
|
||||||
// Create and append an HTML Element
|
|
||||||
console.log("Added Step \""+identity.stepName+"\" to \""+identity.imageName+"\".");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Create a NodeJS Object
|
|
||||||
console.log('\x1b[36m%s\x1b[0m',"Added Step \""+identity.stepName+"\" to \""+identity.imageName+"\".");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UI.onDraw = UI.onDraw || function(identity) {
|
|
||||||
if (identity.ui == false) {
|
|
||||||
// No UI
|
|
||||||
}
|
|
||||||
else if(identity.inBrowser) {
|
|
||||||
// Overlay a loading spinner
|
|
||||||
console.log("Drawing Step \""+identity.stepName+"\" on \""+identity.imageName+"\".");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Don't do anything
|
|
||||||
console.log('\x1b[33m%s\x1b[0m',"Drawing Step \""+identity.stepName+"\" on \""+identity.imageName+"\".");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UI.onComplete = UI.onComplete || function(identity,output) {
|
|
||||||
if (identity.ui == false) {
|
|
||||||
// No UI
|
|
||||||
}
|
|
||||||
else if(identity.inBrowser) {
|
|
||||||
// Update the DIV Element
|
|
||||||
// Hide the laoding spinner
|
|
||||||
console.log("Drawn Step \""+identity.stepName+"\" on \""+identity.imageName+"\".");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Update the NodeJS Object
|
|
||||||
console.log('\x1b[32m%s\x1b[0m',"Drawn Step \""+identity.stepName+"\" on \""+identity.imageName+"\".");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UI.onRemove = UI.onRemove || function(identity) {
|
|
||||||
if(identity.ui == false){
|
|
||||||
// No UI
|
|
||||||
}
|
|
||||||
else if(identity.inBrowser) {
|
|
||||||
// Remove the DIV Element
|
|
||||||
console.log("Removing Step \""+identity.stepName+"\" of \""+identity.imageName+"\".");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Delete the NodeJS Object
|
|
||||||
console.log('\x1b[31m%s\x1b[0m',"Removing Step \""+identity.stepName+"\" of \""+identity.imageName+"\".");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return UI;
|
|
||||||
|
|
||||||
|
events.onSetup = events.onSetup || function(step) {
|
||||||
|
console.log("onSetup "+step.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
events.onDraw = events.onDraw || function(step) {
|
||||||
|
console.log("onDraw "+step.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
events.onComplete = events.onComplete || function(step) {
|
||||||
|
console.log("onComplete "+step.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
events.onRemove = events.onRemove || function(step) {
|
||||||
|
console.log("onRemove "+step.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return events;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},{}],120:[function(require,module,exports){
|
},{}],120:[function(require,module,exports){
|
||||||
@@ -35097,12 +35050,12 @@ module.exports = function Crop(input,options,callback) {
|
|||||||
module.exports = function CropModule(options,UI) {
|
module.exports = function CropModule(options,UI) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.title = "Crop Image";
|
options.title = "Crop Image";
|
||||||
UI.onSetup();
|
UI.onSetup(options.step);
|
||||||
var output
|
var output
|
||||||
|
|
||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
|
|
||||||
UI.onDraw();
|
UI.onDraw(options.step);
|
||||||
const step = this;
|
const step = this;
|
||||||
|
|
||||||
require('./Crop')(input,options,function(out,format){
|
require('./Crop')(input,options,function(out,format){
|
||||||
@@ -35110,7 +35063,8 @@ module.exports = function Crop(input,options,callback) {
|
|||||||
src: out,
|
src: out,
|
||||||
format: format
|
format: format
|
||||||
}
|
}
|
||||||
UI.onComplete(out);
|
options.step.output = out;
|
||||||
|
UI.onComplete(options.step);
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -35132,14 +35086,17 @@ module.exports = function Crop(input,options,callback) {
|
|||||||
module.exports = function DoNothing(options,UI) {
|
module.exports = function DoNothing(options,UI) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.title = "Do Nothing";
|
options.title = "Do Nothing";
|
||||||
UI.onSetup();
|
UI.onSetup(options.step);
|
||||||
var output;
|
var output;
|
||||||
|
|
||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
UI.onDraw();
|
UI.onDraw(options.step);
|
||||||
|
|
||||||
this.output = input;
|
this.output = input;
|
||||||
|
|
||||||
|
options.step.output = this.output.src;
|
||||||
callback();
|
callback();
|
||||||
UI.onComplete(this.output.src);
|
UI.onComplete(options.step);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -35158,12 +35115,12 @@ module.exports = function DoNothingPix(options,UI) {
|
|||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.title = "Do Nothing with pixels";
|
options.title = "Do Nothing with pixels";
|
||||||
UI.onSetup();
|
UI.onSetup(options.step);
|
||||||
var output;
|
var output;
|
||||||
|
|
||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
|
|
||||||
UI.onDraw();
|
UI.onDraw(options.step);
|
||||||
const step = this;
|
const step = this;
|
||||||
|
|
||||||
function changePixel(r, g, b, a) {
|
function changePixel(r, g, b, a) {
|
||||||
@@ -35171,7 +35128,8 @@ module.exports = function DoNothingPix(options,UI) {
|
|||||||
}
|
}
|
||||||
function output(image,datauri,mimetype){
|
function output(image,datauri,mimetype){
|
||||||
step.output = {src:datauri,format:mimetype}
|
step.output = {src:datauri,format:mimetype}
|
||||||
UI.onComplete(datauri);
|
options.step.output = datauri;
|
||||||
|
UI.onComplete(options.step);
|
||||||
}
|
}
|
||||||
return require('../_nomodule/PixelManipulation.js')(input, {
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
output: output,
|
output: output,
|
||||||
@@ -35200,12 +35158,12 @@ module.exports = function GreenChannel(options,UI) {
|
|||||||
options = options || {};
|
options = options || {};
|
||||||
options.title = "Green channel only";
|
options.title = "Green channel only";
|
||||||
options.description = "Displays only the green channel of an image";
|
options.description = "Displays only the green channel of an image";
|
||||||
UI.onSetup();
|
UI.onSetup(options.step);
|
||||||
var output;
|
var output;
|
||||||
|
|
||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
|
|
||||||
UI.onDraw();
|
UI.onDraw(options.step);
|
||||||
const step = this;
|
const step = this;
|
||||||
|
|
||||||
function changePixel(r, g, b, a) {
|
function changePixel(r, g, b, a) {
|
||||||
@@ -35213,7 +35171,8 @@ module.exports = function GreenChannel(options,UI) {
|
|||||||
}
|
}
|
||||||
function output(image,datauri,mimetype){
|
function output(image,datauri,mimetype){
|
||||||
step.output = {src:datauri,format:mimetype};
|
step.output = {src:datauri,format:mimetype};
|
||||||
UI.onComplete(datauri);
|
options.step.output = datauri;
|
||||||
|
UI.onComplete(options.step);
|
||||||
}
|
}
|
||||||
return require('../_nomodule/PixelManipulation.js')(input, {
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
output: output,
|
output: output,
|
||||||
@@ -35243,14 +35202,14 @@ module.exports = function GreenChannel(options,UI) {
|
|||||||
options = options || {};
|
options = options || {};
|
||||||
options.title = "Invert Colors";
|
options.title = "Invert Colors";
|
||||||
options.description = "Inverts the colors of the image";
|
options.description = "Inverts the colors of the image";
|
||||||
UI.onSetup();
|
UI.onSetup(options.step);
|
||||||
var output;
|
var output;
|
||||||
|
|
||||||
//function setup() {} // optional
|
//function setup() {} // optional
|
||||||
|
|
||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
|
|
||||||
UI.onDraw();
|
UI.onDraw(options.step);
|
||||||
const step = this;
|
const step = this;
|
||||||
|
|
||||||
function changePixel(r, g, b, a) {
|
function changePixel(r, g, b, a) {
|
||||||
@@ -35258,7 +35217,8 @@ module.exports = function GreenChannel(options,UI) {
|
|||||||
}
|
}
|
||||||
function output(image,datauri,mimetype){
|
function output(image,datauri,mimetype){
|
||||||
step.output = {src:datauri,format:mimetype};
|
step.output = {src:datauri,format:mimetype};
|
||||||
UI.onComplete(datauri);
|
options.step.output = datauri;
|
||||||
|
UI.onComplete(options.step);
|
||||||
}
|
}
|
||||||
return require('../_nomodule/PixelManipulation.js')(input, {
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
output: output,
|
output: output,
|
||||||
@@ -35287,12 +35247,12 @@ module.exports = function NdviRed(options,UI) {
|
|||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.title = "NDVI for red-filtered cameras (blue is infrared)";
|
options.title = "NDVI for red-filtered cameras (blue is infrared)";
|
||||||
UI.onSetup();
|
UI.onSetup(options.step);
|
||||||
var output;
|
var output;
|
||||||
|
|
||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
|
|
||||||
UI.onDraw();
|
UI.onDraw(options.step);
|
||||||
const step = this;
|
const step = this;
|
||||||
|
|
||||||
function changePixel(r, g, b, a) {
|
function changePixel(r, g, b, a) {
|
||||||
@@ -35302,7 +35262,8 @@ module.exports = function NdviRed(options,UI) {
|
|||||||
}
|
}
|
||||||
function output(image,datauri,mimetype){
|
function output(image,datauri,mimetype){
|
||||||
step.output = {src:datauri,format:mimetype};
|
step.output = {src:datauri,format:mimetype};
|
||||||
UI.onComplete(datauri);
|
options.step.output = datauri;
|
||||||
|
UI.onComplete(options.step);
|
||||||
}
|
}
|
||||||
return require('../_nomodule/PixelManipulation.js')(input, {
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
output: output,
|
output: output,
|
||||||
@@ -35327,12 +35288,12 @@ module.exports = function SegmentedColormap(options,UI) {
|
|||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.title = "Segmented Colormap";
|
options.title = "Segmented Colormap";
|
||||||
UI.onSetup();
|
UI.onSetup(options.step);
|
||||||
var output;
|
var output;
|
||||||
|
|
||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
|
|
||||||
UI.onDraw();
|
UI.onDraw(options.step);
|
||||||
const step = this;
|
const step = this;
|
||||||
|
|
||||||
function changePixel(r, g, b, a) {
|
function changePixel(r, g, b, a) {
|
||||||
@@ -35343,7 +35304,8 @@ module.exports = function SegmentedColormap(options,UI) {
|
|||||||
}
|
}
|
||||||
function output(image,datauri,mimetype){
|
function output(image,datauri,mimetype){
|
||||||
step.output = {src:datauri,format:mimetype};
|
step.output = {src:datauri,format:mimetype};
|
||||||
UI.onComplete(datauri);
|
options.step.output = datauri;
|
||||||
|
UI.onComplete(options.step);
|
||||||
}
|
}
|
||||||
return require('../_nomodule/PixelManipulation.js')(input, {
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
output: output,
|
output: output,
|
||||||
|
|||||||
@@ -8,18 +8,14 @@ function AddStep(ref, image, name, o) {
|
|||||||
o.container = o_.container || ref.options.selector;
|
o.container = o_.container || ref.options.selector;
|
||||||
o.image = image;
|
o.image = image;
|
||||||
|
|
||||||
o.identity = {
|
o.step = {
|
||||||
stepName: o.name,
|
name: o.name,
|
||||||
stepID: o.number,
|
ID: o.number,
|
||||||
imageName: o.image
|
imageName: o.image,
|
||||||
|
inBrowser: ref.options.inBrowser,
|
||||||
|
ui: ref.options.ui
|
||||||
};
|
};
|
||||||
o.UIFs = ref.UI();
|
var UI = ref.events;
|
||||||
var UI = {
|
|
||||||
onSetup: function(){o.UIFs.onSetup(o.identity);},
|
|
||||||
onDraw: function(){o.UIFs.onSetup(o.identity);},
|
|
||||||
onComplete: function(out){o.UIFs.onSetup(o.identity,out);},
|
|
||||||
onRemove: function(){o.UIFs.onSetup(o.identity);},
|
|
||||||
}
|
|
||||||
var module = ref.modules[name](o,UI);
|
var module = ref.modules[name](o,UI);
|
||||||
ref.images[image].steps.push(module);
|
ref.images[image].steps.push(module);
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
formatInput = require('./FormatInput'),
|
formatInput = require('./FormatInput'),
|
||||||
images = {},
|
images = {},
|
||||||
inputlog = [],
|
inputlog = [],
|
||||||
UI;
|
events;
|
||||||
|
|
||||||
setUI();
|
setUI();
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
function removeStep(image,index) {
|
function removeStep(image,index) {
|
||||||
//remove the step from images[image].steps and redraw remaining images
|
//remove the step from images[image].steps and redraw remaining images
|
||||||
if(index>0) {
|
if(index>0) {
|
||||||
images[image].steps[index].UI.onRemove();
|
images[image].steps[index].UI.onRemove(images[image].steps[index].options.step);
|
||||||
images[image].steps.splice(index,1);
|
images[image].steps.splice(index,1);
|
||||||
}
|
}
|
||||||
//tell the UI a step has been removed
|
//tell the UI a step has been removed
|
||||||
@@ -161,9 +161,8 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
return require('./ReplaceImage')(this,selector,steps);
|
return require('./ReplaceImage')(this,selector,steps);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setUI(_UI) {
|
function setUI(UI) {
|
||||||
UI = require('./UserInterface')(_UI,options);
|
events = require('./UserInterface')(UI);
|
||||||
return UI;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -173,7 +172,7 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
inputlog: inputlog,
|
inputlog: inputlog,
|
||||||
modules: modules,
|
modules: modules,
|
||||||
images: images,
|
images: images,
|
||||||
UI: UI,
|
events: events,
|
||||||
|
|
||||||
//user functions
|
//user functions
|
||||||
loadImages: loadImages,
|
loadImages: loadImages,
|
||||||
|
|||||||
@@ -10,18 +10,14 @@ function InsertStep(ref, image, index, name, o) {
|
|||||||
|
|
||||||
if(index==-1) index = ref.images[image].steps.length;
|
if(index==-1) index = ref.images[image].steps.length;
|
||||||
|
|
||||||
o.identity = {
|
o.step = {
|
||||||
stepName: o.name,
|
name: o.name,
|
||||||
stepID: o.number,
|
ID: o.number,
|
||||||
imageName: o.image
|
imageName: o.image,
|
||||||
|
inBrowser: ref.options.inBrowser,
|
||||||
|
ui: ref.options.ui
|
||||||
};
|
};
|
||||||
o.UIFs = ref.UI();
|
var UI = ref.events;
|
||||||
var UI = {
|
|
||||||
onSetup: function(){o.UIFs.onSetup(o.identity);},
|
|
||||||
onDraw: function(){o.UIFs.onSetup(o.identity);},
|
|
||||||
onComplete: function(out){o.UIFs.onSetup(o.identity,out);},
|
|
||||||
onRemove: function(){o.UIFs.onSetup(o.identity);},
|
|
||||||
}
|
|
||||||
var module = ref.modules[name](o,UI);
|
var module = ref.modules[name](o,UI);
|
||||||
ref.images[image].steps.splice(index,0,module);
|
ref.images[image].steps.splice(index,0,module);
|
||||||
|
|
||||||
|
|||||||
@@ -9,27 +9,37 @@ function LoadImage(ref, name, src) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadImage(name, src) {
|
function loadImage(name, src) {
|
||||||
|
var step = {
|
||||||
|
name: "load-image",
|
||||||
|
ID: ref.options.sequencerCounter++,
|
||||||
|
imageName: name,
|
||||||
|
inBrowser: ref.options.inBrowser,
|
||||||
|
ui: ref.options.ui
|
||||||
|
};
|
||||||
|
|
||||||
var image = {
|
var image = {
|
||||||
src: src,
|
src: src,
|
||||||
steps: [{
|
steps: [{
|
||||||
options: {
|
options: {
|
||||||
id: ref.options.sequencerCounter++,
|
id: step.ID,
|
||||||
name: "load-image",
|
name: "load-image",
|
||||||
title: "Load Image"
|
title: "Load Image",
|
||||||
|
step: step
|
||||||
},
|
},
|
||||||
UI: ref.UI({
|
UI: ref.events,
|
||||||
stepName: "load-image",
|
|
||||||
stepID: ref.options.sequencerCounter++,
|
|
||||||
imageName: name
|
|
||||||
}),
|
|
||||||
draw: function() {
|
draw: function() {
|
||||||
|
UI.onDraw(options.step);
|
||||||
if(arguments.length==1){
|
if(arguments.length==1){
|
||||||
this.output = CImage(arguments[0]);
|
this.output = CImage(arguments[0]);
|
||||||
|
options.step.output = this.output;
|
||||||
|
UI.onComplete(options.step);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if(arguments.length==2) {
|
else if(arguments.length==2) {
|
||||||
this.output = CImage(arguments[0]);
|
this.output = CImage(arguments[0]);
|
||||||
|
options.step.output = this.output;
|
||||||
arguments[1]();
|
arguments[1]();
|
||||||
|
UI.onComplete(options.step);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -38,9 +48,11 @@ function LoadImage(ref, name, src) {
|
|||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
ref.images[name] = image;
|
ref.images[name] = image;
|
||||||
ref.images[name].steps[0].UI.onSetup();
|
loadImageStep = ref.images[name].steps[0];
|
||||||
ref.images[name].steps[0].UI.onDraw();
|
loadImageStep.options.step.output = loadImageStep.output.src;
|
||||||
ref.images[name].steps[0].UI.onComplete(image.steps[0].output.src);
|
loadImageStep.UI.onSetup(loadImageStep.options.step);
|
||||||
|
loadImageStep.UI.onDraw(loadImageStep.options.step);
|
||||||
|
loadImageStep.UI.onComplete(loadImageStep.options.step);
|
||||||
}
|
}
|
||||||
|
|
||||||
return loadImage(name,src);
|
return loadImage(name,src);
|
||||||
|
|||||||
@@ -1,75 +1,25 @@
|
|||||||
/*
|
/*
|
||||||
* Default UI for each image-sequencer module
|
* User Interface Handling Module
|
||||||
*/
|
*/
|
||||||
module.exports = function UserInterface(newUI = {},options) {
|
|
||||||
|
|
||||||
var UI = newUI;
|
module.exports = function UserInterface(events = {}) {
|
||||||
|
|
||||||
return function userInterface(identity) {
|
|
||||||
|
|
||||||
identity.ui = options.ui;
|
|
||||||
identity.inBrowser = options.inBrowser;
|
|
||||||
|
|
||||||
UI.onSetup = UI.onSetup || function(identity) {
|
|
||||||
if(identity.ui == false) {
|
|
||||||
// No UI
|
|
||||||
}
|
|
||||||
else if(identity.inBrowser) {
|
|
||||||
// Create and append an HTML Element
|
|
||||||
console.log("Added Step \""+identity.stepName+"\" to \""+identity.imageName+"\".");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Create a NodeJS Object
|
|
||||||
console.log('\x1b[36m%s\x1b[0m',"Added Step \""+identity.stepName+"\" to \""+identity.imageName+"\".");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UI.onDraw = UI.onDraw || function(identity) {
|
|
||||||
if (identity.ui == false) {
|
|
||||||
// No UI
|
|
||||||
}
|
|
||||||
else if(identity.inBrowser) {
|
|
||||||
// Overlay a loading spinner
|
|
||||||
console.log("Drawing Step \""+identity.stepName+"\" on \""+identity.imageName+"\".");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Don't do anything
|
|
||||||
console.log('\x1b[33m%s\x1b[0m',"Drawing Step \""+identity.stepName+"\" on \""+identity.imageName+"\".");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UI.onComplete = UI.onComplete || function(identity,output) {
|
|
||||||
if (identity.ui == false) {
|
|
||||||
// No UI
|
|
||||||
}
|
|
||||||
else if(identity.inBrowser) {
|
|
||||||
// Update the DIV Element
|
|
||||||
// Hide the laoding spinner
|
|
||||||
console.log("Drawn Step \""+identity.stepName+"\" on \""+identity.imageName+"\".");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Update the NodeJS Object
|
|
||||||
console.log('\x1b[32m%s\x1b[0m',"Drawn Step \""+identity.stepName+"\" on \""+identity.imageName+"\".");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UI.onRemove = UI.onRemove || function(identity) {
|
|
||||||
if(identity.ui == false){
|
|
||||||
// No UI
|
|
||||||
}
|
|
||||||
else if(identity.inBrowser) {
|
|
||||||
// Remove the DIV Element
|
|
||||||
console.log("Removing Step \""+identity.stepName+"\" of \""+identity.imageName+"\".");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Delete the NodeJS Object
|
|
||||||
console.log('\x1b[31m%s\x1b[0m',"Removing Step \""+identity.stepName+"\" of \""+identity.imageName+"\".");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return UI;
|
|
||||||
|
|
||||||
|
events.onSetup = events.onSetup || function(step) {
|
||||||
|
console.log("onSetup "+step.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
events.onDraw = events.onDraw || function(step) {
|
||||||
|
console.log("onDraw "+step.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
events.onComplete = events.onComplete || function(step) {
|
||||||
|
console.log("onComplete "+step.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
events.onRemove = events.onRemove || function(step) {
|
||||||
|
console.log("onRemove "+step.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return events;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,12 +16,12 @@
|
|||||||
module.exports = function CropModule(options,UI) {
|
module.exports = function CropModule(options,UI) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.title = "Crop Image";
|
options.title = "Crop Image";
|
||||||
UI.onSetup();
|
UI.onSetup(options.step);
|
||||||
var output
|
var output
|
||||||
|
|
||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
|
|
||||||
UI.onDraw();
|
UI.onDraw(options.step);
|
||||||
const step = this;
|
const step = this;
|
||||||
|
|
||||||
require('./Crop')(input,options,function(out,format){
|
require('./Crop')(input,options,function(out,format){
|
||||||
@@ -29,7 +29,8 @@
|
|||||||
src: out,
|
src: out,
|
||||||
format: format
|
format: format
|
||||||
}
|
}
|
||||||
UI.onComplete(out);
|
options.step.output = out;
|
||||||
|
UI.onComplete(options.step);
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,17 @@
|
|||||||
module.exports = function DoNothing(options,UI) {
|
module.exports = function DoNothing(options,UI) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.title = "Do Nothing";
|
options.title = "Do Nothing";
|
||||||
UI.onSetup();
|
UI.onSetup(options.step);
|
||||||
var output;
|
var output;
|
||||||
|
|
||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
UI.onDraw();
|
UI.onDraw(options.step);
|
||||||
|
|
||||||
this.output = input;
|
this.output = input;
|
||||||
|
|
||||||
|
options.step.output = this.output.src;
|
||||||
callback();
|
callback();
|
||||||
UI.onComplete(this.output.src);
|
UI.onComplete(options.step);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ module.exports = function DoNothingPix(options,UI) {
|
|||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.title = "Do Nothing with pixels";
|
options.title = "Do Nothing with pixels";
|
||||||
UI.onSetup();
|
UI.onSetup(options.step);
|
||||||
var output;
|
var output;
|
||||||
|
|
||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
|
|
||||||
UI.onDraw();
|
UI.onDraw(options.step);
|
||||||
const step = this;
|
const step = this;
|
||||||
|
|
||||||
function changePixel(r, g, b, a) {
|
function changePixel(r, g, b, a) {
|
||||||
@@ -18,7 +18,8 @@ module.exports = function DoNothingPix(options,UI) {
|
|||||||
}
|
}
|
||||||
function output(image,datauri,mimetype){
|
function output(image,datauri,mimetype){
|
||||||
step.output = {src:datauri,format:mimetype}
|
step.output = {src:datauri,format:mimetype}
|
||||||
UI.onComplete(datauri);
|
options.step.output = datauri;
|
||||||
|
UI.onComplete(options.step);
|
||||||
}
|
}
|
||||||
return require('../_nomodule/PixelManipulation.js')(input, {
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
output: output,
|
output: output,
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ module.exports = function GreenChannel(options,UI) {
|
|||||||
options = options || {};
|
options = options || {};
|
||||||
options.title = "Green channel only";
|
options.title = "Green channel only";
|
||||||
options.description = "Displays only the green channel of an image";
|
options.description = "Displays only the green channel of an image";
|
||||||
UI.onSetup();
|
UI.onSetup(options.step);
|
||||||
var output;
|
var output;
|
||||||
|
|
||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
|
|
||||||
UI.onDraw();
|
UI.onDraw(options.step);
|
||||||
const step = this;
|
const step = this;
|
||||||
|
|
||||||
function changePixel(r, g, b, a) {
|
function changePixel(r, g, b, a) {
|
||||||
@@ -19,7 +19,8 @@ module.exports = function GreenChannel(options,UI) {
|
|||||||
}
|
}
|
||||||
function output(image,datauri,mimetype){
|
function output(image,datauri,mimetype){
|
||||||
step.output = {src:datauri,format:mimetype};
|
step.output = {src:datauri,format:mimetype};
|
||||||
UI.onComplete(datauri);
|
options.step.output = datauri;
|
||||||
|
UI.onComplete(options.step);
|
||||||
}
|
}
|
||||||
return require('../_nomodule/PixelManipulation.js')(input, {
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
output: output,
|
output: output,
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ module.exports = function GreenChannel(options,UI) {
|
|||||||
options = options || {};
|
options = options || {};
|
||||||
options.title = "Invert Colors";
|
options.title = "Invert Colors";
|
||||||
options.description = "Inverts the colors of the image";
|
options.description = "Inverts the colors of the image";
|
||||||
UI.onSetup();
|
UI.onSetup(options.step);
|
||||||
var output;
|
var output;
|
||||||
|
|
||||||
//function setup() {} // optional
|
//function setup() {} // optional
|
||||||
|
|
||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
|
|
||||||
UI.onDraw();
|
UI.onDraw(options.step);
|
||||||
const step = this;
|
const step = this;
|
||||||
|
|
||||||
function changePixel(r, g, b, a) {
|
function changePixel(r, g, b, a) {
|
||||||
@@ -21,7 +21,8 @@ module.exports = function GreenChannel(options,UI) {
|
|||||||
}
|
}
|
||||||
function output(image,datauri,mimetype){
|
function output(image,datauri,mimetype){
|
||||||
step.output = {src:datauri,format:mimetype};
|
step.output = {src:datauri,format:mimetype};
|
||||||
UI.onComplete(datauri);
|
options.step.output = datauri;
|
||||||
|
UI.onComplete(options.step);
|
||||||
}
|
}
|
||||||
return require('../_nomodule/PixelManipulation.js')(input, {
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
output: output,
|
output: output,
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ module.exports = function NdviRed(options,UI) {
|
|||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.title = "NDVI for red-filtered cameras (blue is infrared)";
|
options.title = "NDVI for red-filtered cameras (blue is infrared)";
|
||||||
UI.onSetup();
|
UI.onSetup(options.step);
|
||||||
var output;
|
var output;
|
||||||
|
|
||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
|
|
||||||
UI.onDraw();
|
UI.onDraw(options.step);
|
||||||
const step = this;
|
const step = this;
|
||||||
|
|
||||||
function changePixel(r, g, b, a) {
|
function changePixel(r, g, b, a) {
|
||||||
@@ -20,7 +20,8 @@ module.exports = function NdviRed(options,UI) {
|
|||||||
}
|
}
|
||||||
function output(image,datauri,mimetype){
|
function output(image,datauri,mimetype){
|
||||||
step.output = {src:datauri,format:mimetype};
|
step.output = {src:datauri,format:mimetype};
|
||||||
UI.onComplete(datauri);
|
options.step.output = datauri;
|
||||||
|
UI.onComplete(options.step);
|
||||||
}
|
}
|
||||||
return require('../_nomodule/PixelManipulation.js')(input, {
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
output: output,
|
output: output,
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ module.exports = function SegmentedColormap(options,UI) {
|
|||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.title = "Segmented Colormap";
|
options.title = "Segmented Colormap";
|
||||||
UI.onSetup();
|
UI.onSetup(options.step);
|
||||||
var output;
|
var output;
|
||||||
|
|
||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
|
|
||||||
UI.onDraw();
|
UI.onDraw(options.step);
|
||||||
const step = this;
|
const step = this;
|
||||||
|
|
||||||
function changePixel(r, g, b, a) {
|
function changePixel(r, g, b, a) {
|
||||||
@@ -18,7 +18,8 @@ module.exports = function SegmentedColormap(options,UI) {
|
|||||||
}
|
}
|
||||||
function output(image,datauri,mimetype){
|
function output(image,datauri,mimetype){
|
||||||
step.output = {src:datauri,format:mimetype};
|
step.output = {src:datauri,format:mimetype};
|
||||||
UI.onComplete(datauri);
|
options.step.output = datauri;
|
||||||
|
UI.onComplete(options.step);
|
||||||
}
|
}
|
||||||
return require('../_nomodule/PixelManipulation.js')(input, {
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
output: output,
|
output: output,
|
||||||
|
|||||||
5
test.js
5
test.js
@@ -1,5 +1,4 @@
|
|||||||
require('./src/ImageSequencer');
|
require('./src/ImageSequencer');
|
||||||
sequencer = ImageSequencer();
|
sequencer = ImageSequencer();
|
||||||
sequencer.loadImages({images:{red:'examples/red.jpg'},callback:function(){
|
sequencer.loadImages('examples/red.jpg');
|
||||||
sequencer.addSteps(['do-nothing','invert']).run();
|
sequencer.addSteps('do-nothing');
|
||||||
}});
|
|
||||||
|
|||||||
Reference in New Issue
Block a user