Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grid-Overlay module. #974

Merged
merged 3 commits into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = {
'histogram': require('./modules/Histogram'),
'gamma-correction': require('./modules/GammaCorrection'),
'gradient': require('./modules/Gradient'),
'grid-overlay': require('./modules/GridOverlay'),
'import-image': require('./modules/ImportImage'),
'invert': require('image-sequencer-invert'),
'ndvi': require('./modules/Ndvi'),
Expand Down
33 changes: 33 additions & 0 deletions src/modules/GridOverlay/GridOverlay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module.exports = exports = function(pixels, options,priorstep){
var defaults = require('./../../util/getDefaults.js')(require('./info.json'));

options.color = options.color || defaults.color;
options.x = options.x || defaults.x;
options.y = options.y || defaults.y;

var img = $(priorstep.imgElement);
var canvas = document.createElement("canvas");
canvas.width = pixels.shape[0]; //img.width();
canvas.height = pixels.shape[1]; //img.height();
var ctx = canvas.getContext('2d');
ctx.drawImage(img[0], 0, 0);
var p=2;
function drawBoard(){
for (var x = 0; x <= canvas.width; x+=options.x) {
ctx.moveTo(0.5 + x + p, p);
ctx.lineTo(0.5 + x + p, canvas.height + p);
}
for (var y = 0; y <= canvas.height; y+=options.y) {
ctx.moveTo(p, 0.5 + y + p);
ctx.lineTo(canvas.width + p, 0.5 + y + p);
}
ctx.strokeStyle = options.color;
ctx.stroke();
}

drawBoard();

var myImageData = ctx.getImageData(0,0,canvas.width,canvas.height);
pixels.data = myImageData.data
return pixels;
}
50 changes: 50 additions & 0 deletions src/modules/GridOverlay/Module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

module.exports = function GridOverlay(options,UI) {

var output;

function draw(input, callback, progressObj) {

progressObj.stop(true);
progressObj.overrideFlag = true;

var step = this;
if (!options.step.inBrowser) { // This module is only for browser
harshithpabbati marked this conversation as resolved.
Show resolved Hide resolved
this.output = input;
callback();
}
else{
var priorStep = this.getStep(-1); // get the previous step to add text onto it.

function extraManipulation(pixels) {
//if (options.step.inBrowser)
pixels = require('./GridOverlay')(pixels, options,priorStep);
return pixels
}

function output(image, datauri, mimetype) {

// This output is accesible 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,
inBrowser: options.inBrowser,
callback: callback
});

}
}

return {
options: options,
draw: draw,
output: output,
UI: UI
}
}
4 changes: 4 additions & 0 deletions src/modules/GridOverlay/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = [
require('./Module'),
require('./info.json')
]
31 changes: 31 additions & 0 deletions src/modules/GridOverlay/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "GridOverlay",
"description": "Overlays a grid over an Image",
"inputs": {
"x": {
"type": "integer",
"desc": "X-position (measured from left) from where grid starts",
"default": 100
},
"y": {
"type": "integer",
"desc": "Y-position (measured from top) from where grid starts",
"default": 100
},
"color": {
"type": "select",
"desc": "Select the color for the grid.",
"default": "black",
"values": [
"black",
"blue",
"green",
"red",
"white",
"pink",
"orange"
]
}
},
"only": "browser"
}