mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-14 20:30:01 +01:00
Merge master, Rename this_ and ui: 'none'
This commit is contained in:
@@ -26,7 +26,6 @@
|
|||||||
"urify": "^2.1.0"
|
"urify": "^2.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"base64-stream": "~0.1.3",
|
|
||||||
"browserify": "13.0.0",
|
"browserify": "13.0.0",
|
||||||
"buffer": "~5.0.2",
|
"buffer": "~5.0.2",
|
||||||
"get-pixels": "~3.3.0",
|
"get-pixels": "~3.3.0",
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ module.exports = function UserInterface(UI,options) {
|
|||||||
var UI = UI || {};
|
var UI = UI || {};
|
||||||
|
|
||||||
UI.onSetup = UI.onSetup || function() {
|
UI.onSetup = UI.onSetup || function() {
|
||||||
if(options.ui == "none") {
|
if(options.ui == false) {
|
||||||
// No UI
|
// No UI
|
||||||
}
|
}
|
||||||
else if(options.inBrowser) {
|
else if(options.inBrowser) {
|
||||||
@@ -23,7 +23,7 @@ module.exports = function UserInterface(UI,options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UI.onDraw = UI.onDraw || function() {
|
UI.onDraw = UI.onDraw || function() {
|
||||||
if (options.ui == "none") {
|
if (options.ui == false) {
|
||||||
// No UI
|
// No UI
|
||||||
}
|
}
|
||||||
else if(options.inBrowser) {
|
else if(options.inBrowser) {
|
||||||
@@ -37,7 +37,7 @@ module.exports = function UserInterface(UI,options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UI.onComplete = UI.onComplete || function(output) {
|
UI.onComplete = UI.onComplete || function(output) {
|
||||||
if (options.ui == "none") {
|
if (options.ui == false) {
|
||||||
// No UI
|
// No UI
|
||||||
}
|
}
|
||||||
else if(options.inBrowser) {
|
else if(options.inBrowser) {
|
||||||
@@ -52,7 +52,7 @@ module.exports = function UserInterface(UI,options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UI.onRemove = UI.onRemove || function(callback) {
|
UI.onRemove = UI.onRemove || function(callback) {
|
||||||
if(options.ui == "null"){
|
if(options.ui == false){
|
||||||
// No UI
|
// No UI
|
||||||
}
|
}
|
||||||
else if(options.inBrowser) {
|
else if(options.inBrowser) {
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
module.exports = function Crop(input,options,callback) {
|
module.exports = function Crop(input,options,callback) {
|
||||||
|
|
||||||
var getPixels = require("get-pixels"),
|
var getPixels = require('get-pixels'),
|
||||||
savePixels = require("save-pixels"),
|
savePixels = require('save-pixels');
|
||||||
base64 = require('base64-stream');
|
|
||||||
|
|
||||||
getPixels(input.src,function(err,pixels){
|
getPixels(input.src,function(err,pixels){
|
||||||
var newdata = [];
|
|
||||||
var ox = options.x || 0;
|
var ox = options.x || 0;
|
||||||
var oy = options.y || 0;
|
var oy = options.y || 0;
|
||||||
var w = options.w || Math.floor(0.5*pixels.shape[0]);
|
var w = options.w || Math.floor(0.5*pixels.shape[0]);
|
||||||
var h = options.h || Math.floor(0.5*pixels.shape[1]);
|
var h = options.h || Math.floor(0.5*pixels.shape[1]);
|
||||||
var iw = pixels.shape[0]; //Width of Original Image
|
var iw = pixels.shape[0]; //Width of Original Image
|
||||||
newarray = new Uint8Array(4*w*h);
|
var newarray = new Uint8Array(4*w*h);
|
||||||
for (var n = oy; n < oy + h; n++) {
|
for (var n = oy; n < oy + h; n++) {
|
||||||
newarray.set(pixels.data.slice(n*4*iw + ox, n*4*iw + ox + 4*w),4*w*(n-oy));
|
newarray.set(pixels.data.slice(n*4*iw + ox, n*4*iw + ox + 4*w),4*w*(n-oy));
|
||||||
}
|
}
|
||||||
@@ -19,15 +17,19 @@ module.exports = function Crop(input,options,callback) {
|
|||||||
pixels.shape = [w,h,4];
|
pixels.shape = [w,h,4];
|
||||||
pixels.stride[1] = 4*w;
|
pixels.stride[1] = 4*w;
|
||||||
|
|
||||||
options.format = "jpeg";
|
var chunks = [];
|
||||||
|
var totalLength = 0;
|
||||||
w = base64.encode();
|
|
||||||
var r = savePixels(pixels, options.format);
|
var r = savePixels(pixels, options.format);
|
||||||
r.pipe(w).on('finish',function(){
|
|
||||||
data = w.read().toString();
|
r.on('data', function(chunk){
|
||||||
datauri = 'data:image/' + options.format + ';base64,' + data;
|
totalLength += chunk.length;
|
||||||
|
chunks.push(chunk);
|
||||||
|
});
|
||||||
|
|
||||||
|
r.on('end', function(){
|
||||||
|
var data = Buffer.concat(chunks, totalLength).toString('base64');
|
||||||
|
var datauri = 'data:image/' + options.format + ';base64,' + data;
|
||||||
callback(datauri,options.format);
|
callback(datauri,options.format);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|||||||
@@ -22,10 +22,10 @@
|
|||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
|
|
||||||
UI.onDraw();
|
UI.onDraw();
|
||||||
const this_ = this;
|
const step = this;
|
||||||
|
|
||||||
require('./Crop')(input,options,function(out,format){
|
require('./Crop')(input,options,function(out,format){
|
||||||
this_.output = {
|
step.output = {
|
||||||
src: out,
|
src: out,
|
||||||
format: format
|
format: format
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ module.exports = function DoNothingPix(options,UI) {
|
|||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
|
|
||||||
UI.onDraw();
|
UI.onDraw();
|
||||||
var this_ = this;
|
const 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 output(image,datauri,mimetype){
|
function output(image,datauri,mimetype){
|
||||||
this_.output = {src:datauri,format:mimetype}
|
step.output = {src:datauri,format:mimetype}
|
||||||
UI.onComplete(datauri);
|
UI.onComplete(datauri);
|
||||||
}
|
}
|
||||||
return require('../_nomodule/PixelManipulation.js')(input, {
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ module.exports = function GreenChannel(options,UI) {
|
|||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
|
|
||||||
UI.onDraw();
|
UI.onDraw();
|
||||||
var this_ = this;
|
const step = this;
|
||||||
|
|
||||||
function changePixel(r, g, b, a) {
|
function changePixel(r, g, b, a) {
|
||||||
return [0, g, 0, a];
|
return [0, g, 0, a];
|
||||||
}
|
}
|
||||||
function output(image,datauri,mimetype){
|
function output(image,datauri,mimetype){
|
||||||
this_.output = {src:datauri,format:mimetype};
|
step.output = {src:datauri,format:mimetype};
|
||||||
UI.onComplete(datauri);
|
UI.onComplete(datauri);
|
||||||
}
|
}
|
||||||
return require('../_nomodule/PixelManipulation.js')(input, {
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ module.exports = function GreenChannel(options,UI) {
|
|||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
|
|
||||||
UI.onDraw();
|
UI.onDraw();
|
||||||
var this_ = this;
|
const step = this;
|
||||||
|
|
||||||
function changePixel(r, g, b, a) {
|
function changePixel(r, g, b, a) {
|
||||||
return [255-r, 255-g, 255-b, a];
|
return [255-r, 255-g, 255-b, a];
|
||||||
}
|
}
|
||||||
function output(image,datauri,mimetype){
|
function output(image,datauri,mimetype){
|
||||||
this_.output = {src:datauri,format:mimetype};
|
step.output = {src:datauri,format:mimetype};
|
||||||
UI.onComplete(datauri);
|
UI.onComplete(datauri);
|
||||||
}
|
}
|
||||||
return require('../_nomodule/PixelManipulation.js')(input, {
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ module.exports = function NdviRed(options,UI) {
|
|||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
|
|
||||||
UI.onDraw();
|
UI.onDraw();
|
||||||
var this_ = this;
|
const step = this;
|
||||||
|
|
||||||
function changePixel(r, g, b, a) {
|
function changePixel(r, g, b, a) {
|
||||||
var ndvi = (b - r) / (1.00 * b + r);
|
var ndvi = (b - r) / (1.00 * b + r);
|
||||||
@@ -19,7 +19,7 @@ module.exports = function NdviRed(options,UI) {
|
|||||||
return [x, x, x, a];
|
return [x, x, x, a];
|
||||||
}
|
}
|
||||||
function output(image,datauri,mimetype){
|
function output(image,datauri,mimetype){
|
||||||
this_.output = {src:datauri,format:mimetype};
|
step.output = {src:datauri,format:mimetype};
|
||||||
UI.onComplete(datauri);
|
UI.onComplete(datauri);
|
||||||
}
|
}
|
||||||
return require('../_nomodule/PixelManipulation.js')(input, {
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ module.exports = function SegmentedColormap(options,UI) {
|
|||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
|
|
||||||
UI.onDraw();
|
UI.onDraw();
|
||||||
var this_ = this;
|
const step = this;
|
||||||
|
|
||||||
function changePixel(r, g, b, a) {
|
function changePixel(r, g, b, a) {
|
||||||
var ndvi = (b - r) / (r + b);
|
var ndvi = (b - r) / (r + b);
|
||||||
@@ -17,7 +17,7 @@ module.exports = function SegmentedColormap(options,UI) {
|
|||||||
return [res[0], res[1], res[2], 255];
|
return [res[0], res[1], res[2], 255];
|
||||||
}
|
}
|
||||||
function output(image,datauri,mimetype){
|
function output(image,datauri,mimetype){
|
||||||
this_.output = {src:datauri,format:mimetype};
|
step.output = {src:datauri,format:mimetype};
|
||||||
UI.onComplete(datauri);
|
UI.onComplete(datauri);
|
||||||
}
|
}
|
||||||
return require('../_nomodule/PixelManipulation.js')(input, {
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
|
|||||||
@@ -7,16 +7,15 @@ module.exports = function PixelManipulation(image, options) {
|
|||||||
options = options || {};
|
options = options || {};
|
||||||
options.changePixel = options.changePixel || function changePixel(r, g, b, a) {
|
options.changePixel = options.changePixel || function changePixel(r, g, b, a) {
|
||||||
return [r, g, b, a];
|
return [r, g, b, a];
|
||||||
}
|
};
|
||||||
var getPixels = require("get-pixels"),
|
var getPixels = require('get-pixels'),
|
||||||
savePixels = require("save-pixels"),
|
savePixels = require('save-pixels');
|
||||||
base64 = require('base64-stream');
|
|
||||||
|
|
||||||
getPixels(image.src, function(err, pixels) {
|
getPixels(image.src, function(err, pixels) {
|
||||||
|
|
||||||
if(err) {
|
if(err) {
|
||||||
console.log("Bad image path")
|
console.log('Bad image path');
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterate through pixels;
|
// iterate through pixels;
|
||||||
@@ -25,7 +24,7 @@ module.exports = function PixelManipulation(image, options) {
|
|||||||
for(var x = 0; x < pixels.shape[0]; x++) {
|
for(var x = 0; x < pixels.shape[0]; x++) {
|
||||||
for(var y = 0; y < pixels.shape[1]; y++) {
|
for(var y = 0; y < pixels.shape[1]; y++) {
|
||||||
|
|
||||||
pixel = options.changePixel(
|
var pixel = options.changePixel(
|
||||||
pixels.get(x, y, 0),
|
pixels.get(x, y, 0),
|
||||||
pixels.get(x, y, 1),
|
pixels.get(x, y, 1),
|
||||||
pixels.get(x, y, 2),
|
pixels.get(x, y, 2),
|
||||||
@@ -40,19 +39,22 @@ module.exports = function PixelManipulation(image, options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
options.format = "jpeg";
|
|
||||||
|
|
||||||
// there may be a more efficient means to encode an image object,
|
// there may be a more efficient means to encode an image object,
|
||||||
// but node modules and their documentation are essentially arcane on this point
|
// but node modules and their documentation are essentially arcane on this point
|
||||||
w = base64.encode();
|
var chunks = [];
|
||||||
|
var totalLength = 0;
|
||||||
var r = savePixels(pixels, options.format);
|
var r = savePixels(pixels, options.format);
|
||||||
r.pipe(w).on('finish',function(){
|
|
||||||
data = w.read().toString();
|
r.on('data', function(chunk){
|
||||||
datauri = 'data:image/' + options.format + ';base64,' + data;
|
totalLength += chunk.length;
|
||||||
|
chunks.push(chunk);
|
||||||
|
});
|
||||||
|
|
||||||
|
r.on('end', function(){
|
||||||
|
var data = Buffer.concat(chunks, totalLength).toString('base64');
|
||||||
|
var datauri = 'data:image/' + options.format + ';base64,' + data;
|
||||||
if (options.output) options.output(options.image,datauri,options.format);
|
if (options.output) options.output(options.image,datauri,options.format);
|
||||||
if (options.callback) options.callback();
|
if (options.callback) options.callback();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ var test = require('tape');
|
|||||||
|
|
||||||
require('../src/ImageSequencer.js');
|
require('../src/ImageSequencer.js');
|
||||||
|
|
||||||
var sequencer = ImageSequencer({ ui: "none" });
|
var sequencer = ImageSequencer({ ui: false });
|
||||||
var red = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAQABADASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFQEBAQAAAAAAAAAAAAAAAAAABgj/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwCdABykX//Z";
|
var red = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAQABADASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFQEBAQAAAAAAAAAAAAAAAAAABgj/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwCdABykX//Z";
|
||||||
|
|
||||||
test('loadImages/loadImage has a name generator.', function (t){
|
test('loadImages/loadImage has a name generator.', function (t){
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ var test = require('tape');
|
|||||||
|
|
||||||
require('../src/ImageSequencer.js');
|
require('../src/ImageSequencer.js');
|
||||||
|
|
||||||
var sequencer = ImageSequencer({ ui: "none" });
|
var sequencer = ImageSequencer({ ui: false });
|
||||||
var image = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAQABADASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFQEBAQAAAAAAAAAAAAAAAAAABgj/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwCdABykX//Z";
|
var image = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAQABADASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFQEBAQAAAAAAAAAAAAAAAAAABgj/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwCdABykX//Z";
|
||||||
sequencer.loadImages(image);
|
sequencer.loadImages(image);
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ function copy(g,a) {
|
|||||||
var parent = (typeof(global)==="undefined")?window:global;
|
var parent = (typeof(global)==="undefined")?window:global;
|
||||||
var global1 = copy(true,parent);
|
var global1 = copy(true,parent);
|
||||||
|
|
||||||
var sequencer = ImageSequencer({ ui: "none" });
|
var sequencer = ImageSequencer({ ui: false });
|
||||||
var red = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAQABADASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFQEBAQAAAAAAAAAAAAAAAAAABgj/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwCdABykX//Z";
|
var red = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAQABADASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFQEBAQAAAAAAAAAAAAAAAAAABgj/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwCdABykX//Z";
|
||||||
|
|
||||||
test('Image Sequencer has tests', function (t) {
|
test('Image Sequencer has tests', function (t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user