Skip to content

Commit

Permalink
Merge pull request mozilla#15221 from Snuffleupagus/issue-15220
Browse files Browse the repository at this point in the history
Support images with /Filter-entries that contain Arrays (issue 15220)
  • Loading branch information
Snuffleupagus committed Jul 25, 2022
2 parents 14a8b81 + fc018ea commit 8ebd2d3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/core/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,31 @@ class PDFImage {
const dict = image.dict;

const filter = dict.get("F", "Filter");
let filterName;
if (filter instanceof Name) {
switch (filter.name) {
case "JPXDecode":
const jpxImage = new JpxImage();
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;
image.numComps = 1;
break;
filterName = filter.name;
} else if (Array.isArray(filter)) {
const filterZero = xref.fetchIfRef(filter[0]);
if (filterZero instanceof Name) {
filterName = filterZero.name;
}
}
// TODO cache rendered images?
switch (filterName) {
case "JPXDecode":
const jpxImage = new JpxImage();
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;
image.numComps = 1;
break;
}

let width = dict.get("W", "Width");
let height = dict.get("H", "Height");
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/issue15220.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/mozilla/pdf.js/files/9178570/issue15220_page2.pdf
8 changes: 8 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@
"lastPage": 1,
"type": "eq"
},
{ "id": "issue15220",
"file": "pdfs/issue15220.pdf",
"md5": "0864a9e3860c0cb5e98b5eb23287fba4",
"rounds": 1,
"link": true,
"lastPage": 1,
"type": "eq"
},
{ "id": "issue11549",
"file": "pdfs/issue11549_reduced.pdf",
"md5": "a1ea636f413e02e10dbdf379ab4a99ae",
Expand Down

0 comments on commit 8ebd2d3

Please sign in to comment.