-
Notifications
You must be signed in to change notification settings - Fork 618
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
Add a function to apply Exif rotation #2299
Conversation
I still think that rotations and flips are image processing operations and as such belong in |
@ripytide it doesn't really make sense to move it to |
So I think there are two main use-cases in play here:
For the first use-case, It makes the most sense to me for users to look in a single location for operations that process/modify images such as rotating/flipping images, hence I would expect as a user to look in the For the second use-case I can see why it is incompatible with the above solution to the first use-case since if the rotate/flip functions were located in the
I think this is a bit of a problem, and the root cause is the grouping of multiple functionalities in the
The circular dependency above is due to the fact that
I think this is called tight/loose coupling Perhaps we should treat the root cause of the issue and split the |
Oh I've just found the #793 issue, that would have saved me some typing regarding the crate splitting 😄 |
…for applying orientation
@fintelia I've updated the code based on your feedback. Does that look good? I wasn't quite sure where to put the |
@fintelia I've addressed all the feedback. All good points, thank you! Sorry it took so long. Somehow I was convinced I've already done it, I must have dreamt it or something 😅 |
There are some |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left two comments on naming. Otherwise looks good to me
src/orientation.rs
Outdated
/// Flip vertically. Can be performed in-place. | ||
FlipVertical, | ||
/// Rotate by 90 degrees clockwise and flip horizontally. | ||
Rotate90FlipH, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a bit long, but perhaps Rotate90FlipHorizontal
for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that, and my eyes just glaze over when I try to read it. I genuinely believe this option is more readable.
And if its meaning is ever unclear, there is always the doc comment.
src/orientation.rs
Outdated
/// Rotate by 90 degrees clockwise and flip horizontally. | ||
Rotate90FlipH, | ||
/// Rotate by 270 degrees clockwise and flip horizontally. | ||
Rotate270FlipH, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rotate270FlipHorizontal
?
Actually, I wonder if we should create a new |
I've renamed the module to I've also added a function to convert back into Exif and added a doc link from |
This is required to display JPEG photos correctly.
Doesn't wire it up to the JPEG decoding process yet, because that would be a semver-breaking change. But at least provides all the pieces for an API user to apply the correct rotation, together with #2291
Depends on #2292
Why this API?
A common case for a JPEG image is not to be rotated at all, i.e. have the orientation value of 1. Therefore we do not want to unconditionally make a copy of the image - often it is just a no-op. We need to do this in place.
Sadly nobody has implemented in-place 90 and 270 degree rotation yet (see #2294), so we are forced to make a copy in some cases. This copying behavior prevents us from implementing this in imageops module, which is generic over the input and so we cannot use the "replace the input with a copy" trick there.
So there are two options:
Result<Option<GenericImage>>
and make the caller deal with itThis PR picks the second option.