Skip to content

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

Open
radarhere wants to merge 5 commits intopython-pillow:mainfrom
radarhere:avif_gray
Open

Support opening and saving L mode AVIF images with libavif >= 1.3.0#9471
radarhere wants to merge 5 commits intopython-pillow:mainfrom
radarhere:avif_gray

Conversation

@radarhere
Copy link
Member

@radarhere radarhere commented Mar 18, 2026

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.

@radarhere radarhere changed the title Support opening and saving L mode AVIF images for libavif >= 1.3.0 Support opening and saving L mode AVIF images with libavif >= 1.3.0 Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support monochrome AVIF saving and loading

1 participant