asciify-engine 1.0.59 → 1.0.61
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 +25 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -734,11 +734,34 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
|
|
|
734
734
|
ctx.drawImage(source, 0, 0, cols, rows);
|
|
735
735
|
const imageData = ctx.getImageData(0, 0, cols, rows);
|
|
736
736
|
const pixels = imageData.data;
|
|
737
|
+
const ck = options.chromaKey;
|
|
738
|
+
const ckEnabled = ck != null && ck !== false;
|
|
739
|
+
const ckHeuristicGreen = ck === true;
|
|
740
|
+
const ckHeuristicBlue = ck === "blue-screen";
|
|
741
|
+
let ckRGB = null;
|
|
742
|
+
let ckTolSq = 0;
|
|
743
|
+
if (ckEnabled && !ckHeuristicGreen && !ckHeuristicBlue) {
|
|
744
|
+
ckRGB = parseChromaKeyColor(ck);
|
|
745
|
+
ckTolSq = (options.chromaKeyTolerance ?? 60) ** 2;
|
|
746
|
+
}
|
|
737
747
|
let normMin = 0;
|
|
738
748
|
let normRange = 255;
|
|
739
749
|
if (options.normalize) {
|
|
740
750
|
let lo = 255, hi = 0;
|
|
741
751
|
for (let k = 0; k < pixels.length; k += 4) {
|
|
752
|
+
if (ckEnabled) {
|
|
753
|
+
const pr = pixels[k], pg = pixels[k + 1], pb = pixels[k + 2];
|
|
754
|
+
let keyed = false;
|
|
755
|
+
if (ckHeuristicGreen) {
|
|
756
|
+
keyed = pg > pr * 1.4 && pg > pb * 1.4 && pg > 80;
|
|
757
|
+
} else if (ckHeuristicBlue) {
|
|
758
|
+
keyed = pb > pr * 1.4 && pb > pg * 1.4 && pb > 80;
|
|
759
|
+
} else if (ckRGB !== null) {
|
|
760
|
+
const dr = pr - ckRGB.r, dg = pg - ckRGB.g, db = pb - ckRGB.b;
|
|
761
|
+
keyed = dr * dr + dg * dg + db * db <= ckTolSq;
|
|
762
|
+
}
|
|
763
|
+
if (keyed) continue;
|
|
764
|
+
}
|
|
742
765
|
const l = 0.299 * pixels[k] + 0.587 * pixels[k + 1] + 0.114 * pixels[k + 2];
|
|
743
766
|
if (l < lo) lo = l;
|
|
744
767
|
if (l > hi) hi = l;
|
|
@@ -748,16 +771,6 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
|
|
|
748
771
|
}
|
|
749
772
|
const frame = [];
|
|
750
773
|
const invertVal = resolveInvert(options.invert);
|
|
751
|
-
const ck = options.chromaKey;
|
|
752
|
-
const ckEnabled = ck != null && ck !== false;
|
|
753
|
-
const ckHeuristicGreen = ck === true;
|
|
754
|
-
const ckHeuristicBlue = ck === "blue-screen";
|
|
755
|
-
let ckRGB = null;
|
|
756
|
-
let ckTolSq = 0;
|
|
757
|
-
if (ckEnabled && !ckHeuristicGreen && !ckHeuristicBlue) {
|
|
758
|
-
ckRGB = parseChromaKeyColor(ck);
|
|
759
|
-
ckTolSq = (options.chromaKeyTolerance ?? 60) ** 2;
|
|
760
|
-
}
|
|
761
774
|
for (let y = 0; y < rows; y++) {
|
|
762
775
|
const row = [];
|
|
763
776
|
for (let x = 0; x < cols; x++) {
|
|
@@ -909,8 +922,8 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
|
|
|
909
922
|
}
|
|
910
923
|
}
|
|
911
924
|
if (!hasTransparency) {
|
|
912
|
-
const
|
|
913
|
-
ctx.fillStyle =
|
|
925
|
+
const isDarkScheme = typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
926
|
+
ctx.fillStyle = isDarkScheme ? "#0a0a0a" : "#faf9f7";
|
|
914
927
|
ctx.fillRect(0, 0, canvasWidth, canvasHeight);
|
|
915
928
|
}
|
|
916
929
|
const cellW = canvasWidth / cols;
|