Merge 17da7a1304544291615bd06c884af3aed39b7fbe into ec71e4ed651e659b06a4fa46ef0b18ff9ab2a8c7
This commit is contained in:
commit
8e372be3e6
@ -44,6 +44,16 @@ class JpegStream extends DecodeStream {
|
||||
);
|
||||
}
|
||||
|
||||
static get canUseImageDecoderCMYK() {
|
||||
return shadow(
|
||||
this,
|
||||
"canUseImageDecoderCMYK",
|
||||
this.#isImageDecoderSupported
|
||||
? ImageDecoder.isTypeSupported("image/x-jpeg-pdf")
|
||||
: Promise.resolve(false)
|
||||
);
|
||||
}
|
||||
|
||||
static setOptions({ isImageDecoderSupported = false }) {
|
||||
this.#isImageDecoderSupported = isImageDecoderSupported;
|
||||
}
|
||||
@ -171,6 +181,14 @@ class JpegStream extends DecodeStream {
|
||||
if (!useImageDecoder) {
|
||||
return null;
|
||||
}
|
||||
let type = "image/jpeg";
|
||||
if (useImageDecoder.cmyk) {
|
||||
if (await JpegStream.canUseImageDecoderCMYK) {
|
||||
type = "image/x-jpeg-pdf";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (useImageDecoder.exifStart) {
|
||||
// Replace the entire EXIF-block with dummy data, to ensure that a
|
||||
// non-default EXIF orientation won't cause the image to be rotated
|
||||
@ -182,7 +200,7 @@ class JpegStream extends DecodeStream {
|
||||
}
|
||||
decoder = new ImageDecoder({
|
||||
data,
|
||||
type: "image/jpeg",
|
||||
type,
|
||||
preferAnimation: false,
|
||||
});
|
||||
|
||||
|
||||
@ -810,7 +810,7 @@ class JpegImage {
|
||||
}
|
||||
|
||||
static canUseImageDecoder(data, colorTransform = -1) {
|
||||
let exifOffsets = null;
|
||||
const jpegInfo = Object.create(null);
|
||||
let offset = 0;
|
||||
let numComponents = null;
|
||||
let fileMarker = readUint16(data, offset);
|
||||
@ -838,12 +838,13 @@ class JpegImage {
|
||||
appData[4] === 0 &&
|
||||
appData[5] === 0
|
||||
) {
|
||||
if (exifOffsets) {
|
||||
if (jpegInfo.exifStart) {
|
||||
throw new JpegError("Duplicate EXIF-blocks found.");
|
||||
}
|
||||
// Don't do the EXIF-block replacement here, see `JpegStream`,
|
||||
// since that can modify the original PDF document.
|
||||
exifOffsets = { exifStart: oldOffset + 6, exifEnd: newOffset };
|
||||
jpegInfo.exifStart = oldOffset + 6;
|
||||
jpegInfo.exifEnd = newOffset;
|
||||
}
|
||||
fileMarker = readUint16(data, offset);
|
||||
offset += 2;
|
||||
@ -868,13 +869,13 @@ class JpegImage {
|
||||
fileMarker = readUint16(data, offset);
|
||||
offset += 2;
|
||||
}
|
||||
if (numComponents === 4) {
|
||||
return null;
|
||||
}
|
||||
if (numComponents === 3 && colorTransform === 0) {
|
||||
return null;
|
||||
}
|
||||
return exifOffsets || {};
|
||||
if (numComponents === 4) {
|
||||
jpegInfo.cmyk = true;
|
||||
}
|
||||
return jpegInfo;
|
||||
}
|
||||
|
||||
parse(data, { dnlScanLines = null } = {}) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user