Skip to content

Fixed conversion of AVIF image rotation property to EXIF orientation#8866

Merged
hugovk merged 2 commits into
python-pillow:mainfrom
fdintino:fix/avif-decode-irot-imir-exif
Apr 4, 2025
Merged

Fixed conversion of AVIF image rotation property to EXIF orientation#8866
hugovk merged 2 commits into
python-pillow:mainfrom
fdintino:fix/avif-decode-irot-imir-exif

Conversation

@fdintino

@fdintino fdintino commented Apr 3, 2025

Copy link
Copy Markdown
Contributor

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.

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.
@radarhere

Copy link
Copy Markdown
Member

Would it be possible to add a test?

@fdintino

fdintino commented Apr 3, 2025

Copy link
Copy Markdown
Contributor Author

Oh, of course. Yes, I'll add one.

Comment thread Tests/test_file_avif.py
if orientation == 1:
assert "exif" not in reloaded.info
else:
assert reloaded.getexif()[274] == orientation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion fails before this change for orientations 6 and 8.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can include this new assertion if you like, but actually, the next line

assert reloaded.info["exif"] == exif_data

already fails with the new parameters. This is because the next line is checking the full EXIF data, not just the orientation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 radarhere changed the title fix: conversion of AVIF image rotation property to EXIF orientation Fixed conversion of AVIF image rotation property to EXIF orientation Apr 3, 2025
@hugovk
hugovk merged commit 9f654ff into python-pillow:main Apr 4, 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.
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.

3 participants