asciify-engine 1.0.60 → 1.0.63
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 +29 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -282,9 +282,7 @@ function getCellColorStr(cell, colorMode, acR, acG, acB, _isInverted = false) {
|
|
|
282
282
|
case "matrix":
|
|
283
283
|
return GREEN_LUT[0.299 * cell.r + 0.587 * cell.g + 0.114 * cell.b | 0];
|
|
284
284
|
case "accent": {
|
|
285
|
-
|
|
286
|
-
const ab = _isInverted ? 1 - rawAb : rawAb;
|
|
287
|
-
return `rgb(${acR * ab | 0},${acG * ab | 0},${acB * ab | 0})`;
|
|
285
|
+
return `rgb(${acR},${acG},${acB})`;
|
|
288
286
|
}
|
|
289
287
|
default: {
|
|
290
288
|
const gray = 0.299 * cell.r + 0.587 * cell.g + 0.114 * cell.b | 0;
|
|
@@ -308,11 +306,9 @@ function getCellColorRGB(cell, colorMode, acR, acG, acB, _isInverted = false) {
|
|
|
308
306
|
break;
|
|
309
307
|
}
|
|
310
308
|
case "accent": {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
_colorRGB[
|
|
314
|
-
_colorRGB[1] = acG * ab | 0;
|
|
315
|
-
_colorRGB[2] = acB * ab | 0;
|
|
309
|
+
_colorRGB[0] = acR;
|
|
310
|
+
_colorRGB[1] = acG;
|
|
311
|
+
_colorRGB[2] = acB;
|
|
316
312
|
break;
|
|
317
313
|
}
|
|
318
314
|
default: {
|
|
@@ -732,11 +728,34 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
|
|
|
732
728
|
ctx.drawImage(source, 0, 0, cols, rows);
|
|
733
729
|
const imageData = ctx.getImageData(0, 0, cols, rows);
|
|
734
730
|
const pixels = imageData.data;
|
|
731
|
+
const ck = options.chromaKey;
|
|
732
|
+
const ckEnabled = ck != null && ck !== false;
|
|
733
|
+
const ckHeuristicGreen = ck === true;
|
|
734
|
+
const ckHeuristicBlue = ck === "blue-screen";
|
|
735
|
+
let ckRGB = null;
|
|
736
|
+
let ckTolSq = 0;
|
|
737
|
+
if (ckEnabled && !ckHeuristicGreen && !ckHeuristicBlue) {
|
|
738
|
+
ckRGB = parseChromaKeyColor(ck);
|
|
739
|
+
ckTolSq = (options.chromaKeyTolerance ?? 60) ** 2;
|
|
740
|
+
}
|
|
735
741
|
let normMin = 0;
|
|
736
742
|
let normRange = 255;
|
|
737
743
|
if (options.normalize) {
|
|
738
744
|
let lo = 255, hi = 0;
|
|
739
745
|
for (let k = 0; k < pixels.length; k += 4) {
|
|
746
|
+
if (ckEnabled) {
|
|
747
|
+
const pr = pixels[k], pg = pixels[k + 1], pb = pixels[k + 2];
|
|
748
|
+
let keyed = false;
|
|
749
|
+
if (ckHeuristicGreen) {
|
|
750
|
+
keyed = pg > pr * 1.4 && pg > pb * 1.4 && pg > 80;
|
|
751
|
+
} else if (ckHeuristicBlue) {
|
|
752
|
+
keyed = pb > pr * 1.4 && pb > pg * 1.4 && pb > 80;
|
|
753
|
+
} else if (ckRGB !== null) {
|
|
754
|
+
const dr = pr - ckRGB.r, dg = pg - ckRGB.g, db = pb - ckRGB.b;
|
|
755
|
+
keyed = dr * dr + dg * dg + db * db <= ckTolSq;
|
|
756
|
+
}
|
|
757
|
+
if (keyed) continue;
|
|
758
|
+
}
|
|
740
759
|
const l = 0.299 * pixels[k] + 0.587 * pixels[k + 1] + 0.114 * pixels[k + 2];
|
|
741
760
|
if (l < lo) lo = l;
|
|
742
761
|
if (l > hi) hi = l;
|
|
@@ -746,16 +765,7 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
|
|
|
746
765
|
}
|
|
747
766
|
const frame = [];
|
|
748
767
|
const invertVal = resolveInvert(options.invert);
|
|
749
|
-
const
|
|
750
|
-
const ckEnabled = ck != null && ck !== false;
|
|
751
|
-
const ckHeuristicGreen = ck === true;
|
|
752
|
-
const ckHeuristicBlue = ck === "blue-screen";
|
|
753
|
-
let ckRGB = null;
|
|
754
|
-
let ckTolSq = 0;
|
|
755
|
-
if (ckEnabled && !ckHeuristicGreen && !ckHeuristicBlue) {
|
|
756
|
-
ckRGB = parseChromaKeyColor(ck);
|
|
757
|
-
ckTolSq = (options.chromaKeyTolerance ?? 60) ** 2;
|
|
758
|
-
}
|
|
768
|
+
const effectiveCharset = ckEnabled ? options.charset.replace(/ /g, "") || options.charset : options.charset;
|
|
759
769
|
for (let y = 0; y < rows; y++) {
|
|
760
770
|
const row = [];
|
|
761
771
|
for (let x = 0; x < cols; x++) {
|
|
@@ -785,7 +795,7 @@ function imageToAsciiFrame(source, options, targetWidth, targetHeight) {
|
|
|
785
795
|
const lum = options.normalize ? (rawLum - normMin) / normRange * 255 : rawLum;
|
|
786
796
|
const adjustedLum = adjustLuminance(lum, options.brightness, options.contrast);
|
|
787
797
|
const ditheredLum = applyDither(adjustedLum, x, y, options.ditherStrength);
|
|
788
|
-
const char = options.customText ? customTextToChar(ditheredLum, options.customText, x, y, cols, invertVal) : luminanceToChar(ditheredLum,
|
|
798
|
+
const char = options.customText ? customTextToChar(ditheredLum, options.customText, x, y, cols, invertVal) : luminanceToChar(ditheredLum, effectiveCharset, invertVal);
|
|
789
799
|
row.push({ char, r, g, b, a, lum: ditheredLum });
|
|
790
800
|
}
|
|
791
801
|
frame.push(row);
|