Skip to content

Support opening and saving L mode AVIF images with libavif >= 1.3.0 - #9471

Merged
radarhere merged 11 commits into
python-pillow:mainfrom
radarhere:avif_gray
Jun 3, 2026
Merged

Support opening and saving L mode AVIF images with libavif >= 1.3.0#9471
radarhere merged 11 commits into
python-pillow:mainfrom
radarhere:avif_gray

Conversation

@radarhere

@radarhere radarhere commented Mar 18, 2026

Copy link
Copy Markdown
Member

Resolves #9465

If an AVIF image is opened with YUV 4:0:0 subsampling, then it is grayscale, so we can use AVIF_RGB_FORMAT_GRAY, instead of AVIF_RGB_FORMAT_RGB, to load it in L mode rather than RGB. Similarly, if the frame being saved is grayscale, using AVIF_RGB_FORMAT_GRAY simplifies encoding within libavif. However, AVIF_RGB_FORMAT_GRAY only become available in libavif 1.3.0, so this feature is only present for that version. As a side effect, this also means that if an RGB image is saved with 4:0:0 subsampling, it will be in L mode after reopening.

Also, if all frames being saved to an AVIF image are grayscale, then if we default to 4:0:0 subsampling (instead of the current default of 4:2:0), then together, an L mode image can be saved and opened again in the same mode.