replaceImage

This commit is contained in:
Chinmay Pandhare
2017-07-01 23:49:24 +05:30
parent 74f1f92910
commit 3b16b66b28
6 changed files with 35 additions and 9 deletions

View File

@@ -38,7 +38,6 @@ var sequencer = ImageSequencer();
``` ```
### Loading Images into the Sequencer ### Loading Images into the Sequencer
Image Sequencer has an array of images which gets stored in `sequencer.images` in this case. Image Sequencer has an array of images which gets stored in `sequencer.images` in this case.
Images can be loaded into this array by the method `loadImages`. Images can be loaded into this array by the method `loadImages`.
loadImages accepts 1, 2, or 3 parameters. loadImages accepts 1, 2, or 3 parameters.
@@ -61,7 +60,6 @@ loadImages accepts 1, 2, or 3 parameters.
``` ```
### Adding Steps on Images ### Adding Steps on Images
After loading the image, we can add modules to the image using the addSteps method. After loading the image, we can add modules to the image using the addSteps method.
The options argument (object) is an optional parameter to pass in arguments to the module. The options argument (object) is an optional parameter to pass in arguments to the module.
In all the following examples, `image_name` and `module_name` may be a string or an array of strings. In all the following examples, `image_name` and `module_name` may be a string or an array of strings.
@@ -87,7 +85,6 @@ sequencer.addSteps({
``` ```
### Running the Sequencer ### Running the Sequencer
After adding the steps, now we must generate output for each of the step via the `run` method. After adding the steps, now we must generate output for each of the step via the `run` method.
The `run` method accepts parameters `image` and `from`. The `run` method accepts parameters `image` and `from`.
`from` is the index from where the function starts generating output. By default, it will run across all the steps. (from = 1) If no image is specified, the sequencer will be run over all the images. `from` is the index from where the function starts generating output. By default, it will run across all the steps. (from = 1) If no image is specified, the sequencer will be run over all the images.
@@ -104,7 +101,6 @@ image may either be an array or a string.
An optional callback may also be passed. An optional callback may also be passed.
### Removing Steps from an Image ### Removing Steps from an Image
Steps can be removed using the `removeSteps` method. It accepts `image` and `index` as parameters. Steps can be removed using the `removeSteps` method. It accepts `image` and `index` as parameters.
Either, both, or none of them can be an array. JSON input is also accepted. Either, both, or none of them can be an array. JSON input is also accepted.
@@ -125,7 +121,6 @@ sequencer.removeSteps({
``` ```
### Inserting steps on an image ### Inserting steps on an image
Steps can be inserted using the `insertSteps` method. It accepts `image`, `index`, `module_name` and `optional_options` as parameters. `image` may be an array. `optional_options` is an object. The rest are literals. JSON Input is supported too. If no image is provided, Steps will be inserted on all images. Indexes can be negative. Negative sign with an index means that counting will be done in reverse order. If the index is out of bounds, the counting will wrap in the original direction of counting. Steps can be inserted using the `insertSteps` method. It accepts `image`, `index`, `module_name` and `optional_options` as parameters. `image` may be an array. `optional_options` is an object. The rest are literals. JSON Input is supported too. If no image is provided, Steps will be inserted on all images. Indexes can be negative. Negative sign with an index means that counting will be done in reverse order. If the index is out of bounds, the counting will wrap in the original direction of counting.
```js ```js
sequencer.insertSteps("image",index,"module_name",o); sequencer.insertSteps("image",index,"module_name",o);
@@ -143,6 +138,12 @@ sequencer.insertSteps({
}); });
``` ```
### Replacing an Image
An existing image can be replaced with another image, retaining the steps of the initial image. This has a very straightforward syntax.
```js
sequencer.replaceImage('image_name',image_src);
```
## Contributing ## Contributing

BIN
examples/cyan.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 621 B

View File

@@ -94,7 +94,7 @@ ImageSequencer = function ImageSequencer(options) {
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
} }
@@ -125,12 +125,20 @@ ImageSequencer = function ImageSequencer(options) {
json_q.callback(); json_q.callback();
} }
function replaceImage(image,src) {
this_ = this;
this_.images[image].steps[0].draw(src,function(){
this_.run();
});
}
return { return {
options: options, options: options,
loadImages: loadImages, loadImages: loadImages,
addSteps: addSteps, addSteps: addSteps,
removeSteps: removeSteps, removeSteps: removeSteps,
insertSteps: insertSteps, insertSteps: insertSteps,
replaceImage: replaceImage,
run: run, run: run,
modules: modules, modules: modules,
images: images, images: images,

View File

@@ -19,7 +19,12 @@ function LoadImage(ref, name, src) {
}, },
draw: function() { draw: function() {
if(arguments.length==1){ if(arguments.length==1){
this.outputData = CImage(arguments[0]); this.output = CImage(arguments[0]);
return true;
}
else if(arguments.length==2) {
this.output = CImage(arguments[0]);
arguments[1]();
return true; return true;
} }
return false; return false;

View File

@@ -1,5 +1,4 @@
function Run(ref, json_q, callback) { function Run(ref, json_q, callback) {
function drawStep(drawarray,pos) { function drawStep(drawarray,pos) {
if(pos==drawarray.length) if(ref.objTypeOf(callback)=='Function') callback(); if(pos==drawarray.length) if(ref.objTypeOf(callback)=='Function') callback();
if(pos>=drawarray.length) return true; if(pos>=drawarray.length) return true;
@@ -25,7 +24,7 @@ function Run(ref, json_q, callback) {
for (image in json_q) { for (image in json_q) {
if (json_q[image]==0 && ref.images[image].steps.length==1) if (json_q[image]==0 && ref.images[image].steps.length==1)
delete json_q[image]; delete json_q[image];
else json_q[image]++; else if (json_q[image]==0) json_q[image]++;
} }
for (image in json_q) { for (image in json_q) {
prevstep = ref.images[image].steps[json_q[image]-1]; prevstep = ref.images[image].steps[json_q[image]-1];

View File

@@ -108,3 +108,16 @@ test('run() runs the sequencer', function (t) {
t.equal(typeof(sequencer.images.test.steps[sequencer.images.test.steps.length - 1].output), "object", "It Does!"); t.equal(typeof(sequencer.images.test.steps[sequencer.images.test.steps.length - 1].output), "object", "It Does!");
t.end(); t.end();
}); });
test('replaceImage() replaces the image and runs the sequencer', function (t) {
var testarray = [];
for (i in sequencer.images.test.steps) {
testarray.push(sequencer.images.test.steps[i].output.src);
}
t.equal(true,true);
sequencer.replaceImage('test','examples/cyan.jpg');
for (i in testarray) {
t.notEqual(testarray[i],sequencer.images.test.steps[i].output.src);
}
t.end();
});