Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix Exif orientation unwinding#596

Open
AlexQuinlivan wants to merge 4 commits intopinterest:master from
AlexQuinlivan:fix-exif-orientation-unwinding
Open

Fix Exif orientation unwinding #596
AlexQuinlivan wants to merge 4 commits intopinterest:master from
AlexQuinlivan:fix-exif-orientation-unwinding

Conversation

@AlexQuinlivan
Copy link

@AlexQuinlivan AlexQuinlivan commented Apr 16, 2021

Currently, the pin_degreesFromOrientation function that's used when decoding images returns the degrees that represent the Exif orientation. However, the rest of the decode function then applies those values to the already oriented image, causing it to turn the exact wrong way. This affected the normal and mirrored versions of Left and Right.

The change in 6bbf499 addresses this by inverting the returned degrees to be used as a way to unwind the transform that's already applied to the current pixel grid.

Hopefully this is a helpful PR for you, I've made some changes to the base example in 8fb0458 that allow for you to swap out the data source used. At 8fb0458 you can see the issue for the affected orientations, then by 6bbf499 they should all look correct.

...image represents 0 rotation
When converting degrees to radians we want to reverse the degrees calculated
from the image orientation as they represent the current transformation that is
baked into the image. When applying the inverse transform, we will receive an
image that represents UIImageOrientationUp
Copy link
Collaborator

Would you mind adding a test which fails and is fixed by this PR?

Copy link
Author

@garrettmoon sure thing, will get around to shortly

Copy link
Author

@garrettmoon hopefully this test in 2b1b06a is sufficient. It creates a pixel grid and applies certain pixel layouts. It then runs it through the decode function to receive an image with up orientation. Fails on the four horizontal images when you revert 8fb0458, so that's good I guess.

I also found another interesting bug along the way. UIGraphicsImageRenderer would handle CGFloats like 2.0000000004 by rounding up its output pixels to 3. So there's an extra commit in here that feeds it the correctly flipped image size, sans transform application. (Was picked up in the comparison of PNG data, took me a while to see the extra size...)

Copy link
Author

@garrettmoon Hey mate, have you had a chance to look over any of this?

Copy link

Thank you, this works like a charm! I wonder why it hasn't got merged yet.

mikengyn reacted with heart emoji

Copy link
Author

@JunyuKuang no idea. But I've been running this in production now for two years with success.

JunyuKuang and mikengyn reacted with thumbs up emoji

Copy link

This fixed an issue I was dealing with. Thank you!

Copy link

Running this fix in production, and it's working great 👌 would love to see it merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Comments

AltStyle によって変換されたページ (->オリジナル) /