mp4_atom/moov/trak/mdia/minf/stbl/stsd/
visual.rs1use 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)?; 0u16.encode(buf)?; self.data_reference_index.encode(buf)?;
37
38 0u32.encode(buf)?; 0u64.encode(buf)?; 0u32.encode(buf)?; self.width.encode(buf)?;
42 self.height.encode(buf)?;
43 self.horizresolution.encode(buf)?;
44 self.vertresolution.encode(buf)?;
45 0u32.encode(buf)?; self.frame_count.encode(buf)?;
47 self.compressor.encode(buf)?;
48 self.depth.encode(buf)?;
49 (-1i16).encode(buf)?; Ok(())
52 }
53}
54impl Decode for Visual {
55 fn decode<B: Buf>(buf: &mut B) -> Result<Self> {
56 u32::decode(buf)?; u16::decode(buf)?; let data_reference_index = u16::decode(buf)?;
59
60 u32::decode(buf)?; u64::decode(buf)?; u32::decode(buf)?; 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)?; let frame_count = u16::decode(buf)?;
69 let compressor = Compressor::decode(buf)?;
70 let depth = u16::decode(buf)?;
71 i16::decode(buf)?; Ok(Self {
74 data_reference_index,
75 width,
76 height,
77 horizresolution,
78 vertresolution,
79 frame_count,
80 compressor,
81 depth,
82 })
83 }
84}