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 { 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,16 +84,23 @@ 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 = jpxImage.bitsPerComponent;
|
||||||
image.bitsPerComponent = 1;
|
image.numComps = jpxImage.componentsCount;
|
||||||
image.numComps = 1;
|
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?
|
||||||
@ -139,7 +146,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;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user