Skip to content

Commit

Permalink
Fix swww restore error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kerty0 committed Oct 27, 2024
1 parent 716c489 commit fb45d81
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
3 changes: 1 addition & 2 deletions client/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ impl Display for Filter {
Self::CatmullRom => "CatmullRom",
Self::Mitchell => "Mitchell",
Self::Lanczos3 => "Lanczos3",
}
.to_string();
};
write!(f, "{}", str)
}
}
Expand Down
54 changes: 31 additions & 23 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}))
}
2 changes: 1 addition & 1 deletion common/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fb45d81

Please sign in to comment.