diff --git a/scripts/modules/filter.js b/scripts/modules/filter.js index a462655..c52ef3e 100644 --- a/scripts/modules/filter.js +++ b/scripts/modules/filter.js @@ -16,6 +16,9 @@ function Filter(element) case "saturation": this.filter_saturation(this.pixels(),p); break; + case "chromatic": + this.filter_chromatic(this.pixels(),p); + break; } } @@ -41,10 +44,78 @@ function Filter(element) ronin.canvas.context().putImageData(pixels, 0, 0, 0, 0, pixels.width, pixels.height); } + this.filter_chromatic = function(pixels = this.pixels(),p = null) + { + var s; + if(p.length == 0) + s = {r:2,g:2,b:2}; + else if(p.length < 3) + s = {r:parseFloat(p[0]), g:parseFloat(p[0])*.5, b:0}; + else + s = {r:parseFloat(p[0]), g:parseFloat(p[1]), b:parseFloat(p[2])}; + var hw = pixels.width*.5; + var hh = pixels.height*.5; + var maxLength = Math.sqrt(hw*hw+hh*hh); + var output = new ImageData(pixels.width, pixels.height); + for (var i=0; i