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