Skip to content

Commit

Permalink
transform dump_images to functionnal iterator code
Browse files Browse the repository at this point in the history
and split in two functions
  • Loading branch information
gwen-lg committed Feb 3, 2024
1 parent d10af33 commit ba7c71b
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,26 @@ pub fn run(opt: &Opt) -> anyhow::Result<()> {
Ok(())
}

/// dump all images
fn dump_images(vobsubs: &[preprocessor::PreprocessedVobSubtitle]) -> Result<(), Error> {
for (i, sub) in vobsubs.iter().enumerate() {
for (j, image) in sub.images.iter().enumerate() {
let filename = format!("{:06}-{:02}.png", i, j);
image
.save(&filename)
.map_err(|source| Error::DumpImage { filename, source })?;
}
}
Ok(())
vobsubs.iter().enumerate().try_for_each(|(i, sub)| {
sub.images
.iter()
.enumerate()
.try_for_each(|(j, image)| dump_image(i, j, image))
})
}

/// dump one image
fn dump_image(
i: usize,
j: usize,
image: &image::ImageBuffer<image::Luma<u8>, Vec<u8>>,
) -> Result<(), Error> {
let filename = format!("{:06}-{:02}.png", i, j);
image
.save(&filename)
.map_err(|source| Error::DumpImage { filename, source })
}

/// Log errors and remove bad results.
Expand Down

0 comments on commit ba7c71b

Please sign in to comment.