Added Eslint and husky (#1062)

This commit is contained in:
aashna27
2019-05-11 20:09:15 +05:30
committed by Jeffrey Warren
parent 0c3d7be7e2
commit c784de0c19
203 changed files with 3288 additions and 3250 deletions

23
.eslintrc.js Normal file
View File

@@ -0,0 +1,23 @@
module.exports = {
'env': {
'browser': true,
'commonjs': true,
'es6': true,
'node': true
},
'extends': 'eslint:recommended',
'globals': {
'Atomics': 'readonly',
'SharedArrayBuffer': 'readonly'
},
'parserOptions': {
'ecmaVersion': 2018
},
'rules': {
'indent': ['error',2],
'linebreak-style': ['error','unix'],
'quotes': ['error','single'],
'semi': ['error','always'],
'no-undef': 0
}
};

View File

@@ -1,76 +1,76 @@
module.exports = function(grunt) { module.exports = function(grunt) {
grunt.loadNpmTasks("grunt-browserify"); grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks("grunt-contrib-uglify-es"); grunt.loadNpmTasks('grunt-contrib-uglify-es');
grunt.loadNpmTasks("grunt-browser-sync"); grunt.loadNpmTasks('grunt-browser-sync');
require("matchdep") require('matchdep')
.filterDev("grunt-*") .filterDev('grunt-*')
.forEach(grunt.loadNpmTasks); .forEach(grunt.loadNpmTasks);
grunt.initConfig({ grunt.initConfig({
pkg: grunt.file.readJSON("package.json"), pkg: grunt.file.readJSON('package.json'),
watch: { watch: {
options: { options: {
livereload: true livereload: true
}, },
source: { source: {
files: ["src/**/*", "Gruntfile.js", "examples/lib/*", "examples/demo.js"], files: ['src/**/*', 'Gruntfile.js', 'examples/lib/*', 'examples/demo.js'],
tasks: ["compile"] tasks: ['compile']
} }
}, },
browserify: { browserify: {
core: { core: {
src: ["src/ImageSequencer.js"], src: ['src/ImageSequencer.js'],
dest: "dist/image-sequencer.js" dest: 'dist/image-sequencer.js'
}, },
ui: { ui: {
src: ["examples/demo.js"], src: ['examples/demo.js'],
dest: "dist/image-sequencer-ui.js" dest: 'dist/image-sequencer-ui.js'
}, },
prodcore: { prodcore: {
src: ["src/ImageSequencer.js"], src: ['src/ImageSequencer.js'],
dest: "dist/image-sequencer.brow.js" dest: 'dist/image-sequencer.brow.js'
}, },
produi: { produi: {
src: ["examples/demo.js"], src: ['examples/demo.js'],
dest: "dist/image-sequencer-ui.brow.js" dest: 'dist/image-sequencer-ui.brow.js'
} }
}, },
uglify: { uglify: {
core: { core: {
src: ["./dist/image-sequencer.js"], src: ['./dist/image-sequencer.js'],
dest: "./dist/image-sequencer.min.js" dest: './dist/image-sequencer.min.js'
}, },
ui: { ui: {
src: ['dist/image-sequencer-ui.js'], src: ['dist/image-sequencer-ui.js'],
dest: 'dist/image-sequencer-ui.min.js' dest: 'dist/image-sequencer-ui.min.js'
}, },
prodcore: { prodcore: {
src: ["dist/image-sequencer.brow.js"], src: ['dist/image-sequencer.brow.js'],
dest: "dist/image-sequencer.js" dest: 'dist/image-sequencer.js'
}, },
produi: { produi: {
src: ["dist/image-sequencer-ui.brow.js"], src: ['dist/image-sequencer-ui.brow.js'],
dest: "dist/image-sequencer-ui.js" dest: 'dist/image-sequencer-ui.js'
} }
}, },
browserSync: { browserSync: {
dev: { dev: {
options: { options: {
watchTask: true, watchTask: true,
server: "./" server: './'
} }
} }
} }
}); });
/* Default (development): Watch files and build on change. */ /* Default (development): Watch files and build on change. */
grunt.registerTask("default", ["watch"]); grunt.registerTask('default', ['watch']);
grunt.registerTask("build", ["browserify:core", "browserify:ui", "uglify:core", "uglify:ui"]); grunt.registerTask('build', ['browserify:core', 'browserify:ui', 'uglify:core', 'uglify:ui']);
grunt.registerTask("serve", ["browserify:core", "browserify:ui", "browserSync", "watch"]); grunt.registerTask('serve', ['browserify:core', 'browserify:ui', 'browserSync', 'watch']);
grunt.registerTask("compile", ["browserify:core", "browserify:ui"]); grunt.registerTask('compile', ['browserify:core', 'browserify:ui']);
grunt.registerTask("production", ["browserify:prodcore", "browserify:produi", "uglify:prodcore", "uglify:produi"]); grunt.registerTask('production', ['browserify:prodcore', 'browserify:produi', 'uglify:prodcore', 'uglify:produi']);
}; };

View File

@@ -1,9 +1,9 @@
var defaultHtmlSequencerUi = require('./lib/defaultHtmlSequencerUi.js'), var defaultHtmlSequencerUi = require('./lib/defaultHtmlSequencerUi.js'),
setupCache = require('./lib/cache.js'), setupCache = require('./lib/cache.js'),
intermediateHtmlStepUi = require('./lib/intermediateHtmlStepUi.js'), intermediateHtmlStepUi = require('./lib/intermediateHtmlStepUi.js'),
DefaultHtmlStepUi = require('./lib/defaultHtmlStepUi.js'), DefaultHtmlStepUi = require('./lib/defaultHtmlStepUi.js'),
urlHash = require('./lib/urlHash.js'), urlHash = require('./lib/urlHash.js'),
insertPreview = require('./lib/insertPreview.js'); insertPreview = require('./lib/insertPreview.js');
window.onload = function() { window.onload = function() {
sequencer = ImageSequencer(); sequencer = ImageSequencer();
@@ -12,21 +12,21 @@ window.onload = function() {
// Load information of all modules (Name, Inputs, Outputs) // Load information of all modules (Name, Inputs, Outputs)
var modulesInfo = sequencer.modulesInfo(); var modulesInfo = sequencer.modulesInfo();
var addStepSelect = $("#addStep select"); var addStepSelect = $('#addStep select');
addStepSelect.html(""); addStepSelect.html('');
// Add modules to the addStep dropdown // Add modules to the addStep dropdown
for (var m in modulesInfo) { for (var m in modulesInfo) {
if (modulesInfo[m] && modulesInfo[m].name) if (modulesInfo[m] && modulesInfo[m].name)
addStepSelect.append( addStepSelect.append(
'<option value="' + m + '">' + modulesInfo[m].name + "</option>" '<option value="' + m + '">' + modulesInfo[m].name + '</option>'
); );
} }
// Null option // Null option
addStepSelect.append('<option value="" disabled selected>Select a Module</option>'); addStepSelect.append('<option value="" disabled selected>Select a Module</option>');
addStepSelect.selectize({ addStepSelect.selectize({
sortField: 'text' sortField: 'text'
}); });
} }
refreshOptions(); refreshOptions();
@@ -36,7 +36,7 @@ window.onload = function() {
var shouldDisplay = $('body').scrollTop() > 20 || $(':root').scrollTop() > 20; var shouldDisplay = $('body').scrollTop() > 20 || $(':root').scrollTop() > 20;
$('#move-up').css({ $('#move-up').css({
display: shouldDisplay ? 'block' : 'none' display: shouldDisplay ? 'block' : 'none'
}); });
} }
@@ -46,7 +46,7 @@ window.onload = function() {
$(':root').animate({scrollTop: 0}); $(':root').animate({scrollTop: 0});
} }
$('#move-up').on("click",topFunction); $('#move-up').on('click',topFunction);
// UI for each step: // UI for each step:
@@ -59,48 +59,48 @@ window.onload = function() {
if (urlHash.getUrlHashParameter('src')) { if (urlHash.getUrlHashParameter('src')) {
sequencer.loadImage(urlHash.getUrlHashParameter('src'), ui.onLoad); sequencer.loadImage(urlHash.getUrlHashParameter('src'), ui.onLoad);
} else { } else {
sequencer.loadImage("images/tulips.png", ui.onLoad); sequencer.loadImage('images/tulips.png', ui.onLoad);
} }
var resetSequence = function(){ var resetSequence = function(){
var r=confirm("Do you want to reset the sequence?"); var r=confirm('Do you want to reset the sequence?');
if (r) if (r)
window.location = "/"; window.location = '/';
} };
$("#addStep select").on("change", ui.selectNewStepUi); $('#addStep select').on('change', ui.selectNewStepUi);
$("#addStep #add-step-btn").on("click", ui.addStepUi); $('#addStep #add-step-btn').on('click', ui.addStepUi);
$("#resetButton").on("click",resetSequence); $('#resetButton').on('click',resetSequence);
//Module button radio selection //Module button radio selection
$('.radio-group .radio').on("click", function() { $('.radio-group .radio').on('click', function() {
$(this).parent().find('.radio').removeClass('selected'); $(this).parent().find('.radio').removeClass('selected');
$(this).addClass('selected'); $(this).addClass('selected');
newStep = $(this).attr('data-value'); newStep = $(this).attr('data-value');
//$("#addStep option[value=" + newStep + "]").attr('selected', 'selected'); //$("#addStep option[value=" + newStep + "]").attr('selected', 'selected');
$("#addStep select").val(newStep); $('#addStep select').val(newStep);
ui.selectNewStepUi(newStep); ui.selectNewStepUi(newStep);
ui.addStepUi(newStep); ui.addStepUi(newStep);
$(this).removeClass('selected'); $(this).removeClass('selected');
}); });
$('#download-btn').click(function() { $('#download-btn').click(function() {
$('.step-thumbnail:last()').trigger("click"); $('.step-thumbnail:last()').trigger('click');
return false; return false;
}); });
function displayMessageOnSaveSequence(){ function displayMessageOnSaveSequence(){
$(".savesequencemsg").fadeIn(); $('.savesequencemsg').fadeIn();
setTimeout(function() { setTimeout(function() {
$(".savesequencemsg").fadeOut(); $('.savesequencemsg').fadeOut();
}, 1000); }, 1000);
} }
$('body').on('click', 'button.remove', ui.removeStepUi); $('body').on('click', 'button.remove', ui.removeStepUi);
$('#save-seq').click(() => { $('#save-seq').click(() => {
var result = window.prompt("Please give a name to your sequence... (Saved sequence will only be available in this browser)."); var result = window.prompt('Please give a name to your sequence... (Saved sequence will only be available in this browser).');
if(result){ if(result){
result = result + " (local)"; result = result + ' (local)';
sequencer.saveSequence(result, sequencer.toString()); sequencer.saveSequence(result, sequencer.toString());
sequencer.loadModules(); sequencer.loadModules();
displayMessageOnSaveSequence(); displayMessageOnSaveSequence();
@@ -118,11 +118,11 @@ window.onload = function() {
var button = event.target; var button = event.target;
button.disabled = true; button.disabled = true;
button.innerHTML='<i class="fa fa-circle-o-notch fa-spin"></i>' button.innerHTML='<i class="fa fa-circle-o-notch fa-spin"></i>';
try { try {
// Select all images from previous steps // Select all images from previous steps
var imgs = document.getElementsByClassName("step-thumbnail"); var imgs = document.getElementsByClassName('step-thumbnail');
var imgSrcs = []; var imgSrcs = [];
@@ -135,7 +135,7 @@ window.onload = function() {
'gifHeight': imgs[0].height, 'gifHeight': imgs[0].height,
'images': imgSrcs, 'images': imgSrcs,
'frameDuration': 7, 'frameDuration': 7,
} };
gifshot.createGIF(options, function(obj) { gifshot.createGIF(options, function(obj) {
if (!obj.error) { if (!obj.error) {
@@ -143,21 +143,21 @@ window.onload = function() {
var image = obj.image; var image = obj.image;
var animatedImage = document.createElement('img'); var animatedImage = document.createElement('img');
animatedImage.id = "gif_element"; animatedImage.id = 'gif_element';
animatedImage.src = image; animatedImage.src = image;
var modal = $('#js-download-gif-modal'); var modal = $('#js-download-gif-modal');
$("#js-download-as-gif-button").one("click", function() { $('#js-download-as-gif-button').one('click', function() {
// Trigger download // Trigger download
download(image, "index.gif", "image/gif"); download(image, 'index.gif', 'image/gif');
// Close modal // Close modal
modal.modal('hide'); modal.modal('hide');
}) });
var gifContainer = document.getElementById("js-download-modal-gif-container"); var gifContainer = document.getElementById('js-download-modal-gif-container');
// Clear previous results // Clear previous results
gifContainer.innerHTML = ''; gifContainer.innerHTML = '';
@@ -186,16 +186,16 @@ window.onload = function() {
// image selection and drag/drop handling from examples/lib/imageSelection.js // image selection and drag/drop handling from examples/lib/imageSelection.js
sequencer.setInputStep({ sequencer.setInputStep({
dropZoneSelector: "#dropzone", dropZoneSelector: '#dropzone',
fileInputSelector: "#fileInput", fileInputSelector: '#fileInput',
takePhotoSelector: "#take-photo", takePhotoSelector: '#take-photo',
onLoad: function onFileReaderLoad(progress) { onLoad: function onFileReaderLoad(progress) {
var reader = progress.target; var reader = progress.target;
var step = sequencer.steps[0]; var step = sequencer.steps[0];
var util= intermediateHtmlStepUi(sequencer); var util= intermediateHtmlStepUi(sequencer);
step.output.src = reader.result; step.output.src = reader.result;
sequencer.run({ index: 0 }); sequencer.run({ index: 0 });
if(typeof step.options !=="undefined") if(typeof step.options !=='undefined')
step.options.step.imgElement.src = reader.result; step.options.step.imgElement.src = reader.result;
else else
step.imgElement.src = reader.result; step.imgElement.src = reader.result;
@@ -206,7 +206,7 @@ window.onload = function() {
var step = sequencer.steps[0]; var step = sequencer.steps[0];
step.output.src = url; step.output.src = url;
sequencer.run({ index: 0 }); sequencer.run({ index: 0 });
if(typeof step.options !=="undefined") if(typeof step.options !=='undefined')
step.options.step.imgElement.src = url; step.options.step.imgElement.src = url;
else else
step.imgElement.src = url; step.imgElement.src = url;
@@ -220,6 +220,6 @@ window.onload = function() {
if (urlHash.getUrlHashParameter('src')) { if (urlHash.getUrlHashParameter('src')) {
insertPreview.updatePreviews(urlHash.getUrlHashParameter('src'),'#addStep'); insertPreview.updatePreviews(urlHash.getUrlHashParameter('src'),'#addStep');
} else { } else {
insertPreview.updatePreviews("images/tulips.png",'#addStep'); insertPreview.updatePreviews('images/tulips.png','#addStep');
} }
}; };

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -4,11 +4,11 @@ var setupCache = function() {
.then(function(registration) { .then(function(registration) {
const installingWorker = registration.installing; const installingWorker = registration.installing;
installingWorker.onstatechange = () => { installingWorker.onstatechange = () => {
console.log(installingWorker) console.log(installingWorker);
if (installingWorker.state === 'installed') { if (installingWorker.state === 'installed') {
location.reload(); location.reload();
} }
} };
console.log('Registration successful, scope is:', registration.scope); console.log('Registration successful, scope is:', registration.scope);
}) })
.catch(function(error) { .catch(function(error) {
@@ -19,12 +19,12 @@ var setupCache = function() {
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
caches.keys().then(function(cacheNames) { caches.keys().then(function(cacheNames) {
cacheNames.forEach(function(cacheName) { cacheNames.forEach(function(cacheName) {
$("#clear-cache").append(" " + cacheName); $('#clear-cache').append(' ' + cacheName);
}); });
}); });
} }
$("#clear-cache").click(function() { $('#clear-cache').click(function() {
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
caches.keys().then(function(cacheNames) { caches.keys().then(function(cacheNames) {
cacheNames.forEach(function(cacheName) { cacheNames.forEach(function(cacheName) {
@@ -34,6 +34,6 @@ var setupCache = function() {
} }
location.reload(); location.reload();
}); });
} };
module.exports = setupCache; module.exports = setupCache;

View File

@@ -2,50 +2,50 @@ var urlHash = require('./urlHash.js');
function DefaultHtmlSequencerUi(_sequencer, options) { function DefaultHtmlSequencerUi(_sequencer, options) {
options = options || {}; options = options || {};
var addStepSel = options.addStepSel = options.addStepSel || "#addStep"; var addStepSel = options.addStepSel = options.addStepSel || '#addStep';
var removeStepSel = options.removeStepSel = options.removeStepSel || "button.remove"; var removeStepSel = options.removeStepSel = options.removeStepSel || 'button.remove';
var selectStepSel = options.selectStepSel = options.selectStepSel || "#selectStep"; var selectStepSel = options.selectStepSel = options.selectStepSel || '#selectStep';
function onLoad() { function onLoad() {
importStepsFromUrlHash(); importStepsFromUrlHash();
if ($('#selectStep').val()==='none') if ($('#selectStep').val()==='none')
$(addStepSel + " #add-step-btn").prop("disabled", true); $(addStepSel + ' #add-step-btn').prop('disabled', true);
handleSaveSequence(); handleSaveSequence();
} }
// look up needed steps from Url Hash: // look up needed steps from Url Hash:
function importStepsFromUrlHash() { function importStepsFromUrlHash() {
var hash = urlHash.getUrlHashParameter("steps"); var hash = urlHash.getUrlHashParameter('steps');
if (hash) { if (hash) {
_sequencer.importString(hash); _sequencer.importString(hash);
_sequencer.run({ index: 0 }); _sequencer.run({ index: 0 });
} }
urlHash.setUrlHashParameter("steps", sequencer.toString()); urlHash.setUrlHashParameter('steps', sequencer.toString());
} }
function selectNewStepUi() { function selectNewStepUi() {
var m = $(addStepSel + " select").val(); var m = $(addStepSel + ' select').val();
if(!m) m = arguments[0]; if(!m) m = arguments[0];
$(addStepSel + " .info").html(_sequencer.modulesInfo(m).description); $(addStepSel + ' .info').html(_sequencer.modulesInfo(m).description);
$(addStepSel + " #add-step-btn").prop("disabled", false); $(addStepSel + ' #add-step-btn').prop('disabled', false);
} }
function removeStepUi() { function removeStepUi() {
var index = $(removeStepSel).index(this) + 1; var index = $(removeStepSel).index(this) + 1;
sequencer.removeSteps(index).run({ index: index - 1 }); sequencer.removeSteps(index).run({ index: index - 1 });
// remove from URL hash too // remove from URL hash too
urlHash.setUrlHashParameter("steps", sequencer.toString()); urlHash.setUrlHashParameter('steps', sequencer.toString());
//disable save-sequence button if all steps are removed //disable save-sequence button if all steps are removed
handleSaveSequence(); handleSaveSequence();
} }
function addStepUi() { function addStepUi() {
if ($(addStepSel + " select").val() == "none") return; if ($(addStepSel + ' select').val() == 'none') return;
var newStepName; var newStepName;
if(typeof arguments[0] !== "string") if(typeof arguments[0] !== 'string')
newStepName = $(addStepSel + " select option").html().toLowerCase(); newStepName = $(addStepSel + ' select option').html().toLowerCase();
else newStepName = arguments[0] else newStepName = arguments[0];
/* /*
@@ -56,28 +56,28 @@ function DefaultHtmlSequencerUi(_sequencer, options) {
var sequenceLength = 1; var sequenceLength = 1;
if (sequencer.sequences[newStepName]) { if (sequencer.sequences[newStepName]) {
sequenceLength = sequencer.sequences[newStepName].length; sequenceLength = sequencer.sequences[newStepName].length;
} else if (sequencer.modules[newStepName][1]["length"]) { } else if (sequencer.modules[newStepName][1]['length']) {
sequenceLength = sequencer.modules[newStepName][1]["length"]; sequenceLength = sequencer.modules[newStepName][1]['length'];
} }
_sequencer _sequencer
.addSteps(newStepName, options) .addSteps(newStepName, options)
.run({ index: _sequencer.steps.length - sequenceLength - 1 }); .run({ index: _sequencer.steps.length - sequenceLength - 1 });
$(addStepSel + " .info").html("Select a new module to add to your sequence."); $(addStepSel + ' .info').html('Select a new module to add to your sequence.');
$(addStepSel + " select").val("none"); $(addStepSel + ' select').val('none');
//enable save-sequence button if disabled initially //enable save-sequence button if disabled initially
handleSaveSequence(); handleSaveSequence();
// add to URL hash too // add to URL hash too
urlHash.setUrlHashParameter("steps", _sequencer.toString()) urlHash.setUrlHashParameter('steps', _sequencer.toString());
} }
function handleSaveSequence(){ function handleSaveSequence(){
var stepCount=sequencer.steps.length; var stepCount=sequencer.steps.length;
if(stepCount<2) if(stepCount<2)
$(" #save-seq").prop("disabled", true); $(' #save-seq').prop('disabled', true);
else else
$(" #save-seq").prop("disabled", false); $(' #save-seq').prop('disabled', false);
} }
return { return {
@@ -86,7 +86,7 @@ function DefaultHtmlSequencerUi(_sequencer, options) {
selectNewStepUi: selectNewStepUi, selectNewStepUi: selectNewStepUi,
removeStepUi: removeStepUi, removeStepUi: removeStepUi,
addStepUi: addStepUi addStepUi: addStepUi
} };
} }
module.exports = DefaultHtmlSequencerUi; module.exports = DefaultHtmlSequencerUi;

View File

@@ -16,8 +16,8 @@ var mapHtmlTypes = require('./mapHtmltypes');
function DefaultHtmlStepUi(_sequencer, options) { function DefaultHtmlStepUi(_sequencer, options) {
options = options || {}; options = options || {};
var stepsEl = options.stepsEl || document.querySelector("#steps"); var stepsEl = options.stepsEl || document.querySelector('#steps');
var selectStepSel = options.selectStepSel = options.selectStepSel || "#selectStep"; var selectStepSel = options.selectStepSel = options.selectStepSel || '#selectStep';
function onSetup(step, stepOptions) { function onSetup(step, stepOptions) {
if (step.options && step.options.description) if (step.options && step.options.description)
@@ -39,7 +39,7 @@ function DefaultHtmlStepUi(_sequencer, options) {
<div class="row step">\ <div class="row step">\
<div class="col-md-4 details container-fluid">\ <div class="col-md-4 details container-fluid">\
<div class="cal collapse in"><p>' + <div class="cal collapse in"><p>' +
'<i>' + (step.description || "") + '</i>' + '<i>' + (step.description || '') + '</i>' +
'</p></div>\ '</p></div>\
</div>\ </div>\
<div class="col-md-8 cal collapse in step-column">\ <div class="col-md-8 cal collapse in step-column">\
@@ -65,10 +65,10 @@ function DefaultHtmlStepUi(_sequencer, options) {
var util = intermediateHtmlStepUi(_sequencer, step); var util = intermediateHtmlStepUi(_sequencer, step);
var parser = new DOMParser(); var parser = new DOMParser();
step.ui = parser.parseFromString(step.ui, "text/html"); step.ui = parser.parseFromString(step.ui, 'text/html');
step.ui = step.ui.querySelector("div.container-fluid"); step.ui = step.ui.querySelector('div.container-fluid');
step.linkElements = step.ui.querySelectorAll("a"); step.linkElements = step.ui.querySelectorAll('a');
step.imgElement = step.ui.querySelector("a img.img-thumbnail"); step.imgElement = step.ui.querySelector('a img.img-thumbnail');
if (_sequencer.modulesInfo().hasOwnProperty(step.name)) { if (_sequencer.modulesInfo().hasOwnProperty(step.name)) {
var inputs = _sequencer.modulesInfo(step.name).inputs; var inputs = _sequencer.modulesInfo(step.name).inputs;
@@ -77,16 +77,16 @@ function DefaultHtmlStepUi(_sequencer, options) {
for (var paramName in merged) { for (var paramName in merged) {
var isInput = inputs.hasOwnProperty(paramName); var isInput = inputs.hasOwnProperty(paramName);
var html = ""; var html = '';
var inputDesc = isInput ? mapHtmlTypes(inputs[paramName]) : {}; var inputDesc = isInput ? mapHtmlTypes(inputs[paramName]) : {};
if (!isInput) { if (!isInput) {
html += '<span class="output"></span>'; html += '<span class="output"></span>';
} else if (inputDesc.type.toLowerCase() == "select") { } else if (inputDesc.type.toLowerCase() == 'select') {
html += '<select class="form-control target" name="' + paramName + '">'; html += '<select class="form-control target" name="' + paramName + '">';
for (var option in inputDesc.values) { for (var option in inputDesc.values) {
html += "<option>" + inputDesc.values[option] + "</option>"; html += '<option>' + inputDesc.values[option] + '</option>';
} }
html += "</select>"; html += '</select>';
} else { } else {
let paramVal = step.options[paramName] || inputDesc.default; let paramVal = step.options[paramName] || inputDesc.default;
html = html =
@@ -97,9 +97,9 @@ function DefaultHtmlStepUi(_sequencer, options) {
'" value="' + '" value="' +
paramVal + paramVal +
'" placeholder ="' + '" placeholder ="' +
(inputDesc.placeholder || ""); (inputDesc.placeholder || '');
if (inputDesc.type.toLowerCase() == "range") { if (inputDesc.type.toLowerCase() == 'range') {
html += html +=
'"min="' + '"min="' +
inputDesc.min + inputDesc.min +
@@ -112,76 +112,76 @@ function DefaultHtmlStepUi(_sequencer, options) {
else html += '">'; else html += '">';
} }
var div = document.createElement("div"); var div = document.createElement('div');
div.className = "row"; div.className = 'row';
div.setAttribute("name", paramName); div.setAttribute('name', paramName);
var description = inputs[paramName].desc || paramName; var description = inputs[paramName].desc || paramName;
div.innerHTML = div.innerHTML =
"<div class='det cal collapse in'>\ '<div class=\'det cal collapse in\'>\
<label for='" + <label for=\'' +
paramName + paramName +
"'>" + '\'>' +
description + description +
"</label>\ '</label>\
" + ' +
html + html +
"\ '\
</div>"; </div>';
step.ui.querySelector("div.details").appendChild(div); step.ui.querySelector('div.details').appendChild(div);
} }
$(step.ui.querySelector("div.panel-footer")).append( $(step.ui.querySelector('div.panel-footer')).append(
'<div class="cal collapse in"><button type="submit" class="btn btn-sm btn-default btn-save" disabled = "true" >Apply</button> <small style="padding-top:2px;">Press apply to see changes</small></div>' '<div class="cal collapse in"><button type="submit" class="btn btn-sm btn-default btn-save" disabled = "true" >Apply</button> <small style="padding-top:2px;">Press apply to see changes</small></div>'
); );
$(step.ui.querySelector("div.panel-footer")).prepend( $(step.ui.querySelector('div.panel-footer')).prepend(
'<button class="pull-right btn btn-default btn-sm insert-step" >\ '<button class="pull-right btn btn-default btn-sm insert-step" >\
<span class="insert-text"><i class="fa fa-plus"></i> Insert Step</span><span class="no-insert-text" style="display:none">Close</span>\ <span class="insert-text"><i class="fa fa-plus"></i> Insert Step</span><span class="no-insert-text" style="display:none">Close</span>\
</button>' </button>'
); );
} }
if (step.name != "load-image") { if (step.name != 'load-image') {
step.ui step.ui
.querySelector("div.trash-container") .querySelector('div.trash-container')
.prepend( .prepend(
parser.parseFromString(tools, "text/html").querySelector("div") parser.parseFromString(tools, 'text/html').querySelector('div')
); );
$(step.ui.querySelectorAll(".remove")).on('click', function() {notify('Step Removed','remove-notification')}); $(step.ui.querySelectorAll('.remove')).on('click', function() {notify('Step Removed','remove-notification');});
$(step.ui.querySelectorAll(".insert-step")).on('click', function() { util.insertStep(step.ID) }); $(step.ui.querySelectorAll('.insert-step')).on('click', function() { util.insertStep(step.ID); });
// Insert the step's UI in the right place // Insert the step's UI in the right place
if (stepOptions.index == _sequencer.steps.length) { if (stepOptions.index == _sequencer.steps.length) {
stepsEl.appendChild(step.ui); stepsEl.appendChild(step.ui);
$("#steps .step-container:nth-last-child(1) .insert-step").prop('disabled',true); $('#steps .step-container:nth-last-child(1) .insert-step').prop('disabled',true);
if($("#steps .step-container:nth-last-child(2)")) if($('#steps .step-container:nth-last-child(2)'))
$("#steps .step-container:nth-last-child(2) .insert-step").prop('disabled',false); $('#steps .step-container:nth-last-child(2) .insert-step').prop('disabled',false);
} else { } else {
stepsEl.insertBefore(step.ui, $(stepsEl).children()[stepOptions.index]); stepsEl.insertBefore(step.ui, $(stepsEl).children()[stepOptions.index]);
} }
} }
else { else {
$("#load-image").append(step.ui); $('#load-image').append(step.ui);
} }
$(step.ui.querySelector(".toggle")).on("click", () => { $(step.ui.querySelector('.toggle')).on('click', () => {
$(step.ui.querySelector('.toggleIcon')).toggleClass('rotated'); $(step.ui.querySelector('.toggleIcon')).toggleClass('rotated');
$(step.ui.querySelectorAll(".cal")).collapse('toggle'); $(step.ui.querySelectorAll('.cal')).collapse('toggle');
}); });
$(step.imgElement).on("mousemove", _.debounce(() => imageHover(step), 150)); $(step.imgElement).on('mousemove', _.debounce(() => imageHover(step), 150));
function saveOptions(e) { function saveOptions(e) {
e.preventDefault(); e.preventDefault();
if (optionsChanged){ if (optionsChanged){
$(step.ui.querySelector("div.details")) $(step.ui.querySelector('div.details'))
.find("input,select") .find('input,select')
.each(function(i, input) { .each(function(i, input) {
$(input) $(input)
.data('initValue', $(input).val()) .data('initValue', $(input).val())
.data('hasChangedBefore', false); .data('hasChangedBefore', false);
step.options[$(input).attr("name")] = $(input).val(); step.options[$(input).attr('name')] = $(input).val();
}); });
_sequencer.run({ index: step.index - 1 }); _sequencer.run({ index: step.index - 1 });
// modify the url hash // modify the url hash
urlHash.setUrlHashParameter("steps", _sequencer.toString()) urlHash.setUrlHashParameter('steps', _sequencer.toString());
// disable the save button // disable the save button
$(step.ui.querySelector('.btn-save')).prop('disabled', true); $(step.ui.querySelector('.btn-save')).prop('disabled', true);
optionsChanged = false; optionsChanged = false;
@@ -214,32 +214,32 @@ function DefaultHtmlStepUi(_sequencer, options) {
$(this).val(), $(this).val(),
$(this).data('initValue'), $(this).data('initValue'),
$(this).data('hasChangedBefore') $(this).data('hasChangedBefore')
) )
) );
}) });
}) });
$('input[type="range"]').on('input', function() { $('input[type="range"]').on('input', function() {
$(this).next().html($(this).val()); $(this).next().html($(this).val());
}) });
} }
function onDraw(step) { function onDraw(step) {
$(step.ui.querySelector(".load")).show(); $(step.ui.querySelector('.load')).show();
$(step.ui.querySelector("img")).hide(); $(step.ui.querySelector('img')).hide();
$(step.ui.querySelectorAll(".load-spin")).show(); $(step.ui.querySelectorAll('.load-spin')).show();
} }
function onComplete(step) { function onComplete(step) {
$(step.ui.querySelector("img")).show(); $(step.ui.querySelector('img')).show();
$(step.ui.querySelectorAll(".load-spin")).hide(); $(step.ui.querySelectorAll('.load-spin')).hide();
$(step.ui.querySelector(".load")).hide(); $(step.ui.querySelector('.load')).hide();
step.imgElement.src = (step.name == "load-image") ? step.output.src : step.output; step.imgElement.src = (step.name == 'load-image') ? step.output.src : step.output;
var imgthumbnail = step.ui.querySelector(".img-thumbnail"); var imgthumbnail = step.ui.querySelector('.img-thumbnail');
for (let index = 0; index < step.linkElements.length; index++) { for (let index = 0; index < step.linkElements.length; index++) {
if (step.linkElements[index].contains(imgthumbnail)) if (step.linkElements[index].contains(imgthumbnail))
step.linkElements[index].href = step.imgElement.src; step.linkElements[index].href = step.imgElement.src;
@@ -247,13 +247,13 @@ function DefaultHtmlStepUi(_sequencer, options) {
// TODO: use a generalized version of this // TODO: use a generalized version of this
function fileExtension(output) { function fileExtension(output) {
return output.split("/")[1].split(";")[0]; return output.split('/')[1].split(';')[0];
} }
for (let index = 0; index < step.linkElements.length; index++) { for (let index = 0; index < step.linkElements.length; index++) {
step.linkElements[index].download = step.name + "." + fileExtension(step.imgElement.src); step.linkElements[index].download = step.name + '.' + fileExtension(step.imgElement.src);
step.linkElements[index].target = "_blank"; step.linkElements[index].target = '_blank';
} }
// fill inputs with stored step options // fill inputs with stored step options
@@ -262,11 +262,11 @@ function DefaultHtmlStepUi(_sequencer, options) {
var outputs = _sequencer.modulesInfo(step.name).outputs; var outputs = _sequencer.modulesInfo(step.name).outputs;
for (var i in inputs) { for (var i in inputs) {
if (step.options[i] !== undefined) { if (step.options[i] !== undefined) {
if (inputs[i].type.toLowerCase() === "input") if (inputs[i].type.toLowerCase() === 'input')
$(step.ui.querySelector('div[name="' + i + '"] input')) $(step.ui.querySelector('div[name="' + i + '"] input'))
.val(step.options[i]) .val(step.options[i])
.data('initValue', step.options[i]); .data('initValue', step.options[i]);
if (inputs[i].type.toLowerCase() === "select") if (inputs[i].type.toLowerCase() === 'select')
$(step.ui.querySelector('div[name="' + i + '"] select')) $(step.ui.querySelector('div[name="' + i + '"] select'))
.val(step.options[i]) .val(step.options[i])
.data('initValue', step.options[i]); .data('initValue', step.options[i]);
@@ -295,13 +295,13 @@ function DefaultHtmlStepUi(_sequencer, options) {
var xPos = e.pageX - offset.left; var xPos = e.pageX - offset.left;
var yPos = e.pageY - offset.top; var yPos = e.pageY - offset.top;
var myData = context.getImageData(xPos, yPos, 1, 1); var myData = context.getImageData(xPos, yPos, 1, 1);
img[0].title = "rgb: " +myData.data[0]+","+ myData.data[1]+","+myData.data[2];//+ rgbdata; img[0].title = 'rgb: ' +myData.data[0]+','+ myData.data[1]+','+myData.data[2];//+ rgbdata;
}); });
} }
function onRemove(step) { function onRemove(step) {
step.ui.remove(); step.ui.remove();
$("#steps .step-container:nth-last-child(1) .insert-step").prop('disabled',true); $('#steps .step-container:nth-last-child(1) .insert-step').prop('disabled',true);
$('div[class*=imgareaselect-]').remove(); $('div[class*=imgareaselect-]').remove();
} }
@@ -314,7 +314,7 @@ function DefaultHtmlStepUi(_sequencer, options) {
var notification = document.createElement('span'); var notification = document.createElement('span');
notification.innerHTML = ' <i class="fa fa-info-circle" aria-hidden="true"></i> ' + msg ; notification.innerHTML = ' <i class="fa fa-info-circle" aria-hidden="true"></i> ' + msg ;
notification.id = id; notification.id = id;
notification.classList.add("notification"); notification.classList.add('notification');
$('body').append(notification); $('body').append(notification);
} }
@@ -331,13 +331,13 @@ function DefaultHtmlStepUi(_sequencer, options) {
onDraw: onDraw, onDraw: onDraw,
notify: notify, notify: notify,
imageHover: imageHover imageHover: imageHover
} };
} }
if(typeof window === "undefined"){ if(typeof window === 'undefined'){
module.exports={ module.exports={
DefaultHtmlStepUi: DefaultHtmlStepUi DefaultHtmlStepUi: DefaultHtmlStepUi
} };
} }
module.exports = DefaultHtmlStepUi; module.exports = DefaultHtmlStepUi;

View File

@@ -1,55 +1,55 @@
function generatePreview(previewStepName, customValues, path, selector) { function generatePreview(previewStepName, customValues, path, selector) {
var previewSequencer = ImageSequencer(); var previewSequencer = ImageSequencer();
function insertPreview(src) { function insertPreview(src) {
var img = document.createElement('img'); var img = document.createElement('img');
img.classList.add('img-thumbnail') img.classList.add('img-thumbnail');
img.classList.add('no-border'); img.classList.add('no-border');
img.src = src; img.src = src;
$(img).css("max-width", "200%"); $(img).css('max-width', '200%');
$(img).css("transform", "translateX(-20%)"); $(img).css('transform', 'translateX(-20%)');
$(selector + ' .radio-group').find('div').each(function() { $(selector + ' .radio-group').find('div').each(function() {
if ($(this).find('div').attr('data-value') === previewStepName) { if ($(this).find('div').attr('data-value') === previewStepName) {
$(this).find('div').append(img); $(this).find('div').append(img);
}
});
}
function loadPreview() {
if (previewStepName === "crop") {
previewSequencer.addSteps(previewStepName, customValues).run(insertPreview);
} }
else {
previewSequencer.addSteps(previewStepName, { [previewStepName]: customValues }).run(insertPreview);
}
}
previewSequencer.loadImage(path, loadPreview);
}
function updatePreviews(src, selector) {
$(selector+' img').remove();
var previewSequencerSteps = {
"resize": "125%",
"brightness": "175",
"saturation": "0.5",
"rotate": 90,
"contrast": 90,
"crop": {
"x": 0,
"y": 0,
"w": "(50%)",
"h": "(50%)",
"noUI": true
}
}
Object.keys(previewSequencerSteps).forEach(function (step, index) {
generatePreview(step, Object.values(previewSequencerSteps)[index], src, selector);
}); });
} }
function loadPreview() {
if (previewStepName === 'crop') {
previewSequencer.addSteps(previewStepName, customValues).run(insertPreview);
}
else {
previewSequencer.addSteps(previewStepName, { [previewStepName]: customValues }).run(insertPreview);
}
}
previewSequencer.loadImage(path, loadPreview);
}
function updatePreviews(src, selector) {
$(selector+' img').remove();
var previewSequencerSteps = {
'resize': '125%',
'brightness': '175',
'saturation': '0.5',
'rotate': 90,
'contrast': 90,
'crop': {
'x': 0,
'y': 0,
'w': '(50%)',
'h': '(50%)',
'noUI': true
}
};
Object.keys(previewSequencerSteps).forEach(function (step, index) {
generatePreview(step, Object.values(previewSequencerSteps)[index], src, selector);
});
}
module.exports = { module.exports = {
generatePreview : generatePreview, generatePreview : generatePreview,
updatePreviews : updatePreviews updatePreviews : updatePreviews
} };

View File

@@ -1,5 +1,5 @@
var urlHash = require('./urlHash.js'), var urlHash = require('./urlHash.js'),
insertPreview = require('./insertPreview.js'); insertPreview = require('./insertPreview.js');
function IntermediateHtmlStepUi(_sequencer, step, options) { function IntermediateHtmlStepUi(_sequencer, step, options) {
function stepUI() { function stepUI() {
@@ -66,52 +66,52 @@ function IntermediateHtmlStepUi(_sequencer, step, options) {
function selectNewStepUi() { function selectNewStepUi() {
var insertSelect = $(step.ui.querySelector('.insert-step-select')) var insertSelect = $(step.ui.querySelector('.insert-step-select'));
var m = insertSelect.val(); var m = insertSelect.val();
$(step.ui.querySelector('.insertDiv .info')).html(_sequencer.modulesInfo(m).description); $(step.ui.querySelector('.insertDiv .info')).html(_sequencer.modulesInfo(m).description);
$(step.ui.querySelector('.insertDiv .add-step-btn')).prop("disabled", false); $(step.ui.querySelector('.insertDiv .add-step-btn')).prop('disabled', false);
} }
var toggleDiv = function(callback = function(){}){ var toggleDiv = function(callback = function(){}){
$(step.ui.querySelector('.insertDiv')).collapse('toggle'); $(step.ui.querySelector('.insertDiv')).collapse('toggle');
if ($(step.ui.querySelector('.insert-text')).css('display') != "none"){ if ($(step.ui.querySelector('.insert-text')).css('display') != 'none'){
$(step.ui.querySelector('.insert-text')).fadeToggle(200, function(){$(step.ui.querySelector('.no-insert-text')).fadeToggle(200, callback)}) $(step.ui.querySelector('.insert-text')).fadeToggle(200, function(){$(step.ui.querySelector('.no-insert-text')).fadeToggle(200, callback);});
} }
else { else {
$(step.ui.querySelector('.no-insert-text')).fadeToggle(200, function(){$(step.ui.querySelector('.insert-text')).fadeToggle(200, callback)}) $(step.ui.querySelector('.no-insert-text')).fadeToggle(200, function(){$(step.ui.querySelector('.insert-text')).fadeToggle(200, callback);});
} }
} };
insertStep = function (id) { insertStep = function (id) {
var modulesInfo = _sequencer.modulesInfo(); var modulesInfo = _sequencer.modulesInfo();
var parser = new DOMParser(); var parser = new DOMParser();
var addStepUI = stepUI(); var addStepUI = stepUI();
addStepUI = parser.parseFromString(addStepUI, "text/html").querySelector("div") addStepUI = parser.parseFromString(addStepUI, 'text/html').querySelector('div');
if ($(step.ui.querySelector('.insertDiv')).length > 0){ if ($(step.ui.querySelector('.insertDiv')).length > 0){
toggleDiv(); toggleDiv();
} }
else { else {
step.ui step.ui
.querySelector("div.step") .querySelector('div.step')
.insertAdjacentElement('afterend', .insertAdjacentElement('afterend',
addStepUI addStepUI
); );
toggleDiv(function(){ toggleDiv(function(){
insertPreview.updatePreviews(step.output, '.insertDiv'); insertPreview.updatePreviews(step.output, '.insertDiv');
}); });
} }
$(step.ui.querySelector('.insertDiv .close-insert-box')).off('click').on('click', function(){toggleDiv(function(){})}); $(step.ui.querySelector('.insertDiv .close-insert-box')).off('click').on('click', function(){toggleDiv(function(){});});
var insertStepSelect = $(step.ui.querySelector('.insert-step-select')); var insertStepSelect = $(step.ui.querySelector('.insert-step-select'));
insertStepSelect.html(""); insertStepSelect.html('');
// Add modules to the insertStep dropdown // Add modules to the insertStep dropdown
for (var m in modulesInfo) { for (var m in modulesInfo) {
if (modulesInfo[m] !== undefined) if (modulesInfo[m] !== undefined)
insertStepSelect.append( insertStepSelect.append(
'<option value="' + m + '">' + modulesInfo[m].name + "</option>" '<option value="' + m + '">' + modulesInfo[m].name + '</option>'
); );
} }
insertStepSelect.selectize({ insertStepSelect.selectize({
@@ -120,7 +120,7 @@ function IntermediateHtmlStepUi(_sequencer, step, options) {
$(step.ui.querySelector('.inserDiv .add-step-btn')).prop('disabled', true); $(step.ui.querySelector('.inserDiv .add-step-btn')).prop('disabled', true);
insertStepSelect.append('<option value="" disabled selected>Select a Module</option>'); insertStepSelect.append('<option value="" disabled selected>Select a Module</option>');
$(step.ui.querySelector('.insertDiv .radio-group .radio')).on("click", function () { $(step.ui.querySelector('.insertDiv .radio-group .radio')).on('click', function () {
$(this).parent().find('.radio').removeClass('selected'); $(this).parent().find('.radio').removeClass('selected');
$(this).addClass('selected'); $(this).addClass('selected');
newStep = $(this).attr('data-value'); newStep = $(this).attr('data-value');
@@ -130,34 +130,34 @@ function IntermediateHtmlStepUi(_sequencer, step, options) {
$(this).removeClass('selected'); $(this).removeClass('selected');
}); });
insertStepSelect.on('change', selectNewStepUi); insertStepSelect.on('change', selectNewStepUi);
$(step.ui.querySelector('.insertDiv .add-step-btn')).on('click', function () { insert(id) }); $(step.ui.querySelector('.insertDiv .add-step-btn')).on('click', function () { insert(id); });
} };
function insert(id) { function insert(id) {
options = options || {}; options = options || {};
var insertStepSelect = $(step.ui.querySelector('.insert-step-select')); var insertStepSelect = $(step.ui.querySelector('.insert-step-select'));
if (insertStepSelect.val() == "none") return; if (insertStepSelect.val() == 'none') return;
var newStepName = insertStepSelect.val() var newStepName = insertStepSelect.val();
toggleDiv(); toggleDiv();
var sequenceLength = 1; var sequenceLength = 1;
if (sequencer.sequences[newStepName]) { if (sequencer.sequences[newStepName]) {
sequenceLength = sequencer.sequences[newStepName].length; sequenceLength = sequencer.sequences[newStepName].length;
} else if (sequencer.modules[newStepName][1]["length"]) { } else if (sequencer.modules[newStepName][1]['length']) {
sequenceLength = sequencer.modules[newStepName][1]["length"]; sequenceLength = sequencer.modules[newStepName][1]['length'];
} }
_sequencer _sequencer
.insertSteps(id + 1, newStepName).run({ index: id }); .insertSteps(id + 1, newStepName).run({ index: id });
// add to URL hash too // add to URL hash too
urlHash.setUrlHashParameter("steps", _sequencer.toString()); urlHash.setUrlHashParameter('steps', _sequencer.toString());
} }
return { return {
insertStep insertStep
} };
} }
module.exports = IntermediateHtmlStepUi; module.exports = IntermediateHtmlStepUi;

View File

@@ -1,24 +1,24 @@
function mapHtmlTypes(inputInfo){ function mapHtmlTypes(inputInfo){
var htmlType; var htmlType;
switch(inputInfo.type.toLowerCase()){ switch(inputInfo.type.toLowerCase()){
case 'integer': case 'integer':
htmlType = inputInfo.min != undefined ? 'range' : 'number'; htmlType = inputInfo.min != undefined ? 'range' : 'number';
break; break;
case 'string': case 'string':
htmlType = 'text'; htmlType = 'text';
break; break;
case 'select': case 'select':
htmlType = 'select'; htmlType = 'select';
break; break;
case 'percentage': case 'percentage':
htmlType = 'number'; htmlType = 'number';
break; break;
case 'float': case 'float':
htmlType = inputInfo.min != undefined ? 'range' : 'text'; htmlType = inputInfo.min != undefined ? 'range' : 'text';
break; break;
default: default:
htmlType = 'text'; htmlType = 'text';
break; break;
} }
var response = inputInfo; var response = inputInfo;
response.type = htmlType; response.type = htmlType;

View File

@@ -42,8 +42,8 @@ function setUrlHashParameter(param, value) {
} }
module.exports = { module.exports = {
getUrlHashParameter: getUrlHashParameter, getUrlHashParameter: getUrlHashParameter,
setUrlHashParameter: setUrlHashParameter, setUrlHashParameter: setUrlHashParameter,
getUrlHashParameters: getUrlHashParameters, getUrlHashParameters: getUrlHashParameters,
setUrlHashParameters: setUrlHashParameters setUrlHashParameters: setUrlHashParameters
} };

View File

@@ -25,7 +25,7 @@ self.addEventListener('fetch', function(event) {
caches.open(staticCacheName).then(function(cache) { caches.open(staticCacheName).then(function(cache) {
return cache.match(event.request).then(function (response) { return cache.match(event.request).then(function (response) {
return response || fetch(event.request).then(function(response) { return response || fetch(event.request).then(function(response) {
if(event.request.method == "GET") if(event.request.method == 'GET')
cache.put(event.request, response.clone()); cache.put(event.request, response.clone());
return response; return response;
}); });

View File

@@ -2,13 +2,13 @@
require('./src/ImageSequencer'); require('./src/ImageSequencer');
sequencer = ImageSequencer({ ui: false }); sequencer = ImageSequencer({ ui: false });
var fs = require('fs') var fs = require('fs');
var program = require('commander'); var program = require('commander');
var utils = require('./src/CliUtils') var utils = require('./src/CliUtils');
var saveSequence = require('./src/cli/saveSequence.js') var saveSequence = require('./src/cli/saveSequence.js');
var installModule = require('./src/cli/installModule.js') var installModule = require('./src/cli/installModule.js');
var sequencerSteps = require('./src/cli/sequencerSteps.js') var sequencerSteps = require('./src/cli/sequencerSteps.js');
function exit(message) { function exit(message) {
console.error(message); console.error(message);
@@ -16,39 +16,39 @@ function exit(message) {
} }
program program
.version("0.1.0") .version('0.1.0')
.option("-i, --image [PATH/URL]", "Input image URL") .option('-i, --image [PATH/URL]', 'Input image URL')
.option("-s, --step [step-name]", "Name of the step to be added.") .option('-s, --step [step-name]', 'Name of the step to be added.')
.option("-o, --output [PATH]", "Directory where output will be stored.") .option('-o, --output [PATH]', 'Directory where output will be stored.')
.option("-b, --basic", "Basic mode outputs only final image") .option('-b, --basic', 'Basic mode outputs only final image')
.option("-c, --config [Object]", "Options for the step") .option('-c, --config [Object]', 'Options for the step')
.option("--save-sequence [string]", "Name space separated with Stringified sequence") .option('--save-sequence [string]', 'Name space separated with Stringified sequence')
.option('--install-module [string]', "Module name space seaprated npm package name") .option('--install-module [string]', 'Module name space seaprated npm package name')
.parse(process.argv); .parse(process.argv);
if (program.saveSequence) saveSequence(program, sequencer) if (program.saveSequence) saveSequence(program, sequencer);
else if (program.installModule) installModule(program, sequencer) else if (program.installModule) installModule(program, sequencer);
else { else {
// Parse step into an array to allow for multiple steps. // Parse step into an array to allow for multiple steps.
if (!program.step) exit("No steps passed"); if (!program.step) exit('No steps passed');
program.step = program.step.split(" "); program.step = program.step.split(' ');
// User must input an image. // User must input an image.
if (!program.image) exit("Can't read file."); if (!program.image) exit('Can\'t read file.');
// User must input an image. // User must input an image.
fs.access(program.image, function(err) { fs.access(program.image, function(err) {
if (err) exit("Can't read file."); if (err) exit('Can\'t read file.');
}); });
// User must input a step. If steps exist, check that every step is a valid step. // User must input a step. If steps exist, check that every step is a valid step.
if (!program.step || !(utils.validateSteps(program.step, sequencer))) if (!program.step || !(utils.validateSteps(program.step, sequencer)))
exit("Please ensure all steps are valid."); exit('Please ensure all steps are valid.');
// If there's no user defined output directory, select a default directory. // If there's no user defined output directory, select a default directory.
program.output = program.output || "./output/"; program.output = program.output || './output/';
// Set sequencer to log module outputs, if any. // Set sequencer to log module outputs, if any.
sequencer.setUI({ sequencer.setUI({
@@ -57,7 +57,7 @@ else {
step.info = sequencer.modulesInfo(step.name); step.info = sequencer.modulesInfo(step.name);
for (var output in step.info.outputs) { for (var output in step.info.outputs) {
console.log("[" + program.step + "]: " + output + " = " + step[output]); console.log('[' + program.step + ']: ' + output + ' = ' + step[output]);
} }
}, },
notify: function(msg) { notify: function(msg) {
@@ -68,8 +68,8 @@ else {
// Finally, if everything is alright, load the image, add the steps and run the sequencer. // Finally, if everything is alright, load the image, add the steps and run the sequencer.
sequencer.loadImages(program.image, function() { sequencer.loadImages(program.image, function() {
console.warn( console.warn(
"\x1b[33m%s\x1b[0m", '\x1b[33m%s\x1b[0m',
"Please wait \n output directory generated will be empty until the execution is complete" 'Please wait \n output directory generated will be empty until the execution is complete'
); );
//Generate the Output Directory //Generate the Output Directory
@@ -82,7 +82,7 @@ else {
outputFilename = null; outputFilename = null;
} }
sequencerSteps(program, sequencer, outputFilename) sequencerSteps(program, sequencer, outputFilename);
}); });

View File

@@ -10,6 +10,12 @@
"setup": "npm i && npm i -g grunt grunt-cli && grunt build", "setup": "npm i && npm i -g grunt grunt-cli && grunt build",
"start": "grunt serve" "start": "grunt serve"
}, },
"lint-staged": {
"*.js": [
"./node_modules/.bin/eslint --fix",
"git add"
]
},
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/publiclab/image-sequencer.git" "url": "git+https://github.com/publiclab/image-sequencer.git"
@@ -30,6 +36,7 @@
"commander": "^2.11.0", "commander": "^2.11.0",
"data-uri-to-buffer": "^2.0.0", "data-uri-to-buffer": "^2.0.0",
"downloadjs": "^1.4.7", "downloadjs": "^1.4.7",
"eslint": "^5.16.0",
"fisheyegl": "^0.1.2", "fisheyegl": "^0.1.2",
"font-awesome": "~4.7.0", "font-awesome": "~4.7.0",
"geotiff": "^1.0.0-beta.6", "geotiff": "^1.0.0-beta.6",
@@ -62,17 +69,20 @@
"@babel/plugin-syntax-object-rest-spread": "^7.2.0", "@babel/plugin-syntax-object-rest-spread": "^7.2.0",
"babelify": "^10.0.0", "babelify": "^10.0.0",
"browserify": "16.2.3", "browserify": "16.2.3",
"eslint": "^5.16.0",
"grunt": "^1.0.3", "grunt": "^1.0.3",
"grunt-browser-sync": "^2.2.0", "grunt-browser-sync": "^2.2.0",
"grunt-browserify": "^5.0.0", "grunt-browserify": "^5.0.0",
"grunt-contrib-concat": "^1.0.1", "grunt-contrib-concat": "^1.0.1",
"grunt-contrib-uglify-es": "^3.3.0", "grunt-contrib-uglify-es": "^3.3.0",
"grunt-contrib-watch": "^1.1.0", "grunt-contrib-watch": "^1.1.0",
"husky": "^2.2.0",
"image-filter-core": "~2.0.2", "image-filter-core": "~2.0.2",
"image-filter-threshold": "~2.0.1", "image-filter-threshold": "~2.0.1",
"jasmine-core": "^3.3.0", "jasmine-core": "^3.3.0",
"jasmine-jquery": "^2.1.1", "jasmine-jquery": "^2.1.1",
"jasmine-spec-reporter": "^4.2.1", "jasmine-spec-reporter": "^4.2.1",
"lint-staged": "^8.1.6",
"looks-same": "^7.0.0", "looks-same": "^7.0.0",
"matchdep": "^2.0.0", "matchdep": "^2.0.0",
"tap-spec": "^5.0.0", "tap-spec": "^5.0.0",
@@ -80,6 +90,11 @@
"tape-run": "^6.0.0", "tape-run": "^6.0.0",
"uglify-es": "^3.3.7" "uglify-es": "^3.3.7"
}, },
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"homepage": "https://sequencer.publiclab.org", "homepage": "https://sequencer.publiclab.org",
"bin": { "bin": {
"sequencer": "./index.js" "sequencer": "./index.js"

View File

@@ -1,42 +1,42 @@
describe('Default sequencer HTML', function() { describe('Default sequencer HTML', function() {
var DefaultHtmlSequencerUi = require('../examples/lib/defaultHtmlSequencerUi') var DefaultHtmlSequencerUi = require('../examples/lib/defaultHtmlSequencerUi');
var sequencer = require('../src/ImageSequencer')() var sequencer = require('../src/ImageSequencer')();
var defaultHtmlSequencerUi; var defaultHtmlSequencerUi;
beforeEach(()=>{ beforeEach(()=>{
defaultHtmlSequencerUi = new DefaultHtmlSequencerUi(sequencer) defaultHtmlSequencerUi = new DefaultHtmlSequencerUi(sequencer);
spyOn(defaultHtmlSequencerUi,'onLoad') spyOn(defaultHtmlSequencerUi,'onLoad');
spyOn(defaultHtmlSequencerUi,'selectNewStepUi') spyOn(defaultHtmlSequencerUi,'selectNewStepUi');
spyOn(defaultHtmlSequencerUi,'removeStepUi') spyOn(defaultHtmlSequencerUi,'removeStepUi');
spyOn(defaultHtmlSequencerUi,'addStepUi') spyOn(defaultHtmlSequencerUi,'addStepUi');
spyOn(defaultHtmlSequencerUi,'importStepsFromUrlHash') spyOn(defaultHtmlSequencerUi,'importStepsFromUrlHash');
defaultHtmlSequencerUi.onLoad() defaultHtmlSequencerUi.onLoad();
defaultHtmlSequencerUi.selectNewStepUi() defaultHtmlSequencerUi.selectNewStepUi();
defaultHtmlSequencerUi.addStepUi() defaultHtmlSequencerUi.addStepUi();
defaultHtmlSequencerUi.removeStepUi() defaultHtmlSequencerUi.removeStepUi();
defaultHtmlSequencerUi.importStepsFromUrlHash() defaultHtmlSequencerUi.importStepsFromUrlHash();
}) });
it('load default ui', function() { it('load default ui', function() {
expect(defaultHtmlSequencerUi.onLoad).toHaveBeenCalled() expect(defaultHtmlSequencerUi.onLoad).toHaveBeenCalled();
}) });
it('select step ui', function() { it('select step ui', function() {
expect(defaultHtmlSequencerUi.selectNewStepUi).toHaveBeenCalled() expect(defaultHtmlSequencerUi.selectNewStepUi).toHaveBeenCalled();
}) });
it('add step ui', function() { it('add step ui', function() {
expect(defaultHtmlSequencerUi.addStepUi).toHaveBeenCalled() expect(defaultHtmlSequencerUi.addStepUi).toHaveBeenCalled();
}) });
it('remove step ui', function() { it('remove step ui', function() {
expect(defaultHtmlSequencerUi.removeStepUi).toHaveBeenCalled() expect(defaultHtmlSequencerUi.removeStepUi).toHaveBeenCalled();
}) });
it('import options from url', function() { it('import options from url', function() {
expect(defaultHtmlSequencerUi.importStepsFromUrlHash).toHaveBeenCalled() expect(defaultHtmlSequencerUi.importStepsFromUrlHash).toHaveBeenCalled();
}) });
}) });

View File

@@ -1,61 +1,61 @@
var { JSDOM } = require('jsdom'); var { JSDOM } = require('jsdom');
var DOM = new JSDOM(`<body></body>`); var DOM = new JSDOM('<body></body>');
global.document = DOM.window.document; global.document = DOM.window.document;
describe('Sequencer step HTML', function() { describe('Sequencer step HTML', function() {
var DefaultHtmlStepUi = require('../examples/lib/defaultHtmlStepUi') var DefaultHtmlStepUi = require('../examples/lib/defaultHtmlStepUi');
var sequencer = require('../src/ImageSequencer')() var sequencer = require('../src/ImageSequencer')();
var defaultHtmlStepUi; var defaultHtmlStepUi;
var step = 'brightness' var step = 'brightness';
var options = { var options = {
name: "Brightness", name: 'Brightness',
description: "Change the brightness of the image by given percent value" description: 'Change the brightness of the image by given percent value'
} };
// options = JSON.parse(options) // options = JSON.parse(options)
beforeEach(()=>{ beforeEach(()=>{
defaultHtmlStepUi = new DefaultHtmlStepUi(sequencer) defaultHtmlStepUi = new DefaultHtmlStepUi(sequencer);
spyOn(defaultHtmlStepUi,'getPreview') spyOn(defaultHtmlStepUi,'getPreview');
spyOn(defaultHtmlStepUi,'onSetup') spyOn(defaultHtmlStepUi,'onSetup');
spyOn(defaultHtmlStepUi,'onComplete') spyOn(defaultHtmlStepUi,'onComplete');
spyOn(defaultHtmlStepUi,'onDraw') spyOn(defaultHtmlStepUi,'onDraw');
spyOn(defaultHtmlStepUi,'onRemove') spyOn(defaultHtmlStepUi,'onRemove');
spyOn(defaultHtmlStepUi,'notify') spyOn(defaultHtmlStepUi,'notify');
defaultHtmlStepUi.getPreview() defaultHtmlStepUi.getPreview();
defaultHtmlStepUi.onSetup(step,options) defaultHtmlStepUi.onSetup(step,options);
defaultHtmlStepUi.onComplete(step) defaultHtmlStepUi.onComplete(step);
defaultHtmlStepUi.onDraw(step) defaultHtmlStepUi.onDraw(step);
defaultHtmlStepUi.onRemove(step) defaultHtmlStepUi.onRemove(step);
defaultHtmlStepUi.notify('Step removed','remove-notification') defaultHtmlStepUi.notify('Step removed','remove-notification');
}) });
it('result preview ui', function() { it('result preview ui', function() {
expect(defaultHtmlStepUi.getPreview).toHaveBeenCalled() expect(defaultHtmlStepUi.getPreview).toHaveBeenCalled();
}) });
it('load initial setup ui', function() { it('load initial setup ui', function() {
expect(defaultHtmlStepUi.onSetup).toHaveBeenCalledWith(step,options) expect(defaultHtmlStepUi.onSetup).toHaveBeenCalledWith(step,options);
}) });
it('load completion ui', function() { it('load completion ui', function() {
expect(defaultHtmlStepUi.onComplete).toHaveBeenCalledWith(step) expect(defaultHtmlStepUi.onComplete).toHaveBeenCalledWith(step);
}) });
it('draw step ui', function() { it('draw step ui', function() {
expect(defaultHtmlStepUi.onDraw).toHaveBeenCalledWith(step) expect(defaultHtmlStepUi.onDraw).toHaveBeenCalledWith(step);
}) });
it('remove step ui', function() { it('remove step ui', function() {
expect(defaultHtmlStepUi.onRemove).toHaveBeenCalledWith(step) expect(defaultHtmlStepUi.onRemove).toHaveBeenCalledWith(step);
}) });
it('notification ui', function() { it('notification ui', function() {
expect(defaultHtmlStepUi.notify).toHaveBeenCalledWith('Step removed','remove-notification') expect(defaultHtmlStepUi.notify).toHaveBeenCalledWith('Step removed','remove-notification');
}) });
}) });

View File

@@ -1,26 +1,26 @@
describe('Preview UI HTML', function() { describe('Preview UI HTML', function() {
var InsertPreview = require('../examples/lib/insertPreview') var InsertPreview = require('../examples/lib/insertPreview');
var sequencer = require('../src/ImageSequencer')() var sequencer = require('../src/ImageSequencer')();
var insertPreview; var insertPreview;
var options = { brightness: 50 } var options = { brightness: 50 };
beforeEach(()=>{ beforeEach(()=>{
insertPreview = InsertPreview insertPreview = InsertPreview;
spyOn(insertPreview,'generatePreview') spyOn(insertPreview,'generatePreview');
spyOn(insertPreview,'updatePreviews') spyOn(insertPreview,'updatePreviews');
insertPreview.generatePreview('brightness',options,'src','selector') insertPreview.generatePreview('brightness',options,'src','selector');
insertPreview.updatePreviews('src','selector') insertPreview.updatePreviews('src','selector');
}) });
it('generate preview ui', function() { it('generate preview ui', function() {
expect(insertPreview.generatePreview).toHaveBeenCalledWith('brightness',options,'src','selector') expect(insertPreview.generatePreview).toHaveBeenCalledWith('brightness',options,'src','selector');
}) });
it('update preview ui', function() { it('update preview ui', function() {
expect(insertPreview.updatePreviews).toHaveBeenCalledWith('src','selector') expect(insertPreview.updatePreviews).toHaveBeenCalledWith('src','selector');
}) });
}) });

View File

@@ -1,19 +1,19 @@
describe('Intermediate step HTML', function() { describe('Intermediate step HTML', function() {
var IntermediateHtmlStepUi = require('../examples/lib/intermediateHtmlStepUi') var IntermediateHtmlStepUi = require('../examples/lib/intermediateHtmlStepUi');
var sequencer = require('../src/ImageSequencer')() var sequencer = require('../src/ImageSequencer')();
var intermediateHtmlStepUi; var intermediateHtmlStepUi;
beforeEach(()=>{ beforeEach(()=>{
intermediateHtmlStepUi = new IntermediateHtmlStepUi(sequencer) intermediateHtmlStepUi = new IntermediateHtmlStepUi(sequencer);
spyOn(intermediateHtmlStepUi,'insertStep') spyOn(intermediateHtmlStepUi,'insertStep');
intermediateHtmlStepUi.insertStep() intermediateHtmlStepUi.insertStep();
}) });
it('insert step ui', function() { it('insert step ui', function() {
expect(intermediateHtmlStepUi.insertStep).toHaveBeenCalled() expect(intermediateHtmlStepUi.insertStep).toHaveBeenCalled();
}) });
}) });

View File

@@ -1,40 +1,40 @@
describe('URL manipulation methods', function() { describe('URL manipulation methods', function() {
var UrlHash = require('../examples/lib/urlHash') var UrlHash = require('../examples/lib/urlHash');
var urlHash; var urlHash;
var params = { var params = {
module: 'brightness', module: 'brightness',
brightness: 50 brightness: 50
} };
beforeEach(()=>{ beforeEach(()=>{
urlHash = UrlHash urlHash = UrlHash;
spyOn(urlHash,'getUrlHashParameters') spyOn(urlHash,'getUrlHashParameters');
spyOn(urlHash,'getUrlHashParameter') spyOn(urlHash,'getUrlHashParameter');
spyOn(urlHash,'setUrlHashParameters') spyOn(urlHash,'setUrlHashParameters');
spyOn(urlHash,'setUrlHashParameter') spyOn(urlHash,'setUrlHashParameter');
urlHash.getUrlHashParameters() urlHash.getUrlHashParameters();
urlHash.getUrlHashParameter('module') urlHash.getUrlHashParameter('module');
urlHash.setUrlHashParameters(params) urlHash.setUrlHashParameters(params);
urlHash.setUrlHashParameter('module','brightness') urlHash.setUrlHashParameter('module','brightness');
}) });
it('gets url hash params from window hash', function() { it('gets url hash params from window hash', function() {
expect(urlHash.getUrlHashParameters).toHaveBeenCalled() expect(urlHash.getUrlHashParameters).toHaveBeenCalled();
}) });
it('gets url hash param from params object', function() { it('gets url hash param from params object', function() {
expect(urlHash.getUrlHashParameter).toHaveBeenCalledWith('module') expect(urlHash.getUrlHashParameter).toHaveBeenCalledWith('module');
}) });
it('accepts param object and sets url hash params', function() { it('accepts param object and sets url hash params', function() {
expect(urlHash.setUrlHashParameters).toHaveBeenCalledWith(params) expect(urlHash.setUrlHashParameters).toHaveBeenCalledWith(params);
}) });
it('accepts param key-value pair and sets url hash params', function() { it('accepts param key-value pair and sets url hash params', function() {
expect(urlHash.setUrlHashParameter).toHaveBeenCalledWith('module','brightness') expect(urlHash.setUrlHashParameter).toHaveBeenCalledWith('module','brightness');
}) });
}) });

View File

@@ -1,18 +1,18 @@
var fs = require('fs') var fs = require('fs');
/* /*
* This function checks if the directory exists, if not it creates one on the given path * This function checks if the directory exists, if not it creates one on the given path
* Callback is called with argument error if an error is encountered * Callback is called with argument error if an error is encountered
*/ */
function makedir(path,callback){ function makedir(path,callback){
fs.access(path,function(err){ fs.access(path,function(err){
if(err) fs.mkdir(path,function(err){ if(err) fs.mkdir(path,function(err){
if(err) callback(err); if(err) callback(err);
callback(); callback();
});
else callback()
}); });
}; else callback();
});
}
// Takes an array of steps and checks if they are valid steps for the sequencer. // Takes an array of steps and checks if they are valid steps for the sequencer.
function validateSteps(steps, sequencer) { function validateSteps(steps, sequencer) {
@@ -37,9 +37,9 @@ function validateConfig(config_, options_) {
for (var input in options_) { for (var input in options_) {
if (!config_[options_[input]]) { if (!config_[options_[input]]) {
console.error( console.error(
"\x1b[31m%s\x1b[0m", '\x1b[31m%s\x1b[0m',
`Options Object does not have the required details "${ `Options Object does not have the required details "${
options_[input] options_[input]
}" not specified. Fallback case activated` }" not specified. Fallback case activated`
); );
return false; return false;
@@ -52,7 +52,7 @@ function validateConfig(config_, options_) {
} }
module.exports = exports = { module.exports = exports = {
makedir: makedir, makedir: makedir,
validateSteps: validateSteps, validateSteps: validateSteps,
validateConfig: validateConfig validateConfig: validateConfig
} };

View File

@@ -2,7 +2,7 @@ var fs = require('fs');
var getDirectories = function(rootDir, cb) { var getDirectories = function(rootDir, cb) {
fs.readdir(rootDir, function(err, files) { fs.readdir(rootDir, function(err, files) {
var dirs = []; var dirs = [];
if (typeof (files) == "undefined" || files.length == 0) { if (typeof (files) == 'undefined' || files.length == 0) {
cb(dirs); cb(dirs);
return []; return [];
} }
@@ -21,15 +21,15 @@ var getDirectories = function(rootDir, cb) {
} }
} }
}); });
} };
module.exports = function ExportBin(dir = "./output/", ref, basic, filename) { module.exports = function ExportBin(dir = './output/', ref, basic, filename) {
// If user did not give an output filename so we can continue without doing anything // If user did not give an output filename so we can continue without doing anything
dir = (dir[dir.length - 1] == "/") ? dir : dir + "/"; dir = (dir[dir.length - 1] == '/') ? dir : dir + '/';
if (ref.options.inBrowser) return false; if (ref.options.inBrowser) return false;
fs.access(dir, function(err) { fs.access(dir, function(err) {
if (err) console.error(err) if (err) console.error(err);
}); });
if (filename && basic) { if (filename && basic) {
var steps = ref.steps; var steps = ref.steps;
@@ -53,17 +53,17 @@ module.exports = function ExportBin(dir = "./output/", ref, basic, filename) {
var datauri = steps.slice(-1)[0].output.src; var datauri = steps.slice(-1)[0].output.src;
var ext = steps.slice(-1)[0].output.format; var ext = steps.slice(-1)[0].output.format;
var buffer = require('data-uri-to-buffer')(datauri); var buffer = require('data-uri-to-buffer')(datauri);
fs.writeFile(root + "image" + "_" + (steps.length - 1) + "." + ext, buffer, function() { }); fs.writeFile(root + 'image' + '_' + (steps.length - 1) + '.' + ext, buffer, function() { });
} }
else { else {
for (var i in steps) { for (var i in steps) {
var datauri = steps[i].output.src; var datauri = steps[i].output.src;
var ext = steps[i].output.format; var ext = steps[i].output.format;
var buffer = require('data-uri-to-buffer')(datauri); var buffer = require('data-uri-to-buffer')(datauri);
fs.writeFile(root + "image" + "_" + i + "." + ext, buffer, function() { }); fs.writeFile(root + 'image' + '_' + i + '.' + ext, buffer, function() { });
} }
} }
}); });
}); });
} }
} };

View File

@@ -1,5 +1,5 @@
function objTypeOf(object){ function objTypeOf(object){
return Object.prototype.toString.call(object).split(" ")[1].slice(0,-1) return Object.prototype.toString.call(object).split(' ')[1].slice(0,-1);
} }
function getPrimitive(object){ function getPrimitive(object){
@@ -7,13 +7,13 @@ function getPrimitive(object){
} }
function makeArray(input) { function makeArray(input) {
return (objTypeOf(input)=="Array")?input:[input]; return (objTypeOf(input)=='Array')?input:[input];
} }
function copy(a) { function copy(a) {
if (!typeof(a) == "object") return a; if (!typeof(a) == 'object') return a;
if (objTypeOf(a) == "Array") return a.slice(); if (objTypeOf(a) == 'Array') return a.slice();
if (objTypeOf(a) == "Object") { if (objTypeOf(a) == 'Object') {
var b = {}; var b = {};
for (var v in a) { for (var v in a) {
b[v] = copy(a[v]); b[v] = copy(a[v]);
@@ -26,77 +26,77 @@ function copy(a) {
function formatInput(args,format,images) { function formatInput(args,format,images) {
var json_q = {}; var json_q = {};
var format_i = format; var format_i = format;
if (format == "+") if (format == '+')
format = ['string_a', 'o_object']; format = ['string_a', 'o_object'];
else if (format == "-") else if (format == '-')
format = ['number_a']; format = ['number_a'];
else if (format == "^") else if (format == '^')
format = ['number', 'string', 'o_object']; format = ['number', 'string', 'o_object'];
else if (format == "r") else if (format == 'r')
format = ['o_number']; format = ['o_number'];
else if (format == "l") else if (format == 'l')
format = ['string','o_function']; format = ['string','o_function'];
if(format[format.length-1] == "o_object") { if(format[format.length-1] == 'o_object') {
if(objTypeOf(args[args.length-1]) != "Object") if(objTypeOf(args[args.length-1]) != 'Object')
args.push({}); args.push({});
} }
else if (format[format.length-1] == "o_number") { else if (format[format.length-1] == 'o_number') {
if(typeof(args[args.length-1]) != "number" && objTypeOf(args[0])!="Object") if(typeof(args[args.length-1]) != 'number' && objTypeOf(args[0])!='Object')
args.push(1); args.push(1);
} }
else if (format[format.length-1] == "o_function") { else if (format[format.length-1] == 'o_function') {
if(objTypeOf(args[args.length-1]) != "Function" && objTypeOf(args[0])!="Object") if(objTypeOf(args[args.length-1]) != 'Function' && objTypeOf(args[0])!='Object')
args.push(function(){}); args.push(function(){});
} }
if(args.length == format.length) {//making of arrays if(args.length == format.length) {//making of arrays
for (var i in format) { for (var i in format) {
if (format[i].substr(format[i].length-2,2)=="_a") if (format[i].substr(format[i].length-2,2)=='_a')
args[i] = makeArray(args[i]); args[i] = makeArray(args[i]);
} }
} }
if (args.length == 1 ) { if (args.length == 1 ) {
if(format_i == "r") json_q = {0:copy(args[0])}; if(format_i == 'r') json_q = {0:copy(args[0])};
else if(format_i == "-") { else if(format_i == '-') {
json_q=[]; json_q=[];
json_q= copy(args[0]); json_q= copy(args[0]);
} }
} }
else if (format_i == "r" ) { else if (format_i == 'r' ) {
for (var img in args[0]) json_q = {0:args[0]}; for (var img in args[0]) json_q = {0:args[0]};
} }
else if (format_i == "l") { else if (format_i == 'l') {
json_q = { json_q = {
image: args[0], image: args[0],
callback: args[1] callback: args[1]
} };
} }
else { else {
json_q = []; json_q = [];
if(format_i == "+") { if(format_i == '+') {
for(var s in args[0]) { for(var s in args[0]) {
json_q.push({
name: args[0][s],
o: args[1]
});
}
}
if(format_i == "^") {
var size = this.steps.length;
var index = args[0];
index = (index==size)?index:index%size;
if (index<0) index += size+1;
json_q.push({ json_q.push({
index: index, name: args[0][s],
name: args[1], o: args[1]
o: args[2]
}); });
}
}
if(format_i == '^') {
var size = this.steps.length;
var index = args[0];
index = (index==size)?index:index%size;
if (index<0) index += size+1;
json_q.push({
index: index,
name: args[1],
o: args[2]
});
} }
} }

View File

@@ -1,29 +1,29 @@
if (typeof window !== 'undefined') { isBrowser = true } if (typeof window !== 'undefined') { isBrowser = true; }
else { var isBrowser = false } else { var isBrowser = false; }
require('./util/getStep.js'); require('./util/getStep.js');
ImageSequencer = function ImageSequencer(options) { ImageSequencer = function ImageSequencer(options) {
var sequencer = (this.name == "ImageSequencer") ? this : this.sequencer; var sequencer = (this.name == 'ImageSequencer') ? this : this.sequencer;
options = options || {}; options = options || {};
options.inBrowser = options.inBrowser === undefined ? isBrowser : options.inBrowser; options.inBrowser = options.inBrowser === undefined ? isBrowser : options.inBrowser;
options.sequencerCounter = 0; options.sequencerCounter = 0;
function objTypeOf(object) { function objTypeOf(object) {
return Object.prototype.toString.call(object).split(" ")[1].slice(0, -1) return Object.prototype.toString.call(object).split(' ')[1].slice(0, -1);
} }
function log(color, msg) { function log(color, msg) {
if (options.ui != "none") { if (options.ui != 'none') {
if (arguments.length == 1) console.log(arguments[0]); if (arguments.length == 1) console.log(arguments[0]);
else if (arguments.length == 2) console.log(color, msg); else if (arguments.length == 2) console.log(color, msg);
} }
} }
function copy(a) { function copy(a) {
if (!typeof (a) == "object") return a; if (!typeof (a) == 'object') return a;
if (objTypeOf(a) == "Array") return a.slice(); if (objTypeOf(a) == 'Array') return a.slice();
if (objTypeOf(a) == "Object") { if (objTypeOf(a) == 'Object') {
var b = {}; var b = {};
for (var v in a) { for (var v in a) {
b[v] = copy(a[v]); b[v] = copy(a[v]);
@@ -34,7 +34,7 @@ ImageSequencer = function ImageSequencer(options) {
} }
function makeArray(input) { function makeArray(input) {
return (objTypeOf(input) == "Array") ? input : [input]; return (objTypeOf(input) == 'Array') ? input : [input];
} }
var image, var image,
@@ -64,15 +64,15 @@ ImageSequencer = function ImageSequencer(options) {
// else if (options.imageUrl) loadImage(imageUrl); // else if (options.imageUrl) loadImage(imageUrl);
function addSteps() { function addSteps() {
var this_ = (this.name == "ImageSequencer") ? this : this.sequencer; var this_ = (this.name == 'ImageSequencer') ? this : this.sequencer;
var args = []; var args = [];
var json_q = {}; var json_q = {};
for (var arg in arguments) { args.push(copy(arguments[arg])); } for (var arg in arguments) { args.push(copy(arguments[arg])); }
json_q = formatInput.call(this_, args, "+"); json_q = formatInput.call(this_, args, '+');
inputlog.push({ method: "addSteps", json_q: copy(json_q) }); inputlog.push({ method: 'addSteps', json_q: copy(json_q) });
for (var j in json_q) for (var j in json_q)
require("./AddStep")(this_, json_q[j].name, json_q[j].o); require('./AddStep')(this_, json_q[j].name, json_q[j].o);
return this; return this;
} }
@@ -89,31 +89,31 @@ ImageSequencer = function ImageSequencer(options) {
function removeSteps() { function removeSteps() {
var indices; var indices;
var this_ = (this.name == "ImageSequencer") ? this : this.sequencer; var this_ = (this.name == 'ImageSequencer') ? this : this.sequencer;
var args = []; var args = [];
for (var arg in arguments) args.push(copy(arguments[arg])); for (var arg in arguments) args.push(copy(arguments[arg]));
var json_q = formatInput.call(this_, args, "-"); var json_q = formatInput.call(this_, args, '-');
inputlog.push({ method: "removeSteps", json_q: copy(json_q) }); inputlog.push({ method: 'removeSteps', json_q: copy(json_q) });
indices = json_q.sort(function(a, b) { return b - a }); indices = json_q.sort(function(a, b) { return b - a; });
for (var i in indices) for (var i in indices)
removeStep(this_, indices[i]); removeStep(this_, indices[i]);
return this; return this;
} }
function insertSteps() { function insertSteps() {
var this_ = (this.name == "ImageSequencer") ? this : this.sequencer; var this_ = (this.name == 'ImageSequencer') ? this : this.sequencer;
var args = [] var args = [];
for (var arg in arguments) args.push(arguments[arg]); for (var arg in arguments) args.push(arguments[arg]);
var json_q = formatInput.call(this_, args, "^"); var json_q = formatInput.call(this_, args, '^');
inputlog.push({ method: "insertSteps", json_q: copy(json_q) }); inputlog.push({ method: 'insertSteps', json_q: copy(json_q) });
var details = json_q; var details = json_q;
details = details.sort(function(a, b) { return b.index - a.index }); details = details.sort(function(a, b) { return b.index - a.index; });
for (var i in details) for (var i in details)
require("./InsertStep")(this_, details[i].index, details[i].name, details[i].o); require('./InsertStep')(this_, details[i].index, details[i].name, details[i].o);
return this; return this;
} }
@@ -124,21 +124,21 @@ ImageSequencer = function ImageSequencer(options) {
config = config || { mode: 'no-arg' }; config = config || { mode: 'no-arg' };
if (config.index) index = config.index; if (config.index) index = config.index;
if (config.mode != "no-arg" && typeof config != 'function') { if (config.mode != 'no-arg' && typeof config != 'function') {
if (config.progressObj) progressObj = config.progressObj; if (config.progressObj) progressObj = config.progressObj;
delete arguments['0']; delete arguments['0'];
} }
var this_ = (this.name == "ImageSequencer") ? this : this.sequencer; var this_ = (this.name == 'ImageSequencer') ? this : this.sequencer;
var args = []; var args = [];
for (var arg in arguments) args.push(copy(arguments[arg])); for (var arg in arguments) args.push(copy(arguments[arg]));
var callback = function() { }; var 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 is formed callback = args.splice(arg, 1)[0]; //callback is formed
var json_q = formatInput.call(this_, args, "r"); var json_q = formatInput.call(this_, args, 'r');
require('./Run')(this_, json_q, callback, index, progressObj); require('./Run')(this_, json_q, callback, index, progressObj);
@@ -147,19 +147,19 @@ ImageSequencer = function ImageSequencer(options) {
function loadImages() { function loadImages() {
var args = []; var args = [];
var prevSteps = this.getSteps().slice(1).map(step=>step.options.name) var prevSteps = this.getSteps().slice(1).map(step=>step.options.name);
var sequencer = this; var sequencer = this;
sequencer.image = arguments[0]; sequencer.image = arguments[0];
for (var arg in arguments) args.push(copy(arguments[arg])); for (var arg in arguments) args.push(copy(arguments[arg]));
var json_q = formatInput.call(this, args, "l"); var json_q = formatInput.call(this, args, 'l');
if(this.getSteps().length!=0){ if(this.getSteps().length!=0){
this.options.sequencerCounter = 0; this.options.sequencerCounter = 0;
inputlog = []; inputlog = [];
this.steps = []; this.steps = [];
} }
inputlog.push({ method: "loadImages", json_q: copy(json_q) }); inputlog.push({ method: 'loadImages', json_q: copy(json_q) });
var ret = { var ret = {
name: "ImageSequencer Wrapper", name: 'ImageSequencer Wrapper',
sequencer: this, sequencer: this,
addSteps: this.addSteps, addSteps: this.addSteps,
removeSteps: this.removeSteps, removeSteps: this.removeSteps,
@@ -170,11 +170,11 @@ ImageSequencer = function ImageSequencer(options) {
}; };
function loadPrevSteps(ref){ function loadPrevSteps(ref){
if(prevSteps.length!=0){ if(prevSteps.length!=0){
ref.addSteps(prevSteps) ref.addSteps(prevSteps);
prevSteps=[]; prevSteps=[];
} }
} }
require('./ui/LoadImage')(sequencer, "image", json_q.image, function() { require('./ui/LoadImage')(sequencer, 'image', json_q.image, function() {
loadPrevSteps(sequencer); loadPrevSteps(sequencer);
json_q.callback.call(ret); json_q.callback.call(ret);
}); });
@@ -198,11 +198,11 @@ ImageSequencer = function ImageSequencer(options) {
var exportBin = function(dir, basic, filename) { var exportBin = function(dir, basic, filename) {
return require('./ExportBin')(dir, this, basic, filename); return require('./ExportBin')(dir, this, basic, filename);
} };
function modulesInfo(name) { function modulesInfo(name) {
var modulesdata = {} var modulesdata = {};
if (name == "load-image") return {}; if (name == 'load-image') return {};
if (arguments.length == 0) { if (arguments.length == 0) {
for (var modulename in this.modules) { for (var modulename in this.modules) {
modulesdata[modulename] = modules[modulename][1]; modulesdata[modulename] = modules[modulename][1];
@@ -213,8 +213,8 @@ ImageSequencer = function ImageSequencer(options) {
} }
else { else {
if (modules[name]){ if (modules[name]){
modulesdata = modules[name][1]; modulesdata = modules[name][1];
} }
else else
modulesdata = { 'inputs': sequences[name]['options'] }; modulesdata = { 'inputs': sequences[name]['options'] };
} }
@@ -253,7 +253,7 @@ ImageSequencer = function ImageSequencer(options) {
return; return;
} }
var mods = fs.readFileSync('./src/Modules.js').toString(); var mods = fs.readFileSync('./src/Modules.js').toString();
mods = mods.substr(0, mods.length - 1) + " '" + name + "': require('" + path + "'),\n}"; mods = mods.substr(0, mods.length - 1) + ' \'' + name + '\': require(\'' + path + '\'),\n}';
fs.writeFileSync('./src/Modules.js', mods); fs.writeFileSync('./src/Modules.js', mods);
} }
@@ -283,11 +283,11 @@ ImageSequencer = function ImageSequencer(options) {
this.sequences = require('./SavedSequences.json'); this.sequences = require('./SavedSequences.json');
} }
var str = require('./Strings.js')(this.steps, modulesInfo, addSteps, copy) var str = require('./Strings.js')(this.steps, modulesInfo, addSteps, copy);
return { return {
//literals and objects //literals and objects
name: "ImageSequencer", name: 'ImageSequencer',
options: options, options: options,
inputlog: inputlog, inputlog: inputlog,
modules: modules, modules: modules,
@@ -331,7 +331,7 @@ ImageSequencer = function ImageSequencer(options) {
copy: copy, copy: copy,
setInputStep: require('./ui/SetInputStep')(sequencer) setInputStep: require('./ui/SetInputStep')(sequencer)
} };
} };
module.exports = ImageSequencer; module.exports = ImageSequencer;

View File

@@ -7,7 +7,7 @@ function InsertStep(ref, index, name, o) {
} }
if (ref.detectStringSyntax(name)) { if (ref.detectStringSyntax(name)) {
return ref.stringToSteps(name) return ref.stringToSteps(name);
} }
function insertStep(index, name, o_) { function insertStep(index, name, o_) {
@@ -43,7 +43,7 @@ function InsertStep(ref, index, name, o) {
let step = stepsArray[i]; let step = stepsArray[i];
ref.insertSteps(index + Number.parseInt(i), step['name'], step['options']); ref.insertSteps(index + Number.parseInt(i), step['name'], step['options']);
} }
} };
// Tell UI that a step has been set up. // Tell UI that a step has been set up.
o = o || {}; o = o || {};

View File

@@ -42,4 +42,4 @@ module.exports = {
'tint': require('./modules/Tint'), 'tint': require('./modules/Tint'),
'webgl-distort': require('./modules/WebglDistort'), 'webgl-distort': require('./modules/WebglDistort'),
'white-balance': require('./modules/WhiteBalance') 'white-balance': require('./modules/WhiteBalance')
} };

View File

@@ -33,19 +33,19 @@ function ReplaceImage(ref,selector,steps,options) {
} }
var base64 = btoa(raw); var base64 = btoa(raw);
var dataURL="data:image/"+ext+";base64," + base64; var dataURL='data:image/'+ext+';base64,' + base64;
make(dataURL); make(dataURL);
}; };
if(url.substr(0,11).toLowerCase()!="data:image/") xmlHTTP.send(); if(url.substr(0,11).toLowerCase()!='data:image/') xmlHTTP.send();
else make(url); else make(url);
function make(url) { function make(url) {
tempSequencer.loadImage(url, function(){ tempSequencer.loadImage(url, function(){
// this.addSteps(steps).run({stop:function(){}},function(out){ // this.addSteps(steps).run({stop:function(){}},function(out){
var sequence = this.addSteps(steps) var sequence = this.addSteps(steps);
if (ref.detectStringSyntax(steps)) if (ref.detectStringSyntax(steps))
sequence = this.stringToSteps(steps) sequence = this.stringToSteps(steps);
sequence.run({stop:function(){}},function(out){ sequence.run({stop:function(){}},function(out){
img.src = out; img.src = out;
}); });

View File

@@ -5,7 +5,7 @@ function Run(ref, json_q, callback, ind, progressObj) {
function drawStep(drawarray, pos) { function drawStep(drawarray, pos) {
if (pos == drawarray.length && drawarray[pos - 1] !== undefined) { if (pos == drawarray.length && drawarray[pos - 1] !== undefined) {
if (ref.objTypeOf(callback) == "Function" && ref.steps.slice(-1)[0].output) { if (ref.objTypeOf(callback) == 'Function' && ref.steps.slice(-1)[0].output) {
var steps = ref.steps; var steps = ref.steps;
var out = steps[steps.length - 1].output.src; var out = steps[steps.length - 1].output.src;
callback(out); callback(out);
@@ -25,7 +25,7 @@ function Run(ref, json_q, callback, ind, progressObj) {
}; };
step.getIndex = function getIndex() { step.getIndex = function getIndex() {
return i; return i;
} };
for (var util in getStepUtils) { for (var util in getStepUtils) {
if (getStepUtils.hasOwnProperty(util)) { if (getStepUtils.hasOwnProperty(util)) {
@@ -58,26 +58,26 @@ function Run(ref, json_q, callback, ind, progressObj) {
function drawSteps(json_q) { function drawSteps(json_q) {
var drawarray = [], var drawarray = [],
no_steps = ref.steps.length, no_steps = ref.steps.length,
init = json_q[0]; init = json_q[0];
for (var i = 0; i < no_steps - init; i++) { for (var i = 0; i < no_steps - init; i++) {
drawarray.push({i: init + i }); drawarray.push({i: init + i });
} }
drawStep(drawarray, ind); drawStep(drawarray, ind);
} }
function filter(json_q) { function filter(json_q) {
if (json_q[0] == 0 && ref.steps.length == 1) if (json_q[0] == 0 && ref.steps.length == 1)
delete json_q[0]; delete json_q[0];
else if (json_q[0] == 0) json_q[0]++; else if (json_q[0] == 0) json_q[0]++;
var prevstep = ref.steps[json_q[0] - 1]; var prevstep = ref.steps[json_q[0] - 1];
while ( while (
typeof prevstep == "undefined" || typeof prevstep == 'undefined' ||
typeof prevstep.output == "undefined" typeof prevstep.output == 'undefined'
) { ) {
prevstep = ref.steps[--json_q[0] - 1]; prevstep = ref.steps[--json_q[0] - 1];
} }
return json_q; return json_q;
} }

View File

@@ -5,10 +5,10 @@ const dataUriToBuffer = require('data-uri-to-buffer');
const savePixels = require('save-pixels'); const savePixels = require('save-pixels');
module.exports = function(input) { module.exports = function(input) {
input.getPixels = getPixels; input.getPixels = getPixels;
input.pixelManipulation = pixelManipulation; input.pixelManipulation = pixelManipulation;
input.lodash = lodash; input.lodash = lodash;
input.dataUriToBuffer = dataUriToBuffer; input.dataUriToBuffer = dataUriToBuffer;
input.savePixels = savePixels; input.savePixels = savePixels;
return input; return input;
} };

View File

@@ -1,44 +1,44 @@
module.exports = function(steps, modulesInfo, addSteps, copy) { module.exports = function(steps, modulesInfo, addSteps, copy) {
// Genates a CLI string for the current sequence // Genates a CLI string for the current sequence
function toCliString() { function toCliString() {
var cliStringSteps = `"`, cliOptions = {}; var cliStringSteps = '"', cliOptions = {};
for (var step in this.steps) { for (var step in this.steps) {
var name = (typeof this.steps[step].options !== "undefined")? this.steps[step].options.name : this.steps[step].name var name = (typeof this.steps[step].options !== 'undefined')? this.steps[step].options.name : this.steps[step].name;
if (name !== "load-image"){ if (name !== 'load-image'){
cliStringSteps += `${name} `; cliStringSteps += `${name} `;
} }
for (var inp in modulesInfo(name).inputs) { for (var inp in modulesInfo(name).inputs) {
cliOptions[inp] = this.steps[step].options[inp]; cliOptions[inp] = this.steps[step].options[inp];
} }
} }
cliStringSteps = cliStringSteps.substr(0, cliStringSteps.length - 1) + `"`; cliStringSteps = cliStringSteps.substr(0, cliStringSteps.length - 1) + '"';
return `sequencer -i [PATH] -s ${cliStringSteps} -d '${JSON.stringify(cliOptions)}'` return `sequencer -i [PATH] -s ${cliStringSteps} -d '${JSON.stringify(cliOptions)}'`;
} }
// Checks if input is a string of comma separated module names // Checks if input is a string of comma separated module names
function detectStringSyntax(str) { function detectStringSyntax(str) {
let result = (str.includes(',') || str.includes('{')) ? true : false let result = (str.includes(',') || str.includes('{')) ? true : false;
return result return result;
} }
// Parses input string and returns array of module names // Parses input string and returns array of module names
function parseStringSyntax(str) { function parseStringSyntax(str) {
let stringifiedNames = str.replace(/\s/g, '') let stringifiedNames = str.replace(/\s/g, '');
let moduleNames = stringifiedNames.split(',') let moduleNames = stringifiedNames.split(',');
return moduleNames return moduleNames;
} }
// imports string of comma separated module names to sequencer steps // imports string of comma separated module names to sequencer steps
function stringToSteps(str) { function stringToSteps(str) {
let sequencer = this; let sequencer = this;
let names = [] let names = [];
if (this.name != "ImageSequencer") if (this.name != 'ImageSequencer')
sequencer = this.sequencer; sequencer = this.sequencer;
if (detectStringSyntax(str)) if (detectStringSyntax(str))
names = stringToJSON(str) names = stringToJSON(str);
names.forEach(function eachStep(stepObj) { names.forEach(function eachStep(stepObj) {
sequencer.addSteps(stepObj.name, stepObj.options) sequencer.addSteps(stepObj.name, stepObj.options);
}) });
} }
// Strigifies the current sequence // Strigifies the current sequence
@@ -96,7 +96,7 @@ module.exports = function(steps, modulesInfo, addSteps, copy) {
if (str.indexOf(bracesStrings[0]) === -1) { // if there are no settings specified if (str.indexOf(bracesStrings[0]) === -1) { // if there are no settings specified
var moduleName = str.substr(0); var moduleName = str.substr(0);
stepSettings = ""; stepSettings = '';
} else { } else {
var moduleName = str.substr(0, str.indexOf(bracesStrings[0])); var moduleName = str.substr(0, str.indexOf(bracesStrings[0]));
stepSettings = str.slice(str.indexOf(bracesStrings[0]) + 1, -1); stepSettings = str.slice(str.indexOf(bracesStrings[0]) + 1, -1);
@@ -112,20 +112,20 @@ module.exports = function(steps, modulesInfo, addSteps, copy) {
settingName, settingName,
settingValue settingValue
]; ];
if (!!settingName) accumulator[settingName] = settingValue; if (settingName) accumulator[settingName] = settingValue;
return accumulator; return accumulator;
}, {}); }, {});
return { return {
name: moduleName, name: moduleName,
options: stepSettings options: stepSettings
} };
} }
// imports a string into the sequencer steps // imports a string into the sequencer steps
function importString(str) { function importString(str) {
let sequencer = this; let sequencer = this;
if (this.name != "ImageSequencer") if (this.name != 'ImageSequencer')
sequencer = this.sequencer; sequencer = this.sequencer;
var stepsFromString = stringToJSON(str); var stepsFromString = stringToJSON(str);
stepsFromString.forEach(function eachStep(stepObj) { stepsFromString.forEach(function eachStep(stepObj) {
@@ -136,7 +136,7 @@ module.exports = function(steps, modulesInfo, addSteps, copy) {
// imports a array of JSON steps into the sequencer steps // imports a array of JSON steps into the sequencer steps
function importJSON(obj) { function importJSON(obj) {
let sequencer = this; let sequencer = this;
if (this.name != "ImageSequencer") if (this.name != 'ImageSequencer')
sequencer = this.sequencer; sequencer = this.sequencer;
obj.forEach(function eachStep(stepObj) { obj.forEach(function eachStep(stepObj) {
sequencer.addSteps(stepObj.name, stepObj.options); sequencer.addSteps(stepObj.name, stepObj.options);
@@ -155,5 +155,5 @@ module.exports = function(steps, modulesInfo, addSteps, copy) {
stringToJSONstep: stringToJSONstep, stringToJSONstep: stringToJSONstep,
importString: importString, importString: importString,
importJSON: importJSON importJSON: importJSON
} };
} };

View File

@@ -1,17 +1,17 @@
var childProcess = require('child_process') var childProcess = require('child_process');
var Spinner = require('ora'); var Spinner = require('ora');
module.exports = function (program, sequencer) { module.exports = function (program, sequencer) {
console.log( console.log(
"\x1b[33m%s\x1b[0m", '\x1b[33m%s\x1b[0m',
"Please wait while your Module is being Installed...\nThis may take a while!" 'Please wait while your Module is being Installed...\nThis may take a while!'
); );
var params = program.installModule.split(' '); var params = program.installModule.split(' ');
var spinner = Spinner("Now Installing...").start(); var spinner = Spinner('Now Installing...').start();
childProcess.execSync(`npm i ${params[1]}`) childProcess.execSync(`npm i ${params[1]}`);
sequencer.saveNewModule(params[0], params[1]); sequencer.saveNewModule(params[0], params[1]);
sequencer.loadNewModule(params[0], require(params[1])); sequencer.loadNewModule(params[0], require(params[1]));
spinner.stop(); spinner.stop();
console.log("\x1b[32m%s\x1b[0m", "Your module was installed successfully!!"); console.log('\x1b[32m%s\x1b[0m', 'Your module was installed successfully!!');
} };

View File

@@ -1,7 +1,7 @@
module.exports = function (program, sequencer) { module.exports = function (program, sequencer) {
var params = program.saveSequence.split(' '); var params = program.saveSequence.split(' ');
sequencer.saveSequence(params[0], params[1]); sequencer.saveSequence(params[0], params[1]);
console.log("\x1b[32m", "Your sequence was saved successfully!!"); console.log('\x1b[32m', 'Your sequence was saved successfully!!');
} };

View File

@@ -1,13 +1,13 @@
var Spinner = require('ora'); var Spinner = require('ora');
var readlineSync = require('readline-sync'); var readlineSync = require('readline-sync');
var utils = require('../CliUtils') var utils = require('../CliUtils');
module.exports = function (program, sequencer, outputFilename) { module.exports = function (program, sequencer, outputFilename) {
utils.makedir(program.output, () => { utils.makedir(program.output, () => {
console.log('Files will be exported to "' + program.output + '"'); console.log('Files will be exported to "' + program.output + '"');
if (program.basic) if (program.basic)
console.log("Basic mode is enabled, outputting only final image"); console.log('Basic mode is enabled, outputting only final image');
// Iterate through the steps and retrieve their inputs. // Iterate through the steps and retrieve their inputs.
program.step.forEach(function(step) { program.step.forEach(function(step) {
@@ -15,7 +15,7 @@ module.exports = function (program, sequencer, outputFilename) {
// If inputs exists, print to console. // If inputs exists, print to console.
if (Object.keys(options).length) { if (Object.keys(options).length) {
console.log("[" + step + "]: Inputs"); console.log('[' + step + ']: Inputs');
} }
// If inputs exists, print them out with descriptions. // If inputs exists, print them out with descriptions.
@@ -23,9 +23,9 @@ module.exports = function (program, sequencer, outputFilename) {
// The array below creates a variable number of spaces. This is done with (length + 1). // The array below creates a variable number of spaces. This is done with (length + 1).
// The extra 4 that makes it (length + 5) is to account for the []: characters // The extra 4 that makes it (length + 5) is to account for the []: characters
console.log( console.log(
new Array(step.length + 5).join(" ") + new Array(step.length + 5).join(' ') +
input + input +
": " + ': ' +
options[input].desc options[input].desc
); );
}); });
@@ -33,18 +33,18 @@ module.exports = function (program, sequencer, outputFilename) {
if (program.config) { if (program.config) {
try { try {
var config = JSON.parse(program.config); var config = JSON.parse(program.config);
console.log(`The parsed options object: `, config); console.log('The parsed options object: ', config);
} catch (e) { } catch (e) {
console.error( console.error(
"\x1b[31m%s\x1b[0m", '\x1b[31m%s\x1b[0m',
`Options(Config) is not a not valid JSON Fallback activate` 'Options(Config) is not a not valid JSON Fallback activate'
); );
program.config = false; program.config = false;
console.log(e); console.log(e);
} }
} }
if (program.config && utils.validateConfig(config, options)) { if (program.config && utils.validateConfig(config, options)) {
console.log("Now using Options object"); console.log('Now using Options object');
Object.keys(options).forEach(function(input) { Object.keys(options).forEach(function(input) {
options[input] = config[input]; options[input] = config[input];
}); });
@@ -52,15 +52,15 @@ module.exports = function (program, sequencer, outputFilename) {
// If inputs exist, iterate through them and prompt for values. // If inputs exist, iterate through them and prompt for values.
Object.keys(options).forEach(function(input) { Object.keys(options).forEach(function(input) {
var value = readlineSync.question( var value = readlineSync.question(
"[" + '[' +
step + step +
"]: Enter a value for " + ']: Enter a value for ' +
input + input +
" (" + ' (' +
options[input].type + options[input].type +
", default: " + ', default: ' +
options[input].default + options[input].default +
"): " '): '
); );
options[input] = value; options[input] = value;
}); });
@@ -71,7 +71,7 @@ module.exports = function (program, sequencer, outputFilename) {
var spinnerObj = { succeed: () => { }, stop: () => { } }; var spinnerObj = { succeed: () => { }, stop: () => { } };
if (!process.env.TEST) if (!process.env.TEST)
spinnerObj = Spinner("Your Image is being processed..").start(); spinnerObj = Spinner('Your Image is being processed..').start();
// Run the sequencer. // Run the sequencer.
sequencer.run({ progressObj: spinnerObj }, function() { sequencer.run({ progressObj: spinnerObj }, function() {
@@ -81,8 +81,8 @@ module.exports = function (program, sequencer, outputFilename) {
//check if spinner was not overriden stop it //check if spinner was not overriden stop it
if (!spinnerObj.overrideFlag) { if (!spinnerObj.overrideFlag) {
spinnerObj.succeed(); spinnerObj.succeed();
console.log(`\nDone!!`); console.log('\nDone!!');
} }
}); });
}); });
} };

View File

@@ -1,51 +1,51 @@
module.exports = function AddQR(options, UI) { module.exports = function AddQR(options, UI) {
var defaults = require('./../../util/getDefaults.js')(require('./info.json')); var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
options.size = options.size || defaults.size; options.size = options.size || defaults.size;
options.qrCodeString = options.qrCodeString || "https://github.com/publiclab/image-sequencer"; options.qrCodeString = options.qrCodeString || 'https://github.com/publiclab/image-sequencer';
var output; var output;
getPixels = require('get-pixels'); getPixels = require('get-pixels');
function draw(input, callback, progressObj) { function draw(input, callback, progressObj) {
progressObj.stop(true); progressObj.stop(true);
progressObj.overrideFlag = true; progressObj.overrideFlag = true;
var step = this; var step = this;
return getPixels(input.src, function (err, oldPixels) { return getPixels(input.src, function (err, oldPixels) {
function changePixel(r, g, b, a) { function changePixel(r, g, b, a) {
return [r, g, b, a]; return [r, g, b, a];
} }
function extraManipulation(pixels,generateOutput) { function extraManipulation(pixels,generateOutput) {
if (err) { if (err) {
console.log(err); console.log(err);
return; return;
} }
require('./QR')(options, pixels, oldPixels, generateOutput); require('./QR')(options, pixels, oldPixels, generateOutput);
} }
function output(image, datauri, mimetype) { function output(image, datauri, mimetype) {
step.output = { src: datauri, format: mimetype }; step.output = { src: datauri, format: mimetype };
} }
return require('../_nomodule/PixelManipulation.js')(input, { return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
changePixel: changePixel,
extraManipulation: extraManipulation,
format: input.format,
image: options.image,
inBrowser: options.inBrowser,
callback: callback
});
})
}
return {
options: options,
draw: draw,
output: output, output: output,
UI: UI changePixel: changePixel,
} extraManipulation: extraManipulation,
} format: input.format,
image: options.image,
inBrowser: options.inBrowser,
callback: callback
});
});
}
return {
options: options,
draw: draw,
output: output,
UI: UI
};
};

View File

@@ -1,48 +1,48 @@
module.exports = exports = function (options, pixels, oldPixels, callback) { module.exports = exports = function (options, pixels, oldPixels, callback) {
var QRCode = require('qrcode') var QRCode = require('qrcode');
QRCode.toDataURL(options.qrCodeString, function (err, url) { QRCode.toDataURL(options.qrCodeString, function (err, url) {
var getPixels = require("get-pixels"); var getPixels = require('get-pixels');
getPixels(url, function (err, qrPixels) { getPixels(url, function (err, qrPixels) {
if (err) { if (err) {
console.log("Bad image path", image); console.log('Bad image path', image);
} }
var imagejs = require('imagejs'); var imagejs = require('imagejs');
var bitmap = new imagejs.Bitmap({ width: qrPixels.shape[0], height: qrPixels.shape[1] }); var bitmap = new imagejs.Bitmap({ width: qrPixels.shape[0], height: qrPixels.shape[1] });
bitmap._data.data = qrPixels.data; bitmap._data.data = qrPixels.data;
var resized = bitmap.resize({ var resized = bitmap.resize({
width: options.size, height: options.size, width: options.size, height: options.size,
algorithm: "bicubicInterpolation" algorithm: 'bicubicInterpolation'
}); });
qrPixels.data = resized._data.data; qrPixels.data = resized._data.data;
qrPixels.shape = [options.size, options.size, 4]; qrPixels.shape = [options.size, options.size, 4];
qrPixels.stride[1] = 4 * options.size; qrPixels.stride[1] = 4 * options.size;
var width = oldPixels.shape[0], var width = oldPixels.shape[0],
height = oldPixels.shape[1]; height = oldPixels.shape[1];
var xe = width - options.size, var xe = width - options.size,
ye = height - options.size; ye = height - options.size;
for (var m = 0; m < width; m++) { for (var m = 0; m < width; m++) {
for (var n = 0; n < height; n++) { for (var n = 0; n < height; n++) {
if (m >= xe && n >= ye) { if (m >= xe && n >= ye) {
pixels.set(m, n, 0, qrPixels.get(m - xe, n - ye, 0)) pixels.set(m, n, 0, qrPixels.get(m - xe, n - ye, 0));
pixels.set(m, n, 1, qrPixels.get(m - xe, n - ye, 1)) pixels.set(m, n, 1, qrPixels.get(m - xe, n - ye, 1));
pixels.set(m, n, 2, qrPixels.get(m - xe, n - ye, 2)) pixels.set(m, n, 2, qrPixels.get(m - xe, n - ye, 2));
pixels.set(m, n, 3, qrPixels.get(m - xe, n - ye, 3)) pixels.set(m, n, 3, qrPixels.get(m - xe, n - ye, 3));
} }
else { else {
pixels.set(m, n, 0, oldPixels.get(m, n, 0)) pixels.set(m, n, 0, oldPixels.get(m, n, 0));
pixels.set(m, n, 1, oldPixels.get(m, n, 1)) pixels.set(m, n, 1, oldPixels.get(m, n, 1));
pixels.set(m, n, 2, oldPixels.get(m, n, 2)) pixels.set(m, n, 2, oldPixels.get(m, n, 2));
pixels.set(m, n, 3, oldPixels.get(m, n, 3)) pixels.set(m, n, 3, oldPixels.get(m, n, 3));
} }
} }
} }
callback(); callback();
}) });
}) });
} };

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -3,72 +3,72 @@
*/ */
module.exports = function Average(options, UI) { module.exports = function Average(options, UI) {
var output; var output;
options.step.metadata = options.step.metadata || {}; options.step.metadata = options.step.metadata || {};
function draw(input, callback, progressObj) { function draw(input, callback, progressObj) {
progressObj.stop(true); progressObj.stop(true);
progressObj.overrideFlag = true; progressObj.overrideFlag = true;
var step = this; var step = this;
// do the averaging // do the averaging
function extraManipulation(pixels) { function extraManipulation(pixels) {
var i = 0, sum = [0, 0, 0, 0]; var i = 0, sum = [0, 0, 0, 0];
while (i < pixels.data.length) { while (i < pixels.data.length) {
sum[0] += pixels.data[i++]; sum[0] += pixels.data[i++];
sum[1] += pixels.data[i++]; sum[1] += pixels.data[i++];
sum[2] += pixels.data[i++]; sum[2] += pixels.data[i++];
sum[3] += pixels.data[i++]; sum[3] += pixels.data[i++];
} }
let divisor = pixels.data.length / 4; let divisor = pixels.data.length / 4;
sum[0] = Math.floor(sum[0] / divisor); sum[0] = Math.floor(sum[0] / divisor);
sum[1] = Math.floor(sum[1] / divisor); sum[1] = Math.floor(sum[1] / divisor);
sum[2] = Math.floor(sum[2] / divisor); sum[2] = Math.floor(sum[2] / divisor);
sum[3] = Math.floor(sum[3] / divisor); sum[3] = Math.floor(sum[3] / divisor);
i = 0 i = 0;
while (i < pixels.data.length) { while (i < pixels.data.length) {
pixels.data[i++] = sum[0]; pixels.data[i++] = sum[0];
pixels.data[i++] = sum[1]; pixels.data[i++] = sum[1];
pixels.data[i++] = sum[2]; pixels.data[i++] = sum[2];
pixels.data[i++] = sum[3]; pixels.data[i++] = sum[3];
} }
// report back and store average in metadata: // report back and store average in metadata:
options.step.metadata.averages = sum; options.step.metadata.averages = sum;
// TODO: refactor into a new "display()" method as per https://github.com/publiclab/image-sequencer/issues/242
if (options.step.inBrowser && options.step.ui) $(options.step.ui).find('.details').append("<p><b>Averages</b> (r, g, b, a): " + sum.join(', ') + "</p>");
return pixels;
}
function output(image, datauri, mimetype) {
// This output is accessible by Image Sequencer
step.output = {
src: datauri,
format: mimetype
};
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
extraManipulation: extraManipulation,
format: input.format,
image: options.image,
callback: callback
});
// TODO: refactor into a new "display()" method as per https://github.com/publiclab/image-sequencer/issues/242
if (options.step.inBrowser && options.step.ui) $(options.step.ui).find('.details').append('<p><b>Averages</b> (r, g, b, a): ' + sum.join(', ') + '</p>');
return pixels;
} }
return {
options: options, function output(image, datauri, mimetype) {
draw: draw,
output: output, // This output is accessible by Image Sequencer
UI: UI step.output = {
src: datauri,
format: mimetype
};
} }
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
extraManipulation: extraManipulation,
format: input.format,
image: options.image,
callback: callback
});
}
return {
options: options,
draw: draw,
output: output,
UI: UI
};
};

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -1,75 +1,75 @@
module.exports = function Dynamic(options, UI, util) { module.exports = function Dynamic(options, UI, util) {
var defaults = require('./../../util/getDefaults.js')(require('./info.json')); var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
options.func = options.func || defaults.blend; options.func = options.func || defaults.blend;
options.offset = options.offset || defaults.offset; options.offset = options.offset || defaults.offset;
var output; var output;
// This function is called on every draw. // This function is called on every draw.
function draw(input, callback, progressObj) { function draw(input, callback, progressObj) {
progressObj.stop(true); progressObj.stop(true);
progressObj.overrideFlag = true; progressObj.overrideFlag = true;
var step = this; var step = this;
// convert to runnable code: // convert to runnable code:
if (typeof options.func === "string") eval('options.func = ' + options.func); if (typeof options.func === 'string') eval('options.func = ' + options.func);
var getPixels = require('get-pixels'); var getPixels = require('get-pixels');
// convert offset as string to int // convert offset as string to int
if (typeof options.offset === "string") options.offset = parseInt(options.offset); if (typeof options.offset === 'string') options.offset = parseInt(options.offset);
// save first image's pixels // save first image's pixels
var priorStep = this.getStep(options.offset); var priorStep = this.getStep(options.offset);
if (priorStep.output === undefined) { if (priorStep.output === undefined) {
this.output = input; this.output = input;
UI.notify('Offset Unavailable', 'offset-notification'); UI.notify('Offset Unavailable', 'offset-notification');
callback(); callback();
} }
getPixels(priorStep.output.src, function(err, pixels) { getPixels(priorStep.output.src, function(err, pixels) {
options.firstImagePixels = pixels; options.firstImagePixels = pixels;
function changePixel(r2, g2, b2, a2, x, y) { function changePixel(r2, g2, b2, a2, x, y) {
// blend! // blend!
let p = options.firstImagePixels; let p = options.firstImagePixels;
return options.func( return options.func(
r2, g2, b2, a2, r2, g2, b2, a2,
p.get(x, y, 0), p.get(x, y, 0),
p.get(x, y, 1), p.get(x, y, 1),
p.get(x, y, 2), p.get(x, y, 2),
p.get(x, y, 3) p.get(x, y, 3)
) );
} }
function output(image, datauri, mimetype) { function output(image, datauri, mimetype) {
// This output is accessible by Image Sequencer // This output is accessible by Image Sequencer
step.output = { src: datauri, format: mimetype }; step.output = { src: datauri, format: mimetype };
} }
// run PixelManipulatin on second image's pixels // run PixelManipulatin on second image's pixels
return require('../_nomodule/PixelManipulation.js')(input, { return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
changePixel: changePixel,
format: input.format,
image: options.image,
inBrowser: options.inBrowser,
callback: callback
});
});
}
return {
options: options,
draw: draw,
output: output, output: output,
UI: UI changePixel: changePixel,
} format: input.format,
} image: options.image,
inBrowser: options.inBrowser,
callback: callback
});
});
}
return {
options: options,
draw: draw,
output: output,
UI: UI
};
};

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -4,29 +4,29 @@ module.exports = exports = function(pixels, blur) {
r: [], r: [],
g: [], g: [],
b: [], b: [],
} };
for (let y = 0; y < pixels.shape[1]; y++){ for (let y = 0; y < pixels.shape[1]; y++){
pixs.r.push([]) pixs.r.push([]);
pixs.g.push([]) pixs.g.push([]);
pixs.b.push([]) pixs.b.push([]);
for (let x = 0; x < pixels.shape[0]; x++){ for (let x = 0; x < pixels.shape[0]; x++){
pixs.r[y].push(pixels.get(x, y, 0)) pixs.r[y].push(pixels.get(x, y, 0));
pixs.g[y].push(pixels.get(x, y, 1)) pixs.g[y].push(pixels.get(x, y, 1));
pixs.b[y].push(pixels.get(x, y, 2)) pixs.b[y].push(pixels.get(x, y, 2));
} }
} }
const convolve = require('../_nomodule/gpuUtils').convolve const convolve = require('../_nomodule/gpuUtils').convolve;
const conPix = convolve([pixs.r, pixs.g, pixs.b], kernel) const conPix = convolve([pixs.r, pixs.g, pixs.b], kernel);
for (let y = 0; y < pixels.shape[1]; y++){ for (let y = 0; y < pixels.shape[1]; y++){
for (let x = 0; x < pixels.shape[0]; x++){ for (let x = 0; x < pixels.shape[0]; x++){
pixels.set(x, y, 0, Math.max(0, Math.min(conPix[0][y][x], 255))) pixels.set(x, y, 0, Math.max(0, Math.min(conPix[0][y][x], 255)));
pixels.set(x, y, 1, Math.max(0, Math.min(conPix[1][y][x], 255))) pixels.set(x, y, 1, Math.max(0, Math.min(conPix[1][y][x], 255)));
pixels.set(x, y, 2, Math.max(0, Math.min(conPix[2][y][x], 255))) pixels.set(x, y, 2, Math.max(0, Math.min(conPix[2][y][x], 255)));
} }
} }
@@ -38,25 +38,25 @@ module.exports = exports = function(pixels, blur) {
let kernel = [], let kernel = [],
sum = 0; sum = 0;
if (sigma == 0) sigma += 0.05 if (sigma == 0) sigma += 0.05;
const s = 2 * Math.pow(sigma, 2); const s = 2 * Math.pow(sigma, 2);
for (let y = -2; y <= 2; y++) { for (let y = -2; y <= 2; y++) {
kernel.push([]) kernel.push([]);
for (let x = -2; x <= 2; x++) { for (let x = -2; x <= 2; x++) {
let r = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)) let r = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
kernel[y + 2].push(Math.exp(-(r / s))) kernel[y + 2].push(Math.exp(-(r / s)));
sum += kernel[y + 2][x + 2] sum += kernel[y + 2][x + 2];
} }
} }
for (let x = 0; x < 5; x++){ for (let x = 0; x < 5; x++){
for (let y = 0; y < 5; y++){ for (let y = 0; y < 5; y++){
kernel[y][x] = (kernel[y][x] / sum) kernel[y][x] = (kernel[y][x] / sum);
} }
} }
return kernel; return kernel;
} }
} };

View File

@@ -3,43 +3,43 @@
*/ */
module.exports = function Blur(options, UI) { module.exports = function Blur(options, UI) {
var defaults = require('./../../util/getDefaults.js')(require('./info.json')); var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
options.blur = options.blur || defaults.blur; options.blur = options.blur || defaults.blur;
options.blur = parseFloat(options.blur); options.blur = parseFloat(options.blur);
var output; var output;
function draw(input, callback, progressObj) { function draw(input, callback, progressObj) {
progressObj.stop(true); progressObj.stop(true);
progressObj.overrideFlag = true; progressObj.overrideFlag = true;
var step = this; var step = this;
function extraManipulation(pixels) { function extraManipulation(pixels) {
pixels = require('./Blur')(pixels, options.blur); pixels = require('./Blur')(pixels, options.blur);
return pixels; return pixels;
} }
function output(image, datauri, mimetype) { function output(image, datauri, mimetype) {
// This output is accessible by Image Sequencer // This output is accessible by Image Sequencer
step.output = { src: datauri, format: mimetype }; step.output = { src: datauri, format: mimetype };
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
extraManipulation: extraManipulation,
format: input.format,
image: options.image,
callback: callback
});
} }
return {
options: options, return require('../_nomodule/PixelManipulation.js')(input, {
draw: draw, output: output,
output: output, extraManipulation: extraManipulation,
UI: UI format: input.format,
} image: options.image,
} callback: callback
});
}
return {
options: options,
draw: draw,
output: output,
UI: UI
};
};

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -3,55 +3,55 @@
*/ */
module.exports = function Brightness(options, UI) { module.exports = function Brightness(options, UI) {
var defaults = require('./../../util/getDefaults.js')(require('./info.json')); var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
var output; var output;
function draw(input, callback, progressObj) { function draw(input, callback, progressObj) {
options.brightness = options.brightness || defaults.brightness; options.brightness = options.brightness || defaults.brightness;
progressObj.stop(true); progressObj.stop(true);
progressObj.overrideFlag = true; progressObj.overrideFlag = true;
/* /*
In this case progress is handled by changepixel internally otherwise progressObj In this case progress is handled by changepixel internally otherwise progressObj
needs to be overriden and used needs to be overriden and used
For eg. progressObj = new SomeProgressModule() For eg. progressObj = new SomeProgressModule()
*/ */
var step = this, val = (options.brightness) / 100.0;; var step = this, val = (options.brightness) / 100.0;
function changePixel(r, g, b, a) { function changePixel(r, g, b, a) {
r = Math.min(val * r, 255); r = Math.min(val * r, 255);
g = Math.min(val * g, 255); g = Math.min(val * g, 255);
b = Math.min(val * b, 255); b = Math.min(val * b, 255);
return [r, g, b, a]; return [r, g, b, a];
} }
function output(image, datauri, mimetype) { function output(image, datauri, mimetype) {
// This output is accessible by Image Sequencer // This output is accessible by Image Sequencer
step.output = { src: datauri, format: mimetype }; step.output = { src: datauri, format: mimetype };
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
changePixel: changePixel,
format: input.format,
image: options.image,
inBrowser: options.inBrowser,
callback: callback
});
} }
return {
options: options, return require('../_nomodule/PixelManipulation.js')(input, {
draw: draw, output: output,
output: output, changePixel: changePixel,
UI: UI format: input.format,
} image: options.image,
} inBrowser: options.inBrowser,
callback: callback
});
}
return {
options: options,
draw: draw,
output: output,
UI: UI
};
};

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -3,61 +3,61 @@
*/ */
module.exports = function canvasResize(options, UI) { module.exports = function canvasResize(options, UI) {
var defaults = require('./../../util/getDefaults.js')(require('./info.json')); var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
var output; var output;
function draw(input, callback, progressObj) { function draw(input, callback, progressObj) {
options.width = options.width || defaults.width; options.width = options.width || defaults.width;
options.height = options.height || defaults.height; options.height = options.height || defaults.height;
options.x = options.x || defaults.x; options.x = options.x || defaults.x;
options.y = options.y || defaults.y; options.y = options.y || defaults.y;
progressObj.stop(true); progressObj.stop(true);
progressObj.overrideFlag = true; progressObj.overrideFlag = true;
var step = this; var step = this;
function extraManipulation(pixels) { function extraManipulation(pixels) {
let newPixels = require('ndarray')(new Uint8Array(4 * options.width * options.height).fill(255), [options.width, options.height, 4]); let newPixels = require('ndarray')(new Uint8Array(4 * options.width * options.height).fill(255), [options.width, options.height, 4]);
let iMax = options.width - options.x, let iMax = options.width - options.x,
jMax = options.height - options.y; jMax = options.height - options.y;
for (let i = 0; i < iMax && i < pixels.shape[0]; i++) { for (let i = 0; i < iMax && i < pixels.shape[0]; i++) {
for (let j = 0; j < jMax && j < pixels.shape[1]; j++) { for (let j = 0; j < jMax && j < pixels.shape[1]; j++) {
let x = i + options.x, y = j + options.y; let x = i + options.x, y = j + options.y;
newPixels.set(x, y, 0, pixels.get(i, j, 0)); newPixels.set(x, y, 0, pixels.get(i, j, 0));
newPixels.set(x, y, 1, pixels.get(i, j, 1)); newPixels.set(x, y, 1, pixels.get(i, j, 1));
newPixels.set(x, y, 2, pixels.get(i, j, 2)); newPixels.set(x, y, 2, pixels.get(i, j, 2));
newPixels.set(x, y, 3, pixels.get(i, j, 3)); newPixels.set(x, y, 3, pixels.get(i, j, 3));
}
}
return newPixels;
} }
}
return newPixels;
}
function output(image, datauri, mimetype) { function output(image, datauri, mimetype) {
// This output is accessible by Image Sequencer // This output is accessible by Image Sequencer
step.output = { src: datauri, format: mimetype }; step.output = { src: datauri, format: mimetype };
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
extraManipulation: extraManipulation,
format: input.format,
image: options.image,
inBrowser: options.inBrowser,
callback: callback
});
} }
return {
options: options, return require('../_nomodule/PixelManipulation.js')(input, {
draw: draw, output: output,
output: output, extraManipulation: extraManipulation,
UI: UI format: input.format,
} image: options.image,
} inBrowser: options.inBrowser,
callback: callback
});
}
return {
options: options,
draw: draw,
output: output,
UI: UI
};
};

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -17,9 +17,9 @@ module.exports = function Channel(options, UI) {
var step = this; var step = this;
function changePixel(r, g, b, a) { function changePixel(r, g, b, a) {
if (options.channel === "red") return [r, 0, 0, a]; if (options.channel === 'red') return [r, 0, 0, a];
if (options.channel === "green") return [0, g, 0, a]; if (options.channel === 'green') return [0, g, 0, a];
if (options.channel === "blue") return [0, 0, b, a]; if (options.channel === 'blue') return [0, 0, b, a];
} }
function output(image, datauri, mimetype) { function output(image, datauri, mimetype) {
@@ -46,5 +46,5 @@ module.exports = function Channel(options, UI) {
draw: draw, draw: draw,
output: output, output: output,
UI: UI UI: UI
} };
} };

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -1,81 +1,81 @@
module.exports = function ColorTemperature(options, UI) { module.exports = function ColorTemperature(options, UI) {
var output; var output;
function draw(input, callback, progressObj) { function draw(input, callback, progressObj) {
options.temperature = (options.temperature > "40000") ? "40000" : options.temperature options.temperature = (options.temperature > '40000') ? '40000' : options.temperature;
progressObj.stop(true); progressObj.stop(true);
progressObj.overrideFlag = true; progressObj.overrideFlag = true;
var step = this; var step = this;
function extraManipulation(pixels) { function extraManipulation(pixels) {
let temp = parseInt(options.temperature) let temp = parseInt(options.temperature);
temp /= 100 temp /= 100;
let r, g, b; let r, g, b;
if (temp <= 66) { if (temp <= 66) {
r = 255; r = 255;
g = Math.min(Math.max(99.4708025861 * Math.log(temp) - 161.1195681661, 0), 255); g = Math.min(Math.max(99.4708025861 * Math.log(temp) - 161.1195681661, 0), 255);
} else { } else {
r = Math.min(Math.max(329.698727446 * Math.pow(temp - 60, -0.1332047592), 0), 255); r = Math.min(Math.max(329.698727446 * Math.pow(temp - 60, -0.1332047592), 0), 255);
g = Math.min(Math.max(288.1221695283 * Math.pow(temp - 60, -0.0755148492), 0), 255); g = Math.min(Math.max(288.1221695283 * Math.pow(temp - 60, -0.0755148492), 0), 255);
} }
if (temp >= 66) { if (temp >= 66) {
b = 255; b = 255;
} else if (temp <= 19) { } else if (temp <= 19) {
b = 0; b = 0;
} else { } else {
b = temp - 10; b = temp - 10;
b = Math.min(Math.max(138.5177312231 * Math.log(b) - 305.0447927307, 0), 255); b = Math.min(Math.max(138.5177312231 * Math.log(b) - 305.0447927307, 0), 255);
} }
for (let i = 0; i < pixels.shape[0]; i++) { for (let i = 0; i < pixels.shape[0]; i++) {
for (let j = 0; j < pixels.shape[1]; j++) { for (let j = 0; j < pixels.shape[1]; j++) {
r_data = pixels.get(i, j, 0) r_data = pixels.get(i, j, 0);
r_new_data = (255 / r) * r_data r_new_data = (255 / r) * r_data;
pixels.set(i, j, 0, r_new_data) pixels.set(i, j, 0, r_new_data);
g_data = pixels.get(i, j, 1) g_data = pixels.get(i, j, 1);
g_new_data = (255 / g) * g_data g_new_data = (255 / g) * g_data;
pixels.set(i, j, 1, g_new_data) pixels.set(i, j, 1, g_new_data);
b_data = pixels.get(i, j, 2) b_data = pixels.get(i, j, 2);
b_new_data = (255 / b) * b_data b_new_data = (255 / b) * b_data;
pixels.set(i, j, 2, b_new_data) pixels.set(i, j, 2, b_new_data);
}
}
return pixels
} }
}
function output(image, datauri, mimetype) { return pixels;
step.output = { src: datauri, format: mimetype };
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
extraManipulation: extraManipulation,
format: input.format,
image: options.image,
inBrowser: options.inBrowser,
callback: callback
});
} }
return { function output(image, datauri, mimetype) {
options: options,
draw: draw, step.output = { src: datauri, format: mimetype };
output: output,
UI: UI
} }
} return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
extraManipulation: extraManipulation,
format: input.format,
image: options.image,
inBrowser: options.inBrowser,
callback: callback
});
}
return {
options: options,
draw: draw,
output: output,
UI: UI
};
};

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -14,14 +14,14 @@
module.exports = function Colormap(value, options) { module.exports = function Colormap(value, options) {
options.colormap = options.colormap || colormaps.default; options.colormap = options.colormap || colormaps.default;
// if a lookup table is provided as an array: // if a lookup table is provided as an array:
if(typeof(options.colormap) == "object") if(typeof(options.colormap) == 'object')
colormapFunction = colormap(options.colormap); colormapFunction = colormap(options.colormap);
// if a stored colormap is named with a string like "fastie": // if a stored colormap is named with a string like "fastie":
else if(colormaps.hasOwnProperty(options.colormap)) else if(colormaps.hasOwnProperty(options.colormap))
colormapFunction = colormaps[options.colormap]; colormapFunction = colormaps[options.colormap];
else colormapFunction = colormaps.default; else colormapFunction = colormaps.default;
return colormapFunction(value / 255.00); return colormapFunction(value / 255.00);
} };
function colormap(segments) { function colormap(segments) {
return function(x) { return function(x) {
@@ -49,149 +49,149 @@ function colormap(segments) {
} }
return result; return result;
}; };
}; }
var colormaps = { var colormaps = {
greyscale: colormap([ greyscale: colormap([
[0, [0, 0, 0], [255, 255, 255] ], [0, [0, 0, 0], [255, 255, 255] ],
[1, [255, 255, 255], [255, 255, 255] ] [1, [255, 255, 255], [255, 255, 255] ]
]), ]),
bluwhtgrngis: colormap([ bluwhtgrngis: colormap([
[0, [6,23,86], [6,25, 84] ], [0, [6,23,86], [6,25, 84] ],
[0.0625, [6,25,84], [6,25, 84] ],//1 [0.0625, [6,25,84], [6,25, 84] ],//1
[0.125, [6,25,84], [6,25, 84] ],//2 [0.125, [6,25,84], [6,25, 84] ],//2
[0.1875, [6,25,84], [6,25, 84] ], [0.1875, [6,25,84], [6,25, 84] ],
[0.25, [6,25,84], [6,25,84] ], [0.25, [6,25,84], [6,25,84] ],
[0.3125, [6,25,84], [9,24, 84] ],//5 [0.3125, [6,25,84], [9,24, 84] ],//5
[0.3438, [9,24, 84], [119,120,162] ],//5 [0.3438, [9,24, 84], [119,120,162] ],//5
[0.375, [119,129,162],[249,250,251] ], //6 [0.375, [119,129,162],[249,250,251] ], //6
[0.406, [249,250,251],[255,255,255] ], //6.5 [0.406, [249,250,251],[255,255,255] ], //6.5
[0.4375, [255,255,255],[255,255,255] ], //7 white [0.4375, [255,255,255],[255,255,255] ], //7 white
[0.50, [255,255,255],[214,205,191] ],//8 [0.50, [255,255,255],[214,205,191] ],//8
[0.52, [214,205,191],[178,175,96] ],//8.2 [0.52, [214,205,191],[178,175,96] ],//8.2
[0.5625, [178,175,96], [151,176,53] ],//9 [0.5625, [178,175,96], [151,176,53] ],//9
[0.593, [151,176,53], [146,188,12] ],//9.5 [0.593, [151,176,53], [146,188,12] ],//9.5
[0.625, [146,188,12], [96,161,1] ], //10 [0.625, [146,188,12], [96,161,1] ], //10
[0.6875, [96,161,1], [30,127,3] ],//11 [0.6875, [96,161,1], [30,127,3] ],//11
[0.75, [30,127,3], [0,99,1] ],//12 [0.75, [30,127,3], [0,99,1] ],//12
[0.8125, [0,99,1], [0,74,1] ],//13 [0.8125, [0,99,1], [0,74,1] ],//13
[0.875, [0,74,1], [0,52, 0] ],//14 [0.875, [0,74,1], [0,52, 0] ],//14
[0.9375, [0,52, 0], [0,34,0] ], //15 [0.9375, [0,52, 0], [0,34,0] ], //15
[0.968, [0,34,0], [68,70,67] ] //16 [0.968, [0,34,0], [68,70,67] ] //16
]), ]),
brntogrn: colormap([ brntogrn: colormap([
[0, [110,12,3], [118,6,1] ], [0, [110,12,3], [118,6,1] ],
[0.0625, [118,6,1], [141,19,6] ], [0.0625, [118,6,1], [141,19,6] ],
[0.125, [141,19,6], [165,35,13] ], [0.125, [141,19,6], [165,35,13] ],
[0.1875, [165,35,13], [177,59,25] ], [0.1875, [165,35,13], [177,59,25] ],
[0.2188, [177,59,25], [192,91,36] ], [0.2188, [177,59,25], [192,91,36] ],
[0.25, [192,91,36], [214, 145, 76] ], [0.25, [192,91,36], [214, 145, 76] ],
[0.3125, [214,145,76], [230,183,134] ], [0.3125, [214,145,76], [230,183,134] ],
[0.375, [230,183,134],[243, 224, 194]], [0.375, [230,183,134],[243, 224, 194]],
[0.4375, [243,224,194],[250,252,229] ], [0.4375, [243,224,194],[250,252,229] ],
[0.50, [250,252,229],[217,235,185] ], [0.50, [250,252,229],[217,235,185] ],
[0.5625, [217,235,185],[184,218,143] ], [0.5625, [217,235,185],[184,218,143] ],
[0.625, [184,218,143],[141,202,89] ], [0.625, [184,218,143],[141,202,89] ],
[0.6875, [141,202,89], [80,176,61] ], [0.6875, [141,202,89], [80,176,61] ],
[0.75, [80,176,61], [0, 147, 32] ], [0.75, [80,176,61], [0, 147, 32] ],
[0.8125, [0,147,32], [1, 122, 22] ], [0.8125, [0,147,32], [1, 122, 22] ],
[0.875, [1,122,22], [0, 114, 19] ], [0.875, [1,122,22], [0, 114, 19] ],
[0.90, [0,114,19], [0,105,18] ], [0.90, [0,114,19], [0,105,18] ],
[0.9375, [0,105,18], [7,70,14] ] [0.9375, [0,105,18], [7,70,14] ]
]), ]),
blutoredjet: colormap([ blutoredjet: colormap([
[0, [0,0,140], [1,1,186] ], [0, [0,0,140], [1,1,186] ],
[0.0625, [1,1,186], [0,1,248] ], [0.0625, [1,1,186], [0,1,248] ],
[0.125, [0,1,248], [0,70,254] ], [0.125, [0,1,248], [0,70,254] ],
[0.1875, [0,70,254], [0,130,255] ], [0.1875, [0,70,254], [0,130,255] ],
[0.25, [0,130,255], [2,160,255] ], [0.25, [0,130,255], [2,160,255] ],
[0.2813, [2,160,255], [0,187,255] ], //inset [0.2813, [2,160,255], [0,187,255] ], //inset
[0.3125, [0,187,255], [6,250,255] ], [0.3125, [0,187,255], [6,250,255] ],
// [0.348, [0,218,255], [8,252,251] ],//inset // [0.348, [0,218,255], [8,252,251] ],//inset
[0.375, [8,252,251], [27,254,228] ], [0.375, [8,252,251], [27,254,228] ],
[0.406, [27,254,228], [70,255,187] ], //insert [0.406, [27,254,228], [70,255,187] ], //insert
[0.4375, [70,255,187], [104,254,151]], [0.4375, [70,255,187], [104,254,151]],
[0.47, [104,254,151],[132,255,19] ],//insert [0.47, [104,254,151],[132,255,19] ],//insert
[0.50, [132,255,19], [195,255,60] ], [0.50, [132,255,19], [195,255,60] ],
[0.5625, [195,255,60], [231,254,25] ], [0.5625, [195,255,60], [231,254,25] ],
[0.5976, [231,254,25], [253,246,1] ],//insert [0.5976, [231,254,25], [253,246,1] ],//insert
[0.625, [253,246,1], [252,210,1] ], //yellow [0.625, [253,246,1], [252,210,1] ], //yellow
[0.657, [252,210,1], [255,183,0] ],//insert [0.657, [252,210,1], [255,183,0] ],//insert
[0.6875, [255,183,0], [255,125,2] ], [0.6875, [255,183,0], [255,125,2] ],
[0.75, [255,125,2], [255,65, 1] ], [0.75, [255,125,2], [255,65, 1] ],
[0.8125, [255,65, 1], [247, 1, 1] ], [0.8125, [255,65, 1], [247, 1, 1] ],
[0.875, [247,1,1], [200, 1, 3] ], [0.875, [247,1,1], [200, 1, 3] ],
[0.9375, [200,1,3], [122, 3, 2] ] [0.9375, [200,1,3], [122, 3, 2] ]
]), ]),
colors16: colormap([ colors16: colormap([
[0, [0,0,0], [0,0,0] ], [0, [0,0,0], [0,0,0] ],
[0.0625, [3,1,172], [3,1,172] ], [0.0625, [3,1,172], [3,1,172] ],
[0.125, [3,1,222], [3,1, 222] ], [0.125, [3,1,222], [3,1, 222] ],
[0.1875, [0,111,255], [0,111,255] ], [0.1875, [0,111,255], [0,111,255] ],
[0.25, [3,172,255], [3,172,255] ], [0.25, [3,172,255], [3,172,255] ],
[0.3125, [1,226,255], [1,226,255] ], [0.3125, [1,226,255], [1,226,255] ],
[0.375, [2,255,0], [2,255,0] ], [0.375, [2,255,0], [2,255,0] ],
[0.4375, [198,254,0], [190,254,0] ], [0.4375, [198,254,0], [190,254,0] ],
[0.50, [252,255,0], [252,255,0] ], [0.50, [252,255,0], [252,255,0] ],
[0.5625, [255,223,3], [255,223,3] ], [0.5625, [255,223,3], [255,223,3] ],
[0.625, [255,143,3], [255,143,3] ], [0.625, [255,143,3], [255,143,3] ],
[0.6875, [255,95,3], [255,95,3] ], [0.6875, [255,95,3], [255,95,3] ],
[0.75, [242,0,1], [242,0,1] ], [0.75, [242,0,1], [242,0,1] ],
[0.8125, [245,0,170], [245,0,170] ], [0.8125, [245,0,170], [245,0,170] ],
[0.875, [223,180,225], [223,180,225] ], [0.875, [223,180,225], [223,180,225] ],
[0.9375, [255,255,255], [255,255, 255]] [0.9375, [255,255,255], [255,255, 255]]
]), ]),
default: colormap([ default: colormap([
[0, [45,1,121], [25,1,137] ], [0, [45,1,121], [25,1,137] ],
[0.125, [25,1,137], [0,6,156] ], [0.125, [25,1,137], [0,6,156] ],
[0.1875, [0,6,156], [7,41,172] ], [0.1875, [0,6,156], [7,41,172] ],
[0.25, [7,41,172], [22,84,187] ], [0.25, [7,41,172], [22,84,187] ],
[0.3125, [22,84,187], [25,125,194] ], [0.3125, [22,84,187], [25,125,194] ],
[0.375, [25,125,194], [26,177,197] ], [0.375, [25,125,194], [26,177,197] ],
[0.4375, [26,177,197], [23,199,193] ], [0.4375, [26,177,197], [23,199,193] ],
[0.47, [23,199,193], [25, 200,170] ], [0.47, [23,199,193], [25, 200,170] ],
[0.50, [25, 200,170], [21,209,27] ], [0.50, [25, 200,170], [21,209,27] ],
[0.5625, [21,209,27], [108,215,18] ], [0.5625, [21,209,27], [108,215,18] ],
[0.625, [108,215,18], [166,218,19] ], [0.625, [108,215,18], [166,218,19] ],
[0.6875, [166,218,19], [206,221,20] ], [0.6875, [166,218,19], [206,221,20] ],
[0.75, [206,221,20], [222,213,19 ] ], [0.75, [206,221,20], [222,213,19 ] ],
[0.7813, [222,213,19], [222, 191, 19]], [0.7813, [222,213,19], [222, 191, 19]],
[0.8125, [222, 191, 19], [227,133,17] ], [0.8125, [222, 191, 19], [227,133,17] ],
[0.875, [227,133,17], [231,83,16] ], [0.875, [227,133,17], [231,83,16] ],
[0.9375, [231,83,16], [220,61,48] ] [0.9375, [231,83,16], [220,61,48] ]
]), ]),
fastie: colormap([ fastie: colormap([
[0, [255, 255, 255], [0, 0, 0] ], [0, [255, 255, 255], [0, 0, 0] ],
[0.167, [0, 0, 0], [255, 255, 255] ], [0.167, [0, 0, 0], [255, 255, 255] ],
[0.33, [255, 255, 255], [0, 0, 0] ], [0.33, [255, 255, 255], [0, 0, 0] ],
[0.5, [0, 0, 0], [140, 140, 255] ], [0.5, [0, 0, 0], [140, 140, 255] ],
[0.55, [140, 140, 255], [0, 255, 0] ], [0.55, [140, 140, 255], [0, 255, 0] ],
[0.63, [0, 255, 0], [255, 255, 0] ], [0.63, [0, 255, 0], [255, 255, 0] ],
[0.75, [255, 255, 0], [255, 0, 0] ], [0.75, [255, 255, 0], [255, 0, 0] ],
[0.95, [255, 0, 0], [255, 0, 255] ] [0.95, [255, 0, 0], [255, 0, 255] ]
]), ]),
stretched: colormap([ stretched: colormap([
[0, [0, 0, 255], [0, 0, 255] ], [0, [0, 0, 255], [0, 0, 255] ],
[0.1, [0, 0, 255], [38, 195, 195] ], [0.1, [0, 0, 255], [38, 195, 195] ],
[0.5, [0, 150, 0], [255, 255, 0] ], [0.5, [0, 150, 0], [255, 255, 0] ],
[0.7, [255, 255, 0], [255, 50, 50] ], [0.7, [255, 255, 0], [255, 50, 50] ],
[0.9, [255, 50, 50], [255, 50, 50] ] [0.9, [255, 50, 50], [255, 50, 50] ]
]) ])
} };

View File

@@ -38,5 +38,5 @@ module.exports = function Colormap(options, UI) {
draw: draw, draw: draw,
output: output, output: output,
UI: UI UI: UI
} };
} };

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -1,47 +1,47 @@
var _ = require('lodash'); var _ = require('lodash');
module.exports = exports = function(pixels, contrast) { module.exports = exports = function(pixels, contrast) {
let oldpix = _.cloneDeep(pixels); let oldpix = _.cloneDeep(pixels);
contrast = Number(contrast) contrast = Number(contrast);
if (contrast < -100) contrast = -100; if (contrast < -100) contrast = -100;
if (contrast > 100) contrast = 100; if (contrast > 100) contrast = 100;
contrast = (100.0 + contrast) / 100.0; contrast = (100.0 + contrast) / 100.0;
contrast *= contrast; contrast *= contrast;
for (let i = 0; i < pixels.shape[0]; i++) { for (let i = 0; i < pixels.shape[0]; i++) {
for (let j = 0; j < pixels.shape[1]; j++) { for (let j = 0; j < pixels.shape[1]; j++) {
var r = oldpix.get(i, j, 0) / 255.0; var r = oldpix.get(i, j, 0) / 255.0;
r -= 0.5; r -= 0.5;
r *= contrast; r *= contrast;
r += 0.5; r += 0.5;
r *= 255; r *= 255;
if (r < 0) r = 0; if (r < 0) r = 0;
if (r > 255) r = 255; if (r > 255) r = 255;
var g = oldpix.get(i, j, 1) / 255.0; var g = oldpix.get(i, j, 1) / 255.0;
g -= 0.5; g -= 0.5;
g *= contrast; g *= contrast;
g += 0.5; g += 0.5;
g *= 255; g *= 255;
if (g < 0) g = 0; if (g < 0) g = 0;
if (g > 255) g = 255; if (g > 255) g = 255;
var b = oldpix.get(i, j, 2) / 255.0; var b = oldpix.get(i, j, 2) / 255.0;
b -= 0.5; b -= 0.5;
b *= contrast; b *= contrast;
b += 0.5; b += 0.5;
b *= 255; b *= 255;
if (b < 0) b = 0; if (b < 0) b = 0;
if (b > 255) b = 255; if (b > 255) b = 255;
pixels.set(i, j, 0, r); pixels.set(i, j, 0, r);
pixels.set(i, j, 1, g); pixels.set(i, j, 1, g);
pixels.set(i, j, 2, b); pixels.set(i, j, 2, b);
}
} }
return pixels; }
} return pixels;
};

View File

@@ -4,42 +4,42 @@
module.exports = function Contrast(options, UI) { module.exports = function Contrast(options, UI) {
var defaults = require('./../../util/getDefaults.js')(require('./info.json')); var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
options.contrast = options.contrast || defaults.contrast; options.contrast = options.contrast || defaults.contrast;
var output; var output;
function draw(input, callback, progressObj) { function draw(input, callback, progressObj) {
progressObj.stop(true); progressObj.stop(true);
progressObj.overrideFlag = true; progressObj.overrideFlag = true;
var step = this; var step = this;
function extraManipulation(pixels) { function extraManipulation(pixels) {
pixels = require('./Contrast')(pixels, options.contrast) pixels = require('./Contrast')(pixels, options.contrast);
return pixels return pixels;
} }
function output(image, datauri, mimetype) { function output(image, datauri, mimetype) {
// This output is accessible by Image Sequencer // This output is accessible by Image Sequencer
step.output = { src: datauri, format: mimetype }; step.output = { src: datauri, format: mimetype };
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
extraManipulation: extraManipulation,
format: input.format,
image: options.image,
callback: callback
});
} }
return {
options: options, return require('../_nomodule/PixelManipulation.js')(input, {
draw: draw, output: output,
output: output, extraManipulation: extraManipulation,
UI: UI format: input.format,
} image: options.image,
} callback: callback
});
}
return {
options: options,
draw: draw,
output: output,
UI: UI
};
};

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -5,42 +5,42 @@ module.exports = exports = function(pixels, constantFactor, kernelValues, texMod
r: [], r: [],
g: [], g: [],
b: [], b: [],
} };
for (let y = 0; y < pixels.shape[1]; y++){ for (let y = 0; y < pixels.shape[1]; y++){
pixs.r.push([]) pixs.r.push([]);
pixs.g.push([]) pixs.g.push([]);
pixs.b.push([]) pixs.b.push([]);
for (let x = 0; x < pixels.shape[0]; x++){ for (let x = 0; x < pixels.shape[0]; x++){
pixs.r[y].push(pixels.get(x, y, 0)) pixs.r[y].push(pixels.get(x, y, 0));
pixs.g[y].push(pixels.get(x, y, 1)) pixs.g[y].push(pixels.get(x, y, 1));
pixs.b[y].push(pixels.get(x, y, 2)) pixs.b[y].push(pixels.get(x, y, 2));
} }
} }
const convolve = require('../_nomodule/gpuUtils').convolve; const convolve = require('../_nomodule/gpuUtils').convolve;
const conPix = convolve([pixs.r, pixs.g, pixs.b], kernel, (pixels.shape[0] * pixels.shape[1]) < 400000 ? true : false) const conPix = convolve([pixs.r, pixs.g, pixs.b], kernel, (pixels.shape[0] * pixels.shape[1]) < 400000 ? true : false);
for (let y = 0; y < pixels.shape[1]; y++){ for (let y = 0; y < pixels.shape[1]; y++){
for (let x = 0; x < pixels.shape[0]; x++){ for (let x = 0; x < pixels.shape[0]; x++){
pixels.set(x, y, 0, Math.max(0, Math.min(conPix[0][y][x], 255))) pixels.set(x, y, 0, Math.max(0, Math.min(conPix[0][y][x], 255)));
pixels.set(x, y, 1, Math.max(0, Math.min(conPix[1][y][x], 255))) pixels.set(x, y, 1, Math.max(0, Math.min(conPix[1][y][x], 255)));
pixels.set(x, y, 2, Math.max(0, Math.min(conPix[2][y][x], 255))) pixels.set(x, y, 2, Math.max(0, Math.min(conPix[2][y][x], 255)));
} }
} }
return pixels; return pixels;
} };
function kernelGenerator(constantFactor, kernelValues) { function kernelGenerator(constantFactor, kernelValues) {
kernelValues = kernelValues.split(" "); kernelValues = kernelValues.split(' ');
for (i = 0; i < 9; i++) { for (i = 0; i < 9; i++) {
kernelValues[i] = Number(kernelValues[i]) * constantFactor; kernelValues[i] = Number(kernelValues[i]) * constantFactor;
} }
let k = 0; let k = 0;
let arr = []; let arr = [];
for (y = 0; y < 3; y++) { for (y = 0; y < 3; y++) {
arr.push([]) arr.push([]);
for (x = 0; x < 3; x++) { for (x = 0; x < 3; x++) {
arr[y].push(kernelValues[k]); arr[y].push(kernelValues[k]);
k += 1; k += 1;

View File

@@ -1,43 +1,43 @@
module.exports = function Convolution(options, UI) { module.exports = function Convolution(options, UI) {
var defaults = require('./../../util/getDefaults.js')(require('./info.json')); var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
options.kernelValues = options.kernelValues || defaults.kernelValues; options.kernelValues = options.kernelValues || defaults.kernelValues;
options.constantFactor = options.constantFactor || defaults.constantFactor; options.constantFactor = options.constantFactor || defaults.constantFactor;
options.texMode = options.texMode || defaults.texMode; options.texMode = options.texMode || defaults.texMode;
var output; var output;
function draw(input, callback, progressObj) { function draw(input, callback, progressObj) {
progressObj.stop(true); progressObj.stop(true);
progressObj.overrideFlag = true; progressObj.overrideFlag = true;
var step = this; var step = this;
function extraManipulation(pixels) { function extraManipulation(pixels) {
pixels = require('./Convolution')(pixels, options.constantFactor, options.kernelValues, options.texMode); pixels = require('./Convolution')(pixels, options.constantFactor, options.kernelValues, options.texMode);
return pixels; return pixels;
} }
function output(image, datauri, mimetype) { function output(image, datauri, mimetype) {
step.output = { src: datauri, format: mimetype }; step.output = { src: datauri, format: mimetype };
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
extraManipulation: extraManipulation,
format: input.format,
image: options.image,
callback: callback
});
} }
return {
options: options, return require('../_nomodule/PixelManipulation.js')(input, {
draw: draw, output: output,
output: output, extraManipulation: extraManipulation,
UI: UI format: input.format,
} image: options.image,
} callback: callback
});
}
return {
options: options,
draw: draw,
output: output,
UI: UI
};
};

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -1,7 +1,7 @@
module.exports = function Crop(input,options,callback) { module.exports = function Crop(input,options,callback) {
var defaults = require('./../../util/getDefaults.js')(require('./info.json')); var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
var getPixels = require('get-pixels'), var getPixels = require('get-pixels'),
savePixels = require('save-pixels'); savePixels = require('save-pixels');
options.x = parseInt(options.x) || defaults.x; options.x = parseInt(options.x) || defaults.x;
options.y = parseInt(options.y) || defaults.y; options.y = parseInt(options.y) || defaults.y;
@@ -17,18 +17,18 @@ module.exports = function Crop(input,options,callback) {
var iw = pixels.shape[0]; //Width of Original Image var iw = pixels.shape[0]; //Width of Original Image
var ih = pixels.shape[1]; //Height of Original Image var ih = pixels.shape[1]; //Height of Original Image
var backgroundArray = []; var backgroundArray = [];
backgroundColor = options.backgroundColor.split(" "); backgroundColor = options.backgroundColor.split(' ');
for(var i = 0; i < w ; i++){ for(var i = 0; i < w ; i++){
backgroundArray = backgroundArray.concat([backgroundColor[0],backgroundColor[1],backgroundColor[2],backgroundColor[3]]); backgroundArray = backgroundArray.concat([backgroundColor[0],backgroundColor[1],backgroundColor[2],backgroundColor[3]]);
} }
// var newarray = new Uint8Array(4*w*h); // var newarray = new Uint8Array(4*w*h);
var array = [] var array = [];
for (var n = oy; n < oy + h; n++) { for (var n = oy; n < oy + h; n++) {
var offsetValue = 4*w*n; var offsetValue = 4*w*n;
if(n<ih){ if(n<ih){
var start = n*4*iw + ox*4; var start = n*4*iw + ox*4;
var end = n*4*iw + ox*4 + 4*w; var end = n*4*iw + ox*4 + 4*w;
var pushArray = Array.from(pixels.data.slice(start, end )) var pushArray = Array.from(pixels.data.slice(start, end ));
array.push.apply(array,pushArray); array.push.apply(array,pushArray);
} else { } else {
array.push.apply(array,backgroundArray); array.push.apply(array,backgroundArray);

View File

@@ -51,7 +51,7 @@ module.exports = function CropModule(options, UI) {
step.output = { step.output = {
src: out, src: out,
format: format format: format
} };
// This output is accessible to the UI // This output is accessible to the UI
options.step.output = out; options.step.output = out;
@@ -81,5 +81,5 @@ module.exports = function CropModule(options, UI) {
draw: draw, draw: draw,
output: output, output: output,
UI: UI UI: UI
} };
} };

View File

@@ -2,7 +2,7 @@
module.exports = function CropModuleUi(step, ui) { module.exports = function CropModuleUi(step, ui) {
let inputWidth = 0, let inputWidth = 0,
inputHeight = 0; inputHeight = 0;
// We don't have input image dimensions at the // We don't have input image dimensions at the
// time of setting up the UI; that comes when draw() is triggered. // time of setting up the UI; that comes when draw() is triggered.
@@ -10,7 +10,7 @@ module.exports = function CropModuleUi(step, ui) {
// TODO: link this to an event rather than an explicit call in Module.js // TODO: link this to an event rather than an explicit call in Module.js
function setup() { function setup() {
let x = 0, let x = 0,
y = 0; y = 0;
// display original uncropped input image on initial setup // display original uncropped input image on initial setup
showOriginal(); showOriginal();
@@ -42,21 +42,21 @@ module.exports = function CropModuleUi(step, ui) {
converted[2], converted[2],
converted[3] converted[3]
); );
$($(imgEl()).parents()[3]).find("input").trigger("change") $($(imgEl()).parents()[3]).find('input').trigger('change');
} }
}); });
} }
function convertToNatural(_x, _y, _width, _height) { function convertToNatural(_x, _y, _width, _height) {
let displayWidth = $(imgEl()).width(), let displayWidth = $(imgEl()).width(),
displayHeight = $(imgEl()).height(); displayHeight = $(imgEl()).height();
// return in same order [ x, y, width, height ]: // return in same order [ x, y, width, height ]:
return [ return [
Math.floor(( _x / displayWidth ) * inputWidth), Math.floor(( _x / displayWidth ) * inputWidth),
Math.floor(( _y / displayHeight ) * inputHeight), Math.floor(( _y / displayHeight ) * inputHeight),
Math.floor(( _width / displayWidth ) * inputWidth), Math.floor(( _width / displayWidth ) * inputWidth),
Math.floor(( _height / displayHeight ) * inputHeight) Math.floor(( _height / displayHeight ) * inputHeight)
] ];
} }
function remove() { function remove() {
@@ -78,7 +78,7 @@ module.exports = function CropModuleUi(step, ui) {
} }
function setOptions(x1, y1, width, height) { function setOptions(x1, y1, width, height) {
let options = $($(imgEl()).parents()[3]).find("input"); let options = $($(imgEl()).parents()[3]).find('input');
options[0].value = x1; options[0].value = x1;
options[1].value = y1; options[1].value = y1;
options[2].value = width; options[2].value = width;
@@ -94,5 +94,5 @@ module.exports = function CropModuleUi(step, ui) {
setup: setup, setup: setup,
remove: remove, remove: remove,
hide: hide hide: hide
} };
} };

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -25,7 +25,7 @@ module.exports = function DoNothing(options,UI) {
// Tell Image Sequencer that this step is complete // Tell Image Sequencer that this step is complete
options.step.qrval = (decoded)?decoded.data:"undefined"; options.step.qrval = (decoded)?decoded.data:'undefined';
}); });
function output(image, datauri, mimetype){ function output(image, datauri, mimetype){
@@ -49,5 +49,5 @@ module.exports = function DoNothing(options,UI) {
draw: draw, draw: draw,
output: output, output: output,
UI: UI UI: UI
} };
} };

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -28,11 +28,11 @@ module.exports = function Dither(pixels, type) {
for (let currentPixel = 0; currentPixel <= imageDataLength; currentPixel += 4) { for (let currentPixel = 0; currentPixel <= imageDataLength; currentPixel += 4) {
if (type === "none") { if (type === 'none') {
// No dithering // No dithering
pixels.data[currentPixel] = pixels.data[currentPixel] < threshold ? 0 : 255; pixels.data[currentPixel] = pixels.data[currentPixel] < threshold ? 0 : 255;
} else if (type === "bayer") { } else if (type === 'bayer') {
// 4x4 Bayer ordered dithering algorithm // 4x4 Bayer ordered dithering algorithm
let x = currentPixel / 4 % w; let x = currentPixel / 4 % w;
@@ -40,7 +40,7 @@ module.exports = function Dither(pixels, type) {
let map = Math.floor((pixels.data[currentPixel] + bayerThresholdMap[x % 4][y % 4]) / 2); let map = Math.floor((pixels.data[currentPixel] + bayerThresholdMap[x % 4][y % 4]) / 2);
pixels.data[currentPixel] = (map < threshold) ? 0 : 255; pixels.data[currentPixel] = (map < threshold) ? 0 : 255;
} else if (type === "floydsteinberg") { } else if (type === 'floydsteinberg') {
// FloydSteinberg dithering algorithm // FloydSteinberg dithering algorithm
newPixel = pixels.data[currentPixel] < 129 ? 0 : 255; newPixel = pixels.data[currentPixel] < 129 ? 0 : 255;
@@ -73,4 +73,4 @@ module.exports = function Dither(pixels, type) {
} }
return pixels; return pixels;
} };

View File

@@ -1,38 +1,38 @@
module.exports = function Dither(options, UI){ module.exports = function Dither(options, UI){
var defaults = require('./../../util/getDefaults.js')(require('./info.json')); var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
var output; var output;
function draw(input,callback,progressObj){ function draw(input,callback,progressObj){
progressObj.stop(true); progressObj.stop(true);
progressObj.overrideFlag = true; progressObj.overrideFlag = true;
var step = this; var step = this;
options.dither = options.dither || defaults.dither; options.dither = options.dither || defaults.dither;
function extraManipulation(pixels) { function extraManipulation(pixels) {
pixels = require('./Dither')(pixels, options.dither) pixels = require('./Dither')(pixels, options.dither);
return pixels return pixels;
}
function output(image, datauri, mimetype){
// This output is accessible by Image Sequencer
step.output = { src: datauri, format: mimetype };
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
extraManipulation: extraManipulation,
format: input.format,
image: options.image,
callback: callback
});
} }
return {
options: options, function output(image, datauri, mimetype){
draw: draw, // This output is accessible by Image Sequencer
output: output, step.output = { src: datauri, format: mimetype };
UI: UI
} }
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
extraManipulation: extraManipulation,
format: input.format,
image: options.image,
callback: callback
});
}
return {
options: options,
draw: draw,
output: output,
UI: UI
};
};

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -1,9 +1,9 @@
module.exports = exports = function(pixels, options){ module.exports = exports = function(pixels, options){
var defaults = require('./../../util/getDefaults.js')(require('./info.json')); var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
options.startingX = options.startingX || defaults.startingX; options.startingX = options.startingX || defaults.startingX;
options.startingY = options.startingY || defaults.startingY; options.startingY = options.startingY || defaults.startingY;
var ox = Number(options.startingX), var ox = Number(options.startingX),
oy = Number(options.startingY), oy = Number(options.startingY),
iw = pixels.shape[0], iw = pixels.shape[0],
ih = pixels.shape[1], ih = pixels.shape[1],
@@ -11,7 +11,7 @@ module.exports = exports = function(pixels, options){
ex = options.endX = Number(options.endX) - thickness || iw - 1, ex = options.endX = Number(options.endX) - thickness || iw - 1,
ey = options.endY = Number(options.endY) -thickness || ih - 1, ey = options.endY = Number(options.endY) -thickness || ih - 1,
color = options.color || defaults.color; color = options.color || defaults.color;
color = color.split(" "); color = color.split(' ');
var drawSide = function(startX, startY, endX, endY){ var drawSide = function(startX, startY, endX, endY){
for (var n=startX; n <= endX+thickness; n++){ for (var n=startX; n <= endX+thickness; n++){
@@ -22,11 +22,11 @@ module.exports = exports = function(pixels, options){
pixels.set(n, k, 3, color[3]); pixels.set(n, k, 3, color[3]);
} }
} }
} };
drawSide(ox, oy, ox, ey); // Left drawSide(ox, oy, ox, ey); // Left
drawSide(ex, oy, ex, ey); // Right drawSide(ex, oy, ex, ey); // Right
drawSide(ox, oy, ex, oy); // Top drawSide(ox, oy, ex, oy); // Top
drawSide(ox, ey, ex, ey); // Bottom drawSide(ox, ey, ex, ey); // Bottom
return pixels; return pixels;
} };

View File

@@ -1,44 +1,44 @@
module.exports = function DrawRectangle(options, UI) { module.exports = function DrawRectangle(options, UI) {
var output; var output;
function draw(input, callback, progressObj) { function draw(input, callback, progressObj) {
progressObj.stop(true); progressObj.stop(true);
progressObj.overrideFlag = true; progressObj.overrideFlag = true;
var step = this; var step = this;
function changePixel(r, g, b, a) { function changePixel(r, g, b, a) {
return [r, g, b, a] return [r, g, b, a];
} }
function extraManipulation(pixels) { function extraManipulation(pixels) {
pixels = require('./DrawRectangle')(pixels, options) pixels = require('./DrawRectangle')(pixels, options);
return pixels return pixels;
} }
function output(image, datauri, mimetype) { function output(image, datauri, mimetype) {
step.output = { src: datauri, format: mimetype }; step.output = { src: datauri, format: mimetype };
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
changePixel: changePixel,
extraManipulation: extraManipulation,
format: input.format,
image: options.image,
callback: callback
});
} }
return {
options: options, return require('../_nomodule/PixelManipulation.js')(input, {
draw: draw, output: output,
output: output, changePixel: changePixel,
UI: UI extraManipulation: extraManipulation,
} format: input.format,
} image: options.image,
callback: callback
});
}
return {
options: options,
draw: draw,
output: output,
UI: UI
};
};

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -11,10 +11,10 @@ module.exports = function Dynamic(options,UI) {
var step = this; var step = this;
// start with monochrome, but if options.red, options.green, and options.blue are set, accept them too // start with monochrome, but if options.red, options.green, and options.blue are set, accept them too
options.monochrome = options.monochrome || "(R+G+B)/3"; options.monochrome = options.monochrome || '(R+G+B)/3';
function generator(expression) { function generator(expression) {
var func = 'f = function (r, g, b, a) { var R = r, G = g, B = b, A = a;' var func = 'f = function (r, g, b, a) { var R = r, G = g, B = b, A = a;';
func = func + 'return '; func = func + 'return ';
func = func + expression + '}'; func = func + expression + '}';
var f; var f;
@@ -26,7 +26,7 @@ module.exports = function Dynamic(options,UI) {
channels.forEach(function(channel) { channels.forEach(function(channel) {
if (options.hasOwnProperty(channel)) options[channel + '_function'] = generator(options[channel]); if (options.hasOwnProperty(channel)) options[channel + '_function'] = generator(options[channel]);
else if (channel === 'alpha') options['alpha_function'] = function() { return 255; } else if (channel === 'alpha') options['alpha_function'] = function() { return 255; };
else options[channel + '_function'] = generator(options.monochrome); else options[channel + '_function'] = generator(options.monochrome);
}); });
@@ -47,11 +47,11 @@ module.exports = function Dynamic(options,UI) {
/* Functions to get the neighbouring pixel by position (x,y) */ /* Functions to get the neighbouring pixel by position (x,y) */
function getNeighbourPixel(pixels,curX,curY,distX,distY){ function getNeighbourPixel(pixels,curX,curY,distX,distY){
return [ return [
pixels.get(curX+distX,curY+distY,0) pixels.get(curX+distX,curY+distY,0)
,pixels.get(curX+distX,curY+distY,1) ,pixels.get(curX+distX,curY+distY,1)
,pixels.get(curX+distX,curY+distY,2) ,pixels.get(curX+distX,curY+distY,2)
,pixels.get(curX+distX,curY+distY,3) ,pixels.get(curX+distX,curY+distY,3)
] ];
} }
// via P5js: https://github.com/processing/p5.js/blob/2920492842aae9a8bf1a779916893ac19d65cd38/src/math/calculation.js#L461-L472 // via P5js: https://github.com/processing/p5.js/blob/2920492842aae9a8bf1a779916893ac19d65cd38/src/math/calculation.js#L461-L472
@@ -63,13 +63,13 @@ module.exports = function Dynamic(options,UI) {
// also via P5js: https://github.com/processing/p5.js/blob/2920492842aae9a8bf1a779916893ac19d65cd38/src/math/calculation.js#L116-L119 // also via P5js: https://github.com/processing/p5.js/blob/2920492842aae9a8bf1a779916893ac19d65cd38/src/math/calculation.js#L116-L119
function constrain(n, low, high) { function constrain(n, low, high) {
return Math.max(Math.min(n, high), low); return Math.max(Math.min(n, high), low);
}; }
if (start2 < stop2) { if (start2 < stop2) {
return constrain(newval, start2, stop2); return constrain(newval, start2, stop2);
} else { } else {
return constrain(newval, stop2, start2); return constrain(newval, stop2, start2);
} }
}; }
function output(image,datauri,mimetype){ function output(image,datauri,mimetype){
@@ -95,5 +95,5 @@ module.exports = function Dynamic(options,UI) {
draw: draw, draw: draw,
output: output, output: output,
UI: UI UI: UI
} };
} };

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -1,14 +1,14 @@
// Define kernels for the sobel filter // Define kernels for the sobel filter
const kernelx = [ const kernelx = [
[-1, 0, 1], [-1, 0, 1],
[-2, 0, 2], [-2, 0, 2],
[-1, 0, 1] [-1, 0, 1]
], ],
kernely = [ kernely = [
[-1,-2,-1], [-1,-2,-1],
[ 0, 0, 0], [ 0, 0, 0],
[ 1, 2, 1] [ 1, 2, 1]
]; ];
let pixelsToBeSupressed = []; let pixelsToBeSupressed = [];
@@ -39,7 +39,7 @@ module.exports = function(pixels, highThresholdRatio, lowThresholdRatio, useHyst
pixelsToBeSupressed.forEach(pixel => supress(pixels, pixel)); pixelsToBeSupressed.forEach(pixel => supress(pixels, pixel));
return pixels; return pixels;
} };
function supress(pixels, pixel) { function supress(pixels, pixel) {
@@ -84,7 +84,7 @@ function sobelFilter(pixels, x, y) {
return { return {
pixel: [val, val, val, grad], pixel: [val, val, val, grad],
angle: angle angle: angle
} };
} }
function categorizeAngle(angle){ function categorizeAngle(angle){
@@ -108,8 +108,8 @@ function isOutOfBounds(pixels, x, y){
const removeElem = (arr = [], elem) => { const removeElem = (arr = [], elem) => {
return arr = arr.filter((arrelem) => { return arr = arr.filter((arrelem) => {
return arrelem !== elem; return arrelem !== elem;
}) });
} };
// Non Maximum Supression without interpolation // Non Maximum Supression without interpolation
function nonMaxSupress(pixels, grads, angles) { function nonMaxSupress(pixels, grads, angles) {
@@ -122,29 +122,29 @@ function nonMaxSupress(pixels, grads, angles) {
if (!isOutOfBounds(pixels, x - 1, y - 1) && !isOutOfBounds(pixels, x+1, y+1)){ if (!isOutOfBounds(pixels, x - 1, y - 1) && !isOutOfBounds(pixels, x+1, y+1)){
switch (angleCategory){ switch (angleCategory){
case 1: case 1:
if (!((grads[x][y] >= grads[x][y + 1]) && (grads[x][y] >= grads[x][y - 1]))) { if (!((grads[x][y] >= grads[x][y + 1]) && (grads[x][y] >= grads[x][y - 1]))) {
pixelsToBeSupressed.push([x, y]); pixelsToBeSupressed.push([x, y]);
} }
break; break;
case 2: case 2:
if (!((grads[x][y] >= grads[x + 1][y + 1]) && (grads[x][y] >= grads[x - 1][y - 1]))){ if (!((grads[x][y] >= grads[x + 1][y + 1]) && (grads[x][y] >= grads[x - 1][y - 1]))){
pixelsToBeSupressed.push([x, y]); pixelsToBeSupressed.push([x, y]);
} }
break; break;
case 3: case 3:
if (!((grads[x][y] >= grads[x + 1][y]) && (grads[x][y] >= grads[x - 1][y]))) { if (!((grads[x][y] >= grads[x + 1][y]) && (grads[x][y] >= grads[x - 1][y]))) {
pixelsToBeSupressed.push([x, y]); pixelsToBeSupressed.push([x, y]);
} }
break; break;
case 4: case 4:
if (!((grads[x][y] >= grads[x + 1][y - 1]) && (grads[x][y] >= grads[x - 1][y + 1]))) { if (!((grads[x][y] >= grads[x + 1][y - 1]) && (grads[x][y] >= grads[x - 1][y + 1]))) {
pixelsToBeSupressed.push([x, y]); pixelsToBeSupressed.push([x, y]);
} }
break; break;
} }
} }
} }
@@ -154,7 +154,7 @@ function nonMaxSupress(pixels, grads, angles) {
var convertToDegrees = radians => (radians * 180) / Math.PI; var convertToDegrees = radians => (radians * 180) / Math.PI;
// Finds the max value in a 2d array like grads // Finds the max value in a 2d array like grads
var findMaxInMatrix = arr => Math.max(...arr.map(el => el.map(val => !!val ? val : 0)).map(el => Math.max(...el))); var findMaxInMatrix = arr => Math.max(...arr.map(el => el.map(val => val ? val : 0)).map(el => Math.max(...el)));
// Applies the double threshold to the image // Applies the double threshold to the image
function doubleThreshold(pixels, highThresholdRatio, lowThresholdRatio, grads, strongEdgePixels, weakEdgePixels) { function doubleThreshold(pixels, highThresholdRatio, lowThresholdRatio, grads, strongEdgePixels, weakEdgePixels) {
@@ -198,5 +198,5 @@ function hysteresis(strongEdgePixels, weakEdgePixels){
else if(weakEdgePixels.includes([x, y-1])) { else if(weakEdgePixels.includes([x, y-1])) {
removeElem(weakEdgePixels, [x, y-1]); removeElem(weakEdgePixels, [x, y-1]);
} }
}) });
} }

View File

@@ -24,7 +24,7 @@ module.exports = function edgeDetect(options, UI) {
return internalSequencer.loadImage(input.src, function () { return internalSequencer.loadImage(input.src, function () {
internalSequencer.importJSON([{ 'name': 'blur', 'options': {blur: options.blur} }]); internalSequencer.importJSON([{ 'name': 'blur', 'options': {blur: options.blur} }]);
return internalSequencer.run(function onCallback(internalOutput) { return internalSequencer.run(function onCallback(internalOutput) {
require('get-pixels')(internalOutput, function(err, blurPixels){ require('get-pixels')(internalOutput, function(err, blurPixels){
if (err){ if (err){
return; return;
} }
@@ -51,7 +51,7 @@ module.exports = function edgeDetect(options, UI) {
inBrowser: options.inBrowser, inBrowser: options.inBrowser,
callback: callback callback: callback
}); });
}) });
}); });
}); });
} }
@@ -61,5 +61,5 @@ module.exports = function edgeDetect(options, UI) {
draw: draw, draw: draw,
output: output, output: output,
UI: UI UI: UI
} };
} };

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -4,47 +4,47 @@
module.exports = function Exposure(options,UI){ module.exports = function Exposure(options,UI){
var defaults = require('./../../util/getDefaults.js')(require('./info.json')); var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
var output; var output;
function draw(input,callback,progressObj){ function draw(input,callback,progressObj){
options.exposure = options.exposure || defaults.exposure options.exposure = options.exposure || defaults.exposure;
var exposure = Math.pow(2, options.exposure); var exposure = Math.pow(2, options.exposure);
progressObj.stop(true); progressObj.stop(true);
progressObj.overrideFlag = true; progressObj.overrideFlag = true;
var step = this; var step = this;
function changePixel(r, g, b, a){ function changePixel(r, g, b, a){
r = Math.min(255, r*exposure) r = Math.min(255, r*exposure);
g = Math.min(255, g*exposure) g = Math.min(255, g*exposure);
b = Math.min(255, b*exposure) b = Math.min(255, b*exposure);
return [r, g, b, a] return [r, g, b, a];
} }
function output(image,datauri,mimetype){ function output(image,datauri,mimetype){
// This output is accessible by Image Sequencer // This output is accessible by Image Sequencer
step.output = {src:datauri,format:mimetype}; step.output = {src:datauri,format:mimetype};
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
changePixel: changePixel,
format: input.format,
image: options.image,
inBrowser: options.inBrowser,
callback: callback
});
} }
return {
options: options, return require('../_nomodule/PixelManipulation.js')(input, {
draw: draw, output: output,
output: output, changePixel: changePixel,
UI: UI format: input.format,
} image: options.image,
} inBrowser: options.inBrowser,
callback: callback
});
}
return {
options: options,
draw: draw,
output: output,
UI: UI
};
};

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -18,14 +18,14 @@ module.exports = function DoNothing(options, UI) {
// Create a canvas, if it doesn't already exist. // Create a canvas, if it doesn't already exist.
if (!document.querySelector('#image-sequencer-canvas')) { if (!document.querySelector('#image-sequencer-canvas')) {
var canvas = document.createElement('canvas'); var canvas = document.createElement('canvas');
canvas.style.display = "none"; canvas.style.display = 'none';
canvas.setAttribute('id', 'image-sequencer-canvas'); canvas.setAttribute('id', 'image-sequencer-canvas');
document.body.append(canvas); document.body.append(canvas);
} }
else var canvas = document.querySelector('#image-sequencer-canvas'); else var canvas = document.querySelector('#image-sequencer-canvas');
distorter = FisheyeGl({ distorter = FisheyeGl({
selector: "#image-sequencer-canvas" selector: '#image-sequencer-canvas'
}); });
// Parse the inputs // Parse the inputs
@@ -65,5 +65,5 @@ module.exports = function DoNothing(options, UI) {
draw: draw, draw: draw,
output: output, output: output,
UI: UI UI: UI
} };
} };

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -4,7 +4,7 @@
module.exports = function FlipImage(options, UI) { module.exports = function FlipImage(options, UI) {
options.Axis = options.Axis || require('./info.json').inputs.Axis.default; options.Axis = options.Axis || require('./info.json').inputs.Axis.default;
var output, var output,
getPixels = require('get-pixels'); getPixels = require('get-pixels');
function draw(input, callback, progressObj) { function draw(input, callback, progressObj) {
@@ -38,7 +38,7 @@ module.exports = function FlipImage(options, UI) {
inBrowser: options.inBrowser, inBrowser: options.inBrowser,
callback: callback callback: callback
}); });
}) });
} }
@@ -47,5 +47,5 @@ module.exports = function FlipImage(options, UI) {
draw: draw, draw: draw,
output: output, output: output,
UI: UI UI: UI
} };
} };

View File

@@ -1,12 +1,12 @@
module.exports = function flipImage(oldPixels, pixels, axis) { module.exports = function flipImage(oldPixels, pixels, axis) {
var width = oldPixels.shape[0], var width = oldPixels.shape[0],
height = oldPixels.shape[1]; height = oldPixels.shape[1];
function copyPixel(x1, y1, x2, y2){ function copyPixel(x1, y1, x2, y2){
pixels.set(x1, y1, 0, oldPixels.get(x2, y2, 0)) pixels.set(x1, y1, 0, oldPixels.get(x2, y2, 0));
pixels.set(x1, y1, 1, oldPixels.get(x2, y2, 1)) pixels.set(x1, y1, 1, oldPixels.get(x2, y2, 1));
pixels.set(x1, y1, 2, oldPixels.get(x2, y2, 2)) pixels.set(x1, y1, 2, oldPixels.get(x2, y2, 2));
pixels.set(x1, y1, 3, oldPixels.get(x2, y2, 3)) pixels.set(x1, y1, 3, oldPixels.get(x2, y2, 3));
} }
function flip(){ function flip(){
@@ -28,4 +28,4 @@ module.exports = function flipImage(oldPixels, pixels, axis) {
flip(); flip();
return pixels; return pixels;
} };

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -1,47 +1,47 @@
module.exports = function Gamma(options, UI) { module.exports = function Gamma(options, UI) {
var output; var output;
function draw(input, callback, progressObj) { function draw(input, callback, progressObj) {
progressObj.stop(true); progressObj.stop(true);
progressObj.overrideFlag = true; progressObj.overrideFlag = true;
var step = this; var step = this;
var defaults = require('./../../util/getDefaults.js')(require('./info.json')), var defaults = require('./../../util/getDefaults.js')(require('./info.json')),
adjustment = options.adjustment || defaults.adjustment; adjustment = options.adjustment || defaults.adjustment;
var val = adjustment / defaults.adjustment; var val = adjustment / defaults.adjustment;
function changePixel(r, g, b, a) { function changePixel(r, g, b, a) {
r = Math.pow(r / 255, val) * 255; r = Math.pow(r / 255, val) * 255;
g = Math.pow(g / 255, val) * 255; g = Math.pow(g / 255, val) * 255;
b = Math.pow(b / 255, val) * 255; b = Math.pow(b / 255, val) * 255;
return [r, g, b, a]; return [r, g, b, a];
} }
function output(image, datauri, mimetype) { function output(image, datauri, mimetype) {
step.output = { src: datauri, format: mimetype }; step.output = { src: datauri, format: mimetype };
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
changePixel: changePixel,
format: input.format,
image: options.image,
inBrowser: options.inBrowser,
callback: callback
});
} }
return {
options: options, return require('../_nomodule/PixelManipulation.js')(input, {
draw: draw, output: output,
output: output, changePixel: changePixel,
UI: UI format: input.format,
} image: options.image,
} inBrowser: options.inBrowser,
callback: callback
});
}
return {
options: options,
draw: draw,
output: output,
UI: UI
};
};

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -1,61 +1,61 @@
module.exports = function Invert(options, UI) { module.exports = function Invert(options, UI) {
var output; var output;
// The function which is called on every draw. // The function which is called on every draw.
function draw(input, callback, progressObj) { function draw(input, callback, progressObj) {
var getPixels = require('get-pixels'); var getPixels = require('get-pixels');
var savePixels = require('save-pixels'); var savePixels = require('save-pixels');
var step = this; var step = this;
getPixels(input.src, function(err, pixels) { getPixels(input.src, function(err, pixels) {
if (err) { if (err) {
console.log("Bad Image path"); console.log('Bad Image path');
return; return;
} }
var width = pixels.shape[0]; var width = pixels.shape[0];
for (var i = 0; i < pixels.shape[0]; i++) {
for (var j = 0; j < pixels.shape[1]; j++) {
let val = (i / width) * 255;
pixels.set(i, j, 0, val);
pixels.set(i, j, 1, val);
pixels.set(i, j, 2, val);
pixels.set(i, j, 3, 255);
}
}
var chunks = [];
var totalLength = 0;
var r = savePixels(pixels, input.format, { quality: 100 });
r.on("data", function(chunk) {
totalLength += chunk.length;
chunks.push(chunk);
});
r.on("end", function() {
var data = Buffer.concat(chunks, totalLength).toString("base64");
var datauri = "data:image/" + input.format + ";base64," + data;
output(input.image, datauri, input.format);
callback();
});
});
function output(image, datauri, mimetype) {
// This output is accessible by Image Sequencer
step.output = { src: datauri, format: mimetype };
for (var i = 0; i < pixels.shape[0]; i++) {
for (var j = 0; j < pixels.shape[1]; j++) {
let val = (i / width) * 255;
pixels.set(i, j, 0, val);
pixels.set(i, j, 1, val);
pixels.set(i, j, 2, val);
pixels.set(i, j, 3, 255);
} }
} }
var chunks = [];
var totalLength = 0;
var r = savePixels(pixels, input.format, { quality: 100 });
r.on('data', function(chunk) {
totalLength += chunk.length;
chunks.push(chunk);
});
r.on('end', function() {
var data = Buffer.concat(chunks, totalLength).toString('base64');
var datauri = 'data:image/' + input.format + ';base64,' + data;
output(input.image, datauri, input.format);
callback();
});
});
function output(image, datauri, mimetype) {
// This output is accessible by Image Sequencer
step.output = { src: datauri, format: mimetype };
return {
options: options,
draw: draw,
output: output,
UI: UI
} }
} }
return {
options: options,
draw: draw,
output: output,
UI: UI
};
};

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -1,28 +1,28 @@
module.exports = exports = function(pixels, options){ module.exports = exports = function(pixels, options){
var defaults = require('./../../util/getDefaults.js')(require('./info.json')); var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
options.x = Number(options.x) || defaults.x; options.x = Number(options.x) || defaults.x;
options.y = Number(options.y) || defaults.y; options.y = Number(options.y) || defaults.y;
color = options.color || defaults.color; color = options.color || defaults.color;
color = color.split(" "); color = color.split(' ');
for(var x = 0; x < pixels.shape[0]; x+=options.x){ for(var x = 0; x < pixels.shape[0]; x+=options.x){
for(var y = 0 ; y < pixels.shape[1]; y++){ for(var y = 0 ; y < pixels.shape[1]; y++){
pixels.set(x, y, 0, color[0]); pixels.set(x, y, 0, color[0]);
pixels.set(x, y, 1, color[1]); pixels.set(x, y, 1, color[1]);
pixels.set(x, y, 2, color[2]); pixels.set(x, y, 2, color[2]);
pixels.set(x, y, 3, color[3]); pixels.set(x, y, 3, color[3]);
} }
} }
for(var y = 0; y < pixels.shape[1]; y+=options.y){ for(var y = 0; y < pixels.shape[1]; y+=options.y){
for(var x = 0 ; x < pixels.shape[0]; x++){ for(var x = 0 ; x < pixels.shape[0]; x++){
pixels.set(x, y, 0, color[0]); pixels.set(x, y, 0, color[0]);
pixels.set(x, y, 1, color[1]); pixels.set(x, y, 1, color[1]);
pixels.set(x, y, 2, color[2]); pixels.set(x, y, 2, color[2]);
pixels.set(x, y, 3, color[3]); pixels.set(x, y, 3, color[3]);
} }
} }
return pixels; return pixels;
} };

View File

@@ -11,9 +11,9 @@ module.exports = function GridOverlay(options,UI) {
var step = this; var step = this;
function extraManipulation(pixels) { function extraManipulation(pixels) {
pixels = require('./GridOverlay')(pixels, options); pixels = require('./GridOverlay')(pixels, options);
return pixels return pixels;
} }
function output(image, datauri, mimetype) { function output(image, datauri, mimetype) {
@@ -32,12 +32,12 @@ module.exports = function GridOverlay(options,UI) {
}); });
} }
return { return {
options: options, options: options,
draw: draw, draw: draw,
output: output, output: output,
UI: UI UI: UI
} };
} };

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -3,92 +3,92 @@
*/ */
module.exports = function Channel(options, UI) { module.exports = function Channel(options, UI) {
var output; var output;
function draw(input, callback, progressObj) { function draw(input, callback, progressObj) {
var defaults = require('./../../util/getDefaults.js')(require('./info.json')); var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
options.gradient = options.gradient || defaults.gradient; options.gradient = options.gradient || defaults.gradient;
options.gradient = JSON.parse(options.gradient); options.gradient = JSON.parse(options.gradient);
progressObj.stop(true); progressObj.stop(true);
progressObj.overrideFlag = true; progressObj.overrideFlag = true;
var step = this, hist = new Array(256).fill(0); var step = this, hist = new Array(256).fill(0);
function changePixel(r, g, b, a) { function changePixel(r, g, b, a) {
let pixVal = Math.round((r + g + b) / 3); let pixVal = Math.round((r + g + b) / 3);
hist[pixVal]++; hist[pixVal]++;
return [r, g, b, a]; return [r, g, b, a];
}
function extraManipulation(pixels) {
// if (!options.inBrowser)
// require('fs').writeFileSync('./output/histo.txt', hist.reduce((tot, cur, idx) => `${tot}\n${idx} : ${cur}`, ``));
var newarray = new Uint8Array(4 * 256 * 256);
pixels.data = newarray;
pixels.shape = [256, 256, 4];
pixels.stride[1] = 4 * 256;
for (let x = 0; x < 256; x++) {
for (let y = 0; y < 256; y++) {
pixels.set(x, y, 0, 255);
pixels.set(x, y, 1, 255);
pixels.set(x, y, 2, 255);
pixels.set(x, y, 3, 255);
} }
}
function extraManipulation(pixels) { let startY = options.gradient ? 10 : 0;
// if (!options.inBrowser) if (options.gradient) {
// require('fs').writeFileSync('./output/histo.txt', hist.reduce((tot, cur, idx) => `${tot}\n${idx} : ${cur}`, ``)); for (let x = 0; x < 256; x++) {
var newarray = new Uint8Array(4 * 256 * 256); for (let y = 0; y < 10; y++) {
pixels.data = newarray; pixels.set(x, 255 - y, 0, x);
pixels.shape = [256, 256, 4]; pixels.set(x, 255 - y, 1, x);
pixels.stride[1] = 4 * 256; pixels.set(x, 255 - y, 2, x);
}
for (let x = 0; x < 256; x++) {
for (let y = 0; y < 256; y++) {
pixels.set(x, y, 0, 255);
pixels.set(x, y, 1, 255);
pixels.set(x, y, 2, 255);
pixels.set(x, y, 3, 255);
}
}
let startY = options.gradient ? 10 : 0;
if (options.gradient) {
for (let x = 0; x < 256; x++) {
for (let y = 0; y < 10; y++) {
pixels.set(x, 255 - y, 0, x);
pixels.set(x, 255 - y, 1, x);
pixels.set(x, 255 - y, 2, x);
}
}
}
let convfactor = (256 - startY) / Math.max(...hist);
for (let x = 0; x < 256; x++) {
let pixCount = Math.round(convfactor * hist[x]);
for (let y = startY; y < pixCount; y++) {
pixels.set(x, 255 - y, 0, 204);
pixels.set(x, 255 - y, 1, 255);
pixels.set(x, 255 - y, 2, 153);
}
}
return pixels;
} }
}
function output(image, datauri, mimetype) { let convfactor = (256 - startY) / Math.max(...hist);
// This output is accesible by Image Sequencer for (let x = 0; x < 256; x++) {
step.output = { src: datauri, format: mimetype }; let pixCount = Math.round(convfactor * hist[x]);
for (let y = startY; y < pixCount; y++) {
pixels.set(x, 255 - y, 0, 204);
pixels.set(x, 255 - y, 1, 255);
pixels.set(x, 255 - y, 2, 153);
} }
}
return require('../_nomodule/PixelManipulation.js')(input, { return pixels;
output: output, }
changePixel: changePixel,
extraManipulation: extraManipulation, function output(image, datauri, mimetype) {
format: input.format,
image: options.image, // This output is accesible by Image Sequencer
inBrowser: options.inBrowser, step.output = { src: datauri, format: mimetype };
callback: callback
});
} }
return { return require('../_nomodule/PixelManipulation.js')(input, {
options: options, output: output,
//setup: setup, // optional changePixel: changePixel,
draw: draw, extraManipulation: extraManipulation,
output: output, format: input.format,
UI: UI image: options.image,
} inBrowser: options.inBrowser,
} callback: callback
});
}
return {
options: options,
//setup: setup, // optional
draw: draw,
output: output,
UI: UI
};
};

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module.js'), require('./Module.js'),
require('./info.json') require('./info.json')
] ];

View File

@@ -9,7 +9,7 @@
module.exports = function ImportImageModule(options, UI) { module.exports = function ImportImageModule(options, UI) {
var defaults = require('./../../util/getDefaults.js')(require('./info.json')); var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
options.imageUrl = options.inBrowser ? (options.url || defaults.url) : "./examples/images/monarch.png"; options.imageUrl = options.inBrowser ? (options.url || defaults.url) : './examples/images/monarch.png';
var output; var output;
@@ -44,5 +44,5 @@ module.exports = function ImportImageModule(options, UI) {
draw: draw, draw: draw,
output: output, output: output,
UI: UI UI: UI
} };
} };

View File

@@ -25,14 +25,14 @@ module.exports = function ImportImageModuleUi(step, ui) {
// setup file input listener // setup file input listener
sequencer.setInputStep({ sequencer.setInputStep({
dropZoneSelector: "#" + dropzoneId, dropZoneSelector: '#' + dropzoneId,
fileInputSelector: "#" + dropzoneId + " .file-input", fileInputSelector: '#' + dropzoneId + ' .file-input',
onLoad: function onLoadFromInput(progress) { onLoad: function onLoadFromInput(progress) {
var reader = progress.target; var reader = progress.target;
step.options.imageUrl = reader.result; step.options.imageUrl = reader.result;
step.options.url = reader.result; step.options.url = reader.result;
sequencer.run(); sequencer.run();
setUrlHashParameter("steps", sequencer.toString()); setUrlHashParameter('steps', sequencer.toString());
} }
}); });
@@ -44,11 +44,11 @@ module.exports = function ImportImageModuleUi(step, ui) {
step.options.imageUrl = src; step.options.imageUrl = src;
sequencer.run(); sequencer.run();
}); });
} }
return { return {
setup: setup setup: setup
} };
} };

View File

@@ -1,4 +1,4 @@
module.exports = [ module.exports = [
require('./Module'), require('./Module'),
require('./info.json') require('./info.json')
] ];

View File

@@ -40,12 +40,12 @@ function Invert(options, UI) {
draw: draw, draw: draw,
output: output, output: output,
UI: UI UI: UI
} };
} }
var info = { var info = {
"name": "Invert", 'name': 'Invert',
"description": "Inverts the image.", 'description': 'Inverts the image.',
"inputs": { 'inputs': {
} }
} };
module.exports = [Invert, info]; module.exports = [Invert, info];

View File

@@ -19,8 +19,8 @@ module.exports = function Ndvi(options, UI) {
var step = this; var step = this;
function changePixel(r, g, b, a) { function changePixel(r, g, b, a) {
if (options.filter == "red") var ndvi = (b - r) / (1.00 * b + r); if (options.filter == 'red') var ndvi = (b - r) / (1.00 * b + r);
if (options.filter == "blue") var ndvi = (r - b) / (1.00 * b + r); if (options.filter == 'blue') var ndvi = (r - b) / (1.00 * b + r);
var x = 255 * (ndvi + 1) / 2; var x = 255 * (ndvi + 1) / 2;
return [x, x, x, a]; return [x, x, x, a];
} }
@@ -55,5 +55,5 @@ module.exports = function Ndvi(options, UI) {
draw: draw, draw: draw,
output: output, output: output,
UI: UI UI: UI
} };
} };

Some files were not shown because too many files have changed in this diff Show More