From 44f6ca317459b3adc4c0728c7f8594582c152864 Mon Sep 17 00:00:00 2001 From: twilio-ci Date: Thu, 7 Dec 2023 21:35:47 +0000 Subject: [PATCH] 2.1.0-rc2 --- examples/virtualbackground/twilio-video-processors.js | 6 +++--- examples/virtualbackground/twilio-video-processors.min.js | 4 ++-- index.html | 7 +++++-- variables/version.html | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/examples/virtualbackground/twilio-video-processors.js b/examples/virtualbackground/twilio-video-processors.js index 2f6563a..29f1877 100644 --- a/examples/virtualbackground/twilio-video-processors.js +++ b/examples/virtualbackground/twilio-video-processors.js @@ -1,4 +1,4 @@ -/*! twilio-video-processors.js 2.1.0-rc1 +/*! twilio-video-processors.js 2.1.0-rc2 The following license applies to all parts of this software except as documented below. @@ -1220,7 +1220,7 @@ exports.buildJointBilateralFilterStage = void 0; var segmentationHelper_1 = require("../helpers/segmentationHelper"); var webglHelper_1 = require("../helpers/webglHelper"); function buildJointBilateralFilterStage(gl, vertexShader, positionBuffer, texCoordBuffer, inputTexture, segmentationConfig, outputTexture, canvas) { - var fragmentShaderSource = (0, webglHelper_1.glsl)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["#version 300 es\n\n precision highp float;\n\n uniform sampler2D u_inputFrame;\n uniform sampler2D u_segmentationMask;\n uniform vec2 u_texelSize;\n uniform float u_step;\n uniform float u_radius;\n uniform float u_offset;\n uniform float u_sigmaTexel;\n uniform float u_sigmaColor;\n\n in vec2 v_texCoord;\n\n out vec4 outColor;\n\n float gaussian(float x, float sigma) {\n float coeff = -0.5 / (sigma * sigma * 4.0 + 1.0e-6);\n return exp((x * x) * coeff);\n }\n\n void main() {\n vec2 centerCoord = v_texCoord;\n vec3 centerColor = texture(u_inputFrame, centerCoord).rgb;\n float newVal = 0.0;\n\n float spaceWeight = 0.0;\n float colorWeight = 0.0;\n float totalWeight = 0.0;\n\n // Subsample kernel space.\n for (float i = -u_radius + u_offset; i <= u_radius; i += u_step) {\n for (float j = -u_radius + u_offset; j <= u_radius; j += u_step) {\n vec2 shift = vec2(j, i) * u_texelSize;\n vec2 coord = vec2(centerCoord + shift);\n vec3 frameColor = texture(u_inputFrame, coord).rgb;\n float outVal = texture(u_segmentationMask, coord).a;\n\n spaceWeight = gaussian(distance(centerCoord, coord), u_sigmaTexel);\n colorWeight = gaussian(distance(centerColor, frameColor), u_sigmaColor);\n totalWeight += spaceWeight * colorWeight;\n\n newVal += spaceWeight * colorWeight * outVal;\n }\n }\n newVal /= totalWeight;\n\n outColor = vec4(vec3(0.0), newVal);\n }\n "], ["#version 300 es\n\n precision highp float;\n\n uniform sampler2D u_inputFrame;\n uniform sampler2D u_segmentationMask;\n uniform vec2 u_texelSize;\n uniform float u_step;\n uniform float u_radius;\n uniform float u_offset;\n uniform float u_sigmaTexel;\n uniform float u_sigmaColor;\n\n in vec2 v_texCoord;\n\n out vec4 outColor;\n\n float gaussian(float x, float sigma) {\n float coeff = -0.5 / (sigma * sigma * 4.0 + 1.0e-6);\n return exp((x * x) * coeff);\n }\n\n void main() {\n vec2 centerCoord = v_texCoord;\n vec3 centerColor = texture(u_inputFrame, centerCoord).rgb;\n float newVal = 0.0;\n\n float spaceWeight = 0.0;\n float colorWeight = 0.0;\n float totalWeight = 0.0;\n\n // Subsample kernel space.\n for (float i = -u_radius + u_offset; i <= u_radius; i += u_step) {\n for (float j = -u_radius + u_offset; j <= u_radius; j += u_step) {\n vec2 shift = vec2(j, i) * u_texelSize;\n vec2 coord = vec2(centerCoord + shift);\n vec3 frameColor = texture(u_inputFrame, coord).rgb;\n float outVal = texture(u_segmentationMask, coord).a;\n\n spaceWeight = gaussian(distance(centerCoord, coord), u_sigmaTexel);\n colorWeight = gaussian(distance(centerColor, frameColor), u_sigmaColor);\n totalWeight += spaceWeight * colorWeight;\n\n newVal += spaceWeight * colorWeight * outVal;\n }\n }\n newVal /= totalWeight;\n\n outColor = vec4(vec3(0.0), newVal);\n }\n "]))); + var fragmentShaderSource = (0, webglHelper_1.glsl)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["#version 300 es\n\n precision highp float;\n\n uniform sampler2D u_inputFrame;\n uniform sampler2D u_segmentationMask;\n uniform vec2 u_texelSize;\n uniform float u_step;\n uniform float u_radius;\n uniform float u_offset;\n uniform float u_sigmaTexel;\n uniform float u_sigmaColor;\n\n in vec2 v_texCoord;\n\n out vec4 outColor;\n\n float gaussian(float x, float sigma) {\n float coeff = -0.5 / (sigma * sigma * 4.0 + 1.0e-6);\n return exp((x * x) * coeff);\n }\n\n void main() {\n vec2 centerCoord = v_texCoord;\n vec3 centerColor = texture(u_inputFrame, centerCoord).rgb;\n float newVal = 0.0;\n\n float spaceWeight = 0.0;\n float colorWeight = 0.0;\n float totalWeight = 0.0;\n\n vec2 leftTopCoord = vec2(centerCoord + vec2(-u_radius, -u_radius) * u_texelSize);\n vec2 rightTopCoord = vec2(centerCoord + vec2(u_radius, -u_radius) * u_texelSize);\n vec2 leftBottomCoord = vec2(centerCoord + vec2(-u_radius, u_radius) * u_texelSize);\n vec2 rightBottomCoord = vec2(centerCoord + vec2(u_radius, u_radius) * u_texelSize);\n\n float leftTopSegAlpha = texture(u_segmentationMask, leftTopCoord).a;\n float rightTopSegAlpha = texture(u_segmentationMask, rightTopCoord).a;\n float leftBottomSegAlpha = texture(u_segmentationMask, leftBottomCoord).a;\n float rightBottomSegAlpha = texture(u_segmentationMask, rightBottomCoord).a;\n float totalSegAlpha = leftTopSegAlpha + rightTopSegAlpha + leftBottomSegAlpha + rightBottomSegAlpha;\n\n if (totalSegAlpha <= 0.0) {\n outColor = vec4(vec3(0.0), 0.0);\n } else if (totalSegAlpha >= 4.0) {\n outColor = vec4(vec3(0.0), 1.0);\n } else {\n for (float i = -u_radius + u_offset; i <= u_radius; i += u_step) {\n for (float j = -u_radius + u_offset; j <= u_radius; j += u_step) {\n vec2 shift = vec2(j, i) * u_texelSize;\n vec2 coord = vec2(centerCoord + shift);\n vec3 frameColor = texture(u_inputFrame, coord).rgb;\n float outVal = texture(u_segmentationMask, coord).a;\n\n spaceWeight = gaussian(distance(centerCoord, coord), u_sigmaTexel);\n colorWeight = gaussian(distance(centerColor, frameColor), u_sigmaColor);\n totalWeight += spaceWeight * colorWeight;\n\n newVal += spaceWeight * colorWeight * outVal;\n }\n }\n newVal /= totalWeight;\n\n outColor = vec4(vec3(0.0), newVal);\n }\n }\n "], ["#version 300 es\n\n precision highp float;\n\n uniform sampler2D u_inputFrame;\n uniform sampler2D u_segmentationMask;\n uniform vec2 u_texelSize;\n uniform float u_step;\n uniform float u_radius;\n uniform float u_offset;\n uniform float u_sigmaTexel;\n uniform float u_sigmaColor;\n\n in vec2 v_texCoord;\n\n out vec4 outColor;\n\n float gaussian(float x, float sigma) {\n float coeff = -0.5 / (sigma * sigma * 4.0 + 1.0e-6);\n return exp((x * x) * coeff);\n }\n\n void main() {\n vec2 centerCoord = v_texCoord;\n vec3 centerColor = texture(u_inputFrame, centerCoord).rgb;\n float newVal = 0.0;\n\n float spaceWeight = 0.0;\n float colorWeight = 0.0;\n float totalWeight = 0.0;\n\n vec2 leftTopCoord = vec2(centerCoord + vec2(-u_radius, -u_radius) * u_texelSize);\n vec2 rightTopCoord = vec2(centerCoord + vec2(u_radius, -u_radius) * u_texelSize);\n vec2 leftBottomCoord = vec2(centerCoord + vec2(-u_radius, u_radius) * u_texelSize);\n vec2 rightBottomCoord = vec2(centerCoord + vec2(u_radius, u_radius) * u_texelSize);\n\n float leftTopSegAlpha = texture(u_segmentationMask, leftTopCoord).a;\n float rightTopSegAlpha = texture(u_segmentationMask, rightTopCoord).a;\n float leftBottomSegAlpha = texture(u_segmentationMask, leftBottomCoord).a;\n float rightBottomSegAlpha = texture(u_segmentationMask, rightBottomCoord).a;\n float totalSegAlpha = leftTopSegAlpha + rightTopSegAlpha + leftBottomSegAlpha + rightBottomSegAlpha;\n\n if (totalSegAlpha <= 0.0) {\n outColor = vec4(vec3(0.0), 0.0);\n } else if (totalSegAlpha >= 4.0) {\n outColor = vec4(vec3(0.0), 1.0);\n } else {\n for (float i = -u_radius + u_offset; i <= u_radius; i += u_step) {\n for (float j = -u_radius + u_offset; j <= u_radius; j += u_step) {\n vec2 shift = vec2(j, i) * u_texelSize;\n vec2 coord = vec2(centerCoord + shift);\n vec3 frameColor = texture(u_inputFrame, coord).rgb;\n float outVal = texture(u_segmentationMask, coord).a;\n\n spaceWeight = gaussian(distance(centerCoord, coord), u_sigmaTexel);\n colorWeight = gaussian(distance(centerColor, frameColor), u_sigmaColor);\n totalWeight += spaceWeight * colorWeight;\n\n newVal += spaceWeight * colorWeight * outVal;\n }\n }\n newVal /= totalWeight;\n\n outColor = vec4(vec3(0.0), newVal);\n }\n }\n "]))); var _a = segmentationHelper_1.inputResolutions[segmentationConfig.inputResolution], segmentationWidth = _a[0], segmentationHeight = _a[1]; var outputWidth = canvas.width, outputHeight = canvas.height; var texelWidth = 1 / outputWidth; @@ -1721,6 +1721,6 @@ exports.version = void 0; /** * The current version of the library. */ -exports.version = '2.1.0-rc1'; +exports.version = '2.1.0-rc2'; },{}]},{},[2]); diff --git a/examples/virtualbackground/twilio-video-processors.min.js b/examples/virtualbackground/twilio-video-processors.min.js index 515de6c..86cfb83 100644 --- a/examples/virtualbackground/twilio-video-processors.min.js +++ b/examples/virtualbackground/twilio-video-processors.min.js @@ -1,4 +1,4 @@ -/*! twilio-video-processors.js 2.1.0-rc1 +/*! twilio-video-processors.js 2.1.0-rc2 The following license applies to all parts of this software except as documented below. @@ -35,4 +35,4 @@ documented below. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]=this._historyCount){this._masks.splice(0,this._masks.length-this._historyCount+1)}this._masks.push(mask)};BackgroundProcessor.prototype._applyAlpha=function(imageData){var weightedSum=this._masks.reduce(function(sum,mask,j){return sum+(j+1)*(j+1)},0);var pixels=imageData.height*imageData.width;var _loop_1=function(i){var w=this_1._masks.reduce(function(sum,mask,j){return sum+mask[i]*(j+1)*(j+1)},0)/weightedSum;imageData.data[i*4+3]=Math.round(w*255)};var this_1=this;for(var i=0;i=this._personProbabilityThreshold)*personProbability}return inferenceData};BackgroundProcessor._loadedScripts=[];return BackgroundProcessor}(Processor_1.Processor);exports.BackgroundProcessor=BackgroundProcessor},{"../../constants":1,"../../types":16,"../../utils/Benchmark":17,"../../utils/version":19,"../Processor":3,"../webgl2":9}],5:[function(require,module,exports){"use strict";var __extends=this&&this.__extends||function(){var extendStatics=function(d,b){extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)if(Object.prototype.hasOwnProperty.call(b,p))d[p]=b[p]};return extendStatics(d,b)};return function(d,b){if(typeof b!=="function"&&b!==null)throw new TypeError("Class extends value "+String(b)+" is not a constructor or null");extendStatics(d,b);function __(){this.constructor=d}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __)}}();Object.defineProperty(exports,"__esModule",{value:true});exports.GaussianBlurBackgroundProcessor=void 0;var BackgroundProcessor_1=require("./BackgroundProcessor");var constants_1=require("../../constants");var types_1=require("../../types");var GaussianBlurBackgroundProcessor=function(_super){__extends(GaussianBlurBackgroundProcessor,_super);function GaussianBlurBackgroundProcessor(options){var _this=_super.call(this,options)||this;_this._blurFilterRadius=constants_1.BLUR_FILTER_RADIUS;_this._name="GaussianBlurBackgroundProcessor";_this.blurFilterRadius=options.blurFilterRadius;return _this}Object.defineProperty(GaussianBlurBackgroundProcessor.prototype,"blurFilterRadius",{get:function(){return this._blurFilterRadius},set:function(radius){if(!radius){console.warn("Valid blur filter radius not found. Using ".concat(constants_1.BLUR_FILTER_RADIUS," as default."));radius=constants_1.BLUR_FILTER_RADIUS}this._blurFilterRadius=radius},enumerable:false,configurable:true});GaussianBlurBackgroundProcessor.prototype._getWebGL2PipelineType=function(){return types_1.WebGL2PipelineType.Blur};GaussianBlurBackgroundProcessor.prototype._setBackground=function(inputFrame){if(!this._outputContext){return}var ctx=this._outputContext;ctx.filter="blur(".concat(this._blurFilterRadius,"px)");ctx.drawImage(inputFrame,0,0)};return GaussianBlurBackgroundProcessor}(BackgroundProcessor_1.BackgroundProcessor);exports.GaussianBlurBackgroundProcessor=GaussianBlurBackgroundProcessor},{"../../constants":1,"../../types":16,"./BackgroundProcessor":4}],6:[function(require,module,exports){"use strict";var __extends=this&&this.__extends||function(){var extendStatics=function(d,b){extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)if(Object.prototype.hasOwnProperty.call(b,p))d[p]=b[p]};return extendStatics(d,b)};return function(d,b){if(typeof b!=="function"&&b!==null)throw new TypeError("Class extends value "+String(b)+" is not a constructor or null");extendStatics(d,b);function __(){this.constructor=d}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __)}}();Object.defineProperty(exports,"__esModule",{value:true});exports.VirtualBackgroundProcessor=void 0;var BackgroundProcessor_1=require("./BackgroundProcessor");var types_1=require("../../types");var VirtualBackgroundProcessor=function(_super){__extends(VirtualBackgroundProcessor,_super);function VirtualBackgroundProcessor(options){var _this=_super.call(this,options)||this;_this._name="VirtualBackgroundProcessor";_this.backgroundImage=options.backgroundImage;_this.fitType=options.fitType;return _this}Object.defineProperty(VirtualBackgroundProcessor.prototype,"backgroundImage",{get:function(){return this._backgroundImage},set:function(image){var _a;if(!image||!image.complete||!image.naturalHeight){throw new Error("Invalid image. Make sure that the image is an HTMLImageElement and has been successfully loaded")}this._backgroundImage=image;(_a=this._webgl2Pipeline)===null||_a===void 0?void 0:_a.cleanUp();this._webgl2Pipeline=null},enumerable:false,configurable:true});Object.defineProperty(VirtualBackgroundProcessor.prototype,"fitType",{get:function(){return this._fitType},set:function(fitType){var validTypes=Object.keys(types_1.ImageFit);if(!validTypes.includes(fitType)){console.warn("Valid fitType not found. Using '".concat(types_1.ImageFit.Fill,"' as default."));fitType=types_1.ImageFit.Fill}this._fitType=fitType},enumerable:false,configurable:true});VirtualBackgroundProcessor.prototype._getWebGL2PipelineType=function(){return types_1.WebGL2PipelineType.Image};VirtualBackgroundProcessor.prototype._setBackground=function(){if(!this._outputContext||!this._outputCanvas){return}var img=this._backgroundImage;var imageWidth=img.naturalWidth;var imageHeight=img.naturalHeight;var canvasWidth=this._outputCanvas.width;var canvasHeight=this._outputCanvas.height;var ctx=this._outputContext;if(this._fitType===types_1.ImageFit.Fill){ctx.drawImage(img,0,0,imageWidth,imageHeight,0,0,canvasWidth,canvasHeight)}else if(this._fitType===types_1.ImageFit.None){ctx.drawImage(img,0,0,imageWidth,imageHeight)}else if(this._fitType===types_1.ImageFit.Contain){var _a=this._getFitPosition(imageWidth,imageHeight,canvasWidth,canvasHeight,types_1.ImageFit.Contain),x=_a.x,y=_a.y,w=_a.w,h=_a.h;ctx.drawImage(img,0,0,imageWidth,imageHeight,x,y,w,h)}else if(this._fitType===types_1.ImageFit.Cover){var _b=this._getFitPosition(imageWidth,imageHeight,canvasWidth,canvasHeight,types_1.ImageFit.Cover),x=_b.x,y=_b.y,w=_b.w,h=_b.h;ctx.drawImage(img,0,0,imageWidth,imageHeight,x,y,w,h)}};VirtualBackgroundProcessor.prototype._getFitPosition=function(contentWidth,contentHeight,viewportWidth,viewportHeight,type){var factor=viewportWidth/contentWidth;var newContentWidth=viewportWidth;var newContentHeight=factor*contentHeight;if(type===types_1.ImageFit.Contain&&newContentHeight>viewportHeight||type===types_1.ImageFit.Cover&&viewportHeight>newContentHeight){factor=viewportHeight/newContentHeight;newContentWidth=factor*newContentWidth;newContentHeight=viewportHeight}var x=(viewportWidth-newContentWidth)/2;var y=(viewportHeight-newContentHeight)/2;return{x:x,y:y,w:newContentWidth,h:newContentHeight}};return VirtualBackgroundProcessor}(BackgroundProcessor_1.BackgroundProcessor);exports.VirtualBackgroundProcessor=VirtualBackgroundProcessor},{"../../types":16,"./BackgroundProcessor":4}],7:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.inputResolutions=void 0;exports.inputResolutions={"640x360":[640,360],"256x256":[256,256],"256x144":[256,144],"160x96":[160,96]}},{}],8:[function(require,module,exports){"use strict";var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){function adopt(value){return value instanceof P?value:new P(function(resolve){resolve(value)})}return new(P||(P=Promise))(function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator["throw"](value))}catch(e){reject(e)}}function step(result){result.done?resolve(result.value):adopt(result.value).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())})};var __generator=this&&this.__generator||function(thisArg,body){var _={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},f,y,t,g;return g={next:verb(0),throw:verb(1),return:verb(2)},typeof Symbol==="function"&&(g[Symbol.iterator]=function(){return this}),g;function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");while(g&&(g=0,op[0]&&(_=0)),_)try{if(f=1,y&&(t=op[0]&2?y["return"]:op[0]?y["throw"]||((t=y["return"])&&t.call(y),0):y.next)&&!(t=t.call(y,op[1])).done)return t;if(y=0,t)op=[op[0]&2,t.value];switch(op[0]){case 0:case 1:t=op;break;case 4:_.label++;return{value:op[1],done:false};case 5:_.label++;y=op[1];op=[0];continue;case 7:op=_.ops.pop();_.trys.pop();continue;default:if(!(t=_.trys,t=t.length>0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]1?step*.5:0;var sigmaTexel=Math.max(texelWidth,texelHeight)*sigmaSpace;gl.useProgram(program);gl.uniform1f(stepLocation,step);gl.uniform1f(radiusLocation,radius);gl.uniform1f(offsetLocation,offset);gl.uniform1f(sigmaTexelLocation,sigmaTexel)}function updateSigmaColor(sigmaColor){gl.useProgram(program);gl.uniform1f(sigmaColorLocation,sigmaColor)}function cleanUp(){gl.deleteFramebuffer(frameBuffer);gl.deleteProgram(program);gl.deleteShader(fragmentShader)}return{render:render,updateSigmaSpace:updateSigmaSpace,updateSigmaColor:updateSigmaColor,cleanUp:cleanUp}}exports.buildJointBilateralFilterStage=buildJointBilateralFilterStage;var templateObject_1},{"../helpers/segmentationHelper":7,"../helpers/webglHelper":8}],13:[function(require,module,exports){"use strict";var __makeTemplateObject=this&&this.__makeTemplateObject||function(cooked,raw){if(Object.defineProperty){Object.defineProperty(cooked,"raw",{value:raw})}else{cooked.raw=raw}return cooked};Object.defineProperty(exports,"__esModule",{value:true});exports.buildLoadSegmentationStage=void 0;var segmentationHelper_1=require("../helpers/segmentationHelper");var webglHelper_1=require("../helpers/webglHelper");function buildLoadSegmentationStage(gl,vertexShader,positionBuffer,texCoordBuffer,segmentationConfig,tflite,outputTexture){var fragmentShaderSource=(0,webglHelper_1.glsl)(templateObject_1||(templateObject_1=__makeTemplateObject(["#version 300 es\n\n precision highp float;\n\n uniform sampler2D u_inputSegmentation;\n\n in vec2 v_texCoord;\n\n out vec4 outColor;\n\n void main() {\n float segmentation = texture(u_inputSegmentation, v_texCoord).r;\n outColor = vec4(vec3(0.0), segmentation);\n }\n "],["#version 300 es\n\n precision highp float;\n\n uniform sampler2D u_inputSegmentation;\n\n in vec2 v_texCoord;\n\n out vec4 outColor;\n\n void main() {\n float segmentation = texture(u_inputSegmentation, v_texCoord).r;\n outColor = vec4(vec3(0.0), segmentation);\n }\n "])));var tfliteOutputMemoryOffset=tflite._getOutputMemoryOffset()/4;var _a=segmentationHelper_1.inputResolutions[segmentationConfig.inputResolution],segmentationWidth=_a[0],segmentationHeight=_a[1];var fragmentShader=(0,webglHelper_1.compileShader)(gl,gl.FRAGMENT_SHADER,fragmentShaderSource);var program=(0,webglHelper_1.createPiplelineStageProgram)(gl,vertexShader,fragmentShader,positionBuffer,texCoordBuffer);var inputLocation=gl.getUniformLocation(program,"u_inputSegmentation");var inputTexture=(0,webglHelper_1.createTexture)(gl,gl.R32F,segmentationWidth,segmentationHeight);var frameBuffer=gl.createFramebuffer();gl.bindFramebuffer(gl.FRAMEBUFFER,frameBuffer);gl.framebufferTexture2D(gl.FRAMEBUFFER,gl.COLOR_ATTACHMENT0,gl.TEXTURE_2D,outputTexture,0);gl.useProgram(program);gl.uniform1i(inputLocation,1);function render(){gl.viewport(0,0,segmentationWidth,segmentationHeight);gl.useProgram(program);gl.activeTexture(gl.TEXTURE1);gl.bindTexture(gl.TEXTURE_2D,inputTexture);gl.texSubImage2D(gl.TEXTURE_2D,0,0,0,segmentationWidth,segmentationHeight,gl.RED,gl.FLOAT,tflite.HEAPF32,tfliteOutputMemoryOffset);gl.bindFramebuffer(gl.FRAMEBUFFER,frameBuffer);gl.drawArrays(gl.TRIANGLE_STRIP,0,4)}function cleanUp(){gl.deleteFramebuffer(frameBuffer);gl.deleteTexture(inputTexture);gl.deleteProgram(program);gl.deleteShader(fragmentShader)}return{render:render,cleanUp:cleanUp}}exports.buildLoadSegmentationStage=buildLoadSegmentationStage;var templateObject_1},{"../helpers/segmentationHelper":7,"../helpers/webglHelper":8}],14:[function(require,module,exports){"use strict";var __makeTemplateObject=this&&this.__makeTemplateObject||function(cooked,raw){if(Object.defineProperty){Object.defineProperty(cooked,"raw",{value:raw})}else{cooked.raw=raw}return cooked};Object.defineProperty(exports,"__esModule",{value:true});exports.buildResizingStage=void 0;var segmentationHelper_1=require("../helpers/segmentationHelper");var webglHelper_1=require("../helpers/webglHelper");function buildResizingStage(gl,vertexShader,positionBuffer,texCoordBuffer,segmentationConfig,tflite){var fragmentShaderSource=(0,webglHelper_1.glsl)(templateObject_1||(templateObject_1=__makeTemplateObject(["#version 300 es\n\n precision highp float;\n\n uniform sampler2D u_inputFrame;\n\n in vec2 v_texCoord;\n\n out vec4 outColor;\n\n void main() {\n outColor = texture(u_inputFrame, v_texCoord);\n }\n "],["#version 300 es\n\n precision highp float;\n\n uniform sampler2D u_inputFrame;\n\n in vec2 v_texCoord;\n\n out vec4 outColor;\n\n void main() {\n outColor = texture(u_inputFrame, v_texCoord);\n }\n "])));var tfliteInputMemoryOffset=tflite._getInputMemoryOffset()/4;var _a=segmentationHelper_1.inputResolutions[segmentationConfig.inputResolution],outputWidth=_a[0],outputHeight=_a[1];var outputPixelCount=outputWidth*outputHeight;var fragmentShader=(0,webglHelper_1.compileShader)(gl,gl.FRAGMENT_SHADER,fragmentShaderSource);var program=(0,webglHelper_1.createPiplelineStageProgram)(gl,vertexShader,fragmentShader,positionBuffer,texCoordBuffer);var inputFrameLocation=gl.getUniformLocation(program,"u_inputFrame");var outputTexture=(0,webglHelper_1.createTexture)(gl,gl.RGBA8,outputWidth,outputHeight);var frameBuffer=gl.createFramebuffer();gl.bindFramebuffer(gl.FRAMEBUFFER,frameBuffer);gl.framebufferTexture2D(gl.FRAMEBUFFER,gl.COLOR_ATTACHMENT0,gl.TEXTURE_2D,outputTexture,0);var outputPixels=new Uint8Array(outputPixelCount*4);gl.useProgram(program);gl.uniform1i(inputFrameLocation,0);function render(){gl.viewport(0,0,outputWidth,outputHeight);gl.useProgram(program);gl.bindFramebuffer(gl.FRAMEBUFFER,frameBuffer);gl.drawArrays(gl.TRIANGLE_STRIP,0,4);(0,webglHelper_1.readPixelsAsync)(gl,0,0,outputWidth,outputHeight,gl.RGBA,gl.UNSIGNED_BYTE,outputPixels);for(var i=0;i0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]Benchmark.cacheSize){timingCache.splice(0,timingCache.length-Benchmark.cacheSize)}};Benchmark.cacheSize=41;return Benchmark}();exports.Benchmark=Benchmark},{}],18:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isSupported=exports.isBrowserSupported=void 0;function getCanvas(){return typeof window.OffscreenCanvas!=="undefined"?new window.OffscreenCanvas(1,1):document.createElement("canvas")}function isBrowserSupported(){if(typeof window!=="undefined"&&typeof document!=="undefined"){return!!(getCanvas().getContext("2d")||getCanvas().getContext("webgl2"))}else{return false}}exports.isBrowserSupported=isBrowserSupported;exports.isSupported=isBrowserSupported()},{}],19:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.version=void 0;exports.version="2.1.0-rc1"},{}]},{},[2]); \ No newline at end of file +(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]=this._historyCount){this._masks.splice(0,this._masks.length-this._historyCount+1)}this._masks.push(mask)};BackgroundProcessor.prototype._applyAlpha=function(imageData){var weightedSum=this._masks.reduce(function(sum,mask,j){return sum+(j+1)*(j+1)},0);var pixels=imageData.height*imageData.width;var _loop_1=function(i){var w=this_1._masks.reduce(function(sum,mask,j){return sum+mask[i]*(j+1)*(j+1)},0)/weightedSum;imageData.data[i*4+3]=Math.round(w*255)};var this_1=this;for(var i=0;i=this._personProbabilityThreshold)*personProbability}return inferenceData};BackgroundProcessor._loadedScripts=[];return BackgroundProcessor}(Processor_1.Processor);exports.BackgroundProcessor=BackgroundProcessor},{"../../constants":1,"../../types":16,"../../utils/Benchmark":17,"../../utils/version":19,"../Processor":3,"../webgl2":9}],5:[function(require,module,exports){"use strict";var __extends=this&&this.__extends||function(){var extendStatics=function(d,b){extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)if(Object.prototype.hasOwnProperty.call(b,p))d[p]=b[p]};return extendStatics(d,b)};return function(d,b){if(typeof b!=="function"&&b!==null)throw new TypeError("Class extends value "+String(b)+" is not a constructor or null");extendStatics(d,b);function __(){this.constructor=d}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __)}}();Object.defineProperty(exports,"__esModule",{value:true});exports.GaussianBlurBackgroundProcessor=void 0;var BackgroundProcessor_1=require("./BackgroundProcessor");var constants_1=require("../../constants");var types_1=require("../../types");var GaussianBlurBackgroundProcessor=function(_super){__extends(GaussianBlurBackgroundProcessor,_super);function GaussianBlurBackgroundProcessor(options){var _this=_super.call(this,options)||this;_this._blurFilterRadius=constants_1.BLUR_FILTER_RADIUS;_this._name="GaussianBlurBackgroundProcessor";_this.blurFilterRadius=options.blurFilterRadius;return _this}Object.defineProperty(GaussianBlurBackgroundProcessor.prototype,"blurFilterRadius",{get:function(){return this._blurFilterRadius},set:function(radius){if(!radius){console.warn("Valid blur filter radius not found. Using ".concat(constants_1.BLUR_FILTER_RADIUS," as default."));radius=constants_1.BLUR_FILTER_RADIUS}this._blurFilterRadius=radius},enumerable:false,configurable:true});GaussianBlurBackgroundProcessor.prototype._getWebGL2PipelineType=function(){return types_1.WebGL2PipelineType.Blur};GaussianBlurBackgroundProcessor.prototype._setBackground=function(inputFrame){if(!this._outputContext){return}var ctx=this._outputContext;ctx.filter="blur(".concat(this._blurFilterRadius,"px)");ctx.drawImage(inputFrame,0,0)};return GaussianBlurBackgroundProcessor}(BackgroundProcessor_1.BackgroundProcessor);exports.GaussianBlurBackgroundProcessor=GaussianBlurBackgroundProcessor},{"../../constants":1,"../../types":16,"./BackgroundProcessor":4}],6:[function(require,module,exports){"use strict";var __extends=this&&this.__extends||function(){var extendStatics=function(d,b){extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)if(Object.prototype.hasOwnProperty.call(b,p))d[p]=b[p]};return extendStatics(d,b)};return function(d,b){if(typeof b!=="function"&&b!==null)throw new TypeError("Class extends value "+String(b)+" is not a constructor or null");extendStatics(d,b);function __(){this.constructor=d}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __)}}();Object.defineProperty(exports,"__esModule",{value:true});exports.VirtualBackgroundProcessor=void 0;var BackgroundProcessor_1=require("./BackgroundProcessor");var types_1=require("../../types");var VirtualBackgroundProcessor=function(_super){__extends(VirtualBackgroundProcessor,_super);function VirtualBackgroundProcessor(options){var _this=_super.call(this,options)||this;_this._name="VirtualBackgroundProcessor";_this.backgroundImage=options.backgroundImage;_this.fitType=options.fitType;return _this}Object.defineProperty(VirtualBackgroundProcessor.prototype,"backgroundImage",{get:function(){return this._backgroundImage},set:function(image){var _a;if(!image||!image.complete||!image.naturalHeight){throw new Error("Invalid image. Make sure that the image is an HTMLImageElement and has been successfully loaded")}this._backgroundImage=image;(_a=this._webgl2Pipeline)===null||_a===void 0?void 0:_a.cleanUp();this._webgl2Pipeline=null},enumerable:false,configurable:true});Object.defineProperty(VirtualBackgroundProcessor.prototype,"fitType",{get:function(){return this._fitType},set:function(fitType){var validTypes=Object.keys(types_1.ImageFit);if(!validTypes.includes(fitType)){console.warn("Valid fitType not found. Using '".concat(types_1.ImageFit.Fill,"' as default."));fitType=types_1.ImageFit.Fill}this._fitType=fitType},enumerable:false,configurable:true});VirtualBackgroundProcessor.prototype._getWebGL2PipelineType=function(){return types_1.WebGL2PipelineType.Image};VirtualBackgroundProcessor.prototype._setBackground=function(){if(!this._outputContext||!this._outputCanvas){return}var img=this._backgroundImage;var imageWidth=img.naturalWidth;var imageHeight=img.naturalHeight;var canvasWidth=this._outputCanvas.width;var canvasHeight=this._outputCanvas.height;var ctx=this._outputContext;if(this._fitType===types_1.ImageFit.Fill){ctx.drawImage(img,0,0,imageWidth,imageHeight,0,0,canvasWidth,canvasHeight)}else if(this._fitType===types_1.ImageFit.None){ctx.drawImage(img,0,0,imageWidth,imageHeight)}else if(this._fitType===types_1.ImageFit.Contain){var _a=this._getFitPosition(imageWidth,imageHeight,canvasWidth,canvasHeight,types_1.ImageFit.Contain),x=_a.x,y=_a.y,w=_a.w,h=_a.h;ctx.drawImage(img,0,0,imageWidth,imageHeight,x,y,w,h)}else if(this._fitType===types_1.ImageFit.Cover){var _b=this._getFitPosition(imageWidth,imageHeight,canvasWidth,canvasHeight,types_1.ImageFit.Cover),x=_b.x,y=_b.y,w=_b.w,h=_b.h;ctx.drawImage(img,0,0,imageWidth,imageHeight,x,y,w,h)}};VirtualBackgroundProcessor.prototype._getFitPosition=function(contentWidth,contentHeight,viewportWidth,viewportHeight,type){var factor=viewportWidth/contentWidth;var newContentWidth=viewportWidth;var newContentHeight=factor*contentHeight;if(type===types_1.ImageFit.Contain&&newContentHeight>viewportHeight||type===types_1.ImageFit.Cover&&viewportHeight>newContentHeight){factor=viewportHeight/newContentHeight;newContentWidth=factor*newContentWidth;newContentHeight=viewportHeight}var x=(viewportWidth-newContentWidth)/2;var y=(viewportHeight-newContentHeight)/2;return{x:x,y:y,w:newContentWidth,h:newContentHeight}};return VirtualBackgroundProcessor}(BackgroundProcessor_1.BackgroundProcessor);exports.VirtualBackgroundProcessor=VirtualBackgroundProcessor},{"../../types":16,"./BackgroundProcessor":4}],7:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.inputResolutions=void 0;exports.inputResolutions={"640x360":[640,360],"256x256":[256,256],"256x144":[256,144],"160x96":[160,96]}},{}],8:[function(require,module,exports){"use strict";var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){function adopt(value){return value instanceof P?value:new P(function(resolve){resolve(value)})}return new(P||(P=Promise))(function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator["throw"](value))}catch(e){reject(e)}}function step(result){result.done?resolve(result.value):adopt(result.value).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())})};var __generator=this&&this.__generator||function(thisArg,body){var _={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},f,y,t,g;return g={next:verb(0),throw:verb(1),return:verb(2)},typeof Symbol==="function"&&(g[Symbol.iterator]=function(){return this}),g;function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");while(g&&(g=0,op[0]&&(_=0)),_)try{if(f=1,y&&(t=op[0]&2?y["return"]:op[0]?y["throw"]||((t=y["return"])&&t.call(y),0):y.next)&&!(t=t.call(y,op[1])).done)return t;if(y=0,t)op=[op[0]&2,t.value];switch(op[0]){case 0:case 1:t=op;break;case 4:_.label++;return{value:op[1],done:false};case 5:_.label++;y=op[1];op=[0];continue;case 7:op=_.ops.pop();_.trys.pop();continue;default:if(!(t=_.trys,t=t.length>0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]= 4.0) {\n outColor = vec4(vec3(0.0), 1.0);\n } else {\n for (float i = -u_radius + u_offset; i <= u_radius; i += u_step) {\n for (float j = -u_radius + u_offset; j <= u_radius; j += u_step) {\n vec2 shift = vec2(j, i) * u_texelSize;\n vec2 coord = vec2(centerCoord + shift);\n vec3 frameColor = texture(u_inputFrame, coord).rgb;\n float outVal = texture(u_segmentationMask, coord).a;\n\n spaceWeight = gaussian(distance(centerCoord, coord), u_sigmaTexel);\n colorWeight = gaussian(distance(centerColor, frameColor), u_sigmaColor);\n totalWeight += spaceWeight * colorWeight;\n\n newVal += spaceWeight * colorWeight * outVal;\n }\n }\n newVal /= totalWeight;\n\n outColor = vec4(vec3(0.0), newVal);\n }\n }\n "],["#version 300 es\n\n precision highp float;\n\n uniform sampler2D u_inputFrame;\n uniform sampler2D u_segmentationMask;\n uniform vec2 u_texelSize;\n uniform float u_step;\n uniform float u_radius;\n uniform float u_offset;\n uniform float u_sigmaTexel;\n uniform float u_sigmaColor;\n\n in vec2 v_texCoord;\n\n out vec4 outColor;\n\n float gaussian(float x, float sigma) {\n float coeff = -0.5 / (sigma * sigma * 4.0 + 1.0e-6);\n return exp((x * x) * coeff);\n }\n\n void main() {\n vec2 centerCoord = v_texCoord;\n vec3 centerColor = texture(u_inputFrame, centerCoord).rgb;\n float newVal = 0.0;\n\n float spaceWeight = 0.0;\n float colorWeight = 0.0;\n float totalWeight = 0.0;\n\n vec2 leftTopCoord = vec2(centerCoord + vec2(-u_radius, -u_radius) * u_texelSize);\n vec2 rightTopCoord = vec2(centerCoord + vec2(u_radius, -u_radius) * u_texelSize);\n vec2 leftBottomCoord = vec2(centerCoord + vec2(-u_radius, u_radius) * u_texelSize);\n vec2 rightBottomCoord = vec2(centerCoord + vec2(u_radius, u_radius) * u_texelSize);\n\n float leftTopSegAlpha = texture(u_segmentationMask, leftTopCoord).a;\n float rightTopSegAlpha = texture(u_segmentationMask, rightTopCoord).a;\n float leftBottomSegAlpha = texture(u_segmentationMask, leftBottomCoord).a;\n float rightBottomSegAlpha = texture(u_segmentationMask, rightBottomCoord).a;\n float totalSegAlpha = leftTopSegAlpha + rightTopSegAlpha + leftBottomSegAlpha + rightBottomSegAlpha;\n\n if (totalSegAlpha <= 0.0) {\n outColor = vec4(vec3(0.0), 0.0);\n } else if (totalSegAlpha >= 4.0) {\n outColor = vec4(vec3(0.0), 1.0);\n } else {\n for (float i = -u_radius + u_offset; i <= u_radius; i += u_step) {\n for (float j = -u_radius + u_offset; j <= u_radius; j += u_step) {\n vec2 shift = vec2(j, i) * u_texelSize;\n vec2 coord = vec2(centerCoord + shift);\n vec3 frameColor = texture(u_inputFrame, coord).rgb;\n float outVal = texture(u_segmentationMask, coord).a;\n\n spaceWeight = gaussian(distance(centerCoord, coord), u_sigmaTexel);\n colorWeight = gaussian(distance(centerColor, frameColor), u_sigmaColor);\n totalWeight += spaceWeight * colorWeight;\n\n newVal += spaceWeight * colorWeight * outVal;\n }\n }\n newVal /= totalWeight;\n\n outColor = vec4(vec3(0.0), newVal);\n }\n }\n "])));var _a=segmentationHelper_1.inputResolutions[segmentationConfig.inputResolution],segmentationWidth=_a[0],segmentationHeight=_a[1];var outputWidth=canvas.width,outputHeight=canvas.height;var texelWidth=1/outputWidth;var texelHeight=1/outputHeight;var fragmentShader=(0,webglHelper_1.compileShader)(gl,gl.FRAGMENT_SHADER,fragmentShaderSource);var program=(0,webglHelper_1.createPiplelineStageProgram)(gl,vertexShader,fragmentShader,positionBuffer,texCoordBuffer);var inputFrameLocation=gl.getUniformLocation(program,"u_inputFrame");var segmentationMaskLocation=gl.getUniformLocation(program,"u_segmentationMask");var texelSizeLocation=gl.getUniformLocation(program,"u_texelSize");var stepLocation=gl.getUniformLocation(program,"u_step");var radiusLocation=gl.getUniformLocation(program,"u_radius");var offsetLocation=gl.getUniformLocation(program,"u_offset");var sigmaTexelLocation=gl.getUniformLocation(program,"u_sigmaTexel");var sigmaColorLocation=gl.getUniformLocation(program,"u_sigmaColor");var frameBuffer=gl.createFramebuffer();gl.bindFramebuffer(gl.FRAMEBUFFER,frameBuffer);gl.framebufferTexture2D(gl.FRAMEBUFFER,gl.COLOR_ATTACHMENT0,gl.TEXTURE_2D,outputTexture,0);gl.useProgram(program);gl.uniform1i(inputFrameLocation,0);gl.uniform1i(segmentationMaskLocation,1);gl.uniform2f(texelSizeLocation,texelWidth,texelHeight);updateSigmaSpace(0);updateSigmaColor(0);function render(){gl.viewport(0,0,outputWidth,outputHeight);gl.useProgram(program);gl.activeTexture(gl.TEXTURE1);gl.bindTexture(gl.TEXTURE_2D,inputTexture);gl.bindFramebuffer(gl.FRAMEBUFFER,frameBuffer);gl.drawArrays(gl.TRIANGLE_STRIP,0,4)}function updateSigmaSpace(sigmaSpace){sigmaSpace*=Math.max(outputWidth/segmentationWidth,outputHeight/segmentationHeight);var kSparsityFactor=.66;var sparsity=Math.max(1,Math.sqrt(sigmaSpace)*kSparsityFactor);var step=sparsity;var radius=sigmaSpace;var offset=step>1?step*.5:0;var sigmaTexel=Math.max(texelWidth,texelHeight)*sigmaSpace;gl.useProgram(program);gl.uniform1f(stepLocation,step);gl.uniform1f(radiusLocation,radius);gl.uniform1f(offsetLocation,offset);gl.uniform1f(sigmaTexelLocation,sigmaTexel)}function updateSigmaColor(sigmaColor){gl.useProgram(program);gl.uniform1f(sigmaColorLocation,sigmaColor)}function cleanUp(){gl.deleteFramebuffer(frameBuffer);gl.deleteProgram(program);gl.deleteShader(fragmentShader)}return{render:render,updateSigmaSpace:updateSigmaSpace,updateSigmaColor:updateSigmaColor,cleanUp:cleanUp}}exports.buildJointBilateralFilterStage=buildJointBilateralFilterStage;var templateObject_1},{"../helpers/segmentationHelper":7,"../helpers/webglHelper":8}],13:[function(require,module,exports){"use strict";var __makeTemplateObject=this&&this.__makeTemplateObject||function(cooked,raw){if(Object.defineProperty){Object.defineProperty(cooked,"raw",{value:raw})}else{cooked.raw=raw}return cooked};Object.defineProperty(exports,"__esModule",{value:true});exports.buildLoadSegmentationStage=void 0;var segmentationHelper_1=require("../helpers/segmentationHelper");var webglHelper_1=require("../helpers/webglHelper");function buildLoadSegmentationStage(gl,vertexShader,positionBuffer,texCoordBuffer,segmentationConfig,tflite,outputTexture){var fragmentShaderSource=(0,webglHelper_1.glsl)(templateObject_1||(templateObject_1=__makeTemplateObject(["#version 300 es\n\n precision highp float;\n\n uniform sampler2D u_inputSegmentation;\n\n in vec2 v_texCoord;\n\n out vec4 outColor;\n\n void main() {\n float segmentation = texture(u_inputSegmentation, v_texCoord).r;\n outColor = vec4(vec3(0.0), segmentation);\n }\n "],["#version 300 es\n\n precision highp float;\n\n uniform sampler2D u_inputSegmentation;\n\n in vec2 v_texCoord;\n\n out vec4 outColor;\n\n void main() {\n float segmentation = texture(u_inputSegmentation, v_texCoord).r;\n outColor = vec4(vec3(0.0), segmentation);\n }\n "])));var tfliteOutputMemoryOffset=tflite._getOutputMemoryOffset()/4;var _a=segmentationHelper_1.inputResolutions[segmentationConfig.inputResolution],segmentationWidth=_a[0],segmentationHeight=_a[1];var fragmentShader=(0,webglHelper_1.compileShader)(gl,gl.FRAGMENT_SHADER,fragmentShaderSource);var program=(0,webglHelper_1.createPiplelineStageProgram)(gl,vertexShader,fragmentShader,positionBuffer,texCoordBuffer);var inputLocation=gl.getUniformLocation(program,"u_inputSegmentation");var inputTexture=(0,webglHelper_1.createTexture)(gl,gl.R32F,segmentationWidth,segmentationHeight);var frameBuffer=gl.createFramebuffer();gl.bindFramebuffer(gl.FRAMEBUFFER,frameBuffer);gl.framebufferTexture2D(gl.FRAMEBUFFER,gl.COLOR_ATTACHMENT0,gl.TEXTURE_2D,outputTexture,0);gl.useProgram(program);gl.uniform1i(inputLocation,1);function render(){gl.viewport(0,0,segmentationWidth,segmentationHeight);gl.useProgram(program);gl.activeTexture(gl.TEXTURE1);gl.bindTexture(gl.TEXTURE_2D,inputTexture);gl.texSubImage2D(gl.TEXTURE_2D,0,0,0,segmentationWidth,segmentationHeight,gl.RED,gl.FLOAT,tflite.HEAPF32,tfliteOutputMemoryOffset);gl.bindFramebuffer(gl.FRAMEBUFFER,frameBuffer);gl.drawArrays(gl.TRIANGLE_STRIP,0,4)}function cleanUp(){gl.deleteFramebuffer(frameBuffer);gl.deleteTexture(inputTexture);gl.deleteProgram(program);gl.deleteShader(fragmentShader)}return{render:render,cleanUp:cleanUp}}exports.buildLoadSegmentationStage=buildLoadSegmentationStage;var templateObject_1},{"../helpers/segmentationHelper":7,"../helpers/webglHelper":8}],14:[function(require,module,exports){"use strict";var __makeTemplateObject=this&&this.__makeTemplateObject||function(cooked,raw){if(Object.defineProperty){Object.defineProperty(cooked,"raw",{value:raw})}else{cooked.raw=raw}return cooked};Object.defineProperty(exports,"__esModule",{value:true});exports.buildResizingStage=void 0;var segmentationHelper_1=require("../helpers/segmentationHelper");var webglHelper_1=require("../helpers/webglHelper");function buildResizingStage(gl,vertexShader,positionBuffer,texCoordBuffer,segmentationConfig,tflite){var fragmentShaderSource=(0,webglHelper_1.glsl)(templateObject_1||(templateObject_1=__makeTemplateObject(["#version 300 es\n\n precision highp float;\n\n uniform sampler2D u_inputFrame;\n\n in vec2 v_texCoord;\n\n out vec4 outColor;\n\n void main() {\n outColor = texture(u_inputFrame, v_texCoord);\n }\n "],["#version 300 es\n\n precision highp float;\n\n uniform sampler2D u_inputFrame;\n\n in vec2 v_texCoord;\n\n out vec4 outColor;\n\n void main() {\n outColor = texture(u_inputFrame, v_texCoord);\n }\n "])));var tfliteInputMemoryOffset=tflite._getInputMemoryOffset()/4;var _a=segmentationHelper_1.inputResolutions[segmentationConfig.inputResolution],outputWidth=_a[0],outputHeight=_a[1];var outputPixelCount=outputWidth*outputHeight;var fragmentShader=(0,webglHelper_1.compileShader)(gl,gl.FRAGMENT_SHADER,fragmentShaderSource);var program=(0,webglHelper_1.createPiplelineStageProgram)(gl,vertexShader,fragmentShader,positionBuffer,texCoordBuffer);var inputFrameLocation=gl.getUniformLocation(program,"u_inputFrame");var outputTexture=(0,webglHelper_1.createTexture)(gl,gl.RGBA8,outputWidth,outputHeight);var frameBuffer=gl.createFramebuffer();gl.bindFramebuffer(gl.FRAMEBUFFER,frameBuffer);gl.framebufferTexture2D(gl.FRAMEBUFFER,gl.COLOR_ATTACHMENT0,gl.TEXTURE_2D,outputTexture,0);var outputPixels=new Uint8Array(outputPixelCount*4);gl.useProgram(program);gl.uniform1i(inputFrameLocation,0);function render(){gl.viewport(0,0,outputWidth,outputHeight);gl.useProgram(program);gl.bindFramebuffer(gl.FRAMEBUFFER,frameBuffer);gl.drawArrays(gl.TRIANGLE_STRIP,0,4);(0,webglHelper_1.readPixelsAsync)(gl,0,0,outputWidth,outputHeight,gl.RGBA,gl.UNSIGNED_BYTE,outputPixels);for(var i=0;i0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]Benchmark.cacheSize){timingCache.splice(0,timingCache.length-Benchmark.cacheSize)}};Benchmark.cacheSize=41;return Benchmark}();exports.Benchmark=Benchmark},{}],18:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isSupported=exports.isBrowserSupported=void 0;function getCanvas(){return typeof window.OffscreenCanvas!=="undefined"?new window.OffscreenCanvas(1,1):document.createElement("canvas")}function isBrowserSupported(){if(typeof window!=="undefined"&&typeof document!=="undefined"){return!!(getCanvas().getContext("2d")||getCanvas().getContext("webgl2"))}else{return false}}exports.isBrowserSupported=isBrowserSupported;exports.isSupported=isBrowserSupported()},{}],19:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.version=void 0;exports.version="2.1.0-rc2"},{}]},{},[2]); \ No newline at end of file diff --git a/index.html b/index.html index 5d082df..644b49c 100644 --- a/index.html +++ b/index.html @@ -12,7 +12,10 @@

@twilio/video-processors

-

Twilio Video Processors

Twilio Video Processors is a collection of video processing tools which can be used with Twilio Video JavaScript SDK to apply transformations and filters to a VideoTrack.

+

Twilio Video Processors

+

[!WARNING]
We are no longer allowing new customers to onboard to Twilio Video. Effective December 5th, 2024, Twilio Video will End of Life (EOL) and will cease to function for all customers. Customers may transition to any video provider they choose, however, we are recommending customers migrate to the Zoom Video SDK and we have prepared a Migration Guide. Additional information on this EOL is available in our Help Center here.

+
+

Twilio Video Processors is a collection of video processing tools which can be used with Twilio Video JavaScript SDK to apply transformations and filters to a VideoTrack.

   See it live here!

Features

The following Video Processors are provided to apply transformations and filters to a person's background. You can also use them as a reference for creating your own Video Processors that can be used with Twilio Video JavaScript SDK.

    @@ -93,4 +96,4 @@

    version

Generated using TypeDoc

-
+
\ No newline at end of file diff --git a/variables/version.html b/variables/version.html index 02191ac..444ac63 100644 --- a/variables/version.html +++ b/variables/version.html @@ -15,7 +15,7 @@
  • @twilio/video-processors
  • version
  • Variable versionConst

    -
    version: string = '2.1.0-rc1'
    +
    version: string = '2.1.0-rc2'

    The current version of the library.