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