fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
1 lines • 2.69 kB
Source Map (JSON)
{"version":3,"file":"Noise.min.mjs","names":[],"sources":["../../../src/filters/Noise.ts"],"sourcesContent":["import { BaseFilter } from './BaseFilter';\nimport type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';\nimport { classRegistry } from '../ClassRegistry';\nimport { fragmentSource } from './shaders/noise';\n\nexport type NoiseOwnProps = {\n noise: number;\n};\n\nexport const noiseDefaultValues: NoiseOwnProps = {\n noise: 0,\n};\n\n/**\n * Noise filter class\n * @example\n * const filter = new Noise({\n * noise: 700\n * });\n * object.filters.push(filter);\n * object.applyFilters();\n * canvas.renderAll();\n */\nexport class Noise extends BaseFilter<'Noise', NoiseOwnProps> {\n /**\n * Noise value, from\n * @param {Number} noise\n */\n declare noise: NoiseOwnProps['noise'];\n\n static type = 'Noise';\n\n static defaults = noiseDefaultValues;\n\n static uniformLocations = ['uNoise', 'uSeed'];\n\n getFragmentSource() {\n return fragmentSource;\n }\n\n /**\n * Apply the Brightness operation to a Uint8ClampedArray representing the pixels of an image.\n *\n * @param {Object} options\n * @param {ImageData} options.imageData The Uint8ClampedArray to be filtered.\n */\n applyTo2d({ imageData: { data } }: T2DPipelineState) {\n const noise = this.noise;\n for (let i = 0; i < data.length; i += 4) {\n const rand = (0.5 - Math.random()) * noise;\n data[i] += rand;\n data[i + 1] += rand;\n data[i + 2] += rand;\n }\n }\n\n /**\n * Send data from this filter to its shader program's uniforms.\n *\n * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.\n * @param {Object} uniformLocations A map of string uniform names to WebGLUniformLocation objects\n */\n sendUniformData(\n gl: WebGLRenderingContext,\n uniformLocations: TWebGLUniformLocationMap,\n ) {\n gl.uniform1f(uniformLocations.uNoise, this.noise / 255);\n gl.uniform1f(uniformLocations.uSeed, Math.random());\n }\n\n isNeutralState() {\n return this.noise === 0;\n }\n}\n\nclassRegistry.setClass(Noise);\n"],"mappings":"kRAuBA,IAAa,EAAb,cAA2B,CAAA,CAazB,mBAAA,CACE,OAAO,EAST,UAAA,CAAY,UAAA,CAAW,KAAE,IAAA,CACvB,IAAM,EAAQ,KAAK,MACnB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAK,OAAQ,GAAK,EAAG,CACvC,IAAM,GAAQ,GAAM,KAAK,QAAA,EAAY,EACrC,EAAK,IAAM,EACX,EAAK,EAAI,IAAM,EACf,EAAK,EAAI,IAAM,GAUnB,gBACE,EACA,EAAA,CAEA,EAAG,UAAU,EAAiB,OAAQ,KAAK,MAAQ,IAAA,CACnD,EAAG,UAAU,EAAiB,MAAO,KAAK,QAAA,CAAA,CAG5C,gBAAA,CACE,OAAO,KAAK,QAAU,IAAV,EAAA,EAzCP,OAAO,QAAA,CAAA,EAAA,EAEP,WAvBwC,CAC/C,MAAO,EAAA,CAAA,CAAA,EAAA,EAwBA,mBAAmB,CAAC,SAAU,QAAA,CAAA,CAyCvC,EAAc,SAAS,EAAA,CAAA,OAAA,KAAA"}