Add more validation of the /Filter entry, in image dictionaries, to the PDFImage
constructor
Given that the code is currently assuming that the /Filter entry is a `Name`, it cannot hurt to actually ensure that's the case. Also fixes an error message, for JPEG 2000 images with unsupported ColorSpaces, since `this.numComps` hasn't been initialized when it's accessed during the `throw new Error()` invocation.
This commit is contained in:
parent
3521424576
commit
17f65908ae
@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
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 { DecodeStream } from './stream';
|
||||
import { JpegStream } from './jpeg_stream';
|
||||
@ -84,16 +84,23 @@ var PDFImage = (function PDFImageClosure() {
|
||||
this.image = image;
|
||||
var dict = image.dict;
|
||||
if (dict.has('Filter')) {
|
||||
var filter = dict.get('Filter').name;
|
||||
if (filter === 'JPXDecode') {
|
||||
var jpxImage = new JpxImage();
|
||||
jpxImage.parseImageProperties(image.stream);
|
||||
image.stream.reset();
|
||||
image.bitsPerComponent = jpxImage.bitsPerComponent;
|
||||
image.numComps = jpxImage.componentsCount;
|
||||
} else if (filter === 'JBIG2Decode') {
|
||||
image.bitsPerComponent = 1;
|
||||
image.numComps = 1;
|
||||
const filter = dict.get('Filter');
|
||||
if (isName(filter)) {
|
||||
switch (filter.name) {
|
||||
case 'JPXDecode':
|
||||
var jpxImage = new JpxImage();
|
||||
jpxImage.parseImageProperties(image.stream);
|
||||
image.stream.reset();
|
||||
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?
|
||||
@ -139,7 +146,7 @@ var PDFImage = (function PDFImageClosure() {
|
||||
colorSpace = Name.get('DeviceCMYK');
|
||||
break;
|
||||
default:
|
||||
throw new Error(`JPX images with ${this.numComps} ` +
|
||||
throw new Error(`JPX images with ${image.numComps} ` +
|
||||
'color components not supported.');
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ var JpxImage = (function JpxImageClosure() {
|
||||
this.width = Xsiz - XOsiz;
|
||||
this.height = Ysiz - YOsiz;
|
||||
this.componentsCount = Csiz;
|
||||
// Results are always returned as Uint8Arrays
|
||||
// Results are always returned as `Uint8ClampedArray`s.
|
||||
this.bitsPerComponent = 8;
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user