use rayon for parallel image resizing
This commit is contained in:
parent
628e41afa3
commit
890b46e45d
3 changed files with 7 additions and 4 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -881,6 +881,7 @@ dependencies = [
|
||||||
"image",
|
"image",
|
||||||
"log",
|
"log",
|
||||||
"mktemp",
|
"mktemp",
|
||||||
|
"rayon",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_yml",
|
"serde_yml",
|
||||||
"tera",
|
"tera",
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ env_logger = "^0.11.8"
|
||||||
fs_extra = "^1.3.0"
|
fs_extra = "^1.3.0"
|
||||||
image = "^0.25.6"
|
image = "^0.25.6"
|
||||||
log = "^0.4.27"
|
log = "^0.4.27"
|
||||||
|
rayon = "^1.10.0"
|
||||||
serde = { version = "^1.0", features = ["derive"] }
|
serde = { version = "^1.0", features = ["derive"] }
|
||||||
serde_yml = "^0.0.12"
|
serde_yml = "^0.0.12"
|
||||||
tera = { version = "^1.20", default-features = false }
|
tera = { version = "^1.20", default-features = false }
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use crate::config::Config;
|
||||||
use album_dir::{AlbumDir, Image};
|
use album_dir::{AlbumDir, Image};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use image::imageops::FilterType;
|
use image::imageops::FilterType;
|
||||||
|
use rayon::prelude::*;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
@ -145,9 +146,9 @@ fn copy_static(config: &Config) -> anyhow::Result<()> {
|
||||||
|
|
||||||
fn generate_images(config: &Config, album: &AlbumDir) -> anyhow::Result<()> {
|
fn generate_images(config: &Config, album: &AlbumDir) -> anyhow::Result<()> {
|
||||||
let output_path = album.path.join(&config.output_dir);
|
let output_path = album.path.join(&config.output_dir);
|
||||||
// TODO: use par_iter() ?
|
|
||||||
// TODO: progress bar ?
|
// TODO: progress bar ?
|
||||||
for img in album.iter_all_images() {
|
let all_images: Vec<&Image> = album.iter_all_images().collect();
|
||||||
|
all_images.par_iter().try_for_each(|img| {
|
||||||
let orig_image = image::open(&img.path)?;
|
let orig_image = image::open(&img.path)?;
|
||||||
|
|
||||||
// TODO: If orig_path is the same as the original image, and quick mode is on, skip to next
|
// TODO: If orig_path is the same as the original image, and quick mode is on, skip to next
|
||||||
|
|
@ -186,9 +187,9 @@ fn generate_images(config: &Config, album: &AlbumDir) -> anyhow::Result<()> {
|
||||||
orig_image
|
orig_image
|
||||||
.resize(config.view_size.0, config.view_size.1, IMG_RESIZE_FILTER)
|
.resize(config.view_size.0, config.view_size.1, IMG_RESIZE_FILTER)
|
||||||
.save(&screen_path)?;
|
.save(&screen_path)?;
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_html(config: &Config, album: &AlbumDir) -> anyhow::Result<()> {
|
fn generate_html(config: &Config, album: &AlbumDir) -> anyhow::Result<()> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue