Fixed conversion of AVIF image rotation property to EXIF orientation#8866
Merged
hugovk merged 2 commits intoApr 4, 2025
Merged
Conversation
This implements a fix for the issue identified in AOMediaCodec/libavif#2727 and fixed in AOMediaCodec/libavif#2729. The code to convert irot and imir properties to EXIF orientation when decoding AVIF images in Pillow was repurposed from libavif, so it suffers the same bug.
Member
|
Would it be possible to add a test? |
Contributor
Author
|
Oh, of course. Yes, I'll add one. |
fdintino
commented
Apr 3, 2025
| if orientation == 1: | ||
| assert "exif" not in reloaded.info | ||
| else: | ||
| assert reloaded.getexif()[274] == orientation |
Contributor
Author
There was a problem hiding this comment.
This assertion fails before this change for orientations 6 and 8.
Member
There was a problem hiding this comment.
We can include this new assertion if you like, but actually, the next line
assert reloaded.info["exif"] == exif_dataalready fails with the new parameters. This is because the next line is checking the full EXIF data, not just the orientation.
Contributor
Author
There was a problem hiding this comment.
I realize they're redundant, but it was a bit obscure identifying the mismatch with the bytes, so I thought this more specific assertion might be more diagnostic of failures
radarhere
approved these changes
Apr 3, 2025
fdintino
added a commit
to fdintino/pillow-avif-plugin
that referenced
this pull request
Jul 20, 2026
- **Added**: Native grayscale (mode `L`) support when built against
libavif 1.3.0 or greater: images with 4:0:0 subsampling now load in
`L` mode instead of `RGB`, and grayscale images are encoded with
`AVIF_RGB_FORMAT_GRAY`, defaulting to 4:0:0 subsampling. Ported from
Pillow [#9471](python-pillow/Pillow#9471).
- **Added**: `AvifImagePlugin.get_codec_version()` helper and
`_avif.codec_versions` (alias of `_avif.AvifCodecVersions`),
matching Pillow.
- **Fixed**: Conversion of the AVIF rotation property (`irot`) to EXIF
orientation swapped 90° and 270° rotations (Pillow
[#8866](python-pillow/Pillow#8866)).
- **Fixed**: When saving, an EXIF Orientation tag is now removed from
the EXIF payload and stored as `irot`/`imir` transformations instead
of being written in both places.
- **Fixed**: `AvifEncoder` and `AvifDecoder` objects were never freed,
leaking memory with every encode/decode (Pillow
[#9501](python-pillow/Pillow#9501)).
- **Fixed**: Incorrect error check after creating an image frame while
encoding an animation (Pillow
[#9442](python-pillow/Pillow#9442)), missing
NULL dereference checks and a pixel buffer leak on an error path
(Pillow [#9489](python-pillow/Pillow#9489)).
- **Fixed**: Compilation against libavif 0.8.x and 0.9.0/0.9.1
(`avifImageMirror` member name handling).
- **CI**: Update libavif to **1.4.2**. See the table below for all
AVIF codec versions in this release.
- **CI**: Pin the manylinux2014 image used for Python 3.8 wheels to
the last tag that still includes CPython 3.8, and pin `cmake==4.0.3`
for musllinux_1_1 builds (the last release with musllinux_1_1
wheels).
- **CI**: Fix the manylinux2010 build, where libavif 1.4.x's
`src/io.c` uses the C11 `static_assert` macro that el6's glibc
(2.12) does not define in `<assert.h>`, by mapping it to the
compiler's `_Static_assert` keyword for C sources.
- **CI**: Skip installing test dependencies for free-threaded Python
3.13 wheels on macOS and Windows, since Pillow no longer publishes
`cp313t` wheels.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This implements a fix for the issue identified in AOMediaCodec/libavif#2727 and fixed in AOMediaCodec/libavif#2729. The code in Pillow that converts irot and imir properties to EXIF orientation was repurposed from libavif, so it suffers the same bug.