Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Saving grayscale images as AVIF fails with libavif older than 1.3.0

已关闭
#10,262 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

已经有一个关联 PR 被合并了。

  • #10263 来自 @lazerg —— 已合并

评估

难度
3/5
预计耗时
半天
新手友好度
65/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
c, python
领域
backend, data

调研方向

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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

python-pillow/Pillow 的其他 Issue

查看 python-pillow/Pillow 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。