core: support DeflateMode option setting
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 22 May 2021 10:24:05 +0000 (12:24 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 22 May 2021 10:24:05 +0000 (12:24 +0200)
nihav-core/src/compr/deflate.rs
nihav-core/src/options.rs

index 3a3819ef2eb4bea191ed55e7fe985f0c44b1b793..91207891a83a83b760485101db125f3ee98d78e0 100644 (file)
@@ -71,6 +71,7 @@
 //! # }
 //! ```
 
+use crate::options::NAOptionDefinitionType;
 use crate::io::byteio::*;
 use crate::io::bitreader::*;
 use crate::io::codebook::*;
@@ -1721,6 +1722,48 @@ pub enum DeflateMode {
     Best,
 }
 
+impl Default for DeflateMode {
+    fn default() -> Self { DeflateMode::Better }
+}
+
+pub const DEFLATE_MODE_DESCRIPTION: &str = "Deflate compression level.";
+///! Deflate option for no compression.
+pub const DEFLATE_MODE_NONE: &str = "none";
+///! Deflate option for fast compression.
+pub const DEFLATE_MODE_FAST: &str = "fast";
+///! Deflate option for better compression.
+pub const DEFLATE_MODE_BETTER: &str = "better";
+///! Deflate option for best compression.
+pub const DEFLATE_MODE_BEST: &str = "best";
+
+///! All possible option values for deflate compression.
+pub const DEFLATE_OPTION_VALUES: NAOptionDefinitionType = NAOptionDefinitionType::String(Some(&[DEFLATE_MODE_NONE, DEFLATE_MODE_FAST, DEFLATE_MODE_BETTER, DEFLATE_MODE_BEST]));
+
+impl std::str::FromStr for DeflateMode {
+    type Err = ();
+
+    fn from_str(s: &str) -> Result<Self, Self::Err> {
+        match s {
+            DEFLATE_MODE_NONE   => Ok(DeflateMode::NoCompr),
+            DEFLATE_MODE_FAST   => Ok(DeflateMode::Fast),
+            DEFLATE_MODE_BETTER => Ok(DeflateMode::Better),
+            DEFLATE_MODE_BEST   => Ok(DeflateMode::Best),
+            _ => Err(()),
+        }
+    }
+}
+
+impl ToString for DeflateMode {
+    fn to_string(&self) -> String {
+        match *self {
+            DeflateMode::NoCompr    => DEFLATE_MODE_NONE.to_string(),
+            DeflateMode::Fast       => DEFLATE_MODE_FAST.to_string(),
+            DeflateMode::Better     => DEFLATE_MODE_BETTER.to_string(),
+            DeflateMode::Best       => DEFLATE_MODE_BEST.to_string(),
+        }
+    }
+}
+
 #[derive(Clone,Copy,Debug,PartialEq)]
 enum Mode {
     Copy,
index 96e093e4f95976a564d979d42b3fe6d06c5ea3e4..d3d8be889ccceae1ea06b33f27133af522e6d044 100644 (file)
@@ -8,6 +8,8 @@
 use std::sync::Arc;
 use std::fmt;
 
+pub use crate::compr::deflate::{DEFLATE_MODE_DESCRIPTION, DEFLATE_OPTION_VALUES, DEFLATE_MODE_NONE, DEFLATE_MODE_FAST, DEFLATE_MODE_BETTER, DEFLATE_MODE_BEST};
+
 /// Common name for keyframe interval option.
 pub const KEYFRAME_OPTION: &str = "key_int";
 /// Common description for keyframe interval option.