JPEG saved with keep_rgb=True and dpi reopens with incorrect colors
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 25/100
Direzione di ricerca
Start with the JPEG encoder path in src/libImaging/JpegEncode.c and the decoder’s color-space selection; the issue links both relevant code locations and cites libjpeg-turbo’s default selection. Compare JPEGs saved with and without DPI and keep_rgb=True, then run the reproducer in the issue. Done means both files reopen with approximately red pixels while retaining the requested DPI behavior; pull request #10345 is already open.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What did you do?
Saved the same RGB image to JPEG with keep_rgb=True, once with DPI and once without it, then reopened both files:
from io import BytesIO
from PIL import Image
image = Image.new("RGB", (16, 16), (255, 0, 0))
for dpi in (None, (72, 72)):
out = BytesIO()
options = {"keep_rgb": True, "quality": 100, "subsampling": 0}
if dpi is not None:
options["dpi"] = dpi
image.save(out, "JPEG", **options)
out.seek(0)
with Image.open(out) as reopened:
print(dpi, reopened.getpixel((0, 0)))
What did you expect to happen?
Both images should reopen approximately red. Setting DPI should not visibly change the colors.
What actually happened?
On both installations below, the output was:
None (255, 0, 0)
(72, 72) (76, 255, 28)
The DPI version contains both a JFIF APP0 marker and an Adobe APP14 marker with transform 0; the version without DPI contains only the Adobe marker. As a diagnostic, removing the JFIF marker from the generated bytes made Pillow reopen the pixel as (255, 0, 0), but also removed the DPI. I don't know whether the right fix is in the writer, the reader, or both.
FFmpeg 9.0.2 decodes both generated JPEGs as (255, 0, 0) on the same machine. This suggests a difference in decoding the DPI version; I have not isolated the responsible layer.
The generated file has component IDs R, G and B. As a diagnostic, forcing the low-level JPEG decoder input mode to RGB also restores the expected red in both Pillow versions.
Looking at libjpeg-turbo 3.2.0, its default color-space selection gives the JFIF marker precedence over Adobe APP14, selecting YCbCr when both are present. Pillow enables JFIF when both DPI values are positive.
#7679 notes that setting DPI forces JFIF even for non-JFIF color spaces. The JPEG encoder source is identical between the 13.0.0 tag and current main, although I haven't built main to reproduce this there.
What are your OS, Python and Pillow versions?
- Windows 11, Python 3.15.2, Pillow 13.0.0, libjpeg-turbo 3.2.0.
- Also reproduced with Python 3.12.14, Pillow 12.3.0, libjpeg-turbo 3.1.4.1.
Reproducer and investigation assisted by Codex.
- Lingua principale
- Python
- Stelle
- 13.9k
- Fork
- 2.6k
- Merge medio
- 1g 4h
- PR unite (30g)
- 173
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di python-pillow/Pillow
-
Warn that pre-applying arabic_reshaper + python-bidi corrupts text on a Raqm buildForse già presa @Syamjith-NK l’ha presa 61 giorni fa. ApertaDocumentation Font Rendering PNG Third Party Framework
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
python-pillow/Pillow#9907 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Image.putpixel incorrectly labels supported arguments in type annotationsForse già presa @radarhere l’ha presa 189 giorni fa. ApertaPNG
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
python-pillow/Pillow#9584 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
`ImageDraw.arc()` segfaults on a tuple subclass whose `__len__` is too largeForse già presa @Parsiffall1 l’ha presa oggi. Aperta
Difficoltà 4/5 1-2 giorni Idoneità per principianti 58/100
python-pillow/Pillow#10358 ·
I maintainer di solito rispondono entro 1 giorno
-
JPEG dpi read from EXIF uses XResolution for both axesForse già presa @unvisible789 l’ha presa 2 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 20/100
python-pillow/Pillow#10331 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
16-bit PNG tRNS key: convert("RGBA") misses the keyed pixel and makes another transparentForse già presa Una pull request collegata a questa issue è aperta o già unita. ApertaConversion
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
python-pillow/Pillow#10330 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di python-pillow/Pillow
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
I maintainer di solito rispondono entro 4 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
ClockGU/clockwork-backend#169 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
aws-samples/sample-per-model-bedrock#616 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
chnm/teachinghistory-hugo#47 ·
-
good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
pandas-dev/pandas-stubs#2047 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno