From c54872f011c135bbbc963f4a2b6b1d8ee4fa92bc Mon Sep 17 00:00:00 2001 From: Genny Date: Fri, 6 Nov 2020 23:33:01 -0600 Subject: Add gif components --- src/components/logicalscreendescriptor.rs | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/components/logicalscreendescriptor.rs (limited to 'src/components/logicalscreendescriptor.rs') diff --git a/src/components/logicalscreendescriptor.rs b/src/components/logicalscreendescriptor.rs new file mode 100644 index 0000000..b20c9d5 --- /dev/null +++ b/src/components/logicalscreendescriptor.rs @@ -0,0 +1,40 @@ +pub struct LogicalScreenDescriptor { + pub width: u16, + pub height: u16, + pub packed: u8, + pub background_color_index: u8, + pub pixel_aspect_ratio: u8 +} + +impl LogicalScreenDescriptor { + pub fn color_table_present(&mut self, is_present: bool) { + if is_present { + self.packed |= 0b1000_0000; + } else { + self.packed &= 0b0111_1111; + } + } + + pub fn color_table_size(&mut self, size: u8) { + // GCT size is calulated by raising two to this number plus one, + // so we have to work backwards. + let size = (size as f32).log2().ceil() - 1f32; + self.packed |= size as u8; + } + + //TODO: Setter for sort flag in packed field + //TODO: Setter for color resolution in packed field +} + +impl From<&LogicalScreenDescriptor> for Box<[u8]> { + fn from(lsd: &LogicalScreenDescriptor) -> Self { + let mut vec = vec![]; + vec.extend_from_slice(&lsd.width.to_le_bytes()); + vec.extend_from_slice(&lsd.height.to_le_bytes()); + vec.push(lsd.packed); + vec.push(lsd.background_color_index); + vec.push(lsd.pixel_aspect_ratio); + + vec.into_boxed_slice() + } +} \ No newline at end of file -- cgit 1.4.1-3-g733a5