Skip to content

Commit

Permalink
perf: multithreading recursive mode (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
fgardt authored Mar 21, 2024
1 parent 7a2dee7 commit a11567b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ clap = { version = "4.5", features = ["derive"] }
env_logger = "0.10"
image = { version = "0.25", features = ["png"] }
log = "0.4"
rayon = "1.9.0"
thiserror = "1.0"
1 change: 0 additions & 1 deletion src/image_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ pub fn crop_images(images: &mut Vec<RgbaImage>) -> ImgUtilResult<(i32, i32)> {
let mut max_x = std::u32::MIN;
let mut max_y = std::u32::MIN;

// TODO: parallelize this
for image in images.iter() {
// ensure image has same size
if image.width() != raw_width || image.height() != raw_height {
Expand Down
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
use clap::{Args, Parser, Subcommand};
use image::{ImageBuffer, RgbaImage};
use image_util::ImageBufferExt;
use rayon::prelude::*;

#[macro_use]
extern crate log;
Expand Down Expand Up @@ -132,11 +133,11 @@ impl SpritesheetArgs {
return Ok(());
}

for source in sources {
if let Err(err) = generate_spritesheet(self, &source) {
sources.par_iter().for_each(|source| {
if let Err(err) = generate_spritesheet(self, source) {
error!("{}: {err}", source.display(),);
}
}
});

Ok(())
}
Expand Down

0 comments on commit a11567b

Please sign in to comment.