Compare commits

..

No commits in common. "04400c588f22626987ad9a699cdacaa2dc52922c" and "06f44916c8936b92f464d337fe3a0a6b2b78d5b4" have entirely different histories.

9 changed files with 15 additions and 62 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -112,22 +112,11 @@ class PDFImage {
bitsPerComponent: image.bitsPerComponent,
} = JpxImage.parseImageProperties(image.stream));
image.stream.reset();
const reducePower = ImageResizer.getReducePowerForJPX(
image.width,
image.height,
image.numComps
);
this.jpxDecoderOptions = {
numComponents: 0,
isIndexedColormap: false,
smaskInData: dict.has("SMaskInData"),
reducePower,
};
if (reducePower) {
const factor = 2 ** reducePower;
image.width = Math.ceil(image.width / factor);
image.height = Math.ceil(image.height / factor);
}
break;
case "JBIG2Decode":
image.bitsPerComponent = 1;

View File

@ -96,30 +96,6 @@ class ImageResizer {
return area > maxArea;
}
static getReducePowerForJPX(width, height, componentsCount) {
const area = width * height;
// The maximum memory we've in the wasm runtime is 2GB.
// Each component is 4 bytes and we can't allocate all the memory just for
// the buffers so we limit the size to 1GB / (componentsCount * 4).
// We could use more than 2GB by setting MAXIMUM_MEMORY but it would take
// too much time to decode a big image.
const maxJPXArea = 2 ** 30 / (componentsCount * 4);
if (!this.needsToBeResized(width, height)) {
if (area > maxJPXArea) {
// The image is too large, we need to rescale it.
return Math.ceil(Math.log2(area / maxJPXArea));
}
return 0;
}
const { MAX_DIM, MAX_AREA } = this;
const minFactor = Math.max(
width / MAX_DIM,
height / MAX_DIM,
Math.sqrt(area / Math.min(maxJPXArea, MAX_AREA))
);
return Math.ceil(Math.log2(minFactor));
}
static get MAX_DIM() {
return shadow(
this,

View File

@ -92,12 +92,7 @@ class JpxImage {
static async decode(
bytes,
{
numComponents = 4,
isIndexedColormap = false,
smaskInData = false,
reducePower = 0,
} = {}
{ numComponents = 4, isIndexedColormap = false, smaskInData = false } = {}
) {
if (!this.#modulePromise) {
const { promise, resolve } = Promise.withResolvers();
@ -124,14 +119,13 @@ class JpxImage {
try {
const size = bytes.length;
ptr = module._malloc(size);
module.writeArrayToMemory(bytes, ptr);
module.HEAPU8.set(bytes, ptr);
const ret = module._jp2_decode(
ptr,
size,
numComponents > 0 ? numComponents : 0,
!!isIndexedColormap,
!!smaskInData,
reducePower
!!smaskInData
);
if (ret) {
const { errorMessages } = module;

View File

@ -724,4 +724,3 @@
!issue16742.pdf
!chrome-text-selection-markedContent.pdf
!bug1963407.pdf
!issue19517.pdf

Binary file not shown.

View File

@ -12107,12 +12107,5 @@
"value": "Hello World"
}
}
},
{
"id": "issue19517",
"file": "pdfs/issue19517.pdf",
"md5": "2abe67c8b34522feb6b85d252dde9d3e",
"rounds": 1,
"type": "eq"
}
]