mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-13 03:40:03 +01:00
Domain for Chaining
This commit is contained in:
20
README.md
20
README.md
@@ -154,6 +154,26 @@ sequencer.insertSteps(index,module_name,optional_options);
|
|||||||
return value: **`sequencer`** (To allow method chaining)
|
return value: **`sequencer`** (To allow method chaining)
|
||||||
|
|
||||||
|
|
||||||
|
## Method Chaining
|
||||||
|
Methods can be chained on the Image Sequencer:
|
||||||
|
* run() can not be in the middle of the chain.
|
||||||
|
* If the chain starts with loadImage() or loadImages(), the following methods are
|
||||||
|
applied only to the newly loaded images.
|
||||||
|
|
||||||
|
Valid Chains:
|
||||||
|
```js
|
||||||
|
sequencer.loadImage('red').addSteps('invert').run(function(out){
|
||||||
|
//do something with otuput.
|
||||||
|
});
|
||||||
|
sequencer.addSteps(['ndvi-red','invert']).run();
|
||||||
|
et cetra.
|
||||||
|
```
|
||||||
|
|
||||||
|
Invalid Chains:
|
||||||
|
```js
|
||||||
|
sequencer.addSteps('invert').run().addSteps('ndvi-red');
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Multiple Images
|
## Multiple Images
|
||||||
Image Sequencer is capable of handling multiple images at once.
|
Image Sequencer is capable of handling multiple images at once.
|
||||||
|
|||||||
68
dist/image-sequencer.js
vendored
68
dist/image-sequencer.js
vendored
@@ -34620,7 +34620,7 @@ function copy(a) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatInput(args,format,images) {
|
function formatInput(args,format,images) {
|
||||||
images = images || [];
|
images = [];
|
||||||
for (image in this.images) {
|
for (image in this.images) {
|
||||||
images.push(image);
|
images.push(image);
|
||||||
}
|
}
|
||||||
@@ -34745,6 +34745,11 @@ function formatInput(args,format,images) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(format_i == "l") {
|
||||||
|
json_q.loadedimages = [];
|
||||||
|
for (i in json_q.images) json_q.loadedimages.push(i);
|
||||||
|
}
|
||||||
|
|
||||||
return json_q;
|
return json_q;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -34801,15 +34806,18 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
// else if (options.imageUrl) loadImage(imageUrl);
|
// else if (options.imageUrl) loadImage(imageUrl);
|
||||||
|
|
||||||
function addSteps(){
|
function addSteps(){
|
||||||
args = [];
|
thiss = (this.name == "ImageSequencer")?this:this.sequencer;
|
||||||
json_q = {};
|
args = (this.name == "ImageSequencer")?[]:[this.images];
|
||||||
for(arg in arguments){args.push(copy(arguments[arg]));}
|
json_q = {};
|
||||||
json_q = formatInput.call(this,args,"+");
|
for(arg in arguments){args.push(copy(arguments[arg]));}
|
||||||
for (i in json_q)
|
json_q = formatInput.call(thiss,args,"+");
|
||||||
for (j in json_q[i])
|
|
||||||
require("./AddStep")(this,i,json_q[i][j].name,json_q[i][j].o);
|
for (i in json_q)
|
||||||
return this;
|
for (j in json_q[i])
|
||||||
}
|
require("./AddStep")(thiss,i,json_q[i][j].name,json_q[i][j].o);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
@@ -34822,9 +34830,10 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
|
|
||||||
function removeSteps(image,index) {
|
function removeSteps(image,index) {
|
||||||
run = {};
|
run = {};
|
||||||
args = [];
|
this_ = (this.name == "ImageSequencer")?this:this.sequencer;
|
||||||
|
args = (this.name == "ImageSequencer")?[]:[this.images];
|
||||||
for(arg in arguments) args.push(copy(arguments[arg]));
|
for(arg in arguments) args.push(copy(arguments[arg]));
|
||||||
json_q = formatInput.call(this,args,"-");
|
json_q = formatInput.call(this_,args,"-");
|
||||||
|
|
||||||
for (img in json_q) {
|
for (img in json_q) {
|
||||||
indices = json_q[img].sort(function(a,b){return b-a});
|
indices = json_q[img].sort(function(a,b){return b-a});
|
||||||
@@ -34838,17 +34847,17 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
|
|
||||||
function insertSteps(image, index, name, o) {
|
function insertSteps(image, index, name, o) {
|
||||||
run = {};
|
run = {};
|
||||||
this_ = this;
|
this_ = (this.name == "ImageSequencer")?this:this.sequencer;
|
||||||
args = [];
|
args = (this.name == "ImageSequencer")?[]:[this.images];
|
||||||
for (arg in arguments) args.push(arguments[arg]);
|
for (arg in arguments) args.push(arguments[arg]);
|
||||||
|
|
||||||
json_q = formatInput.call(this,args,"^");
|
json_q = formatInput.call(this_,args,"^");
|
||||||
|
|
||||||
for (img in json_q) {
|
for (img in json_q) {
|
||||||
var details = json_q[img];
|
var details = json_q[img];
|
||||||
details = details.sort(function(a,b){return b.index-a.index});
|
details = details.sort(function(a,b){return b.index-a.index});
|
||||||
for (i in details)
|
for (i in details)
|
||||||
require("./InsertStep")(this,img,details[i].index,details[i].name,details[i].o);
|
require("./InsertStep")(this_,img,details[i].index,details[i].name,details[i].o);
|
||||||
run[img] = details[details.length-1].index;
|
run[img] = details[details.length-1].index;
|
||||||
}
|
}
|
||||||
// this.run(run); // This is Creating issues
|
// this.run(run); // This is Creating issues
|
||||||
@@ -34857,19 +34866,19 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
|
|
||||||
function run(t_image,t_from) {
|
function run(t_image,t_from) {
|
||||||
log('\x1b[32m%s\x1b[0m',"Running the Sequencer!");
|
log('\x1b[32m%s\x1b[0m',"Running the Sequencer!");
|
||||||
this_ = this;
|
this_ = (this.name == "ImageSequencer")?this:this.sequencer;
|
||||||
args = [];
|
args = (this.name == "ImageSequencer")?[]:[this.images];
|
||||||
for (var arg in arguments) args.push(copy(arguments[arg]));
|
for (var arg in arguments) args.push(copy(arguments[arg]));
|
||||||
callback = function() {};
|
callback = function() {};
|
||||||
for (var arg in args)
|
for (var arg in args)
|
||||||
if(objTypeOf(args[arg]) == "Function")
|
if(objTypeOf(args[arg]) == "Function")
|
||||||
callback = args.splice(arg,1)[0];
|
callback = args.splice(arg,1)[0];
|
||||||
|
|
||||||
json_q = formatInput.call(this,args,"r");
|
json_q = formatInput.call(this_,args,"r");
|
||||||
|
|
||||||
require('./Run')(this, json_q, callback);
|
require('./Run')(this_, json_q, callback);
|
||||||
|
|
||||||
return this;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadImages() {
|
function loadImages() {
|
||||||
@@ -34877,11 +34886,21 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
for (arg in arguments) args.push(copy(arguments[arg]));
|
for (arg in arguments) args.push(copy(arguments[arg]));
|
||||||
json_q = formatInput.call(this,args,"l");
|
json_q = formatInput.call(this,args,"l");
|
||||||
|
|
||||||
|
loadedimages = this.copy(json_q.loadedimages);
|
||||||
|
|
||||||
for (i in json_q.images)
|
for (i in json_q.images)
|
||||||
require('./LoadImage')(this,i,json_q.images[i])
|
require('./LoadImage')(this,i,json_q.images[i])
|
||||||
|
|
||||||
json_q.callback();
|
json_q.callback();
|
||||||
return this;
|
return {
|
||||||
|
name: "ImageSequencer Wrapper",
|
||||||
|
sequencer: this,
|
||||||
|
addSteps: this.addSteps,
|
||||||
|
removeSteps: this.removeSteps,
|
||||||
|
insertSteps: this.insertSteps,
|
||||||
|
run: this.run,
|
||||||
|
images: loadedimages
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceImage(selector,steps,options) {
|
function replaceImage(selector,steps,options) {
|
||||||
@@ -34890,6 +34909,7 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
name: "ImageSequencer",
|
||||||
options: options,
|
options: options,
|
||||||
loadImages: loadImages,
|
loadImages: loadImages,
|
||||||
loadImage: loadImages,
|
loadImage: loadImages,
|
||||||
@@ -35047,7 +35067,7 @@ function Run(ref, json_q, callback) {
|
|||||||
steps = ref.images[image].steps;
|
steps = ref.images[image].steps;
|
||||||
out = steps[steps.length-1].output.src;
|
out = steps[steps.length-1].output.src;
|
||||||
callback(out);
|
callback(out);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
image = drawarray[pos].image;
|
image = drawarray[pos].image;
|
||||||
@@ -35083,7 +35103,7 @@ function Run(ref, json_q, callback) {
|
|||||||
return json_q;
|
return json_q;
|
||||||
}
|
}
|
||||||
json_q = filter(json_q);
|
json_q = filter(json_q);
|
||||||
drawSteps(json_q);
|
return drawSteps(json_q);
|
||||||
}
|
}
|
||||||
module.exports = Run;
|
module.exports = Run;
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ function copy(a) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatInput(args,format,images) {
|
function formatInput(args,format,images) {
|
||||||
images = images || [];
|
images = [];
|
||||||
for (image in this.images) {
|
for (image in this.images) {
|
||||||
images.push(image);
|
images.push(image);
|
||||||
}
|
}
|
||||||
@@ -149,6 +149,11 @@ function formatInput(args,format,images) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(format_i == "l") {
|
||||||
|
json_q.loadedimages = [];
|
||||||
|
for (i in json_q.images) json_q.loadedimages.push(i);
|
||||||
|
}
|
||||||
|
|
||||||
return json_q;
|
return json_q;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,15 +48,18 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
// else if (options.imageUrl) loadImage(imageUrl);
|
// else if (options.imageUrl) loadImage(imageUrl);
|
||||||
|
|
||||||
function addSteps(){
|
function addSteps(){
|
||||||
args = [];
|
thiss = (this.name == "ImageSequencer")?this:this.sequencer;
|
||||||
json_q = {};
|
args = (this.name == "ImageSequencer")?[]:[this.images];
|
||||||
for(arg in arguments){args.push(copy(arguments[arg]));}
|
json_q = {};
|
||||||
json_q = formatInput.call(this,args,"+");
|
for(arg in arguments){args.push(copy(arguments[arg]));}
|
||||||
for (i in json_q)
|
json_q = formatInput.call(thiss,args,"+");
|
||||||
for (j in json_q[i])
|
|
||||||
require("./AddStep")(this,i,json_q[i][j].name,json_q[i][j].o);
|
for (i in json_q)
|
||||||
return this;
|
for (j in json_q[i])
|
||||||
}
|
require("./AddStep")(thiss,i,json_q[i][j].name,json_q[i][j].o);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
@@ -69,9 +72,10 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
|
|
||||||
function removeSteps(image,index) {
|
function removeSteps(image,index) {
|
||||||
run = {};
|
run = {};
|
||||||
args = [];
|
this_ = (this.name == "ImageSequencer")?this:this.sequencer;
|
||||||
|
args = (this.name == "ImageSequencer")?[]:[this.images];
|
||||||
for(arg in arguments) args.push(copy(arguments[arg]));
|
for(arg in arguments) args.push(copy(arguments[arg]));
|
||||||
json_q = formatInput.call(this,args,"-");
|
json_q = formatInput.call(this_,args,"-");
|
||||||
|
|
||||||
for (img in json_q) {
|
for (img in json_q) {
|
||||||
indices = json_q[img].sort(function(a,b){return b-a});
|
indices = json_q[img].sort(function(a,b){return b-a});
|
||||||
@@ -85,17 +89,17 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
|
|
||||||
function insertSteps(image, index, name, o) {
|
function insertSteps(image, index, name, o) {
|
||||||
run = {};
|
run = {};
|
||||||
this_ = this;
|
this_ = (this.name == "ImageSequencer")?this:this.sequencer;
|
||||||
args = [];
|
args = (this.name == "ImageSequencer")?[]:[this.images];
|
||||||
for (arg in arguments) args.push(arguments[arg]);
|
for (arg in arguments) args.push(arguments[arg]);
|
||||||
|
|
||||||
json_q = formatInput.call(this,args,"^");
|
json_q = formatInput.call(this_,args,"^");
|
||||||
|
|
||||||
for (img in json_q) {
|
for (img in json_q) {
|
||||||
var details = json_q[img];
|
var details = json_q[img];
|
||||||
details = details.sort(function(a,b){return b.index-a.index});
|
details = details.sort(function(a,b){return b.index-a.index});
|
||||||
for (i in details)
|
for (i in details)
|
||||||
require("./InsertStep")(this,img,details[i].index,details[i].name,details[i].o);
|
require("./InsertStep")(this_,img,details[i].index,details[i].name,details[i].o);
|
||||||
run[img] = details[details.length-1].index;
|
run[img] = details[details.length-1].index;
|
||||||
}
|
}
|
||||||
// this.run(run); // This is Creating issues
|
// this.run(run); // This is Creating issues
|
||||||
@@ -104,19 +108,19 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
|
|
||||||
function run(t_image,t_from) {
|
function run(t_image,t_from) {
|
||||||
log('\x1b[32m%s\x1b[0m',"Running the Sequencer!");
|
log('\x1b[32m%s\x1b[0m',"Running the Sequencer!");
|
||||||
this_ = this;
|
this_ = (this.name == "ImageSequencer")?this:this.sequencer;
|
||||||
args = [];
|
args = (this.name == "ImageSequencer")?[]:[this.images];
|
||||||
for (var arg in arguments) args.push(copy(arguments[arg]));
|
for (var arg in arguments) args.push(copy(arguments[arg]));
|
||||||
callback = function() {};
|
callback = function() {};
|
||||||
for (var arg in args)
|
for (var arg in args)
|
||||||
if(objTypeOf(args[arg]) == "Function")
|
if(objTypeOf(args[arg]) == "Function")
|
||||||
callback = args.splice(arg,1)[0];
|
callback = args.splice(arg,1)[0];
|
||||||
|
|
||||||
json_q = formatInput.call(this,args,"r");
|
json_q = formatInput.call(this_,args,"r");
|
||||||
|
|
||||||
require('./Run')(this, json_q, callback);
|
require('./Run')(this_, json_q, callback);
|
||||||
|
|
||||||
return this;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadImages() {
|
function loadImages() {
|
||||||
@@ -124,11 +128,21 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
for (arg in arguments) args.push(copy(arguments[arg]));
|
for (arg in arguments) args.push(copy(arguments[arg]));
|
||||||
json_q = formatInput.call(this,args,"l");
|
json_q = formatInput.call(this,args,"l");
|
||||||
|
|
||||||
|
loadedimages = this.copy(json_q.loadedimages);
|
||||||
|
|
||||||
for (i in json_q.images)
|
for (i in json_q.images)
|
||||||
require('./LoadImage')(this,i,json_q.images[i])
|
require('./LoadImage')(this,i,json_q.images[i])
|
||||||
|
|
||||||
json_q.callback();
|
json_q.callback();
|
||||||
return this;
|
return {
|
||||||
|
name: "ImageSequencer Wrapper",
|
||||||
|
sequencer: this,
|
||||||
|
addSteps: this.addSteps,
|
||||||
|
removeSteps: this.removeSteps,
|
||||||
|
insertSteps: this.insertSteps,
|
||||||
|
run: this.run,
|
||||||
|
images: loadedimages
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceImage(selector,steps,options) {
|
function replaceImage(selector,steps,options) {
|
||||||
@@ -137,6 +151,7 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
name: "ImageSequencer",
|
||||||
options: options,
|
options: options,
|
||||||
loadImages: loadImages,
|
loadImages: loadImages,
|
||||||
loadImage: loadImages,
|
loadImage: loadImages,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ function Run(ref, json_q, callback) {
|
|||||||
steps = ref.images[image].steps;
|
steps = ref.images[image].steps;
|
||||||
out = steps[steps.length-1].output.src;
|
out = steps[steps.length-1].output.src;
|
||||||
callback(out);
|
callback(out);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
image = drawarray[pos].image;
|
image = drawarray[pos].image;
|
||||||
@@ -42,6 +42,6 @@ function Run(ref, json_q, callback) {
|
|||||||
return json_q;
|
return json_q;
|
||||||
}
|
}
|
||||||
json_q = filter(json_q);
|
json_q = filter(json_q);
|
||||||
drawSteps(json_q);
|
return drawSteps(json_q);
|
||||||
}
|
}
|
||||||
module.exports = Run;
|
module.exports = Run;
|
||||||
|
|||||||
Reference in New Issue
Block a user