1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

[api-minor] Add a jpx decoder based on OpenJPEG 2.5.2

The decoder is compiled in WASM:
https://github.com/mozilla/pdf.js.openjpeg

Fixes #17289, #17061, #16485, #13051, #6365, #4648, #12213.
This commit is contained in:
Calixte Denizet 2024-04-15 10:12:05 +02:00
parent 2e94511330
commit 2e83cfbbc1
20 changed files with 172 additions and 2347 deletions

View file

@ -41,44 +41,12 @@ class JpxStream extends DecodeStream {
// directly insert all of its data into `this.buffer`.
}
readBlock() {
readBlock(ignoreColorSpace) {
if (this.eof) {
return;
}
const jpxImage = new JpxImage();
jpxImage.parse(this.bytes);
const width = jpxImage.width;
const height = jpxImage.height;
const componentsCount = jpxImage.componentsCount;
const tileCount = jpxImage.tiles.length;
if (tileCount === 1) {
this.buffer = jpxImage.tiles[0].items;
} else {
const data = new Uint8ClampedArray(width * height * componentsCount);
for (let k = 0; k < tileCount; k++) {
const tileComponents = jpxImage.tiles[k];
const tileWidth = tileComponents.width;
const tileHeight = tileComponents.height;
const tileLeft = tileComponents.left;
const tileTop = tileComponents.top;
const src = tileComponents.items;
let srcPosition = 0;
let dataPosition = (width * tileTop + tileLeft) * componentsCount;
const imgRowSize = width * componentsCount;
const tileRowSize = tileWidth * componentsCount;
for (let j = 0; j < tileHeight; j++) {
const rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
data.set(rowBytes, dataPosition);
srcPosition += tileRowSize;
dataPosition += imgRowSize;
}
}
this.buffer = data;
}
this.buffer = JpxImage.decode(this.bytes, ignoreColorSpace);
this.bufferLength = this.buffer.length;
this.eof = true;
}