mp4_atom/meta/properties/
irot.rs

1use crate::*;
2
3// ImageRotation, ISO/IEC 23008-12 Section 6.5.10
4// Image rotation operation (transformative property).
5
6#[derive(Debug, Clone, PartialEq, Eq, Default)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub struct Irot {
9    pub angle: u8,
10}
11
12impl Atom for Irot {
13    const KIND: FourCC = FourCC::new(b"irot");
14
15    fn decode_body<B: Buf>(buf: &mut B) -> Result<Self> {
16        Ok(Irot {
17            angle: u8::decode(buf)? & 0x03,
18        })
19    }
20
21    fn encode_body<B: BufMut>(&self, buf: &mut B) -> Result<()> {
22        self.angle.encode(buf)
23    }
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29
30    #[test]
31    fn test_irot() {
32        let expected = Irot { angle: 3 };
33        let mut buf = Vec::new();
34        expected.encode(&mut buf).unwrap();
35
36        let mut buf = buf.as_ref();
37        assert_eq!(buf, [0, 0, 0, 9, b'i', b'r', b'o', b't', 3]);
38        let decoded = Irot::decode(&mut buf).unwrap();
39        assert_eq!(decoded, expected);
40    }
41}