Refactor options presets
This commit is contained in:
parent
88f5bb0931
commit
d204427f73
3 changed files with 122 additions and 102 deletions
|
|
@ -3,6 +3,7 @@
|
|||
- Hide all modules from documentation, and only export the specific structures that should be public.
|
||||
Previously there were too many implementation details made public. The modules are still public for the purposes of our integration tests,
|
||||
but we strongly advice against using undocumented modules. These may become private in the future.
|
||||
- Internal refactoring and code cleanup
|
||||
|
||||
### Version 0.18.3
|
||||
- Return exit code of 1 if an error occurred while processing a file using the CLI app ([#93](https://github.com/shssoichiro/oxipng/issues/93))
|
||||
|
|
|
|||
221
src/lib.rs
221
src/lib.rs
|
|
@ -130,109 +130,128 @@ pub struct Options {
|
|||
|
||||
impl Options {
|
||||
pub fn from_preset(level: u8) -> Options {
|
||||
let mut opts = Options::default();
|
||||
let opts = Options::default();
|
||||
match level {
|
||||
0 => {
|
||||
opts.idat_recoding = false;
|
||||
let mut compression = HashSet::new();
|
||||
compression.insert(3);
|
||||
opts.compression = compression;
|
||||
}
|
||||
1 => {
|
||||
let filter = HashSet::new();
|
||||
opts.filter = filter;
|
||||
let strategies = HashSet::new();
|
||||
opts.strategies = strategies;
|
||||
opts.use_heuristics = true;
|
||||
}
|
||||
// 2 is the default
|
||||
3 => {
|
||||
let mut filter = HashSet::new();
|
||||
filter.insert(0);
|
||||
filter.insert(5);
|
||||
opts.filter = filter;
|
||||
let mut compression = HashSet::new();
|
||||
compression.insert(9);
|
||||
opts.compression = compression;
|
||||
let mut memory = HashSet::new();
|
||||
for i in 8..10 {
|
||||
memory.insert(i);
|
||||
}
|
||||
opts.memory = memory;
|
||||
let mut strategies = HashSet::new();
|
||||
for i in 0..4 {
|
||||
strategies.insert(i);
|
||||
}
|
||||
opts.strategies = strategies;
|
||||
}
|
||||
4 => {
|
||||
let mut filter = HashSet::new();
|
||||
for i in 0..6 {
|
||||
filter.insert(i);
|
||||
}
|
||||
opts.filter = filter;
|
||||
let mut compression = HashSet::new();
|
||||
compression.insert(9);
|
||||
opts.compression = compression;
|
||||
let mut memory = HashSet::new();
|
||||
for i in 8..10 {
|
||||
memory.insert(i);
|
||||
}
|
||||
opts.memory = memory;
|
||||
let mut strategies = HashSet::new();
|
||||
for i in 0..4 {
|
||||
strategies.insert(i);
|
||||
}
|
||||
opts.strategies = strategies;
|
||||
}
|
||||
5 => {
|
||||
let mut filter = HashSet::new();
|
||||
for i in 0..6 {
|
||||
filter.insert(i);
|
||||
}
|
||||
opts.filter = filter;
|
||||
let mut compression = HashSet::new();
|
||||
for i in 3..10 {
|
||||
compression.insert(i);
|
||||
}
|
||||
opts.compression = compression;
|
||||
let mut memory = HashSet::new();
|
||||
for i in 8..10 {
|
||||
memory.insert(i);
|
||||
}
|
||||
opts.memory = memory;
|
||||
let mut strategies = HashSet::new();
|
||||
for i in 0..4 {
|
||||
strategies.insert(i);
|
||||
}
|
||||
opts.strategies = strategies;
|
||||
}
|
||||
// Level 6
|
||||
// If higher than 6, assume 6
|
||||
_ => {
|
||||
let mut filter = HashSet::new();
|
||||
for i in 0..6 {
|
||||
filter.insert(i);
|
||||
}
|
||||
opts.filter = filter;
|
||||
let mut compression = HashSet::new();
|
||||
for i in 1..10 {
|
||||
compression.insert(i);
|
||||
}
|
||||
opts.compression = compression;
|
||||
let mut memory = HashSet::new();
|
||||
for i in 7..10 {
|
||||
memory.insert(i);
|
||||
}
|
||||
opts.memory = memory;
|
||||
let mut strategies = HashSet::new();
|
||||
for i in 0..4 {
|
||||
strategies.insert(i);
|
||||
}
|
||||
opts.strategies = strategies;
|
||||
}
|
||||
0 => opts.apply_preset_0(),
|
||||
1 => opts.apply_preset_1(),
|
||||
2 => opts.apply_preset_2(),
|
||||
3 => opts.apply_preset_3(),
|
||||
4 => opts.apply_preset_4(),
|
||||
5 => opts.apply_preset_5(),
|
||||
_ => opts.apply_preset_6(),
|
||||
}
|
||||
opts
|
||||
}
|
||||
|
||||
fn apply_preset_0(mut self) -> Self {
|
||||
self.idat_recoding = false;
|
||||
let mut compression = HashSet::new();
|
||||
compression.insert(3);
|
||||
self.compression = compression;
|
||||
self
|
||||
}
|
||||
|
||||
fn apply_preset_1(mut self) -> Self {
|
||||
let filter = HashSet::new();
|
||||
self.filter = filter;
|
||||
let strategies = HashSet::new();
|
||||
self.strategies = strategies;
|
||||
self.use_heuristics = true;
|
||||
self
|
||||
}
|
||||
|
||||
fn apply_preset_2(self) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
fn apply_preset_3(mut self) -> Self {
|
||||
let mut filter = HashSet::new();
|
||||
filter.insert(0);
|
||||
filter.insert(5);
|
||||
self.filter = filter;
|
||||
let mut compression = HashSet::new();
|
||||
compression.insert(9);
|
||||
self.compression = compression;
|
||||
let mut memory = HashSet::new();
|
||||
for i in 8..10 {
|
||||
memory.insert(i);
|
||||
}
|
||||
self.memory = memory;
|
||||
let mut strategies = HashSet::new();
|
||||
for i in 0..4 {
|
||||
strategies.insert(i);
|
||||
}
|
||||
self.strategies = strategies;
|
||||
self
|
||||
}
|
||||
|
||||
fn apply_preset_4(mut self) -> Self {
|
||||
let mut filter = HashSet::new();
|
||||
for i in 0..6 {
|
||||
filter.insert(i);
|
||||
}
|
||||
self.filter = filter;
|
||||
let mut compression = HashSet::new();
|
||||
compression.insert(9);
|
||||
self.compression = compression;
|
||||
let mut memory = HashSet::new();
|
||||
for i in 8..10 {
|
||||
memory.insert(i);
|
||||
}
|
||||
self.memory = memory;
|
||||
let mut strategies = HashSet::new();
|
||||
for i in 0..4 {
|
||||
strategies.insert(i);
|
||||
}
|
||||
self.strategies = strategies;
|
||||
self
|
||||
}
|
||||
|
||||
fn apply_preset_5(mut self) -> Self {
|
||||
let mut filter = HashSet::new();
|
||||
for i in 0..6 {
|
||||
filter.insert(i);
|
||||
}
|
||||
self.filter = filter;
|
||||
let mut compression = HashSet::new();
|
||||
for i in 3..10 {
|
||||
compression.insert(i);
|
||||
}
|
||||
self.compression = compression;
|
||||
let mut memory = HashSet::new();
|
||||
for i in 8..10 {
|
||||
memory.insert(i);
|
||||
}
|
||||
self.memory = memory;
|
||||
let mut strategies = HashSet::new();
|
||||
for i in 0..4 {
|
||||
strategies.insert(i);
|
||||
}
|
||||
self.strategies = strategies;
|
||||
self
|
||||
}
|
||||
|
||||
fn apply_preset_6(mut self) -> Self {
|
||||
let mut filter = HashSet::new();
|
||||
for i in 0..6 {
|
||||
filter.insert(i);
|
||||
}
|
||||
self.filter = filter;
|
||||
let mut compression = HashSet::new();
|
||||
for i in 1..10 {
|
||||
compression.insert(i);
|
||||
}
|
||||
self.compression = compression;
|
||||
let mut memory = HashSet::new();
|
||||
for i in 7..10 {
|
||||
memory.insert(i);
|
||||
}
|
||||
self.memory = memory;
|
||||
let mut strategies = HashSet::new();
|
||||
for i in 0..4 {
|
||||
strategies.insert(i);
|
||||
}
|
||||
self.strategies = strategies;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ pub struct PngData {
|
|||
impl PngData {
|
||||
/// Create a new `PngData` struct by opening a file
|
||||
#[inline]
|
||||
#[cfg(test)]
|
||||
#[allow(dead_code)]
|
||||
pub fn new(filepath: &Path, fix_errors: bool) -> Result<PngData, PngError> {
|
||||
let byte_data = PngData::read_file(filepath)?;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue