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

Add a function to check if Orientation can be applied in-place #2329

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,23 @@ impl Orientation {
Self::Rotate270 => 8,
}
}

/// Returns `true` if the specified orientation can be applied to an image in-place,
/// without making a copy of the image.
///
/// This is relevant if you need to enforce a memory limit,
/// since a copy of the image will briefly use additional memory to store the copy.
/// The required amount of additional memory is the same as the memory used to store the original image.
pub fn applies_in_place(self) -> bool {
match self {
Orientation::NoTransforms => true,
Orientation::Rotate90 => false,
Orientation::Rotate180 => true,
Orientation::Rotate270 => false,
Orientation::FlipHorizontal => true,
Orientation::FlipVertical => true,
Orientation::Rotate90FlipH => false,
Orientation::Rotate270FlipH => false,
}
}
}
Loading