Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New build v0.4.

  • Loading branch information...
commit 52b351b43d24760bec91c6070b3fe7c23a1b8b46 1 parent 8e6ca63
Alex Michael authored
Showing with 13 additions and 0 deletions.
  1. +13 −0 filtrr2/dist/filtrr2-0.4.min.js
View
13 filtrr2/dist/filtrr2-0.4.min.js
@@ -0,0 +1,13 @@
+var F=function(a,b,d){var c=a[0].nodeName.toLowerCase(),f=a.position(),h=null,i=function(){var b=new Image;b.src=a.attr("src");b.onload=$.proxy(function(){var c=$("<canvas>",{id:a.attr("id"),"class":a.attr("class"),style:a.attr("style")}).css({width:b.width,height:b.height,top:f.top,left:f.left}),d=c[0];this.canvas=c;d.width=b.width;d.height=b.height;d.getContext("2d").drawImage(b,0,0);a.hide();a.parent().append(c);this.processor=new Filtrr2.ImageProcessor(this);e&&e.call(this.processor);g=!0},this)},
+g=!1,e=b||null;this.el=a;this.created=d;this.canvas=this.processor=null;h=new Filtrr2.Events;this.on=$.proxy(function(a,b){h.on(a,b,this)},this);this.off=h.off;this.trigger=h.trigger;this.ready=function(a){if(!a)return g;e=a;g&&e.call(this.ip)};this.update=function(a){a&&g&&a.call(this.processor)};this.save=function(a){var b="image/"+(a||"png");g&&(a=this.canvas[0].toDataURL(b),-1==a.indexOf(b)&&(b="image/png"),a=a.replace(b,"image/octet-stream"),window.location.href=a)};if("img"===c)i.call(this,
+a);else if("canvas"===c)this.canvas=a,this.processor=new Filtrr2.ImageProcessor(this),e&&e.call(this.processor),g=!0;else throw Error("'"+c+"' is an invalid object.");return this},Filtrr2=function(){var a={};if(null==$("<canvas/>")[0].getContext("2d"))throw Error("Canvas is not supported in this browser.");return function(b,d){var c,f;if("undefined"===typeof b||null===b)throw Error("The element you gave Filtrr2 was not defined.");c=typeof b;f=b;key=(c="string"===c||"object"===c&&-1<b.constructor.toString().indexOf("String"))?
+b:b.selector;if(a[key])return a[key].F;c&&(f=$(b));if(0===f.length)throw Error("Element not found.");c=(new Date).getTime();inst=new F(f,d,c);a[key]={timestamp:c,F:inst};return inst}}();Filtrr2.Events=function(){var a={};this.on=function(b,d,c){a[b]||(a[b]=[]);void 0===c&&(c=null);a[b].push({cback:d,ctx:c})};this.off=function(b,d){var c=0,f=[],h=null;if(a[b]&&0<a[b].length)if(d){f=a[b];for(c=0;c<f.length;c++)f.hasOwnProperty(c)&&(h=f[c],h.cback===d&&delete f[c])}else a[b]=[]};this.trigger=function(b){var d=a[b],c=null,f=null,h=[].slice.apply(arguments);for(c in d)d.hasOwnProperty(c)&&(f=d[c])&&f.cback.apply(f.ctx,h.slice(1))}};Filtrr2.FxStore=function(){var a={},b={},d=0;b.add=function(b,f){a[b]=f;d++};b.count=function(){return d};b.get=function(b){return a[b]};b.getNames=function(){var b=[],d=null;for(d in a)a.hasOwnProperty(d)&&b.push(d);return b};return b}();Filtrr2.fx=function(a,b){Filtrr2.FxStore.add(a,b)};
+Filtrr2.ImageProcessor=function(a){for(var b=a.canvas[0],d=b.width,c=b.height,f=b.getContext("2d"),h=Filtrr2.Util.clamp,i=f.getImageData(0,0,d,c),b=Filtrr2.FxStore.getNames(),g=b.length,e=0,j=null,v=this,e=0;e<g;e++)j=b[e],this[j]=function(a,b){return $.proxy(function(){var c=Filtrr2.FxStore.get(a);b.trigger(a+":preprocess");c.apply(this,arguments);b.trigger(a+":postprocess");return this},v)}(j,a);this.render=function(b){a.trigger("prerender");f.putImageData(i,0,0);a.trigger("postrender");b&&b.call(this);
+a.trigger("finalize")};this.process=function(a){for(var b=i.data,e=0,f=0,e=0;e<c;e++)for(f=0;f<d;f++){var g=4*e*d+4*f,k={r:b[g],g:b[g+1],b:b[g+2],a:b[g+3]};a(k,f,e);b[g]=parseInt(h(k.r));b[g+1]=parseInt(h(k.g));b[g+2]=parseInt(h(k.b));b[g+3]=parseInt(h(k.a))}return this};this.convolve=function(a){if(!f.createImageData)throw"createImageData is not supported.";for(var b=f.createImageData(i.width,i.height),e=b.data,g=i.data,j=parseInt(a.length/2),k=parseInt(a[0].length/2),l=0,m=0,n=0,o=0,l=0;l<c;l++)for(m=
+0;m<d;m++){for(var p=4*l*d+4*m,r=0,s=0,t=0,n=-j;n<=j;n++)for(o=-k;o<=k;o++)if(0<=l+n&&l+n<c&&0<=m+o&&m+o<d){var q=a[n+j][o+k];if(0!==q)var u=4*(l+n)*d+4*(m+o),r=r+g[u]*q,s=s+g[u+1]*q,t=t+g[u+2]*q}e[p]=h(r);e[p+1]=h(s);e[p+2]=h(t);e[p+3]=255}i=b;return this}};Filtrr2.fx("adjust",function(a,b,d){this.process(function(c){c.r*=1+a;c.g*=1+b;c.b*=1+d})});Filtrr2.fx("brighten",function(a){a=Filtrr2.Util.normalize(a,-255,255,-100,100);this.process(function(b){b.r+=a;b.g+=a;b.b+=a})});
+Filtrr2.fx("alpha",function(a){a=Filtrr2.Util.normalize(a,0,255,-100,100);this.process(function(b){b.a=a})});Filtrr2.fx("saturate",function(a){a=Filtrr2.Util.normalize(a,0,2,-100,100);this.process(function(b){var d=(b.r+b.g+b.b)/3;b.r=d+a*(b.r-d);b.g=d+a*(b.g-d);b.b=d+a*(b.b-d)})});Filtrr2.fx("invert",function(){this.process(function(a){a.r=255-a.r;a.g=255-a.g;a.b=255-a.b})});
+Filtrr2.fx("posterize",function(a){var a=Filtrr2.Util.clamp(a,1,255),b=Math.floor(255/a);this.process(function(a){a.r=Math.floor(a.r/b)*b;a.g=Math.floor(a.g/b)*b;a.b=Math.floor(a.b/b)*b})});Filtrr2.fx("gamma",function(a){a=Filtrr2.Util.normalize(a,0,2,-100,100);this.process(function(b){b.r=Math.pow(b.r,a);b.g=Math.pow(b.g,a);b.b=Math.pow(b.b,a)})});
+Filtrr2.fx("contrast",function(a){a=Filtrr2.Util.normalize(a,0,2,-100,100);this.process(function(b){b.r=255*((b.r/255-0.5)*a+0.5);b.g=255*((b.g/255-0.5)*a+0.5);b.b=255*((b.b/255-0.5)*a+0.5)})});Filtrr2.fx("sepia",function(){this.process(function(a){var b=a.r,d=a.g,c=a.b;a.r=0.393*b+0.769*d+0.189*c;a.g=0.349*b+0.686*d+0.168*c;a.b=0.272*b+0.534*d+0.131*c})});Filtrr2.fx("subtract",function(a,b,d){this.process(function(c){c.r-=a;c.g-=b;c.b-=d})});
+Filtrr2.fx("fill",function(a,b,d){this.process(function(c){c.r=a;c.g=b;c.b=d})});Filtrr2.fx("blur",function(a){a=a||"simple";"simple"===a?this.convolve([[1/9,1/9,1/9],[1/9,1/9,1/9],[1/9,1/9,1/9]]):"gaussian"===a&&this.convolve([[1/273,4/273,7/273,4/273,1/273],[4/273,16/273,26/273,16/273,4/273],[7/273,26/273,41/273,26/273,7/273],[4/273,16/273,26/273,16/273,4/273],[1/273,4/273,7/273,4/273,1/273]])});Filtrr2.fx("sharpen",function(){this.convolve([[0,-0.2,0],[-0.2,1.8,-0.2],[0,-0.2,0]])});
+Filtrr2.fx("curves",function(a,b,d,c){var f=(new Filtrr2.Util.Bezier(a,b,d,c)).genColorTable();this.process(function(a){a.r=f[a.r];a.g=f[a.g];a.b=f[a.b]})});Filtrr2.fx("expose",function(a){a=Filtrr2.Util.normalize(a,-1,1,-100,100);this.curves({x:0,y:0},{x:0,y:255*a},{x:255-255*a,y:255},{x:255,y:255})});Filtrr2.Util=function(){var a={},b=function(a,b,d){return Math.min(d||255,Math.max(b||0,a))},d=function(a,b){return Math.sqrt(Math.pow(b-a,2))};a.clamp=b;a.dist=d;a.normalize=function(a,f,h,i,g){var e=d(i,g),h=d(f,h)/e,a=b(a,i,g);return f+(a-i)*h};a.Bezier=function(a,b,d,i){this.genColorTable=function(){var g={},e;for(e=0;1024>e;e++){var j=a.y*e/1024*(e/1024)*(e/1024)+b.y*3*(e/1024)*(e/1024)*(1-e/1024)+d.y*3*(e/1024)*(1-e/1024)*(1-e/1024)+i.y*(1-e/1024)*(1-e/1024)*(1-e/1024);g[parseInt(a.x*e/1024*
+(e/1024)*(e/1024)+b.x*3*(e/1024)*(e/1024)*(1-e/1024)+d.x*3*(e/1024)*(1-e/1024)*(1-e/1024)+i.x*(1-e/1024)*(1-e/1024)*(1-e/1024))]=parseInt(j)}return g}};return a}();
Please sign in to comment.
Something went wrong with that request. Please try again.