@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
package/src/filters/Composed.ts
CHANGED
|
@@ -3,23 +3,29 @@ import type { T2DPipelineState, TWebGLPipelineState } from './typedefs';
|
|
|
3
3
|
import { isWebGLPipelineState } from './utils';
|
|
4
4
|
import { classRegistry } from '../ClassRegistry';
|
|
5
5
|
|
|
6
|
+
type ComposedOwnProps = {
|
|
7
|
+
subFilters: BaseFilter<string, object>[];
|
|
8
|
+
};
|
|
9
|
+
|
|
6
10
|
/**
|
|
7
11
|
* A container class that knows how to apply a sequence of filters to an input image.
|
|
8
12
|
*/
|
|
9
|
-
export class Composed extends BaseFilter {
|
|
13
|
+
export class Composed extends BaseFilter<'Composed', ComposedOwnProps> {
|
|
10
14
|
/**
|
|
11
15
|
* A non sparse array of filters to apply
|
|
12
16
|
*/
|
|
13
|
-
declare subFilters:
|
|
17
|
+
declare subFilters: ComposedOwnProps['subFilters'];
|
|
14
18
|
|
|
15
19
|
static type = 'Composed';
|
|
16
20
|
|
|
17
|
-
constructor(
|
|
18
|
-
subFilters
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
constructor(
|
|
22
|
+
options: { subFilters?: BaseFilter<string, object>[] } & Record<
|
|
23
|
+
string,
|
|
24
|
+
any
|
|
25
|
+
> = {}
|
|
26
|
+
) {
|
|
21
27
|
super(options);
|
|
22
|
-
this.subFilters = subFilters;
|
|
28
|
+
this.subFilters = options.subFilters || [];
|
|
23
29
|
}
|
|
24
30
|
|
|
25
31
|
/**
|
|
@@ -39,12 +45,15 @@ export class Composed extends BaseFilter {
|
|
|
39
45
|
|
|
40
46
|
/**
|
|
41
47
|
* Serialize this filter into JSON.
|
|
42
|
-
*
|
|
43
48
|
* @returns {Object} A JSON representation of this filter.
|
|
44
49
|
*/
|
|
45
|
-
toObject
|
|
50
|
+
//@ts-expect-error TS doesn't like this toObject
|
|
51
|
+
toObject(): {
|
|
52
|
+
type: 'Composed';
|
|
53
|
+
subFilters: ReturnType<BaseFilter<string, object>['toObject']>[];
|
|
54
|
+
} {
|
|
46
55
|
return {
|
|
47
|
-
|
|
56
|
+
type: this.type,
|
|
48
57
|
subFilters: this.subFilters.map((filter) => filter.toObject()),
|
|
49
58
|
};
|
|
50
59
|
}
|
|
@@ -64,15 +73,16 @@ export class Composed extends BaseFilter {
|
|
|
64
73
|
static fromObject(
|
|
65
74
|
object: Record<string, any>,
|
|
66
75
|
options: { signal: AbortSignal }
|
|
67
|
-
) {
|
|
76
|
+
): Promise<Composed> {
|
|
68
77
|
return Promise.all(
|
|
69
|
-
((object.subFilters || []) as BaseFilter[]).map(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
((object.subFilters || []) as BaseFilter<string, object>[]).map(
|
|
79
|
+
(filter) =>
|
|
80
|
+
classRegistry
|
|
81
|
+
.getClass<typeof BaseFilter>(filter.type)
|
|
82
|
+
.fromObject(filter, options)
|
|
73
83
|
)
|
|
74
84
|
).then(
|
|
75
|
-
(enlivedFilters) => new this({ subFilters: enlivedFilters }) as
|
|
85
|
+
(enlivedFilters) => new this({ subFilters: enlivedFilters }) as Composed
|
|
76
86
|
);
|
|
77
87
|
}
|
|
78
88
|
}
|
package/src/filters/Contrast.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import type { TClassProperties } from '../typedefs';
|
|
2
1
|
import { BaseFilter } from './BaseFilter';
|
|
3
2
|
import type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';
|
|
4
3
|
import { classRegistry } from '../ClassRegistry';
|
|
5
4
|
import { fragmentSource } from './shaders/constrast';
|
|
6
|
-
|
|
5
|
+
|
|
6
|
+
type ContrastOwnProps = {
|
|
7
|
+
contrast: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const contrastDefaultValues: ContrastOwnProps = {
|
|
7
11
|
contrast: 0,
|
|
8
|
-
mainParameter: 'contrast',
|
|
9
12
|
};
|
|
10
13
|
|
|
11
14
|
/**
|
|
@@ -17,21 +20,28 @@ export const contrastDefaultValues: Partial<TClassProperties<Contrast>> = {
|
|
|
17
20
|
* object.filters.push(filter);
|
|
18
21
|
* object.applyFilters();
|
|
19
22
|
*/
|
|
20
|
-
export class Contrast extends BaseFilter {
|
|
23
|
+
export class Contrast extends BaseFilter<'Contrast', ContrastOwnProps> {
|
|
21
24
|
/**
|
|
22
25
|
* contrast value, range from -1 to 1.
|
|
23
26
|
* @param {Number} contrast
|
|
24
27
|
* @default 0
|
|
25
28
|
*/
|
|
26
|
-
declare contrast:
|
|
29
|
+
declare contrast: ContrastOwnProps['contrast'];
|
|
27
30
|
|
|
28
31
|
static type = 'Contrast';
|
|
29
32
|
|
|
30
33
|
static defaults = contrastDefaultValues;
|
|
31
34
|
|
|
35
|
+
static uniformLocations = ['uContrast'];
|
|
36
|
+
|
|
32
37
|
getFragmentSource() {
|
|
33
38
|
return fragmentSource;
|
|
34
39
|
}
|
|
40
|
+
|
|
41
|
+
isNeutralState() {
|
|
42
|
+
return this.contrast === 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
35
45
|
/**
|
|
36
46
|
* Apply the Contrast operation to a Uint8Array representing the pixels of an image.
|
|
37
47
|
*
|
|
@@ -39,9 +49,6 @@ export class Contrast extends BaseFilter {
|
|
|
39
49
|
* @param {ImageData} options.imageData The Uint8Array to be filtered.
|
|
40
50
|
*/
|
|
41
51
|
applyTo2d({ imageData: { data } }: T2DPipelineState) {
|
|
42
|
-
if (this.contrast === 0) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
52
|
const contrast = Math.floor(this.contrast * 255),
|
|
46
53
|
contrastF = (259 * (contrast + 255)) / (255 * (259 - contrast));
|
|
47
54
|
|
|
@@ -52,21 +59,6 @@ export class Contrast extends BaseFilter {
|
|
|
52
59
|
}
|
|
53
60
|
}
|
|
54
61
|
|
|
55
|
-
/**
|
|
56
|
-
* Return WebGL uniform locations for this filter's shader.
|
|
57
|
-
*
|
|
58
|
-
* @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
|
|
59
|
-
* @param {WebGLShaderProgram} program This filter's compiled shader program.
|
|
60
|
-
*/
|
|
61
|
-
getUniformLocations(
|
|
62
|
-
gl: WebGLRenderingContext,
|
|
63
|
-
program: WebGLProgram
|
|
64
|
-
): TWebGLUniformLocationMap {
|
|
65
|
-
return {
|
|
66
|
-
uContrast: gl.getUniformLocation(program, 'uContrast'),
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
62
|
/**
|
|
71
63
|
* Send data from this filter to its shader program's uniforms.
|
|
72
64
|
*
|
package/src/filters/Convolute.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import type { TClassProperties } from '../typedefs';
|
|
2
1
|
import { BaseFilter } from './BaseFilter';
|
|
3
2
|
import type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';
|
|
4
3
|
import { classRegistry } from '../ClassRegistry';
|
|
5
4
|
import { fragmentSource } from './shaders/convolute';
|
|
6
5
|
|
|
7
|
-
export
|
|
6
|
+
export type ConvoluteOwnProps = {
|
|
7
|
+
opaque: boolean;
|
|
8
|
+
matrix: number[];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const convoluteDefaultValues: ConvoluteOwnProps = {
|
|
8
12
|
opaque: false,
|
|
9
13
|
matrix: [0, 0, 0, 0, 1, 0, 0, 0, 0],
|
|
10
14
|
};
|
|
@@ -49,21 +53,23 @@ export const convoluteDefaultValues: Partial<TClassProperties<Convolute>> = {
|
|
|
49
53
|
* object.applyFilters();
|
|
50
54
|
* canvas.renderAll();
|
|
51
55
|
*/
|
|
52
|
-
export class Convolute extends BaseFilter {
|
|
56
|
+
export class Convolute extends BaseFilter<'Convolute', ConvoluteOwnProps> {
|
|
53
57
|
/*
|
|
54
58
|
* Opaque value (true/false)
|
|
55
59
|
*/
|
|
56
|
-
declare opaque:
|
|
60
|
+
declare opaque: ConvoluteOwnProps['opaque'];
|
|
57
61
|
|
|
58
62
|
/*
|
|
59
63
|
* matrix for the filter, max 9x9
|
|
60
64
|
*/
|
|
61
|
-
declare matrix:
|
|
65
|
+
declare matrix: ConvoluteOwnProps['matrix'];
|
|
62
66
|
|
|
63
67
|
static type = 'Convolute';
|
|
64
68
|
|
|
65
69
|
static defaults = convoluteDefaultValues;
|
|
66
70
|
|
|
71
|
+
static uniformLocations = ['uMatrix', 'uOpaque', 'uHalfSize', 'uSize'];
|
|
72
|
+
|
|
67
73
|
getCacheKey() {
|
|
68
74
|
return `${this.type}_${Math.sqrt(this.matrix.length)}_${
|
|
69
75
|
this.opaque ? 1 : 0
|
|
@@ -139,24 +145,6 @@ export class Convolute extends BaseFilter {
|
|
|
139
145
|
options.imageData = output;
|
|
140
146
|
}
|
|
141
147
|
|
|
142
|
-
/**
|
|
143
|
-
* Return WebGL uniform locations for this filter's shader.
|
|
144
|
-
*
|
|
145
|
-
* @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
|
|
146
|
-
* @param {WebGLShaderProgram} program This filter's compiled shader program.
|
|
147
|
-
*/
|
|
148
|
-
getUniformLocations(
|
|
149
|
-
gl: WebGLRenderingContext,
|
|
150
|
-
program: WebGLProgram
|
|
151
|
-
): TWebGLUniformLocationMap {
|
|
152
|
-
return {
|
|
153
|
-
uMatrix: gl.getUniformLocation(program, 'uMatrix'),
|
|
154
|
-
uOpaque: gl.getUniformLocation(program, 'uOpaque'),
|
|
155
|
-
uHalfSize: gl.getUniformLocation(program, 'uHalfSize'),
|
|
156
|
-
uSize: gl.getUniformLocation(program, 'uSize'),
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
148
|
/**
|
|
161
149
|
* Send data from this filter to its shader program's uniforms.
|
|
162
150
|
*
|
package/src/filters/Gamma.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import type { TClassProperties } from '../typedefs';
|
|
2
1
|
import { BaseFilter } from './BaseFilter';
|
|
3
|
-
import type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';
|
|
4
2
|
import { classRegistry } from '../ClassRegistry';
|
|
5
3
|
import { fragmentSource } from './shaders/gamma';
|
|
4
|
+
import type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';
|
|
5
|
+
|
|
6
|
+
const GAMMA = 'Gamma' as const;
|
|
7
|
+
|
|
6
8
|
export type GammaInput = [number, number, number];
|
|
7
9
|
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
+
export type GammaOwnProps = {
|
|
11
|
+
gamma: GammaInput;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const gammaDefaultValues: GammaOwnProps = {
|
|
10
15
|
gamma: [1, 1, 1],
|
|
11
16
|
};
|
|
12
17
|
|
|
@@ -19,30 +24,36 @@ export const gammaDefaultValues: Partial<TClassProperties<Gamma>> = {
|
|
|
19
24
|
* object.filters.push(filter);
|
|
20
25
|
* object.applyFilters();
|
|
21
26
|
*/
|
|
22
|
-
export class Gamma extends BaseFilter {
|
|
27
|
+
export class Gamma extends BaseFilter<typeof GAMMA, GammaOwnProps> {
|
|
23
28
|
/**
|
|
24
29
|
* Gamma array value, from 0.01 to 2.2.
|
|
25
30
|
* @param {Array} gamma
|
|
26
31
|
* @default
|
|
27
32
|
*/
|
|
28
|
-
declare gamma:
|
|
33
|
+
declare gamma: GammaOwnProps['gamma'];
|
|
29
34
|
declare rgbValues?: {
|
|
30
35
|
r: Uint8Array;
|
|
31
36
|
g: Uint8Array;
|
|
32
37
|
b: Uint8Array;
|
|
33
38
|
};
|
|
34
39
|
|
|
35
|
-
static type =
|
|
40
|
+
static type = GAMMA;
|
|
36
41
|
|
|
37
42
|
static defaults = gammaDefaultValues;
|
|
38
43
|
|
|
44
|
+
static uniformLocations = ['uGamma'];
|
|
45
|
+
|
|
39
46
|
getFragmentSource() {
|
|
40
47
|
return fragmentSource;
|
|
41
48
|
}
|
|
42
49
|
|
|
43
|
-
constructor(
|
|
50
|
+
constructor(options: { gamma?: GammaInput } = {}) {
|
|
44
51
|
super(options);
|
|
45
|
-
this.gamma =
|
|
52
|
+
this.gamma =
|
|
53
|
+
options.gamma ||
|
|
54
|
+
((
|
|
55
|
+
this.constructor as typeof Gamma
|
|
56
|
+
).defaults.gamma.concat() as GammaInput);
|
|
46
57
|
}
|
|
47
58
|
|
|
48
59
|
/**
|
|
@@ -80,21 +91,6 @@ export class Gamma extends BaseFilter {
|
|
|
80
91
|
}
|
|
81
92
|
}
|
|
82
93
|
|
|
83
|
-
/**
|
|
84
|
-
* Return WebGL uniform locations for this filter's shader.
|
|
85
|
-
*
|
|
86
|
-
* @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
|
|
87
|
-
* @param {WebGLShaderProgram} program This filter's compiled shader program.
|
|
88
|
-
*/
|
|
89
|
-
getUniformLocations(
|
|
90
|
-
gl: WebGLRenderingContext,
|
|
91
|
-
program: WebGLProgram
|
|
92
|
-
): TWebGLUniformLocationMap {
|
|
93
|
-
return {
|
|
94
|
-
uGamma: gl.getUniformLocation(program, 'uGamma'),
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
94
|
/**
|
|
99
95
|
* Send data from this filter to its shader program's uniforms.
|
|
100
96
|
*
|
|
@@ -107,6 +103,18 @@ export class Gamma extends BaseFilter {
|
|
|
107
103
|
) {
|
|
108
104
|
gl.uniform3fv(uniformLocations.uGamma, this.gamma);
|
|
109
105
|
}
|
|
106
|
+
|
|
107
|
+
isNeutralState() {
|
|
108
|
+
const { gamma } = this;
|
|
109
|
+
return gamma[0] === 1 && gamma[1] === 1 && gamma[2] === 1;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
toObject(): { type: typeof GAMMA; gamma: GammaInput } {
|
|
113
|
+
return {
|
|
114
|
+
type: GAMMA,
|
|
115
|
+
gamma: this.gamma.concat() as GammaInput,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
110
118
|
}
|
|
111
119
|
|
|
112
120
|
classRegistry.setClass(Gamma);
|
package/src/filters/Grayscale.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { TClassProperties } from '../typedefs';
|
|
2
1
|
import { BaseFilter } from './BaseFilter';
|
|
3
2
|
import type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';
|
|
4
3
|
import { classRegistry } from '../ClassRegistry';
|
|
@@ -6,9 +5,12 @@ import { fragmentSource } from './shaders/grayscale';
|
|
|
6
5
|
|
|
7
6
|
export type TGrayscaleMode = 'average' | 'lightness' | 'luminosity';
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
type GrayscaleOwnProps = {
|
|
9
|
+
mode: TGrayscaleMode;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const grayscaleDefaultValues: GrayscaleOwnProps = {
|
|
10
13
|
mode: 'average',
|
|
11
|
-
mainParameter: 'mode',
|
|
12
14
|
};
|
|
13
15
|
|
|
14
16
|
/**
|
|
@@ -18,13 +20,15 @@ export const grayscaleDefaultValues: Partial<TClassProperties<Grayscale>> = {
|
|
|
18
20
|
* object.filters.push(filter);
|
|
19
21
|
* object.applyFilters();
|
|
20
22
|
*/
|
|
21
|
-
export class Grayscale extends BaseFilter {
|
|
23
|
+
export class Grayscale extends BaseFilter<'Grayscale', GrayscaleOwnProps> {
|
|
22
24
|
declare mode: TGrayscaleMode;
|
|
23
25
|
|
|
24
26
|
static type = 'Grayscale';
|
|
25
27
|
|
|
26
28
|
static defaults = grayscaleDefaultValues;
|
|
27
29
|
|
|
30
|
+
static uniformLocations = ['uMode'];
|
|
31
|
+
|
|
28
32
|
/**
|
|
29
33
|
* Apply the Grayscale operation to a Uint8Array representing the pixels of an image.
|
|
30
34
|
*
|
|
@@ -62,21 +66,6 @@ export class Grayscale extends BaseFilter {
|
|
|
62
66
|
return fragmentSource[this.mode];
|
|
63
67
|
}
|
|
64
68
|
|
|
65
|
-
/**
|
|
66
|
-
* Return WebGL uniform locations for this filter's shader.
|
|
67
|
-
*
|
|
68
|
-
* @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
|
|
69
|
-
* @param {WebGLShaderProgram} program This filter's compiled shader program.
|
|
70
|
-
*/
|
|
71
|
-
getUniformLocations(
|
|
72
|
-
gl: WebGLRenderingContext,
|
|
73
|
-
program: WebGLProgram
|
|
74
|
-
): TWebGLUniformLocationMap {
|
|
75
|
-
return {
|
|
76
|
-
uMode: gl.getUniformLocation(program, 'uMode'),
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
69
|
/**
|
|
81
70
|
* Send data from this filter to its shader program's uniforms.
|
|
82
71
|
*
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import type { TClassProperties } from '../typedefs';
|
|
2
1
|
import { cos } from '../util/misc/cos';
|
|
3
2
|
import { sin } from '../util/misc/sin';
|
|
4
3
|
import { ColorMatrix } from './ColorMatrix';
|
|
5
4
|
import type { TWebGLPipelineState, T2DPipelineState } from './typedefs';
|
|
6
5
|
import { classRegistry } from '../ClassRegistry';
|
|
7
6
|
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
export type HueRotationOwnProps = {
|
|
8
|
+
rotation: number;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const hueRotationDefaultValues: HueRotationOwnProps = {
|
|
12
|
+
rotation: 0,
|
|
13
|
+
};
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* HueRotation filter class
|
|
@@ -20,12 +21,14 @@ export const hueRotationDefaultValues: Partial<TClassProperties<HueRotation>> =
|
|
|
20
21
|
* object.filters.push(filter);
|
|
21
22
|
* object.applyFilters();
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
export class HueRotation extends ColorMatrix<
|
|
25
|
+
'HueRotation',
|
|
26
|
+
HueRotationOwnProps
|
|
27
|
+
> {
|
|
25
28
|
/**
|
|
26
29
|
* HueRotation value, from -1 to 1.
|
|
27
30
|
*/
|
|
28
|
-
declare rotation:
|
|
31
|
+
declare rotation: HueRotationOwnProps['rotation'];
|
|
29
32
|
|
|
30
33
|
static type = 'HueRotation';
|
|
31
34
|
|
|
@@ -51,14 +54,21 @@ export class HueRotation extends ColorMatrix {
|
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
isNeutralState() {
|
|
54
|
-
this.
|
|
55
|
-
return super.isNeutralState();
|
|
57
|
+
return this.rotation === 0;
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
applyTo(options: TWebGLPipelineState | T2DPipelineState) {
|
|
59
61
|
this.calculateMatrix();
|
|
60
62
|
super.applyTo(options);
|
|
61
63
|
}
|
|
64
|
+
|
|
65
|
+
//@ts-expect-error TS and classes with different methods
|
|
66
|
+
toObject(): { type: 'HueRotation'; rotation: number } {
|
|
67
|
+
return {
|
|
68
|
+
type: this.type,
|
|
69
|
+
rotation: this.rotation,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
62
72
|
}
|
|
63
73
|
|
|
64
74
|
classRegistry.setClass(HueRotation);
|
package/src/filters/Invert.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import type { TClassProperties } from '../typedefs';
|
|
2
1
|
import { BaseFilter } from './BaseFilter';
|
|
3
2
|
import type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';
|
|
4
3
|
import { classRegistry } from '../ClassRegistry';
|
|
5
4
|
import { fragmentSource } from './shaders/invert';
|
|
6
5
|
|
|
7
|
-
export
|
|
6
|
+
export type InvertOwnProps = {
|
|
7
|
+
alpha: boolean;
|
|
8
|
+
invert: boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const invertDefaultValues: InvertOwnProps = {
|
|
8
12
|
alpha: false,
|
|
9
13
|
invert: true,
|
|
10
|
-
mainParameter: 'invert',
|
|
11
14
|
};
|
|
12
15
|
|
|
13
16
|
/**
|
|
@@ -16,25 +19,27 @@ export const invertDefaultValues: Partial<TClassProperties<Invert>> = {
|
|
|
16
19
|
* object.filters.push(filter);
|
|
17
20
|
* object.applyFilters(canvas.renderAll.bind(canvas));
|
|
18
21
|
*/
|
|
19
|
-
export class Invert extends BaseFilter {
|
|
22
|
+
export class Invert extends BaseFilter<'Invert', InvertOwnProps> {
|
|
20
23
|
/**
|
|
21
24
|
* Invert also alpha.
|
|
22
25
|
* @param {Boolean} alpha
|
|
23
26
|
* @default
|
|
24
27
|
**/
|
|
25
|
-
declare alpha:
|
|
28
|
+
declare alpha: InvertOwnProps['alpha'];
|
|
26
29
|
|
|
27
30
|
/**
|
|
28
31
|
* Filter invert. if false, does nothing
|
|
29
32
|
* @param {Boolean} invert
|
|
30
33
|
* @default
|
|
31
34
|
*/
|
|
32
|
-
declare invert:
|
|
35
|
+
declare invert: InvertOwnProps['invert'];
|
|
33
36
|
|
|
34
37
|
static type = 'Invert';
|
|
35
38
|
|
|
36
39
|
static defaults = invertDefaultValues;
|
|
37
40
|
|
|
41
|
+
static uniformLocations = ['uInvert', 'uAlpha'];
|
|
42
|
+
|
|
38
43
|
/**
|
|
39
44
|
* Apply the Invert operation to a Uint8Array representing the pixels of an image.
|
|
40
45
|
*
|
|
@@ -67,22 +72,6 @@ export class Invert extends BaseFilter {
|
|
|
67
72
|
return !this.invert;
|
|
68
73
|
}
|
|
69
74
|
|
|
70
|
-
/**
|
|
71
|
-
* Return WebGL uniform locations for this filter's shader.
|
|
72
|
-
*
|
|
73
|
-
* @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
|
|
74
|
-
* @param {WebGLShaderProgram} program This filter's compiled shader program.
|
|
75
|
-
*/
|
|
76
|
-
getUniformLocations(
|
|
77
|
-
gl: WebGLRenderingContext,
|
|
78
|
-
program: WebGLProgram
|
|
79
|
-
): TWebGLUniformLocationMap {
|
|
80
|
-
return {
|
|
81
|
-
uInvert: gl.getUniformLocation(program, 'uInvert'),
|
|
82
|
-
uAlpha: gl.getUniformLocation(program, 'uAlpha'),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
75
|
/**
|
|
87
76
|
* Send data from this filter to its shader program's uniforms.
|
|
88
77
|
*
|
package/src/filters/Noise.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type { TClassProperties } from '../typedefs';
|
|
2
1
|
import { BaseFilter } from './BaseFilter';
|
|
3
2
|
import type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';
|
|
4
3
|
import { classRegistry } from '../ClassRegistry';
|
|
5
4
|
import { fragmentSource } from './shaders/noise';
|
|
6
5
|
|
|
7
|
-
export
|
|
8
|
-
|
|
6
|
+
export type NoiseOwnProps = {
|
|
7
|
+
noise: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const noiseDefaultValues: NoiseOwnProps = {
|
|
9
11
|
noise: 0,
|
|
10
12
|
};
|
|
11
13
|
|
|
@@ -19,18 +21,20 @@ export const noiseDefaultValues: Partial<TClassProperties<Noise>> = {
|
|
|
19
21
|
* object.applyFilters();
|
|
20
22
|
* canvas.renderAll();
|
|
21
23
|
*/
|
|
22
|
-
export class Noise extends BaseFilter {
|
|
24
|
+
export class Noise extends BaseFilter<'Noise', NoiseOwnProps> {
|
|
23
25
|
/**
|
|
24
26
|
* Noise value, from
|
|
25
27
|
* @param {Number} noise
|
|
26
28
|
* @default
|
|
27
29
|
*/
|
|
28
|
-
declare noise:
|
|
30
|
+
declare noise: NoiseOwnProps['noise'];
|
|
29
31
|
|
|
30
32
|
static type = 'Noise';
|
|
31
33
|
|
|
32
34
|
static defaults = noiseDefaultValues;
|
|
33
35
|
|
|
36
|
+
static uniformLocations = ['uNoise', 'uSeed'];
|
|
37
|
+
|
|
34
38
|
getFragmentSource() {
|
|
35
39
|
return fragmentSource;
|
|
36
40
|
}
|
|
@@ -42,9 +46,6 @@ export class Noise extends BaseFilter {
|
|
|
42
46
|
* @param {ImageData} options.imageData The Uint8ClampedArray to be filtered.
|
|
43
47
|
*/
|
|
44
48
|
applyTo2d({ imageData: { data } }: T2DPipelineState) {
|
|
45
|
-
if (this.noise === 0) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
49
|
const noise = this.noise;
|
|
49
50
|
for (let i = 0; i < data.length; i += 4) {
|
|
50
51
|
const rand = (0.5 - Math.random()) * noise;
|
|
@@ -54,22 +55,6 @@ export class Noise extends BaseFilter {
|
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
|
|
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(
|
|
64
|
-
gl: WebGLRenderingContext,
|
|
65
|
-
program: WebGLProgram
|
|
66
|
-
): TWebGLUniformLocationMap {
|
|
67
|
-
return {
|
|
68
|
-
uNoise: gl.getUniformLocation(program, 'uNoise'),
|
|
69
|
-
uSeed: gl.getUniformLocation(program, 'uSeed'),
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
58
|
/**
|
|
74
59
|
* Send data from this filter to its shader program's uniforms.
|
|
75
60
|
*
|
|
@@ -84,12 +69,8 @@ export class Noise extends BaseFilter {
|
|
|
84
69
|
gl.uniform1f(uniformLocations.uSeed, Math.random());
|
|
85
70
|
}
|
|
86
71
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
* @return {Object} Object representation of an instance
|
|
90
|
-
*/
|
|
91
|
-
toObject() {
|
|
92
|
-
return { ...super.toObject(), noise: this.noise };
|
|
72
|
+
isNeutralState() {
|
|
73
|
+
return this.noise === 0;
|
|
93
74
|
}
|
|
94
75
|
}
|
|
95
76
|
|
package/src/filters/Pixelate.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import type { TClassProperties } from '../typedefs';
|
|
2
1
|
import { BaseFilter } from './BaseFilter';
|
|
3
2
|
import type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';
|
|
4
3
|
import { classRegistry } from '../ClassRegistry';
|
|
5
4
|
import { fragmentSource } from './shaders/pixelate';
|
|
6
5
|
|
|
7
|
-
export
|
|
6
|
+
export type PixelateOwnProps = {
|
|
7
|
+
blocksize: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const pixelateDefaultValues: PixelateOwnProps = {
|
|
8
11
|
blocksize: 4,
|
|
9
|
-
mainParameter: 'blocksize',
|
|
10
12
|
};
|
|
11
13
|
|
|
12
14
|
/**
|
|
@@ -18,13 +20,15 @@ export const pixelateDefaultValues: Partial<TClassProperties<Pixelate>> = {
|
|
|
18
20
|
* object.filters.push(filter);
|
|
19
21
|
* object.applyFilters();
|
|
20
22
|
*/
|
|
21
|
-
export class Pixelate extends BaseFilter {
|
|
22
|
-
declare blocksize:
|
|
23
|
+
export class Pixelate extends BaseFilter<'Pixelate', PixelateOwnProps> {
|
|
24
|
+
declare blocksize: PixelateOwnProps['blocksize'];
|
|
23
25
|
|
|
24
26
|
static type = 'Pixelate';
|
|
25
27
|
|
|
26
28
|
static defaults = pixelateDefaultValues;
|
|
27
29
|
|
|
30
|
+
static uniformLocations = ['uBlockSize'];
|
|
31
|
+
|
|
28
32
|
/**
|
|
29
33
|
* Apply the Pixelate operation to a Uint8ClampedArray representing the pixels of an image.
|
|
30
34
|
*
|
|
@@ -64,23 +68,6 @@ export class Pixelate extends BaseFilter {
|
|
|
64
68
|
return fragmentSource;
|
|
65
69
|
}
|
|
66
70
|
|
|
67
|
-
/**
|
|
68
|
-
* Return WebGL uniform locations for this filter's shader.
|
|
69
|
-
*
|
|
70
|
-
* @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
|
|
71
|
-
* @param {WebGLShaderProgram} program This filter's compiled shader program.
|
|
72
|
-
*/
|
|
73
|
-
getUniformLocations(
|
|
74
|
-
gl: WebGLRenderingContext,
|
|
75
|
-
program: WebGLProgram
|
|
76
|
-
): TWebGLUniformLocationMap {
|
|
77
|
-
return {
|
|
78
|
-
uBlocksize: gl.getUniformLocation(program, 'uBlocksize'),
|
|
79
|
-
uStepW: gl.getUniformLocation(program, 'uStepW'),
|
|
80
|
-
uStepH: gl.getUniformLocation(program, 'uStepH'),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
71
|
/**
|
|
85
72
|
* Send data from this filter to its shader program's uniforms.
|
|
86
73
|
*
|