minedmap/tile_mipmapper: store source modified timestamp with mipmapped tiles

This commit is contained in:
Matthias Schiffer 2023-07-30 21:38:42 +02:00
parent 628a702fd7
commit 4d6644f427
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C

View file

@ -61,16 +61,34 @@ impl<'a> TileMipmapper<'a> {
let mut image: image::DynamicImage = let mut image: image::DynamicImage =
image::ImageBuffer::<P, Vec<P::Subpixel>>::new(N, N).into(); image::ImageBuffer::<P, Vec<P::Subpixel>>::new(N, N).into();
for (dx, dz) in [(0, 0), (0, 1), (1, 0), (1, 1)] { let sources: Vec<_> = [(0, 0), (0, 1), (1, 0), (1, 1)]
.into_iter()
.filter_map(|(dx, dz)| {
let source_coords = TileCoords { let source_coords = TileCoords {
x: 2 * coords.x + dx, x: 2 * coords.x + dx,
z: 2 * coords.z + dz, z: 2 * coords.z + dz,
}; };
if !prev.contains(source_coords) { if !prev.contains(source_coords) {
continue; return None;
} }
let source_path = self.config.tile_path(kind, level - 1, source_coords); let source_path = self.config.tile_path(kind, level - 1, source_coords);
let timestamp = match fs::modified_timestamp(&source_path) {
Ok(timestamp) => timestamp,
Err(err) => {
eprintln!("{}", err);
return None;
}
};
Some(((dx, dz), source_path, timestamp))
})
.collect();
let Some(timestamp) = sources.iter().map(|(_, _, ts)| *ts).max() else {
return Ok(());
};
for ((dx, dz), source_path, _) in sources {
let source = match image::open(&source_path) { let source = match image::open(&source_path) {
Ok(source) => source, Ok(source) => source,
Err(err) => { Err(err) => {
@ -91,7 +109,7 @@ impl<'a> TileMipmapper<'a> {
); );
} }
fs::create_with_tmpfile(&output_path, |file| { fs::create_with_timestamp(&output_path, timestamp, |file| {
image image
.write_to(file, image::ImageFormat::Png) .write_to(file, image::ImageFormat::Png)
.context("Failed to save image") .context("Failed to save image")