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 6939d64
Show file tree
Hide file tree
Showing 18 changed files with 230 additions and 2,395 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.

15 changes: 7 additions & 8 deletions src/core/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import { ColorSpace } from "./colorspace.js";
import { DecodeStream } from "./decode_stream.js";
import { ImageResizer } from "./image_resizer.js";
import { JpegStream } from "./jpeg_stream.js";
import { JpxImage } from "./jpx.js";
import { Name } from "./primitives.js";
import { OpenJPEGDecoder } from "./openjpeg_decoder.js";

/**
* Decode and clamp a value. The formula is different from the spec because we
Expand Down 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,
} = OpenJPEGDecoder.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
Loading

0 comments on commit 6939d64

Please sign in to comment.