In one test PDF, deleting a single /Decode entry turned a CMYK JPEG near-black in three renderers

2026-11-29来源 dev.toEnglish

In the test file below, a CMYK JPEG inside a PDF was not a self-contained picture. Its bytes carry the ink values, and a dictionary entry next to them, /Decode [1 0 1 0 1 0 1 0], sits outside those bytes. In that file, deleting that single entry, with the JPEG bytes untouched, made the picture render near-black in MuPDF, poppler and Ghostscript alike: region average colour difference ΔE 49.3 against the original. Decoding the same bytes in a browser, with the entry never consulted, landed ΔE 8.3 away from what a PDF reader shows.

The numbers come from one mixed test PDF with ten kinds of embedded image, one image of each kind, on one Apple-silicon Mac. Every figure means "in this file", and the CMYK, ICC and Lab images are all derived from the same photo. The photo part is from Bonnie Moreland's Lake Mountain Landscape.jpg on Wikimedia Commons (CC0); the JBIG2 page is byte-for-byte from the Internet Archive copy of the 1986 Jianhuazi Zongbiao (Public Domain Mark 1.0); the other text, fax page, screenshot and stamp are self-made with fictional content.

One dictionary key flips the picture

The CMYK image is 1,800 by 1,200 pixels, 1,641,218 bytes, with an Adobe marker in the JPEG and the /Decode array above in the PDF image dictionary. A second copy of the file had that array replaced by spaces of equal length, so no byte offset moved. In all three renderers the image area went to roughly RGB (11, 6, 7), and ΔE against the original was 49.3 in each comparison. ΔE here is CIE76 on the average colour of the region, so it says "the area as a whole moved this far", not anything about print colour quality.

None of the tools run on the unmodified file produced a dark image. Ghostscript at /ebook and macOS's Reduce File Size filter neither turned it dark, and when they were fed the no-/Decode copy, both baked the near-black look into an RGB JPEG. So a tool is not what turns it dark here. What does it is a dictionary that no longer matches the bytes.

A browser decode is already off

Pulled out of the PDF and handed to a browser as an ordinary image, the same JPEG bytes decoded to an average of RGB (102, 108, 118). Pillow gave the identical value. The readers showed about (126, 121, 124) in MuPDF and (120, 114, 122) in poppler. Against the reader the browser result is ΔE 8.3: not near-black, but a measurable shift, and it happens before any re-encode has started. A pipeline that decodes this stream in a browser and writes a new JPEG would start from that shifted colour.

The two readers also disagree with each other a little. After macOS rewrote the image, the region sat ΔE 4.57 from the original in MuPDF and 4.21 in poppler. After Ghostscript converted it to RGB it sat 0.45 in MuPDF and 3.73 in poppler, so the original CMYK was never one fixed colour across readers, and converting to RGB pins it to one of the possible readings.

What is inferred and what is not

Everything above was measured on that file. The explanation below is inference, not tested here. A decoder handed only the JPEG bytes never sees the PDF dictionary, and how the Adobe marker and /Decode interact is the likely place the near-black result and the browser's shift come from. How far a given browser or library honours the Adobe marker was not checked beyond this one file. ICC and Lab images in the same file, converted to RGB by Ghostscript and macOS, stayed within ΔE 0.8 of the original, so the CMYK case is the one that moved.

Where ImgIng fits

In the same run, ImgIng, a browser tool that handles PDFs on the desktop, was used at https://imging.ai/ and left this image alone: its output carried the CMYK stream with an unchanged SHA-256, and the result list marked it as kept original, with a colour or bit-depth protection reason. ImgIng's product notes (as of 2026-11-27) list CMYK print JPEG, JPEG 2000, JBIG2, CCITT fax and images needing full ICC or Lab colour management as kept as-is when a browser cannot re-encode them reliably. Keeping them has a cost: on this file seven images, 71.7% of the bytes, were left untouched, so the saving came from the remaining three.

Before you re-encode a CMYK image

If a pipeline touches CMYK JPEGs inside PDFs, the check is cheap: print the image dictionary, look for /Decode and /ColorSpace, and compare a rendered region before and after in at least two renderers. If the colour has to survive, leaving the stream alone is the safest default; if size matters more, expect it to move: in this file the average colour shifted by 0.45 to 4.57 ΔE depending on tool and reader.

原文:https://www.a8q9.cn/en/article/in-one-test-pdf-deleting-a-single-decode-entry-turned-a-cmyk-jpeg-near-black-in--5dcf51.html

相关文章