@100mslive/hms-virtual-background 1.3.4 → 1.3.6
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/HMSVirtualBackgroundPlugin.d.ts +17 -5
- package/dist/hms-virtual-background.cjs.development.js +233 -79
- package/dist/hms-virtual-background.cjs.development.js.map +1 -1
- package/dist/hms-virtual-background.cjs.production.min.js +1 -1
- package/dist/hms-virtual-background.cjs.production.min.js.map +1 -1
- package/dist/hms-virtual-background.esm.js +233 -79
- package/dist/hms-virtual-background.esm.js.map +1 -1
- package/package.json +13 -8
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import '@tensorflow/tfjs-backend-webgl';
|
|
2
|
+
import { parseGIF, decompressFrames } from 'gifuct-js';
|
|
2
3
|
import { HMSVideoPluginType } from '@100mslive/hms-video';
|
|
3
4
|
|
|
4
5
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
@@ -913,8 +914,9 @@ var loadTFLite = /*#__PURE__*/function () {
|
|
|
913
914
|
}();
|
|
914
915
|
|
|
915
916
|
var TAG$1 = 'VBProcessor';
|
|
917
|
+
var DEFAULT_DELAY = 33;
|
|
916
918
|
|
|
917
|
-
var pkg$1 = /*#__PURE__*/require(
|
|
919
|
+
var pkg$1 = /*#__PURE__*/require('../package.json');
|
|
918
920
|
|
|
919
921
|
var minVideoWidthForSharpening = 214;
|
|
920
922
|
var maxVideoWidthForSharpening = 855;
|
|
@@ -926,7 +928,11 @@ var HMSVirtualBackgroundPlugin = /*#__PURE__*/function () {
|
|
|
926
928
|
enableSharpening = false;
|
|
927
929
|
}
|
|
928
930
|
|
|
931
|
+
this.backgroundType = 'none';
|
|
929
932
|
this.background = background;
|
|
933
|
+
this.enableSharpening = enableSharpening;
|
|
934
|
+
this.backgroundImage = null;
|
|
935
|
+
this.backgroundVideo = null;
|
|
930
936
|
this.personMaskWidth = 256;
|
|
931
937
|
this.personMaskHeight = 144;
|
|
932
938
|
this.isVirtualBackground = false;
|
|
@@ -946,8 +952,14 @@ var HMSVirtualBackgroundPlugin = /*#__PURE__*/function () {
|
|
|
946
952
|
this.personMaskCanvas.height = this.personMaskHeight;
|
|
947
953
|
this.personMaskCtx = this.personMaskCanvas.getContext('2d');
|
|
948
954
|
this.filters = {};
|
|
955
|
+
this.gifFrames = null;
|
|
956
|
+
this.gifFramesIndex = 0;
|
|
957
|
+
this.gifFrameImageData = null;
|
|
958
|
+
this.tempGifCanvas = document.createElement('canvas');
|
|
959
|
+
this.tempGifContext = this.tempGifCanvas.getContext('2d');
|
|
960
|
+
this.giflocalCount = 0;
|
|
949
961
|
this.enableSharpening = enableSharpening;
|
|
950
|
-
this.log(TAG$1,
|
|
962
|
+
this.log(TAG$1, 'Virtual Background plugin created');
|
|
951
963
|
this.setBackground(this.background);
|
|
952
964
|
}
|
|
953
965
|
|
|
@@ -964,7 +976,7 @@ var HMSVirtualBackgroundPlugin = /*#__PURE__*/function () {
|
|
|
964
976
|
break;
|
|
965
977
|
}
|
|
966
978
|
|
|
967
|
-
this.log(TAG$1,
|
|
979
|
+
this.log(TAG$1, 'PREVIOUS LOADED MODEL IS ', this.tfLite);
|
|
968
980
|
this.loadModelCalled = true;
|
|
969
981
|
this.tfLitePromise = loadTFLite();
|
|
970
982
|
_context.next = 6;
|
|
@@ -1001,7 +1013,7 @@ var HMSVirtualBackgroundPlugin = /*#__PURE__*/function () {
|
|
|
1001
1013
|
|
|
1002
1014
|
_proto.isSupported = function isSupported() {
|
|
1003
1015
|
//support chrome, firefox, edge TODO: check this
|
|
1004
|
-
return navigator.userAgent.indexOf(
|
|
1016
|
+
return navigator.userAgent.indexOf('Chrome') !== -1 || navigator.userAgent.indexOf('Firefox') !== -1 || navigator.userAgent.indexOf('Edg') !== -1;
|
|
1005
1017
|
};
|
|
1006
1018
|
|
|
1007
1019
|
_proto.getName = function getName() {
|
|
@@ -1013,71 +1025,145 @@ var HMSVirtualBackgroundPlugin = /*#__PURE__*/function () {
|
|
|
1013
1025
|
};
|
|
1014
1026
|
|
|
1015
1027
|
_proto.setBackground = /*#__PURE__*/function () {
|
|
1016
|
-
var _setBackground = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function
|
|
1028
|
+
var _setBackground = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(path) {
|
|
1029
|
+
var _this = this;
|
|
1030
|
+
|
|
1017
1031
|
var img;
|
|
1018
|
-
return runtime_1.wrap(function
|
|
1032
|
+
return runtime_1.wrap(function _callee3$(_context3) {
|
|
1019
1033
|
while (1) {
|
|
1020
|
-
switch (
|
|
1034
|
+
switch (_context3.prev = _context3.next) {
|
|
1021
1035
|
case 0:
|
|
1022
|
-
if (!(path !==
|
|
1023
|
-
|
|
1036
|
+
if (!(path !== '')) {
|
|
1037
|
+
_context3.next = 50;
|
|
1024
1038
|
break;
|
|
1025
1039
|
}
|
|
1026
1040
|
|
|
1027
|
-
if (!(path ===
|
|
1028
|
-
|
|
1041
|
+
if (!(path === 'none')) {
|
|
1042
|
+
_context3.next = 8;
|
|
1029
1043
|
break;
|
|
1030
1044
|
}
|
|
1031
1045
|
|
|
1032
1046
|
this.log(TAG$1, 'setting background to :', path);
|
|
1033
|
-
this.background =
|
|
1047
|
+
this.background = 'none';
|
|
1048
|
+
this.backgroundType = 'none';
|
|
1034
1049
|
this.isVirtualBackground = false;
|
|
1035
|
-
|
|
1050
|
+
_context3.next = 48;
|
|
1036
1051
|
break;
|
|
1037
1052
|
|
|
1038
|
-
case
|
|
1039
|
-
if (!(path ===
|
|
1040
|
-
|
|
1053
|
+
case 8:
|
|
1054
|
+
if (!(path === 'blur')) {
|
|
1055
|
+
_context3.next = 15;
|
|
1041
1056
|
break;
|
|
1042
1057
|
}
|
|
1043
1058
|
|
|
1044
1059
|
this.log(TAG$1, 'setting background to :', path);
|
|
1045
|
-
this.background =
|
|
1060
|
+
this.background = 'blur';
|
|
1061
|
+
this.backgroundType = 'blur';
|
|
1046
1062
|
this.isVirtualBackground = false;
|
|
1047
|
-
|
|
1063
|
+
_context3.next = 48;
|
|
1048
1064
|
break;
|
|
1049
1065
|
|
|
1050
|
-
case
|
|
1051
|
-
|
|
1066
|
+
case 15:
|
|
1067
|
+
if (!(path instanceof HTMLImageElement)) {
|
|
1068
|
+
_context3.next = 29;
|
|
1069
|
+
break;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
this.log('setting background to image', path);
|
|
1073
|
+
_context3.next = 19;
|
|
1052
1074
|
return this.setImage(path);
|
|
1053
1075
|
|
|
1054
|
-
case
|
|
1055
|
-
img =
|
|
1076
|
+
case 19:
|
|
1077
|
+
img = _context3.sent;
|
|
1056
1078
|
|
|
1057
1079
|
if (!(!img || !img.complete || !img.naturalHeight)) {
|
|
1058
|
-
|
|
1080
|
+
_context3.next = 24;
|
|
1059
1081
|
break;
|
|
1060
1082
|
}
|
|
1061
1083
|
|
|
1062
1084
|
throw new Error('Invalid image. Provide a valid and successfully loaded HTMLImageElement');
|
|
1063
1085
|
|
|
1064
|
-
case
|
|
1086
|
+
case 24:
|
|
1065
1087
|
this.isVirtualBackground = true;
|
|
1066
1088
|
this.backgroundImage = img;
|
|
1089
|
+
this.backgroundType = 'image';
|
|
1067
1090
|
|
|
1068
|
-
case
|
|
1069
|
-
|
|
1091
|
+
case 27:
|
|
1092
|
+
_context3.next = 48;
|
|
1070
1093
|
break;
|
|
1071
1094
|
|
|
1072
|
-
case
|
|
1073
|
-
|
|
1095
|
+
case 29:
|
|
1096
|
+
if (!(path instanceof HTMLVideoElement)) {
|
|
1097
|
+
_context3.next = 38;
|
|
1098
|
+
break;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
this.log('setting background to video', path);
|
|
1102
|
+
this.backgroundVideo = path;
|
|
1103
|
+
this.backgroundVideo.crossOrigin = 'anonymous';
|
|
1104
|
+
this.backgroundVideo.muted = true;
|
|
1105
|
+
this.backgroundVideo.loop = true;
|
|
1106
|
+
this.backgroundVideo.oncanplaythrough = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
|
|
1107
|
+
return runtime_1.wrap(function _callee2$(_context2) {
|
|
1108
|
+
while (1) {
|
|
1109
|
+
switch (_context2.prev = _context2.next) {
|
|
1110
|
+
case 0:
|
|
1111
|
+
if (!(_this.backgroundVideo != null)) {
|
|
1112
|
+
_context2.next = 5;
|
|
1113
|
+
break;
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
_context2.next = 3;
|
|
1117
|
+
return _this.backgroundVideo.play();
|
|
1118
|
+
|
|
1119
|
+
case 3:
|
|
1120
|
+
_this.isVirtualBackground = true;
|
|
1121
|
+
_this.backgroundType = 'video';
|
|
1122
|
+
|
|
1123
|
+
case 5:
|
|
1124
|
+
case "end":
|
|
1125
|
+
return _context2.stop();
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
}, _callee2);
|
|
1129
|
+
}));
|
|
1130
|
+
_context3.next = 48;
|
|
1131
|
+
break;
|
|
1132
|
+
|
|
1133
|
+
case 38:
|
|
1134
|
+
console.log('setting gif to background');
|
|
1135
|
+
_context3.next = 41;
|
|
1136
|
+
return this.setGiF(path);
|
|
1074
1137
|
|
|
1075
|
-
case
|
|
1138
|
+
case 41:
|
|
1139
|
+
this.gifFrames = _context3.sent;
|
|
1140
|
+
|
|
1141
|
+
if (!(this.gifFrames != null && this.gifFrames.length > 0)) {
|
|
1142
|
+
_context3.next = 47;
|
|
1143
|
+
break;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
this.backgroundType = 'gif';
|
|
1147
|
+
this.isVirtualBackground = true;
|
|
1148
|
+
_context3.next = 48;
|
|
1149
|
+
break;
|
|
1150
|
+
|
|
1151
|
+
case 47:
|
|
1152
|
+
throw new Error('Invalid background supplied, see the docs to check supported background type');
|
|
1153
|
+
|
|
1154
|
+
case 48:
|
|
1155
|
+
_context3.next = 51;
|
|
1156
|
+
break;
|
|
1157
|
+
|
|
1158
|
+
case 50:
|
|
1159
|
+
throw new Error('Invalid background supplied, see the docs to check supported background type');
|
|
1160
|
+
|
|
1161
|
+
case 51:
|
|
1076
1162
|
case "end":
|
|
1077
|
-
return
|
|
1163
|
+
return _context3.stop();
|
|
1078
1164
|
}
|
|
1079
1165
|
}
|
|
1080
|
-
},
|
|
1166
|
+
}, _callee3, this);
|
|
1081
1167
|
}));
|
|
1082
1168
|
|
|
1083
1169
|
function setBackground(_x) {
|
|
@@ -1089,19 +1175,31 @@ var HMSVirtualBackgroundPlugin = /*#__PURE__*/function () {
|
|
|
1089
1175
|
|
|
1090
1176
|
_proto.stop = function stop() {
|
|
1091
1177
|
if (this.isVirtualBackground) {
|
|
1092
|
-
var _this$backgroundImage;
|
|
1178
|
+
var _this$backgroundImage, _this$backgroundVideo;
|
|
1093
1179
|
|
|
1094
1180
|
(_this$backgroundImage = this.backgroundImage) == null ? void 0 : _this$backgroundImage.removeAttribute('src');
|
|
1181
|
+
(_this$backgroundVideo = this.backgroundVideo) == null ? void 0 : _this$backgroundVideo.removeAttribute('src');
|
|
1182
|
+
|
|
1183
|
+
if (this.backgroundType === 'video') {
|
|
1184
|
+
this.backgroundVideo.loop = false;
|
|
1185
|
+
this.backgroundVideo = null;
|
|
1186
|
+
}
|
|
1095
1187
|
}
|
|
1096
1188
|
|
|
1097
1189
|
if (this.outputCtx) {
|
|
1098
1190
|
this.outputCtx.fillStyle = "rgb(0, 0, 0)";
|
|
1099
1191
|
this.outputCtx.fillRect(0, 0, this.output.width, this.output.height);
|
|
1100
|
-
}
|
|
1192
|
+
} //gif related
|
|
1193
|
+
|
|
1194
|
+
|
|
1195
|
+
this.gifFrameImageData = null;
|
|
1196
|
+
this.gifFrames = null;
|
|
1197
|
+
this.giflocalCount = 0;
|
|
1198
|
+
this.gifFramesIndex = 0;
|
|
1101
1199
|
};
|
|
1102
1200
|
|
|
1103
1201
|
_proto.processVideoFrame = function processVideoFrame(input, output, skipProcessing) {
|
|
1104
|
-
var
|
|
1202
|
+
var _this2 = this;
|
|
1105
1203
|
|
|
1106
1204
|
if (!input || !output) {
|
|
1107
1205
|
throw new Error('Plugin invalid input/output');
|
|
@@ -1119,36 +1217,41 @@ var HMSVirtualBackgroundPlugin = /*#__PURE__*/function () {
|
|
|
1119
1217
|
ctx.canvas.height = input.height;
|
|
1120
1218
|
}
|
|
1121
1219
|
|
|
1220
|
+
if (this.backgroundType === 'video') {
|
|
1221
|
+
this.backgroundVideo.width = input.width;
|
|
1222
|
+
this.backgroundVideo.height = input.height;
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1122
1225
|
this.outputCtx = ctx;
|
|
1123
1226
|
this.imageAspectRatio = input.width / input.height;
|
|
1124
1227
|
|
|
1125
1228
|
if (this.imageAspectRatio <= 0) {
|
|
1126
|
-
throw new Error(
|
|
1229
|
+
throw new Error('Invalid input width/height');
|
|
1127
1230
|
}
|
|
1128
1231
|
|
|
1129
1232
|
var process = /*#__PURE__*/function () {
|
|
1130
|
-
var
|
|
1131
|
-
return runtime_1.wrap(function
|
|
1233
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
|
|
1234
|
+
return runtime_1.wrap(function _callee4$(_context4) {
|
|
1132
1235
|
while (1) {
|
|
1133
|
-
switch (
|
|
1236
|
+
switch (_context4.prev = _context4.next) {
|
|
1134
1237
|
case 0:
|
|
1135
|
-
|
|
1136
|
-
return
|
|
1238
|
+
_context4.next = 2;
|
|
1239
|
+
return _this2.runSegmentation(skipProcessing);
|
|
1137
1240
|
|
|
1138
1241
|
case 2:
|
|
1139
1242
|
case "end":
|
|
1140
|
-
return
|
|
1243
|
+
return _context4.stop();
|
|
1141
1244
|
}
|
|
1142
1245
|
}
|
|
1143
|
-
},
|
|
1246
|
+
}, _callee4);
|
|
1144
1247
|
}));
|
|
1145
1248
|
|
|
1146
1249
|
return function process() {
|
|
1147
|
-
return
|
|
1250
|
+
return _ref2.apply(this, arguments);
|
|
1148
1251
|
};
|
|
1149
1252
|
}();
|
|
1150
1253
|
|
|
1151
|
-
if (this.background ===
|
|
1254
|
+
if (this.background === 'none' && !this.isVirtualBackground) {
|
|
1152
1255
|
this.outputCtx.globalCompositeOperation = 'copy';
|
|
1153
1256
|
this.outputCtx.filter = 'none';
|
|
1154
1257
|
this.outputCtx.drawImage(input, 0, 0, input.width, input.height);
|
|
@@ -1158,13 +1261,13 @@ var HMSVirtualBackgroundPlugin = /*#__PURE__*/function () {
|
|
|
1158
1261
|
};
|
|
1159
1262
|
|
|
1160
1263
|
_proto.setImage = /*#__PURE__*/function () {
|
|
1161
|
-
var _setImage = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function
|
|
1162
|
-
return runtime_1.wrap(function
|
|
1264
|
+
var _setImage = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(image) {
|
|
1265
|
+
return runtime_1.wrap(function _callee5$(_context5) {
|
|
1163
1266
|
while (1) {
|
|
1164
|
-
switch (
|
|
1267
|
+
switch (_context5.prev = _context5.next) {
|
|
1165
1268
|
case 0:
|
|
1166
1269
|
image.crossOrigin = 'anonymous';
|
|
1167
|
-
return
|
|
1270
|
+
return _context5.abrupt("return", new Promise(function (resolve, reject) {
|
|
1168
1271
|
image.onload = function () {
|
|
1169
1272
|
return resolve(image);
|
|
1170
1273
|
};
|
|
@@ -1174,10 +1277,10 @@ var HMSVirtualBackgroundPlugin = /*#__PURE__*/function () {
|
|
|
1174
1277
|
|
|
1175
1278
|
case 2:
|
|
1176
1279
|
case "end":
|
|
1177
|
-
return
|
|
1280
|
+
return _context5.stop();
|
|
1178
1281
|
}
|
|
1179
1282
|
}
|
|
1180
|
-
},
|
|
1283
|
+
}, _callee5);
|
|
1181
1284
|
}));
|
|
1182
1285
|
|
|
1183
1286
|
function setImage(_x2) {
|
|
@@ -1187,6 +1290,16 @@ var HMSVirtualBackgroundPlugin = /*#__PURE__*/function () {
|
|
|
1187
1290
|
return setImage;
|
|
1188
1291
|
}();
|
|
1189
1292
|
|
|
1293
|
+
_proto.setGiF = function setGiF(url) {
|
|
1294
|
+
return fetch(url).then(function (resp) {
|
|
1295
|
+
return resp.arrayBuffer();
|
|
1296
|
+
}).then(function (buff) {
|
|
1297
|
+
return parseGIF(buff);
|
|
1298
|
+
}).then(function (gif) {
|
|
1299
|
+
return decompressFrames(gif, true);
|
|
1300
|
+
});
|
|
1301
|
+
};
|
|
1302
|
+
|
|
1190
1303
|
_proto.log = function log(tag) {
|
|
1191
1304
|
var _console;
|
|
1192
1305
|
|
|
@@ -1199,7 +1312,8 @@ var HMSVirtualBackgroundPlugin = /*#__PURE__*/function () {
|
|
|
1199
1312
|
|
|
1200
1313
|
_proto.resizeInputData = function resizeInputData() {
|
|
1201
1314
|
this.personMaskCtx.drawImage(this.input, 0, 0, this.input.width, this.input.height, 0, 0, this.personMaskWidth, this.personMaskHeight);
|
|
1202
|
-
var imageData = this.personMaskCtx.getImageData(0, 0, this.personMaskWidth, this.personMaskHeight);
|
|
1315
|
+
var imageData = this.personMaskCtx.getImageData(0, 0, this.personMaskWidth, this.personMaskHeight); //
|
|
1316
|
+
|
|
1203
1317
|
var inputMemoryOffset = this.tfLite._getInputMemoryOffset() / 4;
|
|
1204
1318
|
|
|
1205
1319
|
for (var i = 0; i < this.personMaskPixelCount; i++) {
|
|
@@ -1285,26 +1399,44 @@ var HMSVirtualBackgroundPlugin = /*#__PURE__*/function () {
|
|
|
1285
1399
|
this.outputCtx.imageSmoothingQuality = 'high';
|
|
1286
1400
|
|
|
1287
1401
|
if (this.isVirtualBackground) {
|
|
1288
|
-
this.
|
|
1402
|
+
if (this.backgroundType === 'video' && this.backgroundVideo != null && this.backgroundVideo.readyState >= 4) {
|
|
1403
|
+
this.fitVideoToBackground();
|
|
1404
|
+
} else if (this.backgroundType === 'image') {
|
|
1405
|
+
this.fitImageToBackground();
|
|
1406
|
+
} else if (this.backgroundType === 'gif') {
|
|
1407
|
+
if (this.giflocalCount > this.gifFrames[this.gifFramesIndex].delay / DEFAULT_DELAY) {
|
|
1408
|
+
this.gifFramesIndex++;
|
|
1409
|
+
|
|
1410
|
+
if (this.gifFramesIndex >= this.gifFrames.length) {
|
|
1411
|
+
this.gifFramesIndex = 0;
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
this.giflocalCount = 0;
|
|
1415
|
+
} else {
|
|
1416
|
+
this.giflocalCount++;
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
this.fitGifToBackground();
|
|
1420
|
+
}
|
|
1289
1421
|
} else {
|
|
1290
1422
|
this.addBlurToBackground();
|
|
1291
1423
|
}
|
|
1292
1424
|
};
|
|
1293
1425
|
|
|
1294
1426
|
_proto.runSegmentation = /*#__PURE__*/function () {
|
|
1295
|
-
var _runSegmentation = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function
|
|
1296
|
-
return runtime_1.wrap(function
|
|
1427
|
+
var _runSegmentation = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(skipProcessing) {
|
|
1428
|
+
return runtime_1.wrap(function _callee6$(_context6) {
|
|
1297
1429
|
while (1) {
|
|
1298
|
-
switch (
|
|
1430
|
+
switch (_context6.prev = _context6.next) {
|
|
1299
1431
|
case 0:
|
|
1300
1432
|
if (!this.tfLite) {
|
|
1301
|
-
|
|
1433
|
+
_context6.next = 5;
|
|
1302
1434
|
break;
|
|
1303
1435
|
}
|
|
1304
1436
|
|
|
1305
1437
|
// const start = performance.now();
|
|
1306
1438
|
this.resizeInputData();
|
|
1307
|
-
|
|
1439
|
+
_context6.next = 4;
|
|
1308
1440
|
return this.infer(skipProcessing);
|
|
1309
1441
|
|
|
1310
1442
|
case 4:
|
|
@@ -1313,10 +1445,10 @@ var HMSVirtualBackgroundPlugin = /*#__PURE__*/function () {
|
|
|
1313
1445
|
|
|
1314
1446
|
case 5:
|
|
1315
1447
|
case "end":
|
|
1316
|
-
return
|
|
1448
|
+
return _context6.stop();
|
|
1317
1449
|
}
|
|
1318
1450
|
}
|
|
1319
|
-
},
|
|
1451
|
+
}, _callee6, this);
|
|
1320
1452
|
}));
|
|
1321
1453
|
|
|
1322
1454
|
function runSegmentation(_x3) {
|
|
@@ -1326,30 +1458,52 @@ var HMSVirtualBackgroundPlugin = /*#__PURE__*/function () {
|
|
|
1326
1458
|
return runSegmentation;
|
|
1327
1459
|
}();
|
|
1328
1460
|
|
|
1461
|
+
_proto.fitVideoToBackground = function fitVideoToBackground() {
|
|
1462
|
+
this.fitData(this.backgroundVideo, this.backgroundVideo.width, this.backgroundVideo.height);
|
|
1463
|
+
};
|
|
1464
|
+
|
|
1329
1465
|
_proto.fitImageToBackground = function fitImageToBackground() {
|
|
1330
|
-
|
|
1466
|
+
this.fitData(this.backgroundImage, this.backgroundImage.width, this.backgroundImage.height);
|
|
1467
|
+
};
|
|
1468
|
+
|
|
1469
|
+
_proto.fitGifToBackground = function fitGifToBackground() {
|
|
1470
|
+
if (this.gifFrameImageData == null) {
|
|
1471
|
+
var dims = this.gifFrames[this.gifFramesIndex].dims;
|
|
1472
|
+
this.tempGifCanvas.width = dims.width;
|
|
1473
|
+
this.tempGifCanvas.height = dims.height;
|
|
1474
|
+
this.gifFrameImageData = this.tempGifContext.createImageData(dims.width, dims.height);
|
|
1475
|
+
} // set the patch data as an override
|
|
1476
|
+
|
|
1331
1477
|
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1478
|
+
this.gifFrameImageData.data.set(this.gifFrames[this.gifFramesIndex].patch);
|
|
1479
|
+
this.tempGifContext.putImageData(this.gifFrameImageData, 0, 0);
|
|
1480
|
+
this.fitData(this.tempGifCanvas, this.gifFrameImageData.width, this.gifFrameImageData.height);
|
|
1481
|
+
};
|
|
1482
|
+
|
|
1483
|
+
_proto.fitData = function fitData(data, dataWidth, dataHeight) {
|
|
1484
|
+
var inputWidth, inputHeight, xoffset, yoffset;
|
|
1485
|
+
|
|
1486
|
+
if (dataWidth / dataHeight < this.imageAspectRatio) {
|
|
1487
|
+
inputWidth = dataWidth;
|
|
1488
|
+
inputHeight = dataWidth / this.imageAspectRatio;
|
|
1489
|
+
xoffset = 0;
|
|
1490
|
+
yoffset = (dataHeight - inputHeight) / 2;
|
|
1337
1491
|
} else {
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1492
|
+
inputHeight = dataHeight;
|
|
1493
|
+
inputWidth = dataHeight * this.imageAspectRatio;
|
|
1494
|
+
yoffset = 0;
|
|
1495
|
+
xoffset = (dataWidth - inputWidth) / 2;
|
|
1342
1496
|
}
|
|
1343
1497
|
|
|
1344
|
-
this.outputCtx.drawImage(
|
|
1498
|
+
this.outputCtx.drawImage(data, xoffset, yoffset, inputWidth, inputHeight, 0, 0, this.output.width, this.output.height);
|
|
1345
1499
|
};
|
|
1346
1500
|
|
|
1347
1501
|
_proto.addBlurToBackground = /*#__PURE__*/function () {
|
|
1348
|
-
var _addBlurToBackground = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function
|
|
1502
|
+
var _addBlurToBackground = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7() {
|
|
1349
1503
|
var blurValue;
|
|
1350
|
-
return runtime_1.wrap(function
|
|
1504
|
+
return runtime_1.wrap(function _callee7$(_context7) {
|
|
1351
1505
|
while (1) {
|
|
1352
|
-
switch (
|
|
1506
|
+
switch (_context7.prev = _context7.next) {
|
|
1353
1507
|
case 0:
|
|
1354
1508
|
blurValue = '15px';
|
|
1355
1509
|
if (this.input.width <= 160) blurValue = '5px';else if (this.input.width <= 320) blurValue = '10px';else if (this.input.width <= 640) blurValue = '15px';else if (this.input.width <= 960) blurValue = '20px';else if (this.input.width <= 1280) blurValue = '25px';else if (this.input.width <= 1920) blurValue = '30px';
|
|
@@ -1358,10 +1512,10 @@ var HMSVirtualBackgroundPlugin = /*#__PURE__*/function () {
|
|
|
1358
1512
|
|
|
1359
1513
|
case 4:
|
|
1360
1514
|
case "end":
|
|
1361
|
-
return
|
|
1515
|
+
return _context7.stop();
|
|
1362
1516
|
}
|
|
1363
1517
|
}
|
|
1364
|
-
},
|
|
1518
|
+
}, _callee7, this);
|
|
1365
1519
|
}));
|
|
1366
1520
|
|
|
1367
1521
|
function addBlurToBackground() {
|
|
@@ -1372,13 +1526,13 @@ var HMSVirtualBackgroundPlugin = /*#__PURE__*/function () {
|
|
|
1372
1526
|
}();
|
|
1373
1527
|
|
|
1374
1528
|
_proto.initSharpenFilter = function initSharpenFilter() {
|
|
1375
|
-
var
|
|
1529
|
+
var _this3 = this;
|
|
1376
1530
|
|
|
1377
1531
|
this.filters.tmpCanvas = document.createElement('canvas');
|
|
1378
1532
|
this.filters.tmpCtx = this.filters.tmpCanvas.getContext('2d');
|
|
1379
1533
|
|
|
1380
1534
|
this.filters.createImageData = function (w, h) {
|
|
1381
|
-
return
|
|
1535
|
+
return _this3.filters.tmpCtx.createImageData(w, h);
|
|
1382
1536
|
};
|
|
1383
1537
|
|
|
1384
1538
|
this.filters.convolute = function (pixels, weights, opaque) {
|
|
@@ -1395,7 +1549,7 @@ var HMSVirtualBackgroundPlugin = /*#__PURE__*/function () {
|
|
|
1395
1549
|
var w = sw;
|
|
1396
1550
|
var h = sh;
|
|
1397
1551
|
|
|
1398
|
-
var output =
|
|
1552
|
+
var output = _this3.filters.createImageData(w, h);
|
|
1399
1553
|
|
|
1400
1554
|
var dst = output.data; // go through the destination image pixels
|
|
1401
1555
|
|
|
@@ -1405,7 +1559,7 @@ var HMSVirtualBackgroundPlugin = /*#__PURE__*/function () {
|
|
|
1405
1559
|
for (var x = 0; x < w; x = x + 1) {
|
|
1406
1560
|
var dstOff = (y * w + x) * 4;
|
|
1407
1561
|
|
|
1408
|
-
if (src[dstOff + 3]
|
|
1562
|
+
if (src[dstOff + 3] === 0) {
|
|
1409
1563
|
continue;
|
|
1410
1564
|
} else if (x < w && y < h) {
|
|
1411
1565
|
var sy = y;
|