Skip to main content

libbitsub_core/pgs/
segment.rs

1//! PGS segment types and identifiers.
2
3/// Segment type identifiers as defined in the PGS specification.
4#[repr(u8)]
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum SegmentType {
7    /// Palette Definition Segment (0x14)
8    PaletteDefinition = 0x14,
9    /// Object Definition Segment (0x15)
10    ObjectDefinition = 0x15,
11    /// Presentation Composition Segment (0x16)
12    PresentationComposition = 0x16,
13    /// Window Definition Segment (0x17)
14    WindowDefinition = 0x17,
15    /// End Segment (0x80)
16    End = 0x80,
17}
18
19impl TryFrom<u8> for SegmentType {
20    type Error = u8;
21
22    fn try_from(value: u8) -> Result<Self, Self::Error> {
23        match value {
24            0x14 => Ok(SegmentType::PaletteDefinition),
25            0x15 => Ok(SegmentType::ObjectDefinition),
26            0x16 => Ok(SegmentType::PresentationComposition),
27            0x17 => Ok(SegmentType::WindowDefinition),
28            0x80 => Ok(SegmentType::End),
29            _ => Err(value),
30        }
31    }
32}
33
34/// Composition state indicates how the display set should be processed.
35#[repr(u8)]
36#[derive(Debug, Clone, Copy, PartialEq, Eq)]
37pub enum CompositionState {
38    /// Normal update - can use previous display set data
39    Normal = 0x00,
40    /// Acquisition point - new display set boundary
41    AcquisitionPoint = 0x40,
42    /// Epoch start - complete reset of decoder state
43    EpochStart = 0x80,
44}
45
46impl TryFrom<u8> for CompositionState {
47    type Error = u8;
48
49    fn try_from(value: u8) -> Result<Self, Self::Error> {
50        match value {
51            0x00 => Ok(CompositionState::Normal),
52            0x40 => Ok(CompositionState::AcquisitionPoint),
53            0x80 => Ok(CompositionState::EpochStart),
54            _ => Err(value),
55        }
56    }
57}