mp4_atom/moov/trak/mdia/minf/stbl/stsd/
visual.rs

1use crate::coding::{Decode, Encode};
2use crate::{Buf, BufMut, Compressor, FixedPoint, Result};
3
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct Visual {
7    pub data_reference_index: u16,
8    pub width: u16,
9    pub height: u16,
10    pub horizresolution: FixedPoint<u16>,
11    pub vertresolution: FixedPoint<u16>,
12    pub frame_count: u16,
13    pub compressor: Compressor,
14    pub depth: u16,
15}
16
17impl Default for Visual {
18    fn default() -> Self {
19        Self {
20            data_reference_index: 0,
21            width: 0,
22            height: 0,
23            horizresolution: 0x48.into(),
24            vertresolution: 0x48.into(),
25            frame_count: 1,
26            compressor: Default::default(),
27            depth: 0x0018,
28        }
29    }
30}
31
32impl Encode for Visual {
33    fn encode<B: BufMut>(&self, buf: &mut B) -> Result<()> {
34        0u32.encode(buf)?; // reserved
35        0u16.encode(buf)?; // reserved
36        self.data_reference_index.encode(buf)?;
37
38        0u32.encode(buf)?; // pre-defined, reserved
39        0u64.encode(buf)?; // pre-defined
40        0u32.encode(buf)?; // pre-defined
41        self.width.encode(buf)?;
42        self.height.encode(buf)?;
43        self.horizresolution.encode(buf)?;
44        self.vertresolution.encode(buf)?;
45        0u32.encode(buf)?; // reserved
46        self.frame_count.encode(buf)?;
47        self.compressor.encode(buf)?;
48        self.depth.encode(buf)?;
49        (-1i16).encode(buf)?; // pre-defined
50
51        Ok(())
52    }
53}
54impl Decode for Visual {
55    fn decode<B: Buf>(buf: &mut B) -> Result<Self> {
56        u32::decode(buf)?; // reserved
57        u16::decode(buf)?; // reserved
58        let data_reference_index = u16::decode(buf)?;
59
60        u32::decode(buf)?; // pre-defined, reserved
61        u64::decode(buf)?; // pre-defined
62        u32::decode(buf)?; // pre-defined
63        let width = u16::decode(buf)?;
64        let height = u16::decode(buf)?;
65        let horizresolution = FixedPoint::decode(buf)?;
66        let vertresolution = FixedPoint::decode(buf)?;
67        u32::decode(buf)?; // reserved
68        let frame_count = u16::decode(buf)?;
69        let compressor = Compressor::decode(buf)?;
70        let depth = u16::decode(buf)?;
71        i16::decode(buf)?; // pre-defined
72
73        Ok(Self {
74            data_reference_index,
75            width,
76            height,
77            horizresolution,
78            vertresolution,
79            frame_count,
80            compressor,
81            depth,
82        })
83    }
84}