Skip to main content

zencodec/
orientation.rs

1//! EXIF orientation support.
2//!
3//! [`Orientation`] is re-exported from [`zenpixels`] — the canonical
4//! definition for the zen ecosystem. [`OrientationHint`] is defined here
5//! as codec-layer policy for how decoders should handle orientation.
6
7pub use zenpixels::Orientation;
8
9/// How the decoder should handle orientation during decode.
10///
11/// Replaces a simple `with_orientation_hint(Orientation)` with richer
12/// semantics: the caller can request orientation correction plus
13/// additional transforms, which the decoder can coalesce into a
14/// single operation (e.g., JPEG lossless DCT rotation).
15///
16/// Pass to [`DecodeJob::with_orientation()`](crate::decode::DecodeJob::with_orientation).
17#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
18#[non_exhaustive]
19pub enum OrientationHint {
20    /// Don't touch orientation. Report intrinsic orientation in
21    /// [`ImageInfo::orientation`](crate::ImageInfo).
22    #[default]
23    Preserve,
24
25    /// Resolve EXIF/container orientation to [`Identity`](Orientation::Identity).
26    ///
27    /// The decoder coalesces this with the decode operation when possible
28    /// (e.g., JPEG lossless DCT transform). The output `ImageInfo` will
29    /// report `Orientation::Identity`.
30    Correct,
31
32    /// Resolve EXIF orientation, then apply an additional transform.
33    ///
34    /// The decoder coalesces the combined operation when possible.
35    /// For example, if EXIF says Rotate90 and the hint says Rotate180,
36    /// the decoder applies Rotate270 in a single step.
37    CorrectAndTransform(Orientation),
38
39    /// Ignore EXIF orientation. Apply exactly this transform.
40    ///
41    /// The EXIF orientation is not consulted. The given transform is
42    /// applied literally.
43    ExactTransform(Orientation),
44}
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn orientation_hint_default_is_preserve() {
52        assert_eq!(OrientationHint::default(), OrientationHint::Preserve);
53    }
54
55    #[test]
56    fn orientation_hint_variants() {
57        let _ = OrientationHint::Preserve;
58        let _ = OrientationHint::Correct;
59        let _ = OrientationHint::CorrectAndTransform(Orientation::Rotate90);
60        let _ = OrientationHint::ExactTransform(Orientation::Rotate180);
61    }
62}