Saving grayscale images as AVIF fails with libavif older than 1.3.0
维护者通常 1 天内回复
已经有一个关联 PR 被合并了。
- #10263 来自 @lazerg —— 已合并
评估
调研方向
Start with AvifImagePlugin._save and the AVIF handling in _avif.c, especially the AVIF_VERSION condition around grayscale format support. Compare the "L" rawmode path with the libavif version checks and run the AVIF save tests against libavif 1.0.4 and a newer version. Done means grayscale modes save successfully with both versions, while the RGB control still works.
由索引模型根据 Issue 内容生成。
描述
What did you do?
Saved a grayscale image as AVIF with Pillow built from source against the distribution libavif on Ubuntu 24.04 (libavif-dev 1.0.4):
from io import BytesIO
from PIL import Image, features
print("Pillow", Image.__version__, "| libavif", features.version("avif"))
for mode in ("1", "L", "I", "I;16", "F"):
try:
Image.new(mode, (128, 128)).save(BytesIO(), "AVIF")
print(mode, "saved")
except Exception as e:
print(mode, type(e).__name__ + ":", e)
Image.new("L", (128, 128)).convert("RGB").save(BytesIO(), "AVIF")
print("control: L converted to RGB first, saved")
What did you expect to happen?
The images to be saved, as they were before 12.3.0 (which converted them to RGB). The building-from-source docs say Pillow requires libavif 1.0.0 or greater.
What actually happened?
Pillow 13.1.0.dev0 | libavif 1.0.4
1 RuntimeError: rgb data has incorrect size: 384 * 128 (49152) != 16384
L RuntimeError: rgb data has incorrect size: 384 * 128 (49152) != 16384
I RuntimeError: rgb data has incorrect size: 384 * 128 (49152) != 16384
I;16 RuntimeError: rgb data has incorrect size: 384 * 128 (49152) != 16384
F RuntimeError: rgb data has incorrect size: 384 * 128 (49152) != 16384
control: L converted to RGB first, saved
Every grayscale mode fails; converting to RGB first works.
#9471 (12.3.0) made AvifImagePlugin._save pass rawmode "L" for grayscale modes unconditionally, but _avif.c only handles AVIF_RGB_FORMAT_GRAY under #if AVIF_VERSION >= 1030000. With libavif < 1.3.0 the C side packs the data as RGB, so the size check fails. Wheels bundle a newer libavif, so this only affects builds against an older system libavif.
What are your OS, Python and Pillow versions?
- OS: Ubuntu 24.04 (libavif 1.0.4 from apt)
- Python: 3.13.16
- Pillow: main at 95847325 (13.1.0.dev0), built from source
Found and reproduced with AI assistance; the repro above was run by me.
- 主要语言
- Python
- 星标
- 13.9k
- 派生
- 2.5k
- 平均合并
- 1 天 8 分钟
- 30 天内合并 PR
- 149
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python-pillow/Pillow 的其他 Issue
-
Warn that pre-applying arabic_reshaper + python-bidi corrupts text on a Raqm build可能已有人在做 @Syamjith-NK 于 54 天前认领。 未关闭Documentation Font Rendering PNG Third Party Framework
难度 2/5 1-3 小时 新手友好度 78/100
python-pillow/Pillow#9907 · 2 条评论 ·
维护者通常 1 天内回复
-
Image.putpixel incorrectly labels supported arguments in type annotations可能已有人在做 @radarhere 于 182 天前认领。 未关闭PNG
难度 2/5 1-3 小时 新手友好度 70/100
python-pillow/Pillow#9584 · 1 条评论 ·
维护者通常 1 天内回复
-
SystemError in `ImagePath.Path` item assignment and `ImageDraw` coordinates可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 3/5 1-2 天 新手友好度 66/100
python-pillow/Pillow#10284 ·
维护者通常 1 天内回复
-
Release Pillow 13.1.0 on January 2, 2027可能已有人在做 @radarhere 今天认领。 未关闭Release
python-pillow/Pillow#10276 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Fix attach SBOM to GitHub release again可能已有人在做 @radarhere 今天认领。 未关闭Release
难度 4/5 3-5 天 新手友好度 48/100
python-pillow/Pillow#10275 · 6 条评论 ·
维护者通常 1 天内回复
查看 python-pillow/Pillow 的全部 Issue
相似的 Issue
-
resource-submission validation-passed
难度 1/5 1 小时以内 新手友好度 88/100
hesreallyhim/awesome-claude-code#3214 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
doobidoo/mcp-memory-service#1650 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 82/100
-
难度 2/5 1-3 小时 新手友好度 76/100
ml-explore/mlx-lm#2002 ·
维护者通常 2 天内回复