@tradalab/mediakit 1.1.0 → 1.2.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/dist/recipe.d.ts CHANGED
@@ -21,6 +21,14 @@ type BgFilter = {
21
21
  } | {
22
22
  kind: "image";
23
23
  imagePath: string;
24
+ }
25
+ /**
26
+ * The background becomes TRANSPARENT and the person stays: the output canvas carries the
27
+ * mask as alpha. For a {@link Scene} to put the person over another source; a plain video
28
+ * track has no alpha, so on its own this shows the person over black.
29
+ */
30
+ | {
31
+ kind: "cutout";
24
32
  };
25
33
  /** A colour as red, green, blue, each 0..1. */
26
34
  type Rgb = [number, number, number];
@@ -62,11 +70,26 @@ interface Effects {
62
70
  */
63
71
  lut: string;
64
72
  grade: number;
73
+ /**
74
+ * Take the person mask from a coloured screen instead of segmentation. Cheaper - MediaPipe
75
+ * is never loaded - and the edge keeps hair the model loses. `keyColor` is the screen's
76
+ * colour; [0, 0, 0] means "find it" from the frame's border. `keyTolerance` widens (+) or
77
+ * narrows (-) what counts as screen, -1..1 around a tuned default.
78
+ */
79
+ chromaKey: boolean;
80
+ keyColor: Rgb;
81
+ keyTolerance: number;
65
82
  /**
66
83
  * Lift exposure when the room is dark, on top of `exposure`. Only ever brightens. Needs no
67
84
  * detector: it reads the frame's own brightness.
68
85
  */
69
86
  autoLight: boolean;
87
+ /**
88
+ * Flip the picture left to right, as a selfie preview shows it. Costs nothing on top of any
89
+ * other effect; on its own it is one pass. Text on a whiteboard then reads backwards to
90
+ * everyone watching, which is why it is a choice and not the default.
91
+ */
92
+ mirror: boolean;
70
93
  /**
71
94
  * Jawline slimming, 0..1.
72
95
  *
@@ -112,6 +135,7 @@ declare function touchUpAmount(e: Effects): number;
112
135
  declare const MODE_NONE = 0;
113
136
  declare const MODE_BLUR = 1;
114
137
  declare const MODE_IMAGE = 2;
138
+ declare const MODE_CUTOUT = 3;
115
139
  declare function backgroundMode(f: BgFilter): number;
116
140
  /**
117
141
  * Whether this recipe needs the person mask.
@@ -124,6 +148,12 @@ declare function backgroundMode(f: BgFilter): number;
124
148
  * segmenter at all, BEFORE it can ask Go.
125
149
  */
126
150
  declare function needsMask(f: BgFilter, e: Effects): boolean;
151
+ /**
152
+ * Whether this recipe needs the SEGMENTER: a mask, and not one a colour key already gives.
153
+ * Must match `Recipe.NeedsSegmentation` on the Go side. This, not {@link needsMask}, decides
154
+ * whether MediaPipe is loaded - with `chromaKey` on, its 9 MB are never fetched.
155
+ */
156
+ declare function needsSegmentation(f: BgFilter, e: Effects): boolean;
127
157
  /**
128
158
  * Whether this recipe needs face landmarks.
129
159
  *
@@ -154,7 +184,11 @@ interface CoreRecipe {
154
184
  iris: number;
155
185
  irisColor: Rgb;
156
186
  grade: number;
187
+ chromaKey: boolean;
188
+ keyColor: Rgb;
189
+ keyTolerance: number;
157
190
  autoLight: boolean;
191
+ mirror: boolean;
158
192
  slimFace: number;
159
193
  enlargeEyes: number;
160
194
  noseSlim: number;
@@ -162,4 +196,4 @@ interface CoreRecipe {
162
196
  }
163
197
  declare function coreRecipe(f: BgFilter, e: Effects): CoreRecipe;
164
198
 
165
- export { type BgFilter, type CoreRecipe, type Effects, MODE_BLUR, MODE_IMAGE, MODE_NONE, NO_EFFECTS, type Rgb, TOUCH_UP, backgroundMode, coreRecipe, needsFace, needsMask, touchUp, touchUpAmount };
199
+ export { type BgFilter, type CoreRecipe, type Effects, MODE_BLUR, MODE_CUTOUT, MODE_IMAGE, MODE_NONE, NO_EFFECTS, type Rgb, TOUCH_UP, backgroundMode, coreRecipe, needsFace, needsMask, needsSegmentation, touchUp, touchUpAmount };
package/dist/recipe.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  MODE_BLUR,
3
+ MODE_CUTOUT,
3
4
  MODE_IMAGE,
4
5
  MODE_NONE,
5
6
  NO_EFFECTS,
@@ -8,11 +9,13 @@ import {
8
9
  coreRecipe,
9
10
  needsFace,
10
11
  needsMask,
12
+ needsSegmentation,
11
13
  touchUp,
12
14
  touchUpAmount
13
- } from "./chunk-XLLQ74JA.js";
15
+ } from "./chunk-V47SDU4L.js";
14
16
  export {
15
17
  MODE_BLUR,
18
+ MODE_CUTOUT,
16
19
  MODE_IMAGE,
17
20
  MODE_NONE,
18
21
  NO_EFFECTS,
@@ -21,6 +24,7 @@ export {
21
24
  coreRecipe,
22
25
  needsFace,
23
26
  needsMask,
27
+ needsSegmentation,
24
28
  touchUp,
25
29
  touchUpAmount
26
30
  };
package/dist/worker.js CHANGED
@@ -4167,7 +4167,11 @@
4167
4167
  irisColor: [0.3, 0.5, 0.75],
4168
4168
  lut: "",
4169
4169
  grade: 0,
4170
+ chromaKey: false,
4171
+ keyColor: [0, 0, 0],
4172
+ keyTolerance: 0,
4170
4173
  autoLight: false,
4174
+ mirror: false,
4171
4175
  slimFace: 0,
4172
4176
  enlargeEyes: 0,
4173
4177
  noseSlim: 0,
@@ -4176,12 +4180,15 @@
4176
4180
  var MODE_NONE = 0;
4177
4181
  var MODE_BLUR = 1;
4178
4182
  var MODE_IMAGE = 2;
4183
+ var MODE_CUTOUT = 3;
4179
4184
  function backgroundMode(f2) {
4180
4185
  switch (f2.kind) {
4181
4186
  case "blur":
4182
4187
  return MODE_BLUR;
4183
4188
  case "image":
4184
4189
  return MODE_IMAGE;
4190
+ case "cutout":
4191
+ return MODE_CUTOUT;
4185
4192
  default:
4186
4193
  return MODE_NONE;
4187
4194
  }
@@ -4189,6 +4196,9 @@
4189
4196
  function needsMask(f2, e2) {
4190
4197
  return f2.kind !== "none" || e2.beautify > 0 || e2.autoframe;
4191
4198
  }
4199
+ function needsSegmentation(f2, e2) {
4200
+ return needsMask(f2, e2) && !e2.chromaKey;
4201
+ }
4192
4202
  function needsFace(e2) {
4193
4203
  return e2.teeth > 0 || e2.eyeBright > 0 || e2.underEye > 0 || e2.smileLines > 0 || e2.lips > 0 || e2.blush > 0 || e2.iris > 0 || e2.slimFace > 0 || e2.enlargeEyes > 0 || e2.noseSlim > 0 || e2.chin !== 0;
4194
4204
  }
@@ -4213,7 +4223,11 @@
4213
4223
  iris: e2.iris,
4214
4224
  irisColor: e2.irisColor,
4215
4225
  grade: e2.grade,
4226
+ chromaKey: e2.chromaKey,
4227
+ keyColor: e2.keyColor,
4228
+ keyTolerance: e2.keyTolerance,
4216
4229
  autoLight: e2.autoLight,
4230
+ mirror: e2.mirror,
4217
4231
  slimFace: e2.slimFace,
4218
4232
  enlargeEyes: e2.enlargeEyes,
4219
4233
  noseSlim: e2.noseSlim,
@@ -4288,12 +4302,16 @@
4288
4302
  canvas.height = height;
4289
4303
  return _Engine.on(canvas, filter, effects);
4290
4304
  }
4291
- /** `background`: see {@link Engine.setRecipe}. */
4292
- static async on(canvas, filter, effects = NO_EFFECTS, background) {
4305
+ /**
4306
+ * `background`: see {@link Engine.setRecipe}. `alpha` keeps the output's alpha channel, which
4307
+ * only a `cutout` background writes; it is fixed for the life of the context, so a host that
4308
+ * may switch to `cutout` later has to ask for it here.
4309
+ */
4310
+ static async on(canvas, filter, effects = NO_EFFECTS, background, alpha = false) {
4293
4311
  const width = canvas.width;
4294
4312
  const height = canvas.height;
4295
4313
  const gl = canvas.getContext("webgl2", {
4296
- alpha: false,
4314
+ alpha,
4297
4315
  premultipliedAlpha: false,
4298
4316
  antialias: false,
4299
4317
  depth: false,
@@ -4367,7 +4385,7 @@
4367
4385
  this.lutPath = effects.lut;
4368
4386
  }
4369
4387
  this.core.setRecipe(coreRecipe(filter, effects));
4370
- if (needsMask(filter, effects)) void this.ensureSegmenter();
4388
+ if (needsSegmentation(filter, effects)) void this.ensureSegmenter();
4371
4389
  if (needsFace(effects)) void this.ensureFace();
4372
4390
  }
4373
4391
  ensureFace() {