diff options
Diffstat (limited to 'src/block/extension/graphiccontrol.rs')
-rw-r--r-- | src/block/extension/graphiccontrol.rs | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/src/block/extension/graphiccontrol.rs b/src/block/extension/graphiccontrol.rs index 0d4edd1..830dff4 100644 --- a/src/block/extension/graphiccontrol.rs +++ b/src/block/extension/graphiccontrol.rs @@ -1,4 +1,4 @@ -use std::convert::TryInto; +use std::{convert::TryInto, fmt}; #[derive(Clone, Debug)] pub struct GraphicControl { @@ -21,22 +21,36 @@ impl GraphicControl { transparency_index, }; - ret.disposal_method(disposal_method); + ret.set_disposal_method(disposal_method); ret.user_input(user_input_flag); ret.transparency(transparency_flag); ret } - pub fn disposal_method(&mut self, method: DisposalMethod) { + pub fn disposal_method(&self) -> Option<DisposalMethod> { + match self.packed & 0b000_111_00 { + 0b000_000_00 => Some(DisposalMethod::NoAction), + 0b000_100_00 => Some(DisposalMethod::DoNotDispose), + 0b000_010_00 => Some(DisposalMethod::RestoreBackground), + 0b000_110_00 => Some(DisposalMethod::RestorePrevious), + _ => None, + } + } + + pub fn set_disposal_method(&mut self, method: DisposalMethod) { match method { - DisposalMethod::Clear => self.packed &= 0b111_000_1_1, + DisposalMethod::NoAction => self.packed &= 0b111_000_1_1, DisposalMethod::DoNotDispose => self.packed |= 0b000_100_0_0, DisposalMethod::RestoreBackground => self.packed |= 0b000_010_0_0, DisposalMethod::RestorePrevious => self.packed |= 0b000_110_0_0, }; } + pub fn transparency_index(&self) -> u8 { + self.transparency_index + } + pub fn user_input(&mut self, flag: bool) { if flag { self.packed |= 0b000_000_1_0; @@ -78,9 +92,23 @@ impl From<[u8; 4]> for GraphicControl { } } +#[derive(Clone, Copy, Debug, PartialEq)] pub enum DisposalMethod { - Clear, + NoAction, DoNotDispose, RestoreBackground, RestorePrevious, } + +impl fmt::Display for DisposalMethod { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let st = match self { + DisposalMethod::NoAction => "Dispose as Normal", + DisposalMethod::DoNotDispose => "No Dispose", + DisposalMethod::RestoreBackground => "Restore to background", + DisposalMethod::RestorePrevious => "Restore previous image", + }; + + write!(f, "{}", st) + } +} |