diff options
author | Daniel Schadt <kingdread@gmx.de> | 2023-01-12 23:59:46 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2023-01-12 23:59:46 +0100 |
commit | 7bbba155f10ce1344724ea00ca70c4d3bb469272 (patch) | |
tree | a370a39a8ad226e27bc1c4f3957c993ed17ad816 /src/layer.rs | |
parent | def44c6e969f1027da82e4130a82db7e4916ba86 (diff) | |
download | hittekaart-7bbba155f10ce1344724ea00ca70c4d3bb469272.tar.gz hittekaart-7bbba155f10ce1344724ea00ca70c4d3bb469272.tar.bz2 hittekaart-7bbba155f10ce1344724ea00ca70c4d3bb469272.zip |
parallelize PNG encoding
This gives a massive speedup
Diffstat (limited to 'src/layer.rs')
-rw-r--r-- | src/layer.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/layer.rs b/src/layer.rs index a8057a0..ff69f7d 100644 --- a/src/layer.rs +++ b/src/layer.rs @@ -12,6 +12,7 @@ use image::{ ColorType, ImageBuffer, ImageEncoder, Pixel, RgbaImage, }; use num_traits::Zero; +use rayon::iter::{IntoParallelIterator, ParallelIterator}; pub const TILE_HEIGHT: u64 = 256; pub const TILE_WIDTH: u64 = 256; @@ -104,6 +105,18 @@ impl<P: Pixel> TileLayer<P> { } } +impl<P> TileLayer<P> +where + P: Pixel + Send, + P::Subpixel: Send, +{ + pub fn into_parallel_tiles( + self, + ) -> impl ParallelIterator<Item = (u64, u64, ImageBuffer<P, Vec<P::Subpixel>>)> { + IntoParallelIterator::into_par_iter(self.tiles).map(|((x, y), t)| (x, y, t)) + } +} + pub fn compress_png<P: AsRef<Path>>(image: &RgbaImage, path: P) -> Result<()> { let outstream = BufWriter::new(File::create(path)?); let encoder = |