Move default Options into impl Default in library
This commit is contained in:
parent
05f0e69e98
commit
e4cd9b85e7
3 changed files with 47 additions and 41 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
**Version 0.6.1 (unreleased)**
|
**Version 0.7.0 (unreleased)**
|
||||||
- Minor compression improvement on interlaced images
|
- Minor compression improvement on interlaced images
|
||||||
- Performance optimizations
|
- Performance optimizations
|
||||||
|
- [SEMVER_MINOR] Move default Options into a Default impl
|
||||||
|
|
||||||
**Version 0.6.0**
|
**Version 0.6.0**
|
||||||
- Fix issue where output directory would not be created if it did not exist
|
- Fix issue where output directory would not be created if it did not exist
|
||||||
|
|
|
||||||
44
src/lib.rs
44
src/lib.rs
|
|
@ -81,6 +81,50 @@ pub struct Options {
|
||||||
pub use_heuristics: bool,
|
pub use_heuristics: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Options {
|
||||||
|
fn default() -> Options {
|
||||||
|
// Default settings based on -o 2 from the CLI interface
|
||||||
|
let mut filter = HashSet::new();
|
||||||
|
filter.insert(0);
|
||||||
|
filter.insert(5);
|
||||||
|
let mut compression = HashSet::new();
|
||||||
|
compression.insert(9);
|
||||||
|
let mut memory = HashSet::new();
|
||||||
|
memory.insert(9);
|
||||||
|
let mut strategies = HashSet::new();
|
||||||
|
for i in 0..4 {
|
||||||
|
strategies.insert(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
Options {
|
||||||
|
backup: false,
|
||||||
|
out_file: PathBuf::new(),
|
||||||
|
out_dir: None,
|
||||||
|
stdout: false,
|
||||||
|
pretend: false,
|
||||||
|
recursive: false,
|
||||||
|
fix_errors: false,
|
||||||
|
clobber: true,
|
||||||
|
create: true,
|
||||||
|
force: false,
|
||||||
|
preserve_attrs: false,
|
||||||
|
verbosity: Some(0),
|
||||||
|
filter: filter,
|
||||||
|
interlace: None,
|
||||||
|
compression: compression,
|
||||||
|
memory: memory,
|
||||||
|
strategies: strategies,
|
||||||
|
window: 15,
|
||||||
|
bit_depth_reduction: true,
|
||||||
|
color_type_reduction: true,
|
||||||
|
palette_reduction: true,
|
||||||
|
idat_recoding: true,
|
||||||
|
strip: png::Headers::None,
|
||||||
|
use_heuristics: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Perform optimization on the input file using the options provided
|
/// Perform optimization on the input file using the options provided
|
||||||
pub fn optimize(filepath: &Path, opts: &Options) -> Result<(), String> {
|
pub fn optimize(filepath: &Path, opts: &Options) -> Result<(), String> {
|
||||||
type TrialWithData = (u8, u8, u8, u8, Vec<u8>);
|
type TrialWithData = (u8, u8, u8, u8, Vec<u8>);
|
||||||
|
|
|
||||||
41
src/main.rs
41
src/main.rs
|
|
@ -13,45 +13,6 @@ use std::path::PathBuf;
|
||||||
const VERSION_STRING: &'static str = "0.6.0";
|
const VERSION_STRING: &'static str = "0.6.0";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut filter = HashSet::new();
|
|
||||||
filter.insert(0);
|
|
||||||
filter.insert(5);
|
|
||||||
let mut compression = HashSet::new();
|
|
||||||
compression.insert(9);
|
|
||||||
let mut memory = HashSet::new();
|
|
||||||
memory.insert(9);
|
|
||||||
let mut strategies = HashSet::new();
|
|
||||||
for i in 0..4 {
|
|
||||||
strategies.insert(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
let default_opts = oxipng::Options {
|
|
||||||
backup: false,
|
|
||||||
out_file: PathBuf::new(),
|
|
||||||
out_dir: None,
|
|
||||||
stdout: false,
|
|
||||||
pretend: false,
|
|
||||||
recursive: false,
|
|
||||||
fix_errors: false,
|
|
||||||
clobber: true,
|
|
||||||
create: true,
|
|
||||||
force: false,
|
|
||||||
preserve_attrs: false,
|
|
||||||
verbosity: Some(0),
|
|
||||||
filter: filter,
|
|
||||||
interlace: None,
|
|
||||||
compression: compression,
|
|
||||||
memory: memory,
|
|
||||||
strategies: strategies,
|
|
||||||
window: 15,
|
|
||||||
bit_depth_reduction: true,
|
|
||||||
color_type_reduction: true,
|
|
||||||
palette_reduction: true,
|
|
||||||
idat_recoding: true,
|
|
||||||
strip: png::Headers::None,
|
|
||||||
use_heuristics: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
let matches =
|
let matches =
|
||||||
App::new("oxipng")
|
App::new("oxipng")
|
||||||
.version(VERSION_STRING)
|
.version(VERSION_STRING)
|
||||||
|
|
@ -228,7 +189,7 @@ fn main() {
|
||||||
regardless of the order you write the arguments.")
|
regardless of the order you write the arguments.")
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let mut opts = default_opts;
|
let mut opts = oxipng::Options::default();
|
||||||
|
|
||||||
match parse_opts_into_struct(&matches, &mut opts) {
|
match parse_opts_into_struct(&matches, &mut opts) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue