@poe-platform/safe-bash 0.1.761 → 0.1.762

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.
Files changed (28) hide show
  1. package/dist/image-ast/index.browser.js +69 -7
  2. package/dist/image-ast/index.js +69 -7
  3. package/dist/pdf-ast/index.js +71 -7
  4. package/dist/safe-bash/command-chunks/{chunk-6VX5ZQL5.js → chunk-D4GXXV65.js} +2 -2
  5. package/dist/safe-bash/command-chunks/{chunk-GR725WRX.js → chunk-F7MJRXQ2.js} +1 -1
  6. package/dist/safe-bash/command-chunks/{chunk-OSMLVM7P.js → chunk-P3Q2QSCA.js} +72 -7
  7. package/dist/safe-bash/commands/csvcut/index.d.ts +1 -1
  8. package/dist/safe-bash/commands/csvcut/index.js +3 -1
  9. package/dist/safe-bash/commands/csvgrep/index.d.ts +1 -1
  10. package/dist/safe-bash/commands/csvgrep/index.js +3 -1
  11. package/dist/safe-bash/core.browser.js +7 -5
  12. package/dist/safe-bash/shell/runtime.js +4 -4
  13. package/dist/safe-bash-command-ffmpeg/index.js +1423 -1388
  14. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  15. package/dist/safe-bash-command-pandoc/command.js +3 -3
  16. package/dist/safe-bash-command-pandoc/index.js +3 -3
  17. package/dist/safe-bash-command-pdfimages/index.js +69 -7
  18. package/dist/safe-bash-command-pdfinfo/index.js +69 -7
  19. package/dist/safe-bash-command-pdftk/index.js +69 -7
  20. package/dist/safe-bash-command-pdftoppm/index.js +69 -7
  21. package/dist/safe-bash-command-pdftotext/index.js +69 -7
  22. package/dist/safe-bash-command-qpdf/index.js +69 -7
  23. package/dist/safe-bash-command-sips/index.js +2 -2
  24. package/dist/safe-bash-command-soffice/index.js +1 -1
  25. package/dist/safe-bash-command-ssconvert/index.js +69 -7
  26. package/dist/safe-bash-command-wkhtmltopdf/index.js +69 -7
  27. package/package.json +2 -2
  28. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +10 -0
@@ -28,8 +28,8 @@ import {
28
28
  thresholdImage,
29
29
  tintImage,
30
30
  trimImage
31
- } from "../safe-bash/command-chunks/chunk-GR725WRX.js";
32
- import "../safe-bash/command-chunks/chunk-OSMLVM7P.js";
31
+ } from "../safe-bash/command-chunks/chunk-F7MJRXQ2.js";
32
+ import "../safe-bash/command-chunks/chunk-P3Q2QSCA.js";
33
33
  import {
34
34
  init_buffer
35
35
  } from "../safe-bash/command-chunks/chunk-HX3SHTCE.js";
@@ -2,11 +2,11 @@ import {
2
2
  createPandocCommand,
3
3
  createPandocCommands,
4
4
  pandocCommands
5
- } from "../safe-bash/command-chunks/chunk-6VX5ZQL5.js";
5
+ } from "../safe-bash/command-chunks/chunk-D4GXXV65.js";
6
6
  import "../safe-bash/command-chunks/chunk-MKQVQMXO.js";
7
7
  import "../safe-bash/command-chunks/chunk-RDV7UCYZ.js";
8
- import "../safe-bash/command-chunks/chunk-GR725WRX.js";
9
- import "../safe-bash/command-chunks/chunk-OSMLVM7P.js";
8
+ import "../safe-bash/command-chunks/chunk-F7MJRXQ2.js";
9
+ import "../safe-bash/command-chunks/chunk-P3Q2QSCA.js";
10
10
  import "../safe-bash/command-chunks/chunk-Y2KHC6TZ.js";
11
11
  import "../safe-bash/command-chunks/chunk-YGYOVXTO.js";
12
12
  import "../safe-bash/command-chunks/chunk-I5GLTNVH.js";
@@ -21,11 +21,11 @@ import {
21
21
  readDocument,
22
22
  resolveConversionArgs,
23
23
  writeDocument
24
- } from "../safe-bash/command-chunks/chunk-6VX5ZQL5.js";
24
+ } from "../safe-bash/command-chunks/chunk-D4GXXV65.js";
25
25
  import "../safe-bash/command-chunks/chunk-MKQVQMXO.js";
26
26
  import "../safe-bash/command-chunks/chunk-RDV7UCYZ.js";
27
- import "../safe-bash/command-chunks/chunk-GR725WRX.js";
28
- import "../safe-bash/command-chunks/chunk-OSMLVM7P.js";
27
+ import "../safe-bash/command-chunks/chunk-F7MJRXQ2.js";
28
+ import "../safe-bash/command-chunks/chunk-P3Q2QSCA.js";
29
29
  import {
30
30
  createLuaFilterCapability
31
31
  } from "../safe-bash/command-chunks/chunk-Y2KHC6TZ.js";
@@ -39053,6 +39053,47 @@ function flattenCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
39053
39053
  points.push([x4, y4]);
39054
39054
  return points;
39055
39055
  }
39056
+ function sampleImageLinear(image, x, y, out) {
39057
+ x = Math.max(0, Math.min(image.width - 1, x));
39058
+ y = Math.max(0, Math.min(image.height - 1, y));
39059
+ const x0 = Math.floor(x), y0 = Math.floor(y);
39060
+ const fx = x - x0, fy = y - y0;
39061
+ out.fill(0);
39062
+ for (let j = 0; j < 2; j++) {
39063
+ for (let i = 0; i < 2; i++) {
39064
+ const offset = (Math.min(image.height - 1, y0 + j) * image.width + Math.min(image.width - 1, x0 + i)) * 4;
39065
+ const alpha = image.data[offset + 3] * (i ? fx : 1 - fx) * (j ? fy : 1 - fy);
39066
+ out[0] = out[0] + image.data[offset] * alpha;
39067
+ out[1] = out[1] + image.data[offset + 1] * alpha;
39068
+ out[2] = out[2] + image.data[offset + 2] * alpha;
39069
+ out[3] = out[3] + alpha;
39070
+ }
39071
+ }
39072
+ if (out[3] > 0) {
39073
+ out[0] = out[0] / out[3];
39074
+ out[1] = out[1] / out[3];
39075
+ out[2] = out[2] / out[3];
39076
+ }
39077
+ }
39078
+ function downscaleImage(image, widthScale, heightScale) {
39079
+ const sample = new Float64Array(4);
39080
+ while (widthScale > 2 && image.width > 1 || heightScale > 2 && image.height > 1) {
39081
+ const width = widthScale > 2 ? Math.ceil(image.width / 2) : image.width;
39082
+ const height = heightScale > 2 ? Math.ceil(image.height / 2) : image.height;
39083
+ const data = new Uint8Array(width * height * 4);
39084
+ for (let y = 0; y < height; y++) {
39085
+ for (let x = 0; x < width; x++) {
39086
+ sampleImageLinear(image, (x + 0.5) * image.width / width - 0.5, (y + 0.5) * image.height / height - 0.5, sample);
39087
+ const offset = (y * width + x) * 4;
39088
+ for (let c = 0; c < 4; c++) data[offset + c] = Math.round(sample[c]);
39089
+ }
39090
+ }
39091
+ widthScale /= image.width / width;
39092
+ heightScale /= image.height / height;
39093
+ image = { width, height, data };
39094
+ }
39095
+ return image;
39096
+ }
39056
39097
  function encodePng(bitmap) {
39057
39098
  return encodeRgbaToPng(bitmap.width, bitmap.height, bitmap.data);
39058
39099
  }
@@ -40259,6 +40300,17 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40259
40300
  const maxPx = Math.min(width - 1, clipMaxPx, Math.ceil(Math.max(...cornersPx)) - 1);
40260
40301
  const minPy = Math.max(0, clipMinPy, Math.floor(Math.min(...cornersPy)));
40261
40302
  const maxPy = Math.min(height - 1, clipMaxPy, Math.ceil(Math.max(...cornersPy)) - 1);
40303
+ if (minPx > maxPx || minPy > maxPy) continue;
40304
+ const source = downscaleImage(
40305
+ { width: img.width, height: img.height, data: img.decodedRgba },
40306
+ Math.hypot(d, c) * img.width / Math.abs(det * scale),
40307
+ Math.hypot(b, a) * img.height / Math.abs(det * scale)
40308
+ );
40309
+ const ax = a * scale / img.width, ay = b * scale / img.width;
40310
+ const bx = c * scale / img.height, by = d * scale / img.height;
40311
+ const s1 = ax * ax + ay * ay, s2 = bx * bx + by * by, cross = ax * bx + ay * by;
40312
+ const smooth = Math.fround((s1 + s2 + Math.hypot(s1 - s2, 2 * cross)) / 2) <= 1;
40313
+ const sample = new Float64Array(4);
40262
40314
  for (let py = minPy; py <= maxPy; py++) {
40263
40315
  const yPdf = displayList.height - (py + 0.5) / scale;
40264
40316
  if (img.clipRect && (yPdf < img.clipRect[1] || yPdf > img.clipRect[3])) continue;
@@ -40270,9 +40322,14 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40270
40322
  const u = (d * dxPdf - c * dyPdf) / det;
40271
40323
  const v = (-b * dxPdf + a * dyPdf) / det;
40272
40324
  if (u < 0 || u > 1 || v < 0 || v > 1) continue;
40273
- const sx = Math.min(img.width - 1, Math.max(0, Math.floor(u * img.width)));
40274
- const sy = Math.min(img.height - 1, Math.max(0, Math.floor((1 - v) * img.height)));
40275
- const sIdx = (sy * img.width + sx) * 4;
40325
+ if (smooth) {
40326
+ sampleImageLinear(source, u * source.width - 0.5, (1 - v) * source.height - 0.5, sample);
40327
+ } else {
40328
+ const sx = Math.min(source.width - 1, Math.max(0, Math.floor(u * source.width)));
40329
+ const sy = Math.min(source.height - 1, Math.max(0, Math.floor((1 - v) * source.height)));
40330
+ const sIdx = (sy * source.width + sx) * 4;
40331
+ for (let c2 = 0; c2 < 4; c2++) sample[c2] = source.data[sIdx + c2];
40332
+ }
40276
40333
  blendPixel(
40277
40334
  rgba,
40278
40335
  width,
@@ -40280,11 +40337,11 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40280
40337
  px,
40281
40338
  py,
40282
40339
  {
40283
- r: img.decodedRgba[sIdx] / 255,
40284
- g: img.decodedRgba[sIdx + 1] / 255,
40285
- b: img.decodedRgba[sIdx + 2] / 255
40340
+ r: sample[0] / 255,
40341
+ g: sample[1] / 255,
40342
+ b: sample[2] / 255
40286
40343
  },
40287
- img.decodedRgba[sIdx + 3] / 255,
40344
+ sample[3] / 255,
40288
40345
  img.blendMode,
40289
40346
  clipMask
40290
40347
  );
@@ -41315,3 +41372,8 @@ export {
41315
41372
  * Adapted from PDFium third_party/agg23/agg_curves.cpp, curve4_div.
41316
41373
  * See THIRD_PARTY_NOTICES.md for the pinned revision and adaptations.
41317
41374
  */
41375
+ /*!
41376
+ * Staged image reduction adapted from Mozilla PDF.js CanvasGraphics._scaleImage.
41377
+ * Copyright 2012 Mozilla Foundation. Licensed under Apache-2.0.
41378
+ * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
41379
+ */
@@ -39247,6 +39247,47 @@ function flattenCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
39247
39247
  points.push([x4, y4]);
39248
39248
  return points;
39249
39249
  }
39250
+ function sampleImageLinear(image, x, y, out) {
39251
+ x = Math.max(0, Math.min(image.width - 1, x));
39252
+ y = Math.max(0, Math.min(image.height - 1, y));
39253
+ const x0 = Math.floor(x), y0 = Math.floor(y);
39254
+ const fx = x - x0, fy = y - y0;
39255
+ out.fill(0);
39256
+ for (let j = 0; j < 2; j++) {
39257
+ for (let i = 0; i < 2; i++) {
39258
+ const offset = (Math.min(image.height - 1, y0 + j) * image.width + Math.min(image.width - 1, x0 + i)) * 4;
39259
+ const alpha = image.data[offset + 3] * (i ? fx : 1 - fx) * (j ? fy : 1 - fy);
39260
+ out[0] = out[0] + image.data[offset] * alpha;
39261
+ out[1] = out[1] + image.data[offset + 1] * alpha;
39262
+ out[2] = out[2] + image.data[offset + 2] * alpha;
39263
+ out[3] = out[3] + alpha;
39264
+ }
39265
+ }
39266
+ if (out[3] > 0) {
39267
+ out[0] = out[0] / out[3];
39268
+ out[1] = out[1] / out[3];
39269
+ out[2] = out[2] / out[3];
39270
+ }
39271
+ }
39272
+ function downscaleImage(image, widthScale, heightScale) {
39273
+ const sample = new Float64Array(4);
39274
+ while (widthScale > 2 && image.width > 1 || heightScale > 2 && image.height > 1) {
39275
+ const width = widthScale > 2 ? Math.ceil(image.width / 2) : image.width;
39276
+ const height = heightScale > 2 ? Math.ceil(image.height / 2) : image.height;
39277
+ const data = new Uint8Array(width * height * 4);
39278
+ for (let y = 0; y < height; y++) {
39279
+ for (let x = 0; x < width; x++) {
39280
+ sampleImageLinear(image, (x + 0.5) * image.width / width - 0.5, (y + 0.5) * image.height / height - 0.5, sample);
39281
+ const offset = (y * width + x) * 4;
39282
+ for (let c = 0; c < 4; c++) data[offset + c] = Math.round(sample[c]);
39283
+ }
39284
+ }
39285
+ widthScale /= image.width / width;
39286
+ heightScale /= image.height / height;
39287
+ image = { width, height, data };
39288
+ }
39289
+ return image;
39290
+ }
39250
39291
  function encodePng(bitmap) {
39251
39292
  return encodeRgbaToPng(bitmap.width, bitmap.height, bitmap.data);
39252
39293
  }
@@ -40695,6 +40736,17 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40695
40736
  const maxPx = Math.min(width - 1, clipMaxPx, Math.ceil(Math.max(...cornersPx)) - 1);
40696
40737
  const minPy = Math.max(0, clipMinPy, Math.floor(Math.min(...cornersPy)));
40697
40738
  const maxPy = Math.min(height - 1, clipMaxPy, Math.ceil(Math.max(...cornersPy)) - 1);
40739
+ if (minPx > maxPx || minPy > maxPy) continue;
40740
+ const source = downscaleImage(
40741
+ { width: img.width, height: img.height, data: img.decodedRgba },
40742
+ Math.hypot(d, c) * img.width / Math.abs(det * scale),
40743
+ Math.hypot(b, a) * img.height / Math.abs(det * scale)
40744
+ );
40745
+ const ax = a * scale / img.width, ay = b * scale / img.width;
40746
+ const bx = c * scale / img.height, by = d * scale / img.height;
40747
+ const s1 = ax * ax + ay * ay, s2 = bx * bx + by * by, cross = ax * bx + ay * by;
40748
+ const smooth = Math.fround((s1 + s2 + Math.hypot(s1 - s2, 2 * cross)) / 2) <= 1;
40749
+ const sample = new Float64Array(4);
40698
40750
  for (let py = minPy; py <= maxPy; py++) {
40699
40751
  const yPdf = displayList.height - (py + 0.5) / scale;
40700
40752
  if (img.clipRect && (yPdf < img.clipRect[1] || yPdf > img.clipRect[3])) continue;
@@ -40706,9 +40758,14 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40706
40758
  const u = (d * dxPdf - c * dyPdf) / det;
40707
40759
  const v = (-b * dxPdf + a * dyPdf) / det;
40708
40760
  if (u < 0 || u > 1 || v < 0 || v > 1) continue;
40709
- const sx = Math.min(img.width - 1, Math.max(0, Math.floor(u * img.width)));
40710
- const sy = Math.min(img.height - 1, Math.max(0, Math.floor((1 - v) * img.height)));
40711
- const sIdx = (sy * img.width + sx) * 4;
40761
+ if (smooth) {
40762
+ sampleImageLinear(source, u * source.width - 0.5, (1 - v) * source.height - 0.5, sample);
40763
+ } else {
40764
+ const sx = Math.min(source.width - 1, Math.max(0, Math.floor(u * source.width)));
40765
+ const sy = Math.min(source.height - 1, Math.max(0, Math.floor((1 - v) * source.height)));
40766
+ const sIdx = (sy * source.width + sx) * 4;
40767
+ for (let c2 = 0; c2 < 4; c2++) sample[c2] = source.data[sIdx + c2];
40768
+ }
40712
40769
  blendPixel(
40713
40770
  rgba,
40714
40771
  width,
@@ -40716,11 +40773,11 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40716
40773
  px,
40717
40774
  py,
40718
40775
  {
40719
- r: img.decodedRgba[sIdx] / 255,
40720
- g: img.decodedRgba[sIdx + 1] / 255,
40721
- b: img.decodedRgba[sIdx + 2] / 255
40776
+ r: sample[0] / 255,
40777
+ g: sample[1] / 255,
40778
+ b: sample[2] / 255
40722
40779
  },
40723
- img.decodedRgba[sIdx + 3] / 255,
40780
+ sample[3] / 255,
40724
40781
  img.blendMode,
40725
40782
  clipMask
40726
40783
  );
@@ -44268,3 +44325,8 @@ export {
44268
44325
  * Adapted from PDFium third_party/agg23/agg_curves.cpp, curve4_div.
44269
44326
  * See THIRD_PARTY_NOTICES.md for the pinned revision and adaptations.
44270
44327
  */
44328
+ /*!
44329
+ * Staged image reduction adapted from Mozilla PDF.js CanvasGraphics._scaleImage.
44330
+ * Copyright 2012 Mozilla Foundation. Licensed under Apache-2.0.
44331
+ * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
44332
+ */
@@ -39272,6 +39272,47 @@ function flattenCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
39272
39272
  points.push([x4, y4]);
39273
39273
  return points;
39274
39274
  }
39275
+ function sampleImageLinear(image, x, y, out) {
39276
+ x = Math.max(0, Math.min(image.width - 1, x));
39277
+ y = Math.max(0, Math.min(image.height - 1, y));
39278
+ const x0 = Math.floor(x), y0 = Math.floor(y);
39279
+ const fx = x - x0, fy = y - y0;
39280
+ out.fill(0);
39281
+ for (let j = 0; j < 2; j++) {
39282
+ for (let i = 0; i < 2; i++) {
39283
+ const offset = (Math.min(image.height - 1, y0 + j) * image.width + Math.min(image.width - 1, x0 + i)) * 4;
39284
+ const alpha = image.data[offset + 3] * (i ? fx : 1 - fx) * (j ? fy : 1 - fy);
39285
+ out[0] = out[0] + image.data[offset] * alpha;
39286
+ out[1] = out[1] + image.data[offset + 1] * alpha;
39287
+ out[2] = out[2] + image.data[offset + 2] * alpha;
39288
+ out[3] = out[3] + alpha;
39289
+ }
39290
+ }
39291
+ if (out[3] > 0) {
39292
+ out[0] = out[0] / out[3];
39293
+ out[1] = out[1] / out[3];
39294
+ out[2] = out[2] / out[3];
39295
+ }
39296
+ }
39297
+ function downscaleImage(image, widthScale, heightScale) {
39298
+ const sample = new Float64Array(4);
39299
+ while (widthScale > 2 && image.width > 1 || heightScale > 2 && image.height > 1) {
39300
+ const width = widthScale > 2 ? Math.ceil(image.width / 2) : image.width;
39301
+ const height = heightScale > 2 ? Math.ceil(image.height / 2) : image.height;
39302
+ const data = new Uint8Array(width * height * 4);
39303
+ for (let y = 0; y < height; y++) {
39304
+ for (let x = 0; x < width; x++) {
39305
+ sampleImageLinear(image, (x + 0.5) * image.width / width - 0.5, (y + 0.5) * image.height / height - 0.5, sample);
39306
+ const offset = (y * width + x) * 4;
39307
+ for (let c = 0; c < 4; c++) data[offset + c] = Math.round(sample[c]);
39308
+ }
39309
+ }
39310
+ widthScale /= image.width / width;
39311
+ heightScale /= image.height / height;
39312
+ image = { width, height, data };
39313
+ }
39314
+ return image;
39315
+ }
39275
39316
  function decodePng(pngBytes) {
39276
39317
  if (pngBytes.length < 24 || pngBytes[0] !== 137 || pngBytes[1] !== 80 || pngBytes[2] !== 78 || pngBytes[3] !== 71) {
39277
39318
  throw new Error("Invalid PNG signature");
@@ -40324,6 +40365,17 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40324
40365
  const maxPx = Math.min(width - 1, clipMaxPx, Math.ceil(Math.max(...cornersPx)) - 1);
40325
40366
  const minPy = Math.max(0, clipMinPy, Math.floor(Math.min(...cornersPy)));
40326
40367
  const maxPy = Math.min(height - 1, clipMaxPy, Math.ceil(Math.max(...cornersPy)) - 1);
40368
+ if (minPx > maxPx || minPy > maxPy) continue;
40369
+ const source = downscaleImage(
40370
+ { width: img.width, height: img.height, data: img.decodedRgba },
40371
+ Math.hypot(d, c) * img.width / Math.abs(det * scale),
40372
+ Math.hypot(b, a) * img.height / Math.abs(det * scale)
40373
+ );
40374
+ const ax = a * scale / img.width, ay = b * scale / img.width;
40375
+ const bx = c * scale / img.height, by = d * scale / img.height;
40376
+ const s1 = ax * ax + ay * ay, s2 = bx * bx + by * by, cross = ax * bx + ay * by;
40377
+ const smooth = Math.fround((s1 + s2 + Math.hypot(s1 - s2, 2 * cross)) / 2) <= 1;
40378
+ const sample = new Float64Array(4);
40327
40379
  for (let py = minPy; py <= maxPy; py++) {
40328
40380
  const yPdf = displayList.height - (py + 0.5) / scale;
40329
40381
  if (img.clipRect && (yPdf < img.clipRect[1] || yPdf > img.clipRect[3])) continue;
@@ -40335,9 +40387,14 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40335
40387
  const u = (d * dxPdf - c * dyPdf) / det;
40336
40388
  const v = (-b * dxPdf + a * dyPdf) / det;
40337
40389
  if (u < 0 || u > 1 || v < 0 || v > 1) continue;
40338
- const sx = Math.min(img.width - 1, Math.max(0, Math.floor(u * img.width)));
40339
- const sy = Math.min(img.height - 1, Math.max(0, Math.floor((1 - v) * img.height)));
40340
- const sIdx = (sy * img.width + sx) * 4;
40390
+ if (smooth) {
40391
+ sampleImageLinear(source, u * source.width - 0.5, (1 - v) * source.height - 0.5, sample);
40392
+ } else {
40393
+ const sx = Math.min(source.width - 1, Math.max(0, Math.floor(u * source.width)));
40394
+ const sy = Math.min(source.height - 1, Math.max(0, Math.floor((1 - v) * source.height)));
40395
+ const sIdx = (sy * source.width + sx) * 4;
40396
+ for (let c2 = 0; c2 < 4; c2++) sample[c2] = source.data[sIdx + c2];
40397
+ }
40341
40398
  blendPixel(
40342
40399
  rgba,
40343
40400
  width,
@@ -40345,11 +40402,11 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40345
40402
  px,
40346
40403
  py,
40347
40404
  {
40348
- r: img.decodedRgba[sIdx] / 255,
40349
- g: img.decodedRgba[sIdx + 1] / 255,
40350
- b: img.decodedRgba[sIdx + 2] / 255
40405
+ r: sample[0] / 255,
40406
+ g: sample[1] / 255,
40407
+ b: sample[2] / 255
40351
40408
  },
40352
- img.decodedRgba[sIdx + 3] / 255,
40409
+ sample[3] / 255,
40353
40410
  img.blendMode,
40354
40411
  clipMask
40355
40412
  );
@@ -42956,3 +43013,8 @@ export {
42956
43013
  * Adapted from PDFium third_party/agg23/agg_curves.cpp, curve4_div.
42957
43014
  * See THIRD_PARTY_NOTICES.md for the pinned revision and adaptations.
42958
43015
  */
43016
+ /*!
43017
+ * Staged image reduction adapted from Mozilla PDF.js CanvasGraphics._scaleImage.
43018
+ * Copyright 2012 Mozilla Foundation. Licensed under Apache-2.0.
43019
+ * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
43020
+ */
@@ -38902,6 +38902,47 @@ function flattenCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
38902
38902
  points.push([x4, y4]);
38903
38903
  return points;
38904
38904
  }
38905
+ function sampleImageLinear(image, x, y, out) {
38906
+ x = Math.max(0, Math.min(image.width - 1, x));
38907
+ y = Math.max(0, Math.min(image.height - 1, y));
38908
+ const x0 = Math.floor(x), y0 = Math.floor(y);
38909
+ const fx = x - x0, fy = y - y0;
38910
+ out.fill(0);
38911
+ for (let j = 0; j < 2; j++) {
38912
+ for (let i = 0; i < 2; i++) {
38913
+ const offset = (Math.min(image.height - 1, y0 + j) * image.width + Math.min(image.width - 1, x0 + i)) * 4;
38914
+ const alpha = image.data[offset + 3] * (i ? fx : 1 - fx) * (j ? fy : 1 - fy);
38915
+ out[0] = out[0] + image.data[offset] * alpha;
38916
+ out[1] = out[1] + image.data[offset + 1] * alpha;
38917
+ out[2] = out[2] + image.data[offset + 2] * alpha;
38918
+ out[3] = out[3] + alpha;
38919
+ }
38920
+ }
38921
+ if (out[3] > 0) {
38922
+ out[0] = out[0] / out[3];
38923
+ out[1] = out[1] / out[3];
38924
+ out[2] = out[2] / out[3];
38925
+ }
38926
+ }
38927
+ function downscaleImage(image, widthScale, heightScale) {
38928
+ const sample = new Float64Array(4);
38929
+ while (widthScale > 2 && image.width > 1 || heightScale > 2 && image.height > 1) {
38930
+ const width = widthScale > 2 ? Math.ceil(image.width / 2) : image.width;
38931
+ const height = heightScale > 2 ? Math.ceil(image.height / 2) : image.height;
38932
+ const data = new Uint8Array(width * height * 4);
38933
+ for (let y = 0; y < height; y++) {
38934
+ for (let x = 0; x < width; x++) {
38935
+ sampleImageLinear(image, (x + 0.5) * image.width / width - 0.5, (y + 0.5) * image.height / height - 0.5, sample);
38936
+ const offset = (y * width + x) * 4;
38937
+ for (let c = 0; c < 4; c++) data[offset + c] = Math.round(sample[c]);
38938
+ }
38939
+ }
38940
+ widthScale /= image.width / width;
38941
+ heightScale /= image.height / height;
38942
+ image = { width, height, data };
38943
+ }
38944
+ return image;
38945
+ }
38905
38946
  function encodePng(bitmap) {
38906
38947
  return encodeRgbaToPng(bitmap.width, bitmap.height, bitmap.data);
38907
38948
  }
@@ -40350,6 +40391,17 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40350
40391
  const maxPx = Math.min(width - 1, clipMaxPx, Math.ceil(Math.max(...cornersPx)) - 1);
40351
40392
  const minPy = Math.max(0, clipMinPy, Math.floor(Math.min(...cornersPy)));
40352
40393
  const maxPy = Math.min(height - 1, clipMaxPy, Math.ceil(Math.max(...cornersPy)) - 1);
40394
+ if (minPx > maxPx || minPy > maxPy) continue;
40395
+ const source = downscaleImage(
40396
+ { width: img.width, height: img.height, data: img.decodedRgba },
40397
+ Math.hypot(d, c) * img.width / Math.abs(det * scale),
40398
+ Math.hypot(b, a) * img.height / Math.abs(det * scale)
40399
+ );
40400
+ const ax = a * scale / img.width, ay = b * scale / img.width;
40401
+ const bx = c * scale / img.height, by = d * scale / img.height;
40402
+ const s1 = ax * ax + ay * ay, s2 = bx * bx + by * by, cross = ax * bx + ay * by;
40403
+ const smooth = Math.fround((s1 + s2 + Math.hypot(s1 - s2, 2 * cross)) / 2) <= 1;
40404
+ const sample = new Float64Array(4);
40353
40405
  for (let py = minPy; py <= maxPy; py++) {
40354
40406
  const yPdf = displayList.height - (py + 0.5) / scale;
40355
40407
  if (img.clipRect && (yPdf < img.clipRect[1] || yPdf > img.clipRect[3])) continue;
@@ -40361,9 +40413,14 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40361
40413
  const u = (d * dxPdf - c * dyPdf) / det;
40362
40414
  const v = (-b * dxPdf + a * dyPdf) / det;
40363
40415
  if (u < 0 || u > 1 || v < 0 || v > 1) continue;
40364
- const sx = Math.min(img.width - 1, Math.max(0, Math.floor(u * img.width)));
40365
- const sy = Math.min(img.height - 1, Math.max(0, Math.floor((1 - v) * img.height)));
40366
- const sIdx = (sy * img.width + sx) * 4;
40416
+ if (smooth) {
40417
+ sampleImageLinear(source, u * source.width - 0.5, (1 - v) * source.height - 0.5, sample);
40418
+ } else {
40419
+ const sx = Math.min(source.width - 1, Math.max(0, Math.floor(u * source.width)));
40420
+ const sy = Math.min(source.height - 1, Math.max(0, Math.floor((1 - v) * source.height)));
40421
+ const sIdx = (sy * source.width + sx) * 4;
40422
+ for (let c2 = 0; c2 < 4; c2++) sample[c2] = source.data[sIdx + c2];
40423
+ }
40367
40424
  blendPixel(
40368
40425
  rgba,
40369
40426
  width,
@@ -40371,11 +40428,11 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40371
40428
  px,
40372
40429
  py,
40373
40430
  {
40374
- r: img.decodedRgba[sIdx] / 255,
40375
- g: img.decodedRgba[sIdx + 1] / 255,
40376
- b: img.decodedRgba[sIdx + 2] / 255
40431
+ r: sample[0] / 255,
40432
+ g: sample[1] / 255,
40433
+ b: sample[2] / 255
40377
40434
  },
40378
- img.decodedRgba[sIdx + 3] / 255,
40435
+ sample[3] / 255,
40379
40436
  img.blendMode,
40380
40437
  clipMask
40381
40438
  );
@@ -42138,3 +42195,8 @@ export {
42138
42195
  * Adapted from PDFium third_party/agg23/agg_curves.cpp, curve4_div.
42139
42196
  * See THIRD_PARTY_NOTICES.md for the pinned revision and adaptations.
42140
42197
  */
42198
+ /*!
42199
+ * Staged image reduction adapted from Mozilla PDF.js CanvasGraphics._scaleImage.
42200
+ * Copyright 2012 Mozilla Foundation. Licensed under Apache-2.0.
42201
+ * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
42202
+ */
@@ -39053,6 +39053,47 @@ function flattenCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
39053
39053
  points.push([x4, y4]);
39054
39054
  return points;
39055
39055
  }
39056
+ function sampleImageLinear(image, x, y, out) {
39057
+ x = Math.max(0, Math.min(image.width - 1, x));
39058
+ y = Math.max(0, Math.min(image.height - 1, y));
39059
+ const x0 = Math.floor(x), y0 = Math.floor(y);
39060
+ const fx = x - x0, fy = y - y0;
39061
+ out.fill(0);
39062
+ for (let j = 0; j < 2; j++) {
39063
+ for (let i = 0; i < 2; i++) {
39064
+ const offset = (Math.min(image.height - 1, y0 + j) * image.width + Math.min(image.width - 1, x0 + i)) * 4;
39065
+ const alpha = image.data[offset + 3] * (i ? fx : 1 - fx) * (j ? fy : 1 - fy);
39066
+ out[0] = out[0] + image.data[offset] * alpha;
39067
+ out[1] = out[1] + image.data[offset + 1] * alpha;
39068
+ out[2] = out[2] + image.data[offset + 2] * alpha;
39069
+ out[3] = out[3] + alpha;
39070
+ }
39071
+ }
39072
+ if (out[3] > 0) {
39073
+ out[0] = out[0] / out[3];
39074
+ out[1] = out[1] / out[3];
39075
+ out[2] = out[2] / out[3];
39076
+ }
39077
+ }
39078
+ function downscaleImage(image, widthScale, heightScale) {
39079
+ const sample = new Float64Array(4);
39080
+ while (widthScale > 2 && image.width > 1 || heightScale > 2 && image.height > 1) {
39081
+ const width = widthScale > 2 ? Math.ceil(image.width / 2) : image.width;
39082
+ const height = heightScale > 2 ? Math.ceil(image.height / 2) : image.height;
39083
+ const data = new Uint8Array(width * height * 4);
39084
+ for (let y = 0; y < height; y++) {
39085
+ for (let x = 0; x < width; x++) {
39086
+ sampleImageLinear(image, (x + 0.5) * image.width / width - 0.5, (y + 0.5) * image.height / height - 0.5, sample);
39087
+ const offset = (y * width + x) * 4;
39088
+ for (let c = 0; c < 4; c++) data[offset + c] = Math.round(sample[c]);
39089
+ }
39090
+ }
39091
+ widthScale /= image.width / width;
39092
+ heightScale /= image.height / height;
39093
+ image = { width, height, data };
39094
+ }
39095
+ return image;
39096
+ }
39056
39097
  function encodePng(bitmap) {
39057
39098
  return encodeRgbaToPng(bitmap.width, bitmap.height, bitmap.data);
39058
39099
  }
@@ -40332,6 +40373,17 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40332
40373
  const maxPx = Math.min(width - 1, clipMaxPx, Math.ceil(Math.max(...cornersPx)) - 1);
40333
40374
  const minPy = Math.max(0, clipMinPy, Math.floor(Math.min(...cornersPy)));
40334
40375
  const maxPy = Math.min(height - 1, clipMaxPy, Math.ceil(Math.max(...cornersPy)) - 1);
40376
+ if (minPx > maxPx || minPy > maxPy) continue;
40377
+ const source = downscaleImage(
40378
+ { width: img.width, height: img.height, data: img.decodedRgba },
40379
+ Math.hypot(d, c) * img.width / Math.abs(det * scale),
40380
+ Math.hypot(b, a) * img.height / Math.abs(det * scale)
40381
+ );
40382
+ const ax = a * scale / img.width, ay = b * scale / img.width;
40383
+ const bx = c * scale / img.height, by = d * scale / img.height;
40384
+ const s1 = ax * ax + ay * ay, s2 = bx * bx + by * by, cross = ax * bx + ay * by;
40385
+ const smooth = Math.fround((s1 + s2 + Math.hypot(s1 - s2, 2 * cross)) / 2) <= 1;
40386
+ const sample = new Float64Array(4);
40335
40387
  for (let py = minPy; py <= maxPy; py++) {
40336
40388
  const yPdf = displayList.height - (py + 0.5) / scale;
40337
40389
  if (img.clipRect && (yPdf < img.clipRect[1] || yPdf > img.clipRect[3])) continue;
@@ -40343,9 +40395,14 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40343
40395
  const u = (d * dxPdf - c * dyPdf) / det;
40344
40396
  const v = (-b * dxPdf + a * dyPdf) / det;
40345
40397
  if (u < 0 || u > 1 || v < 0 || v > 1) continue;
40346
- const sx = Math.min(img.width - 1, Math.max(0, Math.floor(u * img.width)));
40347
- const sy = Math.min(img.height - 1, Math.max(0, Math.floor((1 - v) * img.height)));
40348
- const sIdx = (sy * img.width + sx) * 4;
40398
+ if (smooth) {
40399
+ sampleImageLinear(source, u * source.width - 0.5, (1 - v) * source.height - 0.5, sample);
40400
+ } else {
40401
+ const sx = Math.min(source.width - 1, Math.max(0, Math.floor(u * source.width)));
40402
+ const sy = Math.min(source.height - 1, Math.max(0, Math.floor((1 - v) * source.height)));
40403
+ const sIdx = (sy * source.width + sx) * 4;
40404
+ for (let c2 = 0; c2 < 4; c2++) sample[c2] = source.data[sIdx + c2];
40405
+ }
40349
40406
  blendPixel(
40350
40407
  rgba,
40351
40408
  width,
@@ -40353,11 +40410,11 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40353
40410
  px,
40354
40411
  py,
40355
40412
  {
40356
- r: img.decodedRgba[sIdx] / 255,
40357
- g: img.decodedRgba[sIdx + 1] / 255,
40358
- b: img.decodedRgba[sIdx + 2] / 255
40413
+ r: sample[0] / 255,
40414
+ g: sample[1] / 255,
40415
+ b: sample[2] / 255
40359
40416
  },
40360
- img.decodedRgba[sIdx + 3] / 255,
40417
+ sample[3] / 255,
40361
40418
  img.blendMode,
40362
40419
  clipMask
40363
40420
  );
@@ -42412,3 +42469,8 @@ export {
42412
42469
  * Adapted from PDFium third_party/agg23/agg_curves.cpp, curve4_div.
42413
42470
  * See THIRD_PARTY_NOTICES.md for the pinned revision and adaptations.
42414
42471
  */
42472
+ /*!
42473
+ * Staged image reduction adapted from Mozilla PDF.js CanvasGraphics._scaleImage.
42474
+ * Copyright 2012 Mozilla Foundation. Licensed under Apache-2.0.
42475
+ * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
42476
+ */