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 <[u8; 6]>::decode(buf)?;
79 let data_reference_index = u16::decode(buf)?;
80
81 <[u8; 16]>::decode(buf)?;
84 let width = u16::decode(buf)?;
85 let height = u16::decode(buf)?;
86 let horizresolution = FixedPoint::decode(buf)?;
87 let vertresolution = FixedPoint::decode(buf)?;
88 u32::decode(buf)?; let frame_count = u16::decode(buf)?;
90 let compressor = Compressor::decode(buf)?;
91 let depth = u16::decode(buf)?;
92 i16::decode(buf)?; Ok(Self {
95 data_reference_index,
96 width,
97 height,
98 horizresolution,
99 vertresolution,
100 frame_count,
101 compressor,
102 depth,
103 })
104 }
105}