Skip to content

Commit

Permalink
Add a jpx decoder based on OpenJPEG 2.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
calixteman committed Apr 15, 2024
1 parent 2e94511 commit 9c3ba5b
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 2,340 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ external/bcmaps/
external/builder/fixtures/
external/builder/fixtures_esprima/
external/quickjs/
external/openjpeg/
test/tmp/
test/pdfs/
web/locale/
Expand Down
12 changes: 12 additions & 0 deletions external/openjpeg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Build

In order to generate the file `openjpeg.js`:
* git clone https://github.com/mozilla/pdf.js.openjpeg/
* the build requires to have a [Docker](https://www.docker.com/) setup and then:
* `node build.js -C` to build the Docker image
* `node build.js -co /pdf.js/external/openjpeg/` to compile the decoder

## Licensing

[OpenJPEG](https://www.openjpeg.org/) is under [BSD 2-clause "Simplified" License](https://github.com/uclouvain/openjpeg/blob/master/LICENSE)
and [pdf.js.openjpeg](https://github.com/mozilla/pdf.js.openjpeg/) is released under [Apache 2](https://github.com/mozilla/pdf.js.openjpeg/blob/main/LICENSE) license so `openjpeg.js` is released under [Apache 2](https://github.com/mozilla/pdf.js.openjpeg/blob/main/LICENSE) license too.
15 changes: 15 additions & 0 deletions external/openjpeg/openjpeg.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,7 @@ function buildLib(defines, dir) {
),
gulp.src(["web/*.js", "!web/{pdfjs,viewer}.js"], { base: "." }),
gulp.src("test/unit/*.js", { base: "." }),
gulp.src("external/openjpeg/*.js", { base: "openjpeg/" }),
]);

return buildLibHelper(bundleDefines, inputStream, dir);
Expand Down
5 changes: 5 additions & 0 deletions src/core/cleanup_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@
import { clearPatternCaches } from "./pattern.js";
import { clearPrimitiveCaches } from "./primitives.js";
import { clearUnicodeCaches } from "./unicode.js";
import { JpxImage } from "./jpx.js";

function clearGlobalCaches() {
clearPatternCaches();
clearPrimitiveCaches();
clearUnicodeCaches();

// Remove the global `JpxImage` instance, since it may hold a reference to
// the WebAssembly module.
JpxImage.cleanup();
}

export { clearGlobalCaches };
13 changes: 6 additions & 7 deletions src/core/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,13 @@ class PDFImage {
}
switch (filterName) {
case "JPXDecode":
const jpxImage = new JpxImage();
jpxImage.parseImageProperties(image.stream);
({
width: image.width,
height: image.height,
componentsCount: image.numComps,
bitsPerComponent: image.bitsPerComponent,
} = JpxImage.parseImageProperties(image.stream));
image.stream.reset();

image.width = jpxImage.width;
image.height = jpxImage.height;
image.bitsPerComponent = jpxImage.bitsPerComponent;
image.numComps = jpxImage.componentsCount;
break;
case "JBIG2Decode":
image.bitsPerComponent = 1;
Expand Down

0 comments on commit 9c3ba5b

Please sign in to comment.