Added sharpen filter
This commit is contained in:
@@ -64,5 +64,4 @@ function Filter_Chromatic()
|
||||
ronin.surface.active_layer.clear();
|
||||
context.putImageData(imageData, 0, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,29 @@ function Filter()
|
||||
console.log("render: Nothing here.");
|
||||
}
|
||||
|
||||
this.get_neighbors = function(pixels,x,y)
|
||||
{
|
||||
return [
|
||||
this.get_color(pixels,x-1,y-1),this.get_color(pixels,x,y-1),this.get_color(pixels,x+1,y-1),
|
||||
this.get_color(pixels,x-1,y),this.get_color(pixels,x,y),this.get_color(pixels,x+1,y),
|
||||
this.get_color(pixels,x-1,y+1),this.get_color(pixels,x,y+1),this.get_color(pixels,x+1,y+1),
|
||||
];
|
||||
}
|
||||
|
||||
this.get_neighbors_average = function(pixels,x,y,weight_map = [1,1,1,1,1,1,1,1,1])
|
||||
{
|
||||
var n = this.get_neighbors(pixels,x,y);
|
||||
var r = 0;
|
||||
var g = 0;
|
||||
var b = 0;
|
||||
for (var i = 0; i < n.length; i++){
|
||||
r += n[i].r * weight_map[i];
|
||||
g += n[i].g * weight_map[i];
|
||||
b += n[i].b * weight_map[i];
|
||||
}
|
||||
return {r:r/n.length,g:g/n.length,b:b/n.length}
|
||||
}
|
||||
|
||||
this.set_color = function(pixels, color, x, y)
|
||||
{
|
||||
x = Math.max(0,Math.min(x,pixels.width-1));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
function Filter_Saturation()
|
||||
function Filter_Grey()
|
||||
{
|
||||
Filter.call(this);
|
||||
|
||||
51
scripts/filters/sharpen.js
Normal file
51
scripts/filters/sharpen.js
Normal file
@@ -0,0 +1,51 @@
|
||||
function Filter_Sharpen()
|
||||
{
|
||||
Filter.call(this);
|
||||
|
||||
this.parameters = [];
|
||||
|
||||
this.render = function(cmd)
|
||||
{
|
||||
var imageObj = new Image();
|
||||
imageObj.src = ronin.surface.active_layer.element.toDataURL('image/png');
|
||||
|
||||
var w = ronin.surface.size.width;
|
||||
var h = ronin.surface.size.height;
|
||||
var context = ronin.surface.active_layer.context();
|
||||
|
||||
var originalData = context.getImageData(0, 0, w*2, h*2);
|
||||
var data = originalData.data;
|
||||
var newImage = context.getImageData(0, 0, w*2, h*2);
|
||||
|
||||
var weight_map = [
|
||||
-2, 0, -2,
|
||||
0, 16, 0,
|
||||
-2, 0, -2
|
||||
];
|
||||
|
||||
for(var i = 0; i < data.length; i += 4) {
|
||||
var p = i / 4;
|
||||
var x = (p % originalData.width);
|
||||
var y = parseInt(p/originalData.width);
|
||||
|
||||
var average = this.get_neighbors_average(originalData,x,y,weight_map);
|
||||
newImage.data[i] = parseInt(average.r);
|
||||
newImage.data[i+1] = parseInt(average.g);
|
||||
newImage.data[i+2] = parseInt(average.b);
|
||||
}
|
||||
|
||||
ronin.surface.active_layer.clear();
|
||||
context.putImageData(newImage, 0, 0);
|
||||
}
|
||||
|
||||
this.preview = function(cmd)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
this.draw = function(context = this.context(), value, position)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user