Fix swww restore error handling

This commit is contained in:
kerty
2024-10-27 19:16:19 +03:00
parent 716c489ae1
commit fb45d816f2
3 changed files with 33 additions and 26 deletions

View File

@@ -83,8 +83,7 @@ impl Display for Filter {
Self::CatmullRom => "CatmullRom",
Self::Mitchell => "Mitchell",
Self::Lanczos3 => "Lanczos3",
}
.to_string();
};
write!(f, "{}", str)
}
}

View File

@@ -270,32 +270,40 @@ fn restore_from_cache(requested_outputs: &[String]) -> Result<(), String> {
let (_, _, outputs) = get_format_dims_and_outputs(requested_outputs)?;
for output in outputs.iter().flatten() {
let (filter, img_path) = common::cache::get_previous_image_path(output)
.map_err(|e| format!("failed to get previous image path: {e}"))?;
#[allow(deprecated)]
if let Err(e) = process_swww_args(&Swww::Img(cli::Img {
image: cli::parse_image(&img_path)?,
outputs: output.to_string(),
no_resize: false,
resize: ResizeStrategy::Crop,
fill_color: [0, 0, 0],
filter: Filter::from_str(&filter).unwrap_or(Filter::Lanczos3),
transition_type: cli::TransitionType::None,
transition_step: std::num::NonZeroU8::MAX,
transition_duration: 0.0,
transition_fps: 30,
transition_angle: 0.0,
transition_pos: cli::CliPosition {
x: cli::CliCoord::Pixel(0.0),
y: cli::CliCoord::Pixel(0.0),
},
invert_y: false,
transition_bezier: (0.0, 0.0, 0.0, 0.0),
transition_wave: (0.0, 0.0),
})) {
if let Err(e) = restore_output(output) {
eprintln!("WARNING: failed to load cache for output {output}: {e}");
}
}
Ok(())
}
fn restore_output(output: &str) -> Result<(), String> {
let (filter, img_path) = common::cache::get_previous_image_path(output)
.map_err(|e| format!("failed to get previous image path: {e}"))?;
if img_path.is_empty() {
return Err("cache file does not exist".to_string());
}
#[allow(deprecated)]
process_swww_args(&Swww::Img(cli::Img {
image: cli::parse_image(&img_path)?,
outputs: output.to_string(),
no_resize: false,
resize: ResizeStrategy::Crop,
fill_color: [0, 0, 0],
filter: Filter::from_str(&filter).unwrap_or(Filter::Lanczos3),
transition_type: cli::TransitionType::None,
transition_step: std::num::NonZeroU8::MAX,
transition_duration: 0.0,
transition_fps: 30,
transition_angle: 0.0,
transition_pos: cli::CliPosition {
x: cli::CliCoord::Pixel(0.0),
y: cli::CliCoord::Pixel(0.0),
},
invert_y: false,
transition_bezier: (0.0, 0.0, 0.0, 0.0),
transition_wave: (0.0, 0.0),
}))
}

View File

@@ -70,7 +70,7 @@ pub fn get_previous_image_path(output_name: &str) -> io::Result<(String, String)
filepath.push(output_name);
if !filepath.is_file() {
return Ok(("Lanczos3".to_string(), "".to_string()));
return Ok(("".to_string(), "".to_string()));
}
let mut buf = Vec::with_capacity(64);