@stream-io/video-filters-web 0.1.1 → 0.1.2

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 CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ### [0.1.2](https://github.com/GetStream/stream-video-js/compare/@stream-io/video-filters-web-0.1.1...@stream-io/video-filters-web-0.1.2) (2024-06-12)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * infinitely adjustable blur filter ([#1399](https://github.com/GetStream/stream-video-js/issues/1399)) ([447e73f](https://github.com/GetStream/stream-video-js/commit/447e73f2363142a0c1b43d05f848400950ecf697))
11
+
5
12
  ### [0.1.1](https://github.com/GetStream/stream-video-js/compare/@stream-io/video-filters-web-0.1.0...@stream-io/video-filters-web-0.1.1) (2024-06-03)
6
13
 
7
14
 
package/dist/index.cjs.js CHANGED
@@ -133,11 +133,21 @@ function buildBackgroundBlurStage(gl, vertexShader, positionBuffer, texCoordBuff
133
133
  };
134
134
  }
135
135
  function buildBlurPass(gl, vertexShader, positionBuffer, texCoordBuffer, personMaskTexture, canvas, blurLevel) {
136
- const weights = blurLevel === 'low'
137
- ? [0.227027027, 0.1545945946, 0.1016216216, 0.0340540541, 0.0142162162]
138
- : blurLevel === 'medium'
139
- ? [0.327027027, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162]
140
- : [0.627027027, 0.3445945946, 0.2216216216, 0.0540540541, 0.0162162162];
136
+ const sigma = typeof blurLevel === 'number'
137
+ ? blurLevel
138
+ : blurLevel === 'low'
139
+ ? 2
140
+ : blurLevel === 'medium'
141
+ ? 4
142
+ : 6;
143
+ const windowSize = Math.max(1, Math.floor(sigma * 3));
144
+ const offset = new Array(windowSize).fill(0).map((v, index) => index);
145
+ const variance = sigma ** 2;
146
+ const weights = offset.map((x) => {
147
+ var m = sigma * Math.sqrt(2 * Math.PI);
148
+ var e = Math.exp(-(x ** 2) / (2 * variance));
149
+ return e / m;
150
+ });
141
151
  const fragmentShaderSource = glsl `#version 300 es
142
152
 
143
153
  precision highp float;
@@ -149,10 +159,8 @@ function buildBlurPass(gl, vertexShader, positionBuffer, texCoordBuffer, personM
149
159
  in vec2 v_texCoord;
150
160
  out vec4 outColor;
151
161
 
152
- const float offset[5] = float[](0.0, 1.0, 2.0, 3.0, 4.0);
153
- const float weight[5] = float[](
154
- ${weights.join(',')}
155
- );
162
+ const float offset[${windowSize}] = float[](${offset.map((i) => i.toFixed(10)).join(', ')});
163
+ const float weight[${windowSize}] = float[](${weights.map((i) => i.toFixed(10)).join(', ')});
156
164
 
157
165
  void main() {
158
166
  vec4 centerColor = texture(u_inputFrame, v_texCoord);
@@ -160,7 +168,7 @@ function buildBlurPass(gl, vertexShader, positionBuffer, texCoordBuffer, personM
160
168
 
161
169
  vec4 frameColor = centerColor * weight[0] * (1.0 - personMask);
162
170
 
163
- for (int i = 1; i < 5; i++) {
171
+ for (int i = 1; i < ${windowSize}; i++) {
164
172
  vec2 offset = vec2(offset[i]) * u_texelSize;
165
173
 
166
174
  vec2 texCoord = v_texCoord + offset;
@@ -1523,7 +1531,7 @@ const createTFLiteSIMDModule = (__Module) => {
1523
1531
  return __Module.ready;
1524
1532
  };
1525
1533
 
1526
- const version = "0.1.1" ;
1534
+ const version = "0.1.2" ;
1527
1535
  const packageName = "@stream-io/video-filters-web" ;
1528
1536
 
1529
1537
  // @ts-expect-error - module is not declared