@postermywall/fabricjs-2 6.0.0-rc2.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -1
- package/dist/index.js +229 -491
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.min.mjs +1 -1
- package/dist/index.min.mjs.map +1 -1
- package/dist/index.mjs +229 -491
- package/dist/index.mjs.map +1 -1
- package/dist/index.node.cjs +229 -491
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +229 -491
- package/dist/index.node.mjs.map +1 -1
- package/dist/package.json.min.mjs +1 -1
- package/dist/package.json.mjs +1 -1
- package/dist/src/canvas/Canvas.d.ts.map +1 -1
- package/dist/src/canvas/Canvas.min.mjs +1 -1
- package/dist/src/canvas/Canvas.min.mjs.map +1 -1
- package/dist/src/canvas/Canvas.mjs +8 -9
- package/dist/src/canvas/Canvas.mjs.map +1 -1
- package/dist/src/canvas/SelectableCanvas.d.ts +1 -1
- package/dist/src/canvas/SelectableCanvas.d.ts.map +1 -1
- package/dist/src/canvas/SelectableCanvas.min.mjs +1 -1
- package/dist/src/canvas/SelectableCanvas.min.mjs.map +1 -1
- package/dist/src/canvas/SelectableCanvas.mjs +1 -1
- package/dist/src/canvas/SelectableCanvas.mjs.map +1 -1
- package/dist/src/canvas/StaticCanvas.d.ts +4 -4
- package/dist/src/canvas/StaticCanvas.d.ts.map +1 -1
- package/dist/src/canvas/StaticCanvas.min.mjs +1 -1
- package/dist/src/canvas/StaticCanvas.min.mjs.map +1 -1
- package/dist/src/canvas/StaticCanvas.mjs +0 -13
- package/dist/src/canvas/StaticCanvas.mjs.map +1 -1
- package/dist/src/color/Color.d.ts +1 -0
- package/dist/src/color/Color.d.ts.map +1 -1
- package/dist/src/color/Color.min.mjs +1 -1
- package/dist/src/color/Color.min.mjs.map +1 -1
- package/dist/src/color/Color.mjs +3 -1
- package/dist/src/color/Color.mjs.map +1 -1
- package/dist/src/filters/BaseFilter.d.ts +16 -23
- package/dist/src/filters/BaseFilter.d.ts.map +1 -1
- package/dist/src/filters/BaseFilter.min.mjs +1 -1
- package/dist/src/filters/BaseFilter.min.mjs.map +1 -1
- package/dist/src/filters/BaseFilter.mjs +24 -41
- package/dist/src/filters/BaseFilter.mjs.map +1 -1
- package/dist/src/filters/BlendColor.d.ts +13 -24
- package/dist/src/filters/BlendColor.d.ts.map +1 -1
- package/dist/src/filters/BlendColor.min.mjs +1 -1
- package/dist/src/filters/BlendColor.min.mjs.map +1 -1
- package/dist/src/filters/BlendColor.mjs +1 -25
- package/dist/src/filters/BlendColor.mjs.map +1 -1
- package/dist/src/filters/BlendImage.d.ts +18 -19
- package/dist/src/filters/BlendImage.d.ts.map +1 -1
- package/dist/src/filters/BlendImage.min.mjs +1 -1
- package/dist/src/filters/BlendImage.min.mjs.map +1 -1
- package/dist/src/filters/BlendImage.mjs +13 -24
- package/dist/src/filters/BlendImage.mjs.map +1 -1
- package/dist/src/filters/Blur.d.ts +10 -12
- package/dist/src/filters/Blur.d.ts.map +1 -1
- package/dist/src/filters/Blur.min.mjs +1 -1
- package/dist/src/filters/Blur.min.mjs.map +1 -1
- package/dist/src/filters/Blur.mjs +5 -14
- package/dist/src/filters/Blur.mjs.map +1 -1
- package/dist/src/filters/Boilerplate.d.ts +11 -13
- package/dist/src/filters/Boilerplate.d.ts.map +1 -1
- package/dist/src/filters/Brightness.d.ts +10 -12
- package/dist/src/filters/Brightness.d.ts.map +1 -1
- package/dist/src/filters/Brightness.min.mjs +1 -1
- package/dist/src/filters/Brightness.min.mjs.map +1 -1
- package/dist/src/filters/Brightness.mjs +4 -16
- package/dist/src/filters/Brightness.mjs.map +1 -1
- package/dist/src/filters/Canvas2dFilterBackend.d.ts +1 -1
- package/dist/src/filters/Canvas2dFilterBackend.d.ts.map +1 -1
- package/dist/src/filters/Canvas2dFilterBackend.min.mjs.map +1 -1
- package/dist/src/filters/Canvas2dFilterBackend.mjs.map +1 -1
- package/dist/src/filters/ColorMatrix.d.ts +17 -15
- package/dist/src/filters/ColorMatrix.d.ts.map +1 -1
- package/dist/src/filters/ColorMatrix.min.mjs +1 -1
- package/dist/src/filters/ColorMatrix.min.mjs.map +1 -1
- package/dist/src/filters/ColorMatrix.mjs +7 -27
- package/dist/src/filters/ColorMatrix.mjs.map +1 -1
- package/dist/src/filters/ColorMatrixFilters.d.ts +63 -497
- package/dist/src/filters/ColorMatrixFilters.d.ts.map +1 -1
- package/dist/src/filters/ColorMatrixFilters.min.mjs +1 -1
- package/dist/src/filters/ColorMatrixFilters.min.mjs.map +1 -1
- package/dist/src/filters/ColorMatrixFilters.mjs +13 -8
- package/dist/src/filters/ColorMatrixFilters.mjs.map +1 -1
- package/dist/src/filters/Composed.d.ts +11 -10
- package/dist/src/filters/Composed.d.ts.map +1 -1
- package/dist/src/filters/Composed.min.mjs +1 -1
- package/dist/src/filters/Composed.min.mjs.map +1 -1
- package/dist/src/filters/Composed.mjs +7 -12
- package/dist/src/filters/Composed.mjs.map +1 -1
- package/dist/src/filters/Contrast.d.ts +10 -12
- package/dist/src/filters/Contrast.d.ts.map +1 -1
- package/dist/src/filters/Contrast.min.mjs +1 -1
- package/dist/src/filters/Contrast.min.mjs.map +1 -1
- package/dist/src/filters/Contrast.mjs +6 -17
- package/dist/src/filters/Contrast.mjs.map +1 -1
- package/dist/src/filters/Convolute.d.ts +11 -14
- package/dist/src/filters/Convolute.d.ts.map +1 -1
- package/dist/src/filters/Convolute.min.mjs +1 -1
- package/dist/src/filters/Convolute.min.mjs.map +1 -1
- package/dist/src/filters/Convolute.mjs +1 -15
- package/dist/src/filters/Convolute.mjs.map +1 -1
- package/dist/src/filters/Gamma.d.ts +17 -14
- package/dist/src/filters/Gamma.d.ts.map +1 -1
- package/dist/src/filters/Gamma.min.mjs +1 -1
- package/dist/src/filters/Gamma.min.mjs.map +1 -1
- package/dist/src/filters/Gamma.mjs +20 -24
- package/dist/src/filters/Gamma.mjs.map +1 -1
- package/dist/src/filters/Grayscale.d.ts +8 -11
- package/dist/src/filters/Grayscale.d.ts.map +1 -1
- package/dist/src/filters/Grayscale.min.mjs +1 -1
- package/dist/src/filters/Grayscale.min.mjs.map +1 -1
- package/dist/src/filters/Grayscale.mjs +2 -14
- package/dist/src/filters/Grayscale.mjs.map +1 -1
- package/dist/src/filters/HueRotation.d.ts +11 -5
- package/dist/src/filters/HueRotation.d.ts.map +1 -1
- package/dist/src/filters/HueRotation.min.mjs +1 -1
- package/dist/src/filters/HueRotation.min.mjs.map +1 -1
- package/dist/src/filters/HueRotation.mjs +10 -5
- package/dist/src/filters/HueRotation.mjs.map +1 -1
- package/dist/src/filters/Invert.d.ts +10 -13
- package/dist/src/filters/Invert.d.ts.map +1 -1
- package/dist/src/filters/Invert.min.mjs +1 -1
- package/dist/src/filters/Invert.min.mjs.map +1 -1
- package/dist/src/filters/Invert.mjs +2 -15
- package/dist/src/filters/Invert.mjs.map +1 -1
- package/dist/src/filters/Noise.d.ts +9 -20
- package/dist/src/filters/Noise.d.ts.map +1 -1
- package/dist/src/filters/Noise.min.mjs +1 -1
- package/dist/src/filters/Noise.min.mjs.map +1 -1
- package/dist/src/filters/Noise.mjs +4 -27
- package/dist/src/filters/Noise.mjs.map +1 -1
- package/dist/src/filters/Pixelate.d.ts +8 -12
- package/dist/src/filters/Pixelate.d.ts.map +1 -1
- package/dist/src/filters/Pixelate.min.mjs +1 -1
- package/dist/src/filters/Pixelate.min.mjs.map +1 -1
- package/dist/src/filters/Pixelate.mjs +2 -16
- package/dist/src/filters/Pixelate.mjs.map +1 -1
- package/dist/src/filters/RemoveColor.d.ts +12 -23
- package/dist/src/filters/RemoveColor.d.ts.map +1 -1
- package/dist/src/filters/RemoveColor.min.mjs +1 -1
- package/dist/src/filters/RemoveColor.min.mjs.map +1 -1
- package/dist/src/filters/RemoveColor.mjs +2 -25
- package/dist/src/filters/RemoveColor.mjs.map +1 -1
- package/dist/src/filters/Resize.d.ts +14 -30
- package/dist/src/filters/Resize.d.ts.map +1 -1
- package/dist/src/filters/Resize.min.mjs +1 -1
- package/dist/src/filters/Resize.min.mjs.map +1 -1
- package/dist/src/filters/Resize.mjs +3 -30
- package/dist/src/filters/Resize.mjs.map +1 -1
- package/dist/src/filters/Saturation.d.ts +9 -12
- package/dist/src/filters/Saturation.d.ts.map +1 -1
- package/dist/src/filters/Saturation.min.mjs +1 -1
- package/dist/src/filters/Saturation.min.mjs.map +1 -1
- package/dist/src/filters/Saturation.mjs +8 -20
- package/dist/src/filters/Saturation.mjs.map +1 -1
- package/dist/src/filters/Vibrance.d.ts +10 -13
- package/dist/src/filters/Vibrance.d.ts.map +1 -1
- package/dist/src/filters/Vibrance.min.mjs +1 -1
- package/dist/src/filters/Vibrance.min.mjs.map +1 -1
- package/dist/src/filters/Vibrance.mjs +6 -18
- package/dist/src/filters/Vibrance.mjs.map +1 -1
- package/dist/src/filters/WebGLFilterBackend.d.ts +1 -1
- package/dist/src/filters/WebGLFilterBackend.d.ts.map +1 -1
- package/dist/src/filters/WebGLFilterBackend.min.mjs.map +1 -1
- package/dist/src/filters/WebGLFilterBackend.mjs.map +1 -1
- package/dist/src/filters/shaders/blendImage.d.ts +1 -0
- package/dist/src/filters/shaders/blendImage.d.ts.map +1 -1
- package/dist/src/filters/shaders/blendImage.min.mjs +1 -1
- package/dist/src/filters/shaders/blendImage.min.mjs.map +1 -1
- package/dist/src/filters/shaders/blendImage.mjs +2 -1
- package/dist/src/filters/shaders/blendImage.mjs.map +1 -1
- package/dist/src/filters/typedefs.d.ts +22 -0
- package/dist/src/filters/typedefs.d.ts.map +1 -1
- package/dist/src/parser/elements_parser.d.ts +1 -1
- package/dist/src/parser/elements_parser.d.ts.map +1 -1
- package/dist/src/parser/elements_parser.min.mjs.map +1 -1
- package/dist/src/parser/elements_parser.mjs.map +1 -1
- package/dist/src/shapes/ActiveSelection.d.ts +1 -1
- package/dist/src/shapes/ActiveSelection.d.ts.map +1 -1
- package/dist/src/shapes/ActiveSelection.min.mjs +1 -1
- package/dist/src/shapes/ActiveSelection.min.mjs.map +1 -1
- package/dist/src/shapes/ActiveSelection.mjs +13 -10
- package/dist/src/shapes/ActiveSelection.mjs.map +1 -1
- package/dist/src/shapes/Group.d.ts +9 -0
- package/dist/src/shapes/Group.d.ts.map +1 -1
- package/dist/src/shapes/Group.min.mjs +1 -1
- package/dist/src/shapes/Group.min.mjs.map +1 -1
- package/dist/src/shapes/Group.mjs +10 -1
- package/dist/src/shapes/Group.mjs.map +1 -1
- package/dist/src/shapes/Image.d.ts +4 -4
- package/dist/src/shapes/Image.d.ts.map +1 -1
- package/dist/src/shapes/Image.min.mjs.map +1 -1
- package/dist/src/shapes/Image.mjs.map +1 -1
- package/dist/src/shapes/Object/InteractiveObject.d.ts +3 -0
- package/dist/src/shapes/Object/InteractiveObject.d.ts.map +1 -1
- package/dist/src/shapes/Object/InteractiveObject.min.mjs +1 -1
- package/dist/src/shapes/Object/InteractiveObject.min.mjs.map +1 -1
- package/dist/src/shapes/Object/InteractiveObject.mjs +3 -1
- package/dist/src/shapes/Object/InteractiveObject.mjs.map +1 -1
- package/dist/src/shapes/Object/Object.d.ts +1 -16
- package/dist/src/shapes/Object/Object.d.ts.map +1 -1
- package/dist/src/shapes/Object/Object.min.mjs +1 -1
- package/dist/src/shapes/Object/Object.min.mjs.map +1 -1
- package/dist/src/shapes/Object/Object.mjs +9 -10
- package/dist/src/shapes/Object/Object.mjs.map +1 -1
- package/dist/src/shapes/Object/StackedObject.d.ts +8 -15
- package/dist/src/shapes/Object/StackedObject.d.ts.map +1 -1
- package/dist/src/shapes/Object/StackedObject.min.mjs +1 -1
- package/dist/src/shapes/Object/StackedObject.min.mjs.map +1 -1
- package/dist/src/shapes/Object/StackedObject.mjs +11 -21
- package/dist/src/shapes/Object/StackedObject.mjs.map +1 -1
- package/dist/src/shapes/Path.d.ts +2 -2
- package/dist/src/shapes/Path.d.ts.map +1 -1
- package/dist/src/shapes/Path.min.mjs.map +1 -1
- package/dist/src/shapes/Path.mjs +2 -2
- package/dist/src/shapes/Path.mjs.map +1 -1
- package/dist/src/shapes/Text/TextSVGExportMixin.d.ts +1 -1
- package/dist/src/shapes/Text/TextSVGExportMixin.d.ts.map +1 -1
- package/dist/src/shapes/Text/TextSVGExportMixin.min.mjs.map +1 -1
- package/dist/src/shapes/Text/TextSVGExportMixin.mjs.map +1 -1
- package/dist/src/util/misc/objectEnlive.d.ts +2 -2
- package/dist/src/util/misc/objectEnlive.d.ts.map +1 -1
- package/dist/src/util/misc/objectEnlive.min.mjs.map +1 -1
- package/dist/src/util/misc/objectEnlive.mjs.map +1 -1
- package/package.json +2 -2
- package/src/canvas/Canvas.ts +6 -9
- package/src/canvas/SelectableCanvas.ts +2 -2
- package/src/canvas/StaticCanvas.ts +4 -18
- package/src/color/Color.ts +2 -1
- package/src/color/color.test.ts +6 -0
- package/src/filters/BaseFilter.ts +45 -51
- package/src/filters/BlendColor.ts +13 -35
- package/src/filters/BlendImage.ts +26 -40
- package/src/filters/Blur.ts +13 -20
- package/src/filters/Boilerplate.ts +13 -22
- package/src/filters/Brightness.ts +12 -21
- package/src/filters/Canvas2dFilterBackend.ts +1 -1
- package/src/filters/ColorMatrix.ts +29 -34
- package/src/filters/ColorMatrixFilters.ts +15 -9
- package/src/filters/Composed.ts +26 -16
- package/src/filters/Contrast.ts +15 -23
- package/src/filters/Convolute.ts +11 -23
- package/src/filters/Gamma.ts +32 -24
- package/src/filters/Grayscale.ts +8 -19
- package/src/filters/HueRotation.ts +21 -11
- package/src/filters/Invert.ts +11 -22
- package/src/filters/Noise.ts +11 -30
- package/src/filters/Pixelate.ts +9 -22
- package/src/filters/RemoveColor.ts +21 -35
- package/src/filters/Resize.ts +20 -44
- package/src/filters/Saturation.ts +16 -27
- package/src/filters/Vibrance.ts +14 -24
- package/src/filters/WebGLFilterBackend.ts +1 -1
- package/src/filters/shaders/blendImage.ts +12 -0
- package/src/filters/typedefs.ts +23 -0
- package/src/parser/elements_parser.ts +1 -1
- package/src/shapes/ActiveSelection.ts +8 -4
- package/src/shapes/Group.ts +16 -1
- package/src/shapes/Image.ts +8 -6
- package/src/shapes/Object/InteractiveObject.ts +3 -1
- package/src/shapes/Object/Object.ts +10 -35
- package/src/shapes/Object/StackedObject.ts +28 -44
- package/src/shapes/Path.ts +4 -4
- package/src/shapes/Text/TextSVGExportMixin.ts +1 -1
- package/src/util/misc/objectEnlive.ts +12 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoveColor.d.ts","sourceRoot":"","sources":["../../../src/filters/RemoveColor.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"RemoveColor.d.ts","sourceRoot":"","sources":["../../../src/filters/RemoveColor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAE7E,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,mBAItC,CAAC;AAEF;;;;;;;;;GASG;AACH,qBAAa,WAAY,SAAQ,UAAU,CACzC,aAAa,EACb,mBAAmB,CACpB;IACC;;;;OAIG;IACK,KAAK,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC;IAE5C;;;QAGI;IACI,QAAQ,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAElD;;;QAGI;IACI,QAAQ,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAElD,MAAM,CAAC,IAAI,SAAiB;IAE5B,MAAM,CAAC,QAAQ,sBAA4B;IAE3C,MAAM,CAAC,gBAAgB,WAAqB;IAE5C,iBAAiB;IAIjB;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,gBAAgB;IA4BnD;;;;;OAKG;IACH,eAAe,CACb,EAAE,EAAE,qBAAqB,EACzB,gBAAgB,EAAE,wBAAwB;CAmB7C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{defineProperty as o
|
|
1
|
+
import{defineProperty as o}from"../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{classRegistry as e}from"../ClassRegistry.min.mjs";import{Color as r}from"../color/Color.min.mjs";import{BaseFilter as t}from"./BaseFilter.min.mjs";import{fragmentShader as s}from"./shaders/removeColor.min.mjs";const i={color:"#FFFFFF",distance:.02,useAlpha:!1};class m extends t{getFragmentSource(){return s}applyTo2d(o){let{imageData:{data:e}}=o;const t=255*this.distance,s=new r(this.color).getSource(),i=[s[0]-t,s[1]-t,s[2]-t],m=[s[0]+t,s[1]+t,s[2]+t];for(let o=0;o<e.length;o+=4){const r=e[o],t=e[o+1],s=e[o+2];r>i[0]&&t>i[1]&&s>i[2]&&r<m[0]&&t<m[1]&&s<m[2]&&(e[o+3]=0)}}sendUniformData(o,e){const t=new r(this.color).getSource(),s=this.distance,i=[0+t[0]/255-s,0+t[1]/255-s,0+t[2]/255-s,1],m=[t[0]/255+s,t[1]/255+s,t[2]/255+s,1];o.uniform4fv(e.uLow,i),o.uniform4fv(e.uHigh,m)}}o(m,"type","RemoveColor"),o(m,"defaults",i),o(m,"uniformLocations",["uLow","uHigh"]),e.setClass(m);export{m as RemoveColor,i as removeColorDefaultValues};
|
|
2
2
|
//# sourceMappingURL=RemoveColor.min.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoveColor.min.mjs","sources":["../../../src/filters/RemoveColor.ts"],"sourcesContent":["import { classRegistry } from '../ClassRegistry';\nimport { Color } from '../color/Color';\nimport
|
|
1
|
+
{"version":3,"file":"RemoveColor.min.mjs","sources":["../../../src/filters/RemoveColor.ts"],"sourcesContent":["import { classRegistry } from '../ClassRegistry';\nimport { Color } from '../color/Color';\nimport { BaseFilter } from './BaseFilter';\nimport { fragmentShader } from './shaders/removeColor';\nimport type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';\n\nexport type RemoveColorOwnProps = {\n color: string;\n distance: number;\n useAlpha: boolean;\n};\n\nexport const removeColorDefaultValues: RemoveColorOwnProps = {\n color: '#FFFFFF',\n distance: 0.02,\n useAlpha: false,\n};\n\n/**\n * Remove white filter class\n * @example\n * const filter = new RemoveColor({\n * threshold: 0.2,\n * });\n * object.filters.push(filter);\n * object.applyFilters();\n * canvas.renderAll();\n */\nexport class RemoveColor extends BaseFilter<\n 'RemoveColor',\n RemoveColorOwnProps\n> {\n /**\n * Color to remove, in any format understood by {@link Color}.\n * @param {String} type\n * @default\n */\n declare color: RemoveColorOwnProps['color'];\n\n /**\n * distance to actual color, as value up or down from each r,g,b\n * between 0 and 1\n **/\n declare distance: RemoveColorOwnProps['distance'];\n\n /**\n * For color to remove inside distance, use alpha channel for a smoother deletion\n * NOT IMPLEMENTED YET\n **/\n declare useAlpha: RemoveColorOwnProps['useAlpha'];\n\n static type = 'RemoveColor';\n\n static defaults = removeColorDefaultValues;\n\n static uniformLocations = ['uLow', 'uHigh'];\n\n getFragmentSource() {\n return fragmentShader;\n }\n\n /**\n * Applies filter to canvas element\n * @param {Object} canvasEl Canvas element to apply filter to\n */\n applyTo2d({ imageData: { data } }: T2DPipelineState) {\n const distance = this.distance * 255,\n source = new Color(this.color).getSource(),\n lowC = [source[0] - distance, source[1] - distance, source[2] - distance],\n highC = [\n source[0] + distance,\n source[1] + distance,\n source[2] + distance,\n ];\n\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\n if (\n r > lowC[0] &&\n g > lowC[1] &&\n b > lowC[2] &&\n r < highC[0] &&\n g < highC[1] &&\n b < highC[2]\n ) {\n data[i + 3] = 0;\n }\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 const source = new Color(this.color).getSource(),\n distance = this.distance,\n lowC = [\n 0 + source[0] / 255 - distance,\n 0 + source[1] / 255 - distance,\n 0 + source[2] / 255 - distance,\n 1,\n ],\n highC = [\n source[0] / 255 + distance,\n source[1] / 255 + distance,\n source[2] / 255 + distance,\n 1,\n ];\n gl.uniform4fv(uniformLocations.uLow, lowC);\n gl.uniform4fv(uniformLocations.uHigh, highC);\n }\n}\n\nclassRegistry.setClass(RemoveColor);\n"],"names":["removeColorDefaultValues","color","distance","useAlpha","RemoveColor","BaseFilter","getFragmentSource","fragmentShader","applyTo2d","_ref","imageData","data","this","source","Color","getSource","lowC","highC","i","length","r","g","b","sendUniformData","gl","uniformLocations","uniform4fv","uLow","uHigh","_defineProperty","classRegistry","setClass"],"mappings":"2SAYO,MAAMA,EAAgD,CAC3DC,MAAO,UACPC,SAAU,IACVC,UAAU,GAaL,MAAMC,UAAoBC,EA6B/BC,iBAAAA,GACE,OAAOC,CACT,CAMAC,SAAAA,CAASC,GAA4C,IAAzCC,WAAWC,KAAEA,IAA0BF,EACjD,MAAMP,EAA2B,IAAhBU,KAAKV,SACpBW,EAAS,IAAIC,EAAMF,KAAKX,OAAOc,YAC/BC,EAAO,CAACH,EAAO,GAAKX,EAAUW,EAAO,GAAKX,EAAUW,EAAO,GAAKX,GAChEe,EAAQ,CACNJ,EAAO,GAAKX,EACZW,EAAO,GAAKX,EACZW,EAAO,GAAKX,GAGhB,IAAK,IAAIgB,EAAI,EAAGA,EAAIP,EAAKQ,OAAQD,GAAK,EAAG,CACvC,MAAME,EAAIT,EAAKO,GACTG,EAAIV,EAAKO,EAAI,GACbI,EAAIX,EAAKO,EAAI,GAGjBE,EAAIJ,EAAK,IACTK,EAAIL,EAAK,IACTM,EAAIN,EAAK,IACTI,EAAIH,EAAM,IACVI,EAAIJ,EAAM,IACVK,EAAIL,EAAM,KAEVN,EAAKO,EAAI,GAAK,EAElB,CACF,CAQAK,eAAAA,CACEC,EACAC,GAEA,MAAMZ,EAAS,IAAIC,EAAMF,KAAKX,OAAOc,YACnCb,EAAWU,KAAKV,SAChBc,EAAO,CACL,EAAIH,EAAO,GAAK,IAAMX,EACtB,EAAIW,EAAO,GAAK,IAAMX,EACtB,EAAIW,EAAO,GAAK,IAAMX,EACtB,GAEFe,EAAQ,CACNJ,EAAO,GAAK,IAAMX,EAClBW,EAAO,GAAK,IAAMX,EAClBW,EAAO,GAAK,IAAMX,EAClB,GAEJsB,EAAGE,WAAWD,EAAiBE,KAAMX,GACrCQ,EAAGE,WAAWD,EAAiBG,MAAOX,EACxC,EA1EAY,EAjBWzB,EAAW,OAuBR,eAAayB,EAvBhBzB,EAAW,WAyBJJ,GAAwB6B,EAzB/BzB,EAAW,mBA2BI,CAAC,OAAQ,UAmErC0B,EAAcC,SAAS3B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineProperty as _defineProperty
|
|
1
|
+
import { defineProperty as _defineProperty } from '../../_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
2
|
import { classRegistry } from '../ClassRegistry.mjs';
|
|
3
3
|
import { Color } from '../color/Color.mjs';
|
|
4
4
|
import { BaseFilter } from './BaseFilter.mjs';
|
|
@@ -49,19 +49,6 @@ class RemoveColor extends BaseFilter {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
/**
|
|
53
|
-
* Return WebGL uniform locations for this filter's shader.
|
|
54
|
-
*
|
|
55
|
-
* @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
|
|
56
|
-
* @param {WebGLShaderProgram} program This filter's compiled shader program.
|
|
57
|
-
*/
|
|
58
|
-
getUniformLocations(gl, program) {
|
|
59
|
-
return {
|
|
60
|
-
uLow: gl.getUniformLocation(program, 'uLow'),
|
|
61
|
-
uHigh: gl.getUniformLocation(program, 'uHigh')
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
52
|
/**
|
|
66
53
|
* Send data from this filter to its shader program's uniforms.
|
|
67
54
|
*
|
|
@@ -76,17 +63,6 @@ class RemoveColor extends BaseFilter {
|
|
|
76
63
|
gl.uniform4fv(uniformLocations.uLow, lowC);
|
|
77
64
|
gl.uniform4fv(uniformLocations.uHigh, highC);
|
|
78
65
|
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Returns object representation of an instance
|
|
82
|
-
* @return {Object} Object representation of an instance
|
|
83
|
-
*/
|
|
84
|
-
toObject() {
|
|
85
|
-
return _objectSpread2(_objectSpread2({}, super.toObject()), {}, {
|
|
86
|
-
color: this.color,
|
|
87
|
-
distance: this.distance
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
66
|
}
|
|
91
67
|
/**
|
|
92
68
|
* Color to remove, in any format understood by {@link Color}.
|
|
@@ -103,6 +79,7 @@ class RemoveColor extends BaseFilter {
|
|
|
103
79
|
**/
|
|
104
80
|
_defineProperty(RemoveColor, "type", 'RemoveColor');
|
|
105
81
|
_defineProperty(RemoveColor, "defaults", removeColorDefaultValues);
|
|
82
|
+
_defineProperty(RemoveColor, "uniformLocations", ['uLow', 'uHigh']);
|
|
106
83
|
classRegistry.setClass(RemoveColor);
|
|
107
84
|
|
|
108
85
|
export { RemoveColor, removeColorDefaultValues };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoveColor.mjs","sources":["../../../src/filters/RemoveColor.ts"],"sourcesContent":["import { classRegistry } from '../ClassRegistry';\nimport { Color } from '../color/Color';\nimport
|
|
1
|
+
{"version":3,"file":"RemoveColor.mjs","sources":["../../../src/filters/RemoveColor.ts"],"sourcesContent":["import { classRegistry } from '../ClassRegistry';\nimport { Color } from '../color/Color';\nimport { BaseFilter } from './BaseFilter';\nimport { fragmentShader } from './shaders/removeColor';\nimport type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';\n\nexport type RemoveColorOwnProps = {\n color: string;\n distance: number;\n useAlpha: boolean;\n};\n\nexport const removeColorDefaultValues: RemoveColorOwnProps = {\n color: '#FFFFFF',\n distance: 0.02,\n useAlpha: false,\n};\n\n/**\n * Remove white filter class\n * @example\n * const filter = new RemoveColor({\n * threshold: 0.2,\n * });\n * object.filters.push(filter);\n * object.applyFilters();\n * canvas.renderAll();\n */\nexport class RemoveColor extends BaseFilter<\n 'RemoveColor',\n RemoveColorOwnProps\n> {\n /**\n * Color to remove, in any format understood by {@link Color}.\n * @param {String} type\n * @default\n */\n declare color: RemoveColorOwnProps['color'];\n\n /**\n * distance to actual color, as value up or down from each r,g,b\n * between 0 and 1\n **/\n declare distance: RemoveColorOwnProps['distance'];\n\n /**\n * For color to remove inside distance, use alpha channel for a smoother deletion\n * NOT IMPLEMENTED YET\n **/\n declare useAlpha: RemoveColorOwnProps['useAlpha'];\n\n static type = 'RemoveColor';\n\n static defaults = removeColorDefaultValues;\n\n static uniformLocations = ['uLow', 'uHigh'];\n\n getFragmentSource() {\n return fragmentShader;\n }\n\n /**\n * Applies filter to canvas element\n * @param {Object} canvasEl Canvas element to apply filter to\n */\n applyTo2d({ imageData: { data } }: T2DPipelineState) {\n const distance = this.distance * 255,\n source = new Color(this.color).getSource(),\n lowC = [source[0] - distance, source[1] - distance, source[2] - distance],\n highC = [\n source[0] + distance,\n source[1] + distance,\n source[2] + distance,\n ];\n\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\n if (\n r > lowC[0] &&\n g > lowC[1] &&\n b > lowC[2] &&\n r < highC[0] &&\n g < highC[1] &&\n b < highC[2]\n ) {\n data[i + 3] = 0;\n }\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 const source = new Color(this.color).getSource(),\n distance = this.distance,\n lowC = [\n 0 + source[0] / 255 - distance,\n 0 + source[1] / 255 - distance,\n 0 + source[2] / 255 - distance,\n 1,\n ],\n highC = [\n source[0] / 255 + distance,\n source[1] / 255 + distance,\n source[2] / 255 + distance,\n 1,\n ];\n gl.uniform4fv(uniformLocations.uLow, lowC);\n gl.uniform4fv(uniformLocations.uHigh, highC);\n }\n}\n\nclassRegistry.setClass(RemoveColor);\n"],"names":["removeColorDefaultValues","color","distance","useAlpha","RemoveColor","BaseFilter","getFragmentSource","fragmentShader","applyTo2d","_ref","imageData","data","source","Color","getSource","lowC","highC","i","length","r","g","b","sendUniformData","gl","uniformLocations","uniform4fv","uLow","uHigh","_defineProperty","classRegistry","setClass"],"mappings":";;;;;;AAYO,MAAMA,wBAA6C,GAAG;AAC3DC,EAAAA,KAAK,EAAE,SAAS;AAChBC,EAAAA,QAAQ,EAAE,IAAI;AACdC,EAAAA,QAAQ,EAAE,KAAA;AACZ,EAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,WAAW,SAASC,UAAU,CAGzC;AA0BAC,EAAAA,iBAAiBA,GAAG;AAClB,IAAA,OAAOC,cAAc,CAAA;AACvB,GAAA;;AAEA;AACF;AACA;AACA;EACEC,SAASA,CAAAC,IAAA,EAA4C;IAAA,IAA3C;AAAEC,MAAAA,SAAS,EAAE;AAAEC,QAAAA,IAAAA;AAAK,OAAA;AAAoB,KAAC,GAAAF,IAAA,CAAA;AACjD,IAAA,MAAMP,QAAQ,GAAG,IAAI,CAACA,QAAQ,GAAG,GAAG;MAClCU,MAAM,GAAG,IAAIC,KAAK,CAAC,IAAI,CAACZ,KAAK,CAAC,CAACa,SAAS,EAAE;MAC1CC,IAAI,GAAG,CAACH,MAAM,CAAC,CAAC,CAAC,GAAGV,QAAQ,EAAEU,MAAM,CA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C,CAAC,CAAC,GAAG,GAAG,GAAGV,QAAQ,EAC9B,CAAC,GAAGU,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,GAAGV,QAAQ,EAC9B,CAAC,GAAGU,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,GAAGV,QAAQ,EAC9B,CAAC,CACF;AACDc,MAAAA,KAAK,GAAG,CACNJ,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,GAAGV,QAAQ,EAC1BU,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,GAAGV,QAAQ,EAC1BU,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,GAAGV,QAAQ,EAC1B,CAAC,CACF,CAAA;IACHqB,EAAE,CAACE,UAAU,CAACD,gBAAgB,CAACE,IAAI,EAAEX,IAAI,CAAC,CAAA;IAC1CQ,EAAE,CAACE,UAAU,CAACD,gBAAgB,CAACG,KAAK,EAAEX,KAAK,CAAC,CAAA;AAC9C,GAAA;AACF,CAAA;AAxFE;AACF;AACA;AACA;AACA;AAGE;AACF;AACA;AACA;AAGE;AACF;AACA;AACA;AAHEY,eAAA,CAjBWxB,WAAW,EAAA,MAAA,EAuBR,aAAa,CAAA,CAAA;AAAAwB,eAAA,CAvBhBxB,WAAW,EAAA,UAAA,EAyBJJ,wBAAwB,CAAA,CAAA;AAAA4B,eAAA,CAzB/BxB,WAAW,EAAA,kBAAA,EA2BI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA,CAAA;AAmE7CyB,aAAa,CAACC,QAAQ,CAAC1B,WAAW,CAAC;;;;"}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import type { TClassProperties } from '../typedefs';
|
|
2
1
|
import { BaseFilter } from './BaseFilter';
|
|
3
2
|
import type { T2DPipelineState, TWebGLPipelineState, TWebGLUniformLocationMap } from './typedefs';
|
|
4
|
-
export declare const resizeDefaultValues: Partial<TClassProperties<Resize>>;
|
|
5
3
|
export type TResizeType = 'bilinear' | 'hermite' | 'sliceHack' | 'lanczos';
|
|
4
|
+
export type ResizeOwnProps = {
|
|
5
|
+
resizeType: TResizeType;
|
|
6
|
+
scaleX: number;
|
|
7
|
+
scaleY: number;
|
|
8
|
+
lanczosLobes: number;
|
|
9
|
+
};
|
|
10
|
+
export declare const resizeDefaultValues: ResizeOwnProps;
|
|
6
11
|
type ResizeDuring2DResize = Resize & {
|
|
7
12
|
rcpScaleX: number;
|
|
8
13
|
rcpScaleY: number;
|
|
@@ -25,45 +30,35 @@ type ResizeDuringWEBGLResize = Resize & {
|
|
|
25
30
|
* object.filters.push(filter);
|
|
26
31
|
* object.applyFilters(canvas.renderAll.bind(canvas));
|
|
27
32
|
*/
|
|
28
|
-
export declare class Resize extends BaseFilter {
|
|
33
|
+
export declare class Resize extends BaseFilter<'Resize', ResizeOwnProps> {
|
|
29
34
|
/**
|
|
30
35
|
* Resize type
|
|
31
36
|
* for webgl resizeType is just lanczos, for canvas2d can be:
|
|
32
37
|
* bilinear, hermite, sliceHack, lanczos.
|
|
33
38
|
* @default
|
|
34
39
|
*/
|
|
35
|
-
resizeType:
|
|
40
|
+
resizeType: ResizeOwnProps['resizeType'];
|
|
36
41
|
/**
|
|
37
42
|
* Scale factor for resizing, x axis
|
|
38
43
|
* @param {Number} scaleX
|
|
39
44
|
* @default
|
|
40
45
|
*/
|
|
41
|
-
scaleX:
|
|
46
|
+
scaleX: ResizeOwnProps['scaleX'];
|
|
42
47
|
/**
|
|
43
48
|
* Scale factor for resizing, y axis
|
|
44
49
|
* @param {Number} scaleY
|
|
45
50
|
* @default
|
|
46
51
|
*/
|
|
47
|
-
scaleY:
|
|
52
|
+
scaleY: ResizeOwnProps['scaleY'];
|
|
48
53
|
/**
|
|
49
54
|
* LanczosLobes parameter for lanczos filter, valid for resizeType lanczos
|
|
50
55
|
* @param {Number} lanczosLobes
|
|
51
56
|
* @default
|
|
52
57
|
*/
|
|
53
|
-
lanczosLobes:
|
|
54
|
-
fragmentSourceTOP: string;
|
|
58
|
+
lanczosLobes: ResizeOwnProps['lanczosLobes'];
|
|
55
59
|
static type: string;
|
|
56
|
-
static defaults:
|
|
57
|
-
|
|
58
|
-
* Return WebGL uniform locations for this filter's shader.
|
|
59
|
-
*
|
|
60
|
-
* @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
|
|
61
|
-
* @param {WebGLShaderProgram} program This filter's compiled shader program.
|
|
62
|
-
*/
|
|
63
|
-
getUniformLocations(gl: WebGLRenderingContext, program: WebGLProgram): {
|
|
64
|
-
uDelta: WebGLUniformLocation | null;
|
|
65
|
-
uTaps: WebGLUniformLocation | null;
|
|
66
|
-
};
|
|
60
|
+
static defaults: ResizeOwnProps;
|
|
61
|
+
static uniformLocations: string[];
|
|
67
62
|
/**
|
|
68
63
|
* Send data from this filter to its shader program's uniforms.
|
|
69
64
|
*
|
|
@@ -137,17 +132,6 @@ export declare class Resize extends BaseFilter {
|
|
|
137
132
|
* @returns {ImageData}
|
|
138
133
|
*/
|
|
139
134
|
hermiteFastResize(this: ResizeDuring2DResize, options: T2DPipelineState, oW: number, oH: number, dW: number, dH: number): ImageData;
|
|
140
|
-
/**
|
|
141
|
-
* Returns object representation of an instance
|
|
142
|
-
* @return {Object} Object representation of an instance
|
|
143
|
-
*/
|
|
144
|
-
toObject(): {
|
|
145
|
-
type: string;
|
|
146
|
-
scaleX: number;
|
|
147
|
-
scaleY: number;
|
|
148
|
-
resizeType: TResizeType;
|
|
149
|
-
lanczosLobes: number;
|
|
150
|
-
};
|
|
151
135
|
}
|
|
152
136
|
export {};
|
|
153
137
|
//# sourceMappingURL=Resize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Resize.d.ts","sourceRoot":"","sources":["../../../src/filters/Resize.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Resize.d.ts","sourceRoot":"","sources":["../../../src/filters/Resize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1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AgB,EACzB,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM;CA2Db"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{defineProperty as t}from"../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{BaseFilter as e}from"./BaseFilter.min.mjs";import{isWebGLPipelineState as a}from"./utils.min.mjs";import{classRegistry as s}from"../ClassRegistry.min.mjs";import{createCanvasElement as i}from"../util/misc/dom.min.mjs";const o={resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3
|
|
1
|
+
import{defineProperty as t}from"../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{BaseFilter as e}from"./BaseFilter.min.mjs";import{isWebGLPipelineState as a}from"./utils.min.mjs";import{classRegistry as s}from"../ClassRegistry.min.mjs";import{createCanvasElement as i}from"../util/misc/dom.min.mjs";const o={resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3};class r extends e{sendUniformData(t,e){t.uniform2fv(e.uDelta,this.horizontal?[1/this.width,0]:[0,1/this.height]),t.uniform1fv(e.uTaps,this.taps)}getFilterWindow(){const t=this.tempScale;return Math.ceil(this.lanczosLobes/t)}getCacheKey(){const t=this.getFilterWindow();return"".concat(this.type,"_").concat(t)}getFragmentSource(){const t=this.getFilterWindow();return this.generateShader(t)}getTaps(){const t=this.lanczosCreate(this.lanczosLobes),e=this.tempScale,a=this.getFilterWindow(),s=new Array(a);for(let i=1;i<=a;i++)s[i-1]=t(i*e);return s}generateShader(t){const e=new Array(t);for(let a=1;a<=t;a++)e[a-1]="".concat(a,".0 * uDelta");return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n uniform float uTaps[".concat(t,"];\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float sum = 1.0;\n ").concat(e.map(((t,e)=>"\n color += texture2D(uTexture, vTexCoord + ".concat(t,") * uTaps[").concat(e,"] + texture2D(uTexture, vTexCoord - ").concat(t,") * uTaps[").concat(e,"];\n sum += 2.0 * uTaps[").concat(e,"];\n "))).join("\n"),"\n gl_FragColor = color / sum;\n }\n ")}applyToForWebgl(t){t.passes++,this.width=t.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=t.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),t.destinationWidth=this.dW,super.applyTo(t),t.sourceWidth=t.destinationWidth,this.height=t.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),t.destinationHeight=this.dH,super.applyTo(t),t.sourceHeight=t.destinationHeight}applyTo(t){a(t)?this.applyToForWebgl(t):this.applyTo2d(t)}isNeutralState(){return 1===this.scaleX&&1===this.scaleY}lanczosCreate(t){return e=>{if(e>=t||e<=-t)return 0;if(e<1.1920929e-7&&e>-1.1920929e-7)return 1;const a=(e*=Math.PI)/t;return Math.sin(e)/e*Math.sin(a)/a}}applyTo2d(t){const e=t.imageData,a=this.scaleX,s=this.scaleY;this.rcpScaleX=1/a,this.rcpScaleY=1/s;const i=e.width,o=e.height,r=Math.round(i*a),h=Math.round(o*s);let n;n="sliceHack"===this.resizeType?this.sliceByTwo(t,i,o,r,h):"hermite"===this.resizeType?this.hermiteFastResize(t,i,o,r,h):"bilinear"===this.resizeType?this.bilinearFiltering(t,i,o,r,h):"lanczos"===this.resizeType?this.lanczosResize(t,i,o,r,h):new ImageData(r,h),t.imageData=n}sliceByTwo(t,e,a,s,o){const r=t.imageData,h=.5;let n=!1,c=!1,l=e*h,u=a*h;const p=t.filterBackend.resources;let m=0,d=0;const f=e;let g=0;p.sliceByTwo||(p.sliceByTwo=i());const M=p.sliceByTwo;(M.width<1.5*e||M.height<a)&&(M.width=1.5*e,M.height=a);const T=M.getContext("2d");for(T.clearRect(0,0,1.5*e,a),T.putImageData(r,0,0),s=Math.floor(s),o=Math.floor(o);!n||!c;)e=l,a=u,s<Math.floor(l*h)?l=Math.floor(l*h):(l=s,n=!0),o<Math.floor(u*h)?u=Math.floor(u*h):(u=o,c=!0),T.drawImage(M,m,d,e,a,f,g,l,u),m=f,d=g,g+=u;return T.getImageData(m,d,s,o)}lanczosResize(t,e,a,s,i){const o=t.imageData.data,r=t.ctx.createImageData(s,i),h=r.data,n=this.lanczosCreate(this.lanczosLobes),c=this.rcpScaleX,l=this.rcpScaleY,u=2/this.rcpScaleX,p=2/this.rcpScaleY,m=Math.ceil(c*this.lanczosLobes/2),d=Math.ceil(l*this.lanczosLobes/2),f={},g={x:0,y:0},M={x:0,y:0};return function t(T){let y,x,z,w,D,S,b,F,W,v,C;for(g.x=(T+.5)*c,M.x=Math.floor(g.x),y=0;y<i;y++){for(g.y=(y+.5)*l,M.y=Math.floor(g.y),D=0,S=0,b=0,F=0,W=0,x=M.x-m;x<=M.x+m;x++)if(!(x<0||x>=e)){v=Math.floor(1e3*Math.abs(x-g.x)),f[v]||(f[v]={});for(let t=M.y-d;t<=M.y+d;t++)t<0||t>=a||(C=Math.floor(1e3*Math.abs(t-g.y)),f[v][C]||(f[v][C]=n(Math.sqrt(Math.pow(v*u,2)+Math.pow(C*p,2))/1e3)),z=f[v][C],z>0&&(w=4*(t*e+x),D+=z,S+=z*o[w],b+=z*o[w+1],F+=z*o[w+2],W+=z*o[w+3]))}w=4*(y*s+T),h[w]=S/D,h[w+1]=b/D,h[w+2]=F/D,h[w+3]=W/D}return++T<s?t(T):r}(0)}bilinearFiltering(t,e,a,s,i){let o,r,h,n,c,l,u,p,m,d,f,g,M,T=0;const y=this.rcpScaleX,x=this.rcpScaleY,z=4*(e-1),w=t.imageData.data,D=t.ctx.createImageData(s,i),S=D.data;for(u=0;u<i;u++)for(p=0;p<s;p++)for(c=Math.floor(y*p),l=Math.floor(x*u),m=y*p-c,d=x*u-l,M=4*(l*e+c),f=0;f<4;f++)o=w[M+f],r=w[M+4+f],h=w[M+z+f],n=w[M+z+4+f],g=o*(1-m)*(1-d)+r*m*(1-d)+h*d*(1-m)+n*m*d,S[T++]=g;return D}hermiteFastResize(t,e,a,s,i){const o=this.rcpScaleX,r=this.rcpScaleY,h=Math.ceil(o/2),n=Math.ceil(r/2),c=t.imageData.data,l=t.ctx.createImageData(s,i),u=l.data;for(let t=0;t<i;t++)for(let a=0;a<s;a++){const i=4*(a+t*s);let l=0,p=0,m=0,d=0,f=0,g=0,M=0;const T=(t+.5)*r;for(let s=Math.floor(t*r);s<(t+1)*r;s++){const t=Math.abs(T-(s+.5))/n,i=(a+.5)*o,r=t*t;for(let t=Math.floor(a*o);t<(a+1)*o;t++){let a=Math.abs(i-(t+.5))/h;const o=Math.sqrt(r+a*a);o>1&&o<-1||(l=2*o*o*o-3*o*o+1,l>0&&(a=4*(t+s*e),M+=l*c[a+3],m+=l,c[a+3]<255&&(l=l*c[a+3]/250),d+=l*c[a],f+=l*c[a+1],g+=l*c[a+2],p+=l))}}u[i]=d/p,u[i+1]=f/p,u[i+2]=g/p,u[i+3]=M/m}return l}}t(r,"type","Resize"),t(r,"defaults",o),t(r,"uniformLocations",["uDelta","uTaps"]),s.setClass(r);export{r as Resize,o as resizeDefaultValues};
|
|
2
2
|
//# sourceMappingURL=Resize.min.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Resize.min.mjs","sources":["../../../src/filters/Resize.ts"],"sourcesContent":["import type { TClassProperties } from '../typedefs';\nimport { BaseFilter } from './BaseFilter';\nimport type {\n T2DPipelineState,\n TWebGLPipelineState,\n TWebGLUniformLocationMap,\n} from './typedefs';\nimport { isWebGLPipelineState } from './utils';\nimport { classRegistry } from '../ClassRegistry';\nimport { createCanvasElement } from '../util/misc/dom';\nimport type { XY } from '../Point';\n\nexport const resizeDefaultValues: Partial<TClassProperties<Resize>> = {\n resizeType: 'hermite',\n scaleX: 1,\n scaleY: 1,\n lanczosLobes: 3,\n fragmentSourceTOP: `\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n `,\n};\n\nexport type TResizeType = 'bilinear' | 'hermite' | 'sliceHack' | 'lanczos';\n\ntype ResizeDuring2DResize = Resize & {\n rcpScaleX: number;\n rcpScaleY: number;\n};\n\ntype ResizeDuringWEBGLResize = Resize & {\n rcpScaleX: number;\n rcpScaleY: number;\n horizontal: boolean;\n width: number;\n height: number;\n taps: number[];\n tempScale: number;\n dH: number;\n dW: number;\n};\n\n/**\n * Resize image filter class\n * @example\n * const filter = new Resize();\n * object.filters.push(filter);\n * object.applyFilters(canvas.renderAll.bind(canvas));\n */\nexport class Resize extends BaseFilter {\n /**\n * Resize type\n * for webgl resizeType is just lanczos, for canvas2d can be:\n * bilinear, hermite, sliceHack, lanczos.\n * @default\n */\n declare resizeType: TResizeType;\n\n /**\n * Scale factor for resizing, x axis\n * @param {Number} scaleX\n * @default\n */\n declare scaleX: number;\n\n /**\n * Scale factor for resizing, y axis\n * @param {Number} scaleY\n * @default\n */\n declare scaleY: number;\n\n /**\n * LanczosLobes parameter for lanczos filter, valid for resizeType lanczos\n * @param {Number} lanczosLobes\n * @default\n */\n declare lanczosLobes: number;\n\n declare fragmentSourceTOP: string;\n\n static type = 'Resize';\n\n static defaults = resizeDefaultValues;\n\n /**\n * Return WebGL uniform locations for this filter's shader.\n *\n * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.\n * @param {WebGLShaderProgram} program This filter's compiled shader program.\n */\n getUniformLocations(gl: WebGLRenderingContext, program: WebGLProgram) {\n return {\n uDelta: gl.getUniformLocation(program, 'uDelta'),\n uTaps: gl.getUniformLocation(program, 'uTaps'),\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 this: ResizeDuringWEBGLResize,\n gl: WebGLRenderingContext,\n uniformLocations: TWebGLUniformLocationMap\n ) {\n gl.uniform2fv(\n uniformLocations.uDelta,\n this.horizontal ? [1 / this.width, 0] : [0, 1 / this.height]\n );\n gl.uniform1fv(uniformLocations.uTaps, this.taps);\n }\n\n getFilterWindow(this: ResizeDuringWEBGLResize) {\n const scale = this.tempScale;\n return Math.ceil(this.lanczosLobes / scale);\n }\n\n getCacheKey(this: ResizeDuringWEBGLResize): string {\n const filterWindow = this.getFilterWindow();\n return `${this.type}_${filterWindow}`;\n }\n\n getFragmentSource(this: ResizeDuringWEBGLResize): string {\n const filterWindow = this.getFilterWindow();\n return this.generateShader(filterWindow);\n }\n\n getTaps(this: ResizeDuringWEBGLResize) {\n const lobeFunction = this.lanczosCreate(this.lanczosLobes),\n scale = this.tempScale,\n filterWindow = this.getFilterWindow(),\n taps = new Array(filterWindow);\n for (let i = 1; i <= filterWindow; i++) {\n taps[i - 1] = lobeFunction(i * scale);\n }\n return taps;\n }\n\n /**\n * Generate vertex and shader sources from the necessary steps numbers\n * @param {Number} filterWindow\n */\n generateShader(filterWindow: number) {\n const offsets = new Array(filterWindow);\n for (let i = 1; i <= filterWindow; i++) {\n offsets[i - 1] = `${i}.0 * uDelta`;\n }\n return `\n ${this.fragmentSourceTOP}\n uniform float uTaps[${filterWindow}];\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float sum = 1.0;\n ${offsets\n .map(\n (offset, i) => `\n color += texture2D(uTexture, vTexCoord + ${offset}) * uTaps[${i}] + texture2D(uTexture, vTexCoord - ${offset}) * uTaps[${i}];\n sum += 2.0 * uTaps[${i}];\n `\n )\n .join('\\n')}\n gl_FragColor = color / sum;\n }\n `;\n }\n\n applyToForWebgl(this: ResizeDuringWEBGLResize, options: TWebGLPipelineState) {\n options.passes++;\n this.width = options.sourceWidth;\n this.horizontal = true;\n this.dW = Math.round(this.width * this.scaleX);\n this.dH = options.sourceHeight;\n this.tempScale = this.dW / this.width;\n this.taps = this.getTaps();\n options.destinationWidth = this.dW;\n super.applyTo(options);\n options.sourceWidth = options.destinationWidth;\n\n this.height = options.sourceHeight;\n this.horizontal = false;\n this.dH = Math.round(this.height * this.scaleY);\n this.tempScale = this.dH / this.height;\n this.taps = this.getTaps();\n options.destinationHeight = this.dH;\n super.applyTo(options);\n options.sourceHeight = options.destinationHeight;\n }\n\n /**\n * Apply the resize filter to the image\n * Determines whether to use WebGL or Canvas2D based on the options.webgl flag.\n *\n * @param {Object} options\n * @param {Number} options.passes The number of filters remaining to be executed\n * @param {Boolean} options.webgl Whether to use webgl to render the filter.\n * @param {WebGLTexture} options.sourceTexture The texture setup as the source to be filtered.\n * @param {WebGLTexture} options.targetTexture The texture where filtered output should be drawn.\n * @param {WebGLRenderingContext} options.context The GL context used for rendering.\n * @param {Object} options.programCache A map of compiled shader programs, keyed by filter type.\n */\n applyTo(options: TWebGLPipelineState | T2DPipelineState) {\n if (isWebGLPipelineState(options)) {\n (this as unknown as ResizeDuringWEBGLResize).applyToForWebgl(options);\n } else {\n (this as unknown as ResizeDuring2DResize).applyTo2d(options);\n }\n }\n\n isNeutralState() {\n return this.scaleX === 1 && this.scaleY === 1;\n }\n\n lanczosCreate(lobes: number) {\n return (x: number) => {\n if (x >= lobes || x <= -lobes) {\n return 0.0;\n }\n if (x < 1.1920929e-7 && x > -1.1920929e-7) {\n return 1.0;\n }\n x *= Math.PI;\n const xx = x / lobes;\n return ((Math.sin(x) / x) * Math.sin(xx)) / xx;\n };\n }\n\n applyTo2d(this: ResizeDuring2DResize, options: T2DPipelineState) {\n const imageData = options.imageData,\n scaleX = this.scaleX,\n scaleY = this.scaleY;\n\n this.rcpScaleX = 1 / scaleX;\n this.rcpScaleY = 1 / scaleY;\n\n const oW = imageData.width;\n const oH = imageData.height;\n const dW = Math.round(oW * scaleX);\n const dH = Math.round(oH * scaleY);\n let newData: ImageData;\n\n if (this.resizeType === 'sliceHack') {\n newData = this.sliceByTwo(options, oW, oH, dW, dH);\n } else if (this.resizeType === 'hermite') {\n newData = this.hermiteFastResize(options, oW, oH, dW, dH);\n } else if (this.resizeType === 'bilinear') {\n newData = this.bilinearFiltering(options, oW, oH, dW, dH);\n } else if (this.resizeType === 'lanczos') {\n newData = this.lanczosResize(options, oW, oH, dW, dH);\n } else {\n // this should never trigger, is here just for safety net.\n newData = new ImageData(dW, dH);\n }\n options.imageData = newData;\n }\n\n /**\n * Filter sliceByTwo\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n sliceByTwo(\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number\n ) {\n const imageData = options.imageData;\n const mult = 0.5;\n let doneW = false;\n let doneH = false;\n let stepW = oW * mult;\n let stepH = oH * mult;\n const resources = options.filterBackend.resources;\n let sX = 0;\n let sY = 0;\n const dX = oW;\n let dY = 0;\n if (!resources.sliceByTwo) {\n resources.sliceByTwo = createCanvasElement();\n }\n const tmpCanvas = resources.sliceByTwo;\n if (tmpCanvas.width < oW * 1.5 || tmpCanvas.height < oH) {\n tmpCanvas.width = oW * 1.5;\n tmpCanvas.height = oH;\n }\n const ctx = tmpCanvas.getContext('2d')!;\n ctx.clearRect(0, 0, oW * 1.5, oH);\n ctx.putImageData(imageData, 0, 0);\n\n dW = Math.floor(dW);\n dH = Math.floor(dH);\n\n while (!doneW || !doneH) {\n oW = stepW;\n oH = stepH;\n if (dW < Math.floor(stepW * mult)) {\n stepW = Math.floor(stepW * mult);\n } else {\n stepW = dW;\n doneW = true;\n }\n if (dH < Math.floor(stepH * mult)) {\n stepH = Math.floor(stepH * mult);\n } else {\n stepH = dH;\n doneH = true;\n }\n ctx.drawImage(tmpCanvas, sX, sY, oW, oH, dX, dY, stepW, stepH);\n sX = dX;\n sY = dY;\n dY += stepH;\n }\n return ctx.getImageData(sX, sY, dW, dH);\n }\n\n /**\n * Filter lanczosResize\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n lanczosResize(\n this: ResizeDuring2DResize,\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number\n ): ImageData {\n function process(u: number): ImageData {\n let v, i, weight, idx, a, red, green, blue, alpha, fX, fY;\n center.x = (u + 0.5) * ratioX;\n icenter.x = Math.floor(center.x);\n for (v = 0; v < dH; v++) {\n center.y = (v + 0.5) * ratioY;\n icenter.y = Math.floor(center.y);\n a = 0;\n red = 0;\n green = 0;\n blue = 0;\n alpha = 0;\n for (i = icenter.x - range2X; i <= icenter.x + range2X; i++) {\n if (i < 0 || i >= oW) {\n continue;\n }\n fX = Math.floor(1000 * Math.abs(i - center.x));\n if (!cacheLanc[fX]) {\n cacheLanc[fX] = {};\n }\n for (let j = icenter.y - range2Y; j <= icenter.y + range2Y; j++) {\n if (j < 0 || j >= oH) {\n continue;\n }\n fY = Math.floor(1000 * Math.abs(j - center.y));\n if (!cacheLanc[fX][fY]) {\n cacheLanc[fX][fY] = lanczos(\n Math.sqrt(\n Math.pow(fX * rcpRatioX, 2) + Math.pow(fY * rcpRatioY, 2)\n ) / 1000\n );\n }\n weight = cacheLanc[fX][fY];\n if (weight > 0) {\n idx = (j * oW + i) * 4;\n a += weight;\n red += weight * srcData[idx];\n green += weight * srcData[idx + 1];\n blue += weight * srcData[idx + 2];\n alpha += weight * srcData[idx + 3];\n }\n }\n }\n idx = (v * dW + u) * 4;\n destData[idx] = red / a;\n destData[idx + 1] = green / a;\n destData[idx + 2] = blue / a;\n destData[idx + 3] = alpha / a;\n }\n\n if (++u < dW) {\n return process(u);\n } else {\n return destImg;\n }\n }\n\n const srcData = options.imageData.data,\n destImg = options.ctx.createImageData(dW, dH),\n destData = destImg.data,\n lanczos = this.lanczosCreate(this.lanczosLobes),\n ratioX = this.rcpScaleX,\n ratioY = this.rcpScaleY,\n rcpRatioX = 2 / this.rcpScaleX,\n rcpRatioY = 2 / this.rcpScaleY,\n range2X = Math.ceil((ratioX * this.lanczosLobes) / 2),\n range2Y = Math.ceil((ratioY * this.lanczosLobes) / 2),\n cacheLanc: Record<number, Record<number, number>> = {},\n center: XY = { x: 0, y: 0 },\n icenter: XY = { x: 0, y: 0 };\n\n return process(0);\n }\n\n /**\n * bilinearFiltering\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n bilinearFiltering(\n this: ResizeDuring2DResize,\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number\n ) {\n let a;\n let b;\n let c;\n let d;\n let x;\n let y;\n let i;\n let j;\n let xDiff;\n let yDiff;\n let chnl;\n let color;\n let offset = 0;\n let origPix;\n const ratioX = this.rcpScaleX;\n const ratioY = this.rcpScaleY;\n const w4 = 4 * (oW - 1);\n const img = options.imageData;\n const pixels = img.data;\n const destImage = options.ctx.createImageData(dW, dH);\n const destPixels = destImage.data;\n for (i = 0; i < dH; i++) {\n for (j = 0; j < dW; j++) {\n x = Math.floor(ratioX * j);\n y = Math.floor(ratioY * i);\n xDiff = ratioX * j - x;\n yDiff = ratioY * i - y;\n origPix = 4 * (y * oW + x);\n\n for (chnl = 0; chnl < 4; chnl++) {\n a = pixels[origPix + chnl];\n b = pixels[origPix + 4 + chnl];\n c = pixels[origPix + w4 + chnl];\n d = pixels[origPix + w4 + 4 + chnl];\n color =\n a * (1 - xDiff) * (1 - yDiff) +\n b * xDiff * (1 - yDiff) +\n c * yDiff * (1 - xDiff) +\n d * xDiff * yDiff;\n destPixels[offset++] = color;\n }\n }\n }\n return destImage;\n }\n\n /**\n * hermiteFastResize\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n hermiteFastResize(\n this: ResizeDuring2DResize,\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number\n ) {\n const ratioW = this.rcpScaleX,\n ratioH = this.rcpScaleY,\n ratioWHalf = Math.ceil(ratioW / 2),\n ratioHHalf = Math.ceil(ratioH / 2),\n img = options.imageData,\n data = img.data,\n img2 = options.ctx.createImageData(dW, dH),\n data2 = img2.data;\n for (let j = 0; j < dH; j++) {\n for (let i = 0; i < dW; i++) {\n const x2 = (i + j * dW) * 4;\n let weight = 0;\n let weights = 0;\n let weightsAlpha = 0;\n let gxR = 0;\n let gxG = 0;\n let gxB = 0;\n let gxA = 0;\n const centerY = (j + 0.5) * ratioH;\n for (let yy = Math.floor(j * ratioH); yy < (j + 1) * ratioH; yy++) {\n const dy = Math.abs(centerY - (yy + 0.5)) / ratioHHalf,\n centerX = (i + 0.5) * ratioW,\n w0 = dy * dy;\n for (let xx = Math.floor(i * ratioW); xx < (i + 1) * ratioW; xx++) {\n let dx = Math.abs(centerX - (xx + 0.5)) / ratioWHalf;\n const w = Math.sqrt(w0 + dx * dx);\n /* eslint-disable max-depth */\n if (w > 1 && w < -1) {\n continue;\n }\n //hermite filter\n weight = 2 * w * w * w - 3 * w * w + 1;\n if (weight > 0) {\n dx = 4 * (xx + yy * oW);\n //alpha\n gxA += weight * data[dx + 3];\n weightsAlpha += weight;\n //colors\n if (data[dx + 3] < 255) {\n weight = (weight * data[dx + 3]) / 250;\n }\n gxR += weight * data[dx];\n gxG += weight * data[dx + 1];\n gxB += weight * data[dx + 2];\n weights += weight;\n }\n /* eslint-enable max-depth */\n }\n }\n data2[x2] = gxR / weights;\n data2[x2 + 1] = gxG / weights;\n data2[x2 + 2] = gxB / weights;\n data2[x2 + 3] = gxA / weightsAlpha;\n }\n }\n return img2;\n }\n\n /**\n * Returns object representation of an instance\n * @return {Object} Object representation of an instance\n */\n toObject() {\n return {\n type: this.type,\n scaleX: this.scaleX,\n scaleY: this.scaleY,\n resizeType: this.resizeType,\n lanczosLobes: this.lanczosLobes,\n };\n }\n}\n\nclassRegistry.setClass(Resize);\n"],"names":["resizeDefaultValues","resizeType","scaleX","scaleY","lanczosLobes","fragmentSourceTOP","Resize","BaseFilter","getUniformLocations","gl","program","uDelta","getUniformLocation","uTaps","sendUniformData","uniformLocations","uniform2fv","this","horizontal","width","height","uniform1fv","taps","getFilterWindow","scale","tempScale","Math","ceil","getCacheKey","filterWindow","concat","type","getFragmentSource","generateShader","getTaps","lobeFunction","lanczosCreate","Array","i","offsets","map","offset","join","applyToForWebgl","options","passes","sourceWidth","dW","round","dH","sourceHeight","destinationWidth","super","applyTo","destinationHeight","isWebGLPipelineState","applyTo2d","isNeutralState","lobes","x","xx","PI","sin","imageData","rcpScaleX","rcpScaleY","oW","oH","newData","sliceByTwo","hermiteFastResize","bilinearFiltering","lanczosResize","ImageData","mult","doneW","doneH","stepW","stepH","resources","filterBackend","sX","sY","dX","dY","createCanvasElement","tmpCanvas","ctx","getContext","clearRect","putImageData","floor","drawImage","getImageData","srcData","data","destImg","createImageData","destData","lanczos","ratioX","ratioY","rcpRatioX","rcpRatioY","range2X","range2Y","cacheLanc","center","y","icenter","process","u","v","weight","idx","a","red","green","blue","alpha","fX","fY","abs","j","sqrt","pow","b","c","d","xDiff","yDiff","chnl","color","origPix","w4","pixels","destImage","destPixels","ratioW","ratioH","ratioWHalf","ratioHHalf","img2","data2","x2","weights","weightsAlpha","gxR","gxG","gxB","gxA","centerY","yy","dy","centerX","w0","dx","w","toObject","_defineProperty","classRegistry","setClass"],"mappings":"mTAYO,MAAMA,EAAyD,CACpEC,WAAY,UACZC,OAAQ,EACRC,OAAQ,EACRC,aAAc,EACdC,kBAAiB,4HAkCZ,MAAMC,UAAeC,EA0C1BC,mBAAAA,CAAoBC,EAA2BC,GAC7C,MAAO,CACLC,OAAQF,EAAGG,mBAAmBF,EAAS,UACvCG,MAAOJ,EAAGG,mBAAmBF,EAAS,SAE1C,CAQAI,eAAAA,CAEEL,EACAM,GAEAN,EAAGO,WACDD,EAAiBJ,OACjBM,KAAKC,WAAa,CAAC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"Resize.min.mjs","sources":["../../../src/filters/Resize.ts"],"sourcesContent":["import { BaseFilter } from './BaseFilter';\nimport type {\n T2DPipelineState,\n TWebGLPipelineState,\n TWebGLUniformLocationMap,\n} from './typedefs';\nimport { isWebGLPipelineState } from './utils';\nimport { classRegistry } from '../ClassRegistry';\nimport { createCanvasElement } from '../util/misc/dom';\nimport type { XY } from '../Point';\n\nexport type TResizeType = 'bilinear' | 'hermite' | 'sliceHack' | 'lanczos';\n\nexport type ResizeOwnProps = {\n resizeType: TResizeType;\n scaleX: number;\n scaleY: number;\n lanczosLobes: number;\n};\n\nexport const resizeDefaultValues: ResizeOwnProps = {\n resizeType: 'hermite',\n scaleX: 1,\n scaleY: 1,\n lanczosLobes: 3,\n};\n\ntype ResizeDuring2DResize = Resize & {\n rcpScaleX: number;\n rcpScaleY: number;\n};\n\ntype ResizeDuringWEBGLResize = Resize & {\n rcpScaleX: number;\n rcpScaleY: number;\n horizontal: boolean;\n width: number;\n height: number;\n taps: number[];\n tempScale: number;\n dH: number;\n dW: number;\n};\n\n/**\n * Resize image filter class\n * @example\n * const filter = new Resize();\n * object.filters.push(filter);\n * object.applyFilters(canvas.renderAll.bind(canvas));\n */\nexport class Resize extends BaseFilter<'Resize', ResizeOwnProps> {\n /**\n * Resize type\n * for webgl resizeType is just lanczos, for canvas2d can be:\n * bilinear, hermite, sliceHack, lanczos.\n * @default\n */\n declare resizeType: ResizeOwnProps['resizeType'];\n\n /**\n * Scale factor for resizing, x axis\n * @param {Number} scaleX\n * @default\n */\n declare scaleX: ResizeOwnProps['scaleX'];\n\n /**\n * Scale factor for resizing, y axis\n * @param {Number} scaleY\n * @default\n */\n declare scaleY: ResizeOwnProps['scaleY'];\n\n /**\n * LanczosLobes parameter for lanczos filter, valid for resizeType lanczos\n * @param {Number} lanczosLobes\n * @default\n */\n declare lanczosLobes: ResizeOwnProps['lanczosLobes'];\n\n static type = 'Resize';\n\n static defaults = resizeDefaultValues;\n\n static uniformLocations = ['uDelta', 'uTaps'];\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 this: ResizeDuringWEBGLResize,\n gl: WebGLRenderingContext,\n uniformLocations: TWebGLUniformLocationMap\n ) {\n gl.uniform2fv(\n uniformLocations.uDelta,\n this.horizontal ? [1 / this.width, 0] : [0, 1 / this.height]\n );\n gl.uniform1fv(uniformLocations.uTaps, this.taps);\n }\n\n getFilterWindow(this: ResizeDuringWEBGLResize) {\n const scale = this.tempScale;\n return Math.ceil(this.lanczosLobes / scale);\n }\n\n getCacheKey(this: ResizeDuringWEBGLResize): string {\n const filterWindow = this.getFilterWindow();\n return `${this.type}_${filterWindow}`;\n }\n\n getFragmentSource(this: ResizeDuringWEBGLResize): string {\n const filterWindow = this.getFilterWindow();\n return this.generateShader(filterWindow);\n }\n\n getTaps(this: ResizeDuringWEBGLResize) {\n const lobeFunction = this.lanczosCreate(this.lanczosLobes),\n scale = this.tempScale,\n filterWindow = this.getFilterWindow(),\n taps = new Array(filterWindow);\n for (let i = 1; i <= filterWindow; i++) {\n taps[i - 1] = lobeFunction(i * scale);\n }\n return taps;\n }\n\n /**\n * Generate vertex and shader sources from the necessary steps numbers\n * @param {Number} filterWindow\n */\n generateShader(filterWindow: number) {\n const offsets = new Array(filterWindow);\n for (let i = 1; i <= filterWindow; i++) {\n offsets[i - 1] = `${i}.0 * uDelta`;\n }\n return `\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n uniform float uTaps[${filterWindow}];\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float sum = 1.0;\n ${offsets\n .map(\n (offset, i) => `\n color += texture2D(uTexture, vTexCoord + ${offset}) * uTaps[${i}] + texture2D(uTexture, vTexCoord - ${offset}) * uTaps[${i}];\n sum += 2.0 * uTaps[${i}];\n `\n )\n .join('\\n')}\n gl_FragColor = color / sum;\n }\n `;\n }\n\n applyToForWebgl(this: ResizeDuringWEBGLResize, options: TWebGLPipelineState) {\n options.passes++;\n this.width = options.sourceWidth;\n this.horizontal = true;\n this.dW = Math.round(this.width * this.scaleX);\n this.dH = options.sourceHeight;\n this.tempScale = this.dW / this.width;\n this.taps = this.getTaps();\n options.destinationWidth = this.dW;\n super.applyTo(options);\n options.sourceWidth = options.destinationWidth;\n\n this.height = options.sourceHeight;\n this.horizontal = false;\n this.dH = Math.round(this.height * this.scaleY);\n this.tempScale = this.dH / this.height;\n this.taps = this.getTaps();\n options.destinationHeight = this.dH;\n super.applyTo(options);\n options.sourceHeight = options.destinationHeight;\n }\n\n /**\n * Apply the resize filter to the image\n * Determines whether to use WebGL or Canvas2D based on the options.webgl flag.\n *\n * @param {Object} options\n * @param {Number} options.passes The number of filters remaining to be executed\n * @param {Boolean} options.webgl Whether to use webgl to render the filter.\n * @param {WebGLTexture} options.sourceTexture The texture setup as the source to be filtered.\n * @param {WebGLTexture} options.targetTexture The texture where filtered output should be drawn.\n * @param {WebGLRenderingContext} options.context The GL context used for rendering.\n * @param {Object} options.programCache A map of compiled shader programs, keyed by filter type.\n */\n applyTo(options: TWebGLPipelineState | T2DPipelineState) {\n if (isWebGLPipelineState(options)) {\n (this as unknown as ResizeDuringWEBGLResize).applyToForWebgl(options);\n } else {\n (this as unknown as ResizeDuring2DResize).applyTo2d(options);\n }\n }\n\n isNeutralState() {\n return this.scaleX === 1 && this.scaleY === 1;\n }\n\n lanczosCreate(lobes: number) {\n return (x: number) => {\n if (x >= lobes || x <= -lobes) {\n return 0.0;\n }\n if (x < 1.1920929e-7 && x > -1.1920929e-7) {\n return 1.0;\n }\n x *= Math.PI;\n const xx = x / lobes;\n return ((Math.sin(x) / x) * Math.sin(xx)) / xx;\n };\n }\n\n applyTo2d(this: ResizeDuring2DResize, options: T2DPipelineState) {\n const imageData = options.imageData,\n scaleX = this.scaleX,\n scaleY = this.scaleY;\n\n this.rcpScaleX = 1 / scaleX;\n this.rcpScaleY = 1 / scaleY;\n\n const oW = imageData.width;\n const oH = imageData.height;\n const dW = Math.round(oW * scaleX);\n const dH = Math.round(oH * scaleY);\n let newData: ImageData;\n\n if (this.resizeType === 'sliceHack') {\n newData = this.sliceByTwo(options, oW, oH, dW, dH);\n } else if (this.resizeType === 'hermite') {\n newData = this.hermiteFastResize(options, oW, oH, dW, dH);\n } else if (this.resizeType === 'bilinear') {\n newData = this.bilinearFiltering(options, oW, oH, dW, dH);\n } else if (this.resizeType === 'lanczos') {\n newData = this.lanczosResize(options, oW, oH, dW, dH);\n } else {\n // this should never trigger, is here just for safety net.\n newData = new ImageData(dW, dH);\n }\n options.imageData = newData;\n }\n\n /**\n * Filter sliceByTwo\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n sliceByTwo(\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number\n ) {\n const imageData = options.imageData;\n const mult = 0.5;\n let doneW = false;\n let doneH = false;\n let stepW = oW * mult;\n let stepH = oH * mult;\n const resources = options.filterBackend.resources;\n let sX = 0;\n let sY = 0;\n const dX = oW;\n let dY = 0;\n if (!resources.sliceByTwo) {\n resources.sliceByTwo = createCanvasElement();\n }\n const tmpCanvas = resources.sliceByTwo;\n if (tmpCanvas.width < oW * 1.5 || tmpCanvas.height < oH) {\n tmpCanvas.width = oW * 1.5;\n tmpCanvas.height = oH;\n }\n const ctx = tmpCanvas.getContext('2d')!;\n ctx.clearRect(0, 0, oW * 1.5, oH);\n ctx.putImageData(imageData, 0, 0);\n\n dW = Math.floor(dW);\n dH = Math.floor(dH);\n\n while (!doneW || !doneH) {\n oW = stepW;\n oH = stepH;\n if (dW < Math.floor(stepW * mult)) {\n stepW = Math.floor(stepW * mult);\n } else {\n stepW = dW;\n doneW = true;\n }\n if (dH < Math.floor(stepH * mult)) {\n stepH = Math.floor(stepH * mult);\n } else {\n stepH = dH;\n doneH = true;\n }\n ctx.drawImage(tmpCanvas, sX, sY, oW, oH, dX, dY, stepW, stepH);\n sX = dX;\n sY = dY;\n dY += stepH;\n }\n return ctx.getImageData(sX, sY, dW, dH);\n }\n\n /**\n * Filter lanczosResize\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n lanczosResize(\n this: ResizeDuring2DResize,\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number\n ): ImageData {\n function process(u: number): ImageData {\n let v, i, weight, idx, a, red, green, blue, alpha, fX, fY;\n center.x = (u + 0.5) * ratioX;\n icenter.x = Math.floor(center.x);\n for (v = 0; v < dH; v++) {\n center.y = (v + 0.5) * ratioY;\n icenter.y = Math.floor(center.y);\n a = 0;\n red = 0;\n green = 0;\n blue = 0;\n alpha = 0;\n for (i = icenter.x - range2X; i <= icenter.x + range2X; i++) {\n if (i < 0 || i >= oW) {\n continue;\n }\n fX = Math.floor(1000 * Math.abs(i - center.x));\n if (!cacheLanc[fX]) {\n cacheLanc[fX] = {};\n }\n for (let j = icenter.y - range2Y; j <= icenter.y + range2Y; j++) {\n if (j < 0 || j >= oH) {\n continue;\n }\n fY = Math.floor(1000 * Math.abs(j - center.y));\n if (!cacheLanc[fX][fY]) {\n cacheLanc[fX][fY] = lanczos(\n Math.sqrt(\n Math.pow(fX * rcpRatioX, 2) + Math.pow(fY * rcpRatioY, 2)\n ) / 1000\n );\n }\n weight = cacheLanc[fX][fY];\n if (weight > 0) {\n idx = (j * oW + i) * 4;\n a += weight;\n red += weight * srcData[idx];\n green += weight * srcData[idx + 1];\n blue += weight * srcData[idx + 2];\n alpha += weight * srcData[idx + 3];\n }\n }\n }\n idx = (v * dW + u) * 4;\n destData[idx] = red / a;\n destData[idx + 1] = green / a;\n destData[idx + 2] = blue / a;\n destData[idx + 3] = alpha / a;\n }\n\n if (++u < dW) {\n return process(u);\n } else {\n return destImg;\n }\n }\n\n const srcData = options.imageData.data,\n destImg = options.ctx.createImageData(dW, dH),\n destData = destImg.data,\n lanczos = this.lanczosCreate(this.lanczosLobes),\n ratioX = this.rcpScaleX,\n ratioY = this.rcpScaleY,\n rcpRatioX = 2 / this.rcpScaleX,\n rcpRatioY = 2 / this.rcpScaleY,\n range2X = Math.ceil((ratioX * this.lanczosLobes) / 2),\n range2Y = Math.ceil((ratioY * this.lanczosLobes) / 2),\n cacheLanc: Record<number, Record<number, number>> = {},\n center: XY = { x: 0, y: 0 },\n icenter: XY = { x: 0, y: 0 };\n\n return process(0);\n }\n\n /**\n * bilinearFiltering\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n bilinearFiltering(\n this: ResizeDuring2DResize,\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number\n ) {\n let a;\n let b;\n let c;\n let d;\n let x;\n let y;\n let i;\n let j;\n let xDiff;\n let yDiff;\n let chnl;\n let color;\n let offset = 0;\n let origPix;\n const ratioX = this.rcpScaleX;\n const ratioY = this.rcpScaleY;\n const w4 = 4 * (oW - 1);\n const img = options.imageData;\n const pixels = img.data;\n const destImage = options.ctx.createImageData(dW, dH);\n const destPixels = destImage.data;\n for (i = 0; i < dH; i++) {\n for (j = 0; j < dW; j++) {\n x = Math.floor(ratioX * j);\n y = Math.floor(ratioY * i);\n xDiff = ratioX * j - x;\n yDiff = ratioY * i - y;\n origPix = 4 * (y * oW + x);\n\n for (chnl = 0; chnl < 4; chnl++) {\n a = pixels[origPix + chnl];\n b = pixels[origPix + 4 + chnl];\n c = pixels[origPix + w4 + chnl];\n d = pixels[origPix + w4 + 4 + chnl];\n color =\n a * (1 - xDiff) * (1 - yDiff) +\n b * xDiff * (1 - yDiff) +\n c * yDiff * (1 - xDiff) +\n d * xDiff * yDiff;\n destPixels[offset++] = color;\n }\n }\n }\n return destImage;\n }\n\n /**\n * hermiteFastResize\n * @param {Object} canvasEl Canvas element to apply filter to\n * @param {Number} oW Original Width\n * @param {Number} oH Original Height\n * @param {Number} dW Destination Width\n * @param {Number} dH Destination Height\n * @returns {ImageData}\n */\n hermiteFastResize(\n this: ResizeDuring2DResize,\n options: T2DPipelineState,\n oW: number,\n oH: number,\n dW: number,\n dH: number\n ) {\n const ratioW = this.rcpScaleX,\n ratioH = this.rcpScaleY,\n ratioWHalf = Math.ceil(ratioW / 2),\n ratioHHalf = Math.ceil(ratioH / 2),\n img = options.imageData,\n data = img.data,\n img2 = options.ctx.createImageData(dW, dH),\n data2 = img2.data;\n for (let j = 0; j < dH; j++) {\n for (let i = 0; i < dW; i++) {\n const x2 = (i + j * dW) * 4;\n let weight = 0;\n let weights = 0;\n let weightsAlpha = 0;\n let gxR = 0;\n let gxG = 0;\n let gxB = 0;\n let gxA = 0;\n const centerY = (j + 0.5) * ratioH;\n for (let yy = Math.floor(j * ratioH); yy < (j + 1) * ratioH; yy++) {\n const dy = Math.abs(centerY - (yy + 0.5)) / ratioHHalf,\n centerX = (i + 0.5) * ratioW,\n w0 = dy * dy;\n for (let xx = Math.floor(i * ratioW); xx < (i + 1) * ratioW; xx++) {\n let dx = Math.abs(centerX - (xx + 0.5)) / ratioWHalf;\n const w = Math.sqrt(w0 + dx * dx);\n /* eslint-disable max-depth */\n if (w > 1 && w < -1) {\n continue;\n }\n //hermite filter\n weight = 2 * w * w * w - 3 * w * w + 1;\n if (weight > 0) {\n dx = 4 * (xx + yy * oW);\n //alpha\n gxA += weight * data[dx + 3];\n weightsAlpha += weight;\n //colors\n if (data[dx + 3] < 255) {\n weight = (weight * data[dx + 3]) / 250;\n }\n gxR += weight * data[dx];\n gxG += weight * data[dx + 1];\n gxB += weight * data[dx + 2];\n weights += weight;\n }\n /* eslint-enable max-depth */\n }\n }\n data2[x2] = gxR / weights;\n data2[x2 + 1] = gxG / weights;\n data2[x2 + 2] = gxB / weights;\n data2[x2 + 3] = gxA / weightsAlpha;\n }\n }\n return img2;\n }\n}\n\nclassRegistry.setClass(Resize);\n"],"names":["resizeDefaultValues","resizeType","scaleX","scaleY","lanczosLobes","Resize","BaseFilter","sendUniformData","gl","uniformLocations","uniform2fv","uDelta","this","horizontal","width","height","uniform1fv","uTaps","taps","getFilterWindow","scale","tempScale","Math","ceil","getCacheKey","filterWindow","concat","type","getFragmentSource","generateShader","getTaps","lobeFunction","lanczosCreate","Array","i","offsets","map","offset","join","applyToForWebgl","options","passes","sourceWidth","dW","round","dH","sourceHeight","destinationWidth","super","applyTo","destinationHeight","isWebGLPipelineState","applyTo2d","isNeutralState","lobes","x","xx","PI","sin","imageData","rcpScaleX","rcpScaleY","oW","oH","newData","sliceByTwo","hermiteFastResize","bilinearFiltering","lanczosResize","ImageData","mult","doneW","doneH","stepW","stepH","resources","filterBackend","sX","sY","dX","dY","createCanvasElement","tmpCanvas","ctx","getContext","clearRect","putImageData","floor","drawImage","getImageData","srcData","data","destImg","createImageData","destData","lanczos","ratioX","ratioY","rcpRatioX","rcpRatioY","range2X","range2Y","cacheLanc","center","y","icenter","process","u","v","weight","idx","a","red","green","blue","alpha","fX","fY","abs","j","sqrt","pow","b","c","d","xDiff","yDiff","chnl","color","origPix","w4","pixels","destImage","destPixels","ratioW","ratioH","ratioWHalf","ratioHHalf","img2","data2","x2","weights","weightsAlpha","gxR","gxG","gxB","gxA","centerY","yy","dy","centerX","w0","dx","w","_defineProperty","classRegistry","setClass"],"mappings":"mTAoBO,MAAMA,EAAsC,CACjDC,WAAY,UACZC,OAAQ,EACRC,OAAQ,EACRC,aAAc,GA2BT,MAAMC,UAAeC,EA0C1BC,eAAAA,CAEEC,EACAC,GAEAD,EAAGE,WACDD,EAAiBE,OACjBC,KAAKC,WAAa,CAAC,EAAID,KAAKE,MAAO,GAAK,CAAC,EAAG,EAAIF,KAAKG,S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KAAQX,EAC1Ca,GAAWpH,EAAI,IAAOoG,EACtBiB,EAAKF,EAAKA,EACZ,IAAK,IAAI7F,EAAKlC,KAAKiE,MAAMrD,EAAIoG,GAAS9E,GAAMtB,EAAI,GAAKoG,EAAQ9E,IAAM,CACjE,IAAIgG,EAAKlI,KAAKgG,IAAIgC,GAAW9F,EAAK,KAAQgF,EAC1C,MAAMiB,EAAInI,KAAKkG,KAAK+B,EAAKC,EAAKA,GAE1BC,EAAI,GAAKA,GAAK,IAIlB5C,EAAS,EAAI4C,EAAIA,EAAIA,EAAI,EAAIA,EAAIA,EAAI,EACjC5C,EAAS,IACX2C,EAAK,GAAKhG,EAAK4F,EAAKtF,GAEpBoF,GAAOrC,EAASlB,EAAK6D,EAAK,GAC1BV,GAAgBjC,EAEZlB,EAAK6D,EAAK,GAAK,MACjB3C,EAAUA,EAASlB,EAAK6D,EAAK,GAAM,KAErCT,GAAOlC,EAASlB,EAAK6D,GACrBR,GAAOnC,EAASlB,EAAK6D,EAAK,GAC1BP,GAAOpC,EAASlB,EAAK6D,EAAK,GAC1BX,GAAWhC,GAGf,CACF,CACA8B,EAAMC,GAAMG,EAAMF,EAClBF,EAAMC,EAAK,GAAKI,EAAMH,EACtBF,EAAMC,EAAK,GAAKK,EAAMJ,EACtBF,EAAMC,EAAK,GAAKM,EAAMJ,CACxB,CAEF,OAAOJ,CACT,EArdAgB,EAvBWrJ,EAAM,OA8BH,UAAQqJ,EA9BXrJ,EAAM,WAgCCL,GAAmB0J,EAhC1BrJ,EAAM,mBAkCS,CAAC,SAAU,UA6cvCsJ,EAAcC,SAASvJ"}
|
|
@@ -8,8 +8,7 @@ const resizeDefaultValues = {
|
|
|
8
8
|
resizeType: 'hermite',
|
|
9
9
|
scaleX: 1,
|
|
10
10
|
scaleY: 1,
|
|
11
|
-
lanczosLobes: 3
|
|
12
|
-
fragmentSourceTOP: "\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n "
|
|
11
|
+
lanczosLobes: 3
|
|
13
12
|
};
|
|
14
13
|
/**
|
|
15
14
|
* Resize image filter class
|
|
@@ -19,19 +18,6 @@ const resizeDefaultValues = {
|
|
|
19
18
|
* object.applyFilters(canvas.renderAll.bind(canvas));
|
|
20
19
|
*/
|
|
21
20
|
class Resize extends BaseFilter {
|
|
22
|
-
/**
|
|
23
|
-
* Return WebGL uniform locations for this filter's shader.
|
|
24
|
-
*
|
|
25
|
-
* @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
|
|
26
|
-
* @param {WebGLShaderProgram} program This filter's compiled shader program.
|
|
27
|
-
*/
|
|
28
|
-
getUniformLocations(gl, program) {
|
|
29
|
-
return {
|
|
30
|
-
uDelta: gl.getUniformLocation(program, 'uDelta'),
|
|
31
|
-
uTaps: gl.getUniformLocation(program, 'uTaps')
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
21
|
/**
|
|
36
22
|
* Send data from this filter to its shader program's uniforms.
|
|
37
23
|
*
|
|
@@ -74,7 +60,7 @@ class Resize extends BaseFilter {
|
|
|
74
60
|
for (let i = 1; i <= filterWindow; i++) {
|
|
75
61
|
offsets[i - 1] = "".concat(i, ".0 * uDelta");
|
|
76
62
|
}
|
|
77
|
-
return "\n
|
|
63
|
+
return "\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n uniform float uTaps[".concat(filterWindow, "];\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float sum = 1.0;\n ").concat(offsets.map((offset, i) => "\n color += texture2D(uTexture, vTexCoord + ".concat(offset, ") * uTaps[").concat(i, "] + texture2D(uTexture, vTexCoord - ").concat(offset, ") * uTaps[").concat(i, "];\n sum += 2.0 * uTaps[").concat(i, "];\n ")).join('\n'), "\n gl_FragColor = color / sum;\n }\n ");
|
|
78
64
|
}
|
|
79
65
|
applyToForWebgl(options) {
|
|
80
66
|
options.passes++;
|
|
@@ -417,20 +403,6 @@ class Resize extends BaseFilter {
|
|
|
417
403
|
}
|
|
418
404
|
return img2;
|
|
419
405
|
}
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Returns object representation of an instance
|
|
423
|
-
* @return {Object} Object representation of an instance
|
|
424
|
-
*/
|
|
425
|
-
toObject() {
|
|
426
|
-
return {
|
|
427
|
-
type: this.type,
|
|
428
|
-
scaleX: this.scaleX,
|
|
429
|
-
scaleY: this.scaleY,
|
|
430
|
-
resizeType: this.resizeType,
|
|
431
|
-
lanczosLobes: this.lanczosLobes
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
406
|
}
|
|
435
407
|
/**
|
|
436
408
|
* Resize type
|
|
@@ -455,6 +427,7 @@ class Resize extends BaseFilter {
|
|
|
455
427
|
*/
|
|
456
428
|
_defineProperty(Resize, "type", 'Resize');
|
|
457
429
|
_defineProperty(Resize, "defaults", resizeDefaultValues);
|
|
430
|
+
_defineProperty(Resize, "uniformLocations", ['uDelta', 'uTaps']);
|
|
458
431
|
classRegistry.setClass(Resize);
|
|
459
432
|
|
|
460
433
|
export { Resize, resizeDefaultValues };
|