asciify-engine 1.0.47 → 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.cjs CHANGED
@@ -648,11 +648,14 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
648
648
  normRange = hi > lo ? hi - lo : 255;
649
649
  }
650
650
  const frame = [];
651
+ const ck = options.chromaKey;
652
+ const ckEnabled = ck != null && ck !== false;
653
+ const ckHeuristicGreen = ck === true;
654
+ const ckHeuristicBlue = ck === "blue-screen";
651
655
  let ckRGB = null;
652
656
  let ckTolSq = 0;
653
- const ck = options.chromaKey;
654
- if (ck != null && ck !== false) {
655
- ckRGB = ck === true ? { r: 0, g: 177, b: 64 } : parseChromaKeyColor(ck);
657
+ if (ckEnabled && !ckHeuristicGreen && !ckHeuristicBlue) {
658
+ ckRGB = parseChromaKeyColor(ck);
656
659
  ckTolSq = (options.chromaKeyTolerance ?? 60) ** 2;
657
660
  }
658
661
  for (let y = 0; y < rows; y++) {
@@ -663,11 +666,19 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
663
666
  const g = pixels[i + 1];
664
667
  const b = pixels[i + 2];
665
668
  const a = pixels[i + 3];
666
- if (ckRGB !== null) {
667
- const dr = r - ckRGB.r;
668
- const dg = g - ckRGB.g;
669
- const db = b - ckRGB.b;
670
- if (dr * dr + dg * dg + db * db <= ckTolSq) {
669
+ if (ckEnabled) {
670
+ let keyed = false;
671
+ if (ckHeuristicGreen) {
672
+ keyed = g > r * 1.4 && g > b * 1.4 && g > 80;
673
+ } else if (ckHeuristicBlue) {
674
+ keyed = b > r * 1.4 && b > g * 1.4 && b > 80;
675
+ } else if (ckRGB !== null) {
676
+ const dr = r - ckRGB.r;
677
+ const dg = g - ckRGB.g;
678
+ const db = b - ckRGB.b;
679
+ keyed = dr * dr + dg * dg + db * db <= ckTolSq;
680
+ }
681
+ if (keyed) {
671
682
  row.push({ char: " ", r: 0, g: 0, b: 0, a: 0 });
672
683
  continue;
673
684
  }