Merge pull request #9897 from Snuffleupagus/issue-9650
Prefer the Width/Height of the image data, rather than the image dictionary, for JPEG 2000 images (issue 9650)
This commit is contained in:
commit
20fddef5ba
@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { assert, FormatError, ImageKind, info, warn } from '../shared/util';
|
import { assert, FormatError, ImageKind, info, warn } from '../shared/util';
|
||||||
import { isStream, Name } from './primitives';
|
import { isName, isStream, Name } from './primitives';
|
||||||
import { ColorSpace } from './colorspace';
|
import { ColorSpace } from './colorspace';
|
||||||
import { DecodeStream } from './stream';
|
import { DecodeStream } from './stream';
|
||||||
import { JpegStream } from './jpeg_stream';
|
import { JpegStream } from './jpeg_stream';
|
||||||
@ -84,27 +84,47 @@ var PDFImage = (function PDFImageClosure() {
|
|||||||
this.image = image;
|
this.image = image;
|
||||||
var dict = image.dict;
|
var dict = image.dict;
|
||||||
if (dict.has('Filter')) {
|
if (dict.has('Filter')) {
|
||||||
var filter = dict.get('Filter').name;
|
const filter = dict.get('Filter');
|
||||||
if (filter === 'JPXDecode') {
|
if (isName(filter)) {
|
||||||
var jpxImage = new JpxImage();
|
switch (filter.name) {
|
||||||
jpxImage.parseImageProperties(image.stream);
|
case 'JPXDecode':
|
||||||
image.stream.reset();
|
var jpxImage = new JpxImage();
|
||||||
image.bitsPerComponent = jpxImage.bitsPerComponent;
|
jpxImage.parseImageProperties(image.stream);
|
||||||
image.numComps = jpxImage.componentsCount;
|
image.stream.reset();
|
||||||
} else if (filter === 'JBIG2Decode') {
|
|
||||||
image.bitsPerComponent = 1;
|
image.width = jpxImage.width;
|
||||||
image.numComps = 1;
|
image.height = jpxImage.height;
|
||||||
|
image.bitsPerComponent = jpxImage.bitsPerComponent;
|
||||||
|
image.numComps = jpxImage.componentsCount;
|
||||||
|
break;
|
||||||
|
case 'JBIG2Decode':
|
||||||
|
image.bitsPerComponent = 1;
|
||||||
|
image.numComps = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
warn(`PDFImage - invalid /Filter entry in dictionary: "${filter}".`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO cache rendered images?
|
// TODO cache rendered images?
|
||||||
|
|
||||||
this.width = dict.get('Width', 'W');
|
let width = dict.get('Width', 'W');
|
||||||
this.height = dict.get('Height', 'H');
|
let height = dict.get('Height', 'H');
|
||||||
|
|
||||||
if (this.width < 1 || this.height < 1) {
|
if ((Number.isInteger(image.width) && image.width > 0) &&
|
||||||
throw new FormatError(`Invalid image width: ${this.width} or ` +
|
(Number.isInteger(image.height) && image.height > 0) &&
|
||||||
`height: ${this.height}`);
|
(image.width !== width || image.height !== height)) {
|
||||||
|
warn('PDFImage - using the Width/Height of the image data, ' +
|
||||||
|
'rather than the image dictionary.');
|
||||||
|
width = image.width;
|
||||||
|
height = image.height;
|
||||||
}
|
}
|
||||||
|
if (width < 1 || height < 1) {
|
||||||
|
throw new FormatError(`Invalid image width: ${width} or ` +
|
||||||
|
`height: ${height}`);
|
||||||
|
}
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
|
||||||
this.interpolate = dict.get('Interpolate', 'I') || false;
|
this.interpolate = dict.get('Interpolate', 'I') || false;
|
||||||
this.imageMask = dict.get('ImageMask', 'IM') || false;
|
this.imageMask = dict.get('ImageMask', 'IM') || false;
|
||||||
@ -139,7 +159,7 @@ var PDFImage = (function PDFImageClosure() {
|
|||||||
colorSpace = Name.get('DeviceCMYK');
|
colorSpace = Name.get('DeviceCMYK');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`JPX images with ${this.numComps} ` +
|
throw new Error(`JPX images with ${image.numComps} ` +
|
||||||
'color components not supported.');
|
'color components not supported.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
this.width = Xsiz - XOsiz;
|
this.width = Xsiz - XOsiz;
|
||||||
this.height = Ysiz - YOsiz;
|
this.height = Ysiz - YOsiz;
|
||||||
this.componentsCount = Csiz;
|
this.componentsCount = Csiz;
|
||||||
// Results are always returned as Uint8Arrays
|
// Results are always returned as `Uint8ClampedArray`s.
|
||||||
this.bitsPerComponent = 8;
|
this.bitsPerComponent = 8;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
1
test/pdfs/issue9650.pdf.link
Normal file
1
test/pdfs/issue9650.pdf.link
Normal file
@ -0,0 +1 @@
|
|||||||
|
https://github.com/mozilla/pdf.js/files/1898753/Kred.Eingangsrechnungen.pdf
|
@ -3259,6 +3259,14 @@
|
|||||||
"lastPage": 1,
|
"lastPage": 1,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
},
|
},
|
||||||
|
{ "id": "issue9650",
|
||||||
|
"file": "pdfs/issue9650.pdf",
|
||||||
|
"md5": "20d50bda6b1080b6d9088811299c791e",
|
||||||
|
"rounds": 1,
|
||||||
|
"link": true,
|
||||||
|
"lastPage": 1,
|
||||||
|
"type": "eq"
|
||||||
|
},
|
||||||
{ "id": "issue9679",
|
{ "id": "issue9679",
|
||||||
"file": "pdfs/issue9679.pdf",
|
"file": "pdfs/issue9679.pdf",
|
||||||
"md5": "3077d06add3875705aa1021c7b116023",
|
"md5": "3077d06add3875705aa1021c7b116023",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user