asciify-engine 1.0.56 → 1.0.58

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.js CHANGED
@@ -275,7 +275,7 @@ for (let _i = 0; _i < 256; _i++) {
275
275
  GRAY_LUT[_i] = `rgb(${_i},${_i},${_i})`;
276
276
  GREEN_LUT[_i] = `rgb(0,${_i},0)`;
277
277
  }
278
- function getCellColorStr(cell, colorMode, acR, acG, acB, isInverted = false) {
278
+ function getCellColorStr(cell, colorMode, acR, acG, acB, _isInverted = false) {
279
279
  switch (colorMode) {
280
280
  case "fullcolor":
281
281
  return `rgb(${cell.r},${cell.g},${cell.b})`;
@@ -287,12 +287,12 @@ function getCellColorStr(cell, colorMode, acR, acG, acB, isInverted = false) {
287
287
  }
288
288
  default: {
289
289
  const gray = 0.299 * cell.r + 0.587 * cell.g + 0.114 * cell.b | 0;
290
- return GRAY_LUT[isInverted ? 255 - gray : gray];
290
+ return GRAY_LUT[gray];
291
291
  }
292
292
  }
293
293
  }
294
294
  var _colorRGB = [0, 0, 0];
295
- function getCellColorRGB(cell, colorMode, acR, acG, acB, isInverted = false) {
295
+ function getCellColorRGB(cell, colorMode, acR, acG, acB, _isInverted = false) {
296
296
  switch (colorMode) {
297
297
  case "fullcolor":
298
298
  _colorRGB[0] = cell.r;
@@ -314,8 +314,7 @@ function getCellColorRGB(cell, colorMode, acR, acG, acB, isInverted = false) {
314
314
  break;
315
315
  }
316
316
  default: {
317
- let gray = 0.299 * cell.r + 0.587 * cell.g + 0.114 * cell.b | 0;
318
- if (isInverted) gray = 255 - gray;
317
+ const gray = 0.299 * cell.r + 0.587 * cell.g + 0.114 * cell.b | 0;
319
318
  _colorRGB[0] = gray;
320
319
  _colorRGB[1] = gray;
321
320
  _colorRGB[2] = gray;
@@ -906,7 +905,8 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
906
905
  }
907
906
  }
908
907
  if (!hasTransparency) {
909
- ctx.fillStyle = "#0a0a0a";
908
+ const isInvertedBg = resolveInvert(options.invert);
909
+ ctx.fillStyle = isInvertedBg ? "#faf9f7" : "#0a0a0a";
910
910
  ctx.fillRect(0, 0, canvasWidth, canvasHeight);
911
911
  }
912
912
  const cellW = canvasWidth / cols;
@@ -1282,9 +1282,13 @@ async function asciifyVideo(source, canvas, { fontSize = 10, artStyle = "classic
1282
1282
  });
1283
1283
  }
1284
1284
  let timeupdateHandler = null;
1285
- if (trimEnd !== void 0) {
1285
+ if (trimStart > 0 || trimEnd !== void 0) {
1286
1286
  timeupdateHandler = () => {
1287
- if (video.currentTime >= trimEnd) video.currentTime = trimStart;
1287
+ if (trimEnd !== void 0 && video.currentTime >= trimEnd) {
1288
+ video.currentTime = trimStart;
1289
+ } else if (trimStart > 0 && video.currentTime < trimStart) {
1290
+ video.currentTime = trimStart;
1291
+ }
1288
1292
  };
1289
1293
  video.addEventListener("timeupdate", timeupdateHandler);
1290
1294
  }
@@ -1302,6 +1306,8 @@ async function asciifyVideo(source, canvas, { fontSize = 10, artStyle = "classic
1302
1306
  if (cancelled) return;
1303
1307
  animId = requestAnimationFrame(tick);
1304
1308
  if (video.readyState < 2 || canvas.width === 0 || canvas.height === 0) return;
1309
+ if (trimStart > 0 && video.currentTime < trimStart) return;
1310
+ if (trimEnd !== void 0 && video.currentTime >= trimEnd) return;
1305
1311
  const { frame } = imageToAsciiFrame(video, merged, canvas.width, canvas.height);
1306
1312
  if (frame.length > 0) {
1307
1313
  renderFrameToCanvas(ctx, frame, merged, canvas.width, canvas.height, 0, null);