Merge 17da7a1304544291615bd06c884af3aed39b7fbe into ec71e4ed651e659b06a4fa46ef0b18ff9ab2a8c7

This commit is contained in:
calixteman 2025-11-24 14:53:36 +01:00 committed by GitHub
commit 8e372be3e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 8 deletions

View File

@ -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 }) { static setOptions({ isImageDecoderSupported = false }) {
this.#isImageDecoderSupported = isImageDecoderSupported; this.#isImageDecoderSupported = isImageDecoderSupported;
} }
@ -171,6 +181,14 @@ class JpegStream extends DecodeStream {
if (!useImageDecoder) { if (!useImageDecoder) {
return null; return null;
} }
let type = "image/jpeg";
if (useImageDecoder.cmyk) {
if (await JpegStream.canUseImageDecoderCMYK) {
type = "image/x-jpeg-pdf";
} else {
return null;
}
}
if (useImageDecoder.exifStart) { if (useImageDecoder.exifStart) {
// Replace the entire EXIF-block with dummy data, to ensure that a // Replace the entire EXIF-block with dummy data, to ensure that a
// non-default EXIF orientation won't cause the image to be rotated // non-default EXIF orientation won't cause the image to be rotated
@ -182,7 +200,7 @@ class JpegStream extends DecodeStream {
} }
decoder = new ImageDecoder({ decoder = new ImageDecoder({
data, data,
type: "image/jpeg", type,
preferAnimation: false, preferAnimation: false,
}); });

View File

@ -810,7 +810,7 @@ class JpegImage {
} }
static canUseImageDecoder(data, colorTransform = -1) { static canUseImageDecoder(data, colorTransform = -1) {
let exifOffsets = null; const jpegInfo = Object.create(null);
let offset = 0; let offset = 0;
let numComponents = null; let numComponents = null;
let fileMarker = readUint16(data, offset); let fileMarker = readUint16(data, offset);
@ -838,12 +838,13 @@ class JpegImage {
appData[4] === 0 && appData[4] === 0 &&
appData[5] === 0 appData[5] === 0
) { ) {
if (exifOffsets) { if (jpegInfo.exifStart) {
throw new JpegError("Duplicate EXIF-blocks found."); throw new JpegError("Duplicate EXIF-blocks found.");
} }
// Don't do the EXIF-block replacement here, see `JpegStream`, // Don't do the EXIF-block replacement here, see `JpegStream`,
// since that can modify the original PDF document. // 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); fileMarker = readUint16(data, offset);
offset += 2; offset += 2;
@ -868,13 +869,13 @@ class JpegImage {
fileMarker = readUint16(data, offset); fileMarker = readUint16(data, offset);
offset += 2; offset += 2;
} }
if (numComponents === 4) {
return null;
}
if (numComponents === 3 && colorTransform === 0) { if (numComponents === 3 && colorTransform === 0) {
return null; return null;
} }
return exifOffsets || {}; if (numComponents === 4) {
jpegInfo.cmyk = true;
}
return jpegInfo;
} }
parse(data, { dnlScanLines = null } = {}) { parse(data, { dnlScanLines = null } = {}) {