pica 10.0.1 → 10.0.2

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/pica_main.js CHANGED
@@ -968,13 +968,14 @@ https://github.com/nodeca/pica
968
968
  };
969
969
  var checked = false;
970
970
  var checking = null;
971
+ var ctxOpts$1 = { willReadFrequently: true };
971
972
  function check_canvas() {
972
973
  if (typeof document === "undefined" || !document.createElement) return false;
973
974
  try {
974
975
  const canvas = document.createElement("canvas");
975
976
  canvas.width = 2;
976
977
  canvas.height = 1;
977
- const ctx = canvas.getContext("2d");
978
+ const ctx = canvas.getContext("2d", ctxOpts$1);
978
979
  let d = ctx.createImageData(2, 1);
979
980
  d.data[0] = 12;
980
981
  d.data[1] = 23;
@@ -994,7 +995,7 @@ https://github.com/nodeca/pica
994
995
  function check_offscreen_canvas() {
995
996
  if (typeof OffscreenCanvas === "undefined") return false;
996
997
  try {
997
- const ctx = new OffscreenCanvas(2, 1).getContext("2d");
998
+ const ctx = new OffscreenCanvas(2, 1).getContext("2d", ctxOpts$1);
998
999
  let d = ctx.createImageData(2, 1);
999
1000
  d.data[0] = 12;
1000
1001
  d.data[1] = 23;
@@ -1033,7 +1034,7 @@ https://github.com/nodeca/pica
1033
1034
  return createImageBitmap(new Blob([bytes], { type: "image/jpeg" })).then((bitmap) => {
1034
1035
  const canvas = new OffscreenCanvas(1, 1);
1035
1036
  try {
1036
- const ctx = canvas.getContext("2d");
1037
+ const ctx = canvas.getContext("2d", ctxOpts$1);
1037
1038
  ctx.drawImage(bitmap, 1, 1, 1, 1, 0, 0, 1, 1);
1038
1039
  return ctx.getImageData(0, 0, 1, 1).data[0] < 240;
1039
1040
  } finally {
@@ -1048,7 +1049,7 @@ https://github.com/nodeca/pica
1048
1049
  const canvas = document.createElement("canvas");
1049
1050
  canvas.width = 1;
1050
1051
  canvas.height = 1;
1051
- const ctx = canvas.getContext("2d");
1052
+ const ctx = canvas.getContext("2d", ctxOpts$1);
1052
1053
  ctx.drawImage(image, 1, 1, 1, 1, 0, 0, 1, 1);
1053
1054
  resolve(ctx.getImageData(0, 0, 1, 1).data[0] < 240);
1054
1055
  } catch (__) {
@@ -1080,7 +1081,7 @@ https://github.com/nodeca/pica
1080
1081
  canvas.height = 1;
1081
1082
  }
1082
1083
  try {
1083
- const ctx = canvas.getContext("2d");
1084
+ const ctx = canvas.getContext("2d", ctxOpts$1);
1084
1085
  ctx.drawImage(bitmap, 0, 0);
1085
1086
  return bitmap.width !== 1 || bitmap.height !== 1 || ctx.getImageData(0, 0, 1, 1).data[0] < 240;
1086
1087
  } finally {
@@ -1105,7 +1106,7 @@ https://github.com/nodeca/pica
1105
1106
  canvas.height = SRC_SIZE;
1106
1107
  } else if (features.offscreen_canvas || check_offscreen_canvas()) {
1107
1108
  canvas = new OffscreenCanvas(SRC_SIZE, SRC_SIZE);
1108
- canvas.getContext("2d").clearRect(0, 0, SRC_SIZE, SRC_SIZE);
1109
+ canvas.getContext("2d", ctxOpts$1).clearRect(0, 0, SRC_SIZE, SRC_SIZE);
1109
1110
  } else return false;
1110
1111
  return createImageBitmap(canvas, 0, 0, SRC_SIZE, SRC_SIZE, {
1111
1112
  resizeWidth: DST_SIZE,
@@ -1192,6 +1193,7 @@ https://github.com/nodeca/pica
1192
1193
  unsharpRadius: 0,
1193
1194
  unsharpThreshold: 0
1194
1195
  };
1196
+ var ctxOpts = { willReadFrequently: true };
1195
1197
  var Pica = class {
1196
1198
  constructor(options) {
1197
1199
  _defineProperty(this, "options", void 0);
@@ -1336,7 +1338,7 @@ https://github.com/nodeca/pica
1336
1338
  if (this.resize_features.ww && this.capabilities.ww_offscreen_canvas) {
1337
1339
  this.debug("Create tile imageBitmap");
1338
1340
  const tileCanvas = this.createCanvas(tile.width, tile.height, { preferOffscreen: true });
1339
- tileCanvas.getContext("2d").drawImage(stageEnv.srcImageBitmap || from, tile.x, tile.y, tile.width, tile.height, 0, 0, tile.width, tile.height);
1341
+ tileCanvas.getContext("2d", ctxOpts).drawImage(stageEnv.srcImageBitmap || from, tile.x, tile.y, tile.width, tile.height, 0, 0, tile.width, tile.height);
1340
1342
  if (!("transferToImageBitmap" in tileCanvas)) throw new Error("Pica: offscreen canvas is not available for worker transfer");
1341
1343
  return Object.assign({}, extractTo, {
1342
1344
  kind: "bitmap",
@@ -1344,7 +1346,7 @@ https://github.com/nodeca/pica
1344
1346
  });
1345
1347
  }
1346
1348
  if (isCanvas(from)) {
1347
- if (!stageEnv.srcCtx) stageEnv.srcCtx = from.getContext("2d");
1349
+ if (!stageEnv.srcCtx) stageEnv.srcCtx = from.getContext("2d", ctxOpts);
1348
1350
  this.debug("Get tile pixel data");
1349
1351
  return Object.assign({}, extractTo, {
1350
1352
  kind: "array",
@@ -1353,7 +1355,7 @@ https://github.com/nodeca/pica
1353
1355
  }
1354
1356
  this.debug("Draw tile imageBitmap/image to temporary canvas");
1355
1357
  const tmpCanvas = this.createCanvas(tile.width, tile.height, { preferOffscreen: true });
1356
- const tmpCtx = tmpCanvas.getContext("2d");
1358
+ const tmpCtx = tmpCanvas.getContext("2d", ctxOpts);
1357
1359
  tmpCtx.globalCompositeOperation = "copy";
1358
1360
  tmpCtx.drawImage(stageEnv.srcImageBitmap || from, tile.x, tile.y, tile.width, tile.height, 0, 0, tile.width, tile.height);
1359
1361
  this.debug("Get tile pixel data");
@@ -1410,7 +1412,7 @@ https://github.com/nodeca/pica
1410
1412
  return _this3.__landTileData(tile, result, stageEnv);
1411
1413
  }));
1412
1414
  yield Promise.resolve();
1413
- stageEnv.toCtx = to.getContext("2d");
1415
+ stageEnv.toCtx = to.getContext("2d", ctxOpts);
1414
1416
  if (isCanvas(from)) {} else if (isImageBitmap(from)) {
1415
1417
  stageEnv.srcImageBitmap = from;
1416
1418
  stageEnv.isImageBitmapReused = true;
@@ -1490,7 +1492,7 @@ https://github.com/nodeca/pica
1490
1492
  var _this5 = this;
1491
1493
  return _asyncToGenerator(function* () {
1492
1494
  var _utils$filter_to_cib_;
1493
- let toCtx = to.getContext("2d");
1495
+ let toCtx = to.getContext("2d", ctxOpts);
1494
1496
  _this5.debug("Resize via createImageBitmap()");
1495
1497
  const imageBitmap = yield createImageBitmap(from, {
1496
1498
  resizeWidth: resizeParams.toWidth,
@@ -1507,7 +1509,7 @@ https://github.com/nodeca/pica
1507
1509
  }
1508
1510
  _this5.debug("Unsharp result");
1509
1511
  let tmpCanvas = _this5.createCanvas(resizeParams.toWidth, resizeParams.toHeight);
1510
- let tmpCtx = tmpCanvas.getContext("2d");
1512
+ let tmpCtx = tmpCanvas.getContext("2d", ctxOpts);
1511
1513
  tmpCtx.drawImage(imageBitmap, 0, 0);
1512
1514
  imageBitmap.close();
1513
1515
  let iData = tmpCtx.getImageData(0, 0, resizeParams.toWidth, resizeParams.toHeight);
@@ -1558,7 +1560,7 @@ https://github.com/nodeca/pica
1558
1560
  if (ctx.canceled) return ctx.cancelToken;
1559
1561
  if (_this6.capabilities.bug_image_bitmap_orientation_region && (isImage(from) || isImageBitmap(from))) {
1560
1562
  const tmpCanvas = _this6.createCanvas(resizeParams.width, resizeParams.height);
1561
- tmpCanvas.getContext("2d").drawImage(from, 0, 0);
1563
+ tmpCanvas.getContext("2d", ctxOpts).drawImage(from, 0, 0);
1562
1564
  from = tmpCanvas;
1563
1565
  }
1564
1566
  if (_this6.resize_features.cib) {