diff options
author | Genny <gen@nyble.dev> | 2021-09-23 20:33:50 -0500 |
---|---|---|
committer | Genny <gen@nyble.dev> | 2021-09-23 20:33:50 -0500 |
commit | 637441239434fabedfe83f5abc1af4232c802f7a (patch) | |
tree | dbc84cd1a31686077fc046fd42d223f1ca08f890 /src/block/extension | |
parent | 7b8081a79fb3db4a76f9e4cca8f8a88e6e7f873c (diff) | |
download | gifed-637441239434fabedfe83f5abc1af4232c802f7a.tar.gz gifed-637441239434fabedfe83f5abc1af4232c802f7a.zip |
Improve API, monocommit, sorry
Diffstat (limited to 'src/block/extension')
-rw-r--r-- | src/block/extension/graphiccontrol.rs | 38 | ||||
-rw-r--r-- | src/block/extension/mod.rs | 7 |
2 files changed, 40 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) + } +} diff --git a/src/block/extension/mod.rs b/src/block/extension/mod.rs index d0e57c6..f328357 100644 --- a/src/block/extension/mod.rs +++ b/src/block/extension/mod.rs @@ -2,6 +2,7 @@ mod application; mod graphiccontrol; pub use graphiccontrol::{DisposalMethod, GraphicControl}; +use owo_colors::colors::xterm::GrandisCaramel; pub use self::application::Application; @@ -41,3 +42,9 @@ impl From<&Extension> for Box<[u8]> { vec.into_boxed_slice() } } + +impl From<GraphicControl> for Extension { + fn from(gce: GraphicControl) -> Self { + Extension::GraphicControl(gce) + } +} |