fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
3 lines (2 loc) • 2.07 kB
JavaScript
import{defineProperty as t}from"../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{createCanvasElement as e}from"../util/misc/dom.min.mjs";import{BaseFilter as a}from"./BaseFilter.min.mjs";import{isWebGLPipelineState as r}from"./utils.min.mjs";import{classRegistry as i}from"../ClassRegistry.min.mjs";import{fragmentSource as s}from"./shaders/blur.min.mjs";const o={blur:0};class h extends a{getFragmentSource(){return s}applyTo(t){r(t)?(this.aspectRatio=t.sourceWidth/t.sourceHeight,t.passes++,this._setupFrameBuffer(t),this.horizontal=!0,this.applyToWebGL(t),this._swapTextures(t),this._setupFrameBuffer(t),this.horizontal=!1,this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){t.imageData=this.simpleBlur(t)}simpleBlur(t){let{ctx:a,imageData:r,filterBackend:{resources:i}}=t;const{width:s,height:o}=r;i.blurLayer1||(i.blurLayer1=e(),i.blurLayer2=e());const h=i.blurLayer1,l=i.blurLayer2;h.width===s&&h.height===o||(l.width=h.width=s,l.height=h.height=o);const m=h.getContext("2d"),p=l.getContext("2d"),u=15,n=.06*this.blur*.5;let c,g,d,b;for(m.putImageData(r,0,0),p.clearRect(0,0,s,o),b=-15;b<=u;b++)c=(Math.random()-.5)/4,g=b/u,d=n*g*s+c,p.globalAlpha=1-Math.abs(g),p.drawImage(h,d,c),m.drawImage(l,0,0),p.globalAlpha=1,p.clearRect(0,0,l.width,l.height);for(b=-15;b<=u;b++)c=(Math.random()-.5)/4,g=b/u,d=n*g*o+c,p.globalAlpha=1-Math.abs(g),p.drawImage(h,c,d),m.drawImage(l,0,0),p.globalAlpha=1,p.clearRect(0,0,l.width,l.height);a.drawImage(h,0,0);const f=a.getImageData(0,0,h.width,h.height);return m.globalAlpha=1,m.clearRect(0,0,h.width,h.height),f}sendUniformData(t,e){const a=this.chooseRightDelta();t.uniform2fv(e.uDelta,a)}isNeutralState(){return 0===this.blur}chooseRightDelta(){let t=1;const e=[0,0];this.horizontal?this.aspectRatio>1&&(t=1/this.aspectRatio):this.aspectRatio<1&&(t=this.aspectRatio);const a=t*this.blur*.12;return this.horizontal?e[0]=a:e[1]=a,e}}t(h,"type","Blur"),t(h,"defaults",o),t(h,"uniformLocations",["uDelta"]),i.setClass(h);export{h as Blur,o as blurDefaultValues};
//# sourceMappingURL=Blur.min.mjs.map