From 2e9c8a69750af8f1ff553bb8bcae2ff726bb9c1a Mon Sep 17 00:00:00 2001 From: tuxmain Date: Mon, 21 Feb 2022 19:34:30 +0100 Subject: [PATCH] mapserver: Fix unzoom gen --- mapserver/Cargo.lock | 24 ------------- mapserver/Cargo.toml | 1 - mapserver/src/main.rs | 95 ++++++++++++++++++++++++++++++--------------------- 3 files changed, 56 insertions(+), 64 deletions(-) diff --git a/mapserver/Cargo.lock b/mapserver/Cargo.lock index 7568933..e9cbfe1 100644 --- a/mapserver/Cargo.lock +++ b/mapserver/Cargo.lock @@ -604,16 +604,6 @@ dependencies = [ ] [[package]] -name = "ctrlc" -version = "3.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a19c6cedffdc8c03a3346d723eb20bd85a13362bb96dc2ac000842c6381ec7bf" -dependencies = [ - "nix", - "winapi", -] - -[[package]] name = "dashmap" version = "4.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1097,7 +1087,6 @@ version = "0.1.0" dependencies = [ "async-std", "crossbeam-channel", - "ctrlc", "http-types", "image", "log", @@ -1157,19 +1146,6 @@ dependencies = [ ] [[package]] -name = "nix" -version = "0.23.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6" -dependencies = [ - "bitflags", - "cc", - "cfg-if 1.0.0", - "libc", - "memoffset", -] - -[[package]] name = "num-integer" version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/mapserver/Cargo.toml b/mapserver/Cargo.toml index 8872510..db9016c 100644 --- a/mapserver/Cargo.toml +++ b/mapserver/Cargo.toml @@ -6,7 +6,6 @@ edition = "2021" [dependencies] async-std = { version = "1.6.5", features = ["attributes"] } crossbeam-channel = "0.5.2" -ctrlc = "3.2.1" http-types = "2.12.0" image = "0.24.1" log = "0.4.14" diff --git a/mapserver/src/main.rs b/mapserver/src/main.rs index 0aa6160..0409df6 100644 --- a/mapserver/src/main.rs +++ b/mapserver/src/main.rs @@ -120,49 +120,66 @@ fn generate_tile( run_minetestmapper(z, x, y, tile_dir, tile_path, config)? } std::cmp::Ordering::Less => { - let tile1_path = - get_dep_tile(z + 1, x * 2, y * 2, tasks.clone(), config.clone())?; - let tile2_path = get_dep_tile( - z + 1, - x * 2, - y * 2 + 1, - tasks.clone(), - config.clone(), - )?; - let tile3_path = get_dep_tile( - z + 1, - x * 2 + 1, - y * 2, - tasks.clone(), - config.clone(), - )?; - let tile4_path = get_dep_tile( - z + 1, - x * 2 + 1, - y * 2 + 1, - tasks.clone(), - config.clone(), - )?; - - let tile1 = image::open(tile1_path).map_err(Error::Image)?.into_rgb8(); - let tile2 = image::open(tile2_path).map_err(Error::Image)?.into_rgb8(); - let tile3 = image::open(tile3_path).map_err(Error::Image)?.into_rgb8(); - let tile4 = image::open(tile4_path).map_err(Error::Image)?.into_rgb8(); - let mut tile = image::ImageBuffer::, Vec>::new( config.tile_size as u32 * 2, config.tile_size as u32 * 2, ); - image::imageops::replace(&mut tile, &tile1, 0, 0); - image::imageops::replace(&mut tile, &tile2, 0, config.tile_size as i64); - image::imageops::replace(&mut tile, &tile3, config.tile_size as i64, 0); - image::imageops::replace( - &mut tile, - &tile4, - config.tile_size as i64, - config.tile_size as i64, - ); - tile.save(tile_path).map_err(Error::Image)?; + if let Ok(ntile_path) = + get_dep_tile(z + 1, x * 2, y * 2, tasks.clone(), config.clone()) + { + if let Ok(ntile) = image::open(ntile_path) { + image::imageops::replace(&mut tile, &ntile.into_rgb8(), 0, 0); + } + } + if let Ok(ntile_path) = + get_dep_tile(z + 1, x * 2, y * 2 + 1, tasks.clone(), config.clone()) + { + if let Ok(ntile) = image::open(ntile_path) { + image::imageops::replace( + &mut tile, + &ntile.into_rgb8(), + 0, + config.tile_size as i64, + ); + } + } + if let Ok(ntile_path) = + get_dep_tile(z + 1, x * 2 + 1, y * 2, tasks.clone(), config.clone()) + { + if let Ok(ntile) = image::open(ntile_path) { + image::imageops::replace( + &mut tile, + &ntile.into_rgb8(), + config.tile_size as i64, + 0, + ); + } + } + if let Ok(ntile_path) = get_dep_tile( + z + 1, + x * 2 + 1, + y * 2 + 1, + tasks.clone(), + config.clone(), + ) { + if let Ok(ntile) = image::open(ntile_path) { + image::imageops::replace( + &mut tile, + &ntile.into_rgb8(), + config.tile_size as i64, + config.tile_size as i64, + ); + } + } + + image::imageops::resize( + &tile, + config.tile_size as u32, + config.tile_size as u32, + image::imageops::Triangle, + ) + .save(tile_path) + .map_err(Error::Image)?; } std::cmp::Ordering::Greater => Err(Error::Todo)?, }