mp4_atom/meta/properties/
iscl.rs

1use crate::*;
2
3// ImageScaling, ISO/IEC 23008-12 Section 6.5.13
4// output width and height
5
6#[derive(Debug, Clone, PartialEq, Eq, Default)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub struct Iscl {
9    pub target_width_numerator: u16,
10    pub target_width_denominator: u16,
11    pub target_height_numerator: u16,
12    pub target_height_denominator: u16,
13}
14
15impl AtomExt for Iscl {
16    type Ext = ();
17
18    const KIND_EXT: FourCC = FourCC::new(b"iscl");
19
20    fn decode_body_ext<B: Buf>(buf: &mut B, _ext: ()) -> Result<Self> {
21        let target_width_numerator = u16::decode(buf)?;
22        let target_width_denominator = u16::decode(buf)?;
23        let target_height_numerator = u16::decode(buf)?;
24        let target_height_denominator = u16::decode(buf)?;
25        Ok(Iscl {
26            target_width_numerator,
27            target_width_denominator,
28            target_height_numerator,
29            target_height_denominator,
30        })
31    }
32
33    fn encode_body_ext<B: BufMut>(&self, buf: &mut B) -> Result<()> {
34        self.target_width_numerator.encode(buf)?;
35        self.target_width_denominator.encode(buf)?;
36        self.target_height_numerator.encode(buf)?;
37        self.target_height_denominator.encode(buf)?;
38        Ok(())
39    }
40}
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn test_iscl() {
48        let expected = Iscl {
49            target_width_numerator: 10,
50            target_width_denominator: 3,
51            target_height_numerator: 20,
52            target_height_denominator: 5,
53        };
54        let mut buf = Vec::new();
55        expected.encode(&mut buf).unwrap();
56
57        let mut buf = buf.as_ref();
58        assert_eq!(
59            buf,
60            [0, 0, 0, 20, b'i', b's', b'c', b'l', 0, 0, 0, 0, 0, 0x0a, 0, 0x03, 0, 0x14, 0, 0x05]
61        );
62        let decoded = Iscl::decode(&mut buf).unwrap();
63        assert_eq!(decoded, expected);
64    }
65}