diff --git a/README.md b/README.md index 57fd2f28..ca289317 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,6 @@ var sequencer = ImageSequencer(); ``` ### Loading Images into the Sequencer - 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`. loadImages accepts 1, 2, or 3 parameters. @@ -61,7 +60,6 @@ loadImages accepts 1, 2, or 3 parameters. ``` ### Adding Steps on Images - 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. 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 - 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`. `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. ### Removing Steps from an Image - 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. @@ -125,7 +121,6 @@ sequencer.removeSteps({ ``` ### 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. ```js 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 diff --git a/examples/cyan.jpg b/examples/cyan.jpg new file mode 100644 index 00000000..ec09619b Binary files /dev/null and b/examples/cyan.jpg differ diff --git a/src/ImageSequencer.js b/src/ImageSequencer.js index 4d0c1a85..354dc798 100644 --- a/src/ImageSequencer.js +++ b/src/ImageSequencer.js @@ -94,7 +94,7 @@ ImageSequencer = function ImageSequencer(options) { details = details.sort(function(a,b){return b.index-a.index}); for (i in details) 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 } @@ -125,12 +125,20 @@ ImageSequencer = function ImageSequencer(options) { json_q.callback(); } + function replaceImage(image,src) { + this_ = this; + this_.images[image].steps[0].draw(src,function(){ + this_.run(); + }); + } + return { options: options, loadImages: loadImages, addSteps: addSteps, removeSteps: removeSteps, insertSteps: insertSteps, + replaceImage: replaceImage, run: run, modules: modules, images: images, diff --git a/src/LoadImage.js b/src/LoadImage.js index 772a2d1e..7beaf458 100644 --- a/src/LoadImage.js +++ b/src/LoadImage.js @@ -19,7 +19,12 @@ function LoadImage(ref, name, src) { }, draw: function() { 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 false; diff --git a/src/Run.js b/src/Run.js index fe78b624..19fb197f 100644 --- a/src/Run.js +++ b/src/Run.js @@ -1,5 +1,4 @@ function Run(ref, json_q, callback) { - function drawStep(drawarray,pos) { if(pos==drawarray.length) if(ref.objTypeOf(callback)=='Function') callback(); if(pos>=drawarray.length) return true; @@ -25,7 +24,7 @@ function Run(ref, json_q, callback) { for (image in json_q) { if (json_q[image]==0 && ref.images[image].steps.length==1) delete json_q[image]; - else json_q[image]++; + else if (json_q[image]==0) json_q[image]++; } for (image in json_q) { prevstep = ref.images[image].steps[json_q[image]-1]; diff --git a/test/image-sequencer.js b/test/image-sequencer.js index 83f06fcc..d2f0c69d 100644 --- a/test/image-sequencer.js +++ b/test/image-sequencer.js @@ -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.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(); +});