Resolve Conflicts; Update DecodeQr Module

This commit is contained in:
Chinmay Pandhare
2017-07-29 04:25:50 +05:30
27 changed files with 41289 additions and 507 deletions

View File

@@ -37117,11 +37117,14 @@ function AddStep(ref, image, name, o) {
o.container = o_.container || ref.options.selector;
o.image = image;
var UI = ref.UI({
stepName: o.name,
stepID: o.number,
imageName: o.image
});
o.step = {
name: o.name,
ID: o.number,
imageName: o.image,
inBrowser: ref.options.inBrowser,
ui: ref.options.ui
};
var UI = ref.events;
var module = ref.modules[name](o,UI);
ref.images[image].steps.push(module);
@@ -37343,9 +37346,7 @@ ImageSequencer = function ImageSequencer(options) {
formatInput = require('./FormatInput'),
images = {},
inputlog = [],
UI;
setUI();
events = require('./UserInterface')();
// if in browser, prompt for an image
// if (options.imageSelect || options.inBrowser) addStep('image-select');
@@ -37370,7 +37371,8 @@ ImageSequencer = function ImageSequencer(options) {
function removeStep(image,index) {
//remove the step from images[image].steps and redraw remaining images
if(index>0) {
images[image].steps[index].UI.onRemove();
thisStep = images[image].steps[index];
thisStep.UI.onRemove(thisStep.options.step);
images[image].steps.splice(index,1);
}
//tell the UI a step has been removed
@@ -37434,17 +37436,15 @@ ImageSequencer = function ImageSequencer(options) {
function loadImages() {
var args = [];
var sequencer = this;
for (var arg in arguments) args.push(copy(arguments[arg]));
var json_q = formatInput.call(this,args,"l");
inputlog.push({method:"loadImages", json_q:copy(json_q)});
var loadedimages = this.copy(json_q.loadedimages);
// require('./LoadImage')(this,i,json_q.images[i]);
for (var i in json_q.images)
require('./LoadImage')(this,i,json_q.images[i])
json_q.callback();
return {
var ret = {
name: "ImageSequencer Wrapper",
sequencer: this,
addSteps: this.addSteps,
@@ -37455,6 +37455,19 @@ ImageSequencer = function ImageSequencer(options) {
setUI: this.setUI,
images: loadedimages
};
function load(i) {
if(i==loadedimages.length) {
json_q.callback.call(ret);
return;
}
var img = loadedimages[i];
require('./LoadImage')(sequencer,img,json_q.images[img],function(){
load(++i);
});
}
load(0);
}
function replaceImage(selector,steps,options) {
@@ -37462,9 +37475,8 @@ ImageSequencer = function ImageSequencer(options) {
return require('./ReplaceImage')(this,selector,steps);
}
function setUI(_UI) {
UI = require('./UserInterface')(_UI,options);
return UI;
function setUI(UI) {
this.events = require('./UserInterface')(UI);
}
return {
@@ -37474,7 +37486,7 @@ ImageSequencer = function ImageSequencer(options) {
inputlog: inputlog,
modules: modules,
images: images,
UI: UI,
events: events,
//user functions
loadImages: loadImages,
@@ -37508,11 +37520,14 @@ function InsertStep(ref, image, index, name, o) {
if(index==-1) index = ref.images[image].steps.length;
var UI = ref.UI({
stepName: o.name,
stepID: o.number,
imageName: o.image
});
o.step = {
name: o.name,
ID: o.number,
imageName: o.image,
inBrowser: ref.options.inBrowser,
ui: ref.options.ui
};
var UI = ref.events;
var module = ref.modules[name](o,UI);
ref.images[image].steps.splice(index,0,module);
@@ -37524,49 +37539,102 @@ function InsertStep(ref, image, index, name, o) {
module.exports = InsertStep;
},{}],116:[function(require,module,exports){
function LoadImage(ref, name, src) {
function CImage(src) {
var datauri = (ref.options.inBrowser || src.substring(0,11) == "data:image/")?(src):require('urify')(src);
function LoadImage(ref, name, src, main_callback) {
function makeImage(datauri) {
var image = {
src: datauri,
format: datauri.split(':')[1].split(';')[0].split('/')[1]
}
return image;
}
function CImage(src, callback) {
var datauri;
if (!!src.match(/^data:/i)) {
datauri = src;
callback(datauri);
}
else if (!ref.options.inBrowser && !!src.match(/^https?:\/\//i)) {
require( src.match(/^(https?):\/\//i)[1] ).get(src,function(res){
var data = '';
var contentType = res.headers['content-type'];
res.setEncoding('base64');
res.on('data',function(chunk) {data += chunk;});
res.on('end',function() {
callback("data:"+contentType+";base64,"+data);
});
});
}
else if (ref.options.inBrowser) {
var ext = src.split('.').pop();
var image = document.createElement('img');
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
image.onload = function() {
canvas.width = image.naturalWidth;
canvas.height = image.naturalHeight;
context.drawImage(image,0,0);
datauri = canvas.toDataURL(ext);
callback(datauri);
}
image.src = src;
}
else {
datauri = require('urify')(src);
callback(datauri);
}
}
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 = {
src: src,
steps: [{
options: {
id: ref.options.sequencerCounter++,
id: step.ID,
name: "load-image",
title: "Load Image"
title: "Load Image",
step: step
},
UI: ref.UI({
stepName: "load-image",
stepID: ref.options.sequencerCounter++,
imageName: name
}),
UI: ref.events,
draw: function() {
UI.onDraw(options.step);
if(arguments.length==1){
this.output = CImage(arguments[0]);
options.step.output = this.output;
UI.onComplete(options.step);
return true;
}
else if(arguments.length==2) {
this.output = CImage(arguments[0]);
options.step.output = this.output;
arguments[1]();
UI.onComplete(options.step);
return true;
}
return false;
},
output: CImage(src)
}]
};
ref.images[name] = image;
ref.images[name].steps[0].UI.onSetup();
ref.images[name].steps[0].UI.onDraw();
ref.images[name].steps[0].UI.onComplete(image.steps[0].output.src);
CImage(src, function(datauri) {
var output = makeImage(datauri);
ref.images[name] = image;
var loadImageStep = ref.images[name].steps[0];
loadImageStep.output = output;
loadImageStep.options.step.output = loadImageStep.output.src;
loadImageStep.UI.onSetup(loadImageStep.options.step);
loadImageStep.UI.onDraw(loadImageStep.options.step);
loadImageStep.UI.onComplete(loadImageStep.options.step);
main_callback();
return true;
});
}
return loadImage(name,src);
@@ -37677,76 +37745,70 @@ module.exports = Run;
},{}],120:[function(require,module,exports){
/*
* Default UI for each image-sequencer module
* User Interface Handling Module
*/
module.exports = function UserInterface(UI,options) {
return function userInterface(identity) {
module.exports = function UserInterface(events = {}) {
var UI = UI || {};
UI.onSetup = UI.onSetup || function() {
if(options.ui == false) {
events.onSetup = events.onSetup || function(step) {
if(step.ui == false) {
// No UI
}
else if(options.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() {
if (options.ui == false) {
// No UI
}
else if(options.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+"\".");
}
else if(step.inBrowser) {
// Create and append an HTML Element
console.log("Added Step \""+step.name+"\" to \""+step.imageName+"\".");
}
UI.onComplete = UI.onComplete || function(output) {
if (options.ui == false) {
// No UI
}
else if(options.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+"\".");
}
else {
// Create a NodeJS Object
console.log('\x1b[36m%s\x1b[0m',"Added Step \""+step.name+"\" to \""+step.imageName+"\".");
}
UI.onRemove = UI.onRemove || function(callback) {
if(options.ui == false){
// No UI
}
else if(options.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.onDraw = events.onDraw || function(step) {
if (step.ui == false) {
// No UI
}
else if(step.inBrowser) {
// Overlay a loading spinner
console.log("Drawing Step \""+step.name+"\" on \""+step.imageName+"\".");
}
else {
// Don't do anything
console.log('\x1b[33m%s\x1b[0m',"Drawing Step \""+step.name+"\" on \""+step.imageName+"\".");
}
}
events.onComplete = events.onComplete || function(step) {
if (step.ui == false) {
// No UI
}
else if(step.inBrowser) {
// Update the DIV Element
// Hide the laoding spinner
console.log("Drawn Step \""+step.name+"\" on \""+step.imageName+"\".");
}
else {
// Update the NodeJS Object
console.log('\x1b[32m%s\x1b[0m',"Drawn Step \""+step.name+"\" on \""+step.imageName+"\".");
}
}
events.onRemove = events.onRemove || function(step) {
if(step.ui == false){
// No UI
}
else if(step.inBrowser) {
// Remove the DIV Element
console.log("Removing Step \""+step.name+"\" of \""+step.imageName+"\".");
}
else {
// Delete the NodeJS Object
console.log('\x1b[31m%s\x1b[0m',"Removing Step \""+step.name+"\" of \""+step.imageName+"\".");
}
}
return events;
}
},{}],121:[function(require,module,exports){
@@ -37809,12 +37871,12 @@ module.exports = function Crop(input,options,callback) {
module.exports = function CropModule(options,UI) {
options = options || {};
options.title = "Crop Image";
UI.onSetup();
UI.onSetup(options.step);
var output
function draw(input,callback) {
UI.onDraw();
UI.onDraw(options.step);
const step = this;
require('./Crop')(input,options,function(out,format){
@@ -37822,7 +37884,8 @@ module.exports = function Crop(input,options,callback) {
src: out,
format: format
}
UI.onComplete(out);
options.step.output = out;
UI.onComplete(options.step);
callback();
});
@@ -37880,14 +37943,17 @@ module.exports = function DoNothing(options,UI) {
module.exports = function DoNothing(options,UI) {
options = options || {};
options.title = "Do Nothing";
UI.onSetup();
UI.onSetup(options.step);
var output;
function draw(input,callback) {
UI.onDraw();
UI.onDraw(options.step);
this.output = input;
options.step.output = this.output.src;
callback();
UI.onComplete(this.output.src);
UI.onComplete(options.step);
}
return {
@@ -37906,12 +37972,12 @@ module.exports = function DoNothingPix(options,UI) {
options = options || {};
options.title = "Do Nothing with pixels";
UI.onSetup();
UI.onSetup(options.step);
var output;
function draw(input,callback) {
UI.onDraw();
UI.onDraw(options.step);
const step = this;
function changePixel(r, g, b, a) {
@@ -37919,7 +37985,8 @@ module.exports = function DoNothingPix(options,UI) {
}
function output(image,datauri,mimetype){
step.output = {src:datauri,format:mimetype}
UI.onComplete(datauri);
options.step.output = datauri;
UI.onComplete(options.step);
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
@@ -37948,12 +38015,12 @@ module.exports = function GreenChannel(options,UI) {
options = options || {};
options.title = "Green channel only";
options.description = "Displays only the green channel of an image";
UI.onSetup();
UI.onSetup(options.step);
var output;
function draw(input,callback) {
UI.onDraw();
UI.onDraw(options.step);
const step = this;
function changePixel(r, g, b, a) {
@@ -37961,7 +38028,8 @@ module.exports = function GreenChannel(options,UI) {
}
function output(image,datauri,mimetype){
step.output = {src:datauri,format:mimetype};
UI.onComplete(datauri);
options.step.output = datauri;
UI.onComplete(options.step);
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
@@ -37991,14 +38059,14 @@ module.exports = function GreenChannel(options,UI) {
options = options || {};
options.title = "Invert Colors";
options.description = "Inverts the colors of the image";
UI.onSetup();
UI.onSetup(options.step);
var output;
//function setup() {} // optional
function draw(input,callback) {
UI.onDraw();
UI.onDraw(options.step);
const step = this;
function changePixel(r, g, b, a) {
@@ -38006,7 +38074,8 @@ module.exports = function GreenChannel(options,UI) {
}
function output(image,datauri,mimetype){
step.output = {src:datauri,format:mimetype};
UI.onComplete(datauri);
options.step.output = datauri;
UI.onComplete(options.step);
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
@@ -38035,12 +38104,12 @@ module.exports = function NdviRed(options,UI) {
options = options || {};
options.title = "NDVI for red-filtered cameras (blue is infrared)";
UI.onSetup();
UI.onSetup(options.step);
var output;
function draw(input,callback) {
UI.onDraw();
UI.onDraw(options.step);
const step = this;
function changePixel(r, g, b, a) {
@@ -38050,7 +38119,8 @@ module.exports = function NdviRed(options,UI) {
}
function output(image,datauri,mimetype){
step.output = {src:datauri,format:mimetype};
UI.onComplete(datauri);
options.step.output = datauri;
UI.onComplete(options.step);
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
@@ -38075,12 +38145,12 @@ module.exports = function SegmentedColormap(options,UI) {
options = options || {};
options.title = "Segmented Colormap";
UI.onSetup();
UI.onSetup(options.step);
var output;
function draw(input,callback) {
UI.onDraw();
UI.onDraw(options.step);
const step = this;
function changePixel(r, g, b, a) {
@@ -38091,7 +38161,8 @@ module.exports = function SegmentedColormap(options,UI) {
}
function output(image,datauri,mimetype){
step.output = {src:datauri,format:mimetype};
UI.onComplete(datauri);
options.step.output = datauri;
UI.onComplete(options.step);
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
@@ -38217,7 +38288,7 @@ module.exports = function PixelManipulation(image, options) {
// but node modules and their documentation are essentially arcane on this point
var chunks = [];
var totalLength = 0;
var r = savePixels(pixels, options.format);
var r = savePixels(pixels, options.format, {quality: 100});
r.on('data', function(chunk){
totalLength += chunk.length;