fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
1 lines • 3.26 kB
Source Map (JSON)
{"version":3,"file":"Vibrance.min.mjs","names":[],"sources":["../../../src/filters/Vibrance.ts"],"sourcesContent":["import { BaseFilter } from './BaseFilter';\nimport type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';\nimport { classRegistry } from '../ClassRegistry';\nimport { fragmentSource } from './shaders/vibrance';\n\nexport type VibranceOwnProps = {\n vibrance: number;\n};\n\nexport const vibranceDefaultValues: VibranceOwnProps = {\n vibrance: 0,\n};\n\n/**\n * Vibrance filter class\n * @example\n * const filter = new Vibrance({\n * vibrance: 1\n * });\n * object.filters.push(filter);\n * object.applyFilters();\n */\nexport class Vibrance extends BaseFilter<'Vibrance', VibranceOwnProps> {\n /**\n * Vibrance value, from -1 to 1.\n * Increases/decreases the saturation of more muted colors with less effect on saturated colors.\n * A value of 0 has no effect.\n *\n * @param {Number} vibrance\n */\n declare vibrance: VibranceOwnProps['vibrance'];\n\n static type = 'Vibrance';\n\n static defaults = vibranceDefaultValues;\n\n static uniformLocations = ['uVibrance'];\n\n getFragmentSource() {\n return fragmentSource;\n }\n\n /**\n * Apply the Vibrance 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 adjust = -this.vibrance;\n for (let i = 0; i < data.length; i += 4) {\n const r = data[i];\n const g = data[i + 1];\n const b = data[i + 2];\n const max = Math.max(r, g, b);\n const avg = (r + g + b) / 3;\n const amt = ((Math.abs(max - avg) * 2) / 255) * adjust;\n data[i] += max !== r ? (max - r) * amt : 0;\n data[i + 1] += max !== g ? (max - g) * amt : 0;\n data[i + 2] += max !== b ? (max - b) * amt : 0;\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 {TWebGLUniformLocationMap} uniformLocations A map of string uniform names to WebGLUniformLocation objects\n */\n sendUniformData(\n gl: WebGLRenderingContext,\n uniformLocations: TWebGLUniformLocationMap,\n ) {\n gl.uniform1f(uniformLocations.uVibrance, -this.vibrance);\n }\n\n isNeutralState() {\n return this.vibrance === 0;\n }\n}\n\nclassRegistry.setClass(Vibrance);\n"],"mappings":"qRAsBA,IAAa,EAAb,cAA8B,CAAA,CAgB5B,mBAAA,CACE,OAAO,EAST,UAAA,CAAY,UAAA,CAAW,KAAE,IAAA,CACvB,IAAM,EAAA,CAAU,KAAK,SACrB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAK,OAAQ,GAAK,EAAG,CACvC,IAAM,EAAI,EAAK,GACT,EAAI,EAAK,EAAI,GACb,EAAI,EAAK,EAAI,GACb,EAAM,KAAK,IAAI,EAAG,EAAG,EAAA,CACrB,GAAO,EAAI,EAAI,GAAK,EACpB,EAA8B,EAAtB,KAAK,IAAI,EAAM,EAAA,CAAY,IAAO,EAChD,EAAK,IAAM,IAAQ,EAAsB,GAAjB,EAAM,GAAK,EACnC,EAAK,EAAI,IAAM,IAAQ,EAAsB,GAAjB,EAAM,GAAK,EACvC,EAAK,EAAI,IAAM,IAAQ,EAAsB,GAAjB,EAAM,GAAK,GAU3C,gBACE,EACA,EAAA,CAEA,EAAG,UAAU,EAAiB,UAAA,CAAY,KAAK,SAAA,CAGjD,gBAAA,CACE,OAAO,KAAK,WAAa,IAAb,EAAA,EA7CP,OAAO,WAAA,CAAA,EAAA,EAEP,WAzB8C,CACrD,SAAU,EAAA,CAAA,CAAA,EAAA,EA0BH,mBAAmB,CAAC,YAAA,CAAA,CA6C7B,EAAc,SAAS,EAAA,CAAA,OAAA,KAAA"}