asciify-engine 1.0.46 → 1.0.48

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.d.cts CHANGED
@@ -135,14 +135,28 @@ interface AsciiOptions {
135
135
  * are keyed out: their character becomes a space and alpha is set to 0,
136
136
  * letting the canvas background show through.
137
137
  *
138
- * Accepts `{ r, g, b }`, a CSS colour string (`'#00ff00'`, `'blue'`, …),
139
- * or `null` to disable. Default: `null`
138
+ * - `true` **smart green screen**: heuristic detection (`g > r*1.4 && g > b*1.4`)
139
+ * catches every shade of green screen (lime, broadcast, chroma green) with no
140
+ * config. Works on virtually all studio/streaming footage.
141
+ * - `'blue-screen'` — **smart blue screen**: same heuristic for blue.
142
+ * - `{ r, g, b }` or CSS colour string — custom key colour + `chromaKeyTolerance`
143
+ * - `null` / `false` — disabled (default)
144
+ *
145
+ * @example
146
+ * // Standard green screen — zero config:
147
+ * options: { chromaKey: true }
148
+ *
149
+ * // Blue screen — zero config:
150
+ * options: { chromaKey: 'blue-screen' }
151
+ *
152
+ * // Custom CSS colour:
153
+ * options: { chromaKey: '#00b140', chromaKeyTolerance: 70 }
140
154
  */
141
155
  chromaKey: {
142
156
  r: number;
143
157
  g: number;
144
158
  b: number;
145
- } | string | null;
159
+ } | string | boolean | null;
146
160
  /**
147
161
  * Euclidean RGB tolerance radius for chroma-key detection.
148
162
  * `0` = exact match only, `441` ≈ key out everything.
package/dist/index.d.ts CHANGED
@@ -135,14 +135,28 @@ interface AsciiOptions {
135
135
  * are keyed out: their character becomes a space and alpha is set to 0,
136
136
  * letting the canvas background show through.
137
137
  *
138
- * Accepts `{ r, g, b }`, a CSS colour string (`'#00ff00'`, `'blue'`, …),
139
- * or `null` to disable. Default: `null`
138
+ * - `true` **smart green screen**: heuristic detection (`g > r*1.4 && g > b*1.4`)
139
+ * catches every shade of green screen (lime, broadcast, chroma green) with no
140
+ * config. Works on virtually all studio/streaming footage.
141
+ * - `'blue-screen'` — **smart blue screen**: same heuristic for blue.
142
+ * - `{ r, g, b }` or CSS colour string — custom key colour + `chromaKeyTolerance`
143
+ * - `null` / `false` — disabled (default)
144
+ *
145
+ * @example
146
+ * // Standard green screen — zero config:
147
+ * options: { chromaKey: true }
148
+ *
149
+ * // Blue screen — zero config:
150
+ * options: { chromaKey: 'blue-screen' }
151
+ *
152
+ * // Custom CSS colour:
153
+ * options: { chromaKey: '#00b140', chromaKeyTolerance: 70 }
140
154
  */
141
155
  chromaKey: {
142
156
  r: number;
143
157
  g: number;
144
158
  b: number;
145
- } | string | null;
159
+ } | string | boolean | null;
146
160
  /**
147
161
  * Euclidean RGB tolerance radius for chroma-key detection.
148
162
  * `0` = exact match only, `441` ≈ key out everything.
package/dist/index.js CHANGED
@@ -646,10 +646,14 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
646
646
  normRange = hi > lo ? hi - lo : 255;
647
647
  }
648
648
  const frame = [];
649
+ const ck = options.chromaKey;
650
+ const ckEnabled = ck != null && ck !== false;
651
+ const ckHeuristicGreen = ck === true;
652
+ const ckHeuristicBlue = ck === "blue-screen";
649
653
  let ckRGB = null;
650
654
  let ckTolSq = 0;
651
- if (options.chromaKey != null) {
652
- ckRGB = parseChromaKeyColor(options.chromaKey);
655
+ if (ckEnabled && !ckHeuristicGreen && !ckHeuristicBlue) {
656
+ ckRGB = parseChromaKeyColor(ck);
653
657
  ckTolSq = (options.chromaKeyTolerance ?? 60) ** 2;
654
658
  }
655
659
  for (let y = 0; y < rows; y++) {
@@ -660,11 +664,19 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
660
664
  const g = pixels[i + 1];
661
665
  const b = pixels[i + 2];
662
666
  const a = pixels[i + 3];
663
- if (ckRGB !== null) {
664
- const dr = r - ckRGB.r;
665
- const dg = g - ckRGB.g;
666
- const db = b - ckRGB.b;
667
- if (dr * dr + dg * dg + db * db <= ckTolSq) {
667
+ if (ckEnabled) {
668
+ let keyed = false;
669
+ if (ckHeuristicGreen) {
670
+ keyed = g > r * 1.4 && g > b * 1.4 && g > 80;
671
+ } else if (ckHeuristicBlue) {
672
+ keyed = b > r * 1.4 && b > g * 1.4 && b > 80;
673
+ } else if (ckRGB !== null) {
674
+ const dr = r - ckRGB.r;
675
+ const dg = g - ckRGB.g;
676
+ const db = b - ckRGB.b;
677
+ keyed = dr * dr + dg * dg + db * db <= ckTolSq;
678
+ }
679
+ if (keyed) {
668
680
  row.push({ char: " ", r: 0, g: 0, b: 0, a: 0 });
669
681
  continue;
670
682
  }