Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed ld64 flag #6

Merged
merged 1 commit into from
Dec 7, 2024
Merged

Conversation

radarhere
Copy link

@radarhere radarhere commented Nov 13, 2024

Suggestions for python-pillow#5201

Since you're already adding EXIF data to the saved file with avifImageSetMetadataExif, it would seem unnecessary to also use exif_orientation_to_irot_imir?

I've removed get_modern_cmake, since python-pillow#8497 added python3 -m pip install cmake instead, and the goal of that PR was to try and avoid using brew, which get_modern_cmake does.

I saw that _avif.AvifCodecVersions() was only ever called from the test suite, so I've removed that.

@radarhere
Copy link
Author

@fdintino I don't know if this many commits at once is overwhelming. Feel free to let me know if I should stop until you have a chance to look it over, or if you would prefer bigger PRs than more smaller PRs. Feel free to question my suggestions as well.

@fdintino
Copy link
Owner

fdintino commented Dec 2, 2024

I'll make comments on the individual changes, but as for EXIF: according to the AVIF spec, decoders are meant to ignore EXIF orientation and only use the irot and imir transform flags. This page has two example images, one with EXIF orientation and the other with irot and imir. If you are using a recent version of Safari, Chrome, or Firefox, it should look like this:

Screenshot 2024-12-02 at 11 42 57 AM

We are still setting EXIF metadata because we don't want to lose all of the other EXIF tags that might be present.

Comment on lines -176 to -174
ORIGINAL_LDFLAGS=$LDFLAGS
if [[ -n "$IS_MACOS" ]] && [[ "$CIBW_ARCHS" == "arm64" ]]; then
LDFLAGS="${LDFLAGS} -ld64"
fi
Copy link
Owner

@fdintino fdintino Dec 2, 2024

Choose a reason for hiding this comment

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

I'm a little wary of removing this. It was a workaround for fdintino/pillow-avif-plugin#59. I wrote this comment elsewhere summarizing my findings:

image-rs/image#2108 (comment)

[...] I encountered an illegal instruction issue with libavif that I ultimately diagnosed as a bug in Apple's new(ish) static linker. Stepping through the executable in lldb you could see 4 bytes inserted into the middle of a subroutine that were invalid assembly (so, not even a valid but unsupported ARM intrinsic). If those 4 bytes were removed, the subroutine ran correctly. I noticed that the issue went away if I compiled with -O2; my best guess is that the bug occurs in functions with both inline assembly and C code that clang optimizes with ARM intrinsics (I imagine these are necessary but not sufficient conditions, or else people would be encountering many more corrupt executables). I was able to reliably avoid the issue if I compiled with the old ld64 linker, by adding -ld64 to LDFLAGS.

The test test_aom_optimizations served as a regression test of sorts, and it's no longer failing on macOS ARM. So perhaps the linker bug has since been fixed and we no longer need this flag.

@fdintino
Copy link
Owner

fdintino commented Dec 2, 2024

Everything other than the irot/imir removal and the -ld64 flag removal looks good to me. I'm fine removing the -ld64 flag for now, since I can no longer reproduce it. I'll ask the original bug reporter to try to reproduce it as well. If it recurs, we'll know how to fix it and we can raise it with the libaom project.

@radarhere
Copy link
Author

radarhere commented Dec 3, 2024

It is a problem at the moment that the irot/imir isn't interpreted when opening an image, right? If the EXIF orientation is removed when saving, and changed into irot/imir, then when opening the image, Pillow doesn't know about the irot/imir, so the orientation is lost?

@radarhere radarhere force-pushed the libavif-plugin branch 2 times, most recently from 71000f8 to 8acb134 Compare December 4, 2024 11:36
Comment on lines 154 to 156
-DAVIF_CODEC_AOM=LOCAL \
-DAVIF_CODEC_DAV1D=LOCAL \
-DAVIF_CODEC_SVT=LOCAL \
Copy link
Owner

Choose a reason for hiding this comment

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

This sort of change I think I would rather have in a separate pull request. You are aware that rav1e is only an encoder, and so if we don't include either aom or dav1d, we can't decode AVIF images?

Copy link
Author

Choose a reason for hiding this comment

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

Ah, ok, I missed that libavif was installing the dependencies itself when using "LOCAL".

I've created #7 to use "LOCAL" for rav1e, except on manylinux2014 and aarch64.

@radarhere radarhere changed the title Do not apply EXIF orientation when saving, since EXIF is already saved Removed ld64 flag Dec 4, 2024
@fdintino
Copy link
Owner

fdintino commented Dec 7, 2024

It is a problem at the moment that the irot/imir isn't interpreted when opening an image, right? If the EXIF orientation is removed when saving, and changed into irot/imir, then when opening the image, Pillow doesn't know about the irot/imir, so the orientation is lost?

Yes, this is an oversight. I've attempted to keep all of the same functionality as the avifenc and avifdec CLI applications bundled with libavif and I appear to have overlooked the bit that sets exif in avifdec. I'll add that in.

@fdintino fdintino merged commit de4c6c1 into fdintino:libavif-plugin Dec 7, 2024
22 checks passed
@radarhere radarhere deleted the libavif-plugin branch December 7, 2024 19:08
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.

2 participants